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 flush_workqueue(bnx2x_wq);
1572 * General service functions
1575 /* Return true if succeeded to acquire the lock */
1576 static bool bnx2x_trylock_hw_lock(struct bnx2x *bp, u32 resource)
1579 u32 resource_bit = (1 << resource);
1580 int func = BP_FUNC(bp);
1581 u32 hw_lock_control_reg;
1583 DP(NETIF_MSG_HW, "Trying to take a lock on resource %d\n", resource);
1585 /* Validating that the resource is within range */
1586 if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
1588 "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
1589 resource, HW_LOCK_MAX_RESOURCE_VALUE);
1594 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
1596 hw_lock_control_reg =
1597 (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
1599 /* Try to acquire the lock */
1600 REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
1601 lock_status = REG_RD(bp, hw_lock_control_reg);
1602 if (lock_status & resource_bit)
1605 DP(NETIF_MSG_HW, "Failed to get a lock on resource %d\n", resource);
1610 * bnx2x_get_leader_lock_resource - get the recovery leader resource id
1612 * @bp: driver handle
1614 * Returns the recovery leader resource id according to the engine this function
1615 * belongs to. Currently only only 2 engines is supported.
1617 static inline int bnx2x_get_leader_lock_resource(struct bnx2x *bp)
1620 return HW_LOCK_RESOURCE_RECOVERY_LEADER_1;
1622 return HW_LOCK_RESOURCE_RECOVERY_LEADER_0;
1626 * bnx2x_trylock_leader_lock- try to aquire a leader lock.
1628 * @bp: driver handle
1630 * Tries to aquire a leader lock for cuurent engine.
1632 static inline bool bnx2x_trylock_leader_lock(struct bnx2x *bp)
1634 return bnx2x_trylock_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
1638 static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err);
1641 void bnx2x_sp_event(struct bnx2x_fastpath *fp, union eth_rx_cqe *rr_cqe)
1643 struct bnx2x *bp = fp->bp;
1644 int cid = SW_CID(rr_cqe->ramrod_cqe.conn_and_cmd_data);
1645 int command = CQE_CMD(rr_cqe->ramrod_cqe.conn_and_cmd_data);
1646 enum bnx2x_queue_cmd drv_cmd = BNX2X_Q_CMD_MAX;
1647 struct bnx2x_queue_sp_obj *q_obj = &fp->q_obj;
1650 "fp %d cid %d got ramrod #%d state is %x type is %d\n",
1651 fp->index, cid, command, bp->state,
1652 rr_cqe->ramrod_cqe.ramrod_type);
1655 case (RAMROD_CMD_ID_ETH_CLIENT_UPDATE):
1656 DP(NETIF_MSG_IFUP, "got UPDATE ramrod. CID %d\n", cid);
1657 drv_cmd = BNX2X_Q_CMD_UPDATE;
1659 case (RAMROD_CMD_ID_ETH_CLIENT_SETUP):
1660 DP(NETIF_MSG_IFUP, "got MULTI[%d] setup ramrod\n", cid);
1661 drv_cmd = BNX2X_Q_CMD_SETUP;
1664 case (RAMROD_CMD_ID_ETH_HALT):
1665 DP(NETIF_MSG_IFDOWN, "got MULTI[%d] halt ramrod\n", cid);
1666 drv_cmd = BNX2X_Q_CMD_HALT;
1669 case (RAMROD_CMD_ID_ETH_TERMINATE):
1670 DP(NETIF_MSG_IFDOWN, "got MULTI[%d] teminate ramrod\n", cid);
1671 drv_cmd = BNX2X_Q_CMD_TERMINATE;
1674 case (RAMROD_CMD_ID_ETH_EMPTY):
1675 DP(NETIF_MSG_IFDOWN, "got MULTI[%d] empty ramrod\n", cid);
1676 drv_cmd = BNX2X_Q_CMD_EMPTY;
1680 BNX2X_ERR("unexpected MC reply (%d) on fp[%d]\n",
1681 command, fp->index);
1685 if ((drv_cmd != BNX2X_Q_CMD_MAX) &&
1686 q_obj->complete_cmd(bp, q_obj, drv_cmd))
1687 /* q_obj->complete_cmd() failure means that this was
1688 * an unexpected completion.
1690 * In this case we don't want to increase the bp->spq_left
1691 * because apparently we haven't sent this command the first
1694 #ifdef BNX2X_STOP_ON_ERROR
1700 smp_mb__before_atomic_inc();
1701 atomic_inc(&bp->cq_spq_left);
1702 /* push the change in bp->spq_left and towards the memory */
1703 smp_mb__after_atomic_inc();
1708 void bnx2x_update_rx_prod(struct bnx2x *bp, struct bnx2x_fastpath *fp,
1709 u16 bd_prod, u16 rx_comp_prod, u16 rx_sge_prod)
1711 u32 start = BAR_USTRORM_INTMEM + fp->ustorm_rx_prods_offset;
1713 bnx2x_update_rx_prod_gen(bp, fp, bd_prod, rx_comp_prod, rx_sge_prod,
1717 irqreturn_t bnx2x_interrupt(int irq, void *dev_instance)
1719 struct bnx2x *bp = netdev_priv(dev_instance);
1720 u16 status = bnx2x_ack_int(bp);
1724 /* Return here if interrupt is shared and it's not for us */
1725 if (unlikely(status == 0)) {
1726 DP(NETIF_MSG_INTR, "not our interrupt!\n");
1729 DP(NETIF_MSG_INTR, "got an interrupt status 0x%x\n", status);
1731 #ifdef BNX2X_STOP_ON_ERROR
1732 if (unlikely(bp->panic))
1736 for_each_eth_queue(bp, i) {
1737 struct bnx2x_fastpath *fp = &bp->fp[i];
1739 mask = 0x2 << (fp->index + CNIC_CONTEXT_USE);
1740 if (status & mask) {
1741 /* Handle Rx or Tx according to SB id */
1742 prefetch(fp->rx_cons_sb);
1743 prefetch(fp->tx_cons_sb);
1744 prefetch(&fp->sb_running_index[SM_RX_ID]);
1745 napi_schedule(&bnx2x_fp(bp, fp->index, napi));
1752 if (status & (mask | 0x1)) {
1753 struct cnic_ops *c_ops = NULL;
1755 if (likely(bp->state == BNX2X_STATE_OPEN)) {
1757 c_ops = rcu_dereference(bp->cnic_ops);
1759 c_ops->cnic_handler(bp->cnic_data, NULL);
1767 if (unlikely(status & 0x1)) {
1768 queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
1775 if (unlikely(status))
1776 DP(NETIF_MSG_INTR, "got an unknown interrupt! (status 0x%x)\n",
1785 * General service functions
1788 int bnx2x_acquire_hw_lock(struct bnx2x *bp, u32 resource)
1791 u32 resource_bit = (1 << resource);
1792 int func = BP_FUNC(bp);
1793 u32 hw_lock_control_reg;
1796 /* Validating that the resource is within range */
1797 if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
1799 "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
1800 resource, HW_LOCK_MAX_RESOURCE_VALUE);
1805 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
1807 hw_lock_control_reg =
1808 (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
1811 /* Validating that the resource is not already taken */
1812 lock_status = REG_RD(bp, hw_lock_control_reg);
1813 if (lock_status & resource_bit) {
1814 DP(NETIF_MSG_HW, "lock_status 0x%x resource_bit 0x%x\n",
1815 lock_status, resource_bit);
1819 /* Try for 5 second every 5ms */
1820 for (cnt = 0; cnt < 1000; cnt++) {
1821 /* Try to acquire the lock */
1822 REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
1823 lock_status = REG_RD(bp, hw_lock_control_reg);
1824 if (lock_status & resource_bit)
1829 DP(NETIF_MSG_HW, "Timeout\n");
1833 int bnx2x_release_leader_lock(struct bnx2x *bp)
1835 return bnx2x_release_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
1838 int bnx2x_release_hw_lock(struct bnx2x *bp, u32 resource)
1841 u32 resource_bit = (1 << resource);
1842 int func = BP_FUNC(bp);
1843 u32 hw_lock_control_reg;
1845 DP(NETIF_MSG_HW, "Releasing a lock on resource %d\n", resource);
1847 /* Validating that the resource is within range */
1848 if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
1850 "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
1851 resource, HW_LOCK_MAX_RESOURCE_VALUE);
1856 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
1858 hw_lock_control_reg =
1859 (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
1862 /* Validating that the resource is currently taken */
1863 lock_status = REG_RD(bp, hw_lock_control_reg);
1864 if (!(lock_status & resource_bit)) {
1865 DP(NETIF_MSG_HW, "lock_status 0x%x resource_bit 0x%x\n",
1866 lock_status, resource_bit);
1870 REG_WR(bp, hw_lock_control_reg, resource_bit);
1875 int bnx2x_get_gpio(struct bnx2x *bp, int gpio_num, u8 port)
1877 /* The GPIO should be swapped if swap register is set and active */
1878 int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
1879 REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
1880 int gpio_shift = gpio_num +
1881 (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
1882 u32 gpio_mask = (1 << gpio_shift);
1886 if (gpio_num > MISC_REGISTERS_GPIO_3) {
1887 BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
1891 /* read GPIO value */
1892 gpio_reg = REG_RD(bp, MISC_REG_GPIO);
1894 /* get the requested pin value */
1895 if ((gpio_reg & gpio_mask) == gpio_mask)
1900 DP(NETIF_MSG_LINK, "pin %d value 0x%x\n", gpio_num, value);
1905 int bnx2x_set_gpio(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
1907 /* The GPIO should be swapped if swap register is set and active */
1908 int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
1909 REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
1910 int gpio_shift = gpio_num +
1911 (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
1912 u32 gpio_mask = (1 << gpio_shift);
1915 if (gpio_num > MISC_REGISTERS_GPIO_3) {
1916 BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
1920 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
1921 /* read GPIO and mask except the float bits */
1922 gpio_reg = (REG_RD(bp, MISC_REG_GPIO) & MISC_REGISTERS_GPIO_FLOAT);
1925 case MISC_REGISTERS_GPIO_OUTPUT_LOW:
1926 DP(NETIF_MSG_LINK, "Set GPIO %d (shift %d) -> output low\n",
1927 gpio_num, gpio_shift);
1928 /* clear FLOAT and set CLR */
1929 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
1930 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_CLR_POS);
1933 case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
1934 DP(NETIF_MSG_LINK, "Set GPIO %d (shift %d) -> output high\n",
1935 gpio_num, gpio_shift);
1936 /* clear FLOAT and set SET */
1937 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
1938 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_SET_POS);
1941 case MISC_REGISTERS_GPIO_INPUT_HI_Z:
1942 DP(NETIF_MSG_LINK, "Set GPIO %d (shift %d) -> input\n",
1943 gpio_num, gpio_shift);
1945 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
1952 REG_WR(bp, MISC_REG_GPIO, gpio_reg);
1953 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
1958 int bnx2x_set_gpio_int(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
1960 /* The GPIO should be swapped if swap register is set and active */
1961 int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
1962 REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
1963 int gpio_shift = gpio_num +
1964 (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
1965 u32 gpio_mask = (1 << gpio_shift);
1968 if (gpio_num > MISC_REGISTERS_GPIO_3) {
1969 BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
1973 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
1975 gpio_reg = REG_RD(bp, MISC_REG_GPIO_INT);
1978 case MISC_REGISTERS_GPIO_INT_OUTPUT_CLR:
1979 DP(NETIF_MSG_LINK, "Clear GPIO INT %d (shift %d) -> "
1980 "output low\n", gpio_num, gpio_shift);
1981 /* clear SET and set CLR */
1982 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
1983 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
1986 case MISC_REGISTERS_GPIO_INT_OUTPUT_SET:
1987 DP(NETIF_MSG_LINK, "Set GPIO INT %d (shift %d) -> "
1988 "output high\n", gpio_num, gpio_shift);
1989 /* clear CLR and set SET */
1990 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
1991 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
1998 REG_WR(bp, MISC_REG_GPIO_INT, gpio_reg);
1999 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
2004 static int bnx2x_set_spio(struct bnx2x *bp, int spio_num, u32 mode)
2006 u32 spio_mask = (1 << spio_num);
2009 if ((spio_num < MISC_REGISTERS_SPIO_4) ||
2010 (spio_num > MISC_REGISTERS_SPIO_7)) {
2011 BNX2X_ERR("Invalid SPIO %d\n", spio_num);
2015 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
2016 /* read SPIO and mask except the float bits */
2017 spio_reg = (REG_RD(bp, MISC_REG_SPIO) & MISC_REGISTERS_SPIO_FLOAT);
2020 case MISC_REGISTERS_SPIO_OUTPUT_LOW:
2021 DP(NETIF_MSG_LINK, "Set SPIO %d -> output low\n", spio_num);
2022 /* clear FLOAT and set CLR */
2023 spio_reg &= ~(spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS);
2024 spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_CLR_POS);
2027 case MISC_REGISTERS_SPIO_OUTPUT_HIGH:
2028 DP(NETIF_MSG_LINK, "Set SPIO %d -> output high\n", spio_num);
2029 /* clear FLOAT and set SET */
2030 spio_reg &= ~(spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS);
2031 spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_SET_POS);
2034 case MISC_REGISTERS_SPIO_INPUT_HI_Z:
2035 DP(NETIF_MSG_LINK, "Set SPIO %d -> input\n", spio_num);
2037 spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS);
2044 REG_WR(bp, MISC_REG_SPIO, spio_reg);
2045 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
2050 void bnx2x_calc_fc_adv(struct bnx2x *bp)
2052 u8 cfg_idx = bnx2x_get_link_cfg_idx(bp);
2053 switch (bp->link_vars.ieee_fc &
2054 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK) {
2055 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE:
2056 bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
2060 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH:
2061 bp->port.advertising[cfg_idx] |= (ADVERTISED_Asym_Pause |
2065 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC:
2066 bp->port.advertising[cfg_idx] |= ADVERTISED_Asym_Pause;
2070 bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
2076 u8 bnx2x_initial_phy_init(struct bnx2x *bp, int load_mode)
2078 if (!BP_NOMCP(bp)) {
2080 int cfx_idx = bnx2x_get_link_cfg_idx(bp);
2081 u16 req_line_speed = bp->link_params.req_line_speed[cfx_idx];
2082 /* Initialize link parameters structure variables */
2083 /* It is recommended to turn off RX FC for jumbo frames
2084 for better performance */
2085 if ((CHIP_IS_E1x(bp)) && (bp->dev->mtu > 5000))
2086 bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_TX;
2088 bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_BOTH;
2090 bnx2x_acquire_phy_lock(bp);
2092 if (load_mode == LOAD_DIAG) {
2093 bp->link_params.loopback_mode = LOOPBACK_XGXS;
2094 bp->link_params.req_line_speed[cfx_idx] = SPEED_10000;
2097 rc = bnx2x_phy_init(&bp->link_params, &bp->link_vars);
2099 bnx2x_release_phy_lock(bp);
2101 bnx2x_calc_fc_adv(bp);
2103 if (CHIP_REV_IS_SLOW(bp) && bp->link_vars.link_up) {
2104 bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
2105 bnx2x_link_report(bp);
2107 bp->link_params.req_line_speed[cfx_idx] = req_line_speed;
2110 BNX2X_ERR("Bootcode is missing - can not initialize link\n");
2114 void bnx2x_link_set(struct bnx2x *bp)
2116 if (!BP_NOMCP(bp)) {
2117 bnx2x_acquire_phy_lock(bp);
2118 bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
2119 bnx2x_phy_init(&bp->link_params, &bp->link_vars);
2120 bnx2x_release_phy_lock(bp);
2122 bnx2x_calc_fc_adv(bp);
2124 BNX2X_ERR("Bootcode is missing - can not set link\n");
2127 static void bnx2x__link_reset(struct bnx2x *bp)
2129 if (!BP_NOMCP(bp)) {
2130 bnx2x_acquire_phy_lock(bp);
2131 bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
2132 bnx2x_release_phy_lock(bp);
2134 BNX2X_ERR("Bootcode is missing - can not reset link\n");
2137 u8 bnx2x_link_test(struct bnx2x *bp, u8 is_serdes)
2141 if (!BP_NOMCP(bp)) {
2142 bnx2x_acquire_phy_lock(bp);
2143 rc = bnx2x_test_link(&bp->link_params, &bp->link_vars,
2145 bnx2x_release_phy_lock(bp);
2147 BNX2X_ERR("Bootcode is missing - can not test link\n");
2152 static void bnx2x_init_port_minmax(struct bnx2x *bp)
2154 u32 r_param = bp->link_vars.line_speed / 8;
2155 u32 fair_periodic_timeout_usec;
2158 memset(&(bp->cmng.rs_vars), 0,
2159 sizeof(struct rate_shaping_vars_per_port));
2160 memset(&(bp->cmng.fair_vars), 0, sizeof(struct fairness_vars_per_port));
2162 /* 100 usec in SDM ticks = 25 since each tick is 4 usec */
2163 bp->cmng.rs_vars.rs_periodic_timeout = RS_PERIODIC_TIMEOUT_USEC / 4;
2165 /* this is the threshold below which no timer arming will occur
2166 1.25 coefficient is for the threshold to be a little bigger
2167 than the real time, to compensate for timer in-accuracy */
2168 bp->cmng.rs_vars.rs_threshold =
2169 (RS_PERIODIC_TIMEOUT_USEC * r_param * 5) / 4;
2171 /* resolution of fairness timer */
2172 fair_periodic_timeout_usec = QM_ARB_BYTES / r_param;
2173 /* for 10G it is 1000usec. for 1G it is 10000usec. */
2174 t_fair = T_FAIR_COEF / bp->link_vars.line_speed;
2176 /* this is the threshold below which we won't arm the timer anymore */
2177 bp->cmng.fair_vars.fair_threshold = QM_ARB_BYTES;
2179 /* we multiply by 1e3/8 to get bytes/msec.
2180 We don't want the credits to pass a credit
2181 of the t_fair*FAIR_MEM (algorithm resolution) */
2182 bp->cmng.fair_vars.upper_bound = r_param * t_fair * FAIR_MEM;
2183 /* since each tick is 4 usec */
2184 bp->cmng.fair_vars.fairness_timeout = fair_periodic_timeout_usec / 4;
2187 /* Calculates the sum of vn_min_rates.
2188 It's needed for further normalizing of the min_rates.
2190 sum of vn_min_rates.
2192 0 - if all the min_rates are 0.
2193 In the later case fainess algorithm should be deactivated.
2194 If not all min_rates are zero then those that are zeroes will be set to 1.
2196 static void bnx2x_calc_vn_weight_sum(struct bnx2x *bp)
2201 bp->vn_weight_sum = 0;
2202 for (vn = VN_0; vn < E1HVN_MAX; vn++) {
2203 u32 vn_cfg = bp->mf_config[vn];
2204 u32 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
2205 FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
2207 /* Skip hidden vns */
2208 if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
2211 /* If min rate is zero - set it to 1 */
2213 vn_min_rate = DEF_MIN_RATE;
2217 bp->vn_weight_sum += vn_min_rate;
2220 /* if ETS or all min rates are zeros - disable fairness */
2221 if (BNX2X_IS_ETS_ENABLED(bp)) {
2222 bp->cmng.flags.cmng_enables &=
2223 ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
2224 DP(NETIF_MSG_IFUP, "Fairness will be disabled due to ETS\n");
2225 } else if (all_zero) {
2226 bp->cmng.flags.cmng_enables &=
2227 ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
2228 DP(NETIF_MSG_IFUP, "All MIN values are zeroes"
2229 " fairness will be disabled\n");
2231 bp->cmng.flags.cmng_enables |=
2232 CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
2235 static void bnx2x_init_vn_minmax(struct bnx2x *bp, int vn)
2237 struct rate_shaping_vars_per_vn m_rs_vn;
2238 struct fairness_vars_per_vn m_fair_vn;
2239 u32 vn_cfg = bp->mf_config[vn];
2240 int func = 2*vn + BP_PORT(bp);
2241 u16 vn_min_rate, vn_max_rate;
2244 /* If function is hidden - set min and max to zeroes */
2245 if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE) {
2250 u32 maxCfg = bnx2x_extract_max_cfg(bp, vn_cfg);
2252 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
2253 FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
2254 /* If fairness is enabled (not all min rates are zeroes) and
2255 if current min rate is zero - set it to 1.
2256 This is a requirement of the algorithm. */
2257 if (bp->vn_weight_sum && (vn_min_rate == 0))
2258 vn_min_rate = DEF_MIN_RATE;
2261 /* maxCfg in percents of linkspeed */
2262 vn_max_rate = (bp->link_vars.line_speed * maxCfg) / 100;
2264 /* maxCfg is absolute in 100Mb units */
2265 vn_max_rate = maxCfg * 100;
2269 "func %d: vn_min_rate %d vn_max_rate %d vn_weight_sum %d\n",
2270 func, vn_min_rate, vn_max_rate, bp->vn_weight_sum);
2272 memset(&m_rs_vn, 0, sizeof(struct rate_shaping_vars_per_vn));
2273 memset(&m_fair_vn, 0, sizeof(struct fairness_vars_per_vn));
2275 /* global vn counter - maximal Mbps for this vn */
2276 m_rs_vn.vn_counter.rate = vn_max_rate;
2278 /* quota - number of bytes transmitted in this period */
2279 m_rs_vn.vn_counter.quota =
2280 (vn_max_rate * RS_PERIODIC_TIMEOUT_USEC) / 8;
2282 if (bp->vn_weight_sum) {
2283 /* credit for each period of the fairness algorithm:
2284 number of bytes in T_FAIR (the vn share the port rate).
2285 vn_weight_sum should not be larger than 10000, thus
2286 T_FAIR_COEF / (8 * vn_weight_sum) will always be greater
2288 m_fair_vn.vn_credit_delta =
2289 max_t(u32, (vn_min_rate * (T_FAIR_COEF /
2290 (8 * bp->vn_weight_sum))),
2291 (bp->cmng.fair_vars.fair_threshold +
2293 DP(NETIF_MSG_IFUP, "m_fair_vn.vn_credit_delta %d\n",
2294 m_fair_vn.vn_credit_delta);
2297 /* Store it to internal memory */
2298 for (i = 0; i < sizeof(struct rate_shaping_vars_per_vn)/4; i++)
2299 REG_WR(bp, BAR_XSTRORM_INTMEM +
2300 XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(func) + i * 4,
2301 ((u32 *)(&m_rs_vn))[i]);
2303 for (i = 0; i < sizeof(struct fairness_vars_per_vn)/4; i++)
2304 REG_WR(bp, BAR_XSTRORM_INTMEM +
2305 XSTORM_FAIRNESS_PER_VN_VARS_OFFSET(func) + i * 4,
2306 ((u32 *)(&m_fair_vn))[i]);
2309 static int bnx2x_get_cmng_fns_mode(struct bnx2x *bp)
2311 if (CHIP_REV_IS_SLOW(bp))
2312 return CMNG_FNS_NONE;
2314 return CMNG_FNS_MINMAX;
2316 return CMNG_FNS_NONE;
2319 void bnx2x_read_mf_cfg(struct bnx2x *bp)
2321 int vn, n = (CHIP_MODE_IS_4_PORT(bp) ? 2 : 1);
2324 return; /* what should be the default bvalue in this case */
2326 /* For 2 port configuration the absolute function number formula
2328 * abs_func = 2 * vn + BP_PORT + BP_PATH
2330 * and there are 4 functions per port
2332 * For 4 port configuration it is
2333 * abs_func = 4 * vn + 2 * BP_PORT + BP_PATH
2335 * and there are 2 functions per port
2337 for (vn = VN_0; vn < E1HVN_MAX; vn++) {
2338 int /*abs*/func = n * (2 * vn + BP_PORT(bp)) + BP_PATH(bp);
2340 if (func >= E1H_FUNC_MAX)
2344 MF_CFG_RD(bp, func_mf_config[func].config);
2348 static void bnx2x_cmng_fns_init(struct bnx2x *bp, u8 read_cfg, u8 cmng_type)
2351 if (cmng_type == CMNG_FNS_MINMAX) {
2354 /* clear cmng_enables */
2355 bp->cmng.flags.cmng_enables = 0;
2357 /* read mf conf from shmem */
2359 bnx2x_read_mf_cfg(bp);
2361 /* Init rate shaping and fairness contexts */
2362 bnx2x_init_port_minmax(bp);
2364 /* vn_weight_sum and enable fairness if not 0 */
2365 bnx2x_calc_vn_weight_sum(bp);
2367 /* calculate and set min-max rate for each vn */
2369 for (vn = VN_0; vn < E1HVN_MAX; vn++)
2370 bnx2x_init_vn_minmax(bp, vn);
2372 /* always enable rate shaping and fairness */
2373 bp->cmng.flags.cmng_enables |=
2374 CMNG_FLAGS_PER_PORT_RATE_SHAPING_VN;
2375 if (!bp->vn_weight_sum)
2376 DP(NETIF_MSG_IFUP, "All MIN values are zeroes"
2377 " fairness will be disabled\n");
2381 /* rate shaping and fairness are disabled */
2383 "rate shaping and fairness are disabled\n");
2386 static inline void bnx2x_link_sync_notify(struct bnx2x *bp)
2388 int port = BP_PORT(bp);
2392 /* Set the attention towards other drivers on the same port */
2393 for (vn = VN_0; vn < E1HVN_MAX; vn++) {
2394 if (vn == BP_E1HVN(bp))
2397 func = ((vn << 1) | port);
2398 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_0 +
2399 (LINK_SYNC_ATTENTION_BIT_FUNC_0 + func)*4, 1);
2403 /* This function is called upon link interrupt */
2404 static void bnx2x_link_attn(struct bnx2x *bp)
2406 /* Make sure that we are synced with the current statistics */
2407 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
2409 bnx2x_link_update(&bp->link_params, &bp->link_vars);
2411 if (bp->link_vars.link_up) {
2413 /* dropless flow control */
2414 if (!CHIP_IS_E1(bp) && bp->dropless_fc) {
2415 int port = BP_PORT(bp);
2416 u32 pause_enabled = 0;
2418 if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX)
2421 REG_WR(bp, BAR_USTRORM_INTMEM +
2422 USTORM_ETH_PAUSE_ENABLED_OFFSET(port),
2426 if (bp->link_vars.mac_type != MAC_TYPE_EMAC) {
2427 struct host_port_stats *pstats;
2429 pstats = bnx2x_sp(bp, port_stats);
2430 /* reset old mac stats */
2431 memset(&(pstats->mac_stx[0]), 0,
2432 sizeof(struct mac_stx));
2434 if (bp->state == BNX2X_STATE_OPEN)
2435 bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
2438 if (bp->link_vars.link_up && bp->link_vars.line_speed) {
2439 int cmng_fns = bnx2x_get_cmng_fns_mode(bp);
2441 if (cmng_fns != CMNG_FNS_NONE) {
2442 bnx2x_cmng_fns_init(bp, false, cmng_fns);
2443 storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
2445 /* rate shaping and fairness are disabled */
2447 "single function mode without fairness\n");
2450 __bnx2x_link_report(bp);
2453 bnx2x_link_sync_notify(bp);
2456 void bnx2x__link_status_update(struct bnx2x *bp)
2458 if (bp->state != BNX2X_STATE_OPEN)
2461 bnx2x_link_status_update(&bp->link_params, &bp->link_vars);
2463 if (bp->link_vars.link_up)
2464 bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
2466 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
2468 /* indicate link status */
2469 bnx2x_link_report(bp);
2472 static void bnx2x_pmf_update(struct bnx2x *bp)
2474 int port = BP_PORT(bp);
2478 DP(NETIF_MSG_LINK, "pmf %d\n", bp->port.pmf);
2480 bnx2x_dcbx_pmf_update(bp);
2482 /* enable nig attention */
2483 val = (0xff0f | (1 << (BP_E1HVN(bp) + 4)));
2484 if (bp->common.int_block == INT_BLOCK_HC) {
2485 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
2486 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
2487 } else if (!CHIP_IS_E1x(bp)) {
2488 REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
2489 REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
2492 bnx2x_stats_handle(bp, STATS_EVENT_PMF);
2500 * General service functions
2503 /* send the MCP a request, block until there is a reply */
2504 u32 bnx2x_fw_command(struct bnx2x *bp, u32 command, u32 param)
2506 int mb_idx = BP_FW_MB_IDX(bp);
2510 u8 delay = CHIP_REV_IS_SLOW(bp) ? 100 : 10;
2512 mutex_lock(&bp->fw_mb_mutex);
2514 SHMEM_WR(bp, func_mb[mb_idx].drv_mb_param, param);
2515 SHMEM_WR(bp, func_mb[mb_idx].drv_mb_header, (command | seq));
2517 DP(BNX2X_MSG_MCP, "wrote command (%x) to FW MB param 0x%08x\n",
2518 (command | seq), param);
2521 /* let the FW do it's magic ... */
2524 rc = SHMEM_RD(bp, func_mb[mb_idx].fw_mb_header);
2526 /* Give the FW up to 5 second (500*10ms) */
2527 } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 500));
2529 DP(BNX2X_MSG_MCP, "[after %d ms] read (%x) seq is (%x) from FW MB\n",
2530 cnt*delay, rc, seq);
2532 /* is this a reply to our command? */
2533 if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK))
2534 rc &= FW_MSG_CODE_MASK;
2537 BNX2X_ERR("FW failed to respond!\n");
2541 mutex_unlock(&bp->fw_mb_mutex);
2546 static u8 stat_counter_valid(struct bnx2x *bp, struct bnx2x_fastpath *fp)
2549 /* Statistics are not supported for CNIC Clients at the moment */
2556 void bnx2x_func_init(struct bnx2x *bp, struct bnx2x_func_init_params *p)
2558 if (CHIP_IS_E1x(bp)) {
2559 struct tstorm_eth_function_common_config tcfg = {0};
2561 storm_memset_func_cfg(bp, &tcfg, p->func_id);
2564 /* Enable the function in the FW */
2565 storm_memset_vf_to_pf(bp, p->func_id, p->pf_id);
2566 storm_memset_func_en(bp, p->func_id, 1);
2569 if (p->func_flgs & FUNC_FLG_SPQ) {
2570 storm_memset_spq_addr(bp, p->spq_map, p->func_id);
2571 REG_WR(bp, XSEM_REG_FAST_MEMORY +
2572 XSTORM_SPQ_PROD_OFFSET(p->func_id), p->spq_prod);
2576 static inline unsigned long bnx2x_get_q_flags(struct bnx2x *bp,
2577 struct bnx2x_fastpath *fp,
2580 unsigned long flags = 0;
2582 /* PF driver will always initialize the Queue to an ACTIVE state */
2583 __set_bit(BNX2X_Q_FLG_ACTIVE, &flags);
2585 /* calculate other queue flags */
2587 __set_bit(BNX2X_Q_FLG_OV, &flags);
2590 __set_bit(BNX2X_Q_FLG_FCOE, &flags);
2592 if (!fp->disable_tpa)
2593 __set_bit(BNX2X_Q_FLG_TPA, &flags);
2595 if (stat_counter_valid(bp, fp)) {
2596 __set_bit(BNX2X_Q_FLG_STATS, &flags);
2597 __set_bit(BNX2X_Q_FLG_ZERO_STATS, &flags);
2601 __set_bit(BNX2X_Q_FLG_LEADING_RSS, &flags);
2602 __set_bit(BNX2X_Q_FLG_MCAST, &flags);
2605 /* Always set HW VLAN stripping */
2606 __set_bit(BNX2X_Q_FLG_VLAN, &flags);
2611 static void bnx2x_pf_q_prep_general(struct bnx2x *bp,
2612 struct bnx2x_fastpath *fp, struct bnx2x_general_setup_params *gen_init)
2614 gen_init->stat_id = bnx2x_stats_id(fp);
2615 gen_init->spcl_id = fp->cl_id;
2617 /* Always use mini-jumbo MTU for FCoE L2 ring */
2619 gen_init->mtu = BNX2X_FCOE_MINI_JUMBO_MTU;
2621 gen_init->mtu = bp->dev->mtu;
2624 static void bnx2x_pf_rx_q_prep(struct bnx2x *bp,
2625 struct bnx2x_fastpath *fp, struct rxq_pause_params *pause,
2626 struct bnx2x_rxq_setup_params *rxq_init)
2630 u16 tpa_agg_size = 0;
2632 if (!fp->disable_tpa) {
2633 pause->sge_th_hi = 250;
2634 pause->sge_th_lo = 150;
2635 tpa_agg_size = min_t(u32,
2636 (min_t(u32, 8, MAX_SKB_FRAGS) *
2637 SGE_PAGE_SIZE * PAGES_PER_SGE), 0xffff);
2638 max_sge = SGE_PAGE_ALIGN(bp->dev->mtu) >>
2640 max_sge = ((max_sge + PAGES_PER_SGE - 1) &
2641 (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
2642 sge_sz = (u16)min_t(u32, SGE_PAGE_SIZE * PAGES_PER_SGE,
2646 /* pause - not for e1 */
2647 if (!CHIP_IS_E1(bp)) {
2648 pause->bd_th_hi = 350;
2649 pause->bd_th_lo = 250;
2650 pause->rcq_th_hi = 350;
2651 pause->rcq_th_lo = 250;
2657 rxq_init->dscr_map = fp->rx_desc_mapping;
2658 rxq_init->sge_map = fp->rx_sge_mapping;
2659 rxq_init->rcq_map = fp->rx_comp_mapping;
2660 rxq_init->rcq_np_map = fp->rx_comp_mapping + BCM_PAGE_SIZE;
2662 /* This should be a maximum number of data bytes that may be
2663 * placed on the BD (not including paddings).
2665 rxq_init->buf_sz = fp->rx_buf_size - BNX2X_FW_RX_ALIGN -
2666 IP_HEADER_ALIGNMENT_PADDING;
2668 rxq_init->cl_qzone_id = fp->cl_qzone_id;
2669 rxq_init->tpa_agg_sz = tpa_agg_size;
2670 rxq_init->sge_buf_sz = sge_sz;
2671 rxq_init->max_sges_pkt = max_sge;
2672 rxq_init->rss_engine_id = BP_FUNC(bp);
2674 /* Maximum number or simultaneous TPA aggregation for this Queue.
2676 * For PF Clients it should be the maximum avaliable number.
2677 * VF driver(s) may want to define it to a smaller value.
2679 rxq_init->max_tpa_queues =
2680 (CHIP_IS_E1(bp) ? ETH_MAX_AGGREGATION_QUEUES_E1 :
2681 ETH_MAX_AGGREGATION_QUEUES_E1H_E2);
2683 rxq_init->cache_line_log = BNX2X_RX_ALIGN_SHIFT;
2684 rxq_init->fw_sb_id = fp->fw_sb_id;
2687 rxq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_RX_CQ_CONS;
2689 rxq_init->sb_cq_index = U_SB_ETH_RX_CQ_INDEX;
2692 static void bnx2x_pf_tx_q_prep(struct bnx2x *bp,
2693 struct bnx2x_fastpath *fp, struct bnx2x_txq_setup_params *txq_init)
2695 txq_init->dscr_map = fp->tx_desc_mapping;
2696 txq_init->sb_cq_index = C_SB_ETH_TX_CQ_INDEX;
2697 txq_init->traffic_type = LLFC_TRAFFIC_TYPE_NW;
2698 txq_init->fw_sb_id = fp->fw_sb_id;
2701 * set the tss leading client id for TX classfication ==
2702 * leading RSS client id
2704 txq_init->tss_leading_cl_id = bnx2x_fp(bp, 0, cl_id);
2706 if (IS_FCOE_FP(fp)) {
2707 txq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_TX_CQ_CONS;
2708 txq_init->traffic_type = LLFC_TRAFFIC_TYPE_FCOE;
2712 static void bnx2x_pf_init(struct bnx2x *bp)
2714 struct bnx2x_func_init_params func_init = {0};
2715 struct event_ring_data eq_data = { {0} };
2718 if (!CHIP_IS_E1x(bp)) {
2719 /* reset IGU PF statistics: MSIX + ATTN */
2721 REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
2722 BNX2X_IGU_STAS_MSG_VF_CNT*4 +
2723 (CHIP_MODE_IS_4_PORT(bp) ?
2724 BP_FUNC(bp) : BP_VN(bp))*4, 0);
2726 REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
2727 BNX2X_IGU_STAS_MSG_VF_CNT*4 +
2728 BNX2X_IGU_STAS_MSG_PF_CNT*4 +
2729 (CHIP_MODE_IS_4_PORT(bp) ?
2730 BP_FUNC(bp) : BP_VN(bp))*4, 0);
2733 /* function setup flags */
2734 flags = (FUNC_FLG_STATS | FUNC_FLG_LEADING | FUNC_FLG_SPQ);
2736 /* This flag is relevant for E1x only.
2737 * E2 doesn't have a TPA configuration in a function level.
2739 flags |= (bp->flags & TPA_ENABLE_FLAG) ? FUNC_FLG_TPA : 0;
2741 func_init.func_flgs = flags;
2742 func_init.pf_id = BP_FUNC(bp);
2743 func_init.func_id = BP_FUNC(bp);
2744 func_init.spq_map = bp->spq_mapping;
2745 func_init.spq_prod = bp->spq_prod_idx;
2747 bnx2x_func_init(bp, &func_init);
2749 memset(&(bp->cmng), 0, sizeof(struct cmng_struct_per_port));
2752 * Congestion management values depend on the link rate
2753 * There is no active link so initial link rate is set to 10 Gbps.
2754 * When the link comes up The congestion management values are
2755 * re-calculated according to the actual link rate.
2757 bp->link_vars.line_speed = SPEED_10000;
2758 bnx2x_cmng_fns_init(bp, true, bnx2x_get_cmng_fns_mode(bp));
2760 /* Only the PMF sets the HW */
2762 storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
2764 /* init Event Queue */
2765 eq_data.base_addr.hi = U64_HI(bp->eq_mapping);
2766 eq_data.base_addr.lo = U64_LO(bp->eq_mapping);
2767 eq_data.producer = bp->eq_prod;
2768 eq_data.index_id = HC_SP_INDEX_EQ_CONS;
2769 eq_data.sb_id = DEF_SB_ID;
2770 storm_memset_eq_data(bp, &eq_data, BP_FUNC(bp));
2774 static void bnx2x_e1h_disable(struct bnx2x *bp)
2776 int port = BP_PORT(bp);
2778 bnx2x_tx_disable(bp);
2780 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
2783 static void bnx2x_e1h_enable(struct bnx2x *bp)
2785 int port = BP_PORT(bp);
2787 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
2789 /* Tx queue should be only reenabled */
2790 netif_tx_wake_all_queues(bp->dev);
2793 * Should not call netif_carrier_on since it will be called if the link
2794 * is up when checking for link state
2798 /* called due to MCP event (on pmf):
2799 * reread new bandwidth configuration
2801 * notify others function about the change
2803 static inline void bnx2x_config_mf_bw(struct bnx2x *bp)
2805 if (bp->link_vars.link_up) {
2806 bnx2x_cmng_fns_init(bp, true, CMNG_FNS_MINMAX);
2807 bnx2x_link_sync_notify(bp);
2809 storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
2812 static inline void bnx2x_set_mf_bw(struct bnx2x *bp)
2814 bnx2x_config_mf_bw(bp);
2815 bnx2x_fw_command(bp, DRV_MSG_CODE_SET_MF_BW_ACK, 0);
2818 static void bnx2x_dcc_event(struct bnx2x *bp, u32 dcc_event)
2820 DP(BNX2X_MSG_MCP, "dcc_event 0x%x\n", dcc_event);
2822 if (dcc_event & DRV_STATUS_DCC_DISABLE_ENABLE_PF) {
2825 * This is the only place besides the function initialization
2826 * where the bp->flags can change so it is done without any
2829 if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
2830 DP(NETIF_MSG_IFDOWN, "mf_cfg function disabled\n");
2831 bp->flags |= MF_FUNC_DIS;
2833 bnx2x_e1h_disable(bp);
2835 DP(NETIF_MSG_IFUP, "mf_cfg function enabled\n");
2836 bp->flags &= ~MF_FUNC_DIS;
2838 bnx2x_e1h_enable(bp);
2840 dcc_event &= ~DRV_STATUS_DCC_DISABLE_ENABLE_PF;
2842 if (dcc_event & DRV_STATUS_DCC_BANDWIDTH_ALLOCATION) {
2843 bnx2x_config_mf_bw(bp);
2844 dcc_event &= ~DRV_STATUS_DCC_BANDWIDTH_ALLOCATION;
2847 /* Report results to MCP */
2849 bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_FAILURE, 0);
2851 bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_OK, 0);
2854 /* must be called under the spq lock */
2855 static inline struct eth_spe *bnx2x_sp_get_next(struct bnx2x *bp)
2857 struct eth_spe *next_spe = bp->spq_prod_bd;
2859 if (bp->spq_prod_bd == bp->spq_last_bd) {
2860 bp->spq_prod_bd = bp->spq;
2861 bp->spq_prod_idx = 0;
2862 DP(NETIF_MSG_TIMER, "end of spq\n");
2870 /* must be called under the spq lock */
2871 static inline void bnx2x_sp_prod_update(struct bnx2x *bp)
2873 int func = BP_FUNC(bp);
2875 /* Make sure that BD data is updated before writing the producer */
2878 REG_WR16(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func),
2884 * bnx2x_is_contextless_ramrod - check if the current command ends on EQ
2886 * @cmd: command to check
2887 * @cmd_type: command type
2889 static inline bool bnx2x_is_contextless_ramrod(int cmd, int cmd_type)
2891 if ((cmd_type == NONE_CONNECTION_TYPE) ||
2892 (cmd == RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES) ||
2893 (cmd == RAMROD_CMD_ID_ETH_FILTER_RULES) ||
2894 (cmd == RAMROD_CMD_ID_ETH_MULTICAST_RULES) ||
2895 (cmd == RAMROD_CMD_ID_ETH_SET_MAC) ||
2896 (cmd == RAMROD_CMD_ID_ETH_RSS_UPDATE))
2905 * bnx2x_sp_post - place a single command on an SP ring
2907 * @bp: driver handle
2908 * @command: command to place (e.g. SETUP, FILTER_RULES, etc.)
2909 * @cid: SW CID the command is related to
2910 * @data_hi: command private data address (high 32 bits)
2911 * @data_lo: command private data address (low 32 bits)
2912 * @cmd_type: command type (e.g. NONE, ETH)
2914 * SP data is handled as if it's always an address pair, thus data fields are
2915 * not swapped to little endian in upper functions. Instead this function swaps
2916 * data as if it's two u32 fields.
2918 int bnx2x_sp_post(struct bnx2x *bp, int command, int cid,
2919 u32 data_hi, u32 data_lo, int cmd_type)
2921 struct eth_spe *spe;
2923 bool common = bnx2x_is_contextless_ramrod(command, cmd_type);
2925 #ifdef BNX2X_STOP_ON_ERROR
2926 if (unlikely(bp->panic))
2930 spin_lock_bh(&bp->spq_lock);
2933 if (!atomic_read(&bp->eq_spq_left)) {
2934 BNX2X_ERR("BUG! EQ ring full!\n");
2935 spin_unlock_bh(&bp->spq_lock);
2939 } else if (!atomic_read(&bp->cq_spq_left)) {
2940 BNX2X_ERR("BUG! SPQ ring full!\n");
2941 spin_unlock_bh(&bp->spq_lock);
2946 spe = bnx2x_sp_get_next(bp);
2948 /* CID needs port number to be encoded int it */
2949 spe->hdr.conn_and_cmd_data =
2950 cpu_to_le32((command << SPE_HDR_CMD_ID_SHIFT) |
2953 type = (cmd_type << SPE_HDR_CONN_TYPE_SHIFT) & SPE_HDR_CONN_TYPE;
2955 type |= ((BP_FUNC(bp) << SPE_HDR_FUNCTION_ID_SHIFT) &
2956 SPE_HDR_FUNCTION_ID);
2958 spe->hdr.type = cpu_to_le16(type);
2960 spe->data.update_data_addr.hi = cpu_to_le32(data_hi);
2961 spe->data.update_data_addr.lo = cpu_to_le32(data_lo);
2963 /* stats ramrod has it's own slot on the spq */
2964 if (command != RAMROD_CMD_ID_COMMON_STAT_QUERY) {
2966 * It's ok if the actual decrement is issued towards the memory
2967 * somewhere between the spin_lock and spin_unlock. Thus no
2968 * more explict memory barrier is needed.
2971 atomic_dec(&bp->eq_spq_left);
2973 atomic_dec(&bp->cq_spq_left);
2977 DP(BNX2X_MSG_SP/*NETIF_MSG_TIMER*/,
2978 "SPQE[%x] (%x:%x) command %d hw_cid %x data (%x:%x) "
2979 "type(0x%x) left (ETH, COMMON) (%x,%x)\n",
2980 bp->spq_prod_idx, (u32)U64_HI(bp->spq_mapping),
2981 (u32)(U64_LO(bp->spq_mapping) +
2982 (void *)bp->spq_prod_bd - (void *)bp->spq), command,
2983 HW_CID(bp, cid), data_hi, data_lo, type,
2984 atomic_read(&bp->cq_spq_left), atomic_read(&bp->eq_spq_left));
2986 bnx2x_sp_prod_update(bp);
2987 spin_unlock_bh(&bp->spq_lock);
2991 /* acquire split MCP access lock register */
2992 static int bnx2x_acquire_alr(struct bnx2x *bp)
2998 for (j = 0; j < 1000; j++) {
3000 REG_WR(bp, GRCBASE_MCP + 0x9c, val);
3001 val = REG_RD(bp, GRCBASE_MCP + 0x9c);
3002 if (val & (1L << 31))
3007 if (!(val & (1L << 31))) {
3008 BNX2X_ERR("Cannot acquire MCP access lock register\n");
3015 /* release split MCP access lock register */
3016 static void bnx2x_release_alr(struct bnx2x *bp)
3018 REG_WR(bp, GRCBASE_MCP + 0x9c, 0);
3021 #define BNX2X_DEF_SB_ATT_IDX 0x0001
3022 #define BNX2X_DEF_SB_IDX 0x0002
3024 static inline u16 bnx2x_update_dsb_idx(struct bnx2x *bp)
3026 struct host_sp_status_block *def_sb = bp->def_status_blk;
3029 barrier(); /* status block is written to by the chip */
3030 if (bp->def_att_idx != def_sb->atten_status_block.attn_bits_index) {
3031 bp->def_att_idx = def_sb->atten_status_block.attn_bits_index;
3032 rc |= BNX2X_DEF_SB_ATT_IDX;
3035 if (bp->def_idx != def_sb->sp_sb.running_index) {
3036 bp->def_idx = def_sb->sp_sb.running_index;
3037 rc |= BNX2X_DEF_SB_IDX;
3040 /* Do not reorder: indecies reading should complete before handling */
3046 * slow path service functions
3049 static void bnx2x_attn_int_asserted(struct bnx2x *bp, u32 asserted)
3051 int port = BP_PORT(bp);
3052 u32 aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
3053 MISC_REG_AEU_MASK_ATTN_FUNC_0;
3054 u32 nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 :
3055 NIG_REG_MASK_INTERRUPT_PORT0;
3060 if (bp->attn_state & asserted)
3061 BNX2X_ERR("IGU ERROR\n");
3063 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
3064 aeu_mask = REG_RD(bp, aeu_addr);
3066 DP(NETIF_MSG_HW, "aeu_mask %x newly asserted %x\n",
3067 aeu_mask, asserted);
3068 aeu_mask &= ~(asserted & 0x3ff);
3069 DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
3071 REG_WR(bp, aeu_addr, aeu_mask);
3072 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
3074 DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
3075 bp->attn_state |= asserted;
3076 DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
3078 if (asserted & ATTN_HARD_WIRED_MASK) {
3079 if (asserted & ATTN_NIG_FOR_FUNC) {
3081 bnx2x_acquire_phy_lock(bp);
3083 /* save nig interrupt mask */
3084 nig_mask = REG_RD(bp, nig_int_mask_addr);
3086 /* If nig_mask is not set, no need to call the update
3090 REG_WR(bp, nig_int_mask_addr, 0);
3092 bnx2x_link_attn(bp);
3095 /* handle unicore attn? */
3097 if (asserted & ATTN_SW_TIMER_4_FUNC)
3098 DP(NETIF_MSG_HW, "ATTN_SW_TIMER_4_FUNC!\n");
3100 if (asserted & GPIO_2_FUNC)
3101 DP(NETIF_MSG_HW, "GPIO_2_FUNC!\n");
3103 if (asserted & GPIO_3_FUNC)
3104 DP(NETIF_MSG_HW, "GPIO_3_FUNC!\n");
3106 if (asserted & GPIO_4_FUNC)
3107 DP(NETIF_MSG_HW, "GPIO_4_FUNC!\n");
3110 if (asserted & ATTN_GENERAL_ATTN_1) {
3111 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_1!\n");
3112 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_1, 0x0);
3114 if (asserted & ATTN_GENERAL_ATTN_2) {
3115 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_2!\n");
3116 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_2, 0x0);
3118 if (asserted & ATTN_GENERAL_ATTN_3) {
3119 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_3!\n");
3120 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_3, 0x0);
3123 if (asserted & ATTN_GENERAL_ATTN_4) {
3124 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_4!\n");
3125 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_4, 0x0);
3127 if (asserted & ATTN_GENERAL_ATTN_5) {
3128 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_5!\n");
3129 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_5, 0x0);
3131 if (asserted & ATTN_GENERAL_ATTN_6) {
3132 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_6!\n");
3133 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_6, 0x0);
3137 } /* if hardwired */
3139 if (bp->common.int_block == INT_BLOCK_HC)
3140 reg_addr = (HC_REG_COMMAND_REG + port*32 +
3141 COMMAND_REG_ATTN_BITS_SET);
3143 reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_SET_UPPER*8);
3145 DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", asserted,
3146 (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
3147 REG_WR(bp, reg_addr, asserted);
3149 /* now set back the mask */
3150 if (asserted & ATTN_NIG_FOR_FUNC) {
3151 REG_WR(bp, nig_int_mask_addr, nig_mask);
3152 bnx2x_release_phy_lock(bp);
3156 static inline void bnx2x_fan_failure(struct bnx2x *bp)
3158 int port = BP_PORT(bp);
3160 /* mark the failure */
3163 dev_info.port_hw_config[port].external_phy_config);
3165 ext_phy_config &= ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK;
3166 ext_phy_config |= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE;
3167 SHMEM_WR(bp, dev_info.port_hw_config[port].external_phy_config,
3170 /* log the failure */
3171 netdev_err(bp->dev, "Fan Failure on Network Controller has caused"
3172 " the driver to shutdown the card to prevent permanent"
3173 " damage. Please contact OEM Support for assistance\n");
3176 static inline void bnx2x_attn_int_deasserted0(struct bnx2x *bp, u32 attn)
3178 int port = BP_PORT(bp);
3182 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
3183 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
3185 if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) {
3187 val = REG_RD(bp, reg_offset);
3188 val &= ~AEU_INPUTS_ATTN_BITS_SPIO5;
3189 REG_WR(bp, reg_offset, val);
3191 BNX2X_ERR("SPIO5 hw attention\n");
3193 /* Fan failure attention */
3194 bnx2x_hw_reset_phy(&bp->link_params);
3195 bnx2x_fan_failure(bp);
3198 if (attn & (AEU_INPUTS_ATTN_BITS_GPIO3_FUNCTION_0 |
3199 AEU_INPUTS_ATTN_BITS_GPIO3_FUNCTION_1)) {
3200 bnx2x_acquire_phy_lock(bp);
3201 bnx2x_handle_module_detect_int(&bp->link_params);
3202 bnx2x_release_phy_lock(bp);
3205 if (attn & HW_INTERRUT_ASSERT_SET_0) {
3207 val = REG_RD(bp, reg_offset);
3208 val &= ~(attn & HW_INTERRUT_ASSERT_SET_0);
3209 REG_WR(bp, reg_offset, val);
3211 BNX2X_ERR("FATAL HW block attention set0 0x%x\n",
3212 (u32)(attn & HW_INTERRUT_ASSERT_SET_0));
3217 static inline void bnx2x_attn_int_deasserted1(struct bnx2x *bp, u32 attn)
3221 if (attn & AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT) {
3223 val = REG_RD(bp, DORQ_REG_DORQ_INT_STS_CLR);
3224 BNX2X_ERR("DB hw attention 0x%x\n", val);
3225 /* DORQ discard attention */
3227 BNX2X_ERR("FATAL error from DORQ\n");
3230 if (attn & HW_INTERRUT_ASSERT_SET_1) {
3232 int port = BP_PORT(bp);
3235 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 :
3236 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1);
3238 val = REG_RD(bp, reg_offset);
3239 val &= ~(attn & HW_INTERRUT_ASSERT_SET_1);
3240 REG_WR(bp, reg_offset, val);
3242 BNX2X_ERR("FATAL HW block attention set1 0x%x\n",
3243 (u32)(attn & HW_INTERRUT_ASSERT_SET_1));
3248 static inline void bnx2x_attn_int_deasserted2(struct bnx2x *bp, u32 attn)
3252 if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) {
3254 val = REG_RD(bp, CFC_REG_CFC_INT_STS_CLR);
3255 BNX2X_ERR("CFC hw attention 0x%x\n", val);
3256 /* CFC error attention */
3258 BNX2X_ERR("FATAL error from CFC\n");
3261 if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) {
3262 val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_0);
3263 BNX2X_ERR("PXP hw attention-0 0x%x\n", val);
3264 /* RQ_USDMDP_FIFO_OVERFLOW */
3266 BNX2X_ERR("FATAL error from PXP\n");
3268 if (!CHIP_IS_E1x(bp)) {
3269 val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_1);
3270 BNX2X_ERR("PXP hw attention-1 0x%x\n", val);
3274 if (attn & HW_INTERRUT_ASSERT_SET_2) {
3276 int port = BP_PORT(bp);
3279 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 :
3280 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2);
3282 val = REG_RD(bp, reg_offset);
3283 val &= ~(attn & HW_INTERRUT_ASSERT_SET_2);
3284 REG_WR(bp, reg_offset, val);
3286 BNX2X_ERR("FATAL HW block attention set2 0x%x\n",
3287 (u32)(attn & HW_INTERRUT_ASSERT_SET_2));
3292 static inline void bnx2x_attn_int_deasserted3(struct bnx2x *bp, u32 attn)
3296 if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) {
3298 if (attn & BNX2X_PMF_LINK_ASSERT) {
3299 int func = BP_FUNC(bp);
3301 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
3302 bp->mf_config[BP_VN(bp)] = MF_CFG_RD(bp,
3303 func_mf_config[BP_ABS_FUNC(bp)].config);
3305 func_mb[BP_FW_MB_IDX(bp)].drv_status);
3306 if (val & DRV_STATUS_DCC_EVENT_MASK)
3308 (val & DRV_STATUS_DCC_EVENT_MASK));
3310 if (val & DRV_STATUS_SET_MF_BW)
3311 bnx2x_set_mf_bw(bp);
3313 if ((bp->port.pmf == 0) && (val & DRV_STATUS_PMF))
3314 bnx2x_pmf_update(bp);
3316 /* Always call it here: bnx2x_link_report() will
3317 * prevent the link indication duplication.
3319 bnx2x__link_status_update(bp);
3322 (val & DRV_STATUS_DCBX_NEGOTIATION_RESULTS) &&
3323 bp->dcbx_enabled > 0)
3324 /* start dcbx state machine */
3325 bnx2x_dcbx_set_params(bp,
3326 BNX2X_DCBX_STATE_NEG_RECEIVED);
3327 } else if (attn & BNX2X_MC_ASSERT_BITS) {
3329 BNX2X_ERR("MC assert!\n");
3330 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_10, 0);
3331 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_9, 0);
3332 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_8, 0);
3333 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_7, 0);
3336 } else if (attn & BNX2X_MCP_ASSERT) {
3338 BNX2X_ERR("MCP assert!\n");
3339 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_11, 0);
3343 BNX2X_ERR("Unknown HW assert! (attn 0x%x)\n", attn);
3346 if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) {
3347 BNX2X_ERR("LATCHED attention 0x%08x (masked)\n", attn);
3348 if (attn & BNX2X_GRC_TIMEOUT) {
3349 val = CHIP_IS_E1(bp) ? 0 :
3350 REG_RD(bp, MISC_REG_GRC_TIMEOUT_ATTN);
3351 BNX2X_ERR("GRC time-out 0x%08x\n", val);
3353 if (attn & BNX2X_GRC_RSV) {
3354 val = CHIP_IS_E1(bp) ? 0 :
3355 REG_RD(bp, MISC_REG_GRC_RSV_ATTN);
3356 BNX2X_ERR("GRC reserved 0x%08x\n", val);
3358 REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff);
3364 * 0-7 - Engine0 load counter.
3365 * 8-15 - Engine1 load counter.
3366 * 16 - Engine0 RESET_IN_PROGRESS bit.
3367 * 17 - Engine1 RESET_IN_PROGRESS bit.
3368 * 18 - Engine0 ONE_IS_LOADED. Set when there is at least one active function
3370 * 19 - Engine1 ONE_IS_LOADED.
3371 * 20 - Chip reset flow bit. When set none-leader must wait for both engines
3372 * leader to complete (check for both RESET_IN_PROGRESS bits and not for
3373 * just the one belonging to its engine).
3376 #define BNX2X_RECOVERY_GLOB_REG MISC_REG_GENERIC_POR_1
3378 #define BNX2X_PATH0_LOAD_CNT_MASK 0x000000ff
3379 #define BNX2X_PATH0_LOAD_CNT_SHIFT 0
3380 #define BNX2X_PATH1_LOAD_CNT_MASK 0x0000ff00
3381 #define BNX2X_PATH1_LOAD_CNT_SHIFT 8
3382 #define BNX2X_PATH0_RST_IN_PROG_BIT 0x00010000
3383 #define BNX2X_PATH1_RST_IN_PROG_BIT 0x00020000
3384 #define BNX2X_GLOBAL_RESET_BIT 0x00040000
3387 * Set the GLOBAL_RESET bit.
3389 * Should be run under rtnl lock
3391 void bnx2x_set_reset_global(struct bnx2x *bp)
3393 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3395 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val | BNX2X_GLOBAL_RESET_BIT);
3401 * Clear the GLOBAL_RESET bit.
3403 * Should be run under rtnl lock
3405 static inline void bnx2x_clear_reset_global(struct bnx2x *bp)
3407 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3409 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~BNX2X_GLOBAL_RESET_BIT));
3415 * Checks the GLOBAL_RESET bit.
3417 * should be run under rtnl lock
3419 static inline bool bnx2x_reset_is_global(struct bnx2x *bp)
3421 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3423 DP(NETIF_MSG_HW, "GEN_REG_VAL=0x%08x\n", val);
3424 return (val & BNX2X_GLOBAL_RESET_BIT) ? true : false;
3428 * Clear RESET_IN_PROGRESS bit for the current engine.
3430 * Should be run under rtnl lock
3432 static inline void bnx2x_set_reset_done(struct bnx2x *bp)
3434 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3435 u32 bit = BP_PATH(bp) ?
3436 BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
3440 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
3446 * Set RESET_IN_PROGRESS for the current engine.
3448 * should be run under rtnl lock
3450 void bnx2x_set_reset_in_progress(struct bnx2x *bp)
3452 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3453 u32 bit = BP_PATH(bp) ?
3454 BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
3458 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
3464 * Checks the RESET_IN_PROGRESS bit for the given engine.
3465 * should be run under rtnl lock
3467 bool bnx2x_reset_is_done(struct bnx2x *bp, int engine)
3469 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3471 BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
3473 /* return false if bit is set */
3474 return (val & bit) ? false : true;
3478 * Increment the load counter for the current engine.
3480 * should be run under rtnl lock
3482 void bnx2x_inc_load_cnt(struct bnx2x *bp)
3484 u32 val1, val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3485 u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
3486 BNX2X_PATH0_LOAD_CNT_MASK;
3487 u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
3488 BNX2X_PATH0_LOAD_CNT_SHIFT;
3490 DP(NETIF_MSG_HW, "Old GEN_REG_VAL=0x%08x\n", val);
3492 /* get the current counter value */
3493 val1 = (val & mask) >> shift;
3498 /* clear the old value */
3501 /* set the new one */
3502 val |= ((val1 << shift) & mask);
3504 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
3510 * bnx2x_dec_load_cnt - decrement the load counter
3512 * @bp: driver handle
3514 * Should be run under rtnl lock.
3515 * Decrements the load counter for the current engine. Returns
3516 * the new counter value.
3518 u32 bnx2x_dec_load_cnt(struct bnx2x *bp)
3520 u32 val1, val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3521 u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
3522 BNX2X_PATH0_LOAD_CNT_MASK;
3523 u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
3524 BNX2X_PATH0_LOAD_CNT_SHIFT;
3526 DP(NETIF_MSG_HW, "Old GEN_REG_VAL=0x%08x\n", val);
3528 /* get the current counter value */
3529 val1 = (val & mask) >> shift;
3534 /* clear the old value */
3537 /* set the new one */
3538 val |= ((val1 << shift) & mask);
3540 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
3548 * Read the load counter for the current engine.
3550 * should be run under rtnl lock
3552 static inline u32 bnx2x_get_load_cnt(struct bnx2x *bp, int engine)
3554 u32 mask = (engine ? BNX2X_PATH1_LOAD_CNT_MASK :
3555 BNX2X_PATH0_LOAD_CNT_MASK);
3556 u32 shift = (engine ? BNX2X_PATH1_LOAD_CNT_SHIFT :
3557 BNX2X_PATH0_LOAD_CNT_SHIFT);
3558 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3560 DP(NETIF_MSG_HW, "GLOB_REG=0x%08x\n", val);
3562 val = (val & mask) >> shift;
3564 DP(NETIF_MSG_HW, "load_cnt for engine %d = %d\n", engine, val);
3570 * Reset the load counter for the current engine.
3572 * should be run under rtnl lock
3574 static inline void bnx2x_clear_load_cnt(struct bnx2x *bp)
3576 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3577 u32 mask = (BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
3578 BNX2X_PATH0_LOAD_CNT_MASK);
3580 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~mask));
3583 static inline void _print_next_block(int idx, const char *blk)
3590 static inline int bnx2x_check_blocks_with_parity0(u32 sig, int par_num,
3595 for (i = 0; sig; i++) {
3596 cur_bit = ((u32)0x1 << i);
3597 if (sig & cur_bit) {
3599 case AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR:
3601 _print_next_block(par_num++, "BRB");
3603 case AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR:
3605 _print_next_block(par_num++, "PARSER");
3607 case AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR:
3609 _print_next_block(par_num++, "TSDM");
3611 case AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR:
3613 _print_next_block(par_num++,
3616 case AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR:
3618 _print_next_block(par_num++, "TCM");
3620 case AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR:
3622 _print_next_block(par_num++, "TSEMI");
3624 case AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR:
3626 _print_next_block(par_num++, "XPB");
3638 static inline int bnx2x_check_blocks_with_parity1(u32 sig, int par_num,
3639 bool *global, bool print)
3643 for (i = 0; sig; i++) {
3644 cur_bit = ((u32)0x1 << i);
3645 if (sig & cur_bit) {
3647 case AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR:
3649 _print_next_block(par_num++, "PBF");
3651 case AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR:
3653 _print_next_block(par_num++, "QM");
3655 case AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR:
3657 _print_next_block(par_num++, "TM");
3659 case AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR:
3661 _print_next_block(par_num++, "XSDM");
3663 case AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR:
3665 _print_next_block(par_num++, "XCM");
3667 case AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR:
3669 _print_next_block(par_num++, "XSEMI");
3671 case AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR:
3673 _print_next_block(par_num++,
3676 case AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR:
3678 _print_next_block(par_num++, "NIG");
3680 case AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR:
3682 _print_next_block(par_num++,
3686 case AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR:
3688 _print_next_block(par_num++, "DEBUG");
3690 case AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR:
3692 _print_next_block(par_num++, "USDM");
3694 case AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR:
3696 _print_next_block(par_num++, "USEMI");
3698 case AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR:
3700 _print_next_block(par_num++, "UPB");
3702 case AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR:
3704 _print_next_block(par_num++, "CSDM");
3716 static inline int bnx2x_check_blocks_with_parity2(u32 sig, int par_num,
3721 for (i = 0; sig; i++) {
3722 cur_bit = ((u32)0x1 << i);
3723 if (sig & cur_bit) {
3725 case AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR:
3727 _print_next_block(par_num++, "CSEMI");
3729 case AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR:
3731 _print_next_block(par_num++, "PXP");
3733 case AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR:
3735 _print_next_block(par_num++,
3736 "PXPPCICLOCKCLIENT");
3738 case AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR:
3740 _print_next_block(par_num++, "CFC");
3742 case AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR:
3744 _print_next_block(par_num++, "CDU");
3746 case AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR:
3748 _print_next_block(par_num++, "DMAE");
3750 case AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR:
3752 _print_next_block(par_num++, "IGU");
3754 case AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR:
3756 _print_next_block(par_num++, "MISC");
3768 static inline int bnx2x_check_blocks_with_parity3(u32 sig, int par_num,
3769 bool *global, bool print)
3773 for (i = 0; sig; i++) {
3774 cur_bit = ((u32)0x1 << i);
3775 if (sig & cur_bit) {
3777 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY:
3779 _print_next_block(par_num++, "MCP ROM");
3782 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY:
3784 _print_next_block(par_num++,
3788 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY:
3790 _print_next_block(par_num++,
3794 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY:
3796 _print_next_block(par_num++,
3810 static inline bool bnx2x_parity_attn(struct bnx2x *bp, bool *global, bool print,
3811 u32 sig0, u32 sig1, u32 sig2, u32 sig3)
3813 if ((sig0 & HW_PRTY_ASSERT_SET_0) || (sig1 & HW_PRTY_ASSERT_SET_1) ||
3814 (sig2 & HW_PRTY_ASSERT_SET_2) || (sig3 & HW_PRTY_ASSERT_SET_3)) {
3816 DP(NETIF_MSG_HW, "Was parity error: HW block parity attention: "
3817 "[0]:0x%08x [1]:0x%08x "
3818 "[2]:0x%08x [3]:0x%08x\n",
3819 sig0 & HW_PRTY_ASSERT_SET_0,
3820 sig1 & HW_PRTY_ASSERT_SET_1,
3821 sig2 & HW_PRTY_ASSERT_SET_2,
3822 sig3 & HW_PRTY_ASSERT_SET_3);
3825 "Parity errors detected in blocks: ");
3826 par_num = bnx2x_check_blocks_with_parity0(
3827 sig0 & HW_PRTY_ASSERT_SET_0, par_num, print);
3828 par_num = bnx2x_check_blocks_with_parity1(
3829 sig1 & HW_PRTY_ASSERT_SET_1, par_num, global, print);
3830 par_num = bnx2x_check_blocks_with_parity2(
3831 sig2 & HW_PRTY_ASSERT_SET_2, par_num, print);
3832 par_num = bnx2x_check_blocks_with_parity3(
3833 sig3 & HW_PRTY_ASSERT_SET_3, par_num, global, print);
3842 * bnx2x_chk_parity_attn - checks for parity attentions.
3844 * @bp: driver handle
3845 * @global: true if there was a global attention
3846 * @print: show parity attention in syslog
3848 bool bnx2x_chk_parity_attn(struct bnx2x *bp, bool *global, bool print)
3850 struct attn_route attn;
3851 int port = BP_PORT(bp);
3853 attn.sig[0] = REG_RD(bp,
3854 MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 +
3856 attn.sig[1] = REG_RD(bp,
3857 MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 +
3859 attn.sig[2] = REG_RD(bp,
3860 MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 +
3862 attn.sig[3] = REG_RD(bp,
3863 MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 +
3866 return bnx2x_parity_attn(bp, global, print, attn.sig[0], attn.sig[1],
3867 attn.sig[2], attn.sig[3]);
3871 static inline void bnx2x_attn_int_deasserted4(struct bnx2x *bp, u32 attn)
3874 if (attn & AEU_INPUTS_ATTN_BITS_PGLUE_HW_INTERRUPT) {
3876 val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS_CLR);
3877 BNX2X_ERR("PGLUE hw attention 0x%x\n", val);
3878 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR)
3879 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_"
3881 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR)
3882 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_"
3883 "INCORRECT_RCV_BEHAVIOR\n");
3884 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN)
3885 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_"
3886 "WAS_ERROR_ATTN\n");
3887 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN)
3888 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_"
3889 "VF_LENGTH_VIOLATION_ATTN\n");
3891 PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN)
3892 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_"
3893 "VF_GRC_SPACE_VIOLATION_ATTN\n");
3895 PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN)
3896 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_"
3897 "VF_MSIX_BAR_VIOLATION_ATTN\n");
3898 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN)
3899 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_"
3900 "TCPL_ERROR_ATTN\n");
3901 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN)
3902 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_"
3903 "TCPL_IN_TWO_RCBS_ATTN\n");
3904 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW)
3905 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_"
3906 "CSSNOOP_FIFO_OVERFLOW\n");
3908 if (attn & AEU_INPUTS_ATTN_BITS_ATC_HW_INTERRUPT) {
3909 val = REG_RD(bp, ATC_REG_ATC_INT_STS_CLR);
3910 BNX2X_ERR("ATC hw attention 0x%x\n", val);
3911 if (val & ATC_ATC_INT_STS_REG_ADDRESS_ERROR)
3912 BNX2X_ERR("ATC_ATC_INT_STS_REG_ADDRESS_ERROR\n");
3913 if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND)
3914 BNX2X_ERR("ATC_ATC_INT_STS_REG"
3915 "_ATC_TCPL_TO_NOT_PEND\n");
3916 if (val & ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS)
3917 BNX2X_ERR("ATC_ATC_INT_STS_REG_"
3918 "ATC_GPA_MULTIPLE_HITS\n");
3919 if (val & ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT)
3920 BNX2X_ERR("ATC_ATC_INT_STS_REG_"
3921 "ATC_RCPL_TO_EMPTY_CNT\n");
3922 if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR)
3923 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR\n");
3924 if (val & ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU)
3925 BNX2X_ERR("ATC_ATC_INT_STS_REG_"
3926 "ATC_IREQ_LESS_THAN_STU\n");
3929 if (attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
3930 AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)) {
3931 BNX2X_ERR("FATAL parity attention set4 0x%x\n",
3932 (u32)(attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
3933 AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)));
3938 static void bnx2x_attn_int_deasserted(struct bnx2x *bp, u32 deasserted)
3940 struct attn_route attn, *group_mask;
3941 int port = BP_PORT(bp);
3946 bool global = false;
3948 /* need to take HW lock because MCP or other port might also
3949 try to handle this event */
3950 bnx2x_acquire_alr(bp);
3952 if (bnx2x_chk_parity_attn(bp, &global, true)) {
3953 #ifndef BNX2X_STOP_ON_ERROR
3954 bp->recovery_state = BNX2X_RECOVERY_INIT;
3955 schedule_delayed_work(&bp->reset_task, 0);
3956 /* Disable HW interrupts */
3957 bnx2x_int_disable(bp);
3958 /* In case of parity errors don't handle attentions so that
3959 * other function would "see" parity errors.
3964 bnx2x_release_alr(bp);
3968 attn.sig[0] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4);
3969 attn.sig[1] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4);
3970 attn.sig[2] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4);
3971 attn.sig[3] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4);
3972 if (!CHIP_IS_E1x(bp))
3974 REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + port*4);
3978 DP(NETIF_MSG_HW, "attn: %08x %08x %08x %08x %08x\n",
3979 attn.sig[0], attn.sig[1], attn.sig[2], attn.sig[3], attn.sig[4]);
3981 for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
3982 if (deasserted & (1 << index)) {
3983 group_mask = &bp->attn_group[index];
3985 DP(NETIF_MSG_HW, "group[%d]: %08x %08x "
3988 group_mask->sig[0], group_mask->sig[1],
3989 group_mask->sig[2], group_mask->sig[3],
3990 group_mask->sig[4]);
3992 bnx2x_attn_int_deasserted4(bp,
3993 attn.sig[4] & group_mask->sig[4]);
3994 bnx2x_attn_int_deasserted3(bp,
3995 attn.sig[3] & group_mask->sig[3]);
3996 bnx2x_attn_int_deasserted1(bp,
3997 attn.sig[1] & group_mask->sig[1]);
3998 bnx2x_attn_int_deasserted2(bp,
3999 attn.sig[2] & group_mask->sig[2]);
4000 bnx2x_attn_int_deasserted0(bp,
4001 attn.sig[0] & group_mask->sig[0]);
4005 bnx2x_release_alr(bp);
4007 if (bp->common.int_block == INT_BLOCK_HC)
4008 reg_addr = (HC_REG_COMMAND_REG + port*32 +
4009 COMMAND_REG_ATTN_BITS_CLR);
4011 reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_CLR_UPPER*8);
4014 DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", val,
4015 (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
4016 REG_WR(bp, reg_addr, val);
4018 if (~bp->attn_state & deasserted)
4019 BNX2X_ERR("IGU ERROR\n");
4021 reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
4022 MISC_REG_AEU_MASK_ATTN_FUNC_0;
4024 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
4025 aeu_mask = REG_RD(bp, reg_addr);
4027 DP(NETIF_MSG_HW, "aeu_mask %x newly deasserted %x\n",
4028 aeu_mask, deasserted);
4029 aeu_mask |= (deasserted & 0x3ff);
4030 DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
4032 REG_WR(bp, reg_addr, aeu_mask);
4033 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
4035 DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
4036 bp->attn_state &= ~deasserted;
4037 DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
4040 static void bnx2x_attn_int(struct bnx2x *bp)
4042 /* read local copy of bits */
4043 u32 attn_bits = le32_to_cpu(bp->def_status_blk->atten_status_block.
4045 u32 attn_ack = le32_to_cpu(bp->def_status_blk->atten_status_block.
4047 u32 attn_state = bp->attn_state;
4049 /* look for changed bits */
4050 u32 asserted = attn_bits & ~attn_ack & ~attn_state;
4051 u32 deasserted = ~attn_bits & attn_ack & attn_state;
4054 "attn_bits %x attn_ack %x asserted %x deasserted %x\n",
4055 attn_bits, attn_ack, asserted, deasserted);
4057 if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state))
4058 BNX2X_ERR("BAD attention state\n");
4060 /* handle bits that were raised */
4062 bnx2x_attn_int_asserted(bp, asserted);
4065 bnx2x_attn_int_deasserted(bp, deasserted);
4068 void bnx2x_igu_ack_sb(struct bnx2x *bp, u8 igu_sb_id, u8 segment,
4069 u16 index, u8 op, u8 update)
4071 u32 igu_addr = BAR_IGU_INTMEM + (IGU_CMD_INT_ACK_BASE + igu_sb_id)*8;
4073 bnx2x_igu_ack_sb_gen(bp, igu_sb_id, segment, index, op, update,
4077 static inline void bnx2x_update_eq_prod(struct bnx2x *bp, u16 prod)
4079 /* No memory barriers */
4080 storm_memset_eq_prod(bp, prod, BP_FUNC(bp));
4081 mmiowb(); /* keep prod updates ordered */
4085 static int bnx2x_cnic_handle_cfc_del(struct bnx2x *bp, u32 cid,
4086 union event_ring_elem *elem)
4088 u8 err = elem->message.error;
4090 if (!bp->cnic_eth_dev.starting_cid ||
4091 (cid < bp->cnic_eth_dev.starting_cid &&
4092 cid != bp->cnic_eth_dev.iscsi_l2_cid))
4095 DP(BNX2X_MSG_SP, "got delete ramrod for CNIC CID %d\n", cid);
4097 if (unlikely(err)) {
4099 BNX2X_ERR("got delete ramrod for CNIC CID %d with error!\n",
4101 bnx2x_panic_dump(bp);
4103 bnx2x_cnic_cfc_comp(bp, cid, err);
4108 static inline void bnx2x_handle_mcast_eqe(struct bnx2x *bp)
4110 struct bnx2x_mcast_ramrod_params rparam;
4113 memset(&rparam, 0, sizeof(rparam));
4115 rparam.mcast_obj = &bp->mcast_obj;
4117 netif_addr_lock_bh(bp->dev);
4119 /* Clear pending state for the last command */
4120 bp->mcast_obj.raw.clear_pending(&bp->mcast_obj.raw);
4122 /* If there are pending mcast commands - send them */
4123 if (bp->mcast_obj.check_pending(&bp->mcast_obj)) {
4124 rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_CONT);
4126 BNX2X_ERR("Failed to send pending mcast commands: %d\n",
4130 netif_addr_unlock_bh(bp->dev);
4133 static inline void bnx2x_handle_classification_eqe(struct bnx2x *bp,
4134 union event_ring_elem *elem)
4136 unsigned long ramrod_flags = 0;
4138 u32 cid = elem->message.data.eth_event.echo & BNX2X_SWCID_MASK;
4139 struct bnx2x_vlan_mac_obj *vlan_mac_obj;
4141 /* Always push next commands out, don't wait here */
4142 __set_bit(RAMROD_CONT, &ramrod_flags);
4144 switch (elem->message.data.eth_event.echo >> BNX2X_SWCID_SHIFT) {
4145 case BNX2X_FILTER_MAC_PENDING:
4147 if (cid == BNX2X_ISCSI_ETH_CID)
4148 vlan_mac_obj = &bp->iscsi_l2_mac_obj;
4151 vlan_mac_obj = &bp->fp[cid].mac_obj;
4154 vlan_mac_obj = &bp->fp[cid].mac_obj;
4156 case BNX2X_FILTER_MCAST_PENDING:
4157 /* This is only relevant for 57710 where multicast MACs are
4158 * configured as unicast MACs using the same ramrod.
4160 bnx2x_handle_mcast_eqe(bp);
4163 BNX2X_ERR("Unsupported classification command: %d\n",
4164 elem->message.data.eth_event.echo);
4168 rc = vlan_mac_obj->complete(bp, vlan_mac_obj, elem, &ramrod_flags);
4171 BNX2X_ERR("Failed to schedule new commands: %d\n", rc);
4173 DP(BNX2X_MSG_SP, "Scheduled next pending commands...\n");
4178 static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start);
4181 static inline void bnx2x_handle_rx_mode_eqe(struct bnx2x *bp)
4183 netif_addr_lock_bh(bp->dev);
4185 clear_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
4187 /* Send rx_mode command again if was requested */
4188 if (test_and_clear_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state))
4189 bnx2x_set_storm_rx_mode(bp);
4191 else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED,
4193 bnx2x_set_iscsi_eth_rx_mode(bp, true);
4194 else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED,
4196 bnx2x_set_iscsi_eth_rx_mode(bp, false);
4199 netif_addr_unlock_bh(bp->dev);
4202 static inline struct bnx2x_queue_sp_obj *bnx2x_cid_to_q_obj(
4203 struct bnx2x *bp, u32 cid)
4206 if (cid == BNX2X_FCOE_ETH_CID)
4207 return &bnx2x_fcoe(bp, q_obj);
4210 return &bnx2x_fp(bp, cid, q_obj);
4213 static void bnx2x_eq_int(struct bnx2x *bp)
4215 u16 hw_cons, sw_cons, sw_prod;
4216 union event_ring_elem *elem;
4220 struct bnx2x_queue_sp_obj *q_obj;
4221 struct bnx2x_func_sp_obj *f_obj = &bp->func_obj;
4222 struct bnx2x_raw_obj *rss_raw = &bp->rss_conf_obj.raw;
4224 hw_cons = le16_to_cpu(*bp->eq_cons_sb);
4226 /* The hw_cos range is 1-255, 257 - the sw_cons range is 0-254, 256.
4227 * when we get the the next-page we nned to adjust so the loop
4228 * condition below will be met. The next element is the size of a
4229 * regular element and hence incrementing by 1
4231 if ((hw_cons & EQ_DESC_MAX_PAGE) == EQ_DESC_MAX_PAGE)
4234 /* This function may never run in parallel with itself for a
4235 * specific bp, thus there is no need in "paired" read memory
4238 sw_cons = bp->eq_cons;
4239 sw_prod = bp->eq_prod;
4241 DP(BNX2X_MSG_SP, "EQ: hw_cons %u sw_cons %u bp->cq_spq_left %u\n",
4242 hw_cons, sw_cons, atomic_read(&bp->eq_spq_left));
4244 for (; sw_cons != hw_cons;
4245 sw_prod = NEXT_EQ_IDX(sw_prod), sw_cons = NEXT_EQ_IDX(sw_cons)) {
4248 elem = &bp->eq_ring[EQ_DESC(sw_cons)];
4250 cid = SW_CID(elem->message.data.cfc_del_event.cid);
4251 opcode = elem->message.opcode;
4254 /* handle eq element */
4256 case EVENT_RING_OPCODE_STAT_QUERY:
4257 DP(NETIF_MSG_TIMER, "got statistics comp event %d\n",
4259 /* nothing to do with stats comp */
4262 case EVENT_RING_OPCODE_CFC_DEL:
4263 /* handle according to cid range */
4265 * we may want to verify here that the bp state is
4268 DP(NETIF_MSG_IFDOWN,
4269 "got delete ramrod for MULTI[%d]\n", cid);
4271 if (!bnx2x_cnic_handle_cfc_del(bp, cid, elem))
4274 q_obj = bnx2x_cid_to_q_obj(bp, cid);
4276 if (q_obj->complete_cmd(bp, q_obj, BNX2X_Q_CMD_CFC_DEL))
4283 case EVENT_RING_OPCODE_STOP_TRAFFIC:
4284 DP(NETIF_MSG_IFUP, "got STOP TRAFFIC\n");
4285 bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_PAUSED);
4288 case EVENT_RING_OPCODE_START_TRAFFIC:
4289 DP(NETIF_MSG_IFUP, "got START TRAFFIC\n");
4290 bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_RELEASED);
4292 case EVENT_RING_OPCODE_FUNCTION_START:
4293 DP(NETIF_MSG_IFUP, "got FUNC_START ramrod\n");
4294 if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_START))
4299 case EVENT_RING_OPCODE_FUNCTION_STOP:
4300 DP(NETIF_MSG_IFDOWN, "got FUNC_STOP ramrod\n");
4301 if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_STOP))
4307 switch (opcode | bp->state) {
4308 case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
4310 case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
4311 BNX2X_STATE_OPENING_WAIT4_PORT):
4312 cid = elem->message.data.eth_event.echo &
4314 DP(NETIF_MSG_IFUP, "got RSS_UPDATE ramrod. CID %d\n",
4316 rss_raw->clear_pending(rss_raw);
4319 case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_OPEN):
4320 case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_DIAG):
4321 case (EVENT_RING_OPCODE_SET_MAC |
4322 BNX2X_STATE_CLOSING_WAIT4_HALT):
4323 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
4325 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
4327 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
4328 BNX2X_STATE_CLOSING_WAIT4_HALT):
4329 DP(NETIF_MSG_IFUP, "got (un)set mac ramrod\n");
4330 bnx2x_handle_classification_eqe(bp, elem);
4333 case (EVENT_RING_OPCODE_MULTICAST_RULES |
4335 case (EVENT_RING_OPCODE_MULTICAST_RULES |
4337 case (EVENT_RING_OPCODE_MULTICAST_RULES |
4338 BNX2X_STATE_CLOSING_WAIT4_HALT):
4339 DP(NETIF_MSG_IFUP, "got mcast ramrod\n");
4340 bnx2x_handle_mcast_eqe(bp);
4343 case (EVENT_RING_OPCODE_FILTERS_RULES |
4345 case (EVENT_RING_OPCODE_FILTERS_RULES |
4347 case (EVENT_RING_OPCODE_FILTERS_RULES |
4348 BNX2X_STATE_CLOSING_WAIT4_HALT):
4349 DP(NETIF_MSG_IFUP, "got rx_mode ramrod\n");
4350 bnx2x_handle_rx_mode_eqe(bp);
4353 /* unknown event log error and continue */
4354 BNX2X_ERR("Unknown EQ event %d, bp->state 0x%x\n",
4355 elem->message.opcode, bp->state);
4361 smp_mb__before_atomic_inc();
4362 atomic_add(spqe_cnt, &bp->eq_spq_left);
4364 bp->eq_cons = sw_cons;
4365 bp->eq_prod = sw_prod;
4366 /* Make sure that above mem writes were issued towards the memory */
4369 /* update producer */
4370 bnx2x_update_eq_prod(bp, bp->eq_prod);
4373 static void bnx2x_sp_task(struct work_struct *work)
4375 struct bnx2x *bp = container_of(work, struct bnx2x, sp_task.work);
4378 status = bnx2x_update_dsb_idx(bp);
4379 /* if (status == 0) */
4380 /* BNX2X_ERR("spurious slowpath interrupt!\n"); */
4382 DP(NETIF_MSG_INTR, "got a slowpath interrupt (status 0x%x)\n", status);
4385 if (status & BNX2X_DEF_SB_ATT_IDX) {
4387 status &= ~BNX2X_DEF_SB_ATT_IDX;
4390 /* SP events: STAT_QUERY and others */
4391 if (status & BNX2X_DEF_SB_IDX) {
4393 struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);
4395 if ((!NO_FCOE(bp)) &&
4396 (bnx2x_has_rx_work(fp) || bnx2x_has_tx_work(fp)))
4397 napi_schedule(&bnx2x_fcoe(bp, napi));
4399 /* Handle EQ completions */
4402 bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID,
4403 le16_to_cpu(bp->def_idx), IGU_INT_NOP, 1);
4405 status &= ~BNX2X_DEF_SB_IDX;
4408 if (unlikely(status))
4409 DP(NETIF_MSG_INTR, "got an unknown interrupt! (status 0x%x)\n",
4412 bnx2x_ack_sb(bp, bp->igu_dsb_id, ATTENTION_ID,
4413 le16_to_cpu(bp->def_att_idx), IGU_INT_ENABLE, 1);
4416 irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance)
4418 struct net_device *dev = dev_instance;
4419 struct bnx2x *bp = netdev_priv(dev);
4421 bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0,
4422 IGU_INT_DISABLE, 0);
4424 #ifdef BNX2X_STOP_ON_ERROR
4425 if (unlikely(bp->panic))
4431 struct cnic_ops *c_ops;
4434 c_ops = rcu_dereference(bp->cnic_ops);
4436 c_ops->cnic_handler(bp->cnic_data, NULL);
4440 queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
4445 /* end of slow path */
4448 void bnx2x_drv_pulse(struct bnx2x *bp)
4450 SHMEM_WR(bp, func_mb[BP_FW_MB_IDX(bp)].drv_pulse_mb,
4451 bp->fw_drv_pulse_wr_seq);
4455 static void bnx2x_timer(unsigned long data)
4457 struct bnx2x *bp = (struct bnx2x *) data;
4459 if (!netif_running(bp->dev))
4463 struct bnx2x_fastpath *fp = &bp->fp[0];
4466 bnx2x_rx_int(fp, 1000);
4469 if (!BP_NOMCP(bp)) {
4470 int mb_idx = BP_FW_MB_IDX(bp);
4474 ++bp->fw_drv_pulse_wr_seq;
4475 bp->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK;
4476 /* TBD - add SYSTEM_TIME */
4477 drv_pulse = bp->fw_drv_pulse_wr_seq;
4478 bnx2x_drv_pulse(bp);
4480 mcp_pulse = (SHMEM_RD(bp, func_mb[mb_idx].mcp_pulse_mb) &
4481 MCP_PULSE_SEQ_MASK);
4482 /* The delta between driver pulse and mcp response
4483 * should be 1 (before mcp response) or 0 (after mcp response)
4485 if ((drv_pulse != mcp_pulse) &&
4486 (drv_pulse != ((mcp_pulse + 1) & MCP_PULSE_SEQ_MASK))) {
4487 /* someone lost a heartbeat... */
4488 BNX2X_ERR("drv_pulse (0x%x) != mcp_pulse (0x%x)\n",
4489 drv_pulse, mcp_pulse);
4493 if (bp->state == BNX2X_STATE_OPEN)
4494 bnx2x_stats_handle(bp, STATS_EVENT_UPDATE);
4496 mod_timer(&bp->timer, jiffies + bp->current_interval);
4499 /* end of Statistics */
4504 * nic init service functions
4507 static inline void bnx2x_fill(struct bnx2x *bp, u32 addr, int fill, u32 len)
4510 if (!(len%4) && !(addr%4))
4511 for (i = 0; i < len; i += 4)
4512 REG_WR(bp, addr + i, fill);
4514 for (i = 0; i < len; i++)
4515 REG_WR8(bp, addr + i, fill);
4519 /* helper: writes FP SP data to FW - data_size in dwords */
4520 static inline void bnx2x_wr_fp_sb_data(struct bnx2x *bp,
4526 for (index = 0; index < data_size; index++)
4527 REG_WR(bp, BAR_CSTRORM_INTMEM +
4528 CSTORM_STATUS_BLOCK_DATA_OFFSET(fw_sb_id) +
4530 *(sb_data_p + index));
4533 static inline void bnx2x_zero_fp_sb(struct bnx2x *bp, int fw_sb_id)
4537 struct hc_status_block_data_e2 sb_data_e2;
4538 struct hc_status_block_data_e1x sb_data_e1x;
4540 /* disable the function first */
4541 if (!CHIP_IS_E1x(bp)) {
4542 memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
4543 sb_data_e2.common.state = SB_DISABLED;
4544 sb_data_e2.common.p_func.vf_valid = false;
4545 sb_data_p = (u32 *)&sb_data_e2;
4546 data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
4548 memset(&sb_data_e1x, 0,
4549 sizeof(struct hc_status_block_data_e1x));
4550 sb_data_e1x.common.state = SB_DISABLED;
4551 sb_data_e1x.common.p_func.vf_valid = false;
4552 sb_data_p = (u32 *)&sb_data_e1x;
4553 data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
4555 bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
4557 bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
4558 CSTORM_STATUS_BLOCK_OFFSET(fw_sb_id), 0,
4559 CSTORM_STATUS_BLOCK_SIZE);
4560 bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
4561 CSTORM_SYNC_BLOCK_OFFSET(fw_sb_id), 0,
4562 CSTORM_SYNC_BLOCK_SIZE);
4565 /* helper: writes SP SB data to FW */
4566 static inline void bnx2x_wr_sp_sb_data(struct bnx2x *bp,
4567 struct hc_sp_status_block_data *sp_sb_data)
4569 int func = BP_FUNC(bp);
4571 for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
4572 REG_WR(bp, BAR_CSTRORM_INTMEM +
4573 CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
4575 *((u32 *)sp_sb_data + i));
4578 static inline void bnx2x_zero_sp_sb(struct bnx2x *bp)
4580 int func = BP_FUNC(bp);
4581 struct hc_sp_status_block_data sp_sb_data;
4582 memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
4584 sp_sb_data.state = SB_DISABLED;
4585 sp_sb_data.p_func.vf_valid = false;
4587 bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
4589 bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
4590 CSTORM_SP_STATUS_BLOCK_OFFSET(func), 0,
4591 CSTORM_SP_STATUS_BLOCK_SIZE);
4592 bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
4593 CSTORM_SP_SYNC_BLOCK_OFFSET(func), 0,
4594 CSTORM_SP_SYNC_BLOCK_SIZE);
4600 void bnx2x_setup_ndsb_state_machine(struct hc_status_block_sm *hc_sm,
4601 int igu_sb_id, int igu_seg_id)
4603 hc_sm->igu_sb_id = igu_sb_id;
4604 hc_sm->igu_seg_id = igu_seg_id;
4605 hc_sm->timer_value = 0xFF;
4606 hc_sm->time_to_expire = 0xFFFFFFFF;
4609 static void bnx2x_init_sb(struct bnx2x *bp, dma_addr_t mapping, int vfid,
4610 u8 vf_valid, int fw_sb_id, int igu_sb_id)
4614 struct hc_status_block_data_e2 sb_data_e2;
4615 struct hc_status_block_data_e1x sb_data_e1x;
4616 struct hc_status_block_sm *hc_sm_p;
4620 if (CHIP_INT_MODE_IS_BC(bp))
4621 igu_seg_id = HC_SEG_ACCESS_NORM;
4623 igu_seg_id = IGU_SEG_ACCESS_NORM;
4625 bnx2x_zero_fp_sb(bp, fw_sb_id);
4627 if (!CHIP_IS_E1x(bp)) {
4628 memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
4629 sb_data_e2.common.state = SB_ENABLED;
4630 sb_data_e2.common.p_func.pf_id = BP_FUNC(bp);
4631 sb_data_e2.common.p_func.vf_id = vfid;
4632 sb_data_e2.common.p_func.vf_valid = vf_valid;
4633 sb_data_e2.common.p_func.vnic_id = BP_VN(bp);
4634 sb_data_e2.common.same_igu_sb_1b = true;
4635 sb_data_e2.common.host_sb_addr.hi = U64_HI(mapping);
4636 sb_data_e2.common.host_sb_addr.lo = U64_LO(mapping);
4637 hc_sm_p = sb_data_e2.common.state_machine;
4638 sb_data_p = (u32 *)&sb_data_e2;
4639 data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
4641 memset(&sb_data_e1x, 0,
4642 sizeof(struct hc_status_block_data_e1x));
4643 sb_data_e1x.common.state = SB_ENABLED;
4644 sb_data_e1x.common.p_func.pf_id = BP_FUNC(bp);
4645 sb_data_e1x.common.p_func.vf_id = 0xff;
4646 sb_data_e1x.common.p_func.vf_valid = false;
4647 sb_data_e1x.common.p_func.vnic_id = BP_VN(bp);
4648 sb_data_e1x.common.same_igu_sb_1b = true;
4649 sb_data_e1x.common.host_sb_addr.hi = U64_HI(mapping);
4650 sb_data_e1x.common.host_sb_addr.lo = U64_LO(mapping);
4651 hc_sm_p = sb_data_e1x.common.state_machine;
4652 sb_data_p = (u32 *)&sb_data_e1x;
4653 data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
4656 bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_RX_ID],
4657 igu_sb_id, igu_seg_id);
4658 bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_TX_ID],
4659 igu_sb_id, igu_seg_id);
4661 DP(NETIF_MSG_HW, "Init FW SB %d\n", fw_sb_id);
4663 /* write indecies to HW */
4664 bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
4667 static void bnx2x_update_coalesce_sb(struct bnx2x *bp, u8 fw_sb_id,
4668 u16 tx_usec, u16 rx_usec)
4670 bnx2x_update_coalesce_sb_index(bp, fw_sb_id, U_SB_ETH_RX_CQ_INDEX,
4672 bnx2x_update_coalesce_sb_index(bp, fw_sb_id, C_SB_ETH_TX_CQ_INDEX,
4676 static void bnx2x_init_def_sb(struct bnx2x *bp)
4678 struct host_sp_status_block *def_sb = bp->def_status_blk;
4679 dma_addr_t mapping = bp->def_status_blk_mapping;
4680 int igu_sp_sb_index;
4682 int port = BP_PORT(bp);
4683 int func = BP_FUNC(bp);
4687 struct hc_sp_status_block_data sp_sb_data;
4688 memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
4690 if (CHIP_INT_MODE_IS_BC(bp)) {
4691 igu_sp_sb_index = DEF_SB_IGU_ID;
4692 igu_seg_id = HC_SEG_ACCESS_DEF;
4694 igu_sp_sb_index = bp->igu_dsb_id;
4695 igu_seg_id = IGU_SEG_ACCESS_DEF;
4699 section = ((u64)mapping) + offsetof(struct host_sp_status_block,
4700 atten_status_block);
4701 def_sb->atten_status_block.status_block_id = igu_sp_sb_index;
4705 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
4706 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
4707 for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
4709 /* take care of sig[0]..sig[4] */
4710 for (sindex = 0; sindex < 4; sindex++)
4711 bp->attn_group[index].sig[sindex] =
4712 REG_RD(bp, reg_offset + sindex*0x4 + 0x10*index);
4714 if (!CHIP_IS_E1x(bp))
4716 * enable5 is separate from the rest of the registers,
4717 * and therefore the address skip is 4
4718 * and not 16 between the different groups
4720 bp->attn_group[index].sig[4] = REG_RD(bp,
4721 reg_offset + 0x10 + 0x4*index);
4723 bp->attn_group[index].sig[4] = 0;
4726 if (bp->common.int_block == INT_BLOCK_HC) {
4727 reg_offset = (port ? HC_REG_ATTN_MSG1_ADDR_L :
4728 HC_REG_ATTN_MSG0_ADDR_L);
4730 REG_WR(bp, reg_offset, U64_LO(section));
4731 REG_WR(bp, reg_offset + 4, U64_HI(section));
4732 } else if (!CHIP_IS_E1x(bp)) {
4733 REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_L, U64_LO(section));
4734 REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_H, U64_HI(section));
4737 section = ((u64)mapping) + offsetof(struct host_sp_status_block,
4740 bnx2x_zero_sp_sb(bp);
4742 sp_sb_data.state = SB_ENABLED;
4743 sp_sb_data.host_sb_addr.lo = U64_LO(section);
4744 sp_sb_data.host_sb_addr.hi = U64_HI(section);
4745 sp_sb_data.igu_sb_id = igu_sp_sb_index;
4746 sp_sb_data.igu_seg_id = igu_seg_id;
4747 sp_sb_data.p_func.pf_id = func;
4748 sp_sb_data.p_func.vnic_id = BP_VN(bp);
4749 sp_sb_data.p_func.vf_id = 0xff;
4751 bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
4753 bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0, IGU_INT_ENABLE, 0);
4756 void bnx2x_update_coalesce(struct bnx2x *bp)
4760 for_each_eth_queue(bp, i)
4761 bnx2x_update_coalesce_sb(bp, bp->fp[i].fw_sb_id,
4762 bp->tx_ticks, bp->rx_ticks);
4765 static void bnx2x_init_sp_ring(struct bnx2x *bp)
4767 spin_lock_init(&bp->spq_lock);
4768 atomic_set(&bp->cq_spq_left, MAX_SPQ_PENDING);
4770 bp->spq_prod_idx = 0;
4771 bp->dsb_sp_prod = BNX2X_SP_DSB_INDEX;
4772 bp->spq_prod_bd = bp->spq;
4773 bp->spq_last_bd = bp->spq_prod_bd + MAX_SP_DESC_CNT;
4776 static void bnx2x_init_eq_ring(struct bnx2x *bp)
4779 for (i = 1; i <= NUM_EQ_PAGES; i++) {
4780 union event_ring_elem *elem =
4781 &bp->eq_ring[EQ_DESC_CNT_PAGE * i - 1];
4783 elem->next_page.addr.hi =
4784 cpu_to_le32(U64_HI(bp->eq_mapping +
4785 BCM_PAGE_SIZE * (i % NUM_EQ_PAGES)));
4786 elem->next_page.addr.lo =
4787 cpu_to_le32(U64_LO(bp->eq_mapping +
4788 BCM_PAGE_SIZE*(i % NUM_EQ_PAGES)));
4791 bp->eq_prod = NUM_EQ_DESC;
4792 bp->eq_cons_sb = BNX2X_EQ_INDEX;
4793 /* we want a warning message before it gets rought... */
4794 atomic_set(&bp->eq_spq_left,
4795 min_t(int, MAX_SP_DESC_CNT - MAX_SPQ_PENDING, NUM_EQ_DESC) - 1);
4799 /* called with netif_addr_lock_bh() */
4800 void bnx2x_set_q_rx_mode(struct bnx2x *bp, u8 cl_id,
4801 unsigned long rx_mode_flags,
4802 unsigned long rx_accept_flags,
4803 unsigned long tx_accept_flags,
4804 unsigned long ramrod_flags)
4806 struct bnx2x_rx_mode_ramrod_params ramrod_param;
4809 memset(&ramrod_param, 0, sizeof(ramrod_param));
4811 /* Prepare ramrod parameters */
4812 ramrod_param.cid = 0;
4813 ramrod_param.cl_id = cl_id;
4814 ramrod_param.rx_mode_obj = &bp->rx_mode_obj;
4815 ramrod_param.func_id = BP_FUNC(bp);
4817 ramrod_param.pstate = &bp->sp_state;
4818 ramrod_param.state = BNX2X_FILTER_RX_MODE_PENDING;
4820 ramrod_param.rdata = bnx2x_sp(bp, rx_mode_rdata);
4821 ramrod_param.rdata_mapping = bnx2x_sp_mapping(bp, rx_mode_rdata);
4823 set_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
4825 ramrod_param.ramrod_flags = ramrod_flags;
4826 ramrod_param.rx_mode_flags = rx_mode_flags;
4828 ramrod_param.rx_accept_flags = rx_accept_flags;
4829 ramrod_param.tx_accept_flags = tx_accept_flags;
4831 rc = bnx2x_config_rx_mode(bp, &ramrod_param);
4833 BNX2X_ERR("Set rx_mode %d failed\n", bp->rx_mode);
4838 /* called with netif_addr_lock_bh() */
4839 void bnx2x_set_storm_rx_mode(struct bnx2x *bp)
4841 unsigned long rx_mode_flags = 0, ramrod_flags = 0;
4842 unsigned long rx_accept_flags = 0, tx_accept_flags = 0;
4847 /* Configure rx_mode of FCoE Queue */
4848 __set_bit(BNX2X_RX_MODE_FCOE_ETH, &rx_mode_flags);
4851 switch (bp->rx_mode) {
4852 case BNX2X_RX_MODE_NONE:
4854 * 'drop all' supersedes any accept flags that may have been
4855 * passed to the function.
4858 case BNX2X_RX_MODE_NORMAL:
4859 __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
4860 __set_bit(BNX2X_ACCEPT_MULTICAST, &rx_accept_flags);
4861 __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
4863 /* internal switching mode */
4864 __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
4865 __set_bit(BNX2X_ACCEPT_MULTICAST, &tx_accept_flags);
4866 __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
4869 case BNX2X_RX_MODE_ALLMULTI:
4870 __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
4871 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &rx_accept_flags);
4872 __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
4874 /* internal switching mode */
4875 __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
4876 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &tx_accept_flags);
4877 __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
4880 case BNX2X_RX_MODE_PROMISC:
4881 /* According to deffinition of SI mode, iface in promisc mode
4882 * should receive matched and unmatched (in resolution of port)
4885 __set_bit(BNX2X_ACCEPT_UNMATCHED, &rx_accept_flags);
4886 __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
4887 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &rx_accept_flags);
4888 __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
4890 /* internal switching mode */
4891 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &tx_accept_flags);
4892 __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
4895 __set_bit(BNX2X_ACCEPT_ALL_UNICAST, &tx_accept_flags);
4897 __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
4901 BNX2X_ERR("Unknown rx_mode: %d\n", bp->rx_mode);
4905 if (bp->rx_mode != BNX2X_RX_MODE_NONE) {
4906 __set_bit(BNX2X_ACCEPT_ANY_VLAN, &rx_accept_flags);
4907 __set_bit(BNX2X_ACCEPT_ANY_VLAN, &tx_accept_flags);
4910 __set_bit(RAMROD_RX, &ramrod_flags);
4911 __set_bit(RAMROD_TX, &ramrod_flags);
4913 bnx2x_set_q_rx_mode(bp, bp->fp->cl_id, rx_mode_flags, rx_accept_flags,
4914 tx_accept_flags, ramrod_flags);
4917 static void bnx2x_init_internal_common(struct bnx2x *bp)
4923 * In switch independent mode, the TSTORM needs to accept
4924 * packets that failed classification, since approximate match
4925 * mac addresses aren't written to NIG LLH
4927 REG_WR8(bp, BAR_TSTRORM_INTMEM +
4928 TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 2);
4929 else if (!CHIP_IS_E1(bp)) /* 57710 doesn't support MF */
4930 REG_WR8(bp, BAR_TSTRORM_INTMEM +
4931 TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 0);
4933 /* Zero this manually as its initialization is
4934 currently missing in the initTool */
4935 for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++)
4936 REG_WR(bp, BAR_USTRORM_INTMEM +
4937 USTORM_AGG_DATA_OFFSET + i * 4, 0);
4938 if (!CHIP_IS_E1x(bp)) {
4939 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_IGU_MODE_OFFSET,
4940 CHIP_INT_MODE_IS_BC(bp) ?
4941 HC_IGU_BC_MODE : HC_IGU_NBC_MODE);
4945 static void bnx2x_init_internal(struct bnx2x *bp, u32 load_code)
4947 switch (load_code) {
4948 case FW_MSG_CODE_DRV_LOAD_COMMON:
4949 case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP:
4950 bnx2x_init_internal_common(bp);
4953 case FW_MSG_CODE_DRV_LOAD_PORT:
4957 case FW_MSG_CODE_DRV_LOAD_FUNCTION:
4958 /* internal memory per function is
4959 initialized inside bnx2x_pf_init */
4963 BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code);
4968 static inline u8 bnx2x_fp_igu_sb_id(struct bnx2x_fastpath *fp)
4970 return fp->bp->igu_base_sb + fp->index + CNIC_CONTEXT_USE;
4973 static inline u8 bnx2x_fp_fw_sb_id(struct bnx2x_fastpath *fp)
4975 return fp->bp->base_fw_ndsb + fp->index + CNIC_CONTEXT_USE;
4978 static inline u8 bnx2x_fp_cl_id(struct bnx2x_fastpath *fp)
4980 if (CHIP_IS_E1x(fp->bp))
4981 return BP_L_ID(fp->bp) + fp->index;
4982 else /* We want Client ID to be the same as IGU SB ID for 57712 */
4983 return bnx2x_fp_igu_sb_id(fp);
4986 static void bnx2x_init_fp(struct bnx2x *bp, int fp_idx)
4988 struct bnx2x_fastpath *fp = &bp->fp[fp_idx];
4989 unsigned long q_type = 0;
4992 fp->cl_id = bnx2x_fp_cl_id(fp);
4993 fp->fw_sb_id = bnx2x_fp_fw_sb_id(fp);
4994 fp->igu_sb_id = bnx2x_fp_igu_sb_id(fp);
4995 /* qZone id equals to FW (per path) client id */
4996 fp->cl_qzone_id = bnx2x_fp_qzone_id(fp);
4999 fp->ustorm_rx_prods_offset = bnx2x_rx_ustorm_prods_offset(fp);
5000 /* Setup SB indicies */
5001 fp->rx_cons_sb = BNX2X_RX_SB_INDEX;
5002 fp->tx_cons_sb = BNX2X_TX_SB_INDEX;
5004 /* Configure Queue State object */
5005 __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
5006 __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
5007 bnx2x_init_queue_obj(bp, &fp->q_obj, fp->cl_id, fp->cid, BP_FUNC(bp),
5008 bnx2x_sp(bp, q_rdata), bnx2x_sp_mapping(bp, q_rdata),
5012 * Configure classification DBs: Always enable Tx switching
5014 bnx2x_init_vlan_mac_fp_objs(fp, BNX2X_OBJ_TYPE_RX_TX);
5016 DP(NETIF_MSG_IFUP, "queue[%d]: bnx2x_init_sb(%p,%p) "
5017 "cl_id %d fw_sb %d igu_sb %d\n",
5018 fp_idx, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id,
5020 bnx2x_init_sb(bp, fp->status_blk_mapping, BNX2X_VF_ID_INVALID, false,
5021 fp->fw_sb_id, fp->igu_sb_id);
5023 bnx2x_update_fpsb_idx(fp);
5026 void bnx2x_nic_init(struct bnx2x *bp, u32 load_code)
5030 for_each_eth_queue(bp, i)
5031 bnx2x_init_fp(bp, i);
5034 bnx2x_init_fcoe_fp(bp);
5036 bnx2x_init_sb(bp, bp->cnic_sb_mapping,
5037 BNX2X_VF_ID_INVALID, false,
5038 bnx2x_cnic_fw_sb_id(bp), bnx2x_cnic_igu_sb_id(bp));
5042 /* Initialize MOD_ABS interrupts */
5043 bnx2x_init_mod_abs_int(bp, &bp->link_vars, bp->common.chip_id,
5044 bp->common.shmem_base, bp->common.shmem2_base,
5046 /* ensure status block indices were read */
5049 bnx2x_init_def_sb(bp);
5050 bnx2x_update_dsb_idx(bp);
5051 bnx2x_init_rx_rings(bp);
5052 bnx2x_init_tx_rings(bp);
5053 bnx2x_init_sp_ring(bp);
5054 bnx2x_init_eq_ring(bp);
5055 bnx2x_init_internal(bp, load_code);
5057 bnx2x_stats_init(bp);
5059 /* flush all before enabling interrupts */
5063 bnx2x_int_enable(bp);
5065 /* Check for SPIO5 */
5066 bnx2x_attn_int_deasserted0(bp,
5067 REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + BP_PORT(bp)*4) &
5068 AEU_INPUTS_ATTN_BITS_SPIO5);
5071 /* end of nic init */
5074 * gzip service functions
5077 static int bnx2x_gunzip_init(struct bnx2x *bp)
5079 bp->gunzip_buf = dma_alloc_coherent(&bp->pdev->dev, FW_BUF_SIZE,
5080 &bp->gunzip_mapping, GFP_KERNEL);
5081 if (bp->gunzip_buf == NULL)
5084 bp->strm = kmalloc(sizeof(*bp->strm), GFP_KERNEL);
5085 if (bp->strm == NULL)
5088 bp->strm->workspace = kmalloc(zlib_inflate_workspacesize(),
5090 if (bp->strm->workspace == NULL)
5100 dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
5101 bp->gunzip_mapping);
5102 bp->gunzip_buf = NULL;
5105 netdev_err(bp->dev, "Cannot allocate firmware buffer for"
5106 " un-compression\n");
5110 static void bnx2x_gunzip_end(struct bnx2x *bp)
5113 kfree(bp->strm->workspace);
5118 if (bp->gunzip_buf) {
5119 dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
5120 bp->gunzip_mapping);
5121 bp->gunzip_buf = NULL;
5125 static int bnx2x_gunzip(struct bnx2x *bp, const u8 *zbuf, int len)
5129 /* check gzip header */
5130 if ((zbuf[0] != 0x1f) || (zbuf[1] != 0x8b) || (zbuf[2] != Z_DEFLATED)) {
5131 BNX2X_ERR("Bad gzip header\n");
5139 if (zbuf[3] & FNAME)
5140 while ((zbuf[n++] != 0) && (n < len));
5142 bp->strm->next_in = (typeof(bp->strm->next_in))zbuf + n;
5143 bp->strm->avail_in = len - n;
5144 bp->strm->next_out = bp->gunzip_buf;
5145 bp->strm->avail_out = FW_BUF_SIZE;
5147 rc = zlib_inflateInit2(bp->strm, -MAX_WBITS);
5151 rc = zlib_inflate(bp->strm, Z_FINISH);
5152 if ((rc != Z_OK) && (rc != Z_STREAM_END))
5153 netdev_err(bp->dev, "Firmware decompression error: %s\n",
5156 bp->gunzip_outlen = (FW_BUF_SIZE - bp->strm->avail_out);
5157 if (bp->gunzip_outlen & 0x3)
5158 netdev_err(bp->dev, "Firmware decompression error:"
5159 " gunzip_outlen (%d) not aligned\n",
5161 bp->gunzip_outlen >>= 2;
5163 zlib_inflateEnd(bp->strm);
5165 if (rc == Z_STREAM_END)
5171 /* nic load/unload */
5174 * General service functions
5177 /* send a NIG loopback debug packet */
5178 static void bnx2x_lb_pckt(struct bnx2x *bp)
5182 /* Ethernet source and destination addresses */
5183 wb_write[0] = 0x55555555;
5184 wb_write[1] = 0x55555555;
5185 wb_write[2] = 0x20; /* SOP */
5186 REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
5188 /* NON-IP protocol */
5189 wb_write[0] = 0x09000000;
5190 wb_write[1] = 0x55555555;
5191 wb_write[2] = 0x10; /* EOP, eop_bvalid = 0 */
5192 REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
5195 /* some of the internal memories
5196 * are not directly readable from the driver
5197 * to test them we send debug packets
5199 static int bnx2x_int_mem_test(struct bnx2x *bp)
5205 if (CHIP_REV_IS_FPGA(bp))
5207 else if (CHIP_REV_IS_EMUL(bp))
5212 /* Disable inputs of parser neighbor blocks */
5213 REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
5214 REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
5215 REG_WR(bp, CFC_REG_DEBUG0, 0x1);
5216 REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
5218 /* Write 0 to parser credits for CFC search request */
5219 REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
5221 /* send Ethernet packet */
5224 /* TODO do i reset NIG statistic? */
5225 /* Wait until NIG register shows 1 packet of size 0x10 */
5226 count = 1000 * factor;
5229 bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
5230 val = *bnx2x_sp(bp, wb_data[0]);
5238 BNX2X_ERR("NIG timeout val = 0x%x\n", val);
5242 /* Wait until PRS register shows 1 packet */
5243 count = 1000 * factor;
5245 val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
5253 BNX2X_ERR("PRS timeout val = 0x%x\n", val);
5257 /* Reset and init BRB, PRS */
5258 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
5260 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
5262 bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
5263 bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
5265 DP(NETIF_MSG_HW, "part2\n");
5267 /* Disable inputs of parser neighbor blocks */
5268 REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
5269 REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
5270 REG_WR(bp, CFC_REG_DEBUG0, 0x1);
5271 REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
5273 /* Write 0 to parser credits for CFC search request */
5274 REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
5276 /* send 10 Ethernet packets */
5277 for (i = 0; i < 10; i++)
5280 /* Wait until NIG register shows 10 + 1
5281 packets of size 11*0x10 = 0xb0 */
5282 count = 1000 * factor;
5285 bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
5286 val = *bnx2x_sp(bp, wb_data[0]);
5294 BNX2X_ERR("NIG timeout val = 0x%x\n", val);
5298 /* Wait until PRS register shows 2 packets */
5299 val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
5301 BNX2X_ERR("PRS timeout val = 0x%x\n", val);
5303 /* Write 1 to parser credits for CFC search request */
5304 REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x1);
5306 /* Wait until PRS register shows 3 packets */
5307 msleep(10 * factor);
5308 /* Wait until NIG register shows 1 packet of size 0x10 */
5309 val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
5311 BNX2X_ERR("PRS timeout val = 0x%x\n", val);
5313 /* clear NIG EOP FIFO */
5314 for (i = 0; i < 11; i++)
5315 REG_RD(bp, NIG_REG_INGRESS_EOP_LB_FIFO);
5316 val = REG_RD(bp, NIG_REG_INGRESS_EOP_LB_EMPTY);
5318 BNX2X_ERR("clear of NIG failed\n");
5322 /* Reset and init BRB, PRS, NIG */
5323 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
5325 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
5327 bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
5328 bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
5331 REG_WR(bp, PRS_REG_NIC_MODE, 1);
5334 /* Enable inputs of parser neighbor blocks */
5335 REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x7fffffff);
5336 REG_WR(bp, TCM_REG_PRS_IFEN, 0x1);
5337 REG_WR(bp, CFC_REG_DEBUG0, 0x0);
5338 REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x1);
5340 DP(NETIF_MSG_HW, "done\n");
5345 static void bnx2x_enable_blocks_attention(struct bnx2x *bp)
5347 REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
5348 if (!CHIP_IS_E1x(bp))
5349 REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0x40);
5351 REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0);
5352 REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
5353 REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
5355 * mask read length error interrupts in brb for parser
5356 * (parsing unit and 'checksum and crc' unit)
5357 * these errors are legal (PU reads fixed length and CAC can cause
5358 * read length error on truncated packets)
5360 REG_WR(bp, BRB1_REG_BRB1_INT_MASK, 0xFC00);
5361 REG_WR(bp, QM_REG_QM_INT_MASK, 0);
5362 REG_WR(bp, TM_REG_TM_INT_MASK, 0);
5363 REG_WR(bp, XSDM_REG_XSDM_INT_MASK_0, 0);
5364 REG_WR(bp, XSDM_REG_XSDM_INT_MASK_1, 0);
5365 REG_WR(bp, XCM_REG_XCM_INT_MASK, 0);
5366 /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_0, 0); */
5367 /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_1, 0); */
5368 REG_WR(bp, USDM_REG_USDM_INT_MASK_0, 0);
5369 REG_WR(bp, USDM_REG_USDM_INT_MASK_1, 0);
5370 REG_WR(bp, UCM_REG_UCM_INT_MASK, 0);
5371 /* REG_WR(bp, USEM_REG_USEM_INT_MASK_0, 0); */
5372 /* REG_WR(bp, USEM_REG_USEM_INT_MASK_1, 0); */
5373 REG_WR(bp, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0);
5374 REG_WR(bp, CSDM_REG_CSDM_INT_MASK_0, 0);
5375 REG_WR(bp, CSDM_REG_CSDM_INT_MASK_1, 0);
5376 REG_WR(bp, CCM_REG_CCM_INT_MASK, 0);
5377 /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_0, 0); */
5378 /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_1, 0); */
5380 if (CHIP_REV_IS_FPGA(bp))
5381 REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, 0x580000);
5382 else if (!CHIP_IS_E1x(bp))
5383 REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0,
5384 (PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_OF
5385 | PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_AFT
5386 | PXP2_PXP2_INT_MASK_0_REG_PGL_PCIE_ATTN
5387 | PXP2_PXP2_INT_MASK_0_REG_PGL_READ_BLOCKED
5388 | PXP2_PXP2_INT_MASK_0_REG_PGL_WRITE_BLOCKED));
5390 REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, 0x480000);
5391 REG_WR(bp, TSDM_REG_TSDM_INT_MASK_0, 0);
5392 REG_WR(bp, TSDM_REG_TSDM_INT_MASK_1, 0);
5393 REG_WR(bp, TCM_REG_TCM_INT_MASK, 0);
5394 /* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_0, 0); */
5396 if (!CHIP_IS_E1x(bp))
5397 /* enable VFC attentions: bits 11 and 12, bits 31:13 reserved */
5398 REG_WR(bp, TSEM_REG_TSEM_INT_MASK_1, 0x07ff);
5400 REG_WR(bp, CDU_REG_CDU_INT_MASK, 0);
5401 REG_WR(bp, DMAE_REG_DMAE_INT_MASK, 0);
5402 /* REG_WR(bp, MISC_REG_MISC_INT_MASK, 0); */
5403 REG_WR(bp, PBF_REG_PBF_INT_MASK, 0x18); /* bit 3,4 masked */
5406 static void bnx2x_reset_common(struct bnx2x *bp)
5411 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
5414 if (CHIP_IS_E3(bp)) {
5415 val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
5416 val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
5419 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, val);
5422 static void bnx2x_setup_dmae(struct bnx2x *bp)
5425 spin_lock_init(&bp->dmae_lock);
5428 static void bnx2x_init_pxp(struct bnx2x *bp)
5431 int r_order, w_order;
5433 pci_read_config_word(bp->pdev,
5434 bp->pcie_cap + PCI_EXP_DEVCTL, &devctl);
5435 DP(NETIF_MSG_HW, "read 0x%x from devctl\n", devctl);
5436 w_order = ((devctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5);
5438 r_order = ((devctl & PCI_EXP_DEVCTL_READRQ) >> 12);
5440 DP(NETIF_MSG_HW, "force read order to %d\n", bp->mrrs);
5444 bnx2x_init_pxp_arb(bp, r_order, w_order);
5447 static void bnx2x_setup_fan_failure_detection(struct bnx2x *bp)
5457 val = SHMEM_RD(bp, dev_info.shared_hw_config.config2) &
5458 SHARED_HW_CFG_FAN_FAILURE_MASK;
5460 if (val == SHARED_HW_CFG_FAN_FAILURE_ENABLED)
5464 * The fan failure mechanism is usually related to the PHY type since
5465 * the power consumption of the board is affected by the PHY. Currently,
5466 * fan is required for most designs with SFX7101, BCM8727 and BCM8481.
5468 else if (val == SHARED_HW_CFG_FAN_FAILURE_PHY_TYPE)
5469 for (port = PORT_0; port < PORT_MAX; port++) {
5471 bnx2x_fan_failure_det_req(
5473 bp->common.shmem_base,
5474 bp->common.shmem2_base,
5478 DP(NETIF_MSG_HW, "fan detection setting: %d\n", is_required);
5480 if (is_required == 0)
5483 /* Fan failure is indicated by SPIO 5 */
5484 bnx2x_set_spio(bp, MISC_REGISTERS_SPIO_5,
5485 MISC_REGISTERS_SPIO_INPUT_HI_Z);
5487 /* set to active low mode */
5488 val = REG_RD(bp, MISC_REG_SPIO_INT);
5489 val |= ((1 << MISC_REGISTERS_SPIO_5) <<
5490 MISC_REGISTERS_SPIO_INT_OLD_SET_POS);
5491 REG_WR(bp, MISC_REG_SPIO_INT, val);
5493 /* enable interrupt to signal the IGU */
5494 val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
5495 val |= (1 << MISC_REGISTERS_SPIO_5);
5496 REG_WR(bp, MISC_REG_SPIO_EVENT_EN, val);
5499 static void bnx2x_pretend_func(struct bnx2x *bp, u8 pretend_func_num)
5505 if (CHIP_IS_E1H(bp) && (pretend_func_num >= E1H_FUNC_MAX))
5508 switch (BP_ABS_FUNC(bp)) {
5510 offset = PXP2_REG_PGL_PRETEND_FUNC_F0;
5513 offset = PXP2_REG_PGL_PRETEND_FUNC_F1;
5516 offset = PXP2_REG_PGL_PRETEND_FUNC_F2;
5519 offset = PXP2_REG_PGL_PRETEND_FUNC_F3;
5522 offset = PXP2_REG_PGL_PRETEND_FUNC_F4;
5525 offset = PXP2_REG_PGL_PRETEND_FUNC_F5;
5528 offset = PXP2_REG_PGL_PRETEND_FUNC_F6;
5531 offset = PXP2_REG_PGL_PRETEND_FUNC_F7;
5537 REG_WR(bp, offset, pretend_func_num);
5539 DP(NETIF_MSG_HW, "Pretending to func %d\n", pretend_func_num);
5542 void bnx2x_pf_disable(struct bnx2x *bp)
5544 u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
5545 val &= ~IGU_PF_CONF_FUNC_EN;
5547 REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
5548 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
5549 REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 0);
5552 static inline void bnx2x__common_init_phy(struct bnx2x *bp)
5554 u32 shmem_base[2], shmem2_base[2];
5555 shmem_base[0] = bp->common.shmem_base;
5556 shmem2_base[0] = bp->common.shmem2_base;
5557 if (!CHIP_IS_E1x(bp)) {
5559 SHMEM2_RD(bp, other_shmem_base_addr);
5561 SHMEM2_RD(bp, other_shmem2_base_addr);
5563 bnx2x_acquire_phy_lock(bp);
5564 bnx2x_common_init_phy(bp, shmem_base, shmem2_base,
5565 bp->common.chip_id);
5566 bnx2x_release_phy_lock(bp);
5570 * bnx2x_init_hw_common - initialize the HW at the COMMON phase.
5572 * @bp: driver handle
5574 static int bnx2x_init_hw_common(struct bnx2x *bp)
5578 DP(BNX2X_MSG_MCP, "starting common init func %d\n", BP_ABS_FUNC(bp));
5580 bnx2x_reset_common(bp);
5581 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0xffffffff);
5584 if (CHIP_IS_E3(bp)) {
5585 val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
5586 val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
5588 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, val);
5590 bnx2x_init_block(bp, BLOCK_MISC, PHASE_COMMON);
5592 if (!CHIP_IS_E1x(bp)) {
5596 * 4-port mode or 2-port mode we need to turn of master-enable
5597 * for everyone, after that, turn it back on for self.
5598 * so, we disregard multi-function or not, and always disable
5599 * for all functions on the given path, this means 0,2,4,6 for
5600 * path 0 and 1,3,5,7 for path 1
5602 for (abs_func_id = BP_PATH(bp);
5603 abs_func_id < E2_FUNC_MAX*2; abs_func_id += 2) {
5604 if (abs_func_id == BP_ABS_FUNC(bp)) {
5606 PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER,
5611 bnx2x_pretend_func(bp, abs_func_id);
5612 /* clear pf enable */
5613 bnx2x_pf_disable(bp);
5614 bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
5618 bnx2x_init_block(bp, BLOCK_PXP, PHASE_COMMON);
5619 if (CHIP_IS_E1(bp)) {
5620 /* enable HW interrupt from PXP on USDM overflow
5621 bit 16 on INT_MASK_0 */
5622 REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
5625 bnx2x_init_block(bp, BLOCK_PXP2, PHASE_COMMON);
5629 REG_WR(bp, PXP2_REG_RQ_QM_ENDIAN_M, 1);
5630 REG_WR(bp, PXP2_REG_RQ_TM_ENDIAN_M, 1);
5631 REG_WR(bp, PXP2_REG_RQ_SRC_ENDIAN_M, 1);
5632 REG_WR(bp, PXP2_REG_RQ_CDU_ENDIAN_M, 1);
5633 REG_WR(bp, PXP2_REG_RQ_DBG_ENDIAN_M, 1);
5634 /* make sure this value is 0 */
5635 REG_WR(bp, PXP2_REG_RQ_HC_ENDIAN_M, 0);
5637 /* REG_WR(bp, PXP2_REG_RD_PBF_SWAP_MODE, 1); */
5638 REG_WR(bp, PXP2_REG_RD_QM_SWAP_MODE, 1);
5639 REG_WR(bp, PXP2_REG_RD_TM_SWAP_MODE, 1);
5640 REG_WR(bp, PXP2_REG_RD_SRC_SWAP_MODE, 1);
5641 REG_WR(bp, PXP2_REG_RD_CDURD_SWAP_MODE, 1);
5644 bnx2x_ilt_init_page_size(bp, INITOP_SET);
5646 if (CHIP_REV_IS_FPGA(bp) && CHIP_IS_E1H(bp))
5647 REG_WR(bp, PXP2_REG_PGL_TAGS_LIMIT, 0x1);
5649 /* let the HW do it's magic ... */
5651 /* finish PXP init */
5652 val = REG_RD(bp, PXP2_REG_RQ_CFG_DONE);
5654 BNX2X_ERR("PXP2 CFG failed\n");
5657 val = REG_RD(bp, PXP2_REG_RD_INIT_DONE);
5659 BNX2X_ERR("PXP2 RD_INIT failed\n");
5663 /* Timers bug workaround E2 only. We need to set the entire ILT to
5664 * have entries with value "0" and valid bit on.
5665 * This needs to be done by the first PF that is loaded in a path
5666 * (i.e. common phase)
5668 if (!CHIP_IS_E1x(bp)) {
5669 /* In E2 there is a bug in the timers block that can cause function 6 / 7
5670 * (i.e. vnic3) to start even if it is marked as "scan-off".
5671 * This occurs when a different function (func2,3) is being marked
5672 * as "scan-off". Real-life scenario for example: if a driver is being
5673 * load-unloaded while func6,7 are down. This will cause the timer to access
5674 * the ilt, translate to a logical address and send a request to read/write.
5675 * Since the ilt for the function that is down is not valid, this will cause
5676 * a translation error which is unrecoverable.
5677 * The Workaround is intended to make sure that when this happens nothing fatal
5678 * will occur. The workaround:
5679 * 1. First PF driver which loads on a path will:
5680 * a. After taking the chip out of reset, by using pretend,
5681 * it will write "0" to the following registers of
5683 * REG_WR(pdev, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
5684 * REG_WR(pdev, CFC_REG_WEAK_ENABLE_PF,0);
5685 * REG_WR(pdev, CFC_REG_STRONG_ENABLE_PF,0);
5686 * And for itself it will write '1' to
5687 * PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER to enable
5688 * dmae-operations (writing to pram for example.)
5689 * note: can be done for only function 6,7 but cleaner this
5691 * b. Write zero+valid to the entire ILT.
5692 * c. Init the first_timers_ilt_entry, last_timers_ilt_entry of
5693 * VNIC3 (of that port). The range allocated will be the
5694 * entire ILT. This is needed to prevent ILT range error.
5695 * 2. Any PF driver load flow:
5696 * a. ILT update with the physical addresses of the allocated
5698 * b. Wait 20msec. - note that this timeout is needed to make
5699 * sure there are no requests in one of the PXP internal
5700 * queues with "old" ILT addresses.
5701 * c. PF enable in the PGLC.
5702 * d. Clear the was_error of the PF in the PGLC. (could have
5703 * occured while driver was down)
5704 * e. PF enable in the CFC (WEAK + STRONG)
5705 * f. Timers scan enable
5706 * 3. PF driver unload flow:
5707 * a. Clear the Timers scan_en.
5708 * b. Polling for scan_on=0 for that PF.
5709 * c. Clear the PF enable bit in the PXP.
5710 * d. Clear the PF enable in the CFC (WEAK + STRONG)
5711 * e. Write zero+valid to all ILT entries (The valid bit must
5713 * f. If this is VNIC 3 of a port then also init
5714 * first_timers_ilt_entry to zero and last_timers_ilt_entry
5715 * to the last enrty in the ILT.
5718 * Currently the PF error in the PGLC is non recoverable.
5719 * In the future the there will be a recovery routine for this error.
5720 * Currently attention is masked.
5721 * Having an MCP lock on the load/unload process does not guarantee that
5722 * there is no Timer disable during Func6/7 enable. This is because the
5723 * Timers scan is currently being cleared by the MCP on FLR.
5724 * Step 2.d can be done only for PF6/7 and the driver can also check if
5725 * there is error before clearing it. But the flow above is simpler and
5727 * All ILT entries are written by zero+valid and not just PF6/7
5728 * ILT entries since in the future the ILT entries allocation for
5729 * PF-s might be dynamic.
5731 struct ilt_client_info ilt_cli;
5732 struct bnx2x_ilt ilt;
5733 memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
5734 memset(&ilt, 0, sizeof(struct bnx2x_ilt));
5736 /* initialize dummy TM client */
5738 ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
5739 ilt_cli.client_num = ILT_CLIENT_TM;
5741 /* Step 1: set zeroes to all ilt page entries with valid bit on
5742 * Step 2: set the timers first/last ilt entry to point
5743 * to the entire range to prevent ILT range error for 3rd/4th
5744 * vnic (this code assumes existance of the vnic)
5746 * both steps performed by call to bnx2x_ilt_client_init_op()
5747 * with dummy TM client
5749 * we must use pretend since PXP2_REG_RQ_##blk##_FIRST_ILT
5750 * and his brother are split registers
5752 bnx2x_pretend_func(bp, (BP_PATH(bp) + 6));
5753 bnx2x_ilt_client_init_op_ilt(bp, &ilt, &ilt_cli, INITOP_CLEAR);
5754 bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
5756 REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN, BNX2X_PXP_DRAM_ALIGN);
5757 REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_RD, BNX2X_PXP_DRAM_ALIGN);
5758 REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_SEL, 1);
5762 REG_WR(bp, PXP2_REG_RQ_DISABLE_INPUTS, 0);
5763 REG_WR(bp, PXP2_REG_RD_DISABLE_INPUTS, 0);
5765 if (!CHIP_IS_E1x(bp)) {
5766 int factor = CHIP_REV_IS_EMUL(bp) ? 1000 :
5767 (CHIP_REV_IS_FPGA(bp) ? 400 : 0);
5768 bnx2x_init_block(bp, BLOCK_PGLUE_B, PHASE_COMMON);
5770 bnx2x_init_block(bp, BLOCK_ATC, PHASE_COMMON);
5772 /* let the HW do it's magic ... */
5775 val = REG_RD(bp, ATC_REG_ATC_INIT_DONE);
5776 } while (factor-- && (val != 1));
5779 BNX2X_ERR("ATC_INIT failed\n");
5784 bnx2x_init_block(bp, BLOCK_DMAE, PHASE_COMMON);
5786 /* clean the DMAE memory */
5788 bnx2x_init_fill(bp, TSEM_REG_PRAM, 0, 8, 1);
5790 bnx2x_init_block(bp, BLOCK_TCM, PHASE_COMMON);
5792 bnx2x_init_block(bp, BLOCK_UCM, PHASE_COMMON);
5794 bnx2x_init_block(bp, BLOCK_CCM, PHASE_COMMON);
5796 bnx2x_init_block(bp, BLOCK_XCM, PHASE_COMMON);
5798 bnx2x_read_dmae(bp, XSEM_REG_PASSIVE_BUFFER, 3);
5799 bnx2x_read_dmae(bp, CSEM_REG_PASSIVE_BUFFER, 3);
5800 bnx2x_read_dmae(bp, TSEM_REG_PASSIVE_BUFFER, 3);
5801 bnx2x_read_dmae(bp, USEM_REG_PASSIVE_BUFFER, 3);
5803 bnx2x_init_block(bp, BLOCK_QM, PHASE_COMMON);
5806 /* QM queues pointers table */
5807 bnx2x_qm_init_ptr_table(bp, bp->qm_cid_count, INITOP_SET);
5809 /* soft reset pulse */
5810 REG_WR(bp, QM_REG_SOFT_RESET, 1);
5811 REG_WR(bp, QM_REG_SOFT_RESET, 0);
5814 bnx2x_init_block(bp, BLOCK_TM, PHASE_COMMON);
5817 bnx2x_init_block(bp, BLOCK_DORQ, PHASE_COMMON);
5818 REG_WR(bp, DORQ_REG_DPM_CID_OFST, BNX2X_DB_SHIFT);
5819 if (!CHIP_REV_IS_SLOW(bp))
5820 /* enable hw interrupt from doorbell Q */
5821 REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
5823 bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
5825 bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
5826 REG_WR(bp, PRS_REG_A_PRSU_20, 0xf);
5828 if (!CHIP_IS_E1(bp))
5829 REG_WR(bp, PRS_REG_E1HOV_MODE, bp->path_has_ovlan);
5831 if (!CHIP_IS_E1x(bp) && !CHIP_IS_E3B0(bp))
5832 /* Bit-map indicating which L2 hdrs may appear
5833 * after the basic Ethernet header
5835 REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC,
5836 bp->path_has_ovlan ? 7 : 6);
5838 bnx2x_init_block(bp, BLOCK_TSDM, PHASE_COMMON);
5839 bnx2x_init_block(bp, BLOCK_CSDM, PHASE_COMMON);
5840 bnx2x_init_block(bp, BLOCK_USDM, PHASE_COMMON);
5841 bnx2x_init_block(bp, BLOCK_XSDM, PHASE_COMMON);
5843 if (!CHIP_IS_E1x(bp)) {
5844 /* reset VFC memories */
5845 REG_WR(bp, TSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
5846 VFC_MEMORIES_RST_REG_CAM_RST |
5847 VFC_MEMORIES_RST_REG_RAM_RST);
5848 REG_WR(bp, XSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
5849 VFC_MEMORIES_RST_REG_CAM_RST |
5850 VFC_MEMORIES_RST_REG_RAM_RST);
5855 bnx2x_init_block(bp, BLOCK_TSEM, PHASE_COMMON);
5856 bnx2x_init_block(bp, BLOCK_USEM, PHASE_COMMON);
5857 bnx2x_init_block(bp, BLOCK_CSEM, PHASE_COMMON);
5858 bnx2x_init_block(bp, BLOCK_XSEM, PHASE_COMMON);
5861 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
5863 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
5866 bnx2x_init_block(bp, BLOCK_UPB, PHASE_COMMON);
5867 bnx2x_init_block(bp, BLOCK_XPB, PHASE_COMMON);
5868 bnx2x_init_block(bp, BLOCK_PBF, PHASE_COMMON);
5870 if (!CHIP_IS_E1x(bp))
5871 REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC,
5872 bp->path_has_ovlan ? 7 : 6);
5874 REG_WR(bp, SRC_REG_SOFT_RST, 1);
5876 bnx2x_init_block(bp, BLOCK_SRC, PHASE_COMMON);
5879 REG_WR(bp, SRC_REG_KEYSEARCH_0, 0x63285672);
5880 REG_WR(bp, SRC_REG_KEYSEARCH_1, 0x24b8f2cc);
5881 REG_WR(bp, SRC_REG_KEYSEARCH_2, 0x223aef9b);
5882 REG_WR(bp, SRC_REG_KEYSEARCH_3, 0x26001e3a);
5883 REG_WR(bp, SRC_REG_KEYSEARCH_4, 0x7ae91116);
5884 REG_WR(bp, SRC_REG_KEYSEARCH_5, 0x5ce5230b);
5885 REG_WR(bp, SRC_REG_KEYSEARCH_6, 0x298d8adf);
5886 REG_WR(bp, SRC_REG_KEYSEARCH_7, 0x6eb0ff09);
5887 REG_WR(bp, SRC_REG_KEYSEARCH_8, 0x1830f82f);
5888 REG_WR(bp, SRC_REG_KEYSEARCH_9, 0x01e46be7);
5890 REG_WR(bp, SRC_REG_SOFT_RST, 0);
5892 if (sizeof(union cdu_context) != 1024)
5893 /* we currently assume that a context is 1024 bytes */
5894 dev_alert(&bp->pdev->dev, "please adjust the size "
5895 "of cdu_context(%ld)\n",
5896 (long)sizeof(union cdu_context));
5898 bnx2x_init_block(bp, BLOCK_CDU, PHASE_COMMON);
5899 val = (4 << 24) + (0 << 12) + 1024;
5900 REG_WR(bp, CDU_REG_CDU_GLOBAL_PARAMS, val);
5902 bnx2x_init_block(bp, BLOCK_CFC, PHASE_COMMON);
5903 REG_WR(bp, CFC_REG_INIT_REG, 0x7FF);
5904 /* enable context validation interrupt from CFC */
5905 REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
5907 /* set the thresholds to prevent CFC/CDU race */
5908 REG_WR(bp, CFC_REG_DEBUG0, 0x20020000);
5910 bnx2x_init_block(bp, BLOCK_HC, PHASE_COMMON);
5912 if (!CHIP_IS_E1x(bp) && BP_NOMCP(bp))
5913 REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x36);
5915 bnx2x_init_block(bp, BLOCK_IGU, PHASE_COMMON);
5916 bnx2x_init_block(bp, BLOCK_MISC_AEU, PHASE_COMMON);
5918 /* Reset PCIE errors for debug */
5919 REG_WR(bp, 0x2814, 0xffffffff);
5920 REG_WR(bp, 0x3820, 0xffffffff);
5922 if (!CHIP_IS_E1x(bp)) {
5923 REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_CONTROL_5,
5924 (PXPCS_TL_CONTROL_5_ERR_UNSPPORT1 |
5925 PXPCS_TL_CONTROL_5_ERR_UNSPPORT));
5926 REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC345_STAT,
5927 (PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT4 |
5928 PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT3 |
5929 PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT2));
5930 REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC678_STAT,
5931 (PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT7 |
5932 PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT6 |
5933 PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT5));
5936 bnx2x_init_block(bp, BLOCK_NIG, PHASE_COMMON);
5937 if (!CHIP_IS_E1(bp)) {
5938 /* in E3 this done in per-port section */
5939 if (!CHIP_IS_E3(bp))
5940 REG_WR(bp, NIG_REG_LLH_MF_MODE, IS_MF(bp));
5942 if (CHIP_IS_E1H(bp))
5943 /* not applicable for E2 (and above ...) */
5944 REG_WR(bp, NIG_REG_LLH_E1HOV_MODE, IS_MF_SD(bp));
5946 if (CHIP_REV_IS_SLOW(bp))
5949 /* finish CFC init */
5950 val = reg_poll(bp, CFC_REG_LL_INIT_DONE, 1, 100, 10);
5952 BNX2X_ERR("CFC LL_INIT failed\n");
5955 val = reg_poll(bp, CFC_REG_AC_INIT_DONE, 1, 100, 10);
5957 BNX2X_ERR("CFC AC_INIT failed\n");
5960 val = reg_poll(bp, CFC_REG_CAM_INIT_DONE, 1, 100, 10);
5962 BNX2X_ERR("CFC CAM_INIT failed\n");
5965 REG_WR(bp, CFC_REG_DEBUG0, 0);
5967 if (CHIP_IS_E1(bp)) {
5968 /* read NIG statistic
5969 to see if this is our first up since powerup */
5970 bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
5971 val = *bnx2x_sp(bp, wb_data[0]);
5973 /* do internal memory self test */
5974 if ((val == 0) && bnx2x_int_mem_test(bp)) {
5975 BNX2X_ERR("internal mem self test failed\n");
5980 bnx2x_setup_fan_failure_detection(bp);
5982 /* clear PXP2 attentions */
5983 REG_RD(bp, PXP2_REG_PXP2_INT_STS_CLR_0);
5985 bnx2x_enable_blocks_attention(bp);
5986 bnx2x_enable_blocks_parity(bp);
5988 if (!BP_NOMCP(bp)) {
5989 if (CHIP_IS_E1x(bp))
5990 bnx2x__common_init_phy(bp);
5992 BNX2X_ERR("Bootcode is missing - can not initialize link\n");
5998 * bnx2x_init_hw_common_chip - init HW at the COMMON_CHIP phase.
6000 * @bp: driver handle
6002 static int bnx2x_init_hw_common_chip(struct bnx2x *bp)
6004 int rc = bnx2x_init_hw_common(bp);
6009 /* In E2 2-PORT mode, same ext phy is used for the two paths */
6011 bnx2x__common_init_phy(bp);
6016 static int bnx2x_init_hw_port(struct bnx2x *bp)
6018 int port = BP_PORT(bp);
6019 int init_phase = port ? PHASE_PORT1 : PHASE_PORT0;
6023 bnx2x__link_reset(bp);
6025 DP(BNX2X_MSG_MCP, "starting port init port %d\n", port);
6027 REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
6029 bnx2x_init_block(bp, BLOCK_MISC, init_phase);
6030 bnx2x_init_block(bp, BLOCK_PXP, init_phase);
6031 bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
6033 /* Timers bug workaround: disables the pf_master bit in pglue at
6034 * common phase, we need to enable it here before any dmae access are
6035 * attempted. Therefore we manually added the enable-master to the
6036 * port phase (it also happens in the function phase)
6038 if (!CHIP_IS_E1x(bp))
6039 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
6041 bnx2x_init_block(bp, BLOCK_ATC, init_phase);
6042 bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
6043 bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
6044 bnx2x_init_block(bp, BLOCK_QM, init_phase);
6046 bnx2x_init_block(bp, BLOCK_TCM, init_phase);
6047 bnx2x_init_block(bp, BLOCK_UCM, init_phase);
6048 bnx2x_init_block(bp, BLOCK_CCM, init_phase);
6049 bnx2x_init_block(bp, BLOCK_XCM, init_phase);
6051 /* QM cid (connection) count */
6052 bnx2x_qm_init_cid_count(bp, bp->qm_cid_count, INITOP_SET);
6055 bnx2x_init_block(bp, BLOCK_TM, init_phase);
6056 REG_WR(bp, TM_REG_LIN0_SCAN_TIME + port*4, 20);
6057 REG_WR(bp, TM_REG_LIN0_MAX_ACTIVE_CID + port*4, 31);
6060 bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
6062 if (CHIP_IS_E1(bp) || CHIP_IS_E1H(bp)) {
6063 bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
6066 low = ((bp->flags & ONE_PORT_FLAG) ? 160 : 246);
6067 else if (bp->dev->mtu > 4096) {
6068 if (bp->flags & ONE_PORT_FLAG)
6072 /* (24*1024 + val*4)/256 */
6073 low = 96 + (val/64) +
6074 ((val % 64) ? 1 : 0);
6077 low = ((bp->flags & ONE_PORT_FLAG) ? 80 : 160);
6078 high = low + 56; /* 14*1024/256 */
6079 REG_WR(bp, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port*4, low);
6080 REG_WR(bp, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port*4, high);
6083 if (CHIP_MODE_IS_4_PORT(bp))
6084 REG_WR(bp, (BP_PORT(bp) ?
6085 BRB1_REG_MAC_GUARANTIED_1 :
6086 BRB1_REG_MAC_GUARANTIED_0), 40);
6089 bnx2x_init_block(bp, BLOCK_PRS, init_phase);
6090 if (CHIP_IS_E3B0(bp))
6091 /* Ovlan exists only if we are in multi-function +
6092 * switch-dependent mode, in switch-independent there
6093 * is no ovlan headers
6095 REG_WR(bp, BP_PORT(bp) ?
6096 PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
6097 PRS_REG_HDRS_AFTER_BASIC_PORT_0,
6098 (bp->path_has_ovlan ? 7 : 6));
6100 bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
6101 bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
6102 bnx2x_init_block(bp, BLOCK_USDM, init_phase);
6103 bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
6105 bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
6106 bnx2x_init_block(bp, BLOCK_USEM, init_phase);
6107 bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
6108 bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
6110 bnx2x_init_block(bp, BLOCK_UPB, init_phase);
6111 bnx2x_init_block(bp, BLOCK_XPB, init_phase);
6113 bnx2x_init_block(bp, BLOCK_PBF, init_phase);
6115 if (CHIP_IS_E1x(bp)) {
6116 /* configure PBF to work without PAUSE mtu 9000 */
6117 REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
6119 /* update threshold */
6120 REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, (9040/16));
6121 /* update init credit */
6122 REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, (9040/16) + 553 - 22);
6125 REG_WR(bp, PBF_REG_INIT_P0 + port*4, 1);
6127 REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0);
6131 bnx2x_init_block(bp, BLOCK_SRC, init_phase);
6133 bnx2x_init_block(bp, BLOCK_CDU, init_phase);
6134 bnx2x_init_block(bp, BLOCK_CFC, init_phase);
6136 if (CHIP_IS_E1(bp)) {
6137 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
6138 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
6140 bnx2x_init_block(bp, BLOCK_HC, init_phase);
6142 bnx2x_init_block(bp, BLOCK_IGU, init_phase);
6144 bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
6145 /* init aeu_mask_attn_func_0/1:
6146 * - SF mode: bits 3-7 are masked. only bits 0-2 are in use
6147 * - MF mode: bit 3 is masked. bits 0-2 are in use as in SF
6148 * bits 4-7 are used for "per vn group attention" */
6149 val = IS_MF(bp) ? 0xF7 : 0x7;
6150 /* Enable DCBX attention for all but E1 */
6151 val |= CHIP_IS_E1(bp) ? 0 : 0x10;
6152 REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, val);
6154 bnx2x_init_block(bp, BLOCK_NIG, init_phase);
6156 if (!CHIP_IS_E1x(bp)) {
6157 /* Bit-map indicating which L2 hdrs may appear after the
6158 * basic Ethernet header
6160 REG_WR(bp, BP_PORT(bp) ?
6161 NIG_REG_P1_HDRS_AFTER_BASIC :
6162 NIG_REG_P0_HDRS_AFTER_BASIC,
6163 IS_MF_SD(bp) ? 7 : 6);
6166 REG_WR(bp, BP_PORT(bp) ?
6167 NIG_REG_LLH1_MF_MODE :
6168 NIG_REG_LLH_MF_MODE, IS_MF(bp));
6170 if (!CHIP_IS_E3(bp))
6171 REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
6173 if (!CHIP_IS_E1(bp)) {
6174 /* 0x2 disable mf_ov, 0x1 enable */
6175 REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port*4,
6176 (IS_MF_SD(bp) ? 0x1 : 0x2));
6178 if (!CHIP_IS_E1x(bp)) {
6180 switch (bp->mf_mode) {
6181 case MULTI_FUNCTION_SD:
6184 case MULTI_FUNCTION_SI:
6189 REG_WR(bp, (BP_PORT(bp) ? NIG_REG_LLH1_CLS_TYPE :
6190 NIG_REG_LLH0_CLS_TYPE), val);
6193 REG_WR(bp, NIG_REG_LLFC_ENABLE_0 + port*4, 0);
6194 REG_WR(bp, NIG_REG_LLFC_OUT_EN_0 + port*4, 0);
6195 REG_WR(bp, NIG_REG_PAUSE_ENABLE_0 + port*4, 1);
6200 /* If SPIO5 is set to generate interrupts, enable it for this port */
6201 val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
6202 if (val & (1 << MISC_REGISTERS_SPIO_5)) {
6203 u32 reg_addr = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
6204 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
6205 val = REG_RD(bp, reg_addr);
6206 val |= AEU_INPUTS_ATTN_BITS_SPIO5;
6207 REG_WR(bp, reg_addr, val);
6213 static void bnx2x_ilt_wr(struct bnx2x *bp, u32 index, dma_addr_t addr)
6218 reg = PXP2_REG_RQ_ONCHIP_AT + index*8;
6220 reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index*8;
6222 bnx2x_wb_wr(bp, reg, ONCHIP_ADDR1(addr), ONCHIP_ADDR2(addr));
6225 static inline void bnx2x_igu_clear_sb(struct bnx2x *bp, u8 idu_sb_id)
6227 bnx2x_igu_clear_sb_gen(bp, BP_FUNC(bp), idu_sb_id, true /*PF*/);
6230 static inline void bnx2x_clear_func_ilt(struct bnx2x *bp, u32 func)
6232 u32 i, base = FUNC_ILT_BASE(func);
6233 for (i = base; i < base + ILT_PER_FUNC; i++)
6234 bnx2x_ilt_wr(bp, i, 0);
6237 static int bnx2x_init_hw_func(struct bnx2x *bp)
6239 int port = BP_PORT(bp);
6240 int func = BP_FUNC(bp);
6241 int init_phase = PHASE_PF0 + func;
6242 struct bnx2x_ilt *ilt = BP_ILT(bp);
6245 u32 main_mem_base, main_mem_size, main_mem_prty_clr;
6246 int i, main_mem_width;
6248 DP(BNX2X_MSG_MCP, "starting func init func %d\n", func);
6250 /* FLR cleanup - hmmm */
6251 if (!CHIP_IS_E1x(bp))
6252 bnx2x_pf_flr_clnup(bp);
6254 /* set MSI reconfigure capability */
6255 if (bp->common.int_block == INT_BLOCK_HC) {
6256 addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0);
6257 val = REG_RD(bp, addr);
6258 val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0;
6259 REG_WR(bp, addr, val);
6262 bnx2x_init_block(bp, BLOCK_PXP, init_phase);
6263 bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
6266 cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
6268 for (i = 0; i < L2_ILT_LINES(bp); i++) {
6269 ilt->lines[cdu_ilt_start + i].page =
6270 bp->context.vcxt + (ILT_PAGE_CIDS * i);
6271 ilt->lines[cdu_ilt_start + i].page_mapping =
6272 bp->context.cxt_mapping + (CDU_ILT_PAGE_SZ * i);
6273 /* cdu ilt pages are allocated manually so there's no need to
6276 bnx2x_ilt_init_op(bp, INITOP_SET);
6279 bnx2x_src_init_t2(bp, bp->t2, bp->t2_mapping, SRC_CONN_NUM);
6281 /* T1 hash bits value determines the T1 number of entries */
6282 REG_WR(bp, SRC_REG_NUMBER_HASH_BITS0 + port*4, SRC_HASH_BITS);
6287 REG_WR(bp, PRS_REG_NIC_MODE, 1);
6288 #endif /* BCM_CNIC */
6290 if (!CHIP_IS_E1x(bp)) {
6291 u32 pf_conf = IGU_PF_CONF_FUNC_EN;
6293 /* Turn on a single ISR mode in IGU if driver is going to use
6296 if (!(bp->flags & USING_MSIX_FLAG))
6297 pf_conf |= IGU_PF_CONF_SINGLE_ISR_EN;
6299 * Timers workaround bug: function init part.
6300 * Need to wait 20msec after initializing ILT,
6301 * needed to make sure there are no requests in
6302 * one of the PXP internal queues with "old" ILT addresses
6306 * Master enable - Due to WB DMAE writes performed before this
6307 * register is re-initialized as part of the regular function
6310 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
6311 /* Enable the function in IGU */
6312 REG_WR(bp, IGU_REG_PF_CONFIGURATION, pf_conf);
6317 bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
6319 if (!CHIP_IS_E1x(bp))
6320 REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR, func);
6322 bnx2x_init_block(bp, BLOCK_ATC, init_phase);
6323 bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
6324 bnx2x_init_block(bp, BLOCK_NIG, init_phase);
6325 bnx2x_init_block(bp, BLOCK_SRC, init_phase);
6326 bnx2x_init_block(bp, BLOCK_MISC, init_phase);
6327 bnx2x_init_block(bp, BLOCK_TCM, init_phase);
6328 bnx2x_init_block(bp, BLOCK_UCM, init_phase);
6329 bnx2x_init_block(bp, BLOCK_CCM, init_phase);
6330 bnx2x_init_block(bp, BLOCK_XCM, init_phase);
6331 bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
6332 bnx2x_init_block(bp, BLOCK_USEM, init_phase);
6333 bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
6334 bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
6336 if (!CHIP_IS_E1x(bp))
6337 REG_WR(bp, QM_REG_PF_EN, 1);
6339 if (!CHIP_IS_E1x(bp)) {
6340 REG_WR(bp, TSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
6341 REG_WR(bp, USEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
6342 REG_WR(bp, CSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
6343 REG_WR(bp, XSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
6345 bnx2x_init_block(bp, BLOCK_QM, init_phase);
6347 bnx2x_init_block(bp, BLOCK_TM, init_phase);
6348 bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
6349 bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
6350 bnx2x_init_block(bp, BLOCK_PRS, init_phase);
6351 bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
6352 bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
6353 bnx2x_init_block(bp, BLOCK_USDM, init_phase);
6354 bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
6355 bnx2x_init_block(bp, BLOCK_UPB, init_phase);
6356 bnx2x_init_block(bp, BLOCK_XPB, init_phase);
6357 bnx2x_init_block(bp, BLOCK_PBF, init_phase);
6358 if (!CHIP_IS_E1x(bp))
6359 REG_WR(bp, PBF_REG_DISABLE_PF, 0);
6361 bnx2x_init_block(bp, BLOCK_CDU, init_phase);
6363 bnx2x_init_block(bp, BLOCK_CFC, init_phase);
6365 if (!CHIP_IS_E1x(bp))
6366 REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 1);
6369 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
6370 REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + port*8, bp->mf_ov);
6373 bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
6375 /* HC init per function */
6376 if (bp->common.int_block == INT_BLOCK_HC) {
6377 if (CHIP_IS_E1H(bp)) {
6378 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
6380 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
6381 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
6383 bnx2x_init_block(bp, BLOCK_HC, init_phase);
6386 int num_segs, sb_idx, prod_offset;
6388 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
6390 if (!CHIP_IS_E1x(bp)) {
6391 REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
6392 REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
6395 bnx2x_init_block(bp, BLOCK_IGU, init_phase);
6397 if (!CHIP_IS_E1x(bp)) {
6401 * E2 mode: address 0-135 match to the mapping memory;
6402 * 136 - PF0 default prod; 137 - PF1 default prod;
6403 * 138 - PF2 default prod; 139 - PF3 default prod;
6404 * 140 - PF0 attn prod; 141 - PF1 attn prod;
6405 * 142 - PF2 attn prod; 143 - PF3 attn prod;
6408 * E1.5 mode - In backward compatible mode;
6409 * for non default SB; each even line in the memory
6410 * holds the U producer and each odd line hold
6411 * the C producer. The first 128 producers are for
6412 * NDSB (PF0 - 0-31; PF1 - 32-63 and so on). The last 20
6413 * producers are for the DSB for each PF.
6414 * Each PF has five segments: (the order inside each
6415 * segment is PF0; PF1; PF2; PF3) - 128-131 U prods;
6416 * 132-135 C prods; 136-139 X prods; 140-143 T prods;
6417 * 144-147 attn prods;
6419 /* non-default-status-blocks */
6420 num_segs = CHIP_INT_MODE_IS_BC(bp) ?
6421 IGU_BC_NDSB_NUM_SEGS : IGU_NORM_NDSB_NUM_SEGS;
6422 for (sb_idx = 0; sb_idx < bp->igu_sb_cnt; sb_idx++) {
6423 prod_offset = (bp->igu_base_sb + sb_idx) *
6426 for (i = 0; i < num_segs; i++) {
6427 addr = IGU_REG_PROD_CONS_MEMORY +
6428 (prod_offset + i) * 4;
6429 REG_WR(bp, addr, 0);
6431 /* send consumer update with value 0 */
6432 bnx2x_ack_sb(bp, bp->igu_base_sb + sb_idx,
6433 USTORM_ID, 0, IGU_INT_NOP, 1);
6434 bnx2x_igu_clear_sb(bp,
6435 bp->igu_base_sb + sb_idx);
6438 /* default-status-blocks */
6439 num_segs = CHIP_INT_MODE_IS_BC(bp) ?
6440 IGU_BC_DSB_NUM_SEGS : IGU_NORM_DSB_NUM_SEGS;
6442 if (CHIP_MODE_IS_4_PORT(bp))
6443 dsb_idx = BP_FUNC(bp);
6445 dsb_idx = BP_E1HVN(bp);
6447 prod_offset = (CHIP_INT_MODE_IS_BC(bp) ?
6448 IGU_BC_BASE_DSB_PROD + dsb_idx :
6449 IGU_NORM_BASE_DSB_PROD + dsb_idx);
6451 for (i = 0; i < (num_segs * E1HVN_MAX);
6453 addr = IGU_REG_PROD_CONS_MEMORY +
6454 (prod_offset + i)*4;
6455 REG_WR(bp, addr, 0);
6457 /* send consumer update with 0 */
6458 if (CHIP_INT_MODE_IS_BC(bp)) {
6459 bnx2x_ack_sb(bp, bp->igu_dsb_id,
6460 USTORM_ID, 0, IGU_INT_NOP, 1);
6461 bnx2x_ack_sb(bp, bp->igu_dsb_id,
6462 CSTORM_ID, 0, IGU_INT_NOP, 1);
6463 bnx2x_ack_sb(bp, bp->igu_dsb_id,
6464 XSTORM_ID, 0, IGU_INT_NOP, 1);
6465 bnx2x_ack_sb(bp, bp->igu_dsb_id,
6466 TSTORM_ID, 0, IGU_INT_NOP, 1);
6467 bnx2x_ack_sb(bp, bp->igu_dsb_id,
6468 ATTENTION_ID, 0, IGU_INT_NOP, 1);
6470 bnx2x_ack_sb(bp, bp->igu_dsb_id,
6471 USTORM_ID, 0, IGU_INT_NOP, 1);
6472 bnx2x_ack_sb(bp, bp->igu_dsb_id,
6473 ATTENTION_ID, 0, IGU_INT_NOP, 1);
6475 bnx2x_igu_clear_sb(bp, bp->igu_dsb_id);
6477 /* !!! these should become driver const once
6478 rf-tool supports split-68 const */
6479 REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_LSB, 0);
6480 REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_MSB, 0);
6481 REG_WR(bp, IGU_REG_SB_MASK_LSB, 0);
6482 REG_WR(bp, IGU_REG_SB_MASK_MSB, 0);
6483 REG_WR(bp, IGU_REG_PBA_STATUS_LSB, 0);
6484 REG_WR(bp, IGU_REG_PBA_STATUS_MSB, 0);
6488 /* Reset PCIE errors for debug */
6489 REG_WR(bp, 0x2114, 0xffffffff);
6490 REG_WR(bp, 0x2120, 0xffffffff);
6492 if (CHIP_IS_E1x(bp)) {
6493 main_mem_size = HC_REG_MAIN_MEMORY_SIZE / 2; /*dwords*/
6494 main_mem_base = HC_REG_MAIN_MEMORY +
6495 BP_PORT(bp) * (main_mem_size * 4);
6496 main_mem_prty_clr = HC_REG_HC_PRTY_STS_CLR;
6499 val = REG_RD(bp, main_mem_prty_clr);
6501 DP(BNX2X_MSG_MCP, "Hmmm... Parity errors in HC "
6503 "function init (0x%x)!\n", val);
6505 /* Clear "false" parity errors in MSI-X table */
6506 for (i = main_mem_base;
6507 i < main_mem_base + main_mem_size * 4;
6508 i += main_mem_width) {
6509 bnx2x_read_dmae(bp, i, main_mem_width / 4);
6510 bnx2x_write_dmae(bp, bnx2x_sp_mapping(bp, wb_data),
6511 i, main_mem_width / 4);
6513 /* Clear HC parity attention */
6514 REG_RD(bp, main_mem_prty_clr);
6517 #ifdef BNX2X_STOP_ON_ERROR
6518 /* Enable STORMs SP logging */
6519 REG_WR8(bp, BAR_USTRORM_INTMEM +
6520 USTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
6521 REG_WR8(bp, BAR_TSTRORM_INTMEM +
6522 TSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
6523 REG_WR8(bp, BAR_CSTRORM_INTMEM +
6524 CSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
6525 REG_WR8(bp, BAR_XSTRORM_INTMEM +
6526 XSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
6529 bnx2x_phy_probe(&bp->link_params);
6535 void bnx2x_free_mem(struct bnx2x *bp)
6538 bnx2x_free_fp_mem(bp);
6539 /* end of fastpath */
6541 BNX2X_PCI_FREE(bp->def_status_blk, bp->def_status_blk_mapping,
6542 sizeof(struct host_sp_status_block));
6544 BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
6545 bp->fw_stats_data_sz + bp->fw_stats_req_sz);
6547 BNX2X_PCI_FREE(bp->slowpath, bp->slowpath_mapping,
6548 sizeof(struct bnx2x_slowpath));
6550 BNX2X_PCI_FREE(bp->context.vcxt, bp->context.cxt_mapping,
6553 bnx2x_ilt_mem_op(bp, ILT_MEMOP_FREE);
6555 BNX2X_FREE(bp->ilt->lines);
6558 if (!CHIP_IS_E1x(bp))
6559 BNX2X_PCI_FREE(bp->cnic_sb.e2_sb, bp->cnic_sb_mapping,
6560 sizeof(struct host_hc_status_block_e2));
6562 BNX2X_PCI_FREE(bp->cnic_sb.e1x_sb, bp->cnic_sb_mapping,
6563 sizeof(struct host_hc_status_block_e1x));
6565 BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
6568 BNX2X_PCI_FREE(bp->spq, bp->spq_mapping, BCM_PAGE_SIZE);
6570 BNX2X_PCI_FREE(bp->eq_ring, bp->eq_mapping,
6571 BCM_PAGE_SIZE * NUM_EQ_PAGES);
6574 static inline int bnx2x_alloc_fw_stats_mem(struct bnx2x *bp)
6578 /* number of eth_queues */
6579 u8 num_queue_stats = BNX2X_NUM_ETH_QUEUES(bp);
6581 /* Total number of FW statistics requests =
6582 * 1 for port stats + 1 for PF stats + num_eth_queues */
6583 bp->fw_stats_num = 2 + num_queue_stats;
6586 /* Request is built from stats_query_header and an array of
6587 * stats_query_cmd_group each of which contains
6588 * STATS_QUERY_CMD_COUNT rules. The real number or requests is
6589 * configured in the stats_query_header.
6591 num_groups = (2 + num_queue_stats) / STATS_QUERY_CMD_COUNT +
6592 (((2 + num_queue_stats) % STATS_QUERY_CMD_COUNT) ? 1 : 0);
6594 bp->fw_stats_req_sz = sizeof(struct stats_query_header) +
6595 num_groups * sizeof(struct stats_query_cmd_group);
6597 /* Data for statistics requests + stats_conter
6599 * stats_counter holds per-STORM counters that are incremented
6600 * when STORM has finished with the current request.
6602 bp->fw_stats_data_sz = sizeof(struct per_port_stats) +
6603 sizeof(struct per_pf_stats) +
6604 sizeof(struct per_queue_stats) * num_queue_stats +
6605 sizeof(struct stats_counter);
6607 BNX2X_PCI_ALLOC(bp->fw_stats, &bp->fw_stats_mapping,
6608 bp->fw_stats_data_sz + bp->fw_stats_req_sz);
6611 bp->fw_stats_req = (struct bnx2x_fw_stats_req *)bp->fw_stats;
6612 bp->fw_stats_req_mapping = bp->fw_stats_mapping;
6614 bp->fw_stats_data = (struct bnx2x_fw_stats_data *)
6615 ((u8 *)bp->fw_stats + bp->fw_stats_req_sz);
6617 bp->fw_stats_data_mapping = bp->fw_stats_mapping +
6618 bp->fw_stats_req_sz;
6622 BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
6623 bp->fw_stats_data_sz + bp->fw_stats_req_sz);
6628 int bnx2x_alloc_mem(struct bnx2x *bp)
6631 if (!CHIP_IS_E1x(bp))
6632 /* size = the status block + ramrod buffers */
6633 BNX2X_PCI_ALLOC(bp->cnic_sb.e2_sb, &bp->cnic_sb_mapping,
6634 sizeof(struct host_hc_status_block_e2));
6636 BNX2X_PCI_ALLOC(bp->cnic_sb.e1x_sb, &bp->cnic_sb_mapping,
6637 sizeof(struct host_hc_status_block_e1x));
6639 /* allocate searcher T2 table */
6640 BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ);
6644 BNX2X_PCI_ALLOC(bp->def_status_blk, &bp->def_status_blk_mapping,
6645 sizeof(struct host_sp_status_block));
6647 BNX2X_PCI_ALLOC(bp->slowpath, &bp->slowpath_mapping,
6648 sizeof(struct bnx2x_slowpath));
6650 /* Allocated memory for FW statistics */
6651 if (bnx2x_alloc_fw_stats_mem(bp))
6654 bp->context.size = sizeof(union cdu_context) * bp->l2_cid_count;
6656 BNX2X_PCI_ALLOC(bp->context.vcxt, &bp->context.cxt_mapping,
6659 BNX2X_ALLOC(bp->ilt->lines, sizeof(struct ilt_line) * ILT_MAX_LINES);
6661 if (bnx2x_ilt_mem_op(bp, ILT_MEMOP_ALLOC))
6664 /* Slow path ring */
6665 BNX2X_PCI_ALLOC(bp->spq, &bp->spq_mapping, BCM_PAGE_SIZE);
6668 BNX2X_PCI_ALLOC(bp->eq_ring, &bp->eq_mapping,
6669 BCM_PAGE_SIZE * NUM_EQ_PAGES);
6673 /* need to be done at the end, since it's self adjusting to amount
6674 * of memory available for RSS queues
6676 if (bnx2x_alloc_fp_mem(bp))
6686 * Init service functions
6689 int bnx2x_set_mac_one(struct bnx2x *bp, u8 *mac,
6690 struct bnx2x_vlan_mac_obj *obj, bool set,
6691 int mac_type, unsigned long *ramrod_flags)
6694 struct bnx2x_vlan_mac_ramrod_params ramrod_param;
6696 memset(&ramrod_param, 0, sizeof(ramrod_param));
6698 /* Fill general parameters */
6699 ramrod_param.vlan_mac_obj = obj;
6700 ramrod_param.ramrod_flags = *ramrod_flags;
6702 /* Fill a user request section if needed */
6703 if (!test_bit(RAMROD_CONT, ramrod_flags)) {
6704 memcpy(ramrod_param.user_req.u.mac.mac, mac, ETH_ALEN);
6706 __set_bit(mac_type, &ramrod_param.user_req.vlan_mac_flags);
6708 /* Set the command: ADD or DEL */
6710 ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_ADD;
6712 ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_DEL;
6715 rc = bnx2x_config_vlan_mac(bp, &ramrod_param);
6717 BNX2X_ERR("%s MAC failed\n", (set ? "Set" : "Del"));
6721 int bnx2x_del_all_macs(struct bnx2x *bp,
6722 struct bnx2x_vlan_mac_obj *mac_obj,
6723 int mac_type, bool wait_for_comp)
6726 unsigned long ramrod_flags = 0, vlan_mac_flags = 0;
6728 /* Wait for completion of requested */
6730 __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
6732 /* Set the mac type of addresses we want to clear */
6733 __set_bit(mac_type, &vlan_mac_flags);
6735 rc = mac_obj->delete_all(bp, mac_obj, &vlan_mac_flags, &ramrod_flags);
6737 BNX2X_ERR("Failed to delete MACs: %d\n", rc);
6742 int bnx2x_set_eth_mac(struct bnx2x *bp, bool set)
6744 unsigned long ramrod_flags = 0;
6746 DP(NETIF_MSG_IFUP, "Adding Eth MAC\n");
6748 __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
6749 /* Eth MAC is set on RSS leading client (fp[0]) */
6750 return bnx2x_set_mac_one(bp, bp->dev->dev_addr, &bp->fp->mac_obj, set,
6751 BNX2X_ETH_MAC, &ramrod_flags);
6754 int bnx2x_setup_leading(struct bnx2x *bp)
6756 return bnx2x_setup_queue(bp, &bp->fp[0], 1);
6760 * bnx2x_set_int_mode - configure interrupt mode
6762 * @bp: driver handle
6764 * In case of MSI-X it will also try to enable MSI-X.
6766 static void __devinit bnx2x_set_int_mode(struct bnx2x *bp)
6770 bnx2x_enable_msi(bp);
6771 /* falling through... */
6773 bp->num_queues = 1 + NONE_ETH_CONTEXT_USE;
6774 DP(NETIF_MSG_IFUP, "set number of queues to 1\n");
6777 /* Set number of queues according to bp->multi_mode value */
6778 bnx2x_set_num_queues(bp);
6780 DP(NETIF_MSG_IFUP, "set number of queues to %d\n",
6783 /* if we can't use MSI-X we only need one fp,
6784 * so try to enable MSI-X with the requested number of fp's
6785 * and fallback to MSI or legacy INTx with one fp
6787 if (bnx2x_enable_msix(bp)) {
6788 /* failed to enable MSI-X */
6791 "Multi requested but failed to "
6792 "enable MSI-X (%d), "
6793 "set number of queues to %d\n",
6795 1 + NONE_ETH_CONTEXT_USE);
6796 bp->num_queues = 1 + NONE_ETH_CONTEXT_USE;
6798 /* Try to enable MSI */
6799 if (!(bp->flags & DISABLE_MSI_FLAG))
6800 bnx2x_enable_msi(bp);
6806 /* must be called prioir to any HW initializations */
6807 static inline u16 bnx2x_cid_ilt_lines(struct bnx2x *bp)
6809 return L2_ILT_LINES(bp);
6812 void bnx2x_ilt_set_info(struct bnx2x *bp)
6814 struct ilt_client_info *ilt_client;
6815 struct bnx2x_ilt *ilt = BP_ILT(bp);
6818 ilt->start_line = FUNC_ILT_BASE(BP_FUNC(bp));
6819 DP(BNX2X_MSG_SP, "ilt starts at line %d\n", ilt->start_line);
6822 ilt_client = &ilt->clients[ILT_CLIENT_CDU];
6823 ilt_client->client_num = ILT_CLIENT_CDU;
6824 ilt_client->page_size = CDU_ILT_PAGE_SZ;
6825 ilt_client->flags = ILT_CLIENT_SKIP_MEM;
6826 ilt_client->start = line;
6827 line += bnx2x_cid_ilt_lines(bp);
6829 line += CNIC_ILT_LINES;
6831 ilt_client->end = line - 1;
6833 DP(BNX2X_MSG_SP, "ilt client[CDU]: start %d, end %d, psz 0x%x, "
6834 "flags 0x%x, hw psz %d\n",
6837 ilt_client->page_size,
6839 ilog2(ilt_client->page_size >> 12));
6842 if (QM_INIT(bp->qm_cid_count)) {
6843 ilt_client = &ilt->clients[ILT_CLIENT_QM];
6844 ilt_client->client_num = ILT_CLIENT_QM;
6845 ilt_client->page_size = QM_ILT_PAGE_SZ;
6846 ilt_client->flags = 0;
6847 ilt_client->start = line;
6849 /* 4 bytes for each cid */
6850 line += DIV_ROUND_UP(bp->qm_cid_count * QM_QUEUES_PER_FUNC * 4,
6853 ilt_client->end = line - 1;
6855 DP(BNX2X_MSG_SP, "ilt client[QM]: start %d, end %d, psz 0x%x, "
6856 "flags 0x%x, hw psz %d\n",
6859 ilt_client->page_size,
6861 ilog2(ilt_client->page_size >> 12));
6865 ilt_client = &ilt->clients[ILT_CLIENT_SRC];
6867 ilt_client->client_num = ILT_CLIENT_SRC;
6868 ilt_client->page_size = SRC_ILT_PAGE_SZ;
6869 ilt_client->flags = 0;
6870 ilt_client->start = line;
6871 line += SRC_ILT_LINES;
6872 ilt_client->end = line - 1;
6874 DP(BNX2X_MSG_SP, "ilt client[SRC]: start %d, end %d, psz 0x%x, "
6875 "flags 0x%x, hw psz %d\n",
6878 ilt_client->page_size,
6880 ilog2(ilt_client->page_size >> 12));
6883 ilt_client->flags = (ILT_CLIENT_SKIP_INIT | ILT_CLIENT_SKIP_MEM);
6887 ilt_client = &ilt->clients[ILT_CLIENT_TM];
6889 ilt_client->client_num = ILT_CLIENT_TM;
6890 ilt_client->page_size = TM_ILT_PAGE_SZ;
6891 ilt_client->flags = 0;
6892 ilt_client->start = line;
6893 line += TM_ILT_LINES;
6894 ilt_client->end = line - 1;
6896 DP(BNX2X_MSG_SP, "ilt client[TM]: start %d, end %d, psz 0x%x, "
6897 "flags 0x%x, hw psz %d\n",
6900 ilt_client->page_size,
6902 ilog2(ilt_client->page_size >> 12));
6905 ilt_client->flags = (ILT_CLIENT_SKIP_INIT | ILT_CLIENT_SKIP_MEM);
6907 BUG_ON(line > ILT_MAX_LINES);
6911 * bnx2x_pf_q_prep_init - prepare INIT transition parameters
6913 * @bp: driver handle
6914 * @fp: pointer to fastpath
6915 * @init_params: pointer to parameters structure
6917 * parameters configured:
6918 * - HC configuration
6919 * - Queue's CDU context
6921 static inline void bnx2x_pf_q_prep_init(struct bnx2x *bp,
6922 struct bnx2x_fastpath *fp, struct bnx2x_queue_init_params *init_params)
6924 /* FCoE Queue uses Default SB, thus has no HC capabilities */
6925 if (!IS_FCOE_FP(fp)) {
6926 __set_bit(BNX2X_Q_FLG_HC, &init_params->rx.flags);
6927 __set_bit(BNX2X_Q_FLG_HC, &init_params->tx.flags);
6929 /* If HC is supporterd, enable host coalescing in the transition
6932 __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->rx.flags);
6933 __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->tx.flags);
6936 init_params->rx.hc_rate = bp->rx_ticks ?
6937 (1000000 / bp->rx_ticks) : 0;
6938 init_params->tx.hc_rate = bp->tx_ticks ?
6939 (1000000 / bp->tx_ticks) : 0;
6942 init_params->rx.fw_sb_id = init_params->tx.fw_sb_id =
6946 * CQ index among the SB indices: FCoE clients uses the default
6947 * SB, therefore it's different.
6949 init_params->rx.sb_cq_index = U_SB_ETH_RX_CQ_INDEX;
6950 init_params->tx.sb_cq_index = C_SB_ETH_TX_CQ_INDEX;
6953 init_params->cxt = &bp->context.vcxt[fp->cid].eth;
6957 * bnx2x_setup_queue - setup queue
6959 * @bp: driver handle
6960 * @fp: pointer to fastpath
6961 * @leading: is leading
6963 * This function performs 2 steps in a Queue state machine
6964 * actually: 1) RESET->INIT 2) INIT->SETUP
6967 int bnx2x_setup_queue(struct bnx2x *bp, struct bnx2x_fastpath *fp,
6970 struct bnx2x_queue_state_params q_params = {0};
6971 struct bnx2x_queue_setup_params *setup_params =
6972 &q_params.params.setup;
6975 /* reset IGU state skip FCoE L2 queue */
6976 if (!IS_FCOE_FP(fp))
6977 bnx2x_ack_sb(bp, fp->igu_sb_id, USTORM_ID, 0,
6980 q_params.q_obj = &fp->q_obj;
6981 /* We want to wait for completion in this context */
6982 __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
6984 /* Prepare the INIT parameters */
6985 bnx2x_pf_q_prep_init(bp, fp, &q_params.params.init);
6987 /* Set the command */
6988 q_params.cmd = BNX2X_Q_CMD_INIT;
6990 /* Change the state to INIT */
6991 rc = bnx2x_queue_state_change(bp, &q_params);
6993 BNX2X_ERR("Queue INIT failed\n");
6997 /* Now move the Queue to the SETUP state... */
6998 memset(setup_params, 0, sizeof(*setup_params));
7000 /* Set QUEUE flags */
7001 setup_params->flags = bnx2x_get_q_flags(bp, fp, leading);
7003 /* Set general SETUP parameters */
7004 bnx2x_pf_q_prep_general(bp, fp, &setup_params->gen_params);
7006 bnx2x_pf_rx_q_prep(bp, fp, &setup_params->pause,
7007 &setup_params->rxq_params);
7009 bnx2x_pf_tx_q_prep(bp, fp, &setup_params->txq_params);
7011 /* Set the command */
7012 q_params.cmd = BNX2X_Q_CMD_SETUP;
7014 /* Change the state to SETUP */
7015 rc = bnx2x_queue_state_change(bp, &q_params);
7017 BNX2X_ERR("Queue SETUP failed\n");
7022 static int bnx2x_stop_queue(struct bnx2x *bp, int index)
7024 struct bnx2x_fastpath *fp = &bp->fp[index];
7025 struct bnx2x_queue_state_params q_params = {0};
7028 q_params.q_obj = &fp->q_obj;
7029 /* We want to wait for completion in this context */
7030 __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
7032 /* halt the connection */
7033 q_params.cmd = BNX2X_Q_CMD_HALT;
7034 rc = bnx2x_queue_state_change(bp, &q_params);
7038 /* terminate the connection */
7039 q_params.cmd = BNX2X_Q_CMD_TERMINATE;
7040 rc = bnx2x_queue_state_change(bp, &q_params);
7044 /* delete cfc entry */
7045 q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
7046 return bnx2x_queue_state_change(bp, &q_params);
7050 static void bnx2x_reset_func(struct bnx2x *bp)
7052 int port = BP_PORT(bp);
7053 int func = BP_FUNC(bp);
7056 /* Disable the function in the FW */
7057 REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(func), 0);
7058 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(func), 0);
7059 REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(func), 0);
7060 REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(func), 0);
7063 for_each_eth_queue(bp, i) {
7064 struct bnx2x_fastpath *fp = &bp->fp[i];
7065 REG_WR8(bp, BAR_CSTRORM_INTMEM +
7066 CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(fp->fw_sb_id),
7072 REG_WR8(bp, BAR_CSTRORM_INTMEM +
7073 CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(bnx2x_cnic_fw_sb_id(bp)),
7077 REG_WR8(bp, BAR_CSTRORM_INTMEM +
7078 CSTORM_SP_STATUS_BLOCK_DATA_STATE_OFFSET(func),
7081 for (i = 0; i < XSTORM_SPQ_DATA_SIZE / 4; i++)
7082 REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_DATA_OFFSET(func),
7086 if (bp->common.int_block == INT_BLOCK_HC) {
7087 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
7088 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
7090 REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
7091 REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
7095 /* Disable Timer scan */
7096 REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + port*4, 0);
7098 * Wait for at least 10ms and up to 2 second for the timers scan to
7101 for (i = 0; i < 200; i++) {
7103 if (!REG_RD(bp, TM_REG_LIN0_SCAN_ON + port*4))
7108 bnx2x_clear_func_ilt(bp, func);
7110 /* Timers workaround bug for E2: if this is vnic-3,
7111 * we need to set the entire ilt range for this timers.
7113 if (!CHIP_IS_E1x(bp) && BP_VN(bp) == 3) {
7114 struct ilt_client_info ilt_cli;
7115 /* use dummy TM client */
7116 memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
7118 ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
7119 ilt_cli.client_num = ILT_CLIENT_TM;
7121 bnx2x_ilt_boundry_init_op(bp, &ilt_cli, 0, INITOP_CLEAR);
7124 /* this assumes that reset_port() called before reset_func()*/
7125 if (!CHIP_IS_E1x(bp))
7126 bnx2x_pf_disable(bp);
7131 static void bnx2x_reset_port(struct bnx2x *bp)
7133 int port = BP_PORT(bp);
7136 /* Reset physical Link */
7137 bnx2x__link_reset(bp);
7139 REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
7141 /* Do not rcv packets to BRB */
7142 REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0);
7143 /* Do not direct rcv packets that are not for MCP to the BRB */
7144 REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
7145 NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
7148 REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0);
7151 /* Check for BRB port occupancy */
7152 val = REG_RD(bp, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4);
7154 DP(NETIF_MSG_IFDOWN,
7155 "BRB1 is not empty %d blocks are occupied\n", val);
7157 /* TODO: Close Doorbell port? */
7160 static inline int bnx2x_reset_hw(struct bnx2x *bp, u32 load_code)
7162 struct bnx2x_func_state_params func_params = {0};
7164 /* Prepare parameters for function state transitions */
7165 __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
7167 func_params.f_obj = &bp->func_obj;
7168 func_params.cmd = BNX2X_F_CMD_HW_RESET;
7170 func_params.params.hw_init.load_phase = load_code;
7172 return bnx2x_func_state_change(bp, &func_params);
7175 static inline int bnx2x_func_stop(struct bnx2x *bp)
7177 struct bnx2x_func_state_params func_params = {0};
7180 /* Prepare parameters for function state transitions */
7181 __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
7182 func_params.f_obj = &bp->func_obj;
7183 func_params.cmd = BNX2X_F_CMD_STOP;
7186 * Try to stop the function the 'good way'. If fails (in case
7187 * of a parity error during bnx2x_chip_cleanup()) and we are
7188 * not in a debug mode, perform a state transaction in order to
7189 * enable further HW_RESET transaction.
7191 rc = bnx2x_func_state_change(bp, &func_params);
7193 #ifdef BNX2X_STOP_ON_ERROR
7196 BNX2X_ERR("FUNC_STOP ramrod failed. Running a dry "
7198 __set_bit(RAMROD_DRV_CLR_ONLY, &func_params.ramrod_flags);
7199 return bnx2x_func_state_change(bp, &func_params);
7207 * bnx2x_send_unload_req - request unload mode from the MCP.
7209 * @bp: driver handle
7210 * @unload_mode: requested function's unload mode
7212 * Return unload mode returned by the MCP: COMMON, PORT or FUNC.
7214 u32 bnx2x_send_unload_req(struct bnx2x *bp, int unload_mode)
7217 int port = BP_PORT(bp);
7219 /* Select the UNLOAD request mode */
7220 if (unload_mode == UNLOAD_NORMAL)
7221 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
7223 else if (bp->flags & NO_WOL_FLAG)
7224 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP;
7227 u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
7228 u8 *mac_addr = bp->dev->dev_addr;
7230 /* The mac address is written to entries 1-4 to
7231 preserve entry 0 which is used by the PMF */
7232 u8 entry = (BP_E1HVN(bp) + 1)*8;
7234 val = (mac_addr[0] << 8) | mac_addr[1];
7235 EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry, val);
7237 val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
7238 (mac_addr[4] << 8) | mac_addr[5];
7239 EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry + 4, val);
7241 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_EN;
7244 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
7246 /* Send the request to the MCP */
7248 reset_code = bnx2x_fw_command(bp, reset_code, 0);
7250 int path = BP_PATH(bp);
7252 DP(NETIF_MSG_IFDOWN, "NO MCP - load counts[%d] "
7254 path, load_count[path][0], load_count[path][1],
7255 load_count[path][2]);
7256 load_count[path][0]--;
7257 load_count[path][1 + port]--;
7258 DP(NETIF_MSG_IFDOWN, "NO MCP - new load counts[%d] "
7260 path, load_count[path][0], load_count[path][1],
7261 load_count[path][2]);
7262 if (load_count[path][0] == 0)
7263 reset_code = FW_MSG_CODE_DRV_UNLOAD_COMMON;
7264 else if (load_count[path][1 + port] == 0)
7265 reset_code = FW_MSG_CODE_DRV_UNLOAD_PORT;
7267 reset_code = FW_MSG_CODE_DRV_UNLOAD_FUNCTION;
7274 * bnx2x_send_unload_done - send UNLOAD_DONE command to the MCP.
7276 * @bp: driver handle
7278 void bnx2x_send_unload_done(struct bnx2x *bp)
7280 /* Report UNLOAD_DONE to MCP */
7282 bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
7285 void bnx2x_chip_cleanup(struct bnx2x *bp, int unload_mode)
7287 int port = BP_PORT(bp);
7289 struct bnx2x_mcast_ramrod_params rparam = {0};
7292 /* Wait until tx fastpath tasks complete */
7293 for_each_tx_queue(bp, i) {
7294 struct bnx2x_fastpath *fp = &bp->fp[i];
7296 rc = bnx2x_clean_tx_queue(bp, fp);
7297 #ifdef BNX2X_STOP_ON_ERROR
7303 /* Give HW time to discard old tx messages */
7304 usleep_range(1000, 1000);
7306 /* Clean all ETH MACs */
7307 rc = bnx2x_del_all_macs(bp, &bp->fp[0].mac_obj, BNX2X_ETH_MAC, false);
7309 BNX2X_ERR("Failed to delete all ETH macs: %d\n", rc);
7311 /* Clean up UC list */
7312 rc = bnx2x_del_all_macs(bp, &bp->fp[0].mac_obj, BNX2X_UC_LIST_MAC,
7315 BNX2X_ERR("Failed to schedule DEL commands for UC MACs list: "
7319 if (!CHIP_IS_E1(bp))
7320 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
7322 /* Set "drop all" (stop Rx).
7323 * We need to take a netif_addr_lock() here in order to prevent
7324 * a race between the completion code and this code.
7326 netif_addr_lock_bh(bp->dev);
7327 /* Schedule the rx_mode command */
7328 if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
7329 set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
7331 bnx2x_set_storm_rx_mode(bp);
7333 /* Cleanup multicast configuration */
7334 rparam.mcast_obj = &bp->mcast_obj;
7335 rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
7337 BNX2X_ERR("Failed to send DEL multicast command: %d\n", rc);
7339 netif_addr_unlock_bh(bp->dev);
7342 /* Close multi and leading connections
7343 * Completions for ramrods are collected in a synchronous way
7345 for_each_queue(bp, i)
7346 if (bnx2x_stop_queue(bp, i))
7347 #ifdef BNX2X_STOP_ON_ERROR
7352 /* If SP settings didn't get completed so far - something
7353 * very wrong has happen.
7355 if (!bnx2x_wait_sp_comp(bp, ~0x0UL))
7356 BNX2X_ERR("Hmmm... Common slow path ramrods got stuck!\n");
7358 #ifndef BNX2X_STOP_ON_ERROR
7361 rc = bnx2x_func_stop(bp);
7363 BNX2X_ERR("Function stop failed!\n");
7364 #ifdef BNX2X_STOP_ON_ERROR
7370 * Send the UNLOAD_REQUEST to the MCP. This will return if
7371 * this function should perform FUNC, PORT or COMMON HW
7374 reset_code = bnx2x_send_unload_req(bp, unload_mode);
7376 /* Disable HW interrupts, NAPI */
7377 bnx2x_netif_stop(bp, 1);
7382 /* Reset the chip */
7383 rc = bnx2x_reset_hw(bp, reset_code);
7385 BNX2X_ERR("HW_RESET failed\n");
7388 /* Report UNLOAD_DONE to MCP */
7389 bnx2x_send_unload_done(bp);
7392 void bnx2x_disable_close_the_gate(struct bnx2x *bp)
7396 DP(NETIF_MSG_HW, "Disabling \"close the gates\"\n");
7398 if (CHIP_IS_E1(bp)) {
7399 int port = BP_PORT(bp);
7400 u32 addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
7401 MISC_REG_AEU_MASK_ATTN_FUNC_0;
7403 val = REG_RD(bp, addr);
7405 REG_WR(bp, addr, val);
7407 val = REG_RD(bp, MISC_REG_AEU_GENERAL_MASK);
7408 val &= ~(MISC_AEU_GENERAL_MASK_REG_AEU_PXP_CLOSE_MASK |
7409 MISC_AEU_GENERAL_MASK_REG_AEU_NIG_CLOSE_MASK);
7410 REG_WR(bp, MISC_REG_AEU_GENERAL_MASK, val);
7414 /* Close gates #2, #3 and #4: */
7415 static void bnx2x_set_234_gates(struct bnx2x *bp, bool close)
7419 /* Gates #2 and #4a are closed/opened for "not E1" only */
7420 if (!CHIP_IS_E1(bp)) {
7422 REG_WR(bp, PXP_REG_HST_DISCARD_DOORBELLS, !!close);
7424 REG_WR(bp, PXP_REG_HST_DISCARD_INTERNAL_WRITES, !!close);
7428 if (CHIP_IS_E1x(bp)) {
7429 /* Prevent interrupts from HC on both ports */
7430 val = REG_RD(bp, HC_REG_CONFIG_1);
7431 REG_WR(bp, HC_REG_CONFIG_1,
7432 (!close) ? (val | HC_CONFIG_1_REG_BLOCK_DISABLE_1) :
7433 (val & ~(u32)HC_CONFIG_1_REG_BLOCK_DISABLE_1));
7435 val = REG_RD(bp, HC_REG_CONFIG_0);
7436 REG_WR(bp, HC_REG_CONFIG_0,
7437 (!close) ? (val | HC_CONFIG_0_REG_BLOCK_DISABLE_0) :
7438 (val & ~(u32)HC_CONFIG_0_REG_BLOCK_DISABLE_0));
7440 /* Prevent incomming interrupts in IGU */
7441 val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
7443 REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION,
7445 (val | IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE) :
7446 (val & ~(u32)IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE));
7449 DP(NETIF_MSG_HW, "%s gates #2, #3 and #4\n",
7450 close ? "closing" : "opening");
7454 #define SHARED_MF_CLP_MAGIC 0x80000000 /* `magic' bit */
7456 static void bnx2x_clp_reset_prep(struct bnx2x *bp, u32 *magic_val)
7458 /* Do some magic... */
7459 u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
7460 *magic_val = val & SHARED_MF_CLP_MAGIC;
7461 MF_CFG_WR(bp, shared_mf_config.clp_mb, val | SHARED_MF_CLP_MAGIC);
7465 * bnx2x_clp_reset_done - restore the value of the `magic' bit.
7467 * @bp: driver handle
7468 * @magic_val: old value of the `magic' bit.
7470 static void bnx2x_clp_reset_done(struct bnx2x *bp, u32 magic_val)
7472 /* Restore the `magic' bit value... */
7473 u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
7474 MF_CFG_WR(bp, shared_mf_config.clp_mb,
7475 (val & (~SHARED_MF_CLP_MAGIC)) | magic_val);
7479 * bnx2x_reset_mcp_prep - prepare for MCP reset.
7481 * @bp: driver handle
7482 * @magic_val: old value of 'magic' bit.
7484 * Takes care of CLP configurations.
7486 static void bnx2x_reset_mcp_prep(struct bnx2x *bp, u32 *magic_val)
7489 u32 validity_offset;
7491 DP(NETIF_MSG_HW, "Starting\n");
7493 /* Set `magic' bit in order to save MF config */
7494 if (!CHIP_IS_E1(bp))
7495 bnx2x_clp_reset_prep(bp, magic_val);
7497 /* Get shmem offset */
7498 shmem = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
7499 validity_offset = offsetof(struct shmem_region, validity_map[0]);
7501 /* Clear validity map flags */
7503 REG_WR(bp, shmem + validity_offset, 0);
7506 #define MCP_TIMEOUT 5000 /* 5 seconds (in ms) */
7507 #define MCP_ONE_TIMEOUT 100 /* 100 ms */
7510 * bnx2x_mcp_wait_one - wait for MCP_ONE_TIMEOUT
7512 * @bp: driver handle
7514 static inline void bnx2x_mcp_wait_one(struct bnx2x *bp)
7516 /* special handling for emulation and FPGA,
7517 wait 10 times longer */
7518 if (CHIP_REV_IS_SLOW(bp))
7519 msleep(MCP_ONE_TIMEOUT*10);
7521 msleep(MCP_ONE_TIMEOUT);
7525 * initializes bp->common.shmem_base and waits for validity signature to appear
7527 static int bnx2x_init_shmem(struct bnx2x *bp)
7533 bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
7534 if (bp->common.shmem_base) {
7535 val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
7536 if (val & SHR_MEM_VALIDITY_MB)
7540 bnx2x_mcp_wait_one(bp);
7542 } while (cnt++ < (MCP_TIMEOUT / MCP_ONE_TIMEOUT));
7544 BNX2X_ERR("BAD MCP validity signature\n");
7549 static int bnx2x_reset_mcp_comp(struct bnx2x *bp, u32 magic_val)
7551 int rc = bnx2x_init_shmem(bp);
7553 /* Restore the `magic' bit value */
7554 if (!CHIP_IS_E1(bp))
7555 bnx2x_clp_reset_done(bp, magic_val);
7560 static void bnx2x_pxp_prep(struct bnx2x *bp)
7562 if (!CHIP_IS_E1(bp)) {
7563 REG_WR(bp, PXP2_REG_RD_START_INIT, 0);
7564 REG_WR(bp, PXP2_REG_RQ_RBC_DONE, 0);
7570 * Reset the whole chip except for:
7572 * - PCI Glue, PSWHST, PXP/PXP2 RF (all controlled by
7575 * - MISC (including AEU)
7579 static void bnx2x_process_kill_chip_reset(struct bnx2x *bp, bool global)
7581 u32 not_reset_mask1, reset_mask1, not_reset_mask2, reset_mask2;
7585 * Bits that have to be set in reset_mask2 if we want to reset 'global'
7586 * (per chip) blocks.
7589 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CPU |
7590 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CORE;
7593 MISC_REGISTERS_RESET_REG_1_RST_HC |
7594 MISC_REGISTERS_RESET_REG_1_RST_PXPV |
7595 MISC_REGISTERS_RESET_REG_1_RST_PXP;
7598 MISC_REGISTERS_RESET_REG_2_RST_PCI_MDIO |
7599 MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE |
7600 MISC_REGISTERS_RESET_REG_2_RST_EMAC1_HARD_CORE |
7601 MISC_REGISTERS_RESET_REG_2_RST_MISC_CORE |
7602 MISC_REGISTERS_RESET_REG_2_RST_RBCN |
7603 MISC_REGISTERS_RESET_REG_2_RST_GRC |
7604 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_REG_HARD_CORE |
7605 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_HARD_CORE_RST_B;
7607 reset_mask1 = 0xffffffff;
7610 reset_mask2 = 0xffff;
7612 reset_mask2 = 0x1ffff;
7614 if (CHIP_IS_E3(bp)) {
7615 reset_mask2 |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
7616 reset_mask2 |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
7619 /* Don't reset global blocks unless we need to */
7621 reset_mask2 &= ~global_bits2;
7624 * In case of attention in the QM, we need to reset PXP
7625 * (MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR) before QM
7626 * because otherwise QM reset would release 'close the gates' shortly
7627 * before resetting the PXP, then the PSWRQ would send a write
7628 * request to PGLUE. Then when PXP is reset, PGLUE would try to
7629 * read the payload data from PSWWR, but PSWWR would not
7630 * respond. The write queue in PGLUE would stuck, dmae commands
7631 * would not return. Therefore it's important to reset the second
7632 * reset register (containing the
7633 * MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR bit) before the
7634 * first one (containing the MISC_REGISTERS_RESET_REG_1_RST_QM
7637 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
7638 reset_mask2 & (~not_reset_mask2));
7640 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
7641 reset_mask1 & (~not_reset_mask1));
7646 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, reset_mask2);
7647 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, reset_mask1);
7652 * bnx2x_er_poll_igu_vq - poll for pending writes bit.
7653 * It should get cleared in no more than 1s.
7655 * @bp: driver handle
7657 * It should get cleared in no more than 1s. Returns 0 if
7658 * pending writes bit gets cleared.
7660 static int bnx2x_er_poll_igu_vq(struct bnx2x *bp)
7666 pend_bits = REG_RD(bp, IGU_REG_PENDING_BITS_STATUS);
7671 usleep_range(1000, 1000);
7672 } while (cnt-- > 0);
7675 BNX2X_ERR("Still pending IGU requests pend_bits=%x!\n",
7683 static int bnx2x_process_kill(struct bnx2x *bp, bool global)
7687 u32 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, pgl_exp_rom2;
7690 /* Empty the Tetris buffer, wait for 1s */
7692 sr_cnt = REG_RD(bp, PXP2_REG_RD_SR_CNT);
7693 blk_cnt = REG_RD(bp, PXP2_REG_RD_BLK_CNT);
7694 port_is_idle_0 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_0);
7695 port_is_idle_1 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_1);
7696 pgl_exp_rom2 = REG_RD(bp, PXP2_REG_PGL_EXP_ROM2);
7697 if ((sr_cnt == 0x7e) && (blk_cnt == 0xa0) &&
7698 ((port_is_idle_0 & 0x1) == 0x1) &&
7699 ((port_is_idle_1 & 0x1) == 0x1) &&
7700 (pgl_exp_rom2 == 0xffffffff))
7702 usleep_range(1000, 1000);
7703 } while (cnt-- > 0);
7706 DP(NETIF_MSG_HW, "Tetris buffer didn't get empty or there"
7708 " outstanding read requests after 1s!\n");
7709 DP(NETIF_MSG_HW, "sr_cnt=0x%08x, blk_cnt=0x%08x,"
7710 " port_is_idle_0=0x%08x,"
7711 " port_is_idle_1=0x%08x, pgl_exp_rom2=0x%08x\n",
7712 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1,
7719 /* Close gates #2, #3 and #4 */
7720 bnx2x_set_234_gates(bp, true);
7722 /* Poll for IGU VQs for 57712 and newer chips */
7723 if (!CHIP_IS_E1x(bp) && bnx2x_er_poll_igu_vq(bp))
7727 /* TBD: Indicate that "process kill" is in progress to MCP */
7729 /* Clear "unprepared" bit */
7730 REG_WR(bp, MISC_REG_UNPREPARED, 0);
7733 /* Make sure all is written to the chip before the reset */
7736 /* Wait for 1ms to empty GLUE and PCI-E core queues,
7737 * PSWHST, GRC and PSWRD Tetris buffer.
7739 usleep_range(1000, 1000);
7741 /* Prepare to chip reset: */
7744 bnx2x_reset_mcp_prep(bp, &val);
7750 /* reset the chip */
7751 bnx2x_process_kill_chip_reset(bp, global);
7754 /* Recover after reset: */
7756 if (global && bnx2x_reset_mcp_comp(bp, val))
7759 /* TBD: Add resetting the NO_MCP mode DB here */
7764 /* Open the gates #2, #3 and #4 */
7765 bnx2x_set_234_gates(bp, false);
7767 /* TBD: IGU/AEU preparation bring back the AEU/IGU to a
7768 * reset state, re-enable attentions. */
7773 int bnx2x_leader_reset(struct bnx2x *bp)
7776 bool global = bnx2x_reset_is_global(bp);
7778 /* Try to recover after the failure */
7779 if (bnx2x_process_kill(bp, global)) {
7780 netdev_err(bp->dev, "Something bad had happen on engine %d! "
7781 "Aii!\n", BP_PATH(bp));
7783 goto exit_leader_reset;
7787 * Clear RESET_IN_PROGRES and RESET_GLOBAL bits and update the driver
7790 bnx2x_set_reset_done(bp);
7792 bnx2x_clear_reset_global(bp);
7796 bnx2x_release_leader_lock(bp);
7801 static inline void bnx2x_recovery_failed(struct bnx2x *bp)
7803 netdev_err(bp->dev, "Recovery has failed. Power cycle is needed.\n");
7805 /* Disconnect this device */
7806 netif_device_detach(bp->dev);
7809 * Block ifup for all function on this engine until "process kill"
7812 bnx2x_set_reset_in_progress(bp);
7814 /* Shut down the power */
7815 bnx2x_set_power_state(bp, PCI_D3hot);
7817 bp->recovery_state = BNX2X_RECOVERY_FAILED;
7823 * Assumption: runs under rtnl lock. This together with the fact
7824 * that it's called only from bnx2x_reset_task() ensure that it
7825 * will never be called when netif_running(bp->dev) is false.
7827 static void bnx2x_parity_recover(struct bnx2x *bp)
7829 bool global = false;
7831 DP(NETIF_MSG_HW, "Handling parity\n");
7833 switch (bp->recovery_state) {
7834 case BNX2X_RECOVERY_INIT:
7835 DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_INIT\n");
7836 bnx2x_chk_parity_attn(bp, &global, false);
7838 /* Try to get a LEADER_LOCK HW lock */
7839 if (bnx2x_trylock_leader_lock(bp)) {
7840 bnx2x_set_reset_in_progress(bp);
7842 * Check if there is a global attention and if
7843 * there was a global attention, set the global
7848 bnx2x_set_reset_global(bp);
7853 /* Stop the driver */
7854 /* If interface has been removed - break */
7855 if (bnx2x_nic_unload(bp, UNLOAD_RECOVERY))
7858 bp->recovery_state = BNX2X_RECOVERY_WAIT;
7861 * Reset MCP command sequence number and MCP mail box
7862 * sequence as we are going to reset the MCP.
7866 bp->fw_drv_pulse_wr_seq = 0;
7869 /* Ensure "is_leader", MCP command sequence and
7870 * "recovery_state" update values are seen on other
7876 case BNX2X_RECOVERY_WAIT:
7877 DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_WAIT\n");
7878 if (bp->is_leader) {
7879 int other_engine = BP_PATH(bp) ? 0 : 1;
7880 u32 other_load_counter =
7881 bnx2x_get_load_cnt(bp, other_engine);
7883 bnx2x_get_load_cnt(bp, BP_PATH(bp));
7884 global = bnx2x_reset_is_global(bp);
7887 * In case of a parity in a global block, let
7888 * the first leader that performs a
7889 * leader_reset() reset the global blocks in
7890 * order to clear global attentions. Otherwise
7891 * the the gates will remain closed for that
7895 (global && other_load_counter)) {
7896 /* Wait until all other functions get
7899 schedule_delayed_work(&bp->reset_task,
7903 /* If all other functions got down -
7904 * try to bring the chip back to
7905 * normal. In any case it's an exit
7906 * point for a leader.
7908 if (bnx2x_leader_reset(bp)) {
7909 bnx2x_recovery_failed(bp);
7913 /* If we are here, means that the
7914 * leader has succeeded and doesn't
7915 * want to be a leader any more. Try
7916 * to continue as a none-leader.
7920 } else { /* non-leader */
7921 if (!bnx2x_reset_is_done(bp, BP_PATH(bp))) {
7922 /* Try to get a LEADER_LOCK HW lock as
7923 * long as a former leader may have
7924 * been unloaded by the user or
7925 * released a leadership by another
7928 if (bnx2x_trylock_leader_lock(bp)) {
7929 /* I'm a leader now! Restart a
7936 schedule_delayed_work(&bp->reset_task,
7942 * If there was a global attention, wait
7943 * for it to be cleared.
7945 if (bnx2x_reset_is_global(bp)) {
7946 schedule_delayed_work(
7947 &bp->reset_task, HZ/10);
7951 if (bnx2x_nic_load(bp, LOAD_NORMAL))
7952 bnx2x_recovery_failed(bp);
7954 bp->recovery_state =
7955 BNX2X_RECOVERY_DONE;
7968 /* bnx2x_nic_unload() flushes the bnx2x_wq, thus reset task is
7969 * scheduled on a general queue in order to prevent a dead lock.
7971 static void bnx2x_reset_task(struct work_struct *work)
7973 struct bnx2x *bp = container_of(work, struct bnx2x, reset_task.work);
7975 #ifdef BNX2X_STOP_ON_ERROR
7976 BNX2X_ERR("reset task called but STOP_ON_ERROR defined"
7977 " so reset not done to allow debug dump,\n"
7978 KERN_ERR " you will need to reboot when done\n");
7984 if (!netif_running(bp->dev))
7985 goto reset_task_exit;
7987 if (unlikely(bp->recovery_state != BNX2X_RECOVERY_DONE))
7988 bnx2x_parity_recover(bp);
7990 bnx2x_nic_unload(bp, UNLOAD_NORMAL);
7991 bnx2x_nic_load(bp, LOAD_NORMAL);
7998 /* end of nic load/unload */
8001 * Init service functions
8004 static u32 bnx2x_get_pretend_reg(struct bnx2x *bp)
8006 u32 base = PXP2_REG_PGL_PRETEND_FUNC_F0;
8007 u32 stride = PXP2_REG_PGL_PRETEND_FUNC_F1 - base;
8008 return base + (BP_ABS_FUNC(bp)) * stride;
8011 static void bnx2x_undi_int_disable_e1h(struct bnx2x *bp)
8013 u32 reg = bnx2x_get_pretend_reg(bp);
8015 /* Flush all outstanding writes */
8018 /* Pretend to be function 0 */
8020 REG_RD(bp, reg); /* Flush the GRC transaction (in the chip) */
8022 /* From now we are in the "like-E1" mode */
8023 bnx2x_int_disable(bp);
8025 /* Flush all outstanding writes */
8028 /* Restore the original function */
8029 REG_WR(bp, reg, BP_ABS_FUNC(bp));
8033 static inline void bnx2x_undi_int_disable(struct bnx2x *bp)
8036 bnx2x_int_disable(bp);
8038 bnx2x_undi_int_disable_e1h(bp);
8041 static void __devinit bnx2x_undi_unload(struct bnx2x *bp)
8045 /* Check if there is any driver already loaded */
8046 val = REG_RD(bp, MISC_REG_UNPREPARED);
8048 /* Check if it is the UNDI driver
8049 * UNDI driver initializes CID offset for normal bell to 0x7
8051 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_UNDI);
8052 val = REG_RD(bp, DORQ_REG_NORM_CID_OFST);
8054 u32 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
8055 /* save our pf_num */
8056 int orig_pf_num = bp->pf_num;
8058 u32 swap_en, swap_val, value;
8060 /* clear the UNDI indication */
8061 REG_WR(bp, DORQ_REG_NORM_CID_OFST, 0);
8063 BNX2X_DEV_INFO("UNDI is active! reset device\n");
8065 /* try unload UNDI on port 0 */
8068 (SHMEM_RD(bp, func_mb[bp->pf_num].drv_mb_header) &
8069 DRV_MSG_SEQ_NUMBER_MASK);
8070 reset_code = bnx2x_fw_command(bp, reset_code, 0);
8072 /* if UNDI is loaded on the other port */
8073 if (reset_code != FW_MSG_CODE_DRV_UNLOAD_COMMON) {
8075 /* send "DONE" for previous unload */
8076 bnx2x_fw_command(bp,
8077 DRV_MSG_CODE_UNLOAD_DONE, 0);
8079 /* unload UNDI on port 1 */
8082 (SHMEM_RD(bp, func_mb[bp->pf_num].drv_mb_header) &
8083 DRV_MSG_SEQ_NUMBER_MASK);
8084 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
8086 bnx2x_fw_command(bp, reset_code, 0);
8089 /* now it's safe to release the lock */
8090 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_UNDI);
8092 bnx2x_undi_int_disable(bp);
8095 /* close input traffic and wait for it */
8096 /* Do not rcv packets to BRB */
8097 REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_DRV_MASK :
8098 NIG_REG_LLH0_BRB1_DRV_MASK), 0x0);
8099 /* Do not direct rcv packets that are not for MCP to
8101 REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
8102 NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
8104 REG_WR(bp, (port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
8105 MISC_REG_AEU_MASK_ATTN_FUNC_0), 0);
8108 /* save NIG port swap info */
8109 swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
8110 swap_en = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
8113 GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
8117 if (CHIP_IS_E3(bp)) {
8118 value |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
8119 value |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
8123 GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
8126 /* take the NIG out of reset and restore swap values */
8128 GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
8129 MISC_REGISTERS_RESET_REG_1_RST_NIG);
8130 REG_WR(bp, NIG_REG_PORT_SWAP, swap_val);
8131 REG_WR(bp, NIG_REG_STRAP_OVERRIDE, swap_en);
8133 /* send unload done to the MCP */
8134 bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
8136 /* restore our func and fw_seq */
8137 bp->pf_num = orig_pf_num;
8139 (SHMEM_RD(bp, func_mb[bp->pf_num].drv_mb_header) &
8140 DRV_MSG_SEQ_NUMBER_MASK);
8142 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_UNDI);
8146 static void __devinit bnx2x_get_common_hwinfo(struct bnx2x *bp)
8148 u32 val, val2, val3, val4, id;
8151 /* Get the chip revision id and number. */
8152 /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
8153 val = REG_RD(bp, MISC_REG_CHIP_NUM);
8154 id = ((val & 0xffff) << 16);
8155 val = REG_RD(bp, MISC_REG_CHIP_REV);
8156 id |= ((val & 0xf) << 12);
8157 val = REG_RD(bp, MISC_REG_CHIP_METAL);
8158 id |= ((val & 0xff) << 4);
8159 val = REG_RD(bp, MISC_REG_BOND_ID);
8161 bp->common.chip_id = id;
8163 /* Set doorbell size */
8164 bp->db_size = (1 << BNX2X_DB_SHIFT);
8166 if (!CHIP_IS_E1x(bp)) {
8167 val = REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR);
8169 val = REG_RD(bp, MISC_REG_PORT4MODE_EN);
8171 val = (val >> 1) & 1;
8172 BNX2X_DEV_INFO("chip is in %s\n", val ? "4_PORT_MODE" :
8174 bp->common.chip_port_mode = val ? CHIP_4_PORT_MODE :
8177 if (CHIP_MODE_IS_4_PORT(bp))
8178 bp->pfid = (bp->pf_num >> 1); /* 0..3 */
8180 bp->pfid = (bp->pf_num & 0x6); /* 0, 2, 4, 6 */
8182 bp->common.chip_port_mode = CHIP_PORT_MODE_NONE; /* N/A */
8183 bp->pfid = bp->pf_num; /* 0..7 */
8186 bp->link_params.chip_id = bp->common.chip_id;
8187 BNX2X_DEV_INFO("chip ID is 0x%x\n", id);
8189 val = (REG_RD(bp, 0x2874) & 0x55);
8190 if ((bp->common.chip_id & 0x1) ||
8191 (CHIP_IS_E1(bp) && val) || (CHIP_IS_E1H(bp) && (val == 0x55))) {
8192 bp->flags |= ONE_PORT_FLAG;
8193 BNX2X_DEV_INFO("single port device\n");
8196 val = REG_RD(bp, MCP_REG_MCPR_NVM_CFG4);
8197 bp->common.flash_size = (BNX2X_NVRAM_1MB_SIZE <<
8198 (val & MCPR_NVM_CFG4_FLASH_SIZE));
8199 BNX2X_DEV_INFO("flash_size 0x%x (%d)\n",
8200 bp->common.flash_size, bp->common.flash_size);
8202 bnx2x_init_shmem(bp);
8206 bp->common.shmem2_base = REG_RD(bp, (BP_PATH(bp) ?
8207 MISC_REG_GENERIC_CR_1 :
8208 MISC_REG_GENERIC_CR_0));
8210 bp->link_params.shmem_base = bp->common.shmem_base;
8211 bp->link_params.shmem2_base = bp->common.shmem2_base;
8212 BNX2X_DEV_INFO("shmem offset 0x%x shmem2 offset 0x%x\n",
8213 bp->common.shmem_base, bp->common.shmem2_base);
8215 if (!bp->common.shmem_base) {
8216 BNX2X_DEV_INFO("MCP not active\n");
8217 bp->flags |= NO_MCP_FLAG;
8221 bp->common.hw_config = SHMEM_RD(bp, dev_info.shared_hw_config.config);
8222 BNX2X_DEV_INFO("hw_config 0x%08x\n", bp->common.hw_config);
8224 bp->link_params.hw_led_mode = ((bp->common.hw_config &
8225 SHARED_HW_CFG_LED_MODE_MASK) >>
8226 SHARED_HW_CFG_LED_MODE_SHIFT);
8228 bp->link_params.feature_config_flags = 0;
8229 val = SHMEM_RD(bp, dev_info.shared_feature_config.config);
8230 if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED)
8231 bp->link_params.feature_config_flags |=
8232 FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
8234 bp->link_params.feature_config_flags &=
8235 ~FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
8237 val = SHMEM_RD(bp, dev_info.bc_rev) >> 8;
8238 bp->common.bc_ver = val;
8239 BNX2X_DEV_INFO("bc_ver %X\n", val);
8240 if (val < BNX2X_BC_VER) {
8241 /* for now only warn
8242 * later we might need to enforce this */
8243 BNX2X_ERR("This driver needs bc_ver %X but found %X, "
8244 "please upgrade BC\n", BNX2X_BC_VER, val);
8246 bp->link_params.feature_config_flags |=
8247 (val >= REQ_BC_VER_4_VRFY_FIRST_PHY_OPT_MDL) ?
8248 FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY : 0;
8250 bp->link_params.feature_config_flags |=
8251 (val >= REQ_BC_VER_4_VRFY_SPECIFIC_PHY_OPT_MDL) ?
8252 FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY : 0;
8254 pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_PMC, &pmc);
8255 bp->flags |= (pmc & PCI_PM_CAP_PME_D3cold) ? 0 : NO_WOL_FLAG;
8257 BNX2X_DEV_INFO("%sWoL capable\n",
8258 (bp->flags & NO_WOL_FLAG) ? "not " : "");
8260 val = SHMEM_RD(bp, dev_info.shared_hw_config.part_num);
8261 val2 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[4]);
8262 val3 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[8]);
8263 val4 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[12]);
8265 dev_info(&bp->pdev->dev, "part number %X-%X-%X-%X\n",
8266 val, val2, val3, val4);
8269 #define IGU_FID(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID)
8270 #define IGU_VEC(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR)
8272 static void __devinit bnx2x_get_igu_cam_info(struct bnx2x *bp)
8274 int pfid = BP_FUNC(bp);
8275 int vn = BP_E1HVN(bp);
8280 bp->igu_base_sb = 0xff;
8282 if (CHIP_INT_MODE_IS_BC(bp)) {
8283 bp->igu_sb_cnt = min_t(u8, FP_SB_MAX_E1x,
8284 NUM_IGU_SB_REQUIRED(bp->l2_cid_count));
8286 bp->igu_base_sb = (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn) *
8289 bp->igu_dsb_id = E1HVN_MAX * FP_SB_MAX_E1x +
8290 (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn);
8295 /* IGU in normal mode - read CAM */
8296 for (igu_sb_id = 0; igu_sb_id < IGU_REG_MAPPING_MEMORY_SIZE;
8298 val = REG_RD(bp, IGU_REG_MAPPING_MEMORY + igu_sb_id * 4);
8299 if (!(val & IGU_REG_MAPPING_MEMORY_VALID))
8302 if ((fid & IGU_FID_ENCODE_IS_PF)) {
8303 if ((fid & IGU_FID_PF_NUM_MASK) != pfid)
8305 if (IGU_VEC(val) == 0)
8306 /* default status block */
8307 bp->igu_dsb_id = igu_sb_id;
8309 if (bp->igu_base_sb == 0xff)
8310 bp->igu_base_sb = igu_sb_id;
8316 /* It's expected that number of CAM entries for this
8317 * functions is equal to the MSI-X table size (which was a
8318 * used during bp->l2_cid_count value calculation.
8319 * We want a harsh warning if these values are different!
8321 WARN_ON(bp->igu_sb_cnt != NUM_IGU_SB_REQUIRED(bp->l2_cid_count));
8323 if (bp->igu_sb_cnt == 0)
8324 BNX2X_ERR("CAM configuration error\n");
8327 static void __devinit bnx2x_link_settings_supported(struct bnx2x *bp,
8330 int cfg_size = 0, idx, port = BP_PORT(bp);
8332 /* Aggregation of supported attributes of all external phys */
8333 bp->port.supported[0] = 0;
8334 bp->port.supported[1] = 0;
8335 switch (bp->link_params.num_phys) {
8337 bp->port.supported[0] = bp->link_params.phy[INT_PHY].supported;
8341 bp->port.supported[0] = bp->link_params.phy[EXT_PHY1].supported;
8345 if (bp->link_params.multi_phy_config &
8346 PORT_HW_CFG_PHY_SWAPPED_ENABLED) {
8347 bp->port.supported[1] =
8348 bp->link_params.phy[EXT_PHY1].supported;
8349 bp->port.supported[0] =
8350 bp->link_params.phy[EXT_PHY2].supported;
8352 bp->port.supported[0] =
8353 bp->link_params.phy[EXT_PHY1].supported;
8354 bp->port.supported[1] =
8355 bp->link_params.phy[EXT_PHY2].supported;
8361 if (!(bp->port.supported[0] || bp->port.supported[1])) {
8362 BNX2X_ERR("NVRAM config error. BAD phy config."
8363 "PHY1 config 0x%x, PHY2 config 0x%x\n",
8365 dev_info.port_hw_config[port].external_phy_config),
8367 dev_info.port_hw_config[port].external_phy_config2));
8372 bp->port.phy_addr = REG_RD(bp, MISC_REG_WC0_CTRL_PHY_ADDR);
8374 switch (switch_cfg) {
8376 bp->port.phy_addr = REG_RD(
8377 bp, NIG_REG_SERDES0_CTRL_PHY_ADDR + port*0x10);
8379 case SWITCH_CFG_10G:
8380 bp->port.phy_addr = REG_RD(
8381 bp, NIG_REG_XGXS0_CTRL_PHY_ADDR + port*0x18);
8384 BNX2X_ERR("BAD switch_cfg link_config 0x%x\n",
8385 bp->port.link_config[0]);
8389 BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr);
8390 /* mask what we support according to speed_cap_mask per configuration */
8391 for (idx = 0; idx < cfg_size; idx++) {
8392 if (!(bp->link_params.speed_cap_mask[idx] &
8393 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF))
8394 bp->port.supported[idx] &= ~SUPPORTED_10baseT_Half;
8396 if (!(bp->link_params.speed_cap_mask[idx] &
8397 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL))
8398 bp->port.supported[idx] &= ~SUPPORTED_10baseT_Full;
8400 if (!(bp->link_params.speed_cap_mask[idx] &
8401 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF))
8402 bp->port.supported[idx] &= ~SUPPORTED_100baseT_Half;
8404 if (!(bp->link_params.speed_cap_mask[idx] &
8405 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL))
8406 bp->port.supported[idx] &= ~SUPPORTED_100baseT_Full;
8408 if (!(bp->link_params.speed_cap_mask[idx] &
8409 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G))
8410 bp->port.supported[idx] &= ~(SUPPORTED_1000baseT_Half |
8411 SUPPORTED_1000baseT_Full);
8413 if (!(bp->link_params.speed_cap_mask[idx] &
8414 PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
8415 bp->port.supported[idx] &= ~SUPPORTED_2500baseX_Full;
8417 if (!(bp->link_params.speed_cap_mask[idx] &
8418 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G))
8419 bp->port.supported[idx] &= ~SUPPORTED_10000baseT_Full;
8423 BNX2X_DEV_INFO("supported 0x%x 0x%x\n", bp->port.supported[0],
8424 bp->port.supported[1]);
8427 static void __devinit bnx2x_link_settings_requested(struct bnx2x *bp)
8429 u32 link_config, idx, cfg_size = 0;
8430 bp->port.advertising[0] = 0;
8431 bp->port.advertising[1] = 0;
8432 switch (bp->link_params.num_phys) {
8441 for (idx = 0; idx < cfg_size; idx++) {
8442 bp->link_params.req_duplex[idx] = DUPLEX_FULL;
8443 link_config = bp->port.link_config[idx];
8444 switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) {
8445 case PORT_FEATURE_LINK_SPEED_AUTO:
8446 if (bp->port.supported[idx] & SUPPORTED_Autoneg) {
8447 bp->link_params.req_line_speed[idx] =
8449 bp->port.advertising[idx] |=
8450 bp->port.supported[idx];
8452 /* force 10G, no AN */
8453 bp->link_params.req_line_speed[idx] =
8455 bp->port.advertising[idx] |=
8456 (ADVERTISED_10000baseT_Full |
8462 case PORT_FEATURE_LINK_SPEED_10M_FULL:
8463 if (bp->port.supported[idx] & SUPPORTED_10baseT_Full) {
8464 bp->link_params.req_line_speed[idx] =
8466 bp->port.advertising[idx] |=
8467 (ADVERTISED_10baseT_Full |
8470 BNX2X_ERR("NVRAM config error. "
8471 "Invalid link_config 0x%x"
8472 " speed_cap_mask 0x%x\n",
8474 bp->link_params.speed_cap_mask[idx]);
8479 case PORT_FEATURE_LINK_SPEED_10M_HALF:
8480 if (bp->port.supported[idx] & SUPPORTED_10baseT_Half) {
8481 bp->link_params.req_line_speed[idx] =
8483 bp->link_params.req_duplex[idx] =
8485 bp->port.advertising[idx] |=
8486 (ADVERTISED_10baseT_Half |
8489 BNX2X_ERR("NVRAM config error. "
8490 "Invalid link_config 0x%x"
8491 " speed_cap_mask 0x%x\n",
8493 bp->link_params.speed_cap_mask[idx]);
8498 case PORT_FEATURE_LINK_SPEED_100M_FULL:
8499 if (bp->port.supported[idx] &
8500 SUPPORTED_100baseT_Full) {
8501 bp->link_params.req_line_speed[idx] =
8503 bp->port.advertising[idx] |=
8504 (ADVERTISED_100baseT_Full |
8507 BNX2X_ERR("NVRAM config error. "
8508 "Invalid link_config 0x%x"
8509 " speed_cap_mask 0x%x\n",
8511 bp->link_params.speed_cap_mask[idx]);
8516 case PORT_FEATURE_LINK_SPEED_100M_HALF:
8517 if (bp->port.supported[idx] &
8518 SUPPORTED_100baseT_Half) {
8519 bp->link_params.req_line_speed[idx] =
8521 bp->link_params.req_duplex[idx] =
8523 bp->port.advertising[idx] |=
8524 (ADVERTISED_100baseT_Half |
8527 BNX2X_ERR("NVRAM config error. "
8528 "Invalid link_config 0x%x"
8529 " speed_cap_mask 0x%x\n",
8531 bp->link_params.speed_cap_mask[idx]);
8536 case PORT_FEATURE_LINK_SPEED_1G:
8537 if (bp->port.supported[idx] &
8538 SUPPORTED_1000baseT_Full) {
8539 bp->link_params.req_line_speed[idx] =
8541 bp->port.advertising[idx] |=
8542 (ADVERTISED_1000baseT_Full |
8545 BNX2X_ERR("NVRAM config error. "
8546 "Invalid link_config 0x%x"
8547 " speed_cap_mask 0x%x\n",
8549 bp->link_params.speed_cap_mask[idx]);
8554 case PORT_FEATURE_LINK_SPEED_2_5G:
8555 if (bp->port.supported[idx] &
8556 SUPPORTED_2500baseX_Full) {
8557 bp->link_params.req_line_speed[idx] =
8559 bp->port.advertising[idx] |=
8560 (ADVERTISED_2500baseX_Full |
8563 BNX2X_ERR("NVRAM config error. "
8564 "Invalid link_config 0x%x"
8565 " speed_cap_mask 0x%x\n",
8567 bp->link_params.speed_cap_mask[idx]);
8572 case PORT_FEATURE_LINK_SPEED_10G_CX4:
8573 if (bp->port.supported[idx] &
8574 SUPPORTED_10000baseT_Full) {
8575 bp->link_params.req_line_speed[idx] =
8577 bp->port.advertising[idx] |=
8578 (ADVERTISED_10000baseT_Full |
8581 BNX2X_ERR("NVRAM config error. "
8582 "Invalid link_config 0x%x"
8583 " speed_cap_mask 0x%x\n",
8585 bp->link_params.speed_cap_mask[idx]);
8589 case PORT_FEATURE_LINK_SPEED_20G:
8590 bp->link_params.req_line_speed[idx] = SPEED_20000;
8594 BNX2X_ERR("NVRAM config error. "
8595 "BAD link speed link_config 0x%x\n",
8597 bp->link_params.req_line_speed[idx] =
8599 bp->port.advertising[idx] =
8600 bp->port.supported[idx];
8604 bp->link_params.req_flow_ctrl[idx] = (link_config &
8605 PORT_FEATURE_FLOW_CONTROL_MASK);
8606 if ((bp->link_params.req_flow_ctrl[idx] ==
8607 BNX2X_FLOW_CTRL_AUTO) &&
8608 !(bp->port.supported[idx] & SUPPORTED_Autoneg)) {
8609 bp->link_params.req_flow_ctrl[idx] =
8610 BNX2X_FLOW_CTRL_NONE;
8613 BNX2X_DEV_INFO("req_line_speed %d req_duplex %d req_flow_ctrl"
8614 " 0x%x advertising 0x%x\n",
8615 bp->link_params.req_line_speed[idx],
8616 bp->link_params.req_duplex[idx],
8617 bp->link_params.req_flow_ctrl[idx],
8618 bp->port.advertising[idx]);
8622 static void __devinit bnx2x_set_mac_buf(u8 *mac_buf, u32 mac_lo, u16 mac_hi)
8624 mac_hi = cpu_to_be16(mac_hi);
8625 mac_lo = cpu_to_be32(mac_lo);
8626 memcpy(mac_buf, &mac_hi, sizeof(mac_hi));
8627 memcpy(mac_buf + sizeof(mac_hi), &mac_lo, sizeof(mac_lo));
8630 static void __devinit bnx2x_get_port_hwinfo(struct bnx2x *bp)
8632 int port = BP_PORT(bp);
8634 u32 ext_phy_type, ext_phy_config;
8636 bp->link_params.bp = bp;
8637 bp->link_params.port = port;
8639 bp->link_params.lane_config =
8640 SHMEM_RD(bp, dev_info.port_hw_config[port].lane_config);
8642 bp->link_params.speed_cap_mask[0] =
8644 dev_info.port_hw_config[port].speed_capability_mask);
8645 bp->link_params.speed_cap_mask[1] =
8647 dev_info.port_hw_config[port].speed_capability_mask2);
8648 bp->port.link_config[0] =
8649 SHMEM_RD(bp, dev_info.port_feature_config[port].link_config);
8651 bp->port.link_config[1] =
8652 SHMEM_RD(bp, dev_info.port_feature_config[port].link_config2);
8654 bp->link_params.multi_phy_config =
8655 SHMEM_RD(bp, dev_info.port_hw_config[port].multi_phy_config);
8656 /* If the device is capable of WoL, set the default state according
8659 config = SHMEM_RD(bp, dev_info.port_feature_config[port].config);
8660 bp->wol = (!(bp->flags & NO_WOL_FLAG) &&
8661 (config & PORT_FEATURE_WOL_ENABLED));
8663 BNX2X_DEV_INFO("lane_config 0x%08x "
8664 "speed_cap_mask0 0x%08x link_config0 0x%08x\n",
8665 bp->link_params.lane_config,
8666 bp->link_params.speed_cap_mask[0],
8667 bp->port.link_config[0]);
8669 bp->link_params.switch_cfg = (bp->port.link_config[0] &
8670 PORT_FEATURE_CONNECTED_SWITCH_MASK);
8671 bnx2x_phy_probe(&bp->link_params);
8672 bnx2x_link_settings_supported(bp, bp->link_params.switch_cfg);
8674 bnx2x_link_settings_requested(bp);
8677 * If connected directly, work with the internal PHY, otherwise, work
8678 * with the external PHY
8682 dev_info.port_hw_config[port].external_phy_config);
8683 ext_phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
8684 if (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
8685 bp->mdio.prtad = bp->port.phy_addr;
8687 else if ((ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) &&
8688 (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN))
8690 XGXS_EXT_PHY_ADDR(ext_phy_config);
8693 * Check if hw lock is required to access MDC/MDIO bus to the PHY(s)
8694 * In MF mode, it is set to cover self test cases
8697 bp->port.need_hw_lock = 1;
8699 bp->port.need_hw_lock = bnx2x_hw_lock_required(bp,
8700 bp->common.shmem_base,
8701 bp->common.shmem2_base);
8705 static void __devinit bnx2x_get_cnic_info(struct bnx2x *bp)
8707 u32 max_iscsi_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
8708 drv_lic_key[BP_PORT(bp)].max_iscsi_conn);
8709 u32 max_fcoe_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
8710 drv_lic_key[BP_PORT(bp)].max_fcoe_conn);
8712 /* Get the number of maximum allowed iSCSI and FCoE connections */
8713 bp->cnic_eth_dev.max_iscsi_conn =
8714 (max_iscsi_conn & BNX2X_MAX_ISCSI_INIT_CONN_MASK) >>
8715 BNX2X_MAX_ISCSI_INIT_CONN_SHIFT;
8717 bp->cnic_eth_dev.max_fcoe_conn =
8718 (max_fcoe_conn & BNX2X_MAX_FCOE_INIT_CONN_MASK) >>
8719 BNX2X_MAX_FCOE_INIT_CONN_SHIFT;
8721 BNX2X_DEV_INFO("max_iscsi_conn 0x%x max_fcoe_conn 0x%x\n",
8722 bp->cnic_eth_dev.max_iscsi_conn,
8723 bp->cnic_eth_dev.max_fcoe_conn);
8725 /* If mamimum allowed number of connections is zero -
8726 * disable the feature.
8728 if (!bp->cnic_eth_dev.max_iscsi_conn)
8729 bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
8731 if (!bp->cnic_eth_dev.max_fcoe_conn)
8732 bp->flags |= NO_FCOE_FLAG;
8736 static void __devinit bnx2x_get_mac_hwinfo(struct bnx2x *bp)
8739 int func = BP_ABS_FUNC(bp);
8740 int port = BP_PORT(bp);
8742 u8 *iscsi_mac = bp->cnic_eth_dev.iscsi_mac;
8743 u8 *fip_mac = bp->fip_mac;
8746 /* Zero primary MAC configuration */
8747 memset(bp->dev->dev_addr, 0, ETH_ALEN);
8750 BNX2X_ERROR("warning: random MAC workaround active\n");
8751 random_ether_addr(bp->dev->dev_addr);
8752 } else if (IS_MF(bp)) {
8753 val2 = MF_CFG_RD(bp, func_mf_config[func].mac_upper);
8754 val = MF_CFG_RD(bp, func_mf_config[func].mac_lower);
8755 if ((val2 != FUNC_MF_CFG_UPPERMAC_DEFAULT) &&
8756 (val != FUNC_MF_CFG_LOWERMAC_DEFAULT))
8757 bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
8760 /* iSCSI and FCoE NPAR MACs: if there is no either iSCSI or
8761 * FCoE MAC then the appropriate feature should be disabled.
8764 u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg);
8765 if (cfg & MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD) {
8766 val2 = MF_CFG_RD(bp, func_ext_config[func].
8767 iscsi_mac_addr_upper);
8768 val = MF_CFG_RD(bp, func_ext_config[func].
8769 iscsi_mac_addr_lower);
8770 bnx2x_set_mac_buf(iscsi_mac, val, val2);
8771 BNX2X_DEV_INFO("Read iSCSI MAC: "
8773 BNX2X_MAC_PRN_LIST(iscsi_mac));
8775 bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
8777 if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD) {
8778 val2 = MF_CFG_RD(bp, func_ext_config[func].
8779 fcoe_mac_addr_upper);
8780 val = MF_CFG_RD(bp, func_ext_config[func].
8781 fcoe_mac_addr_lower);
8782 bnx2x_set_mac_buf(fip_mac, val, val2);
8783 BNX2X_DEV_INFO("Read FCoE L2 MAC to "
8785 BNX2X_MAC_PRN_LIST(fip_mac));
8788 bp->flags |= NO_FCOE_FLAG;
8792 /* in SF read MACs from port configuration */
8793 val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
8794 val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
8795 bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
8798 val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
8800 val = SHMEM_RD(bp, dev_info.port_hw_config[port].
8802 bnx2x_set_mac_buf(iscsi_mac, val, val2);
8806 memcpy(bp->link_params.mac_addr, bp->dev->dev_addr, ETH_ALEN);
8807 memcpy(bp->dev->perm_addr, bp->dev->dev_addr, ETH_ALEN);
8810 /* Set the FCoE MAC in modes other then MF_SI */
8811 if (!CHIP_IS_E1x(bp)) {
8813 memcpy(fip_mac, bp->dev->dev_addr, ETH_ALEN);
8814 else if (!IS_MF(bp))
8815 memcpy(fip_mac, iscsi_mac, ETH_ALEN);
8818 /* Disable iSCSI if MAC configuration is
8821 if (!is_valid_ether_addr(iscsi_mac)) {
8822 bp->flags |= NO_ISCSI_FLAG;
8823 memset(iscsi_mac, 0, ETH_ALEN);
8826 /* Disable FCoE if MAC configuration is
8829 if (!is_valid_ether_addr(fip_mac)) {
8830 bp->flags |= NO_FCOE_FLAG;
8831 memset(bp->fip_mac, 0, ETH_ALEN);
8835 if (!is_valid_ether_addr(bp->dev->dev_addr))
8836 dev_err(&bp->pdev->dev,
8837 "bad Ethernet MAC address configuration: "
8838 BNX2X_MAC_FMT", change it manually before bringing up "
8839 "the appropriate network interface\n",
8840 BNX2X_MAC_PRN_LIST(bp->dev->dev_addr));
8843 static int __devinit bnx2x_get_hwinfo(struct bnx2x *bp)
8845 int /*abs*/func = BP_ABS_FUNC(bp);
8850 bnx2x_get_common_hwinfo(bp);
8852 if (CHIP_IS_E1x(bp)) {
8853 bp->common.int_block = INT_BLOCK_HC;
8855 bp->igu_dsb_id = DEF_SB_IGU_ID;
8856 bp->igu_base_sb = 0;
8857 bp->igu_sb_cnt = min_t(u8, FP_SB_MAX_E1x,
8858 NUM_IGU_SB_REQUIRED(bp->l2_cid_count));
8860 bp->common.int_block = INT_BLOCK_IGU;
8861 val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
8863 if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
8866 BNX2X_DEV_INFO("FORCING Normal Mode\n");
8868 val &= ~(IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN);
8869 REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION, val);
8870 REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x7f);
8872 while (tout && REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
8874 usleep_range(1000, 1000);
8877 if (REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
8878 dev_err(&bp->pdev->dev,
8879 "FORCING Normal Mode failed!!!\n");
8884 if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
8885 BNX2X_DEV_INFO("IGU Backward Compatible Mode\n");
8886 bp->common.int_block |= INT_BLOCK_MODE_BW_COMP;
8888 BNX2X_DEV_INFO("IGU Normal Mode\n");
8890 bnx2x_get_igu_cam_info(bp);
8895 * set base FW non-default (fast path) status block id, this value is
8896 * used to initialize the fw_sb_id saved on the fp/queue structure to
8897 * determine the id used by the FW.
8899 if (CHIP_IS_E1x(bp))
8900 bp->base_fw_ndsb = BP_PORT(bp) * FP_SB_MAX_E1x + BP_L_ID(bp);
8902 * 57712 - we currently use one FW SB per IGU SB (Rx and Tx of
8903 * the same queue are indicated on the same IGU SB). So we prefer
8904 * FW and IGU SBs to be the same value.
8906 bp->base_fw_ndsb = bp->igu_base_sb;
8908 BNX2X_DEV_INFO("igu_dsb_id %d igu_base_sb %d igu_sb_cnt %d\n"
8909 "base_fw_ndsb %d\n", bp->igu_dsb_id, bp->igu_base_sb,
8910 bp->igu_sb_cnt, bp->base_fw_ndsb);
8913 * Initialize MF configuration
8920 if (!CHIP_IS_E1(bp) && !BP_NOMCP(bp)) {
8921 BNX2X_DEV_INFO("shmem2base 0x%x, size %d, mfcfg offset %d\n",
8922 bp->common.shmem2_base, SHMEM2_RD(bp, size),
8923 (u32)offsetof(struct shmem2_region, mf_cfg_addr));
8925 if (SHMEM2_HAS(bp, mf_cfg_addr))
8926 bp->common.mf_cfg_base = SHMEM2_RD(bp, mf_cfg_addr);
8928 bp->common.mf_cfg_base = bp->common.shmem_base +
8929 offsetof(struct shmem_region, func_mb) +
8930 E1H_FUNC_MAX * sizeof(struct drv_func_mb);
8932 * get mf configuration:
8933 * 1. existence of MF configuration
8934 * 2. MAC address must be legal (check only upper bytes)
8935 * for Switch-Independent mode;
8936 * OVLAN must be legal for Switch-Dependent mode
8937 * 3. SF_MODE configures specific MF mode
8939 if (bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
8940 /* get mf configuration */
8942 dev_info.shared_feature_config.config);
8943 val &= SHARED_FEAT_CFG_FORCE_SF_MODE_MASK;
8946 case SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT:
8947 val = MF_CFG_RD(bp, func_mf_config[func].
8949 /* check for legal mac (upper bytes)*/
8950 if (val != 0xffff) {
8951 bp->mf_mode = MULTI_FUNCTION_SI;
8952 bp->mf_config[vn] = MF_CFG_RD(bp,
8953 func_mf_config[func].config);
8955 BNX2X_DEV_INFO("illegal MAC address "
8958 case SHARED_FEAT_CFG_FORCE_SF_MODE_MF_ALLOWED:
8959 /* get OV configuration */
8961 func_mf_config[FUNC_0].e1hov_tag);
8962 val &= FUNC_MF_CFG_E1HOV_TAG_MASK;
8964 if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
8965 bp->mf_mode = MULTI_FUNCTION_SD;
8966 bp->mf_config[vn] = MF_CFG_RD(bp,
8967 func_mf_config[func].config);
8969 BNX2X_DEV_INFO("illegal OV for SD\n");
8972 /* Unknown configuration: reset mf_config */
8973 bp->mf_config[vn] = 0;
8974 BNX2X_DEV_INFO("unkown MF mode 0x%x\n", val);
8978 BNX2X_DEV_INFO("%s function mode\n",
8979 IS_MF(bp) ? "multi" : "single");
8981 switch (bp->mf_mode) {
8982 case MULTI_FUNCTION_SD:
8983 val = MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
8984 FUNC_MF_CFG_E1HOV_TAG_MASK;
8985 if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
8987 bp->path_has_ovlan = true;
8989 BNX2X_DEV_INFO("MF OV for func %d is %d "
8990 "(0x%04x)\n", func, bp->mf_ov,
8993 dev_err(&bp->pdev->dev,
8994 "No valid MF OV for func %d, "
8995 "aborting\n", func);
8999 case MULTI_FUNCTION_SI:
9000 BNX2X_DEV_INFO("func %d is in MF "
9001 "switch-independent mode\n", func);
9005 dev_err(&bp->pdev->dev,
9006 "VN %d is in a single function mode, "
9013 /* check if other port on the path needs ovlan:
9014 * Since MF configuration is shared between ports
9015 * Possible mixed modes are only
9016 * {SF, SI} {SF, SD} {SD, SF} {SI, SF}
9018 if (CHIP_MODE_IS_4_PORT(bp) &&
9019 !bp->path_has_ovlan &&
9021 bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
9022 u8 other_port = !BP_PORT(bp);
9023 u8 other_func = BP_PATH(bp) + 2*other_port;
9025 func_mf_config[other_func].e1hov_tag);
9026 if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT)
9027 bp->path_has_ovlan = true;
9031 /* adjust igu_sb_cnt to MF for E1x */
9032 if (CHIP_IS_E1x(bp) && IS_MF(bp))
9033 bp->igu_sb_cnt /= E1HVN_MAX;
9036 bnx2x_get_port_hwinfo(bp);
9038 if (!BP_NOMCP(bp)) {
9040 (SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
9041 DRV_MSG_SEQ_NUMBER_MASK);
9042 BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
9045 /* Get MAC addresses */
9046 bnx2x_get_mac_hwinfo(bp);
9049 bnx2x_get_cnic_info(bp);
9052 /* Get current FW pulse sequence */
9053 if (!BP_NOMCP(bp)) {
9054 int mb_idx = BP_FW_MB_IDX(bp);
9056 bp->fw_drv_pulse_wr_seq =
9057 (SHMEM_RD(bp, func_mb[mb_idx].drv_pulse_mb) &
9058 DRV_PULSE_SEQ_MASK);
9059 BNX2X_DEV_INFO("drv_pulse 0x%x\n", bp->fw_drv_pulse_wr_seq);
9065 static void __devinit bnx2x_read_fwinfo(struct bnx2x *bp)
9067 int cnt, i, block_end, rodi;
9068 char vpd_data[BNX2X_VPD_LEN+1];
9069 char str_id_reg[VENDOR_ID_LEN+1];
9070 char str_id_cap[VENDOR_ID_LEN+1];
9073 cnt = pci_read_vpd(bp->pdev, 0, BNX2X_VPD_LEN, vpd_data);
9074 memset(bp->fw_ver, 0, sizeof(bp->fw_ver));
9076 if (cnt < BNX2X_VPD_LEN)
9079 i = pci_vpd_find_tag(vpd_data, 0, BNX2X_VPD_LEN,
9080 PCI_VPD_LRDT_RO_DATA);
9085 block_end = i + PCI_VPD_LRDT_TAG_SIZE +
9086 pci_vpd_lrdt_size(&vpd_data[i]);
9088 i += PCI_VPD_LRDT_TAG_SIZE;
9090 if (block_end > BNX2X_VPD_LEN)
9093 rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
9094 PCI_VPD_RO_KEYWORD_MFR_ID);
9098 len = pci_vpd_info_field_size(&vpd_data[rodi]);
9100 if (len != VENDOR_ID_LEN)
9103 rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
9105 /* vendor specific info */
9106 snprintf(str_id_reg, VENDOR_ID_LEN + 1, "%04x", PCI_VENDOR_ID_DELL);
9107 snprintf(str_id_cap, VENDOR_ID_LEN + 1, "%04X", PCI_VENDOR_ID_DELL);
9108 if (!strncmp(str_id_reg, &vpd_data[rodi], VENDOR_ID_LEN) ||
9109 !strncmp(str_id_cap, &vpd_data[rodi], VENDOR_ID_LEN)) {
9111 rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
9112 PCI_VPD_RO_KEYWORD_VENDOR0);
9114 len = pci_vpd_info_field_size(&vpd_data[rodi]);
9116 rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
9118 if (len < 32 && (len + rodi) <= BNX2X_VPD_LEN) {
9119 memcpy(bp->fw_ver, &vpd_data[rodi], len);
9120 bp->fw_ver[len] = ' ';
9129 static void __devinit bnx2x_set_modes_bitmap(struct bnx2x *bp)
9133 if (CHIP_REV_IS_FPGA(bp))
9134 SET_FLAGS(flags, MODE_FPGA);
9135 else if (CHIP_REV_IS_EMUL(bp))
9136 SET_FLAGS(flags, MODE_EMUL);
9138 SET_FLAGS(flags, MODE_ASIC);
9140 if (CHIP_MODE_IS_4_PORT(bp))
9141 SET_FLAGS(flags, MODE_PORT4);
9143 SET_FLAGS(flags, MODE_PORT2);
9146 SET_FLAGS(flags, MODE_E2);
9147 else if (CHIP_IS_E3(bp)) {
9148 SET_FLAGS(flags, MODE_E3);
9149 if (CHIP_REV(bp) == CHIP_REV_Ax)
9150 SET_FLAGS(flags, MODE_E3_A0);
9151 else {/*if (CHIP_REV(bp) == CHIP_REV_Bx)*/
9152 SET_FLAGS(flags, MODE_E3_B0);
9153 SET_FLAGS(flags, MODE_COS_BC);
9158 SET_FLAGS(flags, MODE_MF);
9159 switch (bp->mf_mode) {
9160 case MULTI_FUNCTION_SD:
9161 SET_FLAGS(flags, MODE_MF_SD);
9163 case MULTI_FUNCTION_SI:
9164 SET_FLAGS(flags, MODE_MF_SI);
9168 SET_FLAGS(flags, MODE_SF);
9170 #if defined(__LITTLE_ENDIAN)
9171 SET_FLAGS(flags, MODE_LITTLE_ENDIAN);
9172 #else /*(__BIG_ENDIAN)*/
9173 SET_FLAGS(flags, MODE_BIG_ENDIAN);
9175 INIT_MODE_FLAGS(bp) = flags;
9178 static int __devinit bnx2x_init_bp(struct bnx2x *bp)
9184 mutex_init(&bp->port.phy_mutex);
9185 mutex_init(&bp->fw_mb_mutex);
9186 spin_lock_init(&bp->stats_lock);
9188 mutex_init(&bp->cnic_mutex);
9191 INIT_DELAYED_WORK(&bp->sp_task, bnx2x_sp_task);
9192 INIT_DELAYED_WORK(&bp->reset_task, bnx2x_reset_task);
9194 rc = bnx2x_get_hwinfo(bp);
9198 bnx2x_set_modes_bitmap(bp);
9200 rc = bnx2x_alloc_mem_bp(bp);
9204 bnx2x_read_fwinfo(bp);
9208 /* need to reset chip if undi was active */
9210 bnx2x_undi_unload(bp);
9212 if (CHIP_REV_IS_FPGA(bp))
9213 dev_err(&bp->pdev->dev, "FPGA detected\n");
9215 if (BP_NOMCP(bp) && (func == 0))
9216 dev_err(&bp->pdev->dev, "MCP disabled, "
9217 "must load devices in order!\n");
9219 bp->multi_mode = multi_mode;
9223 bp->flags &= ~TPA_ENABLE_FLAG;
9224 bp->dev->features &= ~NETIF_F_LRO;
9226 bp->flags |= TPA_ENABLE_FLAG;
9227 bp->dev->features |= NETIF_F_LRO;
9229 bp->disable_tpa = disable_tpa;
9232 bp->dropless_fc = 0;
9234 bp->dropless_fc = dropless_fc;
9238 bp->tx_ring_size = MAX_TX_AVAIL;
9240 /* make sure that the numbers are in the right granularity */
9241 bp->tx_ticks = (50 / BNX2X_BTR) * BNX2X_BTR;
9242 bp->rx_ticks = (25 / BNX2X_BTR) * BNX2X_BTR;
9244 timer_interval = (CHIP_REV_IS_SLOW(bp) ? 5*HZ : HZ);
9245 bp->current_interval = (poll ? poll : timer_interval);
9247 init_timer(&bp->timer);
9248 bp->timer.expires = jiffies + bp->current_interval;
9249 bp->timer.data = (unsigned long) bp;
9250 bp->timer.function = bnx2x_timer;
9252 bnx2x_dcbx_set_state(bp, true, BNX2X_DCBX_ENABLED_ON_NEG_ON);
9253 bnx2x_dcbx_init_params(bp);
9256 if (CHIP_IS_E1x(bp))
9257 bp->cnic_base_cl_id = FP_SB_MAX_E1x;
9259 bp->cnic_base_cl_id = FP_SB_MAX_E2;
9266 /****************************************************************************
9267 * General service functions
9268 ****************************************************************************/
9271 * net_device service functions
9274 /* called with rtnl_lock */
9275 static int bnx2x_open(struct net_device *dev)
9277 struct bnx2x *bp = netdev_priv(dev);
9278 bool global = false;
9279 int other_engine = BP_PATH(bp) ? 0 : 1;
9280 u32 other_load_counter, load_counter;
9282 netif_carrier_off(dev);
9284 bnx2x_set_power_state(bp, PCI_D0);
9286 other_load_counter = bnx2x_get_load_cnt(bp, other_engine);
9287 load_counter = bnx2x_get_load_cnt(bp, BP_PATH(bp));
9290 * If parity had happen during the unload, then attentions
9291 * and/or RECOVERY_IN_PROGRES may still be set. In this case we
9292 * want the first function loaded on the current engine to
9293 * complete the recovery.
9295 if (!bnx2x_reset_is_done(bp, BP_PATH(bp)) ||
9296 bnx2x_chk_parity_attn(bp, &global, true))
9299 * If there are attentions and they are in a global
9300 * blocks, set the GLOBAL_RESET bit regardless whether
9301 * it will be this function that will complete the
9305 bnx2x_set_reset_global(bp);
9308 * Only the first function on the current engine should
9309 * try to recover in open. In case of attentions in
9310 * global blocks only the first in the chip should try
9313 if ((!load_counter &&
9314 (!global || !other_load_counter)) &&
9315 bnx2x_trylock_leader_lock(bp) &&
9316 !bnx2x_leader_reset(bp)) {
9317 netdev_info(bp->dev, "Recovered in open\n");
9321 /* recovery has failed... */
9322 bnx2x_set_power_state(bp, PCI_D3hot);
9323 bp->recovery_state = BNX2X_RECOVERY_FAILED;
9325 netdev_err(bp->dev, "Recovery flow hasn't been properly"
9326 " completed yet. Try again later. If u still see this"
9327 " message after a few retries then power cycle is"
9333 bp->recovery_state = BNX2X_RECOVERY_DONE;
9334 return bnx2x_nic_load(bp, LOAD_OPEN);
9337 /* called with rtnl_lock */
9338 static int bnx2x_close(struct net_device *dev)
9340 struct bnx2x *bp = netdev_priv(dev);
9342 /* Unload the driver, release IRQs */
9343 bnx2x_nic_unload(bp, UNLOAD_CLOSE);
9346 bnx2x_set_power_state(bp, PCI_D3hot);
9351 static inline int bnx2x_init_mcast_macs_list(struct bnx2x *bp,
9352 struct bnx2x_mcast_ramrod_params *p)
9354 int mc_count = netdev_mc_count(bp->dev);
9355 struct bnx2x_mcast_list_elem *mc_mac =
9356 kzalloc(sizeof(*mc_mac) * mc_count, GFP_ATOMIC);
9357 struct netdev_hw_addr *ha;
9362 INIT_LIST_HEAD(&p->mcast_list);
9364 netdev_for_each_mc_addr(ha, bp->dev) {
9365 mc_mac->mac = bnx2x_mc_addr(ha);
9366 list_add_tail(&mc_mac->link, &p->mcast_list);
9370 p->mcast_list_len = mc_count;
9375 static inline void bnx2x_free_mcast_macs_list(
9376 struct bnx2x_mcast_ramrod_params *p)
9378 struct bnx2x_mcast_list_elem *mc_mac =
9379 list_first_entry(&p->mcast_list, struct bnx2x_mcast_list_elem,
9387 * bnx2x_set_uc_list - configure a new unicast MACs list.
9389 * @bp: driver handle
9391 * We will use zero (0) as a MAC type for these MACs.
9393 static inline int bnx2x_set_uc_list(struct bnx2x *bp)
9396 struct net_device *dev = bp->dev;
9397 struct netdev_hw_addr *ha;
9398 struct bnx2x_vlan_mac_obj *mac_obj = &bp->fp->mac_obj;
9399 unsigned long ramrod_flags = 0;
9401 /* First schedule a cleanup up of old configuration */
9402 rc = bnx2x_del_all_macs(bp, mac_obj, BNX2X_UC_LIST_MAC, false);
9404 BNX2X_ERR("Failed to schedule DELETE operations: %d\n", rc);
9408 netdev_for_each_uc_addr(ha, dev) {
9409 rc = bnx2x_set_mac_one(bp, bnx2x_uc_addr(ha), mac_obj, true,
9410 BNX2X_UC_LIST_MAC, &ramrod_flags);
9412 BNX2X_ERR("Failed to schedule ADD operations: %d\n",
9418 /* Execute the pending commands */
9419 __set_bit(RAMROD_CONT, &ramrod_flags);
9420 return bnx2x_set_mac_one(bp, NULL, mac_obj, false /* don't care */,
9421 BNX2X_UC_LIST_MAC, &ramrod_flags);
9424 static inline int bnx2x_set_mc_list(struct bnx2x *bp)
9426 struct net_device *dev = bp->dev;
9427 struct bnx2x_mcast_ramrod_params rparam = {0};
9430 rparam.mcast_obj = &bp->mcast_obj;
9432 /* first, clear all configured multicast MACs */
9433 rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
9435 BNX2X_ERR("Failed to clear multicast "
9436 "configuration: %d\n", rc);
9440 /* then, configure a new MACs list */
9441 if (netdev_mc_count(dev)) {
9442 rc = bnx2x_init_mcast_macs_list(bp, &rparam);
9444 BNX2X_ERR("Failed to create multicast MACs "
9449 /* Now add the new MACs */
9450 rc = bnx2x_config_mcast(bp, &rparam,
9451 BNX2X_MCAST_CMD_ADD);
9453 BNX2X_ERR("Failed to set a new multicast "
9454 "configuration: %d\n", rc);
9456 bnx2x_free_mcast_macs_list(&rparam);
9463 /* If bp->state is OPEN, should be called with netif_addr_lock_bh() */
9464 void bnx2x_set_rx_mode(struct net_device *dev)
9466 struct bnx2x *bp = netdev_priv(dev);
9467 u32 rx_mode = BNX2X_RX_MODE_NORMAL;
9469 if (bp->state != BNX2X_STATE_OPEN) {
9470 DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
9474 DP(NETIF_MSG_IFUP, "dev->flags = %x\n", bp->dev->flags);
9476 if (dev->flags & IFF_PROMISC)
9477 rx_mode = BNX2X_RX_MODE_PROMISC;
9478 else if ((dev->flags & IFF_ALLMULTI) ||
9479 ((netdev_mc_count(dev) > BNX2X_MAX_MULTICAST) &&
9481 rx_mode = BNX2X_RX_MODE_ALLMULTI;
9483 /* some multicasts */
9484 if (bnx2x_set_mc_list(bp) < 0)
9485 rx_mode = BNX2X_RX_MODE_ALLMULTI;
9487 if (bnx2x_set_uc_list(bp) < 0)
9488 rx_mode = BNX2X_RX_MODE_PROMISC;
9491 bp->rx_mode = rx_mode;
9493 /* Schedule the rx_mode command */
9494 if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state)) {
9495 set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
9499 bnx2x_set_storm_rx_mode(bp);
9502 /* called with rtnl_lock */
9503 static int bnx2x_mdio_read(struct net_device *netdev, int prtad,
9504 int devad, u16 addr)
9506 struct bnx2x *bp = netdev_priv(netdev);
9510 DP(NETIF_MSG_LINK, "mdio_read: prtad 0x%x, devad 0x%x, addr 0x%x\n",
9511 prtad, devad, addr);
9513 /* The HW expects different devad if CL22 is used */
9514 devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
9516 bnx2x_acquire_phy_lock(bp);
9517 rc = bnx2x_phy_read(&bp->link_params, prtad, devad, addr, &value);
9518 bnx2x_release_phy_lock(bp);
9519 DP(NETIF_MSG_LINK, "mdio_read_val 0x%x rc = 0x%x\n", value, rc);
9526 /* called with rtnl_lock */
9527 static int bnx2x_mdio_write(struct net_device *netdev, int prtad, int devad,
9528 u16 addr, u16 value)
9530 struct bnx2x *bp = netdev_priv(netdev);
9533 DP(NETIF_MSG_LINK, "mdio_write: prtad 0x%x, devad 0x%x, addr 0x%x,"
9534 " value 0x%x\n", prtad, devad, addr, value);
9536 /* The HW expects different devad if CL22 is used */
9537 devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
9539 bnx2x_acquire_phy_lock(bp);
9540 rc = bnx2x_phy_write(&bp->link_params, prtad, devad, addr, value);
9541 bnx2x_release_phy_lock(bp);
9545 /* called with rtnl_lock */
9546 static int bnx2x_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
9548 struct bnx2x *bp = netdev_priv(dev);
9549 struct mii_ioctl_data *mdio = if_mii(ifr);
9551 DP(NETIF_MSG_LINK, "ioctl: phy id 0x%x, reg 0x%x, val_in 0x%x\n",
9552 mdio->phy_id, mdio->reg_num, mdio->val_in);
9554 if (!netif_running(dev))
9557 return mdio_mii_ioctl(&bp->mdio, mdio, cmd);
9560 #ifdef CONFIG_NET_POLL_CONTROLLER
9561 static void poll_bnx2x(struct net_device *dev)
9563 struct bnx2x *bp = netdev_priv(dev);
9565 disable_irq(bp->pdev->irq);
9566 bnx2x_interrupt(bp->pdev->irq, dev);
9567 enable_irq(bp->pdev->irq);
9571 static const struct net_device_ops bnx2x_netdev_ops = {
9572 .ndo_open = bnx2x_open,
9573 .ndo_stop = bnx2x_close,
9574 .ndo_start_xmit = bnx2x_start_xmit,
9575 .ndo_select_queue = bnx2x_select_queue,
9576 .ndo_set_rx_mode = bnx2x_set_rx_mode,
9577 .ndo_set_mac_address = bnx2x_change_mac_addr,
9578 .ndo_validate_addr = eth_validate_addr,
9579 .ndo_do_ioctl = bnx2x_ioctl,
9580 .ndo_change_mtu = bnx2x_change_mtu,
9581 .ndo_fix_features = bnx2x_fix_features,
9582 .ndo_set_features = bnx2x_set_features,
9583 .ndo_tx_timeout = bnx2x_tx_timeout,
9584 #ifdef CONFIG_NET_POLL_CONTROLLER
9585 .ndo_poll_controller = poll_bnx2x,
9589 static inline int bnx2x_set_coherency_mask(struct bnx2x *bp)
9591 struct device *dev = &bp->pdev->dev;
9593 if (dma_set_mask(dev, DMA_BIT_MASK(64)) == 0) {
9594 bp->flags |= USING_DAC_FLAG;
9595 if (dma_set_coherent_mask(dev, DMA_BIT_MASK(64)) != 0) {
9596 dev_err(dev, "dma_set_coherent_mask failed, "
9600 } else if (dma_set_mask(dev, DMA_BIT_MASK(32)) != 0) {
9601 dev_err(dev, "System does not support DMA, aborting\n");
9608 static int __devinit bnx2x_init_dev(struct pci_dev *pdev,
9609 struct net_device *dev,
9610 unsigned long board_type)
9615 SET_NETDEV_DEV(dev, &pdev->dev);
9616 bp = netdev_priv(dev);
9621 bp->pf_num = PCI_FUNC(pdev->devfn);
9623 rc = pci_enable_device(pdev);
9625 dev_err(&bp->pdev->dev,
9626 "Cannot enable PCI device, aborting\n");
9630 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
9631 dev_err(&bp->pdev->dev,
9632 "Cannot find PCI device base address, aborting\n");
9634 goto err_out_disable;
9637 if (!(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
9638 dev_err(&bp->pdev->dev, "Cannot find second PCI device"
9639 " base address, aborting\n");
9641 goto err_out_disable;
9644 if (atomic_read(&pdev->enable_cnt) == 1) {
9645 rc = pci_request_regions(pdev, DRV_MODULE_NAME);
9647 dev_err(&bp->pdev->dev,
9648 "Cannot obtain PCI resources, aborting\n");
9649 goto err_out_disable;
9652 pci_set_master(pdev);
9653 pci_save_state(pdev);
9656 bp->pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
9657 if (bp->pm_cap == 0) {
9658 dev_err(&bp->pdev->dev,
9659 "Cannot find power management capability, aborting\n");
9661 goto err_out_release;
9664 bp->pcie_cap = pci_find_capability(pdev, PCI_CAP_ID_EXP);
9665 if (bp->pcie_cap == 0) {
9666 dev_err(&bp->pdev->dev,
9667 "Cannot find PCI Express capability, aborting\n");
9669 goto err_out_release;
9672 rc = bnx2x_set_coherency_mask(bp);
9674 goto err_out_release;
9676 dev->mem_start = pci_resource_start(pdev, 0);
9677 dev->base_addr = dev->mem_start;
9678 dev->mem_end = pci_resource_end(pdev, 0);
9680 dev->irq = pdev->irq;
9682 bp->regview = pci_ioremap_bar(pdev, 0);
9684 dev_err(&bp->pdev->dev,
9685 "Cannot map register space, aborting\n");
9687 goto err_out_release;
9690 bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2),
9691 min_t(u64, BNX2X_DB_SIZE(bp),
9692 pci_resource_len(pdev, 2)));
9693 if (!bp->doorbells) {
9694 dev_err(&bp->pdev->dev,
9695 "Cannot map doorbell space, aborting\n");
9700 bnx2x_set_power_state(bp, PCI_D0);
9702 /* clean indirect addresses */
9703 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
9704 PCICFG_VENDOR_ID_OFFSET);
9705 REG_WR(bp, PXP2_REG_PGL_ADDR_88_F0 + BP_PORT(bp)*16, 0);
9706 REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F0 + BP_PORT(bp)*16, 0);
9707 REG_WR(bp, PXP2_REG_PGL_ADDR_90_F0 + BP_PORT(bp)*16, 0);
9708 REG_WR(bp, PXP2_REG_PGL_ADDR_94_F0 + BP_PORT(bp)*16, 0);
9711 * Enable internal target-read (in case we are probed after PF FLR).
9712 * Must be done prior to any BAR read access
9714 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
9716 /* Reset the load counter */
9717 bnx2x_clear_load_cnt(bp);
9719 dev->watchdog_timeo = TX_TIMEOUT;
9721 dev->netdev_ops = &bnx2x_netdev_ops;
9722 bnx2x_set_ethtool_ops(dev);
9724 dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
9725 NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
9726 NETIF_F_RXCSUM | NETIF_F_LRO | NETIF_F_HW_VLAN_TX;
9728 dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
9729 NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 | NETIF_F_HIGHDMA;
9731 dev->features |= dev->hw_features | NETIF_F_HW_VLAN_RX;
9732 if (bp->flags & USING_DAC_FLAG)
9733 dev->features |= NETIF_F_HIGHDMA;
9735 /* Add Loopback capability to the device */
9736 dev->hw_features |= NETIF_F_LOOPBACK;
9739 dev->dcbnl_ops = &bnx2x_dcbnl_ops;
9742 /* get_port_hwinfo() will set prtad and mmds properly */
9743 bp->mdio.prtad = MDIO_PRTAD_NONE;
9745 bp->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
9747 bp->mdio.mdio_read = bnx2x_mdio_read;
9748 bp->mdio.mdio_write = bnx2x_mdio_write;
9754 iounmap(bp->regview);
9757 if (bp->doorbells) {
9758 iounmap(bp->doorbells);
9759 bp->doorbells = NULL;
9763 if (atomic_read(&pdev->enable_cnt) == 1)
9764 pci_release_regions(pdev);
9767 pci_disable_device(pdev);
9768 pci_set_drvdata(pdev, NULL);
9774 static void __devinit bnx2x_get_pcie_width_speed(struct bnx2x *bp,
9775 int *width, int *speed)
9777 u32 val = REG_RD(bp, PCICFG_OFFSET + PCICFG_LINK_CONTROL);
9779 *width = (val & PCICFG_LINK_WIDTH) >> PCICFG_LINK_WIDTH_SHIFT;
9781 /* return value of 1=2.5GHz 2=5GHz */
9782 *speed = (val & PCICFG_LINK_SPEED) >> PCICFG_LINK_SPEED_SHIFT;
9785 static int bnx2x_check_firmware(struct bnx2x *bp)
9787 const struct firmware *firmware = bp->firmware;
9788 struct bnx2x_fw_file_hdr *fw_hdr;
9789 struct bnx2x_fw_file_section *sections;
9790 u32 offset, len, num_ops;
9795 if (firmware->size < sizeof(struct bnx2x_fw_file_hdr))
9798 fw_hdr = (struct bnx2x_fw_file_hdr *)firmware->data;
9799 sections = (struct bnx2x_fw_file_section *)fw_hdr;
9801 /* Make sure none of the offsets and sizes make us read beyond
9802 * the end of the firmware data */
9803 for (i = 0; i < sizeof(*fw_hdr) / sizeof(*sections); i++) {
9804 offset = be32_to_cpu(sections[i].offset);
9805 len = be32_to_cpu(sections[i].len);
9806 if (offset + len > firmware->size) {
9807 dev_err(&bp->pdev->dev,
9808 "Section %d length is out of bounds\n", i);
9813 /* Likewise for the init_ops offsets */
9814 offset = be32_to_cpu(fw_hdr->init_ops_offsets.offset);
9815 ops_offsets = (u16 *)(firmware->data + offset);
9816 num_ops = be32_to_cpu(fw_hdr->init_ops.len) / sizeof(struct raw_op);
9818 for (i = 0; i < be32_to_cpu(fw_hdr->init_ops_offsets.len) / 2; i++) {
9819 if (be16_to_cpu(ops_offsets[i]) > num_ops) {
9820 dev_err(&bp->pdev->dev,
9821 "Section offset %d is out of bounds\n", i);
9826 /* Check FW version */
9827 offset = be32_to_cpu(fw_hdr->fw_version.offset);
9828 fw_ver = firmware->data + offset;
9829 if ((fw_ver[0] != BCM_5710_FW_MAJOR_VERSION) ||
9830 (fw_ver[1] != BCM_5710_FW_MINOR_VERSION) ||
9831 (fw_ver[2] != BCM_5710_FW_REVISION_VERSION) ||
9832 (fw_ver[3] != BCM_5710_FW_ENGINEERING_VERSION)) {
9833 dev_err(&bp->pdev->dev,
9834 "Bad FW version:%d.%d.%d.%d. Should be %d.%d.%d.%d\n",
9835 fw_ver[0], fw_ver[1], fw_ver[2],
9836 fw_ver[3], BCM_5710_FW_MAJOR_VERSION,
9837 BCM_5710_FW_MINOR_VERSION,
9838 BCM_5710_FW_REVISION_VERSION,
9839 BCM_5710_FW_ENGINEERING_VERSION);
9846 static inline void be32_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
9848 const __be32 *source = (const __be32 *)_source;
9849 u32 *target = (u32 *)_target;
9852 for (i = 0; i < n/4; i++)
9853 target[i] = be32_to_cpu(source[i]);
9857 Ops array is stored in the following format:
9858 {op(8bit), offset(24bit, big endian), data(32bit, big endian)}
9860 static inline void bnx2x_prep_ops(const u8 *_source, u8 *_target, u32 n)
9862 const __be32 *source = (const __be32 *)_source;
9863 struct raw_op *target = (struct raw_op *)_target;
9866 for (i = 0, j = 0; i < n/8; i++, j += 2) {
9867 tmp = be32_to_cpu(source[j]);
9868 target[i].op = (tmp >> 24) & 0xff;
9869 target[i].offset = tmp & 0xffffff;
9870 target[i].raw_data = be32_to_cpu(source[j + 1]);
9875 * IRO array is stored in the following format:
9876 * {base(24bit), m1(16bit), m2(16bit), m3(16bit), size(16bit) }
9878 static inline void bnx2x_prep_iro(const u8 *_source, u8 *_target, u32 n)
9880 const __be32 *source = (const __be32 *)_source;
9881 struct iro *target = (struct iro *)_target;
9884 for (i = 0, j = 0; i < n/sizeof(struct iro); i++) {
9885 target[i].base = be32_to_cpu(source[j]);
9887 tmp = be32_to_cpu(source[j]);
9888 target[i].m1 = (tmp >> 16) & 0xffff;
9889 target[i].m2 = tmp & 0xffff;
9891 tmp = be32_to_cpu(source[j]);
9892 target[i].m3 = (tmp >> 16) & 0xffff;
9893 target[i].size = tmp & 0xffff;
9898 static inline void be16_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
9900 const __be16 *source = (const __be16 *)_source;
9901 u16 *target = (u16 *)_target;
9904 for (i = 0; i < n/2; i++)
9905 target[i] = be16_to_cpu(source[i]);
9908 #define BNX2X_ALLOC_AND_SET(arr, lbl, func) \
9910 u32 len = be32_to_cpu(fw_hdr->arr.len); \
9911 bp->arr = kmalloc(len, GFP_KERNEL); \
9913 pr_err("Failed to allocate %d bytes for "#arr"\n", len); \
9916 func(bp->firmware->data + be32_to_cpu(fw_hdr->arr.offset), \
9917 (u8 *)bp->arr, len); \
9920 int bnx2x_init_firmware(struct bnx2x *bp)
9922 const char *fw_file_name;
9923 struct bnx2x_fw_file_hdr *fw_hdr;
9927 fw_file_name = FW_FILE_NAME_E1;
9928 else if (CHIP_IS_E1H(bp))
9929 fw_file_name = FW_FILE_NAME_E1H;
9930 else if (!CHIP_IS_E1x(bp))
9931 fw_file_name = FW_FILE_NAME_E2;
9933 BNX2X_ERR("Unsupported chip revision\n");
9937 BNX2X_DEV_INFO("Loading %s\n", fw_file_name);
9939 rc = request_firmware(&bp->firmware, fw_file_name, &bp->pdev->dev);
9941 BNX2X_ERR("Can't load firmware file %s\n", fw_file_name);
9942 goto request_firmware_exit;
9945 rc = bnx2x_check_firmware(bp);
9947 BNX2X_ERR("Corrupt firmware file %s\n", fw_file_name);
9948 goto request_firmware_exit;
9951 fw_hdr = (struct bnx2x_fw_file_hdr *)bp->firmware->data;
9953 /* Initialize the pointers to the init arrays */
9955 BNX2X_ALLOC_AND_SET(init_data, request_firmware_exit, be32_to_cpu_n);
9958 BNX2X_ALLOC_AND_SET(init_ops, init_ops_alloc_err, bnx2x_prep_ops);
9961 BNX2X_ALLOC_AND_SET(init_ops_offsets, init_offsets_alloc_err,
9964 /* STORMs firmware */
9965 INIT_TSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
9966 be32_to_cpu(fw_hdr->tsem_int_table_data.offset);
9967 INIT_TSEM_PRAM_DATA(bp) = bp->firmware->data +
9968 be32_to_cpu(fw_hdr->tsem_pram_data.offset);
9969 INIT_USEM_INT_TABLE_DATA(bp) = bp->firmware->data +
9970 be32_to_cpu(fw_hdr->usem_int_table_data.offset);
9971 INIT_USEM_PRAM_DATA(bp) = bp->firmware->data +
9972 be32_to_cpu(fw_hdr->usem_pram_data.offset);
9973 INIT_XSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
9974 be32_to_cpu(fw_hdr->xsem_int_table_data.offset);
9975 INIT_XSEM_PRAM_DATA(bp) = bp->firmware->data +
9976 be32_to_cpu(fw_hdr->xsem_pram_data.offset);
9977 INIT_CSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
9978 be32_to_cpu(fw_hdr->csem_int_table_data.offset);
9979 INIT_CSEM_PRAM_DATA(bp) = bp->firmware->data +
9980 be32_to_cpu(fw_hdr->csem_pram_data.offset);
9982 BNX2X_ALLOC_AND_SET(iro_arr, iro_alloc_err, bnx2x_prep_iro);
9987 kfree(bp->init_ops_offsets);
9988 init_offsets_alloc_err:
9989 kfree(bp->init_ops);
9991 kfree(bp->init_data);
9992 request_firmware_exit:
9993 release_firmware(bp->firmware);
9998 static void bnx2x_release_firmware(struct bnx2x *bp)
10000 kfree(bp->init_ops_offsets);
10001 kfree(bp->init_ops);
10002 kfree(bp->init_data);
10003 release_firmware(bp->firmware);
10007 static struct bnx2x_func_sp_drv_ops bnx2x_func_sp_drv = {
10008 .init_hw_cmn_chip = bnx2x_init_hw_common_chip,
10009 .init_hw_cmn = bnx2x_init_hw_common,
10010 .init_hw_port = bnx2x_init_hw_port,
10011 .init_hw_func = bnx2x_init_hw_func,
10013 .reset_hw_cmn = bnx2x_reset_common,
10014 .reset_hw_port = bnx2x_reset_port,
10015 .reset_hw_func = bnx2x_reset_func,
10017 .gunzip_init = bnx2x_gunzip_init,
10018 .gunzip_end = bnx2x_gunzip_end,
10020 .init_fw = bnx2x_init_firmware,
10021 .release_fw = bnx2x_release_firmware,
10024 void bnx2x__init_func_obj(struct bnx2x *bp)
10026 /* Prepare DMAE related driver resources */
10027 bnx2x_setup_dmae(bp);
10029 bnx2x_init_func_obj(bp, &bp->func_obj,
10030 bnx2x_sp(bp, func_rdata),
10031 bnx2x_sp_mapping(bp, func_rdata),
10032 &bnx2x_func_sp_drv);
10035 /* must be called after sriov-enable */
10036 static inline int bnx2x_set_qm_cid_count(struct bnx2x *bp, int l2_cid_count)
10038 int cid_count = L2_FP_COUNT(l2_cid_count);
10041 cid_count += CNIC_CID_MAX;
10043 return roundup(cid_count, QM_CID_ROUND);
10047 * bnx2x_pci_msix_table_size - get the size of the MSI-X table.
10052 static inline int bnx2x_pci_msix_table_size(struct pci_dev *pdev)
10057 pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
10061 pci_read_config_word(pdev, pos + PCI_MSI_FLAGS, &control);
10062 return (control & PCI_MSIX_FLAGS_QSIZE) + 1;
10065 static int __devinit bnx2x_init_one(struct pci_dev *pdev,
10066 const struct pci_device_id *ent)
10068 struct net_device *dev = NULL;
10070 int pcie_width, pcie_speed;
10073 switch (ent->driver_data) {
10085 /* The size requested for the MSI-X table corresponds to the
10086 * actual amount of avaliable IGU/HC status blocks. It includes
10087 * the default SB vector but we want cid_count to contain the
10088 * amount of only non-default SBs, that's what '-1' stands for.
10090 cid_count = bnx2x_pci_msix_table_size(pdev) - 1;
10092 /* do not allow initial cid_count grow above 16
10093 * since Special CIDs starts from this number
10094 * use old FP_SB_MAX_E1x define for this matter
10096 cid_count = min_t(int, FP_SB_MAX_E1x, cid_count);
10098 WARN_ON(!cid_count);
10102 pr_err("Unknown board_type (%ld), aborting\n",
10107 cid_count += FCOE_CONTEXT_USE;
10109 /* dev zeroed in init_etherdev */
10110 dev = alloc_etherdev_mq(sizeof(*bp), cid_count);
10112 dev_err(&pdev->dev, "Cannot allocate net device\n");
10116 /* We don't need a Tx queue for a CNIC and an OOO Rx-only ring,
10117 * so update a cid_count after a netdev allocation.
10119 cid_count += CNIC_CONTEXT_USE;
10121 bp = netdev_priv(dev);
10122 bp->msg_enable = debug;
10124 pci_set_drvdata(pdev, dev);
10126 bp->l2_cid_count = cid_count;
10128 rc = bnx2x_init_dev(pdev, dev, ent->driver_data);
10134 BNX2X_DEV_INFO("cid_count=%d\n", cid_count);
10136 rc = bnx2x_init_bp(bp);
10138 goto init_one_exit;
10140 /* calc qm_cid_count */
10141 bp->qm_cid_count = bnx2x_set_qm_cid_count(bp, cid_count);
10144 /* disable FCOE L2 queue for E1x*/
10145 if (CHIP_IS_E1x(bp))
10146 bp->flags |= NO_FCOE_FLAG;
10150 /* Configure interrupt mode: try to enable MSI-X/MSI if
10151 * needed, set bp->num_queues appropriately.
10153 bnx2x_set_int_mode(bp);
10155 /* Add all NAPI objects */
10156 bnx2x_add_all_napi(bp);
10158 rc = register_netdev(dev);
10160 dev_err(&pdev->dev, "Cannot register net device\n");
10161 goto init_one_exit;
10165 if (!NO_FCOE(bp)) {
10166 /* Add storage MAC address */
10168 dev_addr_add(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
10173 bnx2x_get_pcie_width_speed(bp, &pcie_width, &pcie_speed);
10175 netdev_info(dev, "%s (%c%d) PCI-E x%d %s found at mem %lx,"
10176 " IRQ %d, ", board_info[ent->driver_data].name,
10177 (CHIP_REV(bp) >> 12) + 'A', (CHIP_METAL(bp) >> 4),
10179 ((!CHIP_IS_E2(bp) && pcie_speed == 2) ||
10180 (CHIP_IS_E2(bp) && pcie_speed == 1)) ?
10181 "5GHz (Gen2)" : "2.5GHz",
10182 dev->base_addr, bp->pdev->irq);
10183 pr_cont("node addr %pM\n", dev->dev_addr);
10189 iounmap(bp->regview);
10192 iounmap(bp->doorbells);
10196 if (atomic_read(&pdev->enable_cnt) == 1)
10197 pci_release_regions(pdev);
10199 pci_disable_device(pdev);
10200 pci_set_drvdata(pdev, NULL);
10205 static void __devexit bnx2x_remove_one(struct pci_dev *pdev)
10207 struct net_device *dev = pci_get_drvdata(pdev);
10211 dev_err(&pdev->dev, "BAD net device from bnx2x_init_one\n");
10214 bp = netdev_priv(dev);
10217 /* Delete storage MAC address */
10218 if (!NO_FCOE(bp)) {
10220 dev_addr_del(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
10226 /* Delete app tlvs from dcbnl */
10227 bnx2x_dcbnl_update_applist(bp, true);
10230 unregister_netdev(dev);
10232 /* Delete all NAPI objects */
10233 bnx2x_del_all_napi(bp);
10235 /* Power on: we can't let PCI layer write to us while we are in D3 */
10236 bnx2x_set_power_state(bp, PCI_D0);
10238 /* Disable MSI/MSI-X */
10239 bnx2x_disable_msi(bp);
10242 bnx2x_set_power_state(bp, PCI_D3hot);
10244 /* Make sure RESET task is not scheduled before continuing */
10245 cancel_delayed_work_sync(&bp->reset_task);
10248 iounmap(bp->regview);
10251 iounmap(bp->doorbells);
10253 bnx2x_free_mem_bp(bp);
10257 if (atomic_read(&pdev->enable_cnt) == 1)
10258 pci_release_regions(pdev);
10260 pci_disable_device(pdev);
10261 pci_set_drvdata(pdev, NULL);
10264 static int bnx2x_eeh_nic_unload(struct bnx2x *bp)
10268 bp->state = BNX2X_STATE_ERROR;
10270 bp->rx_mode = BNX2X_RX_MODE_NONE;
10273 bnx2x_cnic_notify(bp, CNIC_CTL_STOP_CMD);
10276 bnx2x_tx_disable(bp);
10278 bnx2x_netif_stop(bp, 0);
10280 del_timer_sync(&bp->timer);
10282 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
10285 bnx2x_free_irq(bp);
10287 /* Free SKBs, SGEs, TPA pool and driver internals */
10288 bnx2x_free_skbs(bp);
10290 for_each_rx_queue(bp, i)
10291 bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
10293 bnx2x_free_mem(bp);
10295 bp->state = BNX2X_STATE_CLOSED;
10297 netif_carrier_off(bp->dev);
10302 static void bnx2x_eeh_recover(struct bnx2x *bp)
10306 mutex_init(&bp->port.phy_mutex);
10308 bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
10309 bp->link_params.shmem_base = bp->common.shmem_base;
10310 BNX2X_DEV_INFO("shmem offset is 0x%x\n", bp->common.shmem_base);
10312 if (!bp->common.shmem_base ||
10313 (bp->common.shmem_base < 0xA0000) ||
10314 (bp->common.shmem_base >= 0xC0000)) {
10315 BNX2X_DEV_INFO("MCP not active\n");
10316 bp->flags |= NO_MCP_FLAG;
10320 val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
10321 if ((val & (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
10322 != (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
10323 BNX2X_ERR("BAD MCP validity signature\n");
10325 if (!BP_NOMCP(bp)) {
10327 (SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
10328 DRV_MSG_SEQ_NUMBER_MASK);
10329 BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
10334 * bnx2x_io_error_detected - called when PCI error is detected
10335 * @pdev: Pointer to PCI device
10336 * @state: The current pci connection state
10338 * This function is called after a PCI bus error affecting
10339 * this device has been detected.
10341 static pci_ers_result_t bnx2x_io_error_detected(struct pci_dev *pdev,
10342 pci_channel_state_t state)
10344 struct net_device *dev = pci_get_drvdata(pdev);
10345 struct bnx2x *bp = netdev_priv(dev);
10349 netif_device_detach(dev);
10351 if (state == pci_channel_io_perm_failure) {
10353 return PCI_ERS_RESULT_DISCONNECT;
10356 if (netif_running(dev))
10357 bnx2x_eeh_nic_unload(bp);
10359 pci_disable_device(pdev);
10363 /* Request a slot reset */
10364 return PCI_ERS_RESULT_NEED_RESET;
10368 * bnx2x_io_slot_reset - called after the PCI bus has been reset
10369 * @pdev: Pointer to PCI device
10371 * Restart the card from scratch, as if from a cold-boot.
10373 static pci_ers_result_t bnx2x_io_slot_reset(struct pci_dev *pdev)
10375 struct net_device *dev = pci_get_drvdata(pdev);
10376 struct bnx2x *bp = netdev_priv(dev);
10380 if (pci_enable_device(pdev)) {
10381 dev_err(&pdev->dev,
10382 "Cannot re-enable PCI device after reset\n");
10384 return PCI_ERS_RESULT_DISCONNECT;
10387 pci_set_master(pdev);
10388 pci_restore_state(pdev);
10390 if (netif_running(dev))
10391 bnx2x_set_power_state(bp, PCI_D0);
10395 return PCI_ERS_RESULT_RECOVERED;
10399 * bnx2x_io_resume - called when traffic can start flowing again
10400 * @pdev: Pointer to PCI device
10402 * This callback is called when the error recovery driver tells us that
10403 * its OK to resume normal operation.
10405 static void bnx2x_io_resume(struct pci_dev *pdev)
10407 struct net_device *dev = pci_get_drvdata(pdev);
10408 struct bnx2x *bp = netdev_priv(dev);
10410 if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
10411 netdev_err(bp->dev, "Handling parity error recovery. "
10412 "Try again later\n");
10418 bnx2x_eeh_recover(bp);
10420 if (netif_running(dev))
10421 bnx2x_nic_load(bp, LOAD_NORMAL);
10423 netif_device_attach(dev);
10428 static struct pci_error_handlers bnx2x_err_handler = {
10429 .error_detected = bnx2x_io_error_detected,
10430 .slot_reset = bnx2x_io_slot_reset,
10431 .resume = bnx2x_io_resume,
10434 static struct pci_driver bnx2x_pci_driver = {
10435 .name = DRV_MODULE_NAME,
10436 .id_table = bnx2x_pci_tbl,
10437 .probe = bnx2x_init_one,
10438 .remove = __devexit_p(bnx2x_remove_one),
10439 .suspend = bnx2x_suspend,
10440 .resume = bnx2x_resume,
10441 .err_handler = &bnx2x_err_handler,
10444 static int __init bnx2x_init(void)
10448 pr_info("%s", version);
10450 bnx2x_wq = create_singlethread_workqueue("bnx2x");
10451 if (bnx2x_wq == NULL) {
10452 pr_err("Cannot create workqueue\n");
10456 ret = pci_register_driver(&bnx2x_pci_driver);
10458 pr_err("Cannot register driver\n");
10459 destroy_workqueue(bnx2x_wq);
10464 static void __exit bnx2x_cleanup(void)
10466 pci_unregister_driver(&bnx2x_pci_driver);
10468 destroy_workqueue(bnx2x_wq);
10471 module_init(bnx2x_init);
10472 module_exit(bnx2x_cleanup);
10476 * bnx2x_set_iscsi_eth_mac_addr - set iSCSI MAC(s).
10478 * @bp: driver handle
10479 * @set: set or clear the CAM entry
10481 * This function will wait until the ramdord completion returns.
10482 * Return 0 if success, -ENODEV if ramrod doesn't return.
10484 static inline int bnx2x_set_iscsi_eth_mac_addr(struct bnx2x *bp)
10486 unsigned long ramrod_flags = 0;
10488 __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
10489 return bnx2x_set_mac_one(bp, bp->cnic_eth_dev.iscsi_mac,
10490 &bp->iscsi_l2_mac_obj, true,
10491 BNX2X_ISCSI_ETH_MAC, &ramrod_flags);
10494 /* count denotes the number of new completions we have seen */
10495 static void bnx2x_cnic_sp_post(struct bnx2x *bp, int count)
10497 struct eth_spe *spe;
10499 #ifdef BNX2X_STOP_ON_ERROR
10500 if (unlikely(bp->panic))
10504 spin_lock_bh(&bp->spq_lock);
10505 BUG_ON(bp->cnic_spq_pending < count);
10506 bp->cnic_spq_pending -= count;
10509 for (; bp->cnic_kwq_pending; bp->cnic_kwq_pending--) {
10510 u16 type = (le16_to_cpu(bp->cnic_kwq_cons->hdr.type)
10511 & SPE_HDR_CONN_TYPE) >>
10512 SPE_HDR_CONN_TYPE_SHIFT;
10513 u8 cmd = (le32_to_cpu(bp->cnic_kwq_cons->hdr.conn_and_cmd_data)
10514 >> SPE_HDR_CMD_ID_SHIFT) & 0xff;
10516 /* Set validation for iSCSI L2 client before sending SETUP
10519 if (type == ETH_CONNECTION_TYPE) {
10520 if (cmd == RAMROD_CMD_ID_ETH_CLIENT_SETUP)
10521 bnx2x_set_ctx_validation(bp, &bp->context.
10522 vcxt[BNX2X_ISCSI_ETH_CID].eth,
10523 BNX2X_ISCSI_ETH_CID);
10527 * There may be not more than 8 L2, not more than 8 L5 SPEs
10528 * and in the air. We also check that number of outstanding
10529 * COMMON ramrods is not more than the EQ and SPQ can
10532 if (type == ETH_CONNECTION_TYPE) {
10533 if (!atomic_read(&bp->cq_spq_left))
10536 atomic_dec(&bp->cq_spq_left);
10537 } else if (type == NONE_CONNECTION_TYPE) {
10538 if (!atomic_read(&bp->eq_spq_left))
10541 atomic_dec(&bp->eq_spq_left);
10542 } else if ((type == ISCSI_CONNECTION_TYPE) ||
10543 (type == FCOE_CONNECTION_TYPE)) {
10544 if (bp->cnic_spq_pending >=
10545 bp->cnic_eth_dev.max_kwqe_pending)
10548 bp->cnic_spq_pending++;
10550 BNX2X_ERR("Unknown SPE type: %d\n", type);
10555 spe = bnx2x_sp_get_next(bp);
10556 *spe = *bp->cnic_kwq_cons;
10558 DP(NETIF_MSG_TIMER, "pending on SPQ %d, on KWQ %d count %d\n",
10559 bp->cnic_spq_pending, bp->cnic_kwq_pending, count);
10561 if (bp->cnic_kwq_cons == bp->cnic_kwq_last)
10562 bp->cnic_kwq_cons = bp->cnic_kwq;
10564 bp->cnic_kwq_cons++;
10566 bnx2x_sp_prod_update(bp);
10567 spin_unlock_bh(&bp->spq_lock);
10570 static int bnx2x_cnic_sp_queue(struct net_device *dev,
10571 struct kwqe_16 *kwqes[], u32 count)
10573 struct bnx2x *bp = netdev_priv(dev);
10576 #ifdef BNX2X_STOP_ON_ERROR
10577 if (unlikely(bp->panic))
10581 spin_lock_bh(&bp->spq_lock);
10583 for (i = 0; i < count; i++) {
10584 struct eth_spe *spe = (struct eth_spe *)kwqes[i];
10586 if (bp->cnic_kwq_pending == MAX_SP_DESC_CNT)
10589 *bp->cnic_kwq_prod = *spe;
10591 bp->cnic_kwq_pending++;
10593 DP(NETIF_MSG_TIMER, "L5 SPQE %x %x %x:%x pos %d\n",
10594 spe->hdr.conn_and_cmd_data, spe->hdr.type,
10595 spe->data.update_data_addr.hi,
10596 spe->data.update_data_addr.lo,
10597 bp->cnic_kwq_pending);
10599 if (bp->cnic_kwq_prod == bp->cnic_kwq_last)
10600 bp->cnic_kwq_prod = bp->cnic_kwq;
10602 bp->cnic_kwq_prod++;
10605 spin_unlock_bh(&bp->spq_lock);
10607 if (bp->cnic_spq_pending < bp->cnic_eth_dev.max_kwqe_pending)
10608 bnx2x_cnic_sp_post(bp, 0);
10613 static int bnx2x_cnic_ctl_send(struct bnx2x *bp, struct cnic_ctl_info *ctl)
10615 struct cnic_ops *c_ops;
10618 mutex_lock(&bp->cnic_mutex);
10619 c_ops = rcu_dereference_protected(bp->cnic_ops,
10620 lockdep_is_held(&bp->cnic_mutex));
10622 rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
10623 mutex_unlock(&bp->cnic_mutex);
10628 static int bnx2x_cnic_ctl_send_bh(struct bnx2x *bp, struct cnic_ctl_info *ctl)
10630 struct cnic_ops *c_ops;
10634 c_ops = rcu_dereference(bp->cnic_ops);
10636 rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
10643 * for commands that have no data
10645 int bnx2x_cnic_notify(struct bnx2x *bp, int cmd)
10647 struct cnic_ctl_info ctl = {0};
10651 return bnx2x_cnic_ctl_send(bp, &ctl);
10654 static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err)
10656 struct cnic_ctl_info ctl = {0};
10658 /* first we tell CNIC and only then we count this as a completion */
10659 ctl.cmd = CNIC_CTL_COMPLETION_CMD;
10660 ctl.data.comp.cid = cid;
10661 ctl.data.comp.error = err;
10663 bnx2x_cnic_ctl_send_bh(bp, &ctl);
10664 bnx2x_cnic_sp_post(bp, 0);
10668 /* Called with netif_addr_lock_bh() taken.
10669 * Sets an rx_mode config for an iSCSI ETH client.
10671 * Completion should be checked outside.
10673 static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start)
10675 unsigned long accept_flags = 0, ramrod_flags = 0;
10676 u8 cl_id = bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
10677 int sched_state = BNX2X_FILTER_ISCSI_ETH_STOP_SCHED;
10680 /* Start accepting on iSCSI L2 ring. Accept all multicasts
10681 * because it's the only way for UIO Queue to accept
10682 * multicasts (in non-promiscuous mode only one Queue per
10683 * function will receive multicast packets (leading in our
10686 __set_bit(BNX2X_ACCEPT_UNICAST, &accept_flags);
10687 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept_flags);
10688 __set_bit(BNX2X_ACCEPT_BROADCAST, &accept_flags);
10689 __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept_flags);
10691 /* Clear STOP_PENDING bit if START is requested */
10692 clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &bp->sp_state);
10694 sched_state = BNX2X_FILTER_ISCSI_ETH_START_SCHED;
10696 /* Clear START_PENDING bit if STOP is requested */
10697 clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &bp->sp_state);
10699 if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
10700 set_bit(sched_state, &bp->sp_state);
10702 __set_bit(RAMROD_RX, &ramrod_flags);
10703 bnx2x_set_q_rx_mode(bp, cl_id, 0, accept_flags, 0,
10709 static int bnx2x_drv_ctl(struct net_device *dev, struct drv_ctl_info *ctl)
10711 struct bnx2x *bp = netdev_priv(dev);
10714 switch (ctl->cmd) {
10715 case DRV_CTL_CTXTBL_WR_CMD: {
10716 u32 index = ctl->data.io.offset;
10717 dma_addr_t addr = ctl->data.io.dma_addr;
10719 bnx2x_ilt_wr(bp, index, addr);
10723 case DRV_CTL_RET_L5_SPQ_CREDIT_CMD: {
10724 int count = ctl->data.credit.credit_count;
10726 bnx2x_cnic_sp_post(bp, count);
10730 /* rtnl_lock is held. */
10731 case DRV_CTL_START_L2_CMD: {
10732 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
10733 unsigned long sp_bits = 0;
10735 /* Configure the iSCSI classification object */
10736 bnx2x_init_mac_obj(bp, &bp->iscsi_l2_mac_obj,
10737 cp->iscsi_l2_client_id,
10738 cp->iscsi_l2_cid, BP_FUNC(bp),
10739 bnx2x_sp(bp, mac_rdata),
10740 bnx2x_sp_mapping(bp, mac_rdata),
10741 BNX2X_FILTER_MAC_PENDING,
10742 &bp->sp_state, BNX2X_OBJ_TYPE_RX,
10745 /* Set iSCSI MAC address */
10746 rc = bnx2x_set_iscsi_eth_mac_addr(bp);
10753 /* Start accepting on iSCSI L2 ring */
10755 netif_addr_lock_bh(dev);
10756 bnx2x_set_iscsi_eth_rx_mode(bp, true);
10757 netif_addr_unlock_bh(dev);
10759 /* bits to wait on */
10760 __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
10761 __set_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &sp_bits);
10763 if (!bnx2x_wait_sp_comp(bp, sp_bits))
10764 BNX2X_ERR("rx_mode completion timed out!\n");
10769 /* rtnl_lock is held. */
10770 case DRV_CTL_STOP_L2_CMD: {
10771 unsigned long sp_bits = 0;
10773 /* Stop accepting on iSCSI L2 ring */
10774 netif_addr_lock_bh(dev);
10775 bnx2x_set_iscsi_eth_rx_mode(bp, false);
10776 netif_addr_unlock_bh(dev);
10778 /* bits to wait on */
10779 __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
10780 __set_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &sp_bits);
10782 if (!bnx2x_wait_sp_comp(bp, sp_bits))
10783 BNX2X_ERR("rx_mode completion timed out!\n");
10788 /* Unset iSCSI L2 MAC */
10789 rc = bnx2x_del_all_macs(bp, &bp->iscsi_l2_mac_obj,
10790 BNX2X_ISCSI_ETH_MAC, true);
10793 case DRV_CTL_RET_L2_SPQ_CREDIT_CMD: {
10794 int count = ctl->data.credit.credit_count;
10796 smp_mb__before_atomic_inc();
10797 atomic_add(count, &bp->cq_spq_left);
10798 smp_mb__after_atomic_inc();
10803 BNX2X_ERR("unknown command %x\n", ctl->cmd);
10810 void bnx2x_setup_cnic_irq_info(struct bnx2x *bp)
10812 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
10814 if (bp->flags & USING_MSIX_FLAG) {
10815 cp->drv_state |= CNIC_DRV_STATE_USING_MSIX;
10816 cp->irq_arr[0].irq_flags |= CNIC_IRQ_FL_MSIX;
10817 cp->irq_arr[0].vector = bp->msix_table[1].vector;
10819 cp->drv_state &= ~CNIC_DRV_STATE_USING_MSIX;
10820 cp->irq_arr[0].irq_flags &= ~CNIC_IRQ_FL_MSIX;
10822 if (!CHIP_IS_E1x(bp))
10823 cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e2_sb;
10825 cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e1x_sb;
10827 cp->irq_arr[0].status_blk_num = bnx2x_cnic_fw_sb_id(bp);
10828 cp->irq_arr[0].status_blk_num2 = bnx2x_cnic_igu_sb_id(bp);
10829 cp->irq_arr[1].status_blk = bp->def_status_blk;
10830 cp->irq_arr[1].status_blk_num = DEF_SB_ID;
10831 cp->irq_arr[1].status_blk_num2 = DEF_SB_IGU_ID;
10836 static int bnx2x_register_cnic(struct net_device *dev, struct cnic_ops *ops,
10839 struct bnx2x *bp = netdev_priv(dev);
10840 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
10845 bp->cnic_kwq = kzalloc(PAGE_SIZE, GFP_KERNEL);
10849 bp->cnic_kwq_cons = bp->cnic_kwq;
10850 bp->cnic_kwq_prod = bp->cnic_kwq;
10851 bp->cnic_kwq_last = bp->cnic_kwq + MAX_SP_DESC_CNT;
10853 bp->cnic_spq_pending = 0;
10854 bp->cnic_kwq_pending = 0;
10856 bp->cnic_data = data;
10859 cp->drv_state |= CNIC_DRV_STATE_REGD;
10860 cp->iro_arr = bp->iro_arr;
10862 bnx2x_setup_cnic_irq_info(bp);
10864 rcu_assign_pointer(bp->cnic_ops, ops);
10869 static int bnx2x_unregister_cnic(struct net_device *dev)
10871 struct bnx2x *bp = netdev_priv(dev);
10872 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
10874 mutex_lock(&bp->cnic_mutex);
10876 rcu_assign_pointer(bp->cnic_ops, NULL);
10877 mutex_unlock(&bp->cnic_mutex);
10879 kfree(bp->cnic_kwq);
10880 bp->cnic_kwq = NULL;
10885 struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev)
10887 struct bnx2x *bp = netdev_priv(dev);
10888 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
10890 /* If both iSCSI and FCoE are disabled - return NULL in
10891 * order to indicate CNIC that it should not try to work
10892 * with this device.
10894 if (NO_ISCSI(bp) && NO_FCOE(bp))
10897 cp->drv_owner = THIS_MODULE;
10898 cp->chip_id = CHIP_ID(bp);
10899 cp->pdev = bp->pdev;
10900 cp->io_base = bp->regview;
10901 cp->io_base2 = bp->doorbells;
10902 cp->max_kwqe_pending = 8;
10903 cp->ctx_blk_size = CDU_ILT_PAGE_SZ;
10904 cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
10905 bnx2x_cid_ilt_lines(bp);
10906 cp->ctx_tbl_len = CNIC_ILT_LINES;
10907 cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
10908 cp->drv_submit_kwqes_16 = bnx2x_cnic_sp_queue;
10909 cp->drv_ctl = bnx2x_drv_ctl;
10910 cp->drv_register_cnic = bnx2x_register_cnic;
10911 cp->drv_unregister_cnic = bnx2x_unregister_cnic;
10912 cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID;
10913 cp->iscsi_l2_client_id =
10914 bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
10915 cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID;
10917 if (NO_ISCSI_OOO(bp))
10918 cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
10921 cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI;
10924 cp->drv_state |= CNIC_DRV_STATE_NO_FCOE;
10926 DP(BNX2X_MSG_SP, "page_size %d, tbl_offset %d, tbl_lines %d, "
10927 "starting cid %d\n",
10929 cp->ctx_tbl_offset,
10934 EXPORT_SYMBOL(bnx2x_cnic_probe);
10936 #endif /* BCM_CNIC */