1 /* bnx2x_main.c: Broadcom Everest network driver.
3 * Copyright (c) 2007-2012 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_dcb.h"
65 #include <linux/firmware.h>
66 #include "bnx2x_fw_file_hdr.h"
68 #define FW_FILE_VERSION \
69 __stringify(BCM_5710_FW_MAJOR_VERSION) "." \
70 __stringify(BCM_5710_FW_MINOR_VERSION) "." \
71 __stringify(BCM_5710_FW_REVISION_VERSION) "." \
72 __stringify(BCM_5710_FW_ENGINEERING_VERSION)
73 #define FW_FILE_NAME_E1 "bnx2x/bnx2x-e1-" FW_FILE_VERSION ".fw"
74 #define FW_FILE_NAME_E1H "bnx2x/bnx2x-e1h-" FW_FILE_VERSION ".fw"
75 #define FW_FILE_NAME_E2 "bnx2x/bnx2x-e2-" FW_FILE_VERSION ".fw"
77 /* Time in jiffies before concluding the transmitter is hung */
78 #define TX_TIMEOUT (5*HZ)
80 static char version[] __devinitdata =
81 "Broadcom NetXtreme II 5771x/578xx 10/20-Gigabit Ethernet Driver "
82 DRV_MODULE_NAME " " DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
84 MODULE_AUTHOR("Eliezer Tamir");
85 MODULE_DESCRIPTION("Broadcom NetXtreme II "
86 "BCM57710/57711/57711E/"
87 "57712/57712_MF/57800/57800_MF/57810/57810_MF/"
88 "57840/57840_MF Driver");
89 MODULE_LICENSE("GPL");
90 MODULE_VERSION(DRV_MODULE_VERSION);
91 MODULE_FIRMWARE(FW_FILE_NAME_E1);
92 MODULE_FIRMWARE(FW_FILE_NAME_E1H);
93 MODULE_FIRMWARE(FW_FILE_NAME_E2);
95 static int multi_mode = 1;
96 module_param(multi_mode, int, 0);
97 MODULE_PARM_DESC(multi_mode, " Multi queue mode "
98 "(0 Disable; 1 Enable (default))");
101 module_param(num_queues, int, 0);
102 MODULE_PARM_DESC(num_queues, " Number of queues for multi_mode=1"
103 " (default is as a number of CPUs)");
105 static int disable_tpa;
106 module_param(disable_tpa, int, 0);
107 MODULE_PARM_DESC(disable_tpa, " Disable the TPA (LRO) feature");
109 #define INT_MODE_INTx 1
110 #define INT_MODE_MSI 2
112 module_param(int_mode, int, 0);
113 MODULE_PARM_DESC(int_mode, " Force interrupt mode other than MSI-X "
116 static int dropless_fc;
117 module_param(dropless_fc, int, 0);
118 MODULE_PARM_DESC(dropless_fc, " Pause on exhausted host ring");
120 static int mrrs = -1;
121 module_param(mrrs, int, 0);
122 MODULE_PARM_DESC(mrrs, " Force Max Read Req Size (0..3) (for debug)");
125 module_param(debug, int, 0);
126 MODULE_PARM_DESC(debug, " Default debug msglevel");
130 struct workqueue_struct *bnx2x_wq;
132 enum bnx2x_board_type {
146 /* indexed by board_type, above */
149 } board_info[] __devinitdata = {
150 { "Broadcom NetXtreme II BCM57710 10 Gigabit PCIe [Everest]" },
151 { "Broadcom NetXtreme II BCM57711 10 Gigabit PCIe" },
152 { "Broadcom NetXtreme II BCM57711E 10 Gigabit PCIe" },
153 { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet" },
154 { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Multi Function" },
155 { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet" },
156 { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Multi Function" },
157 { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet" },
158 { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Multi Function" },
159 { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet" },
160 { "Broadcom NetXtreme II BCM57840 10/20 Gigabit "
161 "Ethernet Multi Function"}
164 #ifndef PCI_DEVICE_ID_NX2_57710
165 #define PCI_DEVICE_ID_NX2_57710 CHIP_NUM_57710
167 #ifndef PCI_DEVICE_ID_NX2_57711
168 #define PCI_DEVICE_ID_NX2_57711 CHIP_NUM_57711
170 #ifndef PCI_DEVICE_ID_NX2_57711E
171 #define PCI_DEVICE_ID_NX2_57711E CHIP_NUM_57711E
173 #ifndef PCI_DEVICE_ID_NX2_57712
174 #define PCI_DEVICE_ID_NX2_57712 CHIP_NUM_57712
176 #ifndef PCI_DEVICE_ID_NX2_57712_MF
177 #define PCI_DEVICE_ID_NX2_57712_MF CHIP_NUM_57712_MF
179 #ifndef PCI_DEVICE_ID_NX2_57800
180 #define PCI_DEVICE_ID_NX2_57800 CHIP_NUM_57800
182 #ifndef PCI_DEVICE_ID_NX2_57800_MF
183 #define PCI_DEVICE_ID_NX2_57800_MF CHIP_NUM_57800_MF
185 #ifndef PCI_DEVICE_ID_NX2_57810
186 #define PCI_DEVICE_ID_NX2_57810 CHIP_NUM_57810
188 #ifndef PCI_DEVICE_ID_NX2_57810_MF
189 #define PCI_DEVICE_ID_NX2_57810_MF CHIP_NUM_57810_MF
191 #ifndef PCI_DEVICE_ID_NX2_57840
192 #define PCI_DEVICE_ID_NX2_57840 CHIP_NUM_57840
194 #ifndef PCI_DEVICE_ID_NX2_57840_MF
195 #define PCI_DEVICE_ID_NX2_57840_MF CHIP_NUM_57840_MF
197 static DEFINE_PCI_DEVICE_TABLE(bnx2x_pci_tbl) = {
198 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57710), BCM57710 },
199 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711), BCM57711 },
200 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711E), BCM57711E },
201 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712), BCM57712 },
202 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_MF), BCM57712_MF },
203 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800), BCM57800 },
204 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_MF), BCM57800_MF },
205 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810), BCM57810 },
206 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_MF), BCM57810_MF },
207 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840), BCM57840 },
208 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MF), BCM57840_MF },
212 MODULE_DEVICE_TABLE(pci, bnx2x_pci_tbl);
214 /* Global resources for unloading a previously loaded device */
215 #define BNX2X_PREV_WAIT_NEEDED 1
216 static DEFINE_SEMAPHORE(bnx2x_prev_sem);
217 static LIST_HEAD(bnx2x_prev_list);
218 /****************************************************************************
219 * General service functions
220 ****************************************************************************/
222 static inline void __storm_memset_dma_mapping(struct bnx2x *bp,
223 u32 addr, dma_addr_t mapping)
225 REG_WR(bp, addr, U64_LO(mapping));
226 REG_WR(bp, addr + 4, U64_HI(mapping));
229 static inline void storm_memset_spq_addr(struct bnx2x *bp,
230 dma_addr_t mapping, u16 abs_fid)
232 u32 addr = XSEM_REG_FAST_MEMORY +
233 XSTORM_SPQ_PAGE_BASE_OFFSET(abs_fid);
235 __storm_memset_dma_mapping(bp, addr, mapping);
238 static inline void storm_memset_vf_to_pf(struct bnx2x *bp, u16 abs_fid,
241 REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_VF_TO_PF_OFFSET(abs_fid),
243 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_VF_TO_PF_OFFSET(abs_fid),
245 REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_VF_TO_PF_OFFSET(abs_fid),
247 REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_VF_TO_PF_OFFSET(abs_fid),
251 static inline void storm_memset_func_en(struct bnx2x *bp, u16 abs_fid,
254 REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(abs_fid),
256 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(abs_fid),
258 REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(abs_fid),
260 REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(abs_fid),
264 static inline void storm_memset_eq_data(struct bnx2x *bp,
265 struct event_ring_data *eq_data,
268 size_t size = sizeof(struct event_ring_data);
270 u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_DATA_OFFSET(pfid);
272 __storm_memset_struct(bp, addr, size, (u32 *)eq_data);
275 static inline void storm_memset_eq_prod(struct bnx2x *bp, u16 eq_prod,
278 u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_PROD_OFFSET(pfid);
279 REG_WR16(bp, addr, eq_prod);
283 * locking is done by mcp
285 static void bnx2x_reg_wr_ind(struct bnx2x *bp, u32 addr, u32 val)
287 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
288 pci_write_config_dword(bp->pdev, PCICFG_GRC_DATA, val);
289 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
290 PCICFG_VENDOR_ID_OFFSET);
293 static u32 bnx2x_reg_rd_ind(struct bnx2x *bp, u32 addr)
297 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
298 pci_read_config_dword(bp->pdev, PCICFG_GRC_DATA, &val);
299 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
300 PCICFG_VENDOR_ID_OFFSET);
305 #define DMAE_DP_SRC_GRC "grc src_addr [%08x]"
306 #define DMAE_DP_SRC_PCI "pci src_addr [%x:%08x]"
307 #define DMAE_DP_DST_GRC "grc dst_addr [%08x]"
308 #define DMAE_DP_DST_PCI "pci dst_addr [%x:%08x]"
309 #define DMAE_DP_DST_NONE "dst_addr [none]"
312 /* copy command into DMAE command memory and set DMAE command go */
313 void bnx2x_post_dmae(struct bnx2x *bp, struct dmae_command *dmae, int idx)
318 cmd_offset = (DMAE_REG_CMD_MEM + sizeof(struct dmae_command) * idx);
319 for (i = 0; i < (sizeof(struct dmae_command)/4); i++) {
320 REG_WR(bp, cmd_offset + i*4, *(((u32 *)dmae) + i));
322 REG_WR(bp, dmae_reg_go_c[idx], 1);
325 u32 bnx2x_dmae_opcode_add_comp(u32 opcode, u8 comp_type)
327 return opcode | ((comp_type << DMAE_COMMAND_C_DST_SHIFT) |
331 u32 bnx2x_dmae_opcode_clr_src_reset(u32 opcode)
333 return opcode & ~DMAE_CMD_SRC_RESET;
336 u32 bnx2x_dmae_opcode(struct bnx2x *bp, u8 src_type, u8 dst_type,
337 bool with_comp, u8 comp_type)
341 opcode |= ((src_type << DMAE_COMMAND_SRC_SHIFT) |
342 (dst_type << DMAE_COMMAND_DST_SHIFT));
344 opcode |= (DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET);
346 opcode |= (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0);
347 opcode |= ((BP_VN(bp) << DMAE_CMD_E1HVN_SHIFT) |
348 (BP_VN(bp) << DMAE_COMMAND_DST_VN_SHIFT));
349 opcode |= (DMAE_COM_SET_ERR << DMAE_COMMAND_ERR_POLICY_SHIFT);
352 opcode |= DMAE_CMD_ENDIANITY_B_DW_SWAP;
354 opcode |= DMAE_CMD_ENDIANITY_DW_SWAP;
357 opcode = bnx2x_dmae_opcode_add_comp(opcode, comp_type);
361 static void bnx2x_prep_dmae_with_comp(struct bnx2x *bp,
362 struct dmae_command *dmae,
363 u8 src_type, u8 dst_type)
365 memset(dmae, 0, sizeof(struct dmae_command));
368 dmae->opcode = bnx2x_dmae_opcode(bp, src_type, dst_type,
369 true, DMAE_COMP_PCI);
371 /* fill in the completion parameters */
372 dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_comp));
373 dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_comp));
374 dmae->comp_val = DMAE_COMP_VAL;
377 /* issue a dmae command over the init-channel and wailt for completion */
378 static int bnx2x_issue_dmae_with_comp(struct bnx2x *bp,
379 struct dmae_command *dmae)
381 u32 *wb_comp = bnx2x_sp(bp, wb_comp);
382 int cnt = CHIP_REV_IS_SLOW(bp) ? (400000) : 4000;
386 * Lock the dmae channel. Disable BHs to prevent a dead-lock
387 * as long as this code is called both from syscall context and
388 * from ndo_set_rx_mode() flow that may be called from BH.
390 spin_lock_bh(&bp->dmae_lock);
392 /* reset completion */
395 /* post the command on the channel used for initializations */
396 bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp));
398 /* wait for completion */
400 while ((*wb_comp & ~DMAE_PCI_ERR_FLAG) != DMAE_COMP_VAL) {
403 (bp->recovery_state != BNX2X_RECOVERY_DONE &&
404 bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
405 BNX2X_ERR("DMAE timeout!\n");
412 if (*wb_comp & DMAE_PCI_ERR_FLAG) {
413 BNX2X_ERR("DMAE PCI error!\n");
418 spin_unlock_bh(&bp->dmae_lock);
422 void bnx2x_write_dmae(struct bnx2x *bp, dma_addr_t dma_addr, u32 dst_addr,
425 struct dmae_command dmae;
427 if (!bp->dmae_ready) {
428 u32 *data = bnx2x_sp(bp, wb_data[0]);
431 bnx2x_init_ind_wr(bp, dst_addr, data, len32);
433 bnx2x_init_str_wr(bp, dst_addr, data, len32);
437 /* set opcode and fixed command fields */
438 bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_GRC);
440 /* fill in addresses and len */
441 dmae.src_addr_lo = U64_LO(dma_addr);
442 dmae.src_addr_hi = U64_HI(dma_addr);
443 dmae.dst_addr_lo = dst_addr >> 2;
444 dmae.dst_addr_hi = 0;
447 /* issue the command and wait for completion */
448 bnx2x_issue_dmae_with_comp(bp, &dmae);
451 void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32)
453 struct dmae_command dmae;
455 if (!bp->dmae_ready) {
456 u32 *data = bnx2x_sp(bp, wb_data[0]);
460 for (i = 0; i < len32; i++)
461 data[i] = bnx2x_reg_rd_ind(bp, src_addr + i*4);
463 for (i = 0; i < len32; i++)
464 data[i] = REG_RD(bp, src_addr + i*4);
469 /* set opcode and fixed command fields */
470 bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_GRC, DMAE_DST_PCI);
472 /* fill in addresses and len */
473 dmae.src_addr_lo = src_addr >> 2;
474 dmae.src_addr_hi = 0;
475 dmae.dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_data));
476 dmae.dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_data));
479 /* issue the command and wait for completion */
480 bnx2x_issue_dmae_with_comp(bp, &dmae);
483 static void bnx2x_write_dmae_phys_len(struct bnx2x *bp, dma_addr_t phys_addr,
486 int dmae_wr_max = DMAE_LEN32_WR_MAX(bp);
489 while (len > dmae_wr_max) {
490 bnx2x_write_dmae(bp, phys_addr + offset,
491 addr + offset, dmae_wr_max);
492 offset += dmae_wr_max * 4;
496 bnx2x_write_dmae(bp, phys_addr + offset, addr + offset, len);
499 static int bnx2x_mc_assert(struct bnx2x *bp)
503 u32 row0, row1, row2, row3;
506 last_idx = REG_RD8(bp, BAR_XSTRORM_INTMEM +
507 XSTORM_ASSERT_LIST_INDEX_OFFSET);
509 BNX2X_ERR("XSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
511 /* print the asserts */
512 for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
514 row0 = REG_RD(bp, BAR_XSTRORM_INTMEM +
515 XSTORM_ASSERT_LIST_OFFSET(i));
516 row1 = REG_RD(bp, BAR_XSTRORM_INTMEM +
517 XSTORM_ASSERT_LIST_OFFSET(i) + 4);
518 row2 = REG_RD(bp, BAR_XSTRORM_INTMEM +
519 XSTORM_ASSERT_LIST_OFFSET(i) + 8);
520 row3 = REG_RD(bp, BAR_XSTRORM_INTMEM +
521 XSTORM_ASSERT_LIST_OFFSET(i) + 12);
523 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
524 BNX2X_ERR("XSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
525 i, row3, row2, row1, row0);
533 last_idx = REG_RD8(bp, BAR_TSTRORM_INTMEM +
534 TSTORM_ASSERT_LIST_INDEX_OFFSET);
536 BNX2X_ERR("TSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
538 /* print the asserts */
539 for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
541 row0 = REG_RD(bp, BAR_TSTRORM_INTMEM +
542 TSTORM_ASSERT_LIST_OFFSET(i));
543 row1 = REG_RD(bp, BAR_TSTRORM_INTMEM +
544 TSTORM_ASSERT_LIST_OFFSET(i) + 4);
545 row2 = REG_RD(bp, BAR_TSTRORM_INTMEM +
546 TSTORM_ASSERT_LIST_OFFSET(i) + 8);
547 row3 = REG_RD(bp, BAR_TSTRORM_INTMEM +
548 TSTORM_ASSERT_LIST_OFFSET(i) + 12);
550 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
551 BNX2X_ERR("TSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
552 i, row3, row2, row1, row0);
560 last_idx = REG_RD8(bp, BAR_CSTRORM_INTMEM +
561 CSTORM_ASSERT_LIST_INDEX_OFFSET);
563 BNX2X_ERR("CSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
565 /* print the asserts */
566 for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
568 row0 = REG_RD(bp, BAR_CSTRORM_INTMEM +
569 CSTORM_ASSERT_LIST_OFFSET(i));
570 row1 = REG_RD(bp, BAR_CSTRORM_INTMEM +
571 CSTORM_ASSERT_LIST_OFFSET(i) + 4);
572 row2 = REG_RD(bp, BAR_CSTRORM_INTMEM +
573 CSTORM_ASSERT_LIST_OFFSET(i) + 8);
574 row3 = REG_RD(bp, BAR_CSTRORM_INTMEM +
575 CSTORM_ASSERT_LIST_OFFSET(i) + 12);
577 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
578 BNX2X_ERR("CSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
579 i, row3, row2, row1, row0);
587 last_idx = REG_RD8(bp, BAR_USTRORM_INTMEM +
588 USTORM_ASSERT_LIST_INDEX_OFFSET);
590 BNX2X_ERR("USTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
592 /* print the asserts */
593 for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
595 row0 = REG_RD(bp, BAR_USTRORM_INTMEM +
596 USTORM_ASSERT_LIST_OFFSET(i));
597 row1 = REG_RD(bp, BAR_USTRORM_INTMEM +
598 USTORM_ASSERT_LIST_OFFSET(i) + 4);
599 row2 = REG_RD(bp, BAR_USTRORM_INTMEM +
600 USTORM_ASSERT_LIST_OFFSET(i) + 8);
601 row3 = REG_RD(bp, BAR_USTRORM_INTMEM +
602 USTORM_ASSERT_LIST_OFFSET(i) + 12);
604 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
605 BNX2X_ERR("USTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
606 i, row3, row2, row1, row0);
616 void bnx2x_fw_dump_lvl(struct bnx2x *bp, const char *lvl)
622 u32 trace_shmem_base;
624 BNX2X_ERR("NO MCP - can not dump\n");
627 netdev_printk(lvl, bp->dev, "bc %d.%d.%d\n",
628 (bp->common.bc_ver & 0xff0000) >> 16,
629 (bp->common.bc_ver & 0xff00) >> 8,
630 (bp->common.bc_ver & 0xff));
632 val = REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER);
633 if (val == REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER))
634 BNX2X_ERR("%s" "MCP PC at 0x%x\n", lvl, val);
636 if (BP_PATH(bp) == 0)
637 trace_shmem_base = bp->common.shmem_base;
639 trace_shmem_base = SHMEM2_RD(bp, other_shmem_base_addr);
640 addr = trace_shmem_base - 0x800;
642 /* validate TRCB signature */
643 mark = REG_RD(bp, addr);
644 if (mark != MFW_TRACE_SIGNATURE) {
645 BNX2X_ERR("Trace buffer signature is missing.");
649 /* read cyclic buffer pointer */
651 mark = REG_RD(bp, addr);
652 mark = (CHIP_IS_E1x(bp) ? MCP_REG_MCPR_SCRATCH : MCP_A_REG_MCPR_SCRATCH)
653 + ((mark + 0x3) & ~0x3) - 0x08000000;
654 printk("%s" "begin fw dump (mark 0x%x)\n", lvl, mark);
657 for (offset = mark; offset <= trace_shmem_base; offset += 0x8*4) {
658 for (word = 0; word < 8; word++)
659 data[word] = htonl(REG_RD(bp, offset + 4*word));
661 pr_cont("%s", (char *)data);
663 for (offset = addr + 4; offset <= mark; offset += 0x8*4) {
664 for (word = 0; word < 8; word++)
665 data[word] = htonl(REG_RD(bp, offset + 4*word));
667 pr_cont("%s", (char *)data);
669 printk("%s" "end of fw dump\n", lvl);
672 static inline void bnx2x_fw_dump(struct bnx2x *bp)
674 bnx2x_fw_dump_lvl(bp, KERN_ERR);
677 void bnx2x_panic_dump(struct bnx2x *bp)
681 struct hc_sp_status_block_data sp_sb_data;
682 int func = BP_FUNC(bp);
683 #ifdef BNX2X_STOP_ON_ERROR
684 u16 start = 0, end = 0;
688 bp->stats_state = STATS_STATE_DISABLED;
689 bp->eth_stats.unrecoverable_error++;
690 DP(BNX2X_MSG_STATS, "stats_state - DISABLED\n");
692 BNX2X_ERR("begin crash dump -----------------\n");
696 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",
697 bp->def_idx, bp->def_att_idx, bp->attn_state,
698 bp->spq_prod_idx, bp->stats_counter);
699 BNX2X_ERR("DSB: attn bits(0x%x) ack(0x%x) id(0x%x) idx(0x%x)\n",
700 bp->def_status_blk->atten_status_block.attn_bits,
701 bp->def_status_blk->atten_status_block.attn_bits_ack,
702 bp->def_status_blk->atten_status_block.status_block_id,
703 bp->def_status_blk->atten_status_block.attn_bits_index);
705 for (i = 0; i < HC_SP_SB_MAX_INDICES; i++)
707 bp->def_status_blk->sp_sb.index_values[i],
708 (i == HC_SP_SB_MAX_INDICES - 1) ? ") " : " ");
710 for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
711 *((u32 *)&sp_sb_data + i) = REG_RD(bp, BAR_CSTRORM_INTMEM +
712 CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
715 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",
716 sp_sb_data.igu_sb_id,
717 sp_sb_data.igu_seg_id,
718 sp_sb_data.p_func.pf_id,
719 sp_sb_data.p_func.vnic_id,
720 sp_sb_data.p_func.vf_id,
721 sp_sb_data.p_func.vf_valid,
725 for_each_eth_queue(bp, i) {
726 struct bnx2x_fastpath *fp = &bp->fp[i];
728 struct hc_status_block_data_e2 sb_data_e2;
729 struct hc_status_block_data_e1x sb_data_e1x;
730 struct hc_status_block_sm *hc_sm_p =
732 sb_data_e1x.common.state_machine :
733 sb_data_e2.common.state_machine;
734 struct hc_index_data *hc_index_p =
736 sb_data_e1x.index_data :
737 sb_data_e2.index_data;
740 struct bnx2x_fp_txdata txdata;
743 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",
744 i, fp->rx_bd_prod, fp->rx_bd_cons,
746 fp->rx_comp_cons, le16_to_cpu(*fp->rx_cons_sb));
747 BNX2X_ERR(" rx_sge_prod(0x%x) last_max_sge(0x%x) fp_hc_idx(0x%x)\n",
748 fp->rx_sge_prod, fp->last_max_sge,
749 le16_to_cpu(fp->fp_hc_idx));
752 for_each_cos_in_tx_queue(fp, cos)
754 txdata = fp->txdata[cos];
755 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",
756 i, txdata.tx_pkt_prod,
757 txdata.tx_pkt_cons, txdata.tx_bd_prod,
759 le16_to_cpu(*txdata.tx_cons_sb));
762 loop = CHIP_IS_E1x(bp) ?
763 HC_SB_MAX_INDICES_E1X : HC_SB_MAX_INDICES_E2;
771 BNX2X_ERR(" run indexes (");
772 for (j = 0; j < HC_SB_MAX_SM; j++)
774 fp->sb_running_index[j],
775 (j == HC_SB_MAX_SM - 1) ? ")" : " ");
777 BNX2X_ERR(" indexes (");
778 for (j = 0; j < loop; j++)
780 fp->sb_index_values[j],
781 (j == loop - 1) ? ")" : " ");
783 data_size = CHIP_IS_E1x(bp) ?
784 sizeof(struct hc_status_block_data_e1x) :
785 sizeof(struct hc_status_block_data_e2);
786 data_size /= sizeof(u32);
787 sb_data_p = CHIP_IS_E1x(bp) ?
788 (u32 *)&sb_data_e1x :
790 /* copy sb data in here */
791 for (j = 0; j < data_size; j++)
792 *(sb_data_p + j) = REG_RD(bp, BAR_CSTRORM_INTMEM +
793 CSTORM_STATUS_BLOCK_DATA_OFFSET(fp->fw_sb_id) +
796 if (!CHIP_IS_E1x(bp)) {
797 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",
798 sb_data_e2.common.p_func.pf_id,
799 sb_data_e2.common.p_func.vf_id,
800 sb_data_e2.common.p_func.vf_valid,
801 sb_data_e2.common.p_func.vnic_id,
802 sb_data_e2.common.same_igu_sb_1b,
803 sb_data_e2.common.state);
805 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",
806 sb_data_e1x.common.p_func.pf_id,
807 sb_data_e1x.common.p_func.vf_id,
808 sb_data_e1x.common.p_func.vf_valid,
809 sb_data_e1x.common.p_func.vnic_id,
810 sb_data_e1x.common.same_igu_sb_1b,
811 sb_data_e1x.common.state);
815 for (j = 0; j < HC_SB_MAX_SM; j++) {
816 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",
817 j, hc_sm_p[j].__flags,
818 hc_sm_p[j].igu_sb_id,
819 hc_sm_p[j].igu_seg_id,
820 hc_sm_p[j].time_to_expire,
821 hc_sm_p[j].timer_value);
825 for (j = 0; j < loop; j++) {
826 pr_cont("INDEX[%d] flags (0x%x) timeout (0x%x)\n", j,
828 hc_index_p[j].timeout);
832 #ifdef BNX2X_STOP_ON_ERROR
835 for_each_rx_queue(bp, i) {
836 struct bnx2x_fastpath *fp = &bp->fp[i];
838 start = RX_BD(le16_to_cpu(*fp->rx_cons_sb) - 10);
839 end = RX_BD(le16_to_cpu(*fp->rx_cons_sb) + 503);
840 for (j = start; j != end; j = RX_BD(j + 1)) {
841 u32 *rx_bd = (u32 *)&fp->rx_desc_ring[j];
842 struct sw_rx_bd *sw_bd = &fp->rx_buf_ring[j];
844 BNX2X_ERR("fp%d: rx_bd[%x]=[%x:%x] sw_bd=[%p]\n",
845 i, j, rx_bd[1], rx_bd[0], sw_bd->data);
848 start = RX_SGE(fp->rx_sge_prod);
849 end = RX_SGE(fp->last_max_sge);
850 for (j = start; j != end; j = RX_SGE(j + 1)) {
851 u32 *rx_sge = (u32 *)&fp->rx_sge_ring[j];
852 struct sw_rx_page *sw_page = &fp->rx_page_ring[j];
854 BNX2X_ERR("fp%d: rx_sge[%x]=[%x:%x] sw_page=[%p]\n",
855 i, j, rx_sge[1], rx_sge[0], sw_page->page);
858 start = RCQ_BD(fp->rx_comp_cons - 10);
859 end = RCQ_BD(fp->rx_comp_cons + 503);
860 for (j = start; j != end; j = RCQ_BD(j + 1)) {
861 u32 *cqe = (u32 *)&fp->rx_comp_ring[j];
863 BNX2X_ERR("fp%d: cqe[%x]=[%x:%x:%x:%x]\n",
864 i, j, cqe[0], cqe[1], cqe[2], cqe[3]);
869 for_each_tx_queue(bp, i) {
870 struct bnx2x_fastpath *fp = &bp->fp[i];
871 for_each_cos_in_tx_queue(fp, cos) {
872 struct bnx2x_fp_txdata *txdata = &fp->txdata[cos];
874 start = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) - 10);
875 end = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) + 245);
876 for (j = start; j != end; j = TX_BD(j + 1)) {
877 struct sw_tx_bd *sw_bd =
878 &txdata->tx_buf_ring[j];
880 BNX2X_ERR("fp%d: txdata %d, packet[%x]=[%p,%x]\n",
881 i, cos, j, sw_bd->skb,
885 start = TX_BD(txdata->tx_bd_cons - 10);
886 end = TX_BD(txdata->tx_bd_cons + 254);
887 for (j = start; j != end; j = TX_BD(j + 1)) {
888 u32 *tx_bd = (u32 *)&txdata->tx_desc_ring[j];
890 BNX2X_ERR("fp%d: txdata %d, tx_bd[%x]=[%x:%x:%x:%x]\n",
891 i, cos, j, tx_bd[0], tx_bd[1],
899 BNX2X_ERR("end crash dump -----------------\n");
905 * bnx2x_pf_flr_clnup() is called during nic_load in the per function HW
908 #define FLR_WAIT_USEC 10000 /* 10 miliseconds */
909 #define FLR_WAIT_INTERVAL 50 /* usec */
910 #define FLR_POLL_CNT (FLR_WAIT_USEC/FLR_WAIT_INTERVAL) /* 200 */
912 struct pbf_pN_buf_regs {
919 struct pbf_pN_cmd_regs {
925 static void bnx2x_pbf_pN_buf_flushed(struct bnx2x *bp,
926 struct pbf_pN_buf_regs *regs,
929 u32 init_crd, crd, crd_start, crd_freed, crd_freed_start;
930 u32 cur_cnt = poll_count;
932 crd_freed = crd_freed_start = REG_RD(bp, regs->crd_freed);
933 crd = crd_start = REG_RD(bp, regs->crd);
934 init_crd = REG_RD(bp, regs->init_crd);
936 DP(BNX2X_MSG_SP, "INIT CREDIT[%d] : %x\n", regs->pN, init_crd);
937 DP(BNX2X_MSG_SP, "CREDIT[%d] : s:%x\n", regs->pN, crd);
938 DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: s:%x\n", regs->pN, crd_freed);
940 while ((crd != init_crd) && ((u32)SUB_S32(crd_freed, crd_freed_start) <
941 (init_crd - crd_start))) {
943 udelay(FLR_WAIT_INTERVAL);
944 crd = REG_RD(bp, regs->crd);
945 crd_freed = REG_RD(bp, regs->crd_freed);
947 DP(BNX2X_MSG_SP, "PBF tx buffer[%d] timed out\n",
949 DP(BNX2X_MSG_SP, "CREDIT[%d] : c:%x\n",
951 DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: c:%x\n",
952 regs->pN, crd_freed);
956 DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF tx buffer[%d]\n",
957 poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
960 static void bnx2x_pbf_pN_cmd_flushed(struct bnx2x *bp,
961 struct pbf_pN_cmd_regs *regs,
964 u32 occup, to_free, freed, freed_start;
965 u32 cur_cnt = poll_count;
967 occup = to_free = REG_RD(bp, regs->lines_occup);
968 freed = freed_start = REG_RD(bp, regs->lines_freed);
970 DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n", regs->pN, occup);
971 DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n", regs->pN, freed);
973 while (occup && ((u32)SUB_S32(freed, freed_start) < to_free)) {
975 udelay(FLR_WAIT_INTERVAL);
976 occup = REG_RD(bp, regs->lines_occup);
977 freed = REG_RD(bp, regs->lines_freed);
979 DP(BNX2X_MSG_SP, "PBF cmd queue[%d] timed out\n",
981 DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n",
983 DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n",
988 DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF cmd queue[%d]\n",
989 poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
992 static inline u32 bnx2x_flr_clnup_reg_poll(struct bnx2x *bp, u32 reg,
993 u32 expected, u32 poll_count)
995 u32 cur_cnt = poll_count;
998 while ((val = REG_RD(bp, reg)) != expected && cur_cnt--)
999 udelay(FLR_WAIT_INTERVAL);
1004 static inline int bnx2x_flr_clnup_poll_hw_counter(struct bnx2x *bp, u32 reg,
1005 char *msg, u32 poll_cnt)
1007 u32 val = bnx2x_flr_clnup_reg_poll(bp, reg, 0, poll_cnt);
1009 BNX2X_ERR("%s usage count=%d\n", msg, val);
1015 static u32 bnx2x_flr_clnup_poll_count(struct bnx2x *bp)
1017 /* adjust polling timeout */
1018 if (CHIP_REV_IS_EMUL(bp))
1019 return FLR_POLL_CNT * 2000;
1021 if (CHIP_REV_IS_FPGA(bp))
1022 return FLR_POLL_CNT * 120;
1024 return FLR_POLL_CNT;
1027 static void bnx2x_tx_hw_flushed(struct bnx2x *bp, u32 poll_count)
1029 struct pbf_pN_cmd_regs cmd_regs[] = {
1030 {0, (CHIP_IS_E3B0(bp)) ?
1031 PBF_REG_TQ_OCCUPANCY_Q0 :
1032 PBF_REG_P0_TQ_OCCUPANCY,
1033 (CHIP_IS_E3B0(bp)) ?
1034 PBF_REG_TQ_LINES_FREED_CNT_Q0 :
1035 PBF_REG_P0_TQ_LINES_FREED_CNT},
1036 {1, (CHIP_IS_E3B0(bp)) ?
1037 PBF_REG_TQ_OCCUPANCY_Q1 :
1038 PBF_REG_P1_TQ_OCCUPANCY,
1039 (CHIP_IS_E3B0(bp)) ?
1040 PBF_REG_TQ_LINES_FREED_CNT_Q1 :
1041 PBF_REG_P1_TQ_LINES_FREED_CNT},
1042 {4, (CHIP_IS_E3B0(bp)) ?
1043 PBF_REG_TQ_OCCUPANCY_LB_Q :
1044 PBF_REG_P4_TQ_OCCUPANCY,
1045 (CHIP_IS_E3B0(bp)) ?
1046 PBF_REG_TQ_LINES_FREED_CNT_LB_Q :
1047 PBF_REG_P4_TQ_LINES_FREED_CNT}
1050 struct pbf_pN_buf_regs buf_regs[] = {
1051 {0, (CHIP_IS_E3B0(bp)) ?
1052 PBF_REG_INIT_CRD_Q0 :
1053 PBF_REG_P0_INIT_CRD ,
1054 (CHIP_IS_E3B0(bp)) ?
1057 (CHIP_IS_E3B0(bp)) ?
1058 PBF_REG_INTERNAL_CRD_FREED_CNT_Q0 :
1059 PBF_REG_P0_INTERNAL_CRD_FREED_CNT},
1060 {1, (CHIP_IS_E3B0(bp)) ?
1061 PBF_REG_INIT_CRD_Q1 :
1062 PBF_REG_P1_INIT_CRD,
1063 (CHIP_IS_E3B0(bp)) ?
1066 (CHIP_IS_E3B0(bp)) ?
1067 PBF_REG_INTERNAL_CRD_FREED_CNT_Q1 :
1068 PBF_REG_P1_INTERNAL_CRD_FREED_CNT},
1069 {4, (CHIP_IS_E3B0(bp)) ?
1070 PBF_REG_INIT_CRD_LB_Q :
1071 PBF_REG_P4_INIT_CRD,
1072 (CHIP_IS_E3B0(bp)) ?
1073 PBF_REG_CREDIT_LB_Q :
1075 (CHIP_IS_E3B0(bp)) ?
1076 PBF_REG_INTERNAL_CRD_FREED_CNT_LB_Q :
1077 PBF_REG_P4_INTERNAL_CRD_FREED_CNT},
1082 /* Verify the command queues are flushed P0, P1, P4 */
1083 for (i = 0; i < ARRAY_SIZE(cmd_regs); i++)
1084 bnx2x_pbf_pN_cmd_flushed(bp, &cmd_regs[i], poll_count);
1087 /* Verify the transmission buffers are flushed P0, P1, P4 */
1088 for (i = 0; i < ARRAY_SIZE(buf_regs); i++)
1089 bnx2x_pbf_pN_buf_flushed(bp, &buf_regs[i], poll_count);
1092 #define OP_GEN_PARAM(param) \
1093 (((param) << SDM_OP_GEN_COMP_PARAM_SHIFT) & SDM_OP_GEN_COMP_PARAM)
1095 #define OP_GEN_TYPE(type) \
1096 (((type) << SDM_OP_GEN_COMP_TYPE_SHIFT) & SDM_OP_GEN_COMP_TYPE)
1098 #define OP_GEN_AGG_VECT(index) \
1099 (((index) << SDM_OP_GEN_AGG_VECT_IDX_SHIFT) & SDM_OP_GEN_AGG_VECT_IDX)
1102 static inline int bnx2x_send_final_clnup(struct bnx2x *bp, u8 clnup_func,
1105 struct sdm_op_gen op_gen = {0};
1107 u32 comp_addr = BAR_CSTRORM_INTMEM +
1108 CSTORM_FINAL_CLEANUP_COMPLETE_OFFSET(clnup_func);
1111 if (REG_RD(bp, comp_addr)) {
1112 BNX2X_ERR("Cleanup complete was not 0 before sending\n");
1116 op_gen.command |= OP_GEN_PARAM(XSTORM_AGG_INT_FINAL_CLEANUP_INDEX);
1117 op_gen.command |= OP_GEN_TYPE(XSTORM_AGG_INT_FINAL_CLEANUP_COMP_TYPE);
1118 op_gen.command |= OP_GEN_AGG_VECT(clnup_func);
1119 op_gen.command |= 1 << SDM_OP_GEN_AGG_VECT_IDX_VALID_SHIFT;
1121 DP(BNX2X_MSG_SP, "sending FW Final cleanup\n");
1122 REG_WR(bp, XSDM_REG_OPERATION_GEN, op_gen.command);
1124 if (bnx2x_flr_clnup_reg_poll(bp, comp_addr, 1, poll_cnt) != 1) {
1125 BNX2X_ERR("FW final cleanup did not succeed\n");
1126 DP(BNX2X_MSG_SP, "At timeout completion address contained %x\n",
1127 (REG_RD(bp, comp_addr)));
1130 /* Zero completion for nxt FLR */
1131 REG_WR(bp, comp_addr, 0);
1136 static inline u8 bnx2x_is_pcie_pending(struct pci_dev *dev)
1141 pos = pci_pcie_cap(dev);
1145 pci_read_config_word(dev, pos + PCI_EXP_DEVSTA, &status);
1146 return status & PCI_EXP_DEVSTA_TRPND;
1149 /* PF FLR specific routines
1151 static int bnx2x_poll_hw_usage_counters(struct bnx2x *bp, u32 poll_cnt)
1154 /* wait for CFC PF usage-counter to zero (includes all the VFs) */
1155 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1156 CFC_REG_NUM_LCIDS_INSIDE_PF,
1157 "CFC PF usage counter timed out",
1162 /* Wait for DQ PF usage-counter to zero (until DQ cleanup) */
1163 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1164 DORQ_REG_PF_USAGE_CNT,
1165 "DQ PF usage counter timed out",
1169 /* Wait for QM PF usage-counter to zero (until DQ cleanup) */
1170 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1171 QM_REG_PF_USG_CNT_0 + 4*BP_FUNC(bp),
1172 "QM PF usage counter timed out",
1176 /* Wait for Timer PF usage-counters to zero (until DQ cleanup) */
1177 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1178 TM_REG_LIN0_VNIC_UC + 4*BP_PORT(bp),
1179 "Timers VNIC usage counter timed out",
1182 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1183 TM_REG_LIN0_NUM_SCANS + 4*BP_PORT(bp),
1184 "Timers NUM_SCANS usage counter timed out",
1188 /* Wait DMAE PF usage counter to zero */
1189 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1190 dmae_reg_go_c[INIT_DMAE_C(bp)],
1191 "DMAE dommand register timed out",
1198 static void bnx2x_hw_enable_status(struct bnx2x *bp)
1202 val = REG_RD(bp, CFC_REG_WEAK_ENABLE_PF);
1203 DP(BNX2X_MSG_SP, "CFC_REG_WEAK_ENABLE_PF is 0x%x\n", val);
1205 val = REG_RD(bp, PBF_REG_DISABLE_PF);
1206 DP(BNX2X_MSG_SP, "PBF_REG_DISABLE_PF is 0x%x\n", val);
1208 val = REG_RD(bp, IGU_REG_PCI_PF_MSI_EN);
1209 DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSI_EN is 0x%x\n", val);
1211 val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_EN);
1212 DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_EN is 0x%x\n", val);
1214 val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_FUNC_MASK);
1215 DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_FUNC_MASK is 0x%x\n", val);
1217 val = REG_RD(bp, PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR);
1218 DP(BNX2X_MSG_SP, "PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR is 0x%x\n", val);
1220 val = REG_RD(bp, PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR);
1221 DP(BNX2X_MSG_SP, "PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR is 0x%x\n", val);
1223 val = REG_RD(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER);
1224 DP(BNX2X_MSG_SP, "PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER is 0x%x\n",
1228 static int bnx2x_pf_flr_clnup(struct bnx2x *bp)
1230 u32 poll_cnt = bnx2x_flr_clnup_poll_count(bp);
1232 DP(BNX2X_MSG_SP, "Cleanup after FLR PF[%d]\n", BP_ABS_FUNC(bp));
1234 /* Re-enable PF target read access */
1235 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
1237 /* Poll HW usage counters */
1238 DP(BNX2X_MSG_SP, "Polling usage counters\n");
1239 if (bnx2x_poll_hw_usage_counters(bp, poll_cnt))
1242 /* Zero the igu 'trailing edge' and 'leading edge' */
1244 /* Send the FW cleanup command */
1245 if (bnx2x_send_final_clnup(bp, (u8)BP_FUNC(bp), poll_cnt))
1250 /* Verify TX hw is flushed */
1251 bnx2x_tx_hw_flushed(bp, poll_cnt);
1253 /* Wait 100ms (not adjusted according to platform) */
1256 /* Verify no pending pci transactions */
1257 if (bnx2x_is_pcie_pending(bp->pdev))
1258 BNX2X_ERR("PCIE Transactions still pending\n");
1261 bnx2x_hw_enable_status(bp);
1264 * Master enable - Due to WB DMAE writes performed before this
1265 * register is re-initialized as part of the regular function init
1267 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
1272 static void bnx2x_hc_int_enable(struct bnx2x *bp)
1274 int port = BP_PORT(bp);
1275 u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
1276 u32 val = REG_RD(bp, addr);
1277 int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
1278 int msi = (bp->flags & USING_MSI_FLAG) ? 1 : 0;
1281 val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
1282 HC_CONFIG_0_REG_INT_LINE_EN_0);
1283 val |= (HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
1284 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
1286 val &= ~HC_CONFIG_0_REG_INT_LINE_EN_0;
1287 val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
1288 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
1289 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
1291 val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
1292 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
1293 HC_CONFIG_0_REG_INT_LINE_EN_0 |
1294 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
1296 if (!CHIP_IS_E1(bp)) {
1298 "write %x to HC %d (addr 0x%x)\n", val, port, addr);
1300 REG_WR(bp, addr, val);
1302 val &= ~HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0;
1307 REG_WR(bp, HC_REG_INT_MASK + port*4, 0x1FFFF);
1310 "write %x to HC %d (addr 0x%x) mode %s\n", val, port, addr,
1311 (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
1313 REG_WR(bp, addr, val);
1315 * Ensure that HC_CONFIG is written before leading/trailing edge config
1320 if (!CHIP_IS_E1(bp)) {
1321 /* init leading/trailing edge */
1323 val = (0xee0f | (1 << (BP_VN(bp) + 4)));
1325 /* enable nig and gpio3 attention */
1330 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
1331 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
1334 /* Make sure that interrupts are indeed enabled from here on */
1338 static void bnx2x_igu_int_enable(struct bnx2x *bp)
1341 int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
1342 int msi = (bp->flags & USING_MSI_FLAG) ? 1 : 0;
1344 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
1347 val &= ~(IGU_PF_CONF_INT_LINE_EN |
1348 IGU_PF_CONF_SINGLE_ISR_EN);
1349 val |= (IGU_PF_CONF_FUNC_EN |
1350 IGU_PF_CONF_MSI_MSIX_EN |
1351 IGU_PF_CONF_ATTN_BIT_EN);
1353 val &= ~IGU_PF_CONF_INT_LINE_EN;
1354 val |= (IGU_PF_CONF_FUNC_EN |
1355 IGU_PF_CONF_MSI_MSIX_EN |
1356 IGU_PF_CONF_ATTN_BIT_EN |
1357 IGU_PF_CONF_SINGLE_ISR_EN);
1359 val &= ~IGU_PF_CONF_MSI_MSIX_EN;
1360 val |= (IGU_PF_CONF_FUNC_EN |
1361 IGU_PF_CONF_INT_LINE_EN |
1362 IGU_PF_CONF_ATTN_BIT_EN |
1363 IGU_PF_CONF_SINGLE_ISR_EN);
1366 DP(NETIF_MSG_IFUP, "write 0x%x to IGU mode %s\n",
1367 val, (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
1369 REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
1373 /* init leading/trailing edge */
1375 val = (0xee0f | (1 << (BP_VN(bp) + 4)));
1377 /* enable nig and gpio3 attention */
1382 REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
1383 REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
1385 /* Make sure that interrupts are indeed enabled from here on */
1389 void bnx2x_int_enable(struct bnx2x *bp)
1391 if (bp->common.int_block == INT_BLOCK_HC)
1392 bnx2x_hc_int_enable(bp);
1394 bnx2x_igu_int_enable(bp);
1397 static void bnx2x_hc_int_disable(struct bnx2x *bp)
1399 int port = BP_PORT(bp);
1400 u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
1401 u32 val = REG_RD(bp, addr);
1404 * in E1 we must use only PCI configuration space to disable
1405 * MSI/MSIX capablility
1406 * It's forbitten to disable IGU_PF_CONF_MSI_MSIX_EN in HC block
1408 if (CHIP_IS_E1(bp)) {
1409 /* Since IGU_PF_CONF_MSI_MSIX_EN still always on
1410 * Use mask register to prevent from HC sending interrupts
1411 * after we exit the function
1413 REG_WR(bp, HC_REG_INT_MASK + port*4, 0);
1415 val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
1416 HC_CONFIG_0_REG_INT_LINE_EN_0 |
1417 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
1419 val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
1420 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
1421 HC_CONFIG_0_REG_INT_LINE_EN_0 |
1422 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
1424 DP(NETIF_MSG_IFDOWN,
1425 "write %x to HC %d (addr 0x%x)\n",
1428 /* flush all outstanding writes */
1431 REG_WR(bp, addr, val);
1432 if (REG_RD(bp, addr) != val)
1433 BNX2X_ERR("BUG! proper val not read from IGU!\n");
1436 static void bnx2x_igu_int_disable(struct bnx2x *bp)
1438 u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
1440 val &= ~(IGU_PF_CONF_MSI_MSIX_EN |
1441 IGU_PF_CONF_INT_LINE_EN |
1442 IGU_PF_CONF_ATTN_BIT_EN);
1444 DP(NETIF_MSG_IFDOWN, "write %x to IGU\n", val);
1446 /* flush all outstanding writes */
1449 REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
1450 if (REG_RD(bp, IGU_REG_PF_CONFIGURATION) != val)
1451 BNX2X_ERR("BUG! proper val not read from IGU!\n");
1454 void bnx2x_int_disable(struct bnx2x *bp)
1456 if (bp->common.int_block == INT_BLOCK_HC)
1457 bnx2x_hc_int_disable(bp);
1459 bnx2x_igu_int_disable(bp);
1462 void bnx2x_int_disable_sync(struct bnx2x *bp, int disable_hw)
1464 int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
1468 /* prevent the HW from sending interrupts */
1469 bnx2x_int_disable(bp);
1471 /* make sure all ISRs are done */
1473 synchronize_irq(bp->msix_table[0].vector);
1478 for_each_eth_queue(bp, i)
1479 synchronize_irq(bp->msix_table[offset++].vector);
1481 synchronize_irq(bp->pdev->irq);
1483 /* make sure sp_task is not running */
1484 cancel_delayed_work(&bp->sp_task);
1485 cancel_delayed_work(&bp->period_task);
1486 flush_workqueue(bnx2x_wq);
1492 * General service functions
1495 /* Return true if succeeded to acquire the lock */
1496 static bool bnx2x_trylock_hw_lock(struct bnx2x *bp, u32 resource)
1499 u32 resource_bit = (1 << resource);
1500 int func = BP_FUNC(bp);
1501 u32 hw_lock_control_reg;
1503 DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
1504 "Trying to take a lock on resource %d\n", resource);
1506 /* Validating that the resource is within range */
1507 if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
1508 DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
1509 "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
1510 resource, HW_LOCK_MAX_RESOURCE_VALUE);
1515 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
1517 hw_lock_control_reg =
1518 (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
1520 /* Try to acquire the lock */
1521 REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
1522 lock_status = REG_RD(bp, hw_lock_control_reg);
1523 if (lock_status & resource_bit)
1526 DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
1527 "Failed to get a lock on resource %d\n", resource);
1532 * bnx2x_get_leader_lock_resource - get the recovery leader resource id
1534 * @bp: driver handle
1536 * Returns the recovery leader resource id according to the engine this function
1537 * belongs to. Currently only only 2 engines is supported.
1539 static inline int bnx2x_get_leader_lock_resource(struct bnx2x *bp)
1542 return HW_LOCK_RESOURCE_RECOVERY_LEADER_1;
1544 return HW_LOCK_RESOURCE_RECOVERY_LEADER_0;
1548 * bnx2x_trylock_leader_lock- try to aquire a leader lock.
1550 * @bp: driver handle
1552 * Tries to aquire a leader lock for cuurent engine.
1554 static inline bool bnx2x_trylock_leader_lock(struct bnx2x *bp)
1556 return bnx2x_trylock_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
1560 static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err);
1563 void bnx2x_sp_event(struct bnx2x_fastpath *fp, union eth_rx_cqe *rr_cqe)
1565 struct bnx2x *bp = fp->bp;
1566 int cid = SW_CID(rr_cqe->ramrod_cqe.conn_and_cmd_data);
1567 int command = CQE_CMD(rr_cqe->ramrod_cqe.conn_and_cmd_data);
1568 enum bnx2x_queue_cmd drv_cmd = BNX2X_Q_CMD_MAX;
1569 struct bnx2x_queue_sp_obj *q_obj = &fp->q_obj;
1572 "fp %d cid %d got ramrod #%d state is %x type is %d\n",
1573 fp->index, cid, command, bp->state,
1574 rr_cqe->ramrod_cqe.ramrod_type);
1577 case (RAMROD_CMD_ID_ETH_CLIENT_UPDATE):
1578 DP(BNX2X_MSG_SP, "got UPDATE ramrod. CID %d\n", cid);
1579 drv_cmd = BNX2X_Q_CMD_UPDATE;
1582 case (RAMROD_CMD_ID_ETH_CLIENT_SETUP):
1583 DP(BNX2X_MSG_SP, "got MULTI[%d] setup ramrod\n", cid);
1584 drv_cmd = BNX2X_Q_CMD_SETUP;
1587 case (RAMROD_CMD_ID_ETH_TX_QUEUE_SETUP):
1588 DP(BNX2X_MSG_SP, "got MULTI[%d] tx-only setup ramrod\n", cid);
1589 drv_cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
1592 case (RAMROD_CMD_ID_ETH_HALT):
1593 DP(BNX2X_MSG_SP, "got MULTI[%d] halt ramrod\n", cid);
1594 drv_cmd = BNX2X_Q_CMD_HALT;
1597 case (RAMROD_CMD_ID_ETH_TERMINATE):
1598 DP(BNX2X_MSG_SP, "got MULTI[%d] teminate ramrod\n", cid);
1599 drv_cmd = BNX2X_Q_CMD_TERMINATE;
1602 case (RAMROD_CMD_ID_ETH_EMPTY):
1603 DP(BNX2X_MSG_SP, "got MULTI[%d] empty ramrod\n", cid);
1604 drv_cmd = BNX2X_Q_CMD_EMPTY;
1608 BNX2X_ERR("unexpected MC reply (%d) on fp[%d]\n",
1609 command, fp->index);
1613 if ((drv_cmd != BNX2X_Q_CMD_MAX) &&
1614 q_obj->complete_cmd(bp, q_obj, drv_cmd))
1615 /* q_obj->complete_cmd() failure means that this was
1616 * an unexpected completion.
1618 * In this case we don't want to increase the bp->spq_left
1619 * because apparently we haven't sent this command the first
1622 #ifdef BNX2X_STOP_ON_ERROR
1628 smp_mb__before_atomic_inc();
1629 atomic_inc(&bp->cq_spq_left);
1630 /* push the change in bp->spq_left and towards the memory */
1631 smp_mb__after_atomic_inc();
1633 DP(BNX2X_MSG_SP, "bp->cq_spq_left %x\n", atomic_read(&bp->cq_spq_left));
1638 void bnx2x_update_rx_prod(struct bnx2x *bp, struct bnx2x_fastpath *fp,
1639 u16 bd_prod, u16 rx_comp_prod, u16 rx_sge_prod)
1641 u32 start = BAR_USTRORM_INTMEM + fp->ustorm_rx_prods_offset;
1643 bnx2x_update_rx_prod_gen(bp, fp, bd_prod, rx_comp_prod, rx_sge_prod,
1647 irqreturn_t bnx2x_interrupt(int irq, void *dev_instance)
1649 struct bnx2x *bp = netdev_priv(dev_instance);
1650 u16 status = bnx2x_ack_int(bp);
1655 /* Return here if interrupt is shared and it's not for us */
1656 if (unlikely(status == 0)) {
1657 DP(NETIF_MSG_INTR, "not our interrupt!\n");
1660 DP(NETIF_MSG_INTR, "got an interrupt status 0x%x\n", status);
1662 #ifdef BNX2X_STOP_ON_ERROR
1663 if (unlikely(bp->panic))
1667 for_each_eth_queue(bp, i) {
1668 struct bnx2x_fastpath *fp = &bp->fp[i];
1670 mask = 0x2 << (fp->index + CNIC_PRESENT);
1671 if (status & mask) {
1672 /* Handle Rx or Tx according to SB id */
1673 prefetch(fp->rx_cons_sb);
1674 for_each_cos_in_tx_queue(fp, cos)
1675 prefetch(fp->txdata[cos].tx_cons_sb);
1676 prefetch(&fp->sb_running_index[SM_RX_ID]);
1677 napi_schedule(&bnx2x_fp(bp, fp->index, napi));
1684 if (status & (mask | 0x1)) {
1685 struct cnic_ops *c_ops = NULL;
1687 if (likely(bp->state == BNX2X_STATE_OPEN)) {
1689 c_ops = rcu_dereference(bp->cnic_ops);
1691 c_ops->cnic_handler(bp->cnic_data, NULL);
1699 if (unlikely(status & 0x1)) {
1700 queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
1707 if (unlikely(status))
1708 DP(NETIF_MSG_INTR, "got an unknown interrupt! (status 0x%x)\n",
1717 * General service functions
1720 int bnx2x_acquire_hw_lock(struct bnx2x *bp, u32 resource)
1723 u32 resource_bit = (1 << resource);
1724 int func = BP_FUNC(bp);
1725 u32 hw_lock_control_reg;
1728 /* Validating that the resource is within range */
1729 if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
1730 BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
1731 resource, HW_LOCK_MAX_RESOURCE_VALUE);
1736 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
1738 hw_lock_control_reg =
1739 (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
1742 /* Validating that the resource is not already taken */
1743 lock_status = REG_RD(bp, hw_lock_control_reg);
1744 if (lock_status & resource_bit) {
1745 BNX2X_ERR("lock_status 0x%x resource_bit 0x%x\n",
1746 lock_status, resource_bit);
1750 /* Try for 5 second every 5ms */
1751 for (cnt = 0; cnt < 1000; cnt++) {
1752 /* Try to acquire the lock */
1753 REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
1754 lock_status = REG_RD(bp, hw_lock_control_reg);
1755 if (lock_status & resource_bit)
1760 BNX2X_ERR("Timeout\n");
1764 int bnx2x_release_leader_lock(struct bnx2x *bp)
1766 return bnx2x_release_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
1769 int bnx2x_release_hw_lock(struct bnx2x *bp, u32 resource)
1772 u32 resource_bit = (1 << resource);
1773 int func = BP_FUNC(bp);
1774 u32 hw_lock_control_reg;
1776 /* Validating that the resource is within range */
1777 if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
1778 BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
1779 resource, HW_LOCK_MAX_RESOURCE_VALUE);
1784 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
1786 hw_lock_control_reg =
1787 (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
1790 /* Validating that the resource is currently taken */
1791 lock_status = REG_RD(bp, hw_lock_control_reg);
1792 if (!(lock_status & resource_bit)) {
1793 BNX2X_ERR("lock_status 0x%x resource_bit 0x%x. unlock was called but lock wasn't taken!\n",
1794 lock_status, resource_bit);
1798 REG_WR(bp, hw_lock_control_reg, resource_bit);
1803 int bnx2x_get_gpio(struct bnx2x *bp, int gpio_num, u8 port)
1805 /* The GPIO should be swapped if swap register is set and active */
1806 int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
1807 REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
1808 int gpio_shift = gpio_num +
1809 (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
1810 u32 gpio_mask = (1 << gpio_shift);
1814 if (gpio_num > MISC_REGISTERS_GPIO_3) {
1815 BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
1819 /* read GPIO value */
1820 gpio_reg = REG_RD(bp, MISC_REG_GPIO);
1822 /* get the requested pin value */
1823 if ((gpio_reg & gpio_mask) == gpio_mask)
1828 DP(NETIF_MSG_LINK, "pin %d value 0x%x\n", gpio_num, value);
1833 int bnx2x_set_gpio(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
1835 /* The GPIO should be swapped if swap register is set and active */
1836 int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
1837 REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
1838 int gpio_shift = gpio_num +
1839 (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
1840 u32 gpio_mask = (1 << gpio_shift);
1843 if (gpio_num > MISC_REGISTERS_GPIO_3) {
1844 BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
1848 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
1849 /* read GPIO and mask except the float bits */
1850 gpio_reg = (REG_RD(bp, MISC_REG_GPIO) & MISC_REGISTERS_GPIO_FLOAT);
1853 case MISC_REGISTERS_GPIO_OUTPUT_LOW:
1855 "Set GPIO %d (shift %d) -> output low\n",
1856 gpio_num, gpio_shift);
1857 /* clear FLOAT and set CLR */
1858 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
1859 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_CLR_POS);
1862 case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
1864 "Set GPIO %d (shift %d) -> output high\n",
1865 gpio_num, gpio_shift);
1866 /* clear FLOAT and set SET */
1867 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
1868 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_SET_POS);
1871 case MISC_REGISTERS_GPIO_INPUT_HI_Z:
1873 "Set GPIO %d (shift %d) -> input\n",
1874 gpio_num, gpio_shift);
1876 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
1883 REG_WR(bp, MISC_REG_GPIO, gpio_reg);
1884 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
1889 int bnx2x_set_mult_gpio(struct bnx2x *bp, u8 pins, u32 mode)
1894 /* Any port swapping should be handled by caller. */
1896 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
1897 /* read GPIO and mask except the float bits */
1898 gpio_reg = REG_RD(bp, MISC_REG_GPIO);
1899 gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_FLOAT_POS);
1900 gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_CLR_POS);
1901 gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_SET_POS);
1904 case MISC_REGISTERS_GPIO_OUTPUT_LOW:
1905 DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output low\n", pins);
1907 gpio_reg |= (pins << MISC_REGISTERS_GPIO_CLR_POS);
1910 case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
1911 DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output high\n", pins);
1913 gpio_reg |= (pins << MISC_REGISTERS_GPIO_SET_POS);
1916 case MISC_REGISTERS_GPIO_INPUT_HI_Z:
1917 DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> input\n", pins);
1919 gpio_reg |= (pins << MISC_REGISTERS_GPIO_FLOAT_POS);
1923 BNX2X_ERR("Invalid GPIO mode assignment %d\n", mode);
1929 REG_WR(bp, MISC_REG_GPIO, gpio_reg);
1931 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
1936 int bnx2x_set_gpio_int(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
1938 /* The GPIO should be swapped if swap register is set and active */
1939 int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
1940 REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
1941 int gpio_shift = gpio_num +
1942 (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
1943 u32 gpio_mask = (1 << gpio_shift);
1946 if (gpio_num > MISC_REGISTERS_GPIO_3) {
1947 BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
1951 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
1953 gpio_reg = REG_RD(bp, MISC_REG_GPIO_INT);
1956 case MISC_REGISTERS_GPIO_INT_OUTPUT_CLR:
1958 "Clear GPIO INT %d (shift %d) -> output low\n",
1959 gpio_num, gpio_shift);
1960 /* clear SET and set CLR */
1961 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
1962 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
1965 case MISC_REGISTERS_GPIO_INT_OUTPUT_SET:
1967 "Set GPIO INT %d (shift %d) -> output high\n",
1968 gpio_num, gpio_shift);
1969 /* clear CLR and set SET */
1970 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
1971 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
1978 REG_WR(bp, MISC_REG_GPIO_INT, gpio_reg);
1979 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
1984 static int bnx2x_set_spio(struct bnx2x *bp, int spio_num, u32 mode)
1986 u32 spio_mask = (1 << spio_num);
1989 if ((spio_num < MISC_REGISTERS_SPIO_4) ||
1990 (spio_num > MISC_REGISTERS_SPIO_7)) {
1991 BNX2X_ERR("Invalid SPIO %d\n", spio_num);
1995 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
1996 /* read SPIO and mask except the float bits */
1997 spio_reg = (REG_RD(bp, MISC_REG_SPIO) & MISC_REGISTERS_SPIO_FLOAT);
2000 case MISC_REGISTERS_SPIO_OUTPUT_LOW:
2001 DP(NETIF_MSG_HW, "Set SPIO %d -> output low\n", spio_num);
2002 /* clear FLOAT and set CLR */
2003 spio_reg &= ~(spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS);
2004 spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_CLR_POS);
2007 case MISC_REGISTERS_SPIO_OUTPUT_HIGH:
2008 DP(NETIF_MSG_HW, "Set SPIO %d -> output high\n", spio_num);
2009 /* clear FLOAT and set SET */
2010 spio_reg &= ~(spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS);
2011 spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_SET_POS);
2014 case MISC_REGISTERS_SPIO_INPUT_HI_Z:
2015 DP(NETIF_MSG_HW, "Set SPIO %d -> input\n", spio_num);
2017 spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS);
2024 REG_WR(bp, MISC_REG_SPIO, spio_reg);
2025 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
2030 void bnx2x_calc_fc_adv(struct bnx2x *bp)
2032 u8 cfg_idx = bnx2x_get_link_cfg_idx(bp);
2033 switch (bp->link_vars.ieee_fc &
2034 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK) {
2035 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE:
2036 bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
2040 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH:
2041 bp->port.advertising[cfg_idx] |= (ADVERTISED_Asym_Pause |
2045 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC:
2046 bp->port.advertising[cfg_idx] |= ADVERTISED_Asym_Pause;
2050 bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
2056 u8 bnx2x_initial_phy_init(struct bnx2x *bp, int load_mode)
2058 if (!BP_NOMCP(bp)) {
2060 int cfx_idx = bnx2x_get_link_cfg_idx(bp);
2061 u16 req_line_speed = bp->link_params.req_line_speed[cfx_idx];
2063 * Initialize link parameters structure variables
2064 * It is recommended to turn off RX FC for jumbo frames
2065 * for better performance
2067 if (CHIP_IS_E1x(bp) && (bp->dev->mtu > 5000))
2068 bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_TX;
2070 bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_BOTH;
2072 bnx2x_acquire_phy_lock(bp);
2074 if (load_mode == LOAD_DIAG) {
2075 struct link_params *lp = &bp->link_params;
2076 lp->loopback_mode = LOOPBACK_XGXS;
2077 /* do PHY loopback at 10G speed, if possible */
2078 if (lp->req_line_speed[cfx_idx] < SPEED_10000) {
2079 if (lp->speed_cap_mask[cfx_idx] &
2080 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
2081 lp->req_line_speed[cfx_idx] =
2084 lp->req_line_speed[cfx_idx] =
2089 rc = bnx2x_phy_init(&bp->link_params, &bp->link_vars);
2091 bnx2x_release_phy_lock(bp);
2093 bnx2x_calc_fc_adv(bp);
2095 if (CHIP_REV_IS_SLOW(bp) && bp->link_vars.link_up) {
2096 bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
2097 bnx2x_link_report(bp);
2099 queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
2100 bp->link_params.req_line_speed[cfx_idx] = req_line_speed;
2103 BNX2X_ERR("Bootcode is missing - can not initialize link\n");
2107 void bnx2x_link_set(struct bnx2x *bp)
2109 if (!BP_NOMCP(bp)) {
2110 bnx2x_acquire_phy_lock(bp);
2111 bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
2112 bnx2x_phy_init(&bp->link_params, &bp->link_vars);
2113 bnx2x_release_phy_lock(bp);
2115 bnx2x_calc_fc_adv(bp);
2117 BNX2X_ERR("Bootcode is missing - can not set link\n");
2120 static void bnx2x__link_reset(struct bnx2x *bp)
2122 if (!BP_NOMCP(bp)) {
2123 bnx2x_acquire_phy_lock(bp);
2124 bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
2125 bnx2x_release_phy_lock(bp);
2127 BNX2X_ERR("Bootcode is missing - can not reset link\n");
2130 u8 bnx2x_link_test(struct bnx2x *bp, u8 is_serdes)
2134 if (!BP_NOMCP(bp)) {
2135 bnx2x_acquire_phy_lock(bp);
2136 rc = bnx2x_test_link(&bp->link_params, &bp->link_vars,
2138 bnx2x_release_phy_lock(bp);
2140 BNX2X_ERR("Bootcode is missing - can not test link\n");
2145 static void bnx2x_init_port_minmax(struct bnx2x *bp)
2147 u32 r_param = bp->link_vars.line_speed / 8;
2148 u32 fair_periodic_timeout_usec;
2151 memset(&(bp->cmng.rs_vars), 0,
2152 sizeof(struct rate_shaping_vars_per_port));
2153 memset(&(bp->cmng.fair_vars), 0, sizeof(struct fairness_vars_per_port));
2155 /* 100 usec in SDM ticks = 25 since each tick is 4 usec */
2156 bp->cmng.rs_vars.rs_periodic_timeout = RS_PERIODIC_TIMEOUT_USEC / 4;
2158 /* this is the threshold below which no timer arming will occur
2159 1.25 coefficient is for the threshold to be a little bigger
2160 than the real time, to compensate for timer in-accuracy */
2161 bp->cmng.rs_vars.rs_threshold =
2162 (RS_PERIODIC_TIMEOUT_USEC * r_param * 5) / 4;
2164 /* resolution of fairness timer */
2165 fair_periodic_timeout_usec = QM_ARB_BYTES / r_param;
2166 /* for 10G it is 1000usec. for 1G it is 10000usec. */
2167 t_fair = T_FAIR_COEF / bp->link_vars.line_speed;
2169 /* this is the threshold below which we won't arm the timer anymore */
2170 bp->cmng.fair_vars.fair_threshold = QM_ARB_BYTES;
2172 /* we multiply by 1e3/8 to get bytes/msec.
2173 We don't want the credits to pass a credit
2174 of the t_fair*FAIR_MEM (algorithm resolution) */
2175 bp->cmng.fair_vars.upper_bound = r_param * t_fair * FAIR_MEM;
2176 /* since each tick is 4 usec */
2177 bp->cmng.fair_vars.fairness_timeout = fair_periodic_timeout_usec / 4;
2180 /* Calculates the sum of vn_min_rates.
2181 It's needed for further normalizing of the min_rates.
2183 sum of vn_min_rates.
2185 0 - if all the min_rates are 0.
2186 In the later case fainess algorithm should be deactivated.
2187 If not all min_rates are zero then those that are zeroes will be set to 1.
2189 static void bnx2x_calc_vn_weight_sum(struct bnx2x *bp)
2194 bp->vn_weight_sum = 0;
2195 for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
2196 u32 vn_cfg = bp->mf_config[vn];
2197 u32 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
2198 FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
2200 /* Skip hidden vns */
2201 if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
2204 /* If min rate is zero - set it to 1 */
2206 vn_min_rate = DEF_MIN_RATE;
2210 bp->vn_weight_sum += vn_min_rate;
2213 /* if ETS or all min rates are zeros - disable fairness */
2214 if (BNX2X_IS_ETS_ENABLED(bp)) {
2215 bp->cmng.flags.cmng_enables &=
2216 ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
2217 DP(NETIF_MSG_IFUP, "Fairness will be disabled due to ETS\n");
2218 } else if (all_zero) {
2219 bp->cmng.flags.cmng_enables &=
2220 ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
2221 DP(NETIF_MSG_IFUP, "All MIN values are zeroes"
2222 " fairness will be disabled\n");
2224 bp->cmng.flags.cmng_enables |=
2225 CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
2228 static void bnx2x_init_vn_minmax(struct bnx2x *bp, int vn)
2230 struct rate_shaping_vars_per_vn m_rs_vn;
2231 struct fairness_vars_per_vn m_fair_vn;
2232 u32 vn_cfg = bp->mf_config[vn];
2233 int func = func_by_vn(bp, vn);
2234 u16 vn_min_rate, vn_max_rate;
2237 /* If function is hidden - set min and max to zeroes */
2238 if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE) {
2243 u32 maxCfg = bnx2x_extract_max_cfg(bp, vn_cfg);
2245 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
2246 FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
2247 /* If fairness is enabled (not all min rates are zeroes) and
2248 if current min rate is zero - set it to 1.
2249 This is a requirement of the algorithm. */
2250 if (bp->vn_weight_sum && (vn_min_rate == 0))
2251 vn_min_rate = DEF_MIN_RATE;
2254 /* maxCfg in percents of linkspeed */
2255 vn_max_rate = (bp->link_vars.line_speed * maxCfg) / 100;
2257 /* maxCfg is absolute in 100Mb units */
2258 vn_max_rate = maxCfg * 100;
2262 "func %d: vn_min_rate %d vn_max_rate %d vn_weight_sum %d\n",
2263 func, vn_min_rate, vn_max_rate, bp->vn_weight_sum);
2265 memset(&m_rs_vn, 0, sizeof(struct rate_shaping_vars_per_vn));
2266 memset(&m_fair_vn, 0, sizeof(struct fairness_vars_per_vn));
2268 /* global vn counter - maximal Mbps for this vn */
2269 m_rs_vn.vn_counter.rate = vn_max_rate;
2271 /* quota - number of bytes transmitted in this period */
2272 m_rs_vn.vn_counter.quota =
2273 (vn_max_rate * RS_PERIODIC_TIMEOUT_USEC) / 8;
2275 if (bp->vn_weight_sum) {
2276 /* credit for each period of the fairness algorithm:
2277 number of bytes in T_FAIR (the vn share the port rate).
2278 vn_weight_sum should not be larger than 10000, thus
2279 T_FAIR_COEF / (8 * vn_weight_sum) will always be greater
2281 m_fair_vn.vn_credit_delta =
2282 max_t(u32, (vn_min_rate * (T_FAIR_COEF /
2283 (8 * bp->vn_weight_sum))),
2284 (bp->cmng.fair_vars.fair_threshold +
2286 DP(NETIF_MSG_IFUP, "m_fair_vn.vn_credit_delta %d\n",
2287 m_fair_vn.vn_credit_delta);
2290 /* Store it to internal memory */
2291 for (i = 0; i < sizeof(struct rate_shaping_vars_per_vn)/4; i++)
2292 REG_WR(bp, BAR_XSTRORM_INTMEM +
2293 XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(func) + i * 4,
2294 ((u32 *)(&m_rs_vn))[i]);
2296 for (i = 0; i < sizeof(struct fairness_vars_per_vn)/4; i++)
2297 REG_WR(bp, BAR_XSTRORM_INTMEM +
2298 XSTORM_FAIRNESS_PER_VN_VARS_OFFSET(func) + i * 4,
2299 ((u32 *)(&m_fair_vn))[i]);
2302 static int bnx2x_get_cmng_fns_mode(struct bnx2x *bp)
2304 if (CHIP_REV_IS_SLOW(bp))
2305 return CMNG_FNS_NONE;
2307 return CMNG_FNS_MINMAX;
2309 return CMNG_FNS_NONE;
2312 void bnx2x_read_mf_cfg(struct bnx2x *bp)
2314 int vn, n = (CHIP_MODE_IS_4_PORT(bp) ? 2 : 1);
2317 return; /* what should be the default bvalue in this case */
2319 /* For 2 port configuration the absolute function number formula
2321 * abs_func = 2 * vn + BP_PORT + BP_PATH
2323 * and there are 4 functions per port
2325 * For 4 port configuration it is
2326 * abs_func = 4 * vn + 2 * BP_PORT + BP_PATH
2328 * and there are 2 functions per port
2330 for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
2331 int /*abs*/func = n * (2 * vn + BP_PORT(bp)) + BP_PATH(bp);
2333 if (func >= E1H_FUNC_MAX)
2337 MF_CFG_RD(bp, func_mf_config[func].config);
2341 static void bnx2x_cmng_fns_init(struct bnx2x *bp, u8 read_cfg, u8 cmng_type)
2344 if (cmng_type == CMNG_FNS_MINMAX) {
2347 /* clear cmng_enables */
2348 bp->cmng.flags.cmng_enables = 0;
2350 /* read mf conf from shmem */
2352 bnx2x_read_mf_cfg(bp);
2354 /* Init rate shaping and fairness contexts */
2355 bnx2x_init_port_minmax(bp);
2357 /* vn_weight_sum and enable fairness if not 0 */
2358 bnx2x_calc_vn_weight_sum(bp);
2360 /* calculate and set min-max rate for each vn */
2362 for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++)
2363 bnx2x_init_vn_minmax(bp, vn);
2365 /* always enable rate shaping and fairness */
2366 bp->cmng.flags.cmng_enables |=
2367 CMNG_FLAGS_PER_PORT_RATE_SHAPING_VN;
2368 if (!bp->vn_weight_sum)
2369 DP(NETIF_MSG_IFUP, "All MIN values are zeroes"
2370 " fairness will be disabled\n");
2374 /* rate shaping and fairness are disabled */
2376 "rate shaping and fairness are disabled\n");
2379 /* This function is called upon link interrupt */
2380 static void bnx2x_link_attn(struct bnx2x *bp)
2382 /* Make sure that we are synced with the current statistics */
2383 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
2385 bnx2x_link_update(&bp->link_params, &bp->link_vars);
2387 if (bp->link_vars.link_up) {
2389 /* dropless flow control */
2390 if (!CHIP_IS_E1(bp) && bp->dropless_fc) {
2391 int port = BP_PORT(bp);
2392 u32 pause_enabled = 0;
2394 if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX)
2397 REG_WR(bp, BAR_USTRORM_INTMEM +
2398 USTORM_ETH_PAUSE_ENABLED_OFFSET(port),
2402 if (bp->link_vars.mac_type != MAC_TYPE_EMAC) {
2403 struct host_port_stats *pstats;
2405 pstats = bnx2x_sp(bp, port_stats);
2406 /* reset old mac stats */
2407 memset(&(pstats->mac_stx[0]), 0,
2408 sizeof(struct mac_stx));
2410 if (bp->state == BNX2X_STATE_OPEN)
2411 bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
2414 if (bp->link_vars.link_up && bp->link_vars.line_speed) {
2415 int cmng_fns = bnx2x_get_cmng_fns_mode(bp);
2417 if (cmng_fns != CMNG_FNS_NONE) {
2418 bnx2x_cmng_fns_init(bp, false, cmng_fns);
2419 storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
2421 /* rate shaping and fairness are disabled */
2423 "single function mode without fairness\n");
2426 __bnx2x_link_report(bp);
2429 bnx2x_link_sync_notify(bp);
2432 void bnx2x__link_status_update(struct bnx2x *bp)
2434 if (bp->state != BNX2X_STATE_OPEN)
2437 /* read updated dcb configuration */
2438 bnx2x_dcbx_pmf_update(bp);
2440 bnx2x_link_status_update(&bp->link_params, &bp->link_vars);
2442 if (bp->link_vars.link_up)
2443 bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
2445 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
2447 /* indicate link status */
2448 bnx2x_link_report(bp);
2451 static void bnx2x_pmf_update(struct bnx2x *bp)
2453 int port = BP_PORT(bp);
2457 DP(BNX2X_MSG_MCP, "pmf %d\n", bp->port.pmf);
2460 * We need the mb() to ensure the ordering between the writing to
2461 * bp->port.pmf here and reading it from the bnx2x_periodic_task().
2465 /* queue a periodic task */
2466 queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
2468 bnx2x_dcbx_pmf_update(bp);
2470 /* enable nig attention */
2471 val = (0xff0f | (1 << (BP_VN(bp) + 4)));
2472 if (bp->common.int_block == INT_BLOCK_HC) {
2473 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
2474 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
2475 } else if (!CHIP_IS_E1x(bp)) {
2476 REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
2477 REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
2480 bnx2x_stats_handle(bp, STATS_EVENT_PMF);
2488 * General service functions
2491 /* send the MCP a request, block until there is a reply */
2492 u32 bnx2x_fw_command(struct bnx2x *bp, u32 command, u32 param)
2494 int mb_idx = BP_FW_MB_IDX(bp);
2498 u8 delay = CHIP_REV_IS_SLOW(bp) ? 100 : 10;
2500 mutex_lock(&bp->fw_mb_mutex);
2502 SHMEM_WR(bp, func_mb[mb_idx].drv_mb_param, param);
2503 SHMEM_WR(bp, func_mb[mb_idx].drv_mb_header, (command | seq));
2505 DP(BNX2X_MSG_MCP, "wrote command (%x) to FW MB param 0x%08x\n",
2506 (command | seq), param);
2509 /* let the FW do it's magic ... */
2512 rc = SHMEM_RD(bp, func_mb[mb_idx].fw_mb_header);
2514 /* Give the FW up to 5 second (500*10ms) */
2515 } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 500));
2517 DP(BNX2X_MSG_MCP, "[after %d ms] read (%x) seq is (%x) from FW MB\n",
2518 cnt*delay, rc, seq);
2520 /* is this a reply to our command? */
2521 if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK))
2522 rc &= FW_MSG_CODE_MASK;
2525 BNX2X_ERR("FW failed to respond!\n");
2529 mutex_unlock(&bp->fw_mb_mutex);
2535 void bnx2x_func_init(struct bnx2x *bp, struct bnx2x_func_init_params *p)
2537 if (CHIP_IS_E1x(bp)) {
2538 struct tstorm_eth_function_common_config tcfg = {0};
2540 storm_memset_func_cfg(bp, &tcfg, p->func_id);
2543 /* Enable the function in the FW */
2544 storm_memset_vf_to_pf(bp, p->func_id, p->pf_id);
2545 storm_memset_func_en(bp, p->func_id, 1);
2548 if (p->func_flgs & FUNC_FLG_SPQ) {
2549 storm_memset_spq_addr(bp, p->spq_map, p->func_id);
2550 REG_WR(bp, XSEM_REG_FAST_MEMORY +
2551 XSTORM_SPQ_PROD_OFFSET(p->func_id), p->spq_prod);
2556 * bnx2x_get_tx_only_flags - Return common flags
2560 * @zero_stats TRUE if statistics zeroing is needed
2562 * Return the flags that are common for the Tx-only and not normal connections.
2564 static inline unsigned long bnx2x_get_common_flags(struct bnx2x *bp,
2565 struct bnx2x_fastpath *fp,
2568 unsigned long flags = 0;
2570 /* PF driver will always initialize the Queue to an ACTIVE state */
2571 __set_bit(BNX2X_Q_FLG_ACTIVE, &flags);
2573 /* tx only connections collect statistics (on the same index as the
2574 * parent connection). The statistics are zeroed when the parent
2575 * connection is initialized.
2578 __set_bit(BNX2X_Q_FLG_STATS, &flags);
2580 __set_bit(BNX2X_Q_FLG_ZERO_STATS, &flags);
2586 static inline unsigned long bnx2x_get_q_flags(struct bnx2x *bp,
2587 struct bnx2x_fastpath *fp,
2590 unsigned long flags = 0;
2592 /* calculate other queue flags */
2594 __set_bit(BNX2X_Q_FLG_OV, &flags);
2597 __set_bit(BNX2X_Q_FLG_FCOE, &flags);
2599 if (!fp->disable_tpa) {
2600 __set_bit(BNX2X_Q_FLG_TPA, &flags);
2601 __set_bit(BNX2X_Q_FLG_TPA_IPV6, &flags);
2602 if (fp->mode == TPA_MODE_GRO)
2603 __set_bit(BNX2X_Q_FLG_TPA_GRO, &flags);
2607 __set_bit(BNX2X_Q_FLG_LEADING_RSS, &flags);
2608 __set_bit(BNX2X_Q_FLG_MCAST, &flags);
2611 /* Always set HW VLAN stripping */
2612 __set_bit(BNX2X_Q_FLG_VLAN, &flags);
2615 return flags | bnx2x_get_common_flags(bp, fp, true);
2618 static void bnx2x_pf_q_prep_general(struct bnx2x *bp,
2619 struct bnx2x_fastpath *fp, struct bnx2x_general_setup_params *gen_init,
2622 gen_init->stat_id = bnx2x_stats_id(fp);
2623 gen_init->spcl_id = fp->cl_id;
2625 /* Always use mini-jumbo MTU for FCoE L2 ring */
2627 gen_init->mtu = BNX2X_FCOE_MINI_JUMBO_MTU;
2629 gen_init->mtu = bp->dev->mtu;
2631 gen_init->cos = cos;
2634 static void bnx2x_pf_rx_q_prep(struct bnx2x *bp,
2635 struct bnx2x_fastpath *fp, struct rxq_pause_params *pause,
2636 struct bnx2x_rxq_setup_params *rxq_init)
2640 u16 tpa_agg_size = 0;
2642 if (!fp->disable_tpa) {
2643 pause->sge_th_lo = SGE_TH_LO(bp);
2644 pause->sge_th_hi = SGE_TH_HI(bp);
2646 /* validate SGE ring has enough to cross high threshold */
2647 WARN_ON(bp->dropless_fc &&
2648 pause->sge_th_hi + FW_PREFETCH_CNT >
2649 MAX_RX_SGE_CNT * NUM_RX_SGE_PAGES);
2651 tpa_agg_size = min_t(u32,
2652 (min_t(u32, 8, MAX_SKB_FRAGS) *
2653 SGE_PAGE_SIZE * PAGES_PER_SGE), 0xffff);
2654 max_sge = SGE_PAGE_ALIGN(bp->dev->mtu) >>
2656 max_sge = ((max_sge + PAGES_PER_SGE - 1) &
2657 (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
2658 sge_sz = (u16)min_t(u32, SGE_PAGE_SIZE * PAGES_PER_SGE,
2662 /* pause - not for e1 */
2663 if (!CHIP_IS_E1(bp)) {
2664 pause->bd_th_lo = BD_TH_LO(bp);
2665 pause->bd_th_hi = BD_TH_HI(bp);
2667 pause->rcq_th_lo = RCQ_TH_LO(bp);
2668 pause->rcq_th_hi = RCQ_TH_HI(bp);
2670 * validate that rings have enough entries to cross
2673 WARN_ON(bp->dropless_fc &&
2674 pause->bd_th_hi + FW_PREFETCH_CNT >
2676 WARN_ON(bp->dropless_fc &&
2677 pause->rcq_th_hi + FW_PREFETCH_CNT >
2678 NUM_RCQ_RINGS * MAX_RCQ_DESC_CNT);
2684 rxq_init->dscr_map = fp->rx_desc_mapping;
2685 rxq_init->sge_map = fp->rx_sge_mapping;
2686 rxq_init->rcq_map = fp->rx_comp_mapping;
2687 rxq_init->rcq_np_map = fp->rx_comp_mapping + BCM_PAGE_SIZE;
2689 /* This should be a maximum number of data bytes that may be
2690 * placed on the BD (not including paddings).
2692 rxq_init->buf_sz = fp->rx_buf_size - BNX2X_FW_RX_ALIGN_START -
2693 BNX2X_FW_RX_ALIGN_END - IP_HEADER_ALIGNMENT_PADDING;
2695 rxq_init->cl_qzone_id = fp->cl_qzone_id;
2696 rxq_init->tpa_agg_sz = tpa_agg_size;
2697 rxq_init->sge_buf_sz = sge_sz;
2698 rxq_init->max_sges_pkt = max_sge;
2699 rxq_init->rss_engine_id = BP_FUNC(bp);
2700 rxq_init->mcast_engine_id = BP_FUNC(bp);
2702 /* Maximum number or simultaneous TPA aggregation for this Queue.
2704 * For PF Clients it should be the maximum avaliable number.
2705 * VF driver(s) may want to define it to a smaller value.
2707 rxq_init->max_tpa_queues = MAX_AGG_QS(bp);
2709 rxq_init->cache_line_log = BNX2X_RX_ALIGN_SHIFT;
2710 rxq_init->fw_sb_id = fp->fw_sb_id;
2713 rxq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_RX_CQ_CONS;
2715 rxq_init->sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
2718 static void bnx2x_pf_tx_q_prep(struct bnx2x *bp,
2719 struct bnx2x_fastpath *fp, struct bnx2x_txq_setup_params *txq_init,
2722 txq_init->dscr_map = fp->txdata[cos].tx_desc_mapping;
2723 txq_init->sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS + cos;
2724 txq_init->traffic_type = LLFC_TRAFFIC_TYPE_NW;
2725 txq_init->fw_sb_id = fp->fw_sb_id;
2728 * set the tss leading client id for TX classfication ==
2729 * leading RSS client id
2731 txq_init->tss_leading_cl_id = bnx2x_fp(bp, 0, cl_id);
2733 if (IS_FCOE_FP(fp)) {
2734 txq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_TX_CQ_CONS;
2735 txq_init->traffic_type = LLFC_TRAFFIC_TYPE_FCOE;
2739 static void bnx2x_pf_init(struct bnx2x *bp)
2741 struct bnx2x_func_init_params func_init = {0};
2742 struct event_ring_data eq_data = { {0} };
2745 if (!CHIP_IS_E1x(bp)) {
2746 /* reset IGU PF statistics: MSIX + ATTN */
2748 REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
2749 BNX2X_IGU_STAS_MSG_VF_CNT*4 +
2750 (CHIP_MODE_IS_4_PORT(bp) ?
2751 BP_FUNC(bp) : BP_VN(bp))*4, 0);
2753 REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
2754 BNX2X_IGU_STAS_MSG_VF_CNT*4 +
2755 BNX2X_IGU_STAS_MSG_PF_CNT*4 +
2756 (CHIP_MODE_IS_4_PORT(bp) ?
2757 BP_FUNC(bp) : BP_VN(bp))*4, 0);
2760 /* function setup flags */
2761 flags = (FUNC_FLG_STATS | FUNC_FLG_LEADING | FUNC_FLG_SPQ);
2763 /* This flag is relevant for E1x only.
2764 * E2 doesn't have a TPA configuration in a function level.
2766 flags |= (bp->flags & TPA_ENABLE_FLAG) ? FUNC_FLG_TPA : 0;
2768 func_init.func_flgs = flags;
2769 func_init.pf_id = BP_FUNC(bp);
2770 func_init.func_id = BP_FUNC(bp);
2771 func_init.spq_map = bp->spq_mapping;
2772 func_init.spq_prod = bp->spq_prod_idx;
2774 bnx2x_func_init(bp, &func_init);
2776 memset(&(bp->cmng), 0, sizeof(struct cmng_struct_per_port));
2779 * Congestion management values depend on the link rate
2780 * There is no active link so initial link rate is set to 10 Gbps.
2781 * When the link comes up The congestion management values are
2782 * re-calculated according to the actual link rate.
2784 bp->link_vars.line_speed = SPEED_10000;
2785 bnx2x_cmng_fns_init(bp, true, bnx2x_get_cmng_fns_mode(bp));
2787 /* Only the PMF sets the HW */
2789 storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
2791 /* init Event Queue */
2792 eq_data.base_addr.hi = U64_HI(bp->eq_mapping);
2793 eq_data.base_addr.lo = U64_LO(bp->eq_mapping);
2794 eq_data.producer = bp->eq_prod;
2795 eq_data.index_id = HC_SP_INDEX_EQ_CONS;
2796 eq_data.sb_id = DEF_SB_ID;
2797 storm_memset_eq_data(bp, &eq_data, BP_FUNC(bp));
2801 static void bnx2x_e1h_disable(struct bnx2x *bp)
2803 int port = BP_PORT(bp);
2805 bnx2x_tx_disable(bp);
2807 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
2810 static void bnx2x_e1h_enable(struct bnx2x *bp)
2812 int port = BP_PORT(bp);
2814 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
2816 /* Tx queue should be only reenabled */
2817 netif_tx_wake_all_queues(bp->dev);
2820 * Should not call netif_carrier_on since it will be called if the link
2821 * is up when checking for link state
2825 #define DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED 3
2827 static void bnx2x_drv_info_ether_stat(struct bnx2x *bp)
2829 struct eth_stats_info *ether_stat =
2830 &bp->slowpath->drv_info_to_mcp.ether_stat;
2832 /* leave last char as NULL */
2833 memcpy(ether_stat->version, DRV_MODULE_VERSION,
2834 ETH_STAT_INFO_VERSION_LEN - 1);
2836 bp->fp[0].mac_obj.get_n_elements(bp, &bp->fp[0].mac_obj,
2837 DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED,
2838 ether_stat->mac_local);
2840 ether_stat->mtu_size = bp->dev->mtu;
2842 if (bp->dev->features & NETIF_F_RXCSUM)
2843 ether_stat->feature_flags |= FEATURE_ETH_CHKSUM_OFFLOAD_MASK;
2844 if (bp->dev->features & NETIF_F_TSO)
2845 ether_stat->feature_flags |= FEATURE_ETH_LSO_MASK;
2846 ether_stat->feature_flags |= bp->common.boot_mode;
2848 ether_stat->promiscuous_mode = (bp->dev->flags & IFF_PROMISC) ? 1 : 0;
2850 ether_stat->txq_size = bp->tx_ring_size;
2851 ether_stat->rxq_size = bp->rx_ring_size;
2854 static void bnx2x_drv_info_fcoe_stat(struct bnx2x *bp)
2857 struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
2858 struct fcoe_stats_info *fcoe_stat =
2859 &bp->slowpath->drv_info_to_mcp.fcoe_stat;
2861 memcpy(fcoe_stat->mac_local, bp->fip_mac, ETH_ALEN);
2863 fcoe_stat->qos_priority =
2864 app->traffic_type_priority[LLFC_TRAFFIC_TYPE_FCOE];
2866 /* insert FCoE stats from ramrod response */
2868 struct tstorm_per_queue_stats *fcoe_q_tstorm_stats =
2869 &bp->fw_stats_data->queue_stats[FCOE_IDX].
2870 tstorm_queue_statistics;
2872 struct xstorm_per_queue_stats *fcoe_q_xstorm_stats =
2873 &bp->fw_stats_data->queue_stats[FCOE_IDX].
2874 xstorm_queue_statistics;
2876 struct fcoe_statistics_params *fw_fcoe_stat =
2877 &bp->fw_stats_data->fcoe;
2879 ADD_64(fcoe_stat->rx_bytes_hi, 0, fcoe_stat->rx_bytes_lo,
2880 fw_fcoe_stat->rx_stat0.fcoe_rx_byte_cnt);
2882 ADD_64(fcoe_stat->rx_bytes_hi,
2883 fcoe_q_tstorm_stats->rcv_ucast_bytes.hi,
2884 fcoe_stat->rx_bytes_lo,
2885 fcoe_q_tstorm_stats->rcv_ucast_bytes.lo);
2887 ADD_64(fcoe_stat->rx_bytes_hi,
2888 fcoe_q_tstorm_stats->rcv_bcast_bytes.hi,
2889 fcoe_stat->rx_bytes_lo,
2890 fcoe_q_tstorm_stats->rcv_bcast_bytes.lo);
2892 ADD_64(fcoe_stat->rx_bytes_hi,
2893 fcoe_q_tstorm_stats->rcv_mcast_bytes.hi,
2894 fcoe_stat->rx_bytes_lo,
2895 fcoe_q_tstorm_stats->rcv_mcast_bytes.lo);
2897 ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
2898 fw_fcoe_stat->rx_stat0.fcoe_rx_pkt_cnt);
2900 ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
2901 fcoe_q_tstorm_stats->rcv_ucast_pkts);
2903 ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
2904 fcoe_q_tstorm_stats->rcv_bcast_pkts);
2906 ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
2907 fcoe_q_tstorm_stats->rcv_mcast_pkts);
2909 ADD_64(fcoe_stat->tx_bytes_hi, 0, fcoe_stat->tx_bytes_lo,
2910 fw_fcoe_stat->tx_stat.fcoe_tx_byte_cnt);
2912 ADD_64(fcoe_stat->tx_bytes_hi,
2913 fcoe_q_xstorm_stats->ucast_bytes_sent.hi,
2914 fcoe_stat->tx_bytes_lo,
2915 fcoe_q_xstorm_stats->ucast_bytes_sent.lo);
2917 ADD_64(fcoe_stat->tx_bytes_hi,
2918 fcoe_q_xstorm_stats->bcast_bytes_sent.hi,
2919 fcoe_stat->tx_bytes_lo,
2920 fcoe_q_xstorm_stats->bcast_bytes_sent.lo);
2922 ADD_64(fcoe_stat->tx_bytes_hi,
2923 fcoe_q_xstorm_stats->mcast_bytes_sent.hi,
2924 fcoe_stat->tx_bytes_lo,
2925 fcoe_q_xstorm_stats->mcast_bytes_sent.lo);
2927 ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
2928 fw_fcoe_stat->tx_stat.fcoe_tx_pkt_cnt);
2930 ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
2931 fcoe_q_xstorm_stats->ucast_pkts_sent);
2933 ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
2934 fcoe_q_xstorm_stats->bcast_pkts_sent);
2936 ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
2937 fcoe_q_xstorm_stats->mcast_pkts_sent);
2940 /* ask L5 driver to add data to the struct */
2941 bnx2x_cnic_notify(bp, CNIC_CTL_FCOE_STATS_GET_CMD);
2945 static void bnx2x_drv_info_iscsi_stat(struct bnx2x *bp)
2948 struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
2949 struct iscsi_stats_info *iscsi_stat =
2950 &bp->slowpath->drv_info_to_mcp.iscsi_stat;
2952 memcpy(iscsi_stat->mac_local, bp->cnic_eth_dev.iscsi_mac, ETH_ALEN);
2954 iscsi_stat->qos_priority =
2955 app->traffic_type_priority[LLFC_TRAFFIC_TYPE_ISCSI];
2957 /* ask L5 driver to add data to the struct */
2958 bnx2x_cnic_notify(bp, CNIC_CTL_ISCSI_STATS_GET_CMD);
2962 /* called due to MCP event (on pmf):
2963 * reread new bandwidth configuration
2965 * notify others function about the change
2967 static inline void bnx2x_config_mf_bw(struct bnx2x *bp)
2969 if (bp->link_vars.link_up) {
2970 bnx2x_cmng_fns_init(bp, true, CMNG_FNS_MINMAX);
2971 bnx2x_link_sync_notify(bp);
2973 storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
2976 static inline void bnx2x_set_mf_bw(struct bnx2x *bp)
2978 bnx2x_config_mf_bw(bp);
2979 bnx2x_fw_command(bp, DRV_MSG_CODE_SET_MF_BW_ACK, 0);
2982 static void bnx2x_handle_drv_info_req(struct bnx2x *bp)
2984 enum drv_info_opcode op_code;
2985 u32 drv_info_ctl = SHMEM2_RD(bp, drv_info_control);
2987 /* if drv_info version supported by MFW doesn't match - send NACK */
2988 if ((drv_info_ctl & DRV_INFO_CONTROL_VER_MASK) != DRV_INFO_CUR_VER) {
2989 bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
2993 op_code = (drv_info_ctl & DRV_INFO_CONTROL_OP_CODE_MASK) >>
2994 DRV_INFO_CONTROL_OP_CODE_SHIFT;
2996 memset(&bp->slowpath->drv_info_to_mcp, 0,
2997 sizeof(union drv_info_to_mcp));
3000 case ETH_STATS_OPCODE:
3001 bnx2x_drv_info_ether_stat(bp);
3003 case FCOE_STATS_OPCODE:
3004 bnx2x_drv_info_fcoe_stat(bp);
3006 case ISCSI_STATS_OPCODE:
3007 bnx2x_drv_info_iscsi_stat(bp);
3010 /* if op code isn't supported - send NACK */
3011 bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
3015 /* if we got drv_info attn from MFW then these fields are defined in
3018 SHMEM2_WR(bp, drv_info_host_addr_lo,
3019 U64_LO(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
3020 SHMEM2_WR(bp, drv_info_host_addr_hi,
3021 U64_HI(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
3023 bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_ACK, 0);
3026 static void bnx2x_dcc_event(struct bnx2x *bp, u32 dcc_event)
3028 DP(BNX2X_MSG_MCP, "dcc_event 0x%x\n", dcc_event);
3030 if (dcc_event & DRV_STATUS_DCC_DISABLE_ENABLE_PF) {
3033 * This is the only place besides the function initialization
3034 * where the bp->flags can change so it is done without any
3037 if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
3038 DP(BNX2X_MSG_MCP, "mf_cfg function disabled\n");
3039 bp->flags |= MF_FUNC_DIS;
3041 bnx2x_e1h_disable(bp);
3043 DP(BNX2X_MSG_MCP, "mf_cfg function enabled\n");
3044 bp->flags &= ~MF_FUNC_DIS;
3046 bnx2x_e1h_enable(bp);
3048 dcc_event &= ~DRV_STATUS_DCC_DISABLE_ENABLE_PF;
3050 if (dcc_event & DRV_STATUS_DCC_BANDWIDTH_ALLOCATION) {
3051 bnx2x_config_mf_bw(bp);
3052 dcc_event &= ~DRV_STATUS_DCC_BANDWIDTH_ALLOCATION;
3055 /* Report results to MCP */
3057 bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_FAILURE, 0);
3059 bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_OK, 0);
3062 /* must be called under the spq lock */
3063 static inline struct eth_spe *bnx2x_sp_get_next(struct bnx2x *bp)
3065 struct eth_spe *next_spe = bp->spq_prod_bd;
3067 if (bp->spq_prod_bd == bp->spq_last_bd) {
3068 bp->spq_prod_bd = bp->spq;
3069 bp->spq_prod_idx = 0;
3070 DP(BNX2X_MSG_SP, "end of spq\n");
3078 /* must be called under the spq lock */
3079 static inline void bnx2x_sp_prod_update(struct bnx2x *bp)
3081 int func = BP_FUNC(bp);
3084 * Make sure that BD data is updated before writing the producer:
3085 * BD data is written to the memory, the producer is read from the
3086 * memory, thus we need a full memory barrier to ensure the ordering.
3090 REG_WR16(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func),
3096 * bnx2x_is_contextless_ramrod - check if the current command ends on EQ
3098 * @cmd: command to check
3099 * @cmd_type: command type
3101 static inline bool bnx2x_is_contextless_ramrod(int cmd, int cmd_type)
3103 if ((cmd_type == NONE_CONNECTION_TYPE) ||
3104 (cmd == RAMROD_CMD_ID_ETH_FORWARD_SETUP) ||
3105 (cmd == RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES) ||
3106 (cmd == RAMROD_CMD_ID_ETH_FILTER_RULES) ||
3107 (cmd == RAMROD_CMD_ID_ETH_MULTICAST_RULES) ||
3108 (cmd == RAMROD_CMD_ID_ETH_SET_MAC) ||
3109 (cmd == RAMROD_CMD_ID_ETH_RSS_UPDATE))
3118 * bnx2x_sp_post - place a single command on an SP ring
3120 * @bp: driver handle
3121 * @command: command to place (e.g. SETUP, FILTER_RULES, etc.)
3122 * @cid: SW CID the command is related to
3123 * @data_hi: command private data address (high 32 bits)
3124 * @data_lo: command private data address (low 32 bits)
3125 * @cmd_type: command type (e.g. NONE, ETH)
3127 * SP data is handled as if it's always an address pair, thus data fields are
3128 * not swapped to little endian in upper functions. Instead this function swaps
3129 * data as if it's two u32 fields.
3131 int bnx2x_sp_post(struct bnx2x *bp, int command, int cid,
3132 u32 data_hi, u32 data_lo, int cmd_type)
3134 struct eth_spe *spe;
3136 bool common = bnx2x_is_contextless_ramrod(command, cmd_type);
3138 #ifdef BNX2X_STOP_ON_ERROR
3139 if (unlikely(bp->panic)) {
3140 BNX2X_ERR("Can't post SP when there is panic\n");
3145 spin_lock_bh(&bp->spq_lock);
3148 if (!atomic_read(&bp->eq_spq_left)) {
3149 BNX2X_ERR("BUG! EQ ring full!\n");
3150 spin_unlock_bh(&bp->spq_lock);
3154 } else if (!atomic_read(&bp->cq_spq_left)) {
3155 BNX2X_ERR("BUG! SPQ ring full!\n");
3156 spin_unlock_bh(&bp->spq_lock);
3161 spe = bnx2x_sp_get_next(bp);
3163 /* CID needs port number to be encoded int it */
3164 spe->hdr.conn_and_cmd_data =
3165 cpu_to_le32((command << SPE_HDR_CMD_ID_SHIFT) |
3168 type = (cmd_type << SPE_HDR_CONN_TYPE_SHIFT) & SPE_HDR_CONN_TYPE;
3170 type |= ((BP_FUNC(bp) << SPE_HDR_FUNCTION_ID_SHIFT) &
3171 SPE_HDR_FUNCTION_ID);
3173 spe->hdr.type = cpu_to_le16(type);
3175 spe->data.update_data_addr.hi = cpu_to_le32(data_hi);
3176 spe->data.update_data_addr.lo = cpu_to_le32(data_lo);
3179 * It's ok if the actual decrement is issued towards the memory
3180 * somewhere between the spin_lock and spin_unlock. Thus no
3181 * more explict memory barrier is needed.
3184 atomic_dec(&bp->eq_spq_left);
3186 atomic_dec(&bp->cq_spq_left);
3190 "SPQE[%x] (%x:%x) (cmd, common?) (%d,%d) hw_cid %x data (%x:%x) type(0x%x) left (CQ, EQ) (%x,%x)\n",
3191 bp->spq_prod_idx, (u32)U64_HI(bp->spq_mapping),
3192 (u32)(U64_LO(bp->spq_mapping) +
3193 (void *)bp->spq_prod_bd - (void *)bp->spq), command, common,
3194 HW_CID(bp, cid), data_hi, data_lo, type,
3195 atomic_read(&bp->cq_spq_left), atomic_read(&bp->eq_spq_left));
3197 bnx2x_sp_prod_update(bp);
3198 spin_unlock_bh(&bp->spq_lock);
3202 /* acquire split MCP access lock register */
3203 static int bnx2x_acquire_alr(struct bnx2x *bp)
3209 for (j = 0; j < 1000; j++) {
3211 REG_WR(bp, GRCBASE_MCP + 0x9c, val);
3212 val = REG_RD(bp, GRCBASE_MCP + 0x9c);
3213 if (val & (1L << 31))
3218 if (!(val & (1L << 31))) {
3219 BNX2X_ERR("Cannot acquire MCP access lock register\n");
3226 /* release split MCP access lock register */
3227 static void bnx2x_release_alr(struct bnx2x *bp)
3229 REG_WR(bp, GRCBASE_MCP + 0x9c, 0);
3232 #define BNX2X_DEF_SB_ATT_IDX 0x0001
3233 #define BNX2X_DEF_SB_IDX 0x0002
3235 static inline u16 bnx2x_update_dsb_idx(struct bnx2x *bp)
3237 struct host_sp_status_block *def_sb = bp->def_status_blk;
3240 barrier(); /* status block is written to by the chip */
3241 if (bp->def_att_idx != def_sb->atten_status_block.attn_bits_index) {
3242 bp->def_att_idx = def_sb->atten_status_block.attn_bits_index;
3243 rc |= BNX2X_DEF_SB_ATT_IDX;
3246 if (bp->def_idx != def_sb->sp_sb.running_index) {
3247 bp->def_idx = def_sb->sp_sb.running_index;
3248 rc |= BNX2X_DEF_SB_IDX;
3251 /* Do not reorder: indecies reading should complete before handling */
3257 * slow path service functions
3260 static void bnx2x_attn_int_asserted(struct bnx2x *bp, u32 asserted)
3262 int port = BP_PORT(bp);
3263 u32 aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
3264 MISC_REG_AEU_MASK_ATTN_FUNC_0;
3265 u32 nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 :
3266 NIG_REG_MASK_INTERRUPT_PORT0;
3271 if (bp->attn_state & asserted)
3272 BNX2X_ERR("IGU ERROR\n");
3274 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
3275 aeu_mask = REG_RD(bp, aeu_addr);
3277 DP(NETIF_MSG_HW, "aeu_mask %x newly asserted %x\n",
3278 aeu_mask, asserted);
3279 aeu_mask &= ~(asserted & 0x3ff);
3280 DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
3282 REG_WR(bp, aeu_addr, aeu_mask);
3283 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
3285 DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
3286 bp->attn_state |= asserted;
3287 DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
3289 if (asserted & ATTN_HARD_WIRED_MASK) {
3290 if (asserted & ATTN_NIG_FOR_FUNC) {
3292 bnx2x_acquire_phy_lock(bp);
3294 /* save nig interrupt mask */
3295 nig_mask = REG_RD(bp, nig_int_mask_addr);
3297 /* If nig_mask is not set, no need to call the update
3301 REG_WR(bp, nig_int_mask_addr, 0);
3303 bnx2x_link_attn(bp);
3306 /* handle unicore attn? */
3308 if (asserted & ATTN_SW_TIMER_4_FUNC)
3309 DP(NETIF_MSG_HW, "ATTN_SW_TIMER_4_FUNC!\n");
3311 if (asserted & GPIO_2_FUNC)
3312 DP(NETIF_MSG_HW, "GPIO_2_FUNC!\n");
3314 if (asserted & GPIO_3_FUNC)
3315 DP(NETIF_MSG_HW, "GPIO_3_FUNC!\n");
3317 if (asserted & GPIO_4_FUNC)
3318 DP(NETIF_MSG_HW, "GPIO_4_FUNC!\n");
3321 if (asserted & ATTN_GENERAL_ATTN_1) {
3322 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_1!\n");
3323 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_1, 0x0);
3325 if (asserted & ATTN_GENERAL_ATTN_2) {
3326 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_2!\n");
3327 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_2, 0x0);
3329 if (asserted & ATTN_GENERAL_ATTN_3) {
3330 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_3!\n");
3331 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_3, 0x0);
3334 if (asserted & ATTN_GENERAL_ATTN_4) {
3335 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_4!\n");
3336 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_4, 0x0);
3338 if (asserted & ATTN_GENERAL_ATTN_5) {
3339 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_5!\n");
3340 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_5, 0x0);
3342 if (asserted & ATTN_GENERAL_ATTN_6) {
3343 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_6!\n");
3344 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_6, 0x0);
3348 } /* if hardwired */
3350 if (bp->common.int_block == INT_BLOCK_HC)
3351 reg_addr = (HC_REG_COMMAND_REG + port*32 +
3352 COMMAND_REG_ATTN_BITS_SET);
3354 reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_SET_UPPER*8);
3356 DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", asserted,
3357 (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
3358 REG_WR(bp, reg_addr, asserted);
3360 /* now set back the mask */
3361 if (asserted & ATTN_NIG_FOR_FUNC) {
3362 REG_WR(bp, nig_int_mask_addr, nig_mask);
3363 bnx2x_release_phy_lock(bp);
3367 static inline void bnx2x_fan_failure(struct bnx2x *bp)
3369 int port = BP_PORT(bp);
3371 /* mark the failure */
3374 dev_info.port_hw_config[port].external_phy_config);
3376 ext_phy_config &= ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK;
3377 ext_phy_config |= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE;
3378 SHMEM_WR(bp, dev_info.port_hw_config[port].external_phy_config,
3381 /* log the failure */
3382 netdev_err(bp->dev, "Fan Failure on Network Controller has caused the driver to shutdown the card to prevent permanent damage.\n"
3383 "Please contact OEM Support for assistance\n");
3386 * Scheudle device reset (unload)
3387 * This is due to some boards consuming sufficient power when driver is
3388 * up to overheat if fan fails.
3390 smp_mb__before_clear_bit();
3391 set_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state);
3392 smp_mb__after_clear_bit();
3393 schedule_delayed_work(&bp->sp_rtnl_task, 0);
3397 static inline void bnx2x_attn_int_deasserted0(struct bnx2x *bp, u32 attn)
3399 int port = BP_PORT(bp);
3403 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
3404 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
3406 if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) {
3408 val = REG_RD(bp, reg_offset);
3409 val &= ~AEU_INPUTS_ATTN_BITS_SPIO5;
3410 REG_WR(bp, reg_offset, val);
3412 BNX2X_ERR("SPIO5 hw attention\n");
3414 /* Fan failure attention */
3415 bnx2x_hw_reset_phy(&bp->link_params);
3416 bnx2x_fan_failure(bp);
3419 if ((attn & bp->link_vars.aeu_int_mask) && bp->port.pmf) {
3420 bnx2x_acquire_phy_lock(bp);
3421 bnx2x_handle_module_detect_int(&bp->link_params);
3422 bnx2x_release_phy_lock(bp);
3425 if (attn & HW_INTERRUT_ASSERT_SET_0) {
3427 val = REG_RD(bp, reg_offset);
3428 val &= ~(attn & HW_INTERRUT_ASSERT_SET_0);
3429 REG_WR(bp, reg_offset, val);
3431 BNX2X_ERR("FATAL HW block attention set0 0x%x\n",
3432 (u32)(attn & HW_INTERRUT_ASSERT_SET_0));
3437 static inline void bnx2x_attn_int_deasserted1(struct bnx2x *bp, u32 attn)
3441 if (attn & AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT) {
3443 val = REG_RD(bp, DORQ_REG_DORQ_INT_STS_CLR);
3444 BNX2X_ERR("DB hw attention 0x%x\n", val);
3445 /* DORQ discard attention */
3447 BNX2X_ERR("FATAL error from DORQ\n");
3450 if (attn & HW_INTERRUT_ASSERT_SET_1) {
3452 int port = BP_PORT(bp);
3455 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 :
3456 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1);
3458 val = REG_RD(bp, reg_offset);
3459 val &= ~(attn & HW_INTERRUT_ASSERT_SET_1);
3460 REG_WR(bp, reg_offset, val);
3462 BNX2X_ERR("FATAL HW block attention set1 0x%x\n",
3463 (u32)(attn & HW_INTERRUT_ASSERT_SET_1));
3468 static inline void bnx2x_attn_int_deasserted2(struct bnx2x *bp, u32 attn)
3472 if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) {
3474 val = REG_RD(bp, CFC_REG_CFC_INT_STS_CLR);
3475 BNX2X_ERR("CFC hw attention 0x%x\n", val);
3476 /* CFC error attention */
3478 BNX2X_ERR("FATAL error from CFC\n");
3481 if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) {
3482 val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_0);
3483 BNX2X_ERR("PXP hw attention-0 0x%x\n", val);
3484 /* RQ_USDMDP_FIFO_OVERFLOW */
3486 BNX2X_ERR("FATAL error from PXP\n");
3488 if (!CHIP_IS_E1x(bp)) {
3489 val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_1);
3490 BNX2X_ERR("PXP hw attention-1 0x%x\n", val);
3494 if (attn & HW_INTERRUT_ASSERT_SET_2) {
3496 int port = BP_PORT(bp);
3499 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 :
3500 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2);
3502 val = REG_RD(bp, reg_offset);
3503 val &= ~(attn & HW_INTERRUT_ASSERT_SET_2);
3504 REG_WR(bp, reg_offset, val);
3506 BNX2X_ERR("FATAL HW block attention set2 0x%x\n",
3507 (u32)(attn & HW_INTERRUT_ASSERT_SET_2));
3512 static inline void bnx2x_attn_int_deasserted3(struct bnx2x *bp, u32 attn)
3516 if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) {
3518 if (attn & BNX2X_PMF_LINK_ASSERT) {
3519 int func = BP_FUNC(bp);
3521 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
3522 bp->mf_config[BP_VN(bp)] = MF_CFG_RD(bp,
3523 func_mf_config[BP_ABS_FUNC(bp)].config);
3525 func_mb[BP_FW_MB_IDX(bp)].drv_status);
3526 if (val & DRV_STATUS_DCC_EVENT_MASK)
3528 (val & DRV_STATUS_DCC_EVENT_MASK));
3530 if (val & DRV_STATUS_SET_MF_BW)
3531 bnx2x_set_mf_bw(bp);
3533 if (val & DRV_STATUS_DRV_INFO_REQ)
3534 bnx2x_handle_drv_info_req(bp);
3535 if ((bp->port.pmf == 0) && (val & DRV_STATUS_PMF))
3536 bnx2x_pmf_update(bp);
3539 (val & DRV_STATUS_DCBX_NEGOTIATION_RESULTS) &&
3540 bp->dcbx_enabled > 0)
3541 /* start dcbx state machine */
3542 bnx2x_dcbx_set_params(bp,
3543 BNX2X_DCBX_STATE_NEG_RECEIVED);
3544 if (bp->link_vars.periodic_flags &
3545 PERIODIC_FLAGS_LINK_EVENT) {
3546 /* sync with link */
3547 bnx2x_acquire_phy_lock(bp);
3548 bp->link_vars.periodic_flags &=
3549 ~PERIODIC_FLAGS_LINK_EVENT;
3550 bnx2x_release_phy_lock(bp);
3552 bnx2x_link_sync_notify(bp);
3553 bnx2x_link_report(bp);
3555 /* Always call it here: bnx2x_link_report() will
3556 * prevent the link indication duplication.
3558 bnx2x__link_status_update(bp);
3559 } else if (attn & BNX2X_MC_ASSERT_BITS) {
3561 BNX2X_ERR("MC assert!\n");
3562 bnx2x_mc_assert(bp);
3563 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_10, 0);
3564 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_9, 0);
3565 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_8, 0);
3566 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_7, 0);
3569 } else if (attn & BNX2X_MCP_ASSERT) {
3571 BNX2X_ERR("MCP assert!\n");
3572 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_11, 0);
3576 BNX2X_ERR("Unknown HW assert! (attn 0x%x)\n", attn);
3579 if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) {
3580 BNX2X_ERR("LATCHED attention 0x%08x (masked)\n", attn);
3581 if (attn & BNX2X_GRC_TIMEOUT) {
3582 val = CHIP_IS_E1(bp) ? 0 :
3583 REG_RD(bp, MISC_REG_GRC_TIMEOUT_ATTN);
3584 BNX2X_ERR("GRC time-out 0x%08x\n", val);
3586 if (attn & BNX2X_GRC_RSV) {
3587 val = CHIP_IS_E1(bp) ? 0 :
3588 REG_RD(bp, MISC_REG_GRC_RSV_ATTN);
3589 BNX2X_ERR("GRC reserved 0x%08x\n", val);
3591 REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff);
3597 * 0-7 - Engine0 load counter.
3598 * 8-15 - Engine1 load counter.
3599 * 16 - Engine0 RESET_IN_PROGRESS bit.
3600 * 17 - Engine1 RESET_IN_PROGRESS bit.
3601 * 18 - Engine0 ONE_IS_LOADED. Set when there is at least one active function
3603 * 19 - Engine1 ONE_IS_LOADED.
3604 * 20 - Chip reset flow bit. When set none-leader must wait for both engines
3605 * leader to complete (check for both RESET_IN_PROGRESS bits and not for
3606 * just the one belonging to its engine).
3609 #define BNX2X_RECOVERY_GLOB_REG MISC_REG_GENERIC_POR_1
3611 #define BNX2X_PATH0_LOAD_CNT_MASK 0x000000ff
3612 #define BNX2X_PATH0_LOAD_CNT_SHIFT 0
3613 #define BNX2X_PATH1_LOAD_CNT_MASK 0x0000ff00
3614 #define BNX2X_PATH1_LOAD_CNT_SHIFT 8
3615 #define BNX2X_PATH0_RST_IN_PROG_BIT 0x00010000
3616 #define BNX2X_PATH1_RST_IN_PROG_BIT 0x00020000
3617 #define BNX2X_GLOBAL_RESET_BIT 0x00040000
3620 * Set the GLOBAL_RESET bit.
3622 * Should be run under rtnl lock
3624 void bnx2x_set_reset_global(struct bnx2x *bp)
3627 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
3628 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3629 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val | BNX2X_GLOBAL_RESET_BIT);
3630 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
3634 * Clear the GLOBAL_RESET bit.
3636 * Should be run under rtnl lock
3638 static inline void bnx2x_clear_reset_global(struct bnx2x *bp)
3641 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
3642 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3643 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~BNX2X_GLOBAL_RESET_BIT));
3644 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
3648 * Checks the GLOBAL_RESET bit.
3650 * should be run under rtnl lock
3652 static inline bool bnx2x_reset_is_global(struct bnx2x *bp)
3654 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3656 DP(NETIF_MSG_HW, "GEN_REG_VAL=0x%08x\n", val);
3657 return (val & BNX2X_GLOBAL_RESET_BIT) ? true : false;
3661 * Clear RESET_IN_PROGRESS bit for the current engine.
3663 * Should be run under rtnl lock
3665 static inline void bnx2x_set_reset_done(struct bnx2x *bp)
3668 u32 bit = BP_PATH(bp) ?
3669 BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
3670 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
3671 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3675 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
3677 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
3681 * Set RESET_IN_PROGRESS for the current engine.
3683 * should be run under rtnl lock
3685 void bnx2x_set_reset_in_progress(struct bnx2x *bp)
3688 u32 bit = BP_PATH(bp) ?
3689 BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
3690 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
3691 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3695 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
3696 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
3700 * Checks the RESET_IN_PROGRESS bit for the given engine.
3701 * should be run under rtnl lock
3703 bool bnx2x_reset_is_done(struct bnx2x *bp, int engine)
3705 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3707 BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
3709 /* return false if bit is set */
3710 return (val & bit) ? false : true;
3714 * set pf load for the current pf.
3716 * should be run under rtnl lock
3718 void bnx2x_set_pf_load(struct bnx2x *bp)
3721 u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
3722 BNX2X_PATH0_LOAD_CNT_MASK;
3723 u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
3724 BNX2X_PATH0_LOAD_CNT_SHIFT;
3726 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
3727 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3729 DP(NETIF_MSG_IFUP, "Old GEN_REG_VAL=0x%08x\n", val);
3731 /* get the current counter value */
3732 val1 = (val & mask) >> shift;
3734 /* set bit of that PF */
3735 val1 |= (1 << bp->pf_num);
3737 /* clear the old value */
3740 /* set the new one */
3741 val |= ((val1 << shift) & mask);
3743 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
3744 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
3748 * bnx2x_clear_pf_load - clear pf load mark
3750 * @bp: driver handle
3752 * Should be run under rtnl lock.
3753 * Decrements the load counter for the current engine. Returns
3754 * whether other functions are still loaded
3756 bool bnx2x_clear_pf_load(struct bnx2x *bp)
3759 u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
3760 BNX2X_PATH0_LOAD_CNT_MASK;
3761 u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
3762 BNX2X_PATH0_LOAD_CNT_SHIFT;
3764 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
3765 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3766 DP(NETIF_MSG_IFDOWN, "Old GEN_REG_VAL=0x%08x\n", val);
3768 /* get the current counter value */
3769 val1 = (val & mask) >> shift;
3771 /* clear bit of that PF */
3772 val1 &= ~(1 << bp->pf_num);
3774 /* clear the old value */
3777 /* set the new one */
3778 val |= ((val1 << shift) & mask);
3780 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
3781 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
3786 * Read the load status for the current engine.
3788 * should be run under rtnl lock
3790 static inline bool bnx2x_get_load_status(struct bnx2x *bp, int engine)
3792 u32 mask = (engine ? BNX2X_PATH1_LOAD_CNT_MASK :
3793 BNX2X_PATH0_LOAD_CNT_MASK);
3794 u32 shift = (engine ? BNX2X_PATH1_LOAD_CNT_SHIFT :
3795 BNX2X_PATH0_LOAD_CNT_SHIFT);
3796 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3798 DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "GLOB_REG=0x%08x\n", val);
3800 val = (val & mask) >> shift;
3802 DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "load mask for engine %d = 0x%x\n",
3809 * Reset the load status for the current engine.
3811 static inline void bnx2x_clear_load_status(struct bnx2x *bp)
3814 u32 mask = (BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
3815 BNX2X_PATH0_LOAD_CNT_MASK);
3816 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
3817 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3818 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~mask));
3819 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
3822 static inline void _print_next_block(int idx, const char *blk)
3824 pr_cont("%s%s", idx ? ", " : "", blk);
3827 static inline int bnx2x_check_blocks_with_parity0(u32 sig, int par_num,
3832 for (i = 0; sig; i++) {
3833 cur_bit = ((u32)0x1 << i);
3834 if (sig & cur_bit) {
3836 case AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR:
3838 _print_next_block(par_num++, "BRB");
3840 case AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR:
3842 _print_next_block(par_num++, "PARSER");
3844 case AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR:
3846 _print_next_block(par_num++, "TSDM");
3848 case AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR:
3850 _print_next_block(par_num++,
3853 case AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR:
3855 _print_next_block(par_num++, "TCM");
3857 case AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR:
3859 _print_next_block(par_num++, "TSEMI");
3861 case AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR:
3863 _print_next_block(par_num++, "XPB");
3875 static inline int bnx2x_check_blocks_with_parity1(u32 sig, int par_num,
3876 bool *global, bool print)
3880 for (i = 0; sig; i++) {
3881 cur_bit = ((u32)0x1 << i);
3882 if (sig & cur_bit) {
3884 case AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR:
3886 _print_next_block(par_num++, "PBF");
3888 case AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR:
3890 _print_next_block(par_num++, "QM");
3892 case AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR:
3894 _print_next_block(par_num++, "TM");
3896 case AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR:
3898 _print_next_block(par_num++, "XSDM");
3900 case AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR:
3902 _print_next_block(par_num++, "XCM");
3904 case AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR:
3906 _print_next_block(par_num++, "XSEMI");
3908 case AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR:
3910 _print_next_block(par_num++,
3913 case AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR:
3915 _print_next_block(par_num++, "NIG");
3917 case AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR:
3919 _print_next_block(par_num++,
3923 case AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR:
3925 _print_next_block(par_num++, "DEBUG");
3927 case AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR:
3929 _print_next_block(par_num++, "USDM");
3931 case AEU_INPUTS_ATTN_BITS_UCM_PARITY_ERROR:
3933 _print_next_block(par_num++, "UCM");
3935 case AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR:
3937 _print_next_block(par_num++, "USEMI");
3939 case AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR:
3941 _print_next_block(par_num++, "UPB");
3943 case AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR:
3945 _print_next_block(par_num++, "CSDM");
3947 case AEU_INPUTS_ATTN_BITS_CCM_PARITY_ERROR:
3949 _print_next_block(par_num++, "CCM");
3961 static inline int bnx2x_check_blocks_with_parity2(u32 sig, int par_num,
3966 for (i = 0; sig; i++) {
3967 cur_bit = ((u32)0x1 << i);
3968 if (sig & cur_bit) {
3970 case AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR:
3972 _print_next_block(par_num++, "CSEMI");
3974 case AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR:
3976 _print_next_block(par_num++, "PXP");
3978 case AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR:
3980 _print_next_block(par_num++,
3981 "PXPPCICLOCKCLIENT");
3983 case AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR:
3985 _print_next_block(par_num++, "CFC");
3987 case AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR:
3989 _print_next_block(par_num++, "CDU");
3991 case AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR:
3993 _print_next_block(par_num++, "DMAE");
3995 case AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR:
3997 _print_next_block(par_num++, "IGU");
3999 case AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR:
4001 _print_next_block(par_num++, "MISC");
4013 static inline int bnx2x_check_blocks_with_parity3(u32 sig, int par_num,
4014 bool *global, bool print)
4018 for (i = 0; sig; i++) {
4019 cur_bit = ((u32)0x1 << i);
4020 if (sig & cur_bit) {
4022 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY:
4024 _print_next_block(par_num++, "MCP ROM");
4027 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY:
4029 _print_next_block(par_num++,
4033 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY:
4035 _print_next_block(par_num++,
4039 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY:
4041 _print_next_block(par_num++,
4055 static inline int bnx2x_check_blocks_with_parity4(u32 sig, int par_num,
4060 for (i = 0; sig; i++) {
4061 cur_bit = ((u32)0x1 << i);
4062 if (sig & cur_bit) {
4064 case AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR:
4066 _print_next_block(par_num++, "PGLUE_B");
4068 case AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR:
4070 _print_next_block(par_num++, "ATC");
4082 static inline bool bnx2x_parity_attn(struct bnx2x *bp, bool *global, bool print,
4085 if ((sig[0] & HW_PRTY_ASSERT_SET_0) ||
4086 (sig[1] & HW_PRTY_ASSERT_SET_1) ||
4087 (sig[2] & HW_PRTY_ASSERT_SET_2) ||
4088 (sig[3] & HW_PRTY_ASSERT_SET_3) ||
4089 (sig[4] & HW_PRTY_ASSERT_SET_4)) {
4091 DP(NETIF_MSG_HW, "Was parity error: HW block parity attention:\n"
4092 "[0]:0x%08x [1]:0x%08x [2]:0x%08x [3]:0x%08x [4]:0x%08x\n",
4093 sig[0] & HW_PRTY_ASSERT_SET_0,
4094 sig[1] & HW_PRTY_ASSERT_SET_1,
4095 sig[2] & HW_PRTY_ASSERT_SET_2,
4096 sig[3] & HW_PRTY_ASSERT_SET_3,
4097 sig[4] & HW_PRTY_ASSERT_SET_4);
4100 "Parity errors detected in blocks: ");
4101 par_num = bnx2x_check_blocks_with_parity0(
4102 sig[0] & HW_PRTY_ASSERT_SET_0, par_num, print);
4103 par_num = bnx2x_check_blocks_with_parity1(
4104 sig[1] & HW_PRTY_ASSERT_SET_1, par_num, global, print);
4105 par_num = bnx2x_check_blocks_with_parity2(
4106 sig[2] & HW_PRTY_ASSERT_SET_2, par_num, print);
4107 par_num = bnx2x_check_blocks_with_parity3(
4108 sig[3] & HW_PRTY_ASSERT_SET_3, par_num, global, print);
4109 par_num = bnx2x_check_blocks_with_parity4(
4110 sig[4] & HW_PRTY_ASSERT_SET_4, par_num, print);
4121 * bnx2x_chk_parity_attn - checks for parity attentions.
4123 * @bp: driver handle
4124 * @global: true if there was a global attention
4125 * @print: show parity attention in syslog
4127 bool bnx2x_chk_parity_attn(struct bnx2x *bp, bool *global, bool print)
4129 struct attn_route attn = { {0} };
4130 int port = BP_PORT(bp);
4132 attn.sig[0] = REG_RD(bp,
4133 MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 +
4135 attn.sig[1] = REG_RD(bp,
4136 MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 +
4138 attn.sig[2] = REG_RD(bp,
4139 MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 +
4141 attn.sig[3] = REG_RD(bp,
4142 MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 +
4145 if (!CHIP_IS_E1x(bp))
4146 attn.sig[4] = REG_RD(bp,
4147 MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 +
4150 return bnx2x_parity_attn(bp, global, print, attn.sig);
4154 static inline void bnx2x_attn_int_deasserted4(struct bnx2x *bp, u32 attn)
4157 if (attn & AEU_INPUTS_ATTN_BITS_PGLUE_HW_INTERRUPT) {
4159 val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS_CLR);
4160 BNX2X_ERR("PGLUE hw attention 0x%x\n", val);
4161 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR)
4162 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR\n");
4163 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR)
4164 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR\n");
4165 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN)
4166 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN\n");
4167 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN)
4168 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN\n");
4170 PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN)
4171 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN\n");
4173 PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN)
4174 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN\n");
4175 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN)
4176 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN\n");
4177 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN)
4178 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN\n");
4179 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW)
4180 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW\n");
4182 if (attn & AEU_INPUTS_ATTN_BITS_ATC_HW_INTERRUPT) {
4183 val = REG_RD(bp, ATC_REG_ATC_INT_STS_CLR);
4184 BNX2X_ERR("ATC hw attention 0x%x\n", val);
4185 if (val & ATC_ATC_INT_STS_REG_ADDRESS_ERROR)
4186 BNX2X_ERR("ATC_ATC_INT_STS_REG_ADDRESS_ERROR\n");
4187 if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND)
4188 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND\n");
4189 if (val & ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS)
4190 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS\n");
4191 if (val & ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT)
4192 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT\n");
4193 if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR)
4194 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR\n");
4195 if (val & ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU)
4196 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU\n");
4199 if (attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
4200 AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)) {
4201 BNX2X_ERR("FATAL parity attention set4 0x%x\n",
4202 (u32)(attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
4203 AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)));
4208 static void bnx2x_attn_int_deasserted(struct bnx2x *bp, u32 deasserted)
4210 struct attn_route attn, *group_mask;
4211 int port = BP_PORT(bp);
4216 bool global = false;
4218 /* need to take HW lock because MCP or other port might also
4219 try to handle this event */
4220 bnx2x_acquire_alr(bp);
4222 if (bnx2x_chk_parity_attn(bp, &global, true)) {
4223 #ifndef BNX2X_STOP_ON_ERROR
4224 bp->recovery_state = BNX2X_RECOVERY_INIT;
4225 schedule_delayed_work(&bp->sp_rtnl_task, 0);
4226 /* Disable HW interrupts */
4227 bnx2x_int_disable(bp);
4228 /* In case of parity errors don't handle attentions so that
4229 * other function would "see" parity errors.
4234 bnx2x_release_alr(bp);
4238 attn.sig[0] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4);
4239 attn.sig[1] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4);
4240 attn.sig[2] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4);
4241 attn.sig[3] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4);
4242 if (!CHIP_IS_E1x(bp))
4244 REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + port*4);
4248 DP(NETIF_MSG_HW, "attn: %08x %08x %08x %08x %08x\n",
4249 attn.sig[0], attn.sig[1], attn.sig[2], attn.sig[3], attn.sig[4]);
4251 for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
4252 if (deasserted & (1 << index)) {
4253 group_mask = &bp->attn_group[index];
4255 DP(NETIF_MSG_HW, "group[%d]: %08x %08x %08x %08x %08x\n",
4257 group_mask->sig[0], group_mask->sig[1],
4258 group_mask->sig[2], group_mask->sig[3],
4259 group_mask->sig[4]);
4261 bnx2x_attn_int_deasserted4(bp,
4262 attn.sig[4] & group_mask->sig[4]);
4263 bnx2x_attn_int_deasserted3(bp,
4264 attn.sig[3] & group_mask->sig[3]);
4265 bnx2x_attn_int_deasserted1(bp,
4266 attn.sig[1] & group_mask->sig[1]);
4267 bnx2x_attn_int_deasserted2(bp,
4268 attn.sig[2] & group_mask->sig[2]);
4269 bnx2x_attn_int_deasserted0(bp,
4270 attn.sig[0] & group_mask->sig[0]);
4274 bnx2x_release_alr(bp);
4276 if (bp->common.int_block == INT_BLOCK_HC)
4277 reg_addr = (HC_REG_COMMAND_REG + port*32 +
4278 COMMAND_REG_ATTN_BITS_CLR);
4280 reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_CLR_UPPER*8);
4283 DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", val,
4284 (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
4285 REG_WR(bp, reg_addr, val);
4287 if (~bp->attn_state & deasserted)
4288 BNX2X_ERR("IGU ERROR\n");
4290 reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
4291 MISC_REG_AEU_MASK_ATTN_FUNC_0;
4293 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
4294 aeu_mask = REG_RD(bp, reg_addr);
4296 DP(NETIF_MSG_HW, "aeu_mask %x newly deasserted %x\n",
4297 aeu_mask, deasserted);
4298 aeu_mask |= (deasserted & 0x3ff);
4299 DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
4301 REG_WR(bp, reg_addr, aeu_mask);
4302 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
4304 DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
4305 bp->attn_state &= ~deasserted;
4306 DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
4309 static void bnx2x_attn_int(struct bnx2x *bp)
4311 /* read local copy of bits */
4312 u32 attn_bits = le32_to_cpu(bp->def_status_blk->atten_status_block.
4314 u32 attn_ack = le32_to_cpu(bp->def_status_blk->atten_status_block.
4316 u32 attn_state = bp->attn_state;
4318 /* look for changed bits */
4319 u32 asserted = attn_bits & ~attn_ack & ~attn_state;
4320 u32 deasserted = ~attn_bits & attn_ack & attn_state;
4323 "attn_bits %x attn_ack %x asserted %x deasserted %x\n",
4324 attn_bits, attn_ack, asserted, deasserted);
4326 if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state))
4327 BNX2X_ERR("BAD attention state\n");
4329 /* handle bits that were raised */
4331 bnx2x_attn_int_asserted(bp, asserted);
4334 bnx2x_attn_int_deasserted(bp, deasserted);
4337 void bnx2x_igu_ack_sb(struct bnx2x *bp, u8 igu_sb_id, u8 segment,
4338 u16 index, u8 op, u8 update)
4340 u32 igu_addr = BAR_IGU_INTMEM + (IGU_CMD_INT_ACK_BASE + igu_sb_id)*8;
4342 bnx2x_igu_ack_sb_gen(bp, igu_sb_id, segment, index, op, update,
4346 static inline void bnx2x_update_eq_prod(struct bnx2x *bp, u16 prod)
4348 /* No memory barriers */
4349 storm_memset_eq_prod(bp, prod, BP_FUNC(bp));
4350 mmiowb(); /* keep prod updates ordered */
4354 static int bnx2x_cnic_handle_cfc_del(struct bnx2x *bp, u32 cid,
4355 union event_ring_elem *elem)
4357 u8 err = elem->message.error;
4359 if (!bp->cnic_eth_dev.starting_cid ||
4360 (cid < bp->cnic_eth_dev.starting_cid &&
4361 cid != bp->cnic_eth_dev.iscsi_l2_cid))
4364 DP(BNX2X_MSG_SP, "got delete ramrod for CNIC CID %d\n", cid);
4366 if (unlikely(err)) {
4368 BNX2X_ERR("got delete ramrod for CNIC CID %d with error!\n",
4370 bnx2x_panic_dump(bp);
4372 bnx2x_cnic_cfc_comp(bp, cid, err);
4377 static inline void bnx2x_handle_mcast_eqe(struct bnx2x *bp)
4379 struct bnx2x_mcast_ramrod_params rparam;
4382 memset(&rparam, 0, sizeof(rparam));
4384 rparam.mcast_obj = &bp->mcast_obj;
4386 netif_addr_lock_bh(bp->dev);
4388 /* Clear pending state for the last command */
4389 bp->mcast_obj.raw.clear_pending(&bp->mcast_obj.raw);
4391 /* If there are pending mcast commands - send them */
4392 if (bp->mcast_obj.check_pending(&bp->mcast_obj)) {
4393 rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_CONT);
4395 BNX2X_ERR("Failed to send pending mcast commands: %d\n",
4399 netif_addr_unlock_bh(bp->dev);
4402 static inline void bnx2x_handle_classification_eqe(struct bnx2x *bp,
4403 union event_ring_elem *elem)
4405 unsigned long ramrod_flags = 0;
4407 u32 cid = elem->message.data.eth_event.echo & BNX2X_SWCID_MASK;
4408 struct bnx2x_vlan_mac_obj *vlan_mac_obj;
4410 /* Always push next commands out, don't wait here */
4411 __set_bit(RAMROD_CONT, &ramrod_flags);
4413 switch (elem->message.data.eth_event.echo >> BNX2X_SWCID_SHIFT) {
4414 case BNX2X_FILTER_MAC_PENDING:
4415 DP(BNX2X_MSG_SP, "Got SETUP_MAC completions\n");
4417 if (cid == BNX2X_ISCSI_ETH_CID)
4418 vlan_mac_obj = &bp->iscsi_l2_mac_obj;
4421 vlan_mac_obj = &bp->fp[cid].mac_obj;
4424 case BNX2X_FILTER_MCAST_PENDING:
4425 DP(BNX2X_MSG_SP, "Got SETUP_MCAST completions\n");
4426 /* This is only relevant for 57710 where multicast MACs are
4427 * configured as unicast MACs using the same ramrod.
4429 bnx2x_handle_mcast_eqe(bp);
4432 BNX2X_ERR("Unsupported classification command: %d\n",
4433 elem->message.data.eth_event.echo);
4437 rc = vlan_mac_obj->complete(bp, vlan_mac_obj, elem, &ramrod_flags);
4440 BNX2X_ERR("Failed to schedule new commands: %d\n", rc);
4442 DP(BNX2X_MSG_SP, "Scheduled next pending commands...\n");
4447 static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start);
4450 static inline void bnx2x_handle_rx_mode_eqe(struct bnx2x *bp)
4452 netif_addr_lock_bh(bp->dev);
4454 clear_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
4456 /* Send rx_mode command again if was requested */
4457 if (test_and_clear_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state))
4458 bnx2x_set_storm_rx_mode(bp);
4460 else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED,
4462 bnx2x_set_iscsi_eth_rx_mode(bp, true);
4463 else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED,
4465 bnx2x_set_iscsi_eth_rx_mode(bp, false);
4468 netif_addr_unlock_bh(bp->dev);
4471 static inline struct bnx2x_queue_sp_obj *bnx2x_cid_to_q_obj(
4472 struct bnx2x *bp, u32 cid)
4474 DP(BNX2X_MSG_SP, "retrieving fp from cid %d\n", cid);
4476 if (cid == BNX2X_FCOE_ETH_CID)
4477 return &bnx2x_fcoe(bp, q_obj);
4480 return &bnx2x_fp(bp, CID_TO_FP(cid), q_obj);
4483 static void bnx2x_eq_int(struct bnx2x *bp)
4485 u16 hw_cons, sw_cons, sw_prod;
4486 union event_ring_elem *elem;
4490 struct bnx2x_queue_sp_obj *q_obj;
4491 struct bnx2x_func_sp_obj *f_obj = &bp->func_obj;
4492 struct bnx2x_raw_obj *rss_raw = &bp->rss_conf_obj.raw;
4494 hw_cons = le16_to_cpu(*bp->eq_cons_sb);
4496 /* The hw_cos range is 1-255, 257 - the sw_cons range is 0-254, 256.
4497 * when we get the the next-page we nned to adjust so the loop
4498 * condition below will be met. The next element is the size of a
4499 * regular element and hence incrementing by 1
4501 if ((hw_cons & EQ_DESC_MAX_PAGE) == EQ_DESC_MAX_PAGE)
4504 /* This function may never run in parallel with itself for a
4505 * specific bp, thus there is no need in "paired" read memory
4508 sw_cons = bp->eq_cons;
4509 sw_prod = bp->eq_prod;
4511 DP(BNX2X_MSG_SP, "EQ: hw_cons %u sw_cons %u bp->eq_spq_left %x\n",
4512 hw_cons, sw_cons, atomic_read(&bp->eq_spq_left));
4514 for (; sw_cons != hw_cons;
4515 sw_prod = NEXT_EQ_IDX(sw_prod), sw_cons = NEXT_EQ_IDX(sw_cons)) {
4518 elem = &bp->eq_ring[EQ_DESC(sw_cons)];
4520 cid = SW_CID(elem->message.data.cfc_del_event.cid);
4521 opcode = elem->message.opcode;
4524 /* handle eq element */
4526 case EVENT_RING_OPCODE_STAT_QUERY:
4527 DP(BNX2X_MSG_SP | BNX2X_MSG_STATS,
4528 "got statistics comp event %d\n",
4530 /* nothing to do with stats comp */
4533 case EVENT_RING_OPCODE_CFC_DEL:
4534 /* handle according to cid range */
4536 * we may want to verify here that the bp state is
4540 "got delete ramrod for MULTI[%d]\n", cid);
4542 if (!bnx2x_cnic_handle_cfc_del(bp, cid, elem))
4545 q_obj = bnx2x_cid_to_q_obj(bp, cid);
4547 if (q_obj->complete_cmd(bp, q_obj, BNX2X_Q_CMD_CFC_DEL))
4554 case EVENT_RING_OPCODE_STOP_TRAFFIC:
4555 DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got STOP TRAFFIC\n");
4556 if (f_obj->complete_cmd(bp, f_obj,
4557 BNX2X_F_CMD_TX_STOP))
4559 bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_PAUSED);
4562 case EVENT_RING_OPCODE_START_TRAFFIC:
4563 DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got START TRAFFIC\n");
4564 if (f_obj->complete_cmd(bp, f_obj,
4565 BNX2X_F_CMD_TX_START))
4567 bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_RELEASED);
4569 case EVENT_RING_OPCODE_FUNCTION_START:
4570 DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
4571 "got FUNC_START ramrod\n");
4572 if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_START))
4577 case EVENT_RING_OPCODE_FUNCTION_STOP:
4578 DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
4579 "got FUNC_STOP ramrod\n");
4580 if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_STOP))
4586 switch (opcode | bp->state) {
4587 case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
4589 case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
4590 BNX2X_STATE_OPENING_WAIT4_PORT):
4591 cid = elem->message.data.eth_event.echo &
4593 DP(BNX2X_MSG_SP, "got RSS_UPDATE ramrod. CID %d\n",
4595 rss_raw->clear_pending(rss_raw);
4598 case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_OPEN):
4599 case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_DIAG):
4600 case (EVENT_RING_OPCODE_SET_MAC |
4601 BNX2X_STATE_CLOSING_WAIT4_HALT):
4602 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
4604 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
4606 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
4607 BNX2X_STATE_CLOSING_WAIT4_HALT):
4608 DP(BNX2X_MSG_SP, "got (un)set mac ramrod\n");
4609 bnx2x_handle_classification_eqe(bp, elem);
4612 case (EVENT_RING_OPCODE_MULTICAST_RULES |
4614 case (EVENT_RING_OPCODE_MULTICAST_RULES |
4616 case (EVENT_RING_OPCODE_MULTICAST_RULES |
4617 BNX2X_STATE_CLOSING_WAIT4_HALT):
4618 DP(BNX2X_MSG_SP, "got mcast ramrod\n");
4619 bnx2x_handle_mcast_eqe(bp);
4622 case (EVENT_RING_OPCODE_FILTERS_RULES |
4624 case (EVENT_RING_OPCODE_FILTERS_RULES |
4626 case (EVENT_RING_OPCODE_FILTERS_RULES |
4627 BNX2X_STATE_CLOSING_WAIT4_HALT):
4628 DP(BNX2X_MSG_SP, "got rx_mode ramrod\n");
4629 bnx2x_handle_rx_mode_eqe(bp);
4632 /* unknown event log error and continue */
4633 BNX2X_ERR("Unknown EQ event %d, bp->state 0x%x\n",
4634 elem->message.opcode, bp->state);
4640 smp_mb__before_atomic_inc();
4641 atomic_add(spqe_cnt, &bp->eq_spq_left);
4643 bp->eq_cons = sw_cons;
4644 bp->eq_prod = sw_prod;
4645 /* Make sure that above mem writes were issued towards the memory */
4648 /* update producer */
4649 bnx2x_update_eq_prod(bp, bp->eq_prod);
4652 static void bnx2x_sp_task(struct work_struct *work)
4654 struct bnx2x *bp = container_of(work, struct bnx2x, sp_task.work);
4657 status = bnx2x_update_dsb_idx(bp);
4658 /* if (status == 0) */
4659 /* BNX2X_ERR("spurious slowpath interrupt!\n"); */
4661 DP(BNX2X_MSG_SP, "got a slowpath interrupt (status 0x%x)\n", status);
4664 if (status & BNX2X_DEF_SB_ATT_IDX) {
4666 status &= ~BNX2X_DEF_SB_ATT_IDX;
4669 /* SP events: STAT_QUERY and others */
4670 if (status & BNX2X_DEF_SB_IDX) {
4672 struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);
4674 if ((!NO_FCOE(bp)) &&
4675 (bnx2x_has_rx_work(fp) || bnx2x_has_tx_work(fp))) {
4677 * Prevent local bottom-halves from running as
4678 * we are going to change the local NAPI list.
4681 napi_schedule(&bnx2x_fcoe(bp, napi));
4685 /* Handle EQ completions */
4688 bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID,
4689 le16_to_cpu(bp->def_idx), IGU_INT_NOP, 1);
4691 status &= ~BNX2X_DEF_SB_IDX;
4694 if (unlikely(status))
4695 DP(BNX2X_MSG_SP, "got an unknown interrupt! (status 0x%x)\n",
4698 bnx2x_ack_sb(bp, bp->igu_dsb_id, ATTENTION_ID,
4699 le16_to_cpu(bp->def_att_idx), IGU_INT_ENABLE, 1);
4702 irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance)
4704 struct net_device *dev = dev_instance;
4705 struct bnx2x *bp = netdev_priv(dev);
4707 bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0,
4708 IGU_INT_DISABLE, 0);
4710 #ifdef BNX2X_STOP_ON_ERROR
4711 if (unlikely(bp->panic))
4717 struct cnic_ops *c_ops;
4720 c_ops = rcu_dereference(bp->cnic_ops);
4722 c_ops->cnic_handler(bp->cnic_data, NULL);
4726 queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
4731 /* end of slow path */
4734 void bnx2x_drv_pulse(struct bnx2x *bp)
4736 SHMEM_WR(bp, func_mb[BP_FW_MB_IDX(bp)].drv_pulse_mb,
4737 bp->fw_drv_pulse_wr_seq);
4741 static void bnx2x_timer(unsigned long data)
4743 struct bnx2x *bp = (struct bnx2x *) data;
4745 if (!netif_running(bp->dev))
4748 if (!BP_NOMCP(bp)) {
4749 int mb_idx = BP_FW_MB_IDX(bp);
4753 ++bp->fw_drv_pulse_wr_seq;
4754 bp->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK;
4755 /* TBD - add SYSTEM_TIME */
4756 drv_pulse = bp->fw_drv_pulse_wr_seq;
4757 bnx2x_drv_pulse(bp);
4759 mcp_pulse = (SHMEM_RD(bp, func_mb[mb_idx].mcp_pulse_mb) &
4760 MCP_PULSE_SEQ_MASK);
4761 /* The delta between driver pulse and mcp response
4762 * should be 1 (before mcp response) or 0 (after mcp response)
4764 if ((drv_pulse != mcp_pulse) &&
4765 (drv_pulse != ((mcp_pulse + 1) & MCP_PULSE_SEQ_MASK))) {
4766 /* someone lost a heartbeat... */
4767 BNX2X_ERR("drv_pulse (0x%x) != mcp_pulse (0x%x)\n",
4768 drv_pulse, mcp_pulse);
4772 if (bp->state == BNX2X_STATE_OPEN)
4773 bnx2x_stats_handle(bp, STATS_EVENT_UPDATE);
4775 mod_timer(&bp->timer, jiffies + bp->current_interval);
4778 /* end of Statistics */
4783 * nic init service functions
4786 static inline void bnx2x_fill(struct bnx2x *bp, u32 addr, int fill, u32 len)
4789 if (!(len%4) && !(addr%4))
4790 for (i = 0; i < len; i += 4)
4791 REG_WR(bp, addr + i, fill);
4793 for (i = 0; i < len; i++)
4794 REG_WR8(bp, addr + i, fill);
4798 /* helper: writes FP SP data to FW - data_size in dwords */
4799 static inline void bnx2x_wr_fp_sb_data(struct bnx2x *bp,
4805 for (index = 0; index < data_size; index++)
4806 REG_WR(bp, BAR_CSTRORM_INTMEM +
4807 CSTORM_STATUS_BLOCK_DATA_OFFSET(fw_sb_id) +
4809 *(sb_data_p + index));
4812 static inline void bnx2x_zero_fp_sb(struct bnx2x *bp, int fw_sb_id)
4816 struct hc_status_block_data_e2 sb_data_e2;
4817 struct hc_status_block_data_e1x sb_data_e1x;
4819 /* disable the function first */
4820 if (!CHIP_IS_E1x(bp)) {
4821 memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
4822 sb_data_e2.common.state = SB_DISABLED;
4823 sb_data_e2.common.p_func.vf_valid = false;
4824 sb_data_p = (u32 *)&sb_data_e2;
4825 data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
4827 memset(&sb_data_e1x, 0,
4828 sizeof(struct hc_status_block_data_e1x));
4829 sb_data_e1x.common.state = SB_DISABLED;
4830 sb_data_e1x.common.p_func.vf_valid = false;
4831 sb_data_p = (u32 *)&sb_data_e1x;
4832 data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
4834 bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
4836 bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
4837 CSTORM_STATUS_BLOCK_OFFSET(fw_sb_id), 0,
4838 CSTORM_STATUS_BLOCK_SIZE);
4839 bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
4840 CSTORM_SYNC_BLOCK_OFFSET(fw_sb_id), 0,
4841 CSTORM_SYNC_BLOCK_SIZE);
4844 /* helper: writes SP SB data to FW */
4845 static inline void bnx2x_wr_sp_sb_data(struct bnx2x *bp,
4846 struct hc_sp_status_block_data *sp_sb_data)
4848 int func = BP_FUNC(bp);
4850 for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
4851 REG_WR(bp, BAR_CSTRORM_INTMEM +
4852 CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
4854 *((u32 *)sp_sb_data + i));
4857 static inline void bnx2x_zero_sp_sb(struct bnx2x *bp)
4859 int func = BP_FUNC(bp);
4860 struct hc_sp_status_block_data sp_sb_data;
4861 memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
4863 sp_sb_data.state = SB_DISABLED;
4864 sp_sb_data.p_func.vf_valid = false;
4866 bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
4868 bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
4869 CSTORM_SP_STATUS_BLOCK_OFFSET(func), 0,
4870 CSTORM_SP_STATUS_BLOCK_SIZE);
4871 bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
4872 CSTORM_SP_SYNC_BLOCK_OFFSET(func), 0,
4873 CSTORM_SP_SYNC_BLOCK_SIZE);
4879 void bnx2x_setup_ndsb_state_machine(struct hc_status_block_sm *hc_sm,
4880 int igu_sb_id, int igu_seg_id)
4882 hc_sm->igu_sb_id = igu_sb_id;
4883 hc_sm->igu_seg_id = igu_seg_id;
4884 hc_sm->timer_value = 0xFF;
4885 hc_sm->time_to_expire = 0xFFFFFFFF;
4889 /* allocates state machine ids. */
4891 void bnx2x_map_sb_state_machines(struct hc_index_data *index_data)
4893 /* zero out state machine indices */
4895 index_data[HC_INDEX_ETH_RX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
4898 index_data[HC_INDEX_OOO_TX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
4899 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags &= ~HC_INDEX_DATA_SM_ID;
4900 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags &= ~HC_INDEX_DATA_SM_ID;
4901 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags &= ~HC_INDEX_DATA_SM_ID;
4905 index_data[HC_INDEX_ETH_RX_CQ_CONS].flags |=
4906 SM_RX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
4909 index_data[HC_INDEX_OOO_TX_CQ_CONS].flags |=
4910 SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
4911 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags |=
4912 SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
4913 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags |=
4914 SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
4915 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags |=
4916 SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
4919 static void bnx2x_init_sb(struct bnx2x *bp, dma_addr_t mapping, int vfid,
4920 u8 vf_valid, int fw_sb_id, int igu_sb_id)
4924 struct hc_status_block_data_e2 sb_data_e2;
4925 struct hc_status_block_data_e1x sb_data_e1x;
4926 struct hc_status_block_sm *hc_sm_p;
4930 if (CHIP_INT_MODE_IS_BC(bp))
4931 igu_seg_id = HC_SEG_ACCESS_NORM;
4933 igu_seg_id = IGU_SEG_ACCESS_NORM;
4935 bnx2x_zero_fp_sb(bp, fw_sb_id);
4937 if (!CHIP_IS_E1x(bp)) {
4938 memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
4939 sb_data_e2.common.state = SB_ENABLED;
4940 sb_data_e2.common.p_func.pf_id = BP_FUNC(bp);
4941 sb_data_e2.common.p_func.vf_id = vfid;
4942 sb_data_e2.common.p_func.vf_valid = vf_valid;
4943 sb_data_e2.common.p_func.vnic_id = BP_VN(bp);
4944 sb_data_e2.common.same_igu_sb_1b = true;
4945 sb_data_e2.common.host_sb_addr.hi = U64_HI(mapping);
4946 sb_data_e2.common.host_sb_addr.lo = U64_LO(mapping);
4947 hc_sm_p = sb_data_e2.common.state_machine;
4948 sb_data_p = (u32 *)&sb_data_e2;
4949 data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
4950 bnx2x_map_sb_state_machines(sb_data_e2.index_data);
4952 memset(&sb_data_e1x, 0,
4953 sizeof(struct hc_status_block_data_e1x));
4954 sb_data_e1x.common.state = SB_ENABLED;
4955 sb_data_e1x.common.p_func.pf_id = BP_FUNC(bp);
4956 sb_data_e1x.common.p_func.vf_id = 0xff;
4957 sb_data_e1x.common.p_func.vf_valid = false;
4958 sb_data_e1x.common.p_func.vnic_id = BP_VN(bp);
4959 sb_data_e1x.common.same_igu_sb_1b = true;
4960 sb_data_e1x.common.host_sb_addr.hi = U64_HI(mapping);
4961 sb_data_e1x.common.host_sb_addr.lo = U64_LO(mapping);
4962 hc_sm_p = sb_data_e1x.common.state_machine;
4963 sb_data_p = (u32 *)&sb_data_e1x;
4964 data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
4965 bnx2x_map_sb_state_machines(sb_data_e1x.index_data);
4968 bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_RX_ID],
4969 igu_sb_id, igu_seg_id);
4970 bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_TX_ID],
4971 igu_sb_id, igu_seg_id);
4973 DP(NETIF_MSG_IFUP, "Init FW SB %d\n", fw_sb_id);
4975 /* write indecies to HW */
4976 bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
4979 static void bnx2x_update_coalesce_sb(struct bnx2x *bp, u8 fw_sb_id,
4980 u16 tx_usec, u16 rx_usec)
4982 bnx2x_update_coalesce_sb_index(bp, fw_sb_id, HC_INDEX_ETH_RX_CQ_CONS,
4984 bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
4985 HC_INDEX_ETH_TX_CQ_CONS_COS0, false,
4987 bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
4988 HC_INDEX_ETH_TX_CQ_CONS_COS1, false,
4990 bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
4991 HC_INDEX_ETH_TX_CQ_CONS_COS2, false,
4995 static void bnx2x_init_def_sb(struct bnx2x *bp)
4997 struct host_sp_status_block *def_sb = bp->def_status_blk;
4998 dma_addr_t mapping = bp->def_status_blk_mapping;
4999 int igu_sp_sb_index;
5001 int port = BP_PORT(bp);
5002 int func = BP_FUNC(bp);
5003 int reg_offset, reg_offset_en5;
5006 struct hc_sp_status_block_data sp_sb_data;
5007 memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
5009 if (CHIP_INT_MODE_IS_BC(bp)) {
5010 igu_sp_sb_index = DEF_SB_IGU_ID;
5011 igu_seg_id = HC_SEG_ACCESS_DEF;
5013 igu_sp_sb_index = bp->igu_dsb_id;
5014 igu_seg_id = IGU_SEG_ACCESS_DEF;
5018 section = ((u64)mapping) + offsetof(struct host_sp_status_block,
5019 atten_status_block);
5020 def_sb->atten_status_block.status_block_id = igu_sp_sb_index;
5024 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
5025 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
5026 reg_offset_en5 = (port ? MISC_REG_AEU_ENABLE5_FUNC_1_OUT_0 :
5027 MISC_REG_AEU_ENABLE5_FUNC_0_OUT_0);
5028 for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
5030 /* take care of sig[0]..sig[4] */
5031 for (sindex = 0; sindex < 4; sindex++)
5032 bp->attn_group[index].sig[sindex] =
5033 REG_RD(bp, reg_offset + sindex*0x4 + 0x10*index);
5035 if (!CHIP_IS_E1x(bp))
5037 * enable5 is separate from the rest of the registers,
5038 * and therefore the address skip is 4
5039 * and not 16 between the different groups
5041 bp->attn_group[index].sig[4] = REG_RD(bp,
5042 reg_offset_en5 + 0x4*index);
5044 bp->attn_group[index].sig[4] = 0;
5047 if (bp->common.int_block == INT_BLOCK_HC) {
5048 reg_offset = (port ? HC_REG_ATTN_MSG1_ADDR_L :
5049 HC_REG_ATTN_MSG0_ADDR_L);
5051 REG_WR(bp, reg_offset, U64_LO(section));
5052 REG_WR(bp, reg_offset + 4, U64_HI(section));
5053 } else if (!CHIP_IS_E1x(bp)) {
5054 REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_L, U64_LO(section));
5055 REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_H, U64_HI(section));
5058 section = ((u64)mapping) + offsetof(struct host_sp_status_block,
5061 bnx2x_zero_sp_sb(bp);
5063 sp_sb_data.state = SB_ENABLED;
5064 sp_sb_data.host_sb_addr.lo = U64_LO(section);
5065 sp_sb_data.host_sb_addr.hi = U64_HI(section);
5066 sp_sb_data.igu_sb_id = igu_sp_sb_index;
5067 sp_sb_data.igu_seg_id = igu_seg_id;
5068 sp_sb_data.p_func.pf_id = func;
5069 sp_sb_data.p_func.vnic_id = BP_VN(bp);
5070 sp_sb_data.p_func.vf_id = 0xff;
5072 bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
5074 bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0, IGU_INT_ENABLE, 0);
5077 void bnx2x_update_coalesce(struct bnx2x *bp)
5081 for_each_eth_queue(bp, i)
5082 bnx2x_update_coalesce_sb(bp, bp->fp[i].fw_sb_id,
5083 bp->tx_ticks, bp->rx_ticks);
5086 static void bnx2x_init_sp_ring(struct bnx2x *bp)
5088 spin_lock_init(&bp->spq_lock);
5089 atomic_set(&bp->cq_spq_left, MAX_SPQ_PENDING);
5091 bp->spq_prod_idx = 0;
5092 bp->dsb_sp_prod = BNX2X_SP_DSB_INDEX;
5093 bp->spq_prod_bd = bp->spq;
5094 bp->spq_last_bd = bp->spq_prod_bd + MAX_SP_DESC_CNT;
5097 static void bnx2x_init_eq_ring(struct bnx2x *bp)
5100 for (i = 1; i <= NUM_EQ_PAGES; i++) {
5101 union event_ring_elem *elem =
5102 &bp->eq_ring[EQ_DESC_CNT_PAGE * i - 1];
5104 elem->next_page.addr.hi =
5105 cpu_to_le32(U64_HI(bp->eq_mapping +
5106 BCM_PAGE_SIZE * (i % NUM_EQ_PAGES)));
5107 elem->next_page.addr.lo =
5108 cpu_to_le32(U64_LO(bp->eq_mapping +
5109 BCM_PAGE_SIZE*(i % NUM_EQ_PAGES)));
5112 bp->eq_prod = NUM_EQ_DESC;
5113 bp->eq_cons_sb = BNX2X_EQ_INDEX;
5114 /* we want a warning message before it gets rought... */
5115 atomic_set(&bp->eq_spq_left,
5116 min_t(int, MAX_SP_DESC_CNT - MAX_SPQ_PENDING, NUM_EQ_DESC) - 1);
5120 /* called with netif_addr_lock_bh() */
5121 void bnx2x_set_q_rx_mode(struct bnx2x *bp, u8 cl_id,
5122 unsigned long rx_mode_flags,
5123 unsigned long rx_accept_flags,
5124 unsigned long tx_accept_flags,
5125 unsigned long ramrod_flags)
5127 struct bnx2x_rx_mode_ramrod_params ramrod_param;
5130 memset(&ramrod_param, 0, sizeof(ramrod_param));
5132 /* Prepare ramrod parameters */
5133 ramrod_param.cid = 0;
5134 ramrod_param.cl_id = cl_id;
5135 ramrod_param.rx_mode_obj = &bp->rx_mode_obj;
5136 ramrod_param.func_id = BP_FUNC(bp);
5138 ramrod_param.pstate = &bp->sp_state;
5139 ramrod_param.state = BNX2X_FILTER_RX_MODE_PENDING;
5141 ramrod_param.rdata = bnx2x_sp(bp, rx_mode_rdata);
5142 ramrod_param.rdata_mapping = bnx2x_sp_mapping(bp, rx_mode_rdata);
5144 set_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
5146 ramrod_param.ramrod_flags = ramrod_flags;
5147 ramrod_param.rx_mode_flags = rx_mode_flags;
5149 ramrod_param.rx_accept_flags = rx_accept_flags;
5150 ramrod_param.tx_accept_flags = tx_accept_flags;
5152 rc = bnx2x_config_rx_mode(bp, &ramrod_param);
5154 BNX2X_ERR("Set rx_mode %d failed\n", bp->rx_mode);
5159 /* called with netif_addr_lock_bh() */
5160 void bnx2x_set_storm_rx_mode(struct bnx2x *bp)
5162 unsigned long rx_mode_flags = 0, ramrod_flags = 0;
5163 unsigned long rx_accept_flags = 0, tx_accept_flags = 0;
5168 /* Configure rx_mode of FCoE Queue */
5169 __set_bit(BNX2X_RX_MODE_FCOE_ETH, &rx_mode_flags);
5172 switch (bp->rx_mode) {
5173 case BNX2X_RX_MODE_NONE:
5175 * 'drop all' supersedes any accept flags that may have been
5176 * passed to the function.
5179 case BNX2X_RX_MODE_NORMAL:
5180 __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
5181 __set_bit(BNX2X_ACCEPT_MULTICAST, &rx_accept_flags);
5182 __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
5184 /* internal switching mode */
5185 __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
5186 __set_bit(BNX2X_ACCEPT_MULTICAST, &tx_accept_flags);
5187 __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
5190 case BNX2X_RX_MODE_ALLMULTI:
5191 __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
5192 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &rx_accept_flags);
5193 __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
5195 /* internal switching mode */
5196 __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
5197 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &tx_accept_flags);
5198 __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
5201 case BNX2X_RX_MODE_PROMISC:
5202 /* According to deffinition of SI mode, iface in promisc mode
5203 * should receive matched and unmatched (in resolution of port)
5206 __set_bit(BNX2X_ACCEPT_UNMATCHED, &rx_accept_flags);
5207 __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
5208 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &rx_accept_flags);
5209 __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
5211 /* internal switching mode */
5212 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &tx_accept_flags);
5213 __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
5216 __set_bit(BNX2X_ACCEPT_ALL_UNICAST, &tx_accept_flags);
5218 __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
5222 BNX2X_ERR("Unknown rx_mode: %d\n", bp->rx_mode);
5226 if (bp->rx_mode != BNX2X_RX_MODE_NONE) {
5227 __set_bit(BNX2X_ACCEPT_ANY_VLAN, &rx_accept_flags);
5228 __set_bit(BNX2X_ACCEPT_ANY_VLAN, &tx_accept_flags);
5231 __set_bit(RAMROD_RX, &ramrod_flags);
5232 __set_bit(RAMROD_TX, &ramrod_flags);
5234 bnx2x_set_q_rx_mode(bp, bp->fp->cl_id, rx_mode_flags, rx_accept_flags,
5235 tx_accept_flags, ramrod_flags);
5238 static void bnx2x_init_internal_common(struct bnx2x *bp)
5244 * In switch independent mode, the TSTORM needs to accept
5245 * packets that failed classification, since approximate match
5246 * mac addresses aren't written to NIG LLH
5248 REG_WR8(bp, BAR_TSTRORM_INTMEM +
5249 TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 2);
5250 else if (!CHIP_IS_E1(bp)) /* 57710 doesn't support MF */
5251 REG_WR8(bp, BAR_TSTRORM_INTMEM +
5252 TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 0);
5254 /* Zero this manually as its initialization is
5255 currently missing in the initTool */
5256 for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++)
5257 REG_WR(bp, BAR_USTRORM_INTMEM +
5258 USTORM_AGG_DATA_OFFSET + i * 4, 0);
5259 if (!CHIP_IS_E1x(bp)) {
5260 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_IGU_MODE_OFFSET,
5261 CHIP_INT_MODE_IS_BC(bp) ?
5262 HC_IGU_BC_MODE : HC_IGU_NBC_MODE);
5266 static void bnx2x_init_internal(struct bnx2x *bp, u32 load_code)
5268 switch (load_code) {
5269 case FW_MSG_CODE_DRV_LOAD_COMMON:
5270 case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP:
5271 bnx2x_init_internal_common(bp);
5274 case FW_MSG_CODE_DRV_LOAD_PORT:
5278 case FW_MSG_CODE_DRV_LOAD_FUNCTION:
5279 /* internal memory per function is
5280 initialized inside bnx2x_pf_init */
5284 BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code);
5289 static inline u8 bnx2x_fp_igu_sb_id(struct bnx2x_fastpath *fp)
5291 return fp->bp->igu_base_sb + fp->index + CNIC_PRESENT;
5294 static inline u8 bnx2x_fp_fw_sb_id(struct bnx2x_fastpath *fp)
5296 return fp->bp->base_fw_ndsb + fp->index + CNIC_PRESENT;
5299 static inline u8 bnx2x_fp_cl_id(struct bnx2x_fastpath *fp)
5301 if (CHIP_IS_E1x(fp->bp))
5302 return BP_L_ID(fp->bp) + fp->index;
5303 else /* We want Client ID to be the same as IGU SB ID for 57712 */
5304 return bnx2x_fp_igu_sb_id(fp);
5307 static void bnx2x_init_eth_fp(struct bnx2x *bp, int fp_idx)
5309 struct bnx2x_fastpath *fp = &bp->fp[fp_idx];
5311 unsigned long q_type = 0;
5312 u32 cids[BNX2X_MULTI_TX_COS] = { 0 };
5313 fp->rx_queue = fp_idx;
5315 fp->cl_id = bnx2x_fp_cl_id(fp);
5316 fp->fw_sb_id = bnx2x_fp_fw_sb_id(fp);
5317 fp->igu_sb_id = bnx2x_fp_igu_sb_id(fp);
5318 /* qZone id equals to FW (per path) client id */
5319 fp->cl_qzone_id = bnx2x_fp_qzone_id(fp);
5322 fp->ustorm_rx_prods_offset = bnx2x_rx_ustorm_prods_offset(fp);
5324 /* Setup SB indicies */
5325 fp->rx_cons_sb = BNX2X_RX_SB_INDEX;
5327 /* Configure Queue State object */
5328 __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
5329 __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
5331 BUG_ON(fp->max_cos > BNX2X_MULTI_TX_COS);
5334 for_each_cos_in_tx_queue(fp, cos) {
5335 bnx2x_init_txdata(bp, &fp->txdata[cos],
5336 CID_COS_TO_TX_ONLY_CID(fp->cid, cos),
5337 FP_COS_TO_TXQ(fp, cos),
5338 BNX2X_TX_SB_INDEX_BASE + cos);
5339 cids[cos] = fp->txdata[cos].cid;
5342 bnx2x_init_queue_obj(bp, &fp->q_obj, fp->cl_id, cids, fp->max_cos,
5343 BP_FUNC(bp), bnx2x_sp(bp, q_rdata),
5344 bnx2x_sp_mapping(bp, q_rdata), q_type);
5347 * Configure classification DBs: Always enable Tx switching
5349 bnx2x_init_vlan_mac_fp_objs(fp, BNX2X_OBJ_TYPE_RX_TX);
5351 DP(NETIF_MSG_IFUP, "queue[%d]: bnx2x_init_sb(%p,%p) cl_id %d fw_sb %d igu_sb %d\n",
5352 fp_idx, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id,
5354 bnx2x_init_sb(bp, fp->status_blk_mapping, BNX2X_VF_ID_INVALID, false,
5355 fp->fw_sb_id, fp->igu_sb_id);
5357 bnx2x_update_fpsb_idx(fp);
5360 void bnx2x_nic_init(struct bnx2x *bp, u32 load_code)
5364 for_each_eth_queue(bp, i)
5365 bnx2x_init_eth_fp(bp, i);
5368 bnx2x_init_fcoe_fp(bp);
5370 bnx2x_init_sb(bp, bp->cnic_sb_mapping,
5371 BNX2X_VF_ID_INVALID, false,
5372 bnx2x_cnic_fw_sb_id(bp), bnx2x_cnic_igu_sb_id(bp));
5376 /* Initialize MOD_ABS interrupts */
5377 bnx2x_init_mod_abs_int(bp, &bp->link_vars, bp->common.chip_id,
5378 bp->common.shmem_base, bp->common.shmem2_base,
5380 /* ensure status block indices were read */
5383 bnx2x_init_def_sb(bp);
5384 bnx2x_update_dsb_idx(bp);
5385 bnx2x_init_rx_rings(bp);
5386 bnx2x_init_tx_rings(bp);
5387 bnx2x_init_sp_ring(bp);
5388 bnx2x_init_eq_ring(bp);
5389 bnx2x_init_internal(bp, load_code);
5391 bnx2x_stats_init(bp);
5393 /* flush all before enabling interrupts */
5397 bnx2x_int_enable(bp);
5399 /* Check for SPIO5 */
5400 bnx2x_attn_int_deasserted0(bp,
5401 REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + BP_PORT(bp)*4) &
5402 AEU_INPUTS_ATTN_BITS_SPIO5);
5405 /* end of nic init */
5408 * gzip service functions
5411 static int bnx2x_gunzip_init(struct bnx2x *bp)
5413 bp->gunzip_buf = dma_alloc_coherent(&bp->pdev->dev, FW_BUF_SIZE,
5414 &bp->gunzip_mapping, GFP_KERNEL);
5415 if (bp->gunzip_buf == NULL)
5418 bp->strm = kmalloc(sizeof(*bp->strm), GFP_KERNEL);
5419 if (bp->strm == NULL)
5422 bp->strm->workspace = vmalloc(zlib_inflate_workspacesize());
5423 if (bp->strm->workspace == NULL)
5433 dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
5434 bp->gunzip_mapping);
5435 bp->gunzip_buf = NULL;
5438 BNX2X_ERR("Cannot allocate firmware buffer for un-compression\n");
5442 static void bnx2x_gunzip_end(struct bnx2x *bp)
5445 vfree(bp->strm->workspace);
5450 if (bp->gunzip_buf) {
5451 dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
5452 bp->gunzip_mapping);
5453 bp->gunzip_buf = NULL;
5457 static int bnx2x_gunzip(struct bnx2x *bp, const u8 *zbuf, int len)
5461 /* check gzip header */
5462 if ((zbuf[0] != 0x1f) || (zbuf[1] != 0x8b) || (zbuf[2] != Z_DEFLATED)) {
5463 BNX2X_ERR("Bad gzip header\n");
5471 if (zbuf[3] & FNAME)
5472 while ((zbuf[n++] != 0) && (n < len));
5474 bp->strm->next_in = (typeof(bp->strm->next_in))zbuf + n;
5475 bp->strm->avail_in = len - n;
5476 bp->strm->next_out = bp->gunzip_buf;
5477 bp->strm->avail_out = FW_BUF_SIZE;
5479 rc = zlib_inflateInit2(bp->strm, -MAX_WBITS);
5483 rc = zlib_inflate(bp->strm, Z_FINISH);
5484 if ((rc != Z_OK) && (rc != Z_STREAM_END))
5485 netdev_err(bp->dev, "Firmware decompression error: %s\n",
5488 bp->gunzip_outlen = (FW_BUF_SIZE - bp->strm->avail_out);
5489 if (bp->gunzip_outlen & 0x3)
5491 "Firmware decompression error: gunzip_outlen (%d) not aligned\n",
5493 bp->gunzip_outlen >>= 2;
5495 zlib_inflateEnd(bp->strm);
5497 if (rc == Z_STREAM_END)
5503 /* nic load/unload */
5506 * General service functions
5509 /* send a NIG loopback debug packet */
5510 static void bnx2x_lb_pckt(struct bnx2x *bp)
5514 /* Ethernet source and destination addresses */
5515 wb_write[0] = 0x55555555;
5516 wb_write[1] = 0x55555555;
5517 wb_write[2] = 0x20; /* SOP */
5518 REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
5520 /* NON-IP protocol */
5521 wb_write[0] = 0x09000000;
5522 wb_write[1] = 0x55555555;
5523 wb_write[2] = 0x10; /* EOP, eop_bvalid = 0 */
5524 REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
5527 /* some of the internal memories
5528 * are not directly readable from the driver
5529 * to test them we send debug packets
5531 static int bnx2x_int_mem_test(struct bnx2x *bp)
5537 if (CHIP_REV_IS_FPGA(bp))
5539 else if (CHIP_REV_IS_EMUL(bp))
5544 /* Disable inputs of parser neighbor blocks */
5545 REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
5546 REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
5547 REG_WR(bp, CFC_REG_DEBUG0, 0x1);
5548 REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
5550 /* Write 0 to parser credits for CFC search request */
5551 REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
5553 /* send Ethernet packet */
5556 /* TODO do i reset NIG statistic? */
5557 /* Wait until NIG register shows 1 packet of size 0x10 */
5558 count = 1000 * factor;
5561 bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
5562 val = *bnx2x_sp(bp, wb_data[0]);
5570 BNX2X_ERR("NIG timeout val = 0x%x\n", val);
5574 /* Wait until PRS register shows 1 packet */
5575 count = 1000 * factor;
5577 val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
5585 BNX2X_ERR("PRS timeout val = 0x%x\n", val);
5589 /* Reset and init BRB, PRS */
5590 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
5592 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
5594 bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
5595 bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
5597 DP(NETIF_MSG_HW, "part2\n");
5599 /* Disable inputs of parser neighbor blocks */
5600 REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
5601 REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
5602 REG_WR(bp, CFC_REG_DEBUG0, 0x1);
5603 REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
5605 /* Write 0 to parser credits for CFC search request */
5606 REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
5608 /* send 10 Ethernet packets */
5609 for (i = 0; i < 10; i++)
5612 /* Wait until NIG register shows 10 + 1
5613 packets of size 11*0x10 = 0xb0 */
5614 count = 1000 * factor;
5617 bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
5618 val = *bnx2x_sp(bp, wb_data[0]);
5626 BNX2X_ERR("NIG timeout val = 0x%x\n", val);
5630 /* Wait until PRS register shows 2 packets */
5631 val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
5633 BNX2X_ERR("PRS timeout val = 0x%x\n", val);
5635 /* Write 1 to parser credits for CFC search request */
5636 REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x1);
5638 /* Wait until PRS register shows 3 packets */
5639 msleep(10 * factor);
5640 /* Wait until NIG register shows 1 packet of size 0x10 */
5641 val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
5643 BNX2X_ERR("PRS timeout val = 0x%x\n", val);
5645 /* clear NIG EOP FIFO */
5646 for (i = 0; i < 11; i++)
5647 REG_RD(bp, NIG_REG_INGRESS_EOP_LB_FIFO);
5648 val = REG_RD(bp, NIG_REG_INGRESS_EOP_LB_EMPTY);
5650 BNX2X_ERR("clear of NIG failed\n");
5654 /* Reset and init BRB, PRS, NIG */
5655 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
5657 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
5659 bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
5660 bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
5663 REG_WR(bp, PRS_REG_NIC_MODE, 1);
5666 /* Enable inputs of parser neighbor blocks */
5667 REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x7fffffff);
5668 REG_WR(bp, TCM_REG_PRS_IFEN, 0x1);
5669 REG_WR(bp, CFC_REG_DEBUG0, 0x0);
5670 REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x1);
5672 DP(NETIF_MSG_HW, "done\n");
5677 static void bnx2x_enable_blocks_attention(struct bnx2x *bp)
5679 REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
5680 if (!CHIP_IS_E1x(bp))
5681 REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0x40);
5683 REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0);
5684 REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
5685 REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
5687 * mask read length error interrupts in brb for parser
5688 * (parsing unit and 'checksum and crc' unit)
5689 * these errors are legal (PU reads fixed length and CAC can cause
5690 * read length error on truncated packets)
5692 REG_WR(bp, BRB1_REG_BRB1_INT_MASK, 0xFC00);
5693 REG_WR(bp, QM_REG_QM_INT_MASK, 0);
5694 REG_WR(bp, TM_REG_TM_INT_MASK, 0);
5695 REG_WR(bp, XSDM_REG_XSDM_INT_MASK_0, 0);
5696 REG_WR(bp, XSDM_REG_XSDM_INT_MASK_1, 0);
5697 REG_WR(bp, XCM_REG_XCM_INT_MASK, 0);
5698 /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_0, 0); */
5699 /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_1, 0); */
5700 REG_WR(bp, USDM_REG_USDM_INT_MASK_0, 0);
5701 REG_WR(bp, USDM_REG_USDM_INT_MASK_1, 0);
5702 REG_WR(bp, UCM_REG_UCM_INT_MASK, 0);
5703 /* REG_WR(bp, USEM_REG_USEM_INT_MASK_0, 0); */
5704 /* REG_WR(bp, USEM_REG_USEM_INT_MASK_1, 0); */
5705 REG_WR(bp, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0);
5706 REG_WR(bp, CSDM_REG_CSDM_INT_MASK_0, 0);
5707 REG_WR(bp, CSDM_REG_CSDM_INT_MASK_1, 0);
5708 REG_WR(bp, CCM_REG_CCM_INT_MASK, 0);
5709 /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_0, 0); */
5710 /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_1, 0); */
5712 if (CHIP_REV_IS_FPGA(bp))
5713 REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, 0x580000);
5714 else if (!CHIP_IS_E1x(bp))
5715 REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0,
5716 (PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_OF
5717 | PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_AFT
5718 | PXP2_PXP2_INT_MASK_0_REG_PGL_PCIE_ATTN
5719 | PXP2_PXP2_INT_MASK_0_REG_PGL_READ_BLOCKED
5720 | PXP2_PXP2_INT_MASK_0_REG_PGL_WRITE_BLOCKED));
5722 REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, 0x480000);
5723 REG_WR(bp, TSDM_REG_TSDM_INT_MASK_0, 0);
5724 REG_WR(bp, TSDM_REG_TSDM_INT_MASK_1, 0);
5725 REG_WR(bp, TCM_REG_TCM_INT_MASK, 0);
5726 /* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_0, 0); */
5728 if (!CHIP_IS_E1x(bp))
5729 /* enable VFC attentions: bits 11 and 12, bits 31:13 reserved */
5730 REG_WR(bp, TSEM_REG_TSEM_INT_MASK_1, 0x07ff);
5732 REG_WR(bp, CDU_REG_CDU_INT_MASK, 0);
5733 REG_WR(bp, DMAE_REG_DMAE_INT_MASK, 0);
5734 /* REG_WR(bp, MISC_REG_MISC_INT_MASK, 0); */
5735 REG_WR(bp, PBF_REG_PBF_INT_MASK, 0x18); /* bit 3,4 masked */
5738 static void bnx2x_reset_common(struct bnx2x *bp)
5743 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
5746 if (CHIP_IS_E3(bp)) {
5747 val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
5748 val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
5751 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, val);
5754 static void bnx2x_setup_dmae(struct bnx2x *bp)
5757 spin_lock_init(&bp->dmae_lock);
5760 static void bnx2x_init_pxp(struct bnx2x *bp)
5763 int r_order, w_order;
5765 pci_read_config_word(bp->pdev,
5766 pci_pcie_cap(bp->pdev) + PCI_EXP_DEVCTL, &devctl);
5767 DP(NETIF_MSG_HW, "read 0x%x from devctl\n", devctl);
5768 w_order = ((devctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5);
5770 r_order = ((devctl & PCI_EXP_DEVCTL_READRQ) >> 12);
5772 DP(NETIF_MSG_HW, "force read order to %d\n", bp->mrrs);
5776 bnx2x_init_pxp_arb(bp, r_order, w_order);
5779 static void bnx2x_setup_fan_failure_detection(struct bnx2x *bp)
5789 val = SHMEM_RD(bp, dev_info.shared_hw_config.config2) &
5790 SHARED_HW_CFG_FAN_FAILURE_MASK;
5792 if (val == SHARED_HW_CFG_FAN_FAILURE_ENABLED)
5796 * The fan failure mechanism is usually related to the PHY type since
5797 * the power consumption of the board is affected by the PHY. Currently,
5798 * fan is required for most designs with SFX7101, BCM8727 and BCM8481.
5800 else if (val == SHARED_HW_CFG_FAN_FAILURE_PHY_TYPE)
5801 for (port = PORT_0; port < PORT_MAX; port++) {
5803 bnx2x_fan_failure_det_req(
5805 bp->common.shmem_base,
5806 bp->common.shmem2_base,
5810 DP(NETIF_MSG_HW, "fan detection setting: %d\n", is_required);
5812 if (is_required == 0)
5815 /* Fan failure is indicated by SPIO 5 */
5816 bnx2x_set_spio(bp, MISC_REGISTERS_SPIO_5,
5817 MISC_REGISTERS_SPIO_INPUT_HI_Z);
5819 /* set to active low mode */
5820 val = REG_RD(bp, MISC_REG_SPIO_INT);
5821 val |= ((1 << MISC_REGISTERS_SPIO_5) <<
5822 MISC_REGISTERS_SPIO_INT_OLD_SET_POS);
5823 REG_WR(bp, MISC_REG_SPIO_INT, val);
5825 /* enable interrupt to signal the IGU */
5826 val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
5827 val |= (1 << MISC_REGISTERS_SPIO_5);
5828 REG_WR(bp, MISC_REG_SPIO_EVENT_EN, val);
5831 static void bnx2x_pretend_func(struct bnx2x *bp, u8 pretend_func_num)
5837 if (CHIP_IS_E1H(bp) && (pretend_func_num >= E1H_FUNC_MAX))
5840 switch (BP_ABS_FUNC(bp)) {
5842 offset = PXP2_REG_PGL_PRETEND_FUNC_F0;
5845 offset = PXP2_REG_PGL_PRETEND_FUNC_F1;
5848 offset = PXP2_REG_PGL_PRETEND_FUNC_F2;
5851 offset = PXP2_REG_PGL_PRETEND_FUNC_F3;
5854 offset = PXP2_REG_PGL_PRETEND_FUNC_F4;
5857 offset = PXP2_REG_PGL_PRETEND_FUNC_F5;
5860 offset = PXP2_REG_PGL_PRETEND_FUNC_F6;
5863 offset = PXP2_REG_PGL_PRETEND_FUNC_F7;
5869 REG_WR(bp, offset, pretend_func_num);
5871 DP(NETIF_MSG_HW, "Pretending to func %d\n", pretend_func_num);
5874 void bnx2x_pf_disable(struct bnx2x *bp)
5876 u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
5877 val &= ~IGU_PF_CONF_FUNC_EN;
5879 REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
5880 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
5881 REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 0);
5884 static inline void bnx2x__common_init_phy(struct bnx2x *bp)
5886 u32 shmem_base[2], shmem2_base[2];
5887 shmem_base[0] = bp->common.shmem_base;
5888 shmem2_base[0] = bp->common.shmem2_base;
5889 if (!CHIP_IS_E1x(bp)) {
5891 SHMEM2_RD(bp, other_shmem_base_addr);
5893 SHMEM2_RD(bp, other_shmem2_base_addr);
5895 bnx2x_acquire_phy_lock(bp);
5896 bnx2x_common_init_phy(bp, shmem_base, shmem2_base,
5897 bp->common.chip_id);
5898 bnx2x_release_phy_lock(bp);
5902 * bnx2x_init_hw_common - initialize the HW at the COMMON phase.
5904 * @bp: driver handle
5906 static int bnx2x_init_hw_common(struct bnx2x *bp)
5910 DP(NETIF_MSG_HW, "starting common init func %d\n", BP_ABS_FUNC(bp));
5913 * take the UNDI lock to protect undi_unload flow from accessing
5914 * registers while we're resetting the chip
5916 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
5918 bnx2x_reset_common(bp);
5919 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0xffffffff);
5922 if (CHIP_IS_E3(bp)) {
5923 val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
5924 val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
5926 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, val);
5928 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
5930 bnx2x_init_block(bp, BLOCK_MISC, PHASE_COMMON);
5932 if (!CHIP_IS_E1x(bp)) {
5936 * 4-port mode or 2-port mode we need to turn of master-enable
5937 * for everyone, after that, turn it back on for self.
5938 * so, we disregard multi-function or not, and always disable
5939 * for all functions on the given path, this means 0,2,4,6 for
5940 * path 0 and 1,3,5,7 for path 1
5942 for (abs_func_id = BP_PATH(bp);
5943 abs_func_id < E2_FUNC_MAX*2; abs_func_id += 2) {
5944 if (abs_func_id == BP_ABS_FUNC(bp)) {
5946 PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER,
5951 bnx2x_pretend_func(bp, abs_func_id);
5952 /* clear pf enable */
5953 bnx2x_pf_disable(bp);
5954 bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
5958 bnx2x_init_block(bp, BLOCK_PXP, PHASE_COMMON);
5959 if (CHIP_IS_E1(bp)) {
5960 /* enable HW interrupt from PXP on USDM overflow
5961 bit 16 on INT_MASK_0 */
5962 REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
5965 bnx2x_init_block(bp, BLOCK_PXP2, PHASE_COMMON);
5969 REG_WR(bp, PXP2_REG_RQ_QM_ENDIAN_M, 1);
5970 REG_WR(bp, PXP2_REG_RQ_TM_ENDIAN_M, 1);
5971 REG_WR(bp, PXP2_REG_RQ_SRC_ENDIAN_M, 1);
5972 REG_WR(bp, PXP2_REG_RQ_CDU_ENDIAN_M, 1);
5973 REG_WR(bp, PXP2_REG_RQ_DBG_ENDIAN_M, 1);
5974 /* make sure this value is 0 */
5975 REG_WR(bp, PXP2_REG_RQ_HC_ENDIAN_M, 0);
5977 /* REG_WR(bp, PXP2_REG_RD_PBF_SWAP_MODE, 1); */
5978 REG_WR(bp, PXP2_REG_RD_QM_SWAP_MODE, 1);
5979 REG_WR(bp, PXP2_REG_RD_TM_SWAP_MODE, 1);
5980 REG_WR(bp, PXP2_REG_RD_SRC_SWAP_MODE, 1);
5981 REG_WR(bp, PXP2_REG_RD_CDURD_SWAP_MODE, 1);
5984 bnx2x_ilt_init_page_size(bp, INITOP_SET);
5986 if (CHIP_REV_IS_FPGA(bp) && CHIP_IS_E1H(bp))
5987 REG_WR(bp, PXP2_REG_PGL_TAGS_LIMIT, 0x1);
5989 /* let the HW do it's magic ... */
5991 /* finish PXP init */
5992 val = REG_RD(bp, PXP2_REG_RQ_CFG_DONE);
5994 BNX2X_ERR("PXP2 CFG failed\n");
5997 val = REG_RD(bp, PXP2_REG_RD_INIT_DONE);
5999 BNX2X_ERR("PXP2 RD_INIT failed\n");
6003 /* Timers bug workaround E2 only. We need to set the entire ILT to
6004 * have entries with value "0" and valid bit on.
6005 * This needs to be done by the first PF that is loaded in a path
6006 * (i.e. common phase)
6008 if (!CHIP_IS_E1x(bp)) {
6009 /* In E2 there is a bug in the timers block that can cause function 6 / 7
6010 * (i.e. vnic3) to start even if it is marked as "scan-off".
6011 * This occurs when a different function (func2,3) is being marked
6012 * as "scan-off". Real-life scenario for example: if a driver is being
6013 * load-unloaded while func6,7 are down. This will cause the timer to access
6014 * the ilt, translate to a logical address and send a request to read/write.
6015 * Since the ilt for the function that is down is not valid, this will cause
6016 * a translation error which is unrecoverable.
6017 * The Workaround is intended to make sure that when this happens nothing fatal
6018 * will occur. The workaround:
6019 * 1. First PF driver which loads on a path will:
6020 * a. After taking the chip out of reset, by using pretend,
6021 * it will write "0" to the following registers of
6023 * REG_WR(pdev, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
6024 * REG_WR(pdev, CFC_REG_WEAK_ENABLE_PF,0);
6025 * REG_WR(pdev, CFC_REG_STRONG_ENABLE_PF,0);
6026 * And for itself it will write '1' to
6027 * PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER to enable
6028 * dmae-operations (writing to pram for example.)
6029 * note: can be done for only function 6,7 but cleaner this
6031 * b. Write zero+valid to the entire ILT.
6032 * c. Init the first_timers_ilt_entry, last_timers_ilt_entry of
6033 * VNIC3 (of that port). The range allocated will be the
6034 * entire ILT. This is needed to prevent ILT range error.
6035 * 2. Any PF driver load flow:
6036 * a. ILT update with the physical addresses of the allocated
6038 * b. Wait 20msec. - note that this timeout is needed to make
6039 * sure there are no requests in one of the PXP internal
6040 * queues with "old" ILT addresses.
6041 * c. PF enable in the PGLC.
6042 * d. Clear the was_error of the PF in the PGLC. (could have
6043 * occured while driver was down)
6044 * e. PF enable in the CFC (WEAK + STRONG)
6045 * f. Timers scan enable
6046 * 3. PF driver unload flow:
6047 * a. Clear the Timers scan_en.
6048 * b. Polling for scan_on=0 for that PF.
6049 * c. Clear the PF enable bit in the PXP.
6050 * d. Clear the PF enable in the CFC (WEAK + STRONG)
6051 * e. Write zero+valid to all ILT entries (The valid bit must
6053 * f. If this is VNIC 3 of a port then also init
6054 * first_timers_ilt_entry to zero and last_timers_ilt_entry
6055 * to the last enrty in the ILT.
6058 * Currently the PF error in the PGLC is non recoverable.
6059 * In the future the there will be a recovery routine for this error.
6060 * Currently attention is masked.
6061 * Having an MCP lock on the load/unload process does not guarantee that
6062 * there is no Timer disable during Func6/7 enable. This is because the
6063 * Timers scan is currently being cleared by the MCP on FLR.
6064 * Step 2.d can be done only for PF6/7 and the driver can also check if
6065 * there is error before clearing it. But the flow above is simpler and
6067 * All ILT entries are written by zero+valid and not just PF6/7
6068 * ILT entries since in the future the ILT entries allocation for
6069 * PF-s might be dynamic.
6071 struct ilt_client_info ilt_cli;
6072 struct bnx2x_ilt ilt;
6073 memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
6074 memset(&ilt, 0, sizeof(struct bnx2x_ilt));
6076 /* initialize dummy TM client */
6078 ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
6079 ilt_cli.client_num = ILT_CLIENT_TM;
6081 /* Step 1: set zeroes to all ilt page entries with valid bit on
6082 * Step 2: set the timers first/last ilt entry to point
6083 * to the entire range to prevent ILT range error for 3rd/4th
6084 * vnic (this code assumes existance of the vnic)
6086 * both steps performed by call to bnx2x_ilt_client_init_op()
6087 * with dummy TM client
6089 * we must use pretend since PXP2_REG_RQ_##blk##_FIRST_ILT
6090 * and his brother are split registers
6092 bnx2x_pretend_func(bp, (BP_PATH(bp) + 6));
6093 bnx2x_ilt_client_init_op_ilt(bp, &ilt, &ilt_cli, INITOP_CLEAR);
6094 bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
6096 REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN, BNX2X_PXP_DRAM_ALIGN);
6097 REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_RD, BNX2X_PXP_DRAM_ALIGN);
6098 REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_SEL, 1);
6102 REG_WR(bp, PXP2_REG_RQ_DISABLE_INPUTS, 0);
6103 REG_WR(bp, PXP2_REG_RD_DISABLE_INPUTS, 0);
6105 if (!CHIP_IS_E1x(bp)) {
6106 int factor = CHIP_REV_IS_EMUL(bp) ? 1000 :
6107 (CHIP_REV_IS_FPGA(bp) ? 400 : 0);
6108 bnx2x_init_block(bp, BLOCK_PGLUE_B, PHASE_COMMON);
6110 bnx2x_init_block(bp, BLOCK_ATC, PHASE_COMMON);
6112 /* let the HW do it's magic ... */
6115 val = REG_RD(bp, ATC_REG_ATC_INIT_DONE);
6116 } while (factor-- && (val != 1));
6119 BNX2X_ERR("ATC_INIT failed\n");
6124 bnx2x_init_block(bp, BLOCK_DMAE, PHASE_COMMON);
6126 /* clean the DMAE memory */
6128 bnx2x_init_fill(bp, TSEM_REG_PRAM, 0, 8, 1);
6130 bnx2x_init_block(bp, BLOCK_TCM, PHASE_COMMON);
6132 bnx2x_init_block(bp, BLOCK_UCM, PHASE_COMMON);
6134 bnx2x_init_block(bp, BLOCK_CCM, PHASE_COMMON);
6136 bnx2x_init_block(bp, BLOCK_XCM, PHASE_COMMON);
6138 bnx2x_read_dmae(bp, XSEM_REG_PASSIVE_BUFFER, 3);
6139 bnx2x_read_dmae(bp, CSEM_REG_PASSIVE_BUFFER, 3);
6140 bnx2x_read_dmae(bp, TSEM_REG_PASSIVE_BUFFER, 3);
6141 bnx2x_read_dmae(bp, USEM_REG_PASSIVE_BUFFER, 3);
6143 bnx2x_init_block(bp, BLOCK_QM, PHASE_COMMON);
6146 /* QM queues pointers table */
6147 bnx2x_qm_init_ptr_table(bp, bp->qm_cid_count, INITOP_SET);
6149 /* soft reset pulse */
6150 REG_WR(bp, QM_REG_SOFT_RESET, 1);
6151 REG_WR(bp, QM_REG_SOFT_RESET, 0);
6154 bnx2x_init_block(bp, BLOCK_TM, PHASE_COMMON);
6157 bnx2x_init_block(bp, BLOCK_DORQ, PHASE_COMMON);
6158 REG_WR(bp, DORQ_REG_DPM_CID_OFST, BNX2X_DB_SHIFT);
6159 if (!CHIP_REV_IS_SLOW(bp))
6160 /* enable hw interrupt from doorbell Q */
6161 REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
6163 bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
6165 bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
6166 REG_WR(bp, PRS_REG_A_PRSU_20, 0xf);
6168 if (!CHIP_IS_E1(bp))
6169 REG_WR(bp, PRS_REG_E1HOV_MODE, bp->path_has_ovlan);
6171 if (!CHIP_IS_E1x(bp) && !CHIP_IS_E3B0(bp))
6172 /* Bit-map indicating which L2 hdrs may appear
6173 * after the basic Ethernet header
6175 REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC,
6176 bp->path_has_ovlan ? 7 : 6);
6178 bnx2x_init_block(bp, BLOCK_TSDM, PHASE_COMMON);
6179 bnx2x_init_block(bp, BLOCK_CSDM, PHASE_COMMON);
6180 bnx2x_init_block(bp, BLOCK_USDM, PHASE_COMMON);
6181 bnx2x_init_block(bp, BLOCK_XSDM, PHASE_COMMON);
6183 if (!CHIP_IS_E1x(bp)) {
6184 /* reset VFC memories */
6185 REG_WR(bp, TSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
6186 VFC_MEMORIES_RST_REG_CAM_RST |
6187 VFC_MEMORIES_RST_REG_RAM_RST);
6188 REG_WR(bp, XSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
6189 VFC_MEMORIES_RST_REG_CAM_RST |
6190 VFC_MEMORIES_RST_REG_RAM_RST);
6195 bnx2x_init_block(bp, BLOCK_TSEM, PHASE_COMMON);
6196 bnx2x_init_block(bp, BLOCK_USEM, PHASE_COMMON);
6197 bnx2x_init_block(bp, BLOCK_CSEM, PHASE_COMMON);
6198 bnx2x_init_block(bp, BLOCK_XSEM, PHASE_COMMON);
6201 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
6203 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
6206 bnx2x_init_block(bp, BLOCK_UPB, PHASE_COMMON);
6207 bnx2x_init_block(bp, BLOCK_XPB, PHASE_COMMON);
6208 bnx2x_init_block(bp, BLOCK_PBF, PHASE_COMMON);
6210 if (!CHIP_IS_E1x(bp))
6211 REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC,
6212 bp->path_has_ovlan ? 7 : 6);
6214 REG_WR(bp, SRC_REG_SOFT_RST, 1);
6216 bnx2x_init_block(bp, BLOCK_SRC, PHASE_COMMON);
6219 REG_WR(bp, SRC_REG_KEYSEARCH_0, 0x63285672);
6220 REG_WR(bp, SRC_REG_KEYSEARCH_1, 0x24b8f2cc);
6221 REG_WR(bp, SRC_REG_KEYSEARCH_2, 0x223aef9b);
6222 REG_WR(bp, SRC_REG_KEYSEARCH_3, 0x26001e3a);
6223 REG_WR(bp, SRC_REG_KEYSEARCH_4, 0x7ae91116);
6224 REG_WR(bp, SRC_REG_KEYSEARCH_5, 0x5ce5230b);
6225 REG_WR(bp, SRC_REG_KEYSEARCH_6, 0x298d8adf);
6226 REG_WR(bp, SRC_REG_KEYSEARCH_7, 0x6eb0ff09);
6227 REG_WR(bp, SRC_REG_KEYSEARCH_8, 0x1830f82f);
6228 REG_WR(bp, SRC_REG_KEYSEARCH_9, 0x01e46be7);
6230 REG_WR(bp, SRC_REG_SOFT_RST, 0);
6232 if (sizeof(union cdu_context) != 1024)
6233 /* we currently assume that a context is 1024 bytes */
6234 dev_alert(&bp->pdev->dev,
6235 "please adjust the size of cdu_context(%ld)\n",
6236 (long)sizeof(union cdu_context));
6238 bnx2x_init_block(bp, BLOCK_CDU, PHASE_COMMON);
6239 val = (4 << 24) + (0 << 12) + 1024;
6240 REG_WR(bp, CDU_REG_CDU_GLOBAL_PARAMS, val);
6242 bnx2x_init_block(bp, BLOCK_CFC, PHASE_COMMON);
6243 REG_WR(bp, CFC_REG_INIT_REG, 0x7FF);
6244 /* enable context validation interrupt from CFC */
6245 REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
6247 /* set the thresholds to prevent CFC/CDU race */
6248 REG_WR(bp, CFC_REG_DEBUG0, 0x20020000);
6250 bnx2x_init_block(bp, BLOCK_HC, PHASE_COMMON);
6252 if (!CHIP_IS_E1x(bp) && BP_NOMCP(bp))
6253 REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x36);
6255 bnx2x_init_block(bp, BLOCK_IGU, PHASE_COMMON);
6256 bnx2x_init_block(bp, BLOCK_MISC_AEU, PHASE_COMMON);
6258 /* Reset PCIE errors for debug */
6259 REG_WR(bp, 0x2814, 0xffffffff);
6260 REG_WR(bp, 0x3820, 0xffffffff);
6262 if (!CHIP_IS_E1x(bp)) {
6263 REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_CONTROL_5,
6264 (PXPCS_TL_CONTROL_5_ERR_UNSPPORT1 |
6265 PXPCS_TL_CONTROL_5_ERR_UNSPPORT));
6266 REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC345_STAT,
6267 (PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT4 |
6268 PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT3 |
6269 PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT2));
6270 REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC678_STAT,
6271 (PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT7 |
6272 PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT6 |
6273 PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT5));
6276 bnx2x_init_block(bp, BLOCK_NIG, PHASE_COMMON);
6277 if (!CHIP_IS_E1(bp)) {
6278 /* in E3 this done in per-port section */
6279 if (!CHIP_IS_E3(bp))
6280 REG_WR(bp, NIG_REG_LLH_MF_MODE, IS_MF(bp));
6282 if (CHIP_IS_E1H(bp))
6283 /* not applicable for E2 (and above ...) */
6284 REG_WR(bp, NIG_REG_LLH_E1HOV_MODE, IS_MF_SD(bp));
6286 if (CHIP_REV_IS_SLOW(bp))
6289 /* finish CFC init */
6290 val = reg_poll(bp, CFC_REG_LL_INIT_DONE, 1, 100, 10);
6292 BNX2X_ERR("CFC LL_INIT failed\n");
6295 val = reg_poll(bp, CFC_REG_AC_INIT_DONE, 1, 100, 10);
6297 BNX2X_ERR("CFC AC_INIT failed\n");
6300 val = reg_poll(bp, CFC_REG_CAM_INIT_DONE, 1, 100, 10);
6302 BNX2X_ERR("CFC CAM_INIT failed\n");
6305 REG_WR(bp, CFC_REG_DEBUG0, 0);
6307 if (CHIP_IS_E1(bp)) {
6308 /* read NIG statistic
6309 to see if this is our first up since powerup */
6310 bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
6311 val = *bnx2x_sp(bp, wb_data[0]);
6313 /* do internal memory self test */
6314 if ((val == 0) && bnx2x_int_mem_test(bp)) {
6315 BNX2X_ERR("internal mem self test failed\n");
6320 bnx2x_setup_fan_failure_detection(bp);
6322 /* clear PXP2 attentions */
6323 REG_RD(bp, PXP2_REG_PXP2_INT_STS_CLR_0);
6325 bnx2x_enable_blocks_attention(bp);
6326 bnx2x_enable_blocks_parity(bp);
6328 if (!BP_NOMCP(bp)) {
6329 if (CHIP_IS_E1x(bp))
6330 bnx2x__common_init_phy(bp);
6332 BNX2X_ERR("Bootcode is missing - can not initialize link\n");
6338 * bnx2x_init_hw_common_chip - init HW at the COMMON_CHIP phase.
6340 * @bp: driver handle
6342 static int bnx2x_init_hw_common_chip(struct bnx2x *bp)
6344 int rc = bnx2x_init_hw_common(bp);
6349 /* In E2 2-PORT mode, same ext phy is used for the two paths */
6351 bnx2x__common_init_phy(bp);
6356 static int bnx2x_init_hw_port(struct bnx2x *bp)
6358 int port = BP_PORT(bp);
6359 int init_phase = port ? PHASE_PORT1 : PHASE_PORT0;
6363 bnx2x__link_reset(bp);
6365 DP(NETIF_MSG_HW, "starting port init port %d\n", port);
6367 REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
6369 bnx2x_init_block(bp, BLOCK_MISC, init_phase);
6370 bnx2x_init_block(bp, BLOCK_PXP, init_phase);
6371 bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
6373 /* Timers bug workaround: disables the pf_master bit in pglue at
6374 * common phase, we need to enable it here before any dmae access are
6375 * attempted. Therefore we manually added the enable-master to the
6376 * port phase (it also happens in the function phase)
6378 if (!CHIP_IS_E1x(bp))
6379 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
6381 bnx2x_init_block(bp, BLOCK_ATC, init_phase);
6382 bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
6383 bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
6384 bnx2x_init_block(bp, BLOCK_QM, init_phase);
6386 bnx2x_init_block(bp, BLOCK_TCM, init_phase);
6387 bnx2x_init_block(bp, BLOCK_UCM, init_phase);
6388 bnx2x_init_block(bp, BLOCK_CCM, init_phase);
6389 bnx2x_init_block(bp, BLOCK_XCM, init_phase);
6391 /* QM cid (connection) count */
6392 bnx2x_qm_init_cid_count(bp, bp->qm_cid_count, INITOP_SET);
6395 bnx2x_init_block(bp, BLOCK_TM, init_phase);
6396 REG_WR(bp, TM_REG_LIN0_SCAN_TIME + port*4, 20);
6397 REG_WR(bp, TM_REG_LIN0_MAX_ACTIVE_CID + port*4, 31);
6400 bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
6402 if (CHIP_IS_E1(bp) || CHIP_IS_E1H(bp)) {
6403 bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
6406 low = ((bp->flags & ONE_PORT_FLAG) ? 160 : 246);
6407 else if (bp->dev->mtu > 4096) {
6408 if (bp->flags & ONE_PORT_FLAG)
6412 /* (24*1024 + val*4)/256 */
6413 low = 96 + (val/64) +
6414 ((val % 64) ? 1 : 0);
6417 low = ((bp->flags & ONE_PORT_FLAG) ? 80 : 160);
6418 high = low + 56; /* 14*1024/256 */
6419 REG_WR(bp, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port*4, low);
6420 REG_WR(bp, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port*4, high);
6423 if (CHIP_MODE_IS_4_PORT(bp))
6424 REG_WR(bp, (BP_PORT(bp) ?
6425 BRB1_REG_MAC_GUARANTIED_1 :
6426 BRB1_REG_MAC_GUARANTIED_0), 40);
6429 bnx2x_init_block(bp, BLOCK_PRS, init_phase);
6430 if (CHIP_IS_E3B0(bp))
6431 /* Ovlan exists only if we are in multi-function +
6432 * switch-dependent mode, in switch-independent there
6433 * is no ovlan headers
6435 REG_WR(bp, BP_PORT(bp) ?
6436 PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
6437 PRS_REG_HDRS_AFTER_BASIC_PORT_0,
6438 (bp->path_has_ovlan ? 7 : 6));
6440 bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
6441 bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
6442 bnx2x_init_block(bp, BLOCK_USDM, init_phase);
6443 bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
6445 bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
6446 bnx2x_init_block(bp, BLOCK_USEM, init_phase);
6447 bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
6448 bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
6450 bnx2x_init_block(bp, BLOCK_UPB, init_phase);
6451 bnx2x_init_block(bp, BLOCK_XPB, init_phase);
6453 bnx2x_init_block(bp, BLOCK_PBF, init_phase);
6455 if (CHIP_IS_E1x(bp)) {
6456 /* configure PBF to work without PAUSE mtu 9000 */
6457 REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
6459 /* update threshold */
6460 REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, (9040/16));
6461 /* update init credit */
6462 REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, (9040/16) + 553 - 22);
6465 REG_WR(bp, PBF_REG_INIT_P0 + port*4, 1);
6467 REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0);
6471 bnx2x_init_block(bp, BLOCK_SRC, init_phase);
6473 bnx2x_init_block(bp, BLOCK_CDU, init_phase);
6474 bnx2x_init_block(bp, BLOCK_CFC, init_phase);
6476 if (CHIP_IS_E1(bp)) {
6477 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
6478 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
6480 bnx2x_init_block(bp, BLOCK_HC, init_phase);
6482 bnx2x_init_block(bp, BLOCK_IGU, init_phase);
6484 bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
6485 /* init aeu_mask_attn_func_0/1:
6486 * - SF mode: bits 3-7 are masked. only bits 0-2 are in use
6487 * - MF mode: bit 3 is masked. bits 0-2 are in use as in SF
6488 * bits 4-7 are used for "per vn group attention" */
6489 val = IS_MF(bp) ? 0xF7 : 0x7;
6490 /* Enable DCBX attention for all but E1 */
6491 val |= CHIP_IS_E1(bp) ? 0 : 0x10;
6492 REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, val);
6494 bnx2x_init_block(bp, BLOCK_NIG, init_phase);
6496 if (!CHIP_IS_E1x(bp)) {
6497 /* Bit-map indicating which L2 hdrs may appear after the
6498 * basic Ethernet header
6500 REG_WR(bp, BP_PORT(bp) ?
6501 NIG_REG_P1_HDRS_AFTER_BASIC :
6502 NIG_REG_P0_HDRS_AFTER_BASIC,
6503 IS_MF_SD(bp) ? 7 : 6);
6506 REG_WR(bp, BP_PORT(bp) ?
6507 NIG_REG_LLH1_MF_MODE :
6508 NIG_REG_LLH_MF_MODE, IS_MF(bp));
6510 if (!CHIP_IS_E3(bp))
6511 REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
6513 if (!CHIP_IS_E1(bp)) {
6514 /* 0x2 disable mf_ov, 0x1 enable */
6515 REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port*4,
6516 (IS_MF_SD(bp) ? 0x1 : 0x2));
6518 if (!CHIP_IS_E1x(bp)) {
6520 switch (bp->mf_mode) {
6521 case MULTI_FUNCTION_SD:
6524 case MULTI_FUNCTION_SI:
6529 REG_WR(bp, (BP_PORT(bp) ? NIG_REG_LLH1_CLS_TYPE :
6530 NIG_REG_LLH0_CLS_TYPE), val);
6533 REG_WR(bp, NIG_REG_LLFC_ENABLE_0 + port*4, 0);
6534 REG_WR(bp, NIG_REG_LLFC_OUT_EN_0 + port*4, 0);
6535 REG_WR(bp, NIG_REG_PAUSE_ENABLE_0 + port*4, 1);
6540 /* If SPIO5 is set to generate interrupts, enable it for this port */
6541 val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
6542 if (val & (1 << MISC_REGISTERS_SPIO_5)) {
6543 u32 reg_addr = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
6544 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
6545 val = REG_RD(bp, reg_addr);
6546 val |= AEU_INPUTS_ATTN_BITS_SPIO5;
6547 REG_WR(bp, reg_addr, val);
6553 static void bnx2x_ilt_wr(struct bnx2x *bp, u32 index, dma_addr_t addr)
6559 reg = PXP2_REG_RQ_ONCHIP_AT + index*8;
6561 reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index*8;
6563 wb_write[0] = ONCHIP_ADDR1(addr);
6564 wb_write[1] = ONCHIP_ADDR2(addr);
6565 REG_WR_DMAE(bp, reg, wb_write, 2);
6568 static inline void bnx2x_igu_clear_sb(struct bnx2x *bp, u8 idu_sb_id)
6570 bnx2x_igu_clear_sb_gen(bp, BP_FUNC(bp), idu_sb_id, true /*PF*/);
6573 static inline void bnx2x_clear_func_ilt(struct bnx2x *bp, u32 func)
6575 u32 i, base = FUNC_ILT_BASE(func);
6576 for (i = base; i < base + ILT_PER_FUNC; i++)
6577 bnx2x_ilt_wr(bp, i, 0);
6580 static int bnx2x_init_hw_func(struct bnx2x *bp)
6582 int port = BP_PORT(bp);
6583 int func = BP_FUNC(bp);
6584 int init_phase = PHASE_PF0 + func;
6585 struct bnx2x_ilt *ilt = BP_ILT(bp);
6588 u32 main_mem_base, main_mem_size, main_mem_prty_clr;
6589 int i, main_mem_width, rc;
6591 DP(NETIF_MSG_HW, "starting func init func %d\n", func);
6593 /* FLR cleanup - hmmm */
6594 if (!CHIP_IS_E1x(bp)) {
6595 rc = bnx2x_pf_flr_clnup(bp);
6600 /* set MSI reconfigure capability */
6601 if (bp->common.int_block == INT_BLOCK_HC) {
6602 addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0);
6603 val = REG_RD(bp, addr);
6604 val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0;
6605 REG_WR(bp, addr, val);
6608 bnx2x_init_block(bp, BLOCK_PXP, init_phase);
6609 bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
6612 cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
6614 for (i = 0; i < L2_ILT_LINES(bp); i++) {
6615 ilt->lines[cdu_ilt_start + i].page =
6616 bp->context.vcxt + (ILT_PAGE_CIDS * i);
6617 ilt->lines[cdu_ilt_start + i].page_mapping =
6618 bp->context.cxt_mapping + (CDU_ILT_PAGE_SZ * i);
6619 /* cdu ilt pages are allocated manually so there's no need to
6622 bnx2x_ilt_init_op(bp, INITOP_SET);
6625 bnx2x_src_init_t2(bp, bp->t2, bp->t2_mapping, SRC_CONN_NUM);
6627 /* T1 hash bits value determines the T1 number of entries */
6628 REG_WR(bp, SRC_REG_NUMBER_HASH_BITS0 + port*4, SRC_HASH_BITS);
6633 REG_WR(bp, PRS_REG_NIC_MODE, 1);
6634 #endif /* BCM_CNIC */
6636 if (!CHIP_IS_E1x(bp)) {
6637 u32 pf_conf = IGU_PF_CONF_FUNC_EN;
6639 /* Turn on a single ISR mode in IGU if driver is going to use
6642 if (!(bp->flags & USING_MSIX_FLAG))
6643 pf_conf |= IGU_PF_CONF_SINGLE_ISR_EN;
6645 * Timers workaround bug: function init part.
6646 * Need to wait 20msec after initializing ILT,
6647 * needed to make sure there are no requests in
6648 * one of the PXP internal queues with "old" ILT addresses
6652 * Master enable - Due to WB DMAE writes performed before this
6653 * register is re-initialized as part of the regular function
6656 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
6657 /* Enable the function in IGU */
6658 REG_WR(bp, IGU_REG_PF_CONFIGURATION, pf_conf);
6663 bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
6665 if (!CHIP_IS_E1x(bp))
6666 REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR, func);
6668 bnx2x_init_block(bp, BLOCK_ATC, init_phase);
6669 bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
6670 bnx2x_init_block(bp, BLOCK_NIG, init_phase);
6671 bnx2x_init_block(bp, BLOCK_SRC, init_phase);
6672 bnx2x_init_block(bp, BLOCK_MISC, init_phase);
6673 bnx2x_init_block(bp, BLOCK_TCM, init_phase);
6674 bnx2x_init_block(bp, BLOCK_UCM, init_phase);
6675 bnx2x_init_block(bp, BLOCK_CCM, init_phase);
6676 bnx2x_init_block(bp, BLOCK_XCM, init_phase);
6677 bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
6678 bnx2x_init_block(bp, BLOCK_USEM, init_phase);
6679 bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
6680 bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
6682 if (!CHIP_IS_E1x(bp))
6683 REG_WR(bp, QM_REG_PF_EN, 1);
6685 if (!CHIP_IS_E1x(bp)) {
6686 REG_WR(bp, TSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
6687 REG_WR(bp, USEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
6688 REG_WR(bp, CSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
6689 REG_WR(bp, XSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
6691 bnx2x_init_block(bp, BLOCK_QM, init_phase);
6693 bnx2x_init_block(bp, BLOCK_TM, init_phase);
6694 bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
6695 bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
6696 bnx2x_init_block(bp, BLOCK_PRS, init_phase);
6697 bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
6698 bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
6699 bnx2x_init_block(bp, BLOCK_USDM, init_phase);
6700 bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
6701 bnx2x_init_block(bp, BLOCK_UPB, init_phase);
6702 bnx2x_init_block(bp, BLOCK_XPB, init_phase);
6703 bnx2x_init_block(bp, BLOCK_PBF, init_phase);
6704 if (!CHIP_IS_E1x(bp))
6705 REG_WR(bp, PBF_REG_DISABLE_PF, 0);
6707 bnx2x_init_block(bp, BLOCK_CDU, init_phase);
6709 bnx2x_init_block(bp, BLOCK_CFC, init_phase);
6711 if (!CHIP_IS_E1x(bp))
6712 REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 1);
6715 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
6716 REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + port*8, bp->mf_ov);
6719 bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
6721 /* HC init per function */
6722 if (bp->common.int_block == INT_BLOCK_HC) {
6723 if (CHIP_IS_E1H(bp)) {
6724 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
6726 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
6727 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
6729 bnx2x_init_block(bp, BLOCK_HC, init_phase);
6732 int num_segs, sb_idx, prod_offset;
6734 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
6736 if (!CHIP_IS_E1x(bp)) {
6737 REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
6738 REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
6741 bnx2x_init_block(bp, BLOCK_IGU, init_phase);
6743 if (!CHIP_IS_E1x(bp)) {
6747 * E2 mode: address 0-135 match to the mapping memory;
6748 * 136 - PF0 default prod; 137 - PF1 default prod;
6749 * 138 - PF2 default prod; 139 - PF3 default prod;
6750 * 140 - PF0 attn prod; 141 - PF1 attn prod;
6751 * 142 - PF2 attn prod; 143 - PF3 attn prod;
6754 * E1.5 mode - In backward compatible mode;
6755 * for non default SB; each even line in the memory
6756 * holds the U producer and each odd line hold
6757 * the C producer. The first 128 producers are for
6758 * NDSB (PF0 - 0-31; PF1 - 32-63 and so on). The last 20
6759 * producers are for the DSB for each PF.
6760 * Each PF has five segments: (the order inside each
6761 * segment is PF0; PF1; PF2; PF3) - 128-131 U prods;
6762 * 132-135 C prods; 136-139 X prods; 140-143 T prods;
6763 * 144-147 attn prods;
6765 /* non-default-status-blocks */
6766 num_segs = CHIP_INT_MODE_IS_BC(bp) ?
6767 IGU_BC_NDSB_NUM_SEGS : IGU_NORM_NDSB_NUM_SEGS;
6768 for (sb_idx = 0; sb_idx < bp->igu_sb_cnt; sb_idx++) {
6769 prod_offset = (bp->igu_base_sb + sb_idx) *
6772 for (i = 0; i < num_segs; i++) {
6773 addr = IGU_REG_PROD_CONS_MEMORY +
6774 (prod_offset + i) * 4;
6775 REG_WR(bp, addr, 0);
6777 /* send consumer update with value 0 */
6778 bnx2x_ack_sb(bp, bp->igu_base_sb + sb_idx,
6779 USTORM_ID, 0, IGU_INT_NOP, 1);
6780 bnx2x_igu_clear_sb(bp,
6781 bp->igu_base_sb + sb_idx);
6784 /* default-status-blocks */
6785 num_segs = CHIP_INT_MODE_IS_BC(bp) ?
6786 IGU_BC_DSB_NUM_SEGS : IGU_NORM_DSB_NUM_SEGS;
6788 if (CHIP_MODE_IS_4_PORT(bp))
6789 dsb_idx = BP_FUNC(bp);
6791 dsb_idx = BP_VN(bp);
6793 prod_offset = (CHIP_INT_MODE_IS_BC(bp) ?
6794 IGU_BC_BASE_DSB_PROD + dsb_idx :
6795 IGU_NORM_BASE_DSB_PROD + dsb_idx);
6798 * igu prods come in chunks of E1HVN_MAX (4) -
6799 * does not matters what is the current chip mode
6801 for (i = 0; i < (num_segs * E1HVN_MAX);
6803 addr = IGU_REG_PROD_CONS_MEMORY +
6804 (prod_offset + i)*4;
6805 REG_WR(bp, addr, 0);
6807 /* send consumer update with 0 */
6808 if (CHIP_INT_MODE_IS_BC(bp)) {
6809 bnx2x_ack_sb(bp, bp->igu_dsb_id,
6810 USTORM_ID, 0, IGU_INT_NOP, 1);
6811 bnx2x_ack_sb(bp, bp->igu_dsb_id,
6812 CSTORM_ID, 0, IGU_INT_NOP, 1);
6813 bnx2x_ack_sb(bp, bp->igu_dsb_id,
6814 XSTORM_ID, 0, IGU_INT_NOP, 1);
6815 bnx2x_ack_sb(bp, bp->igu_dsb_id,
6816 TSTORM_ID, 0, IGU_INT_NOP, 1);
6817 bnx2x_ack_sb(bp, bp->igu_dsb_id,
6818 ATTENTION_ID, 0, IGU_INT_NOP, 1);
6820 bnx2x_ack_sb(bp, bp->igu_dsb_id,
6821 USTORM_ID, 0, IGU_INT_NOP, 1);
6822 bnx2x_ack_sb(bp, bp->igu_dsb_id,
6823 ATTENTION_ID, 0, IGU_INT_NOP, 1);
6825 bnx2x_igu_clear_sb(bp, bp->igu_dsb_id);
6827 /* !!! these should become driver const once
6828 rf-tool supports split-68 const */
6829 REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_LSB, 0);
6830 REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_MSB, 0);
6831 REG_WR(bp, IGU_REG_SB_MASK_LSB, 0);
6832 REG_WR(bp, IGU_REG_SB_MASK_MSB, 0);
6833 REG_WR(bp, IGU_REG_PBA_STATUS_LSB, 0);
6834 REG_WR(bp, IGU_REG_PBA_STATUS_MSB, 0);
6838 /* Reset PCIE errors for debug */
6839 REG_WR(bp, 0x2114, 0xffffffff);
6840 REG_WR(bp, 0x2120, 0xffffffff);
6842 if (CHIP_IS_E1x(bp)) {
6843 main_mem_size = HC_REG_MAIN_MEMORY_SIZE / 2; /*dwords*/
6844 main_mem_base = HC_REG_MAIN_MEMORY +
6845 BP_PORT(bp) * (main_mem_size * 4);
6846 main_mem_prty_clr = HC_REG_HC_PRTY_STS_CLR;
6849 val = REG_RD(bp, main_mem_prty_clr);
6852 "Hmmm... Parity errors in HC block during function init (0x%x)!\n",
6855 /* Clear "false" parity errors in MSI-X table */
6856 for (i = main_mem_base;
6857 i < main_mem_base + main_mem_size * 4;
6858 i += main_mem_width) {
6859 bnx2x_read_dmae(bp, i, main_mem_width / 4);
6860 bnx2x_write_dmae(bp, bnx2x_sp_mapping(bp, wb_data),
6861 i, main_mem_width / 4);
6863 /* Clear HC parity attention */
6864 REG_RD(bp, main_mem_prty_clr);
6867 #ifdef BNX2X_STOP_ON_ERROR
6868 /* Enable STORMs SP logging */
6869 REG_WR8(bp, BAR_USTRORM_INTMEM +
6870 USTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
6871 REG_WR8(bp, BAR_TSTRORM_INTMEM +
6872 TSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
6873 REG_WR8(bp, BAR_CSTRORM_INTMEM +
6874 CSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
6875 REG_WR8(bp, BAR_XSTRORM_INTMEM +
6876 XSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
6879 bnx2x_phy_probe(&bp->link_params);
6885 void bnx2x_free_mem(struct bnx2x *bp)
6888 bnx2x_free_fp_mem(bp);
6889 /* end of fastpath */
6891 BNX2X_PCI_FREE(bp->def_status_blk, bp->def_status_blk_mapping,
6892 sizeof(struct host_sp_status_block));
6894 BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
6895 bp->fw_stats_data_sz + bp->fw_stats_req_sz);
6897 BNX2X_PCI_FREE(bp->slowpath, bp->slowpath_mapping,
6898 sizeof(struct bnx2x_slowpath));
6900 BNX2X_PCI_FREE(bp->context.vcxt, bp->context.cxt_mapping,
6903 bnx2x_ilt_mem_op(bp, ILT_MEMOP_FREE);
6905 BNX2X_FREE(bp->ilt->lines);
6908 if (!CHIP_IS_E1x(bp))
6909 BNX2X_PCI_FREE(bp->cnic_sb.e2_sb, bp->cnic_sb_mapping,
6910 sizeof(struct host_hc_status_block_e2));
6912 BNX2X_PCI_FREE(bp->cnic_sb.e1x_sb, bp->cnic_sb_mapping,
6913 sizeof(struct host_hc_status_block_e1x));
6915 BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
6918 BNX2X_PCI_FREE(bp->spq, bp->spq_mapping, BCM_PAGE_SIZE);
6920 BNX2X_PCI_FREE(bp->eq_ring, bp->eq_mapping,
6921 BCM_PAGE_SIZE * NUM_EQ_PAGES);
6924 static inline int bnx2x_alloc_fw_stats_mem(struct bnx2x *bp)
6927 int is_fcoe_stats = NO_FCOE(bp) ? 0 : 1;
6929 /* number of queues for statistics is number of eth queues + FCoE */
6930 u8 num_queue_stats = BNX2X_NUM_ETH_QUEUES(bp) + is_fcoe_stats;
6932 /* Total number of FW statistics requests =
6933 * 1 for port stats + 1 for PF stats + potential 1 for FCoE stats +
6936 bp->fw_stats_num = 2 + is_fcoe_stats + num_queue_stats;
6939 /* Request is built from stats_query_header and an array of
6940 * stats_query_cmd_group each of which contains
6941 * STATS_QUERY_CMD_COUNT rules. The real number or requests is
6942 * configured in the stats_query_header.
6944 num_groups = ((bp->fw_stats_num) / STATS_QUERY_CMD_COUNT) +
6945 (((bp->fw_stats_num) % STATS_QUERY_CMD_COUNT) ? 1 : 0);
6947 bp->fw_stats_req_sz = sizeof(struct stats_query_header) +
6948 num_groups * sizeof(struct stats_query_cmd_group);
6950 /* Data for statistics requests + stats_conter
6952 * stats_counter holds per-STORM counters that are incremented
6953 * when STORM has finished with the current request.
6955 * memory for FCoE offloaded statistics are counted anyway,
6956 * even if they will not be sent.
6958 bp->fw_stats_data_sz = sizeof(struct per_port_stats) +
6959 sizeof(struct per_pf_stats) +
6960 sizeof(struct fcoe_statistics_params) +
6961 sizeof(struct per_queue_stats) * num_queue_stats +
6962 sizeof(struct stats_counter);
6964 BNX2X_PCI_ALLOC(bp->fw_stats, &bp->fw_stats_mapping,
6965 bp->fw_stats_data_sz + bp->fw_stats_req_sz);
6968 bp->fw_stats_req = (struct bnx2x_fw_stats_req *)bp->fw_stats;
6969 bp->fw_stats_req_mapping = bp->fw_stats_mapping;
6971 bp->fw_stats_data = (struct bnx2x_fw_stats_data *)
6972 ((u8 *)bp->fw_stats + bp->fw_stats_req_sz);
6974 bp->fw_stats_data_mapping = bp->fw_stats_mapping +
6975 bp->fw_stats_req_sz;
6979 BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
6980 bp->fw_stats_data_sz + bp->fw_stats_req_sz);
6981 BNX2X_ERR("Can't allocate memory\n");
6986 int bnx2x_alloc_mem(struct bnx2x *bp)
6989 if (!CHIP_IS_E1x(bp))
6990 /* size = the status block + ramrod buffers */
6991 BNX2X_PCI_ALLOC(bp->cnic_sb.e2_sb, &bp->cnic_sb_mapping,
6992 sizeof(struct host_hc_status_block_e2));
6994 BNX2X_PCI_ALLOC(bp->cnic_sb.e1x_sb, &bp->cnic_sb_mapping,
6995 sizeof(struct host_hc_status_block_e1x));
6997 /* allocate searcher T2 table */
6998 BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ);
7002 BNX2X_PCI_ALLOC(bp->def_status_blk, &bp->def_status_blk_mapping,
7003 sizeof(struct host_sp_status_block));
7005 BNX2X_PCI_ALLOC(bp->slowpath, &bp->slowpath_mapping,
7006 sizeof(struct bnx2x_slowpath));
7009 /* write address to which L5 should insert its values */
7010 bp->cnic_eth_dev.addr_drv_info_to_mcp = &bp->slowpath->drv_info_to_mcp;
7013 /* Allocated memory for FW statistics */
7014 if (bnx2x_alloc_fw_stats_mem(bp))
7017 bp->context.size = sizeof(union cdu_context) * BNX2X_L2_CID_COUNT(bp);
7019 BNX2X_PCI_ALLOC(bp->context.vcxt, &bp->context.cxt_mapping,
7022 BNX2X_ALLOC(bp->ilt->lines, sizeof(struct ilt_line) * ILT_MAX_LINES);
7024 if (bnx2x_ilt_mem_op(bp, ILT_MEMOP_ALLOC))
7027 /* Slow path ring */
7028 BNX2X_PCI_ALLOC(bp->spq, &bp->spq_mapping, BCM_PAGE_SIZE);
7031 BNX2X_PCI_ALLOC(bp->eq_ring, &bp->eq_mapping,
7032 BCM_PAGE_SIZE * NUM_EQ_PAGES);
7036 /* need to be done at the end, since it's self adjusting to amount
7037 * of memory available for RSS queues
7039 if (bnx2x_alloc_fp_mem(bp))
7045 BNX2X_ERR("Can't allocate memory\n");
7050 * Init service functions
7053 int bnx2x_set_mac_one(struct bnx2x *bp, u8 *mac,
7054 struct bnx2x_vlan_mac_obj *obj, bool set,
7055 int mac_type, unsigned long *ramrod_flags)
7058 struct bnx2x_vlan_mac_ramrod_params ramrod_param;
7060 memset(&ramrod_param, 0, sizeof(ramrod_param));
7062 /* Fill general parameters */
7063 ramrod_param.vlan_mac_obj = obj;
7064 ramrod_param.ramrod_flags = *ramrod_flags;
7066 /* Fill a user request section if needed */
7067 if (!test_bit(RAMROD_CONT, ramrod_flags)) {
7068 memcpy(ramrod_param.user_req.u.mac.mac, mac, ETH_ALEN);
7070 __set_bit(mac_type, &ramrod_param.user_req.vlan_mac_flags);
7072 /* Set the command: ADD or DEL */
7074 ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_ADD;
7076 ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_DEL;
7079 rc = bnx2x_config_vlan_mac(bp, &ramrod_param);
7081 BNX2X_ERR("%s MAC failed\n", (set ? "Set" : "Del"));
7085 int bnx2x_del_all_macs(struct bnx2x *bp,
7086 struct bnx2x_vlan_mac_obj *mac_obj,
7087 int mac_type, bool wait_for_comp)
7090 unsigned long ramrod_flags = 0, vlan_mac_flags = 0;
7092 /* Wait for completion of requested */
7094 __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
7096 /* Set the mac type of addresses we want to clear */
7097 __set_bit(mac_type, &vlan_mac_flags);
7099 rc = mac_obj->delete_all(bp, mac_obj, &vlan_mac_flags, &ramrod_flags);
7101 BNX2X_ERR("Failed to delete MACs: %d\n", rc);
7106 int bnx2x_set_eth_mac(struct bnx2x *bp, bool set)
7108 unsigned long ramrod_flags = 0;
7111 if (is_zero_ether_addr(bp->dev->dev_addr) && IS_MF_STORAGE_SD(bp)) {
7112 DP(NETIF_MSG_IFUP | NETIF_MSG_IFDOWN,
7113 "Ignoring Zero MAC for STORAGE SD mode\n");
7118 DP(NETIF_MSG_IFUP, "Adding Eth MAC\n");
7120 __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
7121 /* Eth MAC is set on RSS leading client (fp[0]) */
7122 return bnx2x_set_mac_one(bp, bp->dev->dev_addr, &bp->fp->mac_obj, set,
7123 BNX2X_ETH_MAC, &ramrod_flags);
7126 int bnx2x_setup_leading(struct bnx2x *bp)
7128 return bnx2x_setup_queue(bp, &bp->fp[0], 1);
7132 * bnx2x_set_int_mode - configure interrupt mode
7134 * @bp: driver handle
7136 * In case of MSI-X it will also try to enable MSI-X.
7138 static void __devinit bnx2x_set_int_mode(struct bnx2x *bp)
7142 bnx2x_enable_msi(bp);
7143 /* falling through... */
7145 bp->num_queues = 1 + NON_ETH_CONTEXT_USE;
7146 BNX2X_DEV_INFO("set number of queues to 1\n");
7149 /* Set number of queues according to bp->multi_mode value */
7150 bnx2x_set_num_queues(bp);
7152 BNX2X_DEV_INFO("set number of queues to %d\n", bp->num_queues);
7154 /* if we can't use MSI-X we only need one fp,
7155 * so try to enable MSI-X with the requested number of fp's
7156 * and fallback to MSI or legacy INTx with one fp
7158 if (bnx2x_enable_msix(bp)) {
7159 /* failed to enable MSI-X */
7160 BNX2X_DEV_INFO("Failed to enable MSI-X (%d), set number of queues to %d\n",
7161 bp->num_queues, 1 + NON_ETH_CONTEXT_USE);
7163 bp->num_queues = 1 + NON_ETH_CONTEXT_USE;
7165 /* Try to enable MSI */
7166 if (!(bp->flags & DISABLE_MSI_FLAG))
7167 bnx2x_enable_msi(bp);
7173 /* must be called prioir to any HW initializations */
7174 static inline u16 bnx2x_cid_ilt_lines(struct bnx2x *bp)
7176 return L2_ILT_LINES(bp);
7179 void bnx2x_ilt_set_info(struct bnx2x *bp)
7181 struct ilt_client_info *ilt_client;
7182 struct bnx2x_ilt *ilt = BP_ILT(bp);
7185 ilt->start_line = FUNC_ILT_BASE(BP_FUNC(bp));
7186 DP(BNX2X_MSG_SP, "ilt starts at line %d\n", ilt->start_line);
7189 ilt_client = &ilt->clients[ILT_CLIENT_CDU];
7190 ilt_client->client_num = ILT_CLIENT_CDU;
7191 ilt_client->page_size = CDU_ILT_PAGE_SZ;
7192 ilt_client->flags = ILT_CLIENT_SKIP_MEM;
7193 ilt_client->start = line;
7194 line += bnx2x_cid_ilt_lines(bp);
7196 line += CNIC_ILT_LINES;
7198 ilt_client->end = line - 1;
7200 DP(NETIF_MSG_IFUP, "ilt client[CDU]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
7203 ilt_client->page_size,
7205 ilog2(ilt_client->page_size >> 12));
7208 if (QM_INIT(bp->qm_cid_count)) {
7209 ilt_client = &ilt->clients[ILT_CLIENT_QM];
7210 ilt_client->client_num = ILT_CLIENT_QM;
7211 ilt_client->page_size = QM_ILT_PAGE_SZ;
7212 ilt_client->flags = 0;
7213 ilt_client->start = line;
7215 /* 4 bytes for each cid */
7216 line += DIV_ROUND_UP(bp->qm_cid_count * QM_QUEUES_PER_FUNC * 4,
7219 ilt_client->end = line - 1;
7222 "ilt client[QM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
7225 ilt_client->page_size,
7227 ilog2(ilt_client->page_size >> 12));
7231 ilt_client = &ilt->clients[ILT_CLIENT_SRC];
7233 ilt_client->client_num = ILT_CLIENT_SRC;
7234 ilt_client->page_size = SRC_ILT_PAGE_SZ;
7235 ilt_client->flags = 0;
7236 ilt_client->start = line;
7237 line += SRC_ILT_LINES;
7238 ilt_client->end = line - 1;
7241 "ilt client[SRC]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
7244 ilt_client->page_size,
7246 ilog2(ilt_client->page_size >> 12));
7249 ilt_client->flags = (ILT_CLIENT_SKIP_INIT | ILT_CLIENT_SKIP_MEM);
7253 ilt_client = &ilt->clients[ILT_CLIENT_TM];
7255 ilt_client->client_num = ILT_CLIENT_TM;
7256 ilt_client->page_size = TM_ILT_PAGE_SZ;
7257 ilt_client->flags = 0;
7258 ilt_client->start = line;
7259 line += TM_ILT_LINES;
7260 ilt_client->end = line - 1;
7263 "ilt client[TM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
7266 ilt_client->page_size,
7268 ilog2(ilt_client->page_size >> 12));
7271 ilt_client->flags = (ILT_CLIENT_SKIP_INIT | ILT_CLIENT_SKIP_MEM);
7273 BUG_ON(line > ILT_MAX_LINES);
7277 * bnx2x_pf_q_prep_init - prepare INIT transition parameters
7279 * @bp: driver handle
7280 * @fp: pointer to fastpath
7281 * @init_params: pointer to parameters structure
7283 * parameters configured:
7284 * - HC configuration
7285 * - Queue's CDU context
7287 static inline void bnx2x_pf_q_prep_init(struct bnx2x *bp,
7288 struct bnx2x_fastpath *fp, struct bnx2x_queue_init_params *init_params)
7292 /* FCoE Queue uses Default SB, thus has no HC capabilities */
7293 if (!IS_FCOE_FP(fp)) {
7294 __set_bit(BNX2X_Q_FLG_HC, &init_params->rx.flags);
7295 __set_bit(BNX2X_Q_FLG_HC, &init_params->tx.flags);
7297 /* If HC is supporterd, enable host coalescing in the transition
7300 __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->rx.flags);
7301 __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->tx.flags);
7304 init_params->rx.hc_rate = bp->rx_ticks ?
7305 (1000000 / bp->rx_ticks) : 0;
7306 init_params->tx.hc_rate = bp->tx_ticks ?
7307 (1000000 / bp->tx_ticks) : 0;
7310 init_params->rx.fw_sb_id = init_params->tx.fw_sb_id =
7314 * CQ index among the SB indices: FCoE clients uses the default
7315 * SB, therefore it's different.
7317 init_params->rx.sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
7318 init_params->tx.sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS;
7321 /* set maximum number of COSs supported by this queue */
7322 init_params->max_cos = fp->max_cos;
7324 DP(NETIF_MSG_IFUP, "fp: %d setting queue params max cos to: %d\n",
7325 fp->index, init_params->max_cos);
7327 /* set the context pointers queue object */
7328 for (cos = FIRST_TX_COS_INDEX; cos < init_params->max_cos; cos++)
7329 init_params->cxts[cos] =
7330 &bp->context.vcxt[fp->txdata[cos].cid].eth;
7333 int bnx2x_setup_tx_only(struct bnx2x *bp, struct bnx2x_fastpath *fp,
7334 struct bnx2x_queue_state_params *q_params,
7335 struct bnx2x_queue_setup_tx_only_params *tx_only_params,
7336 int tx_index, bool leading)
7338 memset(tx_only_params, 0, sizeof(*tx_only_params));
7340 /* Set the command */
7341 q_params->cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
7343 /* Set tx-only QUEUE flags: don't zero statistics */
7344 tx_only_params->flags = bnx2x_get_common_flags(bp, fp, false);
7346 /* choose the index of the cid to send the slow path on */
7347 tx_only_params->cid_index = tx_index;
7349 /* Set general TX_ONLY_SETUP parameters */
7350 bnx2x_pf_q_prep_general(bp, fp, &tx_only_params->gen_params, tx_index);
7352 /* Set Tx TX_ONLY_SETUP parameters */
7353 bnx2x_pf_tx_q_prep(bp, fp, &tx_only_params->txq_params, tx_index);
7356 "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",
7357 tx_index, q_params->q_obj->cids[FIRST_TX_COS_INDEX],
7358 q_params->q_obj->cids[tx_index], q_params->q_obj->cl_id,
7359 tx_only_params->gen_params.spcl_id, tx_only_params->flags);
7361 /* send the ramrod */
7362 return bnx2x_queue_state_change(bp, q_params);
7367 * bnx2x_setup_queue - setup queue
7369 * @bp: driver handle
7370 * @fp: pointer to fastpath
7371 * @leading: is leading
7373 * This function performs 2 steps in a Queue state machine
7374 * actually: 1) RESET->INIT 2) INIT->SETUP
7377 int bnx2x_setup_queue(struct bnx2x *bp, struct bnx2x_fastpath *fp,
7380 struct bnx2x_queue_state_params q_params = {NULL};
7381 struct bnx2x_queue_setup_params *setup_params =
7382 &q_params.params.setup;
7383 struct bnx2x_queue_setup_tx_only_params *tx_only_params =
7384 &q_params.params.tx_only;
7388 DP(NETIF_MSG_IFUP, "setting up queue %d\n", fp->index);
7390 /* reset IGU state skip FCoE L2 queue */
7391 if (!IS_FCOE_FP(fp))
7392 bnx2x_ack_sb(bp, fp->igu_sb_id, USTORM_ID, 0,
7395 q_params.q_obj = &fp->q_obj;
7396 /* We want to wait for completion in this context */
7397 __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
7399 /* Prepare the INIT parameters */
7400 bnx2x_pf_q_prep_init(bp, fp, &q_params.params.init);
7402 /* Set the command */
7403 q_params.cmd = BNX2X_Q_CMD_INIT;
7405 /* Change the state to INIT */
7406 rc = bnx2x_queue_state_change(bp, &q_params);
7408 BNX2X_ERR("Queue(%d) INIT failed\n", fp->index);
7412 DP(NETIF_MSG_IFUP, "init complete\n");
7415 /* Now move the Queue to the SETUP state... */
7416 memset(setup_params, 0, sizeof(*setup_params));
7418 /* Set QUEUE flags */
7419 setup_params->flags = bnx2x_get_q_flags(bp, fp, leading);
7421 /* Set general SETUP parameters */
7422 bnx2x_pf_q_prep_general(bp, fp, &setup_params->gen_params,
7423 FIRST_TX_COS_INDEX);
7425 bnx2x_pf_rx_q_prep(bp, fp, &setup_params->pause_params,
7426 &setup_params->rxq_params);
7428 bnx2x_pf_tx_q_prep(bp, fp, &setup_params->txq_params,
7429 FIRST_TX_COS_INDEX);
7431 /* Set the command */
7432 q_params.cmd = BNX2X_Q_CMD_SETUP;
7434 /* Change the state to SETUP */
7435 rc = bnx2x_queue_state_change(bp, &q_params);
7437 BNX2X_ERR("Queue(%d) SETUP failed\n", fp->index);
7441 /* loop through the relevant tx-only indices */
7442 for (tx_index = FIRST_TX_ONLY_COS_INDEX;
7443 tx_index < fp->max_cos;
7446 /* prepare and send tx-only ramrod*/
7447 rc = bnx2x_setup_tx_only(bp, fp, &q_params,
7448 tx_only_params, tx_index, leading);
7450 BNX2X_ERR("Queue(%d.%d) TX_ONLY_SETUP failed\n",
7451 fp->index, tx_index);
7459 static int bnx2x_stop_queue(struct bnx2x *bp, int index)
7461 struct bnx2x_fastpath *fp = &bp->fp[index];
7462 struct bnx2x_fp_txdata *txdata;
7463 struct bnx2x_queue_state_params q_params = {NULL};
7466 DP(NETIF_MSG_IFDOWN, "stopping queue %d cid %d\n", index, fp->cid);
7468 q_params.q_obj = &fp->q_obj;
7469 /* We want to wait for completion in this context */
7470 __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
7473 /* close tx-only connections */
7474 for (tx_index = FIRST_TX_ONLY_COS_INDEX;
7475 tx_index < fp->max_cos;
7478 /* ascertain this is a normal queue*/
7479 txdata = &fp->txdata[tx_index];
7481 DP(NETIF_MSG_IFDOWN, "stopping tx-only queue %d\n",
7484 /* send halt terminate on tx-only connection */
7485 q_params.cmd = BNX2X_Q_CMD_TERMINATE;
7486 memset(&q_params.params.terminate, 0,
7487 sizeof(q_params.params.terminate));
7488 q_params.params.terminate.cid_index = tx_index;
7490 rc = bnx2x_queue_state_change(bp, &q_params);
7494 /* send halt terminate on tx-only connection */
7495 q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
7496 memset(&q_params.params.cfc_del, 0,
7497 sizeof(q_params.params.cfc_del));
7498 q_params.params.cfc_del.cid_index = tx_index;
7499 rc = bnx2x_queue_state_change(bp, &q_params);
7503 /* Stop the primary connection: */
7504 /* ...halt the connection */
7505 q_params.cmd = BNX2X_Q_CMD_HALT;
7506 rc = bnx2x_queue_state_change(bp, &q_params);
7510 /* ...terminate the connection */
7511 q_params.cmd = BNX2X_Q_CMD_TERMINATE;
7512 memset(&q_params.params.terminate, 0,
7513 sizeof(q_params.params.terminate));
7514 q_params.params.terminate.cid_index = FIRST_TX_COS_INDEX;
7515 rc = bnx2x_queue_state_change(bp, &q_params);
7518 /* ...delete cfc entry */
7519 q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
7520 memset(&q_params.params.cfc_del, 0,
7521 sizeof(q_params.params.cfc_del));
7522 q_params.params.cfc_del.cid_index = FIRST_TX_COS_INDEX;
7523 return bnx2x_queue_state_change(bp, &q_params);
7527 static void bnx2x_reset_func(struct bnx2x *bp)
7529 int port = BP_PORT(bp);
7530 int func = BP_FUNC(bp);
7533 /* Disable the function in the FW */
7534 REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(func), 0);
7535 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(func), 0);
7536 REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(func), 0);
7537 REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(func), 0);
7540 for_each_eth_queue(bp, i) {
7541 struct bnx2x_fastpath *fp = &bp->fp[i];
7542 REG_WR8(bp, BAR_CSTRORM_INTMEM +
7543 CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(fp->fw_sb_id),
7549 REG_WR8(bp, BAR_CSTRORM_INTMEM +
7550 CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(bnx2x_cnic_fw_sb_id(bp)),
7554 REG_WR8(bp, BAR_CSTRORM_INTMEM +
7555 CSTORM_SP_STATUS_BLOCK_DATA_STATE_OFFSET(func),
7558 for (i = 0; i < XSTORM_SPQ_DATA_SIZE / 4; i++)
7559 REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_DATA_OFFSET(func),
7563 if (bp->common.int_block == INT_BLOCK_HC) {
7564 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
7565 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
7567 REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
7568 REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
7572 /* Disable Timer scan */
7573 REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + port*4, 0);
7575 * Wait for at least 10ms and up to 2 second for the timers scan to
7578 for (i = 0; i < 200; i++) {
7580 if (!REG_RD(bp, TM_REG_LIN0_SCAN_ON + port*4))
7585 bnx2x_clear_func_ilt(bp, func);
7587 /* Timers workaround bug for E2: if this is vnic-3,
7588 * we need to set the entire ilt range for this timers.
7590 if (!CHIP_IS_E1x(bp) && BP_VN(bp) == 3) {
7591 struct ilt_client_info ilt_cli;
7592 /* use dummy TM client */
7593 memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
7595 ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
7596 ilt_cli.client_num = ILT_CLIENT_TM;
7598 bnx2x_ilt_boundry_init_op(bp, &ilt_cli, 0, INITOP_CLEAR);
7601 /* this assumes that reset_port() called before reset_func()*/
7602 if (!CHIP_IS_E1x(bp))
7603 bnx2x_pf_disable(bp);
7608 static void bnx2x_reset_port(struct bnx2x *bp)
7610 int port = BP_PORT(bp);
7613 /* Reset physical Link */
7614 bnx2x__link_reset(bp);
7616 REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
7618 /* Do not rcv packets to BRB */
7619 REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0);
7620 /* Do not direct rcv packets that are not for MCP to the BRB */
7621 REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
7622 NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
7625 REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0);
7628 /* Check for BRB port occupancy */
7629 val = REG_RD(bp, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4);
7631 DP(NETIF_MSG_IFDOWN,
7632 "BRB1 is not empty %d blocks are occupied\n", val);
7634 /* TODO: Close Doorbell port? */
7637 static inline int bnx2x_reset_hw(struct bnx2x *bp, u32 load_code)
7639 struct bnx2x_func_state_params func_params = {NULL};
7641 /* Prepare parameters for function state transitions */
7642 __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
7644 func_params.f_obj = &bp->func_obj;
7645 func_params.cmd = BNX2X_F_CMD_HW_RESET;
7647 func_params.params.hw_init.load_phase = load_code;
7649 return bnx2x_func_state_change(bp, &func_params);
7652 static inline int bnx2x_func_stop(struct bnx2x *bp)
7654 struct bnx2x_func_state_params func_params = {NULL};
7657 /* Prepare parameters for function state transitions */
7658 __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
7659 func_params.f_obj = &bp->func_obj;
7660 func_params.cmd = BNX2X_F_CMD_STOP;
7663 * Try to stop the function the 'good way'. If fails (in case
7664 * of a parity error during bnx2x_chip_cleanup()) and we are
7665 * not in a debug mode, perform a state transaction in order to
7666 * enable further HW_RESET transaction.
7668 rc = bnx2x_func_state_change(bp, &func_params);
7670 #ifdef BNX2X_STOP_ON_ERROR
7673 BNX2X_ERR("FUNC_STOP ramrod failed. Running a dry transaction\n");
7674 __set_bit(RAMROD_DRV_CLR_ONLY, &func_params.ramrod_flags);
7675 return bnx2x_func_state_change(bp, &func_params);
7683 * bnx2x_send_unload_req - request unload mode from the MCP.
7685 * @bp: driver handle
7686 * @unload_mode: requested function's unload mode
7688 * Return unload mode returned by the MCP: COMMON, PORT or FUNC.
7690 u32 bnx2x_send_unload_req(struct bnx2x *bp, int unload_mode)
7693 int port = BP_PORT(bp);
7695 /* Select the UNLOAD request mode */
7696 if (unload_mode == UNLOAD_NORMAL)
7697 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
7699 else if (bp->flags & NO_WOL_FLAG)
7700 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP;
7703 u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
7704 u8 *mac_addr = bp->dev->dev_addr;
7708 /* The mac address is written to entries 1-4 to
7709 * preserve entry 0 which is used by the PMF
7711 u8 entry = (BP_VN(bp) + 1)*8;
7713 val = (mac_addr[0] << 8) | mac_addr[1];
7714 EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry, val);
7716 val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
7717 (mac_addr[4] << 8) | mac_addr[5];
7718 EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry + 4, val);
7720 /* Enable the PME and clear the status */
7721 pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, &pmc);
7722 pmc |= PCI_PM_CTRL_PME_ENABLE | PCI_PM_CTRL_PME_STATUS;
7723 pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, pmc);
7725 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_EN;
7728 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
7730 /* Send the request to the MCP */
7732 reset_code = bnx2x_fw_command(bp, reset_code, 0);
7734 int path = BP_PATH(bp);
7736 DP(NETIF_MSG_IFDOWN, "NO MCP - load counts[%d] %d, %d, %d\n",
7737 path, load_count[path][0], load_count[path][1],
7738 load_count[path][2]);
7739 load_count[path][0]--;
7740 load_count[path][1 + port]--;
7741 DP(NETIF_MSG_IFDOWN, "NO MCP - new load counts[%d] %d, %d, %d\n",
7742 path, load_count[path][0], load_count[path][1],
7743 load_count[path][2]);
7744 if (load_count[path][0] == 0)
7745 reset_code = FW_MSG_CODE_DRV_UNLOAD_COMMON;
7746 else if (load_count[path][1 + port] == 0)
7747 reset_code = FW_MSG_CODE_DRV_UNLOAD_PORT;
7749 reset_code = FW_MSG_CODE_DRV_UNLOAD_FUNCTION;
7756 * bnx2x_send_unload_done - send UNLOAD_DONE command to the MCP.
7758 * @bp: driver handle
7760 void bnx2x_send_unload_done(struct bnx2x *bp)
7762 /* Report UNLOAD_DONE to MCP */
7764 bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
7767 static inline int bnx2x_func_wait_started(struct bnx2x *bp)
7770 int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
7776 * (assumption: No Attention from MCP at this stage)
7777 * PMF probably in the middle of TXdisable/enable transaction
7778 * 1. Sync IRS for default SB
7779 * 2. Sync SP queue - this guarantes us that attention handling started
7780 * 3. Wait, that TXdisable/enable transaction completes
7782 * 1+2 guranty that if DCBx attention was scheduled it already changed
7783 * pending bit of transaction from STARTED-->TX_STOPPED, if we alredy
7784 * received complettion for the transaction the state is TX_STOPPED.
7785 * State will return to STARTED after completion of TX_STOPPED-->STARTED
7789 /* make sure default SB ISR is done */
7791 synchronize_irq(bp->msix_table[0].vector);
7793 synchronize_irq(bp->pdev->irq);
7795 flush_workqueue(bnx2x_wq);
7797 while (bnx2x_func_get_state(bp, &bp->func_obj) !=
7798 BNX2X_F_STATE_STARTED && tout--)
7801 if (bnx2x_func_get_state(bp, &bp->func_obj) !=
7802 BNX2X_F_STATE_STARTED) {
7803 #ifdef BNX2X_STOP_ON_ERROR
7804 BNX2X_ERR("Wrong function state\n");
7808 * Failed to complete the transaction in a "good way"
7809 * Force both transactions with CLR bit
7811 struct bnx2x_func_state_params func_params = {NULL};
7813 DP(NETIF_MSG_IFDOWN,
7814 "Hmmm... unexpected function state! Forcing STARTED-->TX_ST0PPED-->STARTED\n");
7816 func_params.f_obj = &bp->func_obj;
7817 __set_bit(RAMROD_DRV_CLR_ONLY,
7818 &func_params.ramrod_flags);
7820 /* STARTED-->TX_ST0PPED */
7821 func_params.cmd = BNX2X_F_CMD_TX_STOP;
7822 bnx2x_func_state_change(bp, &func_params);
7824 /* TX_ST0PPED-->STARTED */
7825 func_params.cmd = BNX2X_F_CMD_TX_START;
7826 return bnx2x_func_state_change(bp, &func_params);
7833 void bnx2x_chip_cleanup(struct bnx2x *bp, int unload_mode)
7835 int port = BP_PORT(bp);
7838 struct bnx2x_mcast_ramrod_params rparam = {NULL};
7841 /* Wait until tx fastpath tasks complete */
7842 for_each_tx_queue(bp, i) {
7843 struct bnx2x_fastpath *fp = &bp->fp[i];
7845 for_each_cos_in_tx_queue(fp, cos)
7846 rc = bnx2x_clean_tx_queue(bp, &fp->txdata[cos]);
7847 #ifdef BNX2X_STOP_ON_ERROR
7853 /* Give HW time to discard old tx messages */
7854 usleep_range(1000, 1000);
7856 /* Clean all ETH MACs */
7857 rc = bnx2x_del_all_macs(bp, &bp->fp[0].mac_obj, BNX2X_ETH_MAC, false);
7859 BNX2X_ERR("Failed to delete all ETH macs: %d\n", rc);
7861 /* Clean up UC list */
7862 rc = bnx2x_del_all_macs(bp, &bp->fp[0].mac_obj, BNX2X_UC_LIST_MAC,
7865 BNX2X_ERR("Failed to schedule DEL commands for UC MACs list: %d\n",
7869 if (!CHIP_IS_E1(bp))
7870 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
7872 /* Set "drop all" (stop Rx).
7873 * We need to take a netif_addr_lock() here in order to prevent
7874 * a race between the completion code and this code.
7876 netif_addr_lock_bh(bp->dev);
7877 /* Schedule the rx_mode command */
7878 if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
7879 set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
7881 bnx2x_set_storm_rx_mode(bp);
7883 /* Cleanup multicast configuration */
7884 rparam.mcast_obj = &bp->mcast_obj;
7885 rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
7887 BNX2X_ERR("Failed to send DEL multicast command: %d\n", rc);
7889 netif_addr_unlock_bh(bp->dev);
7894 * Send the UNLOAD_REQUEST to the MCP. This will return if
7895 * this function should perform FUNC, PORT or COMMON HW
7898 reset_code = bnx2x_send_unload_req(bp, unload_mode);
7901 * (assumption: No Attention from MCP at this stage)
7902 * PMF probably in the middle of TXdisable/enable transaction
7904 rc = bnx2x_func_wait_started(bp);
7906 BNX2X_ERR("bnx2x_func_wait_started failed\n");
7907 #ifdef BNX2X_STOP_ON_ERROR
7912 /* Close multi and leading connections
7913 * Completions for ramrods are collected in a synchronous way
7915 for_each_queue(bp, i)
7916 if (bnx2x_stop_queue(bp, i))
7917 #ifdef BNX2X_STOP_ON_ERROR
7922 /* If SP settings didn't get completed so far - something
7923 * very wrong has happen.
7925 if (!bnx2x_wait_sp_comp(bp, ~0x0UL))
7926 BNX2X_ERR("Hmmm... Common slow path ramrods got stuck!\n");
7928 #ifndef BNX2X_STOP_ON_ERROR
7931 rc = bnx2x_func_stop(bp);
7933 BNX2X_ERR("Function stop failed!\n");
7934 #ifdef BNX2X_STOP_ON_ERROR
7939 /* Disable HW interrupts, NAPI */
7940 bnx2x_netif_stop(bp, 1);
7945 /* Reset the chip */
7946 rc = bnx2x_reset_hw(bp, reset_code);
7948 BNX2X_ERR("HW_RESET failed\n");
7951 /* Report UNLOAD_DONE to MCP */
7952 bnx2x_send_unload_done(bp);
7955 void bnx2x_disable_close_the_gate(struct bnx2x *bp)
7959 DP(NETIF_MSG_IFDOWN, "Disabling \"close the gates\"\n");
7961 if (CHIP_IS_E1(bp)) {
7962 int port = BP_PORT(bp);
7963 u32 addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
7964 MISC_REG_AEU_MASK_ATTN_FUNC_0;
7966 val = REG_RD(bp, addr);
7968 REG_WR(bp, addr, val);
7970 val = REG_RD(bp, MISC_REG_AEU_GENERAL_MASK);
7971 val &= ~(MISC_AEU_GENERAL_MASK_REG_AEU_PXP_CLOSE_MASK |
7972 MISC_AEU_GENERAL_MASK_REG_AEU_NIG_CLOSE_MASK);
7973 REG_WR(bp, MISC_REG_AEU_GENERAL_MASK, val);
7977 /* Close gates #2, #3 and #4: */
7978 static void bnx2x_set_234_gates(struct bnx2x *bp, bool close)
7982 /* Gates #2 and #4a are closed/opened for "not E1" only */
7983 if (!CHIP_IS_E1(bp)) {
7985 REG_WR(bp, PXP_REG_HST_DISCARD_DOORBELLS, !!close);
7987 REG_WR(bp, PXP_REG_HST_DISCARD_INTERNAL_WRITES, !!close);
7991 if (CHIP_IS_E1x(bp)) {
7992 /* Prevent interrupts from HC on both ports */
7993 val = REG_RD(bp, HC_REG_CONFIG_1);
7994 REG_WR(bp, HC_REG_CONFIG_1,
7995 (!close) ? (val | HC_CONFIG_1_REG_BLOCK_DISABLE_1) :
7996 (val & ~(u32)HC_CONFIG_1_REG_BLOCK_DISABLE_1));
7998 val = REG_RD(bp, HC_REG_CONFIG_0);
7999 REG_WR(bp, HC_REG_CONFIG_0,
8000 (!close) ? (val | HC_CONFIG_0_REG_BLOCK_DISABLE_0) :
8001 (val & ~(u32)HC_CONFIG_0_REG_BLOCK_DISABLE_0));
8003 /* Prevent incomming interrupts in IGU */
8004 val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
8006 REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION,
8008 (val | IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE) :
8009 (val & ~(u32)IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE));
8012 DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "%s gates #2, #3 and #4\n",
8013 close ? "closing" : "opening");
8017 #define SHARED_MF_CLP_MAGIC 0x80000000 /* `magic' bit */
8019 static void bnx2x_clp_reset_prep(struct bnx2x *bp, u32 *magic_val)
8021 /* Do some magic... */
8022 u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
8023 *magic_val = val & SHARED_MF_CLP_MAGIC;
8024 MF_CFG_WR(bp, shared_mf_config.clp_mb, val | SHARED_MF_CLP_MAGIC);
8028 * bnx2x_clp_reset_done - restore the value of the `magic' bit.
8030 * @bp: driver handle
8031 * @magic_val: old value of the `magic' bit.
8033 static void bnx2x_clp_reset_done(struct bnx2x *bp, u32 magic_val)
8035 /* Restore the `magic' bit value... */
8036 u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
8037 MF_CFG_WR(bp, shared_mf_config.clp_mb,
8038 (val & (~SHARED_MF_CLP_MAGIC)) | magic_val);
8042 * bnx2x_reset_mcp_prep - prepare for MCP reset.
8044 * @bp: driver handle
8045 * @magic_val: old value of 'magic' bit.
8047 * Takes care of CLP configurations.
8049 static void bnx2x_reset_mcp_prep(struct bnx2x *bp, u32 *magic_val)
8052 u32 validity_offset;
8054 DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "Starting\n");
8056 /* Set `magic' bit in order to save MF config */
8057 if (!CHIP_IS_E1(bp))
8058 bnx2x_clp_reset_prep(bp, magic_val);
8060 /* Get shmem offset */
8061 shmem = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
8062 validity_offset = offsetof(struct shmem_region, validity_map[0]);
8064 /* Clear validity map flags */
8066 REG_WR(bp, shmem + validity_offset, 0);
8069 #define MCP_TIMEOUT 5000 /* 5 seconds (in ms) */
8070 #define MCP_ONE_TIMEOUT 100 /* 100 ms */
8073 * bnx2x_mcp_wait_one - wait for MCP_ONE_TIMEOUT
8075 * @bp: driver handle
8077 static inline void bnx2x_mcp_wait_one(struct bnx2x *bp)
8079 /* special handling for emulation and FPGA,
8080 wait 10 times longer */
8081 if (CHIP_REV_IS_SLOW(bp))
8082 msleep(MCP_ONE_TIMEOUT*10);
8084 msleep(MCP_ONE_TIMEOUT);
8088 * initializes bp->common.shmem_base and waits for validity signature to appear
8090 static int bnx2x_init_shmem(struct bnx2x *bp)
8096 bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
8097 if (bp->common.shmem_base) {
8098 val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
8099 if (val & SHR_MEM_VALIDITY_MB)
8103 bnx2x_mcp_wait_one(bp);
8105 } while (cnt++ < (MCP_TIMEOUT / MCP_ONE_TIMEOUT));
8107 BNX2X_ERR("BAD MCP validity signature\n");
8112 static int bnx2x_reset_mcp_comp(struct bnx2x *bp, u32 magic_val)
8114 int rc = bnx2x_init_shmem(bp);
8116 /* Restore the `magic' bit value */
8117 if (!CHIP_IS_E1(bp))
8118 bnx2x_clp_reset_done(bp, magic_val);
8123 static void bnx2x_pxp_prep(struct bnx2x *bp)
8125 if (!CHIP_IS_E1(bp)) {
8126 REG_WR(bp, PXP2_REG_RD_START_INIT, 0);
8127 REG_WR(bp, PXP2_REG_RQ_RBC_DONE, 0);
8133 * Reset the whole chip except for:
8135 * - PCI Glue, PSWHST, PXP/PXP2 RF (all controlled by
8138 * - MISC (including AEU)
8142 static void bnx2x_process_kill_chip_reset(struct bnx2x *bp, bool global)
8144 u32 not_reset_mask1, reset_mask1, not_reset_mask2, reset_mask2;
8145 u32 global_bits2, stay_reset2;
8148 * Bits that have to be set in reset_mask2 if we want to reset 'global'
8149 * (per chip) blocks.
8152 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CPU |
8153 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CORE;
8155 /* Don't reset the following blocks */
8157 MISC_REGISTERS_RESET_REG_1_RST_HC |
8158 MISC_REGISTERS_RESET_REG_1_RST_PXPV |
8159 MISC_REGISTERS_RESET_REG_1_RST_PXP;
8162 MISC_REGISTERS_RESET_REG_2_RST_PCI_MDIO |
8163 MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE |
8164 MISC_REGISTERS_RESET_REG_2_RST_EMAC1_HARD_CORE |
8165 MISC_REGISTERS_RESET_REG_2_RST_MISC_CORE |
8166 MISC_REGISTERS_RESET_REG_2_RST_RBCN |
8167 MISC_REGISTERS_RESET_REG_2_RST_GRC |
8168 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_REG_HARD_CORE |
8169 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_HARD_CORE_RST_B |
8170 MISC_REGISTERS_RESET_REG_2_RST_ATC |
8171 MISC_REGISTERS_RESET_REG_2_PGLC;
8174 * Keep the following blocks in reset:
8175 * - all xxMACs are handled by the bnx2x_link code.
8178 MISC_REGISTERS_RESET_REG_2_RST_BMAC0 |
8179 MISC_REGISTERS_RESET_REG_2_RST_BMAC1 |
8180 MISC_REGISTERS_RESET_REG_2_RST_EMAC0 |
8181 MISC_REGISTERS_RESET_REG_2_RST_EMAC1 |
8182 MISC_REGISTERS_RESET_REG_2_UMAC0 |
8183 MISC_REGISTERS_RESET_REG_2_UMAC1 |
8184 MISC_REGISTERS_RESET_REG_2_XMAC |
8185 MISC_REGISTERS_RESET_REG_2_XMAC_SOFT;
8187 /* Full reset masks according to the chip */
8188 reset_mask1 = 0xffffffff;
8191 reset_mask2 = 0xffff;
8192 else if (CHIP_IS_E1H(bp))
8193 reset_mask2 = 0x1ffff;
8194 else if (CHIP_IS_E2(bp))
8195 reset_mask2 = 0xfffff;
8196 else /* CHIP_IS_E3 */
8197 reset_mask2 = 0x3ffffff;
8199 /* Don't reset global blocks unless we need to */
8201 reset_mask2 &= ~global_bits2;
8204 * In case of attention in the QM, we need to reset PXP
8205 * (MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR) before QM
8206 * because otherwise QM reset would release 'close the gates' shortly
8207 * before resetting the PXP, then the PSWRQ would send a write
8208 * request to PGLUE. Then when PXP is reset, PGLUE would try to
8209 * read the payload data from PSWWR, but PSWWR would not
8210 * respond. The write queue in PGLUE would stuck, dmae commands
8211 * would not return. Therefore it's important to reset the second
8212 * reset register (containing the
8213 * MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR bit) before the
8214 * first one (containing the MISC_REGISTERS_RESET_REG_1_RST_QM
8217 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
8218 reset_mask2 & (~not_reset_mask2));
8220 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
8221 reset_mask1 & (~not_reset_mask1));
8226 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
8227 reset_mask2 & (~stay_reset2));
8232 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, reset_mask1);
8237 * bnx2x_er_poll_igu_vq - poll for pending writes bit.
8238 * It should get cleared in no more than 1s.
8240 * @bp: driver handle
8242 * It should get cleared in no more than 1s. Returns 0 if
8243 * pending writes bit gets cleared.
8245 static int bnx2x_er_poll_igu_vq(struct bnx2x *bp)
8251 pend_bits = REG_RD(bp, IGU_REG_PENDING_BITS_STATUS);
8256 usleep_range(1000, 1000);
8257 } while (cnt-- > 0);
8260 BNX2X_ERR("Still pending IGU requests pend_bits=%x!\n",
8268 static int bnx2x_process_kill(struct bnx2x *bp, bool global)
8272 u32 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, pgl_exp_rom2;
8275 /* Empty the Tetris buffer, wait for 1s */
8277 sr_cnt = REG_RD(bp, PXP2_REG_RD_SR_CNT);
8278 blk_cnt = REG_RD(bp, PXP2_REG_RD_BLK_CNT);
8279 port_is_idle_0 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_0);
8280 port_is_idle_1 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_1);
8281 pgl_exp_rom2 = REG_RD(bp, PXP2_REG_PGL_EXP_ROM2);
8282 if ((sr_cnt == 0x7e) && (blk_cnt == 0xa0) &&
8283 ((port_is_idle_0 & 0x1) == 0x1) &&
8284 ((port_is_idle_1 & 0x1) == 0x1) &&
8285 (pgl_exp_rom2 == 0xffffffff))
8287 usleep_range(1000, 1000);
8288 } while (cnt-- > 0);
8291 BNX2X_ERR("Tetris buffer didn't get empty or there are still outstanding read requests after 1s!\n");
8292 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",
8293 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1,
8300 /* Close gates #2, #3 and #4 */
8301 bnx2x_set_234_gates(bp, true);
8303 /* Poll for IGU VQs for 57712 and newer chips */
8304 if (!CHIP_IS_E1x(bp) && bnx2x_er_poll_igu_vq(bp))
8308 /* TBD: Indicate that "process kill" is in progress to MCP */
8310 /* Clear "unprepared" bit */
8311 REG_WR(bp, MISC_REG_UNPREPARED, 0);
8314 /* Make sure all is written to the chip before the reset */
8317 /* Wait for 1ms to empty GLUE and PCI-E core queues,
8318 * PSWHST, GRC and PSWRD Tetris buffer.
8320 usleep_range(1000, 1000);
8322 /* Prepare to chip reset: */
8325 bnx2x_reset_mcp_prep(bp, &val);
8331 /* reset the chip */
8332 bnx2x_process_kill_chip_reset(bp, global);
8335 /* Recover after reset: */
8337 if (global && bnx2x_reset_mcp_comp(bp, val))
8340 /* TBD: Add resetting the NO_MCP mode DB here */
8345 /* Open the gates #2, #3 and #4 */
8346 bnx2x_set_234_gates(bp, false);
8348 /* TBD: IGU/AEU preparation bring back the AEU/IGU to a
8349 * reset state, re-enable attentions. */
8354 int bnx2x_leader_reset(struct bnx2x *bp)
8357 bool global = bnx2x_reset_is_global(bp);
8360 /* if not going to reset MCP - load "fake" driver to reset HW while
8361 * driver is owner of the HW
8363 if (!global && !BP_NOMCP(bp)) {
8364 load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_REQ, 0);
8366 BNX2X_ERR("MCP response failure, aborting\n");
8368 goto exit_leader_reset;
8370 if ((load_code != FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) &&
8371 (load_code != FW_MSG_CODE_DRV_LOAD_COMMON)) {
8372 BNX2X_ERR("MCP unexpected resp, aborting\n");
8374 goto exit_leader_reset2;
8376 load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_DONE, 0);
8378 BNX2X_ERR("MCP response failure, aborting\n");
8380 goto exit_leader_reset2;
8384 /* Try to recover after the failure */
8385 if (bnx2x_process_kill(bp, global)) {
8386 BNX2X_ERR("Something bad had happen on engine %d! Aii!\n",
8389 goto exit_leader_reset2;
8393 * Clear RESET_IN_PROGRES and RESET_GLOBAL bits and update the driver
8396 bnx2x_set_reset_done(bp);
8398 bnx2x_clear_reset_global(bp);
8401 /* unload "fake driver" if it was loaded */
8402 if (!global && !BP_NOMCP(bp)) {
8403 bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP, 0);
8404 bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
8408 bnx2x_release_leader_lock(bp);
8413 static inline void bnx2x_recovery_failed(struct bnx2x *bp)
8415 netdev_err(bp->dev, "Recovery has failed. Power cycle is needed.\n");
8417 /* Disconnect this device */
8418 netif_device_detach(bp->dev);
8421 * Block ifup for all function on this engine until "process kill"
8424 bnx2x_set_reset_in_progress(bp);
8426 /* Shut down the power */
8427 bnx2x_set_power_state(bp, PCI_D3hot);
8429 bp->recovery_state = BNX2X_RECOVERY_FAILED;
8435 * Assumption: runs under rtnl lock. This together with the fact
8436 * that it's called only from bnx2x_sp_rtnl() ensure that it
8437 * will never be called when netif_running(bp->dev) is false.
8439 static void bnx2x_parity_recover(struct bnx2x *bp)
8441 bool global = false;
8442 u32 error_recovered, error_unrecovered;
8445 DP(NETIF_MSG_HW, "Handling parity\n");
8447 switch (bp->recovery_state) {
8448 case BNX2X_RECOVERY_INIT:
8449 DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_INIT\n");
8450 is_parity = bnx2x_chk_parity_attn(bp, &global, false);
8451 WARN_ON(!is_parity);
8453 /* Try to get a LEADER_LOCK HW lock */
8454 if (bnx2x_trylock_leader_lock(bp)) {
8455 bnx2x_set_reset_in_progress(bp);
8457 * Check if there is a global attention and if
8458 * there was a global attention, set the global
8463 bnx2x_set_reset_global(bp);
8468 /* Stop the driver */
8469 /* If interface has been removed - break */
8470 if (bnx2x_nic_unload(bp, UNLOAD_RECOVERY))
8473 bp->recovery_state = BNX2X_RECOVERY_WAIT;
8475 /* Ensure "is_leader", MCP command sequence and
8476 * "recovery_state" update values are seen on other
8482 case BNX2X_RECOVERY_WAIT:
8483 DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_WAIT\n");
8484 if (bp->is_leader) {
8485 int other_engine = BP_PATH(bp) ? 0 : 1;
8486 bool other_load_status =
8487 bnx2x_get_load_status(bp, other_engine);
8489 bnx2x_get_load_status(bp, BP_PATH(bp));
8490 global = bnx2x_reset_is_global(bp);
8493 * In case of a parity in a global block, let
8494 * the first leader that performs a
8495 * leader_reset() reset the global blocks in
8496 * order to clear global attentions. Otherwise
8497 * the the gates will remain closed for that
8501 (global && other_load_status)) {
8502 /* Wait until all other functions get
8505 schedule_delayed_work(&bp->sp_rtnl_task,
8509 /* If all other functions got down -
8510 * try to bring the chip back to
8511 * normal. In any case it's an exit
8512 * point for a leader.
8514 if (bnx2x_leader_reset(bp)) {
8515 bnx2x_recovery_failed(bp);
8519 /* If we are here, means that the
8520 * leader has succeeded and doesn't
8521 * want to be a leader any more. Try
8522 * to continue as a none-leader.
8526 } else { /* non-leader */
8527 if (!bnx2x_reset_is_done(bp, BP_PATH(bp))) {
8528 /* Try to get a LEADER_LOCK HW lock as
8529 * long as a former leader may have
8530 * been unloaded by the user or
8531 * released a leadership by another
8534 if (bnx2x_trylock_leader_lock(bp)) {
8535 /* I'm a leader now! Restart a
8542 schedule_delayed_work(&bp->sp_rtnl_task,
8548 * If there was a global attention, wait
8549 * for it to be cleared.
8551 if (bnx2x_reset_is_global(bp)) {
8552 schedule_delayed_work(
8559 bp->eth_stats.recoverable_error;
8561 bp->eth_stats.unrecoverable_error;
8562 bp->recovery_state =
8563 BNX2X_RECOVERY_NIC_LOADING;
8564 if (bnx2x_nic_load(bp, LOAD_NORMAL)) {
8565 error_unrecovered++;
8567 "Recovery failed. Power cycle needed\n");
8568 /* Disconnect this device */
8569 netif_device_detach(bp->dev);
8570 /* Shut down the power */
8571 bnx2x_set_power_state(
8575 bp->recovery_state =
8576 BNX2X_RECOVERY_DONE;
8580 bp->eth_stats.recoverable_error =
8582 bp->eth_stats.unrecoverable_error =
8594 static int bnx2x_close(struct net_device *dev);
8596 /* bnx2x_nic_unload() flushes the bnx2x_wq, thus reset task is
8597 * scheduled on a general queue in order to prevent a dead lock.
8599 static void bnx2x_sp_rtnl_task(struct work_struct *work)
8601 struct bnx2x *bp = container_of(work, struct bnx2x, sp_rtnl_task.work);
8605 if (!netif_running(bp->dev))
8608 /* if stop on error is defined no recovery flows should be executed */
8609 #ifdef BNX2X_STOP_ON_ERROR
8610 BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n"
8611 "you will need to reboot when done\n");
8612 goto sp_rtnl_not_reset;
8615 if (unlikely(bp->recovery_state != BNX2X_RECOVERY_DONE)) {
8617 * Clear all pending SP commands as we are going to reset the
8620 bp->sp_rtnl_state = 0;
8623 bnx2x_parity_recover(bp);
8628 if (test_and_clear_bit(BNX2X_SP_RTNL_TX_TIMEOUT, &bp->sp_rtnl_state)) {
8630 * Clear all pending SP commands as we are going to reset the
8633 bp->sp_rtnl_state = 0;
8636 bnx2x_nic_unload(bp, UNLOAD_NORMAL);
8637 bnx2x_nic_load(bp, LOAD_NORMAL);
8641 #ifdef BNX2X_STOP_ON_ERROR
8644 if (test_and_clear_bit(BNX2X_SP_RTNL_SETUP_TC, &bp->sp_rtnl_state))
8645 bnx2x_setup_tc(bp->dev, bp->dcbx_port_params.ets.num_of_cos);
8648 * in case of fan failure we need to reset id if the "stop on error"
8649 * debug flag is set, since we trying to prevent permanent overheating
8652 if (test_and_clear_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state)) {
8653 DP(NETIF_MSG_HW, "fan failure detected. Unloading driver\n");
8654 netif_device_detach(bp->dev);
8655 bnx2x_close(bp->dev);
8662 /* end of nic load/unload */
8664 static void bnx2x_period_task(struct work_struct *work)
8666 struct bnx2x *bp = container_of(work, struct bnx2x, period_task.work);
8668 if (!netif_running(bp->dev))
8669 goto period_task_exit;
8671 if (CHIP_REV_IS_SLOW(bp)) {
8672 BNX2X_ERR("period task called on emulation, ignoring\n");
8673 goto period_task_exit;
8676 bnx2x_acquire_phy_lock(bp);
8678 * The barrier is needed to ensure the ordering between the writing to
8679 * the bp->port.pmf in the bnx2x_nic_load() or bnx2x_pmf_update() and
8684 bnx2x_period_func(&bp->link_params, &bp->link_vars);
8686 /* Re-queue task in 1 sec */
8687 queue_delayed_work(bnx2x_wq, &bp->period_task, 1*HZ);
8690 bnx2x_release_phy_lock(bp);
8696 * Init service functions
8699 static u32 bnx2x_get_pretend_reg(struct bnx2x *bp)
8701 u32 base = PXP2_REG_PGL_PRETEND_FUNC_F0;
8702 u32 stride = PXP2_REG_PGL_PRETEND_FUNC_F1 - base;
8703 return base + (BP_ABS_FUNC(bp)) * stride;
8706 static void bnx2x_undi_int_disable_e1h(struct bnx2x *bp)
8708 u32 reg = bnx2x_get_pretend_reg(bp);
8710 /* Flush all outstanding writes */
8713 /* Pretend to be function 0 */
8715 REG_RD(bp, reg); /* Flush the GRC transaction (in the chip) */
8717 /* From now we are in the "like-E1" mode */
8718 bnx2x_int_disable(bp);
8720 /* Flush all outstanding writes */
8723 /* Restore the original function */
8724 REG_WR(bp, reg, BP_ABS_FUNC(bp));
8728 static inline void bnx2x_undi_int_disable(struct bnx2x *bp)
8731 bnx2x_int_disable(bp);
8733 bnx2x_undi_int_disable_e1h(bp);
8736 static void __devinit bnx2x_prev_unload_close_mac(struct bnx2x *bp)
8738 u32 val, base_addr, offset, mask, reset_reg;
8739 bool mac_stopped = false;
8740 u8 port = BP_PORT(bp);
8742 reset_reg = REG_RD(bp, MISC_REG_RESET_REG_2);
8744 if (!CHIP_IS_E3(bp)) {
8745 val = REG_RD(bp, NIG_REG_BMAC0_REGS_OUT_EN + port * 4);
8746 mask = MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port;
8747 if ((mask & reset_reg) && val) {
8749 BNX2X_DEV_INFO("Disable bmac Rx\n");
8750 base_addr = BP_PORT(bp) ? NIG_REG_INGRESS_BMAC1_MEM
8751 : NIG_REG_INGRESS_BMAC0_MEM;
8752 offset = CHIP_IS_E2(bp) ? BIGMAC2_REGISTER_BMAC_CONTROL
8753 : BIGMAC_REGISTER_BMAC_CONTROL;
8756 * use rd/wr since we cannot use dmae. This is safe
8757 * since MCP won't access the bus due to the request
8758 * to unload, and no function on the path can be
8759 * loaded at this time.
8761 wb_data[0] = REG_RD(bp, base_addr + offset);
8762 wb_data[1] = REG_RD(bp, base_addr + offset + 0x4);
8763 wb_data[0] &= ~BMAC_CONTROL_RX_ENABLE;
8764 REG_WR(bp, base_addr + offset, wb_data[0]);
8765 REG_WR(bp, base_addr + offset + 0x4, wb_data[1]);
8768 BNX2X_DEV_INFO("Disable emac Rx\n");
8769 REG_WR(bp, NIG_REG_NIG_EMAC0_EN + BP_PORT(bp)*4, 0);
8773 if (reset_reg & MISC_REGISTERS_RESET_REG_2_XMAC) {
8774 BNX2X_DEV_INFO("Disable xmac Rx\n");
8775 base_addr = BP_PORT(bp) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
8776 val = REG_RD(bp, base_addr + XMAC_REG_PFC_CTRL_HI);
8777 REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
8779 REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
8781 REG_WR(bp, base_addr + XMAC_REG_CTRL, 0);
8784 mask = MISC_REGISTERS_RESET_REG_2_UMAC0 << port;
8785 if (mask & reset_reg) {
8786 BNX2X_DEV_INFO("Disable umac Rx\n");
8787 base_addr = BP_PORT(bp) ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
8788 REG_WR(bp, base_addr + UMAC_REG_COMMAND_CONFIG, 0);
8798 #define BNX2X_PREV_UNDI_PROD_ADDR(p) (BAR_TSTRORM_INTMEM + 0x1508 + ((p) << 4))
8799 #define BNX2X_PREV_UNDI_RCQ(val) ((val) & 0xffff)
8800 #define BNX2X_PREV_UNDI_BD(val) ((val) >> 16 & 0xffff)
8801 #define BNX2X_PREV_UNDI_PROD(rcq, bd) ((bd) << 16 | (rcq))
8803 static void __devinit bnx2x_prev_unload_undi_inc(struct bnx2x *bp, u8 port,
8807 u32 tmp_reg = REG_RD(bp, BNX2X_PREV_UNDI_PROD_ADDR(port));
8809 rcq = BNX2X_PREV_UNDI_RCQ(tmp_reg) + inc;
8810 bd = BNX2X_PREV_UNDI_BD(tmp_reg) + inc;
8812 tmp_reg = BNX2X_PREV_UNDI_PROD(rcq, bd);
8813 REG_WR(bp, BNX2X_PREV_UNDI_PROD_ADDR(port), tmp_reg);
8815 BNX2X_DEV_INFO("UNDI producer [%d] rings bd -> 0x%04x, rcq -> 0x%04x\n",
8819 static int __devinit bnx2x_prev_mcp_done(struct bnx2x *bp)
8821 u32 rc = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
8823 BNX2X_ERR("MCP response failure, aborting\n");
8830 static bool __devinit bnx2x_prev_is_path_marked(struct bnx2x *bp)
8832 struct bnx2x_prev_path_list *tmp_list;
8835 if (down_trylock(&bnx2x_prev_sem))
8838 list_for_each_entry(tmp_list, &bnx2x_prev_list, list) {
8839 if (PCI_SLOT(bp->pdev->devfn) == tmp_list->slot &&
8840 bp->pdev->bus->number == tmp_list->bus &&
8841 BP_PATH(bp) == tmp_list->path) {
8843 BNX2X_DEV_INFO("Path %d was already cleaned from previous drivers\n",
8849 up(&bnx2x_prev_sem);
8854 static int __devinit bnx2x_prev_mark_path(struct bnx2x *bp)
8856 struct bnx2x_prev_path_list *tmp_list;
8859 tmp_list = (struct bnx2x_prev_path_list *)
8860 kmalloc(sizeof(struct bnx2x_prev_path_list), GFP_KERNEL);
8862 BNX2X_ERR("Failed to allocate 'bnx2x_prev_path_list'\n");
8866 tmp_list->bus = bp->pdev->bus->number;
8867 tmp_list->slot = PCI_SLOT(bp->pdev->devfn);
8868 tmp_list->path = BP_PATH(bp);
8870 rc = down_interruptible(&bnx2x_prev_sem);
8872 BNX2X_ERR("Received %d when tried to take lock\n", rc);
8875 BNX2X_DEV_INFO("Marked path [%d] - finished previous unload\n",
8877 list_add(&tmp_list->list, &bnx2x_prev_list);
8878 up(&bnx2x_prev_sem);
8884 static bool __devinit bnx2x_can_flr(struct bnx2x *bp)
8888 struct pci_dev *dev = bp->pdev;
8890 pos = pci_pcie_cap(dev);
8894 pci_read_config_dword(dev, pos + PCI_EXP_DEVCAP, &cap);
8895 if (!(cap & PCI_EXP_DEVCAP_FLR))
8901 static int __devinit bnx2x_do_flr(struct bnx2x *bp)
8905 struct pci_dev *dev = bp->pdev;
8907 /* probe the capability first */
8908 if (bnx2x_can_flr(bp))
8911 pos = pci_pcie_cap(dev);
8915 /* Wait for Transaction Pending bit clean */
8916 for (i = 0; i < 4; i++) {
8918 msleep((1 << (i - 1)) * 100);
8920 pci_read_config_word(dev, pos + PCI_EXP_DEVSTA, &status);
8921 if (!(status & PCI_EXP_DEVSTA_TRPND))
8926 "transaction is not cleared; proceeding with reset anyway\n");
8929 if (bp->common.bc_ver < REQ_BC_VER_4_INITIATE_FLR) {
8930 BNX2X_ERR("FLR not supported by BC_VER: 0x%x\n",
8935 bnx2x_fw_command(bp, DRV_MSG_CODE_INITIATE_FLR, 0);
8940 static int __devinit bnx2x_prev_unload_uncommon(struct bnx2x *bp)
8944 BNX2X_DEV_INFO("Uncommon unload Flow\n");
8946 /* Test if previous unload process was already finished for this path */
8947 if (bnx2x_prev_is_path_marked(bp))
8948 return bnx2x_prev_mcp_done(bp);
8950 /* If function has FLR capabilities, and existing FW version matches
8951 * the one required, then FLR will be sufficient to clean any residue
8952 * left by previous driver
8954 if (bnx2x_test_firmware_version(bp, false) && bnx2x_can_flr(bp))
8955 return bnx2x_do_flr(bp);
8957 /* Close the MCP request, return failure*/
8958 rc = bnx2x_prev_mcp_done(bp);
8960 rc = BNX2X_PREV_WAIT_NEEDED;
8965 static int __devinit bnx2x_prev_unload_common(struct bnx2x *bp)
8967 u32 reset_reg, tmp_reg = 0, rc;
8968 /* It is possible a previous function received 'common' answer,
8969 * but hasn't loaded yet, therefore creating a scenario of
8970 * multiple functions receiving 'common' on the same path.
8972 BNX2X_DEV_INFO("Common unload Flow\n");
8974 if (bnx2x_prev_is_path_marked(bp))
8975 return bnx2x_prev_mcp_done(bp);
8977 reset_reg = REG_RD(bp, MISC_REG_RESET_REG_1);
8979 /* Reset should be performed after BRB is emptied */
8980 if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_BRB1) {
8981 u32 timer_count = 1000;
8982 bool prev_undi = false;
8984 /* Close the MAC Rx to prevent BRB from filling up */
8985 bnx2x_prev_unload_close_mac(bp);
8987 /* Check if the UNDI driver was previously loaded
8988 * UNDI driver initializes CID offset for normal bell to 0x7
8990 reset_reg = REG_RD(bp, MISC_REG_RESET_REG_1);
8991 if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_DORQ) {
8992 tmp_reg = REG_RD(bp, DORQ_REG_NORM_CID_OFST);
8993 if (tmp_reg == 0x7) {
8994 BNX2X_DEV_INFO("UNDI previously loaded\n");
8996 /* clear the UNDI indication */
8997 REG_WR(bp, DORQ_REG_NORM_CID_OFST, 0);
9000 /* wait until BRB is empty */
9001 tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
9002 while (timer_count) {
9003 u32 prev_brb = tmp_reg;
9005 tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
9009 BNX2X_DEV_INFO("BRB still has 0x%08x\n", tmp_reg);
9011 /* reset timer as long as BRB actually gets emptied */
9012 if (prev_brb > tmp_reg)
9017 /* If UNDI resides in memory, manually increment it */
9019 bnx2x_prev_unload_undi_inc(bp, BP_PORT(bp), 1);
9025 BNX2X_ERR("Failed to empty BRB, hope for the best\n");
9029 /* No packets are in the pipeline, path is ready for reset */
9030 bnx2x_reset_common(bp);
9032 rc = bnx2x_prev_mark_path(bp);
9034 bnx2x_prev_mcp_done(bp);
9038 return bnx2x_prev_mcp_done(bp);
9041 static int __devinit bnx2x_prev_unload(struct bnx2x *bp)
9043 int time_counter = 10;
9044 u32 rc, fw, hw_lock_reg, hw_lock_val;
9045 BNX2X_DEV_INFO("Entering Previous Unload Flow\n");
9047 /* Release previously held locks */
9048 hw_lock_reg = (BP_FUNC(bp) <= 5) ?
9049 (MISC_REG_DRIVER_CONTROL_1 + BP_FUNC(bp) * 8) :
9050 (MISC_REG_DRIVER_CONTROL_7 + (BP_FUNC(bp) - 6) * 8);
9052 hw_lock_val = (REG_RD(bp, hw_lock_reg));
9054 if (hw_lock_val & HW_LOCK_RESOURCE_NVRAM) {
9055 BNX2X_DEV_INFO("Release Previously held NVRAM lock\n");
9056 REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
9057 (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << BP_PORT(bp)));
9060 BNX2X_DEV_INFO("Release Previously held hw lock\n");
9061 REG_WR(bp, hw_lock_reg, 0xffffffff);
9063 BNX2X_DEV_INFO("No need to release hw/nvram locks\n");
9065 if (MCPR_ACCESS_LOCK_LOCK & REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK)) {
9066 BNX2X_DEV_INFO("Release previously held alr\n");
9067 REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, 0);
9072 /* Lock MCP using an unload request */
9073 fw = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS, 0);
9075 BNX2X_ERR("MCP response failure, aborting\n");
9080 if (fw == FW_MSG_CODE_DRV_UNLOAD_COMMON) {
9081 rc = bnx2x_prev_unload_common(bp);
9085 /* non-common reply from MCP night require looping */
9086 rc = bnx2x_prev_unload_uncommon(bp);
9087 if (rc != BNX2X_PREV_WAIT_NEEDED)
9091 } while (--time_counter);
9093 if (!time_counter || rc) {
9094 BNX2X_ERR("Failed unloading previous driver, aborting\n");
9098 BNX2X_DEV_INFO("Finished Previous Unload Flow [%d]\n", rc);
9103 static void __devinit bnx2x_get_common_hwinfo(struct bnx2x *bp)
9105 u32 val, val2, val3, val4, id, boot_mode;
9108 /* Get the chip revision id and number. */
9109 /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
9110 val = REG_RD(bp, MISC_REG_CHIP_NUM);
9111 id = ((val & 0xffff) << 16);
9112 val = REG_RD(bp, MISC_REG_CHIP_REV);
9113 id |= ((val & 0xf) << 12);
9114 val = REG_RD(bp, MISC_REG_CHIP_METAL);
9115 id |= ((val & 0xff) << 4);
9116 val = REG_RD(bp, MISC_REG_BOND_ID);
9118 bp->common.chip_id = id;
9120 /* Set doorbell size */
9121 bp->db_size = (1 << BNX2X_DB_SHIFT);
9123 if (!CHIP_IS_E1x(bp)) {
9124 val = REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR);
9126 val = REG_RD(bp, MISC_REG_PORT4MODE_EN);
9128 val = (val >> 1) & 1;
9129 BNX2X_DEV_INFO("chip is in %s\n", val ? "4_PORT_MODE" :
9131 bp->common.chip_port_mode = val ? CHIP_4_PORT_MODE :
9134 if (CHIP_MODE_IS_4_PORT(bp))
9135 bp->pfid = (bp->pf_num >> 1); /* 0..3 */
9137 bp->pfid = (bp->pf_num & 0x6); /* 0, 2, 4, 6 */
9139 bp->common.chip_port_mode = CHIP_PORT_MODE_NONE; /* N/A */
9140 bp->pfid = bp->pf_num; /* 0..7 */
9143 BNX2X_DEV_INFO("pf_id: %x", bp->pfid);
9145 bp->link_params.chip_id = bp->common.chip_id;
9146 BNX2X_DEV_INFO("chip ID is 0x%x\n", id);
9148 val = (REG_RD(bp, 0x2874) & 0x55);
9149 if ((bp->common.chip_id & 0x1) ||
9150 (CHIP_IS_E1(bp) && val) || (CHIP_IS_E1H(bp) && (val == 0x55))) {
9151 bp->flags |= ONE_PORT_FLAG;
9152 BNX2X_DEV_INFO("single port device\n");
9155 val = REG_RD(bp, MCP_REG_MCPR_NVM_CFG4);
9156 bp->common.flash_size = (BNX2X_NVRAM_1MB_SIZE <<
9157 (val & MCPR_NVM_CFG4_FLASH_SIZE));
9158 BNX2X_DEV_INFO("flash_size 0x%x (%d)\n",
9159 bp->common.flash_size, bp->common.flash_size);
9161 bnx2x_init_shmem(bp);
9165 bp->common.shmem2_base = REG_RD(bp, (BP_PATH(bp) ?
9166 MISC_REG_GENERIC_CR_1 :
9167 MISC_REG_GENERIC_CR_0));
9169 bp->link_params.shmem_base = bp->common.shmem_base;
9170 bp->link_params.shmem2_base = bp->common.shmem2_base;
9171 BNX2X_DEV_INFO("shmem offset 0x%x shmem2 offset 0x%x\n",
9172 bp->common.shmem_base, bp->common.shmem2_base);
9174 if (!bp->common.shmem_base) {
9175 BNX2X_DEV_INFO("MCP not active\n");
9176 bp->flags |= NO_MCP_FLAG;
9180 bp->common.hw_config = SHMEM_RD(bp, dev_info.shared_hw_config.config);
9181 BNX2X_DEV_INFO("hw_config 0x%08x\n", bp->common.hw_config);
9183 bp->link_params.hw_led_mode = ((bp->common.hw_config &
9184 SHARED_HW_CFG_LED_MODE_MASK) >>
9185 SHARED_HW_CFG_LED_MODE_SHIFT);
9187 bp->link_params.feature_config_flags = 0;
9188 val = SHMEM_RD(bp, dev_info.shared_feature_config.config);
9189 if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED)
9190 bp->link_params.feature_config_flags |=
9191 FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
9193 bp->link_params.feature_config_flags &=
9194 ~FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
9196 val = SHMEM_RD(bp, dev_info.bc_rev) >> 8;
9197 bp->common.bc_ver = val;
9198 BNX2X_DEV_INFO("bc_ver %X\n", val);
9199 if (val < BNX2X_BC_VER) {
9200 /* for now only warn
9201 * later we might need to enforce this */
9202 BNX2X_ERR("This driver needs bc_ver %X but found %X, please upgrade BC\n",
9205 bp->link_params.feature_config_flags |=
9206 (val >= REQ_BC_VER_4_VRFY_FIRST_PHY_OPT_MDL) ?
9207 FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY : 0;
9209 bp->link_params.feature_config_flags |=
9210 (val >= REQ_BC_VER_4_VRFY_SPECIFIC_PHY_OPT_MDL) ?
9211 FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY : 0;
9213 bp->link_params.feature_config_flags |=
9214 (val >= REQ_BC_VER_4_SFP_TX_DISABLE_SUPPORTED) ?
9215 FEATURE_CONFIG_BC_SUPPORTS_SFP_TX_DISABLED : 0;
9216 bp->flags |= (val >= REQ_BC_VER_4_PFC_STATS_SUPPORTED) ?
9217 BC_SUPPORTS_PFC_STATS : 0;
9219 boot_mode = SHMEM_RD(bp,
9220 dev_info.port_feature_config[BP_PORT(bp)].mba_config) &
9221 PORT_FEATURE_MBA_BOOT_AGENT_TYPE_MASK;
9222 switch (boot_mode) {
9223 case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_PXE:
9224 bp->common.boot_mode = FEATURE_ETH_BOOTMODE_PXE;
9226 case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_ISCSIB:
9227 bp->common.boot_mode = FEATURE_ETH_BOOTMODE_ISCSI;
9229 case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_FCOE_BOOT:
9230 bp->common.boot_mode = FEATURE_ETH_BOOTMODE_FCOE;
9232 case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_NONE:
9233 bp->common.boot_mode = FEATURE_ETH_BOOTMODE_NONE;
9237 pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_PMC, &pmc);
9238 bp->flags |= (pmc & PCI_PM_CAP_PME_D3cold) ? 0 : NO_WOL_FLAG;
9240 BNX2X_DEV_INFO("%sWoL capable\n",
9241 (bp->flags & NO_WOL_FLAG) ? "not " : "");
9243 val = SHMEM_RD(bp, dev_info.shared_hw_config.part_num);
9244 val2 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[4]);
9245 val3 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[8]);
9246 val4 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[12]);
9248 dev_info(&bp->pdev->dev, "part number %X-%X-%X-%X\n",
9249 val, val2, val3, val4);
9252 #define IGU_FID(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID)
9253 #define IGU_VEC(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR)
9255 static void __devinit bnx2x_get_igu_cam_info(struct bnx2x *bp)
9257 int pfid = BP_FUNC(bp);
9260 u8 fid, igu_sb_cnt = 0;
9262 bp->igu_base_sb = 0xff;
9263 if (CHIP_INT_MODE_IS_BC(bp)) {
9265 igu_sb_cnt = bp->igu_sb_cnt;
9266 bp->igu_base_sb = (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn) *
9269 bp->igu_dsb_id = E1HVN_MAX * FP_SB_MAX_E1x +
9270 (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn);
9275 /* IGU in normal mode - read CAM */
9276 for (igu_sb_id = 0; igu_sb_id < IGU_REG_MAPPING_MEMORY_SIZE;
9278 val = REG_RD(bp, IGU_REG_MAPPING_MEMORY + igu_sb_id * 4);
9279 if (!(val & IGU_REG_MAPPING_MEMORY_VALID))
9282 if ((fid & IGU_FID_ENCODE_IS_PF)) {
9283 if ((fid & IGU_FID_PF_NUM_MASK) != pfid)
9285 if (IGU_VEC(val) == 0)
9286 /* default status block */
9287 bp->igu_dsb_id = igu_sb_id;
9289 if (bp->igu_base_sb == 0xff)
9290 bp->igu_base_sb = igu_sb_id;
9296 #ifdef CONFIG_PCI_MSI
9298 * It's expected that number of CAM entries for this functions is equal
9299 * to the number evaluated based on the MSI-X table size. We want a
9300 * harsh warning if these values are different!
9302 WARN_ON(bp->igu_sb_cnt != igu_sb_cnt);
9305 if (igu_sb_cnt == 0)
9306 BNX2X_ERR("CAM configuration error\n");
9309 static void __devinit bnx2x_link_settings_supported(struct bnx2x *bp,
9312 int cfg_size = 0, idx, port = BP_PORT(bp);
9314 /* Aggregation of supported attributes of all external phys */
9315 bp->port.supported[0] = 0;
9316 bp->port.supported[1] = 0;
9317 switch (bp->link_params.num_phys) {
9319 bp->port.supported[0] = bp->link_params.phy[INT_PHY].supported;
9323 bp->port.supported[0] = bp->link_params.phy[EXT_PHY1].supported;
9327 if (bp->link_params.multi_phy_config &
9328 PORT_HW_CFG_PHY_SWAPPED_ENABLED) {
9329 bp->port.supported[1] =
9330 bp->link_params.phy[EXT_PHY1].supported;
9331 bp->port.supported[0] =
9332 bp->link_params.phy[EXT_PHY2].supported;
9334 bp->port.supported[0] =
9335 bp->link_params.phy[EXT_PHY1].supported;
9336 bp->port.supported[1] =
9337 bp->link_params.phy[EXT_PHY2].supported;
9343 if (!(bp->port.supported[0] || bp->port.supported[1])) {
9344 BNX2X_ERR("NVRAM config error. BAD phy config. PHY1 config 0x%x, PHY2 config 0x%x\n",
9346 dev_info.port_hw_config[port].external_phy_config),
9348 dev_info.port_hw_config[port].external_phy_config2));
9353 bp->port.phy_addr = REG_RD(bp, MISC_REG_WC0_CTRL_PHY_ADDR);
9355 switch (switch_cfg) {
9357 bp->port.phy_addr = REG_RD(
9358 bp, NIG_REG_SERDES0_CTRL_PHY_ADDR + port*0x10);
9360 case SWITCH_CFG_10G:
9361 bp->port.phy_addr = REG_RD(
9362 bp, NIG_REG_XGXS0_CTRL_PHY_ADDR + port*0x18);
9365 BNX2X_ERR("BAD switch_cfg link_config 0x%x\n",
9366 bp->port.link_config[0]);
9370 BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr);
9371 /* mask what we support according to speed_cap_mask per configuration */
9372 for (idx = 0; idx < cfg_size; idx++) {
9373 if (!(bp->link_params.speed_cap_mask[idx] &
9374 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF))
9375 bp->port.supported[idx] &= ~SUPPORTED_10baseT_Half;
9377 if (!(bp->link_params.speed_cap_mask[idx] &
9378 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL))
9379 bp->port.supported[idx] &= ~SUPPORTED_10baseT_Full;
9381 if (!(bp->link_params.speed_cap_mask[idx] &
9382 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF))
9383 bp->port.supported[idx] &= ~SUPPORTED_100baseT_Half;
9385 if (!(bp->link_params.speed_cap_mask[idx] &
9386 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL))
9387 bp->port.supported[idx] &= ~SUPPORTED_100baseT_Full;
9389 if (!(bp->link_params.speed_cap_mask[idx] &
9390 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G))
9391 bp->port.supported[idx] &= ~(SUPPORTED_1000baseT_Half |
9392 SUPPORTED_1000baseT_Full);
9394 if (!(bp->link_params.speed_cap_mask[idx] &
9395 PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
9396 bp->port.supported[idx] &= ~SUPPORTED_2500baseX_Full;
9398 if (!(bp->link_params.speed_cap_mask[idx] &
9399 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G))
9400 bp->port.supported[idx] &= ~SUPPORTED_10000baseT_Full;
9404 BNX2X_DEV_INFO("supported 0x%x 0x%x\n", bp->port.supported[0],
9405 bp->port.supported[1]);
9408 static void __devinit bnx2x_link_settings_requested(struct bnx2x *bp)
9410 u32 link_config, idx, cfg_size = 0;
9411 bp->port.advertising[0] = 0;
9412 bp->port.advertising[1] = 0;
9413 switch (bp->link_params.num_phys) {
9422 for (idx = 0; idx < cfg_size; idx++) {
9423 bp->link_params.req_duplex[idx] = DUPLEX_FULL;
9424 link_config = bp->port.link_config[idx];
9425 switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) {
9426 case PORT_FEATURE_LINK_SPEED_AUTO:
9427 if (bp->port.supported[idx] & SUPPORTED_Autoneg) {
9428 bp->link_params.req_line_speed[idx] =
9430 bp->port.advertising[idx] |=
9431 bp->port.supported[idx];
9432 if (bp->link_params.phy[EXT_PHY1].type ==
9433 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
9434 bp->port.advertising[idx] |=
9435 (SUPPORTED_100baseT_Half |
9436 SUPPORTED_100baseT_Full);
9438 /* force 10G, no AN */
9439 bp->link_params.req_line_speed[idx] =
9441 bp->port.advertising[idx] |=
9442 (ADVERTISED_10000baseT_Full |
9448 case PORT_FEATURE_LINK_SPEED_10M_FULL:
9449 if (bp->port.supported[idx] & SUPPORTED_10baseT_Full) {
9450 bp->link_params.req_line_speed[idx] =
9452 bp->port.advertising[idx] |=
9453 (ADVERTISED_10baseT_Full |
9456 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
9458 bp->link_params.speed_cap_mask[idx]);
9463 case PORT_FEATURE_LINK_SPEED_10M_HALF:
9464 if (bp->port.supported[idx] & SUPPORTED_10baseT_Half) {
9465 bp->link_params.req_line_speed[idx] =
9467 bp->link_params.req_duplex[idx] =
9469 bp->port.advertising[idx] |=
9470 (ADVERTISED_10baseT_Half |
9473 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
9475 bp->link_params.speed_cap_mask[idx]);
9480 case PORT_FEATURE_LINK_SPEED_100M_FULL:
9481 if (bp->port.supported[idx] &
9482 SUPPORTED_100baseT_Full) {
9483 bp->link_params.req_line_speed[idx] =
9485 bp->port.advertising[idx] |=
9486 (ADVERTISED_100baseT_Full |
9489 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
9491 bp->link_params.speed_cap_mask[idx]);
9496 case PORT_FEATURE_LINK_SPEED_100M_HALF:
9497 if (bp->port.supported[idx] &
9498 SUPPORTED_100baseT_Half) {
9499 bp->link_params.req_line_speed[idx] =
9501 bp->link_params.req_duplex[idx] =
9503 bp->port.advertising[idx] |=
9504 (ADVERTISED_100baseT_Half |
9507 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
9509 bp->link_params.speed_cap_mask[idx]);
9514 case PORT_FEATURE_LINK_SPEED_1G:
9515 if (bp->port.supported[idx] &
9516 SUPPORTED_1000baseT_Full) {
9517 bp->link_params.req_line_speed[idx] =
9519 bp->port.advertising[idx] |=
9520 (ADVERTISED_1000baseT_Full |
9523 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
9525 bp->link_params.speed_cap_mask[idx]);
9530 case PORT_FEATURE_LINK_SPEED_2_5G:
9531 if (bp->port.supported[idx] &
9532 SUPPORTED_2500baseX_Full) {
9533 bp->link_params.req_line_speed[idx] =
9535 bp->port.advertising[idx] |=
9536 (ADVERTISED_2500baseX_Full |
9539 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
9541 bp->link_params.speed_cap_mask[idx]);
9546 case PORT_FEATURE_LINK_SPEED_10G_CX4:
9547 if (bp->port.supported[idx] &
9548 SUPPORTED_10000baseT_Full) {
9549 bp->link_params.req_line_speed[idx] =
9551 bp->port.advertising[idx] |=
9552 (ADVERTISED_10000baseT_Full |
9555 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
9557 bp->link_params.speed_cap_mask[idx]);
9561 case PORT_FEATURE_LINK_SPEED_20G:
9562 bp->link_params.req_line_speed[idx] = SPEED_20000;
9566 BNX2X_ERR("NVRAM config error. BAD link speed link_config 0x%x\n",
9568 bp->link_params.req_line_speed[idx] =
9570 bp->port.advertising[idx] =
9571 bp->port.supported[idx];
9575 bp->link_params.req_flow_ctrl[idx] = (link_config &
9576 PORT_FEATURE_FLOW_CONTROL_MASK);
9577 if ((bp->link_params.req_flow_ctrl[idx] ==
9578 BNX2X_FLOW_CTRL_AUTO) &&
9579 !(bp->port.supported[idx] & SUPPORTED_Autoneg)) {
9580 bp->link_params.req_flow_ctrl[idx] =
9581 BNX2X_FLOW_CTRL_NONE;
9584 BNX2X_DEV_INFO("req_line_speed %d req_duplex %d req_flow_ctrl 0x%x advertising 0x%x\n",
9585 bp->link_params.req_line_speed[idx],
9586 bp->link_params.req_duplex[idx],
9587 bp->link_params.req_flow_ctrl[idx],
9588 bp->port.advertising[idx]);
9592 static void __devinit bnx2x_set_mac_buf(u8 *mac_buf, u32 mac_lo, u16 mac_hi)
9594 mac_hi = cpu_to_be16(mac_hi);
9595 mac_lo = cpu_to_be32(mac_lo);
9596 memcpy(mac_buf, &mac_hi, sizeof(mac_hi));
9597 memcpy(mac_buf + sizeof(mac_hi), &mac_lo, sizeof(mac_lo));
9600 static void __devinit bnx2x_get_port_hwinfo(struct bnx2x *bp)
9602 int port = BP_PORT(bp);
9604 u32 ext_phy_type, ext_phy_config;
9606 bp->link_params.bp = bp;
9607 bp->link_params.port = port;
9609 bp->link_params.lane_config =
9610 SHMEM_RD(bp, dev_info.port_hw_config[port].lane_config);
9612 bp->link_params.speed_cap_mask[0] =
9614 dev_info.port_hw_config[port].speed_capability_mask);
9615 bp->link_params.speed_cap_mask[1] =
9617 dev_info.port_hw_config[port].speed_capability_mask2);
9618 bp->port.link_config[0] =
9619 SHMEM_RD(bp, dev_info.port_feature_config[port].link_config);
9621 bp->port.link_config[1] =
9622 SHMEM_RD(bp, dev_info.port_feature_config[port].link_config2);
9624 bp->link_params.multi_phy_config =
9625 SHMEM_RD(bp, dev_info.port_hw_config[port].multi_phy_config);
9626 /* If the device is capable of WoL, set the default state according
9629 config = SHMEM_RD(bp, dev_info.port_feature_config[port].config);
9630 bp->wol = (!(bp->flags & NO_WOL_FLAG) &&
9631 (config & PORT_FEATURE_WOL_ENABLED));
9633 BNX2X_DEV_INFO("lane_config 0x%08x speed_cap_mask0 0x%08x link_config0 0x%08x\n",
9634 bp->link_params.lane_config,
9635 bp->link_params.speed_cap_mask[0],
9636 bp->port.link_config[0]);
9638 bp->link_params.switch_cfg = (bp->port.link_config[0] &
9639 PORT_FEATURE_CONNECTED_SWITCH_MASK);
9640 bnx2x_phy_probe(&bp->link_params);
9641 bnx2x_link_settings_supported(bp, bp->link_params.switch_cfg);
9643 bnx2x_link_settings_requested(bp);
9646 * If connected directly, work with the internal PHY, otherwise, work
9647 * with the external PHY
9651 dev_info.port_hw_config[port].external_phy_config);
9652 ext_phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
9653 if (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
9654 bp->mdio.prtad = bp->port.phy_addr;
9656 else if ((ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) &&
9657 (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN))
9659 XGXS_EXT_PHY_ADDR(ext_phy_config);
9662 * Check if hw lock is required to access MDC/MDIO bus to the PHY(s)
9663 * In MF mode, it is set to cover self test cases
9666 bp->port.need_hw_lock = 1;
9668 bp->port.need_hw_lock = bnx2x_hw_lock_required(bp,
9669 bp->common.shmem_base,
9670 bp->common.shmem2_base);
9673 void bnx2x_get_iscsi_info(struct bnx2x *bp)
9675 u32 no_flags = NO_ISCSI_FLAG;
9677 int port = BP_PORT(bp);
9679 u32 max_iscsi_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
9680 drv_lic_key[port].max_iscsi_conn);
9682 /* Get the number of maximum allowed iSCSI connections */
9683 bp->cnic_eth_dev.max_iscsi_conn =
9684 (max_iscsi_conn & BNX2X_MAX_ISCSI_INIT_CONN_MASK) >>
9685 BNX2X_MAX_ISCSI_INIT_CONN_SHIFT;
9687 BNX2X_DEV_INFO("max_iscsi_conn 0x%x\n",
9688 bp->cnic_eth_dev.max_iscsi_conn);
9691 * If maximum allowed number of connections is zero -
9692 * disable the feature.
9694 if (!bp->cnic_eth_dev.max_iscsi_conn)
9695 bp->flags |= no_flags;
9697 bp->flags |= no_flags;
9702 static void __devinit bnx2x_get_ext_wwn_info(struct bnx2x *bp, int func)
9705 bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
9706 MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_upper);
9707 bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
9708 MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_lower);
9711 bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
9712 MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_upper);
9713 bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
9714 MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_lower);
9717 static void __devinit bnx2x_get_fcoe_info(struct bnx2x *bp)
9720 int port = BP_PORT(bp);
9721 int func = BP_ABS_FUNC(bp);
9723 u32 max_fcoe_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
9724 drv_lic_key[port].max_fcoe_conn);
9726 /* Get the number of maximum allowed FCoE connections */
9727 bp->cnic_eth_dev.max_fcoe_conn =
9728 (max_fcoe_conn & BNX2X_MAX_FCOE_INIT_CONN_MASK) >>
9729 BNX2X_MAX_FCOE_INIT_CONN_SHIFT;
9734 bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
9736 dev_info.port_hw_config[port].
9737 fcoe_wwn_port_name_upper);
9738 bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
9740 dev_info.port_hw_config[port].
9741 fcoe_wwn_port_name_lower);
9744 bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
9746 dev_info.port_hw_config[port].
9747 fcoe_wwn_node_name_upper);
9748 bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
9750 dev_info.port_hw_config[port].
9751 fcoe_wwn_node_name_lower);
9752 } else if (!IS_MF_SD(bp)) {
9753 u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg);
9756 * Read the WWN info only if the FCoE feature is enabled for
9759 if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD)
9760 bnx2x_get_ext_wwn_info(bp, func);
9762 } else if (IS_MF_FCOE_SD(bp))
9763 bnx2x_get_ext_wwn_info(bp, func);
9765 BNX2X_DEV_INFO("max_fcoe_conn 0x%x\n", bp->cnic_eth_dev.max_fcoe_conn);
9768 * If maximum allowed number of connections is zero -
9769 * disable the feature.
9771 if (!bp->cnic_eth_dev.max_fcoe_conn)
9772 bp->flags |= NO_FCOE_FLAG;
9774 bp->flags |= NO_FCOE_FLAG;
9778 static void __devinit bnx2x_get_cnic_info(struct bnx2x *bp)
9781 * iSCSI may be dynamically disabled but reading
9782 * info here we will decrease memory usage by driver
9783 * if the feature is disabled for good
9785 bnx2x_get_iscsi_info(bp);
9786 bnx2x_get_fcoe_info(bp);
9789 static void __devinit bnx2x_get_mac_hwinfo(struct bnx2x *bp)
9792 int func = BP_ABS_FUNC(bp);
9793 int port = BP_PORT(bp);
9795 u8 *iscsi_mac = bp->cnic_eth_dev.iscsi_mac;
9796 u8 *fip_mac = bp->fip_mac;
9799 /* Zero primary MAC configuration */
9800 memset(bp->dev->dev_addr, 0, ETH_ALEN);
9803 BNX2X_ERROR("warning: random MAC workaround active\n");
9804 eth_hw_addr_random(bp->dev);
9805 } else if (IS_MF(bp)) {
9806 val2 = MF_CFG_RD(bp, func_mf_config[func].mac_upper);
9807 val = MF_CFG_RD(bp, func_mf_config[func].mac_lower);
9808 if ((val2 != FUNC_MF_CFG_UPPERMAC_DEFAULT) &&
9809 (val != FUNC_MF_CFG_LOWERMAC_DEFAULT))
9810 bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
9814 * iSCSI and FCoE NPAR MACs: if there is no either iSCSI or
9815 * FCoE MAC then the appropriate feature should be disabled.
9817 * In non SD mode features configuration comes from
9818 * struct func_ext_config.
9820 if (!IS_MF_SD(bp)) {
9821 u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg);
9822 if (cfg & MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD) {
9823 val2 = MF_CFG_RD(bp, func_ext_config[func].
9824 iscsi_mac_addr_upper);
9825 val = MF_CFG_RD(bp, func_ext_config[func].
9826 iscsi_mac_addr_lower);
9827 bnx2x_set_mac_buf(iscsi_mac, val, val2);
9828 BNX2X_DEV_INFO("Read iSCSI MAC: %pM\n",
9831 bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
9833 if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD) {
9834 val2 = MF_CFG_RD(bp, func_ext_config[func].
9835 fcoe_mac_addr_upper);
9836 val = MF_CFG_RD(bp, func_ext_config[func].
9837 fcoe_mac_addr_lower);
9838 bnx2x_set_mac_buf(fip_mac, val, val2);
9839 BNX2X_DEV_INFO("Read FCoE L2 MAC: %pM\n",
9843 bp->flags |= NO_FCOE_FLAG;
9844 } else { /* SD MODE */
9845 if (IS_MF_STORAGE_SD(bp)) {
9846 if (BNX2X_IS_MF_SD_PROTOCOL_ISCSI(bp)) {
9847 /* use primary mac as iscsi mac */
9848 memcpy(iscsi_mac, bp->dev->dev_addr,
9851 BNX2X_DEV_INFO("SD ISCSI MODE\n");
9852 BNX2X_DEV_INFO("Read iSCSI MAC: %pM\n",
9855 memcpy(fip_mac, bp->dev->dev_addr,
9857 BNX2X_DEV_INFO("SD FCoE MODE\n");
9858 BNX2X_DEV_INFO("Read FIP MAC: %pM\n",
9861 /* Zero primary MAC configuration */
9862 memset(bp->dev->dev_addr, 0, ETH_ALEN);
9867 /* in SF read MACs from port configuration */
9868 val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
9869 val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
9870 bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
9873 val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
9875 val = SHMEM_RD(bp, dev_info.port_hw_config[port].
9877 bnx2x_set_mac_buf(iscsi_mac, val, val2);
9879 val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
9880 fcoe_fip_mac_upper);
9881 val = SHMEM_RD(bp, dev_info.port_hw_config[port].
9882 fcoe_fip_mac_lower);
9883 bnx2x_set_mac_buf(fip_mac, val, val2);
9887 memcpy(bp->link_params.mac_addr, bp->dev->dev_addr, ETH_ALEN);
9888 memcpy(bp->dev->perm_addr, bp->dev->dev_addr, ETH_ALEN);
9891 /* Disable iSCSI if MAC configuration is
9894 if (!is_valid_ether_addr(iscsi_mac)) {
9895 bp->flags |= NO_ISCSI_FLAG;
9896 memset(iscsi_mac, 0, ETH_ALEN);
9899 /* Disable FCoE if MAC configuration is
9902 if (!is_valid_ether_addr(fip_mac)) {
9903 bp->flags |= NO_FCOE_FLAG;
9904 memset(bp->fip_mac, 0, ETH_ALEN);
9908 if (!bnx2x_is_valid_ether_addr(bp, bp->dev->dev_addr))
9909 dev_err(&bp->pdev->dev,
9910 "bad Ethernet MAC address configuration: %pM\n"
9911 "change it manually before bringing up the appropriate network interface\n",
9917 static int __devinit bnx2x_get_hwinfo(struct bnx2x *bp)
9919 int /*abs*/func = BP_ABS_FUNC(bp);
9924 bnx2x_get_common_hwinfo(bp);
9927 * initialize IGU parameters
9929 if (CHIP_IS_E1x(bp)) {
9930 bp->common.int_block = INT_BLOCK_HC;
9932 bp->igu_dsb_id = DEF_SB_IGU_ID;
9933 bp->igu_base_sb = 0;
9935 bp->common.int_block = INT_BLOCK_IGU;
9937 /* do not allow device reset during IGU info preocessing */
9938 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
9940 val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
9942 if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
9945 BNX2X_DEV_INFO("FORCING Normal Mode\n");
9947 val &= ~(IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN);
9948 REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION, val);
9949 REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x7f);
9951 while (tout && REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
9953 usleep_range(1000, 1000);
9956 if (REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
9957 dev_err(&bp->pdev->dev,
9958 "FORCING Normal Mode failed!!!\n");
9963 if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
9964 BNX2X_DEV_INFO("IGU Backward Compatible Mode\n");
9965 bp->common.int_block |= INT_BLOCK_MODE_BW_COMP;
9967 BNX2X_DEV_INFO("IGU Normal Mode\n");
9969 bnx2x_get_igu_cam_info(bp);
9971 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
9975 * set base FW non-default (fast path) status block id, this value is
9976 * used to initialize the fw_sb_id saved on the fp/queue structure to
9977 * determine the id used by the FW.
9979 if (CHIP_IS_E1x(bp))
9980 bp->base_fw_ndsb = BP_PORT(bp) * FP_SB_MAX_E1x + BP_L_ID(bp);
9982 * 57712 - we currently use one FW SB per IGU SB (Rx and Tx of
9983 * the same queue are indicated on the same IGU SB). So we prefer
9984 * FW and IGU SBs to be the same value.
9986 bp->base_fw_ndsb = bp->igu_base_sb;
9988 BNX2X_DEV_INFO("igu_dsb_id %d igu_base_sb %d igu_sb_cnt %d\n"
9989 "base_fw_ndsb %d\n", bp->igu_dsb_id, bp->igu_base_sb,
9990 bp->igu_sb_cnt, bp->base_fw_ndsb);
9993 * Initialize MF configuration
10000 if (!CHIP_IS_E1(bp) && !BP_NOMCP(bp)) {
10001 BNX2X_DEV_INFO("shmem2base 0x%x, size %d, mfcfg offset %d\n",
10002 bp->common.shmem2_base, SHMEM2_RD(bp, size),
10003 (u32)offsetof(struct shmem2_region, mf_cfg_addr));
10005 if (SHMEM2_HAS(bp, mf_cfg_addr))
10006 bp->common.mf_cfg_base = SHMEM2_RD(bp, mf_cfg_addr);
10008 bp->common.mf_cfg_base = bp->common.shmem_base +
10009 offsetof(struct shmem_region, func_mb) +
10010 E1H_FUNC_MAX * sizeof(struct drv_func_mb);
10012 * get mf configuration:
10013 * 1. existence of MF configuration
10014 * 2. MAC address must be legal (check only upper bytes)
10015 * for Switch-Independent mode;
10016 * OVLAN must be legal for Switch-Dependent mode
10017 * 3. SF_MODE configures specific MF mode
10019 if (bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
10020 /* get mf configuration */
10022 dev_info.shared_feature_config.config);
10023 val &= SHARED_FEAT_CFG_FORCE_SF_MODE_MASK;
10026 case SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT:
10027 val = MF_CFG_RD(bp, func_mf_config[func].
10029 /* check for legal mac (upper bytes)*/
10030 if (val != 0xffff) {
10031 bp->mf_mode = MULTI_FUNCTION_SI;
10032 bp->mf_config[vn] = MF_CFG_RD(bp,
10033 func_mf_config[func].config);
10035 BNX2X_DEV_INFO("illegal MAC address for SI\n");
10037 case SHARED_FEAT_CFG_FORCE_SF_MODE_MF_ALLOWED:
10038 /* get OV configuration */
10039 val = MF_CFG_RD(bp,
10040 func_mf_config[FUNC_0].e1hov_tag);
10041 val &= FUNC_MF_CFG_E1HOV_TAG_MASK;
10043 if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
10044 bp->mf_mode = MULTI_FUNCTION_SD;
10045 bp->mf_config[vn] = MF_CFG_RD(bp,
10046 func_mf_config[func].config);
10048 BNX2X_DEV_INFO("illegal OV for SD\n");
10051 /* Unknown configuration: reset mf_config */
10052 bp->mf_config[vn] = 0;
10053 BNX2X_DEV_INFO("unknown MF mode 0x%x\n", val);
10057 BNX2X_DEV_INFO("%s function mode\n",
10058 IS_MF(bp) ? "multi" : "single");
10060 switch (bp->mf_mode) {
10061 case MULTI_FUNCTION_SD:
10062 val = MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
10063 FUNC_MF_CFG_E1HOV_TAG_MASK;
10064 if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
10066 bp->path_has_ovlan = true;
10068 BNX2X_DEV_INFO("MF OV for func %d is %d (0x%04x)\n",
10069 func, bp->mf_ov, bp->mf_ov);
10071 dev_err(&bp->pdev->dev,
10072 "No valid MF OV for func %d, aborting\n",
10077 case MULTI_FUNCTION_SI:
10078 BNX2X_DEV_INFO("func %d is in MF switch-independent mode\n",
10083 dev_err(&bp->pdev->dev,
10084 "VN %d is in a single function mode, aborting\n",
10091 /* check if other port on the path needs ovlan:
10092 * Since MF configuration is shared between ports
10093 * Possible mixed modes are only
10094 * {SF, SI} {SF, SD} {SD, SF} {SI, SF}
10096 if (CHIP_MODE_IS_4_PORT(bp) &&
10097 !bp->path_has_ovlan &&
10099 bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
10100 u8 other_port = !BP_PORT(bp);
10101 u8 other_func = BP_PATH(bp) + 2*other_port;
10102 val = MF_CFG_RD(bp,
10103 func_mf_config[other_func].e1hov_tag);
10104 if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT)
10105 bp->path_has_ovlan = true;
10109 /* adjust igu_sb_cnt to MF for E1x */
10110 if (CHIP_IS_E1x(bp) && IS_MF(bp))
10111 bp->igu_sb_cnt /= E1HVN_MAX;
10114 bnx2x_get_port_hwinfo(bp);
10116 /* Get MAC addresses */
10117 bnx2x_get_mac_hwinfo(bp);
10119 bnx2x_get_cnic_info(bp);
10124 static void __devinit bnx2x_read_fwinfo(struct bnx2x *bp)
10126 int cnt, i, block_end, rodi;
10127 char vpd_start[BNX2X_VPD_LEN+1];
10128 char str_id_reg[VENDOR_ID_LEN+1];
10129 char str_id_cap[VENDOR_ID_LEN+1];
10131 char *vpd_extended_data = NULL;
10134 cnt = pci_read_vpd(bp->pdev, 0, BNX2X_VPD_LEN, vpd_start);
10135 memset(bp->fw_ver, 0, sizeof(bp->fw_ver));
10137 if (cnt < BNX2X_VPD_LEN)
10138 goto out_not_found;
10140 /* VPD RO tag should be first tag after identifier string, hence
10141 * we should be able to find it in first BNX2X_VPD_LEN chars
10143 i = pci_vpd_find_tag(vpd_start, 0, BNX2X_VPD_LEN,
10144 PCI_VPD_LRDT_RO_DATA);
10146 goto out_not_found;
10148 block_end = i + PCI_VPD_LRDT_TAG_SIZE +
10149 pci_vpd_lrdt_size(&vpd_start[i]);
10151 i += PCI_VPD_LRDT_TAG_SIZE;
10153 if (block_end > BNX2X_VPD_LEN) {
10154 vpd_extended_data = kmalloc(block_end, GFP_KERNEL);
10155 if (vpd_extended_data == NULL)
10156 goto out_not_found;
10158 /* read rest of vpd image into vpd_extended_data */
10159 memcpy(vpd_extended_data, vpd_start, BNX2X_VPD_LEN);
10160 cnt = pci_read_vpd(bp->pdev, BNX2X_VPD_LEN,
10161 block_end - BNX2X_VPD_LEN,
10162 vpd_extended_data + BNX2X_VPD_LEN);
10163 if (cnt < (block_end - BNX2X_VPD_LEN))
10164 goto out_not_found;
10165 vpd_data = vpd_extended_data;
10167 vpd_data = vpd_start;
10169 /* now vpd_data holds full vpd content in both cases */
10171 rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
10172 PCI_VPD_RO_KEYWORD_MFR_ID);
10174 goto out_not_found;
10176 len = pci_vpd_info_field_size(&vpd_data[rodi]);
10178 if (len != VENDOR_ID_LEN)
10179 goto out_not_found;
10181 rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
10183 /* vendor specific info */
10184 snprintf(str_id_reg, VENDOR_ID_LEN + 1, "%04x", PCI_VENDOR_ID_DELL);
10185 snprintf(str_id_cap, VENDOR_ID_LEN + 1, "%04X", PCI_VENDOR_ID_DELL);
10186 if (!strncmp(str_id_reg, &vpd_data[rodi], VENDOR_ID_LEN) ||
10187 !strncmp(str_id_cap, &vpd_data[rodi], VENDOR_ID_LEN)) {
10189 rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
10190 PCI_VPD_RO_KEYWORD_VENDOR0);
10192 len = pci_vpd_info_field_size(&vpd_data[rodi]);
10194 rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
10196 if (len < 32 && (len + rodi) <= BNX2X_VPD_LEN) {
10197 memcpy(bp->fw_ver, &vpd_data[rodi], len);
10198 bp->fw_ver[len] = ' ';
10201 kfree(vpd_extended_data);
10205 kfree(vpd_extended_data);
10209 static void __devinit bnx2x_set_modes_bitmap(struct bnx2x *bp)
10213 if (CHIP_REV_IS_FPGA(bp))
10214 SET_FLAGS(flags, MODE_FPGA);
10215 else if (CHIP_REV_IS_EMUL(bp))
10216 SET_FLAGS(flags, MODE_EMUL);
10218 SET_FLAGS(flags, MODE_ASIC);
10220 if (CHIP_MODE_IS_4_PORT(bp))
10221 SET_FLAGS(flags, MODE_PORT4);
10223 SET_FLAGS(flags, MODE_PORT2);
10225 if (CHIP_IS_E2(bp))
10226 SET_FLAGS(flags, MODE_E2);
10227 else if (CHIP_IS_E3(bp)) {
10228 SET_FLAGS(flags, MODE_E3);
10229 if (CHIP_REV(bp) == CHIP_REV_Ax)
10230 SET_FLAGS(flags, MODE_E3_A0);
10231 else /*if (CHIP_REV(bp) == CHIP_REV_Bx)*/
10232 SET_FLAGS(flags, MODE_E3_B0 | MODE_COS3);
10236 SET_FLAGS(flags, MODE_MF);
10237 switch (bp->mf_mode) {
10238 case MULTI_FUNCTION_SD:
10239 SET_FLAGS(flags, MODE_MF_SD);
10241 case MULTI_FUNCTION_SI:
10242 SET_FLAGS(flags, MODE_MF_SI);
10246 SET_FLAGS(flags, MODE_SF);
10248 #if defined(__LITTLE_ENDIAN)
10249 SET_FLAGS(flags, MODE_LITTLE_ENDIAN);
10250 #else /*(__BIG_ENDIAN)*/
10251 SET_FLAGS(flags, MODE_BIG_ENDIAN);
10253 INIT_MODE_FLAGS(bp) = flags;
10256 static int __devinit bnx2x_init_bp(struct bnx2x *bp)
10261 mutex_init(&bp->port.phy_mutex);
10262 mutex_init(&bp->fw_mb_mutex);
10263 spin_lock_init(&bp->stats_lock);
10265 mutex_init(&bp->cnic_mutex);
10268 INIT_DELAYED_WORK(&bp->sp_task, bnx2x_sp_task);
10269 INIT_DELAYED_WORK(&bp->sp_rtnl_task, bnx2x_sp_rtnl_task);
10270 INIT_DELAYED_WORK(&bp->period_task, bnx2x_period_task);
10271 rc = bnx2x_get_hwinfo(bp);
10275 bnx2x_set_modes_bitmap(bp);
10277 rc = bnx2x_alloc_mem_bp(bp);
10281 bnx2x_read_fwinfo(bp);
10283 func = BP_FUNC(bp);
10285 /* need to reset chip if undi was active */
10286 if (!BP_NOMCP(bp)) {
10289 SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
10290 DRV_MSG_SEQ_NUMBER_MASK;
10291 BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
10293 bnx2x_prev_unload(bp);
10297 if (CHIP_REV_IS_FPGA(bp))
10298 dev_err(&bp->pdev->dev, "FPGA detected\n");
10300 if (BP_NOMCP(bp) && (func == 0))
10301 dev_err(&bp->pdev->dev, "MCP disabled, must load devices in order!\n");
10303 bp->multi_mode = multi_mode;
10305 bp->disable_tpa = disable_tpa;
10308 bp->disable_tpa |= IS_MF_STORAGE_SD(bp);
10311 /* Set TPA flags */
10312 if (bp->disable_tpa) {
10313 bp->flags &= ~(TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
10314 bp->dev->features &= ~NETIF_F_LRO;
10316 bp->flags |= (TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
10317 bp->dev->features |= NETIF_F_LRO;
10320 if (CHIP_IS_E1(bp))
10321 bp->dropless_fc = 0;
10323 bp->dropless_fc = dropless_fc;
10327 bp->tx_ring_size = MAX_TX_AVAIL;
10329 /* make sure that the numbers are in the right granularity */
10330 bp->tx_ticks = (50 / BNX2X_BTR) * BNX2X_BTR;
10331 bp->rx_ticks = (25 / BNX2X_BTR) * BNX2X_BTR;
10333 bp->current_interval = CHIP_REV_IS_SLOW(bp) ? 5*HZ : HZ;
10335 init_timer(&bp->timer);
10336 bp->timer.expires = jiffies + bp->current_interval;
10337 bp->timer.data = (unsigned long) bp;
10338 bp->timer.function = bnx2x_timer;
10340 bnx2x_dcbx_set_state(bp, true, BNX2X_DCBX_ENABLED_ON_NEG_ON);
10341 bnx2x_dcbx_init_params(bp);
10344 if (CHIP_IS_E1x(bp))
10345 bp->cnic_base_cl_id = FP_SB_MAX_E1x;
10347 bp->cnic_base_cl_id = FP_SB_MAX_E2;
10350 /* multiple tx priority */
10351 if (CHIP_IS_E1x(bp))
10352 bp->max_cos = BNX2X_MULTI_TX_COS_E1X;
10353 if (CHIP_IS_E2(bp) || CHIP_IS_E3A0(bp))
10354 bp->max_cos = BNX2X_MULTI_TX_COS_E2_E3A0;
10355 if (CHIP_IS_E3B0(bp))
10356 bp->max_cos = BNX2X_MULTI_TX_COS_E3B0;
10358 bp->gro_check = bnx2x_need_gro_check(bp->dev->mtu);
10364 /****************************************************************************
10365 * General service functions
10366 ****************************************************************************/
10369 * net_device service functions
10372 /* called with rtnl_lock */
10373 static int bnx2x_open(struct net_device *dev)
10375 struct bnx2x *bp = netdev_priv(dev);
10376 bool global = false;
10377 int other_engine = BP_PATH(bp) ? 0 : 1;
10378 bool other_load_status, load_status;
10380 bp->stats_init = true;
10382 netif_carrier_off(dev);
10384 bnx2x_set_power_state(bp, PCI_D0);
10386 other_load_status = bnx2x_get_load_status(bp, other_engine);
10387 load_status = bnx2x_get_load_status(bp, BP_PATH(bp));
10390 * If parity had happen during the unload, then attentions
10391 * and/or RECOVERY_IN_PROGRES may still be set. In this case we
10392 * want the first function loaded on the current engine to
10393 * complete the recovery.
10395 if (!bnx2x_reset_is_done(bp, BP_PATH(bp)) ||
10396 bnx2x_chk_parity_attn(bp, &global, true))
10399 * If there are attentions and they are in a global
10400 * blocks, set the GLOBAL_RESET bit regardless whether
10401 * it will be this function that will complete the
10405 bnx2x_set_reset_global(bp);
10408 * Only the first function on the current engine should
10409 * try to recover in open. In case of attentions in
10410 * global blocks only the first in the chip should try
10413 if ((!load_status &&
10414 (!global || !other_load_status)) &&
10415 bnx2x_trylock_leader_lock(bp) &&
10416 !bnx2x_leader_reset(bp)) {
10417 netdev_info(bp->dev, "Recovered in open\n");
10421 /* recovery has failed... */
10422 bnx2x_set_power_state(bp, PCI_D3hot);
10423 bp->recovery_state = BNX2X_RECOVERY_FAILED;
10425 BNX2X_ERR("Recovery flow hasn't been properly completed yet. Try again later.\n"
10426 "If you still see this message after a few retries then power cycle is required.\n");
10431 bp->recovery_state = BNX2X_RECOVERY_DONE;
10432 return bnx2x_nic_load(bp, LOAD_OPEN);
10435 /* called with rtnl_lock */
10436 static int bnx2x_close(struct net_device *dev)
10438 struct bnx2x *bp = netdev_priv(dev);
10440 /* Unload the driver, release IRQs */
10441 bnx2x_nic_unload(bp, UNLOAD_CLOSE);
10444 bnx2x_set_power_state(bp, PCI_D3hot);
10449 static inline int bnx2x_init_mcast_macs_list(struct bnx2x *bp,
10450 struct bnx2x_mcast_ramrod_params *p)
10452 int mc_count = netdev_mc_count(bp->dev);
10453 struct bnx2x_mcast_list_elem *mc_mac =
10454 kzalloc(sizeof(*mc_mac) * mc_count, GFP_ATOMIC);
10455 struct netdev_hw_addr *ha;
10460 INIT_LIST_HEAD(&p->mcast_list);
10462 netdev_for_each_mc_addr(ha, bp->dev) {
10463 mc_mac->mac = bnx2x_mc_addr(ha);
10464 list_add_tail(&mc_mac->link, &p->mcast_list);
10468 p->mcast_list_len = mc_count;
10473 static inline void bnx2x_free_mcast_macs_list(
10474 struct bnx2x_mcast_ramrod_params *p)
10476 struct bnx2x_mcast_list_elem *mc_mac =
10477 list_first_entry(&p->mcast_list, struct bnx2x_mcast_list_elem,
10485 * bnx2x_set_uc_list - configure a new unicast MACs list.
10487 * @bp: driver handle
10489 * We will use zero (0) as a MAC type for these MACs.
10491 static inline int bnx2x_set_uc_list(struct bnx2x *bp)
10494 struct net_device *dev = bp->dev;
10495 struct netdev_hw_addr *ha;
10496 struct bnx2x_vlan_mac_obj *mac_obj = &bp->fp->mac_obj;
10497 unsigned long ramrod_flags = 0;
10499 /* First schedule a cleanup up of old configuration */
10500 rc = bnx2x_del_all_macs(bp, mac_obj, BNX2X_UC_LIST_MAC, false);
10502 BNX2X_ERR("Failed to schedule DELETE operations: %d\n", rc);
10506 netdev_for_each_uc_addr(ha, dev) {
10507 rc = bnx2x_set_mac_one(bp, bnx2x_uc_addr(ha), mac_obj, true,
10508 BNX2X_UC_LIST_MAC, &ramrod_flags);
10510 BNX2X_ERR("Failed to schedule ADD operations: %d\n",
10516 /* Execute the pending commands */
10517 __set_bit(RAMROD_CONT, &ramrod_flags);
10518 return bnx2x_set_mac_one(bp, NULL, mac_obj, false /* don't care */,
10519 BNX2X_UC_LIST_MAC, &ramrod_flags);
10522 static inline int bnx2x_set_mc_list(struct bnx2x *bp)
10524 struct net_device *dev = bp->dev;
10525 struct bnx2x_mcast_ramrod_params rparam = {NULL};
10528 rparam.mcast_obj = &bp->mcast_obj;
10530 /* first, clear all configured multicast MACs */
10531 rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
10533 BNX2X_ERR("Failed to clear multicast configuration: %d\n", rc);
10537 /* then, configure a new MACs list */
10538 if (netdev_mc_count(dev)) {
10539 rc = bnx2x_init_mcast_macs_list(bp, &rparam);
10541 BNX2X_ERR("Failed to create multicast MACs list: %d\n",
10546 /* Now add the new MACs */
10547 rc = bnx2x_config_mcast(bp, &rparam,
10548 BNX2X_MCAST_CMD_ADD);
10550 BNX2X_ERR("Failed to set a new multicast configuration: %d\n",
10553 bnx2x_free_mcast_macs_list(&rparam);
10560 /* If bp->state is OPEN, should be called with netif_addr_lock_bh() */
10561 void bnx2x_set_rx_mode(struct net_device *dev)
10563 struct bnx2x *bp = netdev_priv(dev);
10564 u32 rx_mode = BNX2X_RX_MODE_NORMAL;
10566 if (bp->state != BNX2X_STATE_OPEN) {
10567 DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
10571 DP(NETIF_MSG_IFUP, "dev->flags = %x\n", bp->dev->flags);
10573 if (dev->flags & IFF_PROMISC)
10574 rx_mode = BNX2X_RX_MODE_PROMISC;
10575 else if ((dev->flags & IFF_ALLMULTI) ||
10576 ((netdev_mc_count(dev) > BNX2X_MAX_MULTICAST) &&
10578 rx_mode = BNX2X_RX_MODE_ALLMULTI;
10580 /* some multicasts */
10581 if (bnx2x_set_mc_list(bp) < 0)
10582 rx_mode = BNX2X_RX_MODE_ALLMULTI;
10584 if (bnx2x_set_uc_list(bp) < 0)
10585 rx_mode = BNX2X_RX_MODE_PROMISC;
10588 bp->rx_mode = rx_mode;
10590 /* handle ISCSI SD mode */
10591 if (IS_MF_ISCSI_SD(bp))
10592 bp->rx_mode = BNX2X_RX_MODE_NONE;
10595 /* Schedule the rx_mode command */
10596 if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state)) {
10597 set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
10601 bnx2x_set_storm_rx_mode(bp);
10604 /* called with rtnl_lock */
10605 static int bnx2x_mdio_read(struct net_device *netdev, int prtad,
10606 int devad, u16 addr)
10608 struct bnx2x *bp = netdev_priv(netdev);
10612 DP(NETIF_MSG_LINK, "mdio_read: prtad 0x%x, devad 0x%x, addr 0x%x\n",
10613 prtad, devad, addr);
10615 /* The HW expects different devad if CL22 is used */
10616 devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
10618 bnx2x_acquire_phy_lock(bp);
10619 rc = bnx2x_phy_read(&bp->link_params, prtad, devad, addr, &value);
10620 bnx2x_release_phy_lock(bp);
10621 DP(NETIF_MSG_LINK, "mdio_read_val 0x%x rc = 0x%x\n", value, rc);
10628 /* called with rtnl_lock */
10629 static int bnx2x_mdio_write(struct net_device *netdev, int prtad, int devad,
10630 u16 addr, u16 value)
10632 struct bnx2x *bp = netdev_priv(netdev);
10636 "mdio_write: prtad 0x%x, devad 0x%x, addr 0x%x, value 0x%x\n",
10637 prtad, devad, addr, value);
10639 /* The HW expects different devad if CL22 is used */
10640 devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
10642 bnx2x_acquire_phy_lock(bp);
10643 rc = bnx2x_phy_write(&bp->link_params, prtad, devad, addr, value);
10644 bnx2x_release_phy_lock(bp);
10648 /* called with rtnl_lock */
10649 static int bnx2x_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
10651 struct bnx2x *bp = netdev_priv(dev);
10652 struct mii_ioctl_data *mdio = if_mii(ifr);
10654 DP(NETIF_MSG_LINK, "ioctl: phy id 0x%x, reg 0x%x, val_in 0x%x\n",
10655 mdio->phy_id, mdio->reg_num, mdio->val_in);
10657 if (!netif_running(dev))
10660 return mdio_mii_ioctl(&bp->mdio, mdio, cmd);
10663 #ifdef CONFIG_NET_POLL_CONTROLLER
10664 static void poll_bnx2x(struct net_device *dev)
10666 struct bnx2x *bp = netdev_priv(dev);
10668 disable_irq(bp->pdev->irq);
10669 bnx2x_interrupt(bp->pdev->irq, dev);
10670 enable_irq(bp->pdev->irq);
10674 static int bnx2x_validate_addr(struct net_device *dev)
10676 struct bnx2x *bp = netdev_priv(dev);
10678 if (!bnx2x_is_valid_ether_addr(bp, dev->dev_addr)) {
10679 BNX2X_ERR("Non-valid Ethernet address\n");
10680 return -EADDRNOTAVAIL;
10685 static const struct net_device_ops bnx2x_netdev_ops = {
10686 .ndo_open = bnx2x_open,
10687 .ndo_stop = bnx2x_close,
10688 .ndo_start_xmit = bnx2x_start_xmit,
10689 .ndo_select_queue = bnx2x_select_queue,
10690 .ndo_set_rx_mode = bnx2x_set_rx_mode,
10691 .ndo_set_mac_address = bnx2x_change_mac_addr,
10692 .ndo_validate_addr = bnx2x_validate_addr,
10693 .ndo_do_ioctl = bnx2x_ioctl,
10694 .ndo_change_mtu = bnx2x_change_mtu,
10695 .ndo_fix_features = bnx2x_fix_features,
10696 .ndo_set_features = bnx2x_set_features,
10697 .ndo_tx_timeout = bnx2x_tx_timeout,
10698 #ifdef CONFIG_NET_POLL_CONTROLLER
10699 .ndo_poll_controller = poll_bnx2x,
10701 .ndo_setup_tc = bnx2x_setup_tc,
10703 #if defined(NETDEV_FCOE_WWNN) && defined(BCM_CNIC)
10704 .ndo_fcoe_get_wwn = bnx2x_fcoe_get_wwn,
10708 static inline int bnx2x_set_coherency_mask(struct bnx2x *bp)
10710 struct device *dev = &bp->pdev->dev;
10712 if (dma_set_mask(dev, DMA_BIT_MASK(64)) == 0) {
10713 bp->flags |= USING_DAC_FLAG;
10714 if (dma_set_coherent_mask(dev, DMA_BIT_MASK(64)) != 0) {
10715 dev_err(dev, "dma_set_coherent_mask failed, aborting\n");
10718 } else if (dma_set_mask(dev, DMA_BIT_MASK(32)) != 0) {
10719 dev_err(dev, "System does not support DMA, aborting\n");
10726 static int __devinit bnx2x_init_dev(struct pci_dev *pdev,
10727 struct net_device *dev,
10728 unsigned long board_type)
10733 bool chip_is_e1x = (board_type == BCM57710 ||
10734 board_type == BCM57711 ||
10735 board_type == BCM57711E);
10737 SET_NETDEV_DEV(dev, &pdev->dev);
10738 bp = netdev_priv(dev);
10744 rc = pci_enable_device(pdev);
10746 dev_err(&bp->pdev->dev,
10747 "Cannot enable PCI device, aborting\n");
10751 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
10752 dev_err(&bp->pdev->dev,
10753 "Cannot find PCI device base address, aborting\n");
10755 goto err_out_disable;
10758 if (!(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
10759 dev_err(&bp->pdev->dev, "Cannot find second PCI device"
10760 " base address, aborting\n");
10762 goto err_out_disable;
10765 if (atomic_read(&pdev->enable_cnt) == 1) {
10766 rc = pci_request_regions(pdev, DRV_MODULE_NAME);
10768 dev_err(&bp->pdev->dev,
10769 "Cannot obtain PCI resources, aborting\n");
10770 goto err_out_disable;
10773 pci_set_master(pdev);
10774 pci_save_state(pdev);
10777 bp->pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
10778 if (bp->pm_cap == 0) {
10779 dev_err(&bp->pdev->dev,
10780 "Cannot find power management capability, aborting\n");
10782 goto err_out_release;
10785 if (!pci_is_pcie(pdev)) {
10786 dev_err(&bp->pdev->dev, "Not PCI Express, aborting\n");
10788 goto err_out_release;
10791 rc = bnx2x_set_coherency_mask(bp);
10793 goto err_out_release;
10795 dev->mem_start = pci_resource_start(pdev, 0);
10796 dev->base_addr = dev->mem_start;
10797 dev->mem_end = pci_resource_end(pdev, 0);
10799 dev->irq = pdev->irq;
10801 bp->regview = pci_ioremap_bar(pdev, 0);
10802 if (!bp->regview) {
10803 dev_err(&bp->pdev->dev,
10804 "Cannot map register space, aborting\n");
10806 goto err_out_release;
10809 /* In E1/E1H use pci device function given by kernel.
10810 * In E2/E3 read physical function from ME register since these chips
10811 * support Physical Device Assignment where kernel BDF maybe arbitrary
10812 * (depending on hypervisor).
10815 bp->pf_num = PCI_FUNC(pdev->devfn);
10816 else {/* chip is E2/3*/
10817 pci_read_config_dword(bp->pdev,
10818 PCICFG_ME_REGISTER, &pci_cfg_dword);
10819 bp->pf_num = (u8)((pci_cfg_dword & ME_REG_ABS_PF_NUM) >>
10820 ME_REG_ABS_PF_NUM_SHIFT);
10822 BNX2X_DEV_INFO("me reg PF num: %d\n", bp->pf_num);
10824 bnx2x_set_power_state(bp, PCI_D0);
10826 /* clean indirect addresses */
10827 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
10828 PCICFG_VENDOR_ID_OFFSET);
10830 * Clean the following indirect addresses for all functions since it
10831 * is not used by the driver.
10833 REG_WR(bp, PXP2_REG_PGL_ADDR_88_F0, 0);
10834 REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F0, 0);
10835 REG_WR(bp, PXP2_REG_PGL_ADDR_90_F0, 0);
10836 REG_WR(bp, PXP2_REG_PGL_ADDR_94_F0, 0);
10839 REG_WR(bp, PXP2_REG_PGL_ADDR_88_F1, 0);
10840 REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F1, 0);
10841 REG_WR(bp, PXP2_REG_PGL_ADDR_90_F1, 0);
10842 REG_WR(bp, PXP2_REG_PGL_ADDR_94_F1, 0);
10846 * Enable internal target-read (in case we are probed after PF FLR).
10847 * Must be done prior to any BAR read access. Only for 57712 and up
10850 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
10852 /* Reset the load counter */
10853 bnx2x_clear_load_status(bp);
10855 dev->watchdog_timeo = TX_TIMEOUT;
10857 dev->netdev_ops = &bnx2x_netdev_ops;
10858 bnx2x_set_ethtool_ops(dev);
10860 dev->priv_flags |= IFF_UNICAST_FLT;
10862 dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
10863 NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
10864 NETIF_F_RXCSUM | NETIF_F_LRO | NETIF_F_GRO |
10865 NETIF_F_RXHASH | NETIF_F_HW_VLAN_TX;
10867 dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
10868 NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 | NETIF_F_HIGHDMA;
10870 dev->features |= dev->hw_features | NETIF_F_HW_VLAN_RX;
10871 if (bp->flags & USING_DAC_FLAG)
10872 dev->features |= NETIF_F_HIGHDMA;
10874 /* Add Loopback capability to the device */
10875 dev->hw_features |= NETIF_F_LOOPBACK;
10878 dev->dcbnl_ops = &bnx2x_dcbnl_ops;
10881 /* get_port_hwinfo() will set prtad and mmds properly */
10882 bp->mdio.prtad = MDIO_PRTAD_NONE;
10884 bp->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
10885 bp->mdio.dev = dev;
10886 bp->mdio.mdio_read = bnx2x_mdio_read;
10887 bp->mdio.mdio_write = bnx2x_mdio_write;
10892 if (atomic_read(&pdev->enable_cnt) == 1)
10893 pci_release_regions(pdev);
10896 pci_disable_device(pdev);
10897 pci_set_drvdata(pdev, NULL);
10903 static void __devinit bnx2x_get_pcie_width_speed(struct bnx2x *bp,
10904 int *width, int *speed)
10906 u32 val = REG_RD(bp, PCICFG_OFFSET + PCICFG_LINK_CONTROL);
10908 *width = (val & PCICFG_LINK_WIDTH) >> PCICFG_LINK_WIDTH_SHIFT;
10910 /* return value of 1=2.5GHz 2=5GHz */
10911 *speed = (val & PCICFG_LINK_SPEED) >> PCICFG_LINK_SPEED_SHIFT;
10914 static int bnx2x_check_firmware(struct bnx2x *bp)
10916 const struct firmware *firmware = bp->firmware;
10917 struct bnx2x_fw_file_hdr *fw_hdr;
10918 struct bnx2x_fw_file_section *sections;
10919 u32 offset, len, num_ops;
10924 if (firmware->size < sizeof(struct bnx2x_fw_file_hdr)) {
10925 BNX2X_ERR("Wrong FW size\n");
10929 fw_hdr = (struct bnx2x_fw_file_hdr *)firmware->data;
10930 sections = (struct bnx2x_fw_file_section *)fw_hdr;
10932 /* Make sure none of the offsets and sizes make us read beyond
10933 * the end of the firmware data */
10934 for (i = 0; i < sizeof(*fw_hdr) / sizeof(*sections); i++) {
10935 offset = be32_to_cpu(sections[i].offset);
10936 len = be32_to_cpu(sections[i].len);
10937 if (offset + len > firmware->size) {
10938 BNX2X_ERR("Section %d length is out of bounds\n", i);
10943 /* Likewise for the init_ops offsets */
10944 offset = be32_to_cpu(fw_hdr->init_ops_offsets.offset);
10945 ops_offsets = (u16 *)(firmware->data + offset);
10946 num_ops = be32_to_cpu(fw_hdr->init_ops.len) / sizeof(struct raw_op);
10948 for (i = 0; i < be32_to_cpu(fw_hdr->init_ops_offsets.len) / 2; i++) {
10949 if (be16_to_cpu(ops_offsets[i]) > num_ops) {
10950 BNX2X_ERR("Section offset %d is out of bounds\n", i);
10955 /* Check FW version */
10956 offset = be32_to_cpu(fw_hdr->fw_version.offset);
10957 fw_ver = firmware->data + offset;
10958 if ((fw_ver[0] != BCM_5710_FW_MAJOR_VERSION) ||
10959 (fw_ver[1] != BCM_5710_FW_MINOR_VERSION) ||
10960 (fw_ver[2] != BCM_5710_FW_REVISION_VERSION) ||
10961 (fw_ver[3] != BCM_5710_FW_ENGINEERING_VERSION)) {
10962 BNX2X_ERR("Bad FW version:%d.%d.%d.%d. Should be %d.%d.%d.%d\n",
10963 fw_ver[0], fw_ver[1], fw_ver[2], fw_ver[3],
10964 BCM_5710_FW_MAJOR_VERSION,
10965 BCM_5710_FW_MINOR_VERSION,
10966 BCM_5710_FW_REVISION_VERSION,
10967 BCM_5710_FW_ENGINEERING_VERSION);
10974 static inline void be32_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
10976 const __be32 *source = (const __be32 *)_source;
10977 u32 *target = (u32 *)_target;
10980 for (i = 0; i < n/4; i++)
10981 target[i] = be32_to_cpu(source[i]);
10985 Ops array is stored in the following format:
10986 {op(8bit), offset(24bit, big endian), data(32bit, big endian)}
10988 static inline void bnx2x_prep_ops(const u8 *_source, u8 *_target, u32 n)
10990 const __be32 *source = (const __be32 *)_source;
10991 struct raw_op *target = (struct raw_op *)_target;
10994 for (i = 0, j = 0; i < n/8; i++, j += 2) {
10995 tmp = be32_to_cpu(source[j]);
10996 target[i].op = (tmp >> 24) & 0xff;
10997 target[i].offset = tmp & 0xffffff;
10998 target[i].raw_data = be32_to_cpu(source[j + 1]);
11003 * IRO array is stored in the following format:
11004 * {base(24bit), m1(16bit), m2(16bit), m3(16bit), size(16bit) }
11006 static inline void bnx2x_prep_iro(const u8 *_source, u8 *_target, u32 n)
11008 const __be32 *source = (const __be32 *)_source;
11009 struct iro *target = (struct iro *)_target;
11012 for (i = 0, j = 0; i < n/sizeof(struct iro); i++) {
11013 target[i].base = be32_to_cpu(source[j]);
11015 tmp = be32_to_cpu(source[j]);
11016 target[i].m1 = (tmp >> 16) & 0xffff;
11017 target[i].m2 = tmp & 0xffff;
11019 tmp = be32_to_cpu(source[j]);
11020 target[i].m3 = (tmp >> 16) & 0xffff;
11021 target[i].size = tmp & 0xffff;
11026 static inline void be16_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
11028 const __be16 *source = (const __be16 *)_source;
11029 u16 *target = (u16 *)_target;
11032 for (i = 0; i < n/2; i++)
11033 target[i] = be16_to_cpu(source[i]);
11036 #define BNX2X_ALLOC_AND_SET(arr, lbl, func) \
11038 u32 len = be32_to_cpu(fw_hdr->arr.len); \
11039 bp->arr = kmalloc(len, GFP_KERNEL); \
11042 func(bp->firmware->data + be32_to_cpu(fw_hdr->arr.offset), \
11043 (u8 *)bp->arr, len); \
11046 static int bnx2x_init_firmware(struct bnx2x *bp)
11048 const char *fw_file_name;
11049 struct bnx2x_fw_file_hdr *fw_hdr;
11055 if (CHIP_IS_E1(bp))
11056 fw_file_name = FW_FILE_NAME_E1;
11057 else if (CHIP_IS_E1H(bp))
11058 fw_file_name = FW_FILE_NAME_E1H;
11059 else if (!CHIP_IS_E1x(bp))
11060 fw_file_name = FW_FILE_NAME_E2;
11062 BNX2X_ERR("Unsupported chip revision\n");
11065 BNX2X_DEV_INFO("Loading %s\n", fw_file_name);
11067 rc = request_firmware(&bp->firmware, fw_file_name, &bp->pdev->dev);
11069 BNX2X_ERR("Can't load firmware file %s\n",
11071 goto request_firmware_exit;
11074 rc = bnx2x_check_firmware(bp);
11076 BNX2X_ERR("Corrupt firmware file %s\n", fw_file_name);
11077 goto request_firmware_exit;
11080 fw_hdr = (struct bnx2x_fw_file_hdr *)bp->firmware->data;
11082 /* Initialize the pointers to the init arrays */
11084 BNX2X_ALLOC_AND_SET(init_data, request_firmware_exit, be32_to_cpu_n);
11087 BNX2X_ALLOC_AND_SET(init_ops, init_ops_alloc_err, bnx2x_prep_ops);
11090 BNX2X_ALLOC_AND_SET(init_ops_offsets, init_offsets_alloc_err,
11093 /* STORMs firmware */
11094 INIT_TSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
11095 be32_to_cpu(fw_hdr->tsem_int_table_data.offset);
11096 INIT_TSEM_PRAM_DATA(bp) = bp->firmware->data +
11097 be32_to_cpu(fw_hdr->tsem_pram_data.offset);
11098 INIT_USEM_INT_TABLE_DATA(bp) = bp->firmware->data +
11099 be32_to_cpu(fw_hdr->usem_int_table_data.offset);
11100 INIT_USEM_PRAM_DATA(bp) = bp->firmware->data +
11101 be32_to_cpu(fw_hdr->usem_pram_data.offset);
11102 INIT_XSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
11103 be32_to_cpu(fw_hdr->xsem_int_table_data.offset);
11104 INIT_XSEM_PRAM_DATA(bp) = bp->firmware->data +
11105 be32_to_cpu(fw_hdr->xsem_pram_data.offset);
11106 INIT_CSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
11107 be32_to_cpu(fw_hdr->csem_int_table_data.offset);
11108 INIT_CSEM_PRAM_DATA(bp) = bp->firmware->data +
11109 be32_to_cpu(fw_hdr->csem_pram_data.offset);
11111 BNX2X_ALLOC_AND_SET(iro_arr, iro_alloc_err, bnx2x_prep_iro);
11116 kfree(bp->init_ops_offsets);
11117 init_offsets_alloc_err:
11118 kfree(bp->init_ops);
11119 init_ops_alloc_err:
11120 kfree(bp->init_data);
11121 request_firmware_exit:
11122 release_firmware(bp->firmware);
11123 bp->firmware = NULL;
11128 static void bnx2x_release_firmware(struct bnx2x *bp)
11130 kfree(bp->init_ops_offsets);
11131 kfree(bp->init_ops);
11132 kfree(bp->init_data);
11133 release_firmware(bp->firmware);
11134 bp->firmware = NULL;
11138 static struct bnx2x_func_sp_drv_ops bnx2x_func_sp_drv = {
11139 .init_hw_cmn_chip = bnx2x_init_hw_common_chip,
11140 .init_hw_cmn = bnx2x_init_hw_common,
11141 .init_hw_port = bnx2x_init_hw_port,
11142 .init_hw_func = bnx2x_init_hw_func,
11144 .reset_hw_cmn = bnx2x_reset_common,
11145 .reset_hw_port = bnx2x_reset_port,
11146 .reset_hw_func = bnx2x_reset_func,
11148 .gunzip_init = bnx2x_gunzip_init,
11149 .gunzip_end = bnx2x_gunzip_end,
11151 .init_fw = bnx2x_init_firmware,
11152 .release_fw = bnx2x_release_firmware,
11155 void bnx2x__init_func_obj(struct bnx2x *bp)
11157 /* Prepare DMAE related driver resources */
11158 bnx2x_setup_dmae(bp);
11160 bnx2x_init_func_obj(bp, &bp->func_obj,
11161 bnx2x_sp(bp, func_rdata),
11162 bnx2x_sp_mapping(bp, func_rdata),
11163 &bnx2x_func_sp_drv);
11166 /* must be called after sriov-enable */
11167 static inline int bnx2x_set_qm_cid_count(struct bnx2x *bp)
11169 int cid_count = BNX2X_L2_CID_COUNT(bp);
11172 cid_count += CNIC_CID_MAX;
11174 return roundup(cid_count, QM_CID_ROUND);
11178 * bnx2x_get_num_none_def_sbs - return the number of none default SBs
11183 static inline int bnx2x_get_num_non_def_sbs(struct pci_dev *pdev)
11188 pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
11191 * If MSI-X is not supported - return number of SBs needed to support
11192 * one fast path queue: one FP queue + SB for CNIC
11195 return 1 + CNIC_PRESENT;
11198 * The value in the PCI configuration space is the index of the last
11199 * entry, namely one less than the actual size of the table, which is
11200 * exactly what we want to return from this function: number of all SBs
11201 * without the default SB.
11203 pci_read_config_word(pdev, pos + PCI_MSI_FLAGS, &control);
11204 return control & PCI_MSIX_FLAGS_QSIZE;
11207 static int __devinit bnx2x_init_one(struct pci_dev *pdev,
11208 const struct pci_device_id *ent)
11210 struct net_device *dev = NULL;
11212 int pcie_width, pcie_speed;
11213 int rc, max_non_def_sbs;
11214 int rx_count, tx_count, rss_count;
11216 * An estimated maximum supported CoS number according to the chip
11218 * We will try to roughly estimate the maximum number of CoSes this chip
11219 * may support in order to minimize the memory allocated for Tx
11220 * netdev_queue's. This number will be accurately calculated during the
11221 * initialization of bp->max_cos based on the chip versions AND chip
11222 * revision in the bnx2x_init_bp().
11224 u8 max_cos_est = 0;
11226 switch (ent->driver_data) {
11230 max_cos_est = BNX2X_MULTI_TX_COS_E1X;
11235 max_cos_est = BNX2X_MULTI_TX_COS_E2_E3A0;
11244 max_cos_est = BNX2X_MULTI_TX_COS_E3B0;
11248 pr_err("Unknown board_type (%ld), aborting\n",
11253 max_non_def_sbs = bnx2x_get_num_non_def_sbs(pdev);
11256 * Do not allow the maximum SB count to grow above 16
11257 * since Special CIDs starts from 16*BNX2X_MULTI_TX_COS=48.
11258 * We will use the FP_SB_MAX_E1x macro for this matter.
11260 max_non_def_sbs = min_t(int, FP_SB_MAX_E1x, max_non_def_sbs);
11262 WARN_ON(!max_non_def_sbs);
11264 /* Maximum number of RSS queues: one IGU SB goes to CNIC */
11265 rss_count = max_non_def_sbs - CNIC_PRESENT;
11267 /* Maximum number of netdev Rx queues: RSS + FCoE L2 */
11268 rx_count = rss_count + FCOE_PRESENT;
11271 * Maximum number of netdev Tx queues:
11272 * Maximum TSS queues * Maximum supported number of CoS + FCoE L2
11274 tx_count = MAX_TXQS_PER_COS * max_cos_est + FCOE_PRESENT;
11276 /* dev zeroed in init_etherdev */
11277 dev = alloc_etherdev_mqs(sizeof(*bp), tx_count, rx_count);
11281 bp = netdev_priv(dev);
11283 BNX2X_DEV_INFO("Allocated netdev with %d tx and %d rx queues\n",
11284 tx_count, rx_count);
11286 bp->igu_sb_cnt = max_non_def_sbs;
11287 bp->msg_enable = debug;
11288 pci_set_drvdata(pdev, dev);
11290 rc = bnx2x_init_dev(pdev, dev, ent->driver_data);
11296 BNX2X_DEV_INFO("max_non_def_sbs %d\n", max_non_def_sbs);
11298 rc = bnx2x_init_bp(bp);
11300 goto init_one_exit;
11303 * Map doorbels here as we need the real value of bp->max_cos which
11304 * is initialized in bnx2x_init_bp().
11306 bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2),
11307 min_t(u64, BNX2X_DB_SIZE(bp),
11308 pci_resource_len(pdev, 2)));
11309 if (!bp->doorbells) {
11310 dev_err(&bp->pdev->dev,
11311 "Cannot map doorbell space, aborting\n");
11313 goto init_one_exit;
11316 /* calc qm_cid_count */
11317 bp->qm_cid_count = bnx2x_set_qm_cid_count(bp);
11320 /* disable FCOE L2 queue for E1x */
11321 if (CHIP_IS_E1x(bp))
11322 bp->flags |= NO_FCOE_FLAG;
11326 /* Configure interrupt mode: try to enable MSI-X/MSI if
11327 * needed, set bp->num_queues appropriately.
11329 bnx2x_set_int_mode(bp);
11331 /* Add all NAPI objects */
11332 bnx2x_add_all_napi(bp);
11334 rc = register_netdev(dev);
11336 dev_err(&pdev->dev, "Cannot register net device\n");
11337 goto init_one_exit;
11341 if (!NO_FCOE(bp)) {
11342 /* Add storage MAC address */
11344 dev_addr_add(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
11349 bnx2x_get_pcie_width_speed(bp, &pcie_width, &pcie_speed);
11352 "%s (%c%d) PCI-E x%d %s found at mem %lx, IRQ %d, node addr %pM\n",
11353 board_info[ent->driver_data].name,
11354 (CHIP_REV(bp) >> 12) + 'A', (CHIP_METAL(bp) >> 4),
11356 ((!CHIP_IS_E2(bp) && pcie_speed == 2) ||
11357 (CHIP_IS_E2(bp) && pcie_speed == 1)) ?
11358 "5GHz (Gen2)" : "2.5GHz",
11359 dev->base_addr, bp->pdev->irq, dev->dev_addr);
11365 iounmap(bp->regview);
11368 iounmap(bp->doorbells);
11372 if (atomic_read(&pdev->enable_cnt) == 1)
11373 pci_release_regions(pdev);
11375 pci_disable_device(pdev);
11376 pci_set_drvdata(pdev, NULL);
11381 static void __devexit bnx2x_remove_one(struct pci_dev *pdev)
11383 struct net_device *dev = pci_get_drvdata(pdev);
11387 dev_err(&pdev->dev, "BAD net device from bnx2x_init_one\n");
11390 bp = netdev_priv(dev);
11393 /* Delete storage MAC address */
11394 if (!NO_FCOE(bp)) {
11396 dev_addr_del(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
11402 /* Delete app tlvs from dcbnl */
11403 bnx2x_dcbnl_update_applist(bp, true);
11406 unregister_netdev(dev);
11408 /* Delete all NAPI objects */
11409 bnx2x_del_all_napi(bp);
11411 /* Power on: we can't let PCI layer write to us while we are in D3 */
11412 bnx2x_set_power_state(bp, PCI_D0);
11414 /* Disable MSI/MSI-X */
11415 bnx2x_disable_msi(bp);
11418 bnx2x_set_power_state(bp, PCI_D3hot);
11420 /* Make sure RESET task is not scheduled before continuing */
11421 cancel_delayed_work_sync(&bp->sp_rtnl_task);
11424 iounmap(bp->regview);
11427 iounmap(bp->doorbells);
11429 bnx2x_release_firmware(bp);
11431 bnx2x_free_mem_bp(bp);
11435 if (atomic_read(&pdev->enable_cnt) == 1)
11436 pci_release_regions(pdev);
11438 pci_disable_device(pdev);
11439 pci_set_drvdata(pdev, NULL);
11442 static int bnx2x_eeh_nic_unload(struct bnx2x *bp)
11446 bp->state = BNX2X_STATE_ERROR;
11448 bp->rx_mode = BNX2X_RX_MODE_NONE;
11451 bnx2x_cnic_notify(bp, CNIC_CTL_STOP_CMD);
11454 bnx2x_tx_disable(bp);
11456 bnx2x_netif_stop(bp, 0);
11458 del_timer_sync(&bp->timer);
11460 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
11463 bnx2x_free_irq(bp);
11465 /* Free SKBs, SGEs, TPA pool and driver internals */
11466 bnx2x_free_skbs(bp);
11468 for_each_rx_queue(bp, i)
11469 bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
11471 bnx2x_free_mem(bp);
11473 bp->state = BNX2X_STATE_CLOSED;
11475 netif_carrier_off(bp->dev);
11480 static void bnx2x_eeh_recover(struct bnx2x *bp)
11484 mutex_init(&bp->port.phy_mutex);
11487 val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
11488 if ((val & (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
11489 != (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
11490 BNX2X_ERR("BAD MCP validity signature\n");
11494 * bnx2x_io_error_detected - called when PCI error is detected
11495 * @pdev: Pointer to PCI device
11496 * @state: The current pci connection state
11498 * This function is called after a PCI bus error affecting
11499 * this device has been detected.
11501 static pci_ers_result_t bnx2x_io_error_detected(struct pci_dev *pdev,
11502 pci_channel_state_t state)
11504 struct net_device *dev = pci_get_drvdata(pdev);
11505 struct bnx2x *bp = netdev_priv(dev);
11509 netif_device_detach(dev);
11511 if (state == pci_channel_io_perm_failure) {
11513 return PCI_ERS_RESULT_DISCONNECT;
11516 if (netif_running(dev))
11517 bnx2x_eeh_nic_unload(bp);
11519 pci_disable_device(pdev);
11523 /* Request a slot reset */
11524 return PCI_ERS_RESULT_NEED_RESET;
11528 * bnx2x_io_slot_reset - called after the PCI bus has been reset
11529 * @pdev: Pointer to PCI device
11531 * Restart the card from scratch, as if from a cold-boot.
11533 static pci_ers_result_t bnx2x_io_slot_reset(struct pci_dev *pdev)
11535 struct net_device *dev = pci_get_drvdata(pdev);
11536 struct bnx2x *bp = netdev_priv(dev);
11540 if (pci_enable_device(pdev)) {
11541 dev_err(&pdev->dev,
11542 "Cannot re-enable PCI device after reset\n");
11544 return PCI_ERS_RESULT_DISCONNECT;
11547 pci_set_master(pdev);
11548 pci_restore_state(pdev);
11550 if (netif_running(dev))
11551 bnx2x_set_power_state(bp, PCI_D0);
11555 return PCI_ERS_RESULT_RECOVERED;
11559 * bnx2x_io_resume - called when traffic can start flowing again
11560 * @pdev: Pointer to PCI device
11562 * This callback is called when the error recovery driver tells us that
11563 * its OK to resume normal operation.
11565 static void bnx2x_io_resume(struct pci_dev *pdev)
11567 struct net_device *dev = pci_get_drvdata(pdev);
11568 struct bnx2x *bp = netdev_priv(dev);
11570 if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
11571 netdev_err(bp->dev, "Handling parity error recovery. Try again later\n");
11577 bnx2x_eeh_recover(bp);
11579 if (netif_running(dev))
11580 bnx2x_nic_load(bp, LOAD_NORMAL);
11582 netif_device_attach(dev);
11587 static struct pci_error_handlers bnx2x_err_handler = {
11588 .error_detected = bnx2x_io_error_detected,
11589 .slot_reset = bnx2x_io_slot_reset,
11590 .resume = bnx2x_io_resume,
11593 static struct pci_driver bnx2x_pci_driver = {
11594 .name = DRV_MODULE_NAME,
11595 .id_table = bnx2x_pci_tbl,
11596 .probe = bnx2x_init_one,
11597 .remove = __devexit_p(bnx2x_remove_one),
11598 .suspend = bnx2x_suspend,
11599 .resume = bnx2x_resume,
11600 .err_handler = &bnx2x_err_handler,
11603 static int __init bnx2x_init(void)
11607 pr_info("%s", version);
11609 bnx2x_wq = create_singlethread_workqueue("bnx2x");
11610 if (bnx2x_wq == NULL) {
11611 pr_err("Cannot create workqueue\n");
11615 ret = pci_register_driver(&bnx2x_pci_driver);
11617 pr_err("Cannot register driver\n");
11618 destroy_workqueue(bnx2x_wq);
11623 static void __exit bnx2x_cleanup(void)
11625 struct list_head *pos, *q;
11626 pci_unregister_driver(&bnx2x_pci_driver);
11628 destroy_workqueue(bnx2x_wq);
11630 /* Free globablly allocated resources */
11631 list_for_each_safe(pos, q, &bnx2x_prev_list) {
11632 struct bnx2x_prev_path_list *tmp =
11633 list_entry(pos, struct bnx2x_prev_path_list, list);
11639 void bnx2x_notify_link_changed(struct bnx2x *bp)
11641 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + BP_FUNC(bp)*sizeof(u32), 1);
11644 module_init(bnx2x_init);
11645 module_exit(bnx2x_cleanup);
11649 * bnx2x_set_iscsi_eth_mac_addr - set iSCSI MAC(s).
11651 * @bp: driver handle
11652 * @set: set or clear the CAM entry
11654 * This function will wait until the ramdord completion returns.
11655 * Return 0 if success, -ENODEV if ramrod doesn't return.
11657 static inline int bnx2x_set_iscsi_eth_mac_addr(struct bnx2x *bp)
11659 unsigned long ramrod_flags = 0;
11661 __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
11662 return bnx2x_set_mac_one(bp, bp->cnic_eth_dev.iscsi_mac,
11663 &bp->iscsi_l2_mac_obj, true,
11664 BNX2X_ISCSI_ETH_MAC, &ramrod_flags);
11667 /* count denotes the number of new completions we have seen */
11668 static void bnx2x_cnic_sp_post(struct bnx2x *bp, int count)
11670 struct eth_spe *spe;
11672 #ifdef BNX2X_STOP_ON_ERROR
11673 if (unlikely(bp->panic))
11677 spin_lock_bh(&bp->spq_lock);
11678 BUG_ON(bp->cnic_spq_pending < count);
11679 bp->cnic_spq_pending -= count;
11682 for (; bp->cnic_kwq_pending; bp->cnic_kwq_pending--) {
11683 u16 type = (le16_to_cpu(bp->cnic_kwq_cons->hdr.type)
11684 & SPE_HDR_CONN_TYPE) >>
11685 SPE_HDR_CONN_TYPE_SHIFT;
11686 u8 cmd = (le32_to_cpu(bp->cnic_kwq_cons->hdr.conn_and_cmd_data)
11687 >> SPE_HDR_CMD_ID_SHIFT) & 0xff;
11689 /* Set validation for iSCSI L2 client before sending SETUP
11692 if (type == ETH_CONNECTION_TYPE) {
11693 if (cmd == RAMROD_CMD_ID_ETH_CLIENT_SETUP)
11694 bnx2x_set_ctx_validation(bp, &bp->context.
11695 vcxt[BNX2X_ISCSI_ETH_CID].eth,
11696 BNX2X_ISCSI_ETH_CID);
11700 * There may be not more than 8 L2, not more than 8 L5 SPEs
11701 * and in the air. We also check that number of outstanding
11702 * COMMON ramrods is not more than the EQ and SPQ can
11705 if (type == ETH_CONNECTION_TYPE) {
11706 if (!atomic_read(&bp->cq_spq_left))
11709 atomic_dec(&bp->cq_spq_left);
11710 } else if (type == NONE_CONNECTION_TYPE) {
11711 if (!atomic_read(&bp->eq_spq_left))
11714 atomic_dec(&bp->eq_spq_left);
11715 } else if ((type == ISCSI_CONNECTION_TYPE) ||
11716 (type == FCOE_CONNECTION_TYPE)) {
11717 if (bp->cnic_spq_pending >=
11718 bp->cnic_eth_dev.max_kwqe_pending)
11721 bp->cnic_spq_pending++;
11723 BNX2X_ERR("Unknown SPE type: %d\n", type);
11728 spe = bnx2x_sp_get_next(bp);
11729 *spe = *bp->cnic_kwq_cons;
11731 DP(BNX2X_MSG_SP, "pending on SPQ %d, on KWQ %d count %d\n",
11732 bp->cnic_spq_pending, bp->cnic_kwq_pending, count);
11734 if (bp->cnic_kwq_cons == bp->cnic_kwq_last)
11735 bp->cnic_kwq_cons = bp->cnic_kwq;
11737 bp->cnic_kwq_cons++;
11739 bnx2x_sp_prod_update(bp);
11740 spin_unlock_bh(&bp->spq_lock);
11743 static int bnx2x_cnic_sp_queue(struct net_device *dev,
11744 struct kwqe_16 *kwqes[], u32 count)
11746 struct bnx2x *bp = netdev_priv(dev);
11749 #ifdef BNX2X_STOP_ON_ERROR
11750 if (unlikely(bp->panic)) {
11751 BNX2X_ERR("Can't post to SP queue while panic\n");
11756 if ((bp->recovery_state != BNX2X_RECOVERY_DONE) &&
11757 (bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
11758 BNX2X_ERR("Handling parity error recovery. Try again later\n");
11762 spin_lock_bh(&bp->spq_lock);
11764 for (i = 0; i < count; i++) {
11765 struct eth_spe *spe = (struct eth_spe *)kwqes[i];
11767 if (bp->cnic_kwq_pending == MAX_SP_DESC_CNT)
11770 *bp->cnic_kwq_prod = *spe;
11772 bp->cnic_kwq_pending++;
11774 DP(BNX2X_MSG_SP, "L5 SPQE %x %x %x:%x pos %d\n",
11775 spe->hdr.conn_and_cmd_data, spe->hdr.type,
11776 spe->data.update_data_addr.hi,
11777 spe->data.update_data_addr.lo,
11778 bp->cnic_kwq_pending);
11780 if (bp->cnic_kwq_prod == bp->cnic_kwq_last)
11781 bp->cnic_kwq_prod = bp->cnic_kwq;
11783 bp->cnic_kwq_prod++;
11786 spin_unlock_bh(&bp->spq_lock);
11788 if (bp->cnic_spq_pending < bp->cnic_eth_dev.max_kwqe_pending)
11789 bnx2x_cnic_sp_post(bp, 0);
11794 static int bnx2x_cnic_ctl_send(struct bnx2x *bp, struct cnic_ctl_info *ctl)
11796 struct cnic_ops *c_ops;
11799 mutex_lock(&bp->cnic_mutex);
11800 c_ops = rcu_dereference_protected(bp->cnic_ops,
11801 lockdep_is_held(&bp->cnic_mutex));
11803 rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
11804 mutex_unlock(&bp->cnic_mutex);
11809 static int bnx2x_cnic_ctl_send_bh(struct bnx2x *bp, struct cnic_ctl_info *ctl)
11811 struct cnic_ops *c_ops;
11815 c_ops = rcu_dereference(bp->cnic_ops);
11817 rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
11824 * for commands that have no data
11826 int bnx2x_cnic_notify(struct bnx2x *bp, int cmd)
11828 struct cnic_ctl_info ctl = {0};
11832 return bnx2x_cnic_ctl_send(bp, &ctl);
11835 static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err)
11837 struct cnic_ctl_info ctl = {0};
11839 /* first we tell CNIC and only then we count this as a completion */
11840 ctl.cmd = CNIC_CTL_COMPLETION_CMD;
11841 ctl.data.comp.cid = cid;
11842 ctl.data.comp.error = err;
11844 bnx2x_cnic_ctl_send_bh(bp, &ctl);
11845 bnx2x_cnic_sp_post(bp, 0);
11849 /* Called with netif_addr_lock_bh() taken.
11850 * Sets an rx_mode config for an iSCSI ETH client.
11852 * Completion should be checked outside.
11854 static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start)
11856 unsigned long accept_flags = 0, ramrod_flags = 0;
11857 u8 cl_id = bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
11858 int sched_state = BNX2X_FILTER_ISCSI_ETH_STOP_SCHED;
11861 /* Start accepting on iSCSI L2 ring. Accept all multicasts
11862 * because it's the only way for UIO Queue to accept
11863 * multicasts (in non-promiscuous mode only one Queue per
11864 * function will receive multicast packets (leading in our
11867 __set_bit(BNX2X_ACCEPT_UNICAST, &accept_flags);
11868 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept_flags);
11869 __set_bit(BNX2X_ACCEPT_BROADCAST, &accept_flags);
11870 __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept_flags);
11872 /* Clear STOP_PENDING bit if START is requested */
11873 clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &bp->sp_state);
11875 sched_state = BNX2X_FILTER_ISCSI_ETH_START_SCHED;
11877 /* Clear START_PENDING bit if STOP is requested */
11878 clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &bp->sp_state);
11880 if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
11881 set_bit(sched_state, &bp->sp_state);
11883 __set_bit(RAMROD_RX, &ramrod_flags);
11884 bnx2x_set_q_rx_mode(bp, cl_id, 0, accept_flags, 0,
11890 static int bnx2x_drv_ctl(struct net_device *dev, struct drv_ctl_info *ctl)
11892 struct bnx2x *bp = netdev_priv(dev);
11895 switch (ctl->cmd) {
11896 case DRV_CTL_CTXTBL_WR_CMD: {
11897 u32 index = ctl->data.io.offset;
11898 dma_addr_t addr = ctl->data.io.dma_addr;
11900 bnx2x_ilt_wr(bp, index, addr);
11904 case DRV_CTL_RET_L5_SPQ_CREDIT_CMD: {
11905 int count = ctl->data.credit.credit_count;
11907 bnx2x_cnic_sp_post(bp, count);
11911 /* rtnl_lock is held. */
11912 case DRV_CTL_START_L2_CMD: {
11913 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
11914 unsigned long sp_bits = 0;
11916 /* Configure the iSCSI classification object */
11917 bnx2x_init_mac_obj(bp, &bp->iscsi_l2_mac_obj,
11918 cp->iscsi_l2_client_id,
11919 cp->iscsi_l2_cid, BP_FUNC(bp),
11920 bnx2x_sp(bp, mac_rdata),
11921 bnx2x_sp_mapping(bp, mac_rdata),
11922 BNX2X_FILTER_MAC_PENDING,
11923 &bp->sp_state, BNX2X_OBJ_TYPE_RX,
11926 /* Set iSCSI MAC address */
11927 rc = bnx2x_set_iscsi_eth_mac_addr(bp);
11934 /* Start accepting on iSCSI L2 ring */
11936 netif_addr_lock_bh(dev);
11937 bnx2x_set_iscsi_eth_rx_mode(bp, true);
11938 netif_addr_unlock_bh(dev);
11940 /* bits to wait on */
11941 __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
11942 __set_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &sp_bits);
11944 if (!bnx2x_wait_sp_comp(bp, sp_bits))
11945 BNX2X_ERR("rx_mode completion timed out!\n");
11950 /* rtnl_lock is held. */
11951 case DRV_CTL_STOP_L2_CMD: {
11952 unsigned long sp_bits = 0;
11954 /* Stop accepting on iSCSI L2 ring */
11955 netif_addr_lock_bh(dev);
11956 bnx2x_set_iscsi_eth_rx_mode(bp, false);
11957 netif_addr_unlock_bh(dev);
11959 /* bits to wait on */
11960 __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
11961 __set_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &sp_bits);
11963 if (!bnx2x_wait_sp_comp(bp, sp_bits))
11964 BNX2X_ERR("rx_mode completion timed out!\n");
11969 /* Unset iSCSI L2 MAC */
11970 rc = bnx2x_del_all_macs(bp, &bp->iscsi_l2_mac_obj,
11971 BNX2X_ISCSI_ETH_MAC, true);
11974 case DRV_CTL_RET_L2_SPQ_CREDIT_CMD: {
11975 int count = ctl->data.credit.credit_count;
11977 smp_mb__before_atomic_inc();
11978 atomic_add(count, &bp->cq_spq_left);
11979 smp_mb__after_atomic_inc();
11982 case DRV_CTL_ULP_REGISTER_CMD: {
11983 int ulp_type = ctl->data.ulp_type;
11985 if (CHIP_IS_E3(bp)) {
11986 int idx = BP_FW_MB_IDX(bp);
11989 cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
11990 if (ulp_type == CNIC_ULP_ISCSI)
11991 cap |= DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
11992 else if (ulp_type == CNIC_ULP_FCOE)
11993 cap |= DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
11994 SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
11998 case DRV_CTL_ULP_UNREGISTER_CMD: {
11999 int ulp_type = ctl->data.ulp_type;
12001 if (CHIP_IS_E3(bp)) {
12002 int idx = BP_FW_MB_IDX(bp);
12005 cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
12006 if (ulp_type == CNIC_ULP_ISCSI)
12007 cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
12008 else if (ulp_type == CNIC_ULP_FCOE)
12009 cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
12010 SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
12016 BNX2X_ERR("unknown command %x\n", ctl->cmd);
12023 void bnx2x_setup_cnic_irq_info(struct bnx2x *bp)
12025 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
12027 if (bp->flags & USING_MSIX_FLAG) {
12028 cp->drv_state |= CNIC_DRV_STATE_USING_MSIX;
12029 cp->irq_arr[0].irq_flags |= CNIC_IRQ_FL_MSIX;
12030 cp->irq_arr[0].vector = bp->msix_table[1].vector;
12032 cp->drv_state &= ~CNIC_DRV_STATE_USING_MSIX;
12033 cp->irq_arr[0].irq_flags &= ~CNIC_IRQ_FL_MSIX;
12035 if (!CHIP_IS_E1x(bp))
12036 cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e2_sb;
12038 cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e1x_sb;
12040 cp->irq_arr[0].status_blk_num = bnx2x_cnic_fw_sb_id(bp);
12041 cp->irq_arr[0].status_blk_num2 = bnx2x_cnic_igu_sb_id(bp);
12042 cp->irq_arr[1].status_blk = bp->def_status_blk;
12043 cp->irq_arr[1].status_blk_num = DEF_SB_ID;
12044 cp->irq_arr[1].status_blk_num2 = DEF_SB_IGU_ID;
12049 static int bnx2x_register_cnic(struct net_device *dev, struct cnic_ops *ops,
12052 struct bnx2x *bp = netdev_priv(dev);
12053 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
12056 BNX2X_ERR("NULL ops received\n");
12060 bp->cnic_kwq = kzalloc(PAGE_SIZE, GFP_KERNEL);
12064 bp->cnic_kwq_cons = bp->cnic_kwq;
12065 bp->cnic_kwq_prod = bp->cnic_kwq;
12066 bp->cnic_kwq_last = bp->cnic_kwq + MAX_SP_DESC_CNT;
12068 bp->cnic_spq_pending = 0;
12069 bp->cnic_kwq_pending = 0;
12071 bp->cnic_data = data;
12074 cp->drv_state |= CNIC_DRV_STATE_REGD;
12075 cp->iro_arr = bp->iro_arr;
12077 bnx2x_setup_cnic_irq_info(bp);
12079 rcu_assign_pointer(bp->cnic_ops, ops);
12084 static int bnx2x_unregister_cnic(struct net_device *dev)
12086 struct bnx2x *bp = netdev_priv(dev);
12087 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
12089 mutex_lock(&bp->cnic_mutex);
12091 RCU_INIT_POINTER(bp->cnic_ops, NULL);
12092 mutex_unlock(&bp->cnic_mutex);
12094 kfree(bp->cnic_kwq);
12095 bp->cnic_kwq = NULL;
12100 struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev)
12102 struct bnx2x *bp = netdev_priv(dev);
12103 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
12105 /* If both iSCSI and FCoE are disabled - return NULL in
12106 * order to indicate CNIC that it should not try to work
12107 * with this device.
12109 if (NO_ISCSI(bp) && NO_FCOE(bp))
12112 cp->drv_owner = THIS_MODULE;
12113 cp->chip_id = CHIP_ID(bp);
12114 cp->pdev = bp->pdev;
12115 cp->io_base = bp->regview;
12116 cp->io_base2 = bp->doorbells;
12117 cp->max_kwqe_pending = 8;
12118 cp->ctx_blk_size = CDU_ILT_PAGE_SZ;
12119 cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
12120 bnx2x_cid_ilt_lines(bp);
12121 cp->ctx_tbl_len = CNIC_ILT_LINES;
12122 cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
12123 cp->drv_submit_kwqes_16 = bnx2x_cnic_sp_queue;
12124 cp->drv_ctl = bnx2x_drv_ctl;
12125 cp->drv_register_cnic = bnx2x_register_cnic;
12126 cp->drv_unregister_cnic = bnx2x_unregister_cnic;
12127 cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID;
12128 cp->iscsi_l2_client_id =
12129 bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
12130 cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID;
12132 if (NO_ISCSI_OOO(bp))
12133 cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
12136 cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI;
12139 cp->drv_state |= CNIC_DRV_STATE_NO_FCOE;
12142 "page_size %d, tbl_offset %d, tbl_lines %d, starting cid %d\n",
12144 cp->ctx_tbl_offset,
12149 EXPORT_SYMBOL(bnx2x_cnic_probe);
12151 #endif /* BCM_CNIC */