1 /* bnx2x_main.c: Broadcom Everest network driver.
3 * Copyright (c) 2007-2012 Broadcom Corporation
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation.
9 * Maintained by: Eilon Greenstein <eilong@broadcom.com>
10 * Written by: Eliezer Tamir
11 * Based on code from Michael Chan's bnx2 driver
12 * UDP CSUM errata workaround by Arik Gendelman
13 * Slowpath and fastpath rework by Vladislav Zolotarov
14 * Statistics and Link management by Yitchak Gertner
18 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
20 #include <linux/module.h>
21 #include <linux/moduleparam.h>
22 #include <linux/kernel.h>
23 #include <linux/device.h> /* for dev_info() */
24 #include <linux/timer.h>
25 #include <linux/errno.h>
26 #include <linux/ioport.h>
27 #include <linux/slab.h>
28 #include <linux/interrupt.h>
29 #include <linux/pci.h>
30 #include <linux/init.h>
31 #include <linux/netdevice.h>
32 #include <linux/etherdevice.h>
33 #include <linux/skbuff.h>
34 #include <linux/dma-mapping.h>
35 #include <linux/bitops.h>
36 #include <linux/irq.h>
37 #include <linux/delay.h>
38 #include <asm/byteorder.h>
39 #include <linux/time.h>
40 #include <linux/ethtool.h>
41 #include <linux/mii.h>
42 #include <linux/if_vlan.h>
46 #include <net/checksum.h>
47 #include <net/ip6_checksum.h>
48 #include <linux/workqueue.h>
49 #include <linux/crc32.h>
50 #include <linux/crc32c.h>
51 #include <linux/prefetch.h>
52 #include <linux/zlib.h>
54 #include <linux/semaphore.h>
55 #include <linux/stringify.h>
56 #include <linux/vmalloc.h>
59 #include "bnx2x_init.h"
60 #include "bnx2x_init_ops.h"
61 #include "bnx2x_cmn.h"
62 #include "bnx2x_dcb.h"
65 #include <linux/firmware.h>
66 #include "bnx2x_fw_file_hdr.h"
68 #define FW_FILE_VERSION \
69 __stringify(BCM_5710_FW_MAJOR_VERSION) "." \
70 __stringify(BCM_5710_FW_MINOR_VERSION) "." \
71 __stringify(BCM_5710_FW_REVISION_VERSION) "." \
72 __stringify(BCM_5710_FW_ENGINEERING_VERSION)
73 #define FW_FILE_NAME_E1 "bnx2x/bnx2x-e1-" FW_FILE_VERSION ".fw"
74 #define FW_FILE_NAME_E1H "bnx2x/bnx2x-e1h-" FW_FILE_VERSION ".fw"
75 #define FW_FILE_NAME_E2 "bnx2x/bnx2x-e2-" FW_FILE_VERSION ".fw"
77 /* Time in jiffies before concluding the transmitter is hung */
78 #define TX_TIMEOUT (5*HZ)
80 static char version[] __devinitdata =
81 "Broadcom NetXtreme II 5771x/578xx 10/20-Gigabit Ethernet Driver "
82 DRV_MODULE_NAME " " DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
84 MODULE_AUTHOR("Eliezer Tamir");
85 MODULE_DESCRIPTION("Broadcom NetXtreme II "
86 "BCM57710/57711/57711E/"
87 "57712/57712_MF/57800/57800_MF/57810/57810_MF/"
88 "57840/57840_MF Driver");
89 MODULE_LICENSE("GPL");
90 MODULE_VERSION(DRV_MODULE_VERSION);
91 MODULE_FIRMWARE(FW_FILE_NAME_E1);
92 MODULE_FIRMWARE(FW_FILE_NAME_E1H);
93 MODULE_FIRMWARE(FW_FILE_NAME_E2);
95 static int multi_mode = 1;
96 module_param(multi_mode, int, 0);
97 MODULE_PARM_DESC(multi_mode, " Multi queue mode "
98 "(0 Disable; 1 Enable (default))");
101 module_param(num_queues, int, 0);
102 MODULE_PARM_DESC(num_queues, " Number of queues for multi_mode=1"
103 " (default is as a number of CPUs)");
105 static int disable_tpa;
106 module_param(disable_tpa, int, 0);
107 MODULE_PARM_DESC(disable_tpa, " Disable the TPA (LRO) feature");
109 #define INT_MODE_INTx 1
110 #define INT_MODE_MSI 2
112 module_param(int_mode, int, 0);
113 MODULE_PARM_DESC(int_mode, " Force interrupt mode other than MSI-X "
116 static int dropless_fc;
117 module_param(dropless_fc, int, 0);
118 MODULE_PARM_DESC(dropless_fc, " Pause on exhausted host ring");
120 static int mrrs = -1;
121 module_param(mrrs, int, 0);
122 MODULE_PARM_DESC(mrrs, " Force Max Read Req Size (0..3) (for debug)");
125 module_param(debug, int, 0);
126 MODULE_PARM_DESC(debug, " Default debug msglevel");
130 struct workqueue_struct *bnx2x_wq;
132 enum bnx2x_board_type {
146 /* indexed by board_type, above */
149 } board_info[] __devinitdata = {
150 { "Broadcom NetXtreme II BCM57710 10 Gigabit PCIe [Everest]" },
151 { "Broadcom NetXtreme II BCM57711 10 Gigabit PCIe" },
152 { "Broadcom NetXtreme II BCM57711E 10 Gigabit PCIe" },
153 { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet" },
154 { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Multi Function" },
155 { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet" },
156 { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Multi Function" },
157 { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet" },
158 { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Multi Function" },
159 { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet" },
160 { "Broadcom NetXtreme II BCM57840 10/20 Gigabit "
161 "Ethernet Multi Function"}
164 #ifndef PCI_DEVICE_ID_NX2_57710
165 #define PCI_DEVICE_ID_NX2_57710 CHIP_NUM_57710
167 #ifndef PCI_DEVICE_ID_NX2_57711
168 #define PCI_DEVICE_ID_NX2_57711 CHIP_NUM_57711
170 #ifndef PCI_DEVICE_ID_NX2_57711E
171 #define PCI_DEVICE_ID_NX2_57711E CHIP_NUM_57711E
173 #ifndef PCI_DEVICE_ID_NX2_57712
174 #define PCI_DEVICE_ID_NX2_57712 CHIP_NUM_57712
176 #ifndef PCI_DEVICE_ID_NX2_57712_MF
177 #define PCI_DEVICE_ID_NX2_57712_MF CHIP_NUM_57712_MF
179 #ifndef PCI_DEVICE_ID_NX2_57800
180 #define PCI_DEVICE_ID_NX2_57800 CHIP_NUM_57800
182 #ifndef PCI_DEVICE_ID_NX2_57800_MF
183 #define PCI_DEVICE_ID_NX2_57800_MF CHIP_NUM_57800_MF
185 #ifndef PCI_DEVICE_ID_NX2_57810
186 #define PCI_DEVICE_ID_NX2_57810 CHIP_NUM_57810
188 #ifndef PCI_DEVICE_ID_NX2_57810_MF
189 #define PCI_DEVICE_ID_NX2_57810_MF CHIP_NUM_57810_MF
191 #ifndef PCI_DEVICE_ID_NX2_57840
192 #define PCI_DEVICE_ID_NX2_57840 CHIP_NUM_57840
194 #ifndef PCI_DEVICE_ID_NX2_57840_MF
195 #define PCI_DEVICE_ID_NX2_57840_MF CHIP_NUM_57840_MF
197 static DEFINE_PCI_DEVICE_TABLE(bnx2x_pci_tbl) = {
198 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57710), BCM57710 },
199 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711), BCM57711 },
200 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711E), BCM57711E },
201 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712), BCM57712 },
202 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_MF), BCM57712_MF },
203 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800), BCM57800 },
204 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_MF), BCM57800_MF },
205 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810), BCM57810 },
206 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_MF), BCM57810_MF },
207 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840), BCM57840 },
208 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MF), BCM57840_MF },
212 MODULE_DEVICE_TABLE(pci, bnx2x_pci_tbl);
214 /* Global resources for unloading a previously loaded device */
215 #define BNX2X_PREV_WAIT_NEEDED 1
216 static DEFINE_SEMAPHORE(bnx2x_prev_sem);
217 static LIST_HEAD(bnx2x_prev_list);
218 /****************************************************************************
219 * General service functions
220 ****************************************************************************/
222 static inline void __storm_memset_dma_mapping(struct bnx2x *bp,
223 u32 addr, dma_addr_t mapping)
225 REG_WR(bp, addr, U64_LO(mapping));
226 REG_WR(bp, addr + 4, U64_HI(mapping));
229 static inline void storm_memset_spq_addr(struct bnx2x *bp,
230 dma_addr_t mapping, u16 abs_fid)
232 u32 addr = XSEM_REG_FAST_MEMORY +
233 XSTORM_SPQ_PAGE_BASE_OFFSET(abs_fid);
235 __storm_memset_dma_mapping(bp, addr, mapping);
238 static inline void storm_memset_vf_to_pf(struct bnx2x *bp, u16 abs_fid,
241 REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_VF_TO_PF_OFFSET(abs_fid),
243 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_VF_TO_PF_OFFSET(abs_fid),
245 REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_VF_TO_PF_OFFSET(abs_fid),
247 REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_VF_TO_PF_OFFSET(abs_fid),
251 static inline void storm_memset_func_en(struct bnx2x *bp, u16 abs_fid,
254 REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(abs_fid),
256 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(abs_fid),
258 REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(abs_fid),
260 REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(abs_fid),
264 static inline void storm_memset_eq_data(struct bnx2x *bp,
265 struct event_ring_data *eq_data,
268 size_t size = sizeof(struct event_ring_data);
270 u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_DATA_OFFSET(pfid);
272 __storm_memset_struct(bp, addr, size, (u32 *)eq_data);
275 static inline void storm_memset_eq_prod(struct bnx2x *bp, u16 eq_prod,
278 u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_PROD_OFFSET(pfid);
279 REG_WR16(bp, addr, eq_prod);
283 * locking is done by mcp
285 static void bnx2x_reg_wr_ind(struct bnx2x *bp, u32 addr, u32 val)
287 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
288 pci_write_config_dword(bp->pdev, PCICFG_GRC_DATA, val);
289 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
290 PCICFG_VENDOR_ID_OFFSET);
293 static u32 bnx2x_reg_rd_ind(struct bnx2x *bp, u32 addr)
297 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
298 pci_read_config_dword(bp->pdev, PCICFG_GRC_DATA, &val);
299 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
300 PCICFG_VENDOR_ID_OFFSET);
305 #define DMAE_DP_SRC_GRC "grc src_addr [%08x]"
306 #define DMAE_DP_SRC_PCI "pci src_addr [%x:%08x]"
307 #define DMAE_DP_DST_GRC "grc dst_addr [%08x]"
308 #define DMAE_DP_DST_PCI "pci dst_addr [%x:%08x]"
309 #define DMAE_DP_DST_NONE "dst_addr [none]"
311 static void bnx2x_dp_dmae(struct bnx2x *bp, struct dmae_command *dmae,
314 u32 src_type = dmae->opcode & DMAE_COMMAND_SRC;
316 switch (dmae->opcode & DMAE_COMMAND_DST) {
317 case DMAE_CMD_DST_PCI:
318 if (src_type == DMAE_CMD_SRC_PCI)
319 DP(msglvl, "DMAE: opcode 0x%08x\n"
320 "src [%x:%08x], len [%d*4], dst [%x:%08x]\n"
321 "comp_addr [%x:%08x], comp_val 0x%08x\n",
322 dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
323 dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
324 dmae->comp_addr_hi, dmae->comp_addr_lo,
327 DP(msglvl, "DMAE: opcode 0x%08x\n"
328 "src [%08x], len [%d*4], dst [%x:%08x]\n"
329 "comp_addr [%x:%08x], comp_val 0x%08x\n",
330 dmae->opcode, dmae->src_addr_lo >> 2,
331 dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
332 dmae->comp_addr_hi, dmae->comp_addr_lo,
335 case DMAE_CMD_DST_GRC:
336 if (src_type == DMAE_CMD_SRC_PCI)
337 DP(msglvl, "DMAE: opcode 0x%08x\n"
338 "src [%x:%08x], len [%d*4], dst_addr [%08x]\n"
339 "comp_addr [%x:%08x], comp_val 0x%08x\n",
340 dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
341 dmae->len, dmae->dst_addr_lo >> 2,
342 dmae->comp_addr_hi, dmae->comp_addr_lo,
345 DP(msglvl, "DMAE: opcode 0x%08x\n"
346 "src [%08x], len [%d*4], dst [%08x]\n"
347 "comp_addr [%x:%08x], comp_val 0x%08x\n",
348 dmae->opcode, dmae->src_addr_lo >> 2,
349 dmae->len, dmae->dst_addr_lo >> 2,
350 dmae->comp_addr_hi, dmae->comp_addr_lo,
354 if (src_type == DMAE_CMD_SRC_PCI)
355 DP(msglvl, "DMAE: opcode 0x%08x\n"
356 "src_addr [%x:%08x] len [%d * 4] dst_addr [none]\n"
357 "comp_addr [%x:%08x] comp_val 0x%08x\n",
358 dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
359 dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
362 DP(msglvl, "DMAE: opcode 0x%08x\n"
363 "src_addr [%08x] len [%d * 4] dst_addr [none]\n"
364 "comp_addr [%x:%08x] comp_val 0x%08x\n",
365 dmae->opcode, dmae->src_addr_lo >> 2,
366 dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
373 /* copy command into DMAE command memory and set DMAE command go */
374 void bnx2x_post_dmae(struct bnx2x *bp, struct dmae_command *dmae, int idx)
379 cmd_offset = (DMAE_REG_CMD_MEM + sizeof(struct dmae_command) * idx);
380 for (i = 0; i < (sizeof(struct dmae_command)/4); i++) {
381 REG_WR(bp, cmd_offset + i*4, *(((u32 *)dmae) + i));
383 REG_WR(bp, dmae_reg_go_c[idx], 1);
386 u32 bnx2x_dmae_opcode_add_comp(u32 opcode, u8 comp_type)
388 return opcode | ((comp_type << DMAE_COMMAND_C_DST_SHIFT) |
392 u32 bnx2x_dmae_opcode_clr_src_reset(u32 opcode)
394 return opcode & ~DMAE_CMD_SRC_RESET;
397 u32 bnx2x_dmae_opcode(struct bnx2x *bp, u8 src_type, u8 dst_type,
398 bool with_comp, u8 comp_type)
402 opcode |= ((src_type << DMAE_COMMAND_SRC_SHIFT) |
403 (dst_type << DMAE_COMMAND_DST_SHIFT));
405 opcode |= (DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET);
407 opcode |= (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0);
408 opcode |= ((BP_VN(bp) << DMAE_CMD_E1HVN_SHIFT) |
409 (BP_VN(bp) << DMAE_COMMAND_DST_VN_SHIFT));
410 opcode |= (DMAE_COM_SET_ERR << DMAE_COMMAND_ERR_POLICY_SHIFT);
413 opcode |= DMAE_CMD_ENDIANITY_B_DW_SWAP;
415 opcode |= DMAE_CMD_ENDIANITY_DW_SWAP;
418 opcode = bnx2x_dmae_opcode_add_comp(opcode, comp_type);
422 static void bnx2x_prep_dmae_with_comp(struct bnx2x *bp,
423 struct dmae_command *dmae,
424 u8 src_type, u8 dst_type)
426 memset(dmae, 0, sizeof(struct dmae_command));
429 dmae->opcode = bnx2x_dmae_opcode(bp, src_type, dst_type,
430 true, DMAE_COMP_PCI);
432 /* fill in the completion parameters */
433 dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_comp));
434 dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_comp));
435 dmae->comp_val = DMAE_COMP_VAL;
438 /* issue a dmae command over the init-channel and wailt for completion */
439 static int bnx2x_issue_dmae_with_comp(struct bnx2x *bp,
440 struct dmae_command *dmae)
442 u32 *wb_comp = bnx2x_sp(bp, wb_comp);
443 int cnt = CHIP_REV_IS_SLOW(bp) ? (400000) : 4000;
447 * Lock the dmae channel. Disable BHs to prevent a dead-lock
448 * as long as this code is called both from syscall context and
449 * from ndo_set_rx_mode() flow that may be called from BH.
451 spin_lock_bh(&bp->dmae_lock);
453 /* reset completion */
456 /* post the command on the channel used for initializations */
457 bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp));
459 /* wait for completion */
461 while ((*wb_comp & ~DMAE_PCI_ERR_FLAG) != DMAE_COMP_VAL) {
464 (bp->recovery_state != BNX2X_RECOVERY_DONE &&
465 bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
466 BNX2X_ERR("DMAE timeout!\n");
473 if (*wb_comp & DMAE_PCI_ERR_FLAG) {
474 BNX2X_ERR("DMAE PCI error!\n");
479 spin_unlock_bh(&bp->dmae_lock);
483 void bnx2x_write_dmae(struct bnx2x *bp, dma_addr_t dma_addr, u32 dst_addr,
486 struct dmae_command dmae;
488 if (!bp->dmae_ready) {
489 u32 *data = bnx2x_sp(bp, wb_data[0]);
492 bnx2x_init_ind_wr(bp, dst_addr, data, len32);
494 bnx2x_init_str_wr(bp, dst_addr, data, len32);
498 /* set opcode and fixed command fields */
499 bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_GRC);
501 /* fill in addresses and len */
502 dmae.src_addr_lo = U64_LO(dma_addr);
503 dmae.src_addr_hi = U64_HI(dma_addr);
504 dmae.dst_addr_lo = dst_addr >> 2;
505 dmae.dst_addr_hi = 0;
508 bnx2x_dp_dmae(bp, &dmae, BNX2X_MSG_OFF);
510 /* issue the command and wait for completion */
511 bnx2x_issue_dmae_with_comp(bp, &dmae);
514 void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32)
516 struct dmae_command dmae;
518 if (!bp->dmae_ready) {
519 u32 *data = bnx2x_sp(bp, wb_data[0]);
523 for (i = 0; i < len32; i++)
524 data[i] = bnx2x_reg_rd_ind(bp, src_addr + i*4);
526 for (i = 0; i < len32; i++)
527 data[i] = REG_RD(bp, src_addr + i*4);
532 /* set opcode and fixed command fields */
533 bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_GRC, DMAE_DST_PCI);
535 /* fill in addresses and len */
536 dmae.src_addr_lo = src_addr >> 2;
537 dmae.src_addr_hi = 0;
538 dmae.dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_data));
539 dmae.dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_data));
542 bnx2x_dp_dmae(bp, &dmae, BNX2X_MSG_OFF);
544 /* issue the command and wait for completion */
545 bnx2x_issue_dmae_with_comp(bp, &dmae);
548 static void bnx2x_write_dmae_phys_len(struct bnx2x *bp, dma_addr_t phys_addr,
551 int dmae_wr_max = DMAE_LEN32_WR_MAX(bp);
554 while (len > dmae_wr_max) {
555 bnx2x_write_dmae(bp, phys_addr + offset,
556 addr + offset, dmae_wr_max);
557 offset += dmae_wr_max * 4;
561 bnx2x_write_dmae(bp, phys_addr + offset, addr + offset, len);
564 /* used only for slowpath so not inlined */
565 static void bnx2x_wb_wr(struct bnx2x *bp, int reg, u32 val_hi, u32 val_lo)
569 wb_write[0] = val_hi;
570 wb_write[1] = val_lo;
571 REG_WR_DMAE(bp, reg, wb_write, 2);
575 static u64 bnx2x_wb_rd(struct bnx2x *bp, int reg)
579 REG_RD_DMAE(bp, reg, wb_data, 2);
581 return HILO_U64(wb_data[0], wb_data[1]);
585 static int bnx2x_mc_assert(struct bnx2x *bp)
589 u32 row0, row1, row2, row3;
592 last_idx = REG_RD8(bp, BAR_XSTRORM_INTMEM +
593 XSTORM_ASSERT_LIST_INDEX_OFFSET);
595 BNX2X_ERR("XSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
597 /* print the asserts */
598 for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
600 row0 = REG_RD(bp, BAR_XSTRORM_INTMEM +
601 XSTORM_ASSERT_LIST_OFFSET(i));
602 row1 = REG_RD(bp, BAR_XSTRORM_INTMEM +
603 XSTORM_ASSERT_LIST_OFFSET(i) + 4);
604 row2 = REG_RD(bp, BAR_XSTRORM_INTMEM +
605 XSTORM_ASSERT_LIST_OFFSET(i) + 8);
606 row3 = REG_RD(bp, BAR_XSTRORM_INTMEM +
607 XSTORM_ASSERT_LIST_OFFSET(i) + 12);
609 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
610 BNX2X_ERR("XSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
611 i, row3, row2, row1, row0);
619 last_idx = REG_RD8(bp, BAR_TSTRORM_INTMEM +
620 TSTORM_ASSERT_LIST_INDEX_OFFSET);
622 BNX2X_ERR("TSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
624 /* print the asserts */
625 for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
627 row0 = REG_RD(bp, BAR_TSTRORM_INTMEM +
628 TSTORM_ASSERT_LIST_OFFSET(i));
629 row1 = REG_RD(bp, BAR_TSTRORM_INTMEM +
630 TSTORM_ASSERT_LIST_OFFSET(i) + 4);
631 row2 = REG_RD(bp, BAR_TSTRORM_INTMEM +
632 TSTORM_ASSERT_LIST_OFFSET(i) + 8);
633 row3 = REG_RD(bp, BAR_TSTRORM_INTMEM +
634 TSTORM_ASSERT_LIST_OFFSET(i) + 12);
636 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
637 BNX2X_ERR("TSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
638 i, row3, row2, row1, row0);
646 last_idx = REG_RD8(bp, BAR_CSTRORM_INTMEM +
647 CSTORM_ASSERT_LIST_INDEX_OFFSET);
649 BNX2X_ERR("CSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
651 /* print the asserts */
652 for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
654 row0 = REG_RD(bp, BAR_CSTRORM_INTMEM +
655 CSTORM_ASSERT_LIST_OFFSET(i));
656 row1 = REG_RD(bp, BAR_CSTRORM_INTMEM +
657 CSTORM_ASSERT_LIST_OFFSET(i) + 4);
658 row2 = REG_RD(bp, BAR_CSTRORM_INTMEM +
659 CSTORM_ASSERT_LIST_OFFSET(i) + 8);
660 row3 = REG_RD(bp, BAR_CSTRORM_INTMEM +
661 CSTORM_ASSERT_LIST_OFFSET(i) + 12);
663 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
664 BNX2X_ERR("CSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
665 i, row3, row2, row1, row0);
673 last_idx = REG_RD8(bp, BAR_USTRORM_INTMEM +
674 USTORM_ASSERT_LIST_INDEX_OFFSET);
676 BNX2X_ERR("USTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
678 /* print the asserts */
679 for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
681 row0 = REG_RD(bp, BAR_USTRORM_INTMEM +
682 USTORM_ASSERT_LIST_OFFSET(i));
683 row1 = REG_RD(bp, BAR_USTRORM_INTMEM +
684 USTORM_ASSERT_LIST_OFFSET(i) + 4);
685 row2 = REG_RD(bp, BAR_USTRORM_INTMEM +
686 USTORM_ASSERT_LIST_OFFSET(i) + 8);
687 row3 = REG_RD(bp, BAR_USTRORM_INTMEM +
688 USTORM_ASSERT_LIST_OFFSET(i) + 12);
690 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
691 BNX2X_ERR("USTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
692 i, row3, row2, row1, row0);
702 void bnx2x_fw_dump_lvl(struct bnx2x *bp, const char *lvl)
708 u32 trace_shmem_base;
710 BNX2X_ERR("NO MCP - can not dump\n");
713 netdev_printk(lvl, bp->dev, "bc %d.%d.%d\n",
714 (bp->common.bc_ver & 0xff0000) >> 16,
715 (bp->common.bc_ver & 0xff00) >> 8,
716 (bp->common.bc_ver & 0xff));
718 val = REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER);
719 if (val == REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER))
720 BNX2X_ERR("%s" "MCP PC at 0x%x\n", lvl, val);
722 if (BP_PATH(bp) == 0)
723 trace_shmem_base = bp->common.shmem_base;
725 trace_shmem_base = SHMEM2_RD(bp, other_shmem_base_addr);
726 addr = trace_shmem_base - 0x800;
728 /* validate TRCB signature */
729 mark = REG_RD(bp, addr);
730 if (mark != MFW_TRACE_SIGNATURE) {
731 BNX2X_ERR("Trace buffer signature is missing.");
735 /* read cyclic buffer pointer */
737 mark = REG_RD(bp, addr);
738 mark = (CHIP_IS_E1x(bp) ? MCP_REG_MCPR_SCRATCH : MCP_A_REG_MCPR_SCRATCH)
739 + ((mark + 0x3) & ~0x3) - 0x08000000;
740 printk("%s" "begin fw dump (mark 0x%x)\n", lvl, mark);
743 for (offset = mark; offset <= trace_shmem_base; offset += 0x8*4) {
744 for (word = 0; word < 8; word++)
745 data[word] = htonl(REG_RD(bp, offset + 4*word));
747 pr_cont("%s", (char *)data);
749 for (offset = addr + 4; offset <= mark; offset += 0x8*4) {
750 for (word = 0; word < 8; word++)
751 data[word] = htonl(REG_RD(bp, offset + 4*word));
753 pr_cont("%s", (char *)data);
755 printk("%s" "end of fw dump\n", lvl);
758 static inline void bnx2x_fw_dump(struct bnx2x *bp)
760 bnx2x_fw_dump_lvl(bp, KERN_ERR);
763 void bnx2x_panic_dump(struct bnx2x *bp)
767 struct hc_sp_status_block_data sp_sb_data;
768 int func = BP_FUNC(bp);
769 #ifdef BNX2X_STOP_ON_ERROR
770 u16 start = 0, end = 0;
774 bp->stats_state = STATS_STATE_DISABLED;
775 bp->eth_stats.unrecoverable_error++;
776 DP(BNX2X_MSG_STATS, "stats_state - DISABLED\n");
778 BNX2X_ERR("begin crash dump -----------------\n");
782 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",
783 bp->def_idx, bp->def_att_idx, bp->attn_state,
784 bp->spq_prod_idx, bp->stats_counter);
785 BNX2X_ERR("DSB: attn bits(0x%x) ack(0x%x) id(0x%x) idx(0x%x)\n",
786 bp->def_status_blk->atten_status_block.attn_bits,
787 bp->def_status_blk->atten_status_block.attn_bits_ack,
788 bp->def_status_blk->atten_status_block.status_block_id,
789 bp->def_status_blk->atten_status_block.attn_bits_index);
791 for (i = 0; i < HC_SP_SB_MAX_INDICES; i++)
793 bp->def_status_blk->sp_sb.index_values[i],
794 (i == HC_SP_SB_MAX_INDICES - 1) ? ") " : " ");
796 for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
797 *((u32 *)&sp_sb_data + i) = REG_RD(bp, BAR_CSTRORM_INTMEM +
798 CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
801 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",
802 sp_sb_data.igu_sb_id,
803 sp_sb_data.igu_seg_id,
804 sp_sb_data.p_func.pf_id,
805 sp_sb_data.p_func.vnic_id,
806 sp_sb_data.p_func.vf_id,
807 sp_sb_data.p_func.vf_valid,
811 for_each_eth_queue(bp, i) {
812 struct bnx2x_fastpath *fp = &bp->fp[i];
814 struct hc_status_block_data_e2 sb_data_e2;
815 struct hc_status_block_data_e1x sb_data_e1x;
816 struct hc_status_block_sm *hc_sm_p =
818 sb_data_e1x.common.state_machine :
819 sb_data_e2.common.state_machine;
820 struct hc_index_data *hc_index_p =
822 sb_data_e1x.index_data :
823 sb_data_e2.index_data;
826 struct bnx2x_fp_txdata txdata;
829 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",
830 i, fp->rx_bd_prod, fp->rx_bd_cons,
832 fp->rx_comp_cons, le16_to_cpu(*fp->rx_cons_sb));
833 BNX2X_ERR(" rx_sge_prod(0x%x) last_max_sge(0x%x) fp_hc_idx(0x%x)\n",
834 fp->rx_sge_prod, fp->last_max_sge,
835 le16_to_cpu(fp->fp_hc_idx));
838 for_each_cos_in_tx_queue(fp, cos)
840 txdata = fp->txdata[cos];
841 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",
842 i, txdata.tx_pkt_prod,
843 txdata.tx_pkt_cons, txdata.tx_bd_prod,
845 le16_to_cpu(*txdata.tx_cons_sb));
848 loop = CHIP_IS_E1x(bp) ?
849 HC_SB_MAX_INDICES_E1X : HC_SB_MAX_INDICES_E2;
857 BNX2X_ERR(" run indexes (");
858 for (j = 0; j < HC_SB_MAX_SM; j++)
860 fp->sb_running_index[j],
861 (j == HC_SB_MAX_SM - 1) ? ")" : " ");
863 BNX2X_ERR(" indexes (");
864 for (j = 0; j < loop; j++)
866 fp->sb_index_values[j],
867 (j == loop - 1) ? ")" : " ");
869 data_size = CHIP_IS_E1x(bp) ?
870 sizeof(struct hc_status_block_data_e1x) :
871 sizeof(struct hc_status_block_data_e2);
872 data_size /= sizeof(u32);
873 sb_data_p = CHIP_IS_E1x(bp) ?
874 (u32 *)&sb_data_e1x :
876 /* copy sb data in here */
877 for (j = 0; j < data_size; j++)
878 *(sb_data_p + j) = REG_RD(bp, BAR_CSTRORM_INTMEM +
879 CSTORM_STATUS_BLOCK_DATA_OFFSET(fp->fw_sb_id) +
882 if (!CHIP_IS_E1x(bp)) {
883 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",
884 sb_data_e2.common.p_func.pf_id,
885 sb_data_e2.common.p_func.vf_id,
886 sb_data_e2.common.p_func.vf_valid,
887 sb_data_e2.common.p_func.vnic_id,
888 sb_data_e2.common.same_igu_sb_1b,
889 sb_data_e2.common.state);
891 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",
892 sb_data_e1x.common.p_func.pf_id,
893 sb_data_e1x.common.p_func.vf_id,
894 sb_data_e1x.common.p_func.vf_valid,
895 sb_data_e1x.common.p_func.vnic_id,
896 sb_data_e1x.common.same_igu_sb_1b,
897 sb_data_e1x.common.state);
901 for (j = 0; j < HC_SB_MAX_SM; j++) {
902 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",
903 j, hc_sm_p[j].__flags,
904 hc_sm_p[j].igu_sb_id,
905 hc_sm_p[j].igu_seg_id,
906 hc_sm_p[j].time_to_expire,
907 hc_sm_p[j].timer_value);
911 for (j = 0; j < loop; j++) {
912 pr_cont("INDEX[%d] flags (0x%x) timeout (0x%x)\n", j,
914 hc_index_p[j].timeout);
918 #ifdef BNX2X_STOP_ON_ERROR
921 for_each_rx_queue(bp, i) {
922 struct bnx2x_fastpath *fp = &bp->fp[i];
924 start = RX_BD(le16_to_cpu(*fp->rx_cons_sb) - 10);
925 end = RX_BD(le16_to_cpu(*fp->rx_cons_sb) + 503);
926 for (j = start; j != end; j = RX_BD(j + 1)) {
927 u32 *rx_bd = (u32 *)&fp->rx_desc_ring[j];
928 struct sw_rx_bd *sw_bd = &fp->rx_buf_ring[j];
930 BNX2X_ERR("fp%d: rx_bd[%x]=[%x:%x] sw_bd=[%p]\n",
931 i, j, rx_bd[1], rx_bd[0], sw_bd->data);
934 start = RX_SGE(fp->rx_sge_prod);
935 end = RX_SGE(fp->last_max_sge);
936 for (j = start; j != end; j = RX_SGE(j + 1)) {
937 u32 *rx_sge = (u32 *)&fp->rx_sge_ring[j];
938 struct sw_rx_page *sw_page = &fp->rx_page_ring[j];
940 BNX2X_ERR("fp%d: rx_sge[%x]=[%x:%x] sw_page=[%p]\n",
941 i, j, rx_sge[1], rx_sge[0], sw_page->page);
944 start = RCQ_BD(fp->rx_comp_cons - 10);
945 end = RCQ_BD(fp->rx_comp_cons + 503);
946 for (j = start; j != end; j = RCQ_BD(j + 1)) {
947 u32 *cqe = (u32 *)&fp->rx_comp_ring[j];
949 BNX2X_ERR("fp%d: cqe[%x]=[%x:%x:%x:%x]\n",
950 i, j, cqe[0], cqe[1], cqe[2], cqe[3]);
955 for_each_tx_queue(bp, i) {
956 struct bnx2x_fastpath *fp = &bp->fp[i];
957 for_each_cos_in_tx_queue(fp, cos) {
958 struct bnx2x_fp_txdata *txdata = &fp->txdata[cos];
960 start = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) - 10);
961 end = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) + 245);
962 for (j = start; j != end; j = TX_BD(j + 1)) {
963 struct sw_tx_bd *sw_bd =
964 &txdata->tx_buf_ring[j];
966 BNX2X_ERR("fp%d: txdata %d, packet[%x]=[%p,%x]\n",
967 i, cos, j, sw_bd->skb,
971 start = TX_BD(txdata->tx_bd_cons - 10);
972 end = TX_BD(txdata->tx_bd_cons + 254);
973 for (j = start; j != end; j = TX_BD(j + 1)) {
974 u32 *tx_bd = (u32 *)&txdata->tx_desc_ring[j];
976 BNX2X_ERR("fp%d: txdata %d, tx_bd[%x]=[%x:%x:%x:%x]\n",
977 i, cos, j, tx_bd[0], tx_bd[1],
985 BNX2X_ERR("end crash dump -----------------\n");
991 * bnx2x_pf_flr_clnup() is called during nic_load in the per function HW
994 #define FLR_WAIT_USEC 10000 /* 10 miliseconds */
995 #define FLR_WAIT_INTERVAL 50 /* usec */
996 #define FLR_POLL_CNT (FLR_WAIT_USEC/FLR_WAIT_INTERVAL) /* 200 */
998 struct pbf_pN_buf_regs {
1005 struct pbf_pN_cmd_regs {
1011 static void bnx2x_pbf_pN_buf_flushed(struct bnx2x *bp,
1012 struct pbf_pN_buf_regs *regs,
1015 u32 init_crd, crd, crd_start, crd_freed, crd_freed_start;
1016 u32 cur_cnt = poll_count;
1018 crd_freed = crd_freed_start = REG_RD(bp, regs->crd_freed);
1019 crd = crd_start = REG_RD(bp, regs->crd);
1020 init_crd = REG_RD(bp, regs->init_crd);
1022 DP(BNX2X_MSG_SP, "INIT CREDIT[%d] : %x\n", regs->pN, init_crd);
1023 DP(BNX2X_MSG_SP, "CREDIT[%d] : s:%x\n", regs->pN, crd);
1024 DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: s:%x\n", regs->pN, crd_freed);
1026 while ((crd != init_crd) && ((u32)SUB_S32(crd_freed, crd_freed_start) <
1027 (init_crd - crd_start))) {
1029 udelay(FLR_WAIT_INTERVAL);
1030 crd = REG_RD(bp, regs->crd);
1031 crd_freed = REG_RD(bp, regs->crd_freed);
1033 DP(BNX2X_MSG_SP, "PBF tx buffer[%d] timed out\n",
1035 DP(BNX2X_MSG_SP, "CREDIT[%d] : c:%x\n",
1037 DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: c:%x\n",
1038 regs->pN, crd_freed);
1042 DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF tx buffer[%d]\n",
1043 poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
1046 static void bnx2x_pbf_pN_cmd_flushed(struct bnx2x *bp,
1047 struct pbf_pN_cmd_regs *regs,
1050 u32 occup, to_free, freed, freed_start;
1051 u32 cur_cnt = poll_count;
1053 occup = to_free = REG_RD(bp, regs->lines_occup);
1054 freed = freed_start = REG_RD(bp, regs->lines_freed);
1056 DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n", regs->pN, occup);
1057 DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n", regs->pN, freed);
1059 while (occup && ((u32)SUB_S32(freed, freed_start) < to_free)) {
1061 udelay(FLR_WAIT_INTERVAL);
1062 occup = REG_RD(bp, regs->lines_occup);
1063 freed = REG_RD(bp, regs->lines_freed);
1065 DP(BNX2X_MSG_SP, "PBF cmd queue[%d] timed out\n",
1067 DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n",
1069 DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n",
1074 DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF cmd queue[%d]\n",
1075 poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
1078 static inline u32 bnx2x_flr_clnup_reg_poll(struct bnx2x *bp, u32 reg,
1079 u32 expected, u32 poll_count)
1081 u32 cur_cnt = poll_count;
1084 while ((val = REG_RD(bp, reg)) != expected && cur_cnt--)
1085 udelay(FLR_WAIT_INTERVAL);
1090 static inline int bnx2x_flr_clnup_poll_hw_counter(struct bnx2x *bp, u32 reg,
1091 char *msg, u32 poll_cnt)
1093 u32 val = bnx2x_flr_clnup_reg_poll(bp, reg, 0, poll_cnt);
1095 BNX2X_ERR("%s usage count=%d\n", msg, val);
1101 static u32 bnx2x_flr_clnup_poll_count(struct bnx2x *bp)
1103 /* adjust polling timeout */
1104 if (CHIP_REV_IS_EMUL(bp))
1105 return FLR_POLL_CNT * 2000;
1107 if (CHIP_REV_IS_FPGA(bp))
1108 return FLR_POLL_CNT * 120;
1110 return FLR_POLL_CNT;
1113 static void bnx2x_tx_hw_flushed(struct bnx2x *bp, u32 poll_count)
1115 struct pbf_pN_cmd_regs cmd_regs[] = {
1116 {0, (CHIP_IS_E3B0(bp)) ?
1117 PBF_REG_TQ_OCCUPANCY_Q0 :
1118 PBF_REG_P0_TQ_OCCUPANCY,
1119 (CHIP_IS_E3B0(bp)) ?
1120 PBF_REG_TQ_LINES_FREED_CNT_Q0 :
1121 PBF_REG_P0_TQ_LINES_FREED_CNT},
1122 {1, (CHIP_IS_E3B0(bp)) ?
1123 PBF_REG_TQ_OCCUPANCY_Q1 :
1124 PBF_REG_P1_TQ_OCCUPANCY,
1125 (CHIP_IS_E3B0(bp)) ?
1126 PBF_REG_TQ_LINES_FREED_CNT_Q1 :
1127 PBF_REG_P1_TQ_LINES_FREED_CNT},
1128 {4, (CHIP_IS_E3B0(bp)) ?
1129 PBF_REG_TQ_OCCUPANCY_LB_Q :
1130 PBF_REG_P4_TQ_OCCUPANCY,
1131 (CHIP_IS_E3B0(bp)) ?
1132 PBF_REG_TQ_LINES_FREED_CNT_LB_Q :
1133 PBF_REG_P4_TQ_LINES_FREED_CNT}
1136 struct pbf_pN_buf_regs buf_regs[] = {
1137 {0, (CHIP_IS_E3B0(bp)) ?
1138 PBF_REG_INIT_CRD_Q0 :
1139 PBF_REG_P0_INIT_CRD ,
1140 (CHIP_IS_E3B0(bp)) ?
1143 (CHIP_IS_E3B0(bp)) ?
1144 PBF_REG_INTERNAL_CRD_FREED_CNT_Q0 :
1145 PBF_REG_P0_INTERNAL_CRD_FREED_CNT},
1146 {1, (CHIP_IS_E3B0(bp)) ?
1147 PBF_REG_INIT_CRD_Q1 :
1148 PBF_REG_P1_INIT_CRD,
1149 (CHIP_IS_E3B0(bp)) ?
1152 (CHIP_IS_E3B0(bp)) ?
1153 PBF_REG_INTERNAL_CRD_FREED_CNT_Q1 :
1154 PBF_REG_P1_INTERNAL_CRD_FREED_CNT},
1155 {4, (CHIP_IS_E3B0(bp)) ?
1156 PBF_REG_INIT_CRD_LB_Q :
1157 PBF_REG_P4_INIT_CRD,
1158 (CHIP_IS_E3B0(bp)) ?
1159 PBF_REG_CREDIT_LB_Q :
1161 (CHIP_IS_E3B0(bp)) ?
1162 PBF_REG_INTERNAL_CRD_FREED_CNT_LB_Q :
1163 PBF_REG_P4_INTERNAL_CRD_FREED_CNT},
1168 /* Verify the command queues are flushed P0, P1, P4 */
1169 for (i = 0; i < ARRAY_SIZE(cmd_regs); i++)
1170 bnx2x_pbf_pN_cmd_flushed(bp, &cmd_regs[i], poll_count);
1173 /* Verify the transmission buffers are flushed P0, P1, P4 */
1174 for (i = 0; i < ARRAY_SIZE(buf_regs); i++)
1175 bnx2x_pbf_pN_buf_flushed(bp, &buf_regs[i], poll_count);
1178 #define OP_GEN_PARAM(param) \
1179 (((param) << SDM_OP_GEN_COMP_PARAM_SHIFT) & SDM_OP_GEN_COMP_PARAM)
1181 #define OP_GEN_TYPE(type) \
1182 (((type) << SDM_OP_GEN_COMP_TYPE_SHIFT) & SDM_OP_GEN_COMP_TYPE)
1184 #define OP_GEN_AGG_VECT(index) \
1185 (((index) << SDM_OP_GEN_AGG_VECT_IDX_SHIFT) & SDM_OP_GEN_AGG_VECT_IDX)
1188 static inline int bnx2x_send_final_clnup(struct bnx2x *bp, u8 clnup_func,
1191 struct sdm_op_gen op_gen = {0};
1193 u32 comp_addr = BAR_CSTRORM_INTMEM +
1194 CSTORM_FINAL_CLEANUP_COMPLETE_OFFSET(clnup_func);
1197 if (REG_RD(bp, comp_addr)) {
1198 BNX2X_ERR("Cleanup complete was not 0 before sending\n");
1202 op_gen.command |= OP_GEN_PARAM(XSTORM_AGG_INT_FINAL_CLEANUP_INDEX);
1203 op_gen.command |= OP_GEN_TYPE(XSTORM_AGG_INT_FINAL_CLEANUP_COMP_TYPE);
1204 op_gen.command |= OP_GEN_AGG_VECT(clnup_func);
1205 op_gen.command |= 1 << SDM_OP_GEN_AGG_VECT_IDX_VALID_SHIFT;
1207 DP(BNX2X_MSG_SP, "sending FW Final cleanup\n");
1208 REG_WR(bp, XSDM_REG_OPERATION_GEN, op_gen.command);
1210 if (bnx2x_flr_clnup_reg_poll(bp, comp_addr, 1, poll_cnt) != 1) {
1211 BNX2X_ERR("FW final cleanup did not succeed\n");
1212 DP(BNX2X_MSG_SP, "At timeout completion address contained %x\n",
1213 (REG_RD(bp, comp_addr)));
1216 /* Zero completion for nxt FLR */
1217 REG_WR(bp, comp_addr, 0);
1222 static inline u8 bnx2x_is_pcie_pending(struct pci_dev *dev)
1227 pos = pci_pcie_cap(dev);
1231 pci_read_config_word(dev, pos + PCI_EXP_DEVSTA, &status);
1232 return status & PCI_EXP_DEVSTA_TRPND;
1235 /* PF FLR specific routines
1237 static int bnx2x_poll_hw_usage_counters(struct bnx2x *bp, u32 poll_cnt)
1240 /* wait for CFC PF usage-counter to zero (includes all the VFs) */
1241 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1242 CFC_REG_NUM_LCIDS_INSIDE_PF,
1243 "CFC PF usage counter timed out",
1248 /* Wait for DQ PF usage-counter to zero (until DQ cleanup) */
1249 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1250 DORQ_REG_PF_USAGE_CNT,
1251 "DQ PF usage counter timed out",
1255 /* Wait for QM PF usage-counter to zero (until DQ cleanup) */
1256 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1257 QM_REG_PF_USG_CNT_0 + 4*BP_FUNC(bp),
1258 "QM PF usage counter timed out",
1262 /* Wait for Timer PF usage-counters to zero (until DQ cleanup) */
1263 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1264 TM_REG_LIN0_VNIC_UC + 4*BP_PORT(bp),
1265 "Timers VNIC usage counter timed out",
1268 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1269 TM_REG_LIN0_NUM_SCANS + 4*BP_PORT(bp),
1270 "Timers NUM_SCANS usage counter timed out",
1274 /* Wait DMAE PF usage counter to zero */
1275 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1276 dmae_reg_go_c[INIT_DMAE_C(bp)],
1277 "DMAE dommand register timed out",
1284 static void bnx2x_hw_enable_status(struct bnx2x *bp)
1288 val = REG_RD(bp, CFC_REG_WEAK_ENABLE_PF);
1289 DP(BNX2X_MSG_SP, "CFC_REG_WEAK_ENABLE_PF is 0x%x\n", val);
1291 val = REG_RD(bp, PBF_REG_DISABLE_PF);
1292 DP(BNX2X_MSG_SP, "PBF_REG_DISABLE_PF is 0x%x\n", val);
1294 val = REG_RD(bp, IGU_REG_PCI_PF_MSI_EN);
1295 DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSI_EN is 0x%x\n", val);
1297 val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_EN);
1298 DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_EN is 0x%x\n", val);
1300 val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_FUNC_MASK);
1301 DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_FUNC_MASK is 0x%x\n", val);
1303 val = REG_RD(bp, PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR);
1304 DP(BNX2X_MSG_SP, "PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR is 0x%x\n", val);
1306 val = REG_RD(bp, PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR);
1307 DP(BNX2X_MSG_SP, "PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR is 0x%x\n", val);
1309 val = REG_RD(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER);
1310 DP(BNX2X_MSG_SP, "PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER is 0x%x\n",
1314 static int bnx2x_pf_flr_clnup(struct bnx2x *bp)
1316 u32 poll_cnt = bnx2x_flr_clnup_poll_count(bp);
1318 DP(BNX2X_MSG_SP, "Cleanup after FLR PF[%d]\n", BP_ABS_FUNC(bp));
1320 /* Re-enable PF target read access */
1321 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
1323 /* Poll HW usage counters */
1324 DP(BNX2X_MSG_SP, "Polling usage counters\n");
1325 if (bnx2x_poll_hw_usage_counters(bp, poll_cnt))
1328 /* Zero the igu 'trailing edge' and 'leading edge' */
1330 /* Send the FW cleanup command */
1331 if (bnx2x_send_final_clnup(bp, (u8)BP_FUNC(bp), poll_cnt))
1336 /* Verify TX hw is flushed */
1337 bnx2x_tx_hw_flushed(bp, poll_cnt);
1339 /* Wait 100ms (not adjusted according to platform) */
1342 /* Verify no pending pci transactions */
1343 if (bnx2x_is_pcie_pending(bp->pdev))
1344 BNX2X_ERR("PCIE Transactions still pending\n");
1347 bnx2x_hw_enable_status(bp);
1350 * Master enable - Due to WB DMAE writes performed before this
1351 * register is re-initialized as part of the regular function init
1353 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
1358 static void bnx2x_hc_int_enable(struct bnx2x *bp)
1360 int port = BP_PORT(bp);
1361 u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
1362 u32 val = REG_RD(bp, addr);
1363 int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
1364 int msi = (bp->flags & USING_MSI_FLAG) ? 1 : 0;
1367 val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
1368 HC_CONFIG_0_REG_INT_LINE_EN_0);
1369 val |= (HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
1370 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
1372 val &= ~HC_CONFIG_0_REG_INT_LINE_EN_0;
1373 val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
1374 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
1375 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
1377 val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
1378 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
1379 HC_CONFIG_0_REG_INT_LINE_EN_0 |
1380 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
1382 if (!CHIP_IS_E1(bp)) {
1384 "write %x to HC %d (addr 0x%x)\n", val, port, addr);
1386 REG_WR(bp, addr, val);
1388 val &= ~HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0;
1393 REG_WR(bp, HC_REG_INT_MASK + port*4, 0x1FFFF);
1396 "write %x to HC %d (addr 0x%x) mode %s\n", val, port, addr,
1397 (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
1399 REG_WR(bp, addr, val);
1401 * Ensure that HC_CONFIG is written before leading/trailing edge config
1406 if (!CHIP_IS_E1(bp)) {
1407 /* init leading/trailing edge */
1409 val = (0xee0f | (1 << (BP_VN(bp) + 4)));
1411 /* enable nig and gpio3 attention */
1416 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
1417 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
1420 /* Make sure that interrupts are indeed enabled from here on */
1424 static void bnx2x_igu_int_enable(struct bnx2x *bp)
1427 int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
1428 int msi = (bp->flags & USING_MSI_FLAG) ? 1 : 0;
1430 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
1433 val &= ~(IGU_PF_CONF_INT_LINE_EN |
1434 IGU_PF_CONF_SINGLE_ISR_EN);
1435 val |= (IGU_PF_CONF_FUNC_EN |
1436 IGU_PF_CONF_MSI_MSIX_EN |
1437 IGU_PF_CONF_ATTN_BIT_EN);
1439 val &= ~IGU_PF_CONF_INT_LINE_EN;
1440 val |= (IGU_PF_CONF_FUNC_EN |
1441 IGU_PF_CONF_MSI_MSIX_EN |
1442 IGU_PF_CONF_ATTN_BIT_EN |
1443 IGU_PF_CONF_SINGLE_ISR_EN);
1445 val &= ~IGU_PF_CONF_MSI_MSIX_EN;
1446 val |= (IGU_PF_CONF_FUNC_EN |
1447 IGU_PF_CONF_INT_LINE_EN |
1448 IGU_PF_CONF_ATTN_BIT_EN |
1449 IGU_PF_CONF_SINGLE_ISR_EN);
1452 DP(NETIF_MSG_IFUP, "write 0x%x to IGU mode %s\n",
1453 val, (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
1455 REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
1459 /* init leading/trailing edge */
1461 val = (0xee0f | (1 << (BP_VN(bp) + 4)));
1463 /* enable nig and gpio3 attention */
1468 REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
1469 REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
1471 /* Make sure that interrupts are indeed enabled from here on */
1475 void bnx2x_int_enable(struct bnx2x *bp)
1477 if (bp->common.int_block == INT_BLOCK_HC)
1478 bnx2x_hc_int_enable(bp);
1480 bnx2x_igu_int_enable(bp);
1483 static void bnx2x_hc_int_disable(struct bnx2x *bp)
1485 int port = BP_PORT(bp);
1486 u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
1487 u32 val = REG_RD(bp, addr);
1490 * in E1 we must use only PCI configuration space to disable
1491 * MSI/MSIX capablility
1492 * It's forbitten to disable IGU_PF_CONF_MSI_MSIX_EN in HC block
1494 if (CHIP_IS_E1(bp)) {
1495 /* Since IGU_PF_CONF_MSI_MSIX_EN still always on
1496 * Use mask register to prevent from HC sending interrupts
1497 * after we exit the function
1499 REG_WR(bp, HC_REG_INT_MASK + port*4, 0);
1501 val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
1502 HC_CONFIG_0_REG_INT_LINE_EN_0 |
1503 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
1505 val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
1506 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
1507 HC_CONFIG_0_REG_INT_LINE_EN_0 |
1508 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
1510 DP(NETIF_MSG_IFDOWN,
1511 "write %x to HC %d (addr 0x%x)\n",
1514 /* flush all outstanding writes */
1517 REG_WR(bp, addr, val);
1518 if (REG_RD(bp, addr) != val)
1519 BNX2X_ERR("BUG! proper val not read from IGU!\n");
1522 static void bnx2x_igu_int_disable(struct bnx2x *bp)
1524 u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
1526 val &= ~(IGU_PF_CONF_MSI_MSIX_EN |
1527 IGU_PF_CONF_INT_LINE_EN |
1528 IGU_PF_CONF_ATTN_BIT_EN);
1530 DP(NETIF_MSG_IFDOWN, "write %x to IGU\n", val);
1532 /* flush all outstanding writes */
1535 REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
1536 if (REG_RD(bp, IGU_REG_PF_CONFIGURATION) != val)
1537 BNX2X_ERR("BUG! proper val not read from IGU!\n");
1540 void bnx2x_int_disable(struct bnx2x *bp)
1542 if (bp->common.int_block == INT_BLOCK_HC)
1543 bnx2x_hc_int_disable(bp);
1545 bnx2x_igu_int_disable(bp);
1548 void bnx2x_int_disable_sync(struct bnx2x *bp, int disable_hw)
1550 int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
1554 /* prevent the HW from sending interrupts */
1555 bnx2x_int_disable(bp);
1557 /* make sure all ISRs are done */
1559 synchronize_irq(bp->msix_table[0].vector);
1564 for_each_eth_queue(bp, i)
1565 synchronize_irq(bp->msix_table[offset++].vector);
1567 synchronize_irq(bp->pdev->irq);
1569 /* make sure sp_task is not running */
1570 cancel_delayed_work(&bp->sp_task);
1571 cancel_delayed_work(&bp->period_task);
1572 flush_workqueue(bnx2x_wq);
1578 * General service functions
1581 /* Return true if succeeded to acquire the lock */
1582 static bool bnx2x_trylock_hw_lock(struct bnx2x *bp, u32 resource)
1585 u32 resource_bit = (1 << resource);
1586 int func = BP_FUNC(bp);
1587 u32 hw_lock_control_reg;
1589 DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
1590 "Trying to take a lock on resource %d\n", resource);
1592 /* Validating that the resource is within range */
1593 if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
1594 DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
1595 "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
1596 resource, HW_LOCK_MAX_RESOURCE_VALUE);
1601 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
1603 hw_lock_control_reg =
1604 (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
1606 /* Try to acquire the lock */
1607 REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
1608 lock_status = REG_RD(bp, hw_lock_control_reg);
1609 if (lock_status & resource_bit)
1612 DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
1613 "Failed to get a lock on resource %d\n", resource);
1618 * bnx2x_get_leader_lock_resource - get the recovery leader resource id
1620 * @bp: driver handle
1622 * Returns the recovery leader resource id according to the engine this function
1623 * belongs to. Currently only only 2 engines is supported.
1625 static inline int bnx2x_get_leader_lock_resource(struct bnx2x *bp)
1628 return HW_LOCK_RESOURCE_RECOVERY_LEADER_1;
1630 return HW_LOCK_RESOURCE_RECOVERY_LEADER_0;
1634 * bnx2x_trylock_leader_lock- try to aquire a leader lock.
1636 * @bp: driver handle
1638 * Tries to aquire a leader lock for cuurent engine.
1640 static inline bool bnx2x_trylock_leader_lock(struct bnx2x *bp)
1642 return bnx2x_trylock_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
1646 static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err);
1649 void bnx2x_sp_event(struct bnx2x_fastpath *fp, union eth_rx_cqe *rr_cqe)
1651 struct bnx2x *bp = fp->bp;
1652 int cid = SW_CID(rr_cqe->ramrod_cqe.conn_and_cmd_data);
1653 int command = CQE_CMD(rr_cqe->ramrod_cqe.conn_and_cmd_data);
1654 enum bnx2x_queue_cmd drv_cmd = BNX2X_Q_CMD_MAX;
1655 struct bnx2x_queue_sp_obj *q_obj = &fp->q_obj;
1658 "fp %d cid %d got ramrod #%d state is %x type is %d\n",
1659 fp->index, cid, command, bp->state,
1660 rr_cqe->ramrod_cqe.ramrod_type);
1663 case (RAMROD_CMD_ID_ETH_CLIENT_UPDATE):
1664 DP(BNX2X_MSG_SP, "got UPDATE ramrod. CID %d\n", cid);
1665 drv_cmd = BNX2X_Q_CMD_UPDATE;
1668 case (RAMROD_CMD_ID_ETH_CLIENT_SETUP):
1669 DP(BNX2X_MSG_SP, "got MULTI[%d] setup ramrod\n", cid);
1670 drv_cmd = BNX2X_Q_CMD_SETUP;
1673 case (RAMROD_CMD_ID_ETH_TX_QUEUE_SETUP):
1674 DP(BNX2X_MSG_SP, "got MULTI[%d] tx-only setup ramrod\n", cid);
1675 drv_cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
1678 case (RAMROD_CMD_ID_ETH_HALT):
1679 DP(BNX2X_MSG_SP, "got MULTI[%d] halt ramrod\n", cid);
1680 drv_cmd = BNX2X_Q_CMD_HALT;
1683 case (RAMROD_CMD_ID_ETH_TERMINATE):
1684 DP(BNX2X_MSG_SP, "got MULTI[%d] teminate ramrod\n", cid);
1685 drv_cmd = BNX2X_Q_CMD_TERMINATE;
1688 case (RAMROD_CMD_ID_ETH_EMPTY):
1689 DP(BNX2X_MSG_SP, "got MULTI[%d] empty ramrod\n", cid);
1690 drv_cmd = BNX2X_Q_CMD_EMPTY;
1694 BNX2X_ERR("unexpected MC reply (%d) on fp[%d]\n",
1695 command, fp->index);
1699 if ((drv_cmd != BNX2X_Q_CMD_MAX) &&
1700 q_obj->complete_cmd(bp, q_obj, drv_cmd))
1701 /* q_obj->complete_cmd() failure means that this was
1702 * an unexpected completion.
1704 * In this case we don't want to increase the bp->spq_left
1705 * because apparently we haven't sent this command the first
1708 #ifdef BNX2X_STOP_ON_ERROR
1714 smp_mb__before_atomic_inc();
1715 atomic_inc(&bp->cq_spq_left);
1716 /* push the change in bp->spq_left and towards the memory */
1717 smp_mb__after_atomic_inc();
1719 DP(BNX2X_MSG_SP, "bp->cq_spq_left %x\n", atomic_read(&bp->cq_spq_left));
1724 void bnx2x_update_rx_prod(struct bnx2x *bp, struct bnx2x_fastpath *fp,
1725 u16 bd_prod, u16 rx_comp_prod, u16 rx_sge_prod)
1727 u32 start = BAR_USTRORM_INTMEM + fp->ustorm_rx_prods_offset;
1729 bnx2x_update_rx_prod_gen(bp, fp, bd_prod, rx_comp_prod, rx_sge_prod,
1733 irqreturn_t bnx2x_interrupt(int irq, void *dev_instance)
1735 struct bnx2x *bp = netdev_priv(dev_instance);
1736 u16 status = bnx2x_ack_int(bp);
1741 /* Return here if interrupt is shared and it's not for us */
1742 if (unlikely(status == 0)) {
1743 DP(NETIF_MSG_INTR, "not our interrupt!\n");
1746 DP(NETIF_MSG_INTR, "got an interrupt status 0x%x\n", status);
1748 #ifdef BNX2X_STOP_ON_ERROR
1749 if (unlikely(bp->panic))
1753 for_each_eth_queue(bp, i) {
1754 struct bnx2x_fastpath *fp = &bp->fp[i];
1756 mask = 0x2 << (fp->index + CNIC_PRESENT);
1757 if (status & mask) {
1758 /* Handle Rx or Tx according to SB id */
1759 prefetch(fp->rx_cons_sb);
1760 for_each_cos_in_tx_queue(fp, cos)
1761 prefetch(fp->txdata[cos].tx_cons_sb);
1762 prefetch(&fp->sb_running_index[SM_RX_ID]);
1763 napi_schedule(&bnx2x_fp(bp, fp->index, napi));
1770 if (status & (mask | 0x1)) {
1771 struct cnic_ops *c_ops = NULL;
1773 if (likely(bp->state == BNX2X_STATE_OPEN)) {
1775 c_ops = rcu_dereference(bp->cnic_ops);
1777 c_ops->cnic_handler(bp->cnic_data, NULL);
1785 if (unlikely(status & 0x1)) {
1786 queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
1793 if (unlikely(status))
1794 DP(NETIF_MSG_INTR, "got an unknown interrupt! (status 0x%x)\n",
1803 * General service functions
1806 int bnx2x_acquire_hw_lock(struct bnx2x *bp, u32 resource)
1809 u32 resource_bit = (1 << resource);
1810 int func = BP_FUNC(bp);
1811 u32 hw_lock_control_reg;
1814 /* Validating that the resource is within range */
1815 if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
1816 BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
1817 resource, HW_LOCK_MAX_RESOURCE_VALUE);
1822 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
1824 hw_lock_control_reg =
1825 (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
1828 /* Validating that the resource is not already taken */
1829 lock_status = REG_RD(bp, hw_lock_control_reg);
1830 if (lock_status & resource_bit) {
1831 BNX2X_ERR("lock_status 0x%x resource_bit 0x%x\n",
1832 lock_status, resource_bit);
1836 /* Try for 5 second every 5ms */
1837 for (cnt = 0; cnt < 1000; cnt++) {
1838 /* Try to acquire the lock */
1839 REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
1840 lock_status = REG_RD(bp, hw_lock_control_reg);
1841 if (lock_status & resource_bit)
1846 BNX2X_ERR("Timeout\n");
1850 int bnx2x_release_leader_lock(struct bnx2x *bp)
1852 return bnx2x_release_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
1855 int bnx2x_release_hw_lock(struct bnx2x *bp, u32 resource)
1858 u32 resource_bit = (1 << resource);
1859 int func = BP_FUNC(bp);
1860 u32 hw_lock_control_reg;
1862 /* Validating that the resource is within range */
1863 if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
1864 BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
1865 resource, HW_LOCK_MAX_RESOURCE_VALUE);
1870 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
1872 hw_lock_control_reg =
1873 (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
1876 /* Validating that the resource is currently taken */
1877 lock_status = REG_RD(bp, hw_lock_control_reg);
1878 if (!(lock_status & resource_bit)) {
1879 BNX2X_ERR("lock_status 0x%x resource_bit 0x%x. unlock was called but lock wasn't taken!\n",
1880 lock_status, resource_bit);
1884 REG_WR(bp, hw_lock_control_reg, resource_bit);
1889 int bnx2x_get_gpio(struct bnx2x *bp, int gpio_num, u8 port)
1891 /* The GPIO should be swapped if swap register is set and active */
1892 int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
1893 REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
1894 int gpio_shift = gpio_num +
1895 (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
1896 u32 gpio_mask = (1 << gpio_shift);
1900 if (gpio_num > MISC_REGISTERS_GPIO_3) {
1901 BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
1905 /* read GPIO value */
1906 gpio_reg = REG_RD(bp, MISC_REG_GPIO);
1908 /* get the requested pin value */
1909 if ((gpio_reg & gpio_mask) == gpio_mask)
1914 DP(NETIF_MSG_LINK, "pin %d value 0x%x\n", gpio_num, value);
1919 int bnx2x_set_gpio(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
1921 /* The GPIO should be swapped if swap register is set and active */
1922 int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
1923 REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
1924 int gpio_shift = gpio_num +
1925 (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
1926 u32 gpio_mask = (1 << gpio_shift);
1929 if (gpio_num > MISC_REGISTERS_GPIO_3) {
1930 BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
1934 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
1935 /* read GPIO and mask except the float bits */
1936 gpio_reg = (REG_RD(bp, MISC_REG_GPIO) & MISC_REGISTERS_GPIO_FLOAT);
1939 case MISC_REGISTERS_GPIO_OUTPUT_LOW:
1941 "Set GPIO %d (shift %d) -> output low\n",
1942 gpio_num, gpio_shift);
1943 /* clear FLOAT and set CLR */
1944 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
1945 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_CLR_POS);
1948 case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
1950 "Set GPIO %d (shift %d) -> output high\n",
1951 gpio_num, gpio_shift);
1952 /* clear FLOAT and set SET */
1953 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
1954 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_SET_POS);
1957 case MISC_REGISTERS_GPIO_INPUT_HI_Z:
1959 "Set GPIO %d (shift %d) -> input\n",
1960 gpio_num, gpio_shift);
1962 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
1969 REG_WR(bp, MISC_REG_GPIO, gpio_reg);
1970 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
1975 int bnx2x_set_mult_gpio(struct bnx2x *bp, u8 pins, u32 mode)
1980 /* Any port swapping should be handled by caller. */
1982 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
1983 /* read GPIO and mask except the float bits */
1984 gpio_reg = REG_RD(bp, MISC_REG_GPIO);
1985 gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_FLOAT_POS);
1986 gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_CLR_POS);
1987 gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_SET_POS);
1990 case MISC_REGISTERS_GPIO_OUTPUT_LOW:
1991 DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output low\n", pins);
1993 gpio_reg |= (pins << MISC_REGISTERS_GPIO_CLR_POS);
1996 case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
1997 DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output high\n", pins);
1999 gpio_reg |= (pins << MISC_REGISTERS_GPIO_SET_POS);
2002 case MISC_REGISTERS_GPIO_INPUT_HI_Z:
2003 DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> input\n", pins);
2005 gpio_reg |= (pins << MISC_REGISTERS_GPIO_FLOAT_POS);
2009 BNX2X_ERR("Invalid GPIO mode assignment %d\n", mode);
2015 REG_WR(bp, MISC_REG_GPIO, gpio_reg);
2017 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
2022 int bnx2x_set_gpio_int(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
2024 /* The GPIO should be swapped if swap register is set and active */
2025 int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
2026 REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
2027 int gpio_shift = gpio_num +
2028 (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
2029 u32 gpio_mask = (1 << gpio_shift);
2032 if (gpio_num > MISC_REGISTERS_GPIO_3) {
2033 BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
2037 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
2039 gpio_reg = REG_RD(bp, MISC_REG_GPIO_INT);
2042 case MISC_REGISTERS_GPIO_INT_OUTPUT_CLR:
2044 "Clear GPIO INT %d (shift %d) -> output low\n",
2045 gpio_num, gpio_shift);
2046 /* clear SET and set CLR */
2047 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
2048 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
2051 case MISC_REGISTERS_GPIO_INT_OUTPUT_SET:
2053 "Set GPIO INT %d (shift %d) -> output high\n",
2054 gpio_num, gpio_shift);
2055 /* clear CLR and set SET */
2056 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
2057 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
2064 REG_WR(bp, MISC_REG_GPIO_INT, gpio_reg);
2065 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
2070 static int bnx2x_set_spio(struct bnx2x *bp, int spio_num, u32 mode)
2072 u32 spio_mask = (1 << spio_num);
2075 if ((spio_num < MISC_REGISTERS_SPIO_4) ||
2076 (spio_num > MISC_REGISTERS_SPIO_7)) {
2077 BNX2X_ERR("Invalid SPIO %d\n", spio_num);
2081 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
2082 /* read SPIO and mask except the float bits */
2083 spio_reg = (REG_RD(bp, MISC_REG_SPIO) & MISC_REGISTERS_SPIO_FLOAT);
2086 case MISC_REGISTERS_SPIO_OUTPUT_LOW:
2087 DP(NETIF_MSG_HW, "Set SPIO %d -> output low\n", spio_num);
2088 /* clear FLOAT and set CLR */
2089 spio_reg &= ~(spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS);
2090 spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_CLR_POS);
2093 case MISC_REGISTERS_SPIO_OUTPUT_HIGH:
2094 DP(NETIF_MSG_HW, "Set SPIO %d -> output high\n", spio_num);
2095 /* clear FLOAT and set SET */
2096 spio_reg &= ~(spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS);
2097 spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_SET_POS);
2100 case MISC_REGISTERS_SPIO_INPUT_HI_Z:
2101 DP(NETIF_MSG_HW, "Set SPIO %d -> input\n", spio_num);
2103 spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS);
2110 REG_WR(bp, MISC_REG_SPIO, spio_reg);
2111 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
2116 void bnx2x_calc_fc_adv(struct bnx2x *bp)
2118 u8 cfg_idx = bnx2x_get_link_cfg_idx(bp);
2119 switch (bp->link_vars.ieee_fc &
2120 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK) {
2121 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE:
2122 bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
2126 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH:
2127 bp->port.advertising[cfg_idx] |= (ADVERTISED_Asym_Pause |
2131 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC:
2132 bp->port.advertising[cfg_idx] |= ADVERTISED_Asym_Pause;
2136 bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
2142 u8 bnx2x_initial_phy_init(struct bnx2x *bp, int load_mode)
2144 if (!BP_NOMCP(bp)) {
2146 int cfx_idx = bnx2x_get_link_cfg_idx(bp);
2147 u16 req_line_speed = bp->link_params.req_line_speed[cfx_idx];
2149 * Initialize link parameters structure variables
2150 * It is recommended to turn off RX FC for jumbo frames
2151 * for better performance
2153 if (CHIP_IS_E1x(bp) && (bp->dev->mtu > 5000))
2154 bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_TX;
2156 bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_BOTH;
2158 bnx2x_acquire_phy_lock(bp);
2160 if (load_mode == LOAD_DIAG) {
2161 struct link_params *lp = &bp->link_params;
2162 lp->loopback_mode = LOOPBACK_XGXS;
2163 /* do PHY loopback at 10G speed, if possible */
2164 if (lp->req_line_speed[cfx_idx] < SPEED_10000) {
2165 if (lp->speed_cap_mask[cfx_idx] &
2166 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
2167 lp->req_line_speed[cfx_idx] =
2170 lp->req_line_speed[cfx_idx] =
2175 rc = bnx2x_phy_init(&bp->link_params, &bp->link_vars);
2177 bnx2x_release_phy_lock(bp);
2179 bnx2x_calc_fc_adv(bp);
2181 if (CHIP_REV_IS_SLOW(bp) && bp->link_vars.link_up) {
2182 bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
2183 bnx2x_link_report(bp);
2185 queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
2186 bp->link_params.req_line_speed[cfx_idx] = req_line_speed;
2189 BNX2X_ERR("Bootcode is missing - can not initialize link\n");
2193 void bnx2x_link_set(struct bnx2x *bp)
2195 if (!BP_NOMCP(bp)) {
2196 bnx2x_acquire_phy_lock(bp);
2197 bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
2198 bnx2x_phy_init(&bp->link_params, &bp->link_vars);
2199 bnx2x_release_phy_lock(bp);
2201 bnx2x_calc_fc_adv(bp);
2203 BNX2X_ERR("Bootcode is missing - can not set link\n");
2206 static void bnx2x__link_reset(struct bnx2x *bp)
2208 if (!BP_NOMCP(bp)) {
2209 bnx2x_acquire_phy_lock(bp);
2210 bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
2211 bnx2x_release_phy_lock(bp);
2213 BNX2X_ERR("Bootcode is missing - can not reset link\n");
2216 u8 bnx2x_link_test(struct bnx2x *bp, u8 is_serdes)
2220 if (!BP_NOMCP(bp)) {
2221 bnx2x_acquire_phy_lock(bp);
2222 rc = bnx2x_test_link(&bp->link_params, &bp->link_vars,
2224 bnx2x_release_phy_lock(bp);
2226 BNX2X_ERR("Bootcode is missing - can not test link\n");
2231 static void bnx2x_init_port_minmax(struct bnx2x *bp)
2233 u32 r_param = bp->link_vars.line_speed / 8;
2234 u32 fair_periodic_timeout_usec;
2237 memset(&(bp->cmng.rs_vars), 0,
2238 sizeof(struct rate_shaping_vars_per_port));
2239 memset(&(bp->cmng.fair_vars), 0, sizeof(struct fairness_vars_per_port));
2241 /* 100 usec in SDM ticks = 25 since each tick is 4 usec */
2242 bp->cmng.rs_vars.rs_periodic_timeout = RS_PERIODIC_TIMEOUT_USEC / 4;
2244 /* this is the threshold below which no timer arming will occur
2245 1.25 coefficient is for the threshold to be a little bigger
2246 than the real time, to compensate for timer in-accuracy */
2247 bp->cmng.rs_vars.rs_threshold =
2248 (RS_PERIODIC_TIMEOUT_USEC * r_param * 5) / 4;
2250 /* resolution of fairness timer */
2251 fair_periodic_timeout_usec = QM_ARB_BYTES / r_param;
2252 /* for 10G it is 1000usec. for 1G it is 10000usec. */
2253 t_fair = T_FAIR_COEF / bp->link_vars.line_speed;
2255 /* this is the threshold below which we won't arm the timer anymore */
2256 bp->cmng.fair_vars.fair_threshold = QM_ARB_BYTES;
2258 /* we multiply by 1e3/8 to get bytes/msec.
2259 We don't want the credits to pass a credit
2260 of the t_fair*FAIR_MEM (algorithm resolution) */
2261 bp->cmng.fair_vars.upper_bound = r_param * t_fair * FAIR_MEM;
2262 /* since each tick is 4 usec */
2263 bp->cmng.fair_vars.fairness_timeout = fair_periodic_timeout_usec / 4;
2266 /* Calculates the sum of vn_min_rates.
2267 It's needed for further normalizing of the min_rates.
2269 sum of vn_min_rates.
2271 0 - if all the min_rates are 0.
2272 In the later case fainess algorithm should be deactivated.
2273 If not all min_rates are zero then those that are zeroes will be set to 1.
2275 static void bnx2x_calc_vn_weight_sum(struct bnx2x *bp)
2280 bp->vn_weight_sum = 0;
2281 for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
2282 u32 vn_cfg = bp->mf_config[vn];
2283 u32 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
2284 FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
2286 /* Skip hidden vns */
2287 if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
2290 /* If min rate is zero - set it to 1 */
2292 vn_min_rate = DEF_MIN_RATE;
2296 bp->vn_weight_sum += vn_min_rate;
2299 /* if ETS or all min rates are zeros - disable fairness */
2300 if (BNX2X_IS_ETS_ENABLED(bp)) {
2301 bp->cmng.flags.cmng_enables &=
2302 ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
2303 DP(NETIF_MSG_IFUP, "Fairness will be disabled due to ETS\n");
2304 } else if (all_zero) {
2305 bp->cmng.flags.cmng_enables &=
2306 ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
2307 DP(NETIF_MSG_IFUP, "All MIN values are zeroes"
2308 " fairness will be disabled\n");
2310 bp->cmng.flags.cmng_enables |=
2311 CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
2314 static void bnx2x_init_vn_minmax(struct bnx2x *bp, int vn)
2316 struct rate_shaping_vars_per_vn m_rs_vn;
2317 struct fairness_vars_per_vn m_fair_vn;
2318 u32 vn_cfg = bp->mf_config[vn];
2319 int func = func_by_vn(bp, vn);
2320 u16 vn_min_rate, vn_max_rate;
2323 /* If function is hidden - set min and max to zeroes */
2324 if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE) {
2329 u32 maxCfg = bnx2x_extract_max_cfg(bp, vn_cfg);
2331 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
2332 FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
2333 /* If fairness is enabled (not all min rates are zeroes) and
2334 if current min rate is zero - set it to 1.
2335 This is a requirement of the algorithm. */
2336 if (bp->vn_weight_sum && (vn_min_rate == 0))
2337 vn_min_rate = DEF_MIN_RATE;
2340 /* maxCfg in percents of linkspeed */
2341 vn_max_rate = (bp->link_vars.line_speed * maxCfg) / 100;
2343 /* maxCfg is absolute in 100Mb units */
2344 vn_max_rate = maxCfg * 100;
2348 "func %d: vn_min_rate %d vn_max_rate %d vn_weight_sum %d\n",
2349 func, vn_min_rate, vn_max_rate, bp->vn_weight_sum);
2351 memset(&m_rs_vn, 0, sizeof(struct rate_shaping_vars_per_vn));
2352 memset(&m_fair_vn, 0, sizeof(struct fairness_vars_per_vn));
2354 /* global vn counter - maximal Mbps for this vn */
2355 m_rs_vn.vn_counter.rate = vn_max_rate;
2357 /* quota - number of bytes transmitted in this period */
2358 m_rs_vn.vn_counter.quota =
2359 (vn_max_rate * RS_PERIODIC_TIMEOUT_USEC) / 8;
2361 if (bp->vn_weight_sum) {
2362 /* credit for each period of the fairness algorithm:
2363 number of bytes in T_FAIR (the vn share the port rate).
2364 vn_weight_sum should not be larger than 10000, thus
2365 T_FAIR_COEF / (8 * vn_weight_sum) will always be greater
2367 m_fair_vn.vn_credit_delta =
2368 max_t(u32, (vn_min_rate * (T_FAIR_COEF /
2369 (8 * bp->vn_weight_sum))),
2370 (bp->cmng.fair_vars.fair_threshold +
2372 DP(NETIF_MSG_IFUP, "m_fair_vn.vn_credit_delta %d\n",
2373 m_fair_vn.vn_credit_delta);
2376 /* Store it to internal memory */
2377 for (i = 0; i < sizeof(struct rate_shaping_vars_per_vn)/4; i++)
2378 REG_WR(bp, BAR_XSTRORM_INTMEM +
2379 XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(func) + i * 4,
2380 ((u32 *)(&m_rs_vn))[i]);
2382 for (i = 0; i < sizeof(struct fairness_vars_per_vn)/4; i++)
2383 REG_WR(bp, BAR_XSTRORM_INTMEM +
2384 XSTORM_FAIRNESS_PER_VN_VARS_OFFSET(func) + i * 4,
2385 ((u32 *)(&m_fair_vn))[i]);
2388 static int bnx2x_get_cmng_fns_mode(struct bnx2x *bp)
2390 if (CHIP_REV_IS_SLOW(bp))
2391 return CMNG_FNS_NONE;
2393 return CMNG_FNS_MINMAX;
2395 return CMNG_FNS_NONE;
2398 void bnx2x_read_mf_cfg(struct bnx2x *bp)
2400 int vn, n = (CHIP_MODE_IS_4_PORT(bp) ? 2 : 1);
2403 return; /* what should be the default bvalue in this case */
2405 /* For 2 port configuration the absolute function number formula
2407 * abs_func = 2 * vn + BP_PORT + BP_PATH
2409 * and there are 4 functions per port
2411 * For 4 port configuration it is
2412 * abs_func = 4 * vn + 2 * BP_PORT + BP_PATH
2414 * and there are 2 functions per port
2416 for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
2417 int /*abs*/func = n * (2 * vn + BP_PORT(bp)) + BP_PATH(bp);
2419 if (func >= E1H_FUNC_MAX)
2423 MF_CFG_RD(bp, func_mf_config[func].config);
2427 static void bnx2x_cmng_fns_init(struct bnx2x *bp, u8 read_cfg, u8 cmng_type)
2430 if (cmng_type == CMNG_FNS_MINMAX) {
2433 /* clear cmng_enables */
2434 bp->cmng.flags.cmng_enables = 0;
2436 /* read mf conf from shmem */
2438 bnx2x_read_mf_cfg(bp);
2440 /* Init rate shaping and fairness contexts */
2441 bnx2x_init_port_minmax(bp);
2443 /* vn_weight_sum and enable fairness if not 0 */
2444 bnx2x_calc_vn_weight_sum(bp);
2446 /* calculate and set min-max rate for each vn */
2448 for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++)
2449 bnx2x_init_vn_minmax(bp, vn);
2451 /* always enable rate shaping and fairness */
2452 bp->cmng.flags.cmng_enables |=
2453 CMNG_FLAGS_PER_PORT_RATE_SHAPING_VN;
2454 if (!bp->vn_weight_sum)
2455 DP(NETIF_MSG_IFUP, "All MIN values are zeroes"
2456 " fairness will be disabled\n");
2460 /* rate shaping and fairness are disabled */
2462 "rate shaping and fairness are disabled\n");
2465 /* This function is called upon link interrupt */
2466 static void bnx2x_link_attn(struct bnx2x *bp)
2468 /* Make sure that we are synced with the current statistics */
2469 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
2471 bnx2x_link_update(&bp->link_params, &bp->link_vars);
2473 if (bp->link_vars.link_up) {
2475 /* dropless flow control */
2476 if (!CHIP_IS_E1(bp) && bp->dropless_fc) {
2477 int port = BP_PORT(bp);
2478 u32 pause_enabled = 0;
2480 if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX)
2483 REG_WR(bp, BAR_USTRORM_INTMEM +
2484 USTORM_ETH_PAUSE_ENABLED_OFFSET(port),
2488 if (bp->link_vars.mac_type != MAC_TYPE_EMAC) {
2489 struct host_port_stats *pstats;
2491 pstats = bnx2x_sp(bp, port_stats);
2492 /* reset old mac stats */
2493 memset(&(pstats->mac_stx[0]), 0,
2494 sizeof(struct mac_stx));
2496 if (bp->state == BNX2X_STATE_OPEN)
2497 bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
2500 if (bp->link_vars.link_up && bp->link_vars.line_speed) {
2501 int cmng_fns = bnx2x_get_cmng_fns_mode(bp);
2503 if (cmng_fns != CMNG_FNS_NONE) {
2504 bnx2x_cmng_fns_init(bp, false, cmng_fns);
2505 storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
2507 /* rate shaping and fairness are disabled */
2509 "single function mode without fairness\n");
2512 __bnx2x_link_report(bp);
2515 bnx2x_link_sync_notify(bp);
2518 void bnx2x__link_status_update(struct bnx2x *bp)
2520 if (bp->state != BNX2X_STATE_OPEN)
2523 /* read updated dcb configuration */
2524 bnx2x_dcbx_pmf_update(bp);
2526 bnx2x_link_status_update(&bp->link_params, &bp->link_vars);
2528 if (bp->link_vars.link_up)
2529 bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
2531 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
2533 /* indicate link status */
2534 bnx2x_link_report(bp);
2537 static void bnx2x_pmf_update(struct bnx2x *bp)
2539 int port = BP_PORT(bp);
2543 DP(BNX2X_MSG_MCP, "pmf %d\n", bp->port.pmf);
2546 * We need the mb() to ensure the ordering between the writing to
2547 * bp->port.pmf here and reading it from the bnx2x_periodic_task().
2551 /* queue a periodic task */
2552 queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
2554 bnx2x_dcbx_pmf_update(bp);
2556 /* enable nig attention */
2557 val = (0xff0f | (1 << (BP_VN(bp) + 4)));
2558 if (bp->common.int_block == INT_BLOCK_HC) {
2559 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
2560 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
2561 } else if (!CHIP_IS_E1x(bp)) {
2562 REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
2563 REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
2566 bnx2x_stats_handle(bp, STATS_EVENT_PMF);
2574 * General service functions
2577 /* send the MCP a request, block until there is a reply */
2578 u32 bnx2x_fw_command(struct bnx2x *bp, u32 command, u32 param)
2580 int mb_idx = BP_FW_MB_IDX(bp);
2584 u8 delay = CHIP_REV_IS_SLOW(bp) ? 100 : 10;
2586 mutex_lock(&bp->fw_mb_mutex);
2588 SHMEM_WR(bp, func_mb[mb_idx].drv_mb_param, param);
2589 SHMEM_WR(bp, func_mb[mb_idx].drv_mb_header, (command | seq));
2591 DP(BNX2X_MSG_MCP, "wrote command (%x) to FW MB param 0x%08x\n",
2592 (command | seq), param);
2595 /* let the FW do it's magic ... */
2598 rc = SHMEM_RD(bp, func_mb[mb_idx].fw_mb_header);
2600 /* Give the FW up to 5 second (500*10ms) */
2601 } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 500));
2603 DP(BNX2X_MSG_MCP, "[after %d ms] read (%x) seq is (%x) from FW MB\n",
2604 cnt*delay, rc, seq);
2606 /* is this a reply to our command? */
2607 if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK))
2608 rc &= FW_MSG_CODE_MASK;
2611 BNX2X_ERR("FW failed to respond!\n");
2615 mutex_unlock(&bp->fw_mb_mutex);
2621 void bnx2x_func_init(struct bnx2x *bp, struct bnx2x_func_init_params *p)
2623 if (CHIP_IS_E1x(bp)) {
2624 struct tstorm_eth_function_common_config tcfg = {0};
2626 storm_memset_func_cfg(bp, &tcfg, p->func_id);
2629 /* Enable the function in the FW */
2630 storm_memset_vf_to_pf(bp, p->func_id, p->pf_id);
2631 storm_memset_func_en(bp, p->func_id, 1);
2634 if (p->func_flgs & FUNC_FLG_SPQ) {
2635 storm_memset_spq_addr(bp, p->spq_map, p->func_id);
2636 REG_WR(bp, XSEM_REG_FAST_MEMORY +
2637 XSTORM_SPQ_PROD_OFFSET(p->func_id), p->spq_prod);
2642 * bnx2x_get_tx_only_flags - Return common flags
2646 * @zero_stats TRUE if statistics zeroing is needed
2648 * Return the flags that are common for the Tx-only and not normal connections.
2650 static inline unsigned long bnx2x_get_common_flags(struct bnx2x *bp,
2651 struct bnx2x_fastpath *fp,
2654 unsigned long flags = 0;
2656 /* PF driver will always initialize the Queue to an ACTIVE state */
2657 __set_bit(BNX2X_Q_FLG_ACTIVE, &flags);
2659 /* tx only connections collect statistics (on the same index as the
2660 * parent connection). The statistics are zeroed when the parent
2661 * connection is initialized.
2664 __set_bit(BNX2X_Q_FLG_STATS, &flags);
2666 __set_bit(BNX2X_Q_FLG_ZERO_STATS, &flags);
2672 static inline unsigned long bnx2x_get_q_flags(struct bnx2x *bp,
2673 struct bnx2x_fastpath *fp,
2676 unsigned long flags = 0;
2678 /* calculate other queue flags */
2680 __set_bit(BNX2X_Q_FLG_OV, &flags);
2683 __set_bit(BNX2X_Q_FLG_FCOE, &flags);
2685 if (!fp->disable_tpa) {
2686 __set_bit(BNX2X_Q_FLG_TPA, &flags);
2687 __set_bit(BNX2X_Q_FLG_TPA_IPV6, &flags);
2688 if (fp->mode == TPA_MODE_GRO)
2689 __set_bit(BNX2X_Q_FLG_TPA_GRO, &flags);
2693 __set_bit(BNX2X_Q_FLG_LEADING_RSS, &flags);
2694 __set_bit(BNX2X_Q_FLG_MCAST, &flags);
2697 /* Always set HW VLAN stripping */
2698 __set_bit(BNX2X_Q_FLG_VLAN, &flags);
2701 return flags | bnx2x_get_common_flags(bp, fp, true);
2704 static void bnx2x_pf_q_prep_general(struct bnx2x *bp,
2705 struct bnx2x_fastpath *fp, struct bnx2x_general_setup_params *gen_init,
2708 gen_init->stat_id = bnx2x_stats_id(fp);
2709 gen_init->spcl_id = fp->cl_id;
2711 /* Always use mini-jumbo MTU for FCoE L2 ring */
2713 gen_init->mtu = BNX2X_FCOE_MINI_JUMBO_MTU;
2715 gen_init->mtu = bp->dev->mtu;
2717 gen_init->cos = cos;
2720 static void bnx2x_pf_rx_q_prep(struct bnx2x *bp,
2721 struct bnx2x_fastpath *fp, struct rxq_pause_params *pause,
2722 struct bnx2x_rxq_setup_params *rxq_init)
2726 u16 tpa_agg_size = 0;
2728 if (!fp->disable_tpa) {
2729 pause->sge_th_lo = SGE_TH_LO(bp);
2730 pause->sge_th_hi = SGE_TH_HI(bp);
2732 /* validate SGE ring has enough to cross high threshold */
2733 WARN_ON(bp->dropless_fc &&
2734 pause->sge_th_hi + FW_PREFETCH_CNT >
2735 MAX_RX_SGE_CNT * NUM_RX_SGE_PAGES);
2737 tpa_agg_size = min_t(u32,
2738 (min_t(u32, 8, MAX_SKB_FRAGS) *
2739 SGE_PAGE_SIZE * PAGES_PER_SGE), 0xffff);
2740 max_sge = SGE_PAGE_ALIGN(bp->dev->mtu) >>
2742 max_sge = ((max_sge + PAGES_PER_SGE - 1) &
2743 (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
2744 sge_sz = (u16)min_t(u32, SGE_PAGE_SIZE * PAGES_PER_SGE,
2748 /* pause - not for e1 */
2749 if (!CHIP_IS_E1(bp)) {
2750 pause->bd_th_lo = BD_TH_LO(bp);
2751 pause->bd_th_hi = BD_TH_HI(bp);
2753 pause->rcq_th_lo = RCQ_TH_LO(bp);
2754 pause->rcq_th_hi = RCQ_TH_HI(bp);
2756 * validate that rings have enough entries to cross
2759 WARN_ON(bp->dropless_fc &&
2760 pause->bd_th_hi + FW_PREFETCH_CNT >
2762 WARN_ON(bp->dropless_fc &&
2763 pause->rcq_th_hi + FW_PREFETCH_CNT >
2764 NUM_RCQ_RINGS * MAX_RCQ_DESC_CNT);
2770 rxq_init->dscr_map = fp->rx_desc_mapping;
2771 rxq_init->sge_map = fp->rx_sge_mapping;
2772 rxq_init->rcq_map = fp->rx_comp_mapping;
2773 rxq_init->rcq_np_map = fp->rx_comp_mapping + BCM_PAGE_SIZE;
2775 /* This should be a maximum number of data bytes that may be
2776 * placed on the BD (not including paddings).
2778 rxq_init->buf_sz = fp->rx_buf_size - BNX2X_FW_RX_ALIGN_START -
2779 BNX2X_FW_RX_ALIGN_END - IP_HEADER_ALIGNMENT_PADDING;
2781 rxq_init->cl_qzone_id = fp->cl_qzone_id;
2782 rxq_init->tpa_agg_sz = tpa_agg_size;
2783 rxq_init->sge_buf_sz = sge_sz;
2784 rxq_init->max_sges_pkt = max_sge;
2785 rxq_init->rss_engine_id = BP_FUNC(bp);
2786 rxq_init->mcast_engine_id = BP_FUNC(bp);
2788 /* Maximum number or simultaneous TPA aggregation for this Queue.
2790 * For PF Clients it should be the maximum avaliable number.
2791 * VF driver(s) may want to define it to a smaller value.
2793 rxq_init->max_tpa_queues = MAX_AGG_QS(bp);
2795 rxq_init->cache_line_log = BNX2X_RX_ALIGN_SHIFT;
2796 rxq_init->fw_sb_id = fp->fw_sb_id;
2799 rxq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_RX_CQ_CONS;
2801 rxq_init->sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
2804 static void bnx2x_pf_tx_q_prep(struct bnx2x *bp,
2805 struct bnx2x_fastpath *fp, struct bnx2x_txq_setup_params *txq_init,
2808 txq_init->dscr_map = fp->txdata[cos].tx_desc_mapping;
2809 txq_init->sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS + cos;
2810 txq_init->traffic_type = LLFC_TRAFFIC_TYPE_NW;
2811 txq_init->fw_sb_id = fp->fw_sb_id;
2814 * set the tss leading client id for TX classfication ==
2815 * leading RSS client id
2817 txq_init->tss_leading_cl_id = bnx2x_fp(bp, 0, cl_id);
2819 if (IS_FCOE_FP(fp)) {
2820 txq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_TX_CQ_CONS;
2821 txq_init->traffic_type = LLFC_TRAFFIC_TYPE_FCOE;
2825 static void bnx2x_pf_init(struct bnx2x *bp)
2827 struct bnx2x_func_init_params func_init = {0};
2828 struct event_ring_data eq_data = { {0} };
2831 if (!CHIP_IS_E1x(bp)) {
2832 /* reset IGU PF statistics: MSIX + ATTN */
2834 REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
2835 BNX2X_IGU_STAS_MSG_VF_CNT*4 +
2836 (CHIP_MODE_IS_4_PORT(bp) ?
2837 BP_FUNC(bp) : BP_VN(bp))*4, 0);
2839 REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
2840 BNX2X_IGU_STAS_MSG_VF_CNT*4 +
2841 BNX2X_IGU_STAS_MSG_PF_CNT*4 +
2842 (CHIP_MODE_IS_4_PORT(bp) ?
2843 BP_FUNC(bp) : BP_VN(bp))*4, 0);
2846 /* function setup flags */
2847 flags = (FUNC_FLG_STATS | FUNC_FLG_LEADING | FUNC_FLG_SPQ);
2849 /* This flag is relevant for E1x only.
2850 * E2 doesn't have a TPA configuration in a function level.
2852 flags |= (bp->flags & TPA_ENABLE_FLAG) ? FUNC_FLG_TPA : 0;
2854 func_init.func_flgs = flags;
2855 func_init.pf_id = BP_FUNC(bp);
2856 func_init.func_id = BP_FUNC(bp);
2857 func_init.spq_map = bp->spq_mapping;
2858 func_init.spq_prod = bp->spq_prod_idx;
2860 bnx2x_func_init(bp, &func_init);
2862 memset(&(bp->cmng), 0, sizeof(struct cmng_struct_per_port));
2865 * Congestion management values depend on the link rate
2866 * There is no active link so initial link rate is set to 10 Gbps.
2867 * When the link comes up The congestion management values are
2868 * re-calculated according to the actual link rate.
2870 bp->link_vars.line_speed = SPEED_10000;
2871 bnx2x_cmng_fns_init(bp, true, bnx2x_get_cmng_fns_mode(bp));
2873 /* Only the PMF sets the HW */
2875 storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
2877 /* init Event Queue */
2878 eq_data.base_addr.hi = U64_HI(bp->eq_mapping);
2879 eq_data.base_addr.lo = U64_LO(bp->eq_mapping);
2880 eq_data.producer = bp->eq_prod;
2881 eq_data.index_id = HC_SP_INDEX_EQ_CONS;
2882 eq_data.sb_id = DEF_SB_ID;
2883 storm_memset_eq_data(bp, &eq_data, BP_FUNC(bp));
2887 static void bnx2x_e1h_disable(struct bnx2x *bp)
2889 int port = BP_PORT(bp);
2891 bnx2x_tx_disable(bp);
2893 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
2896 static void bnx2x_e1h_enable(struct bnx2x *bp)
2898 int port = BP_PORT(bp);
2900 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
2902 /* Tx queue should be only reenabled */
2903 netif_tx_wake_all_queues(bp->dev);
2906 * Should not call netif_carrier_on since it will be called if the link
2907 * is up when checking for link state
2911 #define DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED 3
2913 static void bnx2x_drv_info_ether_stat(struct bnx2x *bp)
2915 struct eth_stats_info *ether_stat =
2916 &bp->slowpath->drv_info_to_mcp.ether_stat;
2918 /* leave last char as NULL */
2919 memcpy(ether_stat->version, DRV_MODULE_VERSION,
2920 ETH_STAT_INFO_VERSION_LEN - 1);
2922 bp->fp[0].mac_obj.get_n_elements(bp, &bp->fp[0].mac_obj,
2923 DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED,
2924 ether_stat->mac_local);
2926 ether_stat->mtu_size = bp->dev->mtu;
2928 if (bp->dev->features & NETIF_F_RXCSUM)
2929 ether_stat->feature_flags |= FEATURE_ETH_CHKSUM_OFFLOAD_MASK;
2930 if (bp->dev->features & NETIF_F_TSO)
2931 ether_stat->feature_flags |= FEATURE_ETH_LSO_MASK;
2932 ether_stat->feature_flags |= bp->common.boot_mode;
2934 ether_stat->promiscuous_mode = (bp->dev->flags & IFF_PROMISC) ? 1 : 0;
2936 ether_stat->txq_size = bp->tx_ring_size;
2937 ether_stat->rxq_size = bp->rx_ring_size;
2940 static void bnx2x_drv_info_fcoe_stat(struct bnx2x *bp)
2943 struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
2944 struct fcoe_stats_info *fcoe_stat =
2945 &bp->slowpath->drv_info_to_mcp.fcoe_stat;
2947 memcpy(fcoe_stat->mac_local, bp->fip_mac, ETH_ALEN);
2949 fcoe_stat->qos_priority =
2950 app->traffic_type_priority[LLFC_TRAFFIC_TYPE_FCOE];
2952 /* insert FCoE stats from ramrod response */
2954 struct tstorm_per_queue_stats *fcoe_q_tstorm_stats =
2955 &bp->fw_stats_data->queue_stats[FCOE_IDX].
2956 tstorm_queue_statistics;
2958 struct xstorm_per_queue_stats *fcoe_q_xstorm_stats =
2959 &bp->fw_stats_data->queue_stats[FCOE_IDX].
2960 xstorm_queue_statistics;
2962 struct fcoe_statistics_params *fw_fcoe_stat =
2963 &bp->fw_stats_data->fcoe;
2965 ADD_64(fcoe_stat->rx_bytes_hi, 0, fcoe_stat->rx_bytes_lo,
2966 fw_fcoe_stat->rx_stat0.fcoe_rx_byte_cnt);
2968 ADD_64(fcoe_stat->rx_bytes_hi,
2969 fcoe_q_tstorm_stats->rcv_ucast_bytes.hi,
2970 fcoe_stat->rx_bytes_lo,
2971 fcoe_q_tstorm_stats->rcv_ucast_bytes.lo);
2973 ADD_64(fcoe_stat->rx_bytes_hi,
2974 fcoe_q_tstorm_stats->rcv_bcast_bytes.hi,
2975 fcoe_stat->rx_bytes_lo,
2976 fcoe_q_tstorm_stats->rcv_bcast_bytes.lo);
2978 ADD_64(fcoe_stat->rx_bytes_hi,
2979 fcoe_q_tstorm_stats->rcv_mcast_bytes.hi,
2980 fcoe_stat->rx_bytes_lo,
2981 fcoe_q_tstorm_stats->rcv_mcast_bytes.lo);
2983 ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
2984 fw_fcoe_stat->rx_stat0.fcoe_rx_pkt_cnt);
2986 ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
2987 fcoe_q_tstorm_stats->rcv_ucast_pkts);
2989 ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
2990 fcoe_q_tstorm_stats->rcv_bcast_pkts);
2992 ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
2993 fcoe_q_tstorm_stats->rcv_mcast_pkts);
2995 ADD_64(fcoe_stat->tx_bytes_hi, 0, fcoe_stat->tx_bytes_lo,
2996 fw_fcoe_stat->tx_stat.fcoe_tx_byte_cnt);
2998 ADD_64(fcoe_stat->tx_bytes_hi,
2999 fcoe_q_xstorm_stats->ucast_bytes_sent.hi,
3000 fcoe_stat->tx_bytes_lo,
3001 fcoe_q_xstorm_stats->ucast_bytes_sent.lo);
3003 ADD_64(fcoe_stat->tx_bytes_hi,
3004 fcoe_q_xstorm_stats->bcast_bytes_sent.hi,
3005 fcoe_stat->tx_bytes_lo,
3006 fcoe_q_xstorm_stats->bcast_bytes_sent.lo);
3008 ADD_64(fcoe_stat->tx_bytes_hi,
3009 fcoe_q_xstorm_stats->mcast_bytes_sent.hi,
3010 fcoe_stat->tx_bytes_lo,
3011 fcoe_q_xstorm_stats->mcast_bytes_sent.lo);
3013 ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
3014 fw_fcoe_stat->tx_stat.fcoe_tx_pkt_cnt);
3016 ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
3017 fcoe_q_xstorm_stats->ucast_pkts_sent);
3019 ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
3020 fcoe_q_xstorm_stats->bcast_pkts_sent);
3022 ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
3023 fcoe_q_xstorm_stats->mcast_pkts_sent);
3026 /* ask L5 driver to add data to the struct */
3027 bnx2x_cnic_notify(bp, CNIC_CTL_FCOE_STATS_GET_CMD);
3031 static void bnx2x_drv_info_iscsi_stat(struct bnx2x *bp)
3034 struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
3035 struct iscsi_stats_info *iscsi_stat =
3036 &bp->slowpath->drv_info_to_mcp.iscsi_stat;
3038 memcpy(iscsi_stat->mac_local, bp->cnic_eth_dev.iscsi_mac, ETH_ALEN);
3040 iscsi_stat->qos_priority =
3041 app->traffic_type_priority[LLFC_TRAFFIC_TYPE_ISCSI];
3043 /* ask L5 driver to add data to the struct */
3044 bnx2x_cnic_notify(bp, CNIC_CTL_ISCSI_STATS_GET_CMD);
3048 /* called due to MCP event (on pmf):
3049 * reread new bandwidth configuration
3051 * notify others function about the change
3053 static inline void bnx2x_config_mf_bw(struct bnx2x *bp)
3055 if (bp->link_vars.link_up) {
3056 bnx2x_cmng_fns_init(bp, true, CMNG_FNS_MINMAX);
3057 bnx2x_link_sync_notify(bp);
3059 storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
3062 static inline void bnx2x_set_mf_bw(struct bnx2x *bp)
3064 bnx2x_config_mf_bw(bp);
3065 bnx2x_fw_command(bp, DRV_MSG_CODE_SET_MF_BW_ACK, 0);
3068 static void bnx2x_handle_drv_info_req(struct bnx2x *bp)
3070 enum drv_info_opcode op_code;
3071 u32 drv_info_ctl = SHMEM2_RD(bp, drv_info_control);
3073 /* if drv_info version supported by MFW doesn't match - send NACK */
3074 if ((drv_info_ctl & DRV_INFO_CONTROL_VER_MASK) != DRV_INFO_CUR_VER) {
3075 bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
3079 op_code = (drv_info_ctl & DRV_INFO_CONTROL_OP_CODE_MASK) >>
3080 DRV_INFO_CONTROL_OP_CODE_SHIFT;
3082 memset(&bp->slowpath->drv_info_to_mcp, 0,
3083 sizeof(union drv_info_to_mcp));
3086 case ETH_STATS_OPCODE:
3087 bnx2x_drv_info_ether_stat(bp);
3089 case FCOE_STATS_OPCODE:
3090 bnx2x_drv_info_fcoe_stat(bp);
3092 case ISCSI_STATS_OPCODE:
3093 bnx2x_drv_info_iscsi_stat(bp);
3096 /* if op code isn't supported - send NACK */
3097 bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
3101 /* if we got drv_info attn from MFW then these fields are defined in
3104 SHMEM2_WR(bp, drv_info_host_addr_lo,
3105 U64_LO(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
3106 SHMEM2_WR(bp, drv_info_host_addr_hi,
3107 U64_HI(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
3109 bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_ACK, 0);
3112 static void bnx2x_dcc_event(struct bnx2x *bp, u32 dcc_event)
3114 DP(BNX2X_MSG_MCP, "dcc_event 0x%x\n", dcc_event);
3116 if (dcc_event & DRV_STATUS_DCC_DISABLE_ENABLE_PF) {
3119 * This is the only place besides the function initialization
3120 * where the bp->flags can change so it is done without any
3123 if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
3124 DP(BNX2X_MSG_MCP, "mf_cfg function disabled\n");
3125 bp->flags |= MF_FUNC_DIS;
3127 bnx2x_e1h_disable(bp);
3129 DP(BNX2X_MSG_MCP, "mf_cfg function enabled\n");
3130 bp->flags &= ~MF_FUNC_DIS;
3132 bnx2x_e1h_enable(bp);
3134 dcc_event &= ~DRV_STATUS_DCC_DISABLE_ENABLE_PF;
3136 if (dcc_event & DRV_STATUS_DCC_BANDWIDTH_ALLOCATION) {
3137 bnx2x_config_mf_bw(bp);
3138 dcc_event &= ~DRV_STATUS_DCC_BANDWIDTH_ALLOCATION;
3141 /* Report results to MCP */
3143 bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_FAILURE, 0);
3145 bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_OK, 0);
3148 /* must be called under the spq lock */
3149 static inline struct eth_spe *bnx2x_sp_get_next(struct bnx2x *bp)
3151 struct eth_spe *next_spe = bp->spq_prod_bd;
3153 if (bp->spq_prod_bd == bp->spq_last_bd) {
3154 bp->spq_prod_bd = bp->spq;
3155 bp->spq_prod_idx = 0;
3156 DP(BNX2X_MSG_SP, "end of spq\n");
3164 /* must be called under the spq lock */
3165 static inline void bnx2x_sp_prod_update(struct bnx2x *bp)
3167 int func = BP_FUNC(bp);
3170 * Make sure that BD data is updated before writing the producer:
3171 * BD data is written to the memory, the producer is read from the
3172 * memory, thus we need a full memory barrier to ensure the ordering.
3176 REG_WR16(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func),
3182 * bnx2x_is_contextless_ramrod - check if the current command ends on EQ
3184 * @cmd: command to check
3185 * @cmd_type: command type
3187 static inline bool bnx2x_is_contextless_ramrod(int cmd, int cmd_type)
3189 if ((cmd_type == NONE_CONNECTION_TYPE) ||
3190 (cmd == RAMROD_CMD_ID_ETH_FORWARD_SETUP) ||
3191 (cmd == RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES) ||
3192 (cmd == RAMROD_CMD_ID_ETH_FILTER_RULES) ||
3193 (cmd == RAMROD_CMD_ID_ETH_MULTICAST_RULES) ||
3194 (cmd == RAMROD_CMD_ID_ETH_SET_MAC) ||
3195 (cmd == RAMROD_CMD_ID_ETH_RSS_UPDATE))
3204 * bnx2x_sp_post - place a single command on an SP ring
3206 * @bp: driver handle
3207 * @command: command to place (e.g. SETUP, FILTER_RULES, etc.)
3208 * @cid: SW CID the command is related to
3209 * @data_hi: command private data address (high 32 bits)
3210 * @data_lo: command private data address (low 32 bits)
3211 * @cmd_type: command type (e.g. NONE, ETH)
3213 * SP data is handled as if it's always an address pair, thus data fields are
3214 * not swapped to little endian in upper functions. Instead this function swaps
3215 * data as if it's two u32 fields.
3217 int bnx2x_sp_post(struct bnx2x *bp, int command, int cid,
3218 u32 data_hi, u32 data_lo, int cmd_type)
3220 struct eth_spe *spe;
3222 bool common = bnx2x_is_contextless_ramrod(command, cmd_type);
3224 #ifdef BNX2X_STOP_ON_ERROR
3225 if (unlikely(bp->panic)) {
3226 BNX2X_ERR("Can't post SP when there is panic\n");
3231 spin_lock_bh(&bp->spq_lock);
3234 if (!atomic_read(&bp->eq_spq_left)) {
3235 BNX2X_ERR("BUG! EQ ring full!\n");
3236 spin_unlock_bh(&bp->spq_lock);
3240 } else if (!atomic_read(&bp->cq_spq_left)) {
3241 BNX2X_ERR("BUG! SPQ ring full!\n");
3242 spin_unlock_bh(&bp->spq_lock);
3247 spe = bnx2x_sp_get_next(bp);
3249 /* CID needs port number to be encoded int it */
3250 spe->hdr.conn_and_cmd_data =
3251 cpu_to_le32((command << SPE_HDR_CMD_ID_SHIFT) |
3254 type = (cmd_type << SPE_HDR_CONN_TYPE_SHIFT) & SPE_HDR_CONN_TYPE;
3256 type |= ((BP_FUNC(bp) << SPE_HDR_FUNCTION_ID_SHIFT) &
3257 SPE_HDR_FUNCTION_ID);
3259 spe->hdr.type = cpu_to_le16(type);
3261 spe->data.update_data_addr.hi = cpu_to_le32(data_hi);
3262 spe->data.update_data_addr.lo = cpu_to_le32(data_lo);
3265 * It's ok if the actual decrement is issued towards the memory
3266 * somewhere between the spin_lock and spin_unlock. Thus no
3267 * more explict memory barrier is needed.
3270 atomic_dec(&bp->eq_spq_left);
3272 atomic_dec(&bp->cq_spq_left);
3276 "SPQE[%x] (%x:%x) (cmd, common?) (%d,%d) hw_cid %x data (%x:%x) type(0x%x) left (CQ, EQ) (%x,%x)\n",
3277 bp->spq_prod_idx, (u32)U64_HI(bp->spq_mapping),
3278 (u32)(U64_LO(bp->spq_mapping) +
3279 (void *)bp->spq_prod_bd - (void *)bp->spq), command, common,
3280 HW_CID(bp, cid), data_hi, data_lo, type,
3281 atomic_read(&bp->cq_spq_left), atomic_read(&bp->eq_spq_left));
3283 bnx2x_sp_prod_update(bp);
3284 spin_unlock_bh(&bp->spq_lock);
3288 /* acquire split MCP access lock register */
3289 static int bnx2x_acquire_alr(struct bnx2x *bp)
3295 for (j = 0; j < 1000; j++) {
3297 REG_WR(bp, GRCBASE_MCP + 0x9c, val);
3298 val = REG_RD(bp, GRCBASE_MCP + 0x9c);
3299 if (val & (1L << 31))
3304 if (!(val & (1L << 31))) {
3305 BNX2X_ERR("Cannot acquire MCP access lock register\n");
3312 /* release split MCP access lock register */
3313 static void bnx2x_release_alr(struct bnx2x *bp)
3315 REG_WR(bp, GRCBASE_MCP + 0x9c, 0);
3318 #define BNX2X_DEF_SB_ATT_IDX 0x0001
3319 #define BNX2X_DEF_SB_IDX 0x0002
3321 static inline u16 bnx2x_update_dsb_idx(struct bnx2x *bp)
3323 struct host_sp_status_block *def_sb = bp->def_status_blk;
3326 barrier(); /* status block is written to by the chip */
3327 if (bp->def_att_idx != def_sb->atten_status_block.attn_bits_index) {
3328 bp->def_att_idx = def_sb->atten_status_block.attn_bits_index;
3329 rc |= BNX2X_DEF_SB_ATT_IDX;
3332 if (bp->def_idx != def_sb->sp_sb.running_index) {
3333 bp->def_idx = def_sb->sp_sb.running_index;
3334 rc |= BNX2X_DEF_SB_IDX;
3337 /* Do not reorder: indecies reading should complete before handling */
3343 * slow path service functions
3346 static void bnx2x_attn_int_asserted(struct bnx2x *bp, u32 asserted)
3348 int port = BP_PORT(bp);
3349 u32 aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
3350 MISC_REG_AEU_MASK_ATTN_FUNC_0;
3351 u32 nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 :
3352 NIG_REG_MASK_INTERRUPT_PORT0;
3357 if (bp->attn_state & asserted)
3358 BNX2X_ERR("IGU ERROR\n");
3360 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
3361 aeu_mask = REG_RD(bp, aeu_addr);
3363 DP(NETIF_MSG_HW, "aeu_mask %x newly asserted %x\n",
3364 aeu_mask, asserted);
3365 aeu_mask &= ~(asserted & 0x3ff);
3366 DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
3368 REG_WR(bp, aeu_addr, aeu_mask);
3369 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
3371 DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
3372 bp->attn_state |= asserted;
3373 DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
3375 if (asserted & ATTN_HARD_WIRED_MASK) {
3376 if (asserted & ATTN_NIG_FOR_FUNC) {
3378 bnx2x_acquire_phy_lock(bp);
3380 /* save nig interrupt mask */
3381 nig_mask = REG_RD(bp, nig_int_mask_addr);
3383 /* If nig_mask is not set, no need to call the update
3387 REG_WR(bp, nig_int_mask_addr, 0);
3389 bnx2x_link_attn(bp);
3392 /* handle unicore attn? */
3394 if (asserted & ATTN_SW_TIMER_4_FUNC)
3395 DP(NETIF_MSG_HW, "ATTN_SW_TIMER_4_FUNC!\n");
3397 if (asserted & GPIO_2_FUNC)
3398 DP(NETIF_MSG_HW, "GPIO_2_FUNC!\n");
3400 if (asserted & GPIO_3_FUNC)
3401 DP(NETIF_MSG_HW, "GPIO_3_FUNC!\n");
3403 if (asserted & GPIO_4_FUNC)
3404 DP(NETIF_MSG_HW, "GPIO_4_FUNC!\n");
3407 if (asserted & ATTN_GENERAL_ATTN_1) {
3408 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_1!\n");
3409 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_1, 0x0);
3411 if (asserted & ATTN_GENERAL_ATTN_2) {
3412 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_2!\n");
3413 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_2, 0x0);
3415 if (asserted & ATTN_GENERAL_ATTN_3) {
3416 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_3!\n");
3417 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_3, 0x0);
3420 if (asserted & ATTN_GENERAL_ATTN_4) {
3421 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_4!\n");
3422 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_4, 0x0);
3424 if (asserted & ATTN_GENERAL_ATTN_5) {
3425 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_5!\n");
3426 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_5, 0x0);
3428 if (asserted & ATTN_GENERAL_ATTN_6) {
3429 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_6!\n");
3430 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_6, 0x0);
3434 } /* if hardwired */
3436 if (bp->common.int_block == INT_BLOCK_HC)
3437 reg_addr = (HC_REG_COMMAND_REG + port*32 +
3438 COMMAND_REG_ATTN_BITS_SET);
3440 reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_SET_UPPER*8);
3442 DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", asserted,
3443 (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
3444 REG_WR(bp, reg_addr, asserted);
3446 /* now set back the mask */
3447 if (asserted & ATTN_NIG_FOR_FUNC) {
3448 REG_WR(bp, nig_int_mask_addr, nig_mask);
3449 bnx2x_release_phy_lock(bp);
3453 static inline void bnx2x_fan_failure(struct bnx2x *bp)
3455 int port = BP_PORT(bp);
3457 /* mark the failure */
3460 dev_info.port_hw_config[port].external_phy_config);
3462 ext_phy_config &= ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK;
3463 ext_phy_config |= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE;
3464 SHMEM_WR(bp, dev_info.port_hw_config[port].external_phy_config,
3467 /* log the failure */
3468 netdev_err(bp->dev, "Fan Failure on Network Controller has caused the driver to shutdown the card to prevent permanent damage.\n"
3469 "Please contact OEM Support for assistance\n");
3472 * Scheudle device reset (unload)
3473 * This is due to some boards consuming sufficient power when driver is
3474 * up to overheat if fan fails.
3476 smp_mb__before_clear_bit();
3477 set_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state);
3478 smp_mb__after_clear_bit();
3479 schedule_delayed_work(&bp->sp_rtnl_task, 0);
3483 static inline void bnx2x_attn_int_deasserted0(struct bnx2x *bp, u32 attn)
3485 int port = BP_PORT(bp);
3489 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
3490 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
3492 if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) {
3494 val = REG_RD(bp, reg_offset);
3495 val &= ~AEU_INPUTS_ATTN_BITS_SPIO5;
3496 REG_WR(bp, reg_offset, val);
3498 BNX2X_ERR("SPIO5 hw attention\n");
3500 /* Fan failure attention */
3501 bnx2x_hw_reset_phy(&bp->link_params);
3502 bnx2x_fan_failure(bp);
3505 if ((attn & bp->link_vars.aeu_int_mask) && bp->port.pmf) {
3506 bnx2x_acquire_phy_lock(bp);
3507 bnx2x_handle_module_detect_int(&bp->link_params);
3508 bnx2x_release_phy_lock(bp);
3511 if (attn & HW_INTERRUT_ASSERT_SET_0) {
3513 val = REG_RD(bp, reg_offset);
3514 val &= ~(attn & HW_INTERRUT_ASSERT_SET_0);
3515 REG_WR(bp, reg_offset, val);
3517 BNX2X_ERR("FATAL HW block attention set0 0x%x\n",
3518 (u32)(attn & HW_INTERRUT_ASSERT_SET_0));
3523 static inline void bnx2x_attn_int_deasserted1(struct bnx2x *bp, u32 attn)
3527 if (attn & AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT) {
3529 val = REG_RD(bp, DORQ_REG_DORQ_INT_STS_CLR);
3530 BNX2X_ERR("DB hw attention 0x%x\n", val);
3531 /* DORQ discard attention */
3533 BNX2X_ERR("FATAL error from DORQ\n");
3536 if (attn & HW_INTERRUT_ASSERT_SET_1) {
3538 int port = BP_PORT(bp);
3541 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 :
3542 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1);
3544 val = REG_RD(bp, reg_offset);
3545 val &= ~(attn & HW_INTERRUT_ASSERT_SET_1);
3546 REG_WR(bp, reg_offset, val);
3548 BNX2X_ERR("FATAL HW block attention set1 0x%x\n",
3549 (u32)(attn & HW_INTERRUT_ASSERT_SET_1));
3554 static inline void bnx2x_attn_int_deasserted2(struct bnx2x *bp, u32 attn)
3558 if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) {
3560 val = REG_RD(bp, CFC_REG_CFC_INT_STS_CLR);
3561 BNX2X_ERR("CFC hw attention 0x%x\n", val);
3562 /* CFC error attention */
3564 BNX2X_ERR("FATAL error from CFC\n");
3567 if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) {
3568 val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_0);
3569 BNX2X_ERR("PXP hw attention-0 0x%x\n", val);
3570 /* RQ_USDMDP_FIFO_OVERFLOW */
3572 BNX2X_ERR("FATAL error from PXP\n");
3574 if (!CHIP_IS_E1x(bp)) {
3575 val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_1);
3576 BNX2X_ERR("PXP hw attention-1 0x%x\n", val);
3580 if (attn & HW_INTERRUT_ASSERT_SET_2) {
3582 int port = BP_PORT(bp);
3585 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 :
3586 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2);
3588 val = REG_RD(bp, reg_offset);
3589 val &= ~(attn & HW_INTERRUT_ASSERT_SET_2);
3590 REG_WR(bp, reg_offset, val);
3592 BNX2X_ERR("FATAL HW block attention set2 0x%x\n",
3593 (u32)(attn & HW_INTERRUT_ASSERT_SET_2));
3598 static inline void bnx2x_attn_int_deasserted3(struct bnx2x *bp, u32 attn)
3602 if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) {
3604 if (attn & BNX2X_PMF_LINK_ASSERT) {
3605 int func = BP_FUNC(bp);
3607 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
3608 bp->mf_config[BP_VN(bp)] = MF_CFG_RD(bp,
3609 func_mf_config[BP_ABS_FUNC(bp)].config);
3611 func_mb[BP_FW_MB_IDX(bp)].drv_status);
3612 if (val & DRV_STATUS_DCC_EVENT_MASK)
3614 (val & DRV_STATUS_DCC_EVENT_MASK));
3616 if (val & DRV_STATUS_SET_MF_BW)
3617 bnx2x_set_mf_bw(bp);
3619 if (val & DRV_STATUS_DRV_INFO_REQ)
3620 bnx2x_handle_drv_info_req(bp);
3621 if ((bp->port.pmf == 0) && (val & DRV_STATUS_PMF))
3622 bnx2x_pmf_update(bp);
3625 (val & DRV_STATUS_DCBX_NEGOTIATION_RESULTS) &&
3626 bp->dcbx_enabled > 0)
3627 /* start dcbx state machine */
3628 bnx2x_dcbx_set_params(bp,
3629 BNX2X_DCBX_STATE_NEG_RECEIVED);
3630 if (bp->link_vars.periodic_flags &
3631 PERIODIC_FLAGS_LINK_EVENT) {
3632 /* sync with link */
3633 bnx2x_acquire_phy_lock(bp);
3634 bp->link_vars.periodic_flags &=
3635 ~PERIODIC_FLAGS_LINK_EVENT;
3636 bnx2x_release_phy_lock(bp);
3638 bnx2x_link_sync_notify(bp);
3639 bnx2x_link_report(bp);
3641 /* Always call it here: bnx2x_link_report() will
3642 * prevent the link indication duplication.
3644 bnx2x__link_status_update(bp);
3645 } else if (attn & BNX2X_MC_ASSERT_BITS) {
3647 BNX2X_ERR("MC assert!\n");
3648 bnx2x_mc_assert(bp);
3649 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_10, 0);
3650 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_9, 0);
3651 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_8, 0);
3652 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_7, 0);
3655 } else if (attn & BNX2X_MCP_ASSERT) {
3657 BNX2X_ERR("MCP assert!\n");
3658 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_11, 0);
3662 BNX2X_ERR("Unknown HW assert! (attn 0x%x)\n", attn);
3665 if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) {
3666 BNX2X_ERR("LATCHED attention 0x%08x (masked)\n", attn);
3667 if (attn & BNX2X_GRC_TIMEOUT) {
3668 val = CHIP_IS_E1(bp) ? 0 :
3669 REG_RD(bp, MISC_REG_GRC_TIMEOUT_ATTN);
3670 BNX2X_ERR("GRC time-out 0x%08x\n", val);
3672 if (attn & BNX2X_GRC_RSV) {
3673 val = CHIP_IS_E1(bp) ? 0 :
3674 REG_RD(bp, MISC_REG_GRC_RSV_ATTN);
3675 BNX2X_ERR("GRC reserved 0x%08x\n", val);
3677 REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff);
3683 * 0-7 - Engine0 load counter.
3684 * 8-15 - Engine1 load counter.
3685 * 16 - Engine0 RESET_IN_PROGRESS bit.
3686 * 17 - Engine1 RESET_IN_PROGRESS bit.
3687 * 18 - Engine0 ONE_IS_LOADED. Set when there is at least one active function
3689 * 19 - Engine1 ONE_IS_LOADED.
3690 * 20 - Chip reset flow bit. When set none-leader must wait for both engines
3691 * leader to complete (check for both RESET_IN_PROGRESS bits and not for
3692 * just the one belonging to its engine).
3695 #define BNX2X_RECOVERY_GLOB_REG MISC_REG_GENERIC_POR_1
3697 #define BNX2X_PATH0_LOAD_CNT_MASK 0x000000ff
3698 #define BNX2X_PATH0_LOAD_CNT_SHIFT 0
3699 #define BNX2X_PATH1_LOAD_CNT_MASK 0x0000ff00
3700 #define BNX2X_PATH1_LOAD_CNT_SHIFT 8
3701 #define BNX2X_PATH0_RST_IN_PROG_BIT 0x00010000
3702 #define BNX2X_PATH1_RST_IN_PROG_BIT 0x00020000
3703 #define BNX2X_GLOBAL_RESET_BIT 0x00040000
3706 * Set the GLOBAL_RESET bit.
3708 * Should be run under rtnl lock
3710 void bnx2x_set_reset_global(struct bnx2x *bp)
3713 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
3714 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3715 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val | BNX2X_GLOBAL_RESET_BIT);
3716 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
3720 * Clear the GLOBAL_RESET bit.
3722 * Should be run under rtnl lock
3724 static inline void bnx2x_clear_reset_global(struct bnx2x *bp)
3727 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
3728 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3729 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~BNX2X_GLOBAL_RESET_BIT));
3730 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
3734 * Checks the GLOBAL_RESET bit.
3736 * should be run under rtnl lock
3738 static inline bool bnx2x_reset_is_global(struct bnx2x *bp)
3740 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3742 DP(NETIF_MSG_HW, "GEN_REG_VAL=0x%08x\n", val);
3743 return (val & BNX2X_GLOBAL_RESET_BIT) ? true : false;
3747 * Clear RESET_IN_PROGRESS bit for the current engine.
3749 * Should be run under rtnl lock
3751 static inline void bnx2x_set_reset_done(struct bnx2x *bp)
3754 u32 bit = BP_PATH(bp) ?
3755 BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
3756 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
3757 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3761 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
3763 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
3767 * Set RESET_IN_PROGRESS for the current engine.
3769 * should be run under rtnl lock
3771 void bnx2x_set_reset_in_progress(struct bnx2x *bp)
3774 u32 bit = BP_PATH(bp) ?
3775 BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
3776 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
3777 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3781 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
3782 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
3786 * Checks the RESET_IN_PROGRESS bit for the given engine.
3787 * should be run under rtnl lock
3789 bool bnx2x_reset_is_done(struct bnx2x *bp, int engine)
3791 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3793 BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
3795 /* return false if bit is set */
3796 return (val & bit) ? false : true;
3800 * set pf load for the current pf.
3802 * should be run under rtnl lock
3804 void bnx2x_set_pf_load(struct bnx2x *bp)
3807 u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
3808 BNX2X_PATH0_LOAD_CNT_MASK;
3809 u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
3810 BNX2X_PATH0_LOAD_CNT_SHIFT;
3812 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
3813 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3815 DP(NETIF_MSG_IFUP, "Old GEN_REG_VAL=0x%08x\n", val);
3817 /* get the current counter value */
3818 val1 = (val & mask) >> shift;
3820 /* set bit of that PF */
3821 val1 |= (1 << bp->pf_num);
3823 /* clear the old value */
3826 /* set the new one */
3827 val |= ((val1 << shift) & mask);
3829 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
3830 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
3834 * bnx2x_clear_pf_load - clear pf load mark
3836 * @bp: driver handle
3838 * Should be run under rtnl lock.
3839 * Decrements the load counter for the current engine. Returns
3840 * whether other functions are still loaded
3842 bool bnx2x_clear_pf_load(struct bnx2x *bp)
3845 u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
3846 BNX2X_PATH0_LOAD_CNT_MASK;
3847 u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
3848 BNX2X_PATH0_LOAD_CNT_SHIFT;
3850 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
3851 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3852 DP(NETIF_MSG_IFDOWN, "Old GEN_REG_VAL=0x%08x\n", val);
3854 /* get the current counter value */
3855 val1 = (val & mask) >> shift;
3857 /* clear bit of that PF */
3858 val1 &= ~(1 << bp->pf_num);
3860 /* clear the old value */
3863 /* set the new one */
3864 val |= ((val1 << shift) & mask);
3866 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
3867 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
3872 * Read the load status for the current engine.
3874 * should be run under rtnl lock
3876 static inline bool bnx2x_get_load_status(struct bnx2x *bp, int engine)
3878 u32 mask = (engine ? BNX2X_PATH1_LOAD_CNT_MASK :
3879 BNX2X_PATH0_LOAD_CNT_MASK);
3880 u32 shift = (engine ? BNX2X_PATH1_LOAD_CNT_SHIFT :
3881 BNX2X_PATH0_LOAD_CNT_SHIFT);
3882 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3884 DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "GLOB_REG=0x%08x\n", val);
3886 val = (val & mask) >> shift;
3888 DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "load mask for engine %d = 0x%x\n",
3895 * Reset the load status for the current engine.
3897 static inline void bnx2x_clear_load_status(struct bnx2x *bp)
3900 u32 mask = (BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
3901 BNX2X_PATH0_LOAD_CNT_MASK);
3902 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
3903 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3904 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~mask));
3905 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
3908 static inline void _print_next_block(int idx, const char *blk)
3910 pr_cont("%s%s", idx ? ", " : "", blk);
3913 static inline int bnx2x_check_blocks_with_parity0(u32 sig, int par_num,
3918 for (i = 0; sig; i++) {
3919 cur_bit = ((u32)0x1 << i);
3920 if (sig & cur_bit) {
3922 case AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR:
3924 _print_next_block(par_num++, "BRB");
3926 case AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR:
3928 _print_next_block(par_num++, "PARSER");
3930 case AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR:
3932 _print_next_block(par_num++, "TSDM");
3934 case AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR:
3936 _print_next_block(par_num++,
3939 case AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR:
3941 _print_next_block(par_num++, "TCM");
3943 case AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR:
3945 _print_next_block(par_num++, "TSEMI");
3947 case AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR:
3949 _print_next_block(par_num++, "XPB");
3961 static inline int bnx2x_check_blocks_with_parity1(u32 sig, int par_num,
3962 bool *global, bool print)
3966 for (i = 0; sig; i++) {
3967 cur_bit = ((u32)0x1 << i);
3968 if (sig & cur_bit) {
3970 case AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR:
3972 _print_next_block(par_num++, "PBF");
3974 case AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR:
3976 _print_next_block(par_num++, "QM");
3978 case AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR:
3980 _print_next_block(par_num++, "TM");
3982 case AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR:
3984 _print_next_block(par_num++, "XSDM");
3986 case AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR:
3988 _print_next_block(par_num++, "XCM");
3990 case AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR:
3992 _print_next_block(par_num++, "XSEMI");
3994 case AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR:
3996 _print_next_block(par_num++,
3999 case AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR:
4001 _print_next_block(par_num++, "NIG");
4003 case AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR:
4005 _print_next_block(par_num++,
4009 case AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR:
4011 _print_next_block(par_num++, "DEBUG");
4013 case AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR:
4015 _print_next_block(par_num++, "USDM");
4017 case AEU_INPUTS_ATTN_BITS_UCM_PARITY_ERROR:
4019 _print_next_block(par_num++, "UCM");
4021 case AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR:
4023 _print_next_block(par_num++, "USEMI");
4025 case AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR:
4027 _print_next_block(par_num++, "UPB");
4029 case AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR:
4031 _print_next_block(par_num++, "CSDM");
4033 case AEU_INPUTS_ATTN_BITS_CCM_PARITY_ERROR:
4035 _print_next_block(par_num++, "CCM");
4047 static inline int bnx2x_check_blocks_with_parity2(u32 sig, int par_num,
4052 for (i = 0; sig; i++) {
4053 cur_bit = ((u32)0x1 << i);
4054 if (sig & cur_bit) {
4056 case AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR:
4058 _print_next_block(par_num++, "CSEMI");
4060 case AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR:
4062 _print_next_block(par_num++, "PXP");
4064 case AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR:
4066 _print_next_block(par_num++,
4067 "PXPPCICLOCKCLIENT");
4069 case AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR:
4071 _print_next_block(par_num++, "CFC");
4073 case AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR:
4075 _print_next_block(par_num++, "CDU");
4077 case AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR:
4079 _print_next_block(par_num++, "DMAE");
4081 case AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR:
4083 _print_next_block(par_num++, "IGU");
4085 case AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR:
4087 _print_next_block(par_num++, "MISC");
4099 static inline int bnx2x_check_blocks_with_parity3(u32 sig, int par_num,
4100 bool *global, bool print)
4104 for (i = 0; sig; i++) {
4105 cur_bit = ((u32)0x1 << i);
4106 if (sig & cur_bit) {
4108 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY:
4110 _print_next_block(par_num++, "MCP ROM");
4113 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY:
4115 _print_next_block(par_num++,
4119 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY:
4121 _print_next_block(par_num++,
4125 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY:
4127 _print_next_block(par_num++,
4141 static inline int bnx2x_check_blocks_with_parity4(u32 sig, int par_num,
4146 for (i = 0; sig; i++) {
4147 cur_bit = ((u32)0x1 << i);
4148 if (sig & cur_bit) {
4150 case AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR:
4152 _print_next_block(par_num++, "PGLUE_B");
4154 case AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR:
4156 _print_next_block(par_num++, "ATC");
4168 static inline bool bnx2x_parity_attn(struct bnx2x *bp, bool *global, bool print,
4171 if ((sig[0] & HW_PRTY_ASSERT_SET_0) ||
4172 (sig[1] & HW_PRTY_ASSERT_SET_1) ||
4173 (sig[2] & HW_PRTY_ASSERT_SET_2) ||
4174 (sig[3] & HW_PRTY_ASSERT_SET_3) ||
4175 (sig[4] & HW_PRTY_ASSERT_SET_4)) {
4177 DP(NETIF_MSG_HW, "Was parity error: HW block parity attention:\n"
4178 "[0]:0x%08x [1]:0x%08x [2]:0x%08x [3]:0x%08x [4]:0x%08x\n",
4179 sig[0] & HW_PRTY_ASSERT_SET_0,
4180 sig[1] & HW_PRTY_ASSERT_SET_1,
4181 sig[2] & HW_PRTY_ASSERT_SET_2,
4182 sig[3] & HW_PRTY_ASSERT_SET_3,
4183 sig[4] & HW_PRTY_ASSERT_SET_4);
4186 "Parity errors detected in blocks: ");
4187 par_num = bnx2x_check_blocks_with_parity0(
4188 sig[0] & HW_PRTY_ASSERT_SET_0, par_num, print);
4189 par_num = bnx2x_check_blocks_with_parity1(
4190 sig[1] & HW_PRTY_ASSERT_SET_1, par_num, global, print);
4191 par_num = bnx2x_check_blocks_with_parity2(
4192 sig[2] & HW_PRTY_ASSERT_SET_2, par_num, print);
4193 par_num = bnx2x_check_blocks_with_parity3(
4194 sig[3] & HW_PRTY_ASSERT_SET_3, par_num, global, print);
4195 par_num = bnx2x_check_blocks_with_parity4(
4196 sig[4] & HW_PRTY_ASSERT_SET_4, par_num, print);
4207 * bnx2x_chk_parity_attn - checks for parity attentions.
4209 * @bp: driver handle
4210 * @global: true if there was a global attention
4211 * @print: show parity attention in syslog
4213 bool bnx2x_chk_parity_attn(struct bnx2x *bp, bool *global, bool print)
4215 struct attn_route attn = { {0} };
4216 int port = BP_PORT(bp);
4218 attn.sig[0] = REG_RD(bp,
4219 MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 +
4221 attn.sig[1] = REG_RD(bp,
4222 MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 +
4224 attn.sig[2] = REG_RD(bp,
4225 MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 +
4227 attn.sig[3] = REG_RD(bp,
4228 MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 +
4231 if (!CHIP_IS_E1x(bp))
4232 attn.sig[4] = REG_RD(bp,
4233 MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 +
4236 return bnx2x_parity_attn(bp, global, print, attn.sig);
4240 static inline void bnx2x_attn_int_deasserted4(struct bnx2x *bp, u32 attn)
4243 if (attn & AEU_INPUTS_ATTN_BITS_PGLUE_HW_INTERRUPT) {
4245 val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS_CLR);
4246 BNX2X_ERR("PGLUE hw attention 0x%x\n", val);
4247 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR)
4248 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR\n");
4249 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR)
4250 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR\n");
4251 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN)
4252 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN\n");
4253 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN)
4254 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN\n");
4256 PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN)
4257 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN\n");
4259 PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN)
4260 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN\n");
4261 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN)
4262 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN\n");
4263 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN)
4264 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN\n");
4265 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW)
4266 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW\n");
4268 if (attn & AEU_INPUTS_ATTN_BITS_ATC_HW_INTERRUPT) {
4269 val = REG_RD(bp, ATC_REG_ATC_INT_STS_CLR);
4270 BNX2X_ERR("ATC hw attention 0x%x\n", val);
4271 if (val & ATC_ATC_INT_STS_REG_ADDRESS_ERROR)
4272 BNX2X_ERR("ATC_ATC_INT_STS_REG_ADDRESS_ERROR\n");
4273 if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND)
4274 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND\n");
4275 if (val & ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS)
4276 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS\n");
4277 if (val & ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT)
4278 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT\n");
4279 if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR)
4280 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR\n");
4281 if (val & ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU)
4282 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU\n");
4285 if (attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
4286 AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)) {
4287 BNX2X_ERR("FATAL parity attention set4 0x%x\n",
4288 (u32)(attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
4289 AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)));
4294 static void bnx2x_attn_int_deasserted(struct bnx2x *bp, u32 deasserted)
4296 struct attn_route attn, *group_mask;
4297 int port = BP_PORT(bp);
4302 bool global = false;
4304 /* need to take HW lock because MCP or other port might also
4305 try to handle this event */
4306 bnx2x_acquire_alr(bp);
4308 if (bnx2x_chk_parity_attn(bp, &global, true)) {
4309 #ifndef BNX2X_STOP_ON_ERROR
4310 bp->recovery_state = BNX2X_RECOVERY_INIT;
4311 schedule_delayed_work(&bp->sp_rtnl_task, 0);
4312 /* Disable HW interrupts */
4313 bnx2x_int_disable(bp);
4314 /* In case of parity errors don't handle attentions so that
4315 * other function would "see" parity errors.
4320 bnx2x_release_alr(bp);
4324 attn.sig[0] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4);
4325 attn.sig[1] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4);
4326 attn.sig[2] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4);
4327 attn.sig[3] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4);
4328 if (!CHIP_IS_E1x(bp))
4330 REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + port*4);
4334 DP(NETIF_MSG_HW, "attn: %08x %08x %08x %08x %08x\n",
4335 attn.sig[0], attn.sig[1], attn.sig[2], attn.sig[3], attn.sig[4]);
4337 for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
4338 if (deasserted & (1 << index)) {
4339 group_mask = &bp->attn_group[index];
4341 DP(NETIF_MSG_HW, "group[%d]: %08x %08x %08x %08x %08x\n",
4343 group_mask->sig[0], group_mask->sig[1],
4344 group_mask->sig[2], group_mask->sig[3],
4345 group_mask->sig[4]);
4347 bnx2x_attn_int_deasserted4(bp,
4348 attn.sig[4] & group_mask->sig[4]);
4349 bnx2x_attn_int_deasserted3(bp,
4350 attn.sig[3] & group_mask->sig[3]);
4351 bnx2x_attn_int_deasserted1(bp,
4352 attn.sig[1] & group_mask->sig[1]);
4353 bnx2x_attn_int_deasserted2(bp,
4354 attn.sig[2] & group_mask->sig[2]);
4355 bnx2x_attn_int_deasserted0(bp,
4356 attn.sig[0] & group_mask->sig[0]);
4360 bnx2x_release_alr(bp);
4362 if (bp->common.int_block == INT_BLOCK_HC)
4363 reg_addr = (HC_REG_COMMAND_REG + port*32 +
4364 COMMAND_REG_ATTN_BITS_CLR);
4366 reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_CLR_UPPER*8);
4369 DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", val,
4370 (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
4371 REG_WR(bp, reg_addr, val);
4373 if (~bp->attn_state & deasserted)
4374 BNX2X_ERR("IGU ERROR\n");
4376 reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
4377 MISC_REG_AEU_MASK_ATTN_FUNC_0;
4379 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
4380 aeu_mask = REG_RD(bp, reg_addr);
4382 DP(NETIF_MSG_HW, "aeu_mask %x newly deasserted %x\n",
4383 aeu_mask, deasserted);
4384 aeu_mask |= (deasserted & 0x3ff);
4385 DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
4387 REG_WR(bp, reg_addr, aeu_mask);
4388 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
4390 DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
4391 bp->attn_state &= ~deasserted;
4392 DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
4395 static void bnx2x_attn_int(struct bnx2x *bp)
4397 /* read local copy of bits */
4398 u32 attn_bits = le32_to_cpu(bp->def_status_blk->atten_status_block.
4400 u32 attn_ack = le32_to_cpu(bp->def_status_blk->atten_status_block.
4402 u32 attn_state = bp->attn_state;
4404 /* look for changed bits */
4405 u32 asserted = attn_bits & ~attn_ack & ~attn_state;
4406 u32 deasserted = ~attn_bits & attn_ack & attn_state;
4409 "attn_bits %x attn_ack %x asserted %x deasserted %x\n",
4410 attn_bits, attn_ack, asserted, deasserted);
4412 if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state))
4413 BNX2X_ERR("BAD attention state\n");
4415 /* handle bits that were raised */
4417 bnx2x_attn_int_asserted(bp, asserted);
4420 bnx2x_attn_int_deasserted(bp, deasserted);
4423 void bnx2x_igu_ack_sb(struct bnx2x *bp, u8 igu_sb_id, u8 segment,
4424 u16 index, u8 op, u8 update)
4426 u32 igu_addr = BAR_IGU_INTMEM + (IGU_CMD_INT_ACK_BASE + igu_sb_id)*8;
4428 bnx2x_igu_ack_sb_gen(bp, igu_sb_id, segment, index, op, update,
4432 static inline void bnx2x_update_eq_prod(struct bnx2x *bp, u16 prod)
4434 /* No memory barriers */
4435 storm_memset_eq_prod(bp, prod, BP_FUNC(bp));
4436 mmiowb(); /* keep prod updates ordered */
4440 static int bnx2x_cnic_handle_cfc_del(struct bnx2x *bp, u32 cid,
4441 union event_ring_elem *elem)
4443 u8 err = elem->message.error;
4445 if (!bp->cnic_eth_dev.starting_cid ||
4446 (cid < bp->cnic_eth_dev.starting_cid &&
4447 cid != bp->cnic_eth_dev.iscsi_l2_cid))
4450 DP(BNX2X_MSG_SP, "got delete ramrod for CNIC CID %d\n", cid);
4452 if (unlikely(err)) {
4454 BNX2X_ERR("got delete ramrod for CNIC CID %d with error!\n",
4456 bnx2x_panic_dump(bp);
4458 bnx2x_cnic_cfc_comp(bp, cid, err);
4463 static inline void bnx2x_handle_mcast_eqe(struct bnx2x *bp)
4465 struct bnx2x_mcast_ramrod_params rparam;
4468 memset(&rparam, 0, sizeof(rparam));
4470 rparam.mcast_obj = &bp->mcast_obj;
4472 netif_addr_lock_bh(bp->dev);
4474 /* Clear pending state for the last command */
4475 bp->mcast_obj.raw.clear_pending(&bp->mcast_obj.raw);
4477 /* If there are pending mcast commands - send them */
4478 if (bp->mcast_obj.check_pending(&bp->mcast_obj)) {
4479 rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_CONT);
4481 BNX2X_ERR("Failed to send pending mcast commands: %d\n",
4485 netif_addr_unlock_bh(bp->dev);
4488 static inline void bnx2x_handle_classification_eqe(struct bnx2x *bp,
4489 union event_ring_elem *elem)
4491 unsigned long ramrod_flags = 0;
4493 u32 cid = elem->message.data.eth_event.echo & BNX2X_SWCID_MASK;
4494 struct bnx2x_vlan_mac_obj *vlan_mac_obj;
4496 /* Always push next commands out, don't wait here */
4497 __set_bit(RAMROD_CONT, &ramrod_flags);
4499 switch (elem->message.data.eth_event.echo >> BNX2X_SWCID_SHIFT) {
4500 case BNX2X_FILTER_MAC_PENDING:
4501 DP(BNX2X_MSG_SP, "Got SETUP_MAC completions\n");
4503 if (cid == BNX2X_ISCSI_ETH_CID)
4504 vlan_mac_obj = &bp->iscsi_l2_mac_obj;
4507 vlan_mac_obj = &bp->fp[cid].mac_obj;
4510 case BNX2X_FILTER_MCAST_PENDING:
4511 DP(BNX2X_MSG_SP, "Got SETUP_MCAST completions\n");
4512 /* This is only relevant for 57710 where multicast MACs are
4513 * configured as unicast MACs using the same ramrod.
4515 bnx2x_handle_mcast_eqe(bp);
4518 BNX2X_ERR("Unsupported classification command: %d\n",
4519 elem->message.data.eth_event.echo);
4523 rc = vlan_mac_obj->complete(bp, vlan_mac_obj, elem, &ramrod_flags);
4526 BNX2X_ERR("Failed to schedule new commands: %d\n", rc);
4528 DP(BNX2X_MSG_SP, "Scheduled next pending commands...\n");
4533 static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start);
4536 static inline void bnx2x_handle_rx_mode_eqe(struct bnx2x *bp)
4538 netif_addr_lock_bh(bp->dev);
4540 clear_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
4542 /* Send rx_mode command again if was requested */
4543 if (test_and_clear_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state))
4544 bnx2x_set_storm_rx_mode(bp);
4546 else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED,
4548 bnx2x_set_iscsi_eth_rx_mode(bp, true);
4549 else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED,
4551 bnx2x_set_iscsi_eth_rx_mode(bp, false);
4554 netif_addr_unlock_bh(bp->dev);
4557 static inline struct bnx2x_queue_sp_obj *bnx2x_cid_to_q_obj(
4558 struct bnx2x *bp, u32 cid)
4560 DP(BNX2X_MSG_SP, "retrieving fp from cid %d\n", cid);
4562 if (cid == BNX2X_FCOE_ETH_CID)
4563 return &bnx2x_fcoe(bp, q_obj);
4566 return &bnx2x_fp(bp, CID_TO_FP(cid), q_obj);
4569 static void bnx2x_eq_int(struct bnx2x *bp)
4571 u16 hw_cons, sw_cons, sw_prod;
4572 union event_ring_elem *elem;
4576 struct bnx2x_queue_sp_obj *q_obj;
4577 struct bnx2x_func_sp_obj *f_obj = &bp->func_obj;
4578 struct bnx2x_raw_obj *rss_raw = &bp->rss_conf_obj.raw;
4580 hw_cons = le16_to_cpu(*bp->eq_cons_sb);
4582 /* The hw_cos range is 1-255, 257 - the sw_cons range is 0-254, 256.
4583 * when we get the the next-page we nned to adjust so the loop
4584 * condition below will be met. The next element is the size of a
4585 * regular element and hence incrementing by 1
4587 if ((hw_cons & EQ_DESC_MAX_PAGE) == EQ_DESC_MAX_PAGE)
4590 /* This function may never run in parallel with itself for a
4591 * specific bp, thus there is no need in "paired" read memory
4594 sw_cons = bp->eq_cons;
4595 sw_prod = bp->eq_prod;
4597 DP(BNX2X_MSG_SP, "EQ: hw_cons %u sw_cons %u bp->eq_spq_left %x\n",
4598 hw_cons, sw_cons, atomic_read(&bp->eq_spq_left));
4600 for (; sw_cons != hw_cons;
4601 sw_prod = NEXT_EQ_IDX(sw_prod), sw_cons = NEXT_EQ_IDX(sw_cons)) {
4604 elem = &bp->eq_ring[EQ_DESC(sw_cons)];
4606 cid = SW_CID(elem->message.data.cfc_del_event.cid);
4607 opcode = elem->message.opcode;
4610 /* handle eq element */
4612 case EVENT_RING_OPCODE_STAT_QUERY:
4613 DP(BNX2X_MSG_SP | BNX2X_MSG_STATS,
4614 "got statistics comp event %d\n",
4616 /* nothing to do with stats comp */
4619 case EVENT_RING_OPCODE_CFC_DEL:
4620 /* handle according to cid range */
4622 * we may want to verify here that the bp state is
4626 "got delete ramrod for MULTI[%d]\n", cid);
4628 if (!bnx2x_cnic_handle_cfc_del(bp, cid, elem))
4631 q_obj = bnx2x_cid_to_q_obj(bp, cid);
4633 if (q_obj->complete_cmd(bp, q_obj, BNX2X_Q_CMD_CFC_DEL))
4640 case EVENT_RING_OPCODE_STOP_TRAFFIC:
4641 DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got STOP TRAFFIC\n");
4642 if (f_obj->complete_cmd(bp, f_obj,
4643 BNX2X_F_CMD_TX_STOP))
4645 bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_PAUSED);
4648 case EVENT_RING_OPCODE_START_TRAFFIC:
4649 DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got START TRAFFIC\n");
4650 if (f_obj->complete_cmd(bp, f_obj,
4651 BNX2X_F_CMD_TX_START))
4653 bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_RELEASED);
4655 case EVENT_RING_OPCODE_FUNCTION_START:
4656 DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
4657 "got FUNC_START ramrod\n");
4658 if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_START))
4663 case EVENT_RING_OPCODE_FUNCTION_STOP:
4664 DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
4665 "got FUNC_STOP ramrod\n");
4666 if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_STOP))
4672 switch (opcode | bp->state) {
4673 case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
4675 case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
4676 BNX2X_STATE_OPENING_WAIT4_PORT):
4677 cid = elem->message.data.eth_event.echo &
4679 DP(BNX2X_MSG_SP, "got RSS_UPDATE ramrod. CID %d\n",
4681 rss_raw->clear_pending(rss_raw);
4684 case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_OPEN):
4685 case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_DIAG):
4686 case (EVENT_RING_OPCODE_SET_MAC |
4687 BNX2X_STATE_CLOSING_WAIT4_HALT):
4688 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
4690 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
4692 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
4693 BNX2X_STATE_CLOSING_WAIT4_HALT):
4694 DP(BNX2X_MSG_SP, "got (un)set mac ramrod\n");
4695 bnx2x_handle_classification_eqe(bp, elem);
4698 case (EVENT_RING_OPCODE_MULTICAST_RULES |
4700 case (EVENT_RING_OPCODE_MULTICAST_RULES |
4702 case (EVENT_RING_OPCODE_MULTICAST_RULES |
4703 BNX2X_STATE_CLOSING_WAIT4_HALT):
4704 DP(BNX2X_MSG_SP, "got mcast ramrod\n");
4705 bnx2x_handle_mcast_eqe(bp);
4708 case (EVENT_RING_OPCODE_FILTERS_RULES |
4710 case (EVENT_RING_OPCODE_FILTERS_RULES |
4712 case (EVENT_RING_OPCODE_FILTERS_RULES |
4713 BNX2X_STATE_CLOSING_WAIT4_HALT):
4714 DP(BNX2X_MSG_SP, "got rx_mode ramrod\n");
4715 bnx2x_handle_rx_mode_eqe(bp);
4718 /* unknown event log error and continue */
4719 BNX2X_ERR("Unknown EQ event %d, bp->state 0x%x\n",
4720 elem->message.opcode, bp->state);
4726 smp_mb__before_atomic_inc();
4727 atomic_add(spqe_cnt, &bp->eq_spq_left);
4729 bp->eq_cons = sw_cons;
4730 bp->eq_prod = sw_prod;
4731 /* Make sure that above mem writes were issued towards the memory */
4734 /* update producer */
4735 bnx2x_update_eq_prod(bp, bp->eq_prod);
4738 static void bnx2x_sp_task(struct work_struct *work)
4740 struct bnx2x *bp = container_of(work, struct bnx2x, sp_task.work);
4743 status = bnx2x_update_dsb_idx(bp);
4744 /* if (status == 0) */
4745 /* BNX2X_ERR("spurious slowpath interrupt!\n"); */
4747 DP(BNX2X_MSG_SP, "got a slowpath interrupt (status 0x%x)\n", status);
4750 if (status & BNX2X_DEF_SB_ATT_IDX) {
4752 status &= ~BNX2X_DEF_SB_ATT_IDX;
4755 /* SP events: STAT_QUERY and others */
4756 if (status & BNX2X_DEF_SB_IDX) {
4758 struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);
4760 if ((!NO_FCOE(bp)) &&
4761 (bnx2x_has_rx_work(fp) || bnx2x_has_tx_work(fp))) {
4763 * Prevent local bottom-halves from running as
4764 * we are going to change the local NAPI list.
4767 napi_schedule(&bnx2x_fcoe(bp, napi));
4771 /* Handle EQ completions */
4774 bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID,
4775 le16_to_cpu(bp->def_idx), IGU_INT_NOP, 1);
4777 status &= ~BNX2X_DEF_SB_IDX;
4780 if (unlikely(status))
4781 DP(BNX2X_MSG_SP, "got an unknown interrupt! (status 0x%x)\n",
4784 bnx2x_ack_sb(bp, bp->igu_dsb_id, ATTENTION_ID,
4785 le16_to_cpu(bp->def_att_idx), IGU_INT_ENABLE, 1);
4788 irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance)
4790 struct net_device *dev = dev_instance;
4791 struct bnx2x *bp = netdev_priv(dev);
4793 bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0,
4794 IGU_INT_DISABLE, 0);
4796 #ifdef BNX2X_STOP_ON_ERROR
4797 if (unlikely(bp->panic))
4803 struct cnic_ops *c_ops;
4806 c_ops = rcu_dereference(bp->cnic_ops);
4808 c_ops->cnic_handler(bp->cnic_data, NULL);
4812 queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
4817 /* end of slow path */
4820 void bnx2x_drv_pulse(struct bnx2x *bp)
4822 SHMEM_WR(bp, func_mb[BP_FW_MB_IDX(bp)].drv_pulse_mb,
4823 bp->fw_drv_pulse_wr_seq);
4827 static void bnx2x_timer(unsigned long data)
4829 struct bnx2x *bp = (struct bnx2x *) data;
4831 if (!netif_running(bp->dev))
4834 if (!BP_NOMCP(bp)) {
4835 int mb_idx = BP_FW_MB_IDX(bp);
4839 ++bp->fw_drv_pulse_wr_seq;
4840 bp->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK;
4841 /* TBD - add SYSTEM_TIME */
4842 drv_pulse = bp->fw_drv_pulse_wr_seq;
4843 bnx2x_drv_pulse(bp);
4845 mcp_pulse = (SHMEM_RD(bp, func_mb[mb_idx].mcp_pulse_mb) &
4846 MCP_PULSE_SEQ_MASK);
4847 /* The delta between driver pulse and mcp response
4848 * should be 1 (before mcp response) or 0 (after mcp response)
4850 if ((drv_pulse != mcp_pulse) &&
4851 (drv_pulse != ((mcp_pulse + 1) & MCP_PULSE_SEQ_MASK))) {
4852 /* someone lost a heartbeat... */
4853 BNX2X_ERR("drv_pulse (0x%x) != mcp_pulse (0x%x)\n",
4854 drv_pulse, mcp_pulse);
4858 if (bp->state == BNX2X_STATE_OPEN)
4859 bnx2x_stats_handle(bp, STATS_EVENT_UPDATE);
4861 mod_timer(&bp->timer, jiffies + bp->current_interval);
4864 /* end of Statistics */
4869 * nic init service functions
4872 static inline void bnx2x_fill(struct bnx2x *bp, u32 addr, int fill, u32 len)
4875 if (!(len%4) && !(addr%4))
4876 for (i = 0; i < len; i += 4)
4877 REG_WR(bp, addr + i, fill);
4879 for (i = 0; i < len; i++)
4880 REG_WR8(bp, addr + i, fill);
4884 /* helper: writes FP SP data to FW - data_size in dwords */
4885 static inline void bnx2x_wr_fp_sb_data(struct bnx2x *bp,
4891 for (index = 0; index < data_size; index++)
4892 REG_WR(bp, BAR_CSTRORM_INTMEM +
4893 CSTORM_STATUS_BLOCK_DATA_OFFSET(fw_sb_id) +
4895 *(sb_data_p + index));
4898 static inline void bnx2x_zero_fp_sb(struct bnx2x *bp, int fw_sb_id)
4902 struct hc_status_block_data_e2 sb_data_e2;
4903 struct hc_status_block_data_e1x sb_data_e1x;
4905 /* disable the function first */
4906 if (!CHIP_IS_E1x(bp)) {
4907 memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
4908 sb_data_e2.common.state = SB_DISABLED;
4909 sb_data_e2.common.p_func.vf_valid = false;
4910 sb_data_p = (u32 *)&sb_data_e2;
4911 data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
4913 memset(&sb_data_e1x, 0,
4914 sizeof(struct hc_status_block_data_e1x));
4915 sb_data_e1x.common.state = SB_DISABLED;
4916 sb_data_e1x.common.p_func.vf_valid = false;
4917 sb_data_p = (u32 *)&sb_data_e1x;
4918 data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
4920 bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
4922 bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
4923 CSTORM_STATUS_BLOCK_OFFSET(fw_sb_id), 0,
4924 CSTORM_STATUS_BLOCK_SIZE);
4925 bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
4926 CSTORM_SYNC_BLOCK_OFFSET(fw_sb_id), 0,
4927 CSTORM_SYNC_BLOCK_SIZE);
4930 /* helper: writes SP SB data to FW */
4931 static inline void bnx2x_wr_sp_sb_data(struct bnx2x *bp,
4932 struct hc_sp_status_block_data *sp_sb_data)
4934 int func = BP_FUNC(bp);
4936 for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
4937 REG_WR(bp, BAR_CSTRORM_INTMEM +
4938 CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
4940 *((u32 *)sp_sb_data + i));
4943 static inline void bnx2x_zero_sp_sb(struct bnx2x *bp)
4945 int func = BP_FUNC(bp);
4946 struct hc_sp_status_block_data sp_sb_data;
4947 memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
4949 sp_sb_data.state = SB_DISABLED;
4950 sp_sb_data.p_func.vf_valid = false;
4952 bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
4954 bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
4955 CSTORM_SP_STATUS_BLOCK_OFFSET(func), 0,
4956 CSTORM_SP_STATUS_BLOCK_SIZE);
4957 bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
4958 CSTORM_SP_SYNC_BLOCK_OFFSET(func), 0,
4959 CSTORM_SP_SYNC_BLOCK_SIZE);
4965 void bnx2x_setup_ndsb_state_machine(struct hc_status_block_sm *hc_sm,
4966 int igu_sb_id, int igu_seg_id)
4968 hc_sm->igu_sb_id = igu_sb_id;
4969 hc_sm->igu_seg_id = igu_seg_id;
4970 hc_sm->timer_value = 0xFF;
4971 hc_sm->time_to_expire = 0xFFFFFFFF;
4975 /* allocates state machine ids. */
4977 void bnx2x_map_sb_state_machines(struct hc_index_data *index_data)
4979 /* zero out state machine indices */
4981 index_data[HC_INDEX_ETH_RX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
4984 index_data[HC_INDEX_OOO_TX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
4985 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags &= ~HC_INDEX_DATA_SM_ID;
4986 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags &= ~HC_INDEX_DATA_SM_ID;
4987 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags &= ~HC_INDEX_DATA_SM_ID;
4991 index_data[HC_INDEX_ETH_RX_CQ_CONS].flags |=
4992 SM_RX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
4995 index_data[HC_INDEX_OOO_TX_CQ_CONS].flags |=
4996 SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
4997 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags |=
4998 SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
4999 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags |=
5000 SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
5001 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags |=
5002 SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
5005 static void bnx2x_init_sb(struct bnx2x *bp, dma_addr_t mapping, int vfid,
5006 u8 vf_valid, int fw_sb_id, int igu_sb_id)
5010 struct hc_status_block_data_e2 sb_data_e2;
5011 struct hc_status_block_data_e1x sb_data_e1x;
5012 struct hc_status_block_sm *hc_sm_p;
5016 if (CHIP_INT_MODE_IS_BC(bp))
5017 igu_seg_id = HC_SEG_ACCESS_NORM;
5019 igu_seg_id = IGU_SEG_ACCESS_NORM;
5021 bnx2x_zero_fp_sb(bp, fw_sb_id);
5023 if (!CHIP_IS_E1x(bp)) {
5024 memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
5025 sb_data_e2.common.state = SB_ENABLED;
5026 sb_data_e2.common.p_func.pf_id = BP_FUNC(bp);
5027 sb_data_e2.common.p_func.vf_id = vfid;
5028 sb_data_e2.common.p_func.vf_valid = vf_valid;
5029 sb_data_e2.common.p_func.vnic_id = BP_VN(bp);
5030 sb_data_e2.common.same_igu_sb_1b = true;
5031 sb_data_e2.common.host_sb_addr.hi = U64_HI(mapping);
5032 sb_data_e2.common.host_sb_addr.lo = U64_LO(mapping);
5033 hc_sm_p = sb_data_e2.common.state_machine;
5034 sb_data_p = (u32 *)&sb_data_e2;
5035 data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
5036 bnx2x_map_sb_state_machines(sb_data_e2.index_data);
5038 memset(&sb_data_e1x, 0,
5039 sizeof(struct hc_status_block_data_e1x));
5040 sb_data_e1x.common.state = SB_ENABLED;
5041 sb_data_e1x.common.p_func.pf_id = BP_FUNC(bp);
5042 sb_data_e1x.common.p_func.vf_id = 0xff;
5043 sb_data_e1x.common.p_func.vf_valid = false;
5044 sb_data_e1x.common.p_func.vnic_id = BP_VN(bp);
5045 sb_data_e1x.common.same_igu_sb_1b = true;
5046 sb_data_e1x.common.host_sb_addr.hi = U64_HI(mapping);
5047 sb_data_e1x.common.host_sb_addr.lo = U64_LO(mapping);
5048 hc_sm_p = sb_data_e1x.common.state_machine;
5049 sb_data_p = (u32 *)&sb_data_e1x;
5050 data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
5051 bnx2x_map_sb_state_machines(sb_data_e1x.index_data);
5054 bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_RX_ID],
5055 igu_sb_id, igu_seg_id);
5056 bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_TX_ID],
5057 igu_sb_id, igu_seg_id);
5059 DP(NETIF_MSG_IFUP, "Init FW SB %d\n", fw_sb_id);
5061 /* write indecies to HW */
5062 bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
5065 static void bnx2x_update_coalesce_sb(struct bnx2x *bp, u8 fw_sb_id,
5066 u16 tx_usec, u16 rx_usec)
5068 bnx2x_update_coalesce_sb_index(bp, fw_sb_id, HC_INDEX_ETH_RX_CQ_CONS,
5070 bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
5071 HC_INDEX_ETH_TX_CQ_CONS_COS0, false,
5073 bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
5074 HC_INDEX_ETH_TX_CQ_CONS_COS1, false,
5076 bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
5077 HC_INDEX_ETH_TX_CQ_CONS_COS2, false,
5081 static void bnx2x_init_def_sb(struct bnx2x *bp)
5083 struct host_sp_status_block *def_sb = bp->def_status_blk;
5084 dma_addr_t mapping = bp->def_status_blk_mapping;
5085 int igu_sp_sb_index;
5087 int port = BP_PORT(bp);
5088 int func = BP_FUNC(bp);
5089 int reg_offset, reg_offset_en5;
5092 struct hc_sp_status_block_data sp_sb_data;
5093 memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
5095 if (CHIP_INT_MODE_IS_BC(bp)) {
5096 igu_sp_sb_index = DEF_SB_IGU_ID;
5097 igu_seg_id = HC_SEG_ACCESS_DEF;
5099 igu_sp_sb_index = bp->igu_dsb_id;
5100 igu_seg_id = IGU_SEG_ACCESS_DEF;
5104 section = ((u64)mapping) + offsetof(struct host_sp_status_block,
5105 atten_status_block);
5106 def_sb->atten_status_block.status_block_id = igu_sp_sb_index;
5110 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
5111 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
5112 reg_offset_en5 = (port ? MISC_REG_AEU_ENABLE5_FUNC_1_OUT_0 :
5113 MISC_REG_AEU_ENABLE5_FUNC_0_OUT_0);
5114 for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
5116 /* take care of sig[0]..sig[4] */
5117 for (sindex = 0; sindex < 4; sindex++)
5118 bp->attn_group[index].sig[sindex] =
5119 REG_RD(bp, reg_offset + sindex*0x4 + 0x10*index);
5121 if (!CHIP_IS_E1x(bp))
5123 * enable5 is separate from the rest of the registers,
5124 * and therefore the address skip is 4
5125 * and not 16 between the different groups
5127 bp->attn_group[index].sig[4] = REG_RD(bp,
5128 reg_offset_en5 + 0x4*index);
5130 bp->attn_group[index].sig[4] = 0;
5133 if (bp->common.int_block == INT_BLOCK_HC) {
5134 reg_offset = (port ? HC_REG_ATTN_MSG1_ADDR_L :
5135 HC_REG_ATTN_MSG0_ADDR_L);
5137 REG_WR(bp, reg_offset, U64_LO(section));
5138 REG_WR(bp, reg_offset + 4, U64_HI(section));
5139 } else if (!CHIP_IS_E1x(bp)) {
5140 REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_L, U64_LO(section));
5141 REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_H, U64_HI(section));
5144 section = ((u64)mapping) + offsetof(struct host_sp_status_block,
5147 bnx2x_zero_sp_sb(bp);
5149 sp_sb_data.state = SB_ENABLED;
5150 sp_sb_data.host_sb_addr.lo = U64_LO(section);
5151 sp_sb_data.host_sb_addr.hi = U64_HI(section);
5152 sp_sb_data.igu_sb_id = igu_sp_sb_index;
5153 sp_sb_data.igu_seg_id = igu_seg_id;
5154 sp_sb_data.p_func.pf_id = func;
5155 sp_sb_data.p_func.vnic_id = BP_VN(bp);
5156 sp_sb_data.p_func.vf_id = 0xff;
5158 bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
5160 bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0, IGU_INT_ENABLE, 0);
5163 void bnx2x_update_coalesce(struct bnx2x *bp)
5167 for_each_eth_queue(bp, i)
5168 bnx2x_update_coalesce_sb(bp, bp->fp[i].fw_sb_id,
5169 bp->tx_ticks, bp->rx_ticks);
5172 static void bnx2x_init_sp_ring(struct bnx2x *bp)
5174 spin_lock_init(&bp->spq_lock);
5175 atomic_set(&bp->cq_spq_left, MAX_SPQ_PENDING);
5177 bp->spq_prod_idx = 0;
5178 bp->dsb_sp_prod = BNX2X_SP_DSB_INDEX;
5179 bp->spq_prod_bd = bp->spq;
5180 bp->spq_last_bd = bp->spq_prod_bd + MAX_SP_DESC_CNT;
5183 static void bnx2x_init_eq_ring(struct bnx2x *bp)
5186 for (i = 1; i <= NUM_EQ_PAGES; i++) {
5187 union event_ring_elem *elem =
5188 &bp->eq_ring[EQ_DESC_CNT_PAGE * i - 1];
5190 elem->next_page.addr.hi =
5191 cpu_to_le32(U64_HI(bp->eq_mapping +
5192 BCM_PAGE_SIZE * (i % NUM_EQ_PAGES)));
5193 elem->next_page.addr.lo =
5194 cpu_to_le32(U64_LO(bp->eq_mapping +
5195 BCM_PAGE_SIZE*(i % NUM_EQ_PAGES)));
5198 bp->eq_prod = NUM_EQ_DESC;
5199 bp->eq_cons_sb = BNX2X_EQ_INDEX;
5200 /* we want a warning message before it gets rought... */
5201 atomic_set(&bp->eq_spq_left,
5202 min_t(int, MAX_SP_DESC_CNT - MAX_SPQ_PENDING, NUM_EQ_DESC) - 1);
5206 /* called with netif_addr_lock_bh() */
5207 void bnx2x_set_q_rx_mode(struct bnx2x *bp, u8 cl_id,
5208 unsigned long rx_mode_flags,
5209 unsigned long rx_accept_flags,
5210 unsigned long tx_accept_flags,
5211 unsigned long ramrod_flags)
5213 struct bnx2x_rx_mode_ramrod_params ramrod_param;
5216 memset(&ramrod_param, 0, sizeof(ramrod_param));
5218 /* Prepare ramrod parameters */
5219 ramrod_param.cid = 0;
5220 ramrod_param.cl_id = cl_id;
5221 ramrod_param.rx_mode_obj = &bp->rx_mode_obj;
5222 ramrod_param.func_id = BP_FUNC(bp);
5224 ramrod_param.pstate = &bp->sp_state;
5225 ramrod_param.state = BNX2X_FILTER_RX_MODE_PENDING;
5227 ramrod_param.rdata = bnx2x_sp(bp, rx_mode_rdata);
5228 ramrod_param.rdata_mapping = bnx2x_sp_mapping(bp, rx_mode_rdata);
5230 set_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
5232 ramrod_param.ramrod_flags = ramrod_flags;
5233 ramrod_param.rx_mode_flags = rx_mode_flags;
5235 ramrod_param.rx_accept_flags = rx_accept_flags;
5236 ramrod_param.tx_accept_flags = tx_accept_flags;
5238 rc = bnx2x_config_rx_mode(bp, &ramrod_param);
5240 BNX2X_ERR("Set rx_mode %d failed\n", bp->rx_mode);
5245 /* called with netif_addr_lock_bh() */
5246 void bnx2x_set_storm_rx_mode(struct bnx2x *bp)
5248 unsigned long rx_mode_flags = 0, ramrod_flags = 0;
5249 unsigned long rx_accept_flags = 0, tx_accept_flags = 0;
5254 /* Configure rx_mode of FCoE Queue */
5255 __set_bit(BNX2X_RX_MODE_FCOE_ETH, &rx_mode_flags);
5258 switch (bp->rx_mode) {
5259 case BNX2X_RX_MODE_NONE:
5261 * 'drop all' supersedes any accept flags that may have been
5262 * passed to the function.
5265 case BNX2X_RX_MODE_NORMAL:
5266 __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
5267 __set_bit(BNX2X_ACCEPT_MULTICAST, &rx_accept_flags);
5268 __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
5270 /* internal switching mode */
5271 __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
5272 __set_bit(BNX2X_ACCEPT_MULTICAST, &tx_accept_flags);
5273 __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
5276 case BNX2X_RX_MODE_ALLMULTI:
5277 __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
5278 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &rx_accept_flags);
5279 __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
5281 /* internal switching mode */
5282 __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
5283 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &tx_accept_flags);
5284 __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
5287 case BNX2X_RX_MODE_PROMISC:
5288 /* According to deffinition of SI mode, iface in promisc mode
5289 * should receive matched and unmatched (in resolution of port)
5292 __set_bit(BNX2X_ACCEPT_UNMATCHED, &rx_accept_flags);
5293 __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
5294 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &rx_accept_flags);
5295 __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
5297 /* internal switching mode */
5298 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &tx_accept_flags);
5299 __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
5302 __set_bit(BNX2X_ACCEPT_ALL_UNICAST, &tx_accept_flags);
5304 __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
5308 BNX2X_ERR("Unknown rx_mode: %d\n", bp->rx_mode);
5312 if (bp->rx_mode != BNX2X_RX_MODE_NONE) {
5313 __set_bit(BNX2X_ACCEPT_ANY_VLAN, &rx_accept_flags);
5314 __set_bit(BNX2X_ACCEPT_ANY_VLAN, &tx_accept_flags);
5317 __set_bit(RAMROD_RX, &ramrod_flags);
5318 __set_bit(RAMROD_TX, &ramrod_flags);
5320 bnx2x_set_q_rx_mode(bp, bp->fp->cl_id, rx_mode_flags, rx_accept_flags,
5321 tx_accept_flags, ramrod_flags);
5324 static void bnx2x_init_internal_common(struct bnx2x *bp)
5330 * In switch independent mode, the TSTORM needs to accept
5331 * packets that failed classification, since approximate match
5332 * mac addresses aren't written to NIG LLH
5334 REG_WR8(bp, BAR_TSTRORM_INTMEM +
5335 TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 2);
5336 else if (!CHIP_IS_E1(bp)) /* 57710 doesn't support MF */
5337 REG_WR8(bp, BAR_TSTRORM_INTMEM +
5338 TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 0);
5340 /* Zero this manually as its initialization is
5341 currently missing in the initTool */
5342 for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++)
5343 REG_WR(bp, BAR_USTRORM_INTMEM +
5344 USTORM_AGG_DATA_OFFSET + i * 4, 0);
5345 if (!CHIP_IS_E1x(bp)) {
5346 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_IGU_MODE_OFFSET,
5347 CHIP_INT_MODE_IS_BC(bp) ?
5348 HC_IGU_BC_MODE : HC_IGU_NBC_MODE);
5352 static void bnx2x_init_internal(struct bnx2x *bp, u32 load_code)
5354 switch (load_code) {
5355 case FW_MSG_CODE_DRV_LOAD_COMMON:
5356 case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP:
5357 bnx2x_init_internal_common(bp);
5360 case FW_MSG_CODE_DRV_LOAD_PORT:
5364 case FW_MSG_CODE_DRV_LOAD_FUNCTION:
5365 /* internal memory per function is
5366 initialized inside bnx2x_pf_init */
5370 BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code);
5375 static inline u8 bnx2x_fp_igu_sb_id(struct bnx2x_fastpath *fp)
5377 return fp->bp->igu_base_sb + fp->index + CNIC_PRESENT;
5380 static inline u8 bnx2x_fp_fw_sb_id(struct bnx2x_fastpath *fp)
5382 return fp->bp->base_fw_ndsb + fp->index + CNIC_PRESENT;
5385 static inline u8 bnx2x_fp_cl_id(struct bnx2x_fastpath *fp)
5387 if (CHIP_IS_E1x(fp->bp))
5388 return BP_L_ID(fp->bp) + fp->index;
5389 else /* We want Client ID to be the same as IGU SB ID for 57712 */
5390 return bnx2x_fp_igu_sb_id(fp);
5393 static void bnx2x_init_eth_fp(struct bnx2x *bp, int fp_idx)
5395 struct bnx2x_fastpath *fp = &bp->fp[fp_idx];
5397 unsigned long q_type = 0;
5398 u32 cids[BNX2X_MULTI_TX_COS] = { 0 };
5399 fp->rx_queue = fp_idx;
5401 fp->cl_id = bnx2x_fp_cl_id(fp);
5402 fp->fw_sb_id = bnx2x_fp_fw_sb_id(fp);
5403 fp->igu_sb_id = bnx2x_fp_igu_sb_id(fp);
5404 /* qZone id equals to FW (per path) client id */
5405 fp->cl_qzone_id = bnx2x_fp_qzone_id(fp);
5408 fp->ustorm_rx_prods_offset = bnx2x_rx_ustorm_prods_offset(fp);
5410 /* Setup SB indicies */
5411 fp->rx_cons_sb = BNX2X_RX_SB_INDEX;
5413 /* Configure Queue State object */
5414 __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
5415 __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
5417 BUG_ON(fp->max_cos > BNX2X_MULTI_TX_COS);
5420 for_each_cos_in_tx_queue(fp, cos) {
5421 bnx2x_init_txdata(bp, &fp->txdata[cos],
5422 CID_COS_TO_TX_ONLY_CID(fp->cid, cos),
5423 FP_COS_TO_TXQ(fp, cos),
5424 BNX2X_TX_SB_INDEX_BASE + cos);
5425 cids[cos] = fp->txdata[cos].cid;
5428 bnx2x_init_queue_obj(bp, &fp->q_obj, fp->cl_id, cids, fp->max_cos,
5429 BP_FUNC(bp), bnx2x_sp(bp, q_rdata),
5430 bnx2x_sp_mapping(bp, q_rdata), q_type);
5433 * Configure classification DBs: Always enable Tx switching
5435 bnx2x_init_vlan_mac_fp_objs(fp, BNX2X_OBJ_TYPE_RX_TX);
5437 DP(NETIF_MSG_IFUP, "queue[%d]: bnx2x_init_sb(%p,%p) cl_id %d fw_sb %d igu_sb %d\n",
5438 fp_idx, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id,
5440 bnx2x_init_sb(bp, fp->status_blk_mapping, BNX2X_VF_ID_INVALID, false,
5441 fp->fw_sb_id, fp->igu_sb_id);
5443 bnx2x_update_fpsb_idx(fp);
5446 void bnx2x_nic_init(struct bnx2x *bp, u32 load_code)
5450 for_each_eth_queue(bp, i)
5451 bnx2x_init_eth_fp(bp, i);
5454 bnx2x_init_fcoe_fp(bp);
5456 bnx2x_init_sb(bp, bp->cnic_sb_mapping,
5457 BNX2X_VF_ID_INVALID, false,
5458 bnx2x_cnic_fw_sb_id(bp), bnx2x_cnic_igu_sb_id(bp));
5462 /* Initialize MOD_ABS interrupts */
5463 bnx2x_init_mod_abs_int(bp, &bp->link_vars, bp->common.chip_id,
5464 bp->common.shmem_base, bp->common.shmem2_base,
5466 /* ensure status block indices were read */
5469 bnx2x_init_def_sb(bp);
5470 bnx2x_update_dsb_idx(bp);
5471 bnx2x_init_rx_rings(bp);
5472 bnx2x_init_tx_rings(bp);
5473 bnx2x_init_sp_ring(bp);
5474 bnx2x_init_eq_ring(bp);
5475 bnx2x_init_internal(bp, load_code);
5477 bnx2x_stats_init(bp);
5479 /* flush all before enabling interrupts */
5483 bnx2x_int_enable(bp);
5485 /* Check for SPIO5 */
5486 bnx2x_attn_int_deasserted0(bp,
5487 REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + BP_PORT(bp)*4) &
5488 AEU_INPUTS_ATTN_BITS_SPIO5);
5491 /* end of nic init */
5494 * gzip service functions
5497 static int bnx2x_gunzip_init(struct bnx2x *bp)
5499 bp->gunzip_buf = dma_alloc_coherent(&bp->pdev->dev, FW_BUF_SIZE,
5500 &bp->gunzip_mapping, GFP_KERNEL);
5501 if (bp->gunzip_buf == NULL)
5504 bp->strm = kmalloc(sizeof(*bp->strm), GFP_KERNEL);
5505 if (bp->strm == NULL)
5508 bp->strm->workspace = vmalloc(zlib_inflate_workspacesize());
5509 if (bp->strm->workspace == NULL)
5519 dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
5520 bp->gunzip_mapping);
5521 bp->gunzip_buf = NULL;
5524 BNX2X_ERR("Cannot allocate firmware buffer for un-compression\n");
5528 static void bnx2x_gunzip_end(struct bnx2x *bp)
5531 vfree(bp->strm->workspace);
5536 if (bp->gunzip_buf) {
5537 dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
5538 bp->gunzip_mapping);
5539 bp->gunzip_buf = NULL;
5543 static int bnx2x_gunzip(struct bnx2x *bp, const u8 *zbuf, int len)
5547 /* check gzip header */
5548 if ((zbuf[0] != 0x1f) || (zbuf[1] != 0x8b) || (zbuf[2] != Z_DEFLATED)) {
5549 BNX2X_ERR("Bad gzip header\n");
5557 if (zbuf[3] & FNAME)
5558 while ((zbuf[n++] != 0) && (n < len));
5560 bp->strm->next_in = (typeof(bp->strm->next_in))zbuf + n;
5561 bp->strm->avail_in = len - n;
5562 bp->strm->next_out = bp->gunzip_buf;
5563 bp->strm->avail_out = FW_BUF_SIZE;
5565 rc = zlib_inflateInit2(bp->strm, -MAX_WBITS);
5569 rc = zlib_inflate(bp->strm, Z_FINISH);
5570 if ((rc != Z_OK) && (rc != Z_STREAM_END))
5571 netdev_err(bp->dev, "Firmware decompression error: %s\n",
5574 bp->gunzip_outlen = (FW_BUF_SIZE - bp->strm->avail_out);
5575 if (bp->gunzip_outlen & 0x3)
5577 "Firmware decompression error: gunzip_outlen (%d) not aligned\n",
5579 bp->gunzip_outlen >>= 2;
5581 zlib_inflateEnd(bp->strm);
5583 if (rc == Z_STREAM_END)
5589 /* nic load/unload */
5592 * General service functions
5595 /* send a NIG loopback debug packet */
5596 static void bnx2x_lb_pckt(struct bnx2x *bp)
5600 /* Ethernet source and destination addresses */
5601 wb_write[0] = 0x55555555;
5602 wb_write[1] = 0x55555555;
5603 wb_write[2] = 0x20; /* SOP */
5604 REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
5606 /* NON-IP protocol */
5607 wb_write[0] = 0x09000000;
5608 wb_write[1] = 0x55555555;
5609 wb_write[2] = 0x10; /* EOP, eop_bvalid = 0 */
5610 REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
5613 /* some of the internal memories
5614 * are not directly readable from the driver
5615 * to test them we send debug packets
5617 static int bnx2x_int_mem_test(struct bnx2x *bp)
5623 if (CHIP_REV_IS_FPGA(bp))
5625 else if (CHIP_REV_IS_EMUL(bp))
5630 /* Disable inputs of parser neighbor blocks */
5631 REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
5632 REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
5633 REG_WR(bp, CFC_REG_DEBUG0, 0x1);
5634 REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
5636 /* Write 0 to parser credits for CFC search request */
5637 REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
5639 /* send Ethernet packet */
5642 /* TODO do i reset NIG statistic? */
5643 /* Wait until NIG register shows 1 packet of size 0x10 */
5644 count = 1000 * factor;
5647 bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
5648 val = *bnx2x_sp(bp, wb_data[0]);
5656 BNX2X_ERR("NIG timeout val = 0x%x\n", val);
5660 /* Wait until PRS register shows 1 packet */
5661 count = 1000 * factor;
5663 val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
5671 BNX2X_ERR("PRS timeout val = 0x%x\n", val);
5675 /* Reset and init BRB, PRS */
5676 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
5678 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
5680 bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
5681 bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
5683 DP(NETIF_MSG_HW, "part2\n");
5685 /* Disable inputs of parser neighbor blocks */
5686 REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
5687 REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
5688 REG_WR(bp, CFC_REG_DEBUG0, 0x1);
5689 REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
5691 /* Write 0 to parser credits for CFC search request */
5692 REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
5694 /* send 10 Ethernet packets */
5695 for (i = 0; i < 10; i++)
5698 /* Wait until NIG register shows 10 + 1
5699 packets of size 11*0x10 = 0xb0 */
5700 count = 1000 * factor;
5703 bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
5704 val = *bnx2x_sp(bp, wb_data[0]);
5712 BNX2X_ERR("NIG timeout val = 0x%x\n", val);
5716 /* Wait until PRS register shows 2 packets */
5717 val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
5719 BNX2X_ERR("PRS timeout val = 0x%x\n", val);
5721 /* Write 1 to parser credits for CFC search request */
5722 REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x1);
5724 /* Wait until PRS register shows 3 packets */
5725 msleep(10 * factor);
5726 /* Wait until NIG register shows 1 packet of size 0x10 */
5727 val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
5729 BNX2X_ERR("PRS timeout val = 0x%x\n", val);
5731 /* clear NIG EOP FIFO */
5732 for (i = 0; i < 11; i++)
5733 REG_RD(bp, NIG_REG_INGRESS_EOP_LB_FIFO);
5734 val = REG_RD(bp, NIG_REG_INGRESS_EOP_LB_EMPTY);
5736 BNX2X_ERR("clear of NIG failed\n");
5740 /* Reset and init BRB, PRS, NIG */
5741 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
5743 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
5745 bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
5746 bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
5749 REG_WR(bp, PRS_REG_NIC_MODE, 1);
5752 /* Enable inputs of parser neighbor blocks */
5753 REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x7fffffff);
5754 REG_WR(bp, TCM_REG_PRS_IFEN, 0x1);
5755 REG_WR(bp, CFC_REG_DEBUG0, 0x0);
5756 REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x1);
5758 DP(NETIF_MSG_HW, "done\n");
5763 static void bnx2x_enable_blocks_attention(struct bnx2x *bp)
5765 REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
5766 if (!CHIP_IS_E1x(bp))
5767 REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0x40);
5769 REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0);
5770 REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
5771 REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
5773 * mask read length error interrupts in brb for parser
5774 * (parsing unit and 'checksum and crc' unit)
5775 * these errors are legal (PU reads fixed length and CAC can cause
5776 * read length error on truncated packets)
5778 REG_WR(bp, BRB1_REG_BRB1_INT_MASK, 0xFC00);
5779 REG_WR(bp, QM_REG_QM_INT_MASK, 0);
5780 REG_WR(bp, TM_REG_TM_INT_MASK, 0);
5781 REG_WR(bp, XSDM_REG_XSDM_INT_MASK_0, 0);
5782 REG_WR(bp, XSDM_REG_XSDM_INT_MASK_1, 0);
5783 REG_WR(bp, XCM_REG_XCM_INT_MASK, 0);
5784 /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_0, 0); */
5785 /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_1, 0); */
5786 REG_WR(bp, USDM_REG_USDM_INT_MASK_0, 0);
5787 REG_WR(bp, USDM_REG_USDM_INT_MASK_1, 0);
5788 REG_WR(bp, UCM_REG_UCM_INT_MASK, 0);
5789 /* REG_WR(bp, USEM_REG_USEM_INT_MASK_0, 0); */
5790 /* REG_WR(bp, USEM_REG_USEM_INT_MASK_1, 0); */
5791 REG_WR(bp, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0);
5792 REG_WR(bp, CSDM_REG_CSDM_INT_MASK_0, 0);
5793 REG_WR(bp, CSDM_REG_CSDM_INT_MASK_1, 0);
5794 REG_WR(bp, CCM_REG_CCM_INT_MASK, 0);
5795 /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_0, 0); */
5796 /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_1, 0); */
5798 if (CHIP_REV_IS_FPGA(bp))
5799 REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, 0x580000);
5800 else if (!CHIP_IS_E1x(bp))
5801 REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0,
5802 (PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_OF
5803 | PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_AFT
5804 | PXP2_PXP2_INT_MASK_0_REG_PGL_PCIE_ATTN
5805 | PXP2_PXP2_INT_MASK_0_REG_PGL_READ_BLOCKED
5806 | PXP2_PXP2_INT_MASK_0_REG_PGL_WRITE_BLOCKED));
5808 REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, 0x480000);
5809 REG_WR(bp, TSDM_REG_TSDM_INT_MASK_0, 0);
5810 REG_WR(bp, TSDM_REG_TSDM_INT_MASK_1, 0);
5811 REG_WR(bp, TCM_REG_TCM_INT_MASK, 0);
5812 /* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_0, 0); */
5814 if (!CHIP_IS_E1x(bp))
5815 /* enable VFC attentions: bits 11 and 12, bits 31:13 reserved */
5816 REG_WR(bp, TSEM_REG_TSEM_INT_MASK_1, 0x07ff);
5818 REG_WR(bp, CDU_REG_CDU_INT_MASK, 0);
5819 REG_WR(bp, DMAE_REG_DMAE_INT_MASK, 0);
5820 /* REG_WR(bp, MISC_REG_MISC_INT_MASK, 0); */
5821 REG_WR(bp, PBF_REG_PBF_INT_MASK, 0x18); /* bit 3,4 masked */
5824 static void bnx2x_reset_common(struct bnx2x *bp)
5829 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
5832 if (CHIP_IS_E3(bp)) {
5833 val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
5834 val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
5837 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, val);
5840 static void bnx2x_setup_dmae(struct bnx2x *bp)
5843 spin_lock_init(&bp->dmae_lock);
5846 static void bnx2x_init_pxp(struct bnx2x *bp)
5849 int r_order, w_order;
5851 pci_read_config_word(bp->pdev,
5852 pci_pcie_cap(bp->pdev) + PCI_EXP_DEVCTL, &devctl);
5853 DP(NETIF_MSG_HW, "read 0x%x from devctl\n", devctl);
5854 w_order = ((devctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5);
5856 r_order = ((devctl & PCI_EXP_DEVCTL_READRQ) >> 12);
5858 DP(NETIF_MSG_HW, "force read order to %d\n", bp->mrrs);
5862 bnx2x_init_pxp_arb(bp, r_order, w_order);
5865 static void bnx2x_setup_fan_failure_detection(struct bnx2x *bp)
5875 val = SHMEM_RD(bp, dev_info.shared_hw_config.config2) &
5876 SHARED_HW_CFG_FAN_FAILURE_MASK;
5878 if (val == SHARED_HW_CFG_FAN_FAILURE_ENABLED)
5882 * The fan failure mechanism is usually related to the PHY type since
5883 * the power consumption of the board is affected by the PHY. Currently,
5884 * fan is required for most designs with SFX7101, BCM8727 and BCM8481.
5886 else if (val == SHARED_HW_CFG_FAN_FAILURE_PHY_TYPE)
5887 for (port = PORT_0; port < PORT_MAX; port++) {
5889 bnx2x_fan_failure_det_req(
5891 bp->common.shmem_base,
5892 bp->common.shmem2_base,
5896 DP(NETIF_MSG_HW, "fan detection setting: %d\n", is_required);
5898 if (is_required == 0)
5901 /* Fan failure is indicated by SPIO 5 */
5902 bnx2x_set_spio(bp, MISC_REGISTERS_SPIO_5,
5903 MISC_REGISTERS_SPIO_INPUT_HI_Z);
5905 /* set to active low mode */
5906 val = REG_RD(bp, MISC_REG_SPIO_INT);
5907 val |= ((1 << MISC_REGISTERS_SPIO_5) <<
5908 MISC_REGISTERS_SPIO_INT_OLD_SET_POS);
5909 REG_WR(bp, MISC_REG_SPIO_INT, val);
5911 /* enable interrupt to signal the IGU */
5912 val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
5913 val |= (1 << MISC_REGISTERS_SPIO_5);
5914 REG_WR(bp, MISC_REG_SPIO_EVENT_EN, val);
5917 static void bnx2x_pretend_func(struct bnx2x *bp, u8 pretend_func_num)
5923 if (CHIP_IS_E1H(bp) && (pretend_func_num >= E1H_FUNC_MAX))
5926 switch (BP_ABS_FUNC(bp)) {
5928 offset = PXP2_REG_PGL_PRETEND_FUNC_F0;
5931 offset = PXP2_REG_PGL_PRETEND_FUNC_F1;
5934 offset = PXP2_REG_PGL_PRETEND_FUNC_F2;
5937 offset = PXP2_REG_PGL_PRETEND_FUNC_F3;
5940 offset = PXP2_REG_PGL_PRETEND_FUNC_F4;
5943 offset = PXP2_REG_PGL_PRETEND_FUNC_F5;
5946 offset = PXP2_REG_PGL_PRETEND_FUNC_F6;
5949 offset = PXP2_REG_PGL_PRETEND_FUNC_F7;
5955 REG_WR(bp, offset, pretend_func_num);
5957 DP(NETIF_MSG_HW, "Pretending to func %d\n", pretend_func_num);
5960 void bnx2x_pf_disable(struct bnx2x *bp)
5962 u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
5963 val &= ~IGU_PF_CONF_FUNC_EN;
5965 REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
5966 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
5967 REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 0);
5970 static inline void bnx2x__common_init_phy(struct bnx2x *bp)
5972 u32 shmem_base[2], shmem2_base[2];
5973 shmem_base[0] = bp->common.shmem_base;
5974 shmem2_base[0] = bp->common.shmem2_base;
5975 if (!CHIP_IS_E1x(bp)) {
5977 SHMEM2_RD(bp, other_shmem_base_addr);
5979 SHMEM2_RD(bp, other_shmem2_base_addr);
5981 bnx2x_acquire_phy_lock(bp);
5982 bnx2x_common_init_phy(bp, shmem_base, shmem2_base,
5983 bp->common.chip_id);
5984 bnx2x_release_phy_lock(bp);
5988 * bnx2x_init_hw_common - initialize the HW at the COMMON phase.
5990 * @bp: driver handle
5992 static int bnx2x_init_hw_common(struct bnx2x *bp)
5996 DP(NETIF_MSG_HW, "starting common init func %d\n", BP_ABS_FUNC(bp));
5999 * take the UNDI lock to protect undi_unload flow from accessing
6000 * registers while we're resetting the chip
6002 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
6004 bnx2x_reset_common(bp);
6005 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0xffffffff);
6008 if (CHIP_IS_E3(bp)) {
6009 val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
6010 val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
6012 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, val);
6014 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
6016 bnx2x_init_block(bp, BLOCK_MISC, PHASE_COMMON);
6018 if (!CHIP_IS_E1x(bp)) {
6022 * 4-port mode or 2-port mode we need to turn of master-enable
6023 * for everyone, after that, turn it back on for self.
6024 * so, we disregard multi-function or not, and always disable
6025 * for all functions on the given path, this means 0,2,4,6 for
6026 * path 0 and 1,3,5,7 for path 1
6028 for (abs_func_id = BP_PATH(bp);
6029 abs_func_id < E2_FUNC_MAX*2; abs_func_id += 2) {
6030 if (abs_func_id == BP_ABS_FUNC(bp)) {
6032 PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER,
6037 bnx2x_pretend_func(bp, abs_func_id);
6038 /* clear pf enable */
6039 bnx2x_pf_disable(bp);
6040 bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
6044 bnx2x_init_block(bp, BLOCK_PXP, PHASE_COMMON);
6045 if (CHIP_IS_E1(bp)) {
6046 /* enable HW interrupt from PXP on USDM overflow
6047 bit 16 on INT_MASK_0 */
6048 REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
6051 bnx2x_init_block(bp, BLOCK_PXP2, PHASE_COMMON);
6055 REG_WR(bp, PXP2_REG_RQ_QM_ENDIAN_M, 1);
6056 REG_WR(bp, PXP2_REG_RQ_TM_ENDIAN_M, 1);
6057 REG_WR(bp, PXP2_REG_RQ_SRC_ENDIAN_M, 1);
6058 REG_WR(bp, PXP2_REG_RQ_CDU_ENDIAN_M, 1);
6059 REG_WR(bp, PXP2_REG_RQ_DBG_ENDIAN_M, 1);
6060 /* make sure this value is 0 */
6061 REG_WR(bp, PXP2_REG_RQ_HC_ENDIAN_M, 0);
6063 /* REG_WR(bp, PXP2_REG_RD_PBF_SWAP_MODE, 1); */
6064 REG_WR(bp, PXP2_REG_RD_QM_SWAP_MODE, 1);
6065 REG_WR(bp, PXP2_REG_RD_TM_SWAP_MODE, 1);
6066 REG_WR(bp, PXP2_REG_RD_SRC_SWAP_MODE, 1);
6067 REG_WR(bp, PXP2_REG_RD_CDURD_SWAP_MODE, 1);
6070 bnx2x_ilt_init_page_size(bp, INITOP_SET);
6072 if (CHIP_REV_IS_FPGA(bp) && CHIP_IS_E1H(bp))
6073 REG_WR(bp, PXP2_REG_PGL_TAGS_LIMIT, 0x1);
6075 /* let the HW do it's magic ... */
6077 /* finish PXP init */
6078 val = REG_RD(bp, PXP2_REG_RQ_CFG_DONE);
6080 BNX2X_ERR("PXP2 CFG failed\n");
6083 val = REG_RD(bp, PXP2_REG_RD_INIT_DONE);
6085 BNX2X_ERR("PXP2 RD_INIT failed\n");
6089 /* Timers bug workaround E2 only. We need to set the entire ILT to
6090 * have entries with value "0" and valid bit on.
6091 * This needs to be done by the first PF that is loaded in a path
6092 * (i.e. common phase)
6094 if (!CHIP_IS_E1x(bp)) {
6095 /* In E2 there is a bug in the timers block that can cause function 6 / 7
6096 * (i.e. vnic3) to start even if it is marked as "scan-off".
6097 * This occurs when a different function (func2,3) is being marked
6098 * as "scan-off". Real-life scenario for example: if a driver is being
6099 * load-unloaded while func6,7 are down. This will cause the timer to access
6100 * the ilt, translate to a logical address and send a request to read/write.
6101 * Since the ilt for the function that is down is not valid, this will cause
6102 * a translation error which is unrecoverable.
6103 * The Workaround is intended to make sure that when this happens nothing fatal
6104 * will occur. The workaround:
6105 * 1. First PF driver which loads on a path will:
6106 * a. After taking the chip out of reset, by using pretend,
6107 * it will write "0" to the following registers of
6109 * REG_WR(pdev, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
6110 * REG_WR(pdev, CFC_REG_WEAK_ENABLE_PF,0);
6111 * REG_WR(pdev, CFC_REG_STRONG_ENABLE_PF,0);
6112 * And for itself it will write '1' to
6113 * PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER to enable
6114 * dmae-operations (writing to pram for example.)
6115 * note: can be done for only function 6,7 but cleaner this
6117 * b. Write zero+valid to the entire ILT.
6118 * c. Init the first_timers_ilt_entry, last_timers_ilt_entry of
6119 * VNIC3 (of that port). The range allocated will be the
6120 * entire ILT. This is needed to prevent ILT range error.
6121 * 2. Any PF driver load flow:
6122 * a. ILT update with the physical addresses of the allocated
6124 * b. Wait 20msec. - note that this timeout is needed to make
6125 * sure there are no requests in one of the PXP internal
6126 * queues with "old" ILT addresses.
6127 * c. PF enable in the PGLC.
6128 * d. Clear the was_error of the PF in the PGLC. (could have
6129 * occured while driver was down)
6130 * e. PF enable in the CFC (WEAK + STRONG)
6131 * f. Timers scan enable
6132 * 3. PF driver unload flow:
6133 * a. Clear the Timers scan_en.
6134 * b. Polling for scan_on=0 for that PF.
6135 * c. Clear the PF enable bit in the PXP.
6136 * d. Clear the PF enable in the CFC (WEAK + STRONG)
6137 * e. Write zero+valid to all ILT entries (The valid bit must
6139 * f. If this is VNIC 3 of a port then also init
6140 * first_timers_ilt_entry to zero and last_timers_ilt_entry
6141 * to the last enrty in the ILT.
6144 * Currently the PF error in the PGLC is non recoverable.
6145 * In the future the there will be a recovery routine for this error.
6146 * Currently attention is masked.
6147 * Having an MCP lock on the load/unload process does not guarantee that
6148 * there is no Timer disable during Func6/7 enable. This is because the
6149 * Timers scan is currently being cleared by the MCP on FLR.
6150 * Step 2.d can be done only for PF6/7 and the driver can also check if
6151 * there is error before clearing it. But the flow above is simpler and
6153 * All ILT entries are written by zero+valid and not just PF6/7
6154 * ILT entries since in the future the ILT entries allocation for
6155 * PF-s might be dynamic.
6157 struct ilt_client_info ilt_cli;
6158 struct bnx2x_ilt ilt;
6159 memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
6160 memset(&ilt, 0, sizeof(struct bnx2x_ilt));
6162 /* initialize dummy TM client */
6164 ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
6165 ilt_cli.client_num = ILT_CLIENT_TM;
6167 /* Step 1: set zeroes to all ilt page entries with valid bit on
6168 * Step 2: set the timers first/last ilt entry to point
6169 * to the entire range to prevent ILT range error for 3rd/4th
6170 * vnic (this code assumes existance of the vnic)
6172 * both steps performed by call to bnx2x_ilt_client_init_op()
6173 * with dummy TM client
6175 * we must use pretend since PXP2_REG_RQ_##blk##_FIRST_ILT
6176 * and his brother are split registers
6178 bnx2x_pretend_func(bp, (BP_PATH(bp) + 6));
6179 bnx2x_ilt_client_init_op_ilt(bp, &ilt, &ilt_cli, INITOP_CLEAR);
6180 bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
6182 REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN, BNX2X_PXP_DRAM_ALIGN);
6183 REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_RD, BNX2X_PXP_DRAM_ALIGN);
6184 REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_SEL, 1);
6188 REG_WR(bp, PXP2_REG_RQ_DISABLE_INPUTS, 0);
6189 REG_WR(bp, PXP2_REG_RD_DISABLE_INPUTS, 0);
6191 if (!CHIP_IS_E1x(bp)) {
6192 int factor = CHIP_REV_IS_EMUL(bp) ? 1000 :
6193 (CHIP_REV_IS_FPGA(bp) ? 400 : 0);
6194 bnx2x_init_block(bp, BLOCK_PGLUE_B, PHASE_COMMON);
6196 bnx2x_init_block(bp, BLOCK_ATC, PHASE_COMMON);
6198 /* let the HW do it's magic ... */
6201 val = REG_RD(bp, ATC_REG_ATC_INIT_DONE);
6202 } while (factor-- && (val != 1));
6205 BNX2X_ERR("ATC_INIT failed\n");
6210 bnx2x_init_block(bp, BLOCK_DMAE, PHASE_COMMON);
6212 /* clean the DMAE memory */
6214 bnx2x_init_fill(bp, TSEM_REG_PRAM, 0, 8, 1);
6216 bnx2x_init_block(bp, BLOCK_TCM, PHASE_COMMON);
6218 bnx2x_init_block(bp, BLOCK_UCM, PHASE_COMMON);
6220 bnx2x_init_block(bp, BLOCK_CCM, PHASE_COMMON);
6222 bnx2x_init_block(bp, BLOCK_XCM, PHASE_COMMON);
6224 bnx2x_read_dmae(bp, XSEM_REG_PASSIVE_BUFFER, 3);
6225 bnx2x_read_dmae(bp, CSEM_REG_PASSIVE_BUFFER, 3);
6226 bnx2x_read_dmae(bp, TSEM_REG_PASSIVE_BUFFER, 3);
6227 bnx2x_read_dmae(bp, USEM_REG_PASSIVE_BUFFER, 3);
6229 bnx2x_init_block(bp, BLOCK_QM, PHASE_COMMON);
6232 /* QM queues pointers table */
6233 bnx2x_qm_init_ptr_table(bp, bp->qm_cid_count, INITOP_SET);
6235 /* soft reset pulse */
6236 REG_WR(bp, QM_REG_SOFT_RESET, 1);
6237 REG_WR(bp, QM_REG_SOFT_RESET, 0);
6240 bnx2x_init_block(bp, BLOCK_TM, PHASE_COMMON);
6243 bnx2x_init_block(bp, BLOCK_DORQ, PHASE_COMMON);
6244 REG_WR(bp, DORQ_REG_DPM_CID_OFST, BNX2X_DB_SHIFT);
6245 if (!CHIP_REV_IS_SLOW(bp))
6246 /* enable hw interrupt from doorbell Q */
6247 REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
6249 bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
6251 bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
6252 REG_WR(bp, PRS_REG_A_PRSU_20, 0xf);
6254 if (!CHIP_IS_E1(bp))
6255 REG_WR(bp, PRS_REG_E1HOV_MODE, bp->path_has_ovlan);
6257 if (!CHIP_IS_E1x(bp) && !CHIP_IS_E3B0(bp))
6258 /* Bit-map indicating which L2 hdrs may appear
6259 * after the basic Ethernet header
6261 REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC,
6262 bp->path_has_ovlan ? 7 : 6);
6264 bnx2x_init_block(bp, BLOCK_TSDM, PHASE_COMMON);
6265 bnx2x_init_block(bp, BLOCK_CSDM, PHASE_COMMON);
6266 bnx2x_init_block(bp, BLOCK_USDM, PHASE_COMMON);
6267 bnx2x_init_block(bp, BLOCK_XSDM, PHASE_COMMON);
6269 if (!CHIP_IS_E1x(bp)) {
6270 /* reset VFC memories */
6271 REG_WR(bp, TSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
6272 VFC_MEMORIES_RST_REG_CAM_RST |
6273 VFC_MEMORIES_RST_REG_RAM_RST);
6274 REG_WR(bp, XSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
6275 VFC_MEMORIES_RST_REG_CAM_RST |
6276 VFC_MEMORIES_RST_REG_RAM_RST);
6281 bnx2x_init_block(bp, BLOCK_TSEM, PHASE_COMMON);
6282 bnx2x_init_block(bp, BLOCK_USEM, PHASE_COMMON);
6283 bnx2x_init_block(bp, BLOCK_CSEM, PHASE_COMMON);
6284 bnx2x_init_block(bp, BLOCK_XSEM, PHASE_COMMON);
6287 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
6289 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
6292 bnx2x_init_block(bp, BLOCK_UPB, PHASE_COMMON);
6293 bnx2x_init_block(bp, BLOCK_XPB, PHASE_COMMON);
6294 bnx2x_init_block(bp, BLOCK_PBF, PHASE_COMMON);
6296 if (!CHIP_IS_E1x(bp))
6297 REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC,
6298 bp->path_has_ovlan ? 7 : 6);
6300 REG_WR(bp, SRC_REG_SOFT_RST, 1);
6302 bnx2x_init_block(bp, BLOCK_SRC, PHASE_COMMON);
6305 REG_WR(bp, SRC_REG_KEYSEARCH_0, 0x63285672);
6306 REG_WR(bp, SRC_REG_KEYSEARCH_1, 0x24b8f2cc);
6307 REG_WR(bp, SRC_REG_KEYSEARCH_2, 0x223aef9b);
6308 REG_WR(bp, SRC_REG_KEYSEARCH_3, 0x26001e3a);
6309 REG_WR(bp, SRC_REG_KEYSEARCH_4, 0x7ae91116);
6310 REG_WR(bp, SRC_REG_KEYSEARCH_5, 0x5ce5230b);
6311 REG_WR(bp, SRC_REG_KEYSEARCH_6, 0x298d8adf);
6312 REG_WR(bp, SRC_REG_KEYSEARCH_7, 0x6eb0ff09);
6313 REG_WR(bp, SRC_REG_KEYSEARCH_8, 0x1830f82f);
6314 REG_WR(bp, SRC_REG_KEYSEARCH_9, 0x01e46be7);
6316 REG_WR(bp, SRC_REG_SOFT_RST, 0);
6318 if (sizeof(union cdu_context) != 1024)
6319 /* we currently assume that a context is 1024 bytes */
6320 dev_alert(&bp->pdev->dev,
6321 "please adjust the size of cdu_context(%ld)\n",
6322 (long)sizeof(union cdu_context));
6324 bnx2x_init_block(bp, BLOCK_CDU, PHASE_COMMON);
6325 val = (4 << 24) + (0 << 12) + 1024;
6326 REG_WR(bp, CDU_REG_CDU_GLOBAL_PARAMS, val);
6328 bnx2x_init_block(bp, BLOCK_CFC, PHASE_COMMON);
6329 REG_WR(bp, CFC_REG_INIT_REG, 0x7FF);
6330 /* enable context validation interrupt from CFC */
6331 REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
6333 /* set the thresholds to prevent CFC/CDU race */
6334 REG_WR(bp, CFC_REG_DEBUG0, 0x20020000);
6336 bnx2x_init_block(bp, BLOCK_HC, PHASE_COMMON);
6338 if (!CHIP_IS_E1x(bp) && BP_NOMCP(bp))
6339 REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x36);
6341 bnx2x_init_block(bp, BLOCK_IGU, PHASE_COMMON);
6342 bnx2x_init_block(bp, BLOCK_MISC_AEU, PHASE_COMMON);
6344 /* Reset PCIE errors for debug */
6345 REG_WR(bp, 0x2814, 0xffffffff);
6346 REG_WR(bp, 0x3820, 0xffffffff);
6348 if (!CHIP_IS_E1x(bp)) {
6349 REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_CONTROL_5,
6350 (PXPCS_TL_CONTROL_5_ERR_UNSPPORT1 |
6351 PXPCS_TL_CONTROL_5_ERR_UNSPPORT));
6352 REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC345_STAT,
6353 (PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT4 |
6354 PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT3 |
6355 PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT2));
6356 REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC678_STAT,
6357 (PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT7 |
6358 PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT6 |
6359 PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT5));
6362 bnx2x_init_block(bp, BLOCK_NIG, PHASE_COMMON);
6363 if (!CHIP_IS_E1(bp)) {
6364 /* in E3 this done in per-port section */
6365 if (!CHIP_IS_E3(bp))
6366 REG_WR(bp, NIG_REG_LLH_MF_MODE, IS_MF(bp));
6368 if (CHIP_IS_E1H(bp))
6369 /* not applicable for E2 (and above ...) */
6370 REG_WR(bp, NIG_REG_LLH_E1HOV_MODE, IS_MF_SD(bp));
6372 if (CHIP_REV_IS_SLOW(bp))
6375 /* finish CFC init */
6376 val = reg_poll(bp, CFC_REG_LL_INIT_DONE, 1, 100, 10);
6378 BNX2X_ERR("CFC LL_INIT failed\n");
6381 val = reg_poll(bp, CFC_REG_AC_INIT_DONE, 1, 100, 10);
6383 BNX2X_ERR("CFC AC_INIT failed\n");
6386 val = reg_poll(bp, CFC_REG_CAM_INIT_DONE, 1, 100, 10);
6388 BNX2X_ERR("CFC CAM_INIT failed\n");
6391 REG_WR(bp, CFC_REG_DEBUG0, 0);
6393 if (CHIP_IS_E1(bp)) {
6394 /* read NIG statistic
6395 to see if this is our first up since powerup */
6396 bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
6397 val = *bnx2x_sp(bp, wb_data[0]);
6399 /* do internal memory self test */
6400 if ((val == 0) && bnx2x_int_mem_test(bp)) {
6401 BNX2X_ERR("internal mem self test failed\n");
6406 bnx2x_setup_fan_failure_detection(bp);
6408 /* clear PXP2 attentions */
6409 REG_RD(bp, PXP2_REG_PXP2_INT_STS_CLR_0);
6411 bnx2x_enable_blocks_attention(bp);
6412 bnx2x_enable_blocks_parity(bp);
6414 if (!BP_NOMCP(bp)) {
6415 if (CHIP_IS_E1x(bp))
6416 bnx2x__common_init_phy(bp);
6418 BNX2X_ERR("Bootcode is missing - can not initialize link\n");
6424 * bnx2x_init_hw_common_chip - init HW at the COMMON_CHIP phase.
6426 * @bp: driver handle
6428 static int bnx2x_init_hw_common_chip(struct bnx2x *bp)
6430 int rc = bnx2x_init_hw_common(bp);
6435 /* In E2 2-PORT mode, same ext phy is used for the two paths */
6437 bnx2x__common_init_phy(bp);
6442 static int bnx2x_init_hw_port(struct bnx2x *bp)
6444 int port = BP_PORT(bp);
6445 int init_phase = port ? PHASE_PORT1 : PHASE_PORT0;
6449 bnx2x__link_reset(bp);
6451 DP(NETIF_MSG_HW, "starting port init port %d\n", port);
6453 REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
6455 bnx2x_init_block(bp, BLOCK_MISC, init_phase);
6456 bnx2x_init_block(bp, BLOCK_PXP, init_phase);
6457 bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
6459 /* Timers bug workaround: disables the pf_master bit in pglue at
6460 * common phase, we need to enable it here before any dmae access are
6461 * attempted. Therefore we manually added the enable-master to the
6462 * port phase (it also happens in the function phase)
6464 if (!CHIP_IS_E1x(bp))
6465 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
6467 bnx2x_init_block(bp, BLOCK_ATC, init_phase);
6468 bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
6469 bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
6470 bnx2x_init_block(bp, BLOCK_QM, init_phase);
6472 bnx2x_init_block(bp, BLOCK_TCM, init_phase);
6473 bnx2x_init_block(bp, BLOCK_UCM, init_phase);
6474 bnx2x_init_block(bp, BLOCK_CCM, init_phase);
6475 bnx2x_init_block(bp, BLOCK_XCM, init_phase);
6477 /* QM cid (connection) count */
6478 bnx2x_qm_init_cid_count(bp, bp->qm_cid_count, INITOP_SET);
6481 bnx2x_init_block(bp, BLOCK_TM, init_phase);
6482 REG_WR(bp, TM_REG_LIN0_SCAN_TIME + port*4, 20);
6483 REG_WR(bp, TM_REG_LIN0_MAX_ACTIVE_CID + port*4, 31);
6486 bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
6488 if (CHIP_IS_E1(bp) || CHIP_IS_E1H(bp)) {
6489 bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
6492 low = ((bp->flags & ONE_PORT_FLAG) ? 160 : 246);
6493 else if (bp->dev->mtu > 4096) {
6494 if (bp->flags & ONE_PORT_FLAG)
6498 /* (24*1024 + val*4)/256 */
6499 low = 96 + (val/64) +
6500 ((val % 64) ? 1 : 0);
6503 low = ((bp->flags & ONE_PORT_FLAG) ? 80 : 160);
6504 high = low + 56; /* 14*1024/256 */
6505 REG_WR(bp, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port*4, low);
6506 REG_WR(bp, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port*4, high);
6509 if (CHIP_MODE_IS_4_PORT(bp))
6510 REG_WR(bp, (BP_PORT(bp) ?
6511 BRB1_REG_MAC_GUARANTIED_1 :
6512 BRB1_REG_MAC_GUARANTIED_0), 40);
6515 bnx2x_init_block(bp, BLOCK_PRS, init_phase);
6516 if (CHIP_IS_E3B0(bp))
6517 /* Ovlan exists only if we are in multi-function +
6518 * switch-dependent mode, in switch-independent there
6519 * is no ovlan headers
6521 REG_WR(bp, BP_PORT(bp) ?
6522 PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
6523 PRS_REG_HDRS_AFTER_BASIC_PORT_0,
6524 (bp->path_has_ovlan ? 7 : 6));
6526 bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
6527 bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
6528 bnx2x_init_block(bp, BLOCK_USDM, init_phase);
6529 bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
6531 bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
6532 bnx2x_init_block(bp, BLOCK_USEM, init_phase);
6533 bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
6534 bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
6536 bnx2x_init_block(bp, BLOCK_UPB, init_phase);
6537 bnx2x_init_block(bp, BLOCK_XPB, init_phase);
6539 bnx2x_init_block(bp, BLOCK_PBF, init_phase);
6541 if (CHIP_IS_E1x(bp)) {
6542 /* configure PBF to work without PAUSE mtu 9000 */
6543 REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
6545 /* update threshold */
6546 REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, (9040/16));
6547 /* update init credit */
6548 REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, (9040/16) + 553 - 22);
6551 REG_WR(bp, PBF_REG_INIT_P0 + port*4, 1);
6553 REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0);
6557 bnx2x_init_block(bp, BLOCK_SRC, init_phase);
6559 bnx2x_init_block(bp, BLOCK_CDU, init_phase);
6560 bnx2x_init_block(bp, BLOCK_CFC, init_phase);
6562 if (CHIP_IS_E1(bp)) {
6563 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
6564 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
6566 bnx2x_init_block(bp, BLOCK_HC, init_phase);
6568 bnx2x_init_block(bp, BLOCK_IGU, init_phase);
6570 bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
6571 /* init aeu_mask_attn_func_0/1:
6572 * - SF mode: bits 3-7 are masked. only bits 0-2 are in use
6573 * - MF mode: bit 3 is masked. bits 0-2 are in use as in SF
6574 * bits 4-7 are used for "per vn group attention" */
6575 val = IS_MF(bp) ? 0xF7 : 0x7;
6576 /* Enable DCBX attention for all but E1 */
6577 val |= CHIP_IS_E1(bp) ? 0 : 0x10;
6578 REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, val);
6580 bnx2x_init_block(bp, BLOCK_NIG, init_phase);
6582 if (!CHIP_IS_E1x(bp)) {
6583 /* Bit-map indicating which L2 hdrs may appear after the
6584 * basic Ethernet header
6586 REG_WR(bp, BP_PORT(bp) ?
6587 NIG_REG_P1_HDRS_AFTER_BASIC :
6588 NIG_REG_P0_HDRS_AFTER_BASIC,
6589 IS_MF_SD(bp) ? 7 : 6);
6592 REG_WR(bp, BP_PORT(bp) ?
6593 NIG_REG_LLH1_MF_MODE :
6594 NIG_REG_LLH_MF_MODE, IS_MF(bp));
6596 if (!CHIP_IS_E3(bp))
6597 REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
6599 if (!CHIP_IS_E1(bp)) {
6600 /* 0x2 disable mf_ov, 0x1 enable */
6601 REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port*4,
6602 (IS_MF_SD(bp) ? 0x1 : 0x2));
6604 if (!CHIP_IS_E1x(bp)) {
6606 switch (bp->mf_mode) {
6607 case MULTI_FUNCTION_SD:
6610 case MULTI_FUNCTION_SI:
6615 REG_WR(bp, (BP_PORT(bp) ? NIG_REG_LLH1_CLS_TYPE :
6616 NIG_REG_LLH0_CLS_TYPE), val);
6619 REG_WR(bp, NIG_REG_LLFC_ENABLE_0 + port*4, 0);
6620 REG_WR(bp, NIG_REG_LLFC_OUT_EN_0 + port*4, 0);
6621 REG_WR(bp, NIG_REG_PAUSE_ENABLE_0 + port*4, 1);
6626 /* If SPIO5 is set to generate interrupts, enable it for this port */
6627 val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
6628 if (val & (1 << MISC_REGISTERS_SPIO_5)) {
6629 u32 reg_addr = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
6630 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
6631 val = REG_RD(bp, reg_addr);
6632 val |= AEU_INPUTS_ATTN_BITS_SPIO5;
6633 REG_WR(bp, reg_addr, val);
6639 static void bnx2x_ilt_wr(struct bnx2x *bp, u32 index, dma_addr_t addr)
6644 reg = PXP2_REG_RQ_ONCHIP_AT + index*8;
6646 reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index*8;
6648 bnx2x_wb_wr(bp, reg, ONCHIP_ADDR1(addr), ONCHIP_ADDR2(addr));
6651 static inline void bnx2x_igu_clear_sb(struct bnx2x *bp, u8 idu_sb_id)
6653 bnx2x_igu_clear_sb_gen(bp, BP_FUNC(bp), idu_sb_id, true /*PF*/);
6656 static inline void bnx2x_clear_func_ilt(struct bnx2x *bp, u32 func)
6658 u32 i, base = FUNC_ILT_BASE(func);
6659 for (i = base; i < base + ILT_PER_FUNC; i++)
6660 bnx2x_ilt_wr(bp, i, 0);
6663 static int bnx2x_init_hw_func(struct bnx2x *bp)
6665 int port = BP_PORT(bp);
6666 int func = BP_FUNC(bp);
6667 int init_phase = PHASE_PF0 + func;
6668 struct bnx2x_ilt *ilt = BP_ILT(bp);
6671 u32 main_mem_base, main_mem_size, main_mem_prty_clr;
6672 int i, main_mem_width, rc;
6674 DP(NETIF_MSG_HW, "starting func init func %d\n", func);
6676 /* FLR cleanup - hmmm */
6677 if (!CHIP_IS_E1x(bp)) {
6678 rc = bnx2x_pf_flr_clnup(bp);
6683 /* set MSI reconfigure capability */
6684 if (bp->common.int_block == INT_BLOCK_HC) {
6685 addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0);
6686 val = REG_RD(bp, addr);
6687 val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0;
6688 REG_WR(bp, addr, val);
6691 bnx2x_init_block(bp, BLOCK_PXP, init_phase);
6692 bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
6695 cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
6697 for (i = 0; i < L2_ILT_LINES(bp); i++) {
6698 ilt->lines[cdu_ilt_start + i].page =
6699 bp->context.vcxt + (ILT_PAGE_CIDS * i);
6700 ilt->lines[cdu_ilt_start + i].page_mapping =
6701 bp->context.cxt_mapping + (CDU_ILT_PAGE_SZ * i);
6702 /* cdu ilt pages are allocated manually so there's no need to
6705 bnx2x_ilt_init_op(bp, INITOP_SET);
6708 bnx2x_src_init_t2(bp, bp->t2, bp->t2_mapping, SRC_CONN_NUM);
6710 /* T1 hash bits value determines the T1 number of entries */
6711 REG_WR(bp, SRC_REG_NUMBER_HASH_BITS0 + port*4, SRC_HASH_BITS);
6716 REG_WR(bp, PRS_REG_NIC_MODE, 1);
6717 #endif /* BCM_CNIC */
6719 if (!CHIP_IS_E1x(bp)) {
6720 u32 pf_conf = IGU_PF_CONF_FUNC_EN;
6722 /* Turn on a single ISR mode in IGU if driver is going to use
6725 if (!(bp->flags & USING_MSIX_FLAG))
6726 pf_conf |= IGU_PF_CONF_SINGLE_ISR_EN;
6728 * Timers workaround bug: function init part.
6729 * Need to wait 20msec after initializing ILT,
6730 * needed to make sure there are no requests in
6731 * one of the PXP internal queues with "old" ILT addresses
6735 * Master enable - Due to WB DMAE writes performed before this
6736 * register is re-initialized as part of the regular function
6739 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
6740 /* Enable the function in IGU */
6741 REG_WR(bp, IGU_REG_PF_CONFIGURATION, pf_conf);
6746 bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
6748 if (!CHIP_IS_E1x(bp))
6749 REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR, func);
6751 bnx2x_init_block(bp, BLOCK_ATC, init_phase);
6752 bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
6753 bnx2x_init_block(bp, BLOCK_NIG, init_phase);
6754 bnx2x_init_block(bp, BLOCK_SRC, init_phase);
6755 bnx2x_init_block(bp, BLOCK_MISC, init_phase);
6756 bnx2x_init_block(bp, BLOCK_TCM, init_phase);
6757 bnx2x_init_block(bp, BLOCK_UCM, init_phase);
6758 bnx2x_init_block(bp, BLOCK_CCM, init_phase);
6759 bnx2x_init_block(bp, BLOCK_XCM, init_phase);
6760 bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
6761 bnx2x_init_block(bp, BLOCK_USEM, init_phase);
6762 bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
6763 bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
6765 if (!CHIP_IS_E1x(bp))
6766 REG_WR(bp, QM_REG_PF_EN, 1);
6768 if (!CHIP_IS_E1x(bp)) {
6769 REG_WR(bp, TSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
6770 REG_WR(bp, USEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
6771 REG_WR(bp, CSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
6772 REG_WR(bp, XSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
6774 bnx2x_init_block(bp, BLOCK_QM, init_phase);
6776 bnx2x_init_block(bp, BLOCK_TM, init_phase);
6777 bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
6778 bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
6779 bnx2x_init_block(bp, BLOCK_PRS, init_phase);
6780 bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
6781 bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
6782 bnx2x_init_block(bp, BLOCK_USDM, init_phase);
6783 bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
6784 bnx2x_init_block(bp, BLOCK_UPB, init_phase);
6785 bnx2x_init_block(bp, BLOCK_XPB, init_phase);
6786 bnx2x_init_block(bp, BLOCK_PBF, init_phase);
6787 if (!CHIP_IS_E1x(bp))
6788 REG_WR(bp, PBF_REG_DISABLE_PF, 0);
6790 bnx2x_init_block(bp, BLOCK_CDU, init_phase);
6792 bnx2x_init_block(bp, BLOCK_CFC, init_phase);
6794 if (!CHIP_IS_E1x(bp))
6795 REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 1);
6798 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
6799 REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + port*8, bp->mf_ov);
6802 bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
6804 /* HC init per function */
6805 if (bp->common.int_block == INT_BLOCK_HC) {
6806 if (CHIP_IS_E1H(bp)) {
6807 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
6809 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
6810 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
6812 bnx2x_init_block(bp, BLOCK_HC, init_phase);
6815 int num_segs, sb_idx, prod_offset;
6817 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
6819 if (!CHIP_IS_E1x(bp)) {
6820 REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
6821 REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
6824 bnx2x_init_block(bp, BLOCK_IGU, init_phase);
6826 if (!CHIP_IS_E1x(bp)) {
6830 * E2 mode: address 0-135 match to the mapping memory;
6831 * 136 - PF0 default prod; 137 - PF1 default prod;
6832 * 138 - PF2 default prod; 139 - PF3 default prod;
6833 * 140 - PF0 attn prod; 141 - PF1 attn prod;
6834 * 142 - PF2 attn prod; 143 - PF3 attn prod;
6837 * E1.5 mode - In backward compatible mode;
6838 * for non default SB; each even line in the memory
6839 * holds the U producer and each odd line hold
6840 * the C producer. The first 128 producers are for
6841 * NDSB (PF0 - 0-31; PF1 - 32-63 and so on). The last 20
6842 * producers are for the DSB for each PF.
6843 * Each PF has five segments: (the order inside each
6844 * segment is PF0; PF1; PF2; PF3) - 128-131 U prods;
6845 * 132-135 C prods; 136-139 X prods; 140-143 T prods;
6846 * 144-147 attn prods;
6848 /* non-default-status-blocks */
6849 num_segs = CHIP_INT_MODE_IS_BC(bp) ?
6850 IGU_BC_NDSB_NUM_SEGS : IGU_NORM_NDSB_NUM_SEGS;
6851 for (sb_idx = 0; sb_idx < bp->igu_sb_cnt; sb_idx++) {
6852 prod_offset = (bp->igu_base_sb + sb_idx) *
6855 for (i = 0; i < num_segs; i++) {
6856 addr = IGU_REG_PROD_CONS_MEMORY +
6857 (prod_offset + i) * 4;
6858 REG_WR(bp, addr, 0);
6860 /* send consumer update with value 0 */
6861 bnx2x_ack_sb(bp, bp->igu_base_sb + sb_idx,
6862 USTORM_ID, 0, IGU_INT_NOP, 1);
6863 bnx2x_igu_clear_sb(bp,
6864 bp->igu_base_sb + sb_idx);
6867 /* default-status-blocks */
6868 num_segs = CHIP_INT_MODE_IS_BC(bp) ?
6869 IGU_BC_DSB_NUM_SEGS : IGU_NORM_DSB_NUM_SEGS;
6871 if (CHIP_MODE_IS_4_PORT(bp))
6872 dsb_idx = BP_FUNC(bp);
6874 dsb_idx = BP_VN(bp);
6876 prod_offset = (CHIP_INT_MODE_IS_BC(bp) ?
6877 IGU_BC_BASE_DSB_PROD + dsb_idx :
6878 IGU_NORM_BASE_DSB_PROD + dsb_idx);
6881 * igu prods come in chunks of E1HVN_MAX (4) -
6882 * does not matters what is the current chip mode
6884 for (i = 0; i < (num_segs * E1HVN_MAX);
6886 addr = IGU_REG_PROD_CONS_MEMORY +
6887 (prod_offset + i)*4;
6888 REG_WR(bp, addr, 0);
6890 /* send consumer update with 0 */
6891 if (CHIP_INT_MODE_IS_BC(bp)) {
6892 bnx2x_ack_sb(bp, bp->igu_dsb_id,
6893 USTORM_ID, 0, IGU_INT_NOP, 1);
6894 bnx2x_ack_sb(bp, bp->igu_dsb_id,
6895 CSTORM_ID, 0, IGU_INT_NOP, 1);
6896 bnx2x_ack_sb(bp, bp->igu_dsb_id,
6897 XSTORM_ID, 0, IGU_INT_NOP, 1);
6898 bnx2x_ack_sb(bp, bp->igu_dsb_id,
6899 TSTORM_ID, 0, IGU_INT_NOP, 1);
6900 bnx2x_ack_sb(bp, bp->igu_dsb_id,
6901 ATTENTION_ID, 0, IGU_INT_NOP, 1);
6903 bnx2x_ack_sb(bp, bp->igu_dsb_id,
6904 USTORM_ID, 0, IGU_INT_NOP, 1);
6905 bnx2x_ack_sb(bp, bp->igu_dsb_id,
6906 ATTENTION_ID, 0, IGU_INT_NOP, 1);
6908 bnx2x_igu_clear_sb(bp, bp->igu_dsb_id);
6910 /* !!! these should become driver const once
6911 rf-tool supports split-68 const */
6912 REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_LSB, 0);
6913 REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_MSB, 0);
6914 REG_WR(bp, IGU_REG_SB_MASK_LSB, 0);
6915 REG_WR(bp, IGU_REG_SB_MASK_MSB, 0);
6916 REG_WR(bp, IGU_REG_PBA_STATUS_LSB, 0);
6917 REG_WR(bp, IGU_REG_PBA_STATUS_MSB, 0);
6921 /* Reset PCIE errors for debug */
6922 REG_WR(bp, 0x2114, 0xffffffff);
6923 REG_WR(bp, 0x2120, 0xffffffff);
6925 if (CHIP_IS_E1x(bp)) {
6926 main_mem_size = HC_REG_MAIN_MEMORY_SIZE / 2; /*dwords*/
6927 main_mem_base = HC_REG_MAIN_MEMORY +
6928 BP_PORT(bp) * (main_mem_size * 4);
6929 main_mem_prty_clr = HC_REG_HC_PRTY_STS_CLR;
6932 val = REG_RD(bp, main_mem_prty_clr);
6935 "Hmmm... Parity errors in HC block during function init (0x%x)!\n",
6938 /* Clear "false" parity errors in MSI-X table */
6939 for (i = main_mem_base;
6940 i < main_mem_base + main_mem_size * 4;
6941 i += main_mem_width) {
6942 bnx2x_read_dmae(bp, i, main_mem_width / 4);
6943 bnx2x_write_dmae(bp, bnx2x_sp_mapping(bp, wb_data),
6944 i, main_mem_width / 4);
6946 /* Clear HC parity attention */
6947 REG_RD(bp, main_mem_prty_clr);
6950 #ifdef BNX2X_STOP_ON_ERROR
6951 /* Enable STORMs SP logging */
6952 REG_WR8(bp, BAR_USTRORM_INTMEM +
6953 USTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
6954 REG_WR8(bp, BAR_TSTRORM_INTMEM +
6955 TSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
6956 REG_WR8(bp, BAR_CSTRORM_INTMEM +
6957 CSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
6958 REG_WR8(bp, BAR_XSTRORM_INTMEM +
6959 XSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
6962 bnx2x_phy_probe(&bp->link_params);
6968 void bnx2x_free_mem(struct bnx2x *bp)
6971 bnx2x_free_fp_mem(bp);
6972 /* end of fastpath */
6974 BNX2X_PCI_FREE(bp->def_status_blk, bp->def_status_blk_mapping,
6975 sizeof(struct host_sp_status_block));
6977 BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
6978 bp->fw_stats_data_sz + bp->fw_stats_req_sz);
6980 BNX2X_PCI_FREE(bp->slowpath, bp->slowpath_mapping,
6981 sizeof(struct bnx2x_slowpath));
6983 BNX2X_PCI_FREE(bp->context.vcxt, bp->context.cxt_mapping,
6986 bnx2x_ilt_mem_op(bp, ILT_MEMOP_FREE);
6988 BNX2X_FREE(bp->ilt->lines);
6991 if (!CHIP_IS_E1x(bp))
6992 BNX2X_PCI_FREE(bp->cnic_sb.e2_sb, bp->cnic_sb_mapping,
6993 sizeof(struct host_hc_status_block_e2));
6995 BNX2X_PCI_FREE(bp->cnic_sb.e1x_sb, bp->cnic_sb_mapping,
6996 sizeof(struct host_hc_status_block_e1x));
6998 BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
7001 BNX2X_PCI_FREE(bp->spq, bp->spq_mapping, BCM_PAGE_SIZE);
7003 BNX2X_PCI_FREE(bp->eq_ring, bp->eq_mapping,
7004 BCM_PAGE_SIZE * NUM_EQ_PAGES);
7007 static inline int bnx2x_alloc_fw_stats_mem(struct bnx2x *bp)
7010 int is_fcoe_stats = NO_FCOE(bp) ? 0 : 1;
7012 /* number of queues for statistics is number of eth queues + FCoE */
7013 u8 num_queue_stats = BNX2X_NUM_ETH_QUEUES(bp) + is_fcoe_stats;
7015 /* Total number of FW statistics requests =
7016 * 1 for port stats + 1 for PF stats + potential 1 for FCoE stats +
7019 bp->fw_stats_num = 2 + is_fcoe_stats + num_queue_stats;
7022 /* Request is built from stats_query_header and an array of
7023 * stats_query_cmd_group each of which contains
7024 * STATS_QUERY_CMD_COUNT rules. The real number or requests is
7025 * configured in the stats_query_header.
7027 num_groups = ((bp->fw_stats_num) / STATS_QUERY_CMD_COUNT) +
7028 (((bp->fw_stats_num) % STATS_QUERY_CMD_COUNT) ? 1 : 0);
7030 bp->fw_stats_req_sz = sizeof(struct stats_query_header) +
7031 num_groups * sizeof(struct stats_query_cmd_group);
7033 /* Data for statistics requests + stats_conter
7035 * stats_counter holds per-STORM counters that are incremented
7036 * when STORM has finished with the current request.
7038 * memory for FCoE offloaded statistics are counted anyway,
7039 * even if they will not be sent.
7041 bp->fw_stats_data_sz = sizeof(struct per_port_stats) +
7042 sizeof(struct per_pf_stats) +
7043 sizeof(struct fcoe_statistics_params) +
7044 sizeof(struct per_queue_stats) * num_queue_stats +
7045 sizeof(struct stats_counter);
7047 BNX2X_PCI_ALLOC(bp->fw_stats, &bp->fw_stats_mapping,
7048 bp->fw_stats_data_sz + bp->fw_stats_req_sz);
7051 bp->fw_stats_req = (struct bnx2x_fw_stats_req *)bp->fw_stats;
7052 bp->fw_stats_req_mapping = bp->fw_stats_mapping;
7054 bp->fw_stats_data = (struct bnx2x_fw_stats_data *)
7055 ((u8 *)bp->fw_stats + bp->fw_stats_req_sz);
7057 bp->fw_stats_data_mapping = bp->fw_stats_mapping +
7058 bp->fw_stats_req_sz;
7062 BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
7063 bp->fw_stats_data_sz + bp->fw_stats_req_sz);
7064 BNX2X_ERR("Can't allocate memory\n");
7069 int bnx2x_alloc_mem(struct bnx2x *bp)
7072 if (!CHIP_IS_E1x(bp))
7073 /* size = the status block + ramrod buffers */
7074 BNX2X_PCI_ALLOC(bp->cnic_sb.e2_sb, &bp->cnic_sb_mapping,
7075 sizeof(struct host_hc_status_block_e2));
7077 BNX2X_PCI_ALLOC(bp->cnic_sb.e1x_sb, &bp->cnic_sb_mapping,
7078 sizeof(struct host_hc_status_block_e1x));
7080 /* allocate searcher T2 table */
7081 BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ);
7085 BNX2X_PCI_ALLOC(bp->def_status_blk, &bp->def_status_blk_mapping,
7086 sizeof(struct host_sp_status_block));
7088 BNX2X_PCI_ALLOC(bp->slowpath, &bp->slowpath_mapping,
7089 sizeof(struct bnx2x_slowpath));
7092 /* write address to which L5 should insert its values */
7093 bp->cnic_eth_dev.addr_drv_info_to_mcp = &bp->slowpath->drv_info_to_mcp;
7096 /* Allocated memory for FW statistics */
7097 if (bnx2x_alloc_fw_stats_mem(bp))
7100 bp->context.size = sizeof(union cdu_context) * BNX2X_L2_CID_COUNT(bp);
7102 BNX2X_PCI_ALLOC(bp->context.vcxt, &bp->context.cxt_mapping,
7105 BNX2X_ALLOC(bp->ilt->lines, sizeof(struct ilt_line) * ILT_MAX_LINES);
7107 if (bnx2x_ilt_mem_op(bp, ILT_MEMOP_ALLOC))
7110 /* Slow path ring */
7111 BNX2X_PCI_ALLOC(bp->spq, &bp->spq_mapping, BCM_PAGE_SIZE);
7114 BNX2X_PCI_ALLOC(bp->eq_ring, &bp->eq_mapping,
7115 BCM_PAGE_SIZE * NUM_EQ_PAGES);
7119 /* need to be done at the end, since it's self adjusting to amount
7120 * of memory available for RSS queues
7122 if (bnx2x_alloc_fp_mem(bp))
7128 BNX2X_ERR("Can't allocate memory\n");
7133 * Init service functions
7136 int bnx2x_set_mac_one(struct bnx2x *bp, u8 *mac,
7137 struct bnx2x_vlan_mac_obj *obj, bool set,
7138 int mac_type, unsigned long *ramrod_flags)
7141 struct bnx2x_vlan_mac_ramrod_params ramrod_param;
7143 memset(&ramrod_param, 0, sizeof(ramrod_param));
7145 /* Fill general parameters */
7146 ramrod_param.vlan_mac_obj = obj;
7147 ramrod_param.ramrod_flags = *ramrod_flags;
7149 /* Fill a user request section if needed */
7150 if (!test_bit(RAMROD_CONT, ramrod_flags)) {
7151 memcpy(ramrod_param.user_req.u.mac.mac, mac, ETH_ALEN);
7153 __set_bit(mac_type, &ramrod_param.user_req.vlan_mac_flags);
7155 /* Set the command: ADD or DEL */
7157 ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_ADD;
7159 ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_DEL;
7162 rc = bnx2x_config_vlan_mac(bp, &ramrod_param);
7164 BNX2X_ERR("%s MAC failed\n", (set ? "Set" : "Del"));
7168 int bnx2x_del_all_macs(struct bnx2x *bp,
7169 struct bnx2x_vlan_mac_obj *mac_obj,
7170 int mac_type, bool wait_for_comp)
7173 unsigned long ramrod_flags = 0, vlan_mac_flags = 0;
7175 /* Wait for completion of requested */
7177 __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
7179 /* Set the mac type of addresses we want to clear */
7180 __set_bit(mac_type, &vlan_mac_flags);
7182 rc = mac_obj->delete_all(bp, mac_obj, &vlan_mac_flags, &ramrod_flags);
7184 BNX2X_ERR("Failed to delete MACs: %d\n", rc);
7189 int bnx2x_set_eth_mac(struct bnx2x *bp, bool set)
7191 unsigned long ramrod_flags = 0;
7194 if (is_zero_ether_addr(bp->dev->dev_addr) && IS_MF_STORAGE_SD(bp)) {
7195 DP(NETIF_MSG_IFUP | NETIF_MSG_IFDOWN,
7196 "Ignoring Zero MAC for STORAGE SD mode\n");
7201 DP(NETIF_MSG_IFUP, "Adding Eth MAC\n");
7203 __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
7204 /* Eth MAC is set on RSS leading client (fp[0]) */
7205 return bnx2x_set_mac_one(bp, bp->dev->dev_addr, &bp->fp->mac_obj, set,
7206 BNX2X_ETH_MAC, &ramrod_flags);
7209 int bnx2x_setup_leading(struct bnx2x *bp)
7211 return bnx2x_setup_queue(bp, &bp->fp[0], 1);
7215 * bnx2x_set_int_mode - configure interrupt mode
7217 * @bp: driver handle
7219 * In case of MSI-X it will also try to enable MSI-X.
7221 static void __devinit bnx2x_set_int_mode(struct bnx2x *bp)
7225 bnx2x_enable_msi(bp);
7226 /* falling through... */
7228 bp->num_queues = 1 + NON_ETH_CONTEXT_USE;
7229 BNX2X_DEV_INFO("set number of queues to 1\n");
7232 /* Set number of queues according to bp->multi_mode value */
7233 bnx2x_set_num_queues(bp);
7235 BNX2X_DEV_INFO("set number of queues to %d\n", bp->num_queues);
7237 /* if we can't use MSI-X we only need one fp,
7238 * so try to enable MSI-X with the requested number of fp's
7239 * and fallback to MSI or legacy INTx with one fp
7241 if (bnx2x_enable_msix(bp)) {
7242 /* failed to enable MSI-X */
7243 BNX2X_DEV_INFO("Failed to enable MSI-X (%d), set number of queues to %d\n",
7244 bp->num_queues, 1 + NON_ETH_CONTEXT_USE);
7246 bp->num_queues = 1 + NON_ETH_CONTEXT_USE;
7248 /* Try to enable MSI */
7249 if (!(bp->flags & DISABLE_MSI_FLAG))
7250 bnx2x_enable_msi(bp);
7256 /* must be called prioir to any HW initializations */
7257 static inline u16 bnx2x_cid_ilt_lines(struct bnx2x *bp)
7259 return L2_ILT_LINES(bp);
7262 void bnx2x_ilt_set_info(struct bnx2x *bp)
7264 struct ilt_client_info *ilt_client;
7265 struct bnx2x_ilt *ilt = BP_ILT(bp);
7268 ilt->start_line = FUNC_ILT_BASE(BP_FUNC(bp));
7269 DP(BNX2X_MSG_SP, "ilt starts at line %d\n", ilt->start_line);
7272 ilt_client = &ilt->clients[ILT_CLIENT_CDU];
7273 ilt_client->client_num = ILT_CLIENT_CDU;
7274 ilt_client->page_size = CDU_ILT_PAGE_SZ;
7275 ilt_client->flags = ILT_CLIENT_SKIP_MEM;
7276 ilt_client->start = line;
7277 line += bnx2x_cid_ilt_lines(bp);
7279 line += CNIC_ILT_LINES;
7281 ilt_client->end = line - 1;
7283 DP(NETIF_MSG_IFUP, "ilt client[CDU]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
7286 ilt_client->page_size,
7288 ilog2(ilt_client->page_size >> 12));
7291 if (QM_INIT(bp->qm_cid_count)) {
7292 ilt_client = &ilt->clients[ILT_CLIENT_QM];
7293 ilt_client->client_num = ILT_CLIENT_QM;
7294 ilt_client->page_size = QM_ILT_PAGE_SZ;
7295 ilt_client->flags = 0;
7296 ilt_client->start = line;
7298 /* 4 bytes for each cid */
7299 line += DIV_ROUND_UP(bp->qm_cid_count * QM_QUEUES_PER_FUNC * 4,
7302 ilt_client->end = line - 1;
7305 "ilt client[QM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
7308 ilt_client->page_size,
7310 ilog2(ilt_client->page_size >> 12));
7314 ilt_client = &ilt->clients[ILT_CLIENT_SRC];
7316 ilt_client->client_num = ILT_CLIENT_SRC;
7317 ilt_client->page_size = SRC_ILT_PAGE_SZ;
7318 ilt_client->flags = 0;
7319 ilt_client->start = line;
7320 line += SRC_ILT_LINES;
7321 ilt_client->end = line - 1;
7324 "ilt client[SRC]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
7327 ilt_client->page_size,
7329 ilog2(ilt_client->page_size >> 12));
7332 ilt_client->flags = (ILT_CLIENT_SKIP_INIT | ILT_CLIENT_SKIP_MEM);
7336 ilt_client = &ilt->clients[ILT_CLIENT_TM];
7338 ilt_client->client_num = ILT_CLIENT_TM;
7339 ilt_client->page_size = TM_ILT_PAGE_SZ;
7340 ilt_client->flags = 0;
7341 ilt_client->start = line;
7342 line += TM_ILT_LINES;
7343 ilt_client->end = line - 1;
7346 "ilt client[TM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
7349 ilt_client->page_size,
7351 ilog2(ilt_client->page_size >> 12));
7354 ilt_client->flags = (ILT_CLIENT_SKIP_INIT | ILT_CLIENT_SKIP_MEM);
7356 BUG_ON(line > ILT_MAX_LINES);
7360 * bnx2x_pf_q_prep_init - prepare INIT transition parameters
7362 * @bp: driver handle
7363 * @fp: pointer to fastpath
7364 * @init_params: pointer to parameters structure
7366 * parameters configured:
7367 * - HC configuration
7368 * - Queue's CDU context
7370 static inline void bnx2x_pf_q_prep_init(struct bnx2x *bp,
7371 struct bnx2x_fastpath *fp, struct bnx2x_queue_init_params *init_params)
7375 /* FCoE Queue uses Default SB, thus has no HC capabilities */
7376 if (!IS_FCOE_FP(fp)) {
7377 __set_bit(BNX2X_Q_FLG_HC, &init_params->rx.flags);
7378 __set_bit(BNX2X_Q_FLG_HC, &init_params->tx.flags);
7380 /* If HC is supporterd, enable host coalescing in the transition
7383 __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->rx.flags);
7384 __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->tx.flags);
7387 init_params->rx.hc_rate = bp->rx_ticks ?
7388 (1000000 / bp->rx_ticks) : 0;
7389 init_params->tx.hc_rate = bp->tx_ticks ?
7390 (1000000 / bp->tx_ticks) : 0;
7393 init_params->rx.fw_sb_id = init_params->tx.fw_sb_id =
7397 * CQ index among the SB indices: FCoE clients uses the default
7398 * SB, therefore it's different.
7400 init_params->rx.sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
7401 init_params->tx.sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS;
7404 /* set maximum number of COSs supported by this queue */
7405 init_params->max_cos = fp->max_cos;
7407 DP(NETIF_MSG_IFUP, "fp: %d setting queue params max cos to: %d\n",
7408 fp->index, init_params->max_cos);
7410 /* set the context pointers queue object */
7411 for (cos = FIRST_TX_COS_INDEX; cos < init_params->max_cos; cos++)
7412 init_params->cxts[cos] =
7413 &bp->context.vcxt[fp->txdata[cos].cid].eth;
7416 int bnx2x_setup_tx_only(struct bnx2x *bp, struct bnx2x_fastpath *fp,
7417 struct bnx2x_queue_state_params *q_params,
7418 struct bnx2x_queue_setup_tx_only_params *tx_only_params,
7419 int tx_index, bool leading)
7421 memset(tx_only_params, 0, sizeof(*tx_only_params));
7423 /* Set the command */
7424 q_params->cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
7426 /* Set tx-only QUEUE flags: don't zero statistics */
7427 tx_only_params->flags = bnx2x_get_common_flags(bp, fp, false);
7429 /* choose the index of the cid to send the slow path on */
7430 tx_only_params->cid_index = tx_index;
7432 /* Set general TX_ONLY_SETUP parameters */
7433 bnx2x_pf_q_prep_general(bp, fp, &tx_only_params->gen_params, tx_index);
7435 /* Set Tx TX_ONLY_SETUP parameters */
7436 bnx2x_pf_tx_q_prep(bp, fp, &tx_only_params->txq_params, tx_index);
7439 "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",
7440 tx_index, q_params->q_obj->cids[FIRST_TX_COS_INDEX],
7441 q_params->q_obj->cids[tx_index], q_params->q_obj->cl_id,
7442 tx_only_params->gen_params.spcl_id, tx_only_params->flags);
7444 /* send the ramrod */
7445 return bnx2x_queue_state_change(bp, q_params);
7450 * bnx2x_setup_queue - setup queue
7452 * @bp: driver handle
7453 * @fp: pointer to fastpath
7454 * @leading: is leading
7456 * This function performs 2 steps in a Queue state machine
7457 * actually: 1) RESET->INIT 2) INIT->SETUP
7460 int bnx2x_setup_queue(struct bnx2x *bp, struct bnx2x_fastpath *fp,
7463 struct bnx2x_queue_state_params q_params = {NULL};
7464 struct bnx2x_queue_setup_params *setup_params =
7465 &q_params.params.setup;
7466 struct bnx2x_queue_setup_tx_only_params *tx_only_params =
7467 &q_params.params.tx_only;
7471 DP(NETIF_MSG_IFUP, "setting up queue %d\n", fp->index);
7473 /* reset IGU state skip FCoE L2 queue */
7474 if (!IS_FCOE_FP(fp))
7475 bnx2x_ack_sb(bp, fp->igu_sb_id, USTORM_ID, 0,
7478 q_params.q_obj = &fp->q_obj;
7479 /* We want to wait for completion in this context */
7480 __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
7482 /* Prepare the INIT parameters */
7483 bnx2x_pf_q_prep_init(bp, fp, &q_params.params.init);
7485 /* Set the command */
7486 q_params.cmd = BNX2X_Q_CMD_INIT;
7488 /* Change the state to INIT */
7489 rc = bnx2x_queue_state_change(bp, &q_params);
7491 BNX2X_ERR("Queue(%d) INIT failed\n", fp->index);
7495 DP(NETIF_MSG_IFUP, "init complete\n");
7498 /* Now move the Queue to the SETUP state... */
7499 memset(setup_params, 0, sizeof(*setup_params));
7501 /* Set QUEUE flags */
7502 setup_params->flags = bnx2x_get_q_flags(bp, fp, leading);
7504 /* Set general SETUP parameters */
7505 bnx2x_pf_q_prep_general(bp, fp, &setup_params->gen_params,
7506 FIRST_TX_COS_INDEX);
7508 bnx2x_pf_rx_q_prep(bp, fp, &setup_params->pause_params,
7509 &setup_params->rxq_params);
7511 bnx2x_pf_tx_q_prep(bp, fp, &setup_params->txq_params,
7512 FIRST_TX_COS_INDEX);
7514 /* Set the command */
7515 q_params.cmd = BNX2X_Q_CMD_SETUP;
7517 /* Change the state to SETUP */
7518 rc = bnx2x_queue_state_change(bp, &q_params);
7520 BNX2X_ERR("Queue(%d) SETUP failed\n", fp->index);
7524 /* loop through the relevant tx-only indices */
7525 for (tx_index = FIRST_TX_ONLY_COS_INDEX;
7526 tx_index < fp->max_cos;
7529 /* prepare and send tx-only ramrod*/
7530 rc = bnx2x_setup_tx_only(bp, fp, &q_params,
7531 tx_only_params, tx_index, leading);
7533 BNX2X_ERR("Queue(%d.%d) TX_ONLY_SETUP failed\n",
7534 fp->index, tx_index);
7542 static int bnx2x_stop_queue(struct bnx2x *bp, int index)
7544 struct bnx2x_fastpath *fp = &bp->fp[index];
7545 struct bnx2x_fp_txdata *txdata;
7546 struct bnx2x_queue_state_params q_params = {NULL};
7549 DP(NETIF_MSG_IFDOWN, "stopping queue %d cid %d\n", index, fp->cid);
7551 q_params.q_obj = &fp->q_obj;
7552 /* We want to wait for completion in this context */
7553 __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
7556 /* close tx-only connections */
7557 for (tx_index = FIRST_TX_ONLY_COS_INDEX;
7558 tx_index < fp->max_cos;
7561 /* ascertain this is a normal queue*/
7562 txdata = &fp->txdata[tx_index];
7564 DP(NETIF_MSG_IFDOWN, "stopping tx-only queue %d\n",
7567 /* send halt terminate on tx-only connection */
7568 q_params.cmd = BNX2X_Q_CMD_TERMINATE;
7569 memset(&q_params.params.terminate, 0,
7570 sizeof(q_params.params.terminate));
7571 q_params.params.terminate.cid_index = tx_index;
7573 rc = bnx2x_queue_state_change(bp, &q_params);
7577 /* send halt terminate on tx-only connection */
7578 q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
7579 memset(&q_params.params.cfc_del, 0,
7580 sizeof(q_params.params.cfc_del));
7581 q_params.params.cfc_del.cid_index = tx_index;
7582 rc = bnx2x_queue_state_change(bp, &q_params);
7586 /* Stop the primary connection: */
7587 /* ...halt the connection */
7588 q_params.cmd = BNX2X_Q_CMD_HALT;
7589 rc = bnx2x_queue_state_change(bp, &q_params);
7593 /* ...terminate the connection */
7594 q_params.cmd = BNX2X_Q_CMD_TERMINATE;
7595 memset(&q_params.params.terminate, 0,
7596 sizeof(q_params.params.terminate));
7597 q_params.params.terminate.cid_index = FIRST_TX_COS_INDEX;
7598 rc = bnx2x_queue_state_change(bp, &q_params);
7601 /* ...delete cfc entry */
7602 q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
7603 memset(&q_params.params.cfc_del, 0,
7604 sizeof(q_params.params.cfc_del));
7605 q_params.params.cfc_del.cid_index = FIRST_TX_COS_INDEX;
7606 return bnx2x_queue_state_change(bp, &q_params);
7610 static void bnx2x_reset_func(struct bnx2x *bp)
7612 int port = BP_PORT(bp);
7613 int func = BP_FUNC(bp);
7616 /* Disable the function in the FW */
7617 REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(func), 0);
7618 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(func), 0);
7619 REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(func), 0);
7620 REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(func), 0);
7623 for_each_eth_queue(bp, i) {
7624 struct bnx2x_fastpath *fp = &bp->fp[i];
7625 REG_WR8(bp, BAR_CSTRORM_INTMEM +
7626 CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(fp->fw_sb_id),
7632 REG_WR8(bp, BAR_CSTRORM_INTMEM +
7633 CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(bnx2x_cnic_fw_sb_id(bp)),
7637 REG_WR8(bp, BAR_CSTRORM_INTMEM +
7638 CSTORM_SP_STATUS_BLOCK_DATA_STATE_OFFSET(func),
7641 for (i = 0; i < XSTORM_SPQ_DATA_SIZE / 4; i++)
7642 REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_DATA_OFFSET(func),
7646 if (bp->common.int_block == INT_BLOCK_HC) {
7647 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
7648 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
7650 REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
7651 REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
7655 /* Disable Timer scan */
7656 REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + port*4, 0);
7658 * Wait for at least 10ms and up to 2 second for the timers scan to
7661 for (i = 0; i < 200; i++) {
7663 if (!REG_RD(bp, TM_REG_LIN0_SCAN_ON + port*4))
7668 bnx2x_clear_func_ilt(bp, func);
7670 /* Timers workaround bug for E2: if this is vnic-3,
7671 * we need to set the entire ilt range for this timers.
7673 if (!CHIP_IS_E1x(bp) && BP_VN(bp) == 3) {
7674 struct ilt_client_info ilt_cli;
7675 /* use dummy TM client */
7676 memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
7678 ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
7679 ilt_cli.client_num = ILT_CLIENT_TM;
7681 bnx2x_ilt_boundry_init_op(bp, &ilt_cli, 0, INITOP_CLEAR);
7684 /* this assumes that reset_port() called before reset_func()*/
7685 if (!CHIP_IS_E1x(bp))
7686 bnx2x_pf_disable(bp);
7691 static void bnx2x_reset_port(struct bnx2x *bp)
7693 int port = BP_PORT(bp);
7696 /* Reset physical Link */
7697 bnx2x__link_reset(bp);
7699 REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
7701 /* Do not rcv packets to BRB */
7702 REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0);
7703 /* Do not direct rcv packets that are not for MCP to the BRB */
7704 REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
7705 NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
7708 REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0);
7711 /* Check for BRB port occupancy */
7712 val = REG_RD(bp, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4);
7714 DP(NETIF_MSG_IFDOWN,
7715 "BRB1 is not empty %d blocks are occupied\n", val);
7717 /* TODO: Close Doorbell port? */
7720 static inline int bnx2x_reset_hw(struct bnx2x *bp, u32 load_code)
7722 struct bnx2x_func_state_params func_params = {NULL};
7724 /* Prepare parameters for function state transitions */
7725 __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
7727 func_params.f_obj = &bp->func_obj;
7728 func_params.cmd = BNX2X_F_CMD_HW_RESET;
7730 func_params.params.hw_init.load_phase = load_code;
7732 return bnx2x_func_state_change(bp, &func_params);
7735 static inline int bnx2x_func_stop(struct bnx2x *bp)
7737 struct bnx2x_func_state_params func_params = {NULL};
7740 /* Prepare parameters for function state transitions */
7741 __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
7742 func_params.f_obj = &bp->func_obj;
7743 func_params.cmd = BNX2X_F_CMD_STOP;
7746 * Try to stop the function the 'good way'. If fails (in case
7747 * of a parity error during bnx2x_chip_cleanup()) and we are
7748 * not in a debug mode, perform a state transaction in order to
7749 * enable further HW_RESET transaction.
7751 rc = bnx2x_func_state_change(bp, &func_params);
7753 #ifdef BNX2X_STOP_ON_ERROR
7756 BNX2X_ERR("FUNC_STOP ramrod failed. Running a dry transaction\n");
7757 __set_bit(RAMROD_DRV_CLR_ONLY, &func_params.ramrod_flags);
7758 return bnx2x_func_state_change(bp, &func_params);
7766 * bnx2x_send_unload_req - request unload mode from the MCP.
7768 * @bp: driver handle
7769 * @unload_mode: requested function's unload mode
7771 * Return unload mode returned by the MCP: COMMON, PORT or FUNC.
7773 u32 bnx2x_send_unload_req(struct bnx2x *bp, int unload_mode)
7776 int port = BP_PORT(bp);
7778 /* Select the UNLOAD request mode */
7779 if (unload_mode == UNLOAD_NORMAL)
7780 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
7782 else if (bp->flags & NO_WOL_FLAG)
7783 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP;
7786 u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
7787 u8 *mac_addr = bp->dev->dev_addr;
7791 /* The mac address is written to entries 1-4 to
7792 * preserve entry 0 which is used by the PMF
7794 u8 entry = (BP_VN(bp) + 1)*8;
7796 val = (mac_addr[0] << 8) | mac_addr[1];
7797 EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry, val);
7799 val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
7800 (mac_addr[4] << 8) | mac_addr[5];
7801 EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry + 4, val);
7803 /* Enable the PME and clear the status */
7804 pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, &pmc);
7805 pmc |= PCI_PM_CTRL_PME_ENABLE | PCI_PM_CTRL_PME_STATUS;
7806 pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, pmc);
7808 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_EN;
7811 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
7813 /* Send the request to the MCP */
7815 reset_code = bnx2x_fw_command(bp, reset_code, 0);
7817 int path = BP_PATH(bp);
7819 DP(NETIF_MSG_IFDOWN, "NO MCP - load counts[%d] %d, %d, %d\n",
7820 path, load_count[path][0], load_count[path][1],
7821 load_count[path][2]);
7822 load_count[path][0]--;
7823 load_count[path][1 + port]--;
7824 DP(NETIF_MSG_IFDOWN, "NO MCP - new load counts[%d] %d, %d, %d\n",
7825 path, load_count[path][0], load_count[path][1],
7826 load_count[path][2]);
7827 if (load_count[path][0] == 0)
7828 reset_code = FW_MSG_CODE_DRV_UNLOAD_COMMON;
7829 else if (load_count[path][1 + port] == 0)
7830 reset_code = FW_MSG_CODE_DRV_UNLOAD_PORT;
7832 reset_code = FW_MSG_CODE_DRV_UNLOAD_FUNCTION;
7839 * bnx2x_send_unload_done - send UNLOAD_DONE command to the MCP.
7841 * @bp: driver handle
7843 void bnx2x_send_unload_done(struct bnx2x *bp)
7845 /* Report UNLOAD_DONE to MCP */
7847 bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
7850 static inline int bnx2x_func_wait_started(struct bnx2x *bp)
7853 int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
7859 * (assumption: No Attention from MCP at this stage)
7860 * PMF probably in the middle of TXdisable/enable transaction
7861 * 1. Sync IRS for default SB
7862 * 2. Sync SP queue - this guarantes us that attention handling started
7863 * 3. Wait, that TXdisable/enable transaction completes
7865 * 1+2 guranty that if DCBx attention was scheduled it already changed
7866 * pending bit of transaction from STARTED-->TX_STOPPED, if we alredy
7867 * received complettion for the transaction the state is TX_STOPPED.
7868 * State will return to STARTED after completion of TX_STOPPED-->STARTED
7872 /* make sure default SB ISR is done */
7874 synchronize_irq(bp->msix_table[0].vector);
7876 synchronize_irq(bp->pdev->irq);
7878 flush_workqueue(bnx2x_wq);
7880 while (bnx2x_func_get_state(bp, &bp->func_obj) !=
7881 BNX2X_F_STATE_STARTED && tout--)
7884 if (bnx2x_func_get_state(bp, &bp->func_obj) !=
7885 BNX2X_F_STATE_STARTED) {
7886 #ifdef BNX2X_STOP_ON_ERROR
7887 BNX2X_ERR("Wrong function state\n");
7891 * Failed to complete the transaction in a "good way"
7892 * Force both transactions with CLR bit
7894 struct bnx2x_func_state_params func_params = {NULL};
7896 DP(NETIF_MSG_IFDOWN,
7897 "Hmmm... unexpected function state! Forcing STARTED-->TX_ST0PPED-->STARTED\n");
7899 func_params.f_obj = &bp->func_obj;
7900 __set_bit(RAMROD_DRV_CLR_ONLY,
7901 &func_params.ramrod_flags);
7903 /* STARTED-->TX_ST0PPED */
7904 func_params.cmd = BNX2X_F_CMD_TX_STOP;
7905 bnx2x_func_state_change(bp, &func_params);
7907 /* TX_ST0PPED-->STARTED */
7908 func_params.cmd = BNX2X_F_CMD_TX_START;
7909 return bnx2x_func_state_change(bp, &func_params);
7916 void bnx2x_chip_cleanup(struct bnx2x *bp, int unload_mode)
7918 int port = BP_PORT(bp);
7921 struct bnx2x_mcast_ramrod_params rparam = {NULL};
7924 /* Wait until tx fastpath tasks complete */
7925 for_each_tx_queue(bp, i) {
7926 struct bnx2x_fastpath *fp = &bp->fp[i];
7928 for_each_cos_in_tx_queue(fp, cos)
7929 rc = bnx2x_clean_tx_queue(bp, &fp->txdata[cos]);
7930 #ifdef BNX2X_STOP_ON_ERROR
7936 /* Give HW time to discard old tx messages */
7937 usleep_range(1000, 1000);
7939 /* Clean all ETH MACs */
7940 rc = bnx2x_del_all_macs(bp, &bp->fp[0].mac_obj, BNX2X_ETH_MAC, false);
7942 BNX2X_ERR("Failed to delete all ETH macs: %d\n", rc);
7944 /* Clean up UC list */
7945 rc = bnx2x_del_all_macs(bp, &bp->fp[0].mac_obj, BNX2X_UC_LIST_MAC,
7948 BNX2X_ERR("Failed to schedule DEL commands for UC MACs list: %d\n",
7952 if (!CHIP_IS_E1(bp))
7953 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
7955 /* Set "drop all" (stop Rx).
7956 * We need to take a netif_addr_lock() here in order to prevent
7957 * a race between the completion code and this code.
7959 netif_addr_lock_bh(bp->dev);
7960 /* Schedule the rx_mode command */
7961 if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
7962 set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
7964 bnx2x_set_storm_rx_mode(bp);
7966 /* Cleanup multicast configuration */
7967 rparam.mcast_obj = &bp->mcast_obj;
7968 rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
7970 BNX2X_ERR("Failed to send DEL multicast command: %d\n", rc);
7972 netif_addr_unlock_bh(bp->dev);
7977 * Send the UNLOAD_REQUEST to the MCP. This will return if
7978 * this function should perform FUNC, PORT or COMMON HW
7981 reset_code = bnx2x_send_unload_req(bp, unload_mode);
7984 * (assumption: No Attention from MCP at this stage)
7985 * PMF probably in the middle of TXdisable/enable transaction
7987 rc = bnx2x_func_wait_started(bp);
7989 BNX2X_ERR("bnx2x_func_wait_started failed\n");
7990 #ifdef BNX2X_STOP_ON_ERROR
7995 /* Close multi and leading connections
7996 * Completions for ramrods are collected in a synchronous way
7998 for_each_queue(bp, i)
7999 if (bnx2x_stop_queue(bp, i))
8000 #ifdef BNX2X_STOP_ON_ERROR
8005 /* If SP settings didn't get completed so far - something
8006 * very wrong has happen.
8008 if (!bnx2x_wait_sp_comp(bp, ~0x0UL))
8009 BNX2X_ERR("Hmmm... Common slow path ramrods got stuck!\n");
8011 #ifndef BNX2X_STOP_ON_ERROR
8014 rc = bnx2x_func_stop(bp);
8016 BNX2X_ERR("Function stop failed!\n");
8017 #ifdef BNX2X_STOP_ON_ERROR
8022 /* Disable HW interrupts, NAPI */
8023 bnx2x_netif_stop(bp, 1);
8028 /* Reset the chip */
8029 rc = bnx2x_reset_hw(bp, reset_code);
8031 BNX2X_ERR("HW_RESET failed\n");
8034 /* Report UNLOAD_DONE to MCP */
8035 bnx2x_send_unload_done(bp);
8038 void bnx2x_disable_close_the_gate(struct bnx2x *bp)
8042 DP(NETIF_MSG_IFDOWN, "Disabling \"close the gates\"\n");
8044 if (CHIP_IS_E1(bp)) {
8045 int port = BP_PORT(bp);
8046 u32 addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
8047 MISC_REG_AEU_MASK_ATTN_FUNC_0;
8049 val = REG_RD(bp, addr);
8051 REG_WR(bp, addr, val);
8053 val = REG_RD(bp, MISC_REG_AEU_GENERAL_MASK);
8054 val &= ~(MISC_AEU_GENERAL_MASK_REG_AEU_PXP_CLOSE_MASK |
8055 MISC_AEU_GENERAL_MASK_REG_AEU_NIG_CLOSE_MASK);
8056 REG_WR(bp, MISC_REG_AEU_GENERAL_MASK, val);
8060 /* Close gates #2, #3 and #4: */
8061 static void bnx2x_set_234_gates(struct bnx2x *bp, bool close)
8065 /* Gates #2 and #4a are closed/opened for "not E1" only */
8066 if (!CHIP_IS_E1(bp)) {
8068 REG_WR(bp, PXP_REG_HST_DISCARD_DOORBELLS, !!close);
8070 REG_WR(bp, PXP_REG_HST_DISCARD_INTERNAL_WRITES, !!close);
8074 if (CHIP_IS_E1x(bp)) {
8075 /* Prevent interrupts from HC on both ports */
8076 val = REG_RD(bp, HC_REG_CONFIG_1);
8077 REG_WR(bp, HC_REG_CONFIG_1,
8078 (!close) ? (val | HC_CONFIG_1_REG_BLOCK_DISABLE_1) :
8079 (val & ~(u32)HC_CONFIG_1_REG_BLOCK_DISABLE_1));
8081 val = REG_RD(bp, HC_REG_CONFIG_0);
8082 REG_WR(bp, HC_REG_CONFIG_0,
8083 (!close) ? (val | HC_CONFIG_0_REG_BLOCK_DISABLE_0) :
8084 (val & ~(u32)HC_CONFIG_0_REG_BLOCK_DISABLE_0));
8086 /* Prevent incomming interrupts in IGU */
8087 val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
8089 REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION,
8091 (val | IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE) :
8092 (val & ~(u32)IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE));
8095 DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "%s gates #2, #3 and #4\n",
8096 close ? "closing" : "opening");
8100 #define SHARED_MF_CLP_MAGIC 0x80000000 /* `magic' bit */
8102 static void bnx2x_clp_reset_prep(struct bnx2x *bp, u32 *magic_val)
8104 /* Do some magic... */
8105 u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
8106 *magic_val = val & SHARED_MF_CLP_MAGIC;
8107 MF_CFG_WR(bp, shared_mf_config.clp_mb, val | SHARED_MF_CLP_MAGIC);
8111 * bnx2x_clp_reset_done - restore the value of the `magic' bit.
8113 * @bp: driver handle
8114 * @magic_val: old value of the `magic' bit.
8116 static void bnx2x_clp_reset_done(struct bnx2x *bp, u32 magic_val)
8118 /* Restore the `magic' bit value... */
8119 u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
8120 MF_CFG_WR(bp, shared_mf_config.clp_mb,
8121 (val & (~SHARED_MF_CLP_MAGIC)) | magic_val);
8125 * bnx2x_reset_mcp_prep - prepare for MCP reset.
8127 * @bp: driver handle
8128 * @magic_val: old value of 'magic' bit.
8130 * Takes care of CLP configurations.
8132 static void bnx2x_reset_mcp_prep(struct bnx2x *bp, u32 *magic_val)
8135 u32 validity_offset;
8137 DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "Starting\n");
8139 /* Set `magic' bit in order to save MF config */
8140 if (!CHIP_IS_E1(bp))
8141 bnx2x_clp_reset_prep(bp, magic_val);
8143 /* Get shmem offset */
8144 shmem = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
8145 validity_offset = offsetof(struct shmem_region, validity_map[0]);
8147 /* Clear validity map flags */
8149 REG_WR(bp, shmem + validity_offset, 0);
8152 #define MCP_TIMEOUT 5000 /* 5 seconds (in ms) */
8153 #define MCP_ONE_TIMEOUT 100 /* 100 ms */
8156 * bnx2x_mcp_wait_one - wait for MCP_ONE_TIMEOUT
8158 * @bp: driver handle
8160 static inline void bnx2x_mcp_wait_one(struct bnx2x *bp)
8162 /* special handling for emulation and FPGA,
8163 wait 10 times longer */
8164 if (CHIP_REV_IS_SLOW(bp))
8165 msleep(MCP_ONE_TIMEOUT*10);
8167 msleep(MCP_ONE_TIMEOUT);
8171 * initializes bp->common.shmem_base and waits for validity signature to appear
8173 static int bnx2x_init_shmem(struct bnx2x *bp)
8179 bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
8180 if (bp->common.shmem_base) {
8181 val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
8182 if (val & SHR_MEM_VALIDITY_MB)
8186 bnx2x_mcp_wait_one(bp);
8188 } while (cnt++ < (MCP_TIMEOUT / MCP_ONE_TIMEOUT));
8190 BNX2X_ERR("BAD MCP validity signature\n");
8195 static int bnx2x_reset_mcp_comp(struct bnx2x *bp, u32 magic_val)
8197 int rc = bnx2x_init_shmem(bp);
8199 /* Restore the `magic' bit value */
8200 if (!CHIP_IS_E1(bp))
8201 bnx2x_clp_reset_done(bp, magic_val);
8206 static void bnx2x_pxp_prep(struct bnx2x *bp)
8208 if (!CHIP_IS_E1(bp)) {
8209 REG_WR(bp, PXP2_REG_RD_START_INIT, 0);
8210 REG_WR(bp, PXP2_REG_RQ_RBC_DONE, 0);
8216 * Reset the whole chip except for:
8218 * - PCI Glue, PSWHST, PXP/PXP2 RF (all controlled by
8221 * - MISC (including AEU)
8225 static void bnx2x_process_kill_chip_reset(struct bnx2x *bp, bool global)
8227 u32 not_reset_mask1, reset_mask1, not_reset_mask2, reset_mask2;
8228 u32 global_bits2, stay_reset2;
8231 * Bits that have to be set in reset_mask2 if we want to reset 'global'
8232 * (per chip) blocks.
8235 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CPU |
8236 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CORE;
8238 /* Don't reset the following blocks */
8240 MISC_REGISTERS_RESET_REG_1_RST_HC |
8241 MISC_REGISTERS_RESET_REG_1_RST_PXPV |
8242 MISC_REGISTERS_RESET_REG_1_RST_PXP;
8245 MISC_REGISTERS_RESET_REG_2_RST_PCI_MDIO |
8246 MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE |
8247 MISC_REGISTERS_RESET_REG_2_RST_EMAC1_HARD_CORE |
8248 MISC_REGISTERS_RESET_REG_2_RST_MISC_CORE |
8249 MISC_REGISTERS_RESET_REG_2_RST_RBCN |
8250 MISC_REGISTERS_RESET_REG_2_RST_GRC |
8251 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_REG_HARD_CORE |
8252 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_HARD_CORE_RST_B |
8253 MISC_REGISTERS_RESET_REG_2_RST_ATC |
8254 MISC_REGISTERS_RESET_REG_2_PGLC;
8257 * Keep the following blocks in reset:
8258 * - all xxMACs are handled by the bnx2x_link code.
8261 MISC_REGISTERS_RESET_REG_2_RST_BMAC0 |
8262 MISC_REGISTERS_RESET_REG_2_RST_BMAC1 |
8263 MISC_REGISTERS_RESET_REG_2_RST_EMAC0 |
8264 MISC_REGISTERS_RESET_REG_2_RST_EMAC1 |
8265 MISC_REGISTERS_RESET_REG_2_UMAC0 |
8266 MISC_REGISTERS_RESET_REG_2_UMAC1 |
8267 MISC_REGISTERS_RESET_REG_2_XMAC |
8268 MISC_REGISTERS_RESET_REG_2_XMAC_SOFT;
8270 /* Full reset masks according to the chip */
8271 reset_mask1 = 0xffffffff;
8274 reset_mask2 = 0xffff;
8275 else if (CHIP_IS_E1H(bp))
8276 reset_mask2 = 0x1ffff;
8277 else if (CHIP_IS_E2(bp))
8278 reset_mask2 = 0xfffff;
8279 else /* CHIP_IS_E3 */
8280 reset_mask2 = 0x3ffffff;
8282 /* Don't reset global blocks unless we need to */
8284 reset_mask2 &= ~global_bits2;
8287 * In case of attention in the QM, we need to reset PXP
8288 * (MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR) before QM
8289 * because otherwise QM reset would release 'close the gates' shortly
8290 * before resetting the PXP, then the PSWRQ would send a write
8291 * request to PGLUE. Then when PXP is reset, PGLUE would try to
8292 * read the payload data from PSWWR, but PSWWR would not
8293 * respond. The write queue in PGLUE would stuck, dmae commands
8294 * would not return. Therefore it's important to reset the second
8295 * reset register (containing the
8296 * MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR bit) before the
8297 * first one (containing the MISC_REGISTERS_RESET_REG_1_RST_QM
8300 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
8301 reset_mask2 & (~not_reset_mask2));
8303 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
8304 reset_mask1 & (~not_reset_mask1));
8309 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
8310 reset_mask2 & (~stay_reset2));
8315 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, reset_mask1);
8320 * bnx2x_er_poll_igu_vq - poll for pending writes bit.
8321 * It should get cleared in no more than 1s.
8323 * @bp: driver handle
8325 * It should get cleared in no more than 1s. Returns 0 if
8326 * pending writes bit gets cleared.
8328 static int bnx2x_er_poll_igu_vq(struct bnx2x *bp)
8334 pend_bits = REG_RD(bp, IGU_REG_PENDING_BITS_STATUS);
8339 usleep_range(1000, 1000);
8340 } while (cnt-- > 0);
8343 BNX2X_ERR("Still pending IGU requests pend_bits=%x!\n",
8351 static int bnx2x_process_kill(struct bnx2x *bp, bool global)
8355 u32 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, pgl_exp_rom2;
8358 /* Empty the Tetris buffer, wait for 1s */
8360 sr_cnt = REG_RD(bp, PXP2_REG_RD_SR_CNT);
8361 blk_cnt = REG_RD(bp, PXP2_REG_RD_BLK_CNT);
8362 port_is_idle_0 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_0);
8363 port_is_idle_1 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_1);
8364 pgl_exp_rom2 = REG_RD(bp, PXP2_REG_PGL_EXP_ROM2);
8365 if ((sr_cnt == 0x7e) && (blk_cnt == 0xa0) &&
8366 ((port_is_idle_0 & 0x1) == 0x1) &&
8367 ((port_is_idle_1 & 0x1) == 0x1) &&
8368 (pgl_exp_rom2 == 0xffffffff))
8370 usleep_range(1000, 1000);
8371 } while (cnt-- > 0);
8374 BNX2X_ERR("Tetris buffer didn't get empty or there are still outstanding read requests after 1s!\n");
8375 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",
8376 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1,
8383 /* Close gates #2, #3 and #4 */
8384 bnx2x_set_234_gates(bp, true);
8386 /* Poll for IGU VQs for 57712 and newer chips */
8387 if (!CHIP_IS_E1x(bp) && bnx2x_er_poll_igu_vq(bp))
8391 /* TBD: Indicate that "process kill" is in progress to MCP */
8393 /* Clear "unprepared" bit */
8394 REG_WR(bp, MISC_REG_UNPREPARED, 0);
8397 /* Make sure all is written to the chip before the reset */
8400 /* Wait for 1ms to empty GLUE and PCI-E core queues,
8401 * PSWHST, GRC and PSWRD Tetris buffer.
8403 usleep_range(1000, 1000);
8405 /* Prepare to chip reset: */
8408 bnx2x_reset_mcp_prep(bp, &val);
8414 /* reset the chip */
8415 bnx2x_process_kill_chip_reset(bp, global);
8418 /* Recover after reset: */
8420 if (global && bnx2x_reset_mcp_comp(bp, val))
8423 /* TBD: Add resetting the NO_MCP mode DB here */
8428 /* Open the gates #2, #3 and #4 */
8429 bnx2x_set_234_gates(bp, false);
8431 /* TBD: IGU/AEU preparation bring back the AEU/IGU to a
8432 * reset state, re-enable attentions. */
8437 int bnx2x_leader_reset(struct bnx2x *bp)
8440 bool global = bnx2x_reset_is_global(bp);
8443 /* if not going to reset MCP - load "fake" driver to reset HW while
8444 * driver is owner of the HW
8446 if (!global && !BP_NOMCP(bp)) {
8447 load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_REQ, 0);
8449 BNX2X_ERR("MCP response failure, aborting\n");
8451 goto exit_leader_reset;
8453 if ((load_code != FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) &&
8454 (load_code != FW_MSG_CODE_DRV_LOAD_COMMON)) {
8455 BNX2X_ERR("MCP unexpected resp, aborting\n");
8457 goto exit_leader_reset2;
8459 load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_DONE, 0);
8461 BNX2X_ERR("MCP response failure, aborting\n");
8463 goto exit_leader_reset2;
8467 /* Try to recover after the failure */
8468 if (bnx2x_process_kill(bp, global)) {
8469 BNX2X_ERR("Something bad had happen on engine %d! Aii!\n",
8472 goto exit_leader_reset2;
8476 * Clear RESET_IN_PROGRES and RESET_GLOBAL bits and update the driver
8479 bnx2x_set_reset_done(bp);
8481 bnx2x_clear_reset_global(bp);
8484 /* unload "fake driver" if it was loaded */
8485 if (!global && !BP_NOMCP(bp)) {
8486 bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP, 0);
8487 bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
8491 bnx2x_release_leader_lock(bp);
8496 static inline void bnx2x_recovery_failed(struct bnx2x *bp)
8498 netdev_err(bp->dev, "Recovery has failed. Power cycle is needed.\n");
8500 /* Disconnect this device */
8501 netif_device_detach(bp->dev);
8504 * Block ifup for all function on this engine until "process kill"
8507 bnx2x_set_reset_in_progress(bp);
8509 /* Shut down the power */
8510 bnx2x_set_power_state(bp, PCI_D3hot);
8512 bp->recovery_state = BNX2X_RECOVERY_FAILED;
8518 * Assumption: runs under rtnl lock. This together with the fact
8519 * that it's called only from bnx2x_sp_rtnl() ensure that it
8520 * will never be called when netif_running(bp->dev) is false.
8522 static void bnx2x_parity_recover(struct bnx2x *bp)
8524 bool global = false;
8525 u32 error_recovered, error_unrecovered;
8528 DP(NETIF_MSG_HW, "Handling parity\n");
8530 switch (bp->recovery_state) {
8531 case BNX2X_RECOVERY_INIT:
8532 DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_INIT\n");
8533 is_parity = bnx2x_chk_parity_attn(bp, &global, false);
8534 WARN_ON(!is_parity);
8536 /* Try to get a LEADER_LOCK HW lock */
8537 if (bnx2x_trylock_leader_lock(bp)) {
8538 bnx2x_set_reset_in_progress(bp);
8540 * Check if there is a global attention and if
8541 * there was a global attention, set the global
8546 bnx2x_set_reset_global(bp);
8551 /* Stop the driver */
8552 /* If interface has been removed - break */
8553 if (bnx2x_nic_unload(bp, UNLOAD_RECOVERY))
8556 bp->recovery_state = BNX2X_RECOVERY_WAIT;
8558 /* Ensure "is_leader", MCP command sequence and
8559 * "recovery_state" update values are seen on other
8565 case BNX2X_RECOVERY_WAIT:
8566 DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_WAIT\n");
8567 if (bp->is_leader) {
8568 int other_engine = BP_PATH(bp) ? 0 : 1;
8569 bool other_load_status =
8570 bnx2x_get_load_status(bp, other_engine);
8572 bnx2x_get_load_status(bp, BP_PATH(bp));
8573 global = bnx2x_reset_is_global(bp);
8576 * In case of a parity in a global block, let
8577 * the first leader that performs a
8578 * leader_reset() reset the global blocks in
8579 * order to clear global attentions. Otherwise
8580 * the the gates will remain closed for that
8584 (global && other_load_status)) {
8585 /* Wait until all other functions get
8588 schedule_delayed_work(&bp->sp_rtnl_task,
8592 /* If all other functions got down -
8593 * try to bring the chip back to
8594 * normal. In any case it's an exit
8595 * point for a leader.
8597 if (bnx2x_leader_reset(bp)) {
8598 bnx2x_recovery_failed(bp);
8602 /* If we are here, means that the
8603 * leader has succeeded and doesn't
8604 * want to be a leader any more. Try
8605 * to continue as a none-leader.
8609 } else { /* non-leader */
8610 if (!bnx2x_reset_is_done(bp, BP_PATH(bp))) {
8611 /* Try to get a LEADER_LOCK HW lock as
8612 * long as a former leader may have
8613 * been unloaded by the user or
8614 * released a leadership by another
8617 if (bnx2x_trylock_leader_lock(bp)) {
8618 /* I'm a leader now! Restart a
8625 schedule_delayed_work(&bp->sp_rtnl_task,
8631 * If there was a global attention, wait
8632 * for it to be cleared.
8634 if (bnx2x_reset_is_global(bp)) {
8635 schedule_delayed_work(
8642 bp->eth_stats.recoverable_error;
8644 bp->eth_stats.unrecoverable_error;
8645 bp->recovery_state =
8646 BNX2X_RECOVERY_NIC_LOADING;
8647 if (bnx2x_nic_load(bp, LOAD_NORMAL)) {
8648 error_unrecovered++;
8650 "Recovery failed. Power cycle needed\n");
8651 /* Disconnect this device */
8652 netif_device_detach(bp->dev);
8653 /* Shut down the power */
8654 bnx2x_set_power_state(
8658 bp->recovery_state =
8659 BNX2X_RECOVERY_DONE;
8663 bp->eth_stats.recoverable_error =
8665 bp->eth_stats.unrecoverable_error =
8677 static int bnx2x_close(struct net_device *dev);
8679 /* bnx2x_nic_unload() flushes the bnx2x_wq, thus reset task is
8680 * scheduled on a general queue in order to prevent a dead lock.
8682 static void bnx2x_sp_rtnl_task(struct work_struct *work)
8684 struct bnx2x *bp = container_of(work, struct bnx2x, sp_rtnl_task.work);
8688 if (!netif_running(bp->dev))
8691 /* if stop on error is defined no recovery flows should be executed */
8692 #ifdef BNX2X_STOP_ON_ERROR
8693 BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n"
8694 "you will need to reboot when done\n");
8695 goto sp_rtnl_not_reset;
8698 if (unlikely(bp->recovery_state != BNX2X_RECOVERY_DONE)) {
8700 * Clear all pending SP commands as we are going to reset the
8703 bp->sp_rtnl_state = 0;
8706 bnx2x_parity_recover(bp);
8711 if (test_and_clear_bit(BNX2X_SP_RTNL_TX_TIMEOUT, &bp->sp_rtnl_state)) {
8713 * Clear all pending SP commands as we are going to reset the
8716 bp->sp_rtnl_state = 0;
8719 bnx2x_nic_unload(bp, UNLOAD_NORMAL);
8720 bnx2x_nic_load(bp, LOAD_NORMAL);
8724 #ifdef BNX2X_STOP_ON_ERROR
8727 if (test_and_clear_bit(BNX2X_SP_RTNL_SETUP_TC, &bp->sp_rtnl_state))
8728 bnx2x_setup_tc(bp->dev, bp->dcbx_port_params.ets.num_of_cos);
8731 * in case of fan failure we need to reset id if the "stop on error"
8732 * debug flag is set, since we trying to prevent permanent overheating
8735 if (test_and_clear_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state)) {
8736 DP(NETIF_MSG_HW, "fan failure detected. Unloading driver\n");
8737 netif_device_detach(bp->dev);
8738 bnx2x_close(bp->dev);
8745 /* end of nic load/unload */
8747 static void bnx2x_period_task(struct work_struct *work)
8749 struct bnx2x *bp = container_of(work, struct bnx2x, period_task.work);
8751 if (!netif_running(bp->dev))
8752 goto period_task_exit;
8754 if (CHIP_REV_IS_SLOW(bp)) {
8755 BNX2X_ERR("period task called on emulation, ignoring\n");
8756 goto period_task_exit;
8759 bnx2x_acquire_phy_lock(bp);
8761 * The barrier is needed to ensure the ordering between the writing to
8762 * the bp->port.pmf in the bnx2x_nic_load() or bnx2x_pmf_update() and
8767 bnx2x_period_func(&bp->link_params, &bp->link_vars);
8769 /* Re-queue task in 1 sec */
8770 queue_delayed_work(bnx2x_wq, &bp->period_task, 1*HZ);
8773 bnx2x_release_phy_lock(bp);
8779 * Init service functions
8782 static u32 bnx2x_get_pretend_reg(struct bnx2x *bp)
8784 u32 base = PXP2_REG_PGL_PRETEND_FUNC_F0;
8785 u32 stride = PXP2_REG_PGL_PRETEND_FUNC_F1 - base;
8786 return base + (BP_ABS_FUNC(bp)) * stride;
8789 static void bnx2x_undi_int_disable_e1h(struct bnx2x *bp)
8791 u32 reg = bnx2x_get_pretend_reg(bp);
8793 /* Flush all outstanding writes */
8796 /* Pretend to be function 0 */
8798 REG_RD(bp, reg); /* Flush the GRC transaction (in the chip) */
8800 /* From now we are in the "like-E1" mode */
8801 bnx2x_int_disable(bp);
8803 /* Flush all outstanding writes */
8806 /* Restore the original function */
8807 REG_WR(bp, reg, BP_ABS_FUNC(bp));
8811 static inline void bnx2x_undi_int_disable(struct bnx2x *bp)
8814 bnx2x_int_disable(bp);
8816 bnx2x_undi_int_disable_e1h(bp);
8819 static void __devinit bnx2x_prev_unload_close_mac(struct bnx2x *bp)
8821 u32 val, base_addr, offset, mask, reset_reg;
8822 bool mac_stopped = false;
8823 u8 port = BP_PORT(bp);
8825 reset_reg = REG_RD(bp, MISC_REG_RESET_REG_2);
8827 if (!CHIP_IS_E3(bp)) {
8828 val = REG_RD(bp, NIG_REG_BMAC0_REGS_OUT_EN + port * 4);
8829 mask = MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port;
8830 if ((mask & reset_reg) && val) {
8832 BNX2X_DEV_INFO("Disable bmac Rx\n");
8833 base_addr = BP_PORT(bp) ? NIG_REG_INGRESS_BMAC1_MEM
8834 : NIG_REG_INGRESS_BMAC0_MEM;
8835 offset = CHIP_IS_E2(bp) ? BIGMAC2_REGISTER_BMAC_CONTROL
8836 : BIGMAC_REGISTER_BMAC_CONTROL;
8839 * use rd/wr since we cannot use dmae. This is safe
8840 * since MCP won't access the bus due to the request
8841 * to unload, and no function on the path can be
8842 * loaded at this time.
8844 wb_data[0] = REG_RD(bp, base_addr + offset);
8845 wb_data[1] = REG_RD(bp, base_addr + offset + 0x4);
8846 wb_data[0] &= ~BMAC_CONTROL_RX_ENABLE;
8847 REG_WR(bp, base_addr + offset, wb_data[0]);
8848 REG_WR(bp, base_addr + offset + 0x4, wb_data[1]);
8851 BNX2X_DEV_INFO("Disable emac Rx\n");
8852 REG_WR(bp, NIG_REG_NIG_EMAC0_EN + BP_PORT(bp)*4, 0);
8856 if (reset_reg & MISC_REGISTERS_RESET_REG_2_XMAC) {
8857 BNX2X_DEV_INFO("Disable xmac Rx\n");
8858 base_addr = BP_PORT(bp) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
8859 val = REG_RD(bp, base_addr + XMAC_REG_PFC_CTRL_HI);
8860 REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
8862 REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
8864 REG_WR(bp, base_addr + XMAC_REG_CTRL, 0);
8867 mask = MISC_REGISTERS_RESET_REG_2_UMAC0 << port;
8868 if (mask & reset_reg) {
8869 BNX2X_DEV_INFO("Disable umac Rx\n");
8870 base_addr = BP_PORT(bp) ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
8871 REG_WR(bp, base_addr + UMAC_REG_COMMAND_CONFIG, 0);
8881 #define BNX2X_PREV_UNDI_PROD_ADDR(p) (BAR_TSTRORM_INTMEM + 0x1508 + ((p) << 4))
8882 #define BNX2X_PREV_UNDI_RCQ(val) ((val) & 0xffff)
8883 #define BNX2X_PREV_UNDI_BD(val) ((val) >> 16 & 0xffff)
8884 #define BNX2X_PREV_UNDI_PROD(rcq, bd) ((bd) << 16 | (rcq))
8886 static void __devinit bnx2x_prev_unload_undi_inc(struct bnx2x *bp, u8 port,
8890 u32 tmp_reg = REG_RD(bp, BNX2X_PREV_UNDI_PROD_ADDR(port));
8892 rcq = BNX2X_PREV_UNDI_RCQ(tmp_reg) + inc;
8893 bd = BNX2X_PREV_UNDI_BD(tmp_reg) + inc;
8895 tmp_reg = BNX2X_PREV_UNDI_PROD(rcq, bd);
8896 REG_WR(bp, BNX2X_PREV_UNDI_PROD_ADDR(port), tmp_reg);
8898 BNX2X_DEV_INFO("UNDI producer [%d] rings bd -> 0x%04x, rcq -> 0x%04x\n",
8902 static int __devinit bnx2x_prev_mcp_done(struct bnx2x *bp)
8904 u32 rc = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
8906 BNX2X_ERR("MCP response failure, aborting\n");
8913 static bool __devinit bnx2x_prev_is_path_marked(struct bnx2x *bp)
8915 struct bnx2x_prev_path_list *tmp_list;
8918 if (down_trylock(&bnx2x_prev_sem))
8921 list_for_each_entry(tmp_list, &bnx2x_prev_list, list) {
8922 if (PCI_SLOT(bp->pdev->devfn) == tmp_list->slot &&
8923 bp->pdev->bus->number == tmp_list->bus &&
8924 BP_PATH(bp) == tmp_list->path) {
8926 BNX2X_DEV_INFO("Path %d was already cleaned from previous drivers\n",
8932 up(&bnx2x_prev_sem);
8937 static int __devinit bnx2x_prev_mark_path(struct bnx2x *bp)
8939 struct bnx2x_prev_path_list *tmp_list;
8942 tmp_list = (struct bnx2x_prev_path_list *)
8943 kmalloc(sizeof(struct bnx2x_prev_path_list), GFP_KERNEL);
8945 BNX2X_ERR("Failed to allocate 'bnx2x_prev_path_list'\n");
8949 tmp_list->bus = bp->pdev->bus->number;
8950 tmp_list->slot = PCI_SLOT(bp->pdev->devfn);
8951 tmp_list->path = BP_PATH(bp);
8953 rc = down_interruptible(&bnx2x_prev_sem);
8955 BNX2X_ERR("Received %d when tried to take lock\n", rc);
8958 BNX2X_DEV_INFO("Marked path [%d] - finished previous unload\n",
8960 list_add(&tmp_list->list, &bnx2x_prev_list);
8961 up(&bnx2x_prev_sem);
8967 static bool __devinit bnx2x_can_flr(struct bnx2x *bp)
8971 struct pci_dev *dev = bp->pdev;
8973 pos = pci_pcie_cap(dev);
8977 pci_read_config_dword(dev, pos + PCI_EXP_DEVCAP, &cap);
8978 if (!(cap & PCI_EXP_DEVCAP_FLR))
8984 static int __devinit bnx2x_do_flr(struct bnx2x *bp)
8988 struct pci_dev *dev = bp->pdev;
8990 /* probe the capability first */
8991 if (bnx2x_can_flr(bp))
8994 pos = pci_pcie_cap(dev);
8998 /* Wait for Transaction Pending bit clean */
8999 for (i = 0; i < 4; i++) {
9001 msleep((1 << (i - 1)) * 100);
9003 pci_read_config_word(dev, pos + PCI_EXP_DEVSTA, &status);
9004 if (!(status & PCI_EXP_DEVSTA_TRPND))
9009 "transaction is not cleared; proceeding with reset anyway\n");
9012 if (bp->common.bc_ver < REQ_BC_VER_4_INITIATE_FLR) {
9013 BNX2X_ERR("FLR not supported by BC_VER: 0x%x\n",
9018 bnx2x_fw_command(bp, DRV_MSG_CODE_INITIATE_FLR, 0);
9023 static int __devinit bnx2x_prev_unload_uncommon(struct bnx2x *bp)
9027 BNX2X_DEV_INFO("Uncommon unload Flow\n");
9029 /* Test if previous unload process was already finished for this path */
9030 if (bnx2x_prev_is_path_marked(bp))
9031 return bnx2x_prev_mcp_done(bp);
9033 /* If function has FLR capabilities, and existing FW version matches
9034 * the one required, then FLR will be sufficient to clean any residue
9035 * left by previous driver
9037 if (bnx2x_test_firmware_version(bp, false) && bnx2x_can_flr(bp))
9038 return bnx2x_do_flr(bp);
9040 /* Close the MCP request, return failure*/
9041 rc = bnx2x_prev_mcp_done(bp);
9043 rc = BNX2X_PREV_WAIT_NEEDED;
9048 static int __devinit bnx2x_prev_unload_common(struct bnx2x *bp)
9050 u32 reset_reg, tmp_reg = 0, rc;
9051 /* It is possible a previous function received 'common' answer,
9052 * but hasn't loaded yet, therefore creating a scenario of
9053 * multiple functions receiving 'common' on the same path.
9055 BNX2X_DEV_INFO("Common unload Flow\n");
9057 if (bnx2x_prev_is_path_marked(bp))
9058 return bnx2x_prev_mcp_done(bp);
9060 reset_reg = REG_RD(bp, MISC_REG_RESET_REG_1);
9062 /* Reset should be performed after BRB is emptied */
9063 if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_BRB1) {
9064 u32 timer_count = 1000;
9065 bool prev_undi = false;
9067 /* Close the MAC Rx to prevent BRB from filling up */
9068 bnx2x_prev_unload_close_mac(bp);
9070 /* Check if the UNDI driver was previously loaded
9071 * UNDI driver initializes CID offset for normal bell to 0x7
9073 reset_reg = REG_RD(bp, MISC_REG_RESET_REG_1);
9074 if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_DORQ) {
9075 tmp_reg = REG_RD(bp, DORQ_REG_NORM_CID_OFST);
9076 if (tmp_reg == 0x7) {
9077 BNX2X_DEV_INFO("UNDI previously loaded\n");
9079 /* clear the UNDI indication */
9080 REG_WR(bp, DORQ_REG_NORM_CID_OFST, 0);
9083 /* wait until BRB is empty */
9084 tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
9085 while (timer_count) {
9086 u32 prev_brb = tmp_reg;
9088 tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
9092 BNX2X_DEV_INFO("BRB still has 0x%08x\n", tmp_reg);
9094 /* reset timer as long as BRB actually gets emptied */
9095 if (prev_brb > tmp_reg)
9100 /* If UNDI resides in memory, manually increment it */
9102 bnx2x_prev_unload_undi_inc(bp, BP_PORT(bp), 1);
9108 BNX2X_ERR("Failed to empty BRB, hope for the best\n");
9112 /* No packets are in the pipeline, path is ready for reset */
9113 bnx2x_reset_common(bp);
9115 rc = bnx2x_prev_mark_path(bp);
9117 bnx2x_prev_mcp_done(bp);
9121 return bnx2x_prev_mcp_done(bp);
9124 static int __devinit bnx2x_prev_unload(struct bnx2x *bp)
9126 int time_counter = 10;
9127 u32 rc, fw, hw_lock_reg, hw_lock_val;
9128 BNX2X_DEV_INFO("Entering Previous Unload Flow\n");
9130 /* Release previously held locks */
9131 hw_lock_reg = (BP_FUNC(bp) <= 5) ?
9132 (MISC_REG_DRIVER_CONTROL_1 + BP_FUNC(bp) * 8) :
9133 (MISC_REG_DRIVER_CONTROL_7 + (BP_FUNC(bp) - 6) * 8);
9135 hw_lock_val = (REG_RD(bp, hw_lock_reg));
9137 if (hw_lock_val & HW_LOCK_RESOURCE_NVRAM) {
9138 BNX2X_DEV_INFO("Release Previously held NVRAM lock\n");
9139 REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
9140 (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << BP_PORT(bp)));
9143 BNX2X_DEV_INFO("Release Previously held hw lock\n");
9144 REG_WR(bp, hw_lock_reg, 0xffffffff);
9146 BNX2X_DEV_INFO("No need to release hw/nvram locks\n");
9148 if (MCPR_ACCESS_LOCK_LOCK & REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK)) {
9149 BNX2X_DEV_INFO("Release previously held alr\n");
9150 REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, 0);
9155 /* Lock MCP using an unload request */
9156 fw = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS, 0);
9158 BNX2X_ERR("MCP response failure, aborting\n");
9163 if (fw == FW_MSG_CODE_DRV_UNLOAD_COMMON) {
9164 rc = bnx2x_prev_unload_common(bp);
9168 /* non-common reply from MCP night require looping */
9169 rc = bnx2x_prev_unload_uncommon(bp);
9170 if (rc != BNX2X_PREV_WAIT_NEEDED)
9174 } while (--time_counter);
9176 if (!time_counter || rc) {
9177 BNX2X_ERR("Failed unloading previous driver, aborting\n");
9181 BNX2X_DEV_INFO("Finished Previous Unload Flow [%d]\n", rc);
9186 static void __devinit bnx2x_get_common_hwinfo(struct bnx2x *bp)
9188 u32 val, val2, val3, val4, id, boot_mode;
9191 /* Get the chip revision id and number. */
9192 /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
9193 val = REG_RD(bp, MISC_REG_CHIP_NUM);
9194 id = ((val & 0xffff) << 16);
9195 val = REG_RD(bp, MISC_REG_CHIP_REV);
9196 id |= ((val & 0xf) << 12);
9197 val = REG_RD(bp, MISC_REG_CHIP_METAL);
9198 id |= ((val & 0xff) << 4);
9199 val = REG_RD(bp, MISC_REG_BOND_ID);
9201 bp->common.chip_id = id;
9203 /* Set doorbell size */
9204 bp->db_size = (1 << BNX2X_DB_SHIFT);
9206 if (!CHIP_IS_E1x(bp)) {
9207 val = REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR);
9209 val = REG_RD(bp, MISC_REG_PORT4MODE_EN);
9211 val = (val >> 1) & 1;
9212 BNX2X_DEV_INFO("chip is in %s\n", val ? "4_PORT_MODE" :
9214 bp->common.chip_port_mode = val ? CHIP_4_PORT_MODE :
9217 if (CHIP_MODE_IS_4_PORT(bp))
9218 bp->pfid = (bp->pf_num >> 1); /* 0..3 */
9220 bp->pfid = (bp->pf_num & 0x6); /* 0, 2, 4, 6 */
9222 bp->common.chip_port_mode = CHIP_PORT_MODE_NONE; /* N/A */
9223 bp->pfid = bp->pf_num; /* 0..7 */
9226 BNX2X_DEV_INFO("pf_id: %x", bp->pfid);
9228 bp->link_params.chip_id = bp->common.chip_id;
9229 BNX2X_DEV_INFO("chip ID is 0x%x\n", id);
9231 val = (REG_RD(bp, 0x2874) & 0x55);
9232 if ((bp->common.chip_id & 0x1) ||
9233 (CHIP_IS_E1(bp) && val) || (CHIP_IS_E1H(bp) && (val == 0x55))) {
9234 bp->flags |= ONE_PORT_FLAG;
9235 BNX2X_DEV_INFO("single port device\n");
9238 val = REG_RD(bp, MCP_REG_MCPR_NVM_CFG4);
9239 bp->common.flash_size = (BNX2X_NVRAM_1MB_SIZE <<
9240 (val & MCPR_NVM_CFG4_FLASH_SIZE));
9241 BNX2X_DEV_INFO("flash_size 0x%x (%d)\n",
9242 bp->common.flash_size, bp->common.flash_size);
9244 bnx2x_init_shmem(bp);
9248 bp->common.shmem2_base = REG_RD(bp, (BP_PATH(bp) ?
9249 MISC_REG_GENERIC_CR_1 :
9250 MISC_REG_GENERIC_CR_0));
9252 bp->link_params.shmem_base = bp->common.shmem_base;
9253 bp->link_params.shmem2_base = bp->common.shmem2_base;
9254 BNX2X_DEV_INFO("shmem offset 0x%x shmem2 offset 0x%x\n",
9255 bp->common.shmem_base, bp->common.shmem2_base);
9257 if (!bp->common.shmem_base) {
9258 BNX2X_DEV_INFO("MCP not active\n");
9259 bp->flags |= NO_MCP_FLAG;
9263 bp->common.hw_config = SHMEM_RD(bp, dev_info.shared_hw_config.config);
9264 BNX2X_DEV_INFO("hw_config 0x%08x\n", bp->common.hw_config);
9266 bp->link_params.hw_led_mode = ((bp->common.hw_config &
9267 SHARED_HW_CFG_LED_MODE_MASK) >>
9268 SHARED_HW_CFG_LED_MODE_SHIFT);
9270 bp->link_params.feature_config_flags = 0;
9271 val = SHMEM_RD(bp, dev_info.shared_feature_config.config);
9272 if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED)
9273 bp->link_params.feature_config_flags |=
9274 FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
9276 bp->link_params.feature_config_flags &=
9277 ~FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
9279 val = SHMEM_RD(bp, dev_info.bc_rev) >> 8;
9280 bp->common.bc_ver = val;
9281 BNX2X_DEV_INFO("bc_ver %X\n", val);
9282 if (val < BNX2X_BC_VER) {
9283 /* for now only warn
9284 * later we might need to enforce this */
9285 BNX2X_ERR("This driver needs bc_ver %X but found %X, please upgrade BC\n",
9288 bp->link_params.feature_config_flags |=
9289 (val >= REQ_BC_VER_4_VRFY_FIRST_PHY_OPT_MDL) ?
9290 FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY : 0;
9292 bp->link_params.feature_config_flags |=
9293 (val >= REQ_BC_VER_4_VRFY_SPECIFIC_PHY_OPT_MDL) ?
9294 FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY : 0;
9296 bp->link_params.feature_config_flags |=
9297 (val >= REQ_BC_VER_4_SFP_TX_DISABLE_SUPPORTED) ?
9298 FEATURE_CONFIG_BC_SUPPORTS_SFP_TX_DISABLED : 0;
9299 bp->flags |= (val >= REQ_BC_VER_4_PFC_STATS_SUPPORTED) ?
9300 BC_SUPPORTS_PFC_STATS : 0;
9302 boot_mode = SHMEM_RD(bp,
9303 dev_info.port_feature_config[BP_PORT(bp)].mba_config) &
9304 PORT_FEATURE_MBA_BOOT_AGENT_TYPE_MASK;
9305 switch (boot_mode) {
9306 case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_PXE:
9307 bp->common.boot_mode = FEATURE_ETH_BOOTMODE_PXE;
9309 case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_ISCSIB:
9310 bp->common.boot_mode = FEATURE_ETH_BOOTMODE_ISCSI;
9312 case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_FCOE_BOOT:
9313 bp->common.boot_mode = FEATURE_ETH_BOOTMODE_FCOE;
9315 case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_NONE:
9316 bp->common.boot_mode = FEATURE_ETH_BOOTMODE_NONE;
9320 pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_PMC, &pmc);
9321 bp->flags |= (pmc & PCI_PM_CAP_PME_D3cold) ? 0 : NO_WOL_FLAG;
9323 BNX2X_DEV_INFO("%sWoL capable\n",
9324 (bp->flags & NO_WOL_FLAG) ? "not " : "");
9326 val = SHMEM_RD(bp, dev_info.shared_hw_config.part_num);
9327 val2 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[4]);
9328 val3 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[8]);
9329 val4 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[12]);
9331 dev_info(&bp->pdev->dev, "part number %X-%X-%X-%X\n",
9332 val, val2, val3, val4);
9335 #define IGU_FID(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID)
9336 #define IGU_VEC(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR)
9338 static void __devinit bnx2x_get_igu_cam_info(struct bnx2x *bp)
9340 int pfid = BP_FUNC(bp);
9343 u8 fid, igu_sb_cnt = 0;
9345 bp->igu_base_sb = 0xff;
9346 if (CHIP_INT_MODE_IS_BC(bp)) {
9348 igu_sb_cnt = bp->igu_sb_cnt;
9349 bp->igu_base_sb = (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn) *
9352 bp->igu_dsb_id = E1HVN_MAX * FP_SB_MAX_E1x +
9353 (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn);
9358 /* IGU in normal mode - read CAM */
9359 for (igu_sb_id = 0; igu_sb_id < IGU_REG_MAPPING_MEMORY_SIZE;
9361 val = REG_RD(bp, IGU_REG_MAPPING_MEMORY + igu_sb_id * 4);
9362 if (!(val & IGU_REG_MAPPING_MEMORY_VALID))
9365 if ((fid & IGU_FID_ENCODE_IS_PF)) {
9366 if ((fid & IGU_FID_PF_NUM_MASK) != pfid)
9368 if (IGU_VEC(val) == 0)
9369 /* default status block */
9370 bp->igu_dsb_id = igu_sb_id;
9372 if (bp->igu_base_sb == 0xff)
9373 bp->igu_base_sb = igu_sb_id;
9379 #ifdef CONFIG_PCI_MSI
9381 * It's expected that number of CAM entries for this functions is equal
9382 * to the number evaluated based on the MSI-X table size. We want a
9383 * harsh warning if these values are different!
9385 WARN_ON(bp->igu_sb_cnt != igu_sb_cnt);
9388 if (igu_sb_cnt == 0)
9389 BNX2X_ERR("CAM configuration error\n");
9392 static void __devinit bnx2x_link_settings_supported(struct bnx2x *bp,
9395 int cfg_size = 0, idx, port = BP_PORT(bp);
9397 /* Aggregation of supported attributes of all external phys */
9398 bp->port.supported[0] = 0;
9399 bp->port.supported[1] = 0;
9400 switch (bp->link_params.num_phys) {
9402 bp->port.supported[0] = bp->link_params.phy[INT_PHY].supported;
9406 bp->port.supported[0] = bp->link_params.phy[EXT_PHY1].supported;
9410 if (bp->link_params.multi_phy_config &
9411 PORT_HW_CFG_PHY_SWAPPED_ENABLED) {
9412 bp->port.supported[1] =
9413 bp->link_params.phy[EXT_PHY1].supported;
9414 bp->port.supported[0] =
9415 bp->link_params.phy[EXT_PHY2].supported;
9417 bp->port.supported[0] =
9418 bp->link_params.phy[EXT_PHY1].supported;
9419 bp->port.supported[1] =
9420 bp->link_params.phy[EXT_PHY2].supported;
9426 if (!(bp->port.supported[0] || bp->port.supported[1])) {
9427 BNX2X_ERR("NVRAM config error. BAD phy config. PHY1 config 0x%x, PHY2 config 0x%x\n",
9429 dev_info.port_hw_config[port].external_phy_config),
9431 dev_info.port_hw_config[port].external_phy_config2));
9436 bp->port.phy_addr = REG_RD(bp, MISC_REG_WC0_CTRL_PHY_ADDR);
9438 switch (switch_cfg) {
9440 bp->port.phy_addr = REG_RD(
9441 bp, NIG_REG_SERDES0_CTRL_PHY_ADDR + port*0x10);
9443 case SWITCH_CFG_10G:
9444 bp->port.phy_addr = REG_RD(
9445 bp, NIG_REG_XGXS0_CTRL_PHY_ADDR + port*0x18);
9448 BNX2X_ERR("BAD switch_cfg link_config 0x%x\n",
9449 bp->port.link_config[0]);
9453 BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr);
9454 /* mask what we support according to speed_cap_mask per configuration */
9455 for (idx = 0; idx < cfg_size; idx++) {
9456 if (!(bp->link_params.speed_cap_mask[idx] &
9457 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF))
9458 bp->port.supported[idx] &= ~SUPPORTED_10baseT_Half;
9460 if (!(bp->link_params.speed_cap_mask[idx] &
9461 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL))
9462 bp->port.supported[idx] &= ~SUPPORTED_10baseT_Full;
9464 if (!(bp->link_params.speed_cap_mask[idx] &
9465 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF))
9466 bp->port.supported[idx] &= ~SUPPORTED_100baseT_Half;
9468 if (!(bp->link_params.speed_cap_mask[idx] &
9469 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL))
9470 bp->port.supported[idx] &= ~SUPPORTED_100baseT_Full;
9472 if (!(bp->link_params.speed_cap_mask[idx] &
9473 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G))
9474 bp->port.supported[idx] &= ~(SUPPORTED_1000baseT_Half |
9475 SUPPORTED_1000baseT_Full);
9477 if (!(bp->link_params.speed_cap_mask[idx] &
9478 PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
9479 bp->port.supported[idx] &= ~SUPPORTED_2500baseX_Full;
9481 if (!(bp->link_params.speed_cap_mask[idx] &
9482 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G))
9483 bp->port.supported[idx] &= ~SUPPORTED_10000baseT_Full;
9487 BNX2X_DEV_INFO("supported 0x%x 0x%x\n", bp->port.supported[0],
9488 bp->port.supported[1]);
9491 static void __devinit bnx2x_link_settings_requested(struct bnx2x *bp)
9493 u32 link_config, idx, cfg_size = 0;
9494 bp->port.advertising[0] = 0;
9495 bp->port.advertising[1] = 0;
9496 switch (bp->link_params.num_phys) {
9505 for (idx = 0; idx < cfg_size; idx++) {
9506 bp->link_params.req_duplex[idx] = DUPLEX_FULL;
9507 link_config = bp->port.link_config[idx];
9508 switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) {
9509 case PORT_FEATURE_LINK_SPEED_AUTO:
9510 if (bp->port.supported[idx] & SUPPORTED_Autoneg) {
9511 bp->link_params.req_line_speed[idx] =
9513 bp->port.advertising[idx] |=
9514 bp->port.supported[idx];
9515 if (bp->link_params.phy[EXT_PHY1].type ==
9516 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
9517 bp->port.advertising[idx] |=
9518 (SUPPORTED_100baseT_Half |
9519 SUPPORTED_100baseT_Full);
9521 /* force 10G, no AN */
9522 bp->link_params.req_line_speed[idx] =
9524 bp->port.advertising[idx] |=
9525 (ADVERTISED_10000baseT_Full |
9531 case PORT_FEATURE_LINK_SPEED_10M_FULL:
9532 if (bp->port.supported[idx] & SUPPORTED_10baseT_Full) {
9533 bp->link_params.req_line_speed[idx] =
9535 bp->port.advertising[idx] |=
9536 (ADVERTISED_10baseT_Full |
9539 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
9541 bp->link_params.speed_cap_mask[idx]);
9546 case PORT_FEATURE_LINK_SPEED_10M_HALF:
9547 if (bp->port.supported[idx] & SUPPORTED_10baseT_Half) {
9548 bp->link_params.req_line_speed[idx] =
9550 bp->link_params.req_duplex[idx] =
9552 bp->port.advertising[idx] |=
9553 (ADVERTISED_10baseT_Half |
9556 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
9558 bp->link_params.speed_cap_mask[idx]);
9563 case PORT_FEATURE_LINK_SPEED_100M_FULL:
9564 if (bp->port.supported[idx] &
9565 SUPPORTED_100baseT_Full) {
9566 bp->link_params.req_line_speed[idx] =
9568 bp->port.advertising[idx] |=
9569 (ADVERTISED_100baseT_Full |
9572 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
9574 bp->link_params.speed_cap_mask[idx]);
9579 case PORT_FEATURE_LINK_SPEED_100M_HALF:
9580 if (bp->port.supported[idx] &
9581 SUPPORTED_100baseT_Half) {
9582 bp->link_params.req_line_speed[idx] =
9584 bp->link_params.req_duplex[idx] =
9586 bp->port.advertising[idx] |=
9587 (ADVERTISED_100baseT_Half |
9590 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
9592 bp->link_params.speed_cap_mask[idx]);
9597 case PORT_FEATURE_LINK_SPEED_1G:
9598 if (bp->port.supported[idx] &
9599 SUPPORTED_1000baseT_Full) {
9600 bp->link_params.req_line_speed[idx] =
9602 bp->port.advertising[idx] |=
9603 (ADVERTISED_1000baseT_Full |
9606 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
9608 bp->link_params.speed_cap_mask[idx]);
9613 case PORT_FEATURE_LINK_SPEED_2_5G:
9614 if (bp->port.supported[idx] &
9615 SUPPORTED_2500baseX_Full) {
9616 bp->link_params.req_line_speed[idx] =
9618 bp->port.advertising[idx] |=
9619 (ADVERTISED_2500baseX_Full |
9622 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
9624 bp->link_params.speed_cap_mask[idx]);
9629 case PORT_FEATURE_LINK_SPEED_10G_CX4:
9630 if (bp->port.supported[idx] &
9631 SUPPORTED_10000baseT_Full) {
9632 bp->link_params.req_line_speed[idx] =
9634 bp->port.advertising[idx] |=
9635 (ADVERTISED_10000baseT_Full |
9638 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
9640 bp->link_params.speed_cap_mask[idx]);
9644 case PORT_FEATURE_LINK_SPEED_20G:
9645 bp->link_params.req_line_speed[idx] = SPEED_20000;
9649 BNX2X_ERR("NVRAM config error. BAD link speed link_config 0x%x\n",
9651 bp->link_params.req_line_speed[idx] =
9653 bp->port.advertising[idx] =
9654 bp->port.supported[idx];
9658 bp->link_params.req_flow_ctrl[idx] = (link_config &
9659 PORT_FEATURE_FLOW_CONTROL_MASK);
9660 if ((bp->link_params.req_flow_ctrl[idx] ==
9661 BNX2X_FLOW_CTRL_AUTO) &&
9662 !(bp->port.supported[idx] & SUPPORTED_Autoneg)) {
9663 bp->link_params.req_flow_ctrl[idx] =
9664 BNX2X_FLOW_CTRL_NONE;
9667 BNX2X_DEV_INFO("req_line_speed %d req_duplex %d req_flow_ctrl 0x%x advertising 0x%x\n",
9668 bp->link_params.req_line_speed[idx],
9669 bp->link_params.req_duplex[idx],
9670 bp->link_params.req_flow_ctrl[idx],
9671 bp->port.advertising[idx]);
9675 static void __devinit bnx2x_set_mac_buf(u8 *mac_buf, u32 mac_lo, u16 mac_hi)
9677 mac_hi = cpu_to_be16(mac_hi);
9678 mac_lo = cpu_to_be32(mac_lo);
9679 memcpy(mac_buf, &mac_hi, sizeof(mac_hi));
9680 memcpy(mac_buf + sizeof(mac_hi), &mac_lo, sizeof(mac_lo));
9683 static void __devinit bnx2x_get_port_hwinfo(struct bnx2x *bp)
9685 int port = BP_PORT(bp);
9687 u32 ext_phy_type, ext_phy_config;
9689 bp->link_params.bp = bp;
9690 bp->link_params.port = port;
9692 bp->link_params.lane_config =
9693 SHMEM_RD(bp, dev_info.port_hw_config[port].lane_config);
9695 bp->link_params.speed_cap_mask[0] =
9697 dev_info.port_hw_config[port].speed_capability_mask);
9698 bp->link_params.speed_cap_mask[1] =
9700 dev_info.port_hw_config[port].speed_capability_mask2);
9701 bp->port.link_config[0] =
9702 SHMEM_RD(bp, dev_info.port_feature_config[port].link_config);
9704 bp->port.link_config[1] =
9705 SHMEM_RD(bp, dev_info.port_feature_config[port].link_config2);
9707 bp->link_params.multi_phy_config =
9708 SHMEM_RD(bp, dev_info.port_hw_config[port].multi_phy_config);
9709 /* If the device is capable of WoL, set the default state according
9712 config = SHMEM_RD(bp, dev_info.port_feature_config[port].config);
9713 bp->wol = (!(bp->flags & NO_WOL_FLAG) &&
9714 (config & PORT_FEATURE_WOL_ENABLED));
9716 BNX2X_DEV_INFO("lane_config 0x%08x speed_cap_mask0 0x%08x link_config0 0x%08x\n",
9717 bp->link_params.lane_config,
9718 bp->link_params.speed_cap_mask[0],
9719 bp->port.link_config[0]);
9721 bp->link_params.switch_cfg = (bp->port.link_config[0] &
9722 PORT_FEATURE_CONNECTED_SWITCH_MASK);
9723 bnx2x_phy_probe(&bp->link_params);
9724 bnx2x_link_settings_supported(bp, bp->link_params.switch_cfg);
9726 bnx2x_link_settings_requested(bp);
9729 * If connected directly, work with the internal PHY, otherwise, work
9730 * with the external PHY
9734 dev_info.port_hw_config[port].external_phy_config);
9735 ext_phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
9736 if (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
9737 bp->mdio.prtad = bp->port.phy_addr;
9739 else if ((ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) &&
9740 (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN))
9742 XGXS_EXT_PHY_ADDR(ext_phy_config);
9745 * Check if hw lock is required to access MDC/MDIO bus to the PHY(s)
9746 * In MF mode, it is set to cover self test cases
9749 bp->port.need_hw_lock = 1;
9751 bp->port.need_hw_lock = bnx2x_hw_lock_required(bp,
9752 bp->common.shmem_base,
9753 bp->common.shmem2_base);
9756 void bnx2x_get_iscsi_info(struct bnx2x *bp)
9758 u32 no_flags = NO_ISCSI_FLAG;
9760 int port = BP_PORT(bp);
9762 u32 max_iscsi_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
9763 drv_lic_key[port].max_iscsi_conn);
9765 /* Get the number of maximum allowed iSCSI connections */
9766 bp->cnic_eth_dev.max_iscsi_conn =
9767 (max_iscsi_conn & BNX2X_MAX_ISCSI_INIT_CONN_MASK) >>
9768 BNX2X_MAX_ISCSI_INIT_CONN_SHIFT;
9770 BNX2X_DEV_INFO("max_iscsi_conn 0x%x\n",
9771 bp->cnic_eth_dev.max_iscsi_conn);
9774 * If maximum allowed number of connections is zero -
9775 * disable the feature.
9777 if (!bp->cnic_eth_dev.max_iscsi_conn)
9778 bp->flags |= no_flags;
9780 bp->flags |= no_flags;
9785 static void __devinit bnx2x_get_ext_wwn_info(struct bnx2x *bp, int func)
9788 bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
9789 MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_upper);
9790 bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
9791 MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_lower);
9794 bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
9795 MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_upper);
9796 bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
9797 MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_lower);
9800 static void __devinit bnx2x_get_fcoe_info(struct bnx2x *bp)
9803 int port = BP_PORT(bp);
9804 int func = BP_ABS_FUNC(bp);
9806 u32 max_fcoe_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
9807 drv_lic_key[port].max_fcoe_conn);
9809 /* Get the number of maximum allowed FCoE connections */
9810 bp->cnic_eth_dev.max_fcoe_conn =
9811 (max_fcoe_conn & BNX2X_MAX_FCOE_INIT_CONN_MASK) >>
9812 BNX2X_MAX_FCOE_INIT_CONN_SHIFT;
9817 bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
9819 dev_info.port_hw_config[port].
9820 fcoe_wwn_port_name_upper);
9821 bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
9823 dev_info.port_hw_config[port].
9824 fcoe_wwn_port_name_lower);
9827 bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
9829 dev_info.port_hw_config[port].
9830 fcoe_wwn_node_name_upper);
9831 bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
9833 dev_info.port_hw_config[port].
9834 fcoe_wwn_node_name_lower);
9835 } else if (!IS_MF_SD(bp)) {
9836 u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg);
9839 * Read the WWN info only if the FCoE feature is enabled for
9842 if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD)
9843 bnx2x_get_ext_wwn_info(bp, func);
9845 } else if (IS_MF_FCOE_SD(bp))
9846 bnx2x_get_ext_wwn_info(bp, func);
9848 BNX2X_DEV_INFO("max_fcoe_conn 0x%x\n", bp->cnic_eth_dev.max_fcoe_conn);
9851 * If maximum allowed number of connections is zero -
9852 * disable the feature.
9854 if (!bp->cnic_eth_dev.max_fcoe_conn)
9855 bp->flags |= NO_FCOE_FLAG;
9857 bp->flags |= NO_FCOE_FLAG;
9861 static void __devinit bnx2x_get_cnic_info(struct bnx2x *bp)
9864 * iSCSI may be dynamically disabled but reading
9865 * info here we will decrease memory usage by driver
9866 * if the feature is disabled for good
9868 bnx2x_get_iscsi_info(bp);
9869 bnx2x_get_fcoe_info(bp);
9872 static void __devinit bnx2x_get_mac_hwinfo(struct bnx2x *bp)
9875 int func = BP_ABS_FUNC(bp);
9876 int port = BP_PORT(bp);
9878 u8 *iscsi_mac = bp->cnic_eth_dev.iscsi_mac;
9879 u8 *fip_mac = bp->fip_mac;
9882 /* Zero primary MAC configuration */
9883 memset(bp->dev->dev_addr, 0, ETH_ALEN);
9886 BNX2X_ERROR("warning: random MAC workaround active\n");
9887 eth_hw_addr_random(bp->dev);
9888 } else if (IS_MF(bp)) {
9889 val2 = MF_CFG_RD(bp, func_mf_config[func].mac_upper);
9890 val = MF_CFG_RD(bp, func_mf_config[func].mac_lower);
9891 if ((val2 != FUNC_MF_CFG_UPPERMAC_DEFAULT) &&
9892 (val != FUNC_MF_CFG_LOWERMAC_DEFAULT))
9893 bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
9897 * iSCSI and FCoE NPAR MACs: if there is no either iSCSI or
9898 * FCoE MAC then the appropriate feature should be disabled.
9900 * In non SD mode features configuration comes from
9901 * struct func_ext_config.
9903 if (!IS_MF_SD(bp)) {
9904 u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg);
9905 if (cfg & MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD) {
9906 val2 = MF_CFG_RD(bp, func_ext_config[func].
9907 iscsi_mac_addr_upper);
9908 val = MF_CFG_RD(bp, func_ext_config[func].
9909 iscsi_mac_addr_lower);
9910 bnx2x_set_mac_buf(iscsi_mac, val, val2);
9911 BNX2X_DEV_INFO("Read iSCSI MAC: %pM\n",
9914 bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
9916 if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD) {
9917 val2 = MF_CFG_RD(bp, func_ext_config[func].
9918 fcoe_mac_addr_upper);
9919 val = MF_CFG_RD(bp, func_ext_config[func].
9920 fcoe_mac_addr_lower);
9921 bnx2x_set_mac_buf(fip_mac, val, val2);
9922 BNX2X_DEV_INFO("Read FCoE L2 MAC: %pM\n",
9926 bp->flags |= NO_FCOE_FLAG;
9927 } else { /* SD MODE */
9928 if (IS_MF_STORAGE_SD(bp)) {
9929 if (BNX2X_IS_MF_SD_PROTOCOL_ISCSI(bp)) {
9930 /* use primary mac as iscsi mac */
9931 memcpy(iscsi_mac, bp->dev->dev_addr,
9934 BNX2X_DEV_INFO("SD ISCSI MODE\n");
9935 BNX2X_DEV_INFO("Read iSCSI MAC: %pM\n",
9938 memcpy(fip_mac, bp->dev->dev_addr,
9940 BNX2X_DEV_INFO("SD FCoE MODE\n");
9941 BNX2X_DEV_INFO("Read FIP MAC: %pM\n",
9944 /* Zero primary MAC configuration */
9945 memset(bp->dev->dev_addr, 0, ETH_ALEN);
9950 /* in SF read MACs from port configuration */
9951 val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
9952 val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
9953 bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
9956 val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
9958 val = SHMEM_RD(bp, dev_info.port_hw_config[port].
9960 bnx2x_set_mac_buf(iscsi_mac, val, val2);
9962 val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
9963 fcoe_fip_mac_upper);
9964 val = SHMEM_RD(bp, dev_info.port_hw_config[port].
9965 fcoe_fip_mac_lower);
9966 bnx2x_set_mac_buf(fip_mac, val, val2);
9970 memcpy(bp->link_params.mac_addr, bp->dev->dev_addr, ETH_ALEN);
9971 memcpy(bp->dev->perm_addr, bp->dev->dev_addr, ETH_ALEN);
9974 /* Disable iSCSI if MAC configuration is
9977 if (!is_valid_ether_addr(iscsi_mac)) {
9978 bp->flags |= NO_ISCSI_FLAG;
9979 memset(iscsi_mac, 0, ETH_ALEN);
9982 /* Disable FCoE if MAC configuration is
9985 if (!is_valid_ether_addr(fip_mac)) {
9986 bp->flags |= NO_FCOE_FLAG;
9987 memset(bp->fip_mac, 0, ETH_ALEN);
9991 if (!bnx2x_is_valid_ether_addr(bp, bp->dev->dev_addr))
9992 dev_err(&bp->pdev->dev,
9993 "bad Ethernet MAC address configuration: %pM\n"
9994 "change it manually before bringing up the appropriate network interface\n",
10000 static int __devinit bnx2x_get_hwinfo(struct bnx2x *bp)
10002 int /*abs*/func = BP_ABS_FUNC(bp);
10007 bnx2x_get_common_hwinfo(bp);
10010 * initialize IGU parameters
10012 if (CHIP_IS_E1x(bp)) {
10013 bp->common.int_block = INT_BLOCK_HC;
10015 bp->igu_dsb_id = DEF_SB_IGU_ID;
10016 bp->igu_base_sb = 0;
10018 bp->common.int_block = INT_BLOCK_IGU;
10020 /* do not allow device reset during IGU info preocessing */
10021 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
10023 val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
10025 if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
10028 BNX2X_DEV_INFO("FORCING Normal Mode\n");
10030 val &= ~(IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN);
10031 REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION, val);
10032 REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x7f);
10034 while (tout && REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
10036 usleep_range(1000, 1000);
10039 if (REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
10040 dev_err(&bp->pdev->dev,
10041 "FORCING Normal Mode failed!!!\n");
10046 if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
10047 BNX2X_DEV_INFO("IGU Backward Compatible Mode\n");
10048 bp->common.int_block |= INT_BLOCK_MODE_BW_COMP;
10050 BNX2X_DEV_INFO("IGU Normal Mode\n");
10052 bnx2x_get_igu_cam_info(bp);
10054 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
10058 * set base FW non-default (fast path) status block id, this value is
10059 * used to initialize the fw_sb_id saved on the fp/queue structure to
10060 * determine the id used by the FW.
10062 if (CHIP_IS_E1x(bp))
10063 bp->base_fw_ndsb = BP_PORT(bp) * FP_SB_MAX_E1x + BP_L_ID(bp);
10065 * 57712 - we currently use one FW SB per IGU SB (Rx and Tx of
10066 * the same queue are indicated on the same IGU SB). So we prefer
10067 * FW and IGU SBs to be the same value.
10069 bp->base_fw_ndsb = bp->igu_base_sb;
10071 BNX2X_DEV_INFO("igu_dsb_id %d igu_base_sb %d igu_sb_cnt %d\n"
10072 "base_fw_ndsb %d\n", bp->igu_dsb_id, bp->igu_base_sb,
10073 bp->igu_sb_cnt, bp->base_fw_ndsb);
10076 * Initialize MF configuration
10083 if (!CHIP_IS_E1(bp) && !BP_NOMCP(bp)) {
10084 BNX2X_DEV_INFO("shmem2base 0x%x, size %d, mfcfg offset %d\n",
10085 bp->common.shmem2_base, SHMEM2_RD(bp, size),
10086 (u32)offsetof(struct shmem2_region, mf_cfg_addr));
10088 if (SHMEM2_HAS(bp, mf_cfg_addr))
10089 bp->common.mf_cfg_base = SHMEM2_RD(bp, mf_cfg_addr);
10091 bp->common.mf_cfg_base = bp->common.shmem_base +
10092 offsetof(struct shmem_region, func_mb) +
10093 E1H_FUNC_MAX * sizeof(struct drv_func_mb);
10095 * get mf configuration:
10096 * 1. existence of MF configuration
10097 * 2. MAC address must be legal (check only upper bytes)
10098 * for Switch-Independent mode;
10099 * OVLAN must be legal for Switch-Dependent mode
10100 * 3. SF_MODE configures specific MF mode
10102 if (bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
10103 /* get mf configuration */
10105 dev_info.shared_feature_config.config);
10106 val &= SHARED_FEAT_CFG_FORCE_SF_MODE_MASK;
10109 case SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT:
10110 val = MF_CFG_RD(bp, func_mf_config[func].
10112 /* check for legal mac (upper bytes)*/
10113 if (val != 0xffff) {
10114 bp->mf_mode = MULTI_FUNCTION_SI;
10115 bp->mf_config[vn] = MF_CFG_RD(bp,
10116 func_mf_config[func].config);
10118 BNX2X_DEV_INFO("illegal MAC address for SI\n");
10120 case SHARED_FEAT_CFG_FORCE_SF_MODE_MF_ALLOWED:
10121 /* get OV configuration */
10122 val = MF_CFG_RD(bp,
10123 func_mf_config[FUNC_0].e1hov_tag);
10124 val &= FUNC_MF_CFG_E1HOV_TAG_MASK;
10126 if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
10127 bp->mf_mode = MULTI_FUNCTION_SD;
10128 bp->mf_config[vn] = MF_CFG_RD(bp,
10129 func_mf_config[func].config);
10131 BNX2X_DEV_INFO("illegal OV for SD\n");
10134 /* Unknown configuration: reset mf_config */
10135 bp->mf_config[vn] = 0;
10136 BNX2X_DEV_INFO("unknown MF mode 0x%x\n", val);
10140 BNX2X_DEV_INFO("%s function mode\n",
10141 IS_MF(bp) ? "multi" : "single");
10143 switch (bp->mf_mode) {
10144 case MULTI_FUNCTION_SD:
10145 val = MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
10146 FUNC_MF_CFG_E1HOV_TAG_MASK;
10147 if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
10149 bp->path_has_ovlan = true;
10151 BNX2X_DEV_INFO("MF OV for func %d is %d (0x%04x)\n",
10152 func, bp->mf_ov, bp->mf_ov);
10154 dev_err(&bp->pdev->dev,
10155 "No valid MF OV for func %d, aborting\n",
10160 case MULTI_FUNCTION_SI:
10161 BNX2X_DEV_INFO("func %d is in MF switch-independent mode\n",
10166 dev_err(&bp->pdev->dev,
10167 "VN %d is in a single function mode, aborting\n",
10174 /* check if other port on the path needs ovlan:
10175 * Since MF configuration is shared between ports
10176 * Possible mixed modes are only
10177 * {SF, SI} {SF, SD} {SD, SF} {SI, SF}
10179 if (CHIP_MODE_IS_4_PORT(bp) &&
10180 !bp->path_has_ovlan &&
10182 bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
10183 u8 other_port = !BP_PORT(bp);
10184 u8 other_func = BP_PATH(bp) + 2*other_port;
10185 val = MF_CFG_RD(bp,
10186 func_mf_config[other_func].e1hov_tag);
10187 if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT)
10188 bp->path_has_ovlan = true;
10192 /* adjust igu_sb_cnt to MF for E1x */
10193 if (CHIP_IS_E1x(bp) && IS_MF(bp))
10194 bp->igu_sb_cnt /= E1HVN_MAX;
10197 bnx2x_get_port_hwinfo(bp);
10199 /* Get MAC addresses */
10200 bnx2x_get_mac_hwinfo(bp);
10202 bnx2x_get_cnic_info(bp);
10207 static void __devinit bnx2x_read_fwinfo(struct bnx2x *bp)
10209 int cnt, i, block_end, rodi;
10210 char vpd_start[BNX2X_VPD_LEN+1];
10211 char str_id_reg[VENDOR_ID_LEN+1];
10212 char str_id_cap[VENDOR_ID_LEN+1];
10214 char *vpd_extended_data = NULL;
10217 cnt = pci_read_vpd(bp->pdev, 0, BNX2X_VPD_LEN, vpd_start);
10218 memset(bp->fw_ver, 0, sizeof(bp->fw_ver));
10220 if (cnt < BNX2X_VPD_LEN)
10221 goto out_not_found;
10223 /* VPD RO tag should be first tag after identifier string, hence
10224 * we should be able to find it in first BNX2X_VPD_LEN chars
10226 i = pci_vpd_find_tag(vpd_start, 0, BNX2X_VPD_LEN,
10227 PCI_VPD_LRDT_RO_DATA);
10229 goto out_not_found;
10231 block_end = i + PCI_VPD_LRDT_TAG_SIZE +
10232 pci_vpd_lrdt_size(&vpd_start[i]);
10234 i += PCI_VPD_LRDT_TAG_SIZE;
10236 if (block_end > BNX2X_VPD_LEN) {
10237 vpd_extended_data = kmalloc(block_end, GFP_KERNEL);
10238 if (vpd_extended_data == NULL)
10239 goto out_not_found;
10241 /* read rest of vpd image into vpd_extended_data */
10242 memcpy(vpd_extended_data, vpd_start, BNX2X_VPD_LEN);
10243 cnt = pci_read_vpd(bp->pdev, BNX2X_VPD_LEN,
10244 block_end - BNX2X_VPD_LEN,
10245 vpd_extended_data + BNX2X_VPD_LEN);
10246 if (cnt < (block_end - BNX2X_VPD_LEN))
10247 goto out_not_found;
10248 vpd_data = vpd_extended_data;
10250 vpd_data = vpd_start;
10252 /* now vpd_data holds full vpd content in both cases */
10254 rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
10255 PCI_VPD_RO_KEYWORD_MFR_ID);
10257 goto out_not_found;
10259 len = pci_vpd_info_field_size(&vpd_data[rodi]);
10261 if (len != VENDOR_ID_LEN)
10262 goto out_not_found;
10264 rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
10266 /* vendor specific info */
10267 snprintf(str_id_reg, VENDOR_ID_LEN + 1, "%04x", PCI_VENDOR_ID_DELL);
10268 snprintf(str_id_cap, VENDOR_ID_LEN + 1, "%04X", PCI_VENDOR_ID_DELL);
10269 if (!strncmp(str_id_reg, &vpd_data[rodi], VENDOR_ID_LEN) ||
10270 !strncmp(str_id_cap, &vpd_data[rodi], VENDOR_ID_LEN)) {
10272 rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
10273 PCI_VPD_RO_KEYWORD_VENDOR0);
10275 len = pci_vpd_info_field_size(&vpd_data[rodi]);
10277 rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
10279 if (len < 32 && (len + rodi) <= BNX2X_VPD_LEN) {
10280 memcpy(bp->fw_ver, &vpd_data[rodi], len);
10281 bp->fw_ver[len] = ' ';
10284 kfree(vpd_extended_data);
10288 kfree(vpd_extended_data);
10292 static void __devinit bnx2x_set_modes_bitmap(struct bnx2x *bp)
10296 if (CHIP_REV_IS_FPGA(bp))
10297 SET_FLAGS(flags, MODE_FPGA);
10298 else if (CHIP_REV_IS_EMUL(bp))
10299 SET_FLAGS(flags, MODE_EMUL);
10301 SET_FLAGS(flags, MODE_ASIC);
10303 if (CHIP_MODE_IS_4_PORT(bp))
10304 SET_FLAGS(flags, MODE_PORT4);
10306 SET_FLAGS(flags, MODE_PORT2);
10308 if (CHIP_IS_E2(bp))
10309 SET_FLAGS(flags, MODE_E2);
10310 else if (CHIP_IS_E3(bp)) {
10311 SET_FLAGS(flags, MODE_E3);
10312 if (CHIP_REV(bp) == CHIP_REV_Ax)
10313 SET_FLAGS(flags, MODE_E3_A0);
10314 else /*if (CHIP_REV(bp) == CHIP_REV_Bx)*/
10315 SET_FLAGS(flags, MODE_E3_B0 | MODE_COS3);
10319 SET_FLAGS(flags, MODE_MF);
10320 switch (bp->mf_mode) {
10321 case MULTI_FUNCTION_SD:
10322 SET_FLAGS(flags, MODE_MF_SD);
10324 case MULTI_FUNCTION_SI:
10325 SET_FLAGS(flags, MODE_MF_SI);
10329 SET_FLAGS(flags, MODE_SF);
10331 #if defined(__LITTLE_ENDIAN)
10332 SET_FLAGS(flags, MODE_LITTLE_ENDIAN);
10333 #else /*(__BIG_ENDIAN)*/
10334 SET_FLAGS(flags, MODE_BIG_ENDIAN);
10336 INIT_MODE_FLAGS(bp) = flags;
10339 static int __devinit bnx2x_init_bp(struct bnx2x *bp)
10344 mutex_init(&bp->port.phy_mutex);
10345 mutex_init(&bp->fw_mb_mutex);
10346 spin_lock_init(&bp->stats_lock);
10348 mutex_init(&bp->cnic_mutex);
10351 INIT_DELAYED_WORK(&bp->sp_task, bnx2x_sp_task);
10352 INIT_DELAYED_WORK(&bp->sp_rtnl_task, bnx2x_sp_rtnl_task);
10353 INIT_DELAYED_WORK(&bp->period_task, bnx2x_period_task);
10354 rc = bnx2x_get_hwinfo(bp);
10358 bnx2x_set_modes_bitmap(bp);
10360 rc = bnx2x_alloc_mem_bp(bp);
10364 bnx2x_read_fwinfo(bp);
10366 func = BP_FUNC(bp);
10368 /* need to reset chip if undi was active */
10369 if (!BP_NOMCP(bp)) {
10372 SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
10373 DRV_MSG_SEQ_NUMBER_MASK;
10374 BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
10376 bnx2x_prev_unload(bp);
10380 if (CHIP_REV_IS_FPGA(bp))
10381 dev_err(&bp->pdev->dev, "FPGA detected\n");
10383 if (BP_NOMCP(bp) && (func == 0))
10384 dev_err(&bp->pdev->dev, "MCP disabled, must load devices in order!\n");
10386 bp->multi_mode = multi_mode;
10388 bp->disable_tpa = disable_tpa;
10391 bp->disable_tpa |= IS_MF_STORAGE_SD(bp);
10394 /* Set TPA flags */
10395 if (bp->disable_tpa) {
10396 bp->flags &= ~(TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
10397 bp->dev->features &= ~NETIF_F_LRO;
10399 bp->flags |= (TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
10400 bp->dev->features |= NETIF_F_LRO;
10403 if (CHIP_IS_E1(bp))
10404 bp->dropless_fc = 0;
10406 bp->dropless_fc = dropless_fc;
10410 bp->tx_ring_size = MAX_TX_AVAIL;
10412 /* make sure that the numbers are in the right granularity */
10413 bp->tx_ticks = (50 / BNX2X_BTR) * BNX2X_BTR;
10414 bp->rx_ticks = (25 / BNX2X_BTR) * BNX2X_BTR;
10416 bp->current_interval = CHIP_REV_IS_SLOW(bp) ? 5*HZ : HZ;
10418 init_timer(&bp->timer);
10419 bp->timer.expires = jiffies + bp->current_interval;
10420 bp->timer.data = (unsigned long) bp;
10421 bp->timer.function = bnx2x_timer;
10423 bnx2x_dcbx_set_state(bp, true, BNX2X_DCBX_ENABLED_ON_NEG_ON);
10424 bnx2x_dcbx_init_params(bp);
10427 if (CHIP_IS_E1x(bp))
10428 bp->cnic_base_cl_id = FP_SB_MAX_E1x;
10430 bp->cnic_base_cl_id = FP_SB_MAX_E2;
10433 /* multiple tx priority */
10434 if (CHIP_IS_E1x(bp))
10435 bp->max_cos = BNX2X_MULTI_TX_COS_E1X;
10436 if (CHIP_IS_E2(bp) || CHIP_IS_E3A0(bp))
10437 bp->max_cos = BNX2X_MULTI_TX_COS_E2_E3A0;
10438 if (CHIP_IS_E3B0(bp))
10439 bp->max_cos = BNX2X_MULTI_TX_COS_E3B0;
10441 bp->gro_check = bnx2x_need_gro_check(bp->dev->mtu);
10447 /****************************************************************************
10448 * General service functions
10449 ****************************************************************************/
10452 * net_device service functions
10455 /* called with rtnl_lock */
10456 static int bnx2x_open(struct net_device *dev)
10458 struct bnx2x *bp = netdev_priv(dev);
10459 bool global = false;
10460 int other_engine = BP_PATH(bp) ? 0 : 1;
10461 bool other_load_status, load_status;
10463 bp->stats_init = true;
10465 netif_carrier_off(dev);
10467 bnx2x_set_power_state(bp, PCI_D0);
10469 other_load_status = bnx2x_get_load_status(bp, other_engine);
10470 load_status = bnx2x_get_load_status(bp, BP_PATH(bp));
10473 * If parity had happen during the unload, then attentions
10474 * and/or RECOVERY_IN_PROGRES may still be set. In this case we
10475 * want the first function loaded on the current engine to
10476 * complete the recovery.
10478 if (!bnx2x_reset_is_done(bp, BP_PATH(bp)) ||
10479 bnx2x_chk_parity_attn(bp, &global, true))
10482 * If there are attentions and they are in a global
10483 * blocks, set the GLOBAL_RESET bit regardless whether
10484 * it will be this function that will complete the
10488 bnx2x_set_reset_global(bp);
10491 * Only the first function on the current engine should
10492 * try to recover in open. In case of attentions in
10493 * global blocks only the first in the chip should try
10496 if ((!load_status &&
10497 (!global || !other_load_status)) &&
10498 bnx2x_trylock_leader_lock(bp) &&
10499 !bnx2x_leader_reset(bp)) {
10500 netdev_info(bp->dev, "Recovered in open\n");
10504 /* recovery has failed... */
10505 bnx2x_set_power_state(bp, PCI_D3hot);
10506 bp->recovery_state = BNX2X_RECOVERY_FAILED;
10508 BNX2X_ERR("Recovery flow hasn't been properly completed yet. Try again later.\n"
10509 "If you still see this message after a few retries then power cycle is required.\n");
10514 bp->recovery_state = BNX2X_RECOVERY_DONE;
10515 return bnx2x_nic_load(bp, LOAD_OPEN);
10518 /* called with rtnl_lock */
10519 static int bnx2x_close(struct net_device *dev)
10521 struct bnx2x *bp = netdev_priv(dev);
10523 /* Unload the driver, release IRQs */
10524 bnx2x_nic_unload(bp, UNLOAD_CLOSE);
10527 bnx2x_set_power_state(bp, PCI_D3hot);
10532 static inline int bnx2x_init_mcast_macs_list(struct bnx2x *bp,
10533 struct bnx2x_mcast_ramrod_params *p)
10535 int mc_count = netdev_mc_count(bp->dev);
10536 struct bnx2x_mcast_list_elem *mc_mac =
10537 kzalloc(sizeof(*mc_mac) * mc_count, GFP_ATOMIC);
10538 struct netdev_hw_addr *ha;
10543 INIT_LIST_HEAD(&p->mcast_list);
10545 netdev_for_each_mc_addr(ha, bp->dev) {
10546 mc_mac->mac = bnx2x_mc_addr(ha);
10547 list_add_tail(&mc_mac->link, &p->mcast_list);
10551 p->mcast_list_len = mc_count;
10556 static inline void bnx2x_free_mcast_macs_list(
10557 struct bnx2x_mcast_ramrod_params *p)
10559 struct bnx2x_mcast_list_elem *mc_mac =
10560 list_first_entry(&p->mcast_list, struct bnx2x_mcast_list_elem,
10568 * bnx2x_set_uc_list - configure a new unicast MACs list.
10570 * @bp: driver handle
10572 * We will use zero (0) as a MAC type for these MACs.
10574 static inline int bnx2x_set_uc_list(struct bnx2x *bp)
10577 struct net_device *dev = bp->dev;
10578 struct netdev_hw_addr *ha;
10579 struct bnx2x_vlan_mac_obj *mac_obj = &bp->fp->mac_obj;
10580 unsigned long ramrod_flags = 0;
10582 /* First schedule a cleanup up of old configuration */
10583 rc = bnx2x_del_all_macs(bp, mac_obj, BNX2X_UC_LIST_MAC, false);
10585 BNX2X_ERR("Failed to schedule DELETE operations: %d\n", rc);
10589 netdev_for_each_uc_addr(ha, dev) {
10590 rc = bnx2x_set_mac_one(bp, bnx2x_uc_addr(ha), mac_obj, true,
10591 BNX2X_UC_LIST_MAC, &ramrod_flags);
10593 BNX2X_ERR("Failed to schedule ADD operations: %d\n",
10599 /* Execute the pending commands */
10600 __set_bit(RAMROD_CONT, &ramrod_flags);
10601 return bnx2x_set_mac_one(bp, NULL, mac_obj, false /* don't care */,
10602 BNX2X_UC_LIST_MAC, &ramrod_flags);
10605 static inline int bnx2x_set_mc_list(struct bnx2x *bp)
10607 struct net_device *dev = bp->dev;
10608 struct bnx2x_mcast_ramrod_params rparam = {NULL};
10611 rparam.mcast_obj = &bp->mcast_obj;
10613 /* first, clear all configured multicast MACs */
10614 rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
10616 BNX2X_ERR("Failed to clear multicast configuration: %d\n", rc);
10620 /* then, configure a new MACs list */
10621 if (netdev_mc_count(dev)) {
10622 rc = bnx2x_init_mcast_macs_list(bp, &rparam);
10624 BNX2X_ERR("Failed to create multicast MACs list: %d\n",
10629 /* Now add the new MACs */
10630 rc = bnx2x_config_mcast(bp, &rparam,
10631 BNX2X_MCAST_CMD_ADD);
10633 BNX2X_ERR("Failed to set a new multicast configuration: %d\n",
10636 bnx2x_free_mcast_macs_list(&rparam);
10643 /* If bp->state is OPEN, should be called with netif_addr_lock_bh() */
10644 void bnx2x_set_rx_mode(struct net_device *dev)
10646 struct bnx2x *bp = netdev_priv(dev);
10647 u32 rx_mode = BNX2X_RX_MODE_NORMAL;
10649 if (bp->state != BNX2X_STATE_OPEN) {
10650 DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
10654 DP(NETIF_MSG_IFUP, "dev->flags = %x\n", bp->dev->flags);
10656 if (dev->flags & IFF_PROMISC)
10657 rx_mode = BNX2X_RX_MODE_PROMISC;
10658 else if ((dev->flags & IFF_ALLMULTI) ||
10659 ((netdev_mc_count(dev) > BNX2X_MAX_MULTICAST) &&
10661 rx_mode = BNX2X_RX_MODE_ALLMULTI;
10663 /* some multicasts */
10664 if (bnx2x_set_mc_list(bp) < 0)
10665 rx_mode = BNX2X_RX_MODE_ALLMULTI;
10667 if (bnx2x_set_uc_list(bp) < 0)
10668 rx_mode = BNX2X_RX_MODE_PROMISC;
10671 bp->rx_mode = rx_mode;
10673 /* handle ISCSI SD mode */
10674 if (IS_MF_ISCSI_SD(bp))
10675 bp->rx_mode = BNX2X_RX_MODE_NONE;
10678 /* Schedule the rx_mode command */
10679 if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state)) {
10680 set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
10684 bnx2x_set_storm_rx_mode(bp);
10687 /* called with rtnl_lock */
10688 static int bnx2x_mdio_read(struct net_device *netdev, int prtad,
10689 int devad, u16 addr)
10691 struct bnx2x *bp = netdev_priv(netdev);
10695 DP(NETIF_MSG_LINK, "mdio_read: prtad 0x%x, devad 0x%x, addr 0x%x\n",
10696 prtad, devad, addr);
10698 /* The HW expects different devad if CL22 is used */
10699 devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
10701 bnx2x_acquire_phy_lock(bp);
10702 rc = bnx2x_phy_read(&bp->link_params, prtad, devad, addr, &value);
10703 bnx2x_release_phy_lock(bp);
10704 DP(NETIF_MSG_LINK, "mdio_read_val 0x%x rc = 0x%x\n", value, rc);
10711 /* called with rtnl_lock */
10712 static int bnx2x_mdio_write(struct net_device *netdev, int prtad, int devad,
10713 u16 addr, u16 value)
10715 struct bnx2x *bp = netdev_priv(netdev);
10719 "mdio_write: prtad 0x%x, devad 0x%x, addr 0x%x, value 0x%x\n",
10720 prtad, devad, addr, value);
10722 /* The HW expects different devad if CL22 is used */
10723 devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
10725 bnx2x_acquire_phy_lock(bp);
10726 rc = bnx2x_phy_write(&bp->link_params, prtad, devad, addr, value);
10727 bnx2x_release_phy_lock(bp);
10731 /* called with rtnl_lock */
10732 static int bnx2x_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
10734 struct bnx2x *bp = netdev_priv(dev);
10735 struct mii_ioctl_data *mdio = if_mii(ifr);
10737 DP(NETIF_MSG_LINK, "ioctl: phy id 0x%x, reg 0x%x, val_in 0x%x\n",
10738 mdio->phy_id, mdio->reg_num, mdio->val_in);
10740 if (!netif_running(dev))
10743 return mdio_mii_ioctl(&bp->mdio, mdio, cmd);
10746 #ifdef CONFIG_NET_POLL_CONTROLLER
10747 static void poll_bnx2x(struct net_device *dev)
10749 struct bnx2x *bp = netdev_priv(dev);
10751 disable_irq(bp->pdev->irq);
10752 bnx2x_interrupt(bp->pdev->irq, dev);
10753 enable_irq(bp->pdev->irq);
10757 static int bnx2x_validate_addr(struct net_device *dev)
10759 struct bnx2x *bp = netdev_priv(dev);
10761 if (!bnx2x_is_valid_ether_addr(bp, dev->dev_addr)) {
10762 BNX2X_ERR("Non-valid Ethernet address\n");
10763 return -EADDRNOTAVAIL;
10768 static const struct net_device_ops bnx2x_netdev_ops = {
10769 .ndo_open = bnx2x_open,
10770 .ndo_stop = bnx2x_close,
10771 .ndo_start_xmit = bnx2x_start_xmit,
10772 .ndo_select_queue = bnx2x_select_queue,
10773 .ndo_set_rx_mode = bnx2x_set_rx_mode,
10774 .ndo_set_mac_address = bnx2x_change_mac_addr,
10775 .ndo_validate_addr = bnx2x_validate_addr,
10776 .ndo_do_ioctl = bnx2x_ioctl,
10777 .ndo_change_mtu = bnx2x_change_mtu,
10778 .ndo_fix_features = bnx2x_fix_features,
10779 .ndo_set_features = bnx2x_set_features,
10780 .ndo_tx_timeout = bnx2x_tx_timeout,
10781 #ifdef CONFIG_NET_POLL_CONTROLLER
10782 .ndo_poll_controller = poll_bnx2x,
10784 .ndo_setup_tc = bnx2x_setup_tc,
10786 #if defined(NETDEV_FCOE_WWNN) && defined(BCM_CNIC)
10787 .ndo_fcoe_get_wwn = bnx2x_fcoe_get_wwn,
10791 static inline int bnx2x_set_coherency_mask(struct bnx2x *bp)
10793 struct device *dev = &bp->pdev->dev;
10795 if (dma_set_mask(dev, DMA_BIT_MASK(64)) == 0) {
10796 bp->flags |= USING_DAC_FLAG;
10797 if (dma_set_coherent_mask(dev, DMA_BIT_MASK(64)) != 0) {
10798 dev_err(dev, "dma_set_coherent_mask failed, aborting\n");
10801 } else if (dma_set_mask(dev, DMA_BIT_MASK(32)) != 0) {
10802 dev_err(dev, "System does not support DMA, aborting\n");
10809 static int __devinit bnx2x_init_dev(struct pci_dev *pdev,
10810 struct net_device *dev,
10811 unsigned long board_type)
10816 bool chip_is_e1x = (board_type == BCM57710 ||
10817 board_type == BCM57711 ||
10818 board_type == BCM57711E);
10820 SET_NETDEV_DEV(dev, &pdev->dev);
10821 bp = netdev_priv(dev);
10827 rc = pci_enable_device(pdev);
10829 dev_err(&bp->pdev->dev,
10830 "Cannot enable PCI device, aborting\n");
10834 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
10835 dev_err(&bp->pdev->dev,
10836 "Cannot find PCI device base address, aborting\n");
10838 goto err_out_disable;
10841 if (!(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
10842 dev_err(&bp->pdev->dev, "Cannot find second PCI device"
10843 " base address, aborting\n");
10845 goto err_out_disable;
10848 if (atomic_read(&pdev->enable_cnt) == 1) {
10849 rc = pci_request_regions(pdev, DRV_MODULE_NAME);
10851 dev_err(&bp->pdev->dev,
10852 "Cannot obtain PCI resources, aborting\n");
10853 goto err_out_disable;
10856 pci_set_master(pdev);
10857 pci_save_state(pdev);
10860 bp->pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
10861 if (bp->pm_cap == 0) {
10862 dev_err(&bp->pdev->dev,
10863 "Cannot find power management capability, aborting\n");
10865 goto err_out_release;
10868 if (!pci_is_pcie(pdev)) {
10869 dev_err(&bp->pdev->dev, "Not PCI Express, aborting\n");
10871 goto err_out_release;
10874 rc = bnx2x_set_coherency_mask(bp);
10876 goto err_out_release;
10878 dev->mem_start = pci_resource_start(pdev, 0);
10879 dev->base_addr = dev->mem_start;
10880 dev->mem_end = pci_resource_end(pdev, 0);
10882 dev->irq = pdev->irq;
10884 bp->regview = pci_ioremap_bar(pdev, 0);
10885 if (!bp->regview) {
10886 dev_err(&bp->pdev->dev,
10887 "Cannot map register space, aborting\n");
10889 goto err_out_release;
10892 /* In E1/E1H use pci device function given by kernel.
10893 * In E2/E3 read physical function from ME register since these chips
10894 * support Physical Device Assignment where kernel BDF maybe arbitrary
10895 * (depending on hypervisor).
10898 bp->pf_num = PCI_FUNC(pdev->devfn);
10899 else {/* chip is E2/3*/
10900 pci_read_config_dword(bp->pdev,
10901 PCICFG_ME_REGISTER, &pci_cfg_dword);
10902 bp->pf_num = (u8)((pci_cfg_dword & ME_REG_ABS_PF_NUM) >>
10903 ME_REG_ABS_PF_NUM_SHIFT);
10905 BNX2X_DEV_INFO("me reg PF num: %d\n", bp->pf_num);
10907 bnx2x_set_power_state(bp, PCI_D0);
10909 /* clean indirect addresses */
10910 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
10911 PCICFG_VENDOR_ID_OFFSET);
10913 * Clean the following indirect addresses for all functions since it
10914 * is not used by the driver.
10916 REG_WR(bp, PXP2_REG_PGL_ADDR_88_F0, 0);
10917 REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F0, 0);
10918 REG_WR(bp, PXP2_REG_PGL_ADDR_90_F0, 0);
10919 REG_WR(bp, PXP2_REG_PGL_ADDR_94_F0, 0);
10922 REG_WR(bp, PXP2_REG_PGL_ADDR_88_F1, 0);
10923 REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F1, 0);
10924 REG_WR(bp, PXP2_REG_PGL_ADDR_90_F1, 0);
10925 REG_WR(bp, PXP2_REG_PGL_ADDR_94_F1, 0);
10929 * Enable internal target-read (in case we are probed after PF FLR).
10930 * Must be done prior to any BAR read access. Only for 57712 and up
10933 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
10935 /* Reset the load counter */
10936 bnx2x_clear_load_status(bp);
10938 dev->watchdog_timeo = TX_TIMEOUT;
10940 dev->netdev_ops = &bnx2x_netdev_ops;
10941 bnx2x_set_ethtool_ops(dev);
10943 dev->priv_flags |= IFF_UNICAST_FLT;
10945 dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
10946 NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
10947 NETIF_F_RXCSUM | NETIF_F_LRO | NETIF_F_GRO |
10948 NETIF_F_RXHASH | NETIF_F_HW_VLAN_TX;
10950 dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
10951 NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 | NETIF_F_HIGHDMA;
10953 dev->features |= dev->hw_features | NETIF_F_HW_VLAN_RX;
10954 if (bp->flags & USING_DAC_FLAG)
10955 dev->features |= NETIF_F_HIGHDMA;
10957 /* Add Loopback capability to the device */
10958 dev->hw_features |= NETIF_F_LOOPBACK;
10961 dev->dcbnl_ops = &bnx2x_dcbnl_ops;
10964 /* get_port_hwinfo() will set prtad and mmds properly */
10965 bp->mdio.prtad = MDIO_PRTAD_NONE;
10967 bp->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
10968 bp->mdio.dev = dev;
10969 bp->mdio.mdio_read = bnx2x_mdio_read;
10970 bp->mdio.mdio_write = bnx2x_mdio_write;
10975 if (atomic_read(&pdev->enable_cnt) == 1)
10976 pci_release_regions(pdev);
10979 pci_disable_device(pdev);
10980 pci_set_drvdata(pdev, NULL);
10986 static void __devinit bnx2x_get_pcie_width_speed(struct bnx2x *bp,
10987 int *width, int *speed)
10989 u32 val = REG_RD(bp, PCICFG_OFFSET + PCICFG_LINK_CONTROL);
10991 *width = (val & PCICFG_LINK_WIDTH) >> PCICFG_LINK_WIDTH_SHIFT;
10993 /* return value of 1=2.5GHz 2=5GHz */
10994 *speed = (val & PCICFG_LINK_SPEED) >> PCICFG_LINK_SPEED_SHIFT;
10997 static int bnx2x_check_firmware(struct bnx2x *bp)
10999 const struct firmware *firmware = bp->firmware;
11000 struct bnx2x_fw_file_hdr *fw_hdr;
11001 struct bnx2x_fw_file_section *sections;
11002 u32 offset, len, num_ops;
11007 if (firmware->size < sizeof(struct bnx2x_fw_file_hdr)) {
11008 BNX2X_ERR("Wrong FW size\n");
11012 fw_hdr = (struct bnx2x_fw_file_hdr *)firmware->data;
11013 sections = (struct bnx2x_fw_file_section *)fw_hdr;
11015 /* Make sure none of the offsets and sizes make us read beyond
11016 * the end of the firmware data */
11017 for (i = 0; i < sizeof(*fw_hdr) / sizeof(*sections); i++) {
11018 offset = be32_to_cpu(sections[i].offset);
11019 len = be32_to_cpu(sections[i].len);
11020 if (offset + len > firmware->size) {
11021 BNX2X_ERR("Section %d length is out of bounds\n", i);
11026 /* Likewise for the init_ops offsets */
11027 offset = be32_to_cpu(fw_hdr->init_ops_offsets.offset);
11028 ops_offsets = (u16 *)(firmware->data + offset);
11029 num_ops = be32_to_cpu(fw_hdr->init_ops.len) / sizeof(struct raw_op);
11031 for (i = 0; i < be32_to_cpu(fw_hdr->init_ops_offsets.len) / 2; i++) {
11032 if (be16_to_cpu(ops_offsets[i]) > num_ops) {
11033 BNX2X_ERR("Section offset %d is out of bounds\n", i);
11038 /* Check FW version */
11039 offset = be32_to_cpu(fw_hdr->fw_version.offset);
11040 fw_ver = firmware->data + offset;
11041 if ((fw_ver[0] != BCM_5710_FW_MAJOR_VERSION) ||
11042 (fw_ver[1] != BCM_5710_FW_MINOR_VERSION) ||
11043 (fw_ver[2] != BCM_5710_FW_REVISION_VERSION) ||
11044 (fw_ver[3] != BCM_5710_FW_ENGINEERING_VERSION)) {
11045 BNX2X_ERR("Bad FW version:%d.%d.%d.%d. Should be %d.%d.%d.%d\n",
11046 fw_ver[0], fw_ver[1], fw_ver[2], fw_ver[3],
11047 BCM_5710_FW_MAJOR_VERSION,
11048 BCM_5710_FW_MINOR_VERSION,
11049 BCM_5710_FW_REVISION_VERSION,
11050 BCM_5710_FW_ENGINEERING_VERSION);
11057 static inline void be32_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
11059 const __be32 *source = (const __be32 *)_source;
11060 u32 *target = (u32 *)_target;
11063 for (i = 0; i < n/4; i++)
11064 target[i] = be32_to_cpu(source[i]);
11068 Ops array is stored in the following format:
11069 {op(8bit), offset(24bit, big endian), data(32bit, big endian)}
11071 static inline void bnx2x_prep_ops(const u8 *_source, u8 *_target, u32 n)
11073 const __be32 *source = (const __be32 *)_source;
11074 struct raw_op *target = (struct raw_op *)_target;
11077 for (i = 0, j = 0; i < n/8; i++, j += 2) {
11078 tmp = be32_to_cpu(source[j]);
11079 target[i].op = (tmp >> 24) & 0xff;
11080 target[i].offset = tmp & 0xffffff;
11081 target[i].raw_data = be32_to_cpu(source[j + 1]);
11086 * IRO array is stored in the following format:
11087 * {base(24bit), m1(16bit), m2(16bit), m3(16bit), size(16bit) }
11089 static inline void bnx2x_prep_iro(const u8 *_source, u8 *_target, u32 n)
11091 const __be32 *source = (const __be32 *)_source;
11092 struct iro *target = (struct iro *)_target;
11095 for (i = 0, j = 0; i < n/sizeof(struct iro); i++) {
11096 target[i].base = be32_to_cpu(source[j]);
11098 tmp = be32_to_cpu(source[j]);
11099 target[i].m1 = (tmp >> 16) & 0xffff;
11100 target[i].m2 = tmp & 0xffff;
11102 tmp = be32_to_cpu(source[j]);
11103 target[i].m3 = (tmp >> 16) & 0xffff;
11104 target[i].size = tmp & 0xffff;
11109 static inline void be16_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
11111 const __be16 *source = (const __be16 *)_source;
11112 u16 *target = (u16 *)_target;
11115 for (i = 0; i < n/2; i++)
11116 target[i] = be16_to_cpu(source[i]);
11119 #define BNX2X_ALLOC_AND_SET(arr, lbl, func) \
11121 u32 len = be32_to_cpu(fw_hdr->arr.len); \
11122 bp->arr = kmalloc(len, GFP_KERNEL); \
11125 func(bp->firmware->data + be32_to_cpu(fw_hdr->arr.offset), \
11126 (u8 *)bp->arr, len); \
11129 static int bnx2x_init_firmware(struct bnx2x *bp)
11131 const char *fw_file_name;
11132 struct bnx2x_fw_file_hdr *fw_hdr;
11138 if (CHIP_IS_E1(bp))
11139 fw_file_name = FW_FILE_NAME_E1;
11140 else if (CHIP_IS_E1H(bp))
11141 fw_file_name = FW_FILE_NAME_E1H;
11142 else if (!CHIP_IS_E1x(bp))
11143 fw_file_name = FW_FILE_NAME_E2;
11145 BNX2X_ERR("Unsupported chip revision\n");
11148 BNX2X_DEV_INFO("Loading %s\n", fw_file_name);
11150 rc = request_firmware(&bp->firmware, fw_file_name, &bp->pdev->dev);
11152 BNX2X_ERR("Can't load firmware file %s\n",
11154 goto request_firmware_exit;
11157 rc = bnx2x_check_firmware(bp);
11159 BNX2X_ERR("Corrupt firmware file %s\n", fw_file_name);
11160 goto request_firmware_exit;
11163 fw_hdr = (struct bnx2x_fw_file_hdr *)bp->firmware->data;
11165 /* Initialize the pointers to the init arrays */
11167 BNX2X_ALLOC_AND_SET(init_data, request_firmware_exit, be32_to_cpu_n);
11170 BNX2X_ALLOC_AND_SET(init_ops, init_ops_alloc_err, bnx2x_prep_ops);
11173 BNX2X_ALLOC_AND_SET(init_ops_offsets, init_offsets_alloc_err,
11176 /* STORMs firmware */
11177 INIT_TSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
11178 be32_to_cpu(fw_hdr->tsem_int_table_data.offset);
11179 INIT_TSEM_PRAM_DATA(bp) = bp->firmware->data +
11180 be32_to_cpu(fw_hdr->tsem_pram_data.offset);
11181 INIT_USEM_INT_TABLE_DATA(bp) = bp->firmware->data +
11182 be32_to_cpu(fw_hdr->usem_int_table_data.offset);
11183 INIT_USEM_PRAM_DATA(bp) = bp->firmware->data +
11184 be32_to_cpu(fw_hdr->usem_pram_data.offset);
11185 INIT_XSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
11186 be32_to_cpu(fw_hdr->xsem_int_table_data.offset);
11187 INIT_XSEM_PRAM_DATA(bp) = bp->firmware->data +
11188 be32_to_cpu(fw_hdr->xsem_pram_data.offset);
11189 INIT_CSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
11190 be32_to_cpu(fw_hdr->csem_int_table_data.offset);
11191 INIT_CSEM_PRAM_DATA(bp) = bp->firmware->data +
11192 be32_to_cpu(fw_hdr->csem_pram_data.offset);
11194 BNX2X_ALLOC_AND_SET(iro_arr, iro_alloc_err, bnx2x_prep_iro);
11199 kfree(bp->init_ops_offsets);
11200 init_offsets_alloc_err:
11201 kfree(bp->init_ops);
11202 init_ops_alloc_err:
11203 kfree(bp->init_data);
11204 request_firmware_exit:
11205 release_firmware(bp->firmware);
11206 bp->firmware = NULL;
11211 static void bnx2x_release_firmware(struct bnx2x *bp)
11213 kfree(bp->init_ops_offsets);
11214 kfree(bp->init_ops);
11215 kfree(bp->init_data);
11216 release_firmware(bp->firmware);
11217 bp->firmware = NULL;
11221 static struct bnx2x_func_sp_drv_ops bnx2x_func_sp_drv = {
11222 .init_hw_cmn_chip = bnx2x_init_hw_common_chip,
11223 .init_hw_cmn = bnx2x_init_hw_common,
11224 .init_hw_port = bnx2x_init_hw_port,
11225 .init_hw_func = bnx2x_init_hw_func,
11227 .reset_hw_cmn = bnx2x_reset_common,
11228 .reset_hw_port = bnx2x_reset_port,
11229 .reset_hw_func = bnx2x_reset_func,
11231 .gunzip_init = bnx2x_gunzip_init,
11232 .gunzip_end = bnx2x_gunzip_end,
11234 .init_fw = bnx2x_init_firmware,
11235 .release_fw = bnx2x_release_firmware,
11238 void bnx2x__init_func_obj(struct bnx2x *bp)
11240 /* Prepare DMAE related driver resources */
11241 bnx2x_setup_dmae(bp);
11243 bnx2x_init_func_obj(bp, &bp->func_obj,
11244 bnx2x_sp(bp, func_rdata),
11245 bnx2x_sp_mapping(bp, func_rdata),
11246 &bnx2x_func_sp_drv);
11249 /* must be called after sriov-enable */
11250 static inline int bnx2x_set_qm_cid_count(struct bnx2x *bp)
11252 int cid_count = BNX2X_L2_CID_COUNT(bp);
11255 cid_count += CNIC_CID_MAX;
11257 return roundup(cid_count, QM_CID_ROUND);
11261 * bnx2x_get_num_none_def_sbs - return the number of none default SBs
11266 static inline int bnx2x_get_num_non_def_sbs(struct pci_dev *pdev)
11271 pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
11274 * If MSI-X is not supported - return number of SBs needed to support
11275 * one fast path queue: one FP queue + SB for CNIC
11278 return 1 + CNIC_PRESENT;
11281 * The value in the PCI configuration space is the index of the last
11282 * entry, namely one less than the actual size of the table, which is
11283 * exactly what we want to return from this function: number of all SBs
11284 * without the default SB.
11286 pci_read_config_word(pdev, pos + PCI_MSI_FLAGS, &control);
11287 return control & PCI_MSIX_FLAGS_QSIZE;
11290 static int __devinit bnx2x_init_one(struct pci_dev *pdev,
11291 const struct pci_device_id *ent)
11293 struct net_device *dev = NULL;
11295 int pcie_width, pcie_speed;
11296 int rc, max_non_def_sbs;
11297 int rx_count, tx_count, rss_count;
11299 * An estimated maximum supported CoS number according to the chip
11301 * We will try to roughly estimate the maximum number of CoSes this chip
11302 * may support in order to minimize the memory allocated for Tx
11303 * netdev_queue's. This number will be accurately calculated during the
11304 * initialization of bp->max_cos based on the chip versions AND chip
11305 * revision in the bnx2x_init_bp().
11307 u8 max_cos_est = 0;
11309 switch (ent->driver_data) {
11313 max_cos_est = BNX2X_MULTI_TX_COS_E1X;
11318 max_cos_est = BNX2X_MULTI_TX_COS_E2_E3A0;
11327 max_cos_est = BNX2X_MULTI_TX_COS_E3B0;
11331 pr_err("Unknown board_type (%ld), aborting\n",
11336 max_non_def_sbs = bnx2x_get_num_non_def_sbs(pdev);
11339 * Do not allow the maximum SB count to grow above 16
11340 * since Special CIDs starts from 16*BNX2X_MULTI_TX_COS=48.
11341 * We will use the FP_SB_MAX_E1x macro for this matter.
11343 max_non_def_sbs = min_t(int, FP_SB_MAX_E1x, max_non_def_sbs);
11345 WARN_ON(!max_non_def_sbs);
11347 /* Maximum number of RSS queues: one IGU SB goes to CNIC */
11348 rss_count = max_non_def_sbs - CNIC_PRESENT;
11350 /* Maximum number of netdev Rx queues: RSS + FCoE L2 */
11351 rx_count = rss_count + FCOE_PRESENT;
11354 * Maximum number of netdev Tx queues:
11355 * Maximum TSS queues * Maximum supported number of CoS + FCoE L2
11357 tx_count = MAX_TXQS_PER_COS * max_cos_est + FCOE_PRESENT;
11359 /* dev zeroed in init_etherdev */
11360 dev = alloc_etherdev_mqs(sizeof(*bp), tx_count, rx_count);
11364 bp = netdev_priv(dev);
11366 BNX2X_DEV_INFO("Allocated netdev with %d tx and %d rx queues\n",
11367 tx_count, rx_count);
11369 bp->igu_sb_cnt = max_non_def_sbs;
11370 bp->msg_enable = debug;
11371 pci_set_drvdata(pdev, dev);
11373 rc = bnx2x_init_dev(pdev, dev, ent->driver_data);
11379 BNX2X_DEV_INFO("max_non_def_sbs %d\n", max_non_def_sbs);
11381 rc = bnx2x_init_bp(bp);
11383 goto init_one_exit;
11386 * Map doorbels here as we need the real value of bp->max_cos which
11387 * is initialized in bnx2x_init_bp().
11389 bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2),
11390 min_t(u64, BNX2X_DB_SIZE(bp),
11391 pci_resource_len(pdev, 2)));
11392 if (!bp->doorbells) {
11393 dev_err(&bp->pdev->dev,
11394 "Cannot map doorbell space, aborting\n");
11396 goto init_one_exit;
11399 /* calc qm_cid_count */
11400 bp->qm_cid_count = bnx2x_set_qm_cid_count(bp);
11403 /* disable FCOE L2 queue for E1x */
11404 if (CHIP_IS_E1x(bp))
11405 bp->flags |= NO_FCOE_FLAG;
11409 /* Configure interrupt mode: try to enable MSI-X/MSI if
11410 * needed, set bp->num_queues appropriately.
11412 bnx2x_set_int_mode(bp);
11414 /* Add all NAPI objects */
11415 bnx2x_add_all_napi(bp);
11417 rc = register_netdev(dev);
11419 dev_err(&pdev->dev, "Cannot register net device\n");
11420 goto init_one_exit;
11424 if (!NO_FCOE(bp)) {
11425 /* Add storage MAC address */
11427 dev_addr_add(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
11432 bnx2x_get_pcie_width_speed(bp, &pcie_width, &pcie_speed);
11435 "%s (%c%d) PCI-E x%d %s found at mem %lx, IRQ %d, node addr %pM\n",
11436 board_info[ent->driver_data].name,
11437 (CHIP_REV(bp) >> 12) + 'A', (CHIP_METAL(bp) >> 4),
11439 ((!CHIP_IS_E2(bp) && pcie_speed == 2) ||
11440 (CHIP_IS_E2(bp) && pcie_speed == 1)) ?
11441 "5GHz (Gen2)" : "2.5GHz",
11442 dev->base_addr, bp->pdev->irq, dev->dev_addr);
11448 iounmap(bp->regview);
11451 iounmap(bp->doorbells);
11455 if (atomic_read(&pdev->enable_cnt) == 1)
11456 pci_release_regions(pdev);
11458 pci_disable_device(pdev);
11459 pci_set_drvdata(pdev, NULL);
11464 static void __devexit bnx2x_remove_one(struct pci_dev *pdev)
11466 struct net_device *dev = pci_get_drvdata(pdev);
11470 dev_err(&pdev->dev, "BAD net device from bnx2x_init_one\n");
11473 bp = netdev_priv(dev);
11476 /* Delete storage MAC address */
11477 if (!NO_FCOE(bp)) {
11479 dev_addr_del(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
11485 /* Delete app tlvs from dcbnl */
11486 bnx2x_dcbnl_update_applist(bp, true);
11489 unregister_netdev(dev);
11491 /* Delete all NAPI objects */
11492 bnx2x_del_all_napi(bp);
11494 /* Power on: we can't let PCI layer write to us while we are in D3 */
11495 bnx2x_set_power_state(bp, PCI_D0);
11497 /* Disable MSI/MSI-X */
11498 bnx2x_disable_msi(bp);
11501 bnx2x_set_power_state(bp, PCI_D3hot);
11503 /* Make sure RESET task is not scheduled before continuing */
11504 cancel_delayed_work_sync(&bp->sp_rtnl_task);
11507 iounmap(bp->regview);
11510 iounmap(bp->doorbells);
11512 bnx2x_release_firmware(bp);
11514 bnx2x_free_mem_bp(bp);
11518 if (atomic_read(&pdev->enable_cnt) == 1)
11519 pci_release_regions(pdev);
11521 pci_disable_device(pdev);
11522 pci_set_drvdata(pdev, NULL);
11525 static int bnx2x_eeh_nic_unload(struct bnx2x *bp)
11529 bp->state = BNX2X_STATE_ERROR;
11531 bp->rx_mode = BNX2X_RX_MODE_NONE;
11534 bnx2x_cnic_notify(bp, CNIC_CTL_STOP_CMD);
11537 bnx2x_tx_disable(bp);
11539 bnx2x_netif_stop(bp, 0);
11541 del_timer_sync(&bp->timer);
11543 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
11546 bnx2x_free_irq(bp);
11548 /* Free SKBs, SGEs, TPA pool and driver internals */
11549 bnx2x_free_skbs(bp);
11551 for_each_rx_queue(bp, i)
11552 bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
11554 bnx2x_free_mem(bp);
11556 bp->state = BNX2X_STATE_CLOSED;
11558 netif_carrier_off(bp->dev);
11563 static void bnx2x_eeh_recover(struct bnx2x *bp)
11567 mutex_init(&bp->port.phy_mutex);
11570 val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
11571 if ((val & (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
11572 != (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
11573 BNX2X_ERR("BAD MCP validity signature\n");
11577 * bnx2x_io_error_detected - called when PCI error is detected
11578 * @pdev: Pointer to PCI device
11579 * @state: The current pci connection state
11581 * This function is called after a PCI bus error affecting
11582 * this device has been detected.
11584 static pci_ers_result_t bnx2x_io_error_detected(struct pci_dev *pdev,
11585 pci_channel_state_t state)
11587 struct net_device *dev = pci_get_drvdata(pdev);
11588 struct bnx2x *bp = netdev_priv(dev);
11592 netif_device_detach(dev);
11594 if (state == pci_channel_io_perm_failure) {
11596 return PCI_ERS_RESULT_DISCONNECT;
11599 if (netif_running(dev))
11600 bnx2x_eeh_nic_unload(bp);
11602 pci_disable_device(pdev);
11606 /* Request a slot reset */
11607 return PCI_ERS_RESULT_NEED_RESET;
11611 * bnx2x_io_slot_reset - called after the PCI bus has been reset
11612 * @pdev: Pointer to PCI device
11614 * Restart the card from scratch, as if from a cold-boot.
11616 static pci_ers_result_t bnx2x_io_slot_reset(struct pci_dev *pdev)
11618 struct net_device *dev = pci_get_drvdata(pdev);
11619 struct bnx2x *bp = netdev_priv(dev);
11623 if (pci_enable_device(pdev)) {
11624 dev_err(&pdev->dev,
11625 "Cannot re-enable PCI device after reset\n");
11627 return PCI_ERS_RESULT_DISCONNECT;
11630 pci_set_master(pdev);
11631 pci_restore_state(pdev);
11633 if (netif_running(dev))
11634 bnx2x_set_power_state(bp, PCI_D0);
11638 return PCI_ERS_RESULT_RECOVERED;
11642 * bnx2x_io_resume - called when traffic can start flowing again
11643 * @pdev: Pointer to PCI device
11645 * This callback is called when the error recovery driver tells us that
11646 * its OK to resume normal operation.
11648 static void bnx2x_io_resume(struct pci_dev *pdev)
11650 struct net_device *dev = pci_get_drvdata(pdev);
11651 struct bnx2x *bp = netdev_priv(dev);
11653 if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
11654 netdev_err(bp->dev, "Handling parity error recovery. Try again later\n");
11660 bnx2x_eeh_recover(bp);
11662 if (netif_running(dev))
11663 bnx2x_nic_load(bp, LOAD_NORMAL);
11665 netif_device_attach(dev);
11670 static struct pci_error_handlers bnx2x_err_handler = {
11671 .error_detected = bnx2x_io_error_detected,
11672 .slot_reset = bnx2x_io_slot_reset,
11673 .resume = bnx2x_io_resume,
11676 static struct pci_driver bnx2x_pci_driver = {
11677 .name = DRV_MODULE_NAME,
11678 .id_table = bnx2x_pci_tbl,
11679 .probe = bnx2x_init_one,
11680 .remove = __devexit_p(bnx2x_remove_one),
11681 .suspend = bnx2x_suspend,
11682 .resume = bnx2x_resume,
11683 .err_handler = &bnx2x_err_handler,
11686 static int __init bnx2x_init(void)
11690 pr_info("%s", version);
11692 bnx2x_wq = create_singlethread_workqueue("bnx2x");
11693 if (bnx2x_wq == NULL) {
11694 pr_err("Cannot create workqueue\n");
11698 ret = pci_register_driver(&bnx2x_pci_driver);
11700 pr_err("Cannot register driver\n");
11701 destroy_workqueue(bnx2x_wq);
11706 static void __exit bnx2x_cleanup(void)
11708 struct list_head *pos, *q;
11709 pci_unregister_driver(&bnx2x_pci_driver);
11711 destroy_workqueue(bnx2x_wq);
11713 /* Free globablly allocated resources */
11714 list_for_each_safe(pos, q, &bnx2x_prev_list) {
11715 struct bnx2x_prev_path_list *tmp =
11716 list_entry(pos, struct bnx2x_prev_path_list, list);
11722 void bnx2x_notify_link_changed(struct bnx2x *bp)
11724 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + BP_FUNC(bp)*sizeof(u32), 1);
11727 module_init(bnx2x_init);
11728 module_exit(bnx2x_cleanup);
11732 * bnx2x_set_iscsi_eth_mac_addr - set iSCSI MAC(s).
11734 * @bp: driver handle
11735 * @set: set or clear the CAM entry
11737 * This function will wait until the ramdord completion returns.
11738 * Return 0 if success, -ENODEV if ramrod doesn't return.
11740 static inline int bnx2x_set_iscsi_eth_mac_addr(struct bnx2x *bp)
11742 unsigned long ramrod_flags = 0;
11744 __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
11745 return bnx2x_set_mac_one(bp, bp->cnic_eth_dev.iscsi_mac,
11746 &bp->iscsi_l2_mac_obj, true,
11747 BNX2X_ISCSI_ETH_MAC, &ramrod_flags);
11750 /* count denotes the number of new completions we have seen */
11751 static void bnx2x_cnic_sp_post(struct bnx2x *bp, int count)
11753 struct eth_spe *spe;
11755 #ifdef BNX2X_STOP_ON_ERROR
11756 if (unlikely(bp->panic))
11760 spin_lock_bh(&bp->spq_lock);
11761 BUG_ON(bp->cnic_spq_pending < count);
11762 bp->cnic_spq_pending -= count;
11765 for (; bp->cnic_kwq_pending; bp->cnic_kwq_pending--) {
11766 u16 type = (le16_to_cpu(bp->cnic_kwq_cons->hdr.type)
11767 & SPE_HDR_CONN_TYPE) >>
11768 SPE_HDR_CONN_TYPE_SHIFT;
11769 u8 cmd = (le32_to_cpu(bp->cnic_kwq_cons->hdr.conn_and_cmd_data)
11770 >> SPE_HDR_CMD_ID_SHIFT) & 0xff;
11772 /* Set validation for iSCSI L2 client before sending SETUP
11775 if (type == ETH_CONNECTION_TYPE) {
11776 if (cmd == RAMROD_CMD_ID_ETH_CLIENT_SETUP)
11777 bnx2x_set_ctx_validation(bp, &bp->context.
11778 vcxt[BNX2X_ISCSI_ETH_CID].eth,
11779 BNX2X_ISCSI_ETH_CID);
11783 * There may be not more than 8 L2, not more than 8 L5 SPEs
11784 * and in the air. We also check that number of outstanding
11785 * COMMON ramrods is not more than the EQ and SPQ can
11788 if (type == ETH_CONNECTION_TYPE) {
11789 if (!atomic_read(&bp->cq_spq_left))
11792 atomic_dec(&bp->cq_spq_left);
11793 } else if (type == NONE_CONNECTION_TYPE) {
11794 if (!atomic_read(&bp->eq_spq_left))
11797 atomic_dec(&bp->eq_spq_left);
11798 } else if ((type == ISCSI_CONNECTION_TYPE) ||
11799 (type == FCOE_CONNECTION_TYPE)) {
11800 if (bp->cnic_spq_pending >=
11801 bp->cnic_eth_dev.max_kwqe_pending)
11804 bp->cnic_spq_pending++;
11806 BNX2X_ERR("Unknown SPE type: %d\n", type);
11811 spe = bnx2x_sp_get_next(bp);
11812 *spe = *bp->cnic_kwq_cons;
11814 DP(BNX2X_MSG_SP, "pending on SPQ %d, on KWQ %d count %d\n",
11815 bp->cnic_spq_pending, bp->cnic_kwq_pending, count);
11817 if (bp->cnic_kwq_cons == bp->cnic_kwq_last)
11818 bp->cnic_kwq_cons = bp->cnic_kwq;
11820 bp->cnic_kwq_cons++;
11822 bnx2x_sp_prod_update(bp);
11823 spin_unlock_bh(&bp->spq_lock);
11826 static int bnx2x_cnic_sp_queue(struct net_device *dev,
11827 struct kwqe_16 *kwqes[], u32 count)
11829 struct bnx2x *bp = netdev_priv(dev);
11832 #ifdef BNX2X_STOP_ON_ERROR
11833 if (unlikely(bp->panic)) {
11834 BNX2X_ERR("Can't post to SP queue while panic\n");
11839 if ((bp->recovery_state != BNX2X_RECOVERY_DONE) &&
11840 (bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
11841 BNX2X_ERR("Handling parity error recovery. Try again later\n");
11845 spin_lock_bh(&bp->spq_lock);
11847 for (i = 0; i < count; i++) {
11848 struct eth_spe *spe = (struct eth_spe *)kwqes[i];
11850 if (bp->cnic_kwq_pending == MAX_SP_DESC_CNT)
11853 *bp->cnic_kwq_prod = *spe;
11855 bp->cnic_kwq_pending++;
11857 DP(BNX2X_MSG_SP, "L5 SPQE %x %x %x:%x pos %d\n",
11858 spe->hdr.conn_and_cmd_data, spe->hdr.type,
11859 spe->data.update_data_addr.hi,
11860 spe->data.update_data_addr.lo,
11861 bp->cnic_kwq_pending);
11863 if (bp->cnic_kwq_prod == bp->cnic_kwq_last)
11864 bp->cnic_kwq_prod = bp->cnic_kwq;
11866 bp->cnic_kwq_prod++;
11869 spin_unlock_bh(&bp->spq_lock);
11871 if (bp->cnic_spq_pending < bp->cnic_eth_dev.max_kwqe_pending)
11872 bnx2x_cnic_sp_post(bp, 0);
11877 static int bnx2x_cnic_ctl_send(struct bnx2x *bp, struct cnic_ctl_info *ctl)
11879 struct cnic_ops *c_ops;
11882 mutex_lock(&bp->cnic_mutex);
11883 c_ops = rcu_dereference_protected(bp->cnic_ops,
11884 lockdep_is_held(&bp->cnic_mutex));
11886 rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
11887 mutex_unlock(&bp->cnic_mutex);
11892 static int bnx2x_cnic_ctl_send_bh(struct bnx2x *bp, struct cnic_ctl_info *ctl)
11894 struct cnic_ops *c_ops;
11898 c_ops = rcu_dereference(bp->cnic_ops);
11900 rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
11907 * for commands that have no data
11909 int bnx2x_cnic_notify(struct bnx2x *bp, int cmd)
11911 struct cnic_ctl_info ctl = {0};
11915 return bnx2x_cnic_ctl_send(bp, &ctl);
11918 static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err)
11920 struct cnic_ctl_info ctl = {0};
11922 /* first we tell CNIC and only then we count this as a completion */
11923 ctl.cmd = CNIC_CTL_COMPLETION_CMD;
11924 ctl.data.comp.cid = cid;
11925 ctl.data.comp.error = err;
11927 bnx2x_cnic_ctl_send_bh(bp, &ctl);
11928 bnx2x_cnic_sp_post(bp, 0);
11932 /* Called with netif_addr_lock_bh() taken.
11933 * Sets an rx_mode config for an iSCSI ETH client.
11935 * Completion should be checked outside.
11937 static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start)
11939 unsigned long accept_flags = 0, ramrod_flags = 0;
11940 u8 cl_id = bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
11941 int sched_state = BNX2X_FILTER_ISCSI_ETH_STOP_SCHED;
11944 /* Start accepting on iSCSI L2 ring. Accept all multicasts
11945 * because it's the only way for UIO Queue to accept
11946 * multicasts (in non-promiscuous mode only one Queue per
11947 * function will receive multicast packets (leading in our
11950 __set_bit(BNX2X_ACCEPT_UNICAST, &accept_flags);
11951 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept_flags);
11952 __set_bit(BNX2X_ACCEPT_BROADCAST, &accept_flags);
11953 __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept_flags);
11955 /* Clear STOP_PENDING bit if START is requested */
11956 clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &bp->sp_state);
11958 sched_state = BNX2X_FILTER_ISCSI_ETH_START_SCHED;
11960 /* Clear START_PENDING bit if STOP is requested */
11961 clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &bp->sp_state);
11963 if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
11964 set_bit(sched_state, &bp->sp_state);
11966 __set_bit(RAMROD_RX, &ramrod_flags);
11967 bnx2x_set_q_rx_mode(bp, cl_id, 0, accept_flags, 0,
11973 static int bnx2x_drv_ctl(struct net_device *dev, struct drv_ctl_info *ctl)
11975 struct bnx2x *bp = netdev_priv(dev);
11978 switch (ctl->cmd) {
11979 case DRV_CTL_CTXTBL_WR_CMD: {
11980 u32 index = ctl->data.io.offset;
11981 dma_addr_t addr = ctl->data.io.dma_addr;
11983 bnx2x_ilt_wr(bp, index, addr);
11987 case DRV_CTL_RET_L5_SPQ_CREDIT_CMD: {
11988 int count = ctl->data.credit.credit_count;
11990 bnx2x_cnic_sp_post(bp, count);
11994 /* rtnl_lock is held. */
11995 case DRV_CTL_START_L2_CMD: {
11996 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
11997 unsigned long sp_bits = 0;
11999 /* Configure the iSCSI classification object */
12000 bnx2x_init_mac_obj(bp, &bp->iscsi_l2_mac_obj,
12001 cp->iscsi_l2_client_id,
12002 cp->iscsi_l2_cid, BP_FUNC(bp),
12003 bnx2x_sp(bp, mac_rdata),
12004 bnx2x_sp_mapping(bp, mac_rdata),
12005 BNX2X_FILTER_MAC_PENDING,
12006 &bp->sp_state, BNX2X_OBJ_TYPE_RX,
12009 /* Set iSCSI MAC address */
12010 rc = bnx2x_set_iscsi_eth_mac_addr(bp);
12017 /* Start accepting on iSCSI L2 ring */
12019 netif_addr_lock_bh(dev);
12020 bnx2x_set_iscsi_eth_rx_mode(bp, true);
12021 netif_addr_unlock_bh(dev);
12023 /* bits to wait on */
12024 __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
12025 __set_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &sp_bits);
12027 if (!bnx2x_wait_sp_comp(bp, sp_bits))
12028 BNX2X_ERR("rx_mode completion timed out!\n");
12033 /* rtnl_lock is held. */
12034 case DRV_CTL_STOP_L2_CMD: {
12035 unsigned long sp_bits = 0;
12037 /* Stop accepting on iSCSI L2 ring */
12038 netif_addr_lock_bh(dev);
12039 bnx2x_set_iscsi_eth_rx_mode(bp, false);
12040 netif_addr_unlock_bh(dev);
12042 /* bits to wait on */
12043 __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
12044 __set_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &sp_bits);
12046 if (!bnx2x_wait_sp_comp(bp, sp_bits))
12047 BNX2X_ERR("rx_mode completion timed out!\n");
12052 /* Unset iSCSI L2 MAC */
12053 rc = bnx2x_del_all_macs(bp, &bp->iscsi_l2_mac_obj,
12054 BNX2X_ISCSI_ETH_MAC, true);
12057 case DRV_CTL_RET_L2_SPQ_CREDIT_CMD: {
12058 int count = ctl->data.credit.credit_count;
12060 smp_mb__before_atomic_inc();
12061 atomic_add(count, &bp->cq_spq_left);
12062 smp_mb__after_atomic_inc();
12065 case DRV_CTL_ULP_REGISTER_CMD: {
12066 int ulp_type = ctl->data.ulp_type;
12068 if (CHIP_IS_E3(bp)) {
12069 int idx = BP_FW_MB_IDX(bp);
12072 cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
12073 if (ulp_type == CNIC_ULP_ISCSI)
12074 cap |= DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
12075 else if (ulp_type == CNIC_ULP_FCOE)
12076 cap |= DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
12077 SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
12081 case DRV_CTL_ULP_UNREGISTER_CMD: {
12082 int ulp_type = ctl->data.ulp_type;
12084 if (CHIP_IS_E3(bp)) {
12085 int idx = BP_FW_MB_IDX(bp);
12088 cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
12089 if (ulp_type == CNIC_ULP_ISCSI)
12090 cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
12091 else if (ulp_type == CNIC_ULP_FCOE)
12092 cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
12093 SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
12099 BNX2X_ERR("unknown command %x\n", ctl->cmd);
12106 void bnx2x_setup_cnic_irq_info(struct bnx2x *bp)
12108 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
12110 if (bp->flags & USING_MSIX_FLAG) {
12111 cp->drv_state |= CNIC_DRV_STATE_USING_MSIX;
12112 cp->irq_arr[0].irq_flags |= CNIC_IRQ_FL_MSIX;
12113 cp->irq_arr[0].vector = bp->msix_table[1].vector;
12115 cp->drv_state &= ~CNIC_DRV_STATE_USING_MSIX;
12116 cp->irq_arr[0].irq_flags &= ~CNIC_IRQ_FL_MSIX;
12118 if (!CHIP_IS_E1x(bp))
12119 cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e2_sb;
12121 cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e1x_sb;
12123 cp->irq_arr[0].status_blk_num = bnx2x_cnic_fw_sb_id(bp);
12124 cp->irq_arr[0].status_blk_num2 = bnx2x_cnic_igu_sb_id(bp);
12125 cp->irq_arr[1].status_blk = bp->def_status_blk;
12126 cp->irq_arr[1].status_blk_num = DEF_SB_ID;
12127 cp->irq_arr[1].status_blk_num2 = DEF_SB_IGU_ID;
12132 static int bnx2x_register_cnic(struct net_device *dev, struct cnic_ops *ops,
12135 struct bnx2x *bp = netdev_priv(dev);
12136 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
12139 BNX2X_ERR("NULL ops received\n");
12143 bp->cnic_kwq = kzalloc(PAGE_SIZE, GFP_KERNEL);
12147 bp->cnic_kwq_cons = bp->cnic_kwq;
12148 bp->cnic_kwq_prod = bp->cnic_kwq;
12149 bp->cnic_kwq_last = bp->cnic_kwq + MAX_SP_DESC_CNT;
12151 bp->cnic_spq_pending = 0;
12152 bp->cnic_kwq_pending = 0;
12154 bp->cnic_data = data;
12157 cp->drv_state |= CNIC_DRV_STATE_REGD;
12158 cp->iro_arr = bp->iro_arr;
12160 bnx2x_setup_cnic_irq_info(bp);
12162 rcu_assign_pointer(bp->cnic_ops, ops);
12167 static int bnx2x_unregister_cnic(struct net_device *dev)
12169 struct bnx2x *bp = netdev_priv(dev);
12170 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
12172 mutex_lock(&bp->cnic_mutex);
12174 RCU_INIT_POINTER(bp->cnic_ops, NULL);
12175 mutex_unlock(&bp->cnic_mutex);
12177 kfree(bp->cnic_kwq);
12178 bp->cnic_kwq = NULL;
12183 struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev)
12185 struct bnx2x *bp = netdev_priv(dev);
12186 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
12188 /* If both iSCSI and FCoE are disabled - return NULL in
12189 * order to indicate CNIC that it should not try to work
12190 * with this device.
12192 if (NO_ISCSI(bp) && NO_FCOE(bp))
12195 cp->drv_owner = THIS_MODULE;
12196 cp->chip_id = CHIP_ID(bp);
12197 cp->pdev = bp->pdev;
12198 cp->io_base = bp->regview;
12199 cp->io_base2 = bp->doorbells;
12200 cp->max_kwqe_pending = 8;
12201 cp->ctx_blk_size = CDU_ILT_PAGE_SZ;
12202 cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
12203 bnx2x_cid_ilt_lines(bp);
12204 cp->ctx_tbl_len = CNIC_ILT_LINES;
12205 cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
12206 cp->drv_submit_kwqes_16 = bnx2x_cnic_sp_queue;
12207 cp->drv_ctl = bnx2x_drv_ctl;
12208 cp->drv_register_cnic = bnx2x_register_cnic;
12209 cp->drv_unregister_cnic = bnx2x_unregister_cnic;
12210 cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID;
12211 cp->iscsi_l2_client_id =
12212 bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
12213 cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID;
12215 if (NO_ISCSI_OOO(bp))
12216 cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
12219 cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI;
12222 cp->drv_state |= CNIC_DRV_STATE_NO_FCOE;
12225 "page_size %d, tbl_offset %d, tbl_lines %d, starting cid %d\n",
12227 cp->ctx_tbl_offset,
12232 EXPORT_SYMBOL(bnx2x_cnic_probe);
12234 #endif /* BCM_CNIC */