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 #define MAC_LEADING_ZERO_CNT (ALIGN(ETH_ALEN, sizeof(u32)) - ETH_ALEN)
79 /* Time in jiffies before concluding the transmitter is hung */
80 #define TX_TIMEOUT (5*HZ)
82 static char version[] __devinitdata =
83 "Broadcom NetXtreme II 5771x/578xx 10/20-Gigabit Ethernet Driver "
84 DRV_MODULE_NAME " " DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
86 MODULE_AUTHOR("Eliezer Tamir");
87 MODULE_DESCRIPTION("Broadcom NetXtreme II "
88 "BCM57710/57711/57711E/"
89 "57712/57712_MF/57800/57800_MF/57810/57810_MF/"
90 "57840/57840_MF Driver");
91 MODULE_LICENSE("GPL");
92 MODULE_VERSION(DRV_MODULE_VERSION);
93 MODULE_FIRMWARE(FW_FILE_NAME_E1);
94 MODULE_FIRMWARE(FW_FILE_NAME_E1H);
95 MODULE_FIRMWARE(FW_FILE_NAME_E2);
99 module_param(num_queues, int, 0);
100 MODULE_PARM_DESC(num_queues,
101 " Set number of queues (default is as a number of CPUs)");
103 static int disable_tpa;
104 module_param(disable_tpa, int, 0);
105 MODULE_PARM_DESC(disable_tpa, " Disable the TPA (LRO) feature");
107 #define INT_MODE_INTx 1
108 #define INT_MODE_MSI 2
110 module_param(int_mode, int, 0);
111 MODULE_PARM_DESC(int_mode, " Force interrupt mode other than MSI-X "
114 static int dropless_fc;
115 module_param(dropless_fc, int, 0);
116 MODULE_PARM_DESC(dropless_fc, " Pause on exhausted host ring");
118 static int mrrs = -1;
119 module_param(mrrs, int, 0);
120 MODULE_PARM_DESC(mrrs, " Force Max Read Req Size (0..3) (for debug)");
123 module_param(debug, int, 0);
124 MODULE_PARM_DESC(debug, " Default debug msglevel");
128 struct workqueue_struct *bnx2x_wq;
130 enum bnx2x_board_type {
149 /* indexed by board_type, above */
152 } board_info[] __devinitdata = {
153 { "Broadcom NetXtreme II BCM57710 10 Gigabit PCIe [Everest]" },
154 { "Broadcom NetXtreme II BCM57711 10 Gigabit PCIe" },
155 { "Broadcom NetXtreme II BCM57711E 10 Gigabit PCIe" },
156 { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet" },
157 { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Multi Function" },
158 { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet" },
159 { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Multi Function" },
160 { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet" },
161 { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Multi Function" },
162 { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet" },
163 { "Broadcom NetXtreme II BCM57840 10 Gigabit Ethernet" },
164 { "Broadcom NetXtreme II BCM57840 20 Gigabit Ethernet" },
165 { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Multi Function"},
166 { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Multi Function"},
167 { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet"},
168 { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet Multi Function"},
171 #ifndef PCI_DEVICE_ID_NX2_57710
172 #define PCI_DEVICE_ID_NX2_57710 CHIP_NUM_57710
174 #ifndef PCI_DEVICE_ID_NX2_57711
175 #define PCI_DEVICE_ID_NX2_57711 CHIP_NUM_57711
177 #ifndef PCI_DEVICE_ID_NX2_57711E
178 #define PCI_DEVICE_ID_NX2_57711E CHIP_NUM_57711E
180 #ifndef PCI_DEVICE_ID_NX2_57712
181 #define PCI_DEVICE_ID_NX2_57712 CHIP_NUM_57712
183 #ifndef PCI_DEVICE_ID_NX2_57712_MF
184 #define PCI_DEVICE_ID_NX2_57712_MF CHIP_NUM_57712_MF
186 #ifndef PCI_DEVICE_ID_NX2_57800
187 #define PCI_DEVICE_ID_NX2_57800 CHIP_NUM_57800
189 #ifndef PCI_DEVICE_ID_NX2_57800_MF
190 #define PCI_DEVICE_ID_NX2_57800_MF CHIP_NUM_57800_MF
192 #ifndef PCI_DEVICE_ID_NX2_57810
193 #define PCI_DEVICE_ID_NX2_57810 CHIP_NUM_57810
195 #ifndef PCI_DEVICE_ID_NX2_57810_MF
196 #define PCI_DEVICE_ID_NX2_57810_MF CHIP_NUM_57810_MF
198 #ifndef PCI_DEVICE_ID_NX2_57840_O
199 #define PCI_DEVICE_ID_NX2_57840_O CHIP_NUM_57840_OBSOLETE
201 #ifndef PCI_DEVICE_ID_NX2_57840_4_10
202 #define PCI_DEVICE_ID_NX2_57840_4_10 CHIP_NUM_57840_4_10
204 #ifndef PCI_DEVICE_ID_NX2_57840_2_20
205 #define PCI_DEVICE_ID_NX2_57840_2_20 CHIP_NUM_57840_2_20
207 #ifndef PCI_DEVICE_ID_NX2_57840_MFO
208 #define PCI_DEVICE_ID_NX2_57840_MFO CHIP_NUM_57840_MF_OBSOLETE
210 #ifndef PCI_DEVICE_ID_NX2_57840_MF
211 #define PCI_DEVICE_ID_NX2_57840_MF CHIP_NUM_57840_MF
213 #ifndef PCI_DEVICE_ID_NX2_57811
214 #define PCI_DEVICE_ID_NX2_57811 CHIP_NUM_57811
216 #ifndef PCI_DEVICE_ID_NX2_57811_MF
217 #define PCI_DEVICE_ID_NX2_57811_MF CHIP_NUM_57811_MF
219 static DEFINE_PCI_DEVICE_TABLE(bnx2x_pci_tbl) = {
220 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57710), BCM57710 },
221 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711), BCM57711 },
222 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711E), BCM57711E },
223 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712), BCM57712 },
224 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_MF), BCM57712_MF },
225 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800), BCM57800 },
226 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_MF), BCM57800_MF },
227 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810), BCM57810 },
228 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_MF), BCM57810_MF },
229 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_O), BCM57840_O },
230 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_4_10), BCM57840_4_10 },
231 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_2_20), BCM57840_2_20 },
232 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MFO), BCM57840_MFO },
233 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MF), BCM57840_MF },
234 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811), BCM57811 },
235 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811_MF), BCM57811_MF },
239 MODULE_DEVICE_TABLE(pci, bnx2x_pci_tbl);
241 /* Global resources for unloading a previously loaded device */
242 #define BNX2X_PREV_WAIT_NEEDED 1
243 static DEFINE_SEMAPHORE(bnx2x_prev_sem);
244 static LIST_HEAD(bnx2x_prev_list);
245 /****************************************************************************
246 * General service functions
247 ****************************************************************************/
249 static void __storm_memset_dma_mapping(struct bnx2x *bp,
250 u32 addr, dma_addr_t mapping)
252 REG_WR(bp, addr, U64_LO(mapping));
253 REG_WR(bp, addr + 4, U64_HI(mapping));
256 static void storm_memset_spq_addr(struct bnx2x *bp,
257 dma_addr_t mapping, u16 abs_fid)
259 u32 addr = XSEM_REG_FAST_MEMORY +
260 XSTORM_SPQ_PAGE_BASE_OFFSET(abs_fid);
262 __storm_memset_dma_mapping(bp, addr, mapping);
265 static void storm_memset_vf_to_pf(struct bnx2x *bp, u16 abs_fid,
268 REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_VF_TO_PF_OFFSET(abs_fid),
270 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_VF_TO_PF_OFFSET(abs_fid),
272 REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_VF_TO_PF_OFFSET(abs_fid),
274 REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_VF_TO_PF_OFFSET(abs_fid),
278 static void storm_memset_func_en(struct bnx2x *bp, u16 abs_fid,
281 REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(abs_fid),
283 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(abs_fid),
285 REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(abs_fid),
287 REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(abs_fid),
291 static void storm_memset_eq_data(struct bnx2x *bp,
292 struct event_ring_data *eq_data,
295 size_t size = sizeof(struct event_ring_data);
297 u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_DATA_OFFSET(pfid);
299 __storm_memset_struct(bp, addr, size, (u32 *)eq_data);
302 static void storm_memset_eq_prod(struct bnx2x *bp, u16 eq_prod,
305 u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_PROD_OFFSET(pfid);
306 REG_WR16(bp, addr, eq_prod);
310 * locking is done by mcp
312 static void bnx2x_reg_wr_ind(struct bnx2x *bp, u32 addr, u32 val)
314 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
315 pci_write_config_dword(bp->pdev, PCICFG_GRC_DATA, val);
316 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
317 PCICFG_VENDOR_ID_OFFSET);
320 static u32 bnx2x_reg_rd_ind(struct bnx2x *bp, u32 addr)
324 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
325 pci_read_config_dword(bp->pdev, PCICFG_GRC_DATA, &val);
326 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
327 PCICFG_VENDOR_ID_OFFSET);
332 #define DMAE_DP_SRC_GRC "grc src_addr [%08x]"
333 #define DMAE_DP_SRC_PCI "pci src_addr [%x:%08x]"
334 #define DMAE_DP_DST_GRC "grc dst_addr [%08x]"
335 #define DMAE_DP_DST_PCI "pci dst_addr [%x:%08x]"
336 #define DMAE_DP_DST_NONE "dst_addr [none]"
339 /* copy command into DMAE command memory and set DMAE command go */
340 void bnx2x_post_dmae(struct bnx2x *bp, struct dmae_command *dmae, int idx)
345 cmd_offset = (DMAE_REG_CMD_MEM + sizeof(struct dmae_command) * idx);
346 for (i = 0; i < (sizeof(struct dmae_command)/4); i++) {
347 REG_WR(bp, cmd_offset + i*4, *(((u32 *)dmae) + i));
349 REG_WR(bp, dmae_reg_go_c[idx], 1);
352 u32 bnx2x_dmae_opcode_add_comp(u32 opcode, u8 comp_type)
354 return opcode | ((comp_type << DMAE_COMMAND_C_DST_SHIFT) |
358 u32 bnx2x_dmae_opcode_clr_src_reset(u32 opcode)
360 return opcode & ~DMAE_CMD_SRC_RESET;
363 u32 bnx2x_dmae_opcode(struct bnx2x *bp, u8 src_type, u8 dst_type,
364 bool with_comp, u8 comp_type)
368 opcode |= ((src_type << DMAE_COMMAND_SRC_SHIFT) |
369 (dst_type << DMAE_COMMAND_DST_SHIFT));
371 opcode |= (DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET);
373 opcode |= (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0);
374 opcode |= ((BP_VN(bp) << DMAE_CMD_E1HVN_SHIFT) |
375 (BP_VN(bp) << DMAE_COMMAND_DST_VN_SHIFT));
376 opcode |= (DMAE_COM_SET_ERR << DMAE_COMMAND_ERR_POLICY_SHIFT);
379 opcode |= DMAE_CMD_ENDIANITY_B_DW_SWAP;
381 opcode |= DMAE_CMD_ENDIANITY_DW_SWAP;
384 opcode = bnx2x_dmae_opcode_add_comp(opcode, comp_type);
388 static void bnx2x_prep_dmae_with_comp(struct bnx2x *bp,
389 struct dmae_command *dmae,
390 u8 src_type, u8 dst_type)
392 memset(dmae, 0, sizeof(struct dmae_command));
395 dmae->opcode = bnx2x_dmae_opcode(bp, src_type, dst_type,
396 true, DMAE_COMP_PCI);
398 /* fill in the completion parameters */
399 dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_comp));
400 dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_comp));
401 dmae->comp_val = DMAE_COMP_VAL;
404 /* issue a dmae command over the init-channel and wailt for completion */
405 static int bnx2x_issue_dmae_with_comp(struct bnx2x *bp,
406 struct dmae_command *dmae)
408 u32 *wb_comp = bnx2x_sp(bp, wb_comp);
409 int cnt = CHIP_REV_IS_SLOW(bp) ? (400000) : 4000;
413 * Lock the dmae channel. Disable BHs to prevent a dead-lock
414 * as long as this code is called both from syscall context and
415 * from ndo_set_rx_mode() flow that may be called from BH.
417 spin_lock_bh(&bp->dmae_lock);
419 /* reset completion */
422 /* post the command on the channel used for initializations */
423 bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp));
425 /* wait for completion */
427 while ((*wb_comp & ~DMAE_PCI_ERR_FLAG) != DMAE_COMP_VAL) {
430 (bp->recovery_state != BNX2X_RECOVERY_DONE &&
431 bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
432 BNX2X_ERR("DMAE timeout!\n");
439 if (*wb_comp & DMAE_PCI_ERR_FLAG) {
440 BNX2X_ERR("DMAE PCI error!\n");
445 spin_unlock_bh(&bp->dmae_lock);
449 void bnx2x_write_dmae(struct bnx2x *bp, dma_addr_t dma_addr, u32 dst_addr,
452 struct dmae_command dmae;
454 if (!bp->dmae_ready) {
455 u32 *data = bnx2x_sp(bp, wb_data[0]);
458 bnx2x_init_ind_wr(bp, dst_addr, data, len32);
460 bnx2x_init_str_wr(bp, dst_addr, data, len32);
464 /* set opcode and fixed command fields */
465 bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_GRC);
467 /* fill in addresses and len */
468 dmae.src_addr_lo = U64_LO(dma_addr);
469 dmae.src_addr_hi = U64_HI(dma_addr);
470 dmae.dst_addr_lo = dst_addr >> 2;
471 dmae.dst_addr_hi = 0;
474 /* issue the command and wait for completion */
475 bnx2x_issue_dmae_with_comp(bp, &dmae);
478 void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32)
480 struct dmae_command dmae;
482 if (!bp->dmae_ready) {
483 u32 *data = bnx2x_sp(bp, wb_data[0]);
487 for (i = 0; i < len32; i++)
488 data[i] = bnx2x_reg_rd_ind(bp, src_addr + i*4);
490 for (i = 0; i < len32; i++)
491 data[i] = REG_RD(bp, src_addr + i*4);
496 /* set opcode and fixed command fields */
497 bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_GRC, DMAE_DST_PCI);
499 /* fill in addresses and len */
500 dmae.src_addr_lo = src_addr >> 2;
501 dmae.src_addr_hi = 0;
502 dmae.dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_data));
503 dmae.dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_data));
506 /* issue the command and wait for completion */
507 bnx2x_issue_dmae_with_comp(bp, &dmae);
510 static void bnx2x_write_dmae_phys_len(struct bnx2x *bp, dma_addr_t phys_addr,
513 int dmae_wr_max = DMAE_LEN32_WR_MAX(bp);
516 while (len > dmae_wr_max) {
517 bnx2x_write_dmae(bp, phys_addr + offset,
518 addr + offset, dmae_wr_max);
519 offset += dmae_wr_max * 4;
523 bnx2x_write_dmae(bp, phys_addr + offset, addr + offset, len);
526 static int bnx2x_mc_assert(struct bnx2x *bp)
530 u32 row0, row1, row2, row3;
533 last_idx = REG_RD8(bp, BAR_XSTRORM_INTMEM +
534 XSTORM_ASSERT_LIST_INDEX_OFFSET);
536 BNX2X_ERR("XSTORM_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_XSTRORM_INTMEM +
542 XSTORM_ASSERT_LIST_OFFSET(i));
543 row1 = REG_RD(bp, BAR_XSTRORM_INTMEM +
544 XSTORM_ASSERT_LIST_OFFSET(i) + 4);
545 row2 = REG_RD(bp, BAR_XSTRORM_INTMEM +
546 XSTORM_ASSERT_LIST_OFFSET(i) + 8);
547 row3 = REG_RD(bp, BAR_XSTRORM_INTMEM +
548 XSTORM_ASSERT_LIST_OFFSET(i) + 12);
550 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
551 BNX2X_ERR("XSTORM_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_TSTRORM_INTMEM +
561 TSTORM_ASSERT_LIST_INDEX_OFFSET);
563 BNX2X_ERR("TSTORM_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_TSTRORM_INTMEM +
569 TSTORM_ASSERT_LIST_OFFSET(i));
570 row1 = REG_RD(bp, BAR_TSTRORM_INTMEM +
571 TSTORM_ASSERT_LIST_OFFSET(i) + 4);
572 row2 = REG_RD(bp, BAR_TSTRORM_INTMEM +
573 TSTORM_ASSERT_LIST_OFFSET(i) + 8);
574 row3 = REG_RD(bp, BAR_TSTRORM_INTMEM +
575 TSTORM_ASSERT_LIST_OFFSET(i) + 12);
577 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
578 BNX2X_ERR("TSTORM_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_CSTRORM_INTMEM +
588 CSTORM_ASSERT_LIST_INDEX_OFFSET);
590 BNX2X_ERR("CSTORM_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_CSTRORM_INTMEM +
596 CSTORM_ASSERT_LIST_OFFSET(i));
597 row1 = REG_RD(bp, BAR_CSTRORM_INTMEM +
598 CSTORM_ASSERT_LIST_OFFSET(i) + 4);
599 row2 = REG_RD(bp, BAR_CSTRORM_INTMEM +
600 CSTORM_ASSERT_LIST_OFFSET(i) + 8);
601 row3 = REG_RD(bp, BAR_CSTRORM_INTMEM +
602 CSTORM_ASSERT_LIST_OFFSET(i) + 12);
604 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
605 BNX2X_ERR("CSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
606 i, row3, row2, row1, row0);
614 last_idx = REG_RD8(bp, BAR_USTRORM_INTMEM +
615 USTORM_ASSERT_LIST_INDEX_OFFSET);
617 BNX2X_ERR("USTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
619 /* print the asserts */
620 for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
622 row0 = REG_RD(bp, BAR_USTRORM_INTMEM +
623 USTORM_ASSERT_LIST_OFFSET(i));
624 row1 = REG_RD(bp, BAR_USTRORM_INTMEM +
625 USTORM_ASSERT_LIST_OFFSET(i) + 4);
626 row2 = REG_RD(bp, BAR_USTRORM_INTMEM +
627 USTORM_ASSERT_LIST_OFFSET(i) + 8);
628 row3 = REG_RD(bp, BAR_USTRORM_INTMEM +
629 USTORM_ASSERT_LIST_OFFSET(i) + 12);
631 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
632 BNX2X_ERR("USTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
633 i, row3, row2, row1, row0);
643 void bnx2x_fw_dump_lvl(struct bnx2x *bp, const char *lvl)
649 u32 trace_shmem_base;
651 BNX2X_ERR("NO MCP - can not dump\n");
654 netdev_printk(lvl, bp->dev, "bc %d.%d.%d\n",
655 (bp->common.bc_ver & 0xff0000) >> 16,
656 (bp->common.bc_ver & 0xff00) >> 8,
657 (bp->common.bc_ver & 0xff));
659 val = REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER);
660 if (val == REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER))
661 BNX2X_ERR("%s" "MCP PC at 0x%x\n", lvl, val);
663 if (BP_PATH(bp) == 0)
664 trace_shmem_base = bp->common.shmem_base;
666 trace_shmem_base = SHMEM2_RD(bp, other_shmem_base_addr);
667 addr = trace_shmem_base - 0x800;
669 /* validate TRCB signature */
670 mark = REG_RD(bp, addr);
671 if (mark != MFW_TRACE_SIGNATURE) {
672 BNX2X_ERR("Trace buffer signature is missing.");
676 /* read cyclic buffer pointer */
678 mark = REG_RD(bp, addr);
679 mark = (CHIP_IS_E1x(bp) ? MCP_REG_MCPR_SCRATCH : MCP_A_REG_MCPR_SCRATCH)
680 + ((mark + 0x3) & ~0x3) - 0x08000000;
681 printk("%s" "begin fw dump (mark 0x%x)\n", lvl, mark);
684 for (offset = mark; offset <= trace_shmem_base; offset += 0x8*4) {
685 for (word = 0; word < 8; word++)
686 data[word] = htonl(REG_RD(bp, offset + 4*word));
688 pr_cont("%s", (char *)data);
690 for (offset = addr + 4; offset <= mark; offset += 0x8*4) {
691 for (word = 0; word < 8; word++)
692 data[word] = htonl(REG_RD(bp, offset + 4*word));
694 pr_cont("%s", (char *)data);
696 printk("%s" "end of fw dump\n", lvl);
699 static void bnx2x_fw_dump(struct bnx2x *bp)
701 bnx2x_fw_dump_lvl(bp, KERN_ERR);
704 void bnx2x_panic_dump(struct bnx2x *bp)
708 struct hc_sp_status_block_data sp_sb_data;
709 int func = BP_FUNC(bp);
710 #ifdef BNX2X_STOP_ON_ERROR
711 u16 start = 0, end = 0;
715 bp->stats_state = STATS_STATE_DISABLED;
716 bp->eth_stats.unrecoverable_error++;
717 DP(BNX2X_MSG_STATS, "stats_state - DISABLED\n");
719 BNX2X_ERR("begin crash dump -----------------\n");
723 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",
724 bp->def_idx, bp->def_att_idx, bp->attn_state,
725 bp->spq_prod_idx, bp->stats_counter);
726 BNX2X_ERR("DSB: attn bits(0x%x) ack(0x%x) id(0x%x) idx(0x%x)\n",
727 bp->def_status_blk->atten_status_block.attn_bits,
728 bp->def_status_blk->atten_status_block.attn_bits_ack,
729 bp->def_status_blk->atten_status_block.status_block_id,
730 bp->def_status_blk->atten_status_block.attn_bits_index);
732 for (i = 0; i < HC_SP_SB_MAX_INDICES; i++)
734 bp->def_status_blk->sp_sb.index_values[i],
735 (i == HC_SP_SB_MAX_INDICES - 1) ? ") " : " ");
737 for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
738 *((u32 *)&sp_sb_data + i) = REG_RD(bp, BAR_CSTRORM_INTMEM +
739 CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
742 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",
743 sp_sb_data.igu_sb_id,
744 sp_sb_data.igu_seg_id,
745 sp_sb_data.p_func.pf_id,
746 sp_sb_data.p_func.vnic_id,
747 sp_sb_data.p_func.vf_id,
748 sp_sb_data.p_func.vf_valid,
752 for_each_eth_queue(bp, i) {
753 struct bnx2x_fastpath *fp = &bp->fp[i];
755 struct hc_status_block_data_e2 sb_data_e2;
756 struct hc_status_block_data_e1x sb_data_e1x;
757 struct hc_status_block_sm *hc_sm_p =
759 sb_data_e1x.common.state_machine :
760 sb_data_e2.common.state_machine;
761 struct hc_index_data *hc_index_p =
763 sb_data_e1x.index_data :
764 sb_data_e2.index_data;
767 struct bnx2x_fp_txdata txdata;
770 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",
771 i, fp->rx_bd_prod, fp->rx_bd_cons,
773 fp->rx_comp_cons, le16_to_cpu(*fp->rx_cons_sb));
774 BNX2X_ERR(" rx_sge_prod(0x%x) last_max_sge(0x%x) fp_hc_idx(0x%x)\n",
775 fp->rx_sge_prod, fp->last_max_sge,
776 le16_to_cpu(fp->fp_hc_idx));
779 for_each_cos_in_tx_queue(fp, cos)
781 txdata = *fp->txdata_ptr[cos];
782 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",
783 i, txdata.tx_pkt_prod,
784 txdata.tx_pkt_cons, txdata.tx_bd_prod,
786 le16_to_cpu(*txdata.tx_cons_sb));
789 loop = CHIP_IS_E1x(bp) ?
790 HC_SB_MAX_INDICES_E1X : HC_SB_MAX_INDICES_E2;
798 BNX2X_ERR(" run indexes (");
799 for (j = 0; j < HC_SB_MAX_SM; j++)
801 fp->sb_running_index[j],
802 (j == HC_SB_MAX_SM - 1) ? ")" : " ");
804 BNX2X_ERR(" indexes (");
805 for (j = 0; j < loop; j++)
807 fp->sb_index_values[j],
808 (j == loop - 1) ? ")" : " ");
810 data_size = CHIP_IS_E1x(bp) ?
811 sizeof(struct hc_status_block_data_e1x) :
812 sizeof(struct hc_status_block_data_e2);
813 data_size /= sizeof(u32);
814 sb_data_p = CHIP_IS_E1x(bp) ?
815 (u32 *)&sb_data_e1x :
817 /* copy sb data in here */
818 for (j = 0; j < data_size; j++)
819 *(sb_data_p + j) = REG_RD(bp, BAR_CSTRORM_INTMEM +
820 CSTORM_STATUS_BLOCK_DATA_OFFSET(fp->fw_sb_id) +
823 if (!CHIP_IS_E1x(bp)) {
824 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",
825 sb_data_e2.common.p_func.pf_id,
826 sb_data_e2.common.p_func.vf_id,
827 sb_data_e2.common.p_func.vf_valid,
828 sb_data_e2.common.p_func.vnic_id,
829 sb_data_e2.common.same_igu_sb_1b,
830 sb_data_e2.common.state);
832 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",
833 sb_data_e1x.common.p_func.pf_id,
834 sb_data_e1x.common.p_func.vf_id,
835 sb_data_e1x.common.p_func.vf_valid,
836 sb_data_e1x.common.p_func.vnic_id,
837 sb_data_e1x.common.same_igu_sb_1b,
838 sb_data_e1x.common.state);
842 for (j = 0; j < HC_SB_MAX_SM; j++) {
843 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",
844 j, hc_sm_p[j].__flags,
845 hc_sm_p[j].igu_sb_id,
846 hc_sm_p[j].igu_seg_id,
847 hc_sm_p[j].time_to_expire,
848 hc_sm_p[j].timer_value);
852 for (j = 0; j < loop; j++) {
853 pr_cont("INDEX[%d] flags (0x%x) timeout (0x%x)\n", j,
855 hc_index_p[j].timeout);
859 #ifdef BNX2X_STOP_ON_ERROR
862 for_each_rx_queue(bp, i) {
863 struct bnx2x_fastpath *fp = &bp->fp[i];
865 start = RX_BD(le16_to_cpu(*fp->rx_cons_sb) - 10);
866 end = RX_BD(le16_to_cpu(*fp->rx_cons_sb) + 503);
867 for (j = start; j != end; j = RX_BD(j + 1)) {
868 u32 *rx_bd = (u32 *)&fp->rx_desc_ring[j];
869 struct sw_rx_bd *sw_bd = &fp->rx_buf_ring[j];
871 BNX2X_ERR("fp%d: rx_bd[%x]=[%x:%x] sw_bd=[%p]\n",
872 i, j, rx_bd[1], rx_bd[0], sw_bd->data);
875 start = RX_SGE(fp->rx_sge_prod);
876 end = RX_SGE(fp->last_max_sge);
877 for (j = start; j != end; j = RX_SGE(j + 1)) {
878 u32 *rx_sge = (u32 *)&fp->rx_sge_ring[j];
879 struct sw_rx_page *sw_page = &fp->rx_page_ring[j];
881 BNX2X_ERR("fp%d: rx_sge[%x]=[%x:%x] sw_page=[%p]\n",
882 i, j, rx_sge[1], rx_sge[0], sw_page->page);
885 start = RCQ_BD(fp->rx_comp_cons - 10);
886 end = RCQ_BD(fp->rx_comp_cons + 503);
887 for (j = start; j != end; j = RCQ_BD(j + 1)) {
888 u32 *cqe = (u32 *)&fp->rx_comp_ring[j];
890 BNX2X_ERR("fp%d: cqe[%x]=[%x:%x:%x:%x]\n",
891 i, j, cqe[0], cqe[1], cqe[2], cqe[3]);
896 for_each_tx_queue(bp, i) {
897 struct bnx2x_fastpath *fp = &bp->fp[i];
898 for_each_cos_in_tx_queue(fp, cos) {
899 struct bnx2x_fp_txdata *txdata = fp->txdata_ptr[cos];
901 start = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) - 10);
902 end = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) + 245);
903 for (j = start; j != end; j = TX_BD(j + 1)) {
904 struct sw_tx_bd *sw_bd =
905 &txdata->tx_buf_ring[j];
907 BNX2X_ERR("fp%d: txdata %d, packet[%x]=[%p,%x]\n",
908 i, cos, j, sw_bd->skb,
912 start = TX_BD(txdata->tx_bd_cons - 10);
913 end = TX_BD(txdata->tx_bd_cons + 254);
914 for (j = start; j != end; j = TX_BD(j + 1)) {
915 u32 *tx_bd = (u32 *)&txdata->tx_desc_ring[j];
917 BNX2X_ERR("fp%d: txdata %d, tx_bd[%x]=[%x:%x:%x:%x]\n",
918 i, cos, j, tx_bd[0], tx_bd[1],
926 BNX2X_ERR("end crash dump -----------------\n");
932 * bnx2x_pf_flr_clnup() is called during nic_load in the per function HW
935 #define FLR_WAIT_USEC 10000 /* 10 miliseconds */
936 #define FLR_WAIT_INTERVAL 50 /* usec */
937 #define FLR_POLL_CNT (FLR_WAIT_USEC/FLR_WAIT_INTERVAL) /* 200 */
939 struct pbf_pN_buf_regs {
946 struct pbf_pN_cmd_regs {
952 static void bnx2x_pbf_pN_buf_flushed(struct bnx2x *bp,
953 struct pbf_pN_buf_regs *regs,
956 u32 init_crd, crd, crd_start, crd_freed, crd_freed_start;
957 u32 cur_cnt = poll_count;
959 crd_freed = crd_freed_start = REG_RD(bp, regs->crd_freed);
960 crd = crd_start = REG_RD(bp, regs->crd);
961 init_crd = REG_RD(bp, regs->init_crd);
963 DP(BNX2X_MSG_SP, "INIT CREDIT[%d] : %x\n", regs->pN, init_crd);
964 DP(BNX2X_MSG_SP, "CREDIT[%d] : s:%x\n", regs->pN, crd);
965 DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: s:%x\n", regs->pN, crd_freed);
967 while ((crd != init_crd) && ((u32)SUB_S32(crd_freed, crd_freed_start) <
968 (init_crd - crd_start))) {
970 udelay(FLR_WAIT_INTERVAL);
971 crd = REG_RD(bp, regs->crd);
972 crd_freed = REG_RD(bp, regs->crd_freed);
974 DP(BNX2X_MSG_SP, "PBF tx buffer[%d] timed out\n",
976 DP(BNX2X_MSG_SP, "CREDIT[%d] : c:%x\n",
978 DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: c:%x\n",
979 regs->pN, crd_freed);
983 DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF tx buffer[%d]\n",
984 poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
987 static void bnx2x_pbf_pN_cmd_flushed(struct bnx2x *bp,
988 struct pbf_pN_cmd_regs *regs,
991 u32 occup, to_free, freed, freed_start;
992 u32 cur_cnt = poll_count;
994 occup = to_free = REG_RD(bp, regs->lines_occup);
995 freed = freed_start = REG_RD(bp, regs->lines_freed);
997 DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n", regs->pN, occup);
998 DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n", regs->pN, freed);
1000 while (occup && ((u32)SUB_S32(freed, freed_start) < to_free)) {
1002 udelay(FLR_WAIT_INTERVAL);
1003 occup = REG_RD(bp, regs->lines_occup);
1004 freed = REG_RD(bp, regs->lines_freed);
1006 DP(BNX2X_MSG_SP, "PBF cmd queue[%d] timed out\n",
1008 DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n",
1010 DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n",
1015 DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF cmd queue[%d]\n",
1016 poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
1019 static u32 bnx2x_flr_clnup_reg_poll(struct bnx2x *bp, u32 reg,
1020 u32 expected, u32 poll_count)
1022 u32 cur_cnt = poll_count;
1025 while ((val = REG_RD(bp, reg)) != expected && cur_cnt--)
1026 udelay(FLR_WAIT_INTERVAL);
1031 static int bnx2x_flr_clnup_poll_hw_counter(struct bnx2x *bp, u32 reg,
1032 char *msg, u32 poll_cnt)
1034 u32 val = bnx2x_flr_clnup_reg_poll(bp, reg, 0, poll_cnt);
1036 BNX2X_ERR("%s usage count=%d\n", msg, val);
1042 static u32 bnx2x_flr_clnup_poll_count(struct bnx2x *bp)
1044 /* adjust polling timeout */
1045 if (CHIP_REV_IS_EMUL(bp))
1046 return FLR_POLL_CNT * 2000;
1048 if (CHIP_REV_IS_FPGA(bp))
1049 return FLR_POLL_CNT * 120;
1051 return FLR_POLL_CNT;
1054 static void bnx2x_tx_hw_flushed(struct bnx2x *bp, u32 poll_count)
1056 struct pbf_pN_cmd_regs cmd_regs[] = {
1057 {0, (CHIP_IS_E3B0(bp)) ?
1058 PBF_REG_TQ_OCCUPANCY_Q0 :
1059 PBF_REG_P0_TQ_OCCUPANCY,
1060 (CHIP_IS_E3B0(bp)) ?
1061 PBF_REG_TQ_LINES_FREED_CNT_Q0 :
1062 PBF_REG_P0_TQ_LINES_FREED_CNT},
1063 {1, (CHIP_IS_E3B0(bp)) ?
1064 PBF_REG_TQ_OCCUPANCY_Q1 :
1065 PBF_REG_P1_TQ_OCCUPANCY,
1066 (CHIP_IS_E3B0(bp)) ?
1067 PBF_REG_TQ_LINES_FREED_CNT_Q1 :
1068 PBF_REG_P1_TQ_LINES_FREED_CNT},
1069 {4, (CHIP_IS_E3B0(bp)) ?
1070 PBF_REG_TQ_OCCUPANCY_LB_Q :
1071 PBF_REG_P4_TQ_OCCUPANCY,
1072 (CHIP_IS_E3B0(bp)) ?
1073 PBF_REG_TQ_LINES_FREED_CNT_LB_Q :
1074 PBF_REG_P4_TQ_LINES_FREED_CNT}
1077 struct pbf_pN_buf_regs buf_regs[] = {
1078 {0, (CHIP_IS_E3B0(bp)) ?
1079 PBF_REG_INIT_CRD_Q0 :
1080 PBF_REG_P0_INIT_CRD ,
1081 (CHIP_IS_E3B0(bp)) ?
1084 (CHIP_IS_E3B0(bp)) ?
1085 PBF_REG_INTERNAL_CRD_FREED_CNT_Q0 :
1086 PBF_REG_P0_INTERNAL_CRD_FREED_CNT},
1087 {1, (CHIP_IS_E3B0(bp)) ?
1088 PBF_REG_INIT_CRD_Q1 :
1089 PBF_REG_P1_INIT_CRD,
1090 (CHIP_IS_E3B0(bp)) ?
1093 (CHIP_IS_E3B0(bp)) ?
1094 PBF_REG_INTERNAL_CRD_FREED_CNT_Q1 :
1095 PBF_REG_P1_INTERNAL_CRD_FREED_CNT},
1096 {4, (CHIP_IS_E3B0(bp)) ?
1097 PBF_REG_INIT_CRD_LB_Q :
1098 PBF_REG_P4_INIT_CRD,
1099 (CHIP_IS_E3B0(bp)) ?
1100 PBF_REG_CREDIT_LB_Q :
1102 (CHIP_IS_E3B0(bp)) ?
1103 PBF_REG_INTERNAL_CRD_FREED_CNT_LB_Q :
1104 PBF_REG_P4_INTERNAL_CRD_FREED_CNT},
1109 /* Verify the command queues are flushed P0, P1, P4 */
1110 for (i = 0; i < ARRAY_SIZE(cmd_regs); i++)
1111 bnx2x_pbf_pN_cmd_flushed(bp, &cmd_regs[i], poll_count);
1114 /* Verify the transmission buffers are flushed P0, P1, P4 */
1115 for (i = 0; i < ARRAY_SIZE(buf_regs); i++)
1116 bnx2x_pbf_pN_buf_flushed(bp, &buf_regs[i], poll_count);
1119 #define OP_GEN_PARAM(param) \
1120 (((param) << SDM_OP_GEN_COMP_PARAM_SHIFT) & SDM_OP_GEN_COMP_PARAM)
1122 #define OP_GEN_TYPE(type) \
1123 (((type) << SDM_OP_GEN_COMP_TYPE_SHIFT) & SDM_OP_GEN_COMP_TYPE)
1125 #define OP_GEN_AGG_VECT(index) \
1126 (((index) << SDM_OP_GEN_AGG_VECT_IDX_SHIFT) & SDM_OP_GEN_AGG_VECT_IDX)
1129 static int bnx2x_send_final_clnup(struct bnx2x *bp, u8 clnup_func,
1132 struct sdm_op_gen op_gen = {0};
1134 u32 comp_addr = BAR_CSTRORM_INTMEM +
1135 CSTORM_FINAL_CLEANUP_COMPLETE_OFFSET(clnup_func);
1138 if (REG_RD(bp, comp_addr)) {
1139 BNX2X_ERR("Cleanup complete was not 0 before sending\n");
1143 op_gen.command |= OP_GEN_PARAM(XSTORM_AGG_INT_FINAL_CLEANUP_INDEX);
1144 op_gen.command |= OP_GEN_TYPE(XSTORM_AGG_INT_FINAL_CLEANUP_COMP_TYPE);
1145 op_gen.command |= OP_GEN_AGG_VECT(clnup_func);
1146 op_gen.command |= 1 << SDM_OP_GEN_AGG_VECT_IDX_VALID_SHIFT;
1148 DP(BNX2X_MSG_SP, "sending FW Final cleanup\n");
1149 REG_WR(bp, XSDM_REG_OPERATION_GEN, op_gen.command);
1151 if (bnx2x_flr_clnup_reg_poll(bp, comp_addr, 1, poll_cnt) != 1) {
1152 BNX2X_ERR("FW final cleanup did not succeed\n");
1153 DP(BNX2X_MSG_SP, "At timeout completion address contained %x\n",
1154 (REG_RD(bp, comp_addr)));
1157 /* Zero completion for nxt FLR */
1158 REG_WR(bp, comp_addr, 0);
1163 static u8 bnx2x_is_pcie_pending(struct pci_dev *dev)
1167 pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &status);
1168 return status & PCI_EXP_DEVSTA_TRPND;
1171 /* PF FLR specific routines
1173 static int bnx2x_poll_hw_usage_counters(struct bnx2x *bp, u32 poll_cnt)
1176 /* wait for CFC PF usage-counter to zero (includes all the VFs) */
1177 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1178 CFC_REG_NUM_LCIDS_INSIDE_PF,
1179 "CFC PF usage counter timed out",
1184 /* Wait for DQ PF usage-counter to zero (until DQ cleanup) */
1185 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1186 DORQ_REG_PF_USAGE_CNT,
1187 "DQ PF usage counter timed out",
1191 /* Wait for QM PF usage-counter to zero (until DQ cleanup) */
1192 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1193 QM_REG_PF_USG_CNT_0 + 4*BP_FUNC(bp),
1194 "QM PF usage counter timed out",
1198 /* Wait for Timer PF usage-counters to zero (until DQ cleanup) */
1199 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1200 TM_REG_LIN0_VNIC_UC + 4*BP_PORT(bp),
1201 "Timers VNIC usage counter timed out",
1204 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1205 TM_REG_LIN0_NUM_SCANS + 4*BP_PORT(bp),
1206 "Timers NUM_SCANS usage counter timed out",
1210 /* Wait DMAE PF usage counter to zero */
1211 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1212 dmae_reg_go_c[INIT_DMAE_C(bp)],
1213 "DMAE dommand register timed out",
1220 static void bnx2x_hw_enable_status(struct bnx2x *bp)
1224 val = REG_RD(bp, CFC_REG_WEAK_ENABLE_PF);
1225 DP(BNX2X_MSG_SP, "CFC_REG_WEAK_ENABLE_PF is 0x%x\n", val);
1227 val = REG_RD(bp, PBF_REG_DISABLE_PF);
1228 DP(BNX2X_MSG_SP, "PBF_REG_DISABLE_PF is 0x%x\n", val);
1230 val = REG_RD(bp, IGU_REG_PCI_PF_MSI_EN);
1231 DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSI_EN is 0x%x\n", val);
1233 val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_EN);
1234 DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_EN is 0x%x\n", val);
1236 val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_FUNC_MASK);
1237 DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_FUNC_MASK is 0x%x\n", val);
1239 val = REG_RD(bp, PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR);
1240 DP(BNX2X_MSG_SP, "PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR is 0x%x\n", val);
1242 val = REG_RD(bp, PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR);
1243 DP(BNX2X_MSG_SP, "PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR is 0x%x\n", val);
1245 val = REG_RD(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER);
1246 DP(BNX2X_MSG_SP, "PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER is 0x%x\n",
1250 static int bnx2x_pf_flr_clnup(struct bnx2x *bp)
1252 u32 poll_cnt = bnx2x_flr_clnup_poll_count(bp);
1254 DP(BNX2X_MSG_SP, "Cleanup after FLR PF[%d]\n", BP_ABS_FUNC(bp));
1256 /* Re-enable PF target read access */
1257 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
1259 /* Poll HW usage counters */
1260 DP(BNX2X_MSG_SP, "Polling usage counters\n");
1261 if (bnx2x_poll_hw_usage_counters(bp, poll_cnt))
1264 /* Zero the igu 'trailing edge' and 'leading edge' */
1266 /* Send the FW cleanup command */
1267 if (bnx2x_send_final_clnup(bp, (u8)BP_FUNC(bp), poll_cnt))
1272 /* Verify TX hw is flushed */
1273 bnx2x_tx_hw_flushed(bp, poll_cnt);
1275 /* Wait 100ms (not adjusted according to platform) */
1278 /* Verify no pending pci transactions */
1279 if (bnx2x_is_pcie_pending(bp->pdev))
1280 BNX2X_ERR("PCIE Transactions still pending\n");
1283 bnx2x_hw_enable_status(bp);
1286 * Master enable - Due to WB DMAE writes performed before this
1287 * register is re-initialized as part of the regular function init
1289 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
1294 static void bnx2x_hc_int_enable(struct bnx2x *bp)
1296 int port = BP_PORT(bp);
1297 u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
1298 u32 val = REG_RD(bp, addr);
1299 bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
1300 bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
1301 bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
1304 val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
1305 HC_CONFIG_0_REG_INT_LINE_EN_0);
1306 val |= (HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
1307 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
1309 val |= HC_CONFIG_0_REG_SINGLE_ISR_EN_0;
1311 val &= ~HC_CONFIG_0_REG_INT_LINE_EN_0;
1312 val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
1313 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
1314 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
1316 val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
1317 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
1318 HC_CONFIG_0_REG_INT_LINE_EN_0 |
1319 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
1321 if (!CHIP_IS_E1(bp)) {
1323 "write %x to HC %d (addr 0x%x)\n", val, port, addr);
1325 REG_WR(bp, addr, val);
1327 val &= ~HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0;
1332 REG_WR(bp, HC_REG_INT_MASK + port*4, 0x1FFFF);
1335 "write %x to HC %d (addr 0x%x) mode %s\n", val, port, addr,
1336 (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
1338 REG_WR(bp, addr, val);
1340 * Ensure that HC_CONFIG is written before leading/trailing edge config
1345 if (!CHIP_IS_E1(bp)) {
1346 /* init leading/trailing edge */
1348 val = (0xee0f | (1 << (BP_VN(bp) + 4)));
1350 /* enable nig and gpio3 attention */
1355 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
1356 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
1359 /* Make sure that interrupts are indeed enabled from here on */
1363 static void bnx2x_igu_int_enable(struct bnx2x *bp)
1366 bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
1367 bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
1368 bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
1370 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
1373 val &= ~(IGU_PF_CONF_INT_LINE_EN |
1374 IGU_PF_CONF_SINGLE_ISR_EN);
1375 val |= (IGU_PF_CONF_FUNC_EN |
1376 IGU_PF_CONF_MSI_MSIX_EN |
1377 IGU_PF_CONF_ATTN_BIT_EN);
1380 val |= IGU_PF_CONF_SINGLE_ISR_EN;
1382 val &= ~IGU_PF_CONF_INT_LINE_EN;
1383 val |= (IGU_PF_CONF_FUNC_EN |
1384 IGU_PF_CONF_MSI_MSIX_EN |
1385 IGU_PF_CONF_ATTN_BIT_EN |
1386 IGU_PF_CONF_SINGLE_ISR_EN);
1388 val &= ~IGU_PF_CONF_MSI_MSIX_EN;
1389 val |= (IGU_PF_CONF_FUNC_EN |
1390 IGU_PF_CONF_INT_LINE_EN |
1391 IGU_PF_CONF_ATTN_BIT_EN |
1392 IGU_PF_CONF_SINGLE_ISR_EN);
1395 DP(NETIF_MSG_IFUP, "write 0x%x to IGU mode %s\n",
1396 val, (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
1398 REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
1400 if (val & IGU_PF_CONF_INT_LINE_EN)
1401 pci_intx(bp->pdev, true);
1405 /* init leading/trailing edge */
1407 val = (0xee0f | (1 << (BP_VN(bp) + 4)));
1409 /* enable nig and gpio3 attention */
1414 REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
1415 REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
1417 /* Make sure that interrupts are indeed enabled from here on */
1421 void bnx2x_int_enable(struct bnx2x *bp)
1423 if (bp->common.int_block == INT_BLOCK_HC)
1424 bnx2x_hc_int_enable(bp);
1426 bnx2x_igu_int_enable(bp);
1429 static void bnx2x_hc_int_disable(struct bnx2x *bp)
1431 int port = BP_PORT(bp);
1432 u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
1433 u32 val = REG_RD(bp, addr);
1436 * in E1 we must use only PCI configuration space to disable
1437 * MSI/MSIX capablility
1438 * It's forbitten to disable IGU_PF_CONF_MSI_MSIX_EN in HC block
1440 if (CHIP_IS_E1(bp)) {
1441 /* Since IGU_PF_CONF_MSI_MSIX_EN still always on
1442 * Use mask register to prevent from HC sending interrupts
1443 * after we exit the function
1445 REG_WR(bp, HC_REG_INT_MASK + port*4, 0);
1447 val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
1448 HC_CONFIG_0_REG_INT_LINE_EN_0 |
1449 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
1451 val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
1452 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
1453 HC_CONFIG_0_REG_INT_LINE_EN_0 |
1454 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
1456 DP(NETIF_MSG_IFDOWN,
1457 "write %x to HC %d (addr 0x%x)\n",
1460 /* flush all outstanding writes */
1463 REG_WR(bp, addr, val);
1464 if (REG_RD(bp, addr) != val)
1465 BNX2X_ERR("BUG! proper val not read from IGU!\n");
1468 static void bnx2x_igu_int_disable(struct bnx2x *bp)
1470 u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
1472 val &= ~(IGU_PF_CONF_MSI_MSIX_EN |
1473 IGU_PF_CONF_INT_LINE_EN |
1474 IGU_PF_CONF_ATTN_BIT_EN);
1476 DP(NETIF_MSG_IFDOWN, "write %x to IGU\n", val);
1478 /* flush all outstanding writes */
1481 REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
1482 if (REG_RD(bp, IGU_REG_PF_CONFIGURATION) != val)
1483 BNX2X_ERR("BUG! proper val not read from IGU!\n");
1486 void bnx2x_int_disable(struct bnx2x *bp)
1488 if (bp->common.int_block == INT_BLOCK_HC)
1489 bnx2x_hc_int_disable(bp);
1491 bnx2x_igu_int_disable(bp);
1494 void bnx2x_int_disable_sync(struct bnx2x *bp, int disable_hw)
1496 int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
1500 /* prevent the HW from sending interrupts */
1501 bnx2x_int_disable(bp);
1503 /* make sure all ISRs are done */
1505 synchronize_irq(bp->msix_table[0].vector);
1510 for_each_eth_queue(bp, i)
1511 synchronize_irq(bp->msix_table[offset++].vector);
1513 synchronize_irq(bp->pdev->irq);
1515 /* make sure sp_task is not running */
1516 cancel_delayed_work(&bp->sp_task);
1517 cancel_delayed_work(&bp->period_task);
1518 flush_workqueue(bnx2x_wq);
1524 * General service functions
1527 /* Return true if succeeded to acquire the lock */
1528 static bool bnx2x_trylock_hw_lock(struct bnx2x *bp, u32 resource)
1531 u32 resource_bit = (1 << resource);
1532 int func = BP_FUNC(bp);
1533 u32 hw_lock_control_reg;
1535 DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
1536 "Trying to take a lock on resource %d\n", resource);
1538 /* Validating that the resource is within range */
1539 if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
1540 DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
1541 "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
1542 resource, HW_LOCK_MAX_RESOURCE_VALUE);
1547 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
1549 hw_lock_control_reg =
1550 (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
1552 /* Try to acquire the lock */
1553 REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
1554 lock_status = REG_RD(bp, hw_lock_control_reg);
1555 if (lock_status & resource_bit)
1558 DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
1559 "Failed to get a lock on resource %d\n", resource);
1564 * bnx2x_get_leader_lock_resource - get the recovery leader resource id
1566 * @bp: driver handle
1568 * Returns the recovery leader resource id according to the engine this function
1569 * belongs to. Currently only only 2 engines is supported.
1571 static int bnx2x_get_leader_lock_resource(struct bnx2x *bp)
1574 return HW_LOCK_RESOURCE_RECOVERY_LEADER_1;
1576 return HW_LOCK_RESOURCE_RECOVERY_LEADER_0;
1580 * bnx2x_trylock_leader_lock- try to aquire a leader lock.
1582 * @bp: driver handle
1584 * Tries to aquire a leader lock for current engine.
1586 static bool bnx2x_trylock_leader_lock(struct bnx2x *bp)
1588 return bnx2x_trylock_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
1592 static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err);
1595 void bnx2x_sp_event(struct bnx2x_fastpath *fp, union eth_rx_cqe *rr_cqe)
1597 struct bnx2x *bp = fp->bp;
1598 int cid = SW_CID(rr_cqe->ramrod_cqe.conn_and_cmd_data);
1599 int command = CQE_CMD(rr_cqe->ramrod_cqe.conn_and_cmd_data);
1600 enum bnx2x_queue_cmd drv_cmd = BNX2X_Q_CMD_MAX;
1601 struct bnx2x_queue_sp_obj *q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
1604 "fp %d cid %d got ramrod #%d state is %x type is %d\n",
1605 fp->index, cid, command, bp->state,
1606 rr_cqe->ramrod_cqe.ramrod_type);
1609 case (RAMROD_CMD_ID_ETH_CLIENT_UPDATE):
1610 DP(BNX2X_MSG_SP, "got UPDATE ramrod. CID %d\n", cid);
1611 drv_cmd = BNX2X_Q_CMD_UPDATE;
1614 case (RAMROD_CMD_ID_ETH_CLIENT_SETUP):
1615 DP(BNX2X_MSG_SP, "got MULTI[%d] setup ramrod\n", cid);
1616 drv_cmd = BNX2X_Q_CMD_SETUP;
1619 case (RAMROD_CMD_ID_ETH_TX_QUEUE_SETUP):
1620 DP(BNX2X_MSG_SP, "got MULTI[%d] tx-only setup ramrod\n", cid);
1621 drv_cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
1624 case (RAMROD_CMD_ID_ETH_HALT):
1625 DP(BNX2X_MSG_SP, "got MULTI[%d] halt ramrod\n", cid);
1626 drv_cmd = BNX2X_Q_CMD_HALT;
1629 case (RAMROD_CMD_ID_ETH_TERMINATE):
1630 DP(BNX2X_MSG_SP, "got MULTI[%d] teminate ramrod\n", cid);
1631 drv_cmd = BNX2X_Q_CMD_TERMINATE;
1634 case (RAMROD_CMD_ID_ETH_EMPTY):
1635 DP(BNX2X_MSG_SP, "got MULTI[%d] empty ramrod\n", cid);
1636 drv_cmd = BNX2X_Q_CMD_EMPTY;
1640 BNX2X_ERR("unexpected MC reply (%d) on fp[%d]\n",
1641 command, fp->index);
1645 if ((drv_cmd != BNX2X_Q_CMD_MAX) &&
1646 q_obj->complete_cmd(bp, q_obj, drv_cmd))
1647 /* q_obj->complete_cmd() failure means that this was
1648 * an unexpected completion.
1650 * In this case we don't want to increase the bp->spq_left
1651 * because apparently we haven't sent this command the first
1654 #ifdef BNX2X_STOP_ON_ERROR
1660 smp_mb__before_atomic_inc();
1661 atomic_inc(&bp->cq_spq_left);
1662 /* push the change in bp->spq_left and towards the memory */
1663 smp_mb__after_atomic_inc();
1665 DP(BNX2X_MSG_SP, "bp->cq_spq_left %x\n", atomic_read(&bp->cq_spq_left));
1667 if ((drv_cmd == BNX2X_Q_CMD_UPDATE) && (IS_FCOE_FP(fp)) &&
1668 (!!test_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state))) {
1669 /* if Q update ramrod is completed for last Q in AFEX vif set
1670 * flow, then ACK MCP at the end
1672 * mark pending ACK to MCP bit.
1673 * prevent case that both bits are cleared.
1674 * At the end of load/unload driver checks that
1675 * sp_state is cleaerd, and this order prevents
1678 smp_mb__before_clear_bit();
1679 set_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK, &bp->sp_state);
1681 clear_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
1682 smp_mb__after_clear_bit();
1684 /* schedule workqueue to send ack to MCP */
1685 queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
1691 void bnx2x_update_rx_prod(struct bnx2x *bp, struct bnx2x_fastpath *fp,
1692 u16 bd_prod, u16 rx_comp_prod, u16 rx_sge_prod)
1694 u32 start = BAR_USTRORM_INTMEM + fp->ustorm_rx_prods_offset;
1696 bnx2x_update_rx_prod_gen(bp, fp, bd_prod, rx_comp_prod, rx_sge_prod,
1700 irqreturn_t bnx2x_interrupt(int irq, void *dev_instance)
1702 struct bnx2x *bp = netdev_priv(dev_instance);
1703 u16 status = bnx2x_ack_int(bp);
1708 /* Return here if interrupt is shared and it's not for us */
1709 if (unlikely(status == 0)) {
1710 DP(NETIF_MSG_INTR, "not our interrupt!\n");
1713 DP(NETIF_MSG_INTR, "got an interrupt status 0x%x\n", status);
1715 #ifdef BNX2X_STOP_ON_ERROR
1716 if (unlikely(bp->panic))
1720 for_each_eth_queue(bp, i) {
1721 struct bnx2x_fastpath *fp = &bp->fp[i];
1723 mask = 0x2 << (fp->index + CNIC_PRESENT);
1724 if (status & mask) {
1725 /* Handle Rx or Tx according to SB id */
1726 prefetch(fp->rx_cons_sb);
1727 for_each_cos_in_tx_queue(fp, cos)
1728 prefetch(fp->txdata_ptr[cos]->tx_cons_sb);
1729 prefetch(&fp->sb_running_index[SM_RX_ID]);
1730 napi_schedule(&bnx2x_fp(bp, fp->index, napi));
1737 if (status & (mask | 0x1)) {
1738 struct cnic_ops *c_ops = NULL;
1740 if (likely(bp->state == BNX2X_STATE_OPEN)) {
1742 c_ops = rcu_dereference(bp->cnic_ops);
1744 c_ops->cnic_handler(bp->cnic_data, NULL);
1752 if (unlikely(status & 0x1)) {
1753 queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
1760 if (unlikely(status))
1761 DP(NETIF_MSG_INTR, "got an unknown interrupt! (status 0x%x)\n",
1770 * General service functions
1773 int bnx2x_acquire_hw_lock(struct bnx2x *bp, u32 resource)
1776 u32 resource_bit = (1 << resource);
1777 int func = BP_FUNC(bp);
1778 u32 hw_lock_control_reg;
1781 /* Validating that the resource is within range */
1782 if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
1783 BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
1784 resource, HW_LOCK_MAX_RESOURCE_VALUE);
1789 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
1791 hw_lock_control_reg =
1792 (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
1795 /* Validating that the resource is not already taken */
1796 lock_status = REG_RD(bp, hw_lock_control_reg);
1797 if (lock_status & resource_bit) {
1798 BNX2X_ERR("lock_status 0x%x resource_bit 0x%x\n",
1799 lock_status, resource_bit);
1803 /* Try for 5 second every 5ms */
1804 for (cnt = 0; cnt < 1000; cnt++) {
1805 /* Try to acquire the lock */
1806 REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
1807 lock_status = REG_RD(bp, hw_lock_control_reg);
1808 if (lock_status & resource_bit)
1813 BNX2X_ERR("Timeout\n");
1817 int bnx2x_release_leader_lock(struct bnx2x *bp)
1819 return bnx2x_release_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
1822 int bnx2x_release_hw_lock(struct bnx2x *bp, u32 resource)
1825 u32 resource_bit = (1 << resource);
1826 int func = BP_FUNC(bp);
1827 u32 hw_lock_control_reg;
1829 /* Validating that the resource is within range */
1830 if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
1831 BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
1832 resource, HW_LOCK_MAX_RESOURCE_VALUE);
1837 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
1839 hw_lock_control_reg =
1840 (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
1843 /* Validating that the resource is currently taken */
1844 lock_status = REG_RD(bp, hw_lock_control_reg);
1845 if (!(lock_status & resource_bit)) {
1846 BNX2X_ERR("lock_status 0x%x resource_bit 0x%x. unlock was called but lock wasn't taken!\n",
1847 lock_status, resource_bit);
1851 REG_WR(bp, hw_lock_control_reg, resource_bit);
1856 int bnx2x_get_gpio(struct bnx2x *bp, int gpio_num, u8 port)
1858 /* The GPIO should be swapped if swap register is set and active */
1859 int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
1860 REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
1861 int gpio_shift = gpio_num +
1862 (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
1863 u32 gpio_mask = (1 << gpio_shift);
1867 if (gpio_num > MISC_REGISTERS_GPIO_3) {
1868 BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
1872 /* read GPIO value */
1873 gpio_reg = REG_RD(bp, MISC_REG_GPIO);
1875 /* get the requested pin value */
1876 if ((gpio_reg & gpio_mask) == gpio_mask)
1881 DP(NETIF_MSG_LINK, "pin %d value 0x%x\n", gpio_num, value);
1886 int bnx2x_set_gpio(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
1888 /* The GPIO should be swapped if swap register is set and active */
1889 int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
1890 REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
1891 int gpio_shift = gpio_num +
1892 (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
1893 u32 gpio_mask = (1 << gpio_shift);
1896 if (gpio_num > MISC_REGISTERS_GPIO_3) {
1897 BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
1901 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
1902 /* read GPIO and mask except the float bits */
1903 gpio_reg = (REG_RD(bp, MISC_REG_GPIO) & MISC_REGISTERS_GPIO_FLOAT);
1906 case MISC_REGISTERS_GPIO_OUTPUT_LOW:
1908 "Set GPIO %d (shift %d) -> output low\n",
1909 gpio_num, gpio_shift);
1910 /* clear FLOAT and set CLR */
1911 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
1912 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_CLR_POS);
1915 case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
1917 "Set GPIO %d (shift %d) -> output high\n",
1918 gpio_num, gpio_shift);
1919 /* clear FLOAT and set SET */
1920 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
1921 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_SET_POS);
1924 case MISC_REGISTERS_GPIO_INPUT_HI_Z:
1926 "Set GPIO %d (shift %d) -> input\n",
1927 gpio_num, gpio_shift);
1929 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
1936 REG_WR(bp, MISC_REG_GPIO, gpio_reg);
1937 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
1942 int bnx2x_set_mult_gpio(struct bnx2x *bp, u8 pins, u32 mode)
1947 /* Any port swapping should be handled by caller. */
1949 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
1950 /* read GPIO and mask except the float bits */
1951 gpio_reg = REG_RD(bp, MISC_REG_GPIO);
1952 gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_FLOAT_POS);
1953 gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_CLR_POS);
1954 gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_SET_POS);
1957 case MISC_REGISTERS_GPIO_OUTPUT_LOW:
1958 DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output low\n", pins);
1960 gpio_reg |= (pins << MISC_REGISTERS_GPIO_CLR_POS);
1963 case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
1964 DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output high\n", pins);
1966 gpio_reg |= (pins << MISC_REGISTERS_GPIO_SET_POS);
1969 case MISC_REGISTERS_GPIO_INPUT_HI_Z:
1970 DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> input\n", pins);
1972 gpio_reg |= (pins << MISC_REGISTERS_GPIO_FLOAT_POS);
1976 BNX2X_ERR("Invalid GPIO mode assignment %d\n", mode);
1982 REG_WR(bp, MISC_REG_GPIO, gpio_reg);
1984 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
1989 int bnx2x_set_gpio_int(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
1991 /* The GPIO should be swapped if swap register is set and active */
1992 int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
1993 REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
1994 int gpio_shift = gpio_num +
1995 (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
1996 u32 gpio_mask = (1 << gpio_shift);
1999 if (gpio_num > MISC_REGISTERS_GPIO_3) {
2000 BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
2004 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
2006 gpio_reg = REG_RD(bp, MISC_REG_GPIO_INT);
2009 case MISC_REGISTERS_GPIO_INT_OUTPUT_CLR:
2011 "Clear GPIO INT %d (shift %d) -> output low\n",
2012 gpio_num, gpio_shift);
2013 /* clear SET and set CLR */
2014 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
2015 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
2018 case MISC_REGISTERS_GPIO_INT_OUTPUT_SET:
2020 "Set GPIO INT %d (shift %d) -> output high\n",
2021 gpio_num, gpio_shift);
2022 /* clear CLR and set SET */
2023 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
2024 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
2031 REG_WR(bp, MISC_REG_GPIO_INT, gpio_reg);
2032 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
2037 static int bnx2x_set_spio(struct bnx2x *bp, int spio_num, u32 mode)
2039 u32 spio_mask = (1 << spio_num);
2042 if ((spio_num < MISC_REGISTERS_SPIO_4) ||
2043 (spio_num > MISC_REGISTERS_SPIO_7)) {
2044 BNX2X_ERR("Invalid SPIO %d\n", spio_num);
2048 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
2049 /* read SPIO and mask except the float bits */
2050 spio_reg = (REG_RD(bp, MISC_REG_SPIO) & MISC_REGISTERS_SPIO_FLOAT);
2053 case MISC_REGISTERS_SPIO_OUTPUT_LOW:
2054 DP(NETIF_MSG_HW, "Set SPIO %d -> output low\n", spio_num);
2055 /* clear FLOAT and set CLR */
2056 spio_reg &= ~(spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS);
2057 spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_CLR_POS);
2060 case MISC_REGISTERS_SPIO_OUTPUT_HIGH:
2061 DP(NETIF_MSG_HW, "Set SPIO %d -> output high\n", spio_num);
2062 /* clear FLOAT and set SET */
2063 spio_reg &= ~(spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS);
2064 spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_SET_POS);
2067 case MISC_REGISTERS_SPIO_INPUT_HI_Z:
2068 DP(NETIF_MSG_HW, "Set SPIO %d -> input\n", spio_num);
2070 spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS);
2077 REG_WR(bp, MISC_REG_SPIO, spio_reg);
2078 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
2083 void bnx2x_calc_fc_adv(struct bnx2x *bp)
2085 u8 cfg_idx = bnx2x_get_link_cfg_idx(bp);
2086 switch (bp->link_vars.ieee_fc &
2087 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK) {
2088 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE:
2089 bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
2093 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH:
2094 bp->port.advertising[cfg_idx] |= (ADVERTISED_Asym_Pause |
2098 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC:
2099 bp->port.advertising[cfg_idx] |= ADVERTISED_Asym_Pause;
2103 bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
2109 u8 bnx2x_initial_phy_init(struct bnx2x *bp, int load_mode)
2111 if (!BP_NOMCP(bp)) {
2113 int cfx_idx = bnx2x_get_link_cfg_idx(bp);
2114 u16 req_line_speed = bp->link_params.req_line_speed[cfx_idx];
2116 * Initialize link parameters structure variables
2117 * It is recommended to turn off RX FC for jumbo frames
2118 * for better performance
2120 if (CHIP_IS_E1x(bp) && (bp->dev->mtu > 5000))
2121 bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_TX;
2123 bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_BOTH;
2125 bnx2x_acquire_phy_lock(bp);
2127 if (load_mode == LOAD_DIAG) {
2128 struct link_params *lp = &bp->link_params;
2129 lp->loopback_mode = LOOPBACK_XGXS;
2130 /* do PHY loopback at 10G speed, if possible */
2131 if (lp->req_line_speed[cfx_idx] < SPEED_10000) {
2132 if (lp->speed_cap_mask[cfx_idx] &
2133 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
2134 lp->req_line_speed[cfx_idx] =
2137 lp->req_line_speed[cfx_idx] =
2142 if (load_mode == LOAD_LOOPBACK_EXT) {
2143 struct link_params *lp = &bp->link_params;
2144 lp->loopback_mode = LOOPBACK_EXT;
2147 rc = bnx2x_phy_init(&bp->link_params, &bp->link_vars);
2149 bnx2x_release_phy_lock(bp);
2151 bnx2x_calc_fc_adv(bp);
2153 if (CHIP_REV_IS_SLOW(bp) && bp->link_vars.link_up) {
2154 bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
2155 bnx2x_link_report(bp);
2157 queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
2158 bp->link_params.req_line_speed[cfx_idx] = req_line_speed;
2161 BNX2X_ERR("Bootcode is missing - can not initialize link\n");
2165 void bnx2x_link_set(struct bnx2x *bp)
2167 if (!BP_NOMCP(bp)) {
2168 bnx2x_acquire_phy_lock(bp);
2169 bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
2170 bnx2x_phy_init(&bp->link_params, &bp->link_vars);
2171 bnx2x_release_phy_lock(bp);
2173 bnx2x_calc_fc_adv(bp);
2175 BNX2X_ERR("Bootcode is missing - can not set link\n");
2178 static void bnx2x__link_reset(struct bnx2x *bp)
2180 if (!BP_NOMCP(bp)) {
2181 bnx2x_acquire_phy_lock(bp);
2182 bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
2183 bnx2x_release_phy_lock(bp);
2185 BNX2X_ERR("Bootcode is missing - can not reset link\n");
2188 u8 bnx2x_link_test(struct bnx2x *bp, u8 is_serdes)
2192 if (!BP_NOMCP(bp)) {
2193 bnx2x_acquire_phy_lock(bp);
2194 rc = bnx2x_test_link(&bp->link_params, &bp->link_vars,
2196 bnx2x_release_phy_lock(bp);
2198 BNX2X_ERR("Bootcode is missing - can not test link\n");
2204 /* Calculates the sum of vn_min_rates.
2205 It's needed for further normalizing of the min_rates.
2207 sum of vn_min_rates.
2209 0 - if all the min_rates are 0.
2210 In the later case fainess algorithm should be deactivated.
2211 If not all min_rates are zero then those that are zeroes will be set to 1.
2213 static void bnx2x_calc_vn_min(struct bnx2x *bp,
2214 struct cmng_init_input *input)
2219 for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
2220 u32 vn_cfg = bp->mf_config[vn];
2221 u32 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
2222 FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
2224 /* Skip hidden vns */
2225 if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
2227 /* If min rate is zero - set it to 1 */
2228 else if (!vn_min_rate)
2229 vn_min_rate = DEF_MIN_RATE;
2233 input->vnic_min_rate[vn] = vn_min_rate;
2236 /* if ETS or all min rates are zeros - disable fairness */
2237 if (BNX2X_IS_ETS_ENABLED(bp)) {
2238 input->flags.cmng_enables &=
2239 ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
2240 DP(NETIF_MSG_IFUP, "Fairness will be disabled due to ETS\n");
2241 } else if (all_zero) {
2242 input->flags.cmng_enables &=
2243 ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
2245 "All MIN values are zeroes fairness will be disabled\n");
2247 input->flags.cmng_enables |=
2248 CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
2251 static void bnx2x_calc_vn_max(struct bnx2x *bp, int vn,
2252 struct cmng_init_input *input)
2255 u32 vn_cfg = bp->mf_config[vn];
2257 if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
2260 u32 maxCfg = bnx2x_extract_max_cfg(bp, vn_cfg);
2263 /* maxCfg in percents of linkspeed */
2264 vn_max_rate = (bp->link_vars.line_speed * maxCfg) / 100;
2265 } else /* SD modes */
2266 /* maxCfg is absolute in 100Mb units */
2267 vn_max_rate = maxCfg * 100;
2270 DP(NETIF_MSG_IFUP, "vn %d: vn_max_rate %d\n", vn, vn_max_rate);
2272 input->vnic_max_rate[vn] = vn_max_rate;
2276 static int bnx2x_get_cmng_fns_mode(struct bnx2x *bp)
2278 if (CHIP_REV_IS_SLOW(bp))
2279 return CMNG_FNS_NONE;
2281 return CMNG_FNS_MINMAX;
2283 return CMNG_FNS_NONE;
2286 void bnx2x_read_mf_cfg(struct bnx2x *bp)
2288 int vn, n = (CHIP_MODE_IS_4_PORT(bp) ? 2 : 1);
2291 return; /* what should be the default bvalue in this case */
2293 /* For 2 port configuration the absolute function number formula
2295 * abs_func = 2 * vn + BP_PORT + BP_PATH
2297 * and there are 4 functions per port
2299 * For 4 port configuration it is
2300 * abs_func = 4 * vn + 2 * BP_PORT + BP_PATH
2302 * and there are 2 functions per port
2304 for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
2305 int /*abs*/func = n * (2 * vn + BP_PORT(bp)) + BP_PATH(bp);
2307 if (func >= E1H_FUNC_MAX)
2311 MF_CFG_RD(bp, func_mf_config[func].config);
2313 if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
2314 DP(NETIF_MSG_IFUP, "mf_cfg function disabled\n");
2315 bp->flags |= MF_FUNC_DIS;
2317 DP(NETIF_MSG_IFUP, "mf_cfg function enabled\n");
2318 bp->flags &= ~MF_FUNC_DIS;
2322 static void bnx2x_cmng_fns_init(struct bnx2x *bp, u8 read_cfg, u8 cmng_type)
2324 struct cmng_init_input input;
2325 memset(&input, 0, sizeof(struct cmng_init_input));
2327 input.port_rate = bp->link_vars.line_speed;
2329 if (cmng_type == CMNG_FNS_MINMAX) {
2332 /* read mf conf from shmem */
2334 bnx2x_read_mf_cfg(bp);
2336 /* vn_weight_sum and enable fairness if not 0 */
2337 bnx2x_calc_vn_min(bp, &input);
2339 /* calculate and set min-max rate for each vn */
2341 for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++)
2342 bnx2x_calc_vn_max(bp, vn, &input);
2344 /* always enable rate shaping and fairness */
2345 input.flags.cmng_enables |=
2346 CMNG_FLAGS_PER_PORT_RATE_SHAPING_VN;
2348 bnx2x_init_cmng(&input, &bp->cmng);
2352 /* rate shaping and fairness are disabled */
2354 "rate shaping and fairness are disabled\n");
2357 static void storm_memset_cmng(struct bnx2x *bp,
2358 struct cmng_init *cmng,
2362 size_t size = sizeof(struct cmng_struct_per_port);
2364 u32 addr = BAR_XSTRORM_INTMEM +
2365 XSTORM_CMNG_PER_PORT_VARS_OFFSET(port);
2367 __storm_memset_struct(bp, addr, size, (u32 *)&cmng->port);
2369 for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
2370 int func = func_by_vn(bp, vn);
2372 addr = BAR_XSTRORM_INTMEM +
2373 XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(func);
2374 size = sizeof(struct rate_shaping_vars_per_vn);
2375 __storm_memset_struct(bp, addr, size,
2376 (u32 *)&cmng->vnic.vnic_max_rate[vn]);
2378 addr = BAR_XSTRORM_INTMEM +
2379 XSTORM_FAIRNESS_PER_VN_VARS_OFFSET(func);
2380 size = sizeof(struct fairness_vars_per_vn);
2381 __storm_memset_struct(bp, addr, size,
2382 (u32 *)&cmng->vnic.vnic_min_rate[vn]);
2386 /* This function is called upon link interrupt */
2387 static void bnx2x_link_attn(struct bnx2x *bp)
2389 /* Make sure that we are synced with the current statistics */
2390 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
2392 bnx2x_link_update(&bp->link_params, &bp->link_vars);
2394 if (bp->link_vars.link_up) {
2396 /* dropless flow control */
2397 if (!CHIP_IS_E1(bp) && bp->dropless_fc) {
2398 int port = BP_PORT(bp);
2399 u32 pause_enabled = 0;
2401 if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX)
2404 REG_WR(bp, BAR_USTRORM_INTMEM +
2405 USTORM_ETH_PAUSE_ENABLED_OFFSET(port),
2409 if (bp->link_vars.mac_type != MAC_TYPE_EMAC) {
2410 struct host_port_stats *pstats;
2412 pstats = bnx2x_sp(bp, port_stats);
2413 /* reset old mac stats */
2414 memset(&(pstats->mac_stx[0]), 0,
2415 sizeof(struct mac_stx));
2417 if (bp->state == BNX2X_STATE_OPEN)
2418 bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
2421 if (bp->link_vars.link_up && bp->link_vars.line_speed) {
2422 int cmng_fns = bnx2x_get_cmng_fns_mode(bp);
2424 if (cmng_fns != CMNG_FNS_NONE) {
2425 bnx2x_cmng_fns_init(bp, false, cmng_fns);
2426 storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
2428 /* rate shaping and fairness are disabled */
2430 "single function mode without fairness\n");
2433 __bnx2x_link_report(bp);
2436 bnx2x_link_sync_notify(bp);
2439 void bnx2x__link_status_update(struct bnx2x *bp)
2441 if (bp->state != BNX2X_STATE_OPEN)
2444 /* read updated dcb configuration */
2445 bnx2x_dcbx_pmf_update(bp);
2447 bnx2x_link_status_update(&bp->link_params, &bp->link_vars);
2449 if (bp->link_vars.link_up)
2450 bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
2452 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
2454 /* indicate link status */
2455 bnx2x_link_report(bp);
2458 static int bnx2x_afex_func_update(struct bnx2x *bp, u16 vifid,
2459 u16 vlan_val, u8 allowed_prio)
2461 struct bnx2x_func_state_params func_params = {0};
2462 struct bnx2x_func_afex_update_params *f_update_params =
2463 &func_params.params.afex_update;
2465 func_params.f_obj = &bp->func_obj;
2466 func_params.cmd = BNX2X_F_CMD_AFEX_UPDATE;
2468 /* no need to wait for RAMROD completion, so don't
2469 * set RAMROD_COMP_WAIT flag
2472 f_update_params->vif_id = vifid;
2473 f_update_params->afex_default_vlan = vlan_val;
2474 f_update_params->allowed_priorities = allowed_prio;
2476 /* if ramrod can not be sent, response to MCP immediately */
2477 if (bnx2x_func_state_change(bp, &func_params) < 0)
2478 bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
2483 static int bnx2x_afex_handle_vif_list_cmd(struct bnx2x *bp, u8 cmd_type,
2484 u16 vif_index, u8 func_bit_map)
2486 struct bnx2x_func_state_params func_params = {0};
2487 struct bnx2x_func_afex_viflists_params *update_params =
2488 &func_params.params.afex_viflists;
2492 /* validate only LIST_SET and LIST_GET are received from switch */
2493 if ((cmd_type != VIF_LIST_RULE_GET) && (cmd_type != VIF_LIST_RULE_SET))
2494 BNX2X_ERR("BUG! afex_handle_vif_list_cmd invalid type 0x%x\n",
2497 func_params.f_obj = &bp->func_obj;
2498 func_params.cmd = BNX2X_F_CMD_AFEX_VIFLISTS;
2500 /* set parameters according to cmd_type */
2501 update_params->afex_vif_list_command = cmd_type;
2502 update_params->vif_list_index = cpu_to_le16(vif_index);
2503 update_params->func_bit_map =
2504 (cmd_type == VIF_LIST_RULE_GET) ? 0 : func_bit_map;
2505 update_params->func_to_clear = 0;
2507 (cmd_type == VIF_LIST_RULE_GET) ?
2508 DRV_MSG_CODE_AFEX_LISTGET_ACK :
2509 DRV_MSG_CODE_AFEX_LISTSET_ACK;
2511 /* if ramrod can not be sent, respond to MCP immediately for
2512 * SET and GET requests (other are not triggered from MCP)
2514 rc = bnx2x_func_state_change(bp, &func_params);
2516 bnx2x_fw_command(bp, drv_msg_code, 0);
2521 static void bnx2x_handle_afex_cmd(struct bnx2x *bp, u32 cmd)
2523 struct afex_stats afex_stats;
2524 u32 func = BP_ABS_FUNC(bp);
2531 u32 addr_to_write, vifid, addrs, stats_type, i;
2533 if (cmd & DRV_STATUS_AFEX_LISTGET_REQ) {
2534 vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
2536 "afex: got MCP req LISTGET_REQ for vifid 0x%x\n", vifid);
2537 bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_GET, vifid, 0);
2540 if (cmd & DRV_STATUS_AFEX_LISTSET_REQ) {
2541 vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
2542 addrs = SHMEM2_RD(bp, afex_param2_to_driver[BP_FW_MB_IDX(bp)]);
2544 "afex: got MCP req LISTSET_REQ for vifid 0x%x addrs 0x%x\n",
2546 bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_SET, vifid,
2550 if (cmd & DRV_STATUS_AFEX_STATSGET_REQ) {
2551 addr_to_write = SHMEM2_RD(bp,
2552 afex_scratchpad_addr_to_write[BP_FW_MB_IDX(bp)]);
2553 stats_type = SHMEM2_RD(bp,
2554 afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
2557 "afex: got MCP req STATSGET_REQ, write to addr 0x%x\n",
2560 bnx2x_afex_collect_stats(bp, (void *)&afex_stats, stats_type);
2562 /* write response to scratchpad, for MCP */
2563 for (i = 0; i < (sizeof(struct afex_stats)/sizeof(u32)); i++)
2564 REG_WR(bp, addr_to_write + i*sizeof(u32),
2565 *(((u32 *)(&afex_stats))+i));
2567 /* send ack message to MCP */
2568 bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_STATSGET_ACK, 0);
2571 if (cmd & DRV_STATUS_AFEX_VIFSET_REQ) {
2572 mf_config = MF_CFG_RD(bp, func_mf_config[func].config);
2573 bp->mf_config[BP_VN(bp)] = mf_config;
2575 "afex: got MCP req VIFSET_REQ, mf_config 0x%x\n",
2578 /* if VIF_SET is "enabled" */
2579 if (!(mf_config & FUNC_MF_CFG_FUNC_DISABLED)) {
2580 /* set rate limit directly to internal RAM */
2581 struct cmng_init_input cmng_input;
2582 struct rate_shaping_vars_per_vn m_rs_vn;
2583 size_t size = sizeof(struct rate_shaping_vars_per_vn);
2584 u32 addr = BAR_XSTRORM_INTMEM +
2585 XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(BP_FUNC(bp));
2587 bp->mf_config[BP_VN(bp)] = mf_config;
2589 bnx2x_calc_vn_max(bp, BP_VN(bp), &cmng_input);
2590 m_rs_vn.vn_counter.rate =
2591 cmng_input.vnic_max_rate[BP_VN(bp)];
2592 m_rs_vn.vn_counter.quota =
2593 (m_rs_vn.vn_counter.rate *
2594 RS_PERIODIC_TIMEOUT_USEC) / 8;
2596 __storm_memset_struct(bp, addr, size, (u32 *)&m_rs_vn);
2598 /* read relevant values from mf_cfg struct in shmem */
2600 (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
2601 FUNC_MF_CFG_E1HOV_TAG_MASK) >>
2602 FUNC_MF_CFG_E1HOV_TAG_SHIFT;
2604 (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
2605 FUNC_MF_CFG_AFEX_VLAN_MASK) >>
2606 FUNC_MF_CFG_AFEX_VLAN_SHIFT;
2607 vlan_prio = (mf_config &
2608 FUNC_MF_CFG_TRANSMIT_PRIORITY_MASK) >>
2609 FUNC_MF_CFG_TRANSMIT_PRIORITY_SHIFT;
2610 vlan_val |= (vlan_prio << VLAN_PRIO_SHIFT);
2613 func_mf_config[func].afex_config) &
2614 FUNC_MF_CFG_AFEX_VLAN_MODE_MASK) >>
2615 FUNC_MF_CFG_AFEX_VLAN_MODE_SHIFT;
2618 func_mf_config[func].afex_config) &
2619 FUNC_MF_CFG_AFEX_COS_FILTER_MASK) >>
2620 FUNC_MF_CFG_AFEX_COS_FILTER_SHIFT;
2622 /* send ramrod to FW, return in case of failure */
2623 if (bnx2x_afex_func_update(bp, vif_id, vlan_val,
2627 bp->afex_def_vlan_tag = vlan_val;
2628 bp->afex_vlan_mode = vlan_mode;
2630 /* notify link down because BP->flags is disabled */
2631 bnx2x_link_report(bp);
2633 /* send INVALID VIF ramrod to FW */
2634 bnx2x_afex_func_update(bp, 0xFFFF, 0, 0);
2636 /* Reset the default afex VLAN */
2637 bp->afex_def_vlan_tag = -1;
2642 static void bnx2x_pmf_update(struct bnx2x *bp)
2644 int port = BP_PORT(bp);
2648 DP(BNX2X_MSG_MCP, "pmf %d\n", bp->port.pmf);
2651 * We need the mb() to ensure the ordering between the writing to
2652 * bp->port.pmf here and reading it from the bnx2x_periodic_task().
2656 /* queue a periodic task */
2657 queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
2659 bnx2x_dcbx_pmf_update(bp);
2661 /* enable nig attention */
2662 val = (0xff0f | (1 << (BP_VN(bp) + 4)));
2663 if (bp->common.int_block == INT_BLOCK_HC) {
2664 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
2665 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
2666 } else if (!CHIP_IS_E1x(bp)) {
2667 REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
2668 REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
2671 bnx2x_stats_handle(bp, STATS_EVENT_PMF);
2679 * General service functions
2682 /* send the MCP a request, block until there is a reply */
2683 u32 bnx2x_fw_command(struct bnx2x *bp, u32 command, u32 param)
2685 int mb_idx = BP_FW_MB_IDX(bp);
2689 u8 delay = CHIP_REV_IS_SLOW(bp) ? 100 : 10;
2691 mutex_lock(&bp->fw_mb_mutex);
2693 SHMEM_WR(bp, func_mb[mb_idx].drv_mb_param, param);
2694 SHMEM_WR(bp, func_mb[mb_idx].drv_mb_header, (command | seq));
2696 DP(BNX2X_MSG_MCP, "wrote command (%x) to FW MB param 0x%08x\n",
2697 (command | seq), param);
2700 /* let the FW do it's magic ... */
2703 rc = SHMEM_RD(bp, func_mb[mb_idx].fw_mb_header);
2705 /* Give the FW up to 5 second (500*10ms) */
2706 } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 500));
2708 DP(BNX2X_MSG_MCP, "[after %d ms] read (%x) seq is (%x) from FW MB\n",
2709 cnt*delay, rc, seq);
2711 /* is this a reply to our command? */
2712 if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK))
2713 rc &= FW_MSG_CODE_MASK;
2716 BNX2X_ERR("FW failed to respond!\n");
2720 mutex_unlock(&bp->fw_mb_mutex);
2726 static void storm_memset_func_cfg(struct bnx2x *bp,
2727 struct tstorm_eth_function_common_config *tcfg,
2730 size_t size = sizeof(struct tstorm_eth_function_common_config);
2732 u32 addr = BAR_TSTRORM_INTMEM +
2733 TSTORM_FUNCTION_COMMON_CONFIG_OFFSET(abs_fid);
2735 __storm_memset_struct(bp, addr, size, (u32 *)tcfg);
2738 void bnx2x_func_init(struct bnx2x *bp, struct bnx2x_func_init_params *p)
2740 if (CHIP_IS_E1x(bp)) {
2741 struct tstorm_eth_function_common_config tcfg = {0};
2743 storm_memset_func_cfg(bp, &tcfg, p->func_id);
2746 /* Enable the function in the FW */
2747 storm_memset_vf_to_pf(bp, p->func_id, p->pf_id);
2748 storm_memset_func_en(bp, p->func_id, 1);
2751 if (p->func_flgs & FUNC_FLG_SPQ) {
2752 storm_memset_spq_addr(bp, p->spq_map, p->func_id);
2753 REG_WR(bp, XSEM_REG_FAST_MEMORY +
2754 XSTORM_SPQ_PROD_OFFSET(p->func_id), p->spq_prod);
2759 * bnx2x_get_tx_only_flags - Return common flags
2763 * @zero_stats TRUE if statistics zeroing is needed
2765 * Return the flags that are common for the Tx-only and not normal connections.
2767 static unsigned long bnx2x_get_common_flags(struct bnx2x *bp,
2768 struct bnx2x_fastpath *fp,
2771 unsigned long flags = 0;
2773 /* PF driver will always initialize the Queue to an ACTIVE state */
2774 __set_bit(BNX2X_Q_FLG_ACTIVE, &flags);
2776 /* tx only connections collect statistics (on the same index as the
2777 * parent connection). The statistics are zeroed when the parent
2778 * connection is initialized.
2781 __set_bit(BNX2X_Q_FLG_STATS, &flags);
2783 __set_bit(BNX2X_Q_FLG_ZERO_STATS, &flags);
2789 static unsigned long bnx2x_get_q_flags(struct bnx2x *bp,
2790 struct bnx2x_fastpath *fp,
2793 unsigned long flags = 0;
2795 /* calculate other queue flags */
2797 __set_bit(BNX2X_Q_FLG_OV, &flags);
2799 if (IS_FCOE_FP(fp)) {
2800 __set_bit(BNX2X_Q_FLG_FCOE, &flags);
2801 /* For FCoE - force usage of default priority (for afex) */
2802 __set_bit(BNX2X_Q_FLG_FORCE_DEFAULT_PRI, &flags);
2805 if (!fp->disable_tpa) {
2806 __set_bit(BNX2X_Q_FLG_TPA, &flags);
2807 __set_bit(BNX2X_Q_FLG_TPA_IPV6, &flags);
2808 if (fp->mode == TPA_MODE_GRO)
2809 __set_bit(BNX2X_Q_FLG_TPA_GRO, &flags);
2813 __set_bit(BNX2X_Q_FLG_LEADING_RSS, &flags);
2814 __set_bit(BNX2X_Q_FLG_MCAST, &flags);
2817 /* Always set HW VLAN stripping */
2818 __set_bit(BNX2X_Q_FLG_VLAN, &flags);
2820 /* configure silent vlan removal */
2822 __set_bit(BNX2X_Q_FLG_SILENT_VLAN_REM, &flags);
2825 return flags | bnx2x_get_common_flags(bp, fp, true);
2828 static void bnx2x_pf_q_prep_general(struct bnx2x *bp,
2829 struct bnx2x_fastpath *fp, struct bnx2x_general_setup_params *gen_init,
2832 gen_init->stat_id = bnx2x_stats_id(fp);
2833 gen_init->spcl_id = fp->cl_id;
2835 /* Always use mini-jumbo MTU for FCoE L2 ring */
2837 gen_init->mtu = BNX2X_FCOE_MINI_JUMBO_MTU;
2839 gen_init->mtu = bp->dev->mtu;
2841 gen_init->cos = cos;
2844 static void bnx2x_pf_rx_q_prep(struct bnx2x *bp,
2845 struct bnx2x_fastpath *fp, struct rxq_pause_params *pause,
2846 struct bnx2x_rxq_setup_params *rxq_init)
2850 u16 tpa_agg_size = 0;
2852 if (!fp->disable_tpa) {
2853 pause->sge_th_lo = SGE_TH_LO(bp);
2854 pause->sge_th_hi = SGE_TH_HI(bp);
2856 /* validate SGE ring has enough to cross high threshold */
2857 WARN_ON(bp->dropless_fc &&
2858 pause->sge_th_hi + FW_PREFETCH_CNT >
2859 MAX_RX_SGE_CNT * NUM_RX_SGE_PAGES);
2861 tpa_agg_size = min_t(u32,
2862 (min_t(u32, 8, MAX_SKB_FRAGS) *
2863 SGE_PAGE_SIZE * PAGES_PER_SGE), 0xffff);
2864 max_sge = SGE_PAGE_ALIGN(bp->dev->mtu) >>
2866 max_sge = ((max_sge + PAGES_PER_SGE - 1) &
2867 (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
2868 sge_sz = (u16)min_t(u32, SGE_PAGE_SIZE * PAGES_PER_SGE,
2872 /* pause - not for e1 */
2873 if (!CHIP_IS_E1(bp)) {
2874 pause->bd_th_lo = BD_TH_LO(bp);
2875 pause->bd_th_hi = BD_TH_HI(bp);
2877 pause->rcq_th_lo = RCQ_TH_LO(bp);
2878 pause->rcq_th_hi = RCQ_TH_HI(bp);
2880 * validate that rings have enough entries to cross
2883 WARN_ON(bp->dropless_fc &&
2884 pause->bd_th_hi + FW_PREFETCH_CNT >
2886 WARN_ON(bp->dropless_fc &&
2887 pause->rcq_th_hi + FW_PREFETCH_CNT >
2888 NUM_RCQ_RINGS * MAX_RCQ_DESC_CNT);
2894 rxq_init->dscr_map = fp->rx_desc_mapping;
2895 rxq_init->sge_map = fp->rx_sge_mapping;
2896 rxq_init->rcq_map = fp->rx_comp_mapping;
2897 rxq_init->rcq_np_map = fp->rx_comp_mapping + BCM_PAGE_SIZE;
2899 /* This should be a maximum number of data bytes that may be
2900 * placed on the BD (not including paddings).
2902 rxq_init->buf_sz = fp->rx_buf_size - BNX2X_FW_RX_ALIGN_START -
2903 BNX2X_FW_RX_ALIGN_END - IP_HEADER_ALIGNMENT_PADDING;
2905 rxq_init->cl_qzone_id = fp->cl_qzone_id;
2906 rxq_init->tpa_agg_sz = tpa_agg_size;
2907 rxq_init->sge_buf_sz = sge_sz;
2908 rxq_init->max_sges_pkt = max_sge;
2909 rxq_init->rss_engine_id = BP_FUNC(bp);
2910 rxq_init->mcast_engine_id = BP_FUNC(bp);
2912 /* Maximum number or simultaneous TPA aggregation for this Queue.
2914 * For PF Clients it should be the maximum avaliable number.
2915 * VF driver(s) may want to define it to a smaller value.
2917 rxq_init->max_tpa_queues = MAX_AGG_QS(bp);
2919 rxq_init->cache_line_log = BNX2X_RX_ALIGN_SHIFT;
2920 rxq_init->fw_sb_id = fp->fw_sb_id;
2923 rxq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_RX_CQ_CONS;
2925 rxq_init->sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
2926 /* configure silent vlan removal
2927 * if multi function mode is afex, then mask default vlan
2929 if (IS_MF_AFEX(bp)) {
2930 rxq_init->silent_removal_value = bp->afex_def_vlan_tag;
2931 rxq_init->silent_removal_mask = VLAN_VID_MASK;
2935 static void bnx2x_pf_tx_q_prep(struct bnx2x *bp,
2936 struct bnx2x_fastpath *fp, struct bnx2x_txq_setup_params *txq_init,
2939 txq_init->dscr_map = fp->txdata_ptr[cos]->tx_desc_mapping;
2940 txq_init->sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS + cos;
2941 txq_init->traffic_type = LLFC_TRAFFIC_TYPE_NW;
2942 txq_init->fw_sb_id = fp->fw_sb_id;
2945 * set the tss leading client id for TX classfication ==
2946 * leading RSS client id
2948 txq_init->tss_leading_cl_id = bnx2x_fp(bp, 0, cl_id);
2950 if (IS_FCOE_FP(fp)) {
2951 txq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_TX_CQ_CONS;
2952 txq_init->traffic_type = LLFC_TRAFFIC_TYPE_FCOE;
2956 static void bnx2x_pf_init(struct bnx2x *bp)
2958 struct bnx2x_func_init_params func_init = {0};
2959 struct event_ring_data eq_data = { {0} };
2962 if (!CHIP_IS_E1x(bp)) {
2963 /* reset IGU PF statistics: MSIX + ATTN */
2965 REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
2966 BNX2X_IGU_STAS_MSG_VF_CNT*4 +
2967 (CHIP_MODE_IS_4_PORT(bp) ?
2968 BP_FUNC(bp) : BP_VN(bp))*4, 0);
2970 REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
2971 BNX2X_IGU_STAS_MSG_VF_CNT*4 +
2972 BNX2X_IGU_STAS_MSG_PF_CNT*4 +
2973 (CHIP_MODE_IS_4_PORT(bp) ?
2974 BP_FUNC(bp) : BP_VN(bp))*4, 0);
2977 /* function setup flags */
2978 flags = (FUNC_FLG_STATS | FUNC_FLG_LEADING | FUNC_FLG_SPQ);
2980 /* This flag is relevant for E1x only.
2981 * E2 doesn't have a TPA configuration in a function level.
2983 flags |= (bp->flags & TPA_ENABLE_FLAG) ? FUNC_FLG_TPA : 0;
2985 func_init.func_flgs = flags;
2986 func_init.pf_id = BP_FUNC(bp);
2987 func_init.func_id = BP_FUNC(bp);
2988 func_init.spq_map = bp->spq_mapping;
2989 func_init.spq_prod = bp->spq_prod_idx;
2991 bnx2x_func_init(bp, &func_init);
2993 memset(&(bp->cmng), 0, sizeof(struct cmng_struct_per_port));
2996 * Congestion management values depend on the link rate
2997 * There is no active link so initial link rate is set to 10 Gbps.
2998 * When the link comes up The congestion management values are
2999 * re-calculated according to the actual link rate.
3001 bp->link_vars.line_speed = SPEED_10000;
3002 bnx2x_cmng_fns_init(bp, true, bnx2x_get_cmng_fns_mode(bp));
3004 /* Only the PMF sets the HW */
3006 storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
3008 /* init Event Queue */
3009 eq_data.base_addr.hi = U64_HI(bp->eq_mapping);
3010 eq_data.base_addr.lo = U64_LO(bp->eq_mapping);
3011 eq_data.producer = bp->eq_prod;
3012 eq_data.index_id = HC_SP_INDEX_EQ_CONS;
3013 eq_data.sb_id = DEF_SB_ID;
3014 storm_memset_eq_data(bp, &eq_data, BP_FUNC(bp));
3018 static void bnx2x_e1h_disable(struct bnx2x *bp)
3020 int port = BP_PORT(bp);
3022 bnx2x_tx_disable(bp);
3024 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
3027 static void bnx2x_e1h_enable(struct bnx2x *bp)
3029 int port = BP_PORT(bp);
3031 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
3033 /* Tx queue should be only reenabled */
3034 netif_tx_wake_all_queues(bp->dev);
3037 * Should not call netif_carrier_on since it will be called if the link
3038 * is up when checking for link state
3042 #define DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED 3
3044 static void bnx2x_drv_info_ether_stat(struct bnx2x *bp)
3046 struct eth_stats_info *ether_stat =
3047 &bp->slowpath->drv_info_to_mcp.ether_stat;
3049 /* leave last char as NULL */
3050 memcpy(ether_stat->version, DRV_MODULE_VERSION,
3051 ETH_STAT_INFO_VERSION_LEN - 1);
3053 bp->sp_objs[0].mac_obj.get_n_elements(bp, &bp->sp_objs[0].mac_obj,
3054 DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED,
3055 ether_stat->mac_local);
3057 ether_stat->mtu_size = bp->dev->mtu;
3059 if (bp->dev->features & NETIF_F_RXCSUM)
3060 ether_stat->feature_flags |= FEATURE_ETH_CHKSUM_OFFLOAD_MASK;
3061 if (bp->dev->features & NETIF_F_TSO)
3062 ether_stat->feature_flags |= FEATURE_ETH_LSO_MASK;
3063 ether_stat->feature_flags |= bp->common.boot_mode;
3065 ether_stat->promiscuous_mode = (bp->dev->flags & IFF_PROMISC) ? 1 : 0;
3067 ether_stat->txq_size = bp->tx_ring_size;
3068 ether_stat->rxq_size = bp->rx_ring_size;
3071 static void bnx2x_drv_info_fcoe_stat(struct bnx2x *bp)
3074 struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
3075 struct fcoe_stats_info *fcoe_stat =
3076 &bp->slowpath->drv_info_to_mcp.fcoe_stat;
3078 memcpy(fcoe_stat->mac_local + MAC_LEADING_ZERO_CNT,
3079 bp->fip_mac, ETH_ALEN);
3081 fcoe_stat->qos_priority =
3082 app->traffic_type_priority[LLFC_TRAFFIC_TYPE_FCOE];
3084 /* insert FCoE stats from ramrod response */
3086 struct tstorm_per_queue_stats *fcoe_q_tstorm_stats =
3087 &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
3088 tstorm_queue_statistics;
3090 struct xstorm_per_queue_stats *fcoe_q_xstorm_stats =
3091 &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
3092 xstorm_queue_statistics;
3094 struct fcoe_statistics_params *fw_fcoe_stat =
3095 &bp->fw_stats_data->fcoe;
3097 ADD_64(fcoe_stat->rx_bytes_hi, 0, fcoe_stat->rx_bytes_lo,
3098 fw_fcoe_stat->rx_stat0.fcoe_rx_byte_cnt);
3100 ADD_64(fcoe_stat->rx_bytes_hi,
3101 fcoe_q_tstorm_stats->rcv_ucast_bytes.hi,
3102 fcoe_stat->rx_bytes_lo,
3103 fcoe_q_tstorm_stats->rcv_ucast_bytes.lo);
3105 ADD_64(fcoe_stat->rx_bytes_hi,
3106 fcoe_q_tstorm_stats->rcv_bcast_bytes.hi,
3107 fcoe_stat->rx_bytes_lo,
3108 fcoe_q_tstorm_stats->rcv_bcast_bytes.lo);
3110 ADD_64(fcoe_stat->rx_bytes_hi,
3111 fcoe_q_tstorm_stats->rcv_mcast_bytes.hi,
3112 fcoe_stat->rx_bytes_lo,
3113 fcoe_q_tstorm_stats->rcv_mcast_bytes.lo);
3115 ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
3116 fw_fcoe_stat->rx_stat0.fcoe_rx_pkt_cnt);
3118 ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
3119 fcoe_q_tstorm_stats->rcv_ucast_pkts);
3121 ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
3122 fcoe_q_tstorm_stats->rcv_bcast_pkts);
3124 ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
3125 fcoe_q_tstorm_stats->rcv_mcast_pkts);
3127 ADD_64(fcoe_stat->tx_bytes_hi, 0, fcoe_stat->tx_bytes_lo,
3128 fw_fcoe_stat->tx_stat.fcoe_tx_byte_cnt);
3130 ADD_64(fcoe_stat->tx_bytes_hi,
3131 fcoe_q_xstorm_stats->ucast_bytes_sent.hi,
3132 fcoe_stat->tx_bytes_lo,
3133 fcoe_q_xstorm_stats->ucast_bytes_sent.lo);
3135 ADD_64(fcoe_stat->tx_bytes_hi,
3136 fcoe_q_xstorm_stats->bcast_bytes_sent.hi,
3137 fcoe_stat->tx_bytes_lo,
3138 fcoe_q_xstorm_stats->bcast_bytes_sent.lo);
3140 ADD_64(fcoe_stat->tx_bytes_hi,
3141 fcoe_q_xstorm_stats->mcast_bytes_sent.hi,
3142 fcoe_stat->tx_bytes_lo,
3143 fcoe_q_xstorm_stats->mcast_bytes_sent.lo);
3145 ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
3146 fw_fcoe_stat->tx_stat.fcoe_tx_pkt_cnt);
3148 ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
3149 fcoe_q_xstorm_stats->ucast_pkts_sent);
3151 ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
3152 fcoe_q_xstorm_stats->bcast_pkts_sent);
3154 ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
3155 fcoe_q_xstorm_stats->mcast_pkts_sent);
3158 /* ask L5 driver to add data to the struct */
3159 bnx2x_cnic_notify(bp, CNIC_CTL_FCOE_STATS_GET_CMD);
3163 static void bnx2x_drv_info_iscsi_stat(struct bnx2x *bp)
3166 struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
3167 struct iscsi_stats_info *iscsi_stat =
3168 &bp->slowpath->drv_info_to_mcp.iscsi_stat;
3170 memcpy(iscsi_stat->mac_local + MAC_LEADING_ZERO_CNT,
3171 bp->cnic_eth_dev.iscsi_mac, ETH_ALEN);
3173 iscsi_stat->qos_priority =
3174 app->traffic_type_priority[LLFC_TRAFFIC_TYPE_ISCSI];
3176 /* ask L5 driver to add data to the struct */
3177 bnx2x_cnic_notify(bp, CNIC_CTL_ISCSI_STATS_GET_CMD);
3181 /* called due to MCP event (on pmf):
3182 * reread new bandwidth configuration
3184 * notify others function about the change
3186 static void bnx2x_config_mf_bw(struct bnx2x *bp)
3188 if (bp->link_vars.link_up) {
3189 bnx2x_cmng_fns_init(bp, true, CMNG_FNS_MINMAX);
3190 bnx2x_link_sync_notify(bp);
3192 storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
3195 static void bnx2x_set_mf_bw(struct bnx2x *bp)
3197 bnx2x_config_mf_bw(bp);
3198 bnx2x_fw_command(bp, DRV_MSG_CODE_SET_MF_BW_ACK, 0);
3201 static void bnx2x_handle_eee_event(struct bnx2x *bp)
3203 DP(BNX2X_MSG_MCP, "EEE - LLDP event\n");
3204 bnx2x_fw_command(bp, DRV_MSG_CODE_EEE_RESULTS_ACK, 0);
3207 static void bnx2x_handle_drv_info_req(struct bnx2x *bp)
3209 enum drv_info_opcode op_code;
3210 u32 drv_info_ctl = SHMEM2_RD(bp, drv_info_control);
3212 /* if drv_info version supported by MFW doesn't match - send NACK */
3213 if ((drv_info_ctl & DRV_INFO_CONTROL_VER_MASK) != DRV_INFO_CUR_VER) {
3214 bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
3218 op_code = (drv_info_ctl & DRV_INFO_CONTROL_OP_CODE_MASK) >>
3219 DRV_INFO_CONTROL_OP_CODE_SHIFT;
3221 memset(&bp->slowpath->drv_info_to_mcp, 0,
3222 sizeof(union drv_info_to_mcp));
3225 case ETH_STATS_OPCODE:
3226 bnx2x_drv_info_ether_stat(bp);
3228 case FCOE_STATS_OPCODE:
3229 bnx2x_drv_info_fcoe_stat(bp);
3231 case ISCSI_STATS_OPCODE:
3232 bnx2x_drv_info_iscsi_stat(bp);
3235 /* if op code isn't supported - send NACK */
3236 bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
3240 /* if we got drv_info attn from MFW then these fields are defined in
3243 SHMEM2_WR(bp, drv_info_host_addr_lo,
3244 U64_LO(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
3245 SHMEM2_WR(bp, drv_info_host_addr_hi,
3246 U64_HI(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
3248 bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_ACK, 0);
3251 static void bnx2x_dcc_event(struct bnx2x *bp, u32 dcc_event)
3253 DP(BNX2X_MSG_MCP, "dcc_event 0x%x\n", dcc_event);
3255 if (dcc_event & DRV_STATUS_DCC_DISABLE_ENABLE_PF) {
3258 * This is the only place besides the function initialization
3259 * where the bp->flags can change so it is done without any
3262 if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
3263 DP(BNX2X_MSG_MCP, "mf_cfg function disabled\n");
3264 bp->flags |= MF_FUNC_DIS;
3266 bnx2x_e1h_disable(bp);
3268 DP(BNX2X_MSG_MCP, "mf_cfg function enabled\n");
3269 bp->flags &= ~MF_FUNC_DIS;
3271 bnx2x_e1h_enable(bp);
3273 dcc_event &= ~DRV_STATUS_DCC_DISABLE_ENABLE_PF;
3275 if (dcc_event & DRV_STATUS_DCC_BANDWIDTH_ALLOCATION) {
3276 bnx2x_config_mf_bw(bp);
3277 dcc_event &= ~DRV_STATUS_DCC_BANDWIDTH_ALLOCATION;
3280 /* Report results to MCP */
3282 bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_FAILURE, 0);
3284 bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_OK, 0);
3287 /* must be called under the spq lock */
3288 static struct eth_spe *bnx2x_sp_get_next(struct bnx2x *bp)
3290 struct eth_spe *next_spe = bp->spq_prod_bd;
3292 if (bp->spq_prod_bd == bp->spq_last_bd) {
3293 bp->spq_prod_bd = bp->spq;
3294 bp->spq_prod_idx = 0;
3295 DP(BNX2X_MSG_SP, "end of spq\n");
3303 /* must be called under the spq lock */
3304 static void bnx2x_sp_prod_update(struct bnx2x *bp)
3306 int func = BP_FUNC(bp);
3309 * Make sure that BD data is updated before writing the producer:
3310 * BD data is written to the memory, the producer is read from the
3311 * memory, thus we need a full memory barrier to ensure the ordering.
3315 REG_WR16(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func),
3321 * bnx2x_is_contextless_ramrod - check if the current command ends on EQ
3323 * @cmd: command to check
3324 * @cmd_type: command type
3326 static bool bnx2x_is_contextless_ramrod(int cmd, int cmd_type)
3328 if ((cmd_type == NONE_CONNECTION_TYPE) ||
3329 (cmd == RAMROD_CMD_ID_ETH_FORWARD_SETUP) ||
3330 (cmd == RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES) ||
3331 (cmd == RAMROD_CMD_ID_ETH_FILTER_RULES) ||
3332 (cmd == RAMROD_CMD_ID_ETH_MULTICAST_RULES) ||
3333 (cmd == RAMROD_CMD_ID_ETH_SET_MAC) ||
3334 (cmd == RAMROD_CMD_ID_ETH_RSS_UPDATE))
3343 * bnx2x_sp_post - place a single command on an SP ring
3345 * @bp: driver handle
3346 * @command: command to place (e.g. SETUP, FILTER_RULES, etc.)
3347 * @cid: SW CID the command is related to
3348 * @data_hi: command private data address (high 32 bits)
3349 * @data_lo: command private data address (low 32 bits)
3350 * @cmd_type: command type (e.g. NONE, ETH)
3352 * SP data is handled as if it's always an address pair, thus data fields are
3353 * not swapped to little endian in upper functions. Instead this function swaps
3354 * data as if it's two u32 fields.
3356 int bnx2x_sp_post(struct bnx2x *bp, int command, int cid,
3357 u32 data_hi, u32 data_lo, int cmd_type)
3359 struct eth_spe *spe;
3361 bool common = bnx2x_is_contextless_ramrod(command, cmd_type);
3363 #ifdef BNX2X_STOP_ON_ERROR
3364 if (unlikely(bp->panic)) {
3365 BNX2X_ERR("Can't post SP when there is panic\n");
3370 spin_lock_bh(&bp->spq_lock);
3373 if (!atomic_read(&bp->eq_spq_left)) {
3374 BNX2X_ERR("BUG! EQ ring full!\n");
3375 spin_unlock_bh(&bp->spq_lock);
3379 } else if (!atomic_read(&bp->cq_spq_left)) {
3380 BNX2X_ERR("BUG! SPQ ring full!\n");
3381 spin_unlock_bh(&bp->spq_lock);
3386 spe = bnx2x_sp_get_next(bp);
3388 /* CID needs port number to be encoded int it */
3389 spe->hdr.conn_and_cmd_data =
3390 cpu_to_le32((command << SPE_HDR_CMD_ID_SHIFT) |
3393 type = (cmd_type << SPE_HDR_CONN_TYPE_SHIFT) & SPE_HDR_CONN_TYPE;
3395 type |= ((BP_FUNC(bp) << SPE_HDR_FUNCTION_ID_SHIFT) &
3396 SPE_HDR_FUNCTION_ID);
3398 spe->hdr.type = cpu_to_le16(type);
3400 spe->data.update_data_addr.hi = cpu_to_le32(data_hi);
3401 spe->data.update_data_addr.lo = cpu_to_le32(data_lo);
3404 * It's ok if the actual decrement is issued towards the memory
3405 * somewhere between the spin_lock and spin_unlock. Thus no
3406 * more explict memory barrier is needed.
3409 atomic_dec(&bp->eq_spq_left);
3411 atomic_dec(&bp->cq_spq_left);
3415 "SPQE[%x] (%x:%x) (cmd, common?) (%d,%d) hw_cid %x data (%x:%x) type(0x%x) left (CQ, EQ) (%x,%x)\n",
3416 bp->spq_prod_idx, (u32)U64_HI(bp->spq_mapping),
3417 (u32)(U64_LO(bp->spq_mapping) +
3418 (void *)bp->spq_prod_bd - (void *)bp->spq), command, common,
3419 HW_CID(bp, cid), data_hi, data_lo, type,
3420 atomic_read(&bp->cq_spq_left), atomic_read(&bp->eq_spq_left));
3422 bnx2x_sp_prod_update(bp);
3423 spin_unlock_bh(&bp->spq_lock);
3427 /* acquire split MCP access lock register */
3428 static int bnx2x_acquire_alr(struct bnx2x *bp)
3434 for (j = 0; j < 1000; j++) {
3436 REG_WR(bp, GRCBASE_MCP + 0x9c, val);
3437 val = REG_RD(bp, GRCBASE_MCP + 0x9c);
3438 if (val & (1L << 31))
3443 if (!(val & (1L << 31))) {
3444 BNX2X_ERR("Cannot acquire MCP access lock register\n");
3451 /* release split MCP access lock register */
3452 static void bnx2x_release_alr(struct bnx2x *bp)
3454 REG_WR(bp, GRCBASE_MCP + 0x9c, 0);
3457 #define BNX2X_DEF_SB_ATT_IDX 0x0001
3458 #define BNX2X_DEF_SB_IDX 0x0002
3460 static u16 bnx2x_update_dsb_idx(struct bnx2x *bp)
3462 struct host_sp_status_block *def_sb = bp->def_status_blk;
3465 barrier(); /* status block is written to by the chip */
3466 if (bp->def_att_idx != def_sb->atten_status_block.attn_bits_index) {
3467 bp->def_att_idx = def_sb->atten_status_block.attn_bits_index;
3468 rc |= BNX2X_DEF_SB_ATT_IDX;
3471 if (bp->def_idx != def_sb->sp_sb.running_index) {
3472 bp->def_idx = def_sb->sp_sb.running_index;
3473 rc |= BNX2X_DEF_SB_IDX;
3476 /* Do not reorder: indecies reading should complete before handling */
3482 * slow path service functions
3485 static void bnx2x_attn_int_asserted(struct bnx2x *bp, u32 asserted)
3487 int port = BP_PORT(bp);
3488 u32 aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
3489 MISC_REG_AEU_MASK_ATTN_FUNC_0;
3490 u32 nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 :
3491 NIG_REG_MASK_INTERRUPT_PORT0;
3496 if (bp->attn_state & asserted)
3497 BNX2X_ERR("IGU ERROR\n");
3499 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
3500 aeu_mask = REG_RD(bp, aeu_addr);
3502 DP(NETIF_MSG_HW, "aeu_mask %x newly asserted %x\n",
3503 aeu_mask, asserted);
3504 aeu_mask &= ~(asserted & 0x3ff);
3505 DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
3507 REG_WR(bp, aeu_addr, aeu_mask);
3508 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
3510 DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
3511 bp->attn_state |= asserted;
3512 DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
3514 if (asserted & ATTN_HARD_WIRED_MASK) {
3515 if (asserted & ATTN_NIG_FOR_FUNC) {
3517 bnx2x_acquire_phy_lock(bp);
3519 /* save nig interrupt mask */
3520 nig_mask = REG_RD(bp, nig_int_mask_addr);
3522 /* If nig_mask is not set, no need to call the update
3526 REG_WR(bp, nig_int_mask_addr, 0);
3528 bnx2x_link_attn(bp);
3531 /* handle unicore attn? */
3533 if (asserted & ATTN_SW_TIMER_4_FUNC)
3534 DP(NETIF_MSG_HW, "ATTN_SW_TIMER_4_FUNC!\n");
3536 if (asserted & GPIO_2_FUNC)
3537 DP(NETIF_MSG_HW, "GPIO_2_FUNC!\n");
3539 if (asserted & GPIO_3_FUNC)
3540 DP(NETIF_MSG_HW, "GPIO_3_FUNC!\n");
3542 if (asserted & GPIO_4_FUNC)
3543 DP(NETIF_MSG_HW, "GPIO_4_FUNC!\n");
3546 if (asserted & ATTN_GENERAL_ATTN_1) {
3547 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_1!\n");
3548 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_1, 0x0);
3550 if (asserted & ATTN_GENERAL_ATTN_2) {
3551 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_2!\n");
3552 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_2, 0x0);
3554 if (asserted & ATTN_GENERAL_ATTN_3) {
3555 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_3!\n");
3556 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_3, 0x0);
3559 if (asserted & ATTN_GENERAL_ATTN_4) {
3560 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_4!\n");
3561 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_4, 0x0);
3563 if (asserted & ATTN_GENERAL_ATTN_5) {
3564 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_5!\n");
3565 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_5, 0x0);
3567 if (asserted & ATTN_GENERAL_ATTN_6) {
3568 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_6!\n");
3569 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_6, 0x0);
3573 } /* if hardwired */
3575 if (bp->common.int_block == INT_BLOCK_HC)
3576 reg_addr = (HC_REG_COMMAND_REG + port*32 +
3577 COMMAND_REG_ATTN_BITS_SET);
3579 reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_SET_UPPER*8);
3581 DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", asserted,
3582 (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
3583 REG_WR(bp, reg_addr, asserted);
3585 /* now set back the mask */
3586 if (asserted & ATTN_NIG_FOR_FUNC) {
3587 REG_WR(bp, nig_int_mask_addr, nig_mask);
3588 bnx2x_release_phy_lock(bp);
3592 static void bnx2x_fan_failure(struct bnx2x *bp)
3594 int port = BP_PORT(bp);
3596 /* mark the failure */
3599 dev_info.port_hw_config[port].external_phy_config);
3601 ext_phy_config &= ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK;
3602 ext_phy_config |= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE;
3603 SHMEM_WR(bp, dev_info.port_hw_config[port].external_phy_config,
3606 /* log the failure */
3607 netdev_err(bp->dev, "Fan Failure on Network Controller has caused the driver to shutdown the card to prevent permanent damage.\n"
3608 "Please contact OEM Support for assistance\n");
3611 * Scheudle device reset (unload)
3612 * This is due to some boards consuming sufficient power when driver is
3613 * up to overheat if fan fails.
3615 smp_mb__before_clear_bit();
3616 set_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state);
3617 smp_mb__after_clear_bit();
3618 schedule_delayed_work(&bp->sp_rtnl_task, 0);
3622 static void bnx2x_attn_int_deasserted0(struct bnx2x *bp, u32 attn)
3624 int port = BP_PORT(bp);
3628 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
3629 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
3631 if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) {
3633 val = REG_RD(bp, reg_offset);
3634 val &= ~AEU_INPUTS_ATTN_BITS_SPIO5;
3635 REG_WR(bp, reg_offset, val);
3637 BNX2X_ERR("SPIO5 hw attention\n");
3639 /* Fan failure attention */
3640 bnx2x_hw_reset_phy(&bp->link_params);
3641 bnx2x_fan_failure(bp);
3644 if ((attn & bp->link_vars.aeu_int_mask) && bp->port.pmf) {
3645 bnx2x_acquire_phy_lock(bp);
3646 bnx2x_handle_module_detect_int(&bp->link_params);
3647 bnx2x_release_phy_lock(bp);
3650 if (attn & HW_INTERRUT_ASSERT_SET_0) {
3652 val = REG_RD(bp, reg_offset);
3653 val &= ~(attn & HW_INTERRUT_ASSERT_SET_0);
3654 REG_WR(bp, reg_offset, val);
3656 BNX2X_ERR("FATAL HW block attention set0 0x%x\n",
3657 (u32)(attn & HW_INTERRUT_ASSERT_SET_0));
3662 static void bnx2x_attn_int_deasserted1(struct bnx2x *bp, u32 attn)
3666 if (attn & AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT) {
3668 val = REG_RD(bp, DORQ_REG_DORQ_INT_STS_CLR);
3669 BNX2X_ERR("DB hw attention 0x%x\n", val);
3670 /* DORQ discard attention */
3672 BNX2X_ERR("FATAL error from DORQ\n");
3675 if (attn & HW_INTERRUT_ASSERT_SET_1) {
3677 int port = BP_PORT(bp);
3680 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 :
3681 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1);
3683 val = REG_RD(bp, reg_offset);
3684 val &= ~(attn & HW_INTERRUT_ASSERT_SET_1);
3685 REG_WR(bp, reg_offset, val);
3687 BNX2X_ERR("FATAL HW block attention set1 0x%x\n",
3688 (u32)(attn & HW_INTERRUT_ASSERT_SET_1));
3693 static void bnx2x_attn_int_deasserted2(struct bnx2x *bp, u32 attn)
3697 if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) {
3699 val = REG_RD(bp, CFC_REG_CFC_INT_STS_CLR);
3700 BNX2X_ERR("CFC hw attention 0x%x\n", val);
3701 /* CFC error attention */
3703 BNX2X_ERR("FATAL error from CFC\n");
3706 if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) {
3707 val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_0);
3708 BNX2X_ERR("PXP hw attention-0 0x%x\n", val);
3709 /* RQ_USDMDP_FIFO_OVERFLOW */
3711 BNX2X_ERR("FATAL error from PXP\n");
3713 if (!CHIP_IS_E1x(bp)) {
3714 val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_1);
3715 BNX2X_ERR("PXP hw attention-1 0x%x\n", val);
3719 if (attn & HW_INTERRUT_ASSERT_SET_2) {
3721 int port = BP_PORT(bp);
3724 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 :
3725 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2);
3727 val = REG_RD(bp, reg_offset);
3728 val &= ~(attn & HW_INTERRUT_ASSERT_SET_2);
3729 REG_WR(bp, reg_offset, val);
3731 BNX2X_ERR("FATAL HW block attention set2 0x%x\n",
3732 (u32)(attn & HW_INTERRUT_ASSERT_SET_2));
3737 static void bnx2x_attn_int_deasserted3(struct bnx2x *bp, u32 attn)
3741 if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) {
3743 if (attn & BNX2X_PMF_LINK_ASSERT) {
3744 int func = BP_FUNC(bp);
3746 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
3747 bnx2x_read_mf_cfg(bp);
3748 bp->mf_config[BP_VN(bp)] = MF_CFG_RD(bp,
3749 func_mf_config[BP_ABS_FUNC(bp)].config);
3751 func_mb[BP_FW_MB_IDX(bp)].drv_status);
3752 if (val & DRV_STATUS_DCC_EVENT_MASK)
3754 (val & DRV_STATUS_DCC_EVENT_MASK));
3756 if (val & DRV_STATUS_SET_MF_BW)
3757 bnx2x_set_mf_bw(bp);
3759 if (val & DRV_STATUS_DRV_INFO_REQ)
3760 bnx2x_handle_drv_info_req(bp);
3761 if ((bp->port.pmf == 0) && (val & DRV_STATUS_PMF))
3762 bnx2x_pmf_update(bp);
3765 (val & DRV_STATUS_DCBX_NEGOTIATION_RESULTS) &&
3766 bp->dcbx_enabled > 0)
3767 /* start dcbx state machine */
3768 bnx2x_dcbx_set_params(bp,
3769 BNX2X_DCBX_STATE_NEG_RECEIVED);
3770 if (val & DRV_STATUS_AFEX_EVENT_MASK)
3771 bnx2x_handle_afex_cmd(bp,
3772 val & DRV_STATUS_AFEX_EVENT_MASK);
3773 if (val & DRV_STATUS_EEE_NEGOTIATION_RESULTS)
3774 bnx2x_handle_eee_event(bp);
3775 if (bp->link_vars.periodic_flags &
3776 PERIODIC_FLAGS_LINK_EVENT) {
3777 /* sync with link */
3778 bnx2x_acquire_phy_lock(bp);
3779 bp->link_vars.periodic_flags &=
3780 ~PERIODIC_FLAGS_LINK_EVENT;
3781 bnx2x_release_phy_lock(bp);
3783 bnx2x_link_sync_notify(bp);
3784 bnx2x_link_report(bp);
3786 /* Always call it here: bnx2x_link_report() will
3787 * prevent the link indication duplication.
3789 bnx2x__link_status_update(bp);
3790 } else if (attn & BNX2X_MC_ASSERT_BITS) {
3792 BNX2X_ERR("MC assert!\n");
3793 bnx2x_mc_assert(bp);
3794 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_10, 0);
3795 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_9, 0);
3796 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_8, 0);
3797 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_7, 0);
3800 } else if (attn & BNX2X_MCP_ASSERT) {
3802 BNX2X_ERR("MCP assert!\n");
3803 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_11, 0);
3807 BNX2X_ERR("Unknown HW assert! (attn 0x%x)\n", attn);
3810 if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) {
3811 BNX2X_ERR("LATCHED attention 0x%08x (masked)\n", attn);
3812 if (attn & BNX2X_GRC_TIMEOUT) {
3813 val = CHIP_IS_E1(bp) ? 0 :
3814 REG_RD(bp, MISC_REG_GRC_TIMEOUT_ATTN);
3815 BNX2X_ERR("GRC time-out 0x%08x\n", val);
3817 if (attn & BNX2X_GRC_RSV) {
3818 val = CHIP_IS_E1(bp) ? 0 :
3819 REG_RD(bp, MISC_REG_GRC_RSV_ATTN);
3820 BNX2X_ERR("GRC reserved 0x%08x\n", val);
3822 REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff);
3828 * 0-7 - Engine0 load counter.
3829 * 8-15 - Engine1 load counter.
3830 * 16 - Engine0 RESET_IN_PROGRESS bit.
3831 * 17 - Engine1 RESET_IN_PROGRESS bit.
3832 * 18 - Engine0 ONE_IS_LOADED. Set when there is at least one active function
3834 * 19 - Engine1 ONE_IS_LOADED.
3835 * 20 - Chip reset flow bit. When set none-leader must wait for both engines
3836 * leader to complete (check for both RESET_IN_PROGRESS bits and not for
3837 * just the one belonging to its engine).
3840 #define BNX2X_RECOVERY_GLOB_REG MISC_REG_GENERIC_POR_1
3842 #define BNX2X_PATH0_LOAD_CNT_MASK 0x000000ff
3843 #define BNX2X_PATH0_LOAD_CNT_SHIFT 0
3844 #define BNX2X_PATH1_LOAD_CNT_MASK 0x0000ff00
3845 #define BNX2X_PATH1_LOAD_CNT_SHIFT 8
3846 #define BNX2X_PATH0_RST_IN_PROG_BIT 0x00010000
3847 #define BNX2X_PATH1_RST_IN_PROG_BIT 0x00020000
3848 #define BNX2X_GLOBAL_RESET_BIT 0x00040000
3851 * Set the GLOBAL_RESET bit.
3853 * Should be run under rtnl lock
3855 void bnx2x_set_reset_global(struct bnx2x *bp)
3858 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
3859 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3860 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val | BNX2X_GLOBAL_RESET_BIT);
3861 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
3865 * Clear the GLOBAL_RESET bit.
3867 * Should be run under rtnl lock
3869 static void bnx2x_clear_reset_global(struct bnx2x *bp)
3872 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
3873 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3874 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~BNX2X_GLOBAL_RESET_BIT));
3875 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
3879 * Checks the GLOBAL_RESET bit.
3881 * should be run under rtnl lock
3883 static bool bnx2x_reset_is_global(struct bnx2x *bp)
3885 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3887 DP(NETIF_MSG_HW, "GEN_REG_VAL=0x%08x\n", val);
3888 return (val & BNX2X_GLOBAL_RESET_BIT) ? true : false;
3892 * Clear RESET_IN_PROGRESS bit for the current engine.
3894 * Should be run under rtnl lock
3896 static void bnx2x_set_reset_done(struct bnx2x *bp)
3899 u32 bit = BP_PATH(bp) ?
3900 BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
3901 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
3902 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3906 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
3908 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
3912 * Set RESET_IN_PROGRESS for the current engine.
3914 * should be run under rtnl lock
3916 void bnx2x_set_reset_in_progress(struct bnx2x *bp)
3919 u32 bit = BP_PATH(bp) ?
3920 BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
3921 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
3922 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3926 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
3927 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
3931 * Checks the RESET_IN_PROGRESS bit for the given engine.
3932 * should be run under rtnl lock
3934 bool bnx2x_reset_is_done(struct bnx2x *bp, int engine)
3936 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3938 BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
3940 /* return false if bit is set */
3941 return (val & bit) ? false : true;
3945 * set pf load for the current pf.
3947 * should be run under rtnl lock
3949 void bnx2x_set_pf_load(struct bnx2x *bp)
3952 u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
3953 BNX2X_PATH0_LOAD_CNT_MASK;
3954 u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
3955 BNX2X_PATH0_LOAD_CNT_SHIFT;
3957 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
3958 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3960 DP(NETIF_MSG_IFUP, "Old GEN_REG_VAL=0x%08x\n", val);
3962 /* get the current counter value */
3963 val1 = (val & mask) >> shift;
3965 /* set bit of that PF */
3966 val1 |= (1 << bp->pf_num);
3968 /* clear the old value */
3971 /* set the new one */
3972 val |= ((val1 << shift) & mask);
3974 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
3975 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
3979 * bnx2x_clear_pf_load - clear pf load mark
3981 * @bp: driver handle
3983 * Should be run under rtnl lock.
3984 * Decrements the load counter for the current engine. Returns
3985 * whether other functions are still loaded
3987 bool bnx2x_clear_pf_load(struct bnx2x *bp)
3990 u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
3991 BNX2X_PATH0_LOAD_CNT_MASK;
3992 u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
3993 BNX2X_PATH0_LOAD_CNT_SHIFT;
3995 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
3996 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3997 DP(NETIF_MSG_IFDOWN, "Old GEN_REG_VAL=0x%08x\n", val);
3999 /* get the current counter value */
4000 val1 = (val & mask) >> shift;
4002 /* clear bit of that PF */
4003 val1 &= ~(1 << bp->pf_num);
4005 /* clear the old value */
4008 /* set the new one */
4009 val |= ((val1 << shift) & mask);
4011 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
4012 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
4017 * Read the load status for the current engine.
4019 * should be run under rtnl lock
4021 static bool bnx2x_get_load_status(struct bnx2x *bp, int engine)
4023 u32 mask = (engine ? BNX2X_PATH1_LOAD_CNT_MASK :
4024 BNX2X_PATH0_LOAD_CNT_MASK);
4025 u32 shift = (engine ? BNX2X_PATH1_LOAD_CNT_SHIFT :
4026 BNX2X_PATH0_LOAD_CNT_SHIFT);
4027 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
4029 DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "GLOB_REG=0x%08x\n", val);
4031 val = (val & mask) >> shift;
4033 DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "load mask for engine %d = 0x%x\n",
4039 static void _print_next_block(int idx, const char *blk)
4041 pr_cont("%s%s", idx ? ", " : "", blk);
4044 static int bnx2x_check_blocks_with_parity0(u32 sig, int par_num,
4049 for (i = 0; sig; i++) {
4050 cur_bit = ((u32)0x1 << i);
4051 if (sig & cur_bit) {
4053 case AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR:
4055 _print_next_block(par_num++, "BRB");
4057 case AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR:
4059 _print_next_block(par_num++, "PARSER");
4061 case AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR:
4063 _print_next_block(par_num++, "TSDM");
4065 case AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR:
4067 _print_next_block(par_num++,
4070 case AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR:
4072 _print_next_block(par_num++, "TCM");
4074 case AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR:
4076 _print_next_block(par_num++, "TSEMI");
4078 case AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR:
4080 _print_next_block(par_num++, "XPB");
4092 static int bnx2x_check_blocks_with_parity1(u32 sig, int par_num,
4093 bool *global, bool print)
4097 for (i = 0; sig; i++) {
4098 cur_bit = ((u32)0x1 << i);
4099 if (sig & cur_bit) {
4101 case AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR:
4103 _print_next_block(par_num++, "PBF");
4105 case AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR:
4107 _print_next_block(par_num++, "QM");
4109 case AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR:
4111 _print_next_block(par_num++, "TM");
4113 case AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR:
4115 _print_next_block(par_num++, "XSDM");
4117 case AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR:
4119 _print_next_block(par_num++, "XCM");
4121 case AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR:
4123 _print_next_block(par_num++, "XSEMI");
4125 case AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR:
4127 _print_next_block(par_num++,
4130 case AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR:
4132 _print_next_block(par_num++, "NIG");
4134 case AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR:
4136 _print_next_block(par_num++,
4140 case AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR:
4142 _print_next_block(par_num++, "DEBUG");
4144 case AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR:
4146 _print_next_block(par_num++, "USDM");
4148 case AEU_INPUTS_ATTN_BITS_UCM_PARITY_ERROR:
4150 _print_next_block(par_num++, "UCM");
4152 case AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR:
4154 _print_next_block(par_num++, "USEMI");
4156 case AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR:
4158 _print_next_block(par_num++, "UPB");
4160 case AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR:
4162 _print_next_block(par_num++, "CSDM");
4164 case AEU_INPUTS_ATTN_BITS_CCM_PARITY_ERROR:
4166 _print_next_block(par_num++, "CCM");
4178 static int bnx2x_check_blocks_with_parity2(u32 sig, int par_num,
4183 for (i = 0; sig; i++) {
4184 cur_bit = ((u32)0x1 << i);
4185 if (sig & cur_bit) {
4187 case AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR:
4189 _print_next_block(par_num++, "CSEMI");
4191 case AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR:
4193 _print_next_block(par_num++, "PXP");
4195 case AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR:
4197 _print_next_block(par_num++,
4198 "PXPPCICLOCKCLIENT");
4200 case AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR:
4202 _print_next_block(par_num++, "CFC");
4204 case AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR:
4206 _print_next_block(par_num++, "CDU");
4208 case AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR:
4210 _print_next_block(par_num++, "DMAE");
4212 case AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR:
4214 _print_next_block(par_num++, "IGU");
4216 case AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR:
4218 _print_next_block(par_num++, "MISC");
4230 static int bnx2x_check_blocks_with_parity3(u32 sig, int par_num,
4231 bool *global, bool print)
4235 for (i = 0; sig; i++) {
4236 cur_bit = ((u32)0x1 << i);
4237 if (sig & cur_bit) {
4239 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY:
4241 _print_next_block(par_num++, "MCP ROM");
4244 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY:
4246 _print_next_block(par_num++,
4250 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY:
4252 _print_next_block(par_num++,
4256 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY:
4258 _print_next_block(par_num++,
4272 static int bnx2x_check_blocks_with_parity4(u32 sig, int par_num,
4277 for (i = 0; sig; i++) {
4278 cur_bit = ((u32)0x1 << i);
4279 if (sig & cur_bit) {
4281 case AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR:
4283 _print_next_block(par_num++, "PGLUE_B");
4285 case AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR:
4287 _print_next_block(par_num++, "ATC");
4299 static bool bnx2x_parity_attn(struct bnx2x *bp, bool *global, bool print,
4302 if ((sig[0] & HW_PRTY_ASSERT_SET_0) ||
4303 (sig[1] & HW_PRTY_ASSERT_SET_1) ||
4304 (sig[2] & HW_PRTY_ASSERT_SET_2) ||
4305 (sig[3] & HW_PRTY_ASSERT_SET_3) ||
4306 (sig[4] & HW_PRTY_ASSERT_SET_4)) {
4308 DP(NETIF_MSG_HW, "Was parity error: HW block parity attention:\n"
4309 "[0]:0x%08x [1]:0x%08x [2]:0x%08x [3]:0x%08x [4]:0x%08x\n",
4310 sig[0] & HW_PRTY_ASSERT_SET_0,
4311 sig[1] & HW_PRTY_ASSERT_SET_1,
4312 sig[2] & HW_PRTY_ASSERT_SET_2,
4313 sig[3] & HW_PRTY_ASSERT_SET_3,
4314 sig[4] & HW_PRTY_ASSERT_SET_4);
4317 "Parity errors detected in blocks: ");
4318 par_num = bnx2x_check_blocks_with_parity0(
4319 sig[0] & HW_PRTY_ASSERT_SET_0, par_num, print);
4320 par_num = bnx2x_check_blocks_with_parity1(
4321 sig[1] & HW_PRTY_ASSERT_SET_1, par_num, global, print);
4322 par_num = bnx2x_check_blocks_with_parity2(
4323 sig[2] & HW_PRTY_ASSERT_SET_2, par_num, print);
4324 par_num = bnx2x_check_blocks_with_parity3(
4325 sig[3] & HW_PRTY_ASSERT_SET_3, par_num, global, print);
4326 par_num = bnx2x_check_blocks_with_parity4(
4327 sig[4] & HW_PRTY_ASSERT_SET_4, par_num, print);
4338 * bnx2x_chk_parity_attn - checks for parity attentions.
4340 * @bp: driver handle
4341 * @global: true if there was a global attention
4342 * @print: show parity attention in syslog
4344 bool bnx2x_chk_parity_attn(struct bnx2x *bp, bool *global, bool print)
4346 struct attn_route attn = { {0} };
4347 int port = BP_PORT(bp);
4349 attn.sig[0] = REG_RD(bp,
4350 MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 +
4352 attn.sig[1] = REG_RD(bp,
4353 MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 +
4355 attn.sig[2] = REG_RD(bp,
4356 MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 +
4358 attn.sig[3] = REG_RD(bp,
4359 MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 +
4362 if (!CHIP_IS_E1x(bp))
4363 attn.sig[4] = REG_RD(bp,
4364 MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 +
4367 return bnx2x_parity_attn(bp, global, print, attn.sig);
4371 static void bnx2x_attn_int_deasserted4(struct bnx2x *bp, u32 attn)
4374 if (attn & AEU_INPUTS_ATTN_BITS_PGLUE_HW_INTERRUPT) {
4376 val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS_CLR);
4377 BNX2X_ERR("PGLUE hw attention 0x%x\n", val);
4378 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR)
4379 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR\n");
4380 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR)
4381 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR\n");
4382 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN)
4383 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN\n");
4384 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN)
4385 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN\n");
4387 PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN)
4388 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN\n");
4390 PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN)
4391 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN\n");
4392 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN)
4393 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN\n");
4394 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN)
4395 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN\n");
4396 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW)
4397 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW\n");
4399 if (attn & AEU_INPUTS_ATTN_BITS_ATC_HW_INTERRUPT) {
4400 val = REG_RD(bp, ATC_REG_ATC_INT_STS_CLR);
4401 BNX2X_ERR("ATC hw attention 0x%x\n", val);
4402 if (val & ATC_ATC_INT_STS_REG_ADDRESS_ERROR)
4403 BNX2X_ERR("ATC_ATC_INT_STS_REG_ADDRESS_ERROR\n");
4404 if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND)
4405 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND\n");
4406 if (val & ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS)
4407 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS\n");
4408 if (val & ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT)
4409 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT\n");
4410 if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR)
4411 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR\n");
4412 if (val & ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU)
4413 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU\n");
4416 if (attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
4417 AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)) {
4418 BNX2X_ERR("FATAL parity attention set4 0x%x\n",
4419 (u32)(attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
4420 AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)));
4425 static void bnx2x_attn_int_deasserted(struct bnx2x *bp, u32 deasserted)
4427 struct attn_route attn, *group_mask;
4428 int port = BP_PORT(bp);
4433 bool global = false;
4435 /* need to take HW lock because MCP or other port might also
4436 try to handle this event */
4437 bnx2x_acquire_alr(bp);
4439 if (bnx2x_chk_parity_attn(bp, &global, true)) {
4440 #ifndef BNX2X_STOP_ON_ERROR
4441 bp->recovery_state = BNX2X_RECOVERY_INIT;
4442 schedule_delayed_work(&bp->sp_rtnl_task, 0);
4443 /* Disable HW interrupts */
4444 bnx2x_int_disable(bp);
4445 /* In case of parity errors don't handle attentions so that
4446 * other function would "see" parity errors.
4451 bnx2x_release_alr(bp);
4455 attn.sig[0] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4);
4456 attn.sig[1] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4);
4457 attn.sig[2] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4);
4458 attn.sig[3] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4);
4459 if (!CHIP_IS_E1x(bp))
4461 REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + port*4);
4465 DP(NETIF_MSG_HW, "attn: %08x %08x %08x %08x %08x\n",
4466 attn.sig[0], attn.sig[1], attn.sig[2], attn.sig[3], attn.sig[4]);
4468 for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
4469 if (deasserted & (1 << index)) {
4470 group_mask = &bp->attn_group[index];
4472 DP(NETIF_MSG_HW, "group[%d]: %08x %08x %08x %08x %08x\n",
4474 group_mask->sig[0], group_mask->sig[1],
4475 group_mask->sig[2], group_mask->sig[3],
4476 group_mask->sig[4]);
4478 bnx2x_attn_int_deasserted4(bp,
4479 attn.sig[4] & group_mask->sig[4]);
4480 bnx2x_attn_int_deasserted3(bp,
4481 attn.sig[3] & group_mask->sig[3]);
4482 bnx2x_attn_int_deasserted1(bp,
4483 attn.sig[1] & group_mask->sig[1]);
4484 bnx2x_attn_int_deasserted2(bp,
4485 attn.sig[2] & group_mask->sig[2]);
4486 bnx2x_attn_int_deasserted0(bp,
4487 attn.sig[0] & group_mask->sig[0]);
4491 bnx2x_release_alr(bp);
4493 if (bp->common.int_block == INT_BLOCK_HC)
4494 reg_addr = (HC_REG_COMMAND_REG + port*32 +
4495 COMMAND_REG_ATTN_BITS_CLR);
4497 reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_CLR_UPPER*8);
4500 DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", val,
4501 (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
4502 REG_WR(bp, reg_addr, val);
4504 if (~bp->attn_state & deasserted)
4505 BNX2X_ERR("IGU ERROR\n");
4507 reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
4508 MISC_REG_AEU_MASK_ATTN_FUNC_0;
4510 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
4511 aeu_mask = REG_RD(bp, reg_addr);
4513 DP(NETIF_MSG_HW, "aeu_mask %x newly deasserted %x\n",
4514 aeu_mask, deasserted);
4515 aeu_mask |= (deasserted & 0x3ff);
4516 DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
4518 REG_WR(bp, reg_addr, aeu_mask);
4519 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
4521 DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
4522 bp->attn_state &= ~deasserted;
4523 DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
4526 static void bnx2x_attn_int(struct bnx2x *bp)
4528 /* read local copy of bits */
4529 u32 attn_bits = le32_to_cpu(bp->def_status_blk->atten_status_block.
4531 u32 attn_ack = le32_to_cpu(bp->def_status_blk->atten_status_block.
4533 u32 attn_state = bp->attn_state;
4535 /* look for changed bits */
4536 u32 asserted = attn_bits & ~attn_ack & ~attn_state;
4537 u32 deasserted = ~attn_bits & attn_ack & attn_state;
4540 "attn_bits %x attn_ack %x asserted %x deasserted %x\n",
4541 attn_bits, attn_ack, asserted, deasserted);
4543 if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state))
4544 BNX2X_ERR("BAD attention state\n");
4546 /* handle bits that were raised */
4548 bnx2x_attn_int_asserted(bp, asserted);
4551 bnx2x_attn_int_deasserted(bp, deasserted);
4554 void bnx2x_igu_ack_sb(struct bnx2x *bp, u8 igu_sb_id, u8 segment,
4555 u16 index, u8 op, u8 update)
4557 u32 igu_addr = BAR_IGU_INTMEM + (IGU_CMD_INT_ACK_BASE + igu_sb_id)*8;
4559 bnx2x_igu_ack_sb_gen(bp, igu_sb_id, segment, index, op, update,
4563 static void bnx2x_update_eq_prod(struct bnx2x *bp, u16 prod)
4565 /* No memory barriers */
4566 storm_memset_eq_prod(bp, prod, BP_FUNC(bp));
4567 mmiowb(); /* keep prod updates ordered */
4571 static int bnx2x_cnic_handle_cfc_del(struct bnx2x *bp, u32 cid,
4572 union event_ring_elem *elem)
4574 u8 err = elem->message.error;
4576 if (!bp->cnic_eth_dev.starting_cid ||
4577 (cid < bp->cnic_eth_dev.starting_cid &&
4578 cid != bp->cnic_eth_dev.iscsi_l2_cid))
4581 DP(BNX2X_MSG_SP, "got delete ramrod for CNIC CID %d\n", cid);
4583 if (unlikely(err)) {
4585 BNX2X_ERR("got delete ramrod for CNIC CID %d with error!\n",
4587 bnx2x_panic_dump(bp);
4589 bnx2x_cnic_cfc_comp(bp, cid, err);
4594 static void bnx2x_handle_mcast_eqe(struct bnx2x *bp)
4596 struct bnx2x_mcast_ramrod_params rparam;
4599 memset(&rparam, 0, sizeof(rparam));
4601 rparam.mcast_obj = &bp->mcast_obj;
4603 netif_addr_lock_bh(bp->dev);
4605 /* Clear pending state for the last command */
4606 bp->mcast_obj.raw.clear_pending(&bp->mcast_obj.raw);
4608 /* If there are pending mcast commands - send them */
4609 if (bp->mcast_obj.check_pending(&bp->mcast_obj)) {
4610 rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_CONT);
4612 BNX2X_ERR("Failed to send pending mcast commands: %d\n",
4616 netif_addr_unlock_bh(bp->dev);
4619 static void bnx2x_handle_classification_eqe(struct bnx2x *bp,
4620 union event_ring_elem *elem)
4622 unsigned long ramrod_flags = 0;
4624 u32 cid = elem->message.data.eth_event.echo & BNX2X_SWCID_MASK;
4625 struct bnx2x_vlan_mac_obj *vlan_mac_obj;
4627 /* Always push next commands out, don't wait here */
4628 __set_bit(RAMROD_CONT, &ramrod_flags);
4630 switch (elem->message.data.eth_event.echo >> BNX2X_SWCID_SHIFT) {
4631 case BNX2X_FILTER_MAC_PENDING:
4632 DP(BNX2X_MSG_SP, "Got SETUP_MAC completions\n");
4634 if (cid == BNX2X_ISCSI_ETH_CID(bp))
4635 vlan_mac_obj = &bp->iscsi_l2_mac_obj;
4638 vlan_mac_obj = &bp->sp_objs[cid].mac_obj;
4641 case BNX2X_FILTER_MCAST_PENDING:
4642 DP(BNX2X_MSG_SP, "Got SETUP_MCAST completions\n");
4643 /* This is only relevant for 57710 where multicast MACs are
4644 * configured as unicast MACs using the same ramrod.
4646 bnx2x_handle_mcast_eqe(bp);
4649 BNX2X_ERR("Unsupported classification command: %d\n",
4650 elem->message.data.eth_event.echo);
4654 rc = vlan_mac_obj->complete(bp, vlan_mac_obj, elem, &ramrod_flags);
4657 BNX2X_ERR("Failed to schedule new commands: %d\n", rc);
4659 DP(BNX2X_MSG_SP, "Scheduled next pending commands...\n");
4664 static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start);
4667 static void bnx2x_handle_rx_mode_eqe(struct bnx2x *bp)
4669 netif_addr_lock_bh(bp->dev);
4671 clear_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
4673 /* Send rx_mode command again if was requested */
4674 if (test_and_clear_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state))
4675 bnx2x_set_storm_rx_mode(bp);
4677 else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED,
4679 bnx2x_set_iscsi_eth_rx_mode(bp, true);
4680 else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED,
4682 bnx2x_set_iscsi_eth_rx_mode(bp, false);
4685 netif_addr_unlock_bh(bp->dev);
4688 static void bnx2x_after_afex_vif_lists(struct bnx2x *bp,
4689 union event_ring_elem *elem)
4691 if (elem->message.data.vif_list_event.echo == VIF_LIST_RULE_GET) {
4693 "afex: ramrod completed VIF LIST_GET, addrs 0x%x\n",
4694 elem->message.data.vif_list_event.func_bit_map);
4695 bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTGET_ACK,
4696 elem->message.data.vif_list_event.func_bit_map);
4697 } else if (elem->message.data.vif_list_event.echo ==
4698 VIF_LIST_RULE_SET) {
4699 DP(BNX2X_MSG_SP, "afex: ramrod completed VIF LIST_SET\n");
4700 bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTSET_ACK, 0);
4704 /* called with rtnl_lock */
4705 static void bnx2x_after_function_update(struct bnx2x *bp)
4708 struct bnx2x_fastpath *fp;
4709 struct bnx2x_queue_state_params queue_params = {NULL};
4710 struct bnx2x_queue_update_params *q_update_params =
4711 &queue_params.params.update;
4713 /* Send Q update command with afex vlan removal values for all Qs */
4714 queue_params.cmd = BNX2X_Q_CMD_UPDATE;
4716 /* set silent vlan removal values according to vlan mode */
4717 __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM_CHNG,
4718 &q_update_params->update_flags);
4719 __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM,
4720 &q_update_params->update_flags);
4721 __set_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
4723 /* in access mode mark mask and value are 0 to strip all vlans */
4724 if (bp->afex_vlan_mode == FUNC_MF_CFG_AFEX_VLAN_ACCESS_MODE) {
4725 q_update_params->silent_removal_value = 0;
4726 q_update_params->silent_removal_mask = 0;
4728 q_update_params->silent_removal_value =
4729 (bp->afex_def_vlan_tag & VLAN_VID_MASK);
4730 q_update_params->silent_removal_mask = VLAN_VID_MASK;
4733 for_each_eth_queue(bp, q) {
4734 /* Set the appropriate Queue object */
4736 queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
4738 /* send the ramrod */
4739 rc = bnx2x_queue_state_change(bp, &queue_params);
4741 BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
4747 fp = &bp->fp[FCOE_IDX(bp)];
4748 queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
4750 /* clear pending completion bit */
4751 __clear_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
4753 /* mark latest Q bit */
4754 smp_mb__before_clear_bit();
4755 set_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
4756 smp_mb__after_clear_bit();
4758 /* send Q update ramrod for FCoE Q */
4759 rc = bnx2x_queue_state_change(bp, &queue_params);
4761 BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
4764 /* If no FCoE ring - ACK MCP now */
4765 bnx2x_link_report(bp);
4766 bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
4769 /* If no FCoE ring - ACK MCP now */
4770 bnx2x_link_report(bp);
4771 bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
4772 #endif /* BCM_CNIC */
4775 static struct bnx2x_queue_sp_obj *bnx2x_cid_to_q_obj(
4776 struct bnx2x *bp, u32 cid)
4778 DP(BNX2X_MSG_SP, "retrieving fp from cid %d\n", cid);
4780 if (cid == BNX2X_FCOE_ETH_CID(bp))
4781 return &bnx2x_fcoe_sp_obj(bp, q_obj);
4784 return &bp->sp_objs[CID_TO_FP(cid, bp)].q_obj;
4787 static void bnx2x_eq_int(struct bnx2x *bp)
4789 u16 hw_cons, sw_cons, sw_prod;
4790 union event_ring_elem *elem;
4794 struct bnx2x_queue_sp_obj *q_obj;
4795 struct bnx2x_func_sp_obj *f_obj = &bp->func_obj;
4796 struct bnx2x_raw_obj *rss_raw = &bp->rss_conf_obj.raw;
4798 hw_cons = le16_to_cpu(*bp->eq_cons_sb);
4800 /* The hw_cos range is 1-255, 257 - the sw_cons range is 0-254, 256.
4801 * when we get the the next-page we nned to adjust so the loop
4802 * condition below will be met. The next element is the size of a
4803 * regular element and hence incrementing by 1
4805 if ((hw_cons & EQ_DESC_MAX_PAGE) == EQ_DESC_MAX_PAGE)
4808 /* This function may never run in parallel with itself for a
4809 * specific bp, thus there is no need in "paired" read memory
4812 sw_cons = bp->eq_cons;
4813 sw_prod = bp->eq_prod;
4815 DP(BNX2X_MSG_SP, "EQ: hw_cons %u sw_cons %u bp->eq_spq_left %x\n",
4816 hw_cons, sw_cons, atomic_read(&bp->eq_spq_left));
4818 for (; sw_cons != hw_cons;
4819 sw_prod = NEXT_EQ_IDX(sw_prod), sw_cons = NEXT_EQ_IDX(sw_cons)) {
4822 elem = &bp->eq_ring[EQ_DESC(sw_cons)];
4824 cid = SW_CID(elem->message.data.cfc_del_event.cid);
4825 opcode = elem->message.opcode;
4828 /* handle eq element */
4830 case EVENT_RING_OPCODE_STAT_QUERY:
4831 DP(BNX2X_MSG_SP | BNX2X_MSG_STATS,
4832 "got statistics comp event %d\n",
4834 /* nothing to do with stats comp */
4837 case EVENT_RING_OPCODE_CFC_DEL:
4838 /* handle according to cid range */
4840 * we may want to verify here that the bp state is
4844 "got delete ramrod for MULTI[%d]\n", cid);
4846 if (!bnx2x_cnic_handle_cfc_del(bp, cid, elem))
4849 q_obj = bnx2x_cid_to_q_obj(bp, cid);
4851 if (q_obj->complete_cmd(bp, q_obj, BNX2X_Q_CMD_CFC_DEL))
4858 case EVENT_RING_OPCODE_STOP_TRAFFIC:
4859 DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got STOP TRAFFIC\n");
4860 if (f_obj->complete_cmd(bp, f_obj,
4861 BNX2X_F_CMD_TX_STOP))
4863 bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_PAUSED);
4866 case EVENT_RING_OPCODE_START_TRAFFIC:
4867 DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got START TRAFFIC\n");
4868 if (f_obj->complete_cmd(bp, f_obj,
4869 BNX2X_F_CMD_TX_START))
4871 bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_RELEASED);
4873 case EVENT_RING_OPCODE_FUNCTION_UPDATE:
4874 DP(BNX2X_MSG_SP | BNX2X_MSG_MCP,
4875 "AFEX: ramrod completed FUNCTION_UPDATE\n");
4876 f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_AFEX_UPDATE);
4878 /* We will perform the Queues update from sp_rtnl task
4879 * as all Queue SP operations should run under
4882 smp_mb__before_clear_bit();
4883 set_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE,
4884 &bp->sp_rtnl_state);
4885 smp_mb__after_clear_bit();
4887 schedule_delayed_work(&bp->sp_rtnl_task, 0);
4890 case EVENT_RING_OPCODE_AFEX_VIF_LISTS:
4891 f_obj->complete_cmd(bp, f_obj,
4892 BNX2X_F_CMD_AFEX_VIFLISTS);
4893 bnx2x_after_afex_vif_lists(bp, elem);
4895 case EVENT_RING_OPCODE_FUNCTION_START:
4896 DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
4897 "got FUNC_START ramrod\n");
4898 if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_START))
4903 case EVENT_RING_OPCODE_FUNCTION_STOP:
4904 DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
4905 "got FUNC_STOP ramrod\n");
4906 if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_STOP))
4912 switch (opcode | bp->state) {
4913 case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
4915 case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
4916 BNX2X_STATE_OPENING_WAIT4_PORT):
4917 cid = elem->message.data.eth_event.echo &
4919 DP(BNX2X_MSG_SP, "got RSS_UPDATE ramrod. CID %d\n",
4921 rss_raw->clear_pending(rss_raw);
4924 case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_OPEN):
4925 case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_DIAG):
4926 case (EVENT_RING_OPCODE_SET_MAC |
4927 BNX2X_STATE_CLOSING_WAIT4_HALT):
4928 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
4930 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
4932 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
4933 BNX2X_STATE_CLOSING_WAIT4_HALT):
4934 DP(BNX2X_MSG_SP, "got (un)set mac ramrod\n");
4935 bnx2x_handle_classification_eqe(bp, elem);
4938 case (EVENT_RING_OPCODE_MULTICAST_RULES |
4940 case (EVENT_RING_OPCODE_MULTICAST_RULES |
4942 case (EVENT_RING_OPCODE_MULTICAST_RULES |
4943 BNX2X_STATE_CLOSING_WAIT4_HALT):
4944 DP(BNX2X_MSG_SP, "got mcast ramrod\n");
4945 bnx2x_handle_mcast_eqe(bp);
4948 case (EVENT_RING_OPCODE_FILTERS_RULES |
4950 case (EVENT_RING_OPCODE_FILTERS_RULES |
4952 case (EVENT_RING_OPCODE_FILTERS_RULES |
4953 BNX2X_STATE_CLOSING_WAIT4_HALT):
4954 DP(BNX2X_MSG_SP, "got rx_mode ramrod\n");
4955 bnx2x_handle_rx_mode_eqe(bp);
4958 /* unknown event log error and continue */
4959 BNX2X_ERR("Unknown EQ event %d, bp->state 0x%x\n",
4960 elem->message.opcode, bp->state);
4966 smp_mb__before_atomic_inc();
4967 atomic_add(spqe_cnt, &bp->eq_spq_left);
4969 bp->eq_cons = sw_cons;
4970 bp->eq_prod = sw_prod;
4971 /* Make sure that above mem writes were issued towards the memory */
4974 /* update producer */
4975 bnx2x_update_eq_prod(bp, bp->eq_prod);
4978 static void bnx2x_sp_task(struct work_struct *work)
4980 struct bnx2x *bp = container_of(work, struct bnx2x, sp_task.work);
4983 status = bnx2x_update_dsb_idx(bp);
4984 /* if (status == 0) */
4985 /* BNX2X_ERR("spurious slowpath interrupt!\n"); */
4987 DP(BNX2X_MSG_SP, "got a slowpath interrupt (status 0x%x)\n", status);
4990 if (status & BNX2X_DEF_SB_ATT_IDX) {
4992 status &= ~BNX2X_DEF_SB_ATT_IDX;
4995 /* SP events: STAT_QUERY and others */
4996 if (status & BNX2X_DEF_SB_IDX) {
4998 struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);
5000 if ((!NO_FCOE(bp)) &&
5001 (bnx2x_has_rx_work(fp) || bnx2x_has_tx_work(fp))) {
5003 * Prevent local bottom-halves from running as
5004 * we are going to change the local NAPI list.
5007 napi_schedule(&bnx2x_fcoe(bp, napi));
5011 /* Handle EQ completions */
5014 bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID,
5015 le16_to_cpu(bp->def_idx), IGU_INT_NOP, 1);
5017 status &= ~BNX2X_DEF_SB_IDX;
5020 if (unlikely(status))
5021 DP(BNX2X_MSG_SP, "got an unknown interrupt! (status 0x%x)\n",
5024 bnx2x_ack_sb(bp, bp->igu_dsb_id, ATTENTION_ID,
5025 le16_to_cpu(bp->def_att_idx), IGU_INT_ENABLE, 1);
5027 /* afex - poll to check if VIFSET_ACK should be sent to MFW */
5028 if (test_and_clear_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK,
5030 bnx2x_link_report(bp);
5031 bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
5035 irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance)
5037 struct net_device *dev = dev_instance;
5038 struct bnx2x *bp = netdev_priv(dev);
5040 bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0,
5041 IGU_INT_DISABLE, 0);
5043 #ifdef BNX2X_STOP_ON_ERROR
5044 if (unlikely(bp->panic))
5050 struct cnic_ops *c_ops;
5053 c_ops = rcu_dereference(bp->cnic_ops);
5055 c_ops->cnic_handler(bp->cnic_data, NULL);
5059 queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
5064 /* end of slow path */
5067 void bnx2x_drv_pulse(struct bnx2x *bp)
5069 SHMEM_WR(bp, func_mb[BP_FW_MB_IDX(bp)].drv_pulse_mb,
5070 bp->fw_drv_pulse_wr_seq);
5074 static void bnx2x_timer(unsigned long data)
5076 struct bnx2x *bp = (struct bnx2x *) data;
5078 if (!netif_running(bp->dev))
5081 if (!BP_NOMCP(bp)) {
5082 int mb_idx = BP_FW_MB_IDX(bp);
5086 ++bp->fw_drv_pulse_wr_seq;
5087 bp->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK;
5088 /* TBD - add SYSTEM_TIME */
5089 drv_pulse = bp->fw_drv_pulse_wr_seq;
5090 bnx2x_drv_pulse(bp);
5092 mcp_pulse = (SHMEM_RD(bp, func_mb[mb_idx].mcp_pulse_mb) &
5093 MCP_PULSE_SEQ_MASK);
5094 /* The delta between driver pulse and mcp response
5095 * should be 1 (before mcp response) or 0 (after mcp response)
5097 if ((drv_pulse != mcp_pulse) &&
5098 (drv_pulse != ((mcp_pulse + 1) & MCP_PULSE_SEQ_MASK))) {
5099 /* someone lost a heartbeat... */
5100 BNX2X_ERR("drv_pulse (0x%x) != mcp_pulse (0x%x)\n",
5101 drv_pulse, mcp_pulse);
5105 if (bp->state == BNX2X_STATE_OPEN)
5106 bnx2x_stats_handle(bp, STATS_EVENT_UPDATE);
5108 mod_timer(&bp->timer, jiffies + bp->current_interval);
5111 /* end of Statistics */
5116 * nic init service functions
5119 static void bnx2x_fill(struct bnx2x *bp, u32 addr, int fill, u32 len)
5122 if (!(len%4) && !(addr%4))
5123 for (i = 0; i < len; i += 4)
5124 REG_WR(bp, addr + i, fill);
5126 for (i = 0; i < len; i++)
5127 REG_WR8(bp, addr + i, fill);
5131 /* helper: writes FP SP data to FW - data_size in dwords */
5132 static void bnx2x_wr_fp_sb_data(struct bnx2x *bp,
5138 for (index = 0; index < data_size; index++)
5139 REG_WR(bp, BAR_CSTRORM_INTMEM +
5140 CSTORM_STATUS_BLOCK_DATA_OFFSET(fw_sb_id) +
5142 *(sb_data_p + index));
5145 static void bnx2x_zero_fp_sb(struct bnx2x *bp, int fw_sb_id)
5149 struct hc_status_block_data_e2 sb_data_e2;
5150 struct hc_status_block_data_e1x sb_data_e1x;
5152 /* disable the function first */
5153 if (!CHIP_IS_E1x(bp)) {
5154 memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
5155 sb_data_e2.common.state = SB_DISABLED;
5156 sb_data_e2.common.p_func.vf_valid = false;
5157 sb_data_p = (u32 *)&sb_data_e2;
5158 data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
5160 memset(&sb_data_e1x, 0,
5161 sizeof(struct hc_status_block_data_e1x));
5162 sb_data_e1x.common.state = SB_DISABLED;
5163 sb_data_e1x.common.p_func.vf_valid = false;
5164 sb_data_p = (u32 *)&sb_data_e1x;
5165 data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
5167 bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
5169 bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
5170 CSTORM_STATUS_BLOCK_OFFSET(fw_sb_id), 0,
5171 CSTORM_STATUS_BLOCK_SIZE);
5172 bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
5173 CSTORM_SYNC_BLOCK_OFFSET(fw_sb_id), 0,
5174 CSTORM_SYNC_BLOCK_SIZE);
5177 /* helper: writes SP SB data to FW */
5178 static void bnx2x_wr_sp_sb_data(struct bnx2x *bp,
5179 struct hc_sp_status_block_data *sp_sb_data)
5181 int func = BP_FUNC(bp);
5183 for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
5184 REG_WR(bp, BAR_CSTRORM_INTMEM +
5185 CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
5187 *((u32 *)sp_sb_data + i));
5190 static void bnx2x_zero_sp_sb(struct bnx2x *bp)
5192 int func = BP_FUNC(bp);
5193 struct hc_sp_status_block_data sp_sb_data;
5194 memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
5196 sp_sb_data.state = SB_DISABLED;
5197 sp_sb_data.p_func.vf_valid = false;
5199 bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
5201 bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
5202 CSTORM_SP_STATUS_BLOCK_OFFSET(func), 0,
5203 CSTORM_SP_STATUS_BLOCK_SIZE);
5204 bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
5205 CSTORM_SP_SYNC_BLOCK_OFFSET(func), 0,
5206 CSTORM_SP_SYNC_BLOCK_SIZE);
5211 static void bnx2x_setup_ndsb_state_machine(struct hc_status_block_sm *hc_sm,
5212 int igu_sb_id, int igu_seg_id)
5214 hc_sm->igu_sb_id = igu_sb_id;
5215 hc_sm->igu_seg_id = igu_seg_id;
5216 hc_sm->timer_value = 0xFF;
5217 hc_sm->time_to_expire = 0xFFFFFFFF;
5221 /* allocates state machine ids. */
5222 static void bnx2x_map_sb_state_machines(struct hc_index_data *index_data)
5224 /* zero out state machine indices */
5226 index_data[HC_INDEX_ETH_RX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
5229 index_data[HC_INDEX_OOO_TX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
5230 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags &= ~HC_INDEX_DATA_SM_ID;
5231 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags &= ~HC_INDEX_DATA_SM_ID;
5232 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags &= ~HC_INDEX_DATA_SM_ID;
5236 index_data[HC_INDEX_ETH_RX_CQ_CONS].flags |=
5237 SM_RX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
5240 index_data[HC_INDEX_OOO_TX_CQ_CONS].flags |=
5241 SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
5242 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags |=
5243 SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
5244 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags |=
5245 SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
5246 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags |=
5247 SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
5250 static void bnx2x_init_sb(struct bnx2x *bp, dma_addr_t mapping, int vfid,
5251 u8 vf_valid, int fw_sb_id, int igu_sb_id)
5255 struct hc_status_block_data_e2 sb_data_e2;
5256 struct hc_status_block_data_e1x sb_data_e1x;
5257 struct hc_status_block_sm *hc_sm_p;
5261 if (CHIP_INT_MODE_IS_BC(bp))
5262 igu_seg_id = HC_SEG_ACCESS_NORM;
5264 igu_seg_id = IGU_SEG_ACCESS_NORM;
5266 bnx2x_zero_fp_sb(bp, fw_sb_id);
5268 if (!CHIP_IS_E1x(bp)) {
5269 memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
5270 sb_data_e2.common.state = SB_ENABLED;
5271 sb_data_e2.common.p_func.pf_id = BP_FUNC(bp);
5272 sb_data_e2.common.p_func.vf_id = vfid;
5273 sb_data_e2.common.p_func.vf_valid = vf_valid;
5274 sb_data_e2.common.p_func.vnic_id = BP_VN(bp);
5275 sb_data_e2.common.same_igu_sb_1b = true;
5276 sb_data_e2.common.host_sb_addr.hi = U64_HI(mapping);
5277 sb_data_e2.common.host_sb_addr.lo = U64_LO(mapping);
5278 hc_sm_p = sb_data_e2.common.state_machine;
5279 sb_data_p = (u32 *)&sb_data_e2;
5280 data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
5281 bnx2x_map_sb_state_machines(sb_data_e2.index_data);
5283 memset(&sb_data_e1x, 0,
5284 sizeof(struct hc_status_block_data_e1x));
5285 sb_data_e1x.common.state = SB_ENABLED;
5286 sb_data_e1x.common.p_func.pf_id = BP_FUNC(bp);
5287 sb_data_e1x.common.p_func.vf_id = 0xff;
5288 sb_data_e1x.common.p_func.vf_valid = false;
5289 sb_data_e1x.common.p_func.vnic_id = BP_VN(bp);
5290 sb_data_e1x.common.same_igu_sb_1b = true;
5291 sb_data_e1x.common.host_sb_addr.hi = U64_HI(mapping);
5292 sb_data_e1x.common.host_sb_addr.lo = U64_LO(mapping);
5293 hc_sm_p = sb_data_e1x.common.state_machine;
5294 sb_data_p = (u32 *)&sb_data_e1x;
5295 data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
5296 bnx2x_map_sb_state_machines(sb_data_e1x.index_data);
5299 bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_RX_ID],
5300 igu_sb_id, igu_seg_id);
5301 bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_TX_ID],
5302 igu_sb_id, igu_seg_id);
5304 DP(NETIF_MSG_IFUP, "Init FW SB %d\n", fw_sb_id);
5306 /* write indecies to HW */
5307 bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
5310 static void bnx2x_update_coalesce_sb(struct bnx2x *bp, u8 fw_sb_id,
5311 u16 tx_usec, u16 rx_usec)
5313 bnx2x_update_coalesce_sb_index(bp, fw_sb_id, HC_INDEX_ETH_RX_CQ_CONS,
5315 bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
5316 HC_INDEX_ETH_TX_CQ_CONS_COS0, false,
5318 bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
5319 HC_INDEX_ETH_TX_CQ_CONS_COS1, false,
5321 bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
5322 HC_INDEX_ETH_TX_CQ_CONS_COS2, false,
5326 static void bnx2x_init_def_sb(struct bnx2x *bp)
5328 struct host_sp_status_block *def_sb = bp->def_status_blk;
5329 dma_addr_t mapping = bp->def_status_blk_mapping;
5330 int igu_sp_sb_index;
5332 int port = BP_PORT(bp);
5333 int func = BP_FUNC(bp);
5334 int reg_offset, reg_offset_en5;
5337 struct hc_sp_status_block_data sp_sb_data;
5338 memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
5340 if (CHIP_INT_MODE_IS_BC(bp)) {
5341 igu_sp_sb_index = DEF_SB_IGU_ID;
5342 igu_seg_id = HC_SEG_ACCESS_DEF;
5344 igu_sp_sb_index = bp->igu_dsb_id;
5345 igu_seg_id = IGU_SEG_ACCESS_DEF;
5349 section = ((u64)mapping) + offsetof(struct host_sp_status_block,
5350 atten_status_block);
5351 def_sb->atten_status_block.status_block_id = igu_sp_sb_index;
5355 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
5356 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
5357 reg_offset_en5 = (port ? MISC_REG_AEU_ENABLE5_FUNC_1_OUT_0 :
5358 MISC_REG_AEU_ENABLE5_FUNC_0_OUT_0);
5359 for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
5361 /* take care of sig[0]..sig[4] */
5362 for (sindex = 0; sindex < 4; sindex++)
5363 bp->attn_group[index].sig[sindex] =
5364 REG_RD(bp, reg_offset + sindex*0x4 + 0x10*index);
5366 if (!CHIP_IS_E1x(bp))
5368 * enable5 is separate from the rest of the registers,
5369 * and therefore the address skip is 4
5370 * and not 16 between the different groups
5372 bp->attn_group[index].sig[4] = REG_RD(bp,
5373 reg_offset_en5 + 0x4*index);
5375 bp->attn_group[index].sig[4] = 0;
5378 if (bp->common.int_block == INT_BLOCK_HC) {
5379 reg_offset = (port ? HC_REG_ATTN_MSG1_ADDR_L :
5380 HC_REG_ATTN_MSG0_ADDR_L);
5382 REG_WR(bp, reg_offset, U64_LO(section));
5383 REG_WR(bp, reg_offset + 4, U64_HI(section));
5384 } else if (!CHIP_IS_E1x(bp)) {
5385 REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_L, U64_LO(section));
5386 REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_H, U64_HI(section));
5389 section = ((u64)mapping) + offsetof(struct host_sp_status_block,
5392 bnx2x_zero_sp_sb(bp);
5394 sp_sb_data.state = SB_ENABLED;
5395 sp_sb_data.host_sb_addr.lo = U64_LO(section);
5396 sp_sb_data.host_sb_addr.hi = U64_HI(section);
5397 sp_sb_data.igu_sb_id = igu_sp_sb_index;
5398 sp_sb_data.igu_seg_id = igu_seg_id;
5399 sp_sb_data.p_func.pf_id = func;
5400 sp_sb_data.p_func.vnic_id = BP_VN(bp);
5401 sp_sb_data.p_func.vf_id = 0xff;
5403 bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
5405 bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0, IGU_INT_ENABLE, 0);
5408 void bnx2x_update_coalesce(struct bnx2x *bp)
5412 for_each_eth_queue(bp, i)
5413 bnx2x_update_coalesce_sb(bp, bp->fp[i].fw_sb_id,
5414 bp->tx_ticks, bp->rx_ticks);
5417 static void bnx2x_init_sp_ring(struct bnx2x *bp)
5419 spin_lock_init(&bp->spq_lock);
5420 atomic_set(&bp->cq_spq_left, MAX_SPQ_PENDING);
5422 bp->spq_prod_idx = 0;
5423 bp->dsb_sp_prod = BNX2X_SP_DSB_INDEX;
5424 bp->spq_prod_bd = bp->spq;
5425 bp->spq_last_bd = bp->spq_prod_bd + MAX_SP_DESC_CNT;
5428 static void bnx2x_init_eq_ring(struct bnx2x *bp)
5431 for (i = 1; i <= NUM_EQ_PAGES; i++) {
5432 union event_ring_elem *elem =
5433 &bp->eq_ring[EQ_DESC_CNT_PAGE * i - 1];
5435 elem->next_page.addr.hi =
5436 cpu_to_le32(U64_HI(bp->eq_mapping +
5437 BCM_PAGE_SIZE * (i % NUM_EQ_PAGES)));
5438 elem->next_page.addr.lo =
5439 cpu_to_le32(U64_LO(bp->eq_mapping +
5440 BCM_PAGE_SIZE*(i % NUM_EQ_PAGES)));
5443 bp->eq_prod = NUM_EQ_DESC;
5444 bp->eq_cons_sb = BNX2X_EQ_INDEX;
5445 /* we want a warning message before it gets rought... */
5446 atomic_set(&bp->eq_spq_left,
5447 min_t(int, MAX_SP_DESC_CNT - MAX_SPQ_PENDING, NUM_EQ_DESC) - 1);
5451 /* called with netif_addr_lock_bh() */
5452 void bnx2x_set_q_rx_mode(struct bnx2x *bp, u8 cl_id,
5453 unsigned long rx_mode_flags,
5454 unsigned long rx_accept_flags,
5455 unsigned long tx_accept_flags,
5456 unsigned long ramrod_flags)
5458 struct bnx2x_rx_mode_ramrod_params ramrod_param;
5461 memset(&ramrod_param, 0, sizeof(ramrod_param));
5463 /* Prepare ramrod parameters */
5464 ramrod_param.cid = 0;
5465 ramrod_param.cl_id = cl_id;
5466 ramrod_param.rx_mode_obj = &bp->rx_mode_obj;
5467 ramrod_param.func_id = BP_FUNC(bp);
5469 ramrod_param.pstate = &bp->sp_state;
5470 ramrod_param.state = BNX2X_FILTER_RX_MODE_PENDING;
5472 ramrod_param.rdata = bnx2x_sp(bp, rx_mode_rdata);
5473 ramrod_param.rdata_mapping = bnx2x_sp_mapping(bp, rx_mode_rdata);
5475 set_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
5477 ramrod_param.ramrod_flags = ramrod_flags;
5478 ramrod_param.rx_mode_flags = rx_mode_flags;
5480 ramrod_param.rx_accept_flags = rx_accept_flags;
5481 ramrod_param.tx_accept_flags = tx_accept_flags;
5483 rc = bnx2x_config_rx_mode(bp, &ramrod_param);
5485 BNX2X_ERR("Set rx_mode %d failed\n", bp->rx_mode);
5490 /* called with netif_addr_lock_bh() */
5491 void bnx2x_set_storm_rx_mode(struct bnx2x *bp)
5493 unsigned long rx_mode_flags = 0, ramrod_flags = 0;
5494 unsigned long rx_accept_flags = 0, tx_accept_flags = 0;
5499 /* Configure rx_mode of FCoE Queue */
5500 __set_bit(BNX2X_RX_MODE_FCOE_ETH, &rx_mode_flags);
5503 switch (bp->rx_mode) {
5504 case BNX2X_RX_MODE_NONE:
5506 * 'drop all' supersedes any accept flags that may have been
5507 * passed to the function.
5510 case BNX2X_RX_MODE_NORMAL:
5511 __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
5512 __set_bit(BNX2X_ACCEPT_MULTICAST, &rx_accept_flags);
5513 __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
5515 /* internal switching mode */
5516 __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
5517 __set_bit(BNX2X_ACCEPT_MULTICAST, &tx_accept_flags);
5518 __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
5521 case BNX2X_RX_MODE_ALLMULTI:
5522 __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
5523 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &rx_accept_flags);
5524 __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
5526 /* internal switching mode */
5527 __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
5528 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &tx_accept_flags);
5529 __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
5532 case BNX2X_RX_MODE_PROMISC:
5533 /* According to deffinition of SI mode, iface in promisc mode
5534 * should receive matched and unmatched (in resolution of port)
5537 __set_bit(BNX2X_ACCEPT_UNMATCHED, &rx_accept_flags);
5538 __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
5539 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &rx_accept_flags);
5540 __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
5542 /* internal switching mode */
5543 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &tx_accept_flags);
5544 __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
5547 __set_bit(BNX2X_ACCEPT_ALL_UNICAST, &tx_accept_flags);
5549 __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
5553 BNX2X_ERR("Unknown rx_mode: %d\n", bp->rx_mode);
5557 if (bp->rx_mode != BNX2X_RX_MODE_NONE) {
5558 __set_bit(BNX2X_ACCEPT_ANY_VLAN, &rx_accept_flags);
5559 __set_bit(BNX2X_ACCEPT_ANY_VLAN, &tx_accept_flags);
5562 __set_bit(RAMROD_RX, &ramrod_flags);
5563 __set_bit(RAMROD_TX, &ramrod_flags);
5565 bnx2x_set_q_rx_mode(bp, bp->fp->cl_id, rx_mode_flags, rx_accept_flags,
5566 tx_accept_flags, ramrod_flags);
5569 static void bnx2x_init_internal_common(struct bnx2x *bp)
5575 * In switch independent mode, the TSTORM needs to accept
5576 * packets that failed classification, since approximate match
5577 * mac addresses aren't written to NIG LLH
5579 REG_WR8(bp, BAR_TSTRORM_INTMEM +
5580 TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 2);
5581 else if (!CHIP_IS_E1(bp)) /* 57710 doesn't support MF */
5582 REG_WR8(bp, BAR_TSTRORM_INTMEM +
5583 TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 0);
5585 /* Zero this manually as its initialization is
5586 currently missing in the initTool */
5587 for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++)
5588 REG_WR(bp, BAR_USTRORM_INTMEM +
5589 USTORM_AGG_DATA_OFFSET + i * 4, 0);
5590 if (!CHIP_IS_E1x(bp)) {
5591 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_IGU_MODE_OFFSET,
5592 CHIP_INT_MODE_IS_BC(bp) ?
5593 HC_IGU_BC_MODE : HC_IGU_NBC_MODE);
5597 static void bnx2x_init_internal(struct bnx2x *bp, u32 load_code)
5599 switch (load_code) {
5600 case FW_MSG_CODE_DRV_LOAD_COMMON:
5601 case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP:
5602 bnx2x_init_internal_common(bp);
5605 case FW_MSG_CODE_DRV_LOAD_PORT:
5609 case FW_MSG_CODE_DRV_LOAD_FUNCTION:
5610 /* internal memory per function is
5611 initialized inside bnx2x_pf_init */
5615 BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code);
5620 static inline u8 bnx2x_fp_igu_sb_id(struct bnx2x_fastpath *fp)
5622 return fp->bp->igu_base_sb + fp->index + CNIC_PRESENT;
5625 static inline u8 bnx2x_fp_fw_sb_id(struct bnx2x_fastpath *fp)
5627 return fp->bp->base_fw_ndsb + fp->index + CNIC_PRESENT;
5630 static u8 bnx2x_fp_cl_id(struct bnx2x_fastpath *fp)
5632 if (CHIP_IS_E1x(fp->bp))
5633 return BP_L_ID(fp->bp) + fp->index;
5634 else /* We want Client ID to be the same as IGU SB ID for 57712 */
5635 return bnx2x_fp_igu_sb_id(fp);
5638 static void bnx2x_init_eth_fp(struct bnx2x *bp, int fp_idx)
5640 struct bnx2x_fastpath *fp = &bp->fp[fp_idx];
5642 unsigned long q_type = 0;
5643 u32 cids[BNX2X_MULTI_TX_COS] = { 0 };
5644 fp->rx_queue = fp_idx;
5646 fp->cl_id = bnx2x_fp_cl_id(fp);
5647 fp->fw_sb_id = bnx2x_fp_fw_sb_id(fp);
5648 fp->igu_sb_id = bnx2x_fp_igu_sb_id(fp);
5649 /* qZone id equals to FW (per path) client id */
5650 fp->cl_qzone_id = bnx2x_fp_qzone_id(fp);
5653 fp->ustorm_rx_prods_offset = bnx2x_rx_ustorm_prods_offset(fp);
5655 /* Setup SB indicies */
5656 fp->rx_cons_sb = BNX2X_RX_SB_INDEX;
5658 /* Configure Queue State object */
5659 __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
5660 __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
5662 BUG_ON(fp->max_cos > BNX2X_MULTI_TX_COS);
5665 for_each_cos_in_tx_queue(fp, cos) {
5666 bnx2x_init_txdata(bp, fp->txdata_ptr[cos],
5667 CID_COS_TO_TX_ONLY_CID(fp->cid, cos, bp),
5668 FP_COS_TO_TXQ(fp, cos, bp),
5669 BNX2X_TX_SB_INDEX_BASE + cos, fp);
5670 cids[cos] = fp->txdata_ptr[cos]->cid;
5673 bnx2x_init_queue_obj(bp, &bnx2x_sp_obj(bp, fp).q_obj, fp->cl_id, cids,
5674 fp->max_cos, BP_FUNC(bp), bnx2x_sp(bp, q_rdata),
5675 bnx2x_sp_mapping(bp, q_rdata), q_type);
5678 * Configure classification DBs: Always enable Tx switching
5680 bnx2x_init_vlan_mac_fp_objs(fp, BNX2X_OBJ_TYPE_RX_TX);
5682 DP(NETIF_MSG_IFUP, "queue[%d]: bnx2x_init_sb(%p,%p) cl_id %d fw_sb %d igu_sb %d\n",
5683 fp_idx, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id,
5685 bnx2x_init_sb(bp, fp->status_blk_mapping, BNX2X_VF_ID_INVALID, false,
5686 fp->fw_sb_id, fp->igu_sb_id);
5688 bnx2x_update_fpsb_idx(fp);
5691 static void bnx2x_init_tx_ring_one(struct bnx2x_fp_txdata *txdata)
5695 for (i = 1; i <= NUM_TX_RINGS; i++) {
5696 struct eth_tx_next_bd *tx_next_bd =
5697 &txdata->tx_desc_ring[TX_DESC_CNT * i - 1].next_bd;
5699 tx_next_bd->addr_hi =
5700 cpu_to_le32(U64_HI(txdata->tx_desc_mapping +
5701 BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
5702 tx_next_bd->addr_lo =
5703 cpu_to_le32(U64_LO(txdata->tx_desc_mapping +
5704 BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
5707 SET_FLAG(txdata->tx_db.data.header.header, DOORBELL_HDR_DB_TYPE, 1);
5708 txdata->tx_db.data.zero_fill1 = 0;
5709 txdata->tx_db.data.prod = 0;
5711 txdata->tx_pkt_prod = 0;
5712 txdata->tx_pkt_cons = 0;
5713 txdata->tx_bd_prod = 0;
5714 txdata->tx_bd_cons = 0;
5718 static void bnx2x_init_tx_rings(struct bnx2x *bp)
5723 for_each_tx_queue(bp, i)
5724 for_each_cos_in_tx_queue(&bp->fp[i], cos)
5725 bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[cos]);
5728 void bnx2x_nic_init(struct bnx2x *bp, u32 load_code)
5732 for_each_eth_queue(bp, i)
5733 bnx2x_init_eth_fp(bp, i);
5736 bnx2x_init_fcoe_fp(bp);
5738 bnx2x_init_sb(bp, bp->cnic_sb_mapping,
5739 BNX2X_VF_ID_INVALID, false,
5740 bnx2x_cnic_fw_sb_id(bp), bnx2x_cnic_igu_sb_id(bp));
5744 /* Initialize MOD_ABS interrupts */
5745 bnx2x_init_mod_abs_int(bp, &bp->link_vars, bp->common.chip_id,
5746 bp->common.shmem_base, bp->common.shmem2_base,
5748 /* ensure status block indices were read */
5751 bnx2x_init_def_sb(bp);
5752 bnx2x_update_dsb_idx(bp);
5753 bnx2x_init_rx_rings(bp);
5754 bnx2x_init_tx_rings(bp);
5755 bnx2x_init_sp_ring(bp);
5756 bnx2x_init_eq_ring(bp);
5757 bnx2x_init_internal(bp, load_code);
5759 bnx2x_stats_init(bp);
5761 /* flush all before enabling interrupts */
5765 bnx2x_int_enable(bp);
5767 /* Check for SPIO5 */
5768 bnx2x_attn_int_deasserted0(bp,
5769 REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + BP_PORT(bp)*4) &
5770 AEU_INPUTS_ATTN_BITS_SPIO5);
5773 /* end of nic init */
5776 * gzip service functions
5779 static int bnx2x_gunzip_init(struct bnx2x *bp)
5781 bp->gunzip_buf = dma_alloc_coherent(&bp->pdev->dev, FW_BUF_SIZE,
5782 &bp->gunzip_mapping, GFP_KERNEL);
5783 if (bp->gunzip_buf == NULL)
5786 bp->strm = kmalloc(sizeof(*bp->strm), GFP_KERNEL);
5787 if (bp->strm == NULL)
5790 bp->strm->workspace = vmalloc(zlib_inflate_workspacesize());
5791 if (bp->strm->workspace == NULL)
5801 dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
5802 bp->gunzip_mapping);
5803 bp->gunzip_buf = NULL;
5806 BNX2X_ERR("Cannot allocate firmware buffer for un-compression\n");
5810 static void bnx2x_gunzip_end(struct bnx2x *bp)
5813 vfree(bp->strm->workspace);
5818 if (bp->gunzip_buf) {
5819 dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
5820 bp->gunzip_mapping);
5821 bp->gunzip_buf = NULL;
5825 static int bnx2x_gunzip(struct bnx2x *bp, const u8 *zbuf, int len)
5829 /* check gzip header */
5830 if ((zbuf[0] != 0x1f) || (zbuf[1] != 0x8b) || (zbuf[2] != Z_DEFLATED)) {
5831 BNX2X_ERR("Bad gzip header\n");
5839 if (zbuf[3] & FNAME)
5840 while ((zbuf[n++] != 0) && (n < len));
5842 bp->strm->next_in = (typeof(bp->strm->next_in))zbuf + n;
5843 bp->strm->avail_in = len - n;
5844 bp->strm->next_out = bp->gunzip_buf;
5845 bp->strm->avail_out = FW_BUF_SIZE;
5847 rc = zlib_inflateInit2(bp->strm, -MAX_WBITS);
5851 rc = zlib_inflate(bp->strm, Z_FINISH);
5852 if ((rc != Z_OK) && (rc != Z_STREAM_END))
5853 netdev_err(bp->dev, "Firmware decompression error: %s\n",
5856 bp->gunzip_outlen = (FW_BUF_SIZE - bp->strm->avail_out);
5857 if (bp->gunzip_outlen & 0x3)
5859 "Firmware decompression error: gunzip_outlen (%d) not aligned\n",
5861 bp->gunzip_outlen >>= 2;
5863 zlib_inflateEnd(bp->strm);
5865 if (rc == Z_STREAM_END)
5871 /* nic load/unload */
5874 * General service functions
5877 /* send a NIG loopback debug packet */
5878 static void bnx2x_lb_pckt(struct bnx2x *bp)
5882 /* Ethernet source and destination addresses */
5883 wb_write[0] = 0x55555555;
5884 wb_write[1] = 0x55555555;
5885 wb_write[2] = 0x20; /* SOP */
5886 REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
5888 /* NON-IP protocol */
5889 wb_write[0] = 0x09000000;
5890 wb_write[1] = 0x55555555;
5891 wb_write[2] = 0x10; /* EOP, eop_bvalid = 0 */
5892 REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
5895 /* some of the internal memories
5896 * are not directly readable from the driver
5897 * to test them we send debug packets
5899 static int bnx2x_int_mem_test(struct bnx2x *bp)
5905 if (CHIP_REV_IS_FPGA(bp))
5907 else if (CHIP_REV_IS_EMUL(bp))
5912 /* Disable inputs of parser neighbor blocks */
5913 REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
5914 REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
5915 REG_WR(bp, CFC_REG_DEBUG0, 0x1);
5916 REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
5918 /* Write 0 to parser credits for CFC search request */
5919 REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
5921 /* send Ethernet packet */
5924 /* TODO do i reset NIG statistic? */
5925 /* Wait until NIG register shows 1 packet of size 0x10 */
5926 count = 1000 * factor;
5929 bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
5930 val = *bnx2x_sp(bp, wb_data[0]);
5938 BNX2X_ERR("NIG timeout val = 0x%x\n", val);
5942 /* Wait until PRS register shows 1 packet */
5943 count = 1000 * factor;
5945 val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
5953 BNX2X_ERR("PRS timeout val = 0x%x\n", val);
5957 /* Reset and init BRB, PRS */
5958 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
5960 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
5962 bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
5963 bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
5965 DP(NETIF_MSG_HW, "part2\n");
5967 /* Disable inputs of parser neighbor blocks */
5968 REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
5969 REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
5970 REG_WR(bp, CFC_REG_DEBUG0, 0x1);
5971 REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
5973 /* Write 0 to parser credits for CFC search request */
5974 REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
5976 /* send 10 Ethernet packets */
5977 for (i = 0; i < 10; i++)
5980 /* Wait until NIG register shows 10 + 1
5981 packets of size 11*0x10 = 0xb0 */
5982 count = 1000 * factor;
5985 bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
5986 val = *bnx2x_sp(bp, wb_data[0]);
5994 BNX2X_ERR("NIG timeout val = 0x%x\n", val);
5998 /* Wait until PRS register shows 2 packets */
5999 val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
6001 BNX2X_ERR("PRS timeout val = 0x%x\n", val);
6003 /* Write 1 to parser credits for CFC search request */
6004 REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x1);
6006 /* Wait until PRS register shows 3 packets */
6007 msleep(10 * factor);
6008 /* Wait until NIG register shows 1 packet of size 0x10 */
6009 val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
6011 BNX2X_ERR("PRS timeout val = 0x%x\n", val);
6013 /* clear NIG EOP FIFO */
6014 for (i = 0; i < 11; i++)
6015 REG_RD(bp, NIG_REG_INGRESS_EOP_LB_FIFO);
6016 val = REG_RD(bp, NIG_REG_INGRESS_EOP_LB_EMPTY);
6018 BNX2X_ERR("clear of NIG failed\n");
6022 /* Reset and init BRB, PRS, NIG */
6023 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
6025 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
6027 bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
6028 bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
6031 REG_WR(bp, PRS_REG_NIC_MODE, 1);
6034 /* Enable inputs of parser neighbor blocks */
6035 REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x7fffffff);
6036 REG_WR(bp, TCM_REG_PRS_IFEN, 0x1);
6037 REG_WR(bp, CFC_REG_DEBUG0, 0x0);
6038 REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x1);
6040 DP(NETIF_MSG_HW, "done\n");
6045 static void bnx2x_enable_blocks_attention(struct bnx2x *bp)
6047 REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
6048 if (!CHIP_IS_E1x(bp))
6049 REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0x40);
6051 REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0);
6052 REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
6053 REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
6055 * mask read length error interrupts in brb for parser
6056 * (parsing unit and 'checksum and crc' unit)
6057 * these errors are legal (PU reads fixed length and CAC can cause
6058 * read length error on truncated packets)
6060 REG_WR(bp, BRB1_REG_BRB1_INT_MASK, 0xFC00);
6061 REG_WR(bp, QM_REG_QM_INT_MASK, 0);
6062 REG_WR(bp, TM_REG_TM_INT_MASK, 0);
6063 REG_WR(bp, XSDM_REG_XSDM_INT_MASK_0, 0);
6064 REG_WR(bp, XSDM_REG_XSDM_INT_MASK_1, 0);
6065 REG_WR(bp, XCM_REG_XCM_INT_MASK, 0);
6066 /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_0, 0); */
6067 /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_1, 0); */
6068 REG_WR(bp, USDM_REG_USDM_INT_MASK_0, 0);
6069 REG_WR(bp, USDM_REG_USDM_INT_MASK_1, 0);
6070 REG_WR(bp, UCM_REG_UCM_INT_MASK, 0);
6071 /* REG_WR(bp, USEM_REG_USEM_INT_MASK_0, 0); */
6072 /* REG_WR(bp, USEM_REG_USEM_INT_MASK_1, 0); */
6073 REG_WR(bp, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0);
6074 REG_WR(bp, CSDM_REG_CSDM_INT_MASK_0, 0);
6075 REG_WR(bp, CSDM_REG_CSDM_INT_MASK_1, 0);
6076 REG_WR(bp, CCM_REG_CCM_INT_MASK, 0);
6077 /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_0, 0); */
6078 /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_1, 0); */
6080 if (CHIP_REV_IS_FPGA(bp))
6081 REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, 0x580000);
6082 else if (!CHIP_IS_E1x(bp))
6083 REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0,
6084 (PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_OF
6085 | PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_AFT
6086 | PXP2_PXP2_INT_MASK_0_REG_PGL_PCIE_ATTN
6087 | PXP2_PXP2_INT_MASK_0_REG_PGL_READ_BLOCKED
6088 | PXP2_PXP2_INT_MASK_0_REG_PGL_WRITE_BLOCKED));
6090 REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, 0x480000);
6091 REG_WR(bp, TSDM_REG_TSDM_INT_MASK_0, 0);
6092 REG_WR(bp, TSDM_REG_TSDM_INT_MASK_1, 0);
6093 REG_WR(bp, TCM_REG_TCM_INT_MASK, 0);
6094 /* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_0, 0); */
6096 if (!CHIP_IS_E1x(bp))
6097 /* enable VFC attentions: bits 11 and 12, bits 31:13 reserved */
6098 REG_WR(bp, TSEM_REG_TSEM_INT_MASK_1, 0x07ff);
6100 REG_WR(bp, CDU_REG_CDU_INT_MASK, 0);
6101 REG_WR(bp, DMAE_REG_DMAE_INT_MASK, 0);
6102 /* REG_WR(bp, MISC_REG_MISC_INT_MASK, 0); */
6103 REG_WR(bp, PBF_REG_PBF_INT_MASK, 0x18); /* bit 3,4 masked */
6106 static void bnx2x_reset_common(struct bnx2x *bp)
6111 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
6114 if (CHIP_IS_E3(bp)) {
6115 val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
6116 val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
6119 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, val);
6122 static void bnx2x_setup_dmae(struct bnx2x *bp)
6125 spin_lock_init(&bp->dmae_lock);
6128 static void bnx2x_init_pxp(struct bnx2x *bp)
6131 int r_order, w_order;
6133 pcie_capability_read_word(bp->pdev, PCI_EXP_DEVCTL, &devctl);
6134 DP(NETIF_MSG_HW, "read 0x%x from devctl\n", devctl);
6135 w_order = ((devctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5);
6137 r_order = ((devctl & PCI_EXP_DEVCTL_READRQ) >> 12);
6139 DP(NETIF_MSG_HW, "force read order to %d\n", bp->mrrs);
6143 bnx2x_init_pxp_arb(bp, r_order, w_order);
6146 static void bnx2x_setup_fan_failure_detection(struct bnx2x *bp)
6156 val = SHMEM_RD(bp, dev_info.shared_hw_config.config2) &
6157 SHARED_HW_CFG_FAN_FAILURE_MASK;
6159 if (val == SHARED_HW_CFG_FAN_FAILURE_ENABLED)
6163 * The fan failure mechanism is usually related to the PHY type since
6164 * the power consumption of the board is affected by the PHY. Currently,
6165 * fan is required for most designs with SFX7101, BCM8727 and BCM8481.
6167 else if (val == SHARED_HW_CFG_FAN_FAILURE_PHY_TYPE)
6168 for (port = PORT_0; port < PORT_MAX; port++) {
6170 bnx2x_fan_failure_det_req(
6172 bp->common.shmem_base,
6173 bp->common.shmem2_base,
6177 DP(NETIF_MSG_HW, "fan detection setting: %d\n", is_required);
6179 if (is_required == 0)
6182 /* Fan failure is indicated by SPIO 5 */
6183 bnx2x_set_spio(bp, MISC_REGISTERS_SPIO_5,
6184 MISC_REGISTERS_SPIO_INPUT_HI_Z);
6186 /* set to active low mode */
6187 val = REG_RD(bp, MISC_REG_SPIO_INT);
6188 val |= ((1 << MISC_REGISTERS_SPIO_5) <<
6189 MISC_REGISTERS_SPIO_INT_OLD_SET_POS);
6190 REG_WR(bp, MISC_REG_SPIO_INT, val);
6192 /* enable interrupt to signal the IGU */
6193 val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
6194 val |= (1 << MISC_REGISTERS_SPIO_5);
6195 REG_WR(bp, MISC_REG_SPIO_EVENT_EN, val);
6198 static void bnx2x_pretend_func(struct bnx2x *bp, u8 pretend_func_num)
6204 if (CHIP_IS_E1H(bp) && (pretend_func_num >= E1H_FUNC_MAX))
6207 switch (BP_ABS_FUNC(bp)) {
6209 offset = PXP2_REG_PGL_PRETEND_FUNC_F0;
6212 offset = PXP2_REG_PGL_PRETEND_FUNC_F1;
6215 offset = PXP2_REG_PGL_PRETEND_FUNC_F2;
6218 offset = PXP2_REG_PGL_PRETEND_FUNC_F3;
6221 offset = PXP2_REG_PGL_PRETEND_FUNC_F4;
6224 offset = PXP2_REG_PGL_PRETEND_FUNC_F5;
6227 offset = PXP2_REG_PGL_PRETEND_FUNC_F6;
6230 offset = PXP2_REG_PGL_PRETEND_FUNC_F7;
6236 REG_WR(bp, offset, pretend_func_num);
6238 DP(NETIF_MSG_HW, "Pretending to func %d\n", pretend_func_num);
6241 void bnx2x_pf_disable(struct bnx2x *bp)
6243 u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
6244 val &= ~IGU_PF_CONF_FUNC_EN;
6246 REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
6247 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
6248 REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 0);
6251 static void bnx2x__common_init_phy(struct bnx2x *bp)
6253 u32 shmem_base[2], shmem2_base[2];
6254 shmem_base[0] = bp->common.shmem_base;
6255 shmem2_base[0] = bp->common.shmem2_base;
6256 if (!CHIP_IS_E1x(bp)) {
6258 SHMEM2_RD(bp, other_shmem_base_addr);
6260 SHMEM2_RD(bp, other_shmem2_base_addr);
6262 bnx2x_acquire_phy_lock(bp);
6263 bnx2x_common_init_phy(bp, shmem_base, shmem2_base,
6264 bp->common.chip_id);
6265 bnx2x_release_phy_lock(bp);
6269 * bnx2x_init_hw_common - initialize the HW at the COMMON phase.
6271 * @bp: driver handle
6273 static int bnx2x_init_hw_common(struct bnx2x *bp)
6277 DP(NETIF_MSG_HW, "starting common init func %d\n", BP_ABS_FUNC(bp));
6280 * take the UNDI lock to protect undi_unload flow from accessing
6281 * registers while we're resetting the chip
6283 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
6285 bnx2x_reset_common(bp);
6286 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0xffffffff);
6289 if (CHIP_IS_E3(bp)) {
6290 val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
6291 val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
6293 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, val);
6295 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
6297 bnx2x_init_block(bp, BLOCK_MISC, PHASE_COMMON);
6299 if (!CHIP_IS_E1x(bp)) {
6303 * 4-port mode or 2-port mode we need to turn of master-enable
6304 * for everyone, after that, turn it back on for self.
6305 * so, we disregard multi-function or not, and always disable
6306 * for all functions on the given path, this means 0,2,4,6 for
6307 * path 0 and 1,3,5,7 for path 1
6309 for (abs_func_id = BP_PATH(bp);
6310 abs_func_id < E2_FUNC_MAX*2; abs_func_id += 2) {
6311 if (abs_func_id == BP_ABS_FUNC(bp)) {
6313 PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER,
6318 bnx2x_pretend_func(bp, abs_func_id);
6319 /* clear pf enable */
6320 bnx2x_pf_disable(bp);
6321 bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
6325 bnx2x_init_block(bp, BLOCK_PXP, PHASE_COMMON);
6326 if (CHIP_IS_E1(bp)) {
6327 /* enable HW interrupt from PXP on USDM overflow
6328 bit 16 on INT_MASK_0 */
6329 REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
6332 bnx2x_init_block(bp, BLOCK_PXP2, PHASE_COMMON);
6336 REG_WR(bp, PXP2_REG_RQ_QM_ENDIAN_M, 1);
6337 REG_WR(bp, PXP2_REG_RQ_TM_ENDIAN_M, 1);
6338 REG_WR(bp, PXP2_REG_RQ_SRC_ENDIAN_M, 1);
6339 REG_WR(bp, PXP2_REG_RQ_CDU_ENDIAN_M, 1);
6340 REG_WR(bp, PXP2_REG_RQ_DBG_ENDIAN_M, 1);
6341 /* make sure this value is 0 */
6342 REG_WR(bp, PXP2_REG_RQ_HC_ENDIAN_M, 0);
6344 /* REG_WR(bp, PXP2_REG_RD_PBF_SWAP_MODE, 1); */
6345 REG_WR(bp, PXP2_REG_RD_QM_SWAP_MODE, 1);
6346 REG_WR(bp, PXP2_REG_RD_TM_SWAP_MODE, 1);
6347 REG_WR(bp, PXP2_REG_RD_SRC_SWAP_MODE, 1);
6348 REG_WR(bp, PXP2_REG_RD_CDURD_SWAP_MODE, 1);
6351 bnx2x_ilt_init_page_size(bp, INITOP_SET);
6353 if (CHIP_REV_IS_FPGA(bp) && CHIP_IS_E1H(bp))
6354 REG_WR(bp, PXP2_REG_PGL_TAGS_LIMIT, 0x1);
6356 /* let the HW do it's magic ... */
6358 /* finish PXP init */
6359 val = REG_RD(bp, PXP2_REG_RQ_CFG_DONE);
6361 BNX2X_ERR("PXP2 CFG failed\n");
6364 val = REG_RD(bp, PXP2_REG_RD_INIT_DONE);
6366 BNX2X_ERR("PXP2 RD_INIT failed\n");
6370 /* Timers bug workaround E2 only. We need to set the entire ILT to
6371 * have entries with value "0" and valid bit on.
6372 * This needs to be done by the first PF that is loaded in a path
6373 * (i.e. common phase)
6375 if (!CHIP_IS_E1x(bp)) {
6376 /* In E2 there is a bug in the timers block that can cause function 6 / 7
6377 * (i.e. vnic3) to start even if it is marked as "scan-off".
6378 * This occurs when a different function (func2,3) is being marked
6379 * as "scan-off". Real-life scenario for example: if a driver is being
6380 * load-unloaded while func6,7 are down. This will cause the timer to access
6381 * the ilt, translate to a logical address and send a request to read/write.
6382 * Since the ilt for the function that is down is not valid, this will cause
6383 * a translation error which is unrecoverable.
6384 * The Workaround is intended to make sure that when this happens nothing fatal
6385 * will occur. The workaround:
6386 * 1. First PF driver which loads on a path will:
6387 * a. After taking the chip out of reset, by using pretend,
6388 * it will write "0" to the following registers of
6390 * REG_WR(pdev, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
6391 * REG_WR(pdev, CFC_REG_WEAK_ENABLE_PF,0);
6392 * REG_WR(pdev, CFC_REG_STRONG_ENABLE_PF,0);
6393 * And for itself it will write '1' to
6394 * PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER to enable
6395 * dmae-operations (writing to pram for example.)
6396 * note: can be done for only function 6,7 but cleaner this
6398 * b. Write zero+valid to the entire ILT.
6399 * c. Init the first_timers_ilt_entry, last_timers_ilt_entry of
6400 * VNIC3 (of that port). The range allocated will be the
6401 * entire ILT. This is needed to prevent ILT range error.
6402 * 2. Any PF driver load flow:
6403 * a. ILT update with the physical addresses of the allocated
6405 * b. Wait 20msec. - note that this timeout is needed to make
6406 * sure there are no requests in one of the PXP internal
6407 * queues with "old" ILT addresses.
6408 * c. PF enable in the PGLC.
6409 * d. Clear the was_error of the PF in the PGLC. (could have
6410 * occured while driver was down)
6411 * e. PF enable in the CFC (WEAK + STRONG)
6412 * f. Timers scan enable
6413 * 3. PF driver unload flow:
6414 * a. Clear the Timers scan_en.
6415 * b. Polling for scan_on=0 for that PF.
6416 * c. Clear the PF enable bit in the PXP.
6417 * d. Clear the PF enable in the CFC (WEAK + STRONG)
6418 * e. Write zero+valid to all ILT entries (The valid bit must
6420 * f. If this is VNIC 3 of a port then also init
6421 * first_timers_ilt_entry to zero and last_timers_ilt_entry
6422 * to the last enrty in the ILT.
6425 * Currently the PF error in the PGLC is non recoverable.
6426 * In the future the there will be a recovery routine for this error.
6427 * Currently attention is masked.
6428 * Having an MCP lock on the load/unload process does not guarantee that
6429 * there is no Timer disable during Func6/7 enable. This is because the
6430 * Timers scan is currently being cleared by the MCP on FLR.
6431 * Step 2.d can be done only for PF6/7 and the driver can also check if
6432 * there is error before clearing it. But the flow above is simpler and
6434 * All ILT entries are written by zero+valid and not just PF6/7
6435 * ILT entries since in the future the ILT entries allocation for
6436 * PF-s might be dynamic.
6438 struct ilt_client_info ilt_cli;
6439 struct bnx2x_ilt ilt;
6440 memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
6441 memset(&ilt, 0, sizeof(struct bnx2x_ilt));
6443 /* initialize dummy TM client */
6445 ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
6446 ilt_cli.client_num = ILT_CLIENT_TM;
6448 /* Step 1: set zeroes to all ilt page entries with valid bit on
6449 * Step 2: set the timers first/last ilt entry to point
6450 * to the entire range to prevent ILT range error for 3rd/4th
6451 * vnic (this code assumes existance of the vnic)
6453 * both steps performed by call to bnx2x_ilt_client_init_op()
6454 * with dummy TM client
6456 * we must use pretend since PXP2_REG_RQ_##blk##_FIRST_ILT
6457 * and his brother are split registers
6459 bnx2x_pretend_func(bp, (BP_PATH(bp) + 6));
6460 bnx2x_ilt_client_init_op_ilt(bp, &ilt, &ilt_cli, INITOP_CLEAR);
6461 bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
6463 REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN, BNX2X_PXP_DRAM_ALIGN);
6464 REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_RD, BNX2X_PXP_DRAM_ALIGN);
6465 REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_SEL, 1);
6469 REG_WR(bp, PXP2_REG_RQ_DISABLE_INPUTS, 0);
6470 REG_WR(bp, PXP2_REG_RD_DISABLE_INPUTS, 0);
6472 if (!CHIP_IS_E1x(bp)) {
6473 int factor = CHIP_REV_IS_EMUL(bp) ? 1000 :
6474 (CHIP_REV_IS_FPGA(bp) ? 400 : 0);
6475 bnx2x_init_block(bp, BLOCK_PGLUE_B, PHASE_COMMON);
6477 bnx2x_init_block(bp, BLOCK_ATC, PHASE_COMMON);
6479 /* let the HW do it's magic ... */
6482 val = REG_RD(bp, ATC_REG_ATC_INIT_DONE);
6483 } while (factor-- && (val != 1));
6486 BNX2X_ERR("ATC_INIT failed\n");
6491 bnx2x_init_block(bp, BLOCK_DMAE, PHASE_COMMON);
6493 /* clean the DMAE memory */
6495 bnx2x_init_fill(bp, TSEM_REG_PRAM, 0, 8, 1);
6497 bnx2x_init_block(bp, BLOCK_TCM, PHASE_COMMON);
6499 bnx2x_init_block(bp, BLOCK_UCM, PHASE_COMMON);
6501 bnx2x_init_block(bp, BLOCK_CCM, PHASE_COMMON);
6503 bnx2x_init_block(bp, BLOCK_XCM, PHASE_COMMON);
6505 bnx2x_read_dmae(bp, XSEM_REG_PASSIVE_BUFFER, 3);
6506 bnx2x_read_dmae(bp, CSEM_REG_PASSIVE_BUFFER, 3);
6507 bnx2x_read_dmae(bp, TSEM_REG_PASSIVE_BUFFER, 3);
6508 bnx2x_read_dmae(bp, USEM_REG_PASSIVE_BUFFER, 3);
6510 bnx2x_init_block(bp, BLOCK_QM, PHASE_COMMON);
6513 /* QM queues pointers table */
6514 bnx2x_qm_init_ptr_table(bp, bp->qm_cid_count, INITOP_SET);
6516 /* soft reset pulse */
6517 REG_WR(bp, QM_REG_SOFT_RESET, 1);
6518 REG_WR(bp, QM_REG_SOFT_RESET, 0);
6521 bnx2x_init_block(bp, BLOCK_TM, PHASE_COMMON);
6524 bnx2x_init_block(bp, BLOCK_DORQ, PHASE_COMMON);
6525 REG_WR(bp, DORQ_REG_DPM_CID_OFST, BNX2X_DB_SHIFT);
6526 if (!CHIP_REV_IS_SLOW(bp))
6527 /* enable hw interrupt from doorbell Q */
6528 REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
6530 bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
6532 bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
6533 REG_WR(bp, PRS_REG_A_PRSU_20, 0xf);
6535 if (!CHIP_IS_E1(bp))
6536 REG_WR(bp, PRS_REG_E1HOV_MODE, bp->path_has_ovlan);
6538 if (!CHIP_IS_E1x(bp) && !CHIP_IS_E3B0(bp)) {
6539 if (IS_MF_AFEX(bp)) {
6540 /* configure that VNTag and VLAN headers must be
6541 * received in afex mode
6543 REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC, 0xE);
6544 REG_WR(bp, PRS_REG_MUST_HAVE_HDRS, 0xA);
6545 REG_WR(bp, PRS_REG_HDRS_AFTER_TAG_0, 0x6);
6546 REG_WR(bp, PRS_REG_TAG_ETHERTYPE_0, 0x8926);
6547 REG_WR(bp, PRS_REG_TAG_LEN_0, 0x4);
6549 /* Bit-map indicating which L2 hdrs may appear
6550 * after the basic Ethernet header
6552 REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC,
6553 bp->path_has_ovlan ? 7 : 6);
6557 bnx2x_init_block(bp, BLOCK_TSDM, PHASE_COMMON);
6558 bnx2x_init_block(bp, BLOCK_CSDM, PHASE_COMMON);
6559 bnx2x_init_block(bp, BLOCK_USDM, PHASE_COMMON);
6560 bnx2x_init_block(bp, BLOCK_XSDM, PHASE_COMMON);
6562 if (!CHIP_IS_E1x(bp)) {
6563 /* reset VFC memories */
6564 REG_WR(bp, TSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
6565 VFC_MEMORIES_RST_REG_CAM_RST |
6566 VFC_MEMORIES_RST_REG_RAM_RST);
6567 REG_WR(bp, XSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
6568 VFC_MEMORIES_RST_REG_CAM_RST |
6569 VFC_MEMORIES_RST_REG_RAM_RST);
6574 bnx2x_init_block(bp, BLOCK_TSEM, PHASE_COMMON);
6575 bnx2x_init_block(bp, BLOCK_USEM, PHASE_COMMON);
6576 bnx2x_init_block(bp, BLOCK_CSEM, PHASE_COMMON);
6577 bnx2x_init_block(bp, BLOCK_XSEM, PHASE_COMMON);
6580 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
6582 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
6585 bnx2x_init_block(bp, BLOCK_UPB, PHASE_COMMON);
6586 bnx2x_init_block(bp, BLOCK_XPB, PHASE_COMMON);
6587 bnx2x_init_block(bp, BLOCK_PBF, PHASE_COMMON);
6589 if (!CHIP_IS_E1x(bp)) {
6590 if (IS_MF_AFEX(bp)) {
6591 /* configure that VNTag and VLAN headers must be
6594 REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC, 0xE);
6595 REG_WR(bp, PBF_REG_MUST_HAVE_HDRS, 0xA);
6596 REG_WR(bp, PBF_REG_HDRS_AFTER_TAG_0, 0x6);
6597 REG_WR(bp, PBF_REG_TAG_ETHERTYPE_0, 0x8926);
6598 REG_WR(bp, PBF_REG_TAG_LEN_0, 0x4);
6600 REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC,
6601 bp->path_has_ovlan ? 7 : 6);
6605 REG_WR(bp, SRC_REG_SOFT_RST, 1);
6607 bnx2x_init_block(bp, BLOCK_SRC, PHASE_COMMON);
6610 REG_WR(bp, SRC_REG_KEYSEARCH_0, 0x63285672);
6611 REG_WR(bp, SRC_REG_KEYSEARCH_1, 0x24b8f2cc);
6612 REG_WR(bp, SRC_REG_KEYSEARCH_2, 0x223aef9b);
6613 REG_WR(bp, SRC_REG_KEYSEARCH_3, 0x26001e3a);
6614 REG_WR(bp, SRC_REG_KEYSEARCH_4, 0x7ae91116);
6615 REG_WR(bp, SRC_REG_KEYSEARCH_5, 0x5ce5230b);
6616 REG_WR(bp, SRC_REG_KEYSEARCH_6, 0x298d8adf);
6617 REG_WR(bp, SRC_REG_KEYSEARCH_7, 0x6eb0ff09);
6618 REG_WR(bp, SRC_REG_KEYSEARCH_8, 0x1830f82f);
6619 REG_WR(bp, SRC_REG_KEYSEARCH_9, 0x01e46be7);
6621 REG_WR(bp, SRC_REG_SOFT_RST, 0);
6623 if (sizeof(union cdu_context) != 1024)
6624 /* we currently assume that a context is 1024 bytes */
6625 dev_alert(&bp->pdev->dev,
6626 "please adjust the size of cdu_context(%ld)\n",
6627 (long)sizeof(union cdu_context));
6629 bnx2x_init_block(bp, BLOCK_CDU, PHASE_COMMON);
6630 val = (4 << 24) + (0 << 12) + 1024;
6631 REG_WR(bp, CDU_REG_CDU_GLOBAL_PARAMS, val);
6633 bnx2x_init_block(bp, BLOCK_CFC, PHASE_COMMON);
6634 REG_WR(bp, CFC_REG_INIT_REG, 0x7FF);
6635 /* enable context validation interrupt from CFC */
6636 REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
6638 /* set the thresholds to prevent CFC/CDU race */
6639 REG_WR(bp, CFC_REG_DEBUG0, 0x20020000);
6641 bnx2x_init_block(bp, BLOCK_HC, PHASE_COMMON);
6643 if (!CHIP_IS_E1x(bp) && BP_NOMCP(bp))
6644 REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x36);
6646 bnx2x_init_block(bp, BLOCK_IGU, PHASE_COMMON);
6647 bnx2x_init_block(bp, BLOCK_MISC_AEU, PHASE_COMMON);
6649 /* Reset PCIE errors for debug */
6650 REG_WR(bp, 0x2814, 0xffffffff);
6651 REG_WR(bp, 0x3820, 0xffffffff);
6653 if (!CHIP_IS_E1x(bp)) {
6654 REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_CONTROL_5,
6655 (PXPCS_TL_CONTROL_5_ERR_UNSPPORT1 |
6656 PXPCS_TL_CONTROL_5_ERR_UNSPPORT));
6657 REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC345_STAT,
6658 (PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT4 |
6659 PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT3 |
6660 PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT2));
6661 REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC678_STAT,
6662 (PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT7 |
6663 PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT6 |
6664 PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT5));
6667 bnx2x_init_block(bp, BLOCK_NIG, PHASE_COMMON);
6668 if (!CHIP_IS_E1(bp)) {
6669 /* in E3 this done in per-port section */
6670 if (!CHIP_IS_E3(bp))
6671 REG_WR(bp, NIG_REG_LLH_MF_MODE, IS_MF(bp));
6673 if (CHIP_IS_E1H(bp))
6674 /* not applicable for E2 (and above ...) */
6675 REG_WR(bp, NIG_REG_LLH_E1HOV_MODE, IS_MF_SD(bp));
6677 if (CHIP_REV_IS_SLOW(bp))
6680 /* finish CFC init */
6681 val = reg_poll(bp, CFC_REG_LL_INIT_DONE, 1, 100, 10);
6683 BNX2X_ERR("CFC LL_INIT failed\n");
6686 val = reg_poll(bp, CFC_REG_AC_INIT_DONE, 1, 100, 10);
6688 BNX2X_ERR("CFC AC_INIT failed\n");
6691 val = reg_poll(bp, CFC_REG_CAM_INIT_DONE, 1, 100, 10);
6693 BNX2X_ERR("CFC CAM_INIT failed\n");
6696 REG_WR(bp, CFC_REG_DEBUG0, 0);
6698 if (CHIP_IS_E1(bp)) {
6699 /* read NIG statistic
6700 to see if this is our first up since powerup */
6701 bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
6702 val = *bnx2x_sp(bp, wb_data[0]);
6704 /* do internal memory self test */
6705 if ((val == 0) && bnx2x_int_mem_test(bp)) {
6706 BNX2X_ERR("internal mem self test failed\n");
6711 bnx2x_setup_fan_failure_detection(bp);
6713 /* clear PXP2 attentions */
6714 REG_RD(bp, PXP2_REG_PXP2_INT_STS_CLR_0);
6716 bnx2x_enable_blocks_attention(bp);
6717 bnx2x_enable_blocks_parity(bp);
6719 if (!BP_NOMCP(bp)) {
6720 if (CHIP_IS_E1x(bp))
6721 bnx2x__common_init_phy(bp);
6723 BNX2X_ERR("Bootcode is missing - can not initialize link\n");
6729 * bnx2x_init_hw_common_chip - init HW at the COMMON_CHIP phase.
6731 * @bp: driver handle
6733 static int bnx2x_init_hw_common_chip(struct bnx2x *bp)
6735 int rc = bnx2x_init_hw_common(bp);
6740 /* In E2 2-PORT mode, same ext phy is used for the two paths */
6742 bnx2x__common_init_phy(bp);
6747 static int bnx2x_init_hw_port(struct bnx2x *bp)
6749 int port = BP_PORT(bp);
6750 int init_phase = port ? PHASE_PORT1 : PHASE_PORT0;
6754 bnx2x__link_reset(bp);
6756 DP(NETIF_MSG_HW, "starting port init port %d\n", port);
6758 REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
6760 bnx2x_init_block(bp, BLOCK_MISC, init_phase);
6761 bnx2x_init_block(bp, BLOCK_PXP, init_phase);
6762 bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
6764 /* Timers bug workaround: disables the pf_master bit in pglue at
6765 * common phase, we need to enable it here before any dmae access are
6766 * attempted. Therefore we manually added the enable-master to the
6767 * port phase (it also happens in the function phase)
6769 if (!CHIP_IS_E1x(bp))
6770 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
6772 bnx2x_init_block(bp, BLOCK_ATC, init_phase);
6773 bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
6774 bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
6775 bnx2x_init_block(bp, BLOCK_QM, init_phase);
6777 bnx2x_init_block(bp, BLOCK_TCM, init_phase);
6778 bnx2x_init_block(bp, BLOCK_UCM, init_phase);
6779 bnx2x_init_block(bp, BLOCK_CCM, init_phase);
6780 bnx2x_init_block(bp, BLOCK_XCM, init_phase);
6782 /* QM cid (connection) count */
6783 bnx2x_qm_init_cid_count(bp, bp->qm_cid_count, INITOP_SET);
6786 bnx2x_init_block(bp, BLOCK_TM, init_phase);
6787 REG_WR(bp, TM_REG_LIN0_SCAN_TIME + port*4, 20);
6788 REG_WR(bp, TM_REG_LIN0_MAX_ACTIVE_CID + port*4, 31);
6791 bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
6793 if (CHIP_IS_E1(bp) || CHIP_IS_E1H(bp)) {
6794 bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
6797 low = ((bp->flags & ONE_PORT_FLAG) ? 160 : 246);
6798 else if (bp->dev->mtu > 4096) {
6799 if (bp->flags & ONE_PORT_FLAG)
6803 /* (24*1024 + val*4)/256 */
6804 low = 96 + (val/64) +
6805 ((val % 64) ? 1 : 0);
6808 low = ((bp->flags & ONE_PORT_FLAG) ? 80 : 160);
6809 high = low + 56; /* 14*1024/256 */
6810 REG_WR(bp, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port*4, low);
6811 REG_WR(bp, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port*4, high);
6814 if (CHIP_MODE_IS_4_PORT(bp))
6815 REG_WR(bp, (BP_PORT(bp) ?
6816 BRB1_REG_MAC_GUARANTIED_1 :
6817 BRB1_REG_MAC_GUARANTIED_0), 40);
6820 bnx2x_init_block(bp, BLOCK_PRS, init_phase);
6821 if (CHIP_IS_E3B0(bp)) {
6822 if (IS_MF_AFEX(bp)) {
6823 /* configure headers for AFEX mode */
6824 REG_WR(bp, BP_PORT(bp) ?
6825 PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
6826 PRS_REG_HDRS_AFTER_BASIC_PORT_0, 0xE);
6827 REG_WR(bp, BP_PORT(bp) ?
6828 PRS_REG_HDRS_AFTER_TAG_0_PORT_1 :
6829 PRS_REG_HDRS_AFTER_TAG_0_PORT_0, 0x6);
6830 REG_WR(bp, BP_PORT(bp) ?
6831 PRS_REG_MUST_HAVE_HDRS_PORT_1 :
6832 PRS_REG_MUST_HAVE_HDRS_PORT_0, 0xA);
6834 /* Ovlan exists only if we are in multi-function +
6835 * switch-dependent mode, in switch-independent there
6836 * is no ovlan headers
6838 REG_WR(bp, BP_PORT(bp) ?
6839 PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
6840 PRS_REG_HDRS_AFTER_BASIC_PORT_0,
6841 (bp->path_has_ovlan ? 7 : 6));
6845 bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
6846 bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
6847 bnx2x_init_block(bp, BLOCK_USDM, init_phase);
6848 bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
6850 bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
6851 bnx2x_init_block(bp, BLOCK_USEM, init_phase);
6852 bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
6853 bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
6855 bnx2x_init_block(bp, BLOCK_UPB, init_phase);
6856 bnx2x_init_block(bp, BLOCK_XPB, init_phase);
6858 bnx2x_init_block(bp, BLOCK_PBF, init_phase);
6860 if (CHIP_IS_E1x(bp)) {
6861 /* configure PBF to work without PAUSE mtu 9000 */
6862 REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
6864 /* update threshold */
6865 REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, (9040/16));
6866 /* update init credit */
6867 REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, (9040/16) + 553 - 22);
6870 REG_WR(bp, PBF_REG_INIT_P0 + port*4, 1);
6872 REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0);
6876 bnx2x_init_block(bp, BLOCK_SRC, init_phase);
6878 bnx2x_init_block(bp, BLOCK_CDU, init_phase);
6879 bnx2x_init_block(bp, BLOCK_CFC, init_phase);
6881 if (CHIP_IS_E1(bp)) {
6882 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
6883 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
6885 bnx2x_init_block(bp, BLOCK_HC, init_phase);
6887 bnx2x_init_block(bp, BLOCK_IGU, init_phase);
6889 bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
6890 /* init aeu_mask_attn_func_0/1:
6891 * - SF mode: bits 3-7 are masked. only bits 0-2 are in use
6892 * - MF mode: bit 3 is masked. bits 0-2 are in use as in SF
6893 * bits 4-7 are used for "per vn group attention" */
6894 val = IS_MF(bp) ? 0xF7 : 0x7;
6895 /* Enable DCBX attention for all but E1 */
6896 val |= CHIP_IS_E1(bp) ? 0 : 0x10;
6897 REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, val);
6899 bnx2x_init_block(bp, BLOCK_NIG, init_phase);
6901 if (!CHIP_IS_E1x(bp)) {
6902 /* Bit-map indicating which L2 hdrs may appear after the
6903 * basic Ethernet header
6906 REG_WR(bp, BP_PORT(bp) ?
6907 NIG_REG_P1_HDRS_AFTER_BASIC :
6908 NIG_REG_P0_HDRS_AFTER_BASIC, 0xE);
6910 REG_WR(bp, BP_PORT(bp) ?
6911 NIG_REG_P1_HDRS_AFTER_BASIC :
6912 NIG_REG_P0_HDRS_AFTER_BASIC,
6913 IS_MF_SD(bp) ? 7 : 6);
6916 REG_WR(bp, BP_PORT(bp) ?
6917 NIG_REG_LLH1_MF_MODE :
6918 NIG_REG_LLH_MF_MODE, IS_MF(bp));
6920 if (!CHIP_IS_E3(bp))
6921 REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
6923 if (!CHIP_IS_E1(bp)) {
6924 /* 0x2 disable mf_ov, 0x1 enable */
6925 REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port*4,
6926 (IS_MF_SD(bp) ? 0x1 : 0x2));
6928 if (!CHIP_IS_E1x(bp)) {
6930 switch (bp->mf_mode) {
6931 case MULTI_FUNCTION_SD:
6934 case MULTI_FUNCTION_SI:
6935 case MULTI_FUNCTION_AFEX:
6940 REG_WR(bp, (BP_PORT(bp) ? NIG_REG_LLH1_CLS_TYPE :
6941 NIG_REG_LLH0_CLS_TYPE), val);
6944 REG_WR(bp, NIG_REG_LLFC_ENABLE_0 + port*4, 0);
6945 REG_WR(bp, NIG_REG_LLFC_OUT_EN_0 + port*4, 0);
6946 REG_WR(bp, NIG_REG_PAUSE_ENABLE_0 + port*4, 1);
6951 /* If SPIO5 is set to generate interrupts, enable it for this port */
6952 val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
6953 if (val & (1 << MISC_REGISTERS_SPIO_5)) {
6954 u32 reg_addr = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
6955 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
6956 val = REG_RD(bp, reg_addr);
6957 val |= AEU_INPUTS_ATTN_BITS_SPIO5;
6958 REG_WR(bp, reg_addr, val);
6964 static void bnx2x_ilt_wr(struct bnx2x *bp, u32 index, dma_addr_t addr)
6970 reg = PXP2_REG_RQ_ONCHIP_AT + index*8;
6972 reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index*8;
6974 wb_write[0] = ONCHIP_ADDR1(addr);
6975 wb_write[1] = ONCHIP_ADDR2(addr);
6976 REG_WR_DMAE(bp, reg, wb_write, 2);
6979 static void bnx2x_igu_clear_sb_gen(struct bnx2x *bp, u8 func,
6980 u8 idu_sb_id, bool is_Pf)
6982 u32 data, ctl, cnt = 100;
6983 u32 igu_addr_data = IGU_REG_COMMAND_REG_32LSB_DATA;
6984 u32 igu_addr_ctl = IGU_REG_COMMAND_REG_CTRL;
6985 u32 igu_addr_ack = IGU_REG_CSTORM_TYPE_0_SB_CLEANUP + (idu_sb_id/32)*4;
6986 u32 sb_bit = 1 << (idu_sb_id%32);
6987 u32 func_encode = func | (is_Pf ? 1 : 0) << IGU_FID_ENCODE_IS_PF_SHIFT;
6988 u32 addr_encode = IGU_CMD_E2_PROD_UPD_BASE + idu_sb_id;
6990 /* Not supported in BC mode */
6991 if (CHIP_INT_MODE_IS_BC(bp))
6994 data = (IGU_USE_REGISTER_cstorm_type_0_sb_cleanup
6995 << IGU_REGULAR_CLEANUP_TYPE_SHIFT) |
6996 IGU_REGULAR_CLEANUP_SET |
6997 IGU_REGULAR_BCLEANUP;
6999 ctl = addr_encode << IGU_CTRL_REG_ADDRESS_SHIFT |
7000 func_encode << IGU_CTRL_REG_FID_SHIFT |
7001 IGU_CTRL_CMD_TYPE_WR << IGU_CTRL_REG_TYPE_SHIFT;
7003 DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
7004 data, igu_addr_data);
7005 REG_WR(bp, igu_addr_data, data);
7008 DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
7010 REG_WR(bp, igu_addr_ctl, ctl);
7014 /* wait for clean up to finish */
7015 while (!(REG_RD(bp, igu_addr_ack) & sb_bit) && --cnt)
7019 if (!(REG_RD(bp, igu_addr_ack) & sb_bit)) {
7021 "Unable to finish IGU cleanup: idu_sb_id %d offset %d bit %d (cnt %d)\n",
7022 idu_sb_id, idu_sb_id/32, idu_sb_id%32, cnt);
7026 static void bnx2x_igu_clear_sb(struct bnx2x *bp, u8 idu_sb_id)
7028 bnx2x_igu_clear_sb_gen(bp, BP_FUNC(bp), idu_sb_id, true /*PF*/);
7031 static void bnx2x_clear_func_ilt(struct bnx2x *bp, u32 func)
7033 u32 i, base = FUNC_ILT_BASE(func);
7034 for (i = base; i < base + ILT_PER_FUNC; i++)
7035 bnx2x_ilt_wr(bp, i, 0);
7038 static int bnx2x_init_hw_func(struct bnx2x *bp)
7040 int port = BP_PORT(bp);
7041 int func = BP_FUNC(bp);
7042 int init_phase = PHASE_PF0 + func;
7043 struct bnx2x_ilt *ilt = BP_ILT(bp);
7046 u32 main_mem_base, main_mem_size, main_mem_prty_clr;
7047 int i, main_mem_width, rc;
7049 DP(NETIF_MSG_HW, "starting func init func %d\n", func);
7051 /* FLR cleanup - hmmm */
7052 if (!CHIP_IS_E1x(bp)) {
7053 rc = bnx2x_pf_flr_clnup(bp);
7058 /* set MSI reconfigure capability */
7059 if (bp->common.int_block == INT_BLOCK_HC) {
7060 addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0);
7061 val = REG_RD(bp, addr);
7062 val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0;
7063 REG_WR(bp, addr, val);
7066 bnx2x_init_block(bp, BLOCK_PXP, init_phase);
7067 bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
7070 cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
7072 for (i = 0; i < L2_ILT_LINES(bp); i++) {
7073 ilt->lines[cdu_ilt_start + i].page = bp->context[i].vcxt;
7074 ilt->lines[cdu_ilt_start + i].page_mapping =
7075 bp->context[i].cxt_mapping;
7076 ilt->lines[cdu_ilt_start + i].size = bp->context[i].size;
7078 bnx2x_ilt_init_op(bp, INITOP_SET);
7081 bnx2x_src_init_t2(bp, bp->t2, bp->t2_mapping, SRC_CONN_NUM);
7083 /* T1 hash bits value determines the T1 number of entries */
7084 REG_WR(bp, SRC_REG_NUMBER_HASH_BITS0 + port*4, SRC_HASH_BITS);
7089 REG_WR(bp, PRS_REG_NIC_MODE, 1);
7090 #endif /* BCM_CNIC */
7092 if (!CHIP_IS_E1x(bp)) {
7093 u32 pf_conf = IGU_PF_CONF_FUNC_EN;
7095 /* Turn on a single ISR mode in IGU if driver is going to use
7098 if (!(bp->flags & USING_MSIX_FLAG))
7099 pf_conf |= IGU_PF_CONF_SINGLE_ISR_EN;
7101 * Timers workaround bug: function init part.
7102 * Need to wait 20msec after initializing ILT,
7103 * needed to make sure there are no requests in
7104 * one of the PXP internal queues with "old" ILT addresses
7108 * Master enable - Due to WB DMAE writes performed before this
7109 * register is re-initialized as part of the regular function
7112 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
7113 /* Enable the function in IGU */
7114 REG_WR(bp, IGU_REG_PF_CONFIGURATION, pf_conf);
7119 bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
7121 if (!CHIP_IS_E1x(bp))
7122 REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR, func);
7124 bnx2x_init_block(bp, BLOCK_ATC, init_phase);
7125 bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
7126 bnx2x_init_block(bp, BLOCK_NIG, init_phase);
7127 bnx2x_init_block(bp, BLOCK_SRC, init_phase);
7128 bnx2x_init_block(bp, BLOCK_MISC, init_phase);
7129 bnx2x_init_block(bp, BLOCK_TCM, init_phase);
7130 bnx2x_init_block(bp, BLOCK_UCM, init_phase);
7131 bnx2x_init_block(bp, BLOCK_CCM, init_phase);
7132 bnx2x_init_block(bp, BLOCK_XCM, init_phase);
7133 bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
7134 bnx2x_init_block(bp, BLOCK_USEM, init_phase);
7135 bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
7136 bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
7138 if (!CHIP_IS_E1x(bp))
7139 REG_WR(bp, QM_REG_PF_EN, 1);
7141 if (!CHIP_IS_E1x(bp)) {
7142 REG_WR(bp, TSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
7143 REG_WR(bp, USEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
7144 REG_WR(bp, CSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
7145 REG_WR(bp, XSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
7147 bnx2x_init_block(bp, BLOCK_QM, init_phase);
7149 bnx2x_init_block(bp, BLOCK_TM, init_phase);
7150 bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
7151 bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
7152 bnx2x_init_block(bp, BLOCK_PRS, init_phase);
7153 bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
7154 bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
7155 bnx2x_init_block(bp, BLOCK_USDM, init_phase);
7156 bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
7157 bnx2x_init_block(bp, BLOCK_UPB, init_phase);
7158 bnx2x_init_block(bp, BLOCK_XPB, init_phase);
7159 bnx2x_init_block(bp, BLOCK_PBF, init_phase);
7160 if (!CHIP_IS_E1x(bp))
7161 REG_WR(bp, PBF_REG_DISABLE_PF, 0);
7163 bnx2x_init_block(bp, BLOCK_CDU, init_phase);
7165 bnx2x_init_block(bp, BLOCK_CFC, init_phase);
7167 if (!CHIP_IS_E1x(bp))
7168 REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 1);
7171 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
7172 REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + port*8, bp->mf_ov);
7175 bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
7177 /* HC init per function */
7178 if (bp->common.int_block == INT_BLOCK_HC) {
7179 if (CHIP_IS_E1H(bp)) {
7180 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
7182 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
7183 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
7185 bnx2x_init_block(bp, BLOCK_HC, init_phase);
7188 int num_segs, sb_idx, prod_offset;
7190 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
7192 if (!CHIP_IS_E1x(bp)) {
7193 REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
7194 REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
7197 bnx2x_init_block(bp, BLOCK_IGU, init_phase);
7199 if (!CHIP_IS_E1x(bp)) {
7203 * E2 mode: address 0-135 match to the mapping memory;
7204 * 136 - PF0 default prod; 137 - PF1 default prod;
7205 * 138 - PF2 default prod; 139 - PF3 default prod;
7206 * 140 - PF0 attn prod; 141 - PF1 attn prod;
7207 * 142 - PF2 attn prod; 143 - PF3 attn prod;
7210 * E1.5 mode - In backward compatible mode;
7211 * for non default SB; each even line in the memory
7212 * holds the U producer and each odd line hold
7213 * the C producer. The first 128 producers are for
7214 * NDSB (PF0 - 0-31; PF1 - 32-63 and so on). The last 20
7215 * producers are for the DSB for each PF.
7216 * Each PF has five segments: (the order inside each
7217 * segment is PF0; PF1; PF2; PF3) - 128-131 U prods;
7218 * 132-135 C prods; 136-139 X prods; 140-143 T prods;
7219 * 144-147 attn prods;
7221 /* non-default-status-blocks */
7222 num_segs = CHIP_INT_MODE_IS_BC(bp) ?
7223 IGU_BC_NDSB_NUM_SEGS : IGU_NORM_NDSB_NUM_SEGS;
7224 for (sb_idx = 0; sb_idx < bp->igu_sb_cnt; sb_idx++) {
7225 prod_offset = (bp->igu_base_sb + sb_idx) *
7228 for (i = 0; i < num_segs; i++) {
7229 addr = IGU_REG_PROD_CONS_MEMORY +
7230 (prod_offset + i) * 4;
7231 REG_WR(bp, addr, 0);
7233 /* send consumer update with value 0 */
7234 bnx2x_ack_sb(bp, bp->igu_base_sb + sb_idx,
7235 USTORM_ID, 0, IGU_INT_NOP, 1);
7236 bnx2x_igu_clear_sb(bp,
7237 bp->igu_base_sb + sb_idx);
7240 /* default-status-blocks */
7241 num_segs = CHIP_INT_MODE_IS_BC(bp) ?
7242 IGU_BC_DSB_NUM_SEGS : IGU_NORM_DSB_NUM_SEGS;
7244 if (CHIP_MODE_IS_4_PORT(bp))
7245 dsb_idx = BP_FUNC(bp);
7247 dsb_idx = BP_VN(bp);
7249 prod_offset = (CHIP_INT_MODE_IS_BC(bp) ?
7250 IGU_BC_BASE_DSB_PROD + dsb_idx :
7251 IGU_NORM_BASE_DSB_PROD + dsb_idx);
7254 * igu prods come in chunks of E1HVN_MAX (4) -
7255 * does not matters what is the current chip mode
7257 for (i = 0; i < (num_segs * E1HVN_MAX);
7259 addr = IGU_REG_PROD_CONS_MEMORY +
7260 (prod_offset + i)*4;
7261 REG_WR(bp, addr, 0);
7263 /* send consumer update with 0 */
7264 if (CHIP_INT_MODE_IS_BC(bp)) {
7265 bnx2x_ack_sb(bp, bp->igu_dsb_id,
7266 USTORM_ID, 0, IGU_INT_NOP, 1);
7267 bnx2x_ack_sb(bp, bp->igu_dsb_id,
7268 CSTORM_ID, 0, IGU_INT_NOP, 1);
7269 bnx2x_ack_sb(bp, bp->igu_dsb_id,
7270 XSTORM_ID, 0, IGU_INT_NOP, 1);
7271 bnx2x_ack_sb(bp, bp->igu_dsb_id,
7272 TSTORM_ID, 0, IGU_INT_NOP, 1);
7273 bnx2x_ack_sb(bp, bp->igu_dsb_id,
7274 ATTENTION_ID, 0, IGU_INT_NOP, 1);
7276 bnx2x_ack_sb(bp, bp->igu_dsb_id,
7277 USTORM_ID, 0, IGU_INT_NOP, 1);
7278 bnx2x_ack_sb(bp, bp->igu_dsb_id,
7279 ATTENTION_ID, 0, IGU_INT_NOP, 1);
7281 bnx2x_igu_clear_sb(bp, bp->igu_dsb_id);
7283 /* !!! these should become driver const once
7284 rf-tool supports split-68 const */
7285 REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_LSB, 0);
7286 REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_MSB, 0);
7287 REG_WR(bp, IGU_REG_SB_MASK_LSB, 0);
7288 REG_WR(bp, IGU_REG_SB_MASK_MSB, 0);
7289 REG_WR(bp, IGU_REG_PBA_STATUS_LSB, 0);
7290 REG_WR(bp, IGU_REG_PBA_STATUS_MSB, 0);
7294 /* Reset PCIE errors for debug */
7295 REG_WR(bp, 0x2114, 0xffffffff);
7296 REG_WR(bp, 0x2120, 0xffffffff);
7298 if (CHIP_IS_E1x(bp)) {
7299 main_mem_size = HC_REG_MAIN_MEMORY_SIZE / 2; /*dwords*/
7300 main_mem_base = HC_REG_MAIN_MEMORY +
7301 BP_PORT(bp) * (main_mem_size * 4);
7302 main_mem_prty_clr = HC_REG_HC_PRTY_STS_CLR;
7305 val = REG_RD(bp, main_mem_prty_clr);
7308 "Hmmm... Parity errors in HC block during function init (0x%x)!\n",
7311 /* Clear "false" parity errors in MSI-X table */
7312 for (i = main_mem_base;
7313 i < main_mem_base + main_mem_size * 4;
7314 i += main_mem_width) {
7315 bnx2x_read_dmae(bp, i, main_mem_width / 4);
7316 bnx2x_write_dmae(bp, bnx2x_sp_mapping(bp, wb_data),
7317 i, main_mem_width / 4);
7319 /* Clear HC parity attention */
7320 REG_RD(bp, main_mem_prty_clr);
7323 #ifdef BNX2X_STOP_ON_ERROR
7324 /* Enable STORMs SP logging */
7325 REG_WR8(bp, BAR_USTRORM_INTMEM +
7326 USTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
7327 REG_WR8(bp, BAR_TSTRORM_INTMEM +
7328 TSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
7329 REG_WR8(bp, BAR_CSTRORM_INTMEM +
7330 CSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
7331 REG_WR8(bp, BAR_XSTRORM_INTMEM +
7332 XSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
7335 bnx2x_phy_probe(&bp->link_params);
7341 void bnx2x_free_mem(struct bnx2x *bp)
7346 bnx2x_free_fp_mem(bp);
7347 /* end of fastpath */
7349 BNX2X_PCI_FREE(bp->def_status_blk, bp->def_status_blk_mapping,
7350 sizeof(struct host_sp_status_block));
7352 BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
7353 bp->fw_stats_data_sz + bp->fw_stats_req_sz);
7355 BNX2X_PCI_FREE(bp->slowpath, bp->slowpath_mapping,
7356 sizeof(struct bnx2x_slowpath));
7358 for (i = 0; i < L2_ILT_LINES(bp); i++)
7359 BNX2X_PCI_FREE(bp->context[i].vcxt, bp->context[i].cxt_mapping,
7360 bp->context[i].size);
7361 bnx2x_ilt_mem_op(bp, ILT_MEMOP_FREE);
7363 BNX2X_FREE(bp->ilt->lines);
7366 if (!CHIP_IS_E1x(bp))
7367 BNX2X_PCI_FREE(bp->cnic_sb.e2_sb, bp->cnic_sb_mapping,
7368 sizeof(struct host_hc_status_block_e2));
7370 BNX2X_PCI_FREE(bp->cnic_sb.e1x_sb, bp->cnic_sb_mapping,
7371 sizeof(struct host_hc_status_block_e1x));
7373 BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
7376 BNX2X_PCI_FREE(bp->spq, bp->spq_mapping, BCM_PAGE_SIZE);
7378 BNX2X_PCI_FREE(bp->eq_ring, bp->eq_mapping,
7379 BCM_PAGE_SIZE * NUM_EQ_PAGES);
7382 static int bnx2x_alloc_fw_stats_mem(struct bnx2x *bp)
7385 int is_fcoe_stats = NO_FCOE(bp) ? 0 : 1;
7387 /* number of queues for statistics is number of eth queues + FCoE */
7388 u8 num_queue_stats = BNX2X_NUM_ETH_QUEUES(bp) + is_fcoe_stats;
7390 /* Total number of FW statistics requests =
7391 * 1 for port stats + 1 for PF stats + potential 1 for FCoE stats +
7394 bp->fw_stats_num = 2 + is_fcoe_stats + num_queue_stats;
7397 /* Request is built from stats_query_header and an array of
7398 * stats_query_cmd_group each of which contains
7399 * STATS_QUERY_CMD_COUNT rules. The real number or requests is
7400 * configured in the stats_query_header.
7402 num_groups = ((bp->fw_stats_num) / STATS_QUERY_CMD_COUNT) +
7403 (((bp->fw_stats_num) % STATS_QUERY_CMD_COUNT) ? 1 : 0);
7405 bp->fw_stats_req_sz = sizeof(struct stats_query_header) +
7406 num_groups * sizeof(struct stats_query_cmd_group);
7408 /* Data for statistics requests + stats_conter
7410 * stats_counter holds per-STORM counters that are incremented
7411 * when STORM has finished with the current request.
7413 * memory for FCoE offloaded statistics are counted anyway,
7414 * even if they will not be sent.
7416 bp->fw_stats_data_sz = sizeof(struct per_port_stats) +
7417 sizeof(struct per_pf_stats) +
7418 sizeof(struct fcoe_statistics_params) +
7419 sizeof(struct per_queue_stats) * num_queue_stats +
7420 sizeof(struct stats_counter);
7422 BNX2X_PCI_ALLOC(bp->fw_stats, &bp->fw_stats_mapping,
7423 bp->fw_stats_data_sz + bp->fw_stats_req_sz);
7426 bp->fw_stats_req = (struct bnx2x_fw_stats_req *)bp->fw_stats;
7427 bp->fw_stats_req_mapping = bp->fw_stats_mapping;
7429 bp->fw_stats_data = (struct bnx2x_fw_stats_data *)
7430 ((u8 *)bp->fw_stats + bp->fw_stats_req_sz);
7432 bp->fw_stats_data_mapping = bp->fw_stats_mapping +
7433 bp->fw_stats_req_sz;
7437 BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
7438 bp->fw_stats_data_sz + bp->fw_stats_req_sz);
7439 BNX2X_ERR("Can't allocate memory\n");
7444 int bnx2x_alloc_mem(struct bnx2x *bp)
7446 int i, allocated, context_size;
7449 if (!CHIP_IS_E1x(bp))
7450 /* size = the status block + ramrod buffers */
7451 BNX2X_PCI_ALLOC(bp->cnic_sb.e2_sb, &bp->cnic_sb_mapping,
7452 sizeof(struct host_hc_status_block_e2));
7454 BNX2X_PCI_ALLOC(bp->cnic_sb.e1x_sb, &bp->cnic_sb_mapping,
7455 sizeof(struct host_hc_status_block_e1x));
7457 /* allocate searcher T2 table */
7458 BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ);
7462 BNX2X_PCI_ALLOC(bp->def_status_blk, &bp->def_status_blk_mapping,
7463 sizeof(struct host_sp_status_block));
7465 BNX2X_PCI_ALLOC(bp->slowpath, &bp->slowpath_mapping,
7466 sizeof(struct bnx2x_slowpath));
7469 /* write address to which L5 should insert its values */
7470 bp->cnic_eth_dev.addr_drv_info_to_mcp = &bp->slowpath->drv_info_to_mcp;
7473 /* Allocated memory for FW statistics */
7474 if (bnx2x_alloc_fw_stats_mem(bp))
7477 /* Allocate memory for CDU context:
7478 * This memory is allocated separately and not in the generic ILT
7479 * functions because CDU differs in few aspects:
7480 * 1. There are multiple entities allocating memory for context -
7481 * 'regular' driver, CNIC and SRIOV driver. Each separately controls
7482 * its own ILT lines.
7483 * 2. Since CDU page-size is not a single 4KB page (which is the case
7484 * for the other ILT clients), to be efficient we want to support
7485 * allocation of sub-page-size in the last entry.
7486 * 3. Context pointers are used by the driver to pass to FW / update
7487 * the context (for the other ILT clients the pointers are used just to
7488 * free the memory during unload).
7490 context_size = sizeof(union cdu_context) * BNX2X_L2_CID_COUNT(bp);
7492 for (i = 0, allocated = 0; allocated < context_size; i++) {
7493 bp->context[i].size = min(CDU_ILT_PAGE_SZ,
7494 (context_size - allocated));
7495 BNX2X_PCI_ALLOC(bp->context[i].vcxt,
7496 &bp->context[i].cxt_mapping,
7497 bp->context[i].size);
7498 allocated += bp->context[i].size;
7500 BNX2X_ALLOC(bp->ilt->lines, sizeof(struct ilt_line) * ILT_MAX_LINES);
7502 if (bnx2x_ilt_mem_op(bp, ILT_MEMOP_ALLOC))
7505 /* Slow path ring */
7506 BNX2X_PCI_ALLOC(bp->spq, &bp->spq_mapping, BCM_PAGE_SIZE);
7509 BNX2X_PCI_ALLOC(bp->eq_ring, &bp->eq_mapping,
7510 BCM_PAGE_SIZE * NUM_EQ_PAGES);
7514 /* need to be done at the end, since it's self adjusting to amount
7515 * of memory available for RSS queues
7517 if (bnx2x_alloc_fp_mem(bp))
7523 BNX2X_ERR("Can't allocate memory\n");
7528 * Init service functions
7531 int bnx2x_set_mac_one(struct bnx2x *bp, u8 *mac,
7532 struct bnx2x_vlan_mac_obj *obj, bool set,
7533 int mac_type, unsigned long *ramrod_flags)
7536 struct bnx2x_vlan_mac_ramrod_params ramrod_param;
7538 memset(&ramrod_param, 0, sizeof(ramrod_param));
7540 /* Fill general parameters */
7541 ramrod_param.vlan_mac_obj = obj;
7542 ramrod_param.ramrod_flags = *ramrod_flags;
7544 /* Fill a user request section if needed */
7545 if (!test_bit(RAMROD_CONT, ramrod_flags)) {
7546 memcpy(ramrod_param.user_req.u.mac.mac, mac, ETH_ALEN);
7548 __set_bit(mac_type, &ramrod_param.user_req.vlan_mac_flags);
7550 /* Set the command: ADD or DEL */
7552 ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_ADD;
7554 ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_DEL;
7557 rc = bnx2x_config_vlan_mac(bp, &ramrod_param);
7559 BNX2X_ERR("%s MAC failed\n", (set ? "Set" : "Del"));
7563 int bnx2x_del_all_macs(struct bnx2x *bp,
7564 struct bnx2x_vlan_mac_obj *mac_obj,
7565 int mac_type, bool wait_for_comp)
7568 unsigned long ramrod_flags = 0, vlan_mac_flags = 0;
7570 /* Wait for completion of requested */
7572 __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
7574 /* Set the mac type of addresses we want to clear */
7575 __set_bit(mac_type, &vlan_mac_flags);
7577 rc = mac_obj->delete_all(bp, mac_obj, &vlan_mac_flags, &ramrod_flags);
7579 BNX2X_ERR("Failed to delete MACs: %d\n", rc);
7584 int bnx2x_set_eth_mac(struct bnx2x *bp, bool set)
7586 unsigned long ramrod_flags = 0;
7589 if (is_zero_ether_addr(bp->dev->dev_addr) &&
7590 (IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp))) {
7591 DP(NETIF_MSG_IFUP | NETIF_MSG_IFDOWN,
7592 "Ignoring Zero MAC for STORAGE SD mode\n");
7597 DP(NETIF_MSG_IFUP, "Adding Eth MAC\n");
7599 __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
7600 /* Eth MAC is set on RSS leading client (fp[0]) */
7601 return bnx2x_set_mac_one(bp, bp->dev->dev_addr, &bp->sp_objs->mac_obj,
7602 set, BNX2X_ETH_MAC, &ramrod_flags);
7605 int bnx2x_setup_leading(struct bnx2x *bp)
7607 return bnx2x_setup_queue(bp, &bp->fp[0], 1);
7611 * bnx2x_set_int_mode - configure interrupt mode
7613 * @bp: driver handle
7615 * In case of MSI-X it will also try to enable MSI-X.
7617 void bnx2x_set_int_mode(struct bnx2x *bp)
7621 bnx2x_enable_msi(bp);
7622 /* falling through... */
7624 bp->num_queues = 1 + NON_ETH_CONTEXT_USE;
7625 BNX2X_DEV_INFO("set number of queues to 1\n");
7628 /* if we can't use MSI-X we only need one fp,
7629 * so try to enable MSI-X with the requested number of fp's
7630 * and fallback to MSI or legacy INTx with one fp
7632 if (bnx2x_enable_msix(bp) ||
7633 bp->flags & USING_SINGLE_MSIX_FLAG) {
7634 /* failed to enable multiple MSI-X */
7635 BNX2X_DEV_INFO("Failed to enable multiple MSI-X (%d), set number of queues to %d\n",
7636 bp->num_queues, 1 + NON_ETH_CONTEXT_USE);
7638 bp->num_queues = 1 + NON_ETH_CONTEXT_USE;
7640 /* Try to enable MSI */
7641 if (!(bp->flags & USING_SINGLE_MSIX_FLAG) &&
7642 !(bp->flags & DISABLE_MSI_FLAG))
7643 bnx2x_enable_msi(bp);
7649 /* must be called prioir to any HW initializations */
7650 static inline u16 bnx2x_cid_ilt_lines(struct bnx2x *bp)
7652 return L2_ILT_LINES(bp);
7655 void bnx2x_ilt_set_info(struct bnx2x *bp)
7657 struct ilt_client_info *ilt_client;
7658 struct bnx2x_ilt *ilt = BP_ILT(bp);
7661 ilt->start_line = FUNC_ILT_BASE(BP_FUNC(bp));
7662 DP(BNX2X_MSG_SP, "ilt starts at line %d\n", ilt->start_line);
7665 ilt_client = &ilt->clients[ILT_CLIENT_CDU];
7666 ilt_client->client_num = ILT_CLIENT_CDU;
7667 ilt_client->page_size = CDU_ILT_PAGE_SZ;
7668 ilt_client->flags = ILT_CLIENT_SKIP_MEM;
7669 ilt_client->start = line;
7670 line += bnx2x_cid_ilt_lines(bp);
7672 line += CNIC_ILT_LINES;
7674 ilt_client->end = line - 1;
7676 DP(NETIF_MSG_IFUP, "ilt client[CDU]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
7679 ilt_client->page_size,
7681 ilog2(ilt_client->page_size >> 12));
7684 if (QM_INIT(bp->qm_cid_count)) {
7685 ilt_client = &ilt->clients[ILT_CLIENT_QM];
7686 ilt_client->client_num = ILT_CLIENT_QM;
7687 ilt_client->page_size = QM_ILT_PAGE_SZ;
7688 ilt_client->flags = 0;
7689 ilt_client->start = line;
7691 /* 4 bytes for each cid */
7692 line += DIV_ROUND_UP(bp->qm_cid_count * QM_QUEUES_PER_FUNC * 4,
7695 ilt_client->end = line - 1;
7698 "ilt client[QM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
7701 ilt_client->page_size,
7703 ilog2(ilt_client->page_size >> 12));
7707 ilt_client = &ilt->clients[ILT_CLIENT_SRC];
7709 ilt_client->client_num = ILT_CLIENT_SRC;
7710 ilt_client->page_size = SRC_ILT_PAGE_SZ;
7711 ilt_client->flags = 0;
7712 ilt_client->start = line;
7713 line += SRC_ILT_LINES;
7714 ilt_client->end = line - 1;
7717 "ilt client[SRC]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
7720 ilt_client->page_size,
7722 ilog2(ilt_client->page_size >> 12));
7725 ilt_client->flags = (ILT_CLIENT_SKIP_INIT | ILT_CLIENT_SKIP_MEM);
7729 ilt_client = &ilt->clients[ILT_CLIENT_TM];
7731 ilt_client->client_num = ILT_CLIENT_TM;
7732 ilt_client->page_size = TM_ILT_PAGE_SZ;
7733 ilt_client->flags = 0;
7734 ilt_client->start = line;
7735 line += TM_ILT_LINES;
7736 ilt_client->end = line - 1;
7739 "ilt client[TM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
7742 ilt_client->page_size,
7744 ilog2(ilt_client->page_size >> 12));
7747 ilt_client->flags = (ILT_CLIENT_SKIP_INIT | ILT_CLIENT_SKIP_MEM);
7749 BUG_ON(line > ILT_MAX_LINES);
7753 * bnx2x_pf_q_prep_init - prepare INIT transition parameters
7755 * @bp: driver handle
7756 * @fp: pointer to fastpath
7757 * @init_params: pointer to parameters structure
7759 * parameters configured:
7760 * - HC configuration
7761 * - Queue's CDU context
7763 static void bnx2x_pf_q_prep_init(struct bnx2x *bp,
7764 struct bnx2x_fastpath *fp, struct bnx2x_queue_init_params *init_params)
7768 int cxt_index, cxt_offset;
7770 /* FCoE Queue uses Default SB, thus has no HC capabilities */
7771 if (!IS_FCOE_FP(fp)) {
7772 __set_bit(BNX2X_Q_FLG_HC, &init_params->rx.flags);
7773 __set_bit(BNX2X_Q_FLG_HC, &init_params->tx.flags);
7775 /* If HC is supporterd, enable host coalescing in the transition
7778 __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->rx.flags);
7779 __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->tx.flags);
7782 init_params->rx.hc_rate = bp->rx_ticks ?
7783 (1000000 / bp->rx_ticks) : 0;
7784 init_params->tx.hc_rate = bp->tx_ticks ?
7785 (1000000 / bp->tx_ticks) : 0;
7788 init_params->rx.fw_sb_id = init_params->tx.fw_sb_id =
7792 * CQ index among the SB indices: FCoE clients uses the default
7793 * SB, therefore it's different.
7795 init_params->rx.sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
7796 init_params->tx.sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS;
7799 /* set maximum number of COSs supported by this queue */
7800 init_params->max_cos = fp->max_cos;
7802 DP(NETIF_MSG_IFUP, "fp: %d setting queue params max cos to: %d\n",
7803 fp->index, init_params->max_cos);
7805 /* set the context pointers queue object */
7806 for (cos = FIRST_TX_COS_INDEX; cos < init_params->max_cos; cos++) {
7807 cxt_index = fp->txdata_ptr[cos]->cid / ILT_PAGE_CIDS;
7808 cxt_offset = fp->txdata_ptr[cos]->cid - (cxt_index *
7810 init_params->cxts[cos] =
7811 &bp->context[cxt_index].vcxt[cxt_offset].eth;
7815 int bnx2x_setup_tx_only(struct bnx2x *bp, struct bnx2x_fastpath *fp,
7816 struct bnx2x_queue_state_params *q_params,
7817 struct bnx2x_queue_setup_tx_only_params *tx_only_params,
7818 int tx_index, bool leading)
7820 memset(tx_only_params, 0, sizeof(*tx_only_params));
7822 /* Set the command */
7823 q_params->cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
7825 /* Set tx-only QUEUE flags: don't zero statistics */
7826 tx_only_params->flags = bnx2x_get_common_flags(bp, fp, false);
7828 /* choose the index of the cid to send the slow path on */
7829 tx_only_params->cid_index = tx_index;
7831 /* Set general TX_ONLY_SETUP parameters */
7832 bnx2x_pf_q_prep_general(bp, fp, &tx_only_params->gen_params, tx_index);
7834 /* Set Tx TX_ONLY_SETUP parameters */
7835 bnx2x_pf_tx_q_prep(bp, fp, &tx_only_params->txq_params, tx_index);
7838 "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",
7839 tx_index, q_params->q_obj->cids[FIRST_TX_COS_INDEX],
7840 q_params->q_obj->cids[tx_index], q_params->q_obj->cl_id,
7841 tx_only_params->gen_params.spcl_id, tx_only_params->flags);
7843 /* send the ramrod */
7844 return bnx2x_queue_state_change(bp, q_params);
7849 * bnx2x_setup_queue - setup queue
7851 * @bp: driver handle
7852 * @fp: pointer to fastpath
7853 * @leading: is leading
7855 * This function performs 2 steps in a Queue state machine
7856 * actually: 1) RESET->INIT 2) INIT->SETUP
7859 int bnx2x_setup_queue(struct bnx2x *bp, struct bnx2x_fastpath *fp,
7862 struct bnx2x_queue_state_params q_params = {NULL};
7863 struct bnx2x_queue_setup_params *setup_params =
7864 &q_params.params.setup;
7865 struct bnx2x_queue_setup_tx_only_params *tx_only_params =
7866 &q_params.params.tx_only;
7870 DP(NETIF_MSG_IFUP, "setting up queue %d\n", fp->index);
7872 /* reset IGU state skip FCoE L2 queue */
7873 if (!IS_FCOE_FP(fp))
7874 bnx2x_ack_sb(bp, fp->igu_sb_id, USTORM_ID, 0,
7877 q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
7878 /* We want to wait for completion in this context */
7879 __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
7881 /* Prepare the INIT parameters */
7882 bnx2x_pf_q_prep_init(bp, fp, &q_params.params.init);
7884 /* Set the command */
7885 q_params.cmd = BNX2X_Q_CMD_INIT;
7887 /* Change the state to INIT */
7888 rc = bnx2x_queue_state_change(bp, &q_params);
7890 BNX2X_ERR("Queue(%d) INIT failed\n", fp->index);
7894 DP(NETIF_MSG_IFUP, "init complete\n");
7897 /* Now move the Queue to the SETUP state... */
7898 memset(setup_params, 0, sizeof(*setup_params));
7900 /* Set QUEUE flags */
7901 setup_params->flags = bnx2x_get_q_flags(bp, fp, leading);
7903 /* Set general SETUP parameters */
7904 bnx2x_pf_q_prep_general(bp, fp, &setup_params->gen_params,
7905 FIRST_TX_COS_INDEX);
7907 bnx2x_pf_rx_q_prep(bp, fp, &setup_params->pause_params,
7908 &setup_params->rxq_params);
7910 bnx2x_pf_tx_q_prep(bp, fp, &setup_params->txq_params,
7911 FIRST_TX_COS_INDEX);
7913 /* Set the command */
7914 q_params.cmd = BNX2X_Q_CMD_SETUP;
7916 /* Change the state to SETUP */
7917 rc = bnx2x_queue_state_change(bp, &q_params);
7919 BNX2X_ERR("Queue(%d) SETUP failed\n", fp->index);
7923 /* loop through the relevant tx-only indices */
7924 for (tx_index = FIRST_TX_ONLY_COS_INDEX;
7925 tx_index < fp->max_cos;
7928 /* prepare and send tx-only ramrod*/
7929 rc = bnx2x_setup_tx_only(bp, fp, &q_params,
7930 tx_only_params, tx_index, leading);
7932 BNX2X_ERR("Queue(%d.%d) TX_ONLY_SETUP failed\n",
7933 fp->index, tx_index);
7941 static int bnx2x_stop_queue(struct bnx2x *bp, int index)
7943 struct bnx2x_fastpath *fp = &bp->fp[index];
7944 struct bnx2x_fp_txdata *txdata;
7945 struct bnx2x_queue_state_params q_params = {NULL};
7948 DP(NETIF_MSG_IFDOWN, "stopping queue %d cid %d\n", index, fp->cid);
7950 q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
7951 /* We want to wait for completion in this context */
7952 __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
7955 /* close tx-only connections */
7956 for (tx_index = FIRST_TX_ONLY_COS_INDEX;
7957 tx_index < fp->max_cos;
7960 /* ascertain this is a normal queue*/
7961 txdata = fp->txdata_ptr[tx_index];
7963 DP(NETIF_MSG_IFDOWN, "stopping tx-only queue %d\n",
7966 /* send halt terminate on tx-only connection */
7967 q_params.cmd = BNX2X_Q_CMD_TERMINATE;
7968 memset(&q_params.params.terminate, 0,
7969 sizeof(q_params.params.terminate));
7970 q_params.params.terminate.cid_index = tx_index;
7972 rc = bnx2x_queue_state_change(bp, &q_params);
7976 /* send halt terminate on tx-only connection */
7977 q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
7978 memset(&q_params.params.cfc_del, 0,
7979 sizeof(q_params.params.cfc_del));
7980 q_params.params.cfc_del.cid_index = tx_index;
7981 rc = bnx2x_queue_state_change(bp, &q_params);
7985 /* Stop the primary connection: */
7986 /* ...halt the connection */
7987 q_params.cmd = BNX2X_Q_CMD_HALT;
7988 rc = bnx2x_queue_state_change(bp, &q_params);
7992 /* ...terminate the connection */
7993 q_params.cmd = BNX2X_Q_CMD_TERMINATE;
7994 memset(&q_params.params.terminate, 0,
7995 sizeof(q_params.params.terminate));
7996 q_params.params.terminate.cid_index = FIRST_TX_COS_INDEX;
7997 rc = bnx2x_queue_state_change(bp, &q_params);
8000 /* ...delete cfc entry */
8001 q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
8002 memset(&q_params.params.cfc_del, 0,
8003 sizeof(q_params.params.cfc_del));
8004 q_params.params.cfc_del.cid_index = FIRST_TX_COS_INDEX;
8005 return bnx2x_queue_state_change(bp, &q_params);
8009 static void bnx2x_reset_func(struct bnx2x *bp)
8011 int port = BP_PORT(bp);
8012 int func = BP_FUNC(bp);
8015 /* Disable the function in the FW */
8016 REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(func), 0);
8017 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(func), 0);
8018 REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(func), 0);
8019 REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(func), 0);
8022 for_each_eth_queue(bp, i) {
8023 struct bnx2x_fastpath *fp = &bp->fp[i];
8024 REG_WR8(bp, BAR_CSTRORM_INTMEM +
8025 CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(fp->fw_sb_id),
8031 REG_WR8(bp, BAR_CSTRORM_INTMEM +
8032 CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(bnx2x_cnic_fw_sb_id(bp)),
8036 REG_WR8(bp, BAR_CSTRORM_INTMEM +
8037 CSTORM_SP_STATUS_BLOCK_DATA_STATE_OFFSET(func),
8040 for (i = 0; i < XSTORM_SPQ_DATA_SIZE / 4; i++)
8041 REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_DATA_OFFSET(func),
8045 if (bp->common.int_block == INT_BLOCK_HC) {
8046 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
8047 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
8049 REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
8050 REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
8054 /* Disable Timer scan */
8055 REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + port*4, 0);
8057 * Wait for at least 10ms and up to 2 second for the timers scan to
8060 for (i = 0; i < 200; i++) {
8062 if (!REG_RD(bp, TM_REG_LIN0_SCAN_ON + port*4))
8067 bnx2x_clear_func_ilt(bp, func);
8069 /* Timers workaround bug for E2: if this is vnic-3,
8070 * we need to set the entire ilt range for this timers.
8072 if (!CHIP_IS_E1x(bp) && BP_VN(bp) == 3) {
8073 struct ilt_client_info ilt_cli;
8074 /* use dummy TM client */
8075 memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
8077 ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
8078 ilt_cli.client_num = ILT_CLIENT_TM;
8080 bnx2x_ilt_boundry_init_op(bp, &ilt_cli, 0, INITOP_CLEAR);
8083 /* this assumes that reset_port() called before reset_func()*/
8084 if (!CHIP_IS_E1x(bp))
8085 bnx2x_pf_disable(bp);
8090 static void bnx2x_reset_port(struct bnx2x *bp)
8092 int port = BP_PORT(bp);
8095 /* Reset physical Link */
8096 bnx2x__link_reset(bp);
8098 REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
8100 /* Do not rcv packets to BRB */
8101 REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0);
8102 /* Do not direct rcv packets that are not for MCP to the BRB */
8103 REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
8104 NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
8107 REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0);
8110 /* Check for BRB port occupancy */
8111 val = REG_RD(bp, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4);
8113 DP(NETIF_MSG_IFDOWN,
8114 "BRB1 is not empty %d blocks are occupied\n", val);
8116 /* TODO: Close Doorbell port? */
8119 static int bnx2x_reset_hw(struct bnx2x *bp, u32 load_code)
8121 struct bnx2x_func_state_params func_params = {NULL};
8123 /* Prepare parameters for function state transitions */
8124 __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
8126 func_params.f_obj = &bp->func_obj;
8127 func_params.cmd = BNX2X_F_CMD_HW_RESET;
8129 func_params.params.hw_init.load_phase = load_code;
8131 return bnx2x_func_state_change(bp, &func_params);
8134 static int bnx2x_func_stop(struct bnx2x *bp)
8136 struct bnx2x_func_state_params func_params = {NULL};
8139 /* Prepare parameters for function state transitions */
8140 __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
8141 func_params.f_obj = &bp->func_obj;
8142 func_params.cmd = BNX2X_F_CMD_STOP;
8145 * Try to stop the function the 'good way'. If fails (in case
8146 * of a parity error during bnx2x_chip_cleanup()) and we are
8147 * not in a debug mode, perform a state transaction in order to
8148 * enable further HW_RESET transaction.
8150 rc = bnx2x_func_state_change(bp, &func_params);
8152 #ifdef BNX2X_STOP_ON_ERROR
8155 BNX2X_ERR("FUNC_STOP ramrod failed. Running a dry transaction\n");
8156 __set_bit(RAMROD_DRV_CLR_ONLY, &func_params.ramrod_flags);
8157 return bnx2x_func_state_change(bp, &func_params);
8165 * bnx2x_send_unload_req - request unload mode from the MCP.
8167 * @bp: driver handle
8168 * @unload_mode: requested function's unload mode
8170 * Return unload mode returned by the MCP: COMMON, PORT or FUNC.
8172 u32 bnx2x_send_unload_req(struct bnx2x *bp, int unload_mode)
8175 int port = BP_PORT(bp);
8177 /* Select the UNLOAD request mode */
8178 if (unload_mode == UNLOAD_NORMAL)
8179 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
8181 else if (bp->flags & NO_WOL_FLAG)
8182 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP;
8185 u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
8186 u8 *mac_addr = bp->dev->dev_addr;
8190 /* The mac address is written to entries 1-4 to
8191 * preserve entry 0 which is used by the PMF
8193 u8 entry = (BP_VN(bp) + 1)*8;
8195 val = (mac_addr[0] << 8) | mac_addr[1];
8196 EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry, val);
8198 val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
8199 (mac_addr[4] << 8) | mac_addr[5];
8200 EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry + 4, val);
8202 /* Enable the PME and clear the status */
8203 pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, &pmc);
8204 pmc |= PCI_PM_CTRL_PME_ENABLE | PCI_PM_CTRL_PME_STATUS;
8205 pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, pmc);
8207 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_EN;
8210 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
8212 /* Send the request to the MCP */
8214 reset_code = bnx2x_fw_command(bp, reset_code, 0);
8216 int path = BP_PATH(bp);
8218 DP(NETIF_MSG_IFDOWN, "NO MCP - load counts[%d] %d, %d, %d\n",
8219 path, load_count[path][0], load_count[path][1],
8220 load_count[path][2]);
8221 load_count[path][0]--;
8222 load_count[path][1 + port]--;
8223 DP(NETIF_MSG_IFDOWN, "NO MCP - new load counts[%d] %d, %d, %d\n",
8224 path, load_count[path][0], load_count[path][1],
8225 load_count[path][2]);
8226 if (load_count[path][0] == 0)
8227 reset_code = FW_MSG_CODE_DRV_UNLOAD_COMMON;
8228 else if (load_count[path][1 + port] == 0)
8229 reset_code = FW_MSG_CODE_DRV_UNLOAD_PORT;
8231 reset_code = FW_MSG_CODE_DRV_UNLOAD_FUNCTION;
8238 * bnx2x_send_unload_done - send UNLOAD_DONE command to the MCP.
8240 * @bp: driver handle
8242 void bnx2x_send_unload_done(struct bnx2x *bp)
8244 /* Report UNLOAD_DONE to MCP */
8246 bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
8249 static int bnx2x_func_wait_started(struct bnx2x *bp)
8252 int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
8258 * (assumption: No Attention from MCP at this stage)
8259 * PMF probably in the middle of TXdisable/enable transaction
8260 * 1. Sync IRS for default SB
8261 * 2. Sync SP queue - this guarantes us that attention handling started
8262 * 3. Wait, that TXdisable/enable transaction completes
8264 * 1+2 guranty that if DCBx attention was scheduled it already changed
8265 * pending bit of transaction from STARTED-->TX_STOPPED, if we alredy
8266 * received complettion for the transaction the state is TX_STOPPED.
8267 * State will return to STARTED after completion of TX_STOPPED-->STARTED
8271 /* make sure default SB ISR is done */
8273 synchronize_irq(bp->msix_table[0].vector);
8275 synchronize_irq(bp->pdev->irq);
8277 flush_workqueue(bnx2x_wq);
8279 while (bnx2x_func_get_state(bp, &bp->func_obj) !=
8280 BNX2X_F_STATE_STARTED && tout--)
8283 if (bnx2x_func_get_state(bp, &bp->func_obj) !=
8284 BNX2X_F_STATE_STARTED) {
8285 #ifdef BNX2X_STOP_ON_ERROR
8286 BNX2X_ERR("Wrong function state\n");
8290 * Failed to complete the transaction in a "good way"
8291 * Force both transactions with CLR bit
8293 struct bnx2x_func_state_params func_params = {NULL};
8295 DP(NETIF_MSG_IFDOWN,
8296 "Hmmm... unexpected function state! Forcing STARTED-->TX_ST0PPED-->STARTED\n");
8298 func_params.f_obj = &bp->func_obj;
8299 __set_bit(RAMROD_DRV_CLR_ONLY,
8300 &func_params.ramrod_flags);
8302 /* STARTED-->TX_ST0PPED */
8303 func_params.cmd = BNX2X_F_CMD_TX_STOP;
8304 bnx2x_func_state_change(bp, &func_params);
8306 /* TX_ST0PPED-->STARTED */
8307 func_params.cmd = BNX2X_F_CMD_TX_START;
8308 return bnx2x_func_state_change(bp, &func_params);
8315 void bnx2x_chip_cleanup(struct bnx2x *bp, int unload_mode)
8317 int port = BP_PORT(bp);
8320 struct bnx2x_mcast_ramrod_params rparam = {NULL};
8323 /* Wait until tx fastpath tasks complete */
8324 for_each_tx_queue(bp, i) {
8325 struct bnx2x_fastpath *fp = &bp->fp[i];
8327 for_each_cos_in_tx_queue(fp, cos)
8328 rc = bnx2x_clean_tx_queue(bp, fp->txdata_ptr[cos]);
8329 #ifdef BNX2X_STOP_ON_ERROR
8335 /* Give HW time to discard old tx messages */
8336 usleep_range(1000, 1000);
8338 /* Clean all ETH MACs */
8339 rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_ETH_MAC,
8342 BNX2X_ERR("Failed to delete all ETH macs: %d\n", rc);
8344 /* Clean up UC list */
8345 rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_UC_LIST_MAC,
8348 BNX2X_ERR("Failed to schedule DEL commands for UC MACs list: %d\n",
8352 if (!CHIP_IS_E1(bp))
8353 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
8355 /* Set "drop all" (stop Rx).
8356 * We need to take a netif_addr_lock() here in order to prevent
8357 * a race between the completion code and this code.
8359 netif_addr_lock_bh(bp->dev);
8360 /* Schedule the rx_mode command */
8361 if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
8362 set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
8364 bnx2x_set_storm_rx_mode(bp);
8366 /* Cleanup multicast configuration */
8367 rparam.mcast_obj = &bp->mcast_obj;
8368 rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
8370 BNX2X_ERR("Failed to send DEL multicast command: %d\n", rc);
8372 netif_addr_unlock_bh(bp->dev);
8377 * Send the UNLOAD_REQUEST to the MCP. This will return if
8378 * this function should perform FUNC, PORT or COMMON HW
8381 reset_code = bnx2x_send_unload_req(bp, unload_mode);
8384 * (assumption: No Attention from MCP at this stage)
8385 * PMF probably in the middle of TXdisable/enable transaction
8387 rc = bnx2x_func_wait_started(bp);
8389 BNX2X_ERR("bnx2x_func_wait_started failed\n");
8390 #ifdef BNX2X_STOP_ON_ERROR
8395 /* Close multi and leading connections
8396 * Completions for ramrods are collected in a synchronous way
8398 for_each_queue(bp, i)
8399 if (bnx2x_stop_queue(bp, i))
8400 #ifdef BNX2X_STOP_ON_ERROR
8405 /* If SP settings didn't get completed so far - something
8406 * very wrong has happen.
8408 if (!bnx2x_wait_sp_comp(bp, ~0x0UL))
8409 BNX2X_ERR("Hmmm... Common slow path ramrods got stuck!\n");
8411 #ifndef BNX2X_STOP_ON_ERROR
8414 rc = bnx2x_func_stop(bp);
8416 BNX2X_ERR("Function stop failed!\n");
8417 #ifdef BNX2X_STOP_ON_ERROR
8422 /* Disable HW interrupts, NAPI */
8423 bnx2x_netif_stop(bp, 1);
8424 /* Delete all NAPI objects */
8425 bnx2x_del_all_napi(bp);
8430 /* Reset the chip */
8431 rc = bnx2x_reset_hw(bp, reset_code);
8433 BNX2X_ERR("HW_RESET failed\n");
8436 /* Report UNLOAD_DONE to MCP */
8437 bnx2x_send_unload_done(bp);
8440 void bnx2x_disable_close_the_gate(struct bnx2x *bp)
8444 DP(NETIF_MSG_IFDOWN, "Disabling \"close the gates\"\n");
8446 if (CHIP_IS_E1(bp)) {
8447 int port = BP_PORT(bp);
8448 u32 addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
8449 MISC_REG_AEU_MASK_ATTN_FUNC_0;
8451 val = REG_RD(bp, addr);
8453 REG_WR(bp, addr, val);
8455 val = REG_RD(bp, MISC_REG_AEU_GENERAL_MASK);
8456 val &= ~(MISC_AEU_GENERAL_MASK_REG_AEU_PXP_CLOSE_MASK |
8457 MISC_AEU_GENERAL_MASK_REG_AEU_NIG_CLOSE_MASK);
8458 REG_WR(bp, MISC_REG_AEU_GENERAL_MASK, val);
8462 /* Close gates #2, #3 and #4: */
8463 static void bnx2x_set_234_gates(struct bnx2x *bp, bool close)
8467 /* Gates #2 and #4a are closed/opened for "not E1" only */
8468 if (!CHIP_IS_E1(bp)) {
8470 REG_WR(bp, PXP_REG_HST_DISCARD_DOORBELLS, !!close);
8472 REG_WR(bp, PXP_REG_HST_DISCARD_INTERNAL_WRITES, !!close);
8476 if (CHIP_IS_E1x(bp)) {
8477 /* Prevent interrupts from HC on both ports */
8478 val = REG_RD(bp, HC_REG_CONFIG_1);
8479 REG_WR(bp, HC_REG_CONFIG_1,
8480 (!close) ? (val | HC_CONFIG_1_REG_BLOCK_DISABLE_1) :
8481 (val & ~(u32)HC_CONFIG_1_REG_BLOCK_DISABLE_1));
8483 val = REG_RD(bp, HC_REG_CONFIG_0);
8484 REG_WR(bp, HC_REG_CONFIG_0,
8485 (!close) ? (val | HC_CONFIG_0_REG_BLOCK_DISABLE_0) :
8486 (val & ~(u32)HC_CONFIG_0_REG_BLOCK_DISABLE_0));
8488 /* Prevent incomming interrupts in IGU */
8489 val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
8491 REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION,
8493 (val | IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE) :
8494 (val & ~(u32)IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE));
8497 DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "%s gates #2, #3 and #4\n",
8498 close ? "closing" : "opening");
8502 #define SHARED_MF_CLP_MAGIC 0x80000000 /* `magic' bit */
8504 static void bnx2x_clp_reset_prep(struct bnx2x *bp, u32 *magic_val)
8506 /* Do some magic... */
8507 u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
8508 *magic_val = val & SHARED_MF_CLP_MAGIC;
8509 MF_CFG_WR(bp, shared_mf_config.clp_mb, val | SHARED_MF_CLP_MAGIC);
8513 * bnx2x_clp_reset_done - restore the value of the `magic' bit.
8515 * @bp: driver handle
8516 * @magic_val: old value of the `magic' bit.
8518 static void bnx2x_clp_reset_done(struct bnx2x *bp, u32 magic_val)
8520 /* Restore the `magic' bit value... */
8521 u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
8522 MF_CFG_WR(bp, shared_mf_config.clp_mb,
8523 (val & (~SHARED_MF_CLP_MAGIC)) | magic_val);
8527 * bnx2x_reset_mcp_prep - prepare for MCP reset.
8529 * @bp: driver handle
8530 * @magic_val: old value of 'magic' bit.
8532 * Takes care of CLP configurations.
8534 static void bnx2x_reset_mcp_prep(struct bnx2x *bp, u32 *magic_val)
8537 u32 validity_offset;
8539 DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "Starting\n");
8541 /* Set `magic' bit in order to save MF config */
8542 if (!CHIP_IS_E1(bp))
8543 bnx2x_clp_reset_prep(bp, magic_val);
8545 /* Get shmem offset */
8546 shmem = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
8547 validity_offset = offsetof(struct shmem_region, validity_map[0]);
8549 /* Clear validity map flags */
8551 REG_WR(bp, shmem + validity_offset, 0);
8554 #define MCP_TIMEOUT 5000 /* 5 seconds (in ms) */
8555 #define MCP_ONE_TIMEOUT 100 /* 100 ms */
8558 * bnx2x_mcp_wait_one - wait for MCP_ONE_TIMEOUT
8560 * @bp: driver handle
8562 static void bnx2x_mcp_wait_one(struct bnx2x *bp)
8564 /* special handling for emulation and FPGA,
8565 wait 10 times longer */
8566 if (CHIP_REV_IS_SLOW(bp))
8567 msleep(MCP_ONE_TIMEOUT*10);
8569 msleep(MCP_ONE_TIMEOUT);
8573 * initializes bp->common.shmem_base and waits for validity signature to appear
8575 static int bnx2x_init_shmem(struct bnx2x *bp)
8581 bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
8582 if (bp->common.shmem_base) {
8583 val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
8584 if (val & SHR_MEM_VALIDITY_MB)
8588 bnx2x_mcp_wait_one(bp);
8590 } while (cnt++ < (MCP_TIMEOUT / MCP_ONE_TIMEOUT));
8592 BNX2X_ERR("BAD MCP validity signature\n");
8597 static int bnx2x_reset_mcp_comp(struct bnx2x *bp, u32 magic_val)
8599 int rc = bnx2x_init_shmem(bp);
8601 /* Restore the `magic' bit value */
8602 if (!CHIP_IS_E1(bp))
8603 bnx2x_clp_reset_done(bp, magic_val);
8608 static void bnx2x_pxp_prep(struct bnx2x *bp)
8610 if (!CHIP_IS_E1(bp)) {
8611 REG_WR(bp, PXP2_REG_RD_START_INIT, 0);
8612 REG_WR(bp, PXP2_REG_RQ_RBC_DONE, 0);
8618 * Reset the whole chip except for:
8620 * - PCI Glue, PSWHST, PXP/PXP2 RF (all controlled by
8623 * - MISC (including AEU)
8627 static void bnx2x_process_kill_chip_reset(struct bnx2x *bp, bool global)
8629 u32 not_reset_mask1, reset_mask1, not_reset_mask2, reset_mask2;
8630 u32 global_bits2, stay_reset2;
8633 * Bits that have to be set in reset_mask2 if we want to reset 'global'
8634 * (per chip) blocks.
8637 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CPU |
8638 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CORE;
8640 /* Don't reset the following blocks */
8642 MISC_REGISTERS_RESET_REG_1_RST_HC |
8643 MISC_REGISTERS_RESET_REG_1_RST_PXPV |
8644 MISC_REGISTERS_RESET_REG_1_RST_PXP;
8647 MISC_REGISTERS_RESET_REG_2_RST_PCI_MDIO |
8648 MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE |
8649 MISC_REGISTERS_RESET_REG_2_RST_EMAC1_HARD_CORE |
8650 MISC_REGISTERS_RESET_REG_2_RST_MISC_CORE |
8651 MISC_REGISTERS_RESET_REG_2_RST_RBCN |
8652 MISC_REGISTERS_RESET_REG_2_RST_GRC |
8653 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_REG_HARD_CORE |
8654 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_HARD_CORE_RST_B |
8655 MISC_REGISTERS_RESET_REG_2_RST_ATC |
8656 MISC_REGISTERS_RESET_REG_2_PGLC;
8659 * Keep the following blocks in reset:
8660 * - all xxMACs are handled by the bnx2x_link code.
8663 MISC_REGISTERS_RESET_REG_2_RST_BMAC0 |
8664 MISC_REGISTERS_RESET_REG_2_RST_BMAC1 |
8665 MISC_REGISTERS_RESET_REG_2_RST_EMAC0 |
8666 MISC_REGISTERS_RESET_REG_2_RST_EMAC1 |
8667 MISC_REGISTERS_RESET_REG_2_UMAC0 |
8668 MISC_REGISTERS_RESET_REG_2_UMAC1 |
8669 MISC_REGISTERS_RESET_REG_2_XMAC |
8670 MISC_REGISTERS_RESET_REG_2_XMAC_SOFT;
8672 /* Full reset masks according to the chip */
8673 reset_mask1 = 0xffffffff;
8676 reset_mask2 = 0xffff;
8677 else if (CHIP_IS_E1H(bp))
8678 reset_mask2 = 0x1ffff;
8679 else if (CHIP_IS_E2(bp))
8680 reset_mask2 = 0xfffff;
8681 else /* CHIP_IS_E3 */
8682 reset_mask2 = 0x3ffffff;
8684 /* Don't reset global blocks unless we need to */
8686 reset_mask2 &= ~global_bits2;
8689 * In case of attention in the QM, we need to reset PXP
8690 * (MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR) before QM
8691 * because otherwise QM reset would release 'close the gates' shortly
8692 * before resetting the PXP, then the PSWRQ would send a write
8693 * request to PGLUE. Then when PXP is reset, PGLUE would try to
8694 * read the payload data from PSWWR, but PSWWR would not
8695 * respond. The write queue in PGLUE would stuck, dmae commands
8696 * would not return. Therefore it's important to reset the second
8697 * reset register (containing the
8698 * MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR bit) before the
8699 * first one (containing the MISC_REGISTERS_RESET_REG_1_RST_QM
8702 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
8703 reset_mask2 & (~not_reset_mask2));
8705 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
8706 reset_mask1 & (~not_reset_mask1));
8711 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
8712 reset_mask2 & (~stay_reset2));
8717 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, reset_mask1);
8722 * bnx2x_er_poll_igu_vq - poll for pending writes bit.
8723 * It should get cleared in no more than 1s.
8725 * @bp: driver handle
8727 * It should get cleared in no more than 1s. Returns 0 if
8728 * pending writes bit gets cleared.
8730 static int bnx2x_er_poll_igu_vq(struct bnx2x *bp)
8736 pend_bits = REG_RD(bp, IGU_REG_PENDING_BITS_STATUS);
8741 usleep_range(1000, 1000);
8742 } while (cnt-- > 0);
8745 BNX2X_ERR("Still pending IGU requests pend_bits=%x!\n",
8753 static int bnx2x_process_kill(struct bnx2x *bp, bool global)
8757 u32 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, pgl_exp_rom2;
8760 /* Empty the Tetris buffer, wait for 1s */
8762 sr_cnt = REG_RD(bp, PXP2_REG_RD_SR_CNT);
8763 blk_cnt = REG_RD(bp, PXP2_REG_RD_BLK_CNT);
8764 port_is_idle_0 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_0);
8765 port_is_idle_1 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_1);
8766 pgl_exp_rom2 = REG_RD(bp, PXP2_REG_PGL_EXP_ROM2);
8767 if ((sr_cnt == 0x7e) && (blk_cnt == 0xa0) &&
8768 ((port_is_idle_0 & 0x1) == 0x1) &&
8769 ((port_is_idle_1 & 0x1) == 0x1) &&
8770 (pgl_exp_rom2 == 0xffffffff))
8772 usleep_range(1000, 1000);
8773 } while (cnt-- > 0);
8776 BNX2X_ERR("Tetris buffer didn't get empty or there are still outstanding read requests after 1s!\n");
8777 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",
8778 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1,
8785 /* Close gates #2, #3 and #4 */
8786 bnx2x_set_234_gates(bp, true);
8788 /* Poll for IGU VQs for 57712 and newer chips */
8789 if (!CHIP_IS_E1x(bp) && bnx2x_er_poll_igu_vq(bp))
8793 /* TBD: Indicate that "process kill" is in progress to MCP */
8795 /* Clear "unprepared" bit */
8796 REG_WR(bp, MISC_REG_UNPREPARED, 0);
8799 /* Make sure all is written to the chip before the reset */
8802 /* Wait for 1ms to empty GLUE and PCI-E core queues,
8803 * PSWHST, GRC and PSWRD Tetris buffer.
8805 usleep_range(1000, 1000);
8807 /* Prepare to chip reset: */
8810 bnx2x_reset_mcp_prep(bp, &val);
8816 /* reset the chip */
8817 bnx2x_process_kill_chip_reset(bp, global);
8820 /* Recover after reset: */
8822 if (global && bnx2x_reset_mcp_comp(bp, val))
8825 /* TBD: Add resetting the NO_MCP mode DB here */
8830 /* Open the gates #2, #3 and #4 */
8831 bnx2x_set_234_gates(bp, false);
8833 /* TBD: IGU/AEU preparation bring back the AEU/IGU to a
8834 * reset state, re-enable attentions. */
8839 int bnx2x_leader_reset(struct bnx2x *bp)
8842 bool global = bnx2x_reset_is_global(bp);
8845 /* if not going to reset MCP - load "fake" driver to reset HW while
8846 * driver is owner of the HW
8848 if (!global && !BP_NOMCP(bp)) {
8849 load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_REQ, 0);
8851 BNX2X_ERR("MCP response failure, aborting\n");
8853 goto exit_leader_reset;
8855 if ((load_code != FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) &&
8856 (load_code != FW_MSG_CODE_DRV_LOAD_COMMON)) {
8857 BNX2X_ERR("MCP unexpected resp, aborting\n");
8859 goto exit_leader_reset2;
8861 load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_DONE, 0);
8863 BNX2X_ERR("MCP response failure, aborting\n");
8865 goto exit_leader_reset2;
8869 /* Try to recover after the failure */
8870 if (bnx2x_process_kill(bp, global)) {
8871 BNX2X_ERR("Something bad had happen on engine %d! Aii!\n",
8874 goto exit_leader_reset2;
8878 * Clear RESET_IN_PROGRES and RESET_GLOBAL bits and update the driver
8881 bnx2x_set_reset_done(bp);
8883 bnx2x_clear_reset_global(bp);
8886 /* unload "fake driver" if it was loaded */
8887 if (!global && !BP_NOMCP(bp)) {
8888 bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP, 0);
8889 bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
8893 bnx2x_release_leader_lock(bp);
8898 static void bnx2x_recovery_failed(struct bnx2x *bp)
8900 netdev_err(bp->dev, "Recovery has failed. Power cycle is needed.\n");
8902 /* Disconnect this device */
8903 netif_device_detach(bp->dev);
8906 * Block ifup for all function on this engine until "process kill"
8909 bnx2x_set_reset_in_progress(bp);
8911 /* Shut down the power */
8912 bnx2x_set_power_state(bp, PCI_D3hot);
8914 bp->recovery_state = BNX2X_RECOVERY_FAILED;
8920 * Assumption: runs under rtnl lock. This together with the fact
8921 * that it's called only from bnx2x_sp_rtnl() ensure that it
8922 * will never be called when netif_running(bp->dev) is false.
8924 static void bnx2x_parity_recover(struct bnx2x *bp)
8926 bool global = false;
8927 u32 error_recovered, error_unrecovered;
8930 DP(NETIF_MSG_HW, "Handling parity\n");
8932 switch (bp->recovery_state) {
8933 case BNX2X_RECOVERY_INIT:
8934 DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_INIT\n");
8935 is_parity = bnx2x_chk_parity_attn(bp, &global, false);
8936 WARN_ON(!is_parity);
8938 /* Try to get a LEADER_LOCK HW lock */
8939 if (bnx2x_trylock_leader_lock(bp)) {
8940 bnx2x_set_reset_in_progress(bp);
8942 * Check if there is a global attention and if
8943 * there was a global attention, set the global
8948 bnx2x_set_reset_global(bp);
8953 /* Stop the driver */
8954 /* If interface has been removed - break */
8955 if (bnx2x_nic_unload(bp, UNLOAD_RECOVERY))
8958 bp->recovery_state = BNX2X_RECOVERY_WAIT;
8960 /* Ensure "is_leader", MCP command sequence and
8961 * "recovery_state" update values are seen on other
8967 case BNX2X_RECOVERY_WAIT:
8968 DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_WAIT\n");
8969 if (bp->is_leader) {
8970 int other_engine = BP_PATH(bp) ? 0 : 1;
8971 bool other_load_status =
8972 bnx2x_get_load_status(bp, other_engine);
8974 bnx2x_get_load_status(bp, BP_PATH(bp));
8975 global = bnx2x_reset_is_global(bp);
8978 * In case of a parity in a global block, let
8979 * the first leader that performs a
8980 * leader_reset() reset the global blocks in
8981 * order to clear global attentions. Otherwise
8982 * the the gates will remain closed for that
8986 (global && other_load_status)) {
8987 /* Wait until all other functions get
8990 schedule_delayed_work(&bp->sp_rtnl_task,
8994 /* If all other functions got down -
8995 * try to bring the chip back to
8996 * normal. In any case it's an exit
8997 * point for a leader.
8999 if (bnx2x_leader_reset(bp)) {
9000 bnx2x_recovery_failed(bp);
9004 /* If we are here, means that the
9005 * leader has succeeded and doesn't
9006 * want to be a leader any more. Try
9007 * to continue as a none-leader.
9011 } else { /* non-leader */
9012 if (!bnx2x_reset_is_done(bp, BP_PATH(bp))) {
9013 /* Try to get a LEADER_LOCK HW lock as
9014 * long as a former leader may have
9015 * been unloaded by the user or
9016 * released a leadership by another
9019 if (bnx2x_trylock_leader_lock(bp)) {
9020 /* I'm a leader now! Restart a
9027 schedule_delayed_work(&bp->sp_rtnl_task,
9033 * If there was a global attention, wait
9034 * for it to be cleared.
9036 if (bnx2x_reset_is_global(bp)) {
9037 schedule_delayed_work(
9044 bp->eth_stats.recoverable_error;
9046 bp->eth_stats.unrecoverable_error;
9047 bp->recovery_state =
9048 BNX2X_RECOVERY_NIC_LOADING;
9049 if (bnx2x_nic_load(bp, LOAD_NORMAL)) {
9050 error_unrecovered++;
9052 "Recovery failed. Power cycle needed\n");
9053 /* Disconnect this device */
9054 netif_device_detach(bp->dev);
9055 /* Shut down the power */
9056 bnx2x_set_power_state(
9060 bp->recovery_state =
9061 BNX2X_RECOVERY_DONE;
9065 bp->eth_stats.recoverable_error =
9067 bp->eth_stats.unrecoverable_error =
9079 static int bnx2x_close(struct net_device *dev);
9081 /* bnx2x_nic_unload() flushes the bnx2x_wq, thus reset task is
9082 * scheduled on a general queue in order to prevent a dead lock.
9084 static void bnx2x_sp_rtnl_task(struct work_struct *work)
9086 struct bnx2x *bp = container_of(work, struct bnx2x, sp_rtnl_task.work);
9090 if (!netif_running(bp->dev))
9093 /* if stop on error is defined no recovery flows should be executed */
9094 #ifdef BNX2X_STOP_ON_ERROR
9095 BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n"
9096 "you will need to reboot when done\n");
9097 goto sp_rtnl_not_reset;
9100 if (unlikely(bp->recovery_state != BNX2X_RECOVERY_DONE)) {
9102 * Clear all pending SP commands as we are going to reset the
9105 bp->sp_rtnl_state = 0;
9108 bnx2x_parity_recover(bp);
9113 if (test_and_clear_bit(BNX2X_SP_RTNL_TX_TIMEOUT, &bp->sp_rtnl_state)) {
9115 * Clear all pending SP commands as we are going to reset the
9118 bp->sp_rtnl_state = 0;
9121 bnx2x_nic_unload(bp, UNLOAD_NORMAL);
9122 bnx2x_nic_load(bp, LOAD_NORMAL);
9126 #ifdef BNX2X_STOP_ON_ERROR
9129 if (test_and_clear_bit(BNX2X_SP_RTNL_SETUP_TC, &bp->sp_rtnl_state))
9130 bnx2x_setup_tc(bp->dev, bp->dcbx_port_params.ets.num_of_cos);
9131 if (test_and_clear_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE, &bp->sp_rtnl_state))
9132 bnx2x_after_function_update(bp);
9134 * in case of fan failure we need to reset id if the "stop on error"
9135 * debug flag is set, since we trying to prevent permanent overheating
9138 if (test_and_clear_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state)) {
9139 DP(NETIF_MSG_HW, "fan failure detected. Unloading driver\n");
9140 netif_device_detach(bp->dev);
9141 bnx2x_close(bp->dev);
9148 /* end of nic load/unload */
9150 static void bnx2x_period_task(struct work_struct *work)
9152 struct bnx2x *bp = container_of(work, struct bnx2x, period_task.work);
9154 if (!netif_running(bp->dev))
9155 goto period_task_exit;
9157 if (CHIP_REV_IS_SLOW(bp)) {
9158 BNX2X_ERR("period task called on emulation, ignoring\n");
9159 goto period_task_exit;
9162 bnx2x_acquire_phy_lock(bp);
9164 * The barrier is needed to ensure the ordering between the writing to
9165 * the bp->port.pmf in the bnx2x_nic_load() or bnx2x_pmf_update() and
9170 bnx2x_period_func(&bp->link_params, &bp->link_vars);
9172 /* Re-queue task in 1 sec */
9173 queue_delayed_work(bnx2x_wq, &bp->period_task, 1*HZ);
9176 bnx2x_release_phy_lock(bp);
9182 * Init service functions
9185 static u32 bnx2x_get_pretend_reg(struct bnx2x *bp)
9187 u32 base = PXP2_REG_PGL_PRETEND_FUNC_F0;
9188 u32 stride = PXP2_REG_PGL_PRETEND_FUNC_F1 - base;
9189 return base + (BP_ABS_FUNC(bp)) * stride;
9192 static void bnx2x_undi_int_disable_e1h(struct bnx2x *bp)
9194 u32 reg = bnx2x_get_pretend_reg(bp);
9196 /* Flush all outstanding writes */
9199 /* Pretend to be function 0 */
9201 REG_RD(bp, reg); /* Flush the GRC transaction (in the chip) */
9203 /* From now we are in the "like-E1" mode */
9204 bnx2x_int_disable(bp);
9206 /* Flush all outstanding writes */
9209 /* Restore the original function */
9210 REG_WR(bp, reg, BP_ABS_FUNC(bp));
9214 static inline void bnx2x_undi_int_disable(struct bnx2x *bp)
9217 bnx2x_int_disable(bp);
9219 bnx2x_undi_int_disable_e1h(bp);
9222 static void __devinit bnx2x_prev_unload_close_mac(struct bnx2x *bp)
9224 u32 val, base_addr, offset, mask, reset_reg;
9225 bool mac_stopped = false;
9226 u8 port = BP_PORT(bp);
9228 reset_reg = REG_RD(bp, MISC_REG_RESET_REG_2);
9230 if (!CHIP_IS_E3(bp)) {
9231 val = REG_RD(bp, NIG_REG_BMAC0_REGS_OUT_EN + port * 4);
9232 mask = MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port;
9233 if ((mask & reset_reg) && val) {
9235 BNX2X_DEV_INFO("Disable bmac Rx\n");
9236 base_addr = BP_PORT(bp) ? NIG_REG_INGRESS_BMAC1_MEM
9237 : NIG_REG_INGRESS_BMAC0_MEM;
9238 offset = CHIP_IS_E2(bp) ? BIGMAC2_REGISTER_BMAC_CONTROL
9239 : BIGMAC_REGISTER_BMAC_CONTROL;
9242 * use rd/wr since we cannot use dmae. This is safe
9243 * since MCP won't access the bus due to the request
9244 * to unload, and no function on the path can be
9245 * loaded at this time.
9247 wb_data[0] = REG_RD(bp, base_addr + offset);
9248 wb_data[1] = REG_RD(bp, base_addr + offset + 0x4);
9249 wb_data[0] &= ~BMAC_CONTROL_RX_ENABLE;
9250 REG_WR(bp, base_addr + offset, wb_data[0]);
9251 REG_WR(bp, base_addr + offset + 0x4, wb_data[1]);
9254 BNX2X_DEV_INFO("Disable emac Rx\n");
9255 REG_WR(bp, NIG_REG_NIG_EMAC0_EN + BP_PORT(bp)*4, 0);
9259 if (reset_reg & MISC_REGISTERS_RESET_REG_2_XMAC) {
9260 BNX2X_DEV_INFO("Disable xmac Rx\n");
9261 base_addr = BP_PORT(bp) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
9262 val = REG_RD(bp, base_addr + XMAC_REG_PFC_CTRL_HI);
9263 REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
9265 REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
9267 REG_WR(bp, base_addr + XMAC_REG_CTRL, 0);
9270 mask = MISC_REGISTERS_RESET_REG_2_UMAC0 << port;
9271 if (mask & reset_reg) {
9272 BNX2X_DEV_INFO("Disable umac Rx\n");
9273 base_addr = BP_PORT(bp) ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
9274 REG_WR(bp, base_addr + UMAC_REG_COMMAND_CONFIG, 0);
9284 #define BNX2X_PREV_UNDI_PROD_ADDR(p) (BAR_TSTRORM_INTMEM + 0x1508 + ((p) << 4))
9285 #define BNX2X_PREV_UNDI_RCQ(val) ((val) & 0xffff)
9286 #define BNX2X_PREV_UNDI_BD(val) ((val) >> 16 & 0xffff)
9287 #define BNX2X_PREV_UNDI_PROD(rcq, bd) ((bd) << 16 | (rcq))
9289 static void __devinit bnx2x_prev_unload_undi_inc(struct bnx2x *bp, u8 port,
9293 u32 tmp_reg = REG_RD(bp, BNX2X_PREV_UNDI_PROD_ADDR(port));
9295 rcq = BNX2X_PREV_UNDI_RCQ(tmp_reg) + inc;
9296 bd = BNX2X_PREV_UNDI_BD(tmp_reg) + inc;
9298 tmp_reg = BNX2X_PREV_UNDI_PROD(rcq, bd);
9299 REG_WR(bp, BNX2X_PREV_UNDI_PROD_ADDR(port), tmp_reg);
9301 BNX2X_DEV_INFO("UNDI producer [%d] rings bd -> 0x%04x, rcq -> 0x%04x\n",
9305 static int __devinit bnx2x_prev_mcp_done(struct bnx2x *bp)
9307 u32 rc = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
9309 BNX2X_ERR("MCP response failure, aborting\n");
9316 static bool __devinit bnx2x_prev_is_path_marked(struct bnx2x *bp)
9318 struct bnx2x_prev_path_list *tmp_list;
9321 if (down_trylock(&bnx2x_prev_sem))
9324 list_for_each_entry(tmp_list, &bnx2x_prev_list, list) {
9325 if (PCI_SLOT(bp->pdev->devfn) == tmp_list->slot &&
9326 bp->pdev->bus->number == tmp_list->bus &&
9327 BP_PATH(bp) == tmp_list->path) {
9329 BNX2X_DEV_INFO("Path %d was already cleaned from previous drivers\n",
9335 up(&bnx2x_prev_sem);
9340 static int __devinit bnx2x_prev_mark_path(struct bnx2x *bp)
9342 struct bnx2x_prev_path_list *tmp_list;
9345 tmp_list = kmalloc(sizeof(struct bnx2x_prev_path_list), GFP_KERNEL);
9347 BNX2X_ERR("Failed to allocate 'bnx2x_prev_path_list'\n");
9351 tmp_list->bus = bp->pdev->bus->number;
9352 tmp_list->slot = PCI_SLOT(bp->pdev->devfn);
9353 tmp_list->path = BP_PATH(bp);
9355 rc = down_interruptible(&bnx2x_prev_sem);
9357 BNX2X_ERR("Received %d when tried to take lock\n", rc);
9360 BNX2X_DEV_INFO("Marked path [%d] - finished previous unload\n",
9362 list_add(&tmp_list->list, &bnx2x_prev_list);
9363 up(&bnx2x_prev_sem);
9369 static int __devinit bnx2x_do_flr(struct bnx2x *bp)
9373 struct pci_dev *dev = bp->pdev;
9376 if (CHIP_IS_E1x(bp)) {
9377 BNX2X_DEV_INFO("FLR not supported in E1/E1H\n");
9381 /* only bootcode REQ_BC_VER_4_INITIATE_FLR and onwards support flr */
9382 if (bp->common.bc_ver < REQ_BC_VER_4_INITIATE_FLR) {
9383 BNX2X_ERR("FLR not supported by BC_VER: 0x%x\n",
9388 /* Wait for Transaction Pending bit clean */
9389 for (i = 0; i < 4; i++) {
9391 msleep((1 << (i - 1)) * 100);
9393 pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &status);
9394 if (!(status & PCI_EXP_DEVSTA_TRPND))
9399 "transaction is not cleared; proceeding with reset anyway\n");
9403 BNX2X_DEV_INFO("Initiating FLR\n");
9404 bnx2x_fw_command(bp, DRV_MSG_CODE_INITIATE_FLR, 0);
9409 static int __devinit bnx2x_prev_unload_uncommon(struct bnx2x *bp)
9413 BNX2X_DEV_INFO("Uncommon unload Flow\n");
9415 /* Test if previous unload process was already finished for this path */
9416 if (bnx2x_prev_is_path_marked(bp))
9417 return bnx2x_prev_mcp_done(bp);
9419 /* If function has FLR capabilities, and existing FW version matches
9420 * the one required, then FLR will be sufficient to clean any residue
9421 * left by previous driver
9423 rc = bnx2x_test_firmware_version(bp, false);
9426 /* fw version is good */
9427 BNX2X_DEV_INFO("FW version matches our own. Attempting FLR\n");
9428 rc = bnx2x_do_flr(bp);
9432 /* FLR was performed */
9433 BNX2X_DEV_INFO("FLR successful\n");
9437 BNX2X_DEV_INFO("Could not FLR\n");
9439 /* Close the MCP request, return failure*/
9440 rc = bnx2x_prev_mcp_done(bp);
9442 rc = BNX2X_PREV_WAIT_NEEDED;
9447 static int __devinit bnx2x_prev_unload_common(struct bnx2x *bp)
9449 u32 reset_reg, tmp_reg = 0, rc;
9450 /* It is possible a previous function received 'common' answer,
9451 * but hasn't loaded yet, therefore creating a scenario of
9452 * multiple functions receiving 'common' on the same path.
9454 BNX2X_DEV_INFO("Common unload Flow\n");
9456 if (bnx2x_prev_is_path_marked(bp))
9457 return bnx2x_prev_mcp_done(bp);
9459 reset_reg = REG_RD(bp, MISC_REG_RESET_REG_1);
9461 /* Reset should be performed after BRB is emptied */
9462 if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_BRB1) {
9463 u32 timer_count = 1000;
9464 bool prev_undi = false;
9466 /* Close the MAC Rx to prevent BRB from filling up */
9467 bnx2x_prev_unload_close_mac(bp);
9469 /* Check if the UNDI driver was previously loaded
9470 * UNDI driver initializes CID offset for normal bell to 0x7
9472 reset_reg = REG_RD(bp, MISC_REG_RESET_REG_1);
9473 if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_DORQ) {
9474 tmp_reg = REG_RD(bp, DORQ_REG_NORM_CID_OFST);
9475 if (tmp_reg == 0x7) {
9476 BNX2X_DEV_INFO("UNDI previously loaded\n");
9478 /* clear the UNDI indication */
9479 REG_WR(bp, DORQ_REG_NORM_CID_OFST, 0);
9482 /* wait until BRB is empty */
9483 tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
9484 while (timer_count) {
9485 u32 prev_brb = tmp_reg;
9487 tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
9491 BNX2X_DEV_INFO("BRB still has 0x%08x\n", tmp_reg);
9493 /* reset timer as long as BRB actually gets emptied */
9494 if (prev_brb > tmp_reg)
9499 /* If UNDI resides in memory, manually increment it */
9501 bnx2x_prev_unload_undi_inc(bp, BP_PORT(bp), 1);
9507 BNX2X_ERR("Failed to empty BRB, hope for the best\n");
9511 /* No packets are in the pipeline, path is ready for reset */
9512 bnx2x_reset_common(bp);
9514 rc = bnx2x_prev_mark_path(bp);
9516 bnx2x_prev_mcp_done(bp);
9520 return bnx2x_prev_mcp_done(bp);
9523 /* previous driver DMAE transaction may have occurred when pre-boot stage ended
9524 * and boot began, or when kdump kernel was loaded. Either case would invalidate
9525 * the addresses of the transaction, resulting in was-error bit set in the pci
9526 * causing all hw-to-host pcie transactions to timeout. If this happened we want
9527 * to clear the interrupt which detected this from the pglueb and the was done
9530 static void __devinit bnx2x_prev_interrupted_dmae(struct bnx2x *bp)
9532 u32 val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS);
9533 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN) {
9534 BNX2X_ERR("was error bit was found to be set in pglueb upon startup. Clearing");
9535 REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR, 1 << BP_FUNC(bp));
9539 static int __devinit bnx2x_prev_unload(struct bnx2x *bp)
9541 int time_counter = 10;
9542 u32 rc, fw, hw_lock_reg, hw_lock_val;
9543 BNX2X_DEV_INFO("Entering Previous Unload Flow\n");
9545 /* clear hw from errors which may have resulted from an interrupted
9548 bnx2x_prev_interrupted_dmae(bp);
9550 /* Release previously held locks */
9551 hw_lock_reg = (BP_FUNC(bp) <= 5) ?
9552 (MISC_REG_DRIVER_CONTROL_1 + BP_FUNC(bp) * 8) :
9553 (MISC_REG_DRIVER_CONTROL_7 + (BP_FUNC(bp) - 6) * 8);
9555 hw_lock_val = (REG_RD(bp, hw_lock_reg));
9557 if (hw_lock_val & HW_LOCK_RESOURCE_NVRAM) {
9558 BNX2X_DEV_INFO("Release Previously held NVRAM lock\n");
9559 REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
9560 (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << BP_PORT(bp)));
9563 BNX2X_DEV_INFO("Release Previously held hw lock\n");
9564 REG_WR(bp, hw_lock_reg, 0xffffffff);
9566 BNX2X_DEV_INFO("No need to release hw/nvram locks\n");
9568 if (MCPR_ACCESS_LOCK_LOCK & REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK)) {
9569 BNX2X_DEV_INFO("Release previously held alr\n");
9570 REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, 0);
9575 /* Lock MCP using an unload request */
9576 fw = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS, 0);
9578 BNX2X_ERR("MCP response failure, aborting\n");
9583 if (fw == FW_MSG_CODE_DRV_UNLOAD_COMMON) {
9584 rc = bnx2x_prev_unload_common(bp);
9588 /* non-common reply from MCP night require looping */
9589 rc = bnx2x_prev_unload_uncommon(bp);
9590 if (rc != BNX2X_PREV_WAIT_NEEDED)
9594 } while (--time_counter);
9596 if (!time_counter || rc) {
9597 BNX2X_ERR("Failed unloading previous driver, aborting\n");
9601 BNX2X_DEV_INFO("Finished Previous Unload Flow [%d]\n", rc);
9606 static void __devinit bnx2x_get_common_hwinfo(struct bnx2x *bp)
9608 u32 val, val2, val3, val4, id, boot_mode;
9611 /* Get the chip revision id and number. */
9612 /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
9613 val = REG_RD(bp, MISC_REG_CHIP_NUM);
9614 id = ((val & 0xffff) << 16);
9615 val = REG_RD(bp, MISC_REG_CHIP_REV);
9616 id |= ((val & 0xf) << 12);
9617 val = REG_RD(bp, MISC_REG_CHIP_METAL);
9618 id |= ((val & 0xff) << 4);
9619 val = REG_RD(bp, MISC_REG_BOND_ID);
9621 bp->common.chip_id = id;
9623 /* force 57811 according to MISC register */
9624 if (REG_RD(bp, MISC_REG_CHIP_TYPE) & MISC_REG_CHIP_TYPE_57811_MASK) {
9625 if (CHIP_IS_57810(bp))
9626 bp->common.chip_id = (CHIP_NUM_57811 << 16) |
9627 (bp->common.chip_id & 0x0000FFFF);
9628 else if (CHIP_IS_57810_MF(bp))
9629 bp->common.chip_id = (CHIP_NUM_57811_MF << 16) |
9630 (bp->common.chip_id & 0x0000FFFF);
9631 bp->common.chip_id |= 0x1;
9634 /* Set doorbell size */
9635 bp->db_size = (1 << BNX2X_DB_SHIFT);
9637 if (!CHIP_IS_E1x(bp)) {
9638 val = REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR);
9640 val = REG_RD(bp, MISC_REG_PORT4MODE_EN);
9642 val = (val >> 1) & 1;
9643 BNX2X_DEV_INFO("chip is in %s\n", val ? "4_PORT_MODE" :
9645 bp->common.chip_port_mode = val ? CHIP_4_PORT_MODE :
9648 if (CHIP_MODE_IS_4_PORT(bp))
9649 bp->pfid = (bp->pf_num >> 1); /* 0..3 */
9651 bp->pfid = (bp->pf_num & 0x6); /* 0, 2, 4, 6 */
9653 bp->common.chip_port_mode = CHIP_PORT_MODE_NONE; /* N/A */
9654 bp->pfid = bp->pf_num; /* 0..7 */
9657 BNX2X_DEV_INFO("pf_id: %x", bp->pfid);
9659 bp->link_params.chip_id = bp->common.chip_id;
9660 BNX2X_DEV_INFO("chip ID is 0x%x\n", id);
9662 val = (REG_RD(bp, 0x2874) & 0x55);
9663 if ((bp->common.chip_id & 0x1) ||
9664 (CHIP_IS_E1(bp) && val) || (CHIP_IS_E1H(bp) && (val == 0x55))) {
9665 bp->flags |= ONE_PORT_FLAG;
9666 BNX2X_DEV_INFO("single port device\n");
9669 val = REG_RD(bp, MCP_REG_MCPR_NVM_CFG4);
9670 bp->common.flash_size = (BNX2X_NVRAM_1MB_SIZE <<
9671 (val & MCPR_NVM_CFG4_FLASH_SIZE));
9672 BNX2X_DEV_INFO("flash_size 0x%x (%d)\n",
9673 bp->common.flash_size, bp->common.flash_size);
9675 bnx2x_init_shmem(bp);
9679 bp->common.shmem2_base = REG_RD(bp, (BP_PATH(bp) ?
9680 MISC_REG_GENERIC_CR_1 :
9681 MISC_REG_GENERIC_CR_0));
9683 bp->link_params.shmem_base = bp->common.shmem_base;
9684 bp->link_params.shmem2_base = bp->common.shmem2_base;
9685 BNX2X_DEV_INFO("shmem offset 0x%x shmem2 offset 0x%x\n",
9686 bp->common.shmem_base, bp->common.shmem2_base);
9688 if (!bp->common.shmem_base) {
9689 BNX2X_DEV_INFO("MCP not active\n");
9690 bp->flags |= NO_MCP_FLAG;
9694 bp->common.hw_config = SHMEM_RD(bp, dev_info.shared_hw_config.config);
9695 BNX2X_DEV_INFO("hw_config 0x%08x\n", bp->common.hw_config);
9697 bp->link_params.hw_led_mode = ((bp->common.hw_config &
9698 SHARED_HW_CFG_LED_MODE_MASK) >>
9699 SHARED_HW_CFG_LED_MODE_SHIFT);
9701 bp->link_params.feature_config_flags = 0;
9702 val = SHMEM_RD(bp, dev_info.shared_feature_config.config);
9703 if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED)
9704 bp->link_params.feature_config_flags |=
9705 FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
9707 bp->link_params.feature_config_flags &=
9708 ~FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
9710 val = SHMEM_RD(bp, dev_info.bc_rev) >> 8;
9711 bp->common.bc_ver = val;
9712 BNX2X_DEV_INFO("bc_ver %X\n", val);
9713 if (val < BNX2X_BC_VER) {
9714 /* for now only warn
9715 * later we might need to enforce this */
9716 BNX2X_ERR("This driver needs bc_ver %X but found %X, please upgrade BC\n",
9719 bp->link_params.feature_config_flags |=
9720 (val >= REQ_BC_VER_4_VRFY_FIRST_PHY_OPT_MDL) ?
9721 FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY : 0;
9723 bp->link_params.feature_config_flags |=
9724 (val >= REQ_BC_VER_4_VRFY_SPECIFIC_PHY_OPT_MDL) ?
9725 FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY : 0;
9726 bp->link_params.feature_config_flags |=
9727 (val >= REQ_BC_VER_4_VRFY_AFEX_SUPPORTED) ?
9728 FEATURE_CONFIG_BC_SUPPORTS_AFEX : 0;
9729 bp->link_params.feature_config_flags |=
9730 (val >= REQ_BC_VER_4_SFP_TX_DISABLE_SUPPORTED) ?
9731 FEATURE_CONFIG_BC_SUPPORTS_SFP_TX_DISABLED : 0;
9732 bp->flags |= (val >= REQ_BC_VER_4_PFC_STATS_SUPPORTED) ?
9733 BC_SUPPORTS_PFC_STATS : 0;
9735 bp->flags |= (val >= REQ_BC_VER_4_FCOE_FEATURES) ?
9736 BC_SUPPORTS_FCOE_FEATURES : 0;
9738 bp->flags |= (val >= REQ_BC_VER_4_DCBX_ADMIN_MSG_NON_PMF) ?
9739 BC_SUPPORTS_DCBX_MSG_NON_PMF : 0;
9740 boot_mode = SHMEM_RD(bp,
9741 dev_info.port_feature_config[BP_PORT(bp)].mba_config) &
9742 PORT_FEATURE_MBA_BOOT_AGENT_TYPE_MASK;
9743 switch (boot_mode) {
9744 case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_PXE:
9745 bp->common.boot_mode = FEATURE_ETH_BOOTMODE_PXE;
9747 case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_ISCSIB:
9748 bp->common.boot_mode = FEATURE_ETH_BOOTMODE_ISCSI;
9750 case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_FCOE_BOOT:
9751 bp->common.boot_mode = FEATURE_ETH_BOOTMODE_FCOE;
9753 case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_NONE:
9754 bp->common.boot_mode = FEATURE_ETH_BOOTMODE_NONE;
9758 pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_PMC, &pmc);
9759 bp->flags |= (pmc & PCI_PM_CAP_PME_D3cold) ? 0 : NO_WOL_FLAG;
9761 BNX2X_DEV_INFO("%sWoL capable\n",
9762 (bp->flags & NO_WOL_FLAG) ? "not " : "");
9764 val = SHMEM_RD(bp, dev_info.shared_hw_config.part_num);
9765 val2 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[4]);
9766 val3 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[8]);
9767 val4 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[12]);
9769 dev_info(&bp->pdev->dev, "part number %X-%X-%X-%X\n",
9770 val, val2, val3, val4);
9773 #define IGU_FID(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID)
9774 #define IGU_VEC(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR)
9776 static void __devinit bnx2x_get_igu_cam_info(struct bnx2x *bp)
9778 int pfid = BP_FUNC(bp);
9781 u8 fid, igu_sb_cnt = 0;
9783 bp->igu_base_sb = 0xff;
9784 if (CHIP_INT_MODE_IS_BC(bp)) {
9786 igu_sb_cnt = bp->igu_sb_cnt;
9787 bp->igu_base_sb = (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn) *
9790 bp->igu_dsb_id = E1HVN_MAX * FP_SB_MAX_E1x +
9791 (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn);
9796 /* IGU in normal mode - read CAM */
9797 for (igu_sb_id = 0; igu_sb_id < IGU_REG_MAPPING_MEMORY_SIZE;
9799 val = REG_RD(bp, IGU_REG_MAPPING_MEMORY + igu_sb_id * 4);
9800 if (!(val & IGU_REG_MAPPING_MEMORY_VALID))
9803 if ((fid & IGU_FID_ENCODE_IS_PF)) {
9804 if ((fid & IGU_FID_PF_NUM_MASK) != pfid)
9806 if (IGU_VEC(val) == 0)
9807 /* default status block */
9808 bp->igu_dsb_id = igu_sb_id;
9810 if (bp->igu_base_sb == 0xff)
9811 bp->igu_base_sb = igu_sb_id;
9817 #ifdef CONFIG_PCI_MSI
9819 * It's expected that number of CAM entries for this functions is equal
9820 * to the number evaluated based on the MSI-X table size. We want a
9821 * harsh warning if these values are different!
9823 WARN_ON(bp->igu_sb_cnt != igu_sb_cnt);
9826 if (igu_sb_cnt == 0)
9827 BNX2X_ERR("CAM configuration error\n");
9830 static void __devinit bnx2x_link_settings_supported(struct bnx2x *bp,
9833 int cfg_size = 0, idx, port = BP_PORT(bp);
9835 /* Aggregation of supported attributes of all external phys */
9836 bp->port.supported[0] = 0;
9837 bp->port.supported[1] = 0;
9838 switch (bp->link_params.num_phys) {
9840 bp->port.supported[0] = bp->link_params.phy[INT_PHY].supported;
9844 bp->port.supported[0] = bp->link_params.phy[EXT_PHY1].supported;
9848 if (bp->link_params.multi_phy_config &
9849 PORT_HW_CFG_PHY_SWAPPED_ENABLED) {
9850 bp->port.supported[1] =
9851 bp->link_params.phy[EXT_PHY1].supported;
9852 bp->port.supported[0] =
9853 bp->link_params.phy[EXT_PHY2].supported;
9855 bp->port.supported[0] =
9856 bp->link_params.phy[EXT_PHY1].supported;
9857 bp->port.supported[1] =
9858 bp->link_params.phy[EXT_PHY2].supported;
9864 if (!(bp->port.supported[0] || bp->port.supported[1])) {
9865 BNX2X_ERR("NVRAM config error. BAD phy config. PHY1 config 0x%x, PHY2 config 0x%x\n",
9867 dev_info.port_hw_config[port].external_phy_config),
9869 dev_info.port_hw_config[port].external_phy_config2));
9874 bp->port.phy_addr = REG_RD(bp, MISC_REG_WC0_CTRL_PHY_ADDR);
9876 switch (switch_cfg) {
9878 bp->port.phy_addr = REG_RD(
9879 bp, NIG_REG_SERDES0_CTRL_PHY_ADDR + port*0x10);
9881 case SWITCH_CFG_10G:
9882 bp->port.phy_addr = REG_RD(
9883 bp, NIG_REG_XGXS0_CTRL_PHY_ADDR + port*0x18);
9886 BNX2X_ERR("BAD switch_cfg link_config 0x%x\n",
9887 bp->port.link_config[0]);
9891 BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr);
9892 /* mask what we support according to speed_cap_mask per configuration */
9893 for (idx = 0; idx < cfg_size; idx++) {
9894 if (!(bp->link_params.speed_cap_mask[idx] &
9895 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF))
9896 bp->port.supported[idx] &= ~SUPPORTED_10baseT_Half;
9898 if (!(bp->link_params.speed_cap_mask[idx] &
9899 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL))
9900 bp->port.supported[idx] &= ~SUPPORTED_10baseT_Full;
9902 if (!(bp->link_params.speed_cap_mask[idx] &
9903 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF))
9904 bp->port.supported[idx] &= ~SUPPORTED_100baseT_Half;
9906 if (!(bp->link_params.speed_cap_mask[idx] &
9907 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL))
9908 bp->port.supported[idx] &= ~SUPPORTED_100baseT_Full;
9910 if (!(bp->link_params.speed_cap_mask[idx] &
9911 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G))
9912 bp->port.supported[idx] &= ~(SUPPORTED_1000baseT_Half |
9913 SUPPORTED_1000baseT_Full);
9915 if (!(bp->link_params.speed_cap_mask[idx] &
9916 PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
9917 bp->port.supported[idx] &= ~SUPPORTED_2500baseX_Full;
9919 if (!(bp->link_params.speed_cap_mask[idx] &
9920 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G))
9921 bp->port.supported[idx] &= ~SUPPORTED_10000baseT_Full;
9925 BNX2X_DEV_INFO("supported 0x%x 0x%x\n", bp->port.supported[0],
9926 bp->port.supported[1]);
9929 static void __devinit bnx2x_link_settings_requested(struct bnx2x *bp)
9931 u32 link_config, idx, cfg_size = 0;
9932 bp->port.advertising[0] = 0;
9933 bp->port.advertising[1] = 0;
9934 switch (bp->link_params.num_phys) {
9943 for (idx = 0; idx < cfg_size; idx++) {
9944 bp->link_params.req_duplex[idx] = DUPLEX_FULL;
9945 link_config = bp->port.link_config[idx];
9946 switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) {
9947 case PORT_FEATURE_LINK_SPEED_AUTO:
9948 if (bp->port.supported[idx] & SUPPORTED_Autoneg) {
9949 bp->link_params.req_line_speed[idx] =
9951 bp->port.advertising[idx] |=
9952 bp->port.supported[idx];
9953 if (bp->link_params.phy[EXT_PHY1].type ==
9954 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
9955 bp->port.advertising[idx] |=
9956 (SUPPORTED_100baseT_Half |
9957 SUPPORTED_100baseT_Full);
9959 /* force 10G, no AN */
9960 bp->link_params.req_line_speed[idx] =
9962 bp->port.advertising[idx] |=
9963 (ADVERTISED_10000baseT_Full |
9969 case PORT_FEATURE_LINK_SPEED_10M_FULL:
9970 if (bp->port.supported[idx] & SUPPORTED_10baseT_Full) {
9971 bp->link_params.req_line_speed[idx] =
9973 bp->port.advertising[idx] |=
9974 (ADVERTISED_10baseT_Full |
9977 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
9979 bp->link_params.speed_cap_mask[idx]);
9984 case PORT_FEATURE_LINK_SPEED_10M_HALF:
9985 if (bp->port.supported[idx] & SUPPORTED_10baseT_Half) {
9986 bp->link_params.req_line_speed[idx] =
9988 bp->link_params.req_duplex[idx] =
9990 bp->port.advertising[idx] |=
9991 (ADVERTISED_10baseT_Half |
9994 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
9996 bp->link_params.speed_cap_mask[idx]);
10001 case PORT_FEATURE_LINK_SPEED_100M_FULL:
10002 if (bp->port.supported[idx] &
10003 SUPPORTED_100baseT_Full) {
10004 bp->link_params.req_line_speed[idx] =
10006 bp->port.advertising[idx] |=
10007 (ADVERTISED_100baseT_Full |
10010 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
10012 bp->link_params.speed_cap_mask[idx]);
10017 case PORT_FEATURE_LINK_SPEED_100M_HALF:
10018 if (bp->port.supported[idx] &
10019 SUPPORTED_100baseT_Half) {
10020 bp->link_params.req_line_speed[idx] =
10022 bp->link_params.req_duplex[idx] =
10024 bp->port.advertising[idx] |=
10025 (ADVERTISED_100baseT_Half |
10028 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
10030 bp->link_params.speed_cap_mask[idx]);
10035 case PORT_FEATURE_LINK_SPEED_1G:
10036 if (bp->port.supported[idx] &
10037 SUPPORTED_1000baseT_Full) {
10038 bp->link_params.req_line_speed[idx] =
10040 bp->port.advertising[idx] |=
10041 (ADVERTISED_1000baseT_Full |
10044 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
10046 bp->link_params.speed_cap_mask[idx]);
10051 case PORT_FEATURE_LINK_SPEED_2_5G:
10052 if (bp->port.supported[idx] &
10053 SUPPORTED_2500baseX_Full) {
10054 bp->link_params.req_line_speed[idx] =
10056 bp->port.advertising[idx] |=
10057 (ADVERTISED_2500baseX_Full |
10060 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
10062 bp->link_params.speed_cap_mask[idx]);
10067 case PORT_FEATURE_LINK_SPEED_10G_CX4:
10068 if (bp->port.supported[idx] &
10069 SUPPORTED_10000baseT_Full) {
10070 bp->link_params.req_line_speed[idx] =
10072 bp->port.advertising[idx] |=
10073 (ADVERTISED_10000baseT_Full |
10076 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
10078 bp->link_params.speed_cap_mask[idx]);
10082 case PORT_FEATURE_LINK_SPEED_20G:
10083 bp->link_params.req_line_speed[idx] = SPEED_20000;
10087 BNX2X_ERR("NVRAM config error. BAD link speed link_config 0x%x\n",
10089 bp->link_params.req_line_speed[idx] =
10091 bp->port.advertising[idx] =
10092 bp->port.supported[idx];
10096 bp->link_params.req_flow_ctrl[idx] = (link_config &
10097 PORT_FEATURE_FLOW_CONTROL_MASK);
10098 if ((bp->link_params.req_flow_ctrl[idx] ==
10099 BNX2X_FLOW_CTRL_AUTO) &&
10100 !(bp->port.supported[idx] & SUPPORTED_Autoneg)) {
10101 bp->link_params.req_flow_ctrl[idx] =
10102 BNX2X_FLOW_CTRL_NONE;
10105 BNX2X_DEV_INFO("req_line_speed %d req_duplex %d req_flow_ctrl 0x%x advertising 0x%x\n",
10106 bp->link_params.req_line_speed[idx],
10107 bp->link_params.req_duplex[idx],
10108 bp->link_params.req_flow_ctrl[idx],
10109 bp->port.advertising[idx]);
10113 static void __devinit bnx2x_set_mac_buf(u8 *mac_buf, u32 mac_lo, u16 mac_hi)
10115 mac_hi = cpu_to_be16(mac_hi);
10116 mac_lo = cpu_to_be32(mac_lo);
10117 memcpy(mac_buf, &mac_hi, sizeof(mac_hi));
10118 memcpy(mac_buf + sizeof(mac_hi), &mac_lo, sizeof(mac_lo));
10121 static void __devinit bnx2x_get_port_hwinfo(struct bnx2x *bp)
10123 int port = BP_PORT(bp);
10125 u32 ext_phy_type, ext_phy_config, eee_mode;
10127 bp->link_params.bp = bp;
10128 bp->link_params.port = port;
10130 bp->link_params.lane_config =
10131 SHMEM_RD(bp, dev_info.port_hw_config[port].lane_config);
10133 bp->link_params.speed_cap_mask[0] =
10135 dev_info.port_hw_config[port].speed_capability_mask);
10136 bp->link_params.speed_cap_mask[1] =
10138 dev_info.port_hw_config[port].speed_capability_mask2);
10139 bp->port.link_config[0] =
10140 SHMEM_RD(bp, dev_info.port_feature_config[port].link_config);
10142 bp->port.link_config[1] =
10143 SHMEM_RD(bp, dev_info.port_feature_config[port].link_config2);
10145 bp->link_params.multi_phy_config =
10146 SHMEM_RD(bp, dev_info.port_hw_config[port].multi_phy_config);
10147 /* If the device is capable of WoL, set the default state according
10150 config = SHMEM_RD(bp, dev_info.port_feature_config[port].config);
10151 bp->wol = (!(bp->flags & NO_WOL_FLAG) &&
10152 (config & PORT_FEATURE_WOL_ENABLED));
10154 BNX2X_DEV_INFO("lane_config 0x%08x speed_cap_mask0 0x%08x link_config0 0x%08x\n",
10155 bp->link_params.lane_config,
10156 bp->link_params.speed_cap_mask[0],
10157 bp->port.link_config[0]);
10159 bp->link_params.switch_cfg = (bp->port.link_config[0] &
10160 PORT_FEATURE_CONNECTED_SWITCH_MASK);
10161 bnx2x_phy_probe(&bp->link_params);
10162 bnx2x_link_settings_supported(bp, bp->link_params.switch_cfg);
10164 bnx2x_link_settings_requested(bp);
10167 * If connected directly, work with the internal PHY, otherwise, work
10168 * with the external PHY
10172 dev_info.port_hw_config[port].external_phy_config);
10173 ext_phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
10174 if (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
10175 bp->mdio.prtad = bp->port.phy_addr;
10177 else if ((ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) &&
10178 (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN))
10180 XGXS_EXT_PHY_ADDR(ext_phy_config);
10183 * Check if hw lock is required to access MDC/MDIO bus to the PHY(s)
10184 * In MF mode, it is set to cover self test cases
10187 bp->port.need_hw_lock = 1;
10189 bp->port.need_hw_lock = bnx2x_hw_lock_required(bp,
10190 bp->common.shmem_base,
10191 bp->common.shmem2_base);
10193 /* Configure link feature according to nvram value */
10194 eee_mode = (((SHMEM_RD(bp, dev_info.
10195 port_feature_config[port].eee_power_mode)) &
10196 PORT_FEAT_CFG_EEE_POWER_MODE_MASK) >>
10197 PORT_FEAT_CFG_EEE_POWER_MODE_SHIFT);
10198 if (eee_mode != PORT_FEAT_CFG_EEE_POWER_MODE_DISABLED) {
10199 bp->link_params.eee_mode = EEE_MODE_ADV_LPI |
10200 EEE_MODE_ENABLE_LPI |
10201 EEE_MODE_OUTPUT_TIME;
10203 bp->link_params.eee_mode = 0;
10207 void bnx2x_get_iscsi_info(struct bnx2x *bp)
10209 u32 no_flags = NO_ISCSI_FLAG;
10211 int port = BP_PORT(bp);
10213 u32 max_iscsi_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
10214 drv_lic_key[port].max_iscsi_conn);
10216 /* Get the number of maximum allowed iSCSI connections */
10217 bp->cnic_eth_dev.max_iscsi_conn =
10218 (max_iscsi_conn & BNX2X_MAX_ISCSI_INIT_CONN_MASK) >>
10219 BNX2X_MAX_ISCSI_INIT_CONN_SHIFT;
10221 BNX2X_DEV_INFO("max_iscsi_conn 0x%x\n",
10222 bp->cnic_eth_dev.max_iscsi_conn);
10225 * If maximum allowed number of connections is zero -
10226 * disable the feature.
10228 if (!bp->cnic_eth_dev.max_iscsi_conn)
10229 bp->flags |= no_flags;
10231 bp->flags |= no_flags;
10236 static void __devinit bnx2x_get_ext_wwn_info(struct bnx2x *bp, int func)
10239 bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
10240 MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_upper);
10241 bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
10242 MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_lower);
10245 bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
10246 MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_upper);
10247 bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
10248 MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_lower);
10251 static void __devinit bnx2x_get_fcoe_info(struct bnx2x *bp)
10254 int port = BP_PORT(bp);
10255 int func = BP_ABS_FUNC(bp);
10257 u32 max_fcoe_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
10258 drv_lic_key[port].max_fcoe_conn);
10260 /* Get the number of maximum allowed FCoE connections */
10261 bp->cnic_eth_dev.max_fcoe_conn =
10262 (max_fcoe_conn & BNX2X_MAX_FCOE_INIT_CONN_MASK) >>
10263 BNX2X_MAX_FCOE_INIT_CONN_SHIFT;
10265 /* Read the WWN: */
10268 bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
10270 dev_info.port_hw_config[port].
10271 fcoe_wwn_port_name_upper);
10272 bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
10274 dev_info.port_hw_config[port].
10275 fcoe_wwn_port_name_lower);
10278 bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
10280 dev_info.port_hw_config[port].
10281 fcoe_wwn_node_name_upper);
10282 bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
10284 dev_info.port_hw_config[port].
10285 fcoe_wwn_node_name_lower);
10286 } else if (!IS_MF_SD(bp)) {
10287 u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg);
10290 * Read the WWN info only if the FCoE feature is enabled for
10293 if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD)
10294 bnx2x_get_ext_wwn_info(bp, func);
10296 } else if (IS_MF_FCOE_SD(bp))
10297 bnx2x_get_ext_wwn_info(bp, func);
10299 BNX2X_DEV_INFO("max_fcoe_conn 0x%x\n", bp->cnic_eth_dev.max_fcoe_conn);
10302 * If maximum allowed number of connections is zero -
10303 * disable the feature.
10305 if (!bp->cnic_eth_dev.max_fcoe_conn)
10306 bp->flags |= NO_FCOE_FLAG;
10308 bp->flags |= NO_FCOE_FLAG;
10312 static void __devinit bnx2x_get_cnic_info(struct bnx2x *bp)
10315 * iSCSI may be dynamically disabled but reading
10316 * info here we will decrease memory usage by driver
10317 * if the feature is disabled for good
10319 bnx2x_get_iscsi_info(bp);
10320 bnx2x_get_fcoe_info(bp);
10323 static void __devinit bnx2x_get_mac_hwinfo(struct bnx2x *bp)
10326 int func = BP_ABS_FUNC(bp);
10327 int port = BP_PORT(bp);
10329 u8 *iscsi_mac = bp->cnic_eth_dev.iscsi_mac;
10330 u8 *fip_mac = bp->fip_mac;
10333 /* Zero primary MAC configuration */
10334 memset(bp->dev->dev_addr, 0, ETH_ALEN);
10336 if (BP_NOMCP(bp)) {
10337 BNX2X_ERROR("warning: random MAC workaround active\n");
10338 eth_hw_addr_random(bp->dev);
10339 } else if (IS_MF(bp)) {
10340 val2 = MF_CFG_RD(bp, func_mf_config[func].mac_upper);
10341 val = MF_CFG_RD(bp, func_mf_config[func].mac_lower);
10342 if ((val2 != FUNC_MF_CFG_UPPERMAC_DEFAULT) &&
10343 (val != FUNC_MF_CFG_LOWERMAC_DEFAULT))
10344 bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
10348 * iSCSI and FCoE NPAR MACs: if there is no either iSCSI or
10349 * FCoE MAC then the appropriate feature should be disabled.
10351 * In non SD mode features configuration comes from
10352 * struct func_ext_config.
10354 if (!IS_MF_SD(bp)) {
10355 u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg);
10356 if (cfg & MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD) {
10357 val2 = MF_CFG_RD(bp, func_ext_config[func].
10358 iscsi_mac_addr_upper);
10359 val = MF_CFG_RD(bp, func_ext_config[func].
10360 iscsi_mac_addr_lower);
10361 bnx2x_set_mac_buf(iscsi_mac, val, val2);
10362 BNX2X_DEV_INFO("Read iSCSI MAC: %pM\n",
10365 bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
10367 if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD) {
10368 val2 = MF_CFG_RD(bp, func_ext_config[func].
10369 fcoe_mac_addr_upper);
10370 val = MF_CFG_RD(bp, func_ext_config[func].
10371 fcoe_mac_addr_lower);
10372 bnx2x_set_mac_buf(fip_mac, val, val2);
10373 BNX2X_DEV_INFO("Read FCoE L2 MAC: %pM\n",
10377 bp->flags |= NO_FCOE_FLAG;
10379 bp->mf_ext_config = cfg;
10381 } else { /* SD MODE */
10382 if (IS_MF_STORAGE_SD(bp)) {
10383 if (BNX2X_IS_MF_SD_PROTOCOL_ISCSI(bp)) {
10384 /* use primary mac as iscsi mac */
10385 memcpy(iscsi_mac, bp->dev->dev_addr,
10388 BNX2X_DEV_INFO("SD ISCSI MODE\n");
10389 BNX2X_DEV_INFO("Read iSCSI MAC: %pM\n",
10391 } else { /* FCoE */
10392 memcpy(fip_mac, bp->dev->dev_addr,
10394 BNX2X_DEV_INFO("SD FCoE MODE\n");
10395 BNX2X_DEV_INFO("Read FIP MAC: %pM\n",
10398 /* Zero primary MAC configuration */
10399 memset(bp->dev->dev_addr, 0, ETH_ALEN);
10403 if (IS_MF_FCOE_AFEX(bp))
10404 /* use FIP MAC as primary MAC */
10405 memcpy(bp->dev->dev_addr, fip_mac, ETH_ALEN);
10409 /* in SF read MACs from port configuration */
10410 val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
10411 val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
10412 bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
10415 val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
10417 val = SHMEM_RD(bp, dev_info.port_hw_config[port].
10419 bnx2x_set_mac_buf(iscsi_mac, val, val2);
10421 val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
10422 fcoe_fip_mac_upper);
10423 val = SHMEM_RD(bp, dev_info.port_hw_config[port].
10424 fcoe_fip_mac_lower);
10425 bnx2x_set_mac_buf(fip_mac, val, val2);
10429 memcpy(bp->link_params.mac_addr, bp->dev->dev_addr, ETH_ALEN);
10430 memcpy(bp->dev->perm_addr, bp->dev->dev_addr, ETH_ALEN);
10433 /* Disable iSCSI if MAC configuration is
10436 if (!is_valid_ether_addr(iscsi_mac)) {
10437 bp->flags |= NO_ISCSI_FLAG;
10438 memset(iscsi_mac, 0, ETH_ALEN);
10441 /* Disable FCoE if MAC configuration is
10444 if (!is_valid_ether_addr(fip_mac)) {
10445 bp->flags |= NO_FCOE_FLAG;
10446 memset(bp->fip_mac, 0, ETH_ALEN);
10450 if (!bnx2x_is_valid_ether_addr(bp, bp->dev->dev_addr))
10451 dev_err(&bp->pdev->dev,
10452 "bad Ethernet MAC address configuration: %pM\n"
10453 "change it manually before bringing up the appropriate network interface\n",
10454 bp->dev->dev_addr);
10459 static int __devinit bnx2x_get_hwinfo(struct bnx2x *bp)
10461 int /*abs*/func = BP_ABS_FUNC(bp);
10466 bnx2x_get_common_hwinfo(bp);
10469 * initialize IGU parameters
10471 if (CHIP_IS_E1x(bp)) {
10472 bp->common.int_block = INT_BLOCK_HC;
10474 bp->igu_dsb_id = DEF_SB_IGU_ID;
10475 bp->igu_base_sb = 0;
10477 bp->common.int_block = INT_BLOCK_IGU;
10479 /* do not allow device reset during IGU info preocessing */
10480 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
10482 val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
10484 if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
10487 BNX2X_DEV_INFO("FORCING Normal Mode\n");
10489 val &= ~(IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN);
10490 REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION, val);
10491 REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x7f);
10493 while (tout && REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
10495 usleep_range(1000, 1000);
10498 if (REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
10499 dev_err(&bp->pdev->dev,
10500 "FORCING Normal Mode failed!!!\n");
10505 if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
10506 BNX2X_DEV_INFO("IGU Backward Compatible Mode\n");
10507 bp->common.int_block |= INT_BLOCK_MODE_BW_COMP;
10509 BNX2X_DEV_INFO("IGU Normal Mode\n");
10511 bnx2x_get_igu_cam_info(bp);
10513 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
10517 * set base FW non-default (fast path) status block id, this value is
10518 * used to initialize the fw_sb_id saved on the fp/queue structure to
10519 * determine the id used by the FW.
10521 if (CHIP_IS_E1x(bp))
10522 bp->base_fw_ndsb = BP_PORT(bp) * FP_SB_MAX_E1x + BP_L_ID(bp);
10524 * 57712 - we currently use one FW SB per IGU SB (Rx and Tx of
10525 * the same queue are indicated on the same IGU SB). So we prefer
10526 * FW and IGU SBs to be the same value.
10528 bp->base_fw_ndsb = bp->igu_base_sb;
10530 BNX2X_DEV_INFO("igu_dsb_id %d igu_base_sb %d igu_sb_cnt %d\n"
10531 "base_fw_ndsb %d\n", bp->igu_dsb_id, bp->igu_base_sb,
10532 bp->igu_sb_cnt, bp->base_fw_ndsb);
10535 * Initialize MF configuration
10542 if (!CHIP_IS_E1(bp) && !BP_NOMCP(bp)) {
10543 BNX2X_DEV_INFO("shmem2base 0x%x, size %d, mfcfg offset %d\n",
10544 bp->common.shmem2_base, SHMEM2_RD(bp, size),
10545 (u32)offsetof(struct shmem2_region, mf_cfg_addr));
10547 if (SHMEM2_HAS(bp, mf_cfg_addr))
10548 bp->common.mf_cfg_base = SHMEM2_RD(bp, mf_cfg_addr);
10550 bp->common.mf_cfg_base = bp->common.shmem_base +
10551 offsetof(struct shmem_region, func_mb) +
10552 E1H_FUNC_MAX * sizeof(struct drv_func_mb);
10554 * get mf configuration:
10555 * 1. existence of MF configuration
10556 * 2. MAC address must be legal (check only upper bytes)
10557 * for Switch-Independent mode;
10558 * OVLAN must be legal for Switch-Dependent mode
10559 * 3. SF_MODE configures specific MF mode
10561 if (bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
10562 /* get mf configuration */
10564 dev_info.shared_feature_config.config);
10565 val &= SHARED_FEAT_CFG_FORCE_SF_MODE_MASK;
10568 case SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT:
10569 val = MF_CFG_RD(bp, func_mf_config[func].
10571 /* check for legal mac (upper bytes)*/
10572 if (val != 0xffff) {
10573 bp->mf_mode = MULTI_FUNCTION_SI;
10574 bp->mf_config[vn] = MF_CFG_RD(bp,
10575 func_mf_config[func].config);
10577 BNX2X_DEV_INFO("illegal MAC address for SI\n");
10579 case SHARED_FEAT_CFG_FORCE_SF_MODE_AFEX_MODE:
10580 if ((!CHIP_IS_E1x(bp)) &&
10581 (MF_CFG_RD(bp, func_mf_config[func].
10582 mac_upper) != 0xffff) &&
10584 afex_driver_support))) {
10585 bp->mf_mode = MULTI_FUNCTION_AFEX;
10586 bp->mf_config[vn] = MF_CFG_RD(bp,
10587 func_mf_config[func].config);
10589 BNX2X_DEV_INFO("can not configure afex mode\n");
10592 case SHARED_FEAT_CFG_FORCE_SF_MODE_MF_ALLOWED:
10593 /* get OV configuration */
10594 val = MF_CFG_RD(bp,
10595 func_mf_config[FUNC_0].e1hov_tag);
10596 val &= FUNC_MF_CFG_E1HOV_TAG_MASK;
10598 if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
10599 bp->mf_mode = MULTI_FUNCTION_SD;
10600 bp->mf_config[vn] = MF_CFG_RD(bp,
10601 func_mf_config[func].config);
10603 BNX2X_DEV_INFO("illegal OV for SD\n");
10606 /* Unknown configuration: reset mf_config */
10607 bp->mf_config[vn] = 0;
10608 BNX2X_DEV_INFO("unknown MF mode 0x%x\n", val);
10612 BNX2X_DEV_INFO("%s function mode\n",
10613 IS_MF(bp) ? "multi" : "single");
10615 switch (bp->mf_mode) {
10616 case MULTI_FUNCTION_SD:
10617 val = MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
10618 FUNC_MF_CFG_E1HOV_TAG_MASK;
10619 if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
10621 bp->path_has_ovlan = true;
10623 BNX2X_DEV_INFO("MF OV for func %d is %d (0x%04x)\n",
10624 func, bp->mf_ov, bp->mf_ov);
10626 dev_err(&bp->pdev->dev,
10627 "No valid MF OV for func %d, aborting\n",
10632 case MULTI_FUNCTION_AFEX:
10633 BNX2X_DEV_INFO("func %d is in MF afex mode\n", func);
10635 case MULTI_FUNCTION_SI:
10636 BNX2X_DEV_INFO("func %d is in MF switch-independent mode\n",
10641 dev_err(&bp->pdev->dev,
10642 "VN %d is in a single function mode, aborting\n",
10649 /* check if other port on the path needs ovlan:
10650 * Since MF configuration is shared between ports
10651 * Possible mixed modes are only
10652 * {SF, SI} {SF, SD} {SD, SF} {SI, SF}
10654 if (CHIP_MODE_IS_4_PORT(bp) &&
10655 !bp->path_has_ovlan &&
10657 bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
10658 u8 other_port = !BP_PORT(bp);
10659 u8 other_func = BP_PATH(bp) + 2*other_port;
10660 val = MF_CFG_RD(bp,
10661 func_mf_config[other_func].e1hov_tag);
10662 if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT)
10663 bp->path_has_ovlan = true;
10667 /* adjust igu_sb_cnt to MF for E1x */
10668 if (CHIP_IS_E1x(bp) && IS_MF(bp))
10669 bp->igu_sb_cnt /= E1HVN_MAX;
10672 bnx2x_get_port_hwinfo(bp);
10674 /* Get MAC addresses */
10675 bnx2x_get_mac_hwinfo(bp);
10677 bnx2x_get_cnic_info(bp);
10682 static void __devinit bnx2x_read_fwinfo(struct bnx2x *bp)
10684 int cnt, i, block_end, rodi;
10685 char vpd_start[BNX2X_VPD_LEN+1];
10686 char str_id_reg[VENDOR_ID_LEN+1];
10687 char str_id_cap[VENDOR_ID_LEN+1];
10689 char *vpd_extended_data = NULL;
10692 cnt = pci_read_vpd(bp->pdev, 0, BNX2X_VPD_LEN, vpd_start);
10693 memset(bp->fw_ver, 0, sizeof(bp->fw_ver));
10695 if (cnt < BNX2X_VPD_LEN)
10696 goto out_not_found;
10698 /* VPD RO tag should be first tag after identifier string, hence
10699 * we should be able to find it in first BNX2X_VPD_LEN chars
10701 i = pci_vpd_find_tag(vpd_start, 0, BNX2X_VPD_LEN,
10702 PCI_VPD_LRDT_RO_DATA);
10704 goto out_not_found;
10706 block_end = i + PCI_VPD_LRDT_TAG_SIZE +
10707 pci_vpd_lrdt_size(&vpd_start[i]);
10709 i += PCI_VPD_LRDT_TAG_SIZE;
10711 if (block_end > BNX2X_VPD_LEN) {
10712 vpd_extended_data = kmalloc(block_end, GFP_KERNEL);
10713 if (vpd_extended_data == NULL)
10714 goto out_not_found;
10716 /* read rest of vpd image into vpd_extended_data */
10717 memcpy(vpd_extended_data, vpd_start, BNX2X_VPD_LEN);
10718 cnt = pci_read_vpd(bp->pdev, BNX2X_VPD_LEN,
10719 block_end - BNX2X_VPD_LEN,
10720 vpd_extended_data + BNX2X_VPD_LEN);
10721 if (cnt < (block_end - BNX2X_VPD_LEN))
10722 goto out_not_found;
10723 vpd_data = vpd_extended_data;
10725 vpd_data = vpd_start;
10727 /* now vpd_data holds full vpd content in both cases */
10729 rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
10730 PCI_VPD_RO_KEYWORD_MFR_ID);
10732 goto out_not_found;
10734 len = pci_vpd_info_field_size(&vpd_data[rodi]);
10736 if (len != VENDOR_ID_LEN)
10737 goto out_not_found;
10739 rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
10741 /* vendor specific info */
10742 snprintf(str_id_reg, VENDOR_ID_LEN + 1, "%04x", PCI_VENDOR_ID_DELL);
10743 snprintf(str_id_cap, VENDOR_ID_LEN + 1, "%04X", PCI_VENDOR_ID_DELL);
10744 if (!strncmp(str_id_reg, &vpd_data[rodi], VENDOR_ID_LEN) ||
10745 !strncmp(str_id_cap, &vpd_data[rodi], VENDOR_ID_LEN)) {
10747 rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
10748 PCI_VPD_RO_KEYWORD_VENDOR0);
10750 len = pci_vpd_info_field_size(&vpd_data[rodi]);
10752 rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
10754 if (len < 32 && (len + rodi) <= BNX2X_VPD_LEN) {
10755 memcpy(bp->fw_ver, &vpd_data[rodi], len);
10756 bp->fw_ver[len] = ' ';
10759 kfree(vpd_extended_data);
10763 kfree(vpd_extended_data);
10767 static void __devinit bnx2x_set_modes_bitmap(struct bnx2x *bp)
10771 if (CHIP_REV_IS_FPGA(bp))
10772 SET_FLAGS(flags, MODE_FPGA);
10773 else if (CHIP_REV_IS_EMUL(bp))
10774 SET_FLAGS(flags, MODE_EMUL);
10776 SET_FLAGS(flags, MODE_ASIC);
10778 if (CHIP_MODE_IS_4_PORT(bp))
10779 SET_FLAGS(flags, MODE_PORT4);
10781 SET_FLAGS(flags, MODE_PORT2);
10783 if (CHIP_IS_E2(bp))
10784 SET_FLAGS(flags, MODE_E2);
10785 else if (CHIP_IS_E3(bp)) {
10786 SET_FLAGS(flags, MODE_E3);
10787 if (CHIP_REV(bp) == CHIP_REV_Ax)
10788 SET_FLAGS(flags, MODE_E3_A0);
10789 else /*if (CHIP_REV(bp) == CHIP_REV_Bx)*/
10790 SET_FLAGS(flags, MODE_E3_B0 | MODE_COS3);
10794 SET_FLAGS(flags, MODE_MF);
10795 switch (bp->mf_mode) {
10796 case MULTI_FUNCTION_SD:
10797 SET_FLAGS(flags, MODE_MF_SD);
10799 case MULTI_FUNCTION_SI:
10800 SET_FLAGS(flags, MODE_MF_SI);
10802 case MULTI_FUNCTION_AFEX:
10803 SET_FLAGS(flags, MODE_MF_AFEX);
10807 SET_FLAGS(flags, MODE_SF);
10809 #if defined(__LITTLE_ENDIAN)
10810 SET_FLAGS(flags, MODE_LITTLE_ENDIAN);
10811 #else /*(__BIG_ENDIAN)*/
10812 SET_FLAGS(flags, MODE_BIG_ENDIAN);
10814 INIT_MODE_FLAGS(bp) = flags;
10817 static int __devinit bnx2x_init_bp(struct bnx2x *bp)
10822 mutex_init(&bp->port.phy_mutex);
10823 mutex_init(&bp->fw_mb_mutex);
10824 spin_lock_init(&bp->stats_lock);
10826 mutex_init(&bp->cnic_mutex);
10829 INIT_DELAYED_WORK(&bp->sp_task, bnx2x_sp_task);
10830 INIT_DELAYED_WORK(&bp->sp_rtnl_task, bnx2x_sp_rtnl_task);
10831 INIT_DELAYED_WORK(&bp->period_task, bnx2x_period_task);
10832 rc = bnx2x_get_hwinfo(bp);
10836 bnx2x_set_modes_bitmap(bp);
10838 rc = bnx2x_alloc_mem_bp(bp);
10842 bnx2x_read_fwinfo(bp);
10844 func = BP_FUNC(bp);
10846 /* need to reset chip if undi was active */
10847 if (!BP_NOMCP(bp)) {
10850 SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
10851 DRV_MSG_SEQ_NUMBER_MASK;
10852 BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
10854 bnx2x_prev_unload(bp);
10858 if (CHIP_REV_IS_FPGA(bp))
10859 dev_err(&bp->pdev->dev, "FPGA detected\n");
10861 if (BP_NOMCP(bp) && (func == 0))
10862 dev_err(&bp->pdev->dev, "MCP disabled, must load devices in order!\n");
10864 bp->disable_tpa = disable_tpa;
10867 bp->disable_tpa |= IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp);
10870 /* Set TPA flags */
10871 if (bp->disable_tpa) {
10872 bp->flags &= ~(TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
10873 bp->dev->features &= ~NETIF_F_LRO;
10875 bp->flags |= (TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
10876 bp->dev->features |= NETIF_F_LRO;
10879 if (CHIP_IS_E1(bp))
10880 bp->dropless_fc = 0;
10882 bp->dropless_fc = dropless_fc;
10886 bp->tx_ring_size = IS_MF_FCOE_AFEX(bp) ? 0 : MAX_TX_AVAIL;
10888 /* make sure that the numbers are in the right granularity */
10889 bp->tx_ticks = (50 / BNX2X_BTR) * BNX2X_BTR;
10890 bp->rx_ticks = (25 / BNX2X_BTR) * BNX2X_BTR;
10892 bp->current_interval = CHIP_REV_IS_SLOW(bp) ? 5*HZ : HZ;
10894 init_timer(&bp->timer);
10895 bp->timer.expires = jiffies + bp->current_interval;
10896 bp->timer.data = (unsigned long) bp;
10897 bp->timer.function = bnx2x_timer;
10899 bnx2x_dcbx_set_state(bp, true, BNX2X_DCBX_ENABLED_ON_NEG_ON);
10900 bnx2x_dcbx_init_params(bp);
10903 if (CHIP_IS_E1x(bp))
10904 bp->cnic_base_cl_id = FP_SB_MAX_E1x;
10906 bp->cnic_base_cl_id = FP_SB_MAX_E2;
10909 /* multiple tx priority */
10910 if (CHIP_IS_E1x(bp))
10911 bp->max_cos = BNX2X_MULTI_TX_COS_E1X;
10912 if (CHIP_IS_E2(bp) || CHIP_IS_E3A0(bp))
10913 bp->max_cos = BNX2X_MULTI_TX_COS_E2_E3A0;
10914 if (CHIP_IS_E3B0(bp))
10915 bp->max_cos = BNX2X_MULTI_TX_COS_E3B0;
10921 /****************************************************************************
10922 * General service functions
10923 ****************************************************************************/
10926 * net_device service functions
10929 /* called with rtnl_lock */
10930 static int bnx2x_open(struct net_device *dev)
10932 struct bnx2x *bp = netdev_priv(dev);
10933 bool global = false;
10934 int other_engine = BP_PATH(bp) ? 0 : 1;
10935 bool other_load_status, load_status;
10937 bp->stats_init = true;
10939 netif_carrier_off(dev);
10941 bnx2x_set_power_state(bp, PCI_D0);
10943 other_load_status = bnx2x_get_load_status(bp, other_engine);
10944 load_status = bnx2x_get_load_status(bp, BP_PATH(bp));
10947 * If parity had happen during the unload, then attentions
10948 * and/or RECOVERY_IN_PROGRES may still be set. In this case we
10949 * want the first function loaded on the current engine to
10950 * complete the recovery.
10952 if (!bnx2x_reset_is_done(bp, BP_PATH(bp)) ||
10953 bnx2x_chk_parity_attn(bp, &global, true))
10956 * If there are attentions and they are in a global
10957 * blocks, set the GLOBAL_RESET bit regardless whether
10958 * it will be this function that will complete the
10962 bnx2x_set_reset_global(bp);
10965 * Only the first function on the current engine should
10966 * try to recover in open. In case of attentions in
10967 * global blocks only the first in the chip should try
10970 if ((!load_status &&
10971 (!global || !other_load_status)) &&
10972 bnx2x_trylock_leader_lock(bp) &&
10973 !bnx2x_leader_reset(bp)) {
10974 netdev_info(bp->dev, "Recovered in open\n");
10978 /* recovery has failed... */
10979 bnx2x_set_power_state(bp, PCI_D3hot);
10980 bp->recovery_state = BNX2X_RECOVERY_FAILED;
10982 BNX2X_ERR("Recovery flow hasn't been properly completed yet. Try again later.\n"
10983 "If you still see this message after a few retries then power cycle is required.\n");
10988 bp->recovery_state = BNX2X_RECOVERY_DONE;
10989 return bnx2x_nic_load(bp, LOAD_OPEN);
10992 /* called with rtnl_lock */
10993 static int bnx2x_close(struct net_device *dev)
10995 struct bnx2x *bp = netdev_priv(dev);
10997 /* Unload the driver, release IRQs */
10998 bnx2x_nic_unload(bp, UNLOAD_CLOSE);
11001 bnx2x_set_power_state(bp, PCI_D3hot);
11006 static int bnx2x_init_mcast_macs_list(struct bnx2x *bp,
11007 struct bnx2x_mcast_ramrod_params *p)
11009 int mc_count = netdev_mc_count(bp->dev);
11010 struct bnx2x_mcast_list_elem *mc_mac =
11011 kzalloc(sizeof(*mc_mac) * mc_count, GFP_ATOMIC);
11012 struct netdev_hw_addr *ha;
11017 INIT_LIST_HEAD(&p->mcast_list);
11019 netdev_for_each_mc_addr(ha, bp->dev) {
11020 mc_mac->mac = bnx2x_mc_addr(ha);
11021 list_add_tail(&mc_mac->link, &p->mcast_list);
11025 p->mcast_list_len = mc_count;
11030 static void bnx2x_free_mcast_macs_list(
11031 struct bnx2x_mcast_ramrod_params *p)
11033 struct bnx2x_mcast_list_elem *mc_mac =
11034 list_first_entry(&p->mcast_list, struct bnx2x_mcast_list_elem,
11042 * bnx2x_set_uc_list - configure a new unicast MACs list.
11044 * @bp: driver handle
11046 * We will use zero (0) as a MAC type for these MACs.
11048 static int bnx2x_set_uc_list(struct bnx2x *bp)
11051 struct net_device *dev = bp->dev;
11052 struct netdev_hw_addr *ha;
11053 struct bnx2x_vlan_mac_obj *mac_obj = &bp->sp_objs->mac_obj;
11054 unsigned long ramrod_flags = 0;
11056 /* First schedule a cleanup up of old configuration */
11057 rc = bnx2x_del_all_macs(bp, mac_obj, BNX2X_UC_LIST_MAC, false);
11059 BNX2X_ERR("Failed to schedule DELETE operations: %d\n", rc);
11063 netdev_for_each_uc_addr(ha, dev) {
11064 rc = bnx2x_set_mac_one(bp, bnx2x_uc_addr(ha), mac_obj, true,
11065 BNX2X_UC_LIST_MAC, &ramrod_flags);
11067 BNX2X_ERR("Failed to schedule ADD operations: %d\n",
11073 /* Execute the pending commands */
11074 __set_bit(RAMROD_CONT, &ramrod_flags);
11075 return bnx2x_set_mac_one(bp, NULL, mac_obj, false /* don't care */,
11076 BNX2X_UC_LIST_MAC, &ramrod_flags);
11079 static int bnx2x_set_mc_list(struct bnx2x *bp)
11081 struct net_device *dev = bp->dev;
11082 struct bnx2x_mcast_ramrod_params rparam = {NULL};
11085 rparam.mcast_obj = &bp->mcast_obj;
11087 /* first, clear all configured multicast MACs */
11088 rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
11090 BNX2X_ERR("Failed to clear multicast configuration: %d\n", rc);
11094 /* then, configure a new MACs list */
11095 if (netdev_mc_count(dev)) {
11096 rc = bnx2x_init_mcast_macs_list(bp, &rparam);
11098 BNX2X_ERR("Failed to create multicast MACs list: %d\n",
11103 /* Now add the new MACs */
11104 rc = bnx2x_config_mcast(bp, &rparam,
11105 BNX2X_MCAST_CMD_ADD);
11107 BNX2X_ERR("Failed to set a new multicast configuration: %d\n",
11110 bnx2x_free_mcast_macs_list(&rparam);
11117 /* If bp->state is OPEN, should be called with netif_addr_lock_bh() */
11118 void bnx2x_set_rx_mode(struct net_device *dev)
11120 struct bnx2x *bp = netdev_priv(dev);
11121 u32 rx_mode = BNX2X_RX_MODE_NORMAL;
11123 if (bp->state != BNX2X_STATE_OPEN) {
11124 DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
11128 DP(NETIF_MSG_IFUP, "dev->flags = %x\n", bp->dev->flags);
11130 if (dev->flags & IFF_PROMISC)
11131 rx_mode = BNX2X_RX_MODE_PROMISC;
11132 else if ((dev->flags & IFF_ALLMULTI) ||
11133 ((netdev_mc_count(dev) > BNX2X_MAX_MULTICAST) &&
11135 rx_mode = BNX2X_RX_MODE_ALLMULTI;
11137 /* some multicasts */
11138 if (bnx2x_set_mc_list(bp) < 0)
11139 rx_mode = BNX2X_RX_MODE_ALLMULTI;
11141 if (bnx2x_set_uc_list(bp) < 0)
11142 rx_mode = BNX2X_RX_MODE_PROMISC;
11145 bp->rx_mode = rx_mode;
11147 /* handle ISCSI SD mode */
11148 if (IS_MF_ISCSI_SD(bp))
11149 bp->rx_mode = BNX2X_RX_MODE_NONE;
11152 /* Schedule the rx_mode command */
11153 if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state)) {
11154 set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
11158 bnx2x_set_storm_rx_mode(bp);
11161 /* called with rtnl_lock */
11162 static int bnx2x_mdio_read(struct net_device *netdev, int prtad,
11163 int devad, u16 addr)
11165 struct bnx2x *bp = netdev_priv(netdev);
11169 DP(NETIF_MSG_LINK, "mdio_read: prtad 0x%x, devad 0x%x, addr 0x%x\n",
11170 prtad, devad, addr);
11172 /* The HW expects different devad if CL22 is used */
11173 devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
11175 bnx2x_acquire_phy_lock(bp);
11176 rc = bnx2x_phy_read(&bp->link_params, prtad, devad, addr, &value);
11177 bnx2x_release_phy_lock(bp);
11178 DP(NETIF_MSG_LINK, "mdio_read_val 0x%x rc = 0x%x\n", value, rc);
11185 /* called with rtnl_lock */
11186 static int bnx2x_mdio_write(struct net_device *netdev, int prtad, int devad,
11187 u16 addr, u16 value)
11189 struct bnx2x *bp = netdev_priv(netdev);
11193 "mdio_write: prtad 0x%x, devad 0x%x, addr 0x%x, value 0x%x\n",
11194 prtad, devad, addr, value);
11196 /* The HW expects different devad if CL22 is used */
11197 devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
11199 bnx2x_acquire_phy_lock(bp);
11200 rc = bnx2x_phy_write(&bp->link_params, prtad, devad, addr, value);
11201 bnx2x_release_phy_lock(bp);
11205 /* called with rtnl_lock */
11206 static int bnx2x_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
11208 struct bnx2x *bp = netdev_priv(dev);
11209 struct mii_ioctl_data *mdio = if_mii(ifr);
11211 DP(NETIF_MSG_LINK, "ioctl: phy id 0x%x, reg 0x%x, val_in 0x%x\n",
11212 mdio->phy_id, mdio->reg_num, mdio->val_in);
11214 if (!netif_running(dev))
11217 return mdio_mii_ioctl(&bp->mdio, mdio, cmd);
11220 #ifdef CONFIG_NET_POLL_CONTROLLER
11221 static void poll_bnx2x(struct net_device *dev)
11223 struct bnx2x *bp = netdev_priv(dev);
11226 for_each_eth_queue(bp, i) {
11227 struct bnx2x_fastpath *fp = &bp->fp[i];
11228 napi_schedule(&bnx2x_fp(bp, fp->index, napi));
11233 static int bnx2x_validate_addr(struct net_device *dev)
11235 struct bnx2x *bp = netdev_priv(dev);
11237 if (!bnx2x_is_valid_ether_addr(bp, dev->dev_addr)) {
11238 BNX2X_ERR("Non-valid Ethernet address\n");
11239 return -EADDRNOTAVAIL;
11244 static const struct net_device_ops bnx2x_netdev_ops = {
11245 .ndo_open = bnx2x_open,
11246 .ndo_stop = bnx2x_close,
11247 .ndo_start_xmit = bnx2x_start_xmit,
11248 .ndo_select_queue = bnx2x_select_queue,
11249 .ndo_set_rx_mode = bnx2x_set_rx_mode,
11250 .ndo_set_mac_address = bnx2x_change_mac_addr,
11251 .ndo_validate_addr = bnx2x_validate_addr,
11252 .ndo_do_ioctl = bnx2x_ioctl,
11253 .ndo_change_mtu = bnx2x_change_mtu,
11254 .ndo_fix_features = bnx2x_fix_features,
11255 .ndo_set_features = bnx2x_set_features,
11256 .ndo_tx_timeout = bnx2x_tx_timeout,
11257 #ifdef CONFIG_NET_POLL_CONTROLLER
11258 .ndo_poll_controller = poll_bnx2x,
11260 .ndo_setup_tc = bnx2x_setup_tc,
11262 #if defined(NETDEV_FCOE_WWNN) && defined(BCM_CNIC)
11263 .ndo_fcoe_get_wwn = bnx2x_fcoe_get_wwn,
11267 static int bnx2x_set_coherency_mask(struct bnx2x *bp)
11269 struct device *dev = &bp->pdev->dev;
11271 if (dma_set_mask(dev, DMA_BIT_MASK(64)) == 0) {
11272 bp->flags |= USING_DAC_FLAG;
11273 if (dma_set_coherent_mask(dev, DMA_BIT_MASK(64)) != 0) {
11274 dev_err(dev, "dma_set_coherent_mask failed, aborting\n");
11277 } else if (dma_set_mask(dev, DMA_BIT_MASK(32)) != 0) {
11278 dev_err(dev, "System does not support DMA, aborting\n");
11285 static int __devinit bnx2x_init_dev(struct pci_dev *pdev,
11286 struct net_device *dev,
11287 unsigned long board_type)
11292 bool chip_is_e1x = (board_type == BCM57710 ||
11293 board_type == BCM57711 ||
11294 board_type == BCM57711E);
11296 SET_NETDEV_DEV(dev, &pdev->dev);
11297 bp = netdev_priv(dev);
11303 rc = pci_enable_device(pdev);
11305 dev_err(&bp->pdev->dev,
11306 "Cannot enable PCI device, aborting\n");
11310 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
11311 dev_err(&bp->pdev->dev,
11312 "Cannot find PCI device base address, aborting\n");
11314 goto err_out_disable;
11317 if (!(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
11318 dev_err(&bp->pdev->dev, "Cannot find second PCI device"
11319 " base address, aborting\n");
11321 goto err_out_disable;
11324 if (atomic_read(&pdev->enable_cnt) == 1) {
11325 rc = pci_request_regions(pdev, DRV_MODULE_NAME);
11327 dev_err(&bp->pdev->dev,
11328 "Cannot obtain PCI resources, aborting\n");
11329 goto err_out_disable;
11332 pci_set_master(pdev);
11333 pci_save_state(pdev);
11336 bp->pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
11337 if (bp->pm_cap == 0) {
11338 dev_err(&bp->pdev->dev,
11339 "Cannot find power management capability, aborting\n");
11341 goto err_out_release;
11344 if (!pci_is_pcie(pdev)) {
11345 dev_err(&bp->pdev->dev, "Not PCI Express, aborting\n");
11347 goto err_out_release;
11350 rc = bnx2x_set_coherency_mask(bp);
11352 goto err_out_release;
11354 dev->mem_start = pci_resource_start(pdev, 0);
11355 dev->base_addr = dev->mem_start;
11356 dev->mem_end = pci_resource_end(pdev, 0);
11358 dev->irq = pdev->irq;
11360 bp->regview = pci_ioremap_bar(pdev, 0);
11361 if (!bp->regview) {
11362 dev_err(&bp->pdev->dev,
11363 "Cannot map register space, aborting\n");
11365 goto err_out_release;
11368 /* In E1/E1H use pci device function given by kernel.
11369 * In E2/E3 read physical function from ME register since these chips
11370 * support Physical Device Assignment where kernel BDF maybe arbitrary
11371 * (depending on hypervisor).
11374 bp->pf_num = PCI_FUNC(pdev->devfn);
11375 else {/* chip is E2/3*/
11376 pci_read_config_dword(bp->pdev,
11377 PCICFG_ME_REGISTER, &pci_cfg_dword);
11378 bp->pf_num = (u8)((pci_cfg_dword & ME_REG_ABS_PF_NUM) >>
11379 ME_REG_ABS_PF_NUM_SHIFT);
11381 BNX2X_DEV_INFO("me reg PF num: %d\n", bp->pf_num);
11383 bnx2x_set_power_state(bp, PCI_D0);
11385 /* clean indirect addresses */
11386 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
11387 PCICFG_VENDOR_ID_OFFSET);
11389 * Clean the following indirect addresses for all functions since it
11390 * is not used by the driver.
11392 REG_WR(bp, PXP2_REG_PGL_ADDR_88_F0, 0);
11393 REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F0, 0);
11394 REG_WR(bp, PXP2_REG_PGL_ADDR_90_F0, 0);
11395 REG_WR(bp, PXP2_REG_PGL_ADDR_94_F0, 0);
11398 REG_WR(bp, PXP2_REG_PGL_ADDR_88_F1, 0);
11399 REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F1, 0);
11400 REG_WR(bp, PXP2_REG_PGL_ADDR_90_F1, 0);
11401 REG_WR(bp, PXP2_REG_PGL_ADDR_94_F1, 0);
11405 * Enable internal target-read (in case we are probed after PF FLR).
11406 * Must be done prior to any BAR read access. Only for 57712 and up
11409 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
11411 dev->watchdog_timeo = TX_TIMEOUT;
11413 dev->netdev_ops = &bnx2x_netdev_ops;
11414 bnx2x_set_ethtool_ops(dev);
11416 dev->priv_flags |= IFF_UNICAST_FLT;
11418 dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
11419 NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
11420 NETIF_F_RXCSUM | NETIF_F_LRO | NETIF_F_GRO |
11421 NETIF_F_RXHASH | NETIF_F_HW_VLAN_TX;
11423 dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
11424 NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 | NETIF_F_HIGHDMA;
11426 dev->features |= dev->hw_features | NETIF_F_HW_VLAN_RX;
11427 if (bp->flags & USING_DAC_FLAG)
11428 dev->features |= NETIF_F_HIGHDMA;
11430 /* Add Loopback capability to the device */
11431 dev->hw_features |= NETIF_F_LOOPBACK;
11434 dev->dcbnl_ops = &bnx2x_dcbnl_ops;
11437 /* get_port_hwinfo() will set prtad and mmds properly */
11438 bp->mdio.prtad = MDIO_PRTAD_NONE;
11440 bp->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
11441 bp->mdio.dev = dev;
11442 bp->mdio.mdio_read = bnx2x_mdio_read;
11443 bp->mdio.mdio_write = bnx2x_mdio_write;
11448 if (atomic_read(&pdev->enable_cnt) == 1)
11449 pci_release_regions(pdev);
11452 pci_disable_device(pdev);
11453 pci_set_drvdata(pdev, NULL);
11459 static void __devinit bnx2x_get_pcie_width_speed(struct bnx2x *bp,
11460 int *width, int *speed)
11462 u32 val = REG_RD(bp, PCICFG_OFFSET + PCICFG_LINK_CONTROL);
11464 *width = (val & PCICFG_LINK_WIDTH) >> PCICFG_LINK_WIDTH_SHIFT;
11466 /* return value of 1=2.5GHz 2=5GHz */
11467 *speed = (val & PCICFG_LINK_SPEED) >> PCICFG_LINK_SPEED_SHIFT;
11470 static int bnx2x_check_firmware(struct bnx2x *bp)
11472 const struct firmware *firmware = bp->firmware;
11473 struct bnx2x_fw_file_hdr *fw_hdr;
11474 struct bnx2x_fw_file_section *sections;
11475 u32 offset, len, num_ops;
11480 if (firmware->size < sizeof(struct bnx2x_fw_file_hdr)) {
11481 BNX2X_ERR("Wrong FW size\n");
11485 fw_hdr = (struct bnx2x_fw_file_hdr *)firmware->data;
11486 sections = (struct bnx2x_fw_file_section *)fw_hdr;
11488 /* Make sure none of the offsets and sizes make us read beyond
11489 * the end of the firmware data */
11490 for (i = 0; i < sizeof(*fw_hdr) / sizeof(*sections); i++) {
11491 offset = be32_to_cpu(sections[i].offset);
11492 len = be32_to_cpu(sections[i].len);
11493 if (offset + len > firmware->size) {
11494 BNX2X_ERR("Section %d length is out of bounds\n", i);
11499 /* Likewise for the init_ops offsets */
11500 offset = be32_to_cpu(fw_hdr->init_ops_offsets.offset);
11501 ops_offsets = (u16 *)(firmware->data + offset);
11502 num_ops = be32_to_cpu(fw_hdr->init_ops.len) / sizeof(struct raw_op);
11504 for (i = 0; i < be32_to_cpu(fw_hdr->init_ops_offsets.len) / 2; i++) {
11505 if (be16_to_cpu(ops_offsets[i]) > num_ops) {
11506 BNX2X_ERR("Section offset %d is out of bounds\n", i);
11511 /* Check FW version */
11512 offset = be32_to_cpu(fw_hdr->fw_version.offset);
11513 fw_ver = firmware->data + offset;
11514 if ((fw_ver[0] != BCM_5710_FW_MAJOR_VERSION) ||
11515 (fw_ver[1] != BCM_5710_FW_MINOR_VERSION) ||
11516 (fw_ver[2] != BCM_5710_FW_REVISION_VERSION) ||
11517 (fw_ver[3] != BCM_5710_FW_ENGINEERING_VERSION)) {
11518 BNX2X_ERR("Bad FW version:%d.%d.%d.%d. Should be %d.%d.%d.%d\n",
11519 fw_ver[0], fw_ver[1], fw_ver[2], fw_ver[3],
11520 BCM_5710_FW_MAJOR_VERSION,
11521 BCM_5710_FW_MINOR_VERSION,
11522 BCM_5710_FW_REVISION_VERSION,
11523 BCM_5710_FW_ENGINEERING_VERSION);
11530 static void be32_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
11532 const __be32 *source = (const __be32 *)_source;
11533 u32 *target = (u32 *)_target;
11536 for (i = 0; i < n/4; i++)
11537 target[i] = be32_to_cpu(source[i]);
11541 Ops array is stored in the following format:
11542 {op(8bit), offset(24bit, big endian), data(32bit, big endian)}
11544 static void bnx2x_prep_ops(const u8 *_source, u8 *_target, u32 n)
11546 const __be32 *source = (const __be32 *)_source;
11547 struct raw_op *target = (struct raw_op *)_target;
11550 for (i = 0, j = 0; i < n/8; i++, j += 2) {
11551 tmp = be32_to_cpu(source[j]);
11552 target[i].op = (tmp >> 24) & 0xff;
11553 target[i].offset = tmp & 0xffffff;
11554 target[i].raw_data = be32_to_cpu(source[j + 1]);
11558 /* IRO array is stored in the following format:
11559 * {base(24bit), m1(16bit), m2(16bit), m3(16bit), size(16bit) }
11561 static void bnx2x_prep_iro(const u8 *_source, u8 *_target, u32 n)
11563 const __be32 *source = (const __be32 *)_source;
11564 struct iro *target = (struct iro *)_target;
11567 for (i = 0, j = 0; i < n/sizeof(struct iro); i++) {
11568 target[i].base = be32_to_cpu(source[j]);
11570 tmp = be32_to_cpu(source[j]);
11571 target[i].m1 = (tmp >> 16) & 0xffff;
11572 target[i].m2 = tmp & 0xffff;
11574 tmp = be32_to_cpu(source[j]);
11575 target[i].m3 = (tmp >> 16) & 0xffff;
11576 target[i].size = tmp & 0xffff;
11581 static void be16_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
11583 const __be16 *source = (const __be16 *)_source;
11584 u16 *target = (u16 *)_target;
11587 for (i = 0; i < n/2; i++)
11588 target[i] = be16_to_cpu(source[i]);
11591 #define BNX2X_ALLOC_AND_SET(arr, lbl, func) \
11593 u32 len = be32_to_cpu(fw_hdr->arr.len); \
11594 bp->arr = kmalloc(len, GFP_KERNEL); \
11597 func(bp->firmware->data + be32_to_cpu(fw_hdr->arr.offset), \
11598 (u8 *)bp->arr, len); \
11601 static int bnx2x_init_firmware(struct bnx2x *bp)
11603 const char *fw_file_name;
11604 struct bnx2x_fw_file_hdr *fw_hdr;
11610 if (CHIP_IS_E1(bp))
11611 fw_file_name = FW_FILE_NAME_E1;
11612 else if (CHIP_IS_E1H(bp))
11613 fw_file_name = FW_FILE_NAME_E1H;
11614 else if (!CHIP_IS_E1x(bp))
11615 fw_file_name = FW_FILE_NAME_E2;
11617 BNX2X_ERR("Unsupported chip revision\n");
11620 BNX2X_DEV_INFO("Loading %s\n", fw_file_name);
11622 rc = request_firmware(&bp->firmware, fw_file_name, &bp->pdev->dev);
11624 BNX2X_ERR("Can't load firmware file %s\n",
11626 goto request_firmware_exit;
11629 rc = bnx2x_check_firmware(bp);
11631 BNX2X_ERR("Corrupt firmware file %s\n", fw_file_name);
11632 goto request_firmware_exit;
11635 fw_hdr = (struct bnx2x_fw_file_hdr *)bp->firmware->data;
11637 /* Initialize the pointers to the init arrays */
11639 BNX2X_ALLOC_AND_SET(init_data, request_firmware_exit, be32_to_cpu_n);
11642 BNX2X_ALLOC_AND_SET(init_ops, init_ops_alloc_err, bnx2x_prep_ops);
11645 BNX2X_ALLOC_AND_SET(init_ops_offsets, init_offsets_alloc_err,
11648 /* STORMs firmware */
11649 INIT_TSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
11650 be32_to_cpu(fw_hdr->tsem_int_table_data.offset);
11651 INIT_TSEM_PRAM_DATA(bp) = bp->firmware->data +
11652 be32_to_cpu(fw_hdr->tsem_pram_data.offset);
11653 INIT_USEM_INT_TABLE_DATA(bp) = bp->firmware->data +
11654 be32_to_cpu(fw_hdr->usem_int_table_data.offset);
11655 INIT_USEM_PRAM_DATA(bp) = bp->firmware->data +
11656 be32_to_cpu(fw_hdr->usem_pram_data.offset);
11657 INIT_XSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
11658 be32_to_cpu(fw_hdr->xsem_int_table_data.offset);
11659 INIT_XSEM_PRAM_DATA(bp) = bp->firmware->data +
11660 be32_to_cpu(fw_hdr->xsem_pram_data.offset);
11661 INIT_CSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
11662 be32_to_cpu(fw_hdr->csem_int_table_data.offset);
11663 INIT_CSEM_PRAM_DATA(bp) = bp->firmware->data +
11664 be32_to_cpu(fw_hdr->csem_pram_data.offset);
11666 BNX2X_ALLOC_AND_SET(iro_arr, iro_alloc_err, bnx2x_prep_iro);
11671 kfree(bp->init_ops_offsets);
11672 init_offsets_alloc_err:
11673 kfree(bp->init_ops);
11674 init_ops_alloc_err:
11675 kfree(bp->init_data);
11676 request_firmware_exit:
11677 release_firmware(bp->firmware);
11678 bp->firmware = NULL;
11683 static void bnx2x_release_firmware(struct bnx2x *bp)
11685 kfree(bp->init_ops_offsets);
11686 kfree(bp->init_ops);
11687 kfree(bp->init_data);
11688 release_firmware(bp->firmware);
11689 bp->firmware = NULL;
11693 static struct bnx2x_func_sp_drv_ops bnx2x_func_sp_drv = {
11694 .init_hw_cmn_chip = bnx2x_init_hw_common_chip,
11695 .init_hw_cmn = bnx2x_init_hw_common,
11696 .init_hw_port = bnx2x_init_hw_port,
11697 .init_hw_func = bnx2x_init_hw_func,
11699 .reset_hw_cmn = bnx2x_reset_common,
11700 .reset_hw_port = bnx2x_reset_port,
11701 .reset_hw_func = bnx2x_reset_func,
11703 .gunzip_init = bnx2x_gunzip_init,
11704 .gunzip_end = bnx2x_gunzip_end,
11706 .init_fw = bnx2x_init_firmware,
11707 .release_fw = bnx2x_release_firmware,
11710 void bnx2x__init_func_obj(struct bnx2x *bp)
11712 /* Prepare DMAE related driver resources */
11713 bnx2x_setup_dmae(bp);
11715 bnx2x_init_func_obj(bp, &bp->func_obj,
11716 bnx2x_sp(bp, func_rdata),
11717 bnx2x_sp_mapping(bp, func_rdata),
11718 bnx2x_sp(bp, func_afex_rdata),
11719 bnx2x_sp_mapping(bp, func_afex_rdata),
11720 &bnx2x_func_sp_drv);
11723 /* must be called after sriov-enable */
11724 static int bnx2x_set_qm_cid_count(struct bnx2x *bp)
11726 int cid_count = BNX2X_L2_MAX_CID(bp);
11729 cid_count += CNIC_CID_MAX;
11731 return roundup(cid_count, QM_CID_ROUND);
11735 * bnx2x_get_num_none_def_sbs - return the number of none default SBs
11740 static int bnx2x_get_num_non_def_sbs(struct pci_dev *pdev)
11745 pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
11748 * If MSI-X is not supported - return number of SBs needed to support
11749 * one fast path queue: one FP queue + SB for CNIC
11752 return 1 + CNIC_PRESENT;
11755 * The value in the PCI configuration space is the index of the last
11756 * entry, namely one less than the actual size of the table, which is
11757 * exactly what we want to return from this function: number of all SBs
11758 * without the default SB.
11760 pci_read_config_word(pdev, pos + PCI_MSI_FLAGS, &control);
11761 return control & PCI_MSIX_FLAGS_QSIZE;
11764 static int __devinit bnx2x_init_one(struct pci_dev *pdev,
11765 const struct pci_device_id *ent)
11767 struct net_device *dev = NULL;
11769 int pcie_width, pcie_speed;
11770 int rc, max_non_def_sbs;
11771 int rx_count, tx_count, rss_count, doorbell_size;
11773 * An estimated maximum supported CoS number according to the chip
11775 * We will try to roughly estimate the maximum number of CoSes this chip
11776 * may support in order to minimize the memory allocated for Tx
11777 * netdev_queue's. This number will be accurately calculated during the
11778 * initialization of bp->max_cos based on the chip versions AND chip
11779 * revision in the bnx2x_init_bp().
11781 u8 max_cos_est = 0;
11783 switch (ent->driver_data) {
11787 max_cos_est = BNX2X_MULTI_TX_COS_E1X;
11792 max_cos_est = BNX2X_MULTI_TX_COS_E2_E3A0;
11800 case BCM57840_4_10:
11801 case BCM57840_2_20:
11806 max_cos_est = BNX2X_MULTI_TX_COS_E3B0;
11810 pr_err("Unknown board_type (%ld), aborting\n",
11815 max_non_def_sbs = bnx2x_get_num_non_def_sbs(pdev);
11817 WARN_ON(!max_non_def_sbs);
11819 /* Maximum number of RSS queues: one IGU SB goes to CNIC */
11820 rss_count = max_non_def_sbs - CNIC_PRESENT;
11822 /* Maximum number of netdev Rx queues: RSS + FCoE L2 */
11823 rx_count = rss_count + FCOE_PRESENT;
11826 * Maximum number of netdev Tx queues:
11827 * Maximum TSS queues * Maximum supported number of CoS + FCoE L2
11829 tx_count = rss_count * max_cos_est + FCOE_PRESENT;
11831 /* dev zeroed in init_etherdev */
11832 dev = alloc_etherdev_mqs(sizeof(*bp), tx_count, rx_count);
11836 bp = netdev_priv(dev);
11838 bp->igu_sb_cnt = max_non_def_sbs;
11839 bp->msg_enable = debug;
11840 pci_set_drvdata(pdev, dev);
11842 rc = bnx2x_init_dev(pdev, dev, ent->driver_data);
11848 BNX2X_DEV_INFO("max_non_def_sbs %d\n", max_non_def_sbs);
11850 BNX2X_DEV_INFO("Allocated netdev with %d tx and %d rx queues\n",
11851 tx_count, rx_count);
11853 rc = bnx2x_init_bp(bp);
11855 goto init_one_exit;
11858 * Map doorbels here as we need the real value of bp->max_cos which
11859 * is initialized in bnx2x_init_bp().
11861 doorbell_size = BNX2X_L2_MAX_CID(bp) * (1 << BNX2X_DB_SHIFT);
11862 if (doorbell_size > pci_resource_len(pdev, 2)) {
11863 dev_err(&bp->pdev->dev,
11864 "Cannot map doorbells, bar size too small, aborting\n");
11866 goto init_one_exit;
11868 bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2),
11870 if (!bp->doorbells) {
11871 dev_err(&bp->pdev->dev,
11872 "Cannot map doorbell space, aborting\n");
11874 goto init_one_exit;
11877 /* calc qm_cid_count */
11878 bp->qm_cid_count = bnx2x_set_qm_cid_count(bp);
11881 /* disable FCOE L2 queue for E1x */
11882 if (CHIP_IS_E1x(bp))
11883 bp->flags |= NO_FCOE_FLAG;
11888 /* Set bp->num_queues for MSI-X mode*/
11889 bnx2x_set_num_queues(bp);
11891 /* Configure interrupt mode: try to enable MSI-X/MSI if
11894 bnx2x_set_int_mode(bp);
11896 rc = register_netdev(dev);
11898 dev_err(&pdev->dev, "Cannot register net device\n");
11899 goto init_one_exit;
11903 if (!NO_FCOE(bp)) {
11904 /* Add storage MAC address */
11906 dev_addr_add(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
11911 bnx2x_get_pcie_width_speed(bp, &pcie_width, &pcie_speed);
11914 "%s (%c%d) PCI-E x%d %s found at mem %lx, IRQ %d, node addr %pM\n",
11915 board_info[ent->driver_data].name,
11916 (CHIP_REV(bp) >> 12) + 'A', (CHIP_METAL(bp) >> 4),
11918 ((!CHIP_IS_E2(bp) && pcie_speed == 2) ||
11919 (CHIP_IS_E2(bp) && pcie_speed == 1)) ?
11920 "5GHz (Gen2)" : "2.5GHz",
11921 dev->base_addr, bp->pdev->irq, dev->dev_addr);
11927 iounmap(bp->regview);
11930 iounmap(bp->doorbells);
11934 if (atomic_read(&pdev->enable_cnt) == 1)
11935 pci_release_regions(pdev);
11937 pci_disable_device(pdev);
11938 pci_set_drvdata(pdev, NULL);
11943 static void __devexit bnx2x_remove_one(struct pci_dev *pdev)
11945 struct net_device *dev = pci_get_drvdata(pdev);
11949 dev_err(&pdev->dev, "BAD net device from bnx2x_init_one\n");
11952 bp = netdev_priv(dev);
11955 /* Delete storage MAC address */
11956 if (!NO_FCOE(bp)) {
11958 dev_addr_del(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
11964 /* Delete app tlvs from dcbnl */
11965 bnx2x_dcbnl_update_applist(bp, true);
11968 unregister_netdev(dev);
11970 /* Power on: we can't let PCI layer write to us while we are in D3 */
11971 bnx2x_set_power_state(bp, PCI_D0);
11973 /* Disable MSI/MSI-X */
11974 bnx2x_disable_msi(bp);
11977 bnx2x_set_power_state(bp, PCI_D3hot);
11979 /* Make sure RESET task is not scheduled before continuing */
11980 cancel_delayed_work_sync(&bp->sp_rtnl_task);
11983 iounmap(bp->regview);
11986 iounmap(bp->doorbells);
11988 bnx2x_release_firmware(bp);
11990 bnx2x_free_mem_bp(bp);
11994 if (atomic_read(&pdev->enable_cnt) == 1)
11995 pci_release_regions(pdev);
11997 pci_disable_device(pdev);
11998 pci_set_drvdata(pdev, NULL);
12001 static int bnx2x_eeh_nic_unload(struct bnx2x *bp)
12005 bp->state = BNX2X_STATE_ERROR;
12007 bp->rx_mode = BNX2X_RX_MODE_NONE;
12010 bnx2x_cnic_notify(bp, CNIC_CTL_STOP_CMD);
12013 bnx2x_tx_disable(bp);
12015 bnx2x_netif_stop(bp, 0);
12016 /* Delete all NAPI objects */
12017 bnx2x_del_all_napi(bp);
12019 del_timer_sync(&bp->timer);
12021 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
12024 bnx2x_free_irq(bp);
12026 /* Free SKBs, SGEs, TPA pool and driver internals */
12027 bnx2x_free_skbs(bp);
12029 for_each_rx_queue(bp, i)
12030 bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
12032 bnx2x_free_mem(bp);
12034 bp->state = BNX2X_STATE_CLOSED;
12036 netif_carrier_off(bp->dev);
12041 static void bnx2x_eeh_recover(struct bnx2x *bp)
12045 mutex_init(&bp->port.phy_mutex);
12048 val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
12049 if ((val & (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
12050 != (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
12051 BNX2X_ERR("BAD MCP validity signature\n");
12055 * bnx2x_io_error_detected - called when PCI error is detected
12056 * @pdev: Pointer to PCI device
12057 * @state: The current pci connection state
12059 * This function is called after a PCI bus error affecting
12060 * this device has been detected.
12062 static pci_ers_result_t bnx2x_io_error_detected(struct pci_dev *pdev,
12063 pci_channel_state_t state)
12065 struct net_device *dev = pci_get_drvdata(pdev);
12066 struct bnx2x *bp = netdev_priv(dev);
12070 netif_device_detach(dev);
12072 if (state == pci_channel_io_perm_failure) {
12074 return PCI_ERS_RESULT_DISCONNECT;
12077 if (netif_running(dev))
12078 bnx2x_eeh_nic_unload(bp);
12080 pci_disable_device(pdev);
12084 /* Request a slot reset */
12085 return PCI_ERS_RESULT_NEED_RESET;
12089 * bnx2x_io_slot_reset - called after the PCI bus has been reset
12090 * @pdev: Pointer to PCI device
12092 * Restart the card from scratch, as if from a cold-boot.
12094 static pci_ers_result_t bnx2x_io_slot_reset(struct pci_dev *pdev)
12096 struct net_device *dev = pci_get_drvdata(pdev);
12097 struct bnx2x *bp = netdev_priv(dev);
12101 if (pci_enable_device(pdev)) {
12102 dev_err(&pdev->dev,
12103 "Cannot re-enable PCI device after reset\n");
12105 return PCI_ERS_RESULT_DISCONNECT;
12108 pci_set_master(pdev);
12109 pci_restore_state(pdev);
12111 if (netif_running(dev))
12112 bnx2x_set_power_state(bp, PCI_D0);
12116 return PCI_ERS_RESULT_RECOVERED;
12120 * bnx2x_io_resume - called when traffic can start flowing again
12121 * @pdev: Pointer to PCI device
12123 * This callback is called when the error recovery driver tells us that
12124 * its OK to resume normal operation.
12126 static void bnx2x_io_resume(struct pci_dev *pdev)
12128 struct net_device *dev = pci_get_drvdata(pdev);
12129 struct bnx2x *bp = netdev_priv(dev);
12131 if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
12132 netdev_err(bp->dev, "Handling parity error recovery. Try again later\n");
12138 bnx2x_eeh_recover(bp);
12140 if (netif_running(dev))
12141 bnx2x_nic_load(bp, LOAD_NORMAL);
12143 netif_device_attach(dev);
12148 static const struct pci_error_handlers bnx2x_err_handler = {
12149 .error_detected = bnx2x_io_error_detected,
12150 .slot_reset = bnx2x_io_slot_reset,
12151 .resume = bnx2x_io_resume,
12154 static struct pci_driver bnx2x_pci_driver = {
12155 .name = DRV_MODULE_NAME,
12156 .id_table = bnx2x_pci_tbl,
12157 .probe = bnx2x_init_one,
12158 .remove = __devexit_p(bnx2x_remove_one),
12159 .suspend = bnx2x_suspend,
12160 .resume = bnx2x_resume,
12161 .err_handler = &bnx2x_err_handler,
12164 static int __init bnx2x_init(void)
12168 pr_info("%s", version);
12170 bnx2x_wq = create_singlethread_workqueue("bnx2x");
12171 if (bnx2x_wq == NULL) {
12172 pr_err("Cannot create workqueue\n");
12176 ret = pci_register_driver(&bnx2x_pci_driver);
12178 pr_err("Cannot register driver\n");
12179 destroy_workqueue(bnx2x_wq);
12184 static void __exit bnx2x_cleanup(void)
12186 struct list_head *pos, *q;
12187 pci_unregister_driver(&bnx2x_pci_driver);
12189 destroy_workqueue(bnx2x_wq);
12191 /* Free globablly allocated resources */
12192 list_for_each_safe(pos, q, &bnx2x_prev_list) {
12193 struct bnx2x_prev_path_list *tmp =
12194 list_entry(pos, struct bnx2x_prev_path_list, list);
12200 void bnx2x_notify_link_changed(struct bnx2x *bp)
12202 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + BP_FUNC(bp)*sizeof(u32), 1);
12205 module_init(bnx2x_init);
12206 module_exit(bnx2x_cleanup);
12210 * bnx2x_set_iscsi_eth_mac_addr - set iSCSI MAC(s).
12212 * @bp: driver handle
12213 * @set: set or clear the CAM entry
12215 * This function will wait until the ramdord completion returns.
12216 * Return 0 if success, -ENODEV if ramrod doesn't return.
12218 static int bnx2x_set_iscsi_eth_mac_addr(struct bnx2x *bp)
12220 unsigned long ramrod_flags = 0;
12222 __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
12223 return bnx2x_set_mac_one(bp, bp->cnic_eth_dev.iscsi_mac,
12224 &bp->iscsi_l2_mac_obj, true,
12225 BNX2X_ISCSI_ETH_MAC, &ramrod_flags);
12228 /* count denotes the number of new completions we have seen */
12229 static void bnx2x_cnic_sp_post(struct bnx2x *bp, int count)
12231 struct eth_spe *spe;
12232 int cxt_index, cxt_offset;
12234 #ifdef BNX2X_STOP_ON_ERROR
12235 if (unlikely(bp->panic))
12239 spin_lock_bh(&bp->spq_lock);
12240 BUG_ON(bp->cnic_spq_pending < count);
12241 bp->cnic_spq_pending -= count;
12244 for (; bp->cnic_kwq_pending; bp->cnic_kwq_pending--) {
12245 u16 type = (le16_to_cpu(bp->cnic_kwq_cons->hdr.type)
12246 & SPE_HDR_CONN_TYPE) >>
12247 SPE_HDR_CONN_TYPE_SHIFT;
12248 u8 cmd = (le32_to_cpu(bp->cnic_kwq_cons->hdr.conn_and_cmd_data)
12249 >> SPE_HDR_CMD_ID_SHIFT) & 0xff;
12251 /* Set validation for iSCSI L2 client before sending SETUP
12254 if (type == ETH_CONNECTION_TYPE) {
12255 if (cmd == RAMROD_CMD_ID_ETH_CLIENT_SETUP) {
12256 cxt_index = BNX2X_ISCSI_ETH_CID(bp) /
12258 cxt_offset = BNX2X_ISCSI_ETH_CID(bp) -
12259 (cxt_index * ILT_PAGE_CIDS);
12260 bnx2x_set_ctx_validation(bp,
12261 &bp->context[cxt_index].
12262 vcxt[cxt_offset].eth,
12263 BNX2X_ISCSI_ETH_CID(bp));
12268 * There may be not more than 8 L2, not more than 8 L5 SPEs
12269 * and in the air. We also check that number of outstanding
12270 * COMMON ramrods is not more than the EQ and SPQ can
12273 if (type == ETH_CONNECTION_TYPE) {
12274 if (!atomic_read(&bp->cq_spq_left))
12277 atomic_dec(&bp->cq_spq_left);
12278 } else if (type == NONE_CONNECTION_TYPE) {
12279 if (!atomic_read(&bp->eq_spq_left))
12282 atomic_dec(&bp->eq_spq_left);
12283 } else if ((type == ISCSI_CONNECTION_TYPE) ||
12284 (type == FCOE_CONNECTION_TYPE)) {
12285 if (bp->cnic_spq_pending >=
12286 bp->cnic_eth_dev.max_kwqe_pending)
12289 bp->cnic_spq_pending++;
12291 BNX2X_ERR("Unknown SPE type: %d\n", type);
12296 spe = bnx2x_sp_get_next(bp);
12297 *spe = *bp->cnic_kwq_cons;
12299 DP(BNX2X_MSG_SP, "pending on SPQ %d, on KWQ %d count %d\n",
12300 bp->cnic_spq_pending, bp->cnic_kwq_pending, count);
12302 if (bp->cnic_kwq_cons == bp->cnic_kwq_last)
12303 bp->cnic_kwq_cons = bp->cnic_kwq;
12305 bp->cnic_kwq_cons++;
12307 bnx2x_sp_prod_update(bp);
12308 spin_unlock_bh(&bp->spq_lock);
12311 static int bnx2x_cnic_sp_queue(struct net_device *dev,
12312 struct kwqe_16 *kwqes[], u32 count)
12314 struct bnx2x *bp = netdev_priv(dev);
12317 #ifdef BNX2X_STOP_ON_ERROR
12318 if (unlikely(bp->panic)) {
12319 BNX2X_ERR("Can't post to SP queue while panic\n");
12324 if ((bp->recovery_state != BNX2X_RECOVERY_DONE) &&
12325 (bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
12326 BNX2X_ERR("Handling parity error recovery. Try again later\n");
12330 spin_lock_bh(&bp->spq_lock);
12332 for (i = 0; i < count; i++) {
12333 struct eth_spe *spe = (struct eth_spe *)kwqes[i];
12335 if (bp->cnic_kwq_pending == MAX_SP_DESC_CNT)
12338 *bp->cnic_kwq_prod = *spe;
12340 bp->cnic_kwq_pending++;
12342 DP(BNX2X_MSG_SP, "L5 SPQE %x %x %x:%x pos %d\n",
12343 spe->hdr.conn_and_cmd_data, spe->hdr.type,
12344 spe->data.update_data_addr.hi,
12345 spe->data.update_data_addr.lo,
12346 bp->cnic_kwq_pending);
12348 if (bp->cnic_kwq_prod == bp->cnic_kwq_last)
12349 bp->cnic_kwq_prod = bp->cnic_kwq;
12351 bp->cnic_kwq_prod++;
12354 spin_unlock_bh(&bp->spq_lock);
12356 if (bp->cnic_spq_pending < bp->cnic_eth_dev.max_kwqe_pending)
12357 bnx2x_cnic_sp_post(bp, 0);
12362 static int bnx2x_cnic_ctl_send(struct bnx2x *bp, struct cnic_ctl_info *ctl)
12364 struct cnic_ops *c_ops;
12367 mutex_lock(&bp->cnic_mutex);
12368 c_ops = rcu_dereference_protected(bp->cnic_ops,
12369 lockdep_is_held(&bp->cnic_mutex));
12371 rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
12372 mutex_unlock(&bp->cnic_mutex);
12377 static int bnx2x_cnic_ctl_send_bh(struct bnx2x *bp, struct cnic_ctl_info *ctl)
12379 struct cnic_ops *c_ops;
12383 c_ops = rcu_dereference(bp->cnic_ops);
12385 rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
12392 * for commands that have no data
12394 int bnx2x_cnic_notify(struct bnx2x *bp, int cmd)
12396 struct cnic_ctl_info ctl = {0};
12400 return bnx2x_cnic_ctl_send(bp, &ctl);
12403 static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err)
12405 struct cnic_ctl_info ctl = {0};
12407 /* first we tell CNIC and only then we count this as a completion */
12408 ctl.cmd = CNIC_CTL_COMPLETION_CMD;
12409 ctl.data.comp.cid = cid;
12410 ctl.data.comp.error = err;
12412 bnx2x_cnic_ctl_send_bh(bp, &ctl);
12413 bnx2x_cnic_sp_post(bp, 0);
12417 /* Called with netif_addr_lock_bh() taken.
12418 * Sets an rx_mode config for an iSCSI ETH client.
12420 * Completion should be checked outside.
12422 static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start)
12424 unsigned long accept_flags = 0, ramrod_flags = 0;
12425 u8 cl_id = bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
12426 int sched_state = BNX2X_FILTER_ISCSI_ETH_STOP_SCHED;
12429 /* Start accepting on iSCSI L2 ring. Accept all multicasts
12430 * because it's the only way for UIO Queue to accept
12431 * multicasts (in non-promiscuous mode only one Queue per
12432 * function will receive multicast packets (leading in our
12435 __set_bit(BNX2X_ACCEPT_UNICAST, &accept_flags);
12436 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept_flags);
12437 __set_bit(BNX2X_ACCEPT_BROADCAST, &accept_flags);
12438 __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept_flags);
12440 /* Clear STOP_PENDING bit if START is requested */
12441 clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &bp->sp_state);
12443 sched_state = BNX2X_FILTER_ISCSI_ETH_START_SCHED;
12445 /* Clear START_PENDING bit if STOP is requested */
12446 clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &bp->sp_state);
12448 if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
12449 set_bit(sched_state, &bp->sp_state);
12451 __set_bit(RAMROD_RX, &ramrod_flags);
12452 bnx2x_set_q_rx_mode(bp, cl_id, 0, accept_flags, 0,
12458 static int bnx2x_drv_ctl(struct net_device *dev, struct drv_ctl_info *ctl)
12460 struct bnx2x *bp = netdev_priv(dev);
12463 switch (ctl->cmd) {
12464 case DRV_CTL_CTXTBL_WR_CMD: {
12465 u32 index = ctl->data.io.offset;
12466 dma_addr_t addr = ctl->data.io.dma_addr;
12468 bnx2x_ilt_wr(bp, index, addr);
12472 case DRV_CTL_RET_L5_SPQ_CREDIT_CMD: {
12473 int count = ctl->data.credit.credit_count;
12475 bnx2x_cnic_sp_post(bp, count);
12479 /* rtnl_lock is held. */
12480 case DRV_CTL_START_L2_CMD: {
12481 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
12482 unsigned long sp_bits = 0;
12484 /* Configure the iSCSI classification object */
12485 bnx2x_init_mac_obj(bp, &bp->iscsi_l2_mac_obj,
12486 cp->iscsi_l2_client_id,
12487 cp->iscsi_l2_cid, BP_FUNC(bp),
12488 bnx2x_sp(bp, mac_rdata),
12489 bnx2x_sp_mapping(bp, mac_rdata),
12490 BNX2X_FILTER_MAC_PENDING,
12491 &bp->sp_state, BNX2X_OBJ_TYPE_RX,
12494 /* Set iSCSI MAC address */
12495 rc = bnx2x_set_iscsi_eth_mac_addr(bp);
12502 /* Start accepting on iSCSI L2 ring */
12504 netif_addr_lock_bh(dev);
12505 bnx2x_set_iscsi_eth_rx_mode(bp, true);
12506 netif_addr_unlock_bh(dev);
12508 /* bits to wait on */
12509 __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
12510 __set_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &sp_bits);
12512 if (!bnx2x_wait_sp_comp(bp, sp_bits))
12513 BNX2X_ERR("rx_mode completion timed out!\n");
12518 /* rtnl_lock is held. */
12519 case DRV_CTL_STOP_L2_CMD: {
12520 unsigned long sp_bits = 0;
12522 /* Stop accepting on iSCSI L2 ring */
12523 netif_addr_lock_bh(dev);
12524 bnx2x_set_iscsi_eth_rx_mode(bp, false);
12525 netif_addr_unlock_bh(dev);
12527 /* bits to wait on */
12528 __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
12529 __set_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &sp_bits);
12531 if (!bnx2x_wait_sp_comp(bp, sp_bits))
12532 BNX2X_ERR("rx_mode completion timed out!\n");
12537 /* Unset iSCSI L2 MAC */
12538 rc = bnx2x_del_all_macs(bp, &bp->iscsi_l2_mac_obj,
12539 BNX2X_ISCSI_ETH_MAC, true);
12542 case DRV_CTL_RET_L2_SPQ_CREDIT_CMD: {
12543 int count = ctl->data.credit.credit_count;
12545 smp_mb__before_atomic_inc();
12546 atomic_add(count, &bp->cq_spq_left);
12547 smp_mb__after_atomic_inc();
12550 case DRV_CTL_ULP_REGISTER_CMD: {
12551 int ulp_type = ctl->data.register_data.ulp_type;
12553 if (CHIP_IS_E3(bp)) {
12554 int idx = BP_FW_MB_IDX(bp);
12555 u32 cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
12556 int path = BP_PATH(bp);
12557 int port = BP_PORT(bp);
12559 u32 scratch_offset;
12562 /* first write capability to shmem2 */
12563 if (ulp_type == CNIC_ULP_ISCSI)
12564 cap |= DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
12565 else if (ulp_type == CNIC_ULP_FCOE)
12566 cap |= DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
12567 SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
12569 if ((ulp_type != CNIC_ULP_FCOE) ||
12570 (!SHMEM2_HAS(bp, ncsi_oem_data_addr)) ||
12571 (!(bp->flags & BC_SUPPORTS_FCOE_FEATURES)))
12574 /* if reached here - should write fcoe capabilities */
12575 scratch_offset = SHMEM2_RD(bp, ncsi_oem_data_addr);
12576 if (!scratch_offset)
12578 scratch_offset += offsetof(struct glob_ncsi_oem_data,
12579 fcoe_features[path][port]);
12580 host_addr = (u32 *) &(ctl->data.register_data.
12582 for (i = 0; i < sizeof(struct fcoe_capabilities);
12584 REG_WR(bp, scratch_offset + i,
12585 *(host_addr + i/4));
12590 case DRV_CTL_ULP_UNREGISTER_CMD: {
12591 int ulp_type = ctl->data.ulp_type;
12593 if (CHIP_IS_E3(bp)) {
12594 int idx = BP_FW_MB_IDX(bp);
12597 cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
12598 if (ulp_type == CNIC_ULP_ISCSI)
12599 cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
12600 else if (ulp_type == CNIC_ULP_FCOE)
12601 cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
12602 SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
12608 BNX2X_ERR("unknown command %x\n", ctl->cmd);
12615 void bnx2x_setup_cnic_irq_info(struct bnx2x *bp)
12617 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
12619 if (bp->flags & USING_MSIX_FLAG) {
12620 cp->drv_state |= CNIC_DRV_STATE_USING_MSIX;
12621 cp->irq_arr[0].irq_flags |= CNIC_IRQ_FL_MSIX;
12622 cp->irq_arr[0].vector = bp->msix_table[1].vector;
12624 cp->drv_state &= ~CNIC_DRV_STATE_USING_MSIX;
12625 cp->irq_arr[0].irq_flags &= ~CNIC_IRQ_FL_MSIX;
12627 if (!CHIP_IS_E1x(bp))
12628 cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e2_sb;
12630 cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e1x_sb;
12632 cp->irq_arr[0].status_blk_num = bnx2x_cnic_fw_sb_id(bp);
12633 cp->irq_arr[0].status_blk_num2 = bnx2x_cnic_igu_sb_id(bp);
12634 cp->irq_arr[1].status_blk = bp->def_status_blk;
12635 cp->irq_arr[1].status_blk_num = DEF_SB_ID;
12636 cp->irq_arr[1].status_blk_num2 = DEF_SB_IGU_ID;
12641 void bnx2x_setup_cnic_info(struct bnx2x *bp)
12643 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
12646 cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
12647 bnx2x_cid_ilt_lines(bp);
12648 cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
12649 cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
12650 cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
12652 if (NO_ISCSI_OOO(bp))
12653 cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
12656 static int bnx2x_register_cnic(struct net_device *dev, struct cnic_ops *ops,
12659 struct bnx2x *bp = netdev_priv(dev);
12660 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
12663 BNX2X_ERR("NULL ops received\n");
12667 bp->cnic_kwq = kzalloc(PAGE_SIZE, GFP_KERNEL);
12671 bp->cnic_kwq_cons = bp->cnic_kwq;
12672 bp->cnic_kwq_prod = bp->cnic_kwq;
12673 bp->cnic_kwq_last = bp->cnic_kwq + MAX_SP_DESC_CNT;
12675 bp->cnic_spq_pending = 0;
12676 bp->cnic_kwq_pending = 0;
12678 bp->cnic_data = data;
12681 cp->drv_state |= CNIC_DRV_STATE_REGD;
12682 cp->iro_arr = bp->iro_arr;
12684 bnx2x_setup_cnic_irq_info(bp);
12686 rcu_assign_pointer(bp->cnic_ops, ops);
12691 static int bnx2x_unregister_cnic(struct net_device *dev)
12693 struct bnx2x *bp = netdev_priv(dev);
12694 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
12696 mutex_lock(&bp->cnic_mutex);
12698 RCU_INIT_POINTER(bp->cnic_ops, NULL);
12699 mutex_unlock(&bp->cnic_mutex);
12701 kfree(bp->cnic_kwq);
12702 bp->cnic_kwq = NULL;
12707 struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev)
12709 struct bnx2x *bp = netdev_priv(dev);
12710 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
12712 /* If both iSCSI and FCoE are disabled - return NULL in
12713 * order to indicate CNIC that it should not try to work
12714 * with this device.
12716 if (NO_ISCSI(bp) && NO_FCOE(bp))
12719 cp->drv_owner = THIS_MODULE;
12720 cp->chip_id = CHIP_ID(bp);
12721 cp->pdev = bp->pdev;
12722 cp->io_base = bp->regview;
12723 cp->io_base2 = bp->doorbells;
12724 cp->max_kwqe_pending = 8;
12725 cp->ctx_blk_size = CDU_ILT_PAGE_SZ;
12726 cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
12727 bnx2x_cid_ilt_lines(bp);
12728 cp->ctx_tbl_len = CNIC_ILT_LINES;
12729 cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
12730 cp->drv_submit_kwqes_16 = bnx2x_cnic_sp_queue;
12731 cp->drv_ctl = bnx2x_drv_ctl;
12732 cp->drv_register_cnic = bnx2x_register_cnic;
12733 cp->drv_unregister_cnic = bnx2x_unregister_cnic;
12734 cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
12735 cp->iscsi_l2_client_id =
12736 bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
12737 cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
12739 if (NO_ISCSI_OOO(bp))
12740 cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
12743 cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI;
12746 cp->drv_state |= CNIC_DRV_STATE_NO_FCOE;
12749 "page_size %d, tbl_offset %d, tbl_lines %d, starting cid %d\n",
12751 cp->ctx_tbl_offset,
12756 EXPORT_SYMBOL(bnx2x_cnic_probe);
12758 #endif /* BCM_CNIC */