1 /* bnx2x_main.c: Broadcom Everest network driver.
3 * Copyright (c) 2007-2011 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 #include <linux/module.h>
19 #include <linux/moduleparam.h>
20 #include <linux/kernel.h>
21 #include <linux/device.h> /* for dev_info() */
22 #include <linux/timer.h>
23 #include <linux/errno.h>
24 #include <linux/ioport.h>
25 #include <linux/slab.h>
26 #include <linux/interrupt.h>
27 #include <linux/pci.h>
28 #include <linux/init.h>
29 #include <linux/netdevice.h>
30 #include <linux/etherdevice.h>
31 #include <linux/skbuff.h>
32 #include <linux/dma-mapping.h>
33 #include <linux/bitops.h>
34 #include <linux/irq.h>
35 #include <linux/delay.h>
36 #include <asm/byteorder.h>
37 #include <linux/time.h>
38 #include <linux/ethtool.h>
39 #include <linux/mii.h>
40 #include <linux/if_vlan.h>
44 #include <net/checksum.h>
45 #include <net/ip6_checksum.h>
46 #include <linux/workqueue.h>
47 #include <linux/crc32.h>
48 #include <linux/crc32c.h>
49 #include <linux/prefetch.h>
50 #include <linux/zlib.h>
52 #include <linux/stringify.h>
55 #include "bnx2x_init.h"
56 #include "bnx2x_init_ops.h"
57 #include "bnx2x_cmn.h"
58 #include "bnx2x_dcb.h"
61 #include <linux/firmware.h>
62 #include "bnx2x_fw_file_hdr.h"
64 #define FW_FILE_VERSION \
65 __stringify(BCM_5710_FW_MAJOR_VERSION) "." \
66 __stringify(BCM_5710_FW_MINOR_VERSION) "." \
67 __stringify(BCM_5710_FW_REVISION_VERSION) "." \
68 __stringify(BCM_5710_FW_ENGINEERING_VERSION)
69 #define FW_FILE_NAME_E1 "bnx2x/bnx2x-e1-" FW_FILE_VERSION ".fw"
70 #define FW_FILE_NAME_E1H "bnx2x/bnx2x-e1h-" FW_FILE_VERSION ".fw"
71 #define FW_FILE_NAME_E2 "bnx2x/bnx2x-e2-" FW_FILE_VERSION ".fw"
73 /* Time in jiffies before concluding the transmitter is hung */
74 #define TX_TIMEOUT (5*HZ)
76 static char version[] __devinitdata =
77 "Broadcom NetXtreme II 5771x/578xx 10/20-Gigabit Ethernet Driver "
78 DRV_MODULE_NAME " " DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
80 MODULE_AUTHOR("Eliezer Tamir");
81 MODULE_DESCRIPTION("Broadcom NetXtreme II "
82 "BCM57710/57711/57711E/"
83 "57712/57712_MF/57800/57800_MF/57810/57810_MF/"
84 "57840/57840_MF Driver");
85 MODULE_LICENSE("GPL");
86 MODULE_VERSION(DRV_MODULE_VERSION);
87 MODULE_FIRMWARE(FW_FILE_NAME_E1);
88 MODULE_FIRMWARE(FW_FILE_NAME_E1H);
89 MODULE_FIRMWARE(FW_FILE_NAME_E2);
91 static int multi_mode = 1;
92 module_param(multi_mode, int, 0);
93 MODULE_PARM_DESC(multi_mode, " Multi queue mode "
94 "(0 Disable; 1 Enable (default))");
97 module_param(num_queues, int, 0);
98 MODULE_PARM_DESC(num_queues, " Number of queues for multi_mode=1"
99 " (default is as a number of CPUs)");
101 static int disable_tpa;
102 module_param(disable_tpa, int, 0);
103 MODULE_PARM_DESC(disable_tpa, " Disable the TPA (LRO) feature");
105 #define INT_MODE_INTx 1
106 #define INT_MODE_MSI 2
108 module_param(int_mode, int, 0);
109 MODULE_PARM_DESC(int_mode, " Force interrupt mode other than MSI-X "
112 static int dropless_fc;
113 module_param(dropless_fc, int, 0);
114 MODULE_PARM_DESC(dropless_fc, " Pause on exhausted host ring");
117 module_param(poll, int, 0);
118 MODULE_PARM_DESC(poll, " Use polling (for debug)");
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 /****************************************************************************
215 * General service functions
216 ****************************************************************************/
218 static inline void __storm_memset_dma_mapping(struct bnx2x *bp,
219 u32 addr, dma_addr_t mapping)
221 REG_WR(bp, addr, U64_LO(mapping));
222 REG_WR(bp, addr + 4, U64_HI(mapping));
225 static inline void storm_memset_spq_addr(struct bnx2x *bp,
226 dma_addr_t mapping, u16 abs_fid)
228 u32 addr = XSEM_REG_FAST_MEMORY +
229 XSTORM_SPQ_PAGE_BASE_OFFSET(abs_fid);
231 __storm_memset_dma_mapping(bp, addr, mapping);
234 static inline void storm_memset_vf_to_pf(struct bnx2x *bp, u16 abs_fid,
237 REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_VF_TO_PF_OFFSET(abs_fid),
239 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_VF_TO_PF_OFFSET(abs_fid),
241 REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_VF_TO_PF_OFFSET(abs_fid),
243 REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_VF_TO_PF_OFFSET(abs_fid),
247 static inline void storm_memset_func_en(struct bnx2x *bp, u16 abs_fid,
250 REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(abs_fid),
252 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(abs_fid),
254 REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(abs_fid),
256 REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(abs_fid),
260 static inline void storm_memset_eq_data(struct bnx2x *bp,
261 struct event_ring_data *eq_data,
264 size_t size = sizeof(struct event_ring_data);
266 u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_DATA_OFFSET(pfid);
268 __storm_memset_struct(bp, addr, size, (u32 *)eq_data);
271 static inline void storm_memset_eq_prod(struct bnx2x *bp, u16 eq_prod,
274 u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_PROD_OFFSET(pfid);
275 REG_WR16(bp, addr, eq_prod);
279 * locking is done by mcp
281 static void bnx2x_reg_wr_ind(struct bnx2x *bp, u32 addr, u32 val)
283 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
284 pci_write_config_dword(bp->pdev, PCICFG_GRC_DATA, val);
285 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
286 PCICFG_VENDOR_ID_OFFSET);
289 static u32 bnx2x_reg_rd_ind(struct bnx2x *bp, u32 addr)
293 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
294 pci_read_config_dword(bp->pdev, PCICFG_GRC_DATA, &val);
295 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
296 PCICFG_VENDOR_ID_OFFSET);
301 #define DMAE_DP_SRC_GRC "grc src_addr [%08x]"
302 #define DMAE_DP_SRC_PCI "pci src_addr [%x:%08x]"
303 #define DMAE_DP_DST_GRC "grc dst_addr [%08x]"
304 #define DMAE_DP_DST_PCI "pci dst_addr [%x:%08x]"
305 #define DMAE_DP_DST_NONE "dst_addr [none]"
307 static void bnx2x_dp_dmae(struct bnx2x *bp, struct dmae_command *dmae,
310 u32 src_type = dmae->opcode & DMAE_COMMAND_SRC;
312 switch (dmae->opcode & DMAE_COMMAND_DST) {
313 case DMAE_CMD_DST_PCI:
314 if (src_type == DMAE_CMD_SRC_PCI)
315 DP(msglvl, "DMAE: opcode 0x%08x\n"
316 "src [%x:%08x], len [%d*4], dst [%x:%08x]\n"
317 "comp_addr [%x:%08x], comp_val 0x%08x\n",
318 dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
319 dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
320 dmae->comp_addr_hi, dmae->comp_addr_lo,
323 DP(msglvl, "DMAE: opcode 0x%08x\n"
324 "src [%08x], len [%d*4], dst [%x:%08x]\n"
325 "comp_addr [%x:%08x], comp_val 0x%08x\n",
326 dmae->opcode, dmae->src_addr_lo >> 2,
327 dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
328 dmae->comp_addr_hi, dmae->comp_addr_lo,
331 case DMAE_CMD_DST_GRC:
332 if (src_type == DMAE_CMD_SRC_PCI)
333 DP(msglvl, "DMAE: opcode 0x%08x\n"
334 "src [%x:%08x], len [%d*4], dst_addr [%08x]\n"
335 "comp_addr [%x:%08x], comp_val 0x%08x\n",
336 dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
337 dmae->len, dmae->dst_addr_lo >> 2,
338 dmae->comp_addr_hi, dmae->comp_addr_lo,
341 DP(msglvl, "DMAE: opcode 0x%08x\n"
342 "src [%08x], len [%d*4], dst [%08x]\n"
343 "comp_addr [%x:%08x], comp_val 0x%08x\n",
344 dmae->opcode, dmae->src_addr_lo >> 2,
345 dmae->len, dmae->dst_addr_lo >> 2,
346 dmae->comp_addr_hi, dmae->comp_addr_lo,
350 if (src_type == DMAE_CMD_SRC_PCI)
351 DP(msglvl, "DMAE: opcode 0x%08x\n"
352 DP_LEVEL "src_addr [%x:%08x] len [%d * 4] "
354 DP_LEVEL "comp_addr [%x:%08x] comp_val 0x%08x\n",
355 dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
356 dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
359 DP(msglvl, "DMAE: opcode 0x%08x\n"
360 DP_LEVEL "src_addr [%08x] len [%d * 4] "
362 DP_LEVEL "comp_addr [%x:%08x] comp_val 0x%08x\n",
363 dmae->opcode, dmae->src_addr_lo >> 2,
364 dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
371 /* copy command into DMAE command memory and set DMAE command go */
372 void bnx2x_post_dmae(struct bnx2x *bp, struct dmae_command *dmae, int idx)
377 cmd_offset = (DMAE_REG_CMD_MEM + sizeof(struct dmae_command) * idx);
378 for (i = 0; i < (sizeof(struct dmae_command)/4); i++) {
379 REG_WR(bp, cmd_offset + i*4, *(((u32 *)dmae) + i));
381 DP(BNX2X_MSG_OFF, "DMAE cmd[%d].%d (0x%08x) : 0x%08x\n",
382 idx, i, cmd_offset + i*4, *(((u32 *)dmae) + i));
384 REG_WR(bp, dmae_reg_go_c[idx], 1);
387 u32 bnx2x_dmae_opcode_add_comp(u32 opcode, u8 comp_type)
389 return opcode | ((comp_type << DMAE_COMMAND_C_DST_SHIFT) |
393 u32 bnx2x_dmae_opcode_clr_src_reset(u32 opcode)
395 return opcode & ~DMAE_CMD_SRC_RESET;
398 u32 bnx2x_dmae_opcode(struct bnx2x *bp, u8 src_type, u8 dst_type,
399 bool with_comp, u8 comp_type)
403 opcode |= ((src_type << DMAE_COMMAND_SRC_SHIFT) |
404 (dst_type << DMAE_COMMAND_DST_SHIFT));
406 opcode |= (DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET);
408 opcode |= (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0);
409 opcode |= ((BP_E1HVN(bp) << DMAE_CMD_E1HVN_SHIFT) |
410 (BP_E1HVN(bp) << DMAE_COMMAND_DST_VN_SHIFT));
411 opcode |= (DMAE_COM_SET_ERR << DMAE_COMMAND_ERR_POLICY_SHIFT);
414 opcode |= DMAE_CMD_ENDIANITY_B_DW_SWAP;
416 opcode |= DMAE_CMD_ENDIANITY_DW_SWAP;
419 opcode = bnx2x_dmae_opcode_add_comp(opcode, comp_type);
423 static void bnx2x_prep_dmae_with_comp(struct bnx2x *bp,
424 struct dmae_command *dmae,
425 u8 src_type, u8 dst_type)
427 memset(dmae, 0, sizeof(struct dmae_command));
430 dmae->opcode = bnx2x_dmae_opcode(bp, src_type, dst_type,
431 true, DMAE_COMP_PCI);
433 /* fill in the completion parameters */
434 dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_comp));
435 dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_comp));
436 dmae->comp_val = DMAE_COMP_VAL;
439 /* issue a dmae command over the init-channel and wailt for completion */
440 static int bnx2x_issue_dmae_with_comp(struct bnx2x *bp,
441 struct dmae_command *dmae)
443 u32 *wb_comp = bnx2x_sp(bp, wb_comp);
444 int cnt = CHIP_REV_IS_SLOW(bp) ? (400000) : 4000;
447 DP(BNX2X_MSG_OFF, "data before [0x%08x 0x%08x 0x%08x 0x%08x]\n",
448 bp->slowpath->wb_data[0], bp->slowpath->wb_data[1],
449 bp->slowpath->wb_data[2], bp->slowpath->wb_data[3]);
452 * Lock the dmae channel. Disable BHs to prevent a dead-lock
453 * as long as this code is called both from syscall context and
454 * from ndo_set_rx_mode() flow that may be called from BH.
456 spin_lock_bh(&bp->dmae_lock);
458 /* reset completion */
461 /* post the command on the channel used for initializations */
462 bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp));
464 /* wait for completion */
466 while ((*wb_comp & ~DMAE_PCI_ERR_FLAG) != DMAE_COMP_VAL) {
467 DP(BNX2X_MSG_OFF, "wb_comp 0x%08x\n", *wb_comp);
470 BNX2X_ERR("DMAE timeout!\n");
477 if (*wb_comp & DMAE_PCI_ERR_FLAG) {
478 BNX2X_ERR("DMAE PCI error!\n");
482 DP(BNX2X_MSG_OFF, "data after [0x%08x 0x%08x 0x%08x 0x%08x]\n",
483 bp->slowpath->wb_data[0], bp->slowpath->wb_data[1],
484 bp->slowpath->wb_data[2], bp->slowpath->wb_data[3]);
487 spin_unlock_bh(&bp->dmae_lock);
491 void bnx2x_write_dmae(struct bnx2x *bp, dma_addr_t dma_addr, u32 dst_addr,
494 struct dmae_command dmae;
496 if (!bp->dmae_ready) {
497 u32 *data = bnx2x_sp(bp, wb_data[0]);
499 DP(BNX2X_MSG_OFF, "DMAE is not ready (dst_addr %08x len32 %d)"
500 " using indirect\n", dst_addr, len32);
501 bnx2x_init_ind_wr(bp, dst_addr, data, len32);
505 /* set opcode and fixed command fields */
506 bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_GRC);
508 /* fill in addresses and len */
509 dmae.src_addr_lo = U64_LO(dma_addr);
510 dmae.src_addr_hi = U64_HI(dma_addr);
511 dmae.dst_addr_lo = dst_addr >> 2;
512 dmae.dst_addr_hi = 0;
515 bnx2x_dp_dmae(bp, &dmae, BNX2X_MSG_OFF);
517 /* issue the command and wait for completion */
518 bnx2x_issue_dmae_with_comp(bp, &dmae);
521 void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32)
523 struct dmae_command dmae;
525 if (!bp->dmae_ready) {
526 u32 *data = bnx2x_sp(bp, wb_data[0]);
529 DP(BNX2X_MSG_OFF, "DMAE is not ready (src_addr %08x len32 %d)"
530 " using indirect\n", src_addr, len32);
531 for (i = 0; i < len32; i++)
532 data[i] = bnx2x_reg_rd_ind(bp, src_addr + i*4);
536 /* set opcode and fixed command fields */
537 bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_GRC, DMAE_DST_PCI);
539 /* fill in addresses and len */
540 dmae.src_addr_lo = src_addr >> 2;
541 dmae.src_addr_hi = 0;
542 dmae.dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_data));
543 dmae.dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_data));
546 bnx2x_dp_dmae(bp, &dmae, BNX2X_MSG_OFF);
548 /* issue the command and wait for completion */
549 bnx2x_issue_dmae_with_comp(bp, &dmae);
552 static void bnx2x_write_dmae_phys_len(struct bnx2x *bp, dma_addr_t phys_addr,
555 int dmae_wr_max = DMAE_LEN32_WR_MAX(bp);
558 while (len > dmae_wr_max) {
559 bnx2x_write_dmae(bp, phys_addr + offset,
560 addr + offset, dmae_wr_max);
561 offset += dmae_wr_max * 4;
565 bnx2x_write_dmae(bp, phys_addr + offset, addr + offset, len);
568 /* used only for slowpath so not inlined */
569 static void bnx2x_wb_wr(struct bnx2x *bp, int reg, u32 val_hi, u32 val_lo)
573 wb_write[0] = val_hi;
574 wb_write[1] = val_lo;
575 REG_WR_DMAE(bp, reg, wb_write, 2);
579 static u64 bnx2x_wb_rd(struct bnx2x *bp, int reg)
583 REG_RD_DMAE(bp, reg, wb_data, 2);
585 return HILO_U64(wb_data[0], wb_data[1]);
589 static int bnx2x_mc_assert(struct bnx2x *bp)
593 u32 row0, row1, row2, row3;
596 last_idx = REG_RD8(bp, BAR_XSTRORM_INTMEM +
597 XSTORM_ASSERT_LIST_INDEX_OFFSET);
599 BNX2X_ERR("XSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
601 /* print the asserts */
602 for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
604 row0 = REG_RD(bp, BAR_XSTRORM_INTMEM +
605 XSTORM_ASSERT_LIST_OFFSET(i));
606 row1 = REG_RD(bp, BAR_XSTRORM_INTMEM +
607 XSTORM_ASSERT_LIST_OFFSET(i) + 4);
608 row2 = REG_RD(bp, BAR_XSTRORM_INTMEM +
609 XSTORM_ASSERT_LIST_OFFSET(i) + 8);
610 row3 = REG_RD(bp, BAR_XSTRORM_INTMEM +
611 XSTORM_ASSERT_LIST_OFFSET(i) + 12);
613 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
614 BNX2X_ERR("XSTORM_ASSERT_INDEX 0x%x = 0x%08x"
615 " 0x%08x 0x%08x 0x%08x\n",
616 i, row3, row2, row1, row0);
624 last_idx = REG_RD8(bp, BAR_TSTRORM_INTMEM +
625 TSTORM_ASSERT_LIST_INDEX_OFFSET);
627 BNX2X_ERR("TSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
629 /* print the asserts */
630 for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
632 row0 = REG_RD(bp, BAR_TSTRORM_INTMEM +
633 TSTORM_ASSERT_LIST_OFFSET(i));
634 row1 = REG_RD(bp, BAR_TSTRORM_INTMEM +
635 TSTORM_ASSERT_LIST_OFFSET(i) + 4);
636 row2 = REG_RD(bp, BAR_TSTRORM_INTMEM +
637 TSTORM_ASSERT_LIST_OFFSET(i) + 8);
638 row3 = REG_RD(bp, BAR_TSTRORM_INTMEM +
639 TSTORM_ASSERT_LIST_OFFSET(i) + 12);
641 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
642 BNX2X_ERR("TSTORM_ASSERT_INDEX 0x%x = 0x%08x"
643 " 0x%08x 0x%08x 0x%08x\n",
644 i, row3, row2, row1, row0);
652 last_idx = REG_RD8(bp, BAR_CSTRORM_INTMEM +
653 CSTORM_ASSERT_LIST_INDEX_OFFSET);
655 BNX2X_ERR("CSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
657 /* print the asserts */
658 for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
660 row0 = REG_RD(bp, BAR_CSTRORM_INTMEM +
661 CSTORM_ASSERT_LIST_OFFSET(i));
662 row1 = REG_RD(bp, BAR_CSTRORM_INTMEM +
663 CSTORM_ASSERT_LIST_OFFSET(i) + 4);
664 row2 = REG_RD(bp, BAR_CSTRORM_INTMEM +
665 CSTORM_ASSERT_LIST_OFFSET(i) + 8);
666 row3 = REG_RD(bp, BAR_CSTRORM_INTMEM +
667 CSTORM_ASSERT_LIST_OFFSET(i) + 12);
669 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
670 BNX2X_ERR("CSTORM_ASSERT_INDEX 0x%x = 0x%08x"
671 " 0x%08x 0x%08x 0x%08x\n",
672 i, row3, row2, row1, row0);
680 last_idx = REG_RD8(bp, BAR_USTRORM_INTMEM +
681 USTORM_ASSERT_LIST_INDEX_OFFSET);
683 BNX2X_ERR("USTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
685 /* print the asserts */
686 for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
688 row0 = REG_RD(bp, BAR_USTRORM_INTMEM +
689 USTORM_ASSERT_LIST_OFFSET(i));
690 row1 = REG_RD(bp, BAR_USTRORM_INTMEM +
691 USTORM_ASSERT_LIST_OFFSET(i) + 4);
692 row2 = REG_RD(bp, BAR_USTRORM_INTMEM +
693 USTORM_ASSERT_LIST_OFFSET(i) + 8);
694 row3 = REG_RD(bp, BAR_USTRORM_INTMEM +
695 USTORM_ASSERT_LIST_OFFSET(i) + 12);
697 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
698 BNX2X_ERR("USTORM_ASSERT_INDEX 0x%x = 0x%08x"
699 " 0x%08x 0x%08x 0x%08x\n",
700 i, row3, row2, row1, row0);
710 void bnx2x_fw_dump_lvl(struct bnx2x *bp, const char *lvl)
716 u32 trace_shmem_base;
718 BNX2X_ERR("NO MCP - can not dump\n");
721 netdev_printk(lvl, bp->dev, "bc %d.%d.%d\n",
722 (bp->common.bc_ver & 0xff0000) >> 16,
723 (bp->common.bc_ver & 0xff00) >> 8,
724 (bp->common.bc_ver & 0xff));
726 val = REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER);
727 if (val == REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER))
728 printk("%s" "MCP PC at 0x%x\n", lvl, val);
730 if (BP_PATH(bp) == 0)
731 trace_shmem_base = bp->common.shmem_base;
733 trace_shmem_base = SHMEM2_RD(bp, other_shmem_base_addr);
734 addr = trace_shmem_base - 0x0800 + 4;
735 mark = REG_RD(bp, addr);
736 mark = (CHIP_IS_E1x(bp) ? MCP_REG_MCPR_SCRATCH : MCP_A_REG_MCPR_SCRATCH)
737 + ((mark + 0x3) & ~0x3) - 0x08000000;
738 printk("%s" "begin fw dump (mark 0x%x)\n", lvl, mark);
741 for (offset = mark; offset <= trace_shmem_base; offset += 0x8*4) {
742 for (word = 0; word < 8; word++)
743 data[word] = htonl(REG_RD(bp, offset + 4*word));
745 pr_cont("%s", (char *)data);
747 for (offset = addr + 4; offset <= mark; offset += 0x8*4) {
748 for (word = 0; word < 8; word++)
749 data[word] = htonl(REG_RD(bp, offset + 4*word));
751 pr_cont("%s", (char *)data);
753 printk("%s" "end of fw dump\n", lvl);
756 static inline void bnx2x_fw_dump(struct bnx2x *bp)
758 bnx2x_fw_dump_lvl(bp, KERN_ERR);
761 void bnx2x_panic_dump(struct bnx2x *bp)
765 struct hc_sp_status_block_data sp_sb_data;
766 int func = BP_FUNC(bp);
767 #ifdef BNX2X_STOP_ON_ERROR
768 u16 start = 0, end = 0;
771 bp->stats_state = STATS_STATE_DISABLED;
772 DP(BNX2X_MSG_STATS, "stats_state - DISABLED\n");
774 BNX2X_ERR("begin crash dump -----------------\n");
778 BNX2X_ERR("def_idx(0x%x) def_att_idx(0x%x) attn_state(0x%x)"
779 " spq_prod_idx(0x%x) next_stats_cnt(0x%x)\n",
780 bp->def_idx, bp->def_att_idx, bp->attn_state,
781 bp->spq_prod_idx, bp->stats_counter);
782 BNX2X_ERR("DSB: attn bits(0x%x) ack(0x%x) id(0x%x) idx(0x%x)\n",
783 bp->def_status_blk->atten_status_block.attn_bits,
784 bp->def_status_blk->atten_status_block.attn_bits_ack,
785 bp->def_status_blk->atten_status_block.status_block_id,
786 bp->def_status_blk->atten_status_block.attn_bits_index);
788 for (i = 0; i < HC_SP_SB_MAX_INDICES; i++)
790 bp->def_status_blk->sp_sb.index_values[i],
791 (i == HC_SP_SB_MAX_INDICES - 1) ? ") " : " ");
793 for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
794 *((u32 *)&sp_sb_data + i) = REG_RD(bp, BAR_CSTRORM_INTMEM +
795 CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
798 pr_cont("igu_sb_id(0x%x) igu_seg_id(0x%x) "
799 "pf_id(0x%x) vnic_id(0x%x) "
800 "vf_id(0x%x) vf_valid (0x%x) "
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;
828 BNX2X_ERR("fp%d: rx_bd_prod(0x%x) rx_bd_cons(0x%x)"
829 " rx_comp_prod(0x%x)"
830 " rx_comp_cons(0x%x) *rx_cons_sb(0x%x)\n",
831 i, fp->rx_bd_prod, fp->rx_bd_cons,
833 fp->rx_comp_cons, le16_to_cpu(*fp->rx_cons_sb));
834 BNX2X_ERR(" rx_sge_prod(0x%x) last_max_sge(0x%x)"
835 " fp_hc_idx(0x%x)\n",
836 fp->rx_sge_prod, fp->last_max_sge,
837 le16_to_cpu(fp->fp_hc_idx));
840 BNX2X_ERR("fp%d: tx_pkt_prod(0x%x) tx_pkt_cons(0x%x)"
841 " tx_bd_prod(0x%x) tx_bd_cons(0x%x)"
842 " *tx_cons_sb(0x%x)\n",
843 i, fp->tx_pkt_prod, fp->tx_pkt_cons, fp->tx_bd_prod,
844 fp->tx_bd_cons, le16_to_cpu(*fp->tx_cons_sb));
846 loop = CHIP_IS_E1x(bp) ?
847 HC_SB_MAX_INDICES_E1X : HC_SB_MAX_INDICES_E2;
855 BNX2X_ERR(" run indexes (");
856 for (j = 0; j < HC_SB_MAX_SM; j++)
858 fp->sb_running_index[j],
859 (j == HC_SB_MAX_SM - 1) ? ")" : " ");
861 BNX2X_ERR(" indexes (");
862 for (j = 0; j < loop; j++)
864 fp->sb_index_values[j],
865 (j == loop - 1) ? ")" : " ");
867 data_size = CHIP_IS_E1x(bp) ?
868 sizeof(struct hc_status_block_data_e1x) :
869 sizeof(struct hc_status_block_data_e2);
870 data_size /= sizeof(u32);
871 sb_data_p = CHIP_IS_E1x(bp) ?
872 (u32 *)&sb_data_e1x :
874 /* copy sb data in here */
875 for (j = 0; j < data_size; j++)
876 *(sb_data_p + j) = REG_RD(bp, BAR_CSTRORM_INTMEM +
877 CSTORM_STATUS_BLOCK_DATA_OFFSET(fp->fw_sb_id) +
880 if (!CHIP_IS_E1x(bp)) {
881 pr_cont("pf_id(0x%x) vf_id(0x%x) vf_valid(0x%x) "
882 "vnic_id(0x%x) same_igu_sb_1b(0x%x) "
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) "
892 "vnic_id(0x%x) same_igu_sb_1b(0x%x) "
894 sb_data_e1x.common.p_func.pf_id,
895 sb_data_e1x.common.p_func.vf_id,
896 sb_data_e1x.common.p_func.vf_valid,
897 sb_data_e1x.common.p_func.vnic_id,
898 sb_data_e1x.common.same_igu_sb_1b,
899 sb_data_e1x.common.state);
903 for (j = 0; j < HC_SB_MAX_SM; j++) {
904 pr_cont("SM[%d] __flags (0x%x) "
905 "igu_sb_id (0x%x) igu_seg_id(0x%x) "
906 "time_to_expire (0x%x) "
907 "timer_value(0x%x)\n", j,
909 hc_sm_p[j].igu_sb_id,
910 hc_sm_p[j].igu_seg_id,
911 hc_sm_p[j].time_to_expire,
912 hc_sm_p[j].timer_value);
916 for (j = 0; j < loop; j++) {
917 pr_cont("INDEX[%d] flags (0x%x) "
918 "timeout (0x%x)\n", j,
920 hc_index_p[j].timeout);
924 #ifdef BNX2X_STOP_ON_ERROR
927 for_each_rx_queue(bp, i) {
928 struct bnx2x_fastpath *fp = &bp->fp[i];
930 start = RX_BD(le16_to_cpu(*fp->rx_cons_sb) - 10);
931 end = RX_BD(le16_to_cpu(*fp->rx_cons_sb) + 503);
932 for (j = start; j != end; j = RX_BD(j + 1)) {
933 u32 *rx_bd = (u32 *)&fp->rx_desc_ring[j];
934 struct sw_rx_bd *sw_bd = &fp->rx_buf_ring[j];
936 BNX2X_ERR("fp%d: rx_bd[%x]=[%x:%x] sw_bd=[%p]\n",
937 i, j, rx_bd[1], rx_bd[0], sw_bd->skb);
940 start = RX_SGE(fp->rx_sge_prod);
941 end = RX_SGE(fp->last_max_sge);
942 for (j = start; j != end; j = RX_SGE(j + 1)) {
943 u32 *rx_sge = (u32 *)&fp->rx_sge_ring[j];
944 struct sw_rx_page *sw_page = &fp->rx_page_ring[j];
946 BNX2X_ERR("fp%d: rx_sge[%x]=[%x:%x] sw_page=[%p]\n",
947 i, j, rx_sge[1], rx_sge[0], sw_page->page);
950 start = RCQ_BD(fp->rx_comp_cons - 10);
951 end = RCQ_BD(fp->rx_comp_cons + 503);
952 for (j = start; j != end; j = RCQ_BD(j + 1)) {
953 u32 *cqe = (u32 *)&fp->rx_comp_ring[j];
955 BNX2X_ERR("fp%d: cqe[%x]=[%x:%x:%x:%x]\n",
956 i, j, cqe[0], cqe[1], cqe[2], cqe[3]);
961 for_each_tx_queue(bp, i) {
962 struct bnx2x_fastpath *fp = &bp->fp[i];
964 start = TX_BD(le16_to_cpu(*fp->tx_cons_sb) - 10);
965 end = TX_BD(le16_to_cpu(*fp->tx_cons_sb) + 245);
966 for (j = start; j != end; j = TX_BD(j + 1)) {
967 struct sw_tx_bd *sw_bd = &fp->tx_buf_ring[j];
969 BNX2X_ERR("fp%d: packet[%x]=[%p,%x]\n",
970 i, j, sw_bd->skb, sw_bd->first_bd);
973 start = TX_BD(fp->tx_bd_cons - 10);
974 end = TX_BD(fp->tx_bd_cons + 254);
975 for (j = start; j != end; j = TX_BD(j + 1)) {
976 u32 *tx_bd = (u32 *)&fp->tx_desc_ring[j];
978 BNX2X_ERR("fp%d: tx_bd[%x]=[%x:%x:%x:%x]\n",
979 i, j, tx_bd[0], tx_bd[1], tx_bd[2], tx_bd[3]);
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_INTERAVAL 50 /* usec */
996 #define FLR_POLL_CNT (FLR_WAIT_USEC/FLR_WAIT_INTERAVAL) /* 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_INTERAVAL);
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_INTERAVAL, 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_INTERAVAL);
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_INTERAVAL, 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_INTERAVAL);
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 is not 0\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, "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");
1214 /* Zero completion for nxt FLR */
1215 REG_WR(bp, comp_addr, 0);
1220 static inline u8 bnx2x_is_pcie_pending(struct pci_dev *dev)
1225 pos = pci_find_capability(dev, PCI_CAP_ID_EXP);
1229 pci_read_config_word(dev, pos + PCI_EXP_DEVSTA, &status);
1230 return status & PCI_EXP_DEVSTA_TRPND;
1233 /* PF FLR specific routines
1235 static int bnx2x_poll_hw_usage_counters(struct bnx2x *bp, u32 poll_cnt)
1238 /* wait for CFC PF usage-counter to zero (includes all the VFs) */
1239 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1240 CFC_REG_NUM_LCIDS_INSIDE_PF,
1241 "CFC PF usage counter timed out",
1246 /* Wait for DQ PF usage-counter to zero (until DQ cleanup) */
1247 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1248 DORQ_REG_PF_USAGE_CNT,
1249 "DQ PF usage counter timed out",
1253 /* Wait for QM PF usage-counter to zero (until DQ cleanup) */
1254 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1255 QM_REG_PF_USG_CNT_0 + 4*BP_FUNC(bp),
1256 "QM PF usage counter timed out",
1260 /* Wait for Timer PF usage-counters to zero (until DQ cleanup) */
1261 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1262 TM_REG_LIN0_VNIC_UC + 4*BP_PORT(bp),
1263 "Timers VNIC usage counter timed out",
1266 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1267 TM_REG_LIN0_NUM_SCANS + 4*BP_PORT(bp),
1268 "Timers NUM_SCANS usage counter timed out",
1272 /* Wait DMAE PF usage counter to zero */
1273 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1274 dmae_reg_go_c[INIT_DMAE_C(bp)],
1275 "DMAE dommand register timed out",
1282 static void bnx2x_hw_enable_status(struct bnx2x *bp)
1286 val = REG_RD(bp, CFC_REG_WEAK_ENABLE_PF);
1287 DP(BNX2X_MSG_SP, "CFC_REG_WEAK_ENABLE_PF is 0x%x\n", val);
1289 val = REG_RD(bp, PBF_REG_DISABLE_PF);
1290 DP(BNX2X_MSG_SP, "PBF_REG_DISABLE_PF is 0x%x\n", val);
1292 val = REG_RD(bp, IGU_REG_PCI_PF_MSI_EN);
1293 DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSI_EN is 0x%x\n", val);
1295 val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_EN);
1296 DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_EN is 0x%x\n", val);
1298 val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_FUNC_MASK);
1299 DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_FUNC_MASK is 0x%x\n", val);
1301 val = REG_RD(bp, PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR);
1302 DP(BNX2X_MSG_SP, "PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR is 0x%x\n", val);
1304 val = REG_RD(bp, PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR);
1305 DP(BNX2X_MSG_SP, "PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR is 0x%x\n", val);
1307 val = REG_RD(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER);
1308 DP(BNX2X_MSG_SP, "PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER is 0x%x\n",
1312 static int bnx2x_pf_flr_clnup(struct bnx2x *bp)
1314 u32 poll_cnt = bnx2x_flr_clnup_poll_count(bp);
1316 DP(BNX2X_MSG_SP, "Cleanup after FLR PF[%d]\n", BP_ABS_FUNC(bp));
1318 /* Re-enable PF target read access */
1319 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
1321 /* Poll HW usage counters */
1322 if (bnx2x_poll_hw_usage_counters(bp, poll_cnt))
1325 /* Zero the igu 'trailing edge' and 'leading edge' */
1327 /* Send the FW cleanup command */
1328 if (bnx2x_send_final_clnup(bp, (u8)BP_FUNC(bp), poll_cnt))
1333 /* Verify TX hw is flushed */
1334 bnx2x_tx_hw_flushed(bp, poll_cnt);
1336 /* Wait 100ms (not adjusted according to platform) */
1339 /* Verify no pending pci transactions */
1340 if (bnx2x_is_pcie_pending(bp->pdev))
1341 BNX2X_ERR("PCIE Transactions still pending\n");
1344 bnx2x_hw_enable_status(bp);
1347 * Master enable - Due to WB DMAE writes performed before this
1348 * register is re-initialized as part of the regular function init
1350 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
1355 static void bnx2x_hc_int_enable(struct bnx2x *bp)
1357 int port = BP_PORT(bp);
1358 u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
1359 u32 val = REG_RD(bp, addr);
1360 int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
1361 int msi = (bp->flags & USING_MSI_FLAG) ? 1 : 0;
1364 val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
1365 HC_CONFIG_0_REG_INT_LINE_EN_0);
1366 val |= (HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
1367 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
1369 val &= ~HC_CONFIG_0_REG_INT_LINE_EN_0;
1370 val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
1371 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
1372 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
1374 val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
1375 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
1376 HC_CONFIG_0_REG_INT_LINE_EN_0 |
1377 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
1379 if (!CHIP_IS_E1(bp)) {
1380 DP(NETIF_MSG_INTR, "write %x to HC %d (addr 0x%x)\n",
1383 REG_WR(bp, addr, val);
1385 val &= ~HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0;
1390 REG_WR(bp, HC_REG_INT_MASK + port*4, 0x1FFFF);
1392 DP(NETIF_MSG_INTR, "write %x to HC %d (addr 0x%x) mode %s\n",
1393 val, port, addr, (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
1395 REG_WR(bp, addr, val);
1397 * Ensure that HC_CONFIG is written before leading/trailing edge config
1402 if (!CHIP_IS_E1(bp)) {
1403 /* init leading/trailing edge */
1405 val = (0xee0f | (1 << (BP_E1HVN(bp) + 4)));
1407 /* enable nig and gpio3 attention */
1412 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
1413 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
1416 /* Make sure that interrupts are indeed enabled from here on */
1420 static void bnx2x_igu_int_enable(struct bnx2x *bp)
1423 int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
1424 int msi = (bp->flags & USING_MSI_FLAG) ? 1 : 0;
1426 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
1429 val &= ~(IGU_PF_CONF_INT_LINE_EN |
1430 IGU_PF_CONF_SINGLE_ISR_EN);
1431 val |= (IGU_PF_CONF_FUNC_EN |
1432 IGU_PF_CONF_MSI_MSIX_EN |
1433 IGU_PF_CONF_ATTN_BIT_EN);
1435 val &= ~IGU_PF_CONF_INT_LINE_EN;
1436 val |= (IGU_PF_CONF_FUNC_EN |
1437 IGU_PF_CONF_MSI_MSIX_EN |
1438 IGU_PF_CONF_ATTN_BIT_EN |
1439 IGU_PF_CONF_SINGLE_ISR_EN);
1441 val &= ~IGU_PF_CONF_MSI_MSIX_EN;
1442 val |= (IGU_PF_CONF_FUNC_EN |
1443 IGU_PF_CONF_INT_LINE_EN |
1444 IGU_PF_CONF_ATTN_BIT_EN |
1445 IGU_PF_CONF_SINGLE_ISR_EN);
1448 DP(NETIF_MSG_INTR, "write 0x%x to IGU mode %s\n",
1449 val, (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
1451 REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
1455 /* init leading/trailing edge */
1457 val = (0xee0f | (1 << (BP_E1HVN(bp) + 4)));
1459 /* enable nig and gpio3 attention */
1464 REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
1465 REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
1467 /* Make sure that interrupts are indeed enabled from here on */
1471 void bnx2x_int_enable(struct bnx2x *bp)
1473 if (bp->common.int_block == INT_BLOCK_HC)
1474 bnx2x_hc_int_enable(bp);
1476 bnx2x_igu_int_enable(bp);
1479 static void bnx2x_hc_int_disable(struct bnx2x *bp)
1481 int port = BP_PORT(bp);
1482 u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
1483 u32 val = REG_RD(bp, addr);
1486 * in E1 we must use only PCI configuration space to disable
1487 * MSI/MSIX capablility
1488 * It's forbitten to disable IGU_PF_CONF_MSI_MSIX_EN in HC block
1490 if (CHIP_IS_E1(bp)) {
1491 /* Since IGU_PF_CONF_MSI_MSIX_EN still always on
1492 * Use mask register to prevent from HC sending interrupts
1493 * after we exit the function
1495 REG_WR(bp, HC_REG_INT_MASK + port*4, 0);
1497 val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
1498 HC_CONFIG_0_REG_INT_LINE_EN_0 |
1499 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
1501 val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
1502 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
1503 HC_CONFIG_0_REG_INT_LINE_EN_0 |
1504 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
1506 DP(NETIF_MSG_INTR, "write %x to HC %d (addr 0x%x)\n",
1509 /* flush all outstanding writes */
1512 REG_WR(bp, addr, val);
1513 if (REG_RD(bp, addr) != val)
1514 BNX2X_ERR("BUG! proper val not read from IGU!\n");
1517 static void bnx2x_igu_int_disable(struct bnx2x *bp)
1519 u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
1521 val &= ~(IGU_PF_CONF_MSI_MSIX_EN |
1522 IGU_PF_CONF_INT_LINE_EN |
1523 IGU_PF_CONF_ATTN_BIT_EN);
1525 DP(NETIF_MSG_INTR, "write %x to IGU\n", val);
1527 /* flush all outstanding writes */
1530 REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
1531 if (REG_RD(bp, IGU_REG_PF_CONFIGURATION) != val)
1532 BNX2X_ERR("BUG! proper val not read from IGU!\n");
1535 static void bnx2x_int_disable(struct bnx2x *bp)
1537 if (bp->common.int_block == INT_BLOCK_HC)
1538 bnx2x_hc_int_disable(bp);
1540 bnx2x_igu_int_disable(bp);
1543 void bnx2x_int_disable_sync(struct bnx2x *bp, int disable_hw)
1545 int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
1549 /* prevent the HW from sending interrupts */
1550 bnx2x_int_disable(bp);
1552 /* make sure all ISRs are done */
1554 synchronize_irq(bp->msix_table[0].vector);
1559 for_each_eth_queue(bp, i)
1560 synchronize_irq(bp->msix_table[offset++].vector);
1562 synchronize_irq(bp->pdev->irq);
1564 /* make sure sp_task is not running */
1565 cancel_delayed_work(&bp->sp_task);
1566 cancel_delayed_work(&bp->period_task);
1567 flush_workqueue(bnx2x_wq);
1573 * General service functions
1576 /* Return true if succeeded to acquire the lock */
1577 static bool bnx2x_trylock_hw_lock(struct bnx2x *bp, u32 resource)
1580 u32 resource_bit = (1 << resource);
1581 int func = BP_FUNC(bp);
1582 u32 hw_lock_control_reg;
1584 DP(NETIF_MSG_HW, "Trying to take a lock on resource %d\n", resource);
1586 /* Validating that the resource is within range */
1587 if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
1589 "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
1590 resource, HW_LOCK_MAX_RESOURCE_VALUE);
1595 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
1597 hw_lock_control_reg =
1598 (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
1600 /* Try to acquire the lock */
1601 REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
1602 lock_status = REG_RD(bp, hw_lock_control_reg);
1603 if (lock_status & resource_bit)
1606 DP(NETIF_MSG_HW, "Failed to get a lock on resource %d\n", resource);
1611 * bnx2x_get_leader_lock_resource - get the recovery leader resource id
1613 * @bp: driver handle
1615 * Returns the recovery leader resource id according to the engine this function
1616 * belongs to. Currently only only 2 engines is supported.
1618 static inline int bnx2x_get_leader_lock_resource(struct bnx2x *bp)
1621 return HW_LOCK_RESOURCE_RECOVERY_LEADER_1;
1623 return HW_LOCK_RESOURCE_RECOVERY_LEADER_0;
1627 * bnx2x_trylock_leader_lock- try to aquire a leader lock.
1629 * @bp: driver handle
1631 * Tries to aquire a leader lock for cuurent engine.
1633 static inline bool bnx2x_trylock_leader_lock(struct bnx2x *bp)
1635 return bnx2x_trylock_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
1639 static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err);
1642 void bnx2x_sp_event(struct bnx2x_fastpath *fp, union eth_rx_cqe *rr_cqe)
1644 struct bnx2x *bp = fp->bp;
1645 int cid = SW_CID(rr_cqe->ramrod_cqe.conn_and_cmd_data);
1646 int command = CQE_CMD(rr_cqe->ramrod_cqe.conn_and_cmd_data);
1647 enum bnx2x_queue_cmd drv_cmd = BNX2X_Q_CMD_MAX;
1648 struct bnx2x_queue_sp_obj *q_obj = &fp->q_obj;
1651 "fp %d cid %d got ramrod #%d state is %x type is %d\n",
1652 fp->index, cid, command, bp->state,
1653 rr_cqe->ramrod_cqe.ramrod_type);
1656 case (RAMROD_CMD_ID_ETH_CLIENT_UPDATE):
1657 DP(NETIF_MSG_IFUP, "got UPDATE ramrod. CID %d\n", cid);
1658 drv_cmd = BNX2X_Q_CMD_UPDATE;
1660 case (RAMROD_CMD_ID_ETH_CLIENT_SETUP):
1661 DP(NETIF_MSG_IFUP, "got MULTI[%d] setup ramrod\n", cid);
1662 drv_cmd = BNX2X_Q_CMD_SETUP;
1665 case (RAMROD_CMD_ID_ETH_HALT):
1666 DP(NETIF_MSG_IFDOWN, "got MULTI[%d] halt ramrod\n", cid);
1667 drv_cmd = BNX2X_Q_CMD_HALT;
1670 case (RAMROD_CMD_ID_ETH_TERMINATE):
1671 DP(NETIF_MSG_IFDOWN, "got MULTI[%d] teminate ramrod\n", cid);
1672 drv_cmd = BNX2X_Q_CMD_TERMINATE;
1675 case (RAMROD_CMD_ID_ETH_EMPTY):
1676 DP(NETIF_MSG_IFDOWN, "got MULTI[%d] empty ramrod\n", cid);
1677 drv_cmd = BNX2X_Q_CMD_EMPTY;
1681 BNX2X_ERR("unexpected MC reply (%d) on fp[%d]\n",
1682 command, fp->index);
1686 if ((drv_cmd != BNX2X_Q_CMD_MAX) &&
1687 q_obj->complete_cmd(bp, q_obj, drv_cmd))
1688 /* q_obj->complete_cmd() failure means that this was
1689 * an unexpected completion.
1691 * In this case we don't want to increase the bp->spq_left
1692 * because apparently we haven't sent this command the first
1695 #ifdef BNX2X_STOP_ON_ERROR
1701 smp_mb__before_atomic_inc();
1702 atomic_inc(&bp->cq_spq_left);
1703 /* push the change in bp->spq_left and towards the memory */
1704 smp_mb__after_atomic_inc();
1709 void bnx2x_update_rx_prod(struct bnx2x *bp, struct bnx2x_fastpath *fp,
1710 u16 bd_prod, u16 rx_comp_prod, u16 rx_sge_prod)
1712 u32 start = BAR_USTRORM_INTMEM + fp->ustorm_rx_prods_offset;
1714 bnx2x_update_rx_prod_gen(bp, fp, bd_prod, rx_comp_prod, rx_sge_prod,
1718 irqreturn_t bnx2x_interrupt(int irq, void *dev_instance)
1720 struct bnx2x *bp = netdev_priv(dev_instance);
1721 u16 status = bnx2x_ack_int(bp);
1725 /* Return here if interrupt is shared and it's not for us */
1726 if (unlikely(status == 0)) {
1727 DP(NETIF_MSG_INTR, "not our interrupt!\n");
1730 DP(NETIF_MSG_INTR, "got an interrupt status 0x%x\n", status);
1732 #ifdef BNX2X_STOP_ON_ERROR
1733 if (unlikely(bp->panic))
1737 for_each_eth_queue(bp, i) {
1738 struct bnx2x_fastpath *fp = &bp->fp[i];
1740 mask = 0x2 << (fp->index + CNIC_CONTEXT_USE);
1741 if (status & mask) {
1742 /* Handle Rx or Tx according to SB id */
1743 prefetch(fp->rx_cons_sb);
1744 prefetch(fp->tx_cons_sb);
1745 prefetch(&fp->sb_running_index[SM_RX_ID]);
1746 napi_schedule(&bnx2x_fp(bp, fp->index, napi));
1753 if (status & (mask | 0x1)) {
1754 struct cnic_ops *c_ops = NULL;
1756 if (likely(bp->state == BNX2X_STATE_OPEN)) {
1758 c_ops = rcu_dereference(bp->cnic_ops);
1760 c_ops->cnic_handler(bp->cnic_data, NULL);
1768 if (unlikely(status & 0x1)) {
1769 queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
1776 if (unlikely(status))
1777 DP(NETIF_MSG_INTR, "got an unknown interrupt! (status 0x%x)\n",
1786 * General service functions
1789 int bnx2x_acquire_hw_lock(struct bnx2x *bp, u32 resource)
1792 u32 resource_bit = (1 << resource);
1793 int func = BP_FUNC(bp);
1794 u32 hw_lock_control_reg;
1797 /* Validating that the resource is within range */
1798 if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
1800 "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
1801 resource, HW_LOCK_MAX_RESOURCE_VALUE);
1806 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
1808 hw_lock_control_reg =
1809 (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
1812 /* Validating that the resource is not already taken */
1813 lock_status = REG_RD(bp, hw_lock_control_reg);
1814 if (lock_status & resource_bit) {
1815 DP(NETIF_MSG_HW, "lock_status 0x%x resource_bit 0x%x\n",
1816 lock_status, resource_bit);
1820 /* Try for 5 second every 5ms */
1821 for (cnt = 0; cnt < 1000; cnt++) {
1822 /* Try to acquire the lock */
1823 REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
1824 lock_status = REG_RD(bp, hw_lock_control_reg);
1825 if (lock_status & resource_bit)
1830 DP(NETIF_MSG_HW, "Timeout\n");
1834 int bnx2x_release_leader_lock(struct bnx2x *bp)
1836 return bnx2x_release_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
1839 int bnx2x_release_hw_lock(struct bnx2x *bp, u32 resource)
1842 u32 resource_bit = (1 << resource);
1843 int func = BP_FUNC(bp);
1844 u32 hw_lock_control_reg;
1846 DP(NETIF_MSG_HW, "Releasing a lock on resource %d\n", resource);
1848 /* Validating that the resource is within range */
1849 if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
1851 "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
1852 resource, HW_LOCK_MAX_RESOURCE_VALUE);
1857 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
1859 hw_lock_control_reg =
1860 (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
1863 /* Validating that the resource is currently taken */
1864 lock_status = REG_RD(bp, hw_lock_control_reg);
1865 if (!(lock_status & resource_bit)) {
1866 DP(NETIF_MSG_HW, "lock_status 0x%x resource_bit 0x%x\n",
1867 lock_status, resource_bit);
1871 REG_WR(bp, hw_lock_control_reg, resource_bit);
1876 int bnx2x_get_gpio(struct bnx2x *bp, int gpio_num, u8 port)
1878 /* The GPIO should be swapped if swap register is set and active */
1879 int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
1880 REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
1881 int gpio_shift = gpio_num +
1882 (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
1883 u32 gpio_mask = (1 << gpio_shift);
1887 if (gpio_num > MISC_REGISTERS_GPIO_3) {
1888 BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
1892 /* read GPIO value */
1893 gpio_reg = REG_RD(bp, MISC_REG_GPIO);
1895 /* get the requested pin value */
1896 if ((gpio_reg & gpio_mask) == gpio_mask)
1901 DP(NETIF_MSG_LINK, "pin %d value 0x%x\n", gpio_num, value);
1906 int bnx2x_set_gpio(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
1908 /* The GPIO should be swapped if swap register is set and active */
1909 int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
1910 REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
1911 int gpio_shift = gpio_num +
1912 (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
1913 u32 gpio_mask = (1 << gpio_shift);
1916 if (gpio_num > MISC_REGISTERS_GPIO_3) {
1917 BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
1921 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
1922 /* read GPIO and mask except the float bits */
1923 gpio_reg = (REG_RD(bp, MISC_REG_GPIO) & MISC_REGISTERS_GPIO_FLOAT);
1926 case MISC_REGISTERS_GPIO_OUTPUT_LOW:
1927 DP(NETIF_MSG_LINK, "Set GPIO %d (shift %d) -> output low\n",
1928 gpio_num, gpio_shift);
1929 /* clear FLOAT and set CLR */
1930 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
1931 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_CLR_POS);
1934 case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
1935 DP(NETIF_MSG_LINK, "Set GPIO %d (shift %d) -> output high\n",
1936 gpio_num, gpio_shift);
1937 /* clear FLOAT and set SET */
1938 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
1939 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_SET_POS);
1942 case MISC_REGISTERS_GPIO_INPUT_HI_Z:
1943 DP(NETIF_MSG_LINK, "Set GPIO %d (shift %d) -> input\n",
1944 gpio_num, gpio_shift);
1946 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
1953 REG_WR(bp, MISC_REG_GPIO, gpio_reg);
1954 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
1959 int bnx2x_set_mult_gpio(struct bnx2x *bp, u8 pins, u32 mode)
1964 /* Any port swapping should be handled by caller. */
1966 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
1967 /* read GPIO and mask except the float bits */
1968 gpio_reg = REG_RD(bp, MISC_REG_GPIO);
1969 gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_FLOAT_POS);
1970 gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_CLR_POS);
1971 gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_SET_POS);
1974 case MISC_REGISTERS_GPIO_OUTPUT_LOW:
1975 DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output low\n", pins);
1977 gpio_reg |= (pins << MISC_REGISTERS_GPIO_CLR_POS);
1980 case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
1981 DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output high\n", pins);
1983 gpio_reg |= (pins << MISC_REGISTERS_GPIO_SET_POS);
1986 case MISC_REGISTERS_GPIO_INPUT_HI_Z:
1987 DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> input\n", pins);
1989 gpio_reg |= (pins << MISC_REGISTERS_GPIO_FLOAT_POS);
1993 BNX2X_ERR("Invalid GPIO mode assignment %d\n", mode);
1999 REG_WR(bp, MISC_REG_GPIO, gpio_reg);
2001 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
2006 int bnx2x_set_gpio_int(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
2008 /* The GPIO should be swapped if swap register is set and active */
2009 int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
2010 REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
2011 int gpio_shift = gpio_num +
2012 (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
2013 u32 gpio_mask = (1 << gpio_shift);
2016 if (gpio_num > MISC_REGISTERS_GPIO_3) {
2017 BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
2021 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
2023 gpio_reg = REG_RD(bp, MISC_REG_GPIO_INT);
2026 case MISC_REGISTERS_GPIO_INT_OUTPUT_CLR:
2027 DP(NETIF_MSG_LINK, "Clear GPIO INT %d (shift %d) -> "
2028 "output low\n", gpio_num, gpio_shift);
2029 /* clear SET and set CLR */
2030 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
2031 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
2034 case MISC_REGISTERS_GPIO_INT_OUTPUT_SET:
2035 DP(NETIF_MSG_LINK, "Set GPIO INT %d (shift %d) -> "
2036 "output high\n", gpio_num, gpio_shift);
2037 /* clear CLR and set SET */
2038 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
2039 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
2046 REG_WR(bp, MISC_REG_GPIO_INT, gpio_reg);
2047 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
2052 static int bnx2x_set_spio(struct bnx2x *bp, int spio_num, u32 mode)
2054 u32 spio_mask = (1 << spio_num);
2057 if ((spio_num < MISC_REGISTERS_SPIO_4) ||
2058 (spio_num > MISC_REGISTERS_SPIO_7)) {
2059 BNX2X_ERR("Invalid SPIO %d\n", spio_num);
2063 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
2064 /* read SPIO and mask except the float bits */
2065 spio_reg = (REG_RD(bp, MISC_REG_SPIO) & MISC_REGISTERS_SPIO_FLOAT);
2068 case MISC_REGISTERS_SPIO_OUTPUT_LOW:
2069 DP(NETIF_MSG_LINK, "Set SPIO %d -> output low\n", spio_num);
2070 /* clear FLOAT and set CLR */
2071 spio_reg &= ~(spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS);
2072 spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_CLR_POS);
2075 case MISC_REGISTERS_SPIO_OUTPUT_HIGH:
2076 DP(NETIF_MSG_LINK, "Set SPIO %d -> output high\n", spio_num);
2077 /* clear FLOAT and set SET */
2078 spio_reg &= ~(spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS);
2079 spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_SET_POS);
2082 case MISC_REGISTERS_SPIO_INPUT_HI_Z:
2083 DP(NETIF_MSG_LINK, "Set SPIO %d -> input\n", spio_num);
2085 spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS);
2092 REG_WR(bp, MISC_REG_SPIO, spio_reg);
2093 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
2098 void bnx2x_calc_fc_adv(struct bnx2x *bp)
2100 u8 cfg_idx = bnx2x_get_link_cfg_idx(bp);
2101 switch (bp->link_vars.ieee_fc &
2102 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK) {
2103 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE:
2104 bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
2108 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH:
2109 bp->port.advertising[cfg_idx] |= (ADVERTISED_Asym_Pause |
2113 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC:
2114 bp->port.advertising[cfg_idx] |= ADVERTISED_Asym_Pause;
2118 bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
2124 u8 bnx2x_initial_phy_init(struct bnx2x *bp, int load_mode)
2126 if (!BP_NOMCP(bp)) {
2128 int cfx_idx = bnx2x_get_link_cfg_idx(bp);
2129 u16 req_line_speed = bp->link_params.req_line_speed[cfx_idx];
2130 /* Initialize link parameters structure variables */
2131 /* It is recommended to turn off RX FC for jumbo frames
2132 for better performance */
2133 if ((CHIP_IS_E1x(bp)) && (bp->dev->mtu > 5000))
2134 bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_TX;
2136 bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_BOTH;
2138 bnx2x_acquire_phy_lock(bp);
2140 if (load_mode == LOAD_DIAG) {
2141 bp->link_params.loopback_mode = LOOPBACK_XGXS;
2142 bp->link_params.req_line_speed[cfx_idx] = SPEED_10000;
2145 rc = bnx2x_phy_init(&bp->link_params, &bp->link_vars);
2147 bnx2x_release_phy_lock(bp);
2149 bnx2x_calc_fc_adv(bp);
2151 if (CHIP_REV_IS_SLOW(bp) && bp->link_vars.link_up) {
2152 bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
2153 bnx2x_link_report(bp);
2155 queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
2156 bp->link_params.req_line_speed[cfx_idx] = req_line_speed;
2159 BNX2X_ERR("Bootcode is missing - can not initialize link\n");
2163 void bnx2x_link_set(struct bnx2x *bp)
2165 if (!BP_NOMCP(bp)) {
2166 bnx2x_acquire_phy_lock(bp);
2167 bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
2168 bnx2x_phy_init(&bp->link_params, &bp->link_vars);
2169 bnx2x_release_phy_lock(bp);
2171 bnx2x_calc_fc_adv(bp);
2173 BNX2X_ERR("Bootcode is missing - can not set link\n");
2176 static void bnx2x__link_reset(struct bnx2x *bp)
2178 if (!BP_NOMCP(bp)) {
2179 bnx2x_acquire_phy_lock(bp);
2180 bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
2181 bnx2x_release_phy_lock(bp);
2183 BNX2X_ERR("Bootcode is missing - can not reset link\n");
2186 u8 bnx2x_link_test(struct bnx2x *bp, u8 is_serdes)
2190 if (!BP_NOMCP(bp)) {
2191 bnx2x_acquire_phy_lock(bp);
2192 rc = bnx2x_test_link(&bp->link_params, &bp->link_vars,
2194 bnx2x_release_phy_lock(bp);
2196 BNX2X_ERR("Bootcode is missing - can not test link\n");
2201 static void bnx2x_init_port_minmax(struct bnx2x *bp)
2203 u32 r_param = bp->link_vars.line_speed / 8;
2204 u32 fair_periodic_timeout_usec;
2207 memset(&(bp->cmng.rs_vars), 0,
2208 sizeof(struct rate_shaping_vars_per_port));
2209 memset(&(bp->cmng.fair_vars), 0, sizeof(struct fairness_vars_per_port));
2211 /* 100 usec in SDM ticks = 25 since each tick is 4 usec */
2212 bp->cmng.rs_vars.rs_periodic_timeout = RS_PERIODIC_TIMEOUT_USEC / 4;
2214 /* this is the threshold below which no timer arming will occur
2215 1.25 coefficient is for the threshold to be a little bigger
2216 than the real time, to compensate for timer in-accuracy */
2217 bp->cmng.rs_vars.rs_threshold =
2218 (RS_PERIODIC_TIMEOUT_USEC * r_param * 5) / 4;
2220 /* resolution of fairness timer */
2221 fair_periodic_timeout_usec = QM_ARB_BYTES / r_param;
2222 /* for 10G it is 1000usec. for 1G it is 10000usec. */
2223 t_fair = T_FAIR_COEF / bp->link_vars.line_speed;
2225 /* this is the threshold below which we won't arm the timer anymore */
2226 bp->cmng.fair_vars.fair_threshold = QM_ARB_BYTES;
2228 /* we multiply by 1e3/8 to get bytes/msec.
2229 We don't want the credits to pass a credit
2230 of the t_fair*FAIR_MEM (algorithm resolution) */
2231 bp->cmng.fair_vars.upper_bound = r_param * t_fair * FAIR_MEM;
2232 /* since each tick is 4 usec */
2233 bp->cmng.fair_vars.fairness_timeout = fair_periodic_timeout_usec / 4;
2236 /* Calculates the sum of vn_min_rates.
2237 It's needed for further normalizing of the min_rates.
2239 sum of vn_min_rates.
2241 0 - if all the min_rates are 0.
2242 In the later case fainess algorithm should be deactivated.
2243 If not all min_rates are zero then those that are zeroes will be set to 1.
2245 static void bnx2x_calc_vn_weight_sum(struct bnx2x *bp)
2250 bp->vn_weight_sum = 0;
2251 for (vn = VN_0; vn < E1HVN_MAX; vn++) {
2252 u32 vn_cfg = bp->mf_config[vn];
2253 u32 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
2254 FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
2256 /* Skip hidden vns */
2257 if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
2260 /* If min rate is zero - set it to 1 */
2262 vn_min_rate = DEF_MIN_RATE;
2266 bp->vn_weight_sum += vn_min_rate;
2269 /* if ETS or all min rates are zeros - disable fairness */
2270 if (BNX2X_IS_ETS_ENABLED(bp)) {
2271 bp->cmng.flags.cmng_enables &=
2272 ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
2273 DP(NETIF_MSG_IFUP, "Fairness will be disabled due to ETS\n");
2274 } else if (all_zero) {
2275 bp->cmng.flags.cmng_enables &=
2276 ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
2277 DP(NETIF_MSG_IFUP, "All MIN values are zeroes"
2278 " fairness will be disabled\n");
2280 bp->cmng.flags.cmng_enables |=
2281 CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
2284 static void bnx2x_init_vn_minmax(struct bnx2x *bp, int vn)
2286 struct rate_shaping_vars_per_vn m_rs_vn;
2287 struct fairness_vars_per_vn m_fair_vn;
2288 u32 vn_cfg = bp->mf_config[vn];
2289 int func = 2*vn + BP_PORT(bp);
2290 u16 vn_min_rate, vn_max_rate;
2293 /* If function is hidden - set min and max to zeroes */
2294 if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE) {
2299 u32 maxCfg = bnx2x_extract_max_cfg(bp, vn_cfg);
2301 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
2302 FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
2303 /* If fairness is enabled (not all min rates are zeroes) and
2304 if current min rate is zero - set it to 1.
2305 This is a requirement of the algorithm. */
2306 if (bp->vn_weight_sum && (vn_min_rate == 0))
2307 vn_min_rate = DEF_MIN_RATE;
2310 /* maxCfg in percents of linkspeed */
2311 vn_max_rate = (bp->link_vars.line_speed * maxCfg) / 100;
2313 /* maxCfg is absolute in 100Mb units */
2314 vn_max_rate = maxCfg * 100;
2318 "func %d: vn_min_rate %d vn_max_rate %d vn_weight_sum %d\n",
2319 func, vn_min_rate, vn_max_rate, bp->vn_weight_sum);
2321 memset(&m_rs_vn, 0, sizeof(struct rate_shaping_vars_per_vn));
2322 memset(&m_fair_vn, 0, sizeof(struct fairness_vars_per_vn));
2324 /* global vn counter - maximal Mbps for this vn */
2325 m_rs_vn.vn_counter.rate = vn_max_rate;
2327 /* quota - number of bytes transmitted in this period */
2328 m_rs_vn.vn_counter.quota =
2329 (vn_max_rate * RS_PERIODIC_TIMEOUT_USEC) / 8;
2331 if (bp->vn_weight_sum) {
2332 /* credit for each period of the fairness algorithm:
2333 number of bytes in T_FAIR (the vn share the port rate).
2334 vn_weight_sum should not be larger than 10000, thus
2335 T_FAIR_COEF / (8 * vn_weight_sum) will always be greater
2337 m_fair_vn.vn_credit_delta =
2338 max_t(u32, (vn_min_rate * (T_FAIR_COEF /
2339 (8 * bp->vn_weight_sum))),
2340 (bp->cmng.fair_vars.fair_threshold +
2342 DP(NETIF_MSG_IFUP, "m_fair_vn.vn_credit_delta %d\n",
2343 m_fair_vn.vn_credit_delta);
2346 /* Store it to internal memory */
2347 for (i = 0; i < sizeof(struct rate_shaping_vars_per_vn)/4; i++)
2348 REG_WR(bp, BAR_XSTRORM_INTMEM +
2349 XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(func) + i * 4,
2350 ((u32 *)(&m_rs_vn))[i]);
2352 for (i = 0; i < sizeof(struct fairness_vars_per_vn)/4; i++)
2353 REG_WR(bp, BAR_XSTRORM_INTMEM +
2354 XSTORM_FAIRNESS_PER_VN_VARS_OFFSET(func) + i * 4,
2355 ((u32 *)(&m_fair_vn))[i]);
2358 static int bnx2x_get_cmng_fns_mode(struct bnx2x *bp)
2360 if (CHIP_REV_IS_SLOW(bp))
2361 return CMNG_FNS_NONE;
2363 return CMNG_FNS_MINMAX;
2365 return CMNG_FNS_NONE;
2368 void bnx2x_read_mf_cfg(struct bnx2x *bp)
2370 int vn, n = (CHIP_MODE_IS_4_PORT(bp) ? 2 : 1);
2373 return; /* what should be the default bvalue in this case */
2375 /* For 2 port configuration the absolute function number formula
2377 * abs_func = 2 * vn + BP_PORT + BP_PATH
2379 * and there are 4 functions per port
2381 * For 4 port configuration it is
2382 * abs_func = 4 * vn + 2 * BP_PORT + BP_PATH
2384 * and there are 2 functions per port
2386 for (vn = VN_0; vn < E1HVN_MAX; vn++) {
2387 int /*abs*/func = n * (2 * vn + BP_PORT(bp)) + BP_PATH(bp);
2389 if (func >= E1H_FUNC_MAX)
2393 MF_CFG_RD(bp, func_mf_config[func].config);
2397 static void bnx2x_cmng_fns_init(struct bnx2x *bp, u8 read_cfg, u8 cmng_type)
2400 if (cmng_type == CMNG_FNS_MINMAX) {
2403 /* clear cmng_enables */
2404 bp->cmng.flags.cmng_enables = 0;
2406 /* read mf conf from shmem */
2408 bnx2x_read_mf_cfg(bp);
2410 /* Init rate shaping and fairness contexts */
2411 bnx2x_init_port_minmax(bp);
2413 /* vn_weight_sum and enable fairness if not 0 */
2414 bnx2x_calc_vn_weight_sum(bp);
2416 /* calculate and set min-max rate for each vn */
2418 for (vn = VN_0; vn < E1HVN_MAX; vn++)
2419 bnx2x_init_vn_minmax(bp, vn);
2421 /* always enable rate shaping and fairness */
2422 bp->cmng.flags.cmng_enables |=
2423 CMNG_FLAGS_PER_PORT_RATE_SHAPING_VN;
2424 if (!bp->vn_weight_sum)
2425 DP(NETIF_MSG_IFUP, "All MIN values are zeroes"
2426 " fairness will be disabled\n");
2430 /* rate shaping and fairness are disabled */
2432 "rate shaping and fairness are disabled\n");
2435 static inline void bnx2x_link_sync_notify(struct bnx2x *bp)
2437 int port = BP_PORT(bp);
2441 /* Set the attention towards other drivers on the same port */
2442 for (vn = VN_0; vn < E1HVN_MAX; vn++) {
2443 if (vn == BP_E1HVN(bp))
2446 func = ((vn << 1) | port);
2447 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_0 +
2448 (LINK_SYNC_ATTENTION_BIT_FUNC_0 + func)*4, 1);
2452 /* This function is called upon link interrupt */
2453 static void bnx2x_link_attn(struct bnx2x *bp)
2455 /* Make sure that we are synced with the current statistics */
2456 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
2458 bnx2x_link_update(&bp->link_params, &bp->link_vars);
2460 if (bp->link_vars.link_up) {
2462 /* dropless flow control */
2463 if (!CHIP_IS_E1(bp) && bp->dropless_fc) {
2464 int port = BP_PORT(bp);
2465 u32 pause_enabled = 0;
2467 if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX)
2470 REG_WR(bp, BAR_USTRORM_INTMEM +
2471 USTORM_ETH_PAUSE_ENABLED_OFFSET(port),
2475 if (bp->link_vars.mac_type != MAC_TYPE_EMAC) {
2476 struct host_port_stats *pstats;
2478 pstats = bnx2x_sp(bp, port_stats);
2479 /* reset old mac stats */
2480 memset(&(pstats->mac_stx[0]), 0,
2481 sizeof(struct mac_stx));
2483 if (bp->state == BNX2X_STATE_OPEN)
2484 bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
2487 if (bp->link_vars.link_up && bp->link_vars.line_speed) {
2488 int cmng_fns = bnx2x_get_cmng_fns_mode(bp);
2490 if (cmng_fns != CMNG_FNS_NONE) {
2491 bnx2x_cmng_fns_init(bp, false, cmng_fns);
2492 storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
2494 /* rate shaping and fairness are disabled */
2496 "single function mode without fairness\n");
2499 __bnx2x_link_report(bp);
2502 bnx2x_link_sync_notify(bp);
2505 void bnx2x__link_status_update(struct bnx2x *bp)
2507 if (bp->state != BNX2X_STATE_OPEN)
2510 bnx2x_link_status_update(&bp->link_params, &bp->link_vars);
2512 if (bp->link_vars.link_up)
2513 bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
2515 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
2517 /* indicate link status */
2518 bnx2x_link_report(bp);
2521 static void bnx2x_pmf_update(struct bnx2x *bp)
2523 int port = BP_PORT(bp);
2527 DP(NETIF_MSG_LINK, "pmf %d\n", bp->port.pmf);
2530 * We need the mb() to ensure the ordering between the writing to
2531 * bp->port.pmf here and reading it from the bnx2x_periodic_task().
2535 /* queue a periodic task */
2536 queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
2538 bnx2x_dcbx_pmf_update(bp);
2540 /* enable nig attention */
2541 val = (0xff0f | (1 << (BP_E1HVN(bp) + 4)));
2542 if (bp->common.int_block == INT_BLOCK_HC) {
2543 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
2544 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
2545 } else if (!CHIP_IS_E1x(bp)) {
2546 REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
2547 REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
2550 bnx2x_stats_handle(bp, STATS_EVENT_PMF);
2558 * General service functions
2561 /* send the MCP a request, block until there is a reply */
2562 u32 bnx2x_fw_command(struct bnx2x *bp, u32 command, u32 param)
2564 int mb_idx = BP_FW_MB_IDX(bp);
2568 u8 delay = CHIP_REV_IS_SLOW(bp) ? 100 : 10;
2570 mutex_lock(&bp->fw_mb_mutex);
2572 SHMEM_WR(bp, func_mb[mb_idx].drv_mb_param, param);
2573 SHMEM_WR(bp, func_mb[mb_idx].drv_mb_header, (command | seq));
2575 DP(BNX2X_MSG_MCP, "wrote command (%x) to FW MB param 0x%08x\n",
2576 (command | seq), param);
2579 /* let the FW do it's magic ... */
2582 rc = SHMEM_RD(bp, func_mb[mb_idx].fw_mb_header);
2584 /* Give the FW up to 5 second (500*10ms) */
2585 } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 500));
2587 DP(BNX2X_MSG_MCP, "[after %d ms] read (%x) seq is (%x) from FW MB\n",
2588 cnt*delay, rc, seq);
2590 /* is this a reply to our command? */
2591 if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK))
2592 rc &= FW_MSG_CODE_MASK;
2595 BNX2X_ERR("FW failed to respond!\n");
2599 mutex_unlock(&bp->fw_mb_mutex);
2604 static u8 stat_counter_valid(struct bnx2x *bp, struct bnx2x_fastpath *fp)
2607 /* Statistics are not supported for CNIC Clients at the moment */
2614 void bnx2x_func_init(struct bnx2x *bp, struct bnx2x_func_init_params *p)
2616 if (CHIP_IS_E1x(bp)) {
2617 struct tstorm_eth_function_common_config tcfg = {0};
2619 storm_memset_func_cfg(bp, &tcfg, p->func_id);
2622 /* Enable the function in the FW */
2623 storm_memset_vf_to_pf(bp, p->func_id, p->pf_id);
2624 storm_memset_func_en(bp, p->func_id, 1);
2627 if (p->func_flgs & FUNC_FLG_SPQ) {
2628 storm_memset_spq_addr(bp, p->spq_map, p->func_id);
2629 REG_WR(bp, XSEM_REG_FAST_MEMORY +
2630 XSTORM_SPQ_PROD_OFFSET(p->func_id), p->spq_prod);
2634 static inline unsigned long bnx2x_get_q_flags(struct bnx2x *bp,
2635 struct bnx2x_fastpath *fp,
2638 unsigned long flags = 0;
2640 /* PF driver will always initialize the Queue to an ACTIVE state */
2641 __set_bit(BNX2X_Q_FLG_ACTIVE, &flags);
2643 /* calculate other queue flags */
2645 __set_bit(BNX2X_Q_FLG_OV, &flags);
2648 __set_bit(BNX2X_Q_FLG_FCOE, &flags);
2650 if (!fp->disable_tpa)
2651 __set_bit(BNX2X_Q_FLG_TPA, &flags);
2653 if (stat_counter_valid(bp, fp)) {
2654 __set_bit(BNX2X_Q_FLG_STATS, &flags);
2655 __set_bit(BNX2X_Q_FLG_ZERO_STATS, &flags);
2659 __set_bit(BNX2X_Q_FLG_LEADING_RSS, &flags);
2660 __set_bit(BNX2X_Q_FLG_MCAST, &flags);
2663 /* Always set HW VLAN stripping */
2664 __set_bit(BNX2X_Q_FLG_VLAN, &flags);
2669 static void bnx2x_pf_q_prep_general(struct bnx2x *bp,
2670 struct bnx2x_fastpath *fp, struct bnx2x_general_setup_params *gen_init)
2672 gen_init->stat_id = bnx2x_stats_id(fp);
2673 gen_init->spcl_id = fp->cl_id;
2675 /* Always use mini-jumbo MTU for FCoE L2 ring */
2677 gen_init->mtu = BNX2X_FCOE_MINI_JUMBO_MTU;
2679 gen_init->mtu = bp->dev->mtu;
2682 static void bnx2x_pf_rx_q_prep(struct bnx2x *bp,
2683 struct bnx2x_fastpath *fp, struct rxq_pause_params *pause,
2684 struct bnx2x_rxq_setup_params *rxq_init)
2688 u16 tpa_agg_size = 0;
2690 if (!fp->disable_tpa) {
2691 pause->sge_th_hi = 250;
2692 pause->sge_th_lo = 150;
2693 tpa_agg_size = min_t(u32,
2694 (min_t(u32, 8, MAX_SKB_FRAGS) *
2695 SGE_PAGE_SIZE * PAGES_PER_SGE), 0xffff);
2696 max_sge = SGE_PAGE_ALIGN(bp->dev->mtu) >>
2698 max_sge = ((max_sge + PAGES_PER_SGE - 1) &
2699 (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
2700 sge_sz = (u16)min_t(u32, SGE_PAGE_SIZE * PAGES_PER_SGE,
2704 /* pause - not for e1 */
2705 if (!CHIP_IS_E1(bp)) {
2706 pause->bd_th_hi = 350;
2707 pause->bd_th_lo = 250;
2708 pause->rcq_th_hi = 350;
2709 pause->rcq_th_lo = 250;
2715 rxq_init->dscr_map = fp->rx_desc_mapping;
2716 rxq_init->sge_map = fp->rx_sge_mapping;
2717 rxq_init->rcq_map = fp->rx_comp_mapping;
2718 rxq_init->rcq_np_map = fp->rx_comp_mapping + BCM_PAGE_SIZE;
2720 /* This should be a maximum number of data bytes that may be
2721 * placed on the BD (not including paddings).
2723 rxq_init->buf_sz = fp->rx_buf_size - BNX2X_FW_RX_ALIGN -
2724 IP_HEADER_ALIGNMENT_PADDING;
2726 rxq_init->cl_qzone_id = fp->cl_qzone_id;
2727 rxq_init->tpa_agg_sz = tpa_agg_size;
2728 rxq_init->sge_buf_sz = sge_sz;
2729 rxq_init->max_sges_pkt = max_sge;
2730 rxq_init->rss_engine_id = BP_FUNC(bp);
2732 /* Maximum number or simultaneous TPA aggregation for this Queue.
2734 * For PF Clients it should be the maximum avaliable number.
2735 * VF driver(s) may want to define it to a smaller value.
2737 rxq_init->max_tpa_queues =
2738 (CHIP_IS_E1(bp) ? ETH_MAX_AGGREGATION_QUEUES_E1 :
2739 ETH_MAX_AGGREGATION_QUEUES_E1H_E2);
2741 rxq_init->cache_line_log = BNX2X_RX_ALIGN_SHIFT;
2742 rxq_init->fw_sb_id = fp->fw_sb_id;
2745 rxq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_RX_CQ_CONS;
2747 rxq_init->sb_cq_index = U_SB_ETH_RX_CQ_INDEX;
2750 static void bnx2x_pf_tx_q_prep(struct bnx2x *bp,
2751 struct bnx2x_fastpath *fp, struct bnx2x_txq_setup_params *txq_init)
2753 txq_init->dscr_map = fp->tx_desc_mapping;
2754 txq_init->sb_cq_index = C_SB_ETH_TX_CQ_INDEX;
2755 txq_init->traffic_type = LLFC_TRAFFIC_TYPE_NW;
2756 txq_init->fw_sb_id = fp->fw_sb_id;
2759 * set the tss leading client id for TX classfication ==
2760 * leading RSS client id
2762 txq_init->tss_leading_cl_id = bnx2x_fp(bp, 0, cl_id);
2764 if (IS_FCOE_FP(fp)) {
2765 txq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_TX_CQ_CONS;
2766 txq_init->traffic_type = LLFC_TRAFFIC_TYPE_FCOE;
2770 static void bnx2x_pf_init(struct bnx2x *bp)
2772 struct bnx2x_func_init_params func_init = {0};
2773 struct event_ring_data eq_data = { {0} };
2776 if (!CHIP_IS_E1x(bp)) {
2777 /* reset IGU PF statistics: MSIX + ATTN */
2779 REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
2780 BNX2X_IGU_STAS_MSG_VF_CNT*4 +
2781 (CHIP_MODE_IS_4_PORT(bp) ?
2782 BP_FUNC(bp) : BP_VN(bp))*4, 0);
2784 REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
2785 BNX2X_IGU_STAS_MSG_VF_CNT*4 +
2786 BNX2X_IGU_STAS_MSG_PF_CNT*4 +
2787 (CHIP_MODE_IS_4_PORT(bp) ?
2788 BP_FUNC(bp) : BP_VN(bp))*4, 0);
2791 /* function setup flags */
2792 flags = (FUNC_FLG_STATS | FUNC_FLG_LEADING | FUNC_FLG_SPQ);
2794 /* This flag is relevant for E1x only.
2795 * E2 doesn't have a TPA configuration in a function level.
2797 flags |= (bp->flags & TPA_ENABLE_FLAG) ? FUNC_FLG_TPA : 0;
2799 func_init.func_flgs = flags;
2800 func_init.pf_id = BP_FUNC(bp);
2801 func_init.func_id = BP_FUNC(bp);
2802 func_init.spq_map = bp->spq_mapping;
2803 func_init.spq_prod = bp->spq_prod_idx;
2805 bnx2x_func_init(bp, &func_init);
2807 memset(&(bp->cmng), 0, sizeof(struct cmng_struct_per_port));
2810 * Congestion management values depend on the link rate
2811 * There is no active link so initial link rate is set to 10 Gbps.
2812 * When the link comes up The congestion management values are
2813 * re-calculated according to the actual link rate.
2815 bp->link_vars.line_speed = SPEED_10000;
2816 bnx2x_cmng_fns_init(bp, true, bnx2x_get_cmng_fns_mode(bp));
2818 /* Only the PMF sets the HW */
2820 storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
2822 /* init Event Queue */
2823 eq_data.base_addr.hi = U64_HI(bp->eq_mapping);
2824 eq_data.base_addr.lo = U64_LO(bp->eq_mapping);
2825 eq_data.producer = bp->eq_prod;
2826 eq_data.index_id = HC_SP_INDEX_EQ_CONS;
2827 eq_data.sb_id = DEF_SB_ID;
2828 storm_memset_eq_data(bp, &eq_data, BP_FUNC(bp));
2832 static void bnx2x_e1h_disable(struct bnx2x *bp)
2834 int port = BP_PORT(bp);
2836 bnx2x_tx_disable(bp);
2838 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
2841 static void bnx2x_e1h_enable(struct bnx2x *bp)
2843 int port = BP_PORT(bp);
2845 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
2847 /* Tx queue should be only reenabled */
2848 netif_tx_wake_all_queues(bp->dev);
2851 * Should not call netif_carrier_on since it will be called if the link
2852 * is up when checking for link state
2856 /* called due to MCP event (on pmf):
2857 * reread new bandwidth configuration
2859 * notify others function about the change
2861 static inline void bnx2x_config_mf_bw(struct bnx2x *bp)
2863 if (bp->link_vars.link_up) {
2864 bnx2x_cmng_fns_init(bp, true, CMNG_FNS_MINMAX);
2865 bnx2x_link_sync_notify(bp);
2867 storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
2870 static inline void bnx2x_set_mf_bw(struct bnx2x *bp)
2872 bnx2x_config_mf_bw(bp);
2873 bnx2x_fw_command(bp, DRV_MSG_CODE_SET_MF_BW_ACK, 0);
2876 static void bnx2x_dcc_event(struct bnx2x *bp, u32 dcc_event)
2878 DP(BNX2X_MSG_MCP, "dcc_event 0x%x\n", dcc_event);
2880 if (dcc_event & DRV_STATUS_DCC_DISABLE_ENABLE_PF) {
2883 * This is the only place besides the function initialization
2884 * where the bp->flags can change so it is done without any
2887 if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
2888 DP(NETIF_MSG_IFDOWN, "mf_cfg function disabled\n");
2889 bp->flags |= MF_FUNC_DIS;
2891 bnx2x_e1h_disable(bp);
2893 DP(NETIF_MSG_IFUP, "mf_cfg function enabled\n");
2894 bp->flags &= ~MF_FUNC_DIS;
2896 bnx2x_e1h_enable(bp);
2898 dcc_event &= ~DRV_STATUS_DCC_DISABLE_ENABLE_PF;
2900 if (dcc_event & DRV_STATUS_DCC_BANDWIDTH_ALLOCATION) {
2901 bnx2x_config_mf_bw(bp);
2902 dcc_event &= ~DRV_STATUS_DCC_BANDWIDTH_ALLOCATION;
2905 /* Report results to MCP */
2907 bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_FAILURE, 0);
2909 bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_OK, 0);
2912 /* must be called under the spq lock */
2913 static inline struct eth_spe *bnx2x_sp_get_next(struct bnx2x *bp)
2915 struct eth_spe *next_spe = bp->spq_prod_bd;
2917 if (bp->spq_prod_bd == bp->spq_last_bd) {
2918 bp->spq_prod_bd = bp->spq;
2919 bp->spq_prod_idx = 0;
2920 DP(NETIF_MSG_TIMER, "end of spq\n");
2928 /* must be called under the spq lock */
2929 static inline void bnx2x_sp_prod_update(struct bnx2x *bp)
2931 int func = BP_FUNC(bp);
2933 /* Make sure that BD data is updated before writing the producer */
2936 REG_WR16(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func),
2942 * bnx2x_is_contextless_ramrod - check if the current command ends on EQ
2944 * @cmd: command to check
2945 * @cmd_type: command type
2947 static inline bool bnx2x_is_contextless_ramrod(int cmd, int cmd_type)
2949 if ((cmd_type == NONE_CONNECTION_TYPE) ||
2950 (cmd == RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES) ||
2951 (cmd == RAMROD_CMD_ID_ETH_FILTER_RULES) ||
2952 (cmd == RAMROD_CMD_ID_ETH_MULTICAST_RULES) ||
2953 (cmd == RAMROD_CMD_ID_ETH_SET_MAC) ||
2954 (cmd == RAMROD_CMD_ID_ETH_RSS_UPDATE))
2963 * bnx2x_sp_post - place a single command on an SP ring
2965 * @bp: driver handle
2966 * @command: command to place (e.g. SETUP, FILTER_RULES, etc.)
2967 * @cid: SW CID the command is related to
2968 * @data_hi: command private data address (high 32 bits)
2969 * @data_lo: command private data address (low 32 bits)
2970 * @cmd_type: command type (e.g. NONE, ETH)
2972 * SP data is handled as if it's always an address pair, thus data fields are
2973 * not swapped to little endian in upper functions. Instead this function swaps
2974 * data as if it's two u32 fields.
2976 int bnx2x_sp_post(struct bnx2x *bp, int command, int cid,
2977 u32 data_hi, u32 data_lo, int cmd_type)
2979 struct eth_spe *spe;
2981 bool common = bnx2x_is_contextless_ramrod(command, cmd_type);
2983 #ifdef BNX2X_STOP_ON_ERROR
2984 if (unlikely(bp->panic))
2988 spin_lock_bh(&bp->spq_lock);
2991 if (!atomic_read(&bp->eq_spq_left)) {
2992 BNX2X_ERR("BUG! EQ ring full!\n");
2993 spin_unlock_bh(&bp->spq_lock);
2997 } else if (!atomic_read(&bp->cq_spq_left)) {
2998 BNX2X_ERR("BUG! SPQ ring full!\n");
2999 spin_unlock_bh(&bp->spq_lock);
3004 spe = bnx2x_sp_get_next(bp);
3006 /* CID needs port number to be encoded int it */
3007 spe->hdr.conn_and_cmd_data =
3008 cpu_to_le32((command << SPE_HDR_CMD_ID_SHIFT) |
3011 type = (cmd_type << SPE_HDR_CONN_TYPE_SHIFT) & SPE_HDR_CONN_TYPE;
3013 type |= ((BP_FUNC(bp) << SPE_HDR_FUNCTION_ID_SHIFT) &
3014 SPE_HDR_FUNCTION_ID);
3016 spe->hdr.type = cpu_to_le16(type);
3018 spe->data.update_data_addr.hi = cpu_to_le32(data_hi);
3019 spe->data.update_data_addr.lo = cpu_to_le32(data_lo);
3021 /* stats ramrod has it's own slot on the spq */
3022 if (command != RAMROD_CMD_ID_COMMON_STAT_QUERY) {
3024 * It's ok if the actual decrement is issued towards the memory
3025 * somewhere between the spin_lock and spin_unlock. Thus no
3026 * more explict memory barrier is needed.
3029 atomic_dec(&bp->eq_spq_left);
3031 atomic_dec(&bp->cq_spq_left);
3035 DP(BNX2X_MSG_SP/*NETIF_MSG_TIMER*/,
3036 "SPQE[%x] (%x:%x) command %d hw_cid %x data (%x:%x) "
3037 "type(0x%x) left (ETH, COMMON) (%x,%x)\n",
3038 bp->spq_prod_idx, (u32)U64_HI(bp->spq_mapping),
3039 (u32)(U64_LO(bp->spq_mapping) +
3040 (void *)bp->spq_prod_bd - (void *)bp->spq), command,
3041 HW_CID(bp, cid), data_hi, data_lo, type,
3042 atomic_read(&bp->cq_spq_left), atomic_read(&bp->eq_spq_left));
3044 bnx2x_sp_prod_update(bp);
3045 spin_unlock_bh(&bp->spq_lock);
3049 /* acquire split MCP access lock register */
3050 static int bnx2x_acquire_alr(struct bnx2x *bp)
3056 for (j = 0; j < 1000; j++) {
3058 REG_WR(bp, GRCBASE_MCP + 0x9c, val);
3059 val = REG_RD(bp, GRCBASE_MCP + 0x9c);
3060 if (val & (1L << 31))
3065 if (!(val & (1L << 31))) {
3066 BNX2X_ERR("Cannot acquire MCP access lock register\n");
3073 /* release split MCP access lock register */
3074 static void bnx2x_release_alr(struct bnx2x *bp)
3076 REG_WR(bp, GRCBASE_MCP + 0x9c, 0);
3079 #define BNX2X_DEF_SB_ATT_IDX 0x0001
3080 #define BNX2X_DEF_SB_IDX 0x0002
3082 static inline u16 bnx2x_update_dsb_idx(struct bnx2x *bp)
3084 struct host_sp_status_block *def_sb = bp->def_status_blk;
3087 barrier(); /* status block is written to by the chip */
3088 if (bp->def_att_idx != def_sb->atten_status_block.attn_bits_index) {
3089 bp->def_att_idx = def_sb->atten_status_block.attn_bits_index;
3090 rc |= BNX2X_DEF_SB_ATT_IDX;
3093 if (bp->def_idx != def_sb->sp_sb.running_index) {
3094 bp->def_idx = def_sb->sp_sb.running_index;
3095 rc |= BNX2X_DEF_SB_IDX;
3098 /* Do not reorder: indecies reading should complete before handling */
3104 * slow path service functions
3107 static void bnx2x_attn_int_asserted(struct bnx2x *bp, u32 asserted)
3109 int port = BP_PORT(bp);
3110 u32 aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
3111 MISC_REG_AEU_MASK_ATTN_FUNC_0;
3112 u32 nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 :
3113 NIG_REG_MASK_INTERRUPT_PORT0;
3118 if (bp->attn_state & asserted)
3119 BNX2X_ERR("IGU ERROR\n");
3121 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
3122 aeu_mask = REG_RD(bp, aeu_addr);
3124 DP(NETIF_MSG_HW, "aeu_mask %x newly asserted %x\n",
3125 aeu_mask, asserted);
3126 aeu_mask &= ~(asserted & 0x3ff);
3127 DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
3129 REG_WR(bp, aeu_addr, aeu_mask);
3130 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
3132 DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
3133 bp->attn_state |= asserted;
3134 DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
3136 if (asserted & ATTN_HARD_WIRED_MASK) {
3137 if (asserted & ATTN_NIG_FOR_FUNC) {
3139 bnx2x_acquire_phy_lock(bp);
3141 /* save nig interrupt mask */
3142 nig_mask = REG_RD(bp, nig_int_mask_addr);
3144 /* If nig_mask is not set, no need to call the update
3148 REG_WR(bp, nig_int_mask_addr, 0);
3150 bnx2x_link_attn(bp);
3153 /* handle unicore attn? */
3155 if (asserted & ATTN_SW_TIMER_4_FUNC)
3156 DP(NETIF_MSG_HW, "ATTN_SW_TIMER_4_FUNC!\n");
3158 if (asserted & GPIO_2_FUNC)
3159 DP(NETIF_MSG_HW, "GPIO_2_FUNC!\n");
3161 if (asserted & GPIO_3_FUNC)
3162 DP(NETIF_MSG_HW, "GPIO_3_FUNC!\n");
3164 if (asserted & GPIO_4_FUNC)
3165 DP(NETIF_MSG_HW, "GPIO_4_FUNC!\n");
3168 if (asserted & ATTN_GENERAL_ATTN_1) {
3169 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_1!\n");
3170 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_1, 0x0);
3172 if (asserted & ATTN_GENERAL_ATTN_2) {
3173 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_2!\n");
3174 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_2, 0x0);
3176 if (asserted & ATTN_GENERAL_ATTN_3) {
3177 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_3!\n");
3178 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_3, 0x0);
3181 if (asserted & ATTN_GENERAL_ATTN_4) {
3182 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_4!\n");
3183 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_4, 0x0);
3185 if (asserted & ATTN_GENERAL_ATTN_5) {
3186 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_5!\n");
3187 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_5, 0x0);
3189 if (asserted & ATTN_GENERAL_ATTN_6) {
3190 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_6!\n");
3191 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_6, 0x0);
3195 } /* if hardwired */
3197 if (bp->common.int_block == INT_BLOCK_HC)
3198 reg_addr = (HC_REG_COMMAND_REG + port*32 +
3199 COMMAND_REG_ATTN_BITS_SET);
3201 reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_SET_UPPER*8);
3203 DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", asserted,
3204 (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
3205 REG_WR(bp, reg_addr, asserted);
3207 /* now set back the mask */
3208 if (asserted & ATTN_NIG_FOR_FUNC) {
3209 REG_WR(bp, nig_int_mask_addr, nig_mask);
3210 bnx2x_release_phy_lock(bp);
3214 static inline void bnx2x_fan_failure(struct bnx2x *bp)
3216 int port = BP_PORT(bp);
3218 /* mark the failure */
3221 dev_info.port_hw_config[port].external_phy_config);
3223 ext_phy_config &= ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK;
3224 ext_phy_config |= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE;
3225 SHMEM_WR(bp, dev_info.port_hw_config[port].external_phy_config,
3228 /* log the failure */
3229 netdev_err(bp->dev, "Fan Failure on Network Controller has caused"
3230 " the driver to shutdown the card to prevent permanent"
3231 " damage. Please contact OEM Support for assistance\n");
3234 static inline void bnx2x_attn_int_deasserted0(struct bnx2x *bp, u32 attn)
3236 int port = BP_PORT(bp);
3240 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
3241 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
3243 if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) {
3245 val = REG_RD(bp, reg_offset);
3246 val &= ~AEU_INPUTS_ATTN_BITS_SPIO5;
3247 REG_WR(bp, reg_offset, val);
3249 BNX2X_ERR("SPIO5 hw attention\n");
3251 /* Fan failure attention */
3252 bnx2x_hw_reset_phy(&bp->link_params);
3253 bnx2x_fan_failure(bp);
3256 if ((attn & bp->link_vars.aeu_int_mask) && bp->port.pmf) {
3257 bnx2x_acquire_phy_lock(bp);
3258 bnx2x_handle_module_detect_int(&bp->link_params);
3259 bnx2x_release_phy_lock(bp);
3262 if (attn & HW_INTERRUT_ASSERT_SET_0) {
3264 val = REG_RD(bp, reg_offset);
3265 val &= ~(attn & HW_INTERRUT_ASSERT_SET_0);
3266 REG_WR(bp, reg_offset, val);
3268 BNX2X_ERR("FATAL HW block attention set0 0x%x\n",
3269 (u32)(attn & HW_INTERRUT_ASSERT_SET_0));
3274 static inline void bnx2x_attn_int_deasserted1(struct bnx2x *bp, u32 attn)
3278 if (attn & AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT) {
3280 val = REG_RD(bp, DORQ_REG_DORQ_INT_STS_CLR);
3281 BNX2X_ERR("DB hw attention 0x%x\n", val);
3282 /* DORQ discard attention */
3284 BNX2X_ERR("FATAL error from DORQ\n");
3287 if (attn & HW_INTERRUT_ASSERT_SET_1) {
3289 int port = BP_PORT(bp);
3292 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 :
3293 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1);
3295 val = REG_RD(bp, reg_offset);
3296 val &= ~(attn & HW_INTERRUT_ASSERT_SET_1);
3297 REG_WR(bp, reg_offset, val);
3299 BNX2X_ERR("FATAL HW block attention set1 0x%x\n",
3300 (u32)(attn & HW_INTERRUT_ASSERT_SET_1));
3305 static inline void bnx2x_attn_int_deasserted2(struct bnx2x *bp, u32 attn)
3309 if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) {
3311 val = REG_RD(bp, CFC_REG_CFC_INT_STS_CLR);
3312 BNX2X_ERR("CFC hw attention 0x%x\n", val);
3313 /* CFC error attention */
3315 BNX2X_ERR("FATAL error from CFC\n");
3318 if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) {
3319 val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_0);
3320 BNX2X_ERR("PXP hw attention-0 0x%x\n", val);
3321 /* RQ_USDMDP_FIFO_OVERFLOW */
3323 BNX2X_ERR("FATAL error from PXP\n");
3325 if (!CHIP_IS_E1x(bp)) {
3326 val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_1);
3327 BNX2X_ERR("PXP hw attention-1 0x%x\n", val);
3331 if (attn & HW_INTERRUT_ASSERT_SET_2) {
3333 int port = BP_PORT(bp);
3336 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 :
3337 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2);
3339 val = REG_RD(bp, reg_offset);
3340 val &= ~(attn & HW_INTERRUT_ASSERT_SET_2);
3341 REG_WR(bp, reg_offset, val);
3343 BNX2X_ERR("FATAL HW block attention set2 0x%x\n",
3344 (u32)(attn & HW_INTERRUT_ASSERT_SET_2));
3349 static inline void bnx2x_attn_int_deasserted3(struct bnx2x *bp, u32 attn)
3353 if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) {
3355 if (attn & BNX2X_PMF_LINK_ASSERT) {
3356 int func = BP_FUNC(bp);
3358 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
3359 bp->mf_config[BP_VN(bp)] = MF_CFG_RD(bp,
3360 func_mf_config[BP_ABS_FUNC(bp)].config);
3362 func_mb[BP_FW_MB_IDX(bp)].drv_status);
3363 if (val & DRV_STATUS_DCC_EVENT_MASK)
3365 (val & DRV_STATUS_DCC_EVENT_MASK));
3367 if (val & DRV_STATUS_SET_MF_BW)
3368 bnx2x_set_mf_bw(bp);
3370 if ((bp->port.pmf == 0) && (val & DRV_STATUS_PMF))
3371 bnx2x_pmf_update(bp);
3374 (val & DRV_STATUS_DCBX_NEGOTIATION_RESULTS) &&
3375 bp->dcbx_enabled > 0)
3376 /* start dcbx state machine */
3377 bnx2x_dcbx_set_params(bp,
3378 BNX2X_DCBX_STATE_NEG_RECEIVED);
3379 if (bp->link_vars.periodic_flags &
3380 PERIODIC_FLAGS_LINK_EVENT) {
3381 /* sync with link */
3382 bnx2x_acquire_phy_lock(bp);
3383 bp->link_vars.periodic_flags &=
3384 ~PERIODIC_FLAGS_LINK_EVENT;
3385 bnx2x_release_phy_lock(bp);
3387 bnx2x_link_sync_notify(bp);
3388 bnx2x_link_report(bp);
3390 /* Always call it here: bnx2x_link_report() will
3391 * prevent the link indication duplication.
3393 bnx2x__link_status_update(bp);
3394 } else if (attn & BNX2X_MC_ASSERT_BITS) {
3396 BNX2X_ERR("MC assert!\n");
3397 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_10, 0);
3398 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_9, 0);
3399 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_8, 0);
3400 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_7, 0);
3403 } else if (attn & BNX2X_MCP_ASSERT) {
3405 BNX2X_ERR("MCP assert!\n");
3406 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_11, 0);
3410 BNX2X_ERR("Unknown HW assert! (attn 0x%x)\n", attn);
3413 if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) {
3414 BNX2X_ERR("LATCHED attention 0x%08x (masked)\n", attn);
3415 if (attn & BNX2X_GRC_TIMEOUT) {
3416 val = CHIP_IS_E1(bp) ? 0 :
3417 REG_RD(bp, MISC_REG_GRC_TIMEOUT_ATTN);
3418 BNX2X_ERR("GRC time-out 0x%08x\n", val);
3420 if (attn & BNX2X_GRC_RSV) {
3421 val = CHIP_IS_E1(bp) ? 0 :
3422 REG_RD(bp, MISC_REG_GRC_RSV_ATTN);
3423 BNX2X_ERR("GRC reserved 0x%08x\n", val);
3425 REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff);
3431 * 0-7 - Engine0 load counter.
3432 * 8-15 - Engine1 load counter.
3433 * 16 - Engine0 RESET_IN_PROGRESS bit.
3434 * 17 - Engine1 RESET_IN_PROGRESS bit.
3435 * 18 - Engine0 ONE_IS_LOADED. Set when there is at least one active function
3437 * 19 - Engine1 ONE_IS_LOADED.
3438 * 20 - Chip reset flow bit. When set none-leader must wait for both engines
3439 * leader to complete (check for both RESET_IN_PROGRESS bits and not for
3440 * just the one belonging to its engine).
3443 #define BNX2X_RECOVERY_GLOB_REG MISC_REG_GENERIC_POR_1
3445 #define BNX2X_PATH0_LOAD_CNT_MASK 0x000000ff
3446 #define BNX2X_PATH0_LOAD_CNT_SHIFT 0
3447 #define BNX2X_PATH1_LOAD_CNT_MASK 0x0000ff00
3448 #define BNX2X_PATH1_LOAD_CNT_SHIFT 8
3449 #define BNX2X_PATH0_RST_IN_PROG_BIT 0x00010000
3450 #define BNX2X_PATH1_RST_IN_PROG_BIT 0x00020000
3451 #define BNX2X_GLOBAL_RESET_BIT 0x00040000
3454 * Set the GLOBAL_RESET bit.
3456 * Should be run under rtnl lock
3458 void bnx2x_set_reset_global(struct bnx2x *bp)
3460 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3462 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val | BNX2X_GLOBAL_RESET_BIT);
3468 * Clear the GLOBAL_RESET bit.
3470 * Should be run under rtnl lock
3472 static inline void bnx2x_clear_reset_global(struct bnx2x *bp)
3474 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3476 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~BNX2X_GLOBAL_RESET_BIT));
3482 * Checks the GLOBAL_RESET bit.
3484 * should be run under rtnl lock
3486 static inline bool bnx2x_reset_is_global(struct bnx2x *bp)
3488 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3490 DP(NETIF_MSG_HW, "GEN_REG_VAL=0x%08x\n", val);
3491 return (val & BNX2X_GLOBAL_RESET_BIT) ? true : false;
3495 * Clear RESET_IN_PROGRESS bit for the current engine.
3497 * Should be run under rtnl lock
3499 static inline void bnx2x_set_reset_done(struct bnx2x *bp)
3501 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3502 u32 bit = BP_PATH(bp) ?
3503 BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
3507 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
3513 * Set RESET_IN_PROGRESS for the current engine.
3515 * should be run under rtnl lock
3517 void bnx2x_set_reset_in_progress(struct bnx2x *bp)
3519 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3520 u32 bit = BP_PATH(bp) ?
3521 BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
3525 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
3531 * Checks the RESET_IN_PROGRESS bit for the given engine.
3532 * should be run under rtnl lock
3534 bool bnx2x_reset_is_done(struct bnx2x *bp, int engine)
3536 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3538 BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
3540 /* return false if bit is set */
3541 return (val & bit) ? false : true;
3545 * Increment the load counter for the current engine.
3547 * should be run under rtnl lock
3549 void bnx2x_inc_load_cnt(struct bnx2x *bp)
3551 u32 val1, val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3552 u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
3553 BNX2X_PATH0_LOAD_CNT_MASK;
3554 u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
3555 BNX2X_PATH0_LOAD_CNT_SHIFT;
3557 DP(NETIF_MSG_HW, "Old GEN_REG_VAL=0x%08x\n", val);
3559 /* get the current counter value */
3560 val1 = (val & mask) >> shift;
3565 /* clear the old value */
3568 /* set the new one */
3569 val |= ((val1 << shift) & mask);
3571 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
3577 * bnx2x_dec_load_cnt - decrement the load counter
3579 * @bp: driver handle
3581 * Should be run under rtnl lock.
3582 * Decrements the load counter for the current engine. Returns
3583 * the new counter value.
3585 u32 bnx2x_dec_load_cnt(struct bnx2x *bp)
3587 u32 val1, val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3588 u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
3589 BNX2X_PATH0_LOAD_CNT_MASK;
3590 u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
3591 BNX2X_PATH0_LOAD_CNT_SHIFT;
3593 DP(NETIF_MSG_HW, "Old GEN_REG_VAL=0x%08x\n", val);
3595 /* get the current counter value */
3596 val1 = (val & mask) >> shift;
3601 /* clear the old value */
3604 /* set the new one */
3605 val |= ((val1 << shift) & mask);
3607 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
3615 * Read the load counter for the current engine.
3617 * should be run under rtnl lock
3619 static inline u32 bnx2x_get_load_cnt(struct bnx2x *bp, int engine)
3621 u32 mask = (engine ? BNX2X_PATH1_LOAD_CNT_MASK :
3622 BNX2X_PATH0_LOAD_CNT_MASK);
3623 u32 shift = (engine ? BNX2X_PATH1_LOAD_CNT_SHIFT :
3624 BNX2X_PATH0_LOAD_CNT_SHIFT);
3625 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3627 DP(NETIF_MSG_HW, "GLOB_REG=0x%08x\n", val);
3629 val = (val & mask) >> shift;
3631 DP(NETIF_MSG_HW, "load_cnt for engine %d = %d\n", engine, val);
3637 * Reset the load counter for the current engine.
3639 * should be run under rtnl lock
3641 static inline void bnx2x_clear_load_cnt(struct bnx2x *bp)
3643 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3644 u32 mask = (BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
3645 BNX2X_PATH0_LOAD_CNT_MASK);
3647 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~mask));
3650 static inline void _print_next_block(int idx, const char *blk)
3657 static inline int bnx2x_check_blocks_with_parity0(u32 sig, int par_num,
3662 for (i = 0; sig; i++) {
3663 cur_bit = ((u32)0x1 << i);
3664 if (sig & cur_bit) {
3666 case AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR:
3668 _print_next_block(par_num++, "BRB");
3670 case AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR:
3672 _print_next_block(par_num++, "PARSER");
3674 case AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR:
3676 _print_next_block(par_num++, "TSDM");
3678 case AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR:
3680 _print_next_block(par_num++,
3683 case AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR:
3685 _print_next_block(par_num++, "TCM");
3687 case AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR:
3689 _print_next_block(par_num++, "TSEMI");
3691 case AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR:
3693 _print_next_block(par_num++, "XPB");
3705 static inline int bnx2x_check_blocks_with_parity1(u32 sig, int par_num,
3706 bool *global, bool print)
3710 for (i = 0; sig; i++) {
3711 cur_bit = ((u32)0x1 << i);
3712 if (sig & cur_bit) {
3714 case AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR:
3716 _print_next_block(par_num++, "PBF");
3718 case AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR:
3720 _print_next_block(par_num++, "QM");
3722 case AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR:
3724 _print_next_block(par_num++, "TM");
3726 case AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR:
3728 _print_next_block(par_num++, "XSDM");
3730 case AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR:
3732 _print_next_block(par_num++, "XCM");
3734 case AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR:
3736 _print_next_block(par_num++, "XSEMI");
3738 case AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR:
3740 _print_next_block(par_num++,
3743 case AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR:
3745 _print_next_block(par_num++, "NIG");
3747 case AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR:
3749 _print_next_block(par_num++,
3753 case AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR:
3755 _print_next_block(par_num++, "DEBUG");
3757 case AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR:
3759 _print_next_block(par_num++, "USDM");
3761 case AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR:
3763 _print_next_block(par_num++, "USEMI");
3765 case AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR:
3767 _print_next_block(par_num++, "UPB");
3769 case AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR:
3771 _print_next_block(par_num++, "CSDM");
3783 static inline int bnx2x_check_blocks_with_parity2(u32 sig, int par_num,
3788 for (i = 0; sig; i++) {
3789 cur_bit = ((u32)0x1 << i);
3790 if (sig & cur_bit) {
3792 case AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR:
3794 _print_next_block(par_num++, "CSEMI");
3796 case AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR:
3798 _print_next_block(par_num++, "PXP");
3800 case AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR:
3802 _print_next_block(par_num++,
3803 "PXPPCICLOCKCLIENT");
3805 case AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR:
3807 _print_next_block(par_num++, "CFC");
3809 case AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR:
3811 _print_next_block(par_num++, "CDU");
3813 case AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR:
3815 _print_next_block(par_num++, "DMAE");
3817 case AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR:
3819 _print_next_block(par_num++, "IGU");
3821 case AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR:
3823 _print_next_block(par_num++, "MISC");
3835 static inline int bnx2x_check_blocks_with_parity3(u32 sig, int par_num,
3836 bool *global, bool print)
3840 for (i = 0; sig; i++) {
3841 cur_bit = ((u32)0x1 << i);
3842 if (sig & cur_bit) {
3844 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY:
3846 _print_next_block(par_num++, "MCP ROM");
3849 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY:
3851 _print_next_block(par_num++,
3855 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY:
3857 _print_next_block(par_num++,
3861 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY:
3863 _print_next_block(par_num++,
3877 static inline bool bnx2x_parity_attn(struct bnx2x *bp, bool *global, bool print,
3878 u32 sig0, u32 sig1, u32 sig2, u32 sig3)
3880 if ((sig0 & HW_PRTY_ASSERT_SET_0) || (sig1 & HW_PRTY_ASSERT_SET_1) ||
3881 (sig2 & HW_PRTY_ASSERT_SET_2) || (sig3 & HW_PRTY_ASSERT_SET_3)) {
3883 DP(NETIF_MSG_HW, "Was parity error: HW block parity attention: "
3884 "[0]:0x%08x [1]:0x%08x "
3885 "[2]:0x%08x [3]:0x%08x\n",
3886 sig0 & HW_PRTY_ASSERT_SET_0,
3887 sig1 & HW_PRTY_ASSERT_SET_1,
3888 sig2 & HW_PRTY_ASSERT_SET_2,
3889 sig3 & HW_PRTY_ASSERT_SET_3);
3892 "Parity errors detected in blocks: ");
3893 par_num = bnx2x_check_blocks_with_parity0(
3894 sig0 & HW_PRTY_ASSERT_SET_0, par_num, print);
3895 par_num = bnx2x_check_blocks_with_parity1(
3896 sig1 & HW_PRTY_ASSERT_SET_1, par_num, global, print);
3897 par_num = bnx2x_check_blocks_with_parity2(
3898 sig2 & HW_PRTY_ASSERT_SET_2, par_num, print);
3899 par_num = bnx2x_check_blocks_with_parity3(
3900 sig3 & HW_PRTY_ASSERT_SET_3, par_num, global, print);
3909 * bnx2x_chk_parity_attn - checks for parity attentions.
3911 * @bp: driver handle
3912 * @global: true if there was a global attention
3913 * @print: show parity attention in syslog
3915 bool bnx2x_chk_parity_attn(struct bnx2x *bp, bool *global, bool print)
3917 struct attn_route attn;
3918 int port = BP_PORT(bp);
3920 attn.sig[0] = REG_RD(bp,
3921 MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 +
3923 attn.sig[1] = REG_RD(bp,
3924 MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 +
3926 attn.sig[2] = REG_RD(bp,
3927 MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 +
3929 attn.sig[3] = REG_RD(bp,
3930 MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 +
3933 return bnx2x_parity_attn(bp, global, print, attn.sig[0], attn.sig[1],
3934 attn.sig[2], attn.sig[3]);
3938 static inline void bnx2x_attn_int_deasserted4(struct bnx2x *bp, u32 attn)
3941 if (attn & AEU_INPUTS_ATTN_BITS_PGLUE_HW_INTERRUPT) {
3943 val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS_CLR);
3944 BNX2X_ERR("PGLUE hw attention 0x%x\n", val);
3945 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR)
3946 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_"
3948 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR)
3949 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_"
3950 "INCORRECT_RCV_BEHAVIOR\n");
3951 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN)
3952 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_"
3953 "WAS_ERROR_ATTN\n");
3954 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN)
3955 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_"
3956 "VF_LENGTH_VIOLATION_ATTN\n");
3958 PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN)
3959 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_"
3960 "VF_GRC_SPACE_VIOLATION_ATTN\n");
3962 PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN)
3963 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_"
3964 "VF_MSIX_BAR_VIOLATION_ATTN\n");
3965 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN)
3966 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_"
3967 "TCPL_ERROR_ATTN\n");
3968 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN)
3969 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_"
3970 "TCPL_IN_TWO_RCBS_ATTN\n");
3971 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW)
3972 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_"
3973 "CSSNOOP_FIFO_OVERFLOW\n");
3975 if (attn & AEU_INPUTS_ATTN_BITS_ATC_HW_INTERRUPT) {
3976 val = REG_RD(bp, ATC_REG_ATC_INT_STS_CLR);
3977 BNX2X_ERR("ATC hw attention 0x%x\n", val);
3978 if (val & ATC_ATC_INT_STS_REG_ADDRESS_ERROR)
3979 BNX2X_ERR("ATC_ATC_INT_STS_REG_ADDRESS_ERROR\n");
3980 if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND)
3981 BNX2X_ERR("ATC_ATC_INT_STS_REG"
3982 "_ATC_TCPL_TO_NOT_PEND\n");
3983 if (val & ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS)
3984 BNX2X_ERR("ATC_ATC_INT_STS_REG_"
3985 "ATC_GPA_MULTIPLE_HITS\n");
3986 if (val & ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT)
3987 BNX2X_ERR("ATC_ATC_INT_STS_REG_"
3988 "ATC_RCPL_TO_EMPTY_CNT\n");
3989 if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR)
3990 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR\n");
3991 if (val & ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU)
3992 BNX2X_ERR("ATC_ATC_INT_STS_REG_"
3993 "ATC_IREQ_LESS_THAN_STU\n");
3996 if (attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
3997 AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)) {
3998 BNX2X_ERR("FATAL parity attention set4 0x%x\n",
3999 (u32)(attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
4000 AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)));
4005 static void bnx2x_attn_int_deasserted(struct bnx2x *bp, u32 deasserted)
4007 struct attn_route attn, *group_mask;
4008 int port = BP_PORT(bp);
4013 bool global = false;
4015 /* need to take HW lock because MCP or other port might also
4016 try to handle this event */
4017 bnx2x_acquire_alr(bp);
4019 if (bnx2x_chk_parity_attn(bp, &global, true)) {
4020 #ifndef BNX2X_STOP_ON_ERROR
4021 bp->recovery_state = BNX2X_RECOVERY_INIT;
4022 schedule_delayed_work(&bp->reset_task, 0);
4023 /* Disable HW interrupts */
4024 bnx2x_int_disable(bp);
4025 /* In case of parity errors don't handle attentions so that
4026 * other function would "see" parity errors.
4031 bnx2x_release_alr(bp);
4035 attn.sig[0] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4);
4036 attn.sig[1] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4);
4037 attn.sig[2] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4);
4038 attn.sig[3] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4);
4039 if (!CHIP_IS_E1x(bp))
4041 REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + port*4);
4045 DP(NETIF_MSG_HW, "attn: %08x %08x %08x %08x %08x\n",
4046 attn.sig[0], attn.sig[1], attn.sig[2], attn.sig[3], attn.sig[4]);
4048 for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
4049 if (deasserted & (1 << index)) {
4050 group_mask = &bp->attn_group[index];
4052 DP(NETIF_MSG_HW, "group[%d]: %08x %08x "
4055 group_mask->sig[0], group_mask->sig[1],
4056 group_mask->sig[2], group_mask->sig[3],
4057 group_mask->sig[4]);
4059 bnx2x_attn_int_deasserted4(bp,
4060 attn.sig[4] & group_mask->sig[4]);
4061 bnx2x_attn_int_deasserted3(bp,
4062 attn.sig[3] & group_mask->sig[3]);
4063 bnx2x_attn_int_deasserted1(bp,
4064 attn.sig[1] & group_mask->sig[1]);
4065 bnx2x_attn_int_deasserted2(bp,
4066 attn.sig[2] & group_mask->sig[2]);
4067 bnx2x_attn_int_deasserted0(bp,
4068 attn.sig[0] & group_mask->sig[0]);
4072 bnx2x_release_alr(bp);
4074 if (bp->common.int_block == INT_BLOCK_HC)
4075 reg_addr = (HC_REG_COMMAND_REG + port*32 +
4076 COMMAND_REG_ATTN_BITS_CLR);
4078 reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_CLR_UPPER*8);
4081 DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", val,
4082 (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
4083 REG_WR(bp, reg_addr, val);
4085 if (~bp->attn_state & deasserted)
4086 BNX2X_ERR("IGU ERROR\n");
4088 reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
4089 MISC_REG_AEU_MASK_ATTN_FUNC_0;
4091 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
4092 aeu_mask = REG_RD(bp, reg_addr);
4094 DP(NETIF_MSG_HW, "aeu_mask %x newly deasserted %x\n",
4095 aeu_mask, deasserted);
4096 aeu_mask |= (deasserted & 0x3ff);
4097 DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
4099 REG_WR(bp, reg_addr, aeu_mask);
4100 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
4102 DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
4103 bp->attn_state &= ~deasserted;
4104 DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
4107 static void bnx2x_attn_int(struct bnx2x *bp)
4109 /* read local copy of bits */
4110 u32 attn_bits = le32_to_cpu(bp->def_status_blk->atten_status_block.
4112 u32 attn_ack = le32_to_cpu(bp->def_status_blk->atten_status_block.
4114 u32 attn_state = bp->attn_state;
4116 /* look for changed bits */
4117 u32 asserted = attn_bits & ~attn_ack & ~attn_state;
4118 u32 deasserted = ~attn_bits & attn_ack & attn_state;
4121 "attn_bits %x attn_ack %x asserted %x deasserted %x\n",
4122 attn_bits, attn_ack, asserted, deasserted);
4124 if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state))
4125 BNX2X_ERR("BAD attention state\n");
4127 /* handle bits that were raised */
4129 bnx2x_attn_int_asserted(bp, asserted);
4132 bnx2x_attn_int_deasserted(bp, deasserted);
4135 void bnx2x_igu_ack_sb(struct bnx2x *bp, u8 igu_sb_id, u8 segment,
4136 u16 index, u8 op, u8 update)
4138 u32 igu_addr = BAR_IGU_INTMEM + (IGU_CMD_INT_ACK_BASE + igu_sb_id)*8;
4140 bnx2x_igu_ack_sb_gen(bp, igu_sb_id, segment, index, op, update,
4144 static inline void bnx2x_update_eq_prod(struct bnx2x *bp, u16 prod)
4146 /* No memory barriers */
4147 storm_memset_eq_prod(bp, prod, BP_FUNC(bp));
4148 mmiowb(); /* keep prod updates ordered */
4152 static int bnx2x_cnic_handle_cfc_del(struct bnx2x *bp, u32 cid,
4153 union event_ring_elem *elem)
4155 u8 err = elem->message.error;
4157 if (!bp->cnic_eth_dev.starting_cid ||
4158 (cid < bp->cnic_eth_dev.starting_cid &&
4159 cid != bp->cnic_eth_dev.iscsi_l2_cid))
4162 DP(BNX2X_MSG_SP, "got delete ramrod for CNIC CID %d\n", cid);
4164 if (unlikely(err)) {
4166 BNX2X_ERR("got delete ramrod for CNIC CID %d with error!\n",
4168 bnx2x_panic_dump(bp);
4170 bnx2x_cnic_cfc_comp(bp, cid, err);
4175 static inline void bnx2x_handle_mcast_eqe(struct bnx2x *bp)
4177 struct bnx2x_mcast_ramrod_params rparam;
4180 memset(&rparam, 0, sizeof(rparam));
4182 rparam.mcast_obj = &bp->mcast_obj;
4184 netif_addr_lock_bh(bp->dev);
4186 /* Clear pending state for the last command */
4187 bp->mcast_obj.raw.clear_pending(&bp->mcast_obj.raw);
4189 /* If there are pending mcast commands - send them */
4190 if (bp->mcast_obj.check_pending(&bp->mcast_obj)) {
4191 rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_CONT);
4193 BNX2X_ERR("Failed to send pending mcast commands: %d\n",
4197 netif_addr_unlock_bh(bp->dev);
4200 static inline void bnx2x_handle_classification_eqe(struct bnx2x *bp,
4201 union event_ring_elem *elem)
4203 unsigned long ramrod_flags = 0;
4205 u32 cid = elem->message.data.eth_event.echo & BNX2X_SWCID_MASK;
4206 struct bnx2x_vlan_mac_obj *vlan_mac_obj;
4208 /* Always push next commands out, don't wait here */
4209 __set_bit(RAMROD_CONT, &ramrod_flags);
4211 switch (elem->message.data.eth_event.echo >> BNX2X_SWCID_SHIFT) {
4212 case BNX2X_FILTER_MAC_PENDING:
4214 if (cid == BNX2X_ISCSI_ETH_CID)
4215 vlan_mac_obj = &bp->iscsi_l2_mac_obj;
4218 vlan_mac_obj = &bp->fp[cid].mac_obj;
4221 vlan_mac_obj = &bp->fp[cid].mac_obj;
4223 case BNX2X_FILTER_MCAST_PENDING:
4224 /* This is only relevant for 57710 where multicast MACs are
4225 * configured as unicast MACs using the same ramrod.
4227 bnx2x_handle_mcast_eqe(bp);
4230 BNX2X_ERR("Unsupported classification command: %d\n",
4231 elem->message.data.eth_event.echo);
4235 rc = vlan_mac_obj->complete(bp, vlan_mac_obj, elem, &ramrod_flags);
4238 BNX2X_ERR("Failed to schedule new commands: %d\n", rc);
4240 DP(BNX2X_MSG_SP, "Scheduled next pending commands...\n");
4245 static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start);
4248 static inline void bnx2x_handle_rx_mode_eqe(struct bnx2x *bp)
4250 netif_addr_lock_bh(bp->dev);
4252 clear_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
4254 /* Send rx_mode command again if was requested */
4255 if (test_and_clear_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state))
4256 bnx2x_set_storm_rx_mode(bp);
4258 else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED,
4260 bnx2x_set_iscsi_eth_rx_mode(bp, true);
4261 else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED,
4263 bnx2x_set_iscsi_eth_rx_mode(bp, false);
4266 netif_addr_unlock_bh(bp->dev);
4269 static inline struct bnx2x_queue_sp_obj *bnx2x_cid_to_q_obj(
4270 struct bnx2x *bp, u32 cid)
4273 if (cid == BNX2X_FCOE_ETH_CID)
4274 return &bnx2x_fcoe(bp, q_obj);
4277 return &bnx2x_fp(bp, cid, q_obj);
4280 static void bnx2x_eq_int(struct bnx2x *bp)
4282 u16 hw_cons, sw_cons, sw_prod;
4283 union event_ring_elem *elem;
4287 struct bnx2x_queue_sp_obj *q_obj;
4288 struct bnx2x_func_sp_obj *f_obj = &bp->func_obj;
4289 struct bnx2x_raw_obj *rss_raw = &bp->rss_conf_obj.raw;
4291 hw_cons = le16_to_cpu(*bp->eq_cons_sb);
4293 /* The hw_cos range is 1-255, 257 - the sw_cons range is 0-254, 256.
4294 * when we get the the next-page we nned to adjust so the loop
4295 * condition below will be met. The next element is the size of a
4296 * regular element and hence incrementing by 1
4298 if ((hw_cons & EQ_DESC_MAX_PAGE) == EQ_DESC_MAX_PAGE)
4301 /* This function may never run in parallel with itself for a
4302 * specific bp, thus there is no need in "paired" read memory
4305 sw_cons = bp->eq_cons;
4306 sw_prod = bp->eq_prod;
4308 DP(BNX2X_MSG_SP, "EQ: hw_cons %u sw_cons %u bp->cq_spq_left %u\n",
4309 hw_cons, sw_cons, atomic_read(&bp->eq_spq_left));
4311 for (; sw_cons != hw_cons;
4312 sw_prod = NEXT_EQ_IDX(sw_prod), sw_cons = NEXT_EQ_IDX(sw_cons)) {
4315 elem = &bp->eq_ring[EQ_DESC(sw_cons)];
4317 cid = SW_CID(elem->message.data.cfc_del_event.cid);
4318 opcode = elem->message.opcode;
4321 /* handle eq element */
4323 case EVENT_RING_OPCODE_STAT_QUERY:
4324 DP(NETIF_MSG_TIMER, "got statistics comp event %d\n",
4326 /* nothing to do with stats comp */
4329 case EVENT_RING_OPCODE_CFC_DEL:
4330 /* handle according to cid range */
4332 * we may want to verify here that the bp state is
4335 DP(NETIF_MSG_IFDOWN,
4336 "got delete ramrod for MULTI[%d]\n", cid);
4338 if (!bnx2x_cnic_handle_cfc_del(bp, cid, elem))
4341 q_obj = bnx2x_cid_to_q_obj(bp, cid);
4343 if (q_obj->complete_cmd(bp, q_obj, BNX2X_Q_CMD_CFC_DEL))
4350 case EVENT_RING_OPCODE_STOP_TRAFFIC:
4351 DP(NETIF_MSG_IFUP, "got STOP TRAFFIC\n");
4352 bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_PAUSED);
4355 case EVENT_RING_OPCODE_START_TRAFFIC:
4356 DP(NETIF_MSG_IFUP, "got START TRAFFIC\n");
4357 bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_RELEASED);
4359 case EVENT_RING_OPCODE_FUNCTION_START:
4360 DP(NETIF_MSG_IFUP, "got FUNC_START ramrod\n");
4361 if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_START))
4366 case EVENT_RING_OPCODE_FUNCTION_STOP:
4367 DP(NETIF_MSG_IFDOWN, "got FUNC_STOP ramrod\n");
4368 if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_STOP))
4374 switch (opcode | bp->state) {
4375 case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
4377 case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
4378 BNX2X_STATE_OPENING_WAIT4_PORT):
4379 cid = elem->message.data.eth_event.echo &
4381 DP(NETIF_MSG_IFUP, "got RSS_UPDATE ramrod. CID %d\n",
4383 rss_raw->clear_pending(rss_raw);
4386 case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_OPEN):
4387 case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_DIAG):
4388 case (EVENT_RING_OPCODE_SET_MAC |
4389 BNX2X_STATE_CLOSING_WAIT4_HALT):
4390 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
4392 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
4394 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
4395 BNX2X_STATE_CLOSING_WAIT4_HALT):
4396 DP(NETIF_MSG_IFUP, "got (un)set mac ramrod\n");
4397 bnx2x_handle_classification_eqe(bp, elem);
4400 case (EVENT_RING_OPCODE_MULTICAST_RULES |
4402 case (EVENT_RING_OPCODE_MULTICAST_RULES |
4404 case (EVENT_RING_OPCODE_MULTICAST_RULES |
4405 BNX2X_STATE_CLOSING_WAIT4_HALT):
4406 DP(NETIF_MSG_IFUP, "got mcast ramrod\n");
4407 bnx2x_handle_mcast_eqe(bp);
4410 case (EVENT_RING_OPCODE_FILTERS_RULES |
4412 case (EVENT_RING_OPCODE_FILTERS_RULES |
4414 case (EVENT_RING_OPCODE_FILTERS_RULES |
4415 BNX2X_STATE_CLOSING_WAIT4_HALT):
4416 DP(NETIF_MSG_IFUP, "got rx_mode ramrod\n");
4417 bnx2x_handle_rx_mode_eqe(bp);
4420 /* unknown event log error and continue */
4421 BNX2X_ERR("Unknown EQ event %d, bp->state 0x%x\n",
4422 elem->message.opcode, bp->state);
4428 smp_mb__before_atomic_inc();
4429 atomic_add(spqe_cnt, &bp->eq_spq_left);
4431 bp->eq_cons = sw_cons;
4432 bp->eq_prod = sw_prod;
4433 /* Make sure that above mem writes were issued towards the memory */
4436 /* update producer */
4437 bnx2x_update_eq_prod(bp, bp->eq_prod);
4440 static void bnx2x_sp_task(struct work_struct *work)
4442 struct bnx2x *bp = container_of(work, struct bnx2x, sp_task.work);
4445 status = bnx2x_update_dsb_idx(bp);
4446 /* if (status == 0) */
4447 /* BNX2X_ERR("spurious slowpath interrupt!\n"); */
4449 DP(NETIF_MSG_INTR, "got a slowpath interrupt (status 0x%x)\n", status);
4452 if (status & BNX2X_DEF_SB_ATT_IDX) {
4454 status &= ~BNX2X_DEF_SB_ATT_IDX;
4457 /* SP events: STAT_QUERY and others */
4458 if (status & BNX2X_DEF_SB_IDX) {
4460 struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);
4462 if ((!NO_FCOE(bp)) &&
4463 (bnx2x_has_rx_work(fp) || bnx2x_has_tx_work(fp)))
4464 napi_schedule(&bnx2x_fcoe(bp, napi));
4466 /* Handle EQ completions */
4469 bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID,
4470 le16_to_cpu(bp->def_idx), IGU_INT_NOP, 1);
4472 status &= ~BNX2X_DEF_SB_IDX;
4475 if (unlikely(status))
4476 DP(NETIF_MSG_INTR, "got an unknown interrupt! (status 0x%x)\n",
4479 bnx2x_ack_sb(bp, bp->igu_dsb_id, ATTENTION_ID,
4480 le16_to_cpu(bp->def_att_idx), IGU_INT_ENABLE, 1);
4483 irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance)
4485 struct net_device *dev = dev_instance;
4486 struct bnx2x *bp = netdev_priv(dev);
4488 bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0,
4489 IGU_INT_DISABLE, 0);
4491 #ifdef BNX2X_STOP_ON_ERROR
4492 if (unlikely(bp->panic))
4498 struct cnic_ops *c_ops;
4501 c_ops = rcu_dereference(bp->cnic_ops);
4503 c_ops->cnic_handler(bp->cnic_data, NULL);
4507 queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
4512 /* end of slow path */
4515 void bnx2x_drv_pulse(struct bnx2x *bp)
4517 SHMEM_WR(bp, func_mb[BP_FW_MB_IDX(bp)].drv_pulse_mb,
4518 bp->fw_drv_pulse_wr_seq);
4522 static void bnx2x_timer(unsigned long data)
4524 struct bnx2x *bp = (struct bnx2x *) data;
4526 if (!netif_running(bp->dev))
4530 struct bnx2x_fastpath *fp = &bp->fp[0];
4533 bnx2x_rx_int(fp, 1000);
4536 if (!BP_NOMCP(bp)) {
4537 int mb_idx = BP_FW_MB_IDX(bp);
4541 ++bp->fw_drv_pulse_wr_seq;
4542 bp->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK;
4543 /* TBD - add SYSTEM_TIME */
4544 drv_pulse = bp->fw_drv_pulse_wr_seq;
4545 bnx2x_drv_pulse(bp);
4547 mcp_pulse = (SHMEM_RD(bp, func_mb[mb_idx].mcp_pulse_mb) &
4548 MCP_PULSE_SEQ_MASK);
4549 /* The delta between driver pulse and mcp response
4550 * should be 1 (before mcp response) or 0 (after mcp response)
4552 if ((drv_pulse != mcp_pulse) &&
4553 (drv_pulse != ((mcp_pulse + 1) & MCP_PULSE_SEQ_MASK))) {
4554 /* someone lost a heartbeat... */
4555 BNX2X_ERR("drv_pulse (0x%x) != mcp_pulse (0x%x)\n",
4556 drv_pulse, mcp_pulse);
4560 if (bp->state == BNX2X_STATE_OPEN)
4561 bnx2x_stats_handle(bp, STATS_EVENT_UPDATE);
4563 mod_timer(&bp->timer, jiffies + bp->current_interval);
4566 /* end of Statistics */
4571 * nic init service functions
4574 static inline void bnx2x_fill(struct bnx2x *bp, u32 addr, int fill, u32 len)
4577 if (!(len%4) && !(addr%4))
4578 for (i = 0; i < len; i += 4)
4579 REG_WR(bp, addr + i, fill);
4581 for (i = 0; i < len; i++)
4582 REG_WR8(bp, addr + i, fill);
4586 /* helper: writes FP SP data to FW - data_size in dwords */
4587 static inline void bnx2x_wr_fp_sb_data(struct bnx2x *bp,
4593 for (index = 0; index < data_size; index++)
4594 REG_WR(bp, BAR_CSTRORM_INTMEM +
4595 CSTORM_STATUS_BLOCK_DATA_OFFSET(fw_sb_id) +
4597 *(sb_data_p + index));
4600 static inline void bnx2x_zero_fp_sb(struct bnx2x *bp, int fw_sb_id)
4604 struct hc_status_block_data_e2 sb_data_e2;
4605 struct hc_status_block_data_e1x sb_data_e1x;
4607 /* disable the function first */
4608 if (!CHIP_IS_E1x(bp)) {
4609 memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
4610 sb_data_e2.common.state = SB_DISABLED;
4611 sb_data_e2.common.p_func.vf_valid = false;
4612 sb_data_p = (u32 *)&sb_data_e2;
4613 data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
4615 memset(&sb_data_e1x, 0,
4616 sizeof(struct hc_status_block_data_e1x));
4617 sb_data_e1x.common.state = SB_DISABLED;
4618 sb_data_e1x.common.p_func.vf_valid = false;
4619 sb_data_p = (u32 *)&sb_data_e1x;
4620 data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
4622 bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
4624 bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
4625 CSTORM_STATUS_BLOCK_OFFSET(fw_sb_id), 0,
4626 CSTORM_STATUS_BLOCK_SIZE);
4627 bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
4628 CSTORM_SYNC_BLOCK_OFFSET(fw_sb_id), 0,
4629 CSTORM_SYNC_BLOCK_SIZE);
4632 /* helper: writes SP SB data to FW */
4633 static inline void bnx2x_wr_sp_sb_data(struct bnx2x *bp,
4634 struct hc_sp_status_block_data *sp_sb_data)
4636 int func = BP_FUNC(bp);
4638 for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
4639 REG_WR(bp, BAR_CSTRORM_INTMEM +
4640 CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
4642 *((u32 *)sp_sb_data + i));
4645 static inline void bnx2x_zero_sp_sb(struct bnx2x *bp)
4647 int func = BP_FUNC(bp);
4648 struct hc_sp_status_block_data sp_sb_data;
4649 memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
4651 sp_sb_data.state = SB_DISABLED;
4652 sp_sb_data.p_func.vf_valid = false;
4654 bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
4656 bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
4657 CSTORM_SP_STATUS_BLOCK_OFFSET(func), 0,
4658 CSTORM_SP_STATUS_BLOCK_SIZE);
4659 bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
4660 CSTORM_SP_SYNC_BLOCK_OFFSET(func), 0,
4661 CSTORM_SP_SYNC_BLOCK_SIZE);
4667 void bnx2x_setup_ndsb_state_machine(struct hc_status_block_sm *hc_sm,
4668 int igu_sb_id, int igu_seg_id)
4670 hc_sm->igu_sb_id = igu_sb_id;
4671 hc_sm->igu_seg_id = igu_seg_id;
4672 hc_sm->timer_value = 0xFF;
4673 hc_sm->time_to_expire = 0xFFFFFFFF;
4676 static void bnx2x_init_sb(struct bnx2x *bp, dma_addr_t mapping, int vfid,
4677 u8 vf_valid, int fw_sb_id, int igu_sb_id)
4681 struct hc_status_block_data_e2 sb_data_e2;
4682 struct hc_status_block_data_e1x sb_data_e1x;
4683 struct hc_status_block_sm *hc_sm_p;
4687 if (CHIP_INT_MODE_IS_BC(bp))
4688 igu_seg_id = HC_SEG_ACCESS_NORM;
4690 igu_seg_id = IGU_SEG_ACCESS_NORM;
4692 bnx2x_zero_fp_sb(bp, fw_sb_id);
4694 if (!CHIP_IS_E1x(bp)) {
4695 memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
4696 sb_data_e2.common.state = SB_ENABLED;
4697 sb_data_e2.common.p_func.pf_id = BP_FUNC(bp);
4698 sb_data_e2.common.p_func.vf_id = vfid;
4699 sb_data_e2.common.p_func.vf_valid = vf_valid;
4700 sb_data_e2.common.p_func.vnic_id = BP_VN(bp);
4701 sb_data_e2.common.same_igu_sb_1b = true;
4702 sb_data_e2.common.host_sb_addr.hi = U64_HI(mapping);
4703 sb_data_e2.common.host_sb_addr.lo = U64_LO(mapping);
4704 hc_sm_p = sb_data_e2.common.state_machine;
4705 sb_data_p = (u32 *)&sb_data_e2;
4706 data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
4708 memset(&sb_data_e1x, 0,
4709 sizeof(struct hc_status_block_data_e1x));
4710 sb_data_e1x.common.state = SB_ENABLED;
4711 sb_data_e1x.common.p_func.pf_id = BP_FUNC(bp);
4712 sb_data_e1x.common.p_func.vf_id = 0xff;
4713 sb_data_e1x.common.p_func.vf_valid = false;
4714 sb_data_e1x.common.p_func.vnic_id = BP_VN(bp);
4715 sb_data_e1x.common.same_igu_sb_1b = true;
4716 sb_data_e1x.common.host_sb_addr.hi = U64_HI(mapping);
4717 sb_data_e1x.common.host_sb_addr.lo = U64_LO(mapping);
4718 hc_sm_p = sb_data_e1x.common.state_machine;
4719 sb_data_p = (u32 *)&sb_data_e1x;
4720 data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
4723 bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_RX_ID],
4724 igu_sb_id, igu_seg_id);
4725 bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_TX_ID],
4726 igu_sb_id, igu_seg_id);
4728 DP(NETIF_MSG_HW, "Init FW SB %d\n", fw_sb_id);
4730 /* write indecies to HW */
4731 bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
4734 static void bnx2x_update_coalesce_sb(struct bnx2x *bp, u8 fw_sb_id,
4735 u16 tx_usec, u16 rx_usec)
4737 bnx2x_update_coalesce_sb_index(bp, fw_sb_id, U_SB_ETH_RX_CQ_INDEX,
4739 bnx2x_update_coalesce_sb_index(bp, fw_sb_id, C_SB_ETH_TX_CQ_INDEX,
4743 static void bnx2x_init_def_sb(struct bnx2x *bp)
4745 struct host_sp_status_block *def_sb = bp->def_status_blk;
4746 dma_addr_t mapping = bp->def_status_blk_mapping;
4747 int igu_sp_sb_index;
4749 int port = BP_PORT(bp);
4750 int func = BP_FUNC(bp);
4754 struct hc_sp_status_block_data sp_sb_data;
4755 memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
4757 if (CHIP_INT_MODE_IS_BC(bp)) {
4758 igu_sp_sb_index = DEF_SB_IGU_ID;
4759 igu_seg_id = HC_SEG_ACCESS_DEF;
4761 igu_sp_sb_index = bp->igu_dsb_id;
4762 igu_seg_id = IGU_SEG_ACCESS_DEF;
4766 section = ((u64)mapping) + offsetof(struct host_sp_status_block,
4767 atten_status_block);
4768 def_sb->atten_status_block.status_block_id = igu_sp_sb_index;
4772 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
4773 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
4774 for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
4776 /* take care of sig[0]..sig[4] */
4777 for (sindex = 0; sindex < 4; sindex++)
4778 bp->attn_group[index].sig[sindex] =
4779 REG_RD(bp, reg_offset + sindex*0x4 + 0x10*index);
4781 if (!CHIP_IS_E1x(bp))
4783 * enable5 is separate from the rest of the registers,
4784 * and therefore the address skip is 4
4785 * and not 16 between the different groups
4787 bp->attn_group[index].sig[4] = REG_RD(bp,
4788 reg_offset + 0x10 + 0x4*index);
4790 bp->attn_group[index].sig[4] = 0;
4793 if (bp->common.int_block == INT_BLOCK_HC) {
4794 reg_offset = (port ? HC_REG_ATTN_MSG1_ADDR_L :
4795 HC_REG_ATTN_MSG0_ADDR_L);
4797 REG_WR(bp, reg_offset, U64_LO(section));
4798 REG_WR(bp, reg_offset + 4, U64_HI(section));
4799 } else if (!CHIP_IS_E1x(bp)) {
4800 REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_L, U64_LO(section));
4801 REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_H, U64_HI(section));
4804 section = ((u64)mapping) + offsetof(struct host_sp_status_block,
4807 bnx2x_zero_sp_sb(bp);
4809 sp_sb_data.state = SB_ENABLED;
4810 sp_sb_data.host_sb_addr.lo = U64_LO(section);
4811 sp_sb_data.host_sb_addr.hi = U64_HI(section);
4812 sp_sb_data.igu_sb_id = igu_sp_sb_index;
4813 sp_sb_data.igu_seg_id = igu_seg_id;
4814 sp_sb_data.p_func.pf_id = func;
4815 sp_sb_data.p_func.vnic_id = BP_VN(bp);
4816 sp_sb_data.p_func.vf_id = 0xff;
4818 bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
4820 bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0, IGU_INT_ENABLE, 0);
4823 void bnx2x_update_coalesce(struct bnx2x *bp)
4827 for_each_eth_queue(bp, i)
4828 bnx2x_update_coalesce_sb(bp, bp->fp[i].fw_sb_id,
4829 bp->tx_ticks, bp->rx_ticks);
4832 static void bnx2x_init_sp_ring(struct bnx2x *bp)
4834 spin_lock_init(&bp->spq_lock);
4835 atomic_set(&bp->cq_spq_left, MAX_SPQ_PENDING);
4837 bp->spq_prod_idx = 0;
4838 bp->dsb_sp_prod = BNX2X_SP_DSB_INDEX;
4839 bp->spq_prod_bd = bp->spq;
4840 bp->spq_last_bd = bp->spq_prod_bd + MAX_SP_DESC_CNT;
4843 static void bnx2x_init_eq_ring(struct bnx2x *bp)
4846 for (i = 1; i <= NUM_EQ_PAGES; i++) {
4847 union event_ring_elem *elem =
4848 &bp->eq_ring[EQ_DESC_CNT_PAGE * i - 1];
4850 elem->next_page.addr.hi =
4851 cpu_to_le32(U64_HI(bp->eq_mapping +
4852 BCM_PAGE_SIZE * (i % NUM_EQ_PAGES)));
4853 elem->next_page.addr.lo =
4854 cpu_to_le32(U64_LO(bp->eq_mapping +
4855 BCM_PAGE_SIZE*(i % NUM_EQ_PAGES)));
4858 bp->eq_prod = NUM_EQ_DESC;
4859 bp->eq_cons_sb = BNX2X_EQ_INDEX;
4860 /* we want a warning message before it gets rought... */
4861 atomic_set(&bp->eq_spq_left,
4862 min_t(int, MAX_SP_DESC_CNT - MAX_SPQ_PENDING, NUM_EQ_DESC) - 1);
4866 /* called with netif_addr_lock_bh() */
4867 void bnx2x_set_q_rx_mode(struct bnx2x *bp, u8 cl_id,
4868 unsigned long rx_mode_flags,
4869 unsigned long rx_accept_flags,
4870 unsigned long tx_accept_flags,
4871 unsigned long ramrod_flags)
4873 struct bnx2x_rx_mode_ramrod_params ramrod_param;
4876 memset(&ramrod_param, 0, sizeof(ramrod_param));
4878 /* Prepare ramrod parameters */
4879 ramrod_param.cid = 0;
4880 ramrod_param.cl_id = cl_id;
4881 ramrod_param.rx_mode_obj = &bp->rx_mode_obj;
4882 ramrod_param.func_id = BP_FUNC(bp);
4884 ramrod_param.pstate = &bp->sp_state;
4885 ramrod_param.state = BNX2X_FILTER_RX_MODE_PENDING;
4887 ramrod_param.rdata = bnx2x_sp(bp, rx_mode_rdata);
4888 ramrod_param.rdata_mapping = bnx2x_sp_mapping(bp, rx_mode_rdata);
4890 set_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
4892 ramrod_param.ramrod_flags = ramrod_flags;
4893 ramrod_param.rx_mode_flags = rx_mode_flags;
4895 ramrod_param.rx_accept_flags = rx_accept_flags;
4896 ramrod_param.tx_accept_flags = tx_accept_flags;
4898 rc = bnx2x_config_rx_mode(bp, &ramrod_param);
4900 BNX2X_ERR("Set rx_mode %d failed\n", bp->rx_mode);
4905 /* called with netif_addr_lock_bh() */
4906 void bnx2x_set_storm_rx_mode(struct bnx2x *bp)
4908 unsigned long rx_mode_flags = 0, ramrod_flags = 0;
4909 unsigned long rx_accept_flags = 0, tx_accept_flags = 0;
4914 /* Configure rx_mode of FCoE Queue */
4915 __set_bit(BNX2X_RX_MODE_FCOE_ETH, &rx_mode_flags);
4918 switch (bp->rx_mode) {
4919 case BNX2X_RX_MODE_NONE:
4921 * 'drop all' supersedes any accept flags that may have been
4922 * passed to the function.
4925 case BNX2X_RX_MODE_NORMAL:
4926 __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
4927 __set_bit(BNX2X_ACCEPT_MULTICAST, &rx_accept_flags);
4928 __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
4930 /* internal switching mode */
4931 __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
4932 __set_bit(BNX2X_ACCEPT_MULTICAST, &tx_accept_flags);
4933 __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
4936 case BNX2X_RX_MODE_ALLMULTI:
4937 __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
4938 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &rx_accept_flags);
4939 __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
4941 /* internal switching mode */
4942 __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
4943 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &tx_accept_flags);
4944 __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
4947 case BNX2X_RX_MODE_PROMISC:
4948 /* According to deffinition of SI mode, iface in promisc mode
4949 * should receive matched and unmatched (in resolution of port)
4952 __set_bit(BNX2X_ACCEPT_UNMATCHED, &rx_accept_flags);
4953 __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
4954 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &rx_accept_flags);
4955 __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
4957 /* internal switching mode */
4958 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &tx_accept_flags);
4959 __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
4962 __set_bit(BNX2X_ACCEPT_ALL_UNICAST, &tx_accept_flags);
4964 __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
4968 BNX2X_ERR("Unknown rx_mode: %d\n", bp->rx_mode);
4972 if (bp->rx_mode != BNX2X_RX_MODE_NONE) {
4973 __set_bit(BNX2X_ACCEPT_ANY_VLAN, &rx_accept_flags);
4974 __set_bit(BNX2X_ACCEPT_ANY_VLAN, &tx_accept_flags);
4977 __set_bit(RAMROD_RX, &ramrod_flags);
4978 __set_bit(RAMROD_TX, &ramrod_flags);
4980 bnx2x_set_q_rx_mode(bp, bp->fp->cl_id, rx_mode_flags, rx_accept_flags,
4981 tx_accept_flags, ramrod_flags);
4984 static void bnx2x_init_internal_common(struct bnx2x *bp)
4990 * In switch independent mode, the TSTORM needs to accept
4991 * packets that failed classification, since approximate match
4992 * mac addresses aren't written to NIG LLH
4994 REG_WR8(bp, BAR_TSTRORM_INTMEM +
4995 TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 2);
4996 else if (!CHIP_IS_E1(bp)) /* 57710 doesn't support MF */
4997 REG_WR8(bp, BAR_TSTRORM_INTMEM +
4998 TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 0);
5000 /* Zero this manually as its initialization is
5001 currently missing in the initTool */
5002 for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++)
5003 REG_WR(bp, BAR_USTRORM_INTMEM +
5004 USTORM_AGG_DATA_OFFSET + i * 4, 0);
5005 if (!CHIP_IS_E1x(bp)) {
5006 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_IGU_MODE_OFFSET,
5007 CHIP_INT_MODE_IS_BC(bp) ?
5008 HC_IGU_BC_MODE : HC_IGU_NBC_MODE);
5012 static void bnx2x_init_internal(struct bnx2x *bp, u32 load_code)
5014 switch (load_code) {
5015 case FW_MSG_CODE_DRV_LOAD_COMMON:
5016 case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP:
5017 bnx2x_init_internal_common(bp);
5020 case FW_MSG_CODE_DRV_LOAD_PORT:
5024 case FW_MSG_CODE_DRV_LOAD_FUNCTION:
5025 /* internal memory per function is
5026 initialized inside bnx2x_pf_init */
5030 BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code);
5035 static inline u8 bnx2x_fp_igu_sb_id(struct bnx2x_fastpath *fp)
5037 return fp->bp->igu_base_sb + fp->index + CNIC_CONTEXT_USE;
5040 static inline u8 bnx2x_fp_fw_sb_id(struct bnx2x_fastpath *fp)
5042 return fp->bp->base_fw_ndsb + fp->index + CNIC_CONTEXT_USE;
5045 static inline u8 bnx2x_fp_cl_id(struct bnx2x_fastpath *fp)
5047 if (CHIP_IS_E1x(fp->bp))
5048 return BP_L_ID(fp->bp) + fp->index;
5049 else /* We want Client ID to be the same as IGU SB ID for 57712 */
5050 return bnx2x_fp_igu_sb_id(fp);
5053 static void bnx2x_init_fp(struct bnx2x *bp, int fp_idx)
5055 struct bnx2x_fastpath *fp = &bp->fp[fp_idx];
5056 unsigned long q_type = 0;
5059 fp->cl_id = bnx2x_fp_cl_id(fp);
5060 fp->fw_sb_id = bnx2x_fp_fw_sb_id(fp);
5061 fp->igu_sb_id = bnx2x_fp_igu_sb_id(fp);
5062 /* qZone id equals to FW (per path) client id */
5063 fp->cl_qzone_id = bnx2x_fp_qzone_id(fp);
5066 fp->ustorm_rx_prods_offset = bnx2x_rx_ustorm_prods_offset(fp);
5067 /* Setup SB indicies */
5068 fp->rx_cons_sb = BNX2X_RX_SB_INDEX;
5069 fp->tx_cons_sb = BNX2X_TX_SB_INDEX;
5071 /* Configure Queue State object */
5072 __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
5073 __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
5074 bnx2x_init_queue_obj(bp, &fp->q_obj, fp->cl_id, fp->cid, BP_FUNC(bp),
5075 bnx2x_sp(bp, q_rdata), bnx2x_sp_mapping(bp, q_rdata),
5079 * Configure classification DBs: Always enable Tx switching
5081 bnx2x_init_vlan_mac_fp_objs(fp, BNX2X_OBJ_TYPE_RX_TX);
5083 DP(NETIF_MSG_IFUP, "queue[%d]: bnx2x_init_sb(%p,%p) "
5084 "cl_id %d fw_sb %d igu_sb %d\n",
5085 fp_idx, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id,
5087 bnx2x_init_sb(bp, fp->status_blk_mapping, BNX2X_VF_ID_INVALID, false,
5088 fp->fw_sb_id, fp->igu_sb_id);
5090 bnx2x_update_fpsb_idx(fp);
5093 void bnx2x_nic_init(struct bnx2x *bp, u32 load_code)
5097 for_each_eth_queue(bp, i)
5098 bnx2x_init_fp(bp, i);
5101 bnx2x_init_fcoe_fp(bp);
5103 bnx2x_init_sb(bp, bp->cnic_sb_mapping,
5104 BNX2X_VF_ID_INVALID, false,
5105 bnx2x_cnic_fw_sb_id(bp), bnx2x_cnic_igu_sb_id(bp));
5109 /* Initialize MOD_ABS interrupts */
5110 bnx2x_init_mod_abs_int(bp, &bp->link_vars, bp->common.chip_id,
5111 bp->common.shmem_base, bp->common.shmem2_base,
5113 /* ensure status block indices were read */
5116 bnx2x_init_def_sb(bp);
5117 bnx2x_update_dsb_idx(bp);
5118 bnx2x_init_rx_rings(bp);
5119 bnx2x_init_tx_rings(bp);
5120 bnx2x_init_sp_ring(bp);
5121 bnx2x_init_eq_ring(bp);
5122 bnx2x_init_internal(bp, load_code);
5124 bnx2x_stats_init(bp);
5126 /* flush all before enabling interrupts */
5130 bnx2x_int_enable(bp);
5132 /* Check for SPIO5 */
5133 bnx2x_attn_int_deasserted0(bp,
5134 REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + BP_PORT(bp)*4) &
5135 AEU_INPUTS_ATTN_BITS_SPIO5);
5138 /* end of nic init */
5141 * gzip service functions
5144 static int bnx2x_gunzip_init(struct bnx2x *bp)
5146 bp->gunzip_buf = dma_alloc_coherent(&bp->pdev->dev, FW_BUF_SIZE,
5147 &bp->gunzip_mapping, GFP_KERNEL);
5148 if (bp->gunzip_buf == NULL)
5151 bp->strm = kmalloc(sizeof(*bp->strm), GFP_KERNEL);
5152 if (bp->strm == NULL)
5155 bp->strm->workspace = kmalloc(zlib_inflate_workspacesize(),
5157 if (bp->strm->workspace == NULL)
5167 dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
5168 bp->gunzip_mapping);
5169 bp->gunzip_buf = NULL;
5172 netdev_err(bp->dev, "Cannot allocate firmware buffer for"
5173 " un-compression\n");
5177 static void bnx2x_gunzip_end(struct bnx2x *bp)
5180 kfree(bp->strm->workspace);
5185 if (bp->gunzip_buf) {
5186 dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
5187 bp->gunzip_mapping);
5188 bp->gunzip_buf = NULL;
5192 static int bnx2x_gunzip(struct bnx2x *bp, const u8 *zbuf, int len)
5196 /* check gzip header */
5197 if ((zbuf[0] != 0x1f) || (zbuf[1] != 0x8b) || (zbuf[2] != Z_DEFLATED)) {
5198 BNX2X_ERR("Bad gzip header\n");
5206 if (zbuf[3] & FNAME)
5207 while ((zbuf[n++] != 0) && (n < len));
5209 bp->strm->next_in = (typeof(bp->strm->next_in))zbuf + n;
5210 bp->strm->avail_in = len - n;
5211 bp->strm->next_out = bp->gunzip_buf;
5212 bp->strm->avail_out = FW_BUF_SIZE;
5214 rc = zlib_inflateInit2(bp->strm, -MAX_WBITS);
5218 rc = zlib_inflate(bp->strm, Z_FINISH);
5219 if ((rc != Z_OK) && (rc != Z_STREAM_END))
5220 netdev_err(bp->dev, "Firmware decompression error: %s\n",
5223 bp->gunzip_outlen = (FW_BUF_SIZE - bp->strm->avail_out);
5224 if (bp->gunzip_outlen & 0x3)
5225 netdev_err(bp->dev, "Firmware decompression error:"
5226 " gunzip_outlen (%d) not aligned\n",
5228 bp->gunzip_outlen >>= 2;
5230 zlib_inflateEnd(bp->strm);
5232 if (rc == Z_STREAM_END)
5238 /* nic load/unload */
5241 * General service functions
5244 /* send a NIG loopback debug packet */
5245 static void bnx2x_lb_pckt(struct bnx2x *bp)
5249 /* Ethernet source and destination addresses */
5250 wb_write[0] = 0x55555555;
5251 wb_write[1] = 0x55555555;
5252 wb_write[2] = 0x20; /* SOP */
5253 REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
5255 /* NON-IP protocol */
5256 wb_write[0] = 0x09000000;
5257 wb_write[1] = 0x55555555;
5258 wb_write[2] = 0x10; /* EOP, eop_bvalid = 0 */
5259 REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
5262 /* some of the internal memories
5263 * are not directly readable from the driver
5264 * to test them we send debug packets
5266 static int bnx2x_int_mem_test(struct bnx2x *bp)
5272 if (CHIP_REV_IS_FPGA(bp))
5274 else if (CHIP_REV_IS_EMUL(bp))
5279 /* Disable inputs of parser neighbor blocks */
5280 REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
5281 REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
5282 REG_WR(bp, CFC_REG_DEBUG0, 0x1);
5283 REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
5285 /* Write 0 to parser credits for CFC search request */
5286 REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
5288 /* send Ethernet packet */
5291 /* TODO do i reset NIG statistic? */
5292 /* Wait until NIG register shows 1 packet of size 0x10 */
5293 count = 1000 * factor;
5296 bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
5297 val = *bnx2x_sp(bp, wb_data[0]);
5305 BNX2X_ERR("NIG timeout val = 0x%x\n", val);
5309 /* Wait until PRS register shows 1 packet */
5310 count = 1000 * factor;
5312 val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
5320 BNX2X_ERR("PRS timeout val = 0x%x\n", val);
5324 /* Reset and init BRB, PRS */
5325 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
5327 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
5329 bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
5330 bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
5332 DP(NETIF_MSG_HW, "part2\n");
5334 /* Disable inputs of parser neighbor blocks */
5335 REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
5336 REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
5337 REG_WR(bp, CFC_REG_DEBUG0, 0x1);
5338 REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
5340 /* Write 0 to parser credits for CFC search request */
5341 REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
5343 /* send 10 Ethernet packets */
5344 for (i = 0; i < 10; i++)
5347 /* Wait until NIG register shows 10 + 1
5348 packets of size 11*0x10 = 0xb0 */
5349 count = 1000 * factor;
5352 bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
5353 val = *bnx2x_sp(bp, wb_data[0]);
5361 BNX2X_ERR("NIG timeout val = 0x%x\n", val);
5365 /* Wait until PRS register shows 2 packets */
5366 val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
5368 BNX2X_ERR("PRS timeout val = 0x%x\n", val);
5370 /* Write 1 to parser credits for CFC search request */
5371 REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x1);
5373 /* Wait until PRS register shows 3 packets */
5374 msleep(10 * factor);
5375 /* Wait until NIG register shows 1 packet of size 0x10 */
5376 val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
5378 BNX2X_ERR("PRS timeout val = 0x%x\n", val);
5380 /* clear NIG EOP FIFO */
5381 for (i = 0; i < 11; i++)
5382 REG_RD(bp, NIG_REG_INGRESS_EOP_LB_FIFO);
5383 val = REG_RD(bp, NIG_REG_INGRESS_EOP_LB_EMPTY);
5385 BNX2X_ERR("clear of NIG failed\n");
5389 /* Reset and init BRB, PRS, NIG */
5390 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
5392 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
5394 bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
5395 bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
5398 REG_WR(bp, PRS_REG_NIC_MODE, 1);
5401 /* Enable inputs of parser neighbor blocks */
5402 REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x7fffffff);
5403 REG_WR(bp, TCM_REG_PRS_IFEN, 0x1);
5404 REG_WR(bp, CFC_REG_DEBUG0, 0x0);
5405 REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x1);
5407 DP(NETIF_MSG_HW, "done\n");
5412 static void bnx2x_enable_blocks_attention(struct bnx2x *bp)
5414 REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
5415 if (!CHIP_IS_E1x(bp))
5416 REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0x40);
5418 REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0);
5419 REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
5420 REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
5422 * mask read length error interrupts in brb for parser
5423 * (parsing unit and 'checksum and crc' unit)
5424 * these errors are legal (PU reads fixed length and CAC can cause
5425 * read length error on truncated packets)
5427 REG_WR(bp, BRB1_REG_BRB1_INT_MASK, 0xFC00);
5428 REG_WR(bp, QM_REG_QM_INT_MASK, 0);
5429 REG_WR(bp, TM_REG_TM_INT_MASK, 0);
5430 REG_WR(bp, XSDM_REG_XSDM_INT_MASK_0, 0);
5431 REG_WR(bp, XSDM_REG_XSDM_INT_MASK_1, 0);
5432 REG_WR(bp, XCM_REG_XCM_INT_MASK, 0);
5433 /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_0, 0); */
5434 /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_1, 0); */
5435 REG_WR(bp, USDM_REG_USDM_INT_MASK_0, 0);
5436 REG_WR(bp, USDM_REG_USDM_INT_MASK_1, 0);
5437 REG_WR(bp, UCM_REG_UCM_INT_MASK, 0);
5438 /* REG_WR(bp, USEM_REG_USEM_INT_MASK_0, 0); */
5439 /* REG_WR(bp, USEM_REG_USEM_INT_MASK_1, 0); */
5440 REG_WR(bp, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0);
5441 REG_WR(bp, CSDM_REG_CSDM_INT_MASK_0, 0);
5442 REG_WR(bp, CSDM_REG_CSDM_INT_MASK_1, 0);
5443 REG_WR(bp, CCM_REG_CCM_INT_MASK, 0);
5444 /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_0, 0); */
5445 /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_1, 0); */
5447 if (CHIP_REV_IS_FPGA(bp))
5448 REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, 0x580000);
5449 else if (!CHIP_IS_E1x(bp))
5450 REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0,
5451 (PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_OF
5452 | PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_AFT
5453 | PXP2_PXP2_INT_MASK_0_REG_PGL_PCIE_ATTN
5454 | PXP2_PXP2_INT_MASK_0_REG_PGL_READ_BLOCKED
5455 | PXP2_PXP2_INT_MASK_0_REG_PGL_WRITE_BLOCKED));
5457 REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, 0x480000);
5458 REG_WR(bp, TSDM_REG_TSDM_INT_MASK_0, 0);
5459 REG_WR(bp, TSDM_REG_TSDM_INT_MASK_1, 0);
5460 REG_WR(bp, TCM_REG_TCM_INT_MASK, 0);
5461 /* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_0, 0); */
5463 if (!CHIP_IS_E1x(bp))
5464 /* enable VFC attentions: bits 11 and 12, bits 31:13 reserved */
5465 REG_WR(bp, TSEM_REG_TSEM_INT_MASK_1, 0x07ff);
5467 REG_WR(bp, CDU_REG_CDU_INT_MASK, 0);
5468 REG_WR(bp, DMAE_REG_DMAE_INT_MASK, 0);
5469 /* REG_WR(bp, MISC_REG_MISC_INT_MASK, 0); */
5470 REG_WR(bp, PBF_REG_PBF_INT_MASK, 0x18); /* bit 3,4 masked */
5473 static void bnx2x_reset_common(struct bnx2x *bp)
5478 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
5481 if (CHIP_IS_E3(bp)) {
5482 val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
5483 val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
5486 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, val);
5489 static void bnx2x_setup_dmae(struct bnx2x *bp)
5492 spin_lock_init(&bp->dmae_lock);
5495 static void bnx2x_init_pxp(struct bnx2x *bp)
5498 int r_order, w_order;
5500 pci_read_config_word(bp->pdev,
5501 bp->pcie_cap + PCI_EXP_DEVCTL, &devctl);
5502 DP(NETIF_MSG_HW, "read 0x%x from devctl\n", devctl);
5503 w_order = ((devctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5);
5505 r_order = ((devctl & PCI_EXP_DEVCTL_READRQ) >> 12);
5507 DP(NETIF_MSG_HW, "force read order to %d\n", bp->mrrs);
5511 bnx2x_init_pxp_arb(bp, r_order, w_order);
5514 static void bnx2x_setup_fan_failure_detection(struct bnx2x *bp)
5524 val = SHMEM_RD(bp, dev_info.shared_hw_config.config2) &
5525 SHARED_HW_CFG_FAN_FAILURE_MASK;
5527 if (val == SHARED_HW_CFG_FAN_FAILURE_ENABLED)
5531 * The fan failure mechanism is usually related to the PHY type since
5532 * the power consumption of the board is affected by the PHY. Currently,
5533 * fan is required for most designs with SFX7101, BCM8727 and BCM8481.
5535 else if (val == SHARED_HW_CFG_FAN_FAILURE_PHY_TYPE)
5536 for (port = PORT_0; port < PORT_MAX; port++) {
5538 bnx2x_fan_failure_det_req(
5540 bp->common.shmem_base,
5541 bp->common.shmem2_base,
5545 DP(NETIF_MSG_HW, "fan detection setting: %d\n", is_required);
5547 if (is_required == 0)
5550 /* Fan failure is indicated by SPIO 5 */
5551 bnx2x_set_spio(bp, MISC_REGISTERS_SPIO_5,
5552 MISC_REGISTERS_SPIO_INPUT_HI_Z);
5554 /* set to active low mode */
5555 val = REG_RD(bp, MISC_REG_SPIO_INT);
5556 val |= ((1 << MISC_REGISTERS_SPIO_5) <<
5557 MISC_REGISTERS_SPIO_INT_OLD_SET_POS);
5558 REG_WR(bp, MISC_REG_SPIO_INT, val);
5560 /* enable interrupt to signal the IGU */
5561 val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
5562 val |= (1 << MISC_REGISTERS_SPIO_5);
5563 REG_WR(bp, MISC_REG_SPIO_EVENT_EN, val);
5566 static void bnx2x_pretend_func(struct bnx2x *bp, u8 pretend_func_num)
5572 if (CHIP_IS_E1H(bp) && (pretend_func_num >= E1H_FUNC_MAX))
5575 switch (BP_ABS_FUNC(bp)) {
5577 offset = PXP2_REG_PGL_PRETEND_FUNC_F0;
5580 offset = PXP2_REG_PGL_PRETEND_FUNC_F1;
5583 offset = PXP2_REG_PGL_PRETEND_FUNC_F2;
5586 offset = PXP2_REG_PGL_PRETEND_FUNC_F3;
5589 offset = PXP2_REG_PGL_PRETEND_FUNC_F4;
5592 offset = PXP2_REG_PGL_PRETEND_FUNC_F5;
5595 offset = PXP2_REG_PGL_PRETEND_FUNC_F6;
5598 offset = PXP2_REG_PGL_PRETEND_FUNC_F7;
5604 REG_WR(bp, offset, pretend_func_num);
5606 DP(NETIF_MSG_HW, "Pretending to func %d\n", pretend_func_num);
5609 void bnx2x_pf_disable(struct bnx2x *bp)
5611 u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
5612 val &= ~IGU_PF_CONF_FUNC_EN;
5614 REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
5615 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
5616 REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 0);
5619 static inline void bnx2x__common_init_phy(struct bnx2x *bp)
5621 u32 shmem_base[2], shmem2_base[2];
5622 shmem_base[0] = bp->common.shmem_base;
5623 shmem2_base[0] = bp->common.shmem2_base;
5624 if (!CHIP_IS_E1x(bp)) {
5626 SHMEM2_RD(bp, other_shmem_base_addr);
5628 SHMEM2_RD(bp, other_shmem2_base_addr);
5630 bnx2x_acquire_phy_lock(bp);
5631 bnx2x_common_init_phy(bp, shmem_base, shmem2_base,
5632 bp->common.chip_id);
5633 bnx2x_release_phy_lock(bp);
5637 * bnx2x_init_hw_common - initialize the HW at the COMMON phase.
5639 * @bp: driver handle
5641 static int bnx2x_init_hw_common(struct bnx2x *bp)
5645 DP(BNX2X_MSG_MCP, "starting common init func %d\n", BP_ABS_FUNC(bp));
5647 bnx2x_reset_common(bp);
5648 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0xffffffff);
5651 if (CHIP_IS_E3(bp)) {
5652 val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
5653 val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
5655 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, val);
5657 bnx2x_init_block(bp, BLOCK_MISC, PHASE_COMMON);
5659 if (!CHIP_IS_E1x(bp)) {
5663 * 4-port mode or 2-port mode we need to turn of master-enable
5664 * for everyone, after that, turn it back on for self.
5665 * so, we disregard multi-function or not, and always disable
5666 * for all functions on the given path, this means 0,2,4,6 for
5667 * path 0 and 1,3,5,7 for path 1
5669 for (abs_func_id = BP_PATH(bp);
5670 abs_func_id < E2_FUNC_MAX*2; abs_func_id += 2) {
5671 if (abs_func_id == BP_ABS_FUNC(bp)) {
5673 PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER,
5678 bnx2x_pretend_func(bp, abs_func_id);
5679 /* clear pf enable */
5680 bnx2x_pf_disable(bp);
5681 bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
5685 bnx2x_init_block(bp, BLOCK_PXP, PHASE_COMMON);
5686 if (CHIP_IS_E1(bp)) {
5687 /* enable HW interrupt from PXP on USDM overflow
5688 bit 16 on INT_MASK_0 */
5689 REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
5692 bnx2x_init_block(bp, BLOCK_PXP2, PHASE_COMMON);
5696 REG_WR(bp, PXP2_REG_RQ_QM_ENDIAN_M, 1);
5697 REG_WR(bp, PXP2_REG_RQ_TM_ENDIAN_M, 1);
5698 REG_WR(bp, PXP2_REG_RQ_SRC_ENDIAN_M, 1);
5699 REG_WR(bp, PXP2_REG_RQ_CDU_ENDIAN_M, 1);
5700 REG_WR(bp, PXP2_REG_RQ_DBG_ENDIAN_M, 1);
5701 /* make sure this value is 0 */
5702 REG_WR(bp, PXP2_REG_RQ_HC_ENDIAN_M, 0);
5704 /* REG_WR(bp, PXP2_REG_RD_PBF_SWAP_MODE, 1); */
5705 REG_WR(bp, PXP2_REG_RD_QM_SWAP_MODE, 1);
5706 REG_WR(bp, PXP2_REG_RD_TM_SWAP_MODE, 1);
5707 REG_WR(bp, PXP2_REG_RD_SRC_SWAP_MODE, 1);
5708 REG_WR(bp, PXP2_REG_RD_CDURD_SWAP_MODE, 1);
5711 bnx2x_ilt_init_page_size(bp, INITOP_SET);
5713 if (CHIP_REV_IS_FPGA(bp) && CHIP_IS_E1H(bp))
5714 REG_WR(bp, PXP2_REG_PGL_TAGS_LIMIT, 0x1);
5716 /* let the HW do it's magic ... */
5718 /* finish PXP init */
5719 val = REG_RD(bp, PXP2_REG_RQ_CFG_DONE);
5721 BNX2X_ERR("PXP2 CFG failed\n");
5724 val = REG_RD(bp, PXP2_REG_RD_INIT_DONE);
5726 BNX2X_ERR("PXP2 RD_INIT failed\n");
5730 /* Timers bug workaround E2 only. We need to set the entire ILT to
5731 * have entries with value "0" and valid bit on.
5732 * This needs to be done by the first PF that is loaded in a path
5733 * (i.e. common phase)
5735 if (!CHIP_IS_E1x(bp)) {
5736 /* In E2 there is a bug in the timers block that can cause function 6 / 7
5737 * (i.e. vnic3) to start even if it is marked as "scan-off".
5738 * This occurs when a different function (func2,3) is being marked
5739 * as "scan-off". Real-life scenario for example: if a driver is being
5740 * load-unloaded while func6,7 are down. This will cause the timer to access
5741 * the ilt, translate to a logical address and send a request to read/write.
5742 * Since the ilt for the function that is down is not valid, this will cause
5743 * a translation error which is unrecoverable.
5744 * The Workaround is intended to make sure that when this happens nothing fatal
5745 * will occur. The workaround:
5746 * 1. First PF driver which loads on a path will:
5747 * a. After taking the chip out of reset, by using pretend,
5748 * it will write "0" to the following registers of
5750 * REG_WR(pdev, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
5751 * REG_WR(pdev, CFC_REG_WEAK_ENABLE_PF,0);
5752 * REG_WR(pdev, CFC_REG_STRONG_ENABLE_PF,0);
5753 * And for itself it will write '1' to
5754 * PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER to enable
5755 * dmae-operations (writing to pram for example.)
5756 * note: can be done for only function 6,7 but cleaner this
5758 * b. Write zero+valid to the entire ILT.
5759 * c. Init the first_timers_ilt_entry, last_timers_ilt_entry of
5760 * VNIC3 (of that port). The range allocated will be the
5761 * entire ILT. This is needed to prevent ILT range error.
5762 * 2. Any PF driver load flow:
5763 * a. ILT update with the physical addresses of the allocated
5765 * b. Wait 20msec. - note that this timeout is needed to make
5766 * sure there are no requests in one of the PXP internal
5767 * queues with "old" ILT addresses.
5768 * c. PF enable in the PGLC.
5769 * d. Clear the was_error of the PF in the PGLC. (could have
5770 * occured while driver was down)
5771 * e. PF enable in the CFC (WEAK + STRONG)
5772 * f. Timers scan enable
5773 * 3. PF driver unload flow:
5774 * a. Clear the Timers scan_en.
5775 * b. Polling for scan_on=0 for that PF.
5776 * c. Clear the PF enable bit in the PXP.
5777 * d. Clear the PF enable in the CFC (WEAK + STRONG)
5778 * e. Write zero+valid to all ILT entries (The valid bit must
5780 * f. If this is VNIC 3 of a port then also init
5781 * first_timers_ilt_entry to zero and last_timers_ilt_entry
5782 * to the last enrty in the ILT.
5785 * Currently the PF error in the PGLC is non recoverable.
5786 * In the future the there will be a recovery routine for this error.
5787 * Currently attention is masked.
5788 * Having an MCP lock on the load/unload process does not guarantee that
5789 * there is no Timer disable during Func6/7 enable. This is because the
5790 * Timers scan is currently being cleared by the MCP on FLR.
5791 * Step 2.d can be done only for PF6/7 and the driver can also check if
5792 * there is error before clearing it. But the flow above is simpler and
5794 * All ILT entries are written by zero+valid and not just PF6/7
5795 * ILT entries since in the future the ILT entries allocation for
5796 * PF-s might be dynamic.
5798 struct ilt_client_info ilt_cli;
5799 struct bnx2x_ilt ilt;
5800 memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
5801 memset(&ilt, 0, sizeof(struct bnx2x_ilt));
5803 /* initialize dummy TM client */
5805 ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
5806 ilt_cli.client_num = ILT_CLIENT_TM;
5808 /* Step 1: set zeroes to all ilt page entries with valid bit on
5809 * Step 2: set the timers first/last ilt entry to point
5810 * to the entire range to prevent ILT range error for 3rd/4th
5811 * vnic (this code assumes existance of the vnic)
5813 * both steps performed by call to bnx2x_ilt_client_init_op()
5814 * with dummy TM client
5816 * we must use pretend since PXP2_REG_RQ_##blk##_FIRST_ILT
5817 * and his brother are split registers
5819 bnx2x_pretend_func(bp, (BP_PATH(bp) + 6));
5820 bnx2x_ilt_client_init_op_ilt(bp, &ilt, &ilt_cli, INITOP_CLEAR);
5821 bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
5823 REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN, BNX2X_PXP_DRAM_ALIGN);
5824 REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_RD, BNX2X_PXP_DRAM_ALIGN);
5825 REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_SEL, 1);
5829 REG_WR(bp, PXP2_REG_RQ_DISABLE_INPUTS, 0);
5830 REG_WR(bp, PXP2_REG_RD_DISABLE_INPUTS, 0);
5832 if (!CHIP_IS_E1x(bp)) {
5833 int factor = CHIP_REV_IS_EMUL(bp) ? 1000 :
5834 (CHIP_REV_IS_FPGA(bp) ? 400 : 0);
5835 bnx2x_init_block(bp, BLOCK_PGLUE_B, PHASE_COMMON);
5837 bnx2x_init_block(bp, BLOCK_ATC, PHASE_COMMON);
5839 /* let the HW do it's magic ... */
5842 val = REG_RD(bp, ATC_REG_ATC_INIT_DONE);
5843 } while (factor-- && (val != 1));
5846 BNX2X_ERR("ATC_INIT failed\n");
5851 bnx2x_init_block(bp, BLOCK_DMAE, PHASE_COMMON);
5853 /* clean the DMAE memory */
5855 bnx2x_init_fill(bp, TSEM_REG_PRAM, 0, 8, 1);
5857 bnx2x_init_block(bp, BLOCK_TCM, PHASE_COMMON);
5859 bnx2x_init_block(bp, BLOCK_UCM, PHASE_COMMON);
5861 bnx2x_init_block(bp, BLOCK_CCM, PHASE_COMMON);
5863 bnx2x_init_block(bp, BLOCK_XCM, PHASE_COMMON);
5865 bnx2x_read_dmae(bp, XSEM_REG_PASSIVE_BUFFER, 3);
5866 bnx2x_read_dmae(bp, CSEM_REG_PASSIVE_BUFFER, 3);
5867 bnx2x_read_dmae(bp, TSEM_REG_PASSIVE_BUFFER, 3);
5868 bnx2x_read_dmae(bp, USEM_REG_PASSIVE_BUFFER, 3);
5870 bnx2x_init_block(bp, BLOCK_QM, PHASE_COMMON);
5873 /* QM queues pointers table */
5874 bnx2x_qm_init_ptr_table(bp, bp->qm_cid_count, INITOP_SET);
5876 /* soft reset pulse */
5877 REG_WR(bp, QM_REG_SOFT_RESET, 1);
5878 REG_WR(bp, QM_REG_SOFT_RESET, 0);
5881 bnx2x_init_block(bp, BLOCK_TM, PHASE_COMMON);
5884 bnx2x_init_block(bp, BLOCK_DORQ, PHASE_COMMON);
5885 REG_WR(bp, DORQ_REG_DPM_CID_OFST, BNX2X_DB_SHIFT);
5886 if (!CHIP_REV_IS_SLOW(bp))
5887 /* enable hw interrupt from doorbell Q */
5888 REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
5890 bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
5892 bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
5893 REG_WR(bp, PRS_REG_A_PRSU_20, 0xf);
5895 if (!CHIP_IS_E1(bp))
5896 REG_WR(bp, PRS_REG_E1HOV_MODE, bp->path_has_ovlan);
5898 if (!CHIP_IS_E1x(bp) && !CHIP_IS_E3B0(bp))
5899 /* Bit-map indicating which L2 hdrs may appear
5900 * after the basic Ethernet header
5902 REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC,
5903 bp->path_has_ovlan ? 7 : 6);
5905 bnx2x_init_block(bp, BLOCK_TSDM, PHASE_COMMON);
5906 bnx2x_init_block(bp, BLOCK_CSDM, PHASE_COMMON);
5907 bnx2x_init_block(bp, BLOCK_USDM, PHASE_COMMON);
5908 bnx2x_init_block(bp, BLOCK_XSDM, PHASE_COMMON);
5910 if (!CHIP_IS_E1x(bp)) {
5911 /* reset VFC memories */
5912 REG_WR(bp, TSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
5913 VFC_MEMORIES_RST_REG_CAM_RST |
5914 VFC_MEMORIES_RST_REG_RAM_RST);
5915 REG_WR(bp, XSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
5916 VFC_MEMORIES_RST_REG_CAM_RST |
5917 VFC_MEMORIES_RST_REG_RAM_RST);
5922 bnx2x_init_block(bp, BLOCK_TSEM, PHASE_COMMON);
5923 bnx2x_init_block(bp, BLOCK_USEM, PHASE_COMMON);
5924 bnx2x_init_block(bp, BLOCK_CSEM, PHASE_COMMON);
5925 bnx2x_init_block(bp, BLOCK_XSEM, PHASE_COMMON);
5928 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
5930 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
5933 bnx2x_init_block(bp, BLOCK_UPB, PHASE_COMMON);
5934 bnx2x_init_block(bp, BLOCK_XPB, PHASE_COMMON);
5935 bnx2x_init_block(bp, BLOCK_PBF, PHASE_COMMON);
5937 if (!CHIP_IS_E1x(bp))
5938 REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC,
5939 bp->path_has_ovlan ? 7 : 6);
5941 REG_WR(bp, SRC_REG_SOFT_RST, 1);
5943 bnx2x_init_block(bp, BLOCK_SRC, PHASE_COMMON);
5946 REG_WR(bp, SRC_REG_KEYSEARCH_0, 0x63285672);
5947 REG_WR(bp, SRC_REG_KEYSEARCH_1, 0x24b8f2cc);
5948 REG_WR(bp, SRC_REG_KEYSEARCH_2, 0x223aef9b);
5949 REG_WR(bp, SRC_REG_KEYSEARCH_3, 0x26001e3a);
5950 REG_WR(bp, SRC_REG_KEYSEARCH_4, 0x7ae91116);
5951 REG_WR(bp, SRC_REG_KEYSEARCH_5, 0x5ce5230b);
5952 REG_WR(bp, SRC_REG_KEYSEARCH_6, 0x298d8adf);
5953 REG_WR(bp, SRC_REG_KEYSEARCH_7, 0x6eb0ff09);
5954 REG_WR(bp, SRC_REG_KEYSEARCH_8, 0x1830f82f);
5955 REG_WR(bp, SRC_REG_KEYSEARCH_9, 0x01e46be7);
5957 REG_WR(bp, SRC_REG_SOFT_RST, 0);
5959 if (sizeof(union cdu_context) != 1024)
5960 /* we currently assume that a context is 1024 bytes */
5961 dev_alert(&bp->pdev->dev, "please adjust the size "
5962 "of cdu_context(%ld)\n",
5963 (long)sizeof(union cdu_context));
5965 bnx2x_init_block(bp, BLOCK_CDU, PHASE_COMMON);
5966 val = (4 << 24) + (0 << 12) + 1024;
5967 REG_WR(bp, CDU_REG_CDU_GLOBAL_PARAMS, val);
5969 bnx2x_init_block(bp, BLOCK_CFC, PHASE_COMMON);
5970 REG_WR(bp, CFC_REG_INIT_REG, 0x7FF);
5971 /* enable context validation interrupt from CFC */
5972 REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
5974 /* set the thresholds to prevent CFC/CDU race */
5975 REG_WR(bp, CFC_REG_DEBUG0, 0x20020000);
5977 bnx2x_init_block(bp, BLOCK_HC, PHASE_COMMON);
5979 if (!CHIP_IS_E1x(bp) && BP_NOMCP(bp))
5980 REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x36);
5982 bnx2x_init_block(bp, BLOCK_IGU, PHASE_COMMON);
5983 bnx2x_init_block(bp, BLOCK_MISC_AEU, PHASE_COMMON);
5985 /* Reset PCIE errors for debug */
5986 REG_WR(bp, 0x2814, 0xffffffff);
5987 REG_WR(bp, 0x3820, 0xffffffff);
5989 if (!CHIP_IS_E1x(bp)) {
5990 REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_CONTROL_5,
5991 (PXPCS_TL_CONTROL_5_ERR_UNSPPORT1 |
5992 PXPCS_TL_CONTROL_5_ERR_UNSPPORT));
5993 REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC345_STAT,
5994 (PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT4 |
5995 PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT3 |
5996 PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT2));
5997 REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC678_STAT,
5998 (PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT7 |
5999 PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT6 |
6000 PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT5));
6003 bnx2x_init_block(bp, BLOCK_NIG, PHASE_COMMON);
6004 if (!CHIP_IS_E1(bp)) {
6005 /* in E3 this done in per-port section */
6006 if (!CHIP_IS_E3(bp))
6007 REG_WR(bp, NIG_REG_LLH_MF_MODE, IS_MF(bp));
6009 if (CHIP_IS_E1H(bp))
6010 /* not applicable for E2 (and above ...) */
6011 REG_WR(bp, NIG_REG_LLH_E1HOV_MODE, IS_MF_SD(bp));
6013 if (CHIP_REV_IS_SLOW(bp))
6016 /* finish CFC init */
6017 val = reg_poll(bp, CFC_REG_LL_INIT_DONE, 1, 100, 10);
6019 BNX2X_ERR("CFC LL_INIT failed\n");
6022 val = reg_poll(bp, CFC_REG_AC_INIT_DONE, 1, 100, 10);
6024 BNX2X_ERR("CFC AC_INIT failed\n");
6027 val = reg_poll(bp, CFC_REG_CAM_INIT_DONE, 1, 100, 10);
6029 BNX2X_ERR("CFC CAM_INIT failed\n");
6032 REG_WR(bp, CFC_REG_DEBUG0, 0);
6034 if (CHIP_IS_E1(bp)) {
6035 /* read NIG statistic
6036 to see if this is our first up since powerup */
6037 bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
6038 val = *bnx2x_sp(bp, wb_data[0]);
6040 /* do internal memory self test */
6041 if ((val == 0) && bnx2x_int_mem_test(bp)) {
6042 BNX2X_ERR("internal mem self test failed\n");
6047 bnx2x_setup_fan_failure_detection(bp);
6049 /* clear PXP2 attentions */
6050 REG_RD(bp, PXP2_REG_PXP2_INT_STS_CLR_0);
6052 bnx2x_enable_blocks_attention(bp);
6053 bnx2x_enable_blocks_parity(bp);
6055 if (!BP_NOMCP(bp)) {
6056 if (CHIP_IS_E1x(bp))
6057 bnx2x__common_init_phy(bp);
6059 BNX2X_ERR("Bootcode is missing - can not initialize link\n");
6065 * bnx2x_init_hw_common_chip - init HW at the COMMON_CHIP phase.
6067 * @bp: driver handle
6069 static int bnx2x_init_hw_common_chip(struct bnx2x *bp)
6071 int rc = bnx2x_init_hw_common(bp);
6076 /* In E2 2-PORT mode, same ext phy is used for the two paths */
6078 bnx2x__common_init_phy(bp);
6083 static int bnx2x_init_hw_port(struct bnx2x *bp)
6085 int port = BP_PORT(bp);
6086 int init_phase = port ? PHASE_PORT1 : PHASE_PORT0;
6090 bnx2x__link_reset(bp);
6092 DP(BNX2X_MSG_MCP, "starting port init port %d\n", port);
6094 REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
6096 bnx2x_init_block(bp, BLOCK_MISC, init_phase);
6097 bnx2x_init_block(bp, BLOCK_PXP, init_phase);
6098 bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
6100 /* Timers bug workaround: disables the pf_master bit in pglue at
6101 * common phase, we need to enable it here before any dmae access are
6102 * attempted. Therefore we manually added the enable-master to the
6103 * port phase (it also happens in the function phase)
6105 if (!CHIP_IS_E1x(bp))
6106 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
6108 bnx2x_init_block(bp, BLOCK_ATC, init_phase);
6109 bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
6110 bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
6111 bnx2x_init_block(bp, BLOCK_QM, init_phase);
6113 bnx2x_init_block(bp, BLOCK_TCM, init_phase);
6114 bnx2x_init_block(bp, BLOCK_UCM, init_phase);
6115 bnx2x_init_block(bp, BLOCK_CCM, init_phase);
6116 bnx2x_init_block(bp, BLOCK_XCM, init_phase);
6118 /* QM cid (connection) count */
6119 bnx2x_qm_init_cid_count(bp, bp->qm_cid_count, INITOP_SET);
6122 bnx2x_init_block(bp, BLOCK_TM, init_phase);
6123 REG_WR(bp, TM_REG_LIN0_SCAN_TIME + port*4, 20);
6124 REG_WR(bp, TM_REG_LIN0_MAX_ACTIVE_CID + port*4, 31);
6127 bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
6129 if (CHIP_IS_E1(bp) || CHIP_IS_E1H(bp)) {
6130 bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
6133 low = ((bp->flags & ONE_PORT_FLAG) ? 160 : 246);
6134 else if (bp->dev->mtu > 4096) {
6135 if (bp->flags & ONE_PORT_FLAG)
6139 /* (24*1024 + val*4)/256 */
6140 low = 96 + (val/64) +
6141 ((val % 64) ? 1 : 0);
6144 low = ((bp->flags & ONE_PORT_FLAG) ? 80 : 160);
6145 high = low + 56; /* 14*1024/256 */
6146 REG_WR(bp, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port*4, low);
6147 REG_WR(bp, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port*4, high);
6150 if (CHIP_MODE_IS_4_PORT(bp))
6151 REG_WR(bp, (BP_PORT(bp) ?
6152 BRB1_REG_MAC_GUARANTIED_1 :
6153 BRB1_REG_MAC_GUARANTIED_0), 40);
6156 bnx2x_init_block(bp, BLOCK_PRS, init_phase);
6157 if (CHIP_IS_E3B0(bp))
6158 /* Ovlan exists only if we are in multi-function +
6159 * switch-dependent mode, in switch-independent there
6160 * is no ovlan headers
6162 REG_WR(bp, BP_PORT(bp) ?
6163 PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
6164 PRS_REG_HDRS_AFTER_BASIC_PORT_0,
6165 (bp->path_has_ovlan ? 7 : 6));
6167 bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
6168 bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
6169 bnx2x_init_block(bp, BLOCK_USDM, init_phase);
6170 bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
6172 bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
6173 bnx2x_init_block(bp, BLOCK_USEM, init_phase);
6174 bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
6175 bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
6177 bnx2x_init_block(bp, BLOCK_UPB, init_phase);
6178 bnx2x_init_block(bp, BLOCK_XPB, init_phase);
6180 bnx2x_init_block(bp, BLOCK_PBF, init_phase);
6182 if (CHIP_IS_E1x(bp)) {
6183 /* configure PBF to work without PAUSE mtu 9000 */
6184 REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
6186 /* update threshold */
6187 REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, (9040/16));
6188 /* update init credit */
6189 REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, (9040/16) + 553 - 22);
6192 REG_WR(bp, PBF_REG_INIT_P0 + port*4, 1);
6194 REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0);
6198 bnx2x_init_block(bp, BLOCK_SRC, init_phase);
6200 bnx2x_init_block(bp, BLOCK_CDU, init_phase);
6201 bnx2x_init_block(bp, BLOCK_CFC, init_phase);
6203 if (CHIP_IS_E1(bp)) {
6204 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
6205 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
6207 bnx2x_init_block(bp, BLOCK_HC, init_phase);
6209 bnx2x_init_block(bp, BLOCK_IGU, init_phase);
6211 bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
6212 /* init aeu_mask_attn_func_0/1:
6213 * - SF mode: bits 3-7 are masked. only bits 0-2 are in use
6214 * - MF mode: bit 3 is masked. bits 0-2 are in use as in SF
6215 * bits 4-7 are used for "per vn group attention" */
6216 val = IS_MF(bp) ? 0xF7 : 0x7;
6217 /* Enable DCBX attention for all but E1 */
6218 val |= CHIP_IS_E1(bp) ? 0 : 0x10;
6219 REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, val);
6221 bnx2x_init_block(bp, BLOCK_NIG, init_phase);
6223 if (!CHIP_IS_E1x(bp)) {
6224 /* Bit-map indicating which L2 hdrs may appear after the
6225 * basic Ethernet header
6227 REG_WR(bp, BP_PORT(bp) ?
6228 NIG_REG_P1_HDRS_AFTER_BASIC :
6229 NIG_REG_P0_HDRS_AFTER_BASIC,
6230 IS_MF_SD(bp) ? 7 : 6);
6233 REG_WR(bp, BP_PORT(bp) ?
6234 NIG_REG_LLH1_MF_MODE :
6235 NIG_REG_LLH_MF_MODE, IS_MF(bp));
6237 if (!CHIP_IS_E3(bp))
6238 REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
6240 if (!CHIP_IS_E1(bp)) {
6241 /* 0x2 disable mf_ov, 0x1 enable */
6242 REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port*4,
6243 (IS_MF_SD(bp) ? 0x1 : 0x2));
6245 if (!CHIP_IS_E1x(bp)) {
6247 switch (bp->mf_mode) {
6248 case MULTI_FUNCTION_SD:
6251 case MULTI_FUNCTION_SI:
6256 REG_WR(bp, (BP_PORT(bp) ? NIG_REG_LLH1_CLS_TYPE :
6257 NIG_REG_LLH0_CLS_TYPE), val);
6260 REG_WR(bp, NIG_REG_LLFC_ENABLE_0 + port*4, 0);
6261 REG_WR(bp, NIG_REG_LLFC_OUT_EN_0 + port*4, 0);
6262 REG_WR(bp, NIG_REG_PAUSE_ENABLE_0 + port*4, 1);
6267 /* If SPIO5 is set to generate interrupts, enable it for this port */
6268 val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
6269 if (val & (1 << MISC_REGISTERS_SPIO_5)) {
6270 u32 reg_addr = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
6271 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
6272 val = REG_RD(bp, reg_addr);
6273 val |= AEU_INPUTS_ATTN_BITS_SPIO5;
6274 REG_WR(bp, reg_addr, val);
6280 static void bnx2x_ilt_wr(struct bnx2x *bp, u32 index, dma_addr_t addr)
6285 reg = PXP2_REG_RQ_ONCHIP_AT + index*8;
6287 reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index*8;
6289 bnx2x_wb_wr(bp, reg, ONCHIP_ADDR1(addr), ONCHIP_ADDR2(addr));
6292 static inline void bnx2x_igu_clear_sb(struct bnx2x *bp, u8 idu_sb_id)
6294 bnx2x_igu_clear_sb_gen(bp, BP_FUNC(bp), idu_sb_id, true /*PF*/);
6297 static inline void bnx2x_clear_func_ilt(struct bnx2x *bp, u32 func)
6299 u32 i, base = FUNC_ILT_BASE(func);
6300 for (i = base; i < base + ILT_PER_FUNC; i++)
6301 bnx2x_ilt_wr(bp, i, 0);
6304 static int bnx2x_init_hw_func(struct bnx2x *bp)
6306 int port = BP_PORT(bp);
6307 int func = BP_FUNC(bp);
6308 int init_phase = PHASE_PF0 + func;
6309 struct bnx2x_ilt *ilt = BP_ILT(bp);
6312 u32 main_mem_base, main_mem_size, main_mem_prty_clr;
6313 int i, main_mem_width;
6315 DP(BNX2X_MSG_MCP, "starting func init func %d\n", func);
6317 /* FLR cleanup - hmmm */
6318 if (!CHIP_IS_E1x(bp))
6319 bnx2x_pf_flr_clnup(bp);
6321 /* set MSI reconfigure capability */
6322 if (bp->common.int_block == INT_BLOCK_HC) {
6323 addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0);
6324 val = REG_RD(bp, addr);
6325 val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0;
6326 REG_WR(bp, addr, val);
6329 bnx2x_init_block(bp, BLOCK_PXP, init_phase);
6330 bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
6333 cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
6335 for (i = 0; i < L2_ILT_LINES(bp); i++) {
6336 ilt->lines[cdu_ilt_start + i].page =
6337 bp->context.vcxt + (ILT_PAGE_CIDS * i);
6338 ilt->lines[cdu_ilt_start + i].page_mapping =
6339 bp->context.cxt_mapping + (CDU_ILT_PAGE_SZ * i);
6340 /* cdu ilt pages are allocated manually so there's no need to
6343 bnx2x_ilt_init_op(bp, INITOP_SET);
6346 bnx2x_src_init_t2(bp, bp->t2, bp->t2_mapping, SRC_CONN_NUM);
6348 /* T1 hash bits value determines the T1 number of entries */
6349 REG_WR(bp, SRC_REG_NUMBER_HASH_BITS0 + port*4, SRC_HASH_BITS);
6354 REG_WR(bp, PRS_REG_NIC_MODE, 1);
6355 #endif /* BCM_CNIC */
6357 if (!CHIP_IS_E1x(bp)) {
6358 u32 pf_conf = IGU_PF_CONF_FUNC_EN;
6360 /* Turn on a single ISR mode in IGU if driver is going to use
6363 if (!(bp->flags & USING_MSIX_FLAG))
6364 pf_conf |= IGU_PF_CONF_SINGLE_ISR_EN;
6366 * Timers workaround bug: function init part.
6367 * Need to wait 20msec after initializing ILT,
6368 * needed to make sure there are no requests in
6369 * one of the PXP internal queues with "old" ILT addresses
6373 * Master enable - Due to WB DMAE writes performed before this
6374 * register is re-initialized as part of the regular function
6377 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
6378 /* Enable the function in IGU */
6379 REG_WR(bp, IGU_REG_PF_CONFIGURATION, pf_conf);
6384 bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
6386 if (!CHIP_IS_E1x(bp))
6387 REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR, func);
6389 bnx2x_init_block(bp, BLOCK_ATC, init_phase);
6390 bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
6391 bnx2x_init_block(bp, BLOCK_NIG, init_phase);
6392 bnx2x_init_block(bp, BLOCK_SRC, init_phase);
6393 bnx2x_init_block(bp, BLOCK_MISC, init_phase);
6394 bnx2x_init_block(bp, BLOCK_TCM, init_phase);
6395 bnx2x_init_block(bp, BLOCK_UCM, init_phase);
6396 bnx2x_init_block(bp, BLOCK_CCM, init_phase);
6397 bnx2x_init_block(bp, BLOCK_XCM, init_phase);
6398 bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
6399 bnx2x_init_block(bp, BLOCK_USEM, init_phase);
6400 bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
6401 bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
6403 if (!CHIP_IS_E1x(bp))
6404 REG_WR(bp, QM_REG_PF_EN, 1);
6406 if (!CHIP_IS_E1x(bp)) {
6407 REG_WR(bp, TSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
6408 REG_WR(bp, USEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
6409 REG_WR(bp, CSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
6410 REG_WR(bp, XSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
6412 bnx2x_init_block(bp, BLOCK_QM, init_phase);
6414 bnx2x_init_block(bp, BLOCK_TM, init_phase);
6415 bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
6416 bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
6417 bnx2x_init_block(bp, BLOCK_PRS, init_phase);
6418 bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
6419 bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
6420 bnx2x_init_block(bp, BLOCK_USDM, init_phase);
6421 bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
6422 bnx2x_init_block(bp, BLOCK_UPB, init_phase);
6423 bnx2x_init_block(bp, BLOCK_XPB, init_phase);
6424 bnx2x_init_block(bp, BLOCK_PBF, init_phase);
6425 if (!CHIP_IS_E1x(bp))
6426 REG_WR(bp, PBF_REG_DISABLE_PF, 0);
6428 bnx2x_init_block(bp, BLOCK_CDU, init_phase);
6430 bnx2x_init_block(bp, BLOCK_CFC, init_phase);
6432 if (!CHIP_IS_E1x(bp))
6433 REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 1);
6436 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
6437 REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + port*8, bp->mf_ov);
6440 bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
6442 /* HC init per function */
6443 if (bp->common.int_block == INT_BLOCK_HC) {
6444 if (CHIP_IS_E1H(bp)) {
6445 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
6447 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
6448 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
6450 bnx2x_init_block(bp, BLOCK_HC, init_phase);
6453 int num_segs, sb_idx, prod_offset;
6455 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
6457 if (!CHIP_IS_E1x(bp)) {
6458 REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
6459 REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
6462 bnx2x_init_block(bp, BLOCK_IGU, init_phase);
6464 if (!CHIP_IS_E1x(bp)) {
6468 * E2 mode: address 0-135 match to the mapping memory;
6469 * 136 - PF0 default prod; 137 - PF1 default prod;
6470 * 138 - PF2 default prod; 139 - PF3 default prod;
6471 * 140 - PF0 attn prod; 141 - PF1 attn prod;
6472 * 142 - PF2 attn prod; 143 - PF3 attn prod;
6475 * E1.5 mode - In backward compatible mode;
6476 * for non default SB; each even line in the memory
6477 * holds the U producer and each odd line hold
6478 * the C producer. The first 128 producers are for
6479 * NDSB (PF0 - 0-31; PF1 - 32-63 and so on). The last 20
6480 * producers are for the DSB for each PF.
6481 * Each PF has five segments: (the order inside each
6482 * segment is PF0; PF1; PF2; PF3) - 128-131 U prods;
6483 * 132-135 C prods; 136-139 X prods; 140-143 T prods;
6484 * 144-147 attn prods;
6486 /* non-default-status-blocks */
6487 num_segs = CHIP_INT_MODE_IS_BC(bp) ?
6488 IGU_BC_NDSB_NUM_SEGS : IGU_NORM_NDSB_NUM_SEGS;
6489 for (sb_idx = 0; sb_idx < bp->igu_sb_cnt; sb_idx++) {
6490 prod_offset = (bp->igu_base_sb + sb_idx) *
6493 for (i = 0; i < num_segs; i++) {
6494 addr = IGU_REG_PROD_CONS_MEMORY +
6495 (prod_offset + i) * 4;
6496 REG_WR(bp, addr, 0);
6498 /* send consumer update with value 0 */
6499 bnx2x_ack_sb(bp, bp->igu_base_sb + sb_idx,
6500 USTORM_ID, 0, IGU_INT_NOP, 1);
6501 bnx2x_igu_clear_sb(bp,
6502 bp->igu_base_sb + sb_idx);
6505 /* default-status-blocks */
6506 num_segs = CHIP_INT_MODE_IS_BC(bp) ?
6507 IGU_BC_DSB_NUM_SEGS : IGU_NORM_DSB_NUM_SEGS;
6509 if (CHIP_MODE_IS_4_PORT(bp))
6510 dsb_idx = BP_FUNC(bp);
6512 dsb_idx = BP_E1HVN(bp);
6514 prod_offset = (CHIP_INT_MODE_IS_BC(bp) ?
6515 IGU_BC_BASE_DSB_PROD + dsb_idx :
6516 IGU_NORM_BASE_DSB_PROD + dsb_idx);
6518 for (i = 0; i < (num_segs * E1HVN_MAX);
6520 addr = IGU_REG_PROD_CONS_MEMORY +
6521 (prod_offset + i)*4;
6522 REG_WR(bp, addr, 0);
6524 /* send consumer update with 0 */
6525 if (CHIP_INT_MODE_IS_BC(bp)) {
6526 bnx2x_ack_sb(bp, bp->igu_dsb_id,
6527 USTORM_ID, 0, IGU_INT_NOP, 1);
6528 bnx2x_ack_sb(bp, bp->igu_dsb_id,
6529 CSTORM_ID, 0, IGU_INT_NOP, 1);
6530 bnx2x_ack_sb(bp, bp->igu_dsb_id,
6531 XSTORM_ID, 0, IGU_INT_NOP, 1);
6532 bnx2x_ack_sb(bp, bp->igu_dsb_id,
6533 TSTORM_ID, 0, IGU_INT_NOP, 1);
6534 bnx2x_ack_sb(bp, bp->igu_dsb_id,
6535 ATTENTION_ID, 0, IGU_INT_NOP, 1);
6537 bnx2x_ack_sb(bp, bp->igu_dsb_id,
6538 USTORM_ID, 0, IGU_INT_NOP, 1);
6539 bnx2x_ack_sb(bp, bp->igu_dsb_id,
6540 ATTENTION_ID, 0, IGU_INT_NOP, 1);
6542 bnx2x_igu_clear_sb(bp, bp->igu_dsb_id);
6544 /* !!! these should become driver const once
6545 rf-tool supports split-68 const */
6546 REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_LSB, 0);
6547 REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_MSB, 0);
6548 REG_WR(bp, IGU_REG_SB_MASK_LSB, 0);
6549 REG_WR(bp, IGU_REG_SB_MASK_MSB, 0);
6550 REG_WR(bp, IGU_REG_PBA_STATUS_LSB, 0);
6551 REG_WR(bp, IGU_REG_PBA_STATUS_MSB, 0);
6555 /* Reset PCIE errors for debug */
6556 REG_WR(bp, 0x2114, 0xffffffff);
6557 REG_WR(bp, 0x2120, 0xffffffff);
6559 if (CHIP_IS_E1x(bp)) {
6560 main_mem_size = HC_REG_MAIN_MEMORY_SIZE / 2; /*dwords*/
6561 main_mem_base = HC_REG_MAIN_MEMORY +
6562 BP_PORT(bp) * (main_mem_size * 4);
6563 main_mem_prty_clr = HC_REG_HC_PRTY_STS_CLR;
6566 val = REG_RD(bp, main_mem_prty_clr);
6568 DP(BNX2X_MSG_MCP, "Hmmm... Parity errors in HC "
6570 "function init (0x%x)!\n", val);
6572 /* Clear "false" parity errors in MSI-X table */
6573 for (i = main_mem_base;
6574 i < main_mem_base + main_mem_size * 4;
6575 i += main_mem_width) {
6576 bnx2x_read_dmae(bp, i, main_mem_width / 4);
6577 bnx2x_write_dmae(bp, bnx2x_sp_mapping(bp, wb_data),
6578 i, main_mem_width / 4);
6580 /* Clear HC parity attention */
6581 REG_RD(bp, main_mem_prty_clr);
6584 #ifdef BNX2X_STOP_ON_ERROR
6585 /* Enable STORMs SP logging */
6586 REG_WR8(bp, BAR_USTRORM_INTMEM +
6587 USTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
6588 REG_WR8(bp, BAR_TSTRORM_INTMEM +
6589 TSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
6590 REG_WR8(bp, BAR_CSTRORM_INTMEM +
6591 CSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
6592 REG_WR8(bp, BAR_XSTRORM_INTMEM +
6593 XSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
6596 bnx2x_phy_probe(&bp->link_params);
6602 void bnx2x_free_mem(struct bnx2x *bp)
6605 bnx2x_free_fp_mem(bp);
6606 /* end of fastpath */
6608 BNX2X_PCI_FREE(bp->def_status_blk, bp->def_status_blk_mapping,
6609 sizeof(struct host_sp_status_block));
6611 BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
6612 bp->fw_stats_data_sz + bp->fw_stats_req_sz);
6614 BNX2X_PCI_FREE(bp->slowpath, bp->slowpath_mapping,
6615 sizeof(struct bnx2x_slowpath));
6617 BNX2X_PCI_FREE(bp->context.vcxt, bp->context.cxt_mapping,
6620 bnx2x_ilt_mem_op(bp, ILT_MEMOP_FREE);
6622 BNX2X_FREE(bp->ilt->lines);
6625 if (!CHIP_IS_E1x(bp))
6626 BNX2X_PCI_FREE(bp->cnic_sb.e2_sb, bp->cnic_sb_mapping,
6627 sizeof(struct host_hc_status_block_e2));
6629 BNX2X_PCI_FREE(bp->cnic_sb.e1x_sb, bp->cnic_sb_mapping,
6630 sizeof(struct host_hc_status_block_e1x));
6632 BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
6635 BNX2X_PCI_FREE(bp->spq, bp->spq_mapping, BCM_PAGE_SIZE);
6637 BNX2X_PCI_FREE(bp->eq_ring, bp->eq_mapping,
6638 BCM_PAGE_SIZE * NUM_EQ_PAGES);
6641 static inline int bnx2x_alloc_fw_stats_mem(struct bnx2x *bp)
6645 /* number of eth_queues */
6646 u8 num_queue_stats = BNX2X_NUM_ETH_QUEUES(bp);
6648 /* Total number of FW statistics requests =
6649 * 1 for port stats + 1 for PF stats + num_eth_queues */
6650 bp->fw_stats_num = 2 + num_queue_stats;
6653 /* Request is built from stats_query_header and an array of
6654 * stats_query_cmd_group each of which contains
6655 * STATS_QUERY_CMD_COUNT rules. The real number or requests is
6656 * configured in the stats_query_header.
6658 num_groups = (2 + num_queue_stats) / STATS_QUERY_CMD_COUNT +
6659 (((2 + num_queue_stats) % STATS_QUERY_CMD_COUNT) ? 1 : 0);
6661 bp->fw_stats_req_sz = sizeof(struct stats_query_header) +
6662 num_groups * sizeof(struct stats_query_cmd_group);
6664 /* Data for statistics requests + stats_conter
6666 * stats_counter holds per-STORM counters that are incremented
6667 * when STORM has finished with the current request.
6669 bp->fw_stats_data_sz = sizeof(struct per_port_stats) +
6670 sizeof(struct per_pf_stats) +
6671 sizeof(struct per_queue_stats) * num_queue_stats +
6672 sizeof(struct stats_counter);
6674 BNX2X_PCI_ALLOC(bp->fw_stats, &bp->fw_stats_mapping,
6675 bp->fw_stats_data_sz + bp->fw_stats_req_sz);
6678 bp->fw_stats_req = (struct bnx2x_fw_stats_req *)bp->fw_stats;
6679 bp->fw_stats_req_mapping = bp->fw_stats_mapping;
6681 bp->fw_stats_data = (struct bnx2x_fw_stats_data *)
6682 ((u8 *)bp->fw_stats + bp->fw_stats_req_sz);
6684 bp->fw_stats_data_mapping = bp->fw_stats_mapping +
6685 bp->fw_stats_req_sz;
6689 BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
6690 bp->fw_stats_data_sz + bp->fw_stats_req_sz);
6695 int bnx2x_alloc_mem(struct bnx2x *bp)
6698 if (!CHIP_IS_E1x(bp))
6699 /* size = the status block + ramrod buffers */
6700 BNX2X_PCI_ALLOC(bp->cnic_sb.e2_sb, &bp->cnic_sb_mapping,
6701 sizeof(struct host_hc_status_block_e2));
6703 BNX2X_PCI_ALLOC(bp->cnic_sb.e1x_sb, &bp->cnic_sb_mapping,
6704 sizeof(struct host_hc_status_block_e1x));
6706 /* allocate searcher T2 table */
6707 BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ);
6711 BNX2X_PCI_ALLOC(bp->def_status_blk, &bp->def_status_blk_mapping,
6712 sizeof(struct host_sp_status_block));
6714 BNX2X_PCI_ALLOC(bp->slowpath, &bp->slowpath_mapping,
6715 sizeof(struct bnx2x_slowpath));
6717 /* Allocated memory for FW statistics */
6718 if (bnx2x_alloc_fw_stats_mem(bp))
6721 bp->context.size = sizeof(union cdu_context) * bp->l2_cid_count;
6723 BNX2X_PCI_ALLOC(bp->context.vcxt, &bp->context.cxt_mapping,
6726 BNX2X_ALLOC(bp->ilt->lines, sizeof(struct ilt_line) * ILT_MAX_LINES);
6728 if (bnx2x_ilt_mem_op(bp, ILT_MEMOP_ALLOC))
6731 /* Slow path ring */
6732 BNX2X_PCI_ALLOC(bp->spq, &bp->spq_mapping, BCM_PAGE_SIZE);
6735 BNX2X_PCI_ALLOC(bp->eq_ring, &bp->eq_mapping,
6736 BCM_PAGE_SIZE * NUM_EQ_PAGES);
6740 /* need to be done at the end, since it's self adjusting to amount
6741 * of memory available for RSS queues
6743 if (bnx2x_alloc_fp_mem(bp))
6753 * Init service functions
6756 int bnx2x_set_mac_one(struct bnx2x *bp, u8 *mac,
6757 struct bnx2x_vlan_mac_obj *obj, bool set,
6758 int mac_type, unsigned long *ramrod_flags)
6761 struct bnx2x_vlan_mac_ramrod_params ramrod_param;
6763 memset(&ramrod_param, 0, sizeof(ramrod_param));
6765 /* Fill general parameters */
6766 ramrod_param.vlan_mac_obj = obj;
6767 ramrod_param.ramrod_flags = *ramrod_flags;
6769 /* Fill a user request section if needed */
6770 if (!test_bit(RAMROD_CONT, ramrod_flags)) {
6771 memcpy(ramrod_param.user_req.u.mac.mac, mac, ETH_ALEN);
6773 __set_bit(mac_type, &ramrod_param.user_req.vlan_mac_flags);
6775 /* Set the command: ADD or DEL */
6777 ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_ADD;
6779 ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_DEL;
6782 rc = bnx2x_config_vlan_mac(bp, &ramrod_param);
6784 BNX2X_ERR("%s MAC failed\n", (set ? "Set" : "Del"));
6788 int bnx2x_del_all_macs(struct bnx2x *bp,
6789 struct bnx2x_vlan_mac_obj *mac_obj,
6790 int mac_type, bool wait_for_comp)
6793 unsigned long ramrod_flags = 0, vlan_mac_flags = 0;
6795 /* Wait for completion of requested */
6797 __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
6799 /* Set the mac type of addresses we want to clear */
6800 __set_bit(mac_type, &vlan_mac_flags);
6802 rc = mac_obj->delete_all(bp, mac_obj, &vlan_mac_flags, &ramrod_flags);
6804 BNX2X_ERR("Failed to delete MACs: %d\n", rc);
6809 int bnx2x_set_eth_mac(struct bnx2x *bp, bool set)
6811 unsigned long ramrod_flags = 0;
6813 DP(NETIF_MSG_IFUP, "Adding Eth MAC\n");
6815 __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
6816 /* Eth MAC is set on RSS leading client (fp[0]) */
6817 return bnx2x_set_mac_one(bp, bp->dev->dev_addr, &bp->fp->mac_obj, set,
6818 BNX2X_ETH_MAC, &ramrod_flags);
6821 int bnx2x_setup_leading(struct bnx2x *bp)
6823 return bnx2x_setup_queue(bp, &bp->fp[0], 1);
6827 * bnx2x_set_int_mode - configure interrupt mode
6829 * @bp: driver handle
6831 * In case of MSI-X it will also try to enable MSI-X.
6833 static void __devinit bnx2x_set_int_mode(struct bnx2x *bp)
6837 bnx2x_enable_msi(bp);
6838 /* falling through... */
6840 bp->num_queues = 1 + NONE_ETH_CONTEXT_USE;
6841 DP(NETIF_MSG_IFUP, "set number of queues to 1\n");
6844 /* Set number of queues according to bp->multi_mode value */
6845 bnx2x_set_num_queues(bp);
6847 DP(NETIF_MSG_IFUP, "set number of queues to %d\n",
6850 /* if we can't use MSI-X we only need one fp,
6851 * so try to enable MSI-X with the requested number of fp's
6852 * and fallback to MSI or legacy INTx with one fp
6854 if (bnx2x_enable_msix(bp)) {
6855 /* failed to enable MSI-X */
6858 "Multi requested but failed to "
6859 "enable MSI-X (%d), "
6860 "set number of queues to %d\n",
6862 1 + NONE_ETH_CONTEXT_USE);
6863 bp->num_queues = 1 + NONE_ETH_CONTEXT_USE;
6865 /* Try to enable MSI */
6866 if (!(bp->flags & DISABLE_MSI_FLAG))
6867 bnx2x_enable_msi(bp);
6873 /* must be called prioir to any HW initializations */
6874 static inline u16 bnx2x_cid_ilt_lines(struct bnx2x *bp)
6876 return L2_ILT_LINES(bp);
6879 void bnx2x_ilt_set_info(struct bnx2x *bp)
6881 struct ilt_client_info *ilt_client;
6882 struct bnx2x_ilt *ilt = BP_ILT(bp);
6885 ilt->start_line = FUNC_ILT_BASE(BP_FUNC(bp));
6886 DP(BNX2X_MSG_SP, "ilt starts at line %d\n", ilt->start_line);
6889 ilt_client = &ilt->clients[ILT_CLIENT_CDU];
6890 ilt_client->client_num = ILT_CLIENT_CDU;
6891 ilt_client->page_size = CDU_ILT_PAGE_SZ;
6892 ilt_client->flags = ILT_CLIENT_SKIP_MEM;
6893 ilt_client->start = line;
6894 line += bnx2x_cid_ilt_lines(bp);
6896 line += CNIC_ILT_LINES;
6898 ilt_client->end = line - 1;
6900 DP(BNX2X_MSG_SP, "ilt client[CDU]: start %d, end %d, psz 0x%x, "
6901 "flags 0x%x, hw psz %d\n",
6904 ilt_client->page_size,
6906 ilog2(ilt_client->page_size >> 12));
6909 if (QM_INIT(bp->qm_cid_count)) {
6910 ilt_client = &ilt->clients[ILT_CLIENT_QM];
6911 ilt_client->client_num = ILT_CLIENT_QM;
6912 ilt_client->page_size = QM_ILT_PAGE_SZ;
6913 ilt_client->flags = 0;
6914 ilt_client->start = line;
6916 /* 4 bytes for each cid */
6917 line += DIV_ROUND_UP(bp->qm_cid_count * QM_QUEUES_PER_FUNC * 4,
6920 ilt_client->end = line - 1;
6922 DP(BNX2X_MSG_SP, "ilt client[QM]: start %d, end %d, psz 0x%x, "
6923 "flags 0x%x, hw psz %d\n",
6926 ilt_client->page_size,
6928 ilog2(ilt_client->page_size >> 12));
6932 ilt_client = &ilt->clients[ILT_CLIENT_SRC];
6934 ilt_client->client_num = ILT_CLIENT_SRC;
6935 ilt_client->page_size = SRC_ILT_PAGE_SZ;
6936 ilt_client->flags = 0;
6937 ilt_client->start = line;
6938 line += SRC_ILT_LINES;
6939 ilt_client->end = line - 1;
6941 DP(BNX2X_MSG_SP, "ilt client[SRC]: start %d, end %d, psz 0x%x, "
6942 "flags 0x%x, hw psz %d\n",
6945 ilt_client->page_size,
6947 ilog2(ilt_client->page_size >> 12));
6950 ilt_client->flags = (ILT_CLIENT_SKIP_INIT | ILT_CLIENT_SKIP_MEM);
6954 ilt_client = &ilt->clients[ILT_CLIENT_TM];
6956 ilt_client->client_num = ILT_CLIENT_TM;
6957 ilt_client->page_size = TM_ILT_PAGE_SZ;
6958 ilt_client->flags = 0;
6959 ilt_client->start = line;
6960 line += TM_ILT_LINES;
6961 ilt_client->end = line - 1;
6963 DP(BNX2X_MSG_SP, "ilt client[TM]: start %d, end %d, psz 0x%x, "
6964 "flags 0x%x, hw psz %d\n",
6967 ilt_client->page_size,
6969 ilog2(ilt_client->page_size >> 12));
6972 ilt_client->flags = (ILT_CLIENT_SKIP_INIT | ILT_CLIENT_SKIP_MEM);
6974 BUG_ON(line > ILT_MAX_LINES);
6978 * bnx2x_pf_q_prep_init - prepare INIT transition parameters
6980 * @bp: driver handle
6981 * @fp: pointer to fastpath
6982 * @init_params: pointer to parameters structure
6984 * parameters configured:
6985 * - HC configuration
6986 * - Queue's CDU context
6988 static inline void bnx2x_pf_q_prep_init(struct bnx2x *bp,
6989 struct bnx2x_fastpath *fp, struct bnx2x_queue_init_params *init_params)
6991 /* FCoE Queue uses Default SB, thus has no HC capabilities */
6992 if (!IS_FCOE_FP(fp)) {
6993 __set_bit(BNX2X_Q_FLG_HC, &init_params->rx.flags);
6994 __set_bit(BNX2X_Q_FLG_HC, &init_params->tx.flags);
6996 /* If HC is supporterd, enable host coalescing in the transition
6999 __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->rx.flags);
7000 __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->tx.flags);
7003 init_params->rx.hc_rate = bp->rx_ticks ?
7004 (1000000 / bp->rx_ticks) : 0;
7005 init_params->tx.hc_rate = bp->tx_ticks ?
7006 (1000000 / bp->tx_ticks) : 0;
7009 init_params->rx.fw_sb_id = init_params->tx.fw_sb_id =
7013 * CQ index among the SB indices: FCoE clients uses the default
7014 * SB, therefore it's different.
7016 init_params->rx.sb_cq_index = U_SB_ETH_RX_CQ_INDEX;
7017 init_params->tx.sb_cq_index = C_SB_ETH_TX_CQ_INDEX;
7020 init_params->cxt = &bp->context.vcxt[fp->cid].eth;
7024 * bnx2x_setup_queue - setup queue
7026 * @bp: driver handle
7027 * @fp: pointer to fastpath
7028 * @leading: is leading
7030 * This function performs 2 steps in a Queue state machine
7031 * actually: 1) RESET->INIT 2) INIT->SETUP
7034 int bnx2x_setup_queue(struct bnx2x *bp, struct bnx2x_fastpath *fp,
7037 struct bnx2x_queue_state_params q_params = {0};
7038 struct bnx2x_queue_setup_params *setup_params =
7039 &q_params.params.setup;
7042 /* reset IGU state skip FCoE L2 queue */
7043 if (!IS_FCOE_FP(fp))
7044 bnx2x_ack_sb(bp, fp->igu_sb_id, USTORM_ID, 0,
7047 q_params.q_obj = &fp->q_obj;
7048 /* We want to wait for completion in this context */
7049 __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
7051 /* Prepare the INIT parameters */
7052 bnx2x_pf_q_prep_init(bp, fp, &q_params.params.init);
7054 /* Set the command */
7055 q_params.cmd = BNX2X_Q_CMD_INIT;
7057 /* Change the state to INIT */
7058 rc = bnx2x_queue_state_change(bp, &q_params);
7060 BNX2X_ERR("Queue INIT failed\n");
7064 /* Now move the Queue to the SETUP state... */
7065 memset(setup_params, 0, sizeof(*setup_params));
7067 /* Set QUEUE flags */
7068 setup_params->flags = bnx2x_get_q_flags(bp, fp, leading);
7070 /* Set general SETUP parameters */
7071 bnx2x_pf_q_prep_general(bp, fp, &setup_params->gen_params);
7073 bnx2x_pf_rx_q_prep(bp, fp, &setup_params->pause,
7074 &setup_params->rxq_params);
7076 bnx2x_pf_tx_q_prep(bp, fp, &setup_params->txq_params);
7078 /* Set the command */
7079 q_params.cmd = BNX2X_Q_CMD_SETUP;
7081 /* Change the state to SETUP */
7082 rc = bnx2x_queue_state_change(bp, &q_params);
7084 BNX2X_ERR("Queue SETUP failed\n");
7089 static int bnx2x_stop_queue(struct bnx2x *bp, int index)
7091 struct bnx2x_fastpath *fp = &bp->fp[index];
7092 struct bnx2x_queue_state_params q_params = {0};
7095 q_params.q_obj = &fp->q_obj;
7096 /* We want to wait for completion in this context */
7097 __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
7099 /* halt the connection */
7100 q_params.cmd = BNX2X_Q_CMD_HALT;
7101 rc = bnx2x_queue_state_change(bp, &q_params);
7105 /* terminate the connection */
7106 q_params.cmd = BNX2X_Q_CMD_TERMINATE;
7107 rc = bnx2x_queue_state_change(bp, &q_params);
7111 /* delete cfc entry */
7112 q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
7113 return bnx2x_queue_state_change(bp, &q_params);
7117 static void bnx2x_reset_func(struct bnx2x *bp)
7119 int port = BP_PORT(bp);
7120 int func = BP_FUNC(bp);
7123 /* Disable the function in the FW */
7124 REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(func), 0);
7125 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(func), 0);
7126 REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(func), 0);
7127 REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(func), 0);
7130 for_each_eth_queue(bp, i) {
7131 struct bnx2x_fastpath *fp = &bp->fp[i];
7132 REG_WR8(bp, BAR_CSTRORM_INTMEM +
7133 CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(fp->fw_sb_id),
7139 REG_WR8(bp, BAR_CSTRORM_INTMEM +
7140 CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(bnx2x_cnic_fw_sb_id(bp)),
7144 REG_WR8(bp, BAR_CSTRORM_INTMEM +
7145 CSTORM_SP_STATUS_BLOCK_DATA_STATE_OFFSET(func),
7148 for (i = 0; i < XSTORM_SPQ_DATA_SIZE / 4; i++)
7149 REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_DATA_OFFSET(func),
7153 if (bp->common.int_block == INT_BLOCK_HC) {
7154 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
7155 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
7157 REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
7158 REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
7162 /* Disable Timer scan */
7163 REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + port*4, 0);
7165 * Wait for at least 10ms and up to 2 second for the timers scan to
7168 for (i = 0; i < 200; i++) {
7170 if (!REG_RD(bp, TM_REG_LIN0_SCAN_ON + port*4))
7175 bnx2x_clear_func_ilt(bp, func);
7177 /* Timers workaround bug for E2: if this is vnic-3,
7178 * we need to set the entire ilt range for this timers.
7180 if (!CHIP_IS_E1x(bp) && BP_VN(bp) == 3) {
7181 struct ilt_client_info ilt_cli;
7182 /* use dummy TM client */
7183 memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
7185 ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
7186 ilt_cli.client_num = ILT_CLIENT_TM;
7188 bnx2x_ilt_boundry_init_op(bp, &ilt_cli, 0, INITOP_CLEAR);
7191 /* this assumes that reset_port() called before reset_func()*/
7192 if (!CHIP_IS_E1x(bp))
7193 bnx2x_pf_disable(bp);
7198 static void bnx2x_reset_port(struct bnx2x *bp)
7200 int port = BP_PORT(bp);
7203 /* Reset physical Link */
7204 bnx2x__link_reset(bp);
7206 REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
7208 /* Do not rcv packets to BRB */
7209 REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0);
7210 /* Do not direct rcv packets that are not for MCP to the BRB */
7211 REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
7212 NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
7215 REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0);
7218 /* Check for BRB port occupancy */
7219 val = REG_RD(bp, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4);
7221 DP(NETIF_MSG_IFDOWN,
7222 "BRB1 is not empty %d blocks are occupied\n", val);
7224 /* TODO: Close Doorbell port? */
7227 static inline int bnx2x_reset_hw(struct bnx2x *bp, u32 load_code)
7229 struct bnx2x_func_state_params func_params = {0};
7231 /* Prepare parameters for function state transitions */
7232 __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
7234 func_params.f_obj = &bp->func_obj;
7235 func_params.cmd = BNX2X_F_CMD_HW_RESET;
7237 func_params.params.hw_init.load_phase = load_code;
7239 return bnx2x_func_state_change(bp, &func_params);
7242 static inline int bnx2x_func_stop(struct bnx2x *bp)
7244 struct bnx2x_func_state_params func_params = {0};
7247 /* Prepare parameters for function state transitions */
7248 __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
7249 func_params.f_obj = &bp->func_obj;
7250 func_params.cmd = BNX2X_F_CMD_STOP;
7253 * Try to stop the function the 'good way'. If fails (in case
7254 * of a parity error during bnx2x_chip_cleanup()) and we are
7255 * not in a debug mode, perform a state transaction in order to
7256 * enable further HW_RESET transaction.
7258 rc = bnx2x_func_state_change(bp, &func_params);
7260 #ifdef BNX2X_STOP_ON_ERROR
7263 BNX2X_ERR("FUNC_STOP ramrod failed. Running a dry "
7265 __set_bit(RAMROD_DRV_CLR_ONLY, &func_params.ramrod_flags);
7266 return bnx2x_func_state_change(bp, &func_params);
7274 * bnx2x_send_unload_req - request unload mode from the MCP.
7276 * @bp: driver handle
7277 * @unload_mode: requested function's unload mode
7279 * Return unload mode returned by the MCP: COMMON, PORT or FUNC.
7281 u32 bnx2x_send_unload_req(struct bnx2x *bp, int unload_mode)
7284 int port = BP_PORT(bp);
7286 /* Select the UNLOAD request mode */
7287 if (unload_mode == UNLOAD_NORMAL)
7288 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
7290 else if (bp->flags & NO_WOL_FLAG)
7291 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP;
7294 u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
7295 u8 *mac_addr = bp->dev->dev_addr;
7297 /* The mac address is written to entries 1-4 to
7298 preserve entry 0 which is used by the PMF */
7299 u8 entry = (BP_E1HVN(bp) + 1)*8;
7301 val = (mac_addr[0] << 8) | mac_addr[1];
7302 EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry, val);
7304 val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
7305 (mac_addr[4] << 8) | mac_addr[5];
7306 EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry + 4, val);
7308 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_EN;
7311 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
7313 /* Send the request to the MCP */
7315 reset_code = bnx2x_fw_command(bp, reset_code, 0);
7317 int path = BP_PATH(bp);
7319 DP(NETIF_MSG_IFDOWN, "NO MCP - load counts[%d] "
7321 path, load_count[path][0], load_count[path][1],
7322 load_count[path][2]);
7323 load_count[path][0]--;
7324 load_count[path][1 + port]--;
7325 DP(NETIF_MSG_IFDOWN, "NO MCP - new load counts[%d] "
7327 path, load_count[path][0], load_count[path][1],
7328 load_count[path][2]);
7329 if (load_count[path][0] == 0)
7330 reset_code = FW_MSG_CODE_DRV_UNLOAD_COMMON;
7331 else if (load_count[path][1 + port] == 0)
7332 reset_code = FW_MSG_CODE_DRV_UNLOAD_PORT;
7334 reset_code = FW_MSG_CODE_DRV_UNLOAD_FUNCTION;
7341 * bnx2x_send_unload_done - send UNLOAD_DONE command to the MCP.
7343 * @bp: driver handle
7345 void bnx2x_send_unload_done(struct bnx2x *bp)
7347 /* Report UNLOAD_DONE to MCP */
7349 bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
7352 void bnx2x_chip_cleanup(struct bnx2x *bp, int unload_mode)
7354 int port = BP_PORT(bp);
7356 struct bnx2x_mcast_ramrod_params rparam = {0};
7359 /* Wait until tx fastpath tasks complete */
7360 for_each_tx_queue(bp, i) {
7361 struct bnx2x_fastpath *fp = &bp->fp[i];
7363 rc = bnx2x_clean_tx_queue(bp, fp);
7364 #ifdef BNX2X_STOP_ON_ERROR
7370 /* Give HW time to discard old tx messages */
7371 usleep_range(1000, 1000);
7373 /* Clean all ETH MACs */
7374 rc = bnx2x_del_all_macs(bp, &bp->fp[0].mac_obj, BNX2X_ETH_MAC, false);
7376 BNX2X_ERR("Failed to delete all ETH macs: %d\n", rc);
7378 /* Clean up UC list */
7379 rc = bnx2x_del_all_macs(bp, &bp->fp[0].mac_obj, BNX2X_UC_LIST_MAC,
7382 BNX2X_ERR("Failed to schedule DEL commands for UC MACs list: "
7386 if (!CHIP_IS_E1(bp))
7387 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
7389 /* Set "drop all" (stop Rx).
7390 * We need to take a netif_addr_lock() here in order to prevent
7391 * a race between the completion code and this code.
7393 netif_addr_lock_bh(bp->dev);
7394 /* Schedule the rx_mode command */
7395 if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
7396 set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
7398 bnx2x_set_storm_rx_mode(bp);
7400 /* Cleanup multicast configuration */
7401 rparam.mcast_obj = &bp->mcast_obj;
7402 rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
7404 BNX2X_ERR("Failed to send DEL multicast command: %d\n", rc);
7406 netif_addr_unlock_bh(bp->dev);
7409 /* Close multi and leading connections
7410 * Completions for ramrods are collected in a synchronous way
7412 for_each_queue(bp, i)
7413 if (bnx2x_stop_queue(bp, i))
7414 #ifdef BNX2X_STOP_ON_ERROR
7419 /* If SP settings didn't get completed so far - something
7420 * very wrong has happen.
7422 if (!bnx2x_wait_sp_comp(bp, ~0x0UL))
7423 BNX2X_ERR("Hmmm... Common slow path ramrods got stuck!\n");
7425 #ifndef BNX2X_STOP_ON_ERROR
7428 rc = bnx2x_func_stop(bp);
7430 BNX2X_ERR("Function stop failed!\n");
7431 #ifdef BNX2X_STOP_ON_ERROR
7437 * Send the UNLOAD_REQUEST to the MCP. This will return if
7438 * this function should perform FUNC, PORT or COMMON HW
7441 reset_code = bnx2x_send_unload_req(bp, unload_mode);
7443 /* Disable HW interrupts, NAPI */
7444 bnx2x_netif_stop(bp, 1);
7449 /* Reset the chip */
7450 rc = bnx2x_reset_hw(bp, reset_code);
7452 BNX2X_ERR("HW_RESET failed\n");
7455 /* Report UNLOAD_DONE to MCP */
7456 bnx2x_send_unload_done(bp);
7459 void bnx2x_disable_close_the_gate(struct bnx2x *bp)
7463 DP(NETIF_MSG_HW, "Disabling \"close the gates\"\n");
7465 if (CHIP_IS_E1(bp)) {
7466 int port = BP_PORT(bp);
7467 u32 addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
7468 MISC_REG_AEU_MASK_ATTN_FUNC_0;
7470 val = REG_RD(bp, addr);
7472 REG_WR(bp, addr, val);
7474 val = REG_RD(bp, MISC_REG_AEU_GENERAL_MASK);
7475 val &= ~(MISC_AEU_GENERAL_MASK_REG_AEU_PXP_CLOSE_MASK |
7476 MISC_AEU_GENERAL_MASK_REG_AEU_NIG_CLOSE_MASK);
7477 REG_WR(bp, MISC_REG_AEU_GENERAL_MASK, val);
7481 /* Close gates #2, #3 and #4: */
7482 static void bnx2x_set_234_gates(struct bnx2x *bp, bool close)
7486 /* Gates #2 and #4a are closed/opened for "not E1" only */
7487 if (!CHIP_IS_E1(bp)) {
7489 REG_WR(bp, PXP_REG_HST_DISCARD_DOORBELLS, !!close);
7491 REG_WR(bp, PXP_REG_HST_DISCARD_INTERNAL_WRITES, !!close);
7495 if (CHIP_IS_E1x(bp)) {
7496 /* Prevent interrupts from HC on both ports */
7497 val = REG_RD(bp, HC_REG_CONFIG_1);
7498 REG_WR(bp, HC_REG_CONFIG_1,
7499 (!close) ? (val | HC_CONFIG_1_REG_BLOCK_DISABLE_1) :
7500 (val & ~(u32)HC_CONFIG_1_REG_BLOCK_DISABLE_1));
7502 val = REG_RD(bp, HC_REG_CONFIG_0);
7503 REG_WR(bp, HC_REG_CONFIG_0,
7504 (!close) ? (val | HC_CONFIG_0_REG_BLOCK_DISABLE_0) :
7505 (val & ~(u32)HC_CONFIG_0_REG_BLOCK_DISABLE_0));
7507 /* Prevent incomming interrupts in IGU */
7508 val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
7510 REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION,
7512 (val | IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE) :
7513 (val & ~(u32)IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE));
7516 DP(NETIF_MSG_HW, "%s gates #2, #3 and #4\n",
7517 close ? "closing" : "opening");
7521 #define SHARED_MF_CLP_MAGIC 0x80000000 /* `magic' bit */
7523 static void bnx2x_clp_reset_prep(struct bnx2x *bp, u32 *magic_val)
7525 /* Do some magic... */
7526 u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
7527 *magic_val = val & SHARED_MF_CLP_MAGIC;
7528 MF_CFG_WR(bp, shared_mf_config.clp_mb, val | SHARED_MF_CLP_MAGIC);
7532 * bnx2x_clp_reset_done - restore the value of the `magic' bit.
7534 * @bp: driver handle
7535 * @magic_val: old value of the `magic' bit.
7537 static void bnx2x_clp_reset_done(struct bnx2x *bp, u32 magic_val)
7539 /* Restore the `magic' bit value... */
7540 u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
7541 MF_CFG_WR(bp, shared_mf_config.clp_mb,
7542 (val & (~SHARED_MF_CLP_MAGIC)) | magic_val);
7546 * bnx2x_reset_mcp_prep - prepare for MCP reset.
7548 * @bp: driver handle
7549 * @magic_val: old value of 'magic' bit.
7551 * Takes care of CLP configurations.
7553 static void bnx2x_reset_mcp_prep(struct bnx2x *bp, u32 *magic_val)
7556 u32 validity_offset;
7558 DP(NETIF_MSG_HW, "Starting\n");
7560 /* Set `magic' bit in order to save MF config */
7561 if (!CHIP_IS_E1(bp))
7562 bnx2x_clp_reset_prep(bp, magic_val);
7564 /* Get shmem offset */
7565 shmem = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
7566 validity_offset = offsetof(struct shmem_region, validity_map[0]);
7568 /* Clear validity map flags */
7570 REG_WR(bp, shmem + validity_offset, 0);
7573 #define MCP_TIMEOUT 5000 /* 5 seconds (in ms) */
7574 #define MCP_ONE_TIMEOUT 100 /* 100 ms */
7577 * bnx2x_mcp_wait_one - wait for MCP_ONE_TIMEOUT
7579 * @bp: driver handle
7581 static inline void bnx2x_mcp_wait_one(struct bnx2x *bp)
7583 /* special handling for emulation and FPGA,
7584 wait 10 times longer */
7585 if (CHIP_REV_IS_SLOW(bp))
7586 msleep(MCP_ONE_TIMEOUT*10);
7588 msleep(MCP_ONE_TIMEOUT);
7592 * initializes bp->common.shmem_base and waits for validity signature to appear
7594 static int bnx2x_init_shmem(struct bnx2x *bp)
7600 bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
7601 if (bp->common.shmem_base) {
7602 val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
7603 if (val & SHR_MEM_VALIDITY_MB)
7607 bnx2x_mcp_wait_one(bp);
7609 } while (cnt++ < (MCP_TIMEOUT / MCP_ONE_TIMEOUT));
7611 BNX2X_ERR("BAD MCP validity signature\n");
7616 static int bnx2x_reset_mcp_comp(struct bnx2x *bp, u32 magic_val)
7618 int rc = bnx2x_init_shmem(bp);
7620 /* Restore the `magic' bit value */
7621 if (!CHIP_IS_E1(bp))
7622 bnx2x_clp_reset_done(bp, magic_val);
7627 static void bnx2x_pxp_prep(struct bnx2x *bp)
7629 if (!CHIP_IS_E1(bp)) {
7630 REG_WR(bp, PXP2_REG_RD_START_INIT, 0);
7631 REG_WR(bp, PXP2_REG_RQ_RBC_DONE, 0);
7637 * Reset the whole chip except for:
7639 * - PCI Glue, PSWHST, PXP/PXP2 RF (all controlled by
7642 * - MISC (including AEU)
7646 static void bnx2x_process_kill_chip_reset(struct bnx2x *bp, bool global)
7648 u32 not_reset_mask1, reset_mask1, not_reset_mask2, reset_mask2;
7652 * Bits that have to be set in reset_mask2 if we want to reset 'global'
7653 * (per chip) blocks.
7656 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CPU |
7657 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CORE;
7660 MISC_REGISTERS_RESET_REG_1_RST_HC |
7661 MISC_REGISTERS_RESET_REG_1_RST_PXPV |
7662 MISC_REGISTERS_RESET_REG_1_RST_PXP;
7665 MISC_REGISTERS_RESET_REG_2_RST_PCI_MDIO |
7666 MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE |
7667 MISC_REGISTERS_RESET_REG_2_RST_EMAC1_HARD_CORE |
7668 MISC_REGISTERS_RESET_REG_2_RST_MISC_CORE |
7669 MISC_REGISTERS_RESET_REG_2_RST_RBCN |
7670 MISC_REGISTERS_RESET_REG_2_RST_GRC |
7671 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_REG_HARD_CORE |
7672 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_HARD_CORE_RST_B;
7674 reset_mask1 = 0xffffffff;
7677 reset_mask2 = 0xffff;
7679 reset_mask2 = 0x1ffff;
7681 if (CHIP_IS_E3(bp)) {
7682 reset_mask2 |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
7683 reset_mask2 |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
7686 /* Don't reset global blocks unless we need to */
7688 reset_mask2 &= ~global_bits2;
7691 * In case of attention in the QM, we need to reset PXP
7692 * (MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR) before QM
7693 * because otherwise QM reset would release 'close the gates' shortly
7694 * before resetting the PXP, then the PSWRQ would send a write
7695 * request to PGLUE. Then when PXP is reset, PGLUE would try to
7696 * read the payload data from PSWWR, but PSWWR would not
7697 * respond. The write queue in PGLUE would stuck, dmae commands
7698 * would not return. Therefore it's important to reset the second
7699 * reset register (containing the
7700 * MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR bit) before the
7701 * first one (containing the MISC_REGISTERS_RESET_REG_1_RST_QM
7704 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
7705 reset_mask2 & (~not_reset_mask2));
7707 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
7708 reset_mask1 & (~not_reset_mask1));
7713 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, reset_mask2);
7714 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, reset_mask1);
7719 * bnx2x_er_poll_igu_vq - poll for pending writes bit.
7720 * It should get cleared in no more than 1s.
7722 * @bp: driver handle
7724 * It should get cleared in no more than 1s. Returns 0 if
7725 * pending writes bit gets cleared.
7727 static int bnx2x_er_poll_igu_vq(struct bnx2x *bp)
7733 pend_bits = REG_RD(bp, IGU_REG_PENDING_BITS_STATUS);
7738 usleep_range(1000, 1000);
7739 } while (cnt-- > 0);
7742 BNX2X_ERR("Still pending IGU requests pend_bits=%x!\n",
7750 static int bnx2x_process_kill(struct bnx2x *bp, bool global)
7754 u32 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, pgl_exp_rom2;
7757 /* Empty the Tetris buffer, wait for 1s */
7759 sr_cnt = REG_RD(bp, PXP2_REG_RD_SR_CNT);
7760 blk_cnt = REG_RD(bp, PXP2_REG_RD_BLK_CNT);
7761 port_is_idle_0 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_0);
7762 port_is_idle_1 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_1);
7763 pgl_exp_rom2 = REG_RD(bp, PXP2_REG_PGL_EXP_ROM2);
7764 if ((sr_cnt == 0x7e) && (blk_cnt == 0xa0) &&
7765 ((port_is_idle_0 & 0x1) == 0x1) &&
7766 ((port_is_idle_1 & 0x1) == 0x1) &&
7767 (pgl_exp_rom2 == 0xffffffff))
7769 usleep_range(1000, 1000);
7770 } while (cnt-- > 0);
7773 DP(NETIF_MSG_HW, "Tetris buffer didn't get empty or there"
7775 " outstanding read requests after 1s!\n");
7776 DP(NETIF_MSG_HW, "sr_cnt=0x%08x, blk_cnt=0x%08x,"
7777 " port_is_idle_0=0x%08x,"
7778 " port_is_idle_1=0x%08x, pgl_exp_rom2=0x%08x\n",
7779 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1,
7786 /* Close gates #2, #3 and #4 */
7787 bnx2x_set_234_gates(bp, true);
7789 /* Poll for IGU VQs for 57712 and newer chips */
7790 if (!CHIP_IS_E1x(bp) && bnx2x_er_poll_igu_vq(bp))
7794 /* TBD: Indicate that "process kill" is in progress to MCP */
7796 /* Clear "unprepared" bit */
7797 REG_WR(bp, MISC_REG_UNPREPARED, 0);
7800 /* Make sure all is written to the chip before the reset */
7803 /* Wait for 1ms to empty GLUE and PCI-E core queues,
7804 * PSWHST, GRC and PSWRD Tetris buffer.
7806 usleep_range(1000, 1000);
7808 /* Prepare to chip reset: */
7811 bnx2x_reset_mcp_prep(bp, &val);
7817 /* reset the chip */
7818 bnx2x_process_kill_chip_reset(bp, global);
7821 /* Recover after reset: */
7823 if (global && bnx2x_reset_mcp_comp(bp, val))
7826 /* TBD: Add resetting the NO_MCP mode DB here */
7831 /* Open the gates #2, #3 and #4 */
7832 bnx2x_set_234_gates(bp, false);
7834 /* TBD: IGU/AEU preparation bring back the AEU/IGU to a
7835 * reset state, re-enable attentions. */
7840 int bnx2x_leader_reset(struct bnx2x *bp)
7843 bool global = bnx2x_reset_is_global(bp);
7845 /* Try to recover after the failure */
7846 if (bnx2x_process_kill(bp, global)) {
7847 netdev_err(bp->dev, "Something bad had happen on engine %d! "
7848 "Aii!\n", BP_PATH(bp));
7850 goto exit_leader_reset;
7854 * Clear RESET_IN_PROGRES and RESET_GLOBAL bits and update the driver
7857 bnx2x_set_reset_done(bp);
7859 bnx2x_clear_reset_global(bp);
7863 bnx2x_release_leader_lock(bp);
7868 static inline void bnx2x_recovery_failed(struct bnx2x *bp)
7870 netdev_err(bp->dev, "Recovery has failed. Power cycle is needed.\n");
7872 /* Disconnect this device */
7873 netif_device_detach(bp->dev);
7876 * Block ifup for all function on this engine until "process kill"
7879 bnx2x_set_reset_in_progress(bp);
7881 /* Shut down the power */
7882 bnx2x_set_power_state(bp, PCI_D3hot);
7884 bp->recovery_state = BNX2X_RECOVERY_FAILED;
7890 * Assumption: runs under rtnl lock. This together with the fact
7891 * that it's called only from bnx2x_reset_task() ensure that it
7892 * will never be called when netif_running(bp->dev) is false.
7894 static void bnx2x_parity_recover(struct bnx2x *bp)
7896 bool global = false;
7898 DP(NETIF_MSG_HW, "Handling parity\n");
7900 switch (bp->recovery_state) {
7901 case BNX2X_RECOVERY_INIT:
7902 DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_INIT\n");
7903 bnx2x_chk_parity_attn(bp, &global, false);
7905 /* Try to get a LEADER_LOCK HW lock */
7906 if (bnx2x_trylock_leader_lock(bp)) {
7907 bnx2x_set_reset_in_progress(bp);
7909 * Check if there is a global attention and if
7910 * there was a global attention, set the global
7915 bnx2x_set_reset_global(bp);
7920 /* Stop the driver */
7921 /* If interface has been removed - break */
7922 if (bnx2x_nic_unload(bp, UNLOAD_RECOVERY))
7925 bp->recovery_state = BNX2X_RECOVERY_WAIT;
7928 * Reset MCP command sequence number and MCP mail box
7929 * sequence as we are going to reset the MCP.
7933 bp->fw_drv_pulse_wr_seq = 0;
7936 /* Ensure "is_leader", MCP command sequence and
7937 * "recovery_state" update values are seen on other
7943 case BNX2X_RECOVERY_WAIT:
7944 DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_WAIT\n");
7945 if (bp->is_leader) {
7946 int other_engine = BP_PATH(bp) ? 0 : 1;
7947 u32 other_load_counter =
7948 bnx2x_get_load_cnt(bp, other_engine);
7950 bnx2x_get_load_cnt(bp, BP_PATH(bp));
7951 global = bnx2x_reset_is_global(bp);
7954 * In case of a parity in a global block, let
7955 * the first leader that performs a
7956 * leader_reset() reset the global blocks in
7957 * order to clear global attentions. Otherwise
7958 * the the gates will remain closed for that
7962 (global && other_load_counter)) {
7963 /* Wait until all other functions get
7966 schedule_delayed_work(&bp->reset_task,
7970 /* If all other functions got down -
7971 * try to bring the chip back to
7972 * normal. In any case it's an exit
7973 * point for a leader.
7975 if (bnx2x_leader_reset(bp)) {
7976 bnx2x_recovery_failed(bp);
7980 /* If we are here, means that the
7981 * leader has succeeded and doesn't
7982 * want to be a leader any more. Try
7983 * to continue as a none-leader.
7987 } else { /* non-leader */
7988 if (!bnx2x_reset_is_done(bp, BP_PATH(bp))) {
7989 /* Try to get a LEADER_LOCK HW lock as
7990 * long as a former leader may have
7991 * been unloaded by the user or
7992 * released a leadership by another
7995 if (bnx2x_trylock_leader_lock(bp)) {
7996 /* I'm a leader now! Restart a
8003 schedule_delayed_work(&bp->reset_task,
8009 * If there was a global attention, wait
8010 * for it to be cleared.
8012 if (bnx2x_reset_is_global(bp)) {
8013 schedule_delayed_work(
8014 &bp->reset_task, HZ/10);
8018 if (bnx2x_nic_load(bp, LOAD_NORMAL))
8019 bnx2x_recovery_failed(bp);
8021 bp->recovery_state =
8022 BNX2X_RECOVERY_DONE;
8035 /* bnx2x_nic_unload() flushes the bnx2x_wq, thus reset task is
8036 * scheduled on a general queue in order to prevent a dead lock.
8038 static void bnx2x_reset_task(struct work_struct *work)
8040 struct bnx2x *bp = container_of(work, struct bnx2x, reset_task.work);
8042 #ifdef BNX2X_STOP_ON_ERROR
8043 BNX2X_ERR("reset task called but STOP_ON_ERROR defined"
8044 " so reset not done to allow debug dump,\n"
8045 KERN_ERR " you will need to reboot when done\n");
8051 if (!netif_running(bp->dev))
8052 goto reset_task_exit;
8054 if (unlikely(bp->recovery_state != BNX2X_RECOVERY_DONE))
8055 bnx2x_parity_recover(bp);
8057 bnx2x_nic_unload(bp, UNLOAD_NORMAL);
8058 bnx2x_nic_load(bp, LOAD_NORMAL);
8065 /* end of nic load/unload */
8067 static void bnx2x_period_task(struct work_struct *work)
8069 struct bnx2x *bp = container_of(work, struct bnx2x, period_task.work);
8071 if (!netif_running(bp->dev))
8072 goto period_task_exit;
8074 if (CHIP_REV_IS_SLOW(bp)) {
8075 BNX2X_ERR("period task called on emulation, ignoring\n");
8076 goto period_task_exit;
8079 bnx2x_acquire_phy_lock(bp);
8081 * The barrier is needed to ensure the ordering between the writing to
8082 * the bp->port.pmf in the bnx2x_nic_load() or bnx2x_pmf_update() and
8087 bnx2x_period_func(&bp->link_params, &bp->link_vars);
8089 /* Re-queue task in 1 sec */
8090 queue_delayed_work(bnx2x_wq, &bp->period_task, 1*HZ);
8093 bnx2x_release_phy_lock(bp);
8099 * Init service functions
8102 static u32 bnx2x_get_pretend_reg(struct bnx2x *bp)
8104 u32 base = PXP2_REG_PGL_PRETEND_FUNC_F0;
8105 u32 stride = PXP2_REG_PGL_PRETEND_FUNC_F1 - base;
8106 return base + (BP_ABS_FUNC(bp)) * stride;
8109 static void bnx2x_undi_int_disable_e1h(struct bnx2x *bp)
8111 u32 reg = bnx2x_get_pretend_reg(bp);
8113 /* Flush all outstanding writes */
8116 /* Pretend to be function 0 */
8118 REG_RD(bp, reg); /* Flush the GRC transaction (in the chip) */
8120 /* From now we are in the "like-E1" mode */
8121 bnx2x_int_disable(bp);
8123 /* Flush all outstanding writes */
8126 /* Restore the original function */
8127 REG_WR(bp, reg, BP_ABS_FUNC(bp));
8131 static inline void bnx2x_undi_int_disable(struct bnx2x *bp)
8134 bnx2x_int_disable(bp);
8136 bnx2x_undi_int_disable_e1h(bp);
8139 static void __devinit bnx2x_undi_unload(struct bnx2x *bp)
8143 /* Check if there is any driver already loaded */
8144 val = REG_RD(bp, MISC_REG_UNPREPARED);
8146 /* Check if it is the UNDI driver
8147 * UNDI driver initializes CID offset for normal bell to 0x7
8149 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_UNDI);
8150 val = REG_RD(bp, DORQ_REG_NORM_CID_OFST);
8152 u32 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
8153 /* save our pf_num */
8154 int orig_pf_num = bp->pf_num;
8156 u32 swap_en, swap_val, value;
8158 /* clear the UNDI indication */
8159 REG_WR(bp, DORQ_REG_NORM_CID_OFST, 0);
8161 BNX2X_DEV_INFO("UNDI is active! reset device\n");
8163 /* try unload UNDI on port 0 */
8166 (SHMEM_RD(bp, func_mb[bp->pf_num].drv_mb_header) &
8167 DRV_MSG_SEQ_NUMBER_MASK);
8168 reset_code = bnx2x_fw_command(bp, reset_code, 0);
8170 /* if UNDI is loaded on the other port */
8171 if (reset_code != FW_MSG_CODE_DRV_UNLOAD_COMMON) {
8173 /* send "DONE" for previous unload */
8174 bnx2x_fw_command(bp,
8175 DRV_MSG_CODE_UNLOAD_DONE, 0);
8177 /* unload UNDI on port 1 */
8180 (SHMEM_RD(bp, func_mb[bp->pf_num].drv_mb_header) &
8181 DRV_MSG_SEQ_NUMBER_MASK);
8182 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
8184 bnx2x_fw_command(bp, reset_code, 0);
8187 /* now it's safe to release the lock */
8188 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_UNDI);
8190 bnx2x_undi_int_disable(bp);
8193 /* close input traffic and wait for it */
8194 /* Do not rcv packets to BRB */
8195 REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_DRV_MASK :
8196 NIG_REG_LLH0_BRB1_DRV_MASK), 0x0);
8197 /* Do not direct rcv packets that are not for MCP to
8199 REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
8200 NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
8202 REG_WR(bp, (port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
8203 MISC_REG_AEU_MASK_ATTN_FUNC_0), 0);
8206 /* save NIG port swap info */
8207 swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
8208 swap_en = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
8211 GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
8215 if (CHIP_IS_E3(bp)) {
8216 value |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
8217 value |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
8221 GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
8224 /* take the NIG out of reset and restore swap values */
8226 GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
8227 MISC_REGISTERS_RESET_REG_1_RST_NIG);
8228 REG_WR(bp, NIG_REG_PORT_SWAP, swap_val);
8229 REG_WR(bp, NIG_REG_STRAP_OVERRIDE, swap_en);
8231 /* send unload done to the MCP */
8232 bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
8234 /* restore our func and fw_seq */
8235 bp->pf_num = orig_pf_num;
8237 (SHMEM_RD(bp, func_mb[bp->pf_num].drv_mb_header) &
8238 DRV_MSG_SEQ_NUMBER_MASK);
8240 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_UNDI);
8244 static void __devinit bnx2x_get_common_hwinfo(struct bnx2x *bp)
8246 u32 val, val2, val3, val4, id;
8249 /* Get the chip revision id and number. */
8250 /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
8251 val = REG_RD(bp, MISC_REG_CHIP_NUM);
8252 id = ((val & 0xffff) << 16);
8253 val = REG_RD(bp, MISC_REG_CHIP_REV);
8254 id |= ((val & 0xf) << 12);
8255 val = REG_RD(bp, MISC_REG_CHIP_METAL);
8256 id |= ((val & 0xff) << 4);
8257 val = REG_RD(bp, MISC_REG_BOND_ID);
8259 bp->common.chip_id = id;
8261 /* Set doorbell size */
8262 bp->db_size = (1 << BNX2X_DB_SHIFT);
8264 if (!CHIP_IS_E1x(bp)) {
8265 val = REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR);
8267 val = REG_RD(bp, MISC_REG_PORT4MODE_EN);
8269 val = (val >> 1) & 1;
8270 BNX2X_DEV_INFO("chip is in %s\n", val ? "4_PORT_MODE" :
8272 bp->common.chip_port_mode = val ? CHIP_4_PORT_MODE :
8275 if (CHIP_MODE_IS_4_PORT(bp))
8276 bp->pfid = (bp->pf_num >> 1); /* 0..3 */
8278 bp->pfid = (bp->pf_num & 0x6); /* 0, 2, 4, 6 */
8280 bp->common.chip_port_mode = CHIP_PORT_MODE_NONE; /* N/A */
8281 bp->pfid = bp->pf_num; /* 0..7 */
8284 bp->link_params.chip_id = bp->common.chip_id;
8285 BNX2X_DEV_INFO("chip ID is 0x%x\n", id);
8287 val = (REG_RD(bp, 0x2874) & 0x55);
8288 if ((bp->common.chip_id & 0x1) ||
8289 (CHIP_IS_E1(bp) && val) || (CHIP_IS_E1H(bp) && (val == 0x55))) {
8290 bp->flags |= ONE_PORT_FLAG;
8291 BNX2X_DEV_INFO("single port device\n");
8294 val = REG_RD(bp, MCP_REG_MCPR_NVM_CFG4);
8295 bp->common.flash_size = (BNX2X_NVRAM_1MB_SIZE <<
8296 (val & MCPR_NVM_CFG4_FLASH_SIZE));
8297 BNX2X_DEV_INFO("flash_size 0x%x (%d)\n",
8298 bp->common.flash_size, bp->common.flash_size);
8300 bnx2x_init_shmem(bp);
8304 bp->common.shmem2_base = REG_RD(bp, (BP_PATH(bp) ?
8305 MISC_REG_GENERIC_CR_1 :
8306 MISC_REG_GENERIC_CR_0));
8308 bp->link_params.shmem_base = bp->common.shmem_base;
8309 bp->link_params.shmem2_base = bp->common.shmem2_base;
8310 BNX2X_DEV_INFO("shmem offset 0x%x shmem2 offset 0x%x\n",
8311 bp->common.shmem_base, bp->common.shmem2_base);
8313 if (!bp->common.shmem_base) {
8314 BNX2X_DEV_INFO("MCP not active\n");
8315 bp->flags |= NO_MCP_FLAG;
8319 bp->common.hw_config = SHMEM_RD(bp, dev_info.shared_hw_config.config);
8320 BNX2X_DEV_INFO("hw_config 0x%08x\n", bp->common.hw_config);
8322 bp->link_params.hw_led_mode = ((bp->common.hw_config &
8323 SHARED_HW_CFG_LED_MODE_MASK) >>
8324 SHARED_HW_CFG_LED_MODE_SHIFT);
8326 bp->link_params.feature_config_flags = 0;
8327 val = SHMEM_RD(bp, dev_info.shared_feature_config.config);
8328 if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED)
8329 bp->link_params.feature_config_flags |=
8330 FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
8332 bp->link_params.feature_config_flags &=
8333 ~FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
8335 val = SHMEM_RD(bp, dev_info.bc_rev) >> 8;
8336 bp->common.bc_ver = val;
8337 BNX2X_DEV_INFO("bc_ver %X\n", val);
8338 if (val < BNX2X_BC_VER) {
8339 /* for now only warn
8340 * later we might need to enforce this */
8341 BNX2X_ERR("This driver needs bc_ver %X but found %X, "
8342 "please upgrade BC\n", BNX2X_BC_VER, val);
8344 bp->link_params.feature_config_flags |=
8345 (val >= REQ_BC_VER_4_VRFY_FIRST_PHY_OPT_MDL) ?
8346 FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY : 0;
8348 bp->link_params.feature_config_flags |=
8349 (val >= REQ_BC_VER_4_VRFY_SPECIFIC_PHY_OPT_MDL) ?
8350 FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY : 0;
8352 pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_PMC, &pmc);
8353 bp->flags |= (pmc & PCI_PM_CAP_PME_D3cold) ? 0 : NO_WOL_FLAG;
8355 BNX2X_DEV_INFO("%sWoL capable\n",
8356 (bp->flags & NO_WOL_FLAG) ? "not " : "");
8358 val = SHMEM_RD(bp, dev_info.shared_hw_config.part_num);
8359 val2 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[4]);
8360 val3 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[8]);
8361 val4 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[12]);
8363 dev_info(&bp->pdev->dev, "part number %X-%X-%X-%X\n",
8364 val, val2, val3, val4);
8367 #define IGU_FID(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID)
8368 #define IGU_VEC(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR)
8370 static void __devinit bnx2x_get_igu_cam_info(struct bnx2x *bp)
8372 int pfid = BP_FUNC(bp);
8373 int vn = BP_E1HVN(bp);
8378 bp->igu_base_sb = 0xff;
8380 if (CHIP_INT_MODE_IS_BC(bp)) {
8381 bp->igu_sb_cnt = min_t(u8, FP_SB_MAX_E1x,
8382 NUM_IGU_SB_REQUIRED(bp->l2_cid_count));
8384 bp->igu_base_sb = (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn) *
8387 bp->igu_dsb_id = E1HVN_MAX * FP_SB_MAX_E1x +
8388 (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn);
8393 /* IGU in normal mode - read CAM */
8394 for (igu_sb_id = 0; igu_sb_id < IGU_REG_MAPPING_MEMORY_SIZE;
8396 val = REG_RD(bp, IGU_REG_MAPPING_MEMORY + igu_sb_id * 4);
8397 if (!(val & IGU_REG_MAPPING_MEMORY_VALID))
8400 if ((fid & IGU_FID_ENCODE_IS_PF)) {
8401 if ((fid & IGU_FID_PF_NUM_MASK) != pfid)
8403 if (IGU_VEC(val) == 0)
8404 /* default status block */
8405 bp->igu_dsb_id = igu_sb_id;
8407 if (bp->igu_base_sb == 0xff)
8408 bp->igu_base_sb = igu_sb_id;
8414 /* It's expected that number of CAM entries for this
8415 * functions is equal to the MSI-X table size (which was a
8416 * used during bp->l2_cid_count value calculation.
8417 * We want a harsh warning if these values are different!
8419 WARN_ON(bp->igu_sb_cnt != NUM_IGU_SB_REQUIRED(bp->l2_cid_count));
8421 if (bp->igu_sb_cnt == 0)
8422 BNX2X_ERR("CAM configuration error\n");
8425 static void __devinit bnx2x_link_settings_supported(struct bnx2x *bp,
8428 int cfg_size = 0, idx, port = BP_PORT(bp);
8430 /* Aggregation of supported attributes of all external phys */
8431 bp->port.supported[0] = 0;
8432 bp->port.supported[1] = 0;
8433 switch (bp->link_params.num_phys) {
8435 bp->port.supported[0] = bp->link_params.phy[INT_PHY].supported;
8439 bp->port.supported[0] = bp->link_params.phy[EXT_PHY1].supported;
8443 if (bp->link_params.multi_phy_config &
8444 PORT_HW_CFG_PHY_SWAPPED_ENABLED) {
8445 bp->port.supported[1] =
8446 bp->link_params.phy[EXT_PHY1].supported;
8447 bp->port.supported[0] =
8448 bp->link_params.phy[EXT_PHY2].supported;
8450 bp->port.supported[0] =
8451 bp->link_params.phy[EXT_PHY1].supported;
8452 bp->port.supported[1] =
8453 bp->link_params.phy[EXT_PHY2].supported;
8459 if (!(bp->port.supported[0] || bp->port.supported[1])) {
8460 BNX2X_ERR("NVRAM config error. BAD phy config."
8461 "PHY1 config 0x%x, PHY2 config 0x%x\n",
8463 dev_info.port_hw_config[port].external_phy_config),
8465 dev_info.port_hw_config[port].external_phy_config2));
8470 bp->port.phy_addr = REG_RD(bp, MISC_REG_WC0_CTRL_PHY_ADDR);
8472 switch (switch_cfg) {
8474 bp->port.phy_addr = REG_RD(
8475 bp, NIG_REG_SERDES0_CTRL_PHY_ADDR + port*0x10);
8477 case SWITCH_CFG_10G:
8478 bp->port.phy_addr = REG_RD(
8479 bp, NIG_REG_XGXS0_CTRL_PHY_ADDR + port*0x18);
8482 BNX2X_ERR("BAD switch_cfg link_config 0x%x\n",
8483 bp->port.link_config[0]);
8487 BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr);
8488 /* mask what we support according to speed_cap_mask per configuration */
8489 for (idx = 0; idx < cfg_size; idx++) {
8490 if (!(bp->link_params.speed_cap_mask[idx] &
8491 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF))
8492 bp->port.supported[idx] &= ~SUPPORTED_10baseT_Half;
8494 if (!(bp->link_params.speed_cap_mask[idx] &
8495 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL))
8496 bp->port.supported[idx] &= ~SUPPORTED_10baseT_Full;
8498 if (!(bp->link_params.speed_cap_mask[idx] &
8499 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF))
8500 bp->port.supported[idx] &= ~SUPPORTED_100baseT_Half;
8502 if (!(bp->link_params.speed_cap_mask[idx] &
8503 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL))
8504 bp->port.supported[idx] &= ~SUPPORTED_100baseT_Full;
8506 if (!(bp->link_params.speed_cap_mask[idx] &
8507 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G))
8508 bp->port.supported[idx] &= ~(SUPPORTED_1000baseT_Half |
8509 SUPPORTED_1000baseT_Full);
8511 if (!(bp->link_params.speed_cap_mask[idx] &
8512 PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
8513 bp->port.supported[idx] &= ~SUPPORTED_2500baseX_Full;
8515 if (!(bp->link_params.speed_cap_mask[idx] &
8516 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G))
8517 bp->port.supported[idx] &= ~SUPPORTED_10000baseT_Full;
8521 BNX2X_DEV_INFO("supported 0x%x 0x%x\n", bp->port.supported[0],
8522 bp->port.supported[1]);
8525 static void __devinit bnx2x_link_settings_requested(struct bnx2x *bp)
8527 u32 link_config, idx, cfg_size = 0;
8528 bp->port.advertising[0] = 0;
8529 bp->port.advertising[1] = 0;
8530 switch (bp->link_params.num_phys) {
8539 for (idx = 0; idx < cfg_size; idx++) {
8540 bp->link_params.req_duplex[idx] = DUPLEX_FULL;
8541 link_config = bp->port.link_config[idx];
8542 switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) {
8543 case PORT_FEATURE_LINK_SPEED_AUTO:
8544 if (bp->port.supported[idx] & SUPPORTED_Autoneg) {
8545 bp->link_params.req_line_speed[idx] =
8547 bp->port.advertising[idx] |=
8548 bp->port.supported[idx];
8550 /* force 10G, no AN */
8551 bp->link_params.req_line_speed[idx] =
8553 bp->port.advertising[idx] |=
8554 (ADVERTISED_10000baseT_Full |
8560 case PORT_FEATURE_LINK_SPEED_10M_FULL:
8561 if (bp->port.supported[idx] & SUPPORTED_10baseT_Full) {
8562 bp->link_params.req_line_speed[idx] =
8564 bp->port.advertising[idx] |=
8565 (ADVERTISED_10baseT_Full |
8568 BNX2X_ERR("NVRAM config error. "
8569 "Invalid link_config 0x%x"
8570 " speed_cap_mask 0x%x\n",
8572 bp->link_params.speed_cap_mask[idx]);
8577 case PORT_FEATURE_LINK_SPEED_10M_HALF:
8578 if (bp->port.supported[idx] & SUPPORTED_10baseT_Half) {
8579 bp->link_params.req_line_speed[idx] =
8581 bp->link_params.req_duplex[idx] =
8583 bp->port.advertising[idx] |=
8584 (ADVERTISED_10baseT_Half |
8587 BNX2X_ERR("NVRAM config error. "
8588 "Invalid link_config 0x%x"
8589 " speed_cap_mask 0x%x\n",
8591 bp->link_params.speed_cap_mask[idx]);
8596 case PORT_FEATURE_LINK_SPEED_100M_FULL:
8597 if (bp->port.supported[idx] &
8598 SUPPORTED_100baseT_Full) {
8599 bp->link_params.req_line_speed[idx] =
8601 bp->port.advertising[idx] |=
8602 (ADVERTISED_100baseT_Full |
8605 BNX2X_ERR("NVRAM config error. "
8606 "Invalid link_config 0x%x"
8607 " speed_cap_mask 0x%x\n",
8609 bp->link_params.speed_cap_mask[idx]);
8614 case PORT_FEATURE_LINK_SPEED_100M_HALF:
8615 if (bp->port.supported[idx] &
8616 SUPPORTED_100baseT_Half) {
8617 bp->link_params.req_line_speed[idx] =
8619 bp->link_params.req_duplex[idx] =
8621 bp->port.advertising[idx] |=
8622 (ADVERTISED_100baseT_Half |
8625 BNX2X_ERR("NVRAM config error. "
8626 "Invalid link_config 0x%x"
8627 " speed_cap_mask 0x%x\n",
8629 bp->link_params.speed_cap_mask[idx]);
8634 case PORT_FEATURE_LINK_SPEED_1G:
8635 if (bp->port.supported[idx] &
8636 SUPPORTED_1000baseT_Full) {
8637 bp->link_params.req_line_speed[idx] =
8639 bp->port.advertising[idx] |=
8640 (ADVERTISED_1000baseT_Full |
8643 BNX2X_ERR("NVRAM config error. "
8644 "Invalid link_config 0x%x"
8645 " speed_cap_mask 0x%x\n",
8647 bp->link_params.speed_cap_mask[idx]);
8652 case PORT_FEATURE_LINK_SPEED_2_5G:
8653 if (bp->port.supported[idx] &
8654 SUPPORTED_2500baseX_Full) {
8655 bp->link_params.req_line_speed[idx] =
8657 bp->port.advertising[idx] |=
8658 (ADVERTISED_2500baseX_Full |
8661 BNX2X_ERR("NVRAM config error. "
8662 "Invalid link_config 0x%x"
8663 " speed_cap_mask 0x%x\n",
8665 bp->link_params.speed_cap_mask[idx]);
8670 case PORT_FEATURE_LINK_SPEED_10G_CX4:
8671 if (bp->port.supported[idx] &
8672 SUPPORTED_10000baseT_Full) {
8673 bp->link_params.req_line_speed[idx] =
8675 bp->port.advertising[idx] |=
8676 (ADVERTISED_10000baseT_Full |
8679 BNX2X_ERR("NVRAM config error. "
8680 "Invalid link_config 0x%x"
8681 " speed_cap_mask 0x%x\n",
8683 bp->link_params.speed_cap_mask[idx]);
8687 case PORT_FEATURE_LINK_SPEED_20G:
8688 bp->link_params.req_line_speed[idx] = SPEED_20000;
8692 BNX2X_ERR("NVRAM config error. "
8693 "BAD link speed link_config 0x%x\n",
8695 bp->link_params.req_line_speed[idx] =
8697 bp->port.advertising[idx] =
8698 bp->port.supported[idx];
8702 bp->link_params.req_flow_ctrl[idx] = (link_config &
8703 PORT_FEATURE_FLOW_CONTROL_MASK);
8704 if ((bp->link_params.req_flow_ctrl[idx] ==
8705 BNX2X_FLOW_CTRL_AUTO) &&
8706 !(bp->port.supported[idx] & SUPPORTED_Autoneg)) {
8707 bp->link_params.req_flow_ctrl[idx] =
8708 BNX2X_FLOW_CTRL_NONE;
8711 BNX2X_DEV_INFO("req_line_speed %d req_duplex %d req_flow_ctrl"
8712 " 0x%x advertising 0x%x\n",
8713 bp->link_params.req_line_speed[idx],
8714 bp->link_params.req_duplex[idx],
8715 bp->link_params.req_flow_ctrl[idx],
8716 bp->port.advertising[idx]);
8720 static void __devinit bnx2x_set_mac_buf(u8 *mac_buf, u32 mac_lo, u16 mac_hi)
8722 mac_hi = cpu_to_be16(mac_hi);
8723 mac_lo = cpu_to_be32(mac_lo);
8724 memcpy(mac_buf, &mac_hi, sizeof(mac_hi));
8725 memcpy(mac_buf + sizeof(mac_hi), &mac_lo, sizeof(mac_lo));
8728 static void __devinit bnx2x_get_port_hwinfo(struct bnx2x *bp)
8730 int port = BP_PORT(bp);
8732 u32 ext_phy_type, ext_phy_config;
8734 bp->link_params.bp = bp;
8735 bp->link_params.port = port;
8737 bp->link_params.lane_config =
8738 SHMEM_RD(bp, dev_info.port_hw_config[port].lane_config);
8740 bp->link_params.speed_cap_mask[0] =
8742 dev_info.port_hw_config[port].speed_capability_mask);
8743 bp->link_params.speed_cap_mask[1] =
8745 dev_info.port_hw_config[port].speed_capability_mask2);
8746 bp->port.link_config[0] =
8747 SHMEM_RD(bp, dev_info.port_feature_config[port].link_config);
8749 bp->port.link_config[1] =
8750 SHMEM_RD(bp, dev_info.port_feature_config[port].link_config2);
8752 bp->link_params.multi_phy_config =
8753 SHMEM_RD(bp, dev_info.port_hw_config[port].multi_phy_config);
8754 /* If the device is capable of WoL, set the default state according
8757 config = SHMEM_RD(bp, dev_info.port_feature_config[port].config);
8758 bp->wol = (!(bp->flags & NO_WOL_FLAG) &&
8759 (config & PORT_FEATURE_WOL_ENABLED));
8761 BNX2X_DEV_INFO("lane_config 0x%08x "
8762 "speed_cap_mask0 0x%08x link_config0 0x%08x\n",
8763 bp->link_params.lane_config,
8764 bp->link_params.speed_cap_mask[0],
8765 bp->port.link_config[0]);
8767 bp->link_params.switch_cfg = (bp->port.link_config[0] &
8768 PORT_FEATURE_CONNECTED_SWITCH_MASK);
8769 bnx2x_phy_probe(&bp->link_params);
8770 bnx2x_link_settings_supported(bp, bp->link_params.switch_cfg);
8772 bnx2x_link_settings_requested(bp);
8775 * If connected directly, work with the internal PHY, otherwise, work
8776 * with the external PHY
8780 dev_info.port_hw_config[port].external_phy_config);
8781 ext_phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
8782 if (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
8783 bp->mdio.prtad = bp->port.phy_addr;
8785 else if ((ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) &&
8786 (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN))
8788 XGXS_EXT_PHY_ADDR(ext_phy_config);
8791 * Check if hw lock is required to access MDC/MDIO bus to the PHY(s)
8792 * In MF mode, it is set to cover self test cases
8795 bp->port.need_hw_lock = 1;
8797 bp->port.need_hw_lock = bnx2x_hw_lock_required(bp,
8798 bp->common.shmem_base,
8799 bp->common.shmem2_base);
8803 static void __devinit bnx2x_get_cnic_info(struct bnx2x *bp)
8805 u32 max_iscsi_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
8806 drv_lic_key[BP_PORT(bp)].max_iscsi_conn);
8807 u32 max_fcoe_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
8808 drv_lic_key[BP_PORT(bp)].max_fcoe_conn);
8810 /* Get the number of maximum allowed iSCSI and FCoE connections */
8811 bp->cnic_eth_dev.max_iscsi_conn =
8812 (max_iscsi_conn & BNX2X_MAX_ISCSI_INIT_CONN_MASK) >>
8813 BNX2X_MAX_ISCSI_INIT_CONN_SHIFT;
8815 bp->cnic_eth_dev.max_fcoe_conn =
8816 (max_fcoe_conn & BNX2X_MAX_FCOE_INIT_CONN_MASK) >>
8817 BNX2X_MAX_FCOE_INIT_CONN_SHIFT;
8819 BNX2X_DEV_INFO("max_iscsi_conn 0x%x max_fcoe_conn 0x%x\n",
8820 bp->cnic_eth_dev.max_iscsi_conn,
8821 bp->cnic_eth_dev.max_fcoe_conn);
8823 /* If mamimum allowed number of connections is zero -
8824 * disable the feature.
8826 if (!bp->cnic_eth_dev.max_iscsi_conn)
8827 bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
8829 if (!bp->cnic_eth_dev.max_fcoe_conn)
8830 bp->flags |= NO_FCOE_FLAG;
8834 static void __devinit bnx2x_get_mac_hwinfo(struct bnx2x *bp)
8837 int func = BP_ABS_FUNC(bp);
8838 int port = BP_PORT(bp);
8840 u8 *iscsi_mac = bp->cnic_eth_dev.iscsi_mac;
8841 u8 *fip_mac = bp->fip_mac;
8844 /* Zero primary MAC configuration */
8845 memset(bp->dev->dev_addr, 0, ETH_ALEN);
8848 BNX2X_ERROR("warning: random MAC workaround active\n");
8849 random_ether_addr(bp->dev->dev_addr);
8850 } else if (IS_MF(bp)) {
8851 val2 = MF_CFG_RD(bp, func_mf_config[func].mac_upper);
8852 val = MF_CFG_RD(bp, func_mf_config[func].mac_lower);
8853 if ((val2 != FUNC_MF_CFG_UPPERMAC_DEFAULT) &&
8854 (val != FUNC_MF_CFG_LOWERMAC_DEFAULT))
8855 bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
8858 /* iSCSI and FCoE NPAR MACs: if there is no either iSCSI or
8859 * FCoE MAC then the appropriate feature should be disabled.
8862 u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg);
8863 if (cfg & MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD) {
8864 val2 = MF_CFG_RD(bp, func_ext_config[func].
8865 iscsi_mac_addr_upper);
8866 val = MF_CFG_RD(bp, func_ext_config[func].
8867 iscsi_mac_addr_lower);
8868 bnx2x_set_mac_buf(iscsi_mac, val, val2);
8869 BNX2X_DEV_INFO("Read iSCSI MAC: "
8871 BNX2X_MAC_PRN_LIST(iscsi_mac));
8873 bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
8875 if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD) {
8876 val2 = MF_CFG_RD(bp, func_ext_config[func].
8877 fcoe_mac_addr_upper);
8878 val = MF_CFG_RD(bp, func_ext_config[func].
8879 fcoe_mac_addr_lower);
8880 bnx2x_set_mac_buf(fip_mac, val, val2);
8881 BNX2X_DEV_INFO("Read FCoE L2 MAC to "
8883 BNX2X_MAC_PRN_LIST(fip_mac));
8886 bp->flags |= NO_FCOE_FLAG;
8890 /* in SF read MACs from port configuration */
8891 val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
8892 val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
8893 bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
8896 val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
8898 val = SHMEM_RD(bp, dev_info.port_hw_config[port].
8900 bnx2x_set_mac_buf(iscsi_mac, val, val2);
8904 memcpy(bp->link_params.mac_addr, bp->dev->dev_addr, ETH_ALEN);
8905 memcpy(bp->dev->perm_addr, bp->dev->dev_addr, ETH_ALEN);
8908 /* Set the FCoE MAC in modes other then MF_SI */
8909 if (!CHIP_IS_E1x(bp)) {
8911 memcpy(fip_mac, bp->dev->dev_addr, ETH_ALEN);
8912 else if (!IS_MF(bp))
8913 memcpy(fip_mac, iscsi_mac, ETH_ALEN);
8916 /* Disable iSCSI if MAC configuration is
8919 if (!is_valid_ether_addr(iscsi_mac)) {
8920 bp->flags |= NO_ISCSI_FLAG;
8921 memset(iscsi_mac, 0, ETH_ALEN);
8924 /* Disable FCoE if MAC configuration is
8927 if (!is_valid_ether_addr(fip_mac)) {
8928 bp->flags |= NO_FCOE_FLAG;
8929 memset(bp->fip_mac, 0, ETH_ALEN);
8933 if (!is_valid_ether_addr(bp->dev->dev_addr))
8934 dev_err(&bp->pdev->dev,
8935 "bad Ethernet MAC address configuration: "
8936 BNX2X_MAC_FMT", change it manually before bringing up "
8937 "the appropriate network interface\n",
8938 BNX2X_MAC_PRN_LIST(bp->dev->dev_addr));
8941 static int __devinit bnx2x_get_hwinfo(struct bnx2x *bp)
8943 int /*abs*/func = BP_ABS_FUNC(bp);
8948 bnx2x_get_common_hwinfo(bp);
8950 if (CHIP_IS_E1x(bp)) {
8951 bp->common.int_block = INT_BLOCK_HC;
8953 bp->igu_dsb_id = DEF_SB_IGU_ID;
8954 bp->igu_base_sb = 0;
8955 bp->igu_sb_cnt = min_t(u8, FP_SB_MAX_E1x,
8956 NUM_IGU_SB_REQUIRED(bp->l2_cid_count));
8958 bp->common.int_block = INT_BLOCK_IGU;
8959 val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
8961 if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
8964 BNX2X_DEV_INFO("FORCING Normal Mode\n");
8966 val &= ~(IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN);
8967 REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION, val);
8968 REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x7f);
8970 while (tout && REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
8972 usleep_range(1000, 1000);
8975 if (REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
8976 dev_err(&bp->pdev->dev,
8977 "FORCING Normal Mode failed!!!\n");
8982 if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
8983 BNX2X_DEV_INFO("IGU Backward Compatible Mode\n");
8984 bp->common.int_block |= INT_BLOCK_MODE_BW_COMP;
8986 BNX2X_DEV_INFO("IGU Normal Mode\n");
8988 bnx2x_get_igu_cam_info(bp);
8993 * set base FW non-default (fast path) status block id, this value is
8994 * used to initialize the fw_sb_id saved on the fp/queue structure to
8995 * determine the id used by the FW.
8997 if (CHIP_IS_E1x(bp))
8998 bp->base_fw_ndsb = BP_PORT(bp) * FP_SB_MAX_E1x + BP_L_ID(bp);
9000 * 57712 - we currently use one FW SB per IGU SB (Rx and Tx of
9001 * the same queue are indicated on the same IGU SB). So we prefer
9002 * FW and IGU SBs to be the same value.
9004 bp->base_fw_ndsb = bp->igu_base_sb;
9006 BNX2X_DEV_INFO("igu_dsb_id %d igu_base_sb %d igu_sb_cnt %d\n"
9007 "base_fw_ndsb %d\n", bp->igu_dsb_id, bp->igu_base_sb,
9008 bp->igu_sb_cnt, bp->base_fw_ndsb);
9011 * Initialize MF configuration
9018 if (!CHIP_IS_E1(bp) && !BP_NOMCP(bp)) {
9019 BNX2X_DEV_INFO("shmem2base 0x%x, size %d, mfcfg offset %d\n",
9020 bp->common.shmem2_base, SHMEM2_RD(bp, size),
9021 (u32)offsetof(struct shmem2_region, mf_cfg_addr));
9023 if (SHMEM2_HAS(bp, mf_cfg_addr))
9024 bp->common.mf_cfg_base = SHMEM2_RD(bp, mf_cfg_addr);
9026 bp->common.mf_cfg_base = bp->common.shmem_base +
9027 offsetof(struct shmem_region, func_mb) +
9028 E1H_FUNC_MAX * sizeof(struct drv_func_mb);
9030 * get mf configuration:
9031 * 1. existence of MF configuration
9032 * 2. MAC address must be legal (check only upper bytes)
9033 * for Switch-Independent mode;
9034 * OVLAN must be legal for Switch-Dependent mode
9035 * 3. SF_MODE configures specific MF mode
9037 if (bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
9038 /* get mf configuration */
9040 dev_info.shared_feature_config.config);
9041 val &= SHARED_FEAT_CFG_FORCE_SF_MODE_MASK;
9044 case SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT:
9045 val = MF_CFG_RD(bp, func_mf_config[func].
9047 /* check for legal mac (upper bytes)*/
9048 if (val != 0xffff) {
9049 bp->mf_mode = MULTI_FUNCTION_SI;
9050 bp->mf_config[vn] = MF_CFG_RD(bp,
9051 func_mf_config[func].config);
9053 BNX2X_DEV_INFO("illegal MAC address "
9056 case SHARED_FEAT_CFG_FORCE_SF_MODE_MF_ALLOWED:
9057 /* get OV configuration */
9059 func_mf_config[FUNC_0].e1hov_tag);
9060 val &= FUNC_MF_CFG_E1HOV_TAG_MASK;
9062 if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
9063 bp->mf_mode = MULTI_FUNCTION_SD;
9064 bp->mf_config[vn] = MF_CFG_RD(bp,
9065 func_mf_config[func].config);
9067 BNX2X_DEV_INFO("illegal OV for SD\n");
9070 /* Unknown configuration: reset mf_config */
9071 bp->mf_config[vn] = 0;
9072 BNX2X_DEV_INFO("unkown MF mode 0x%x\n", val);
9076 BNX2X_DEV_INFO("%s function mode\n",
9077 IS_MF(bp) ? "multi" : "single");
9079 switch (bp->mf_mode) {
9080 case MULTI_FUNCTION_SD:
9081 val = MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
9082 FUNC_MF_CFG_E1HOV_TAG_MASK;
9083 if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
9085 bp->path_has_ovlan = true;
9087 BNX2X_DEV_INFO("MF OV for func %d is %d "
9088 "(0x%04x)\n", func, bp->mf_ov,
9091 dev_err(&bp->pdev->dev,
9092 "No valid MF OV for func %d, "
9093 "aborting\n", func);
9097 case MULTI_FUNCTION_SI:
9098 BNX2X_DEV_INFO("func %d is in MF "
9099 "switch-independent mode\n", func);
9103 dev_err(&bp->pdev->dev,
9104 "VN %d is in a single function mode, "
9111 /* check if other port on the path needs ovlan:
9112 * Since MF configuration is shared between ports
9113 * Possible mixed modes are only
9114 * {SF, SI} {SF, SD} {SD, SF} {SI, SF}
9116 if (CHIP_MODE_IS_4_PORT(bp) &&
9117 !bp->path_has_ovlan &&
9119 bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
9120 u8 other_port = !BP_PORT(bp);
9121 u8 other_func = BP_PATH(bp) + 2*other_port;
9123 func_mf_config[other_func].e1hov_tag);
9124 if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT)
9125 bp->path_has_ovlan = true;
9129 /* adjust igu_sb_cnt to MF for E1x */
9130 if (CHIP_IS_E1x(bp) && IS_MF(bp))
9131 bp->igu_sb_cnt /= E1HVN_MAX;
9134 bnx2x_get_port_hwinfo(bp);
9136 if (!BP_NOMCP(bp)) {
9138 (SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
9139 DRV_MSG_SEQ_NUMBER_MASK);
9140 BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
9143 /* Get MAC addresses */
9144 bnx2x_get_mac_hwinfo(bp);
9147 bnx2x_get_cnic_info(bp);
9150 /* Get current FW pulse sequence */
9151 if (!BP_NOMCP(bp)) {
9152 int mb_idx = BP_FW_MB_IDX(bp);
9154 bp->fw_drv_pulse_wr_seq =
9155 (SHMEM_RD(bp, func_mb[mb_idx].drv_pulse_mb) &
9156 DRV_PULSE_SEQ_MASK);
9157 BNX2X_DEV_INFO("drv_pulse 0x%x\n", bp->fw_drv_pulse_wr_seq);
9163 static void __devinit bnx2x_read_fwinfo(struct bnx2x *bp)
9165 int cnt, i, block_end, rodi;
9166 char vpd_data[BNX2X_VPD_LEN+1];
9167 char str_id_reg[VENDOR_ID_LEN+1];
9168 char str_id_cap[VENDOR_ID_LEN+1];
9171 cnt = pci_read_vpd(bp->pdev, 0, BNX2X_VPD_LEN, vpd_data);
9172 memset(bp->fw_ver, 0, sizeof(bp->fw_ver));
9174 if (cnt < BNX2X_VPD_LEN)
9177 i = pci_vpd_find_tag(vpd_data, 0, BNX2X_VPD_LEN,
9178 PCI_VPD_LRDT_RO_DATA);
9183 block_end = i + PCI_VPD_LRDT_TAG_SIZE +
9184 pci_vpd_lrdt_size(&vpd_data[i]);
9186 i += PCI_VPD_LRDT_TAG_SIZE;
9188 if (block_end > BNX2X_VPD_LEN)
9191 rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
9192 PCI_VPD_RO_KEYWORD_MFR_ID);
9196 len = pci_vpd_info_field_size(&vpd_data[rodi]);
9198 if (len != VENDOR_ID_LEN)
9201 rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
9203 /* vendor specific info */
9204 snprintf(str_id_reg, VENDOR_ID_LEN + 1, "%04x", PCI_VENDOR_ID_DELL);
9205 snprintf(str_id_cap, VENDOR_ID_LEN + 1, "%04X", PCI_VENDOR_ID_DELL);
9206 if (!strncmp(str_id_reg, &vpd_data[rodi], VENDOR_ID_LEN) ||
9207 !strncmp(str_id_cap, &vpd_data[rodi], VENDOR_ID_LEN)) {
9209 rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
9210 PCI_VPD_RO_KEYWORD_VENDOR0);
9212 len = pci_vpd_info_field_size(&vpd_data[rodi]);
9214 rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
9216 if (len < 32 && (len + rodi) <= BNX2X_VPD_LEN) {
9217 memcpy(bp->fw_ver, &vpd_data[rodi], len);
9218 bp->fw_ver[len] = ' ';
9227 static void __devinit bnx2x_set_modes_bitmap(struct bnx2x *bp)
9231 if (CHIP_REV_IS_FPGA(bp))
9232 SET_FLAGS(flags, MODE_FPGA);
9233 else if (CHIP_REV_IS_EMUL(bp))
9234 SET_FLAGS(flags, MODE_EMUL);
9236 SET_FLAGS(flags, MODE_ASIC);
9238 if (CHIP_MODE_IS_4_PORT(bp))
9239 SET_FLAGS(flags, MODE_PORT4);
9241 SET_FLAGS(flags, MODE_PORT2);
9244 SET_FLAGS(flags, MODE_E2);
9245 else if (CHIP_IS_E3(bp)) {
9246 SET_FLAGS(flags, MODE_E3);
9247 if (CHIP_REV(bp) == CHIP_REV_Ax)
9248 SET_FLAGS(flags, MODE_E3_A0);
9249 else {/*if (CHIP_REV(bp) == CHIP_REV_Bx)*/
9250 SET_FLAGS(flags, MODE_E3_B0);
9251 SET_FLAGS(flags, MODE_COS_BC);
9256 SET_FLAGS(flags, MODE_MF);
9257 switch (bp->mf_mode) {
9258 case MULTI_FUNCTION_SD:
9259 SET_FLAGS(flags, MODE_MF_SD);
9261 case MULTI_FUNCTION_SI:
9262 SET_FLAGS(flags, MODE_MF_SI);
9266 SET_FLAGS(flags, MODE_SF);
9268 #if defined(__LITTLE_ENDIAN)
9269 SET_FLAGS(flags, MODE_LITTLE_ENDIAN);
9270 #else /*(__BIG_ENDIAN)*/
9271 SET_FLAGS(flags, MODE_BIG_ENDIAN);
9273 INIT_MODE_FLAGS(bp) = flags;
9276 static int __devinit bnx2x_init_bp(struct bnx2x *bp)
9282 mutex_init(&bp->port.phy_mutex);
9283 mutex_init(&bp->fw_mb_mutex);
9284 spin_lock_init(&bp->stats_lock);
9286 mutex_init(&bp->cnic_mutex);
9289 INIT_DELAYED_WORK(&bp->sp_task, bnx2x_sp_task);
9290 INIT_DELAYED_WORK(&bp->reset_task, bnx2x_reset_task);
9291 INIT_DELAYED_WORK(&bp->period_task, bnx2x_period_task);
9292 rc = bnx2x_get_hwinfo(bp);
9296 bnx2x_set_modes_bitmap(bp);
9298 rc = bnx2x_alloc_mem_bp(bp);
9302 bnx2x_read_fwinfo(bp);
9306 /* need to reset chip if undi was active */
9308 bnx2x_undi_unload(bp);
9310 if (CHIP_REV_IS_FPGA(bp))
9311 dev_err(&bp->pdev->dev, "FPGA detected\n");
9313 if (BP_NOMCP(bp) && (func == 0))
9314 dev_err(&bp->pdev->dev, "MCP disabled, "
9315 "must load devices in order!\n");
9317 bp->multi_mode = multi_mode;
9321 bp->flags &= ~TPA_ENABLE_FLAG;
9322 bp->dev->features &= ~NETIF_F_LRO;
9324 bp->flags |= TPA_ENABLE_FLAG;
9325 bp->dev->features |= NETIF_F_LRO;
9327 bp->disable_tpa = disable_tpa;
9330 bp->dropless_fc = 0;
9332 bp->dropless_fc = dropless_fc;
9336 bp->tx_ring_size = MAX_TX_AVAIL;
9338 /* make sure that the numbers are in the right granularity */
9339 bp->tx_ticks = (50 / BNX2X_BTR) * BNX2X_BTR;
9340 bp->rx_ticks = (25 / BNX2X_BTR) * BNX2X_BTR;
9342 timer_interval = (CHIP_REV_IS_SLOW(bp) ? 5*HZ : HZ);
9343 bp->current_interval = (poll ? poll : timer_interval);
9345 init_timer(&bp->timer);
9346 bp->timer.expires = jiffies + bp->current_interval;
9347 bp->timer.data = (unsigned long) bp;
9348 bp->timer.function = bnx2x_timer;
9350 bnx2x_dcbx_set_state(bp, true, BNX2X_DCBX_ENABLED_ON_NEG_ON);
9351 bnx2x_dcbx_init_params(bp);
9354 if (CHIP_IS_E1x(bp))
9355 bp->cnic_base_cl_id = FP_SB_MAX_E1x;
9357 bp->cnic_base_cl_id = FP_SB_MAX_E2;
9364 /****************************************************************************
9365 * General service functions
9366 ****************************************************************************/
9369 * net_device service functions
9372 /* called with rtnl_lock */
9373 static int bnx2x_open(struct net_device *dev)
9375 struct bnx2x *bp = netdev_priv(dev);
9376 bool global = false;
9377 int other_engine = BP_PATH(bp) ? 0 : 1;
9378 u32 other_load_counter, load_counter;
9380 netif_carrier_off(dev);
9382 bnx2x_set_power_state(bp, PCI_D0);
9384 other_load_counter = bnx2x_get_load_cnt(bp, other_engine);
9385 load_counter = bnx2x_get_load_cnt(bp, BP_PATH(bp));
9388 * If parity had happen during the unload, then attentions
9389 * and/or RECOVERY_IN_PROGRES may still be set. In this case we
9390 * want the first function loaded on the current engine to
9391 * complete the recovery.
9393 if (!bnx2x_reset_is_done(bp, BP_PATH(bp)) ||
9394 bnx2x_chk_parity_attn(bp, &global, true))
9397 * If there are attentions and they are in a global
9398 * blocks, set the GLOBAL_RESET bit regardless whether
9399 * it will be this function that will complete the
9403 bnx2x_set_reset_global(bp);
9406 * Only the first function on the current engine should
9407 * try to recover in open. In case of attentions in
9408 * global blocks only the first in the chip should try
9411 if ((!load_counter &&
9412 (!global || !other_load_counter)) &&
9413 bnx2x_trylock_leader_lock(bp) &&
9414 !bnx2x_leader_reset(bp)) {
9415 netdev_info(bp->dev, "Recovered in open\n");
9419 /* recovery has failed... */
9420 bnx2x_set_power_state(bp, PCI_D3hot);
9421 bp->recovery_state = BNX2X_RECOVERY_FAILED;
9423 netdev_err(bp->dev, "Recovery flow hasn't been properly"
9424 " completed yet. Try again later. If u still see this"
9425 " message after a few retries then power cycle is"
9431 bp->recovery_state = BNX2X_RECOVERY_DONE;
9432 return bnx2x_nic_load(bp, LOAD_OPEN);
9435 /* called with rtnl_lock */
9436 static int bnx2x_close(struct net_device *dev)
9438 struct bnx2x *bp = netdev_priv(dev);
9440 /* Unload the driver, release IRQs */
9441 bnx2x_nic_unload(bp, UNLOAD_CLOSE);
9444 bnx2x_set_power_state(bp, PCI_D3hot);
9449 static inline int bnx2x_init_mcast_macs_list(struct bnx2x *bp,
9450 struct bnx2x_mcast_ramrod_params *p)
9452 int mc_count = netdev_mc_count(bp->dev);
9453 struct bnx2x_mcast_list_elem *mc_mac =
9454 kzalloc(sizeof(*mc_mac) * mc_count, GFP_ATOMIC);
9455 struct netdev_hw_addr *ha;
9460 INIT_LIST_HEAD(&p->mcast_list);
9462 netdev_for_each_mc_addr(ha, bp->dev) {
9463 mc_mac->mac = bnx2x_mc_addr(ha);
9464 list_add_tail(&mc_mac->link, &p->mcast_list);
9468 p->mcast_list_len = mc_count;
9473 static inline void bnx2x_free_mcast_macs_list(
9474 struct bnx2x_mcast_ramrod_params *p)
9476 struct bnx2x_mcast_list_elem *mc_mac =
9477 list_first_entry(&p->mcast_list, struct bnx2x_mcast_list_elem,
9485 * bnx2x_set_uc_list - configure a new unicast MACs list.
9487 * @bp: driver handle
9489 * We will use zero (0) as a MAC type for these MACs.
9491 static inline int bnx2x_set_uc_list(struct bnx2x *bp)
9494 struct net_device *dev = bp->dev;
9495 struct netdev_hw_addr *ha;
9496 struct bnx2x_vlan_mac_obj *mac_obj = &bp->fp->mac_obj;
9497 unsigned long ramrod_flags = 0;
9499 /* First schedule a cleanup up of old configuration */
9500 rc = bnx2x_del_all_macs(bp, mac_obj, BNX2X_UC_LIST_MAC, false);
9502 BNX2X_ERR("Failed to schedule DELETE operations: %d\n", rc);
9506 netdev_for_each_uc_addr(ha, dev) {
9507 rc = bnx2x_set_mac_one(bp, bnx2x_uc_addr(ha), mac_obj, true,
9508 BNX2X_UC_LIST_MAC, &ramrod_flags);
9510 BNX2X_ERR("Failed to schedule ADD operations: %d\n",
9516 /* Execute the pending commands */
9517 __set_bit(RAMROD_CONT, &ramrod_flags);
9518 return bnx2x_set_mac_one(bp, NULL, mac_obj, false /* don't care */,
9519 BNX2X_UC_LIST_MAC, &ramrod_flags);
9522 static inline int bnx2x_set_mc_list(struct bnx2x *bp)
9524 struct net_device *dev = bp->dev;
9525 struct bnx2x_mcast_ramrod_params rparam = {0};
9528 rparam.mcast_obj = &bp->mcast_obj;
9530 /* first, clear all configured multicast MACs */
9531 rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
9533 BNX2X_ERR("Failed to clear multicast "
9534 "configuration: %d\n", rc);
9538 /* then, configure a new MACs list */
9539 if (netdev_mc_count(dev)) {
9540 rc = bnx2x_init_mcast_macs_list(bp, &rparam);
9542 BNX2X_ERR("Failed to create multicast MACs "
9547 /* Now add the new MACs */
9548 rc = bnx2x_config_mcast(bp, &rparam,
9549 BNX2X_MCAST_CMD_ADD);
9551 BNX2X_ERR("Failed to set a new multicast "
9552 "configuration: %d\n", rc);
9554 bnx2x_free_mcast_macs_list(&rparam);
9561 /* If bp->state is OPEN, should be called with netif_addr_lock_bh() */
9562 void bnx2x_set_rx_mode(struct net_device *dev)
9564 struct bnx2x *bp = netdev_priv(dev);
9565 u32 rx_mode = BNX2X_RX_MODE_NORMAL;
9567 if (bp->state != BNX2X_STATE_OPEN) {
9568 DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
9572 DP(NETIF_MSG_IFUP, "dev->flags = %x\n", bp->dev->flags);
9574 if (dev->flags & IFF_PROMISC)
9575 rx_mode = BNX2X_RX_MODE_PROMISC;
9576 else if ((dev->flags & IFF_ALLMULTI) ||
9577 ((netdev_mc_count(dev) > BNX2X_MAX_MULTICAST) &&
9579 rx_mode = BNX2X_RX_MODE_ALLMULTI;
9581 /* some multicasts */
9582 if (bnx2x_set_mc_list(bp) < 0)
9583 rx_mode = BNX2X_RX_MODE_ALLMULTI;
9585 if (bnx2x_set_uc_list(bp) < 0)
9586 rx_mode = BNX2X_RX_MODE_PROMISC;
9589 bp->rx_mode = rx_mode;
9591 /* Schedule the rx_mode command */
9592 if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state)) {
9593 set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
9597 bnx2x_set_storm_rx_mode(bp);
9600 /* called with rtnl_lock */
9601 static int bnx2x_mdio_read(struct net_device *netdev, int prtad,
9602 int devad, u16 addr)
9604 struct bnx2x *bp = netdev_priv(netdev);
9608 DP(NETIF_MSG_LINK, "mdio_read: prtad 0x%x, devad 0x%x, addr 0x%x\n",
9609 prtad, devad, addr);
9611 /* The HW expects different devad if CL22 is used */
9612 devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
9614 bnx2x_acquire_phy_lock(bp);
9615 rc = bnx2x_phy_read(&bp->link_params, prtad, devad, addr, &value);
9616 bnx2x_release_phy_lock(bp);
9617 DP(NETIF_MSG_LINK, "mdio_read_val 0x%x rc = 0x%x\n", value, rc);
9624 /* called with rtnl_lock */
9625 static int bnx2x_mdio_write(struct net_device *netdev, int prtad, int devad,
9626 u16 addr, u16 value)
9628 struct bnx2x *bp = netdev_priv(netdev);
9631 DP(NETIF_MSG_LINK, "mdio_write: prtad 0x%x, devad 0x%x, addr 0x%x,"
9632 " value 0x%x\n", prtad, devad, addr, value);
9634 /* The HW expects different devad if CL22 is used */
9635 devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
9637 bnx2x_acquire_phy_lock(bp);
9638 rc = bnx2x_phy_write(&bp->link_params, prtad, devad, addr, value);
9639 bnx2x_release_phy_lock(bp);
9643 /* called with rtnl_lock */
9644 static int bnx2x_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
9646 struct bnx2x *bp = netdev_priv(dev);
9647 struct mii_ioctl_data *mdio = if_mii(ifr);
9649 DP(NETIF_MSG_LINK, "ioctl: phy id 0x%x, reg 0x%x, val_in 0x%x\n",
9650 mdio->phy_id, mdio->reg_num, mdio->val_in);
9652 if (!netif_running(dev))
9655 return mdio_mii_ioctl(&bp->mdio, mdio, cmd);
9658 #ifdef CONFIG_NET_POLL_CONTROLLER
9659 static void poll_bnx2x(struct net_device *dev)
9661 struct bnx2x *bp = netdev_priv(dev);
9663 disable_irq(bp->pdev->irq);
9664 bnx2x_interrupt(bp->pdev->irq, dev);
9665 enable_irq(bp->pdev->irq);
9669 static const struct net_device_ops bnx2x_netdev_ops = {
9670 .ndo_open = bnx2x_open,
9671 .ndo_stop = bnx2x_close,
9672 .ndo_start_xmit = bnx2x_start_xmit,
9673 .ndo_select_queue = bnx2x_select_queue,
9674 .ndo_set_rx_mode = bnx2x_set_rx_mode,
9675 .ndo_set_mac_address = bnx2x_change_mac_addr,
9676 .ndo_validate_addr = eth_validate_addr,
9677 .ndo_do_ioctl = bnx2x_ioctl,
9678 .ndo_change_mtu = bnx2x_change_mtu,
9679 .ndo_fix_features = bnx2x_fix_features,
9680 .ndo_set_features = bnx2x_set_features,
9681 .ndo_tx_timeout = bnx2x_tx_timeout,
9682 #ifdef CONFIG_NET_POLL_CONTROLLER
9683 .ndo_poll_controller = poll_bnx2x,
9687 static inline int bnx2x_set_coherency_mask(struct bnx2x *bp)
9689 struct device *dev = &bp->pdev->dev;
9691 if (dma_set_mask(dev, DMA_BIT_MASK(64)) == 0) {
9692 bp->flags |= USING_DAC_FLAG;
9693 if (dma_set_coherent_mask(dev, DMA_BIT_MASK(64)) != 0) {
9694 dev_err(dev, "dma_set_coherent_mask failed, "
9698 } else if (dma_set_mask(dev, DMA_BIT_MASK(32)) != 0) {
9699 dev_err(dev, "System does not support DMA, aborting\n");
9706 static int __devinit bnx2x_init_dev(struct pci_dev *pdev,
9707 struct net_device *dev,
9708 unsigned long board_type)
9713 SET_NETDEV_DEV(dev, &pdev->dev);
9714 bp = netdev_priv(dev);
9719 bp->pf_num = PCI_FUNC(pdev->devfn);
9721 rc = pci_enable_device(pdev);
9723 dev_err(&bp->pdev->dev,
9724 "Cannot enable PCI device, aborting\n");
9728 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
9729 dev_err(&bp->pdev->dev,
9730 "Cannot find PCI device base address, aborting\n");
9732 goto err_out_disable;
9735 if (!(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
9736 dev_err(&bp->pdev->dev, "Cannot find second PCI device"
9737 " base address, aborting\n");
9739 goto err_out_disable;
9742 if (atomic_read(&pdev->enable_cnt) == 1) {
9743 rc = pci_request_regions(pdev, DRV_MODULE_NAME);
9745 dev_err(&bp->pdev->dev,
9746 "Cannot obtain PCI resources, aborting\n");
9747 goto err_out_disable;
9750 pci_set_master(pdev);
9751 pci_save_state(pdev);
9754 bp->pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
9755 if (bp->pm_cap == 0) {
9756 dev_err(&bp->pdev->dev,
9757 "Cannot find power management capability, aborting\n");
9759 goto err_out_release;
9762 bp->pcie_cap = pci_find_capability(pdev, PCI_CAP_ID_EXP);
9763 if (bp->pcie_cap == 0) {
9764 dev_err(&bp->pdev->dev,
9765 "Cannot find PCI Express capability, aborting\n");
9767 goto err_out_release;
9770 rc = bnx2x_set_coherency_mask(bp);
9772 goto err_out_release;
9774 dev->mem_start = pci_resource_start(pdev, 0);
9775 dev->base_addr = dev->mem_start;
9776 dev->mem_end = pci_resource_end(pdev, 0);
9778 dev->irq = pdev->irq;
9780 bp->regview = pci_ioremap_bar(pdev, 0);
9782 dev_err(&bp->pdev->dev,
9783 "Cannot map register space, aborting\n");
9785 goto err_out_release;
9788 bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2),
9789 min_t(u64, BNX2X_DB_SIZE(bp),
9790 pci_resource_len(pdev, 2)));
9791 if (!bp->doorbells) {
9792 dev_err(&bp->pdev->dev,
9793 "Cannot map doorbell space, aborting\n");
9798 bnx2x_set_power_state(bp, PCI_D0);
9800 /* clean indirect addresses */
9801 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
9802 PCICFG_VENDOR_ID_OFFSET);
9803 REG_WR(bp, PXP2_REG_PGL_ADDR_88_F0 + BP_PORT(bp)*16, 0);
9804 REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F0 + BP_PORT(bp)*16, 0);
9805 REG_WR(bp, PXP2_REG_PGL_ADDR_90_F0 + BP_PORT(bp)*16, 0);
9806 REG_WR(bp, PXP2_REG_PGL_ADDR_94_F0 + BP_PORT(bp)*16, 0);
9809 * Enable internal target-read (in case we are probed after PF FLR).
9810 * Must be done prior to any BAR read access
9812 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
9814 /* Reset the load counter */
9815 bnx2x_clear_load_cnt(bp);
9817 dev->watchdog_timeo = TX_TIMEOUT;
9819 dev->netdev_ops = &bnx2x_netdev_ops;
9820 bnx2x_set_ethtool_ops(dev);
9822 dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
9823 NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
9824 NETIF_F_RXCSUM | NETIF_F_LRO | NETIF_F_HW_VLAN_TX;
9826 dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
9827 NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 | NETIF_F_HIGHDMA;
9829 dev->features |= dev->hw_features | NETIF_F_HW_VLAN_RX;
9830 if (bp->flags & USING_DAC_FLAG)
9831 dev->features |= NETIF_F_HIGHDMA;
9833 /* Add Loopback capability to the device */
9834 dev->hw_features |= NETIF_F_LOOPBACK;
9837 dev->dcbnl_ops = &bnx2x_dcbnl_ops;
9840 /* get_port_hwinfo() will set prtad and mmds properly */
9841 bp->mdio.prtad = MDIO_PRTAD_NONE;
9843 bp->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
9845 bp->mdio.mdio_read = bnx2x_mdio_read;
9846 bp->mdio.mdio_write = bnx2x_mdio_write;
9852 iounmap(bp->regview);
9855 if (bp->doorbells) {
9856 iounmap(bp->doorbells);
9857 bp->doorbells = NULL;
9861 if (atomic_read(&pdev->enable_cnt) == 1)
9862 pci_release_regions(pdev);
9865 pci_disable_device(pdev);
9866 pci_set_drvdata(pdev, NULL);
9872 static void __devinit bnx2x_get_pcie_width_speed(struct bnx2x *bp,
9873 int *width, int *speed)
9875 u32 val = REG_RD(bp, PCICFG_OFFSET + PCICFG_LINK_CONTROL);
9877 *width = (val & PCICFG_LINK_WIDTH) >> PCICFG_LINK_WIDTH_SHIFT;
9879 /* return value of 1=2.5GHz 2=5GHz */
9880 *speed = (val & PCICFG_LINK_SPEED) >> PCICFG_LINK_SPEED_SHIFT;
9883 static int bnx2x_check_firmware(struct bnx2x *bp)
9885 const struct firmware *firmware = bp->firmware;
9886 struct bnx2x_fw_file_hdr *fw_hdr;
9887 struct bnx2x_fw_file_section *sections;
9888 u32 offset, len, num_ops;
9893 if (firmware->size < sizeof(struct bnx2x_fw_file_hdr))
9896 fw_hdr = (struct bnx2x_fw_file_hdr *)firmware->data;
9897 sections = (struct bnx2x_fw_file_section *)fw_hdr;
9899 /* Make sure none of the offsets and sizes make us read beyond
9900 * the end of the firmware data */
9901 for (i = 0; i < sizeof(*fw_hdr) / sizeof(*sections); i++) {
9902 offset = be32_to_cpu(sections[i].offset);
9903 len = be32_to_cpu(sections[i].len);
9904 if (offset + len > firmware->size) {
9905 dev_err(&bp->pdev->dev,
9906 "Section %d length is out of bounds\n", i);
9911 /* Likewise for the init_ops offsets */
9912 offset = be32_to_cpu(fw_hdr->init_ops_offsets.offset);
9913 ops_offsets = (u16 *)(firmware->data + offset);
9914 num_ops = be32_to_cpu(fw_hdr->init_ops.len) / sizeof(struct raw_op);
9916 for (i = 0; i < be32_to_cpu(fw_hdr->init_ops_offsets.len) / 2; i++) {
9917 if (be16_to_cpu(ops_offsets[i]) > num_ops) {
9918 dev_err(&bp->pdev->dev,
9919 "Section offset %d is out of bounds\n", i);
9924 /* Check FW version */
9925 offset = be32_to_cpu(fw_hdr->fw_version.offset);
9926 fw_ver = firmware->data + offset;
9927 if ((fw_ver[0] != BCM_5710_FW_MAJOR_VERSION) ||
9928 (fw_ver[1] != BCM_5710_FW_MINOR_VERSION) ||
9929 (fw_ver[2] != BCM_5710_FW_REVISION_VERSION) ||
9930 (fw_ver[3] != BCM_5710_FW_ENGINEERING_VERSION)) {
9931 dev_err(&bp->pdev->dev,
9932 "Bad FW version:%d.%d.%d.%d. Should be %d.%d.%d.%d\n",
9933 fw_ver[0], fw_ver[1], fw_ver[2],
9934 fw_ver[3], BCM_5710_FW_MAJOR_VERSION,
9935 BCM_5710_FW_MINOR_VERSION,
9936 BCM_5710_FW_REVISION_VERSION,
9937 BCM_5710_FW_ENGINEERING_VERSION);
9944 static inline void be32_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
9946 const __be32 *source = (const __be32 *)_source;
9947 u32 *target = (u32 *)_target;
9950 for (i = 0; i < n/4; i++)
9951 target[i] = be32_to_cpu(source[i]);
9955 Ops array is stored in the following format:
9956 {op(8bit), offset(24bit, big endian), data(32bit, big endian)}
9958 static inline void bnx2x_prep_ops(const u8 *_source, u8 *_target, u32 n)
9960 const __be32 *source = (const __be32 *)_source;
9961 struct raw_op *target = (struct raw_op *)_target;
9964 for (i = 0, j = 0; i < n/8; i++, j += 2) {
9965 tmp = be32_to_cpu(source[j]);
9966 target[i].op = (tmp >> 24) & 0xff;
9967 target[i].offset = tmp & 0xffffff;
9968 target[i].raw_data = be32_to_cpu(source[j + 1]);
9973 * IRO array is stored in the following format:
9974 * {base(24bit), m1(16bit), m2(16bit), m3(16bit), size(16bit) }
9976 static inline void bnx2x_prep_iro(const u8 *_source, u8 *_target, u32 n)
9978 const __be32 *source = (const __be32 *)_source;
9979 struct iro *target = (struct iro *)_target;
9982 for (i = 0, j = 0; i < n/sizeof(struct iro); i++) {
9983 target[i].base = be32_to_cpu(source[j]);
9985 tmp = be32_to_cpu(source[j]);
9986 target[i].m1 = (tmp >> 16) & 0xffff;
9987 target[i].m2 = tmp & 0xffff;
9989 tmp = be32_to_cpu(source[j]);
9990 target[i].m3 = (tmp >> 16) & 0xffff;
9991 target[i].size = tmp & 0xffff;
9996 static inline void be16_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
9998 const __be16 *source = (const __be16 *)_source;
9999 u16 *target = (u16 *)_target;
10002 for (i = 0; i < n/2; i++)
10003 target[i] = be16_to_cpu(source[i]);
10006 #define BNX2X_ALLOC_AND_SET(arr, lbl, func) \
10008 u32 len = be32_to_cpu(fw_hdr->arr.len); \
10009 bp->arr = kmalloc(len, GFP_KERNEL); \
10011 pr_err("Failed to allocate %d bytes for "#arr"\n", len); \
10014 func(bp->firmware->data + be32_to_cpu(fw_hdr->arr.offset), \
10015 (u8 *)bp->arr, len); \
10018 int bnx2x_init_firmware(struct bnx2x *bp)
10020 const char *fw_file_name;
10021 struct bnx2x_fw_file_hdr *fw_hdr;
10024 if (CHIP_IS_E1(bp))
10025 fw_file_name = FW_FILE_NAME_E1;
10026 else if (CHIP_IS_E1H(bp))
10027 fw_file_name = FW_FILE_NAME_E1H;
10028 else if (!CHIP_IS_E1x(bp))
10029 fw_file_name = FW_FILE_NAME_E2;
10031 BNX2X_ERR("Unsupported chip revision\n");
10035 BNX2X_DEV_INFO("Loading %s\n", fw_file_name);
10037 rc = request_firmware(&bp->firmware, fw_file_name, &bp->pdev->dev);
10039 BNX2X_ERR("Can't load firmware file %s\n", fw_file_name);
10040 goto request_firmware_exit;
10043 rc = bnx2x_check_firmware(bp);
10045 BNX2X_ERR("Corrupt firmware file %s\n", fw_file_name);
10046 goto request_firmware_exit;
10049 fw_hdr = (struct bnx2x_fw_file_hdr *)bp->firmware->data;
10051 /* Initialize the pointers to the init arrays */
10053 BNX2X_ALLOC_AND_SET(init_data, request_firmware_exit, be32_to_cpu_n);
10056 BNX2X_ALLOC_AND_SET(init_ops, init_ops_alloc_err, bnx2x_prep_ops);
10059 BNX2X_ALLOC_AND_SET(init_ops_offsets, init_offsets_alloc_err,
10062 /* STORMs firmware */
10063 INIT_TSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
10064 be32_to_cpu(fw_hdr->tsem_int_table_data.offset);
10065 INIT_TSEM_PRAM_DATA(bp) = bp->firmware->data +
10066 be32_to_cpu(fw_hdr->tsem_pram_data.offset);
10067 INIT_USEM_INT_TABLE_DATA(bp) = bp->firmware->data +
10068 be32_to_cpu(fw_hdr->usem_int_table_data.offset);
10069 INIT_USEM_PRAM_DATA(bp) = bp->firmware->data +
10070 be32_to_cpu(fw_hdr->usem_pram_data.offset);
10071 INIT_XSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
10072 be32_to_cpu(fw_hdr->xsem_int_table_data.offset);
10073 INIT_XSEM_PRAM_DATA(bp) = bp->firmware->data +
10074 be32_to_cpu(fw_hdr->xsem_pram_data.offset);
10075 INIT_CSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
10076 be32_to_cpu(fw_hdr->csem_int_table_data.offset);
10077 INIT_CSEM_PRAM_DATA(bp) = bp->firmware->data +
10078 be32_to_cpu(fw_hdr->csem_pram_data.offset);
10080 BNX2X_ALLOC_AND_SET(iro_arr, iro_alloc_err, bnx2x_prep_iro);
10085 kfree(bp->init_ops_offsets);
10086 init_offsets_alloc_err:
10087 kfree(bp->init_ops);
10088 init_ops_alloc_err:
10089 kfree(bp->init_data);
10090 request_firmware_exit:
10091 release_firmware(bp->firmware);
10096 static void bnx2x_release_firmware(struct bnx2x *bp)
10098 kfree(bp->init_ops_offsets);
10099 kfree(bp->init_ops);
10100 kfree(bp->init_data);
10101 release_firmware(bp->firmware);
10105 static struct bnx2x_func_sp_drv_ops bnx2x_func_sp_drv = {
10106 .init_hw_cmn_chip = bnx2x_init_hw_common_chip,
10107 .init_hw_cmn = bnx2x_init_hw_common,
10108 .init_hw_port = bnx2x_init_hw_port,
10109 .init_hw_func = bnx2x_init_hw_func,
10111 .reset_hw_cmn = bnx2x_reset_common,
10112 .reset_hw_port = bnx2x_reset_port,
10113 .reset_hw_func = bnx2x_reset_func,
10115 .gunzip_init = bnx2x_gunzip_init,
10116 .gunzip_end = bnx2x_gunzip_end,
10118 .init_fw = bnx2x_init_firmware,
10119 .release_fw = bnx2x_release_firmware,
10122 void bnx2x__init_func_obj(struct bnx2x *bp)
10124 /* Prepare DMAE related driver resources */
10125 bnx2x_setup_dmae(bp);
10127 bnx2x_init_func_obj(bp, &bp->func_obj,
10128 bnx2x_sp(bp, func_rdata),
10129 bnx2x_sp_mapping(bp, func_rdata),
10130 &bnx2x_func_sp_drv);
10133 /* must be called after sriov-enable */
10134 static inline int bnx2x_set_qm_cid_count(struct bnx2x *bp, int l2_cid_count)
10136 int cid_count = L2_FP_COUNT(l2_cid_count);
10139 cid_count += CNIC_CID_MAX;
10141 return roundup(cid_count, QM_CID_ROUND);
10145 * bnx2x_pci_msix_table_size - get the size of the MSI-X table.
10150 static inline int bnx2x_pci_msix_table_size(struct pci_dev *pdev)
10155 pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
10159 pci_read_config_word(pdev, pos + PCI_MSI_FLAGS, &control);
10160 return (control & PCI_MSIX_FLAGS_QSIZE) + 1;
10163 static int __devinit bnx2x_init_one(struct pci_dev *pdev,
10164 const struct pci_device_id *ent)
10166 struct net_device *dev = NULL;
10168 int pcie_width, pcie_speed;
10171 switch (ent->driver_data) {
10183 /* The size requested for the MSI-X table corresponds to the
10184 * actual amount of avaliable IGU/HC status blocks. It includes
10185 * the default SB vector but we want cid_count to contain the
10186 * amount of only non-default SBs, that's what '-1' stands for.
10188 cid_count = bnx2x_pci_msix_table_size(pdev) - 1;
10190 /* do not allow initial cid_count grow above 16
10191 * since Special CIDs starts from this number
10192 * use old FP_SB_MAX_E1x define for this matter
10194 cid_count = min_t(int, FP_SB_MAX_E1x, cid_count);
10196 WARN_ON(!cid_count);
10200 pr_err("Unknown board_type (%ld), aborting\n",
10205 cid_count += FCOE_CONTEXT_USE;
10207 /* dev zeroed in init_etherdev */
10208 dev = alloc_etherdev_mq(sizeof(*bp), cid_count);
10210 dev_err(&pdev->dev, "Cannot allocate net device\n");
10214 /* We don't need a Tx queue for a CNIC and an OOO Rx-only ring,
10215 * so update a cid_count after a netdev allocation.
10217 cid_count += CNIC_CONTEXT_USE;
10219 bp = netdev_priv(dev);
10220 bp->msg_enable = debug;
10222 pci_set_drvdata(pdev, dev);
10224 bp->l2_cid_count = cid_count;
10226 rc = bnx2x_init_dev(pdev, dev, ent->driver_data);
10232 BNX2X_DEV_INFO("cid_count=%d\n", cid_count);
10234 rc = bnx2x_init_bp(bp);
10236 goto init_one_exit;
10238 /* calc qm_cid_count */
10239 bp->qm_cid_count = bnx2x_set_qm_cid_count(bp, cid_count);
10242 /* disable FCOE L2 queue for E1x*/
10243 if (CHIP_IS_E1x(bp))
10244 bp->flags |= NO_FCOE_FLAG;
10248 /* Configure interrupt mode: try to enable MSI-X/MSI if
10249 * needed, set bp->num_queues appropriately.
10251 bnx2x_set_int_mode(bp);
10253 /* Add all NAPI objects */
10254 bnx2x_add_all_napi(bp);
10256 rc = register_netdev(dev);
10258 dev_err(&pdev->dev, "Cannot register net device\n");
10259 goto init_one_exit;
10263 if (!NO_FCOE(bp)) {
10264 /* Add storage MAC address */
10266 dev_addr_add(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
10271 bnx2x_get_pcie_width_speed(bp, &pcie_width, &pcie_speed);
10273 netdev_info(dev, "%s (%c%d) PCI-E x%d %s found at mem %lx,"
10274 " IRQ %d, ", board_info[ent->driver_data].name,
10275 (CHIP_REV(bp) >> 12) + 'A', (CHIP_METAL(bp) >> 4),
10277 ((!CHIP_IS_E2(bp) && pcie_speed == 2) ||
10278 (CHIP_IS_E2(bp) && pcie_speed == 1)) ?
10279 "5GHz (Gen2)" : "2.5GHz",
10280 dev->base_addr, bp->pdev->irq);
10281 pr_cont("node addr %pM\n", dev->dev_addr);
10287 iounmap(bp->regview);
10290 iounmap(bp->doorbells);
10294 if (atomic_read(&pdev->enable_cnt) == 1)
10295 pci_release_regions(pdev);
10297 pci_disable_device(pdev);
10298 pci_set_drvdata(pdev, NULL);
10303 static void __devexit bnx2x_remove_one(struct pci_dev *pdev)
10305 struct net_device *dev = pci_get_drvdata(pdev);
10309 dev_err(&pdev->dev, "BAD net device from bnx2x_init_one\n");
10312 bp = netdev_priv(dev);
10315 /* Delete storage MAC address */
10316 if (!NO_FCOE(bp)) {
10318 dev_addr_del(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
10324 /* Delete app tlvs from dcbnl */
10325 bnx2x_dcbnl_update_applist(bp, true);
10328 unregister_netdev(dev);
10330 /* Delete all NAPI objects */
10331 bnx2x_del_all_napi(bp);
10333 /* Power on: we can't let PCI layer write to us while we are in D3 */
10334 bnx2x_set_power_state(bp, PCI_D0);
10336 /* Disable MSI/MSI-X */
10337 bnx2x_disable_msi(bp);
10340 bnx2x_set_power_state(bp, PCI_D3hot);
10342 /* Make sure RESET task is not scheduled before continuing */
10343 cancel_delayed_work_sync(&bp->reset_task);
10346 iounmap(bp->regview);
10349 iounmap(bp->doorbells);
10351 bnx2x_free_mem_bp(bp);
10355 if (atomic_read(&pdev->enable_cnt) == 1)
10356 pci_release_regions(pdev);
10358 pci_disable_device(pdev);
10359 pci_set_drvdata(pdev, NULL);
10362 static int bnx2x_eeh_nic_unload(struct bnx2x *bp)
10366 bp->state = BNX2X_STATE_ERROR;
10368 bp->rx_mode = BNX2X_RX_MODE_NONE;
10371 bnx2x_cnic_notify(bp, CNIC_CTL_STOP_CMD);
10374 bnx2x_tx_disable(bp);
10376 bnx2x_netif_stop(bp, 0);
10378 del_timer_sync(&bp->timer);
10380 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
10383 bnx2x_free_irq(bp);
10385 /* Free SKBs, SGEs, TPA pool and driver internals */
10386 bnx2x_free_skbs(bp);
10388 for_each_rx_queue(bp, i)
10389 bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
10391 bnx2x_free_mem(bp);
10393 bp->state = BNX2X_STATE_CLOSED;
10395 netif_carrier_off(bp->dev);
10400 static void bnx2x_eeh_recover(struct bnx2x *bp)
10404 mutex_init(&bp->port.phy_mutex);
10406 bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
10407 bp->link_params.shmem_base = bp->common.shmem_base;
10408 BNX2X_DEV_INFO("shmem offset is 0x%x\n", bp->common.shmem_base);
10410 if (!bp->common.shmem_base ||
10411 (bp->common.shmem_base < 0xA0000) ||
10412 (bp->common.shmem_base >= 0xC0000)) {
10413 BNX2X_DEV_INFO("MCP not active\n");
10414 bp->flags |= NO_MCP_FLAG;
10418 val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
10419 if ((val & (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
10420 != (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
10421 BNX2X_ERR("BAD MCP validity signature\n");
10423 if (!BP_NOMCP(bp)) {
10425 (SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
10426 DRV_MSG_SEQ_NUMBER_MASK);
10427 BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
10432 * bnx2x_io_error_detected - called when PCI error is detected
10433 * @pdev: Pointer to PCI device
10434 * @state: The current pci connection state
10436 * This function is called after a PCI bus error affecting
10437 * this device has been detected.
10439 static pci_ers_result_t bnx2x_io_error_detected(struct pci_dev *pdev,
10440 pci_channel_state_t state)
10442 struct net_device *dev = pci_get_drvdata(pdev);
10443 struct bnx2x *bp = netdev_priv(dev);
10447 netif_device_detach(dev);
10449 if (state == pci_channel_io_perm_failure) {
10451 return PCI_ERS_RESULT_DISCONNECT;
10454 if (netif_running(dev))
10455 bnx2x_eeh_nic_unload(bp);
10457 pci_disable_device(pdev);
10461 /* Request a slot reset */
10462 return PCI_ERS_RESULT_NEED_RESET;
10466 * bnx2x_io_slot_reset - called after the PCI bus has been reset
10467 * @pdev: Pointer to PCI device
10469 * Restart the card from scratch, as if from a cold-boot.
10471 static pci_ers_result_t bnx2x_io_slot_reset(struct pci_dev *pdev)
10473 struct net_device *dev = pci_get_drvdata(pdev);
10474 struct bnx2x *bp = netdev_priv(dev);
10478 if (pci_enable_device(pdev)) {
10479 dev_err(&pdev->dev,
10480 "Cannot re-enable PCI device after reset\n");
10482 return PCI_ERS_RESULT_DISCONNECT;
10485 pci_set_master(pdev);
10486 pci_restore_state(pdev);
10488 if (netif_running(dev))
10489 bnx2x_set_power_state(bp, PCI_D0);
10493 return PCI_ERS_RESULT_RECOVERED;
10497 * bnx2x_io_resume - called when traffic can start flowing again
10498 * @pdev: Pointer to PCI device
10500 * This callback is called when the error recovery driver tells us that
10501 * its OK to resume normal operation.
10503 static void bnx2x_io_resume(struct pci_dev *pdev)
10505 struct net_device *dev = pci_get_drvdata(pdev);
10506 struct bnx2x *bp = netdev_priv(dev);
10508 if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
10509 netdev_err(bp->dev, "Handling parity error recovery. "
10510 "Try again later\n");
10516 bnx2x_eeh_recover(bp);
10518 if (netif_running(dev))
10519 bnx2x_nic_load(bp, LOAD_NORMAL);
10521 netif_device_attach(dev);
10526 static struct pci_error_handlers bnx2x_err_handler = {
10527 .error_detected = bnx2x_io_error_detected,
10528 .slot_reset = bnx2x_io_slot_reset,
10529 .resume = bnx2x_io_resume,
10532 static struct pci_driver bnx2x_pci_driver = {
10533 .name = DRV_MODULE_NAME,
10534 .id_table = bnx2x_pci_tbl,
10535 .probe = bnx2x_init_one,
10536 .remove = __devexit_p(bnx2x_remove_one),
10537 .suspend = bnx2x_suspend,
10538 .resume = bnx2x_resume,
10539 .err_handler = &bnx2x_err_handler,
10542 static int __init bnx2x_init(void)
10546 pr_info("%s", version);
10548 bnx2x_wq = create_singlethread_workqueue("bnx2x");
10549 if (bnx2x_wq == NULL) {
10550 pr_err("Cannot create workqueue\n");
10554 ret = pci_register_driver(&bnx2x_pci_driver);
10556 pr_err("Cannot register driver\n");
10557 destroy_workqueue(bnx2x_wq);
10562 static void __exit bnx2x_cleanup(void)
10564 pci_unregister_driver(&bnx2x_pci_driver);
10566 destroy_workqueue(bnx2x_wq);
10569 void bnx2x_notify_link_changed(struct bnx2x *bp)
10571 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + BP_FUNC(bp)*sizeof(u32), 1);
10574 module_init(bnx2x_init);
10575 module_exit(bnx2x_cleanup);
10579 * bnx2x_set_iscsi_eth_mac_addr - set iSCSI MAC(s).
10581 * @bp: driver handle
10582 * @set: set or clear the CAM entry
10584 * This function will wait until the ramdord completion returns.
10585 * Return 0 if success, -ENODEV if ramrod doesn't return.
10587 static inline int bnx2x_set_iscsi_eth_mac_addr(struct bnx2x *bp)
10589 unsigned long ramrod_flags = 0;
10591 __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
10592 return bnx2x_set_mac_one(bp, bp->cnic_eth_dev.iscsi_mac,
10593 &bp->iscsi_l2_mac_obj, true,
10594 BNX2X_ISCSI_ETH_MAC, &ramrod_flags);
10597 /* count denotes the number of new completions we have seen */
10598 static void bnx2x_cnic_sp_post(struct bnx2x *bp, int count)
10600 struct eth_spe *spe;
10602 #ifdef BNX2X_STOP_ON_ERROR
10603 if (unlikely(bp->panic))
10607 spin_lock_bh(&bp->spq_lock);
10608 BUG_ON(bp->cnic_spq_pending < count);
10609 bp->cnic_spq_pending -= count;
10612 for (; bp->cnic_kwq_pending; bp->cnic_kwq_pending--) {
10613 u16 type = (le16_to_cpu(bp->cnic_kwq_cons->hdr.type)
10614 & SPE_HDR_CONN_TYPE) >>
10615 SPE_HDR_CONN_TYPE_SHIFT;
10616 u8 cmd = (le32_to_cpu(bp->cnic_kwq_cons->hdr.conn_and_cmd_data)
10617 >> SPE_HDR_CMD_ID_SHIFT) & 0xff;
10619 /* Set validation for iSCSI L2 client before sending SETUP
10622 if (type == ETH_CONNECTION_TYPE) {
10623 if (cmd == RAMROD_CMD_ID_ETH_CLIENT_SETUP)
10624 bnx2x_set_ctx_validation(bp, &bp->context.
10625 vcxt[BNX2X_ISCSI_ETH_CID].eth,
10626 BNX2X_ISCSI_ETH_CID);
10630 * There may be not more than 8 L2, not more than 8 L5 SPEs
10631 * and in the air. We also check that number of outstanding
10632 * COMMON ramrods is not more than the EQ and SPQ can
10635 if (type == ETH_CONNECTION_TYPE) {
10636 if (!atomic_read(&bp->cq_spq_left))
10639 atomic_dec(&bp->cq_spq_left);
10640 } else if (type == NONE_CONNECTION_TYPE) {
10641 if (!atomic_read(&bp->eq_spq_left))
10644 atomic_dec(&bp->eq_spq_left);
10645 } else if ((type == ISCSI_CONNECTION_TYPE) ||
10646 (type == FCOE_CONNECTION_TYPE)) {
10647 if (bp->cnic_spq_pending >=
10648 bp->cnic_eth_dev.max_kwqe_pending)
10651 bp->cnic_spq_pending++;
10653 BNX2X_ERR("Unknown SPE type: %d\n", type);
10658 spe = bnx2x_sp_get_next(bp);
10659 *spe = *bp->cnic_kwq_cons;
10661 DP(NETIF_MSG_TIMER, "pending on SPQ %d, on KWQ %d count %d\n",
10662 bp->cnic_spq_pending, bp->cnic_kwq_pending, count);
10664 if (bp->cnic_kwq_cons == bp->cnic_kwq_last)
10665 bp->cnic_kwq_cons = bp->cnic_kwq;
10667 bp->cnic_kwq_cons++;
10669 bnx2x_sp_prod_update(bp);
10670 spin_unlock_bh(&bp->spq_lock);
10673 static int bnx2x_cnic_sp_queue(struct net_device *dev,
10674 struct kwqe_16 *kwqes[], u32 count)
10676 struct bnx2x *bp = netdev_priv(dev);
10679 #ifdef BNX2X_STOP_ON_ERROR
10680 if (unlikely(bp->panic))
10684 spin_lock_bh(&bp->spq_lock);
10686 for (i = 0; i < count; i++) {
10687 struct eth_spe *spe = (struct eth_spe *)kwqes[i];
10689 if (bp->cnic_kwq_pending == MAX_SP_DESC_CNT)
10692 *bp->cnic_kwq_prod = *spe;
10694 bp->cnic_kwq_pending++;
10696 DP(NETIF_MSG_TIMER, "L5 SPQE %x %x %x:%x pos %d\n",
10697 spe->hdr.conn_and_cmd_data, spe->hdr.type,
10698 spe->data.update_data_addr.hi,
10699 spe->data.update_data_addr.lo,
10700 bp->cnic_kwq_pending);
10702 if (bp->cnic_kwq_prod == bp->cnic_kwq_last)
10703 bp->cnic_kwq_prod = bp->cnic_kwq;
10705 bp->cnic_kwq_prod++;
10708 spin_unlock_bh(&bp->spq_lock);
10710 if (bp->cnic_spq_pending < bp->cnic_eth_dev.max_kwqe_pending)
10711 bnx2x_cnic_sp_post(bp, 0);
10716 static int bnx2x_cnic_ctl_send(struct bnx2x *bp, struct cnic_ctl_info *ctl)
10718 struct cnic_ops *c_ops;
10721 mutex_lock(&bp->cnic_mutex);
10722 c_ops = rcu_dereference_protected(bp->cnic_ops,
10723 lockdep_is_held(&bp->cnic_mutex));
10725 rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
10726 mutex_unlock(&bp->cnic_mutex);
10731 static int bnx2x_cnic_ctl_send_bh(struct bnx2x *bp, struct cnic_ctl_info *ctl)
10733 struct cnic_ops *c_ops;
10737 c_ops = rcu_dereference(bp->cnic_ops);
10739 rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
10746 * for commands that have no data
10748 int bnx2x_cnic_notify(struct bnx2x *bp, int cmd)
10750 struct cnic_ctl_info ctl = {0};
10754 return bnx2x_cnic_ctl_send(bp, &ctl);
10757 static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err)
10759 struct cnic_ctl_info ctl = {0};
10761 /* first we tell CNIC and only then we count this as a completion */
10762 ctl.cmd = CNIC_CTL_COMPLETION_CMD;
10763 ctl.data.comp.cid = cid;
10764 ctl.data.comp.error = err;
10766 bnx2x_cnic_ctl_send_bh(bp, &ctl);
10767 bnx2x_cnic_sp_post(bp, 0);
10771 /* Called with netif_addr_lock_bh() taken.
10772 * Sets an rx_mode config for an iSCSI ETH client.
10774 * Completion should be checked outside.
10776 static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start)
10778 unsigned long accept_flags = 0, ramrod_flags = 0;
10779 u8 cl_id = bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
10780 int sched_state = BNX2X_FILTER_ISCSI_ETH_STOP_SCHED;
10783 /* Start accepting on iSCSI L2 ring. Accept all multicasts
10784 * because it's the only way for UIO Queue to accept
10785 * multicasts (in non-promiscuous mode only one Queue per
10786 * function will receive multicast packets (leading in our
10789 __set_bit(BNX2X_ACCEPT_UNICAST, &accept_flags);
10790 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept_flags);
10791 __set_bit(BNX2X_ACCEPT_BROADCAST, &accept_flags);
10792 __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept_flags);
10794 /* Clear STOP_PENDING bit if START is requested */
10795 clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &bp->sp_state);
10797 sched_state = BNX2X_FILTER_ISCSI_ETH_START_SCHED;
10799 /* Clear START_PENDING bit if STOP is requested */
10800 clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &bp->sp_state);
10802 if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
10803 set_bit(sched_state, &bp->sp_state);
10805 __set_bit(RAMROD_RX, &ramrod_flags);
10806 bnx2x_set_q_rx_mode(bp, cl_id, 0, accept_flags, 0,
10812 static int bnx2x_drv_ctl(struct net_device *dev, struct drv_ctl_info *ctl)
10814 struct bnx2x *bp = netdev_priv(dev);
10817 switch (ctl->cmd) {
10818 case DRV_CTL_CTXTBL_WR_CMD: {
10819 u32 index = ctl->data.io.offset;
10820 dma_addr_t addr = ctl->data.io.dma_addr;
10822 bnx2x_ilt_wr(bp, index, addr);
10826 case DRV_CTL_RET_L5_SPQ_CREDIT_CMD: {
10827 int count = ctl->data.credit.credit_count;
10829 bnx2x_cnic_sp_post(bp, count);
10833 /* rtnl_lock is held. */
10834 case DRV_CTL_START_L2_CMD: {
10835 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
10836 unsigned long sp_bits = 0;
10838 /* Configure the iSCSI classification object */
10839 bnx2x_init_mac_obj(bp, &bp->iscsi_l2_mac_obj,
10840 cp->iscsi_l2_client_id,
10841 cp->iscsi_l2_cid, BP_FUNC(bp),
10842 bnx2x_sp(bp, mac_rdata),
10843 bnx2x_sp_mapping(bp, mac_rdata),
10844 BNX2X_FILTER_MAC_PENDING,
10845 &bp->sp_state, BNX2X_OBJ_TYPE_RX,
10848 /* Set iSCSI MAC address */
10849 rc = bnx2x_set_iscsi_eth_mac_addr(bp);
10856 /* Start accepting on iSCSI L2 ring */
10858 netif_addr_lock_bh(dev);
10859 bnx2x_set_iscsi_eth_rx_mode(bp, true);
10860 netif_addr_unlock_bh(dev);
10862 /* bits to wait on */
10863 __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
10864 __set_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &sp_bits);
10866 if (!bnx2x_wait_sp_comp(bp, sp_bits))
10867 BNX2X_ERR("rx_mode completion timed out!\n");
10872 /* rtnl_lock is held. */
10873 case DRV_CTL_STOP_L2_CMD: {
10874 unsigned long sp_bits = 0;
10876 /* Stop accepting on iSCSI L2 ring */
10877 netif_addr_lock_bh(dev);
10878 bnx2x_set_iscsi_eth_rx_mode(bp, false);
10879 netif_addr_unlock_bh(dev);
10881 /* bits to wait on */
10882 __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
10883 __set_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &sp_bits);
10885 if (!bnx2x_wait_sp_comp(bp, sp_bits))
10886 BNX2X_ERR("rx_mode completion timed out!\n");
10891 /* Unset iSCSI L2 MAC */
10892 rc = bnx2x_del_all_macs(bp, &bp->iscsi_l2_mac_obj,
10893 BNX2X_ISCSI_ETH_MAC, true);
10896 case DRV_CTL_RET_L2_SPQ_CREDIT_CMD: {
10897 int count = ctl->data.credit.credit_count;
10899 smp_mb__before_atomic_inc();
10900 atomic_add(count, &bp->cq_spq_left);
10901 smp_mb__after_atomic_inc();
10906 BNX2X_ERR("unknown command %x\n", ctl->cmd);
10913 void bnx2x_setup_cnic_irq_info(struct bnx2x *bp)
10915 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
10917 if (bp->flags & USING_MSIX_FLAG) {
10918 cp->drv_state |= CNIC_DRV_STATE_USING_MSIX;
10919 cp->irq_arr[0].irq_flags |= CNIC_IRQ_FL_MSIX;
10920 cp->irq_arr[0].vector = bp->msix_table[1].vector;
10922 cp->drv_state &= ~CNIC_DRV_STATE_USING_MSIX;
10923 cp->irq_arr[0].irq_flags &= ~CNIC_IRQ_FL_MSIX;
10925 if (!CHIP_IS_E1x(bp))
10926 cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e2_sb;
10928 cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e1x_sb;
10930 cp->irq_arr[0].status_blk_num = bnx2x_cnic_fw_sb_id(bp);
10931 cp->irq_arr[0].status_blk_num2 = bnx2x_cnic_igu_sb_id(bp);
10932 cp->irq_arr[1].status_blk = bp->def_status_blk;
10933 cp->irq_arr[1].status_blk_num = DEF_SB_ID;
10934 cp->irq_arr[1].status_blk_num2 = DEF_SB_IGU_ID;
10939 static int bnx2x_register_cnic(struct net_device *dev, struct cnic_ops *ops,
10942 struct bnx2x *bp = netdev_priv(dev);
10943 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
10948 bp->cnic_kwq = kzalloc(PAGE_SIZE, GFP_KERNEL);
10952 bp->cnic_kwq_cons = bp->cnic_kwq;
10953 bp->cnic_kwq_prod = bp->cnic_kwq;
10954 bp->cnic_kwq_last = bp->cnic_kwq + MAX_SP_DESC_CNT;
10956 bp->cnic_spq_pending = 0;
10957 bp->cnic_kwq_pending = 0;
10959 bp->cnic_data = data;
10962 cp->drv_state |= CNIC_DRV_STATE_REGD;
10963 cp->iro_arr = bp->iro_arr;
10965 bnx2x_setup_cnic_irq_info(bp);
10967 rcu_assign_pointer(bp->cnic_ops, ops);
10972 static int bnx2x_unregister_cnic(struct net_device *dev)
10974 struct bnx2x *bp = netdev_priv(dev);
10975 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
10977 mutex_lock(&bp->cnic_mutex);
10979 rcu_assign_pointer(bp->cnic_ops, NULL);
10980 mutex_unlock(&bp->cnic_mutex);
10982 kfree(bp->cnic_kwq);
10983 bp->cnic_kwq = NULL;
10988 struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev)
10990 struct bnx2x *bp = netdev_priv(dev);
10991 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
10993 /* If both iSCSI and FCoE are disabled - return NULL in
10994 * order to indicate CNIC that it should not try to work
10995 * with this device.
10997 if (NO_ISCSI(bp) && NO_FCOE(bp))
11000 cp->drv_owner = THIS_MODULE;
11001 cp->chip_id = CHIP_ID(bp);
11002 cp->pdev = bp->pdev;
11003 cp->io_base = bp->regview;
11004 cp->io_base2 = bp->doorbells;
11005 cp->max_kwqe_pending = 8;
11006 cp->ctx_blk_size = CDU_ILT_PAGE_SZ;
11007 cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
11008 bnx2x_cid_ilt_lines(bp);
11009 cp->ctx_tbl_len = CNIC_ILT_LINES;
11010 cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
11011 cp->drv_submit_kwqes_16 = bnx2x_cnic_sp_queue;
11012 cp->drv_ctl = bnx2x_drv_ctl;
11013 cp->drv_register_cnic = bnx2x_register_cnic;
11014 cp->drv_unregister_cnic = bnx2x_unregister_cnic;
11015 cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID;
11016 cp->iscsi_l2_client_id =
11017 bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
11018 cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID;
11020 if (NO_ISCSI_OOO(bp))
11021 cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
11024 cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI;
11027 cp->drv_state |= CNIC_DRV_STATE_NO_FCOE;
11029 DP(BNX2X_MSG_SP, "page_size %d, tbl_offset %d, tbl_lines %d, "
11030 "starting cid %d\n",
11032 cp->ctx_tbl_offset,
11037 EXPORT_SYMBOL(bnx2x_cnic_probe);
11039 #endif /* BCM_CNIC */