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>
53 #include <linux/vmalloc.h>
56 #include "bnx2x_init.h"
57 #include "bnx2x_init_ops.h"
58 #include "bnx2x_cmn.h"
59 #include "bnx2x_dcb.h"
62 #include <linux/firmware.h>
63 #include "bnx2x_fw_file_hdr.h"
65 #define FW_FILE_VERSION \
66 __stringify(BCM_5710_FW_MAJOR_VERSION) "." \
67 __stringify(BCM_5710_FW_MINOR_VERSION) "." \
68 __stringify(BCM_5710_FW_REVISION_VERSION) "." \
69 __stringify(BCM_5710_FW_ENGINEERING_VERSION)
70 #define FW_FILE_NAME_E1 "bnx2x/bnx2x-e1-" FW_FILE_VERSION ".fw"
71 #define FW_FILE_NAME_E1H "bnx2x/bnx2x-e1h-" FW_FILE_VERSION ".fw"
72 #define FW_FILE_NAME_E2 "bnx2x/bnx2x-e2-" FW_FILE_VERSION ".fw"
74 /* Time in jiffies before concluding the transmitter is hung */
75 #define TX_TIMEOUT (5*HZ)
77 static char version[] __devinitdata =
78 "Broadcom NetXtreme II 5771x/578xx 10/20-Gigabit Ethernet Driver "
79 DRV_MODULE_NAME " " DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
81 MODULE_AUTHOR("Eliezer Tamir");
82 MODULE_DESCRIPTION("Broadcom NetXtreme II "
83 "BCM57710/57711/57711E/"
84 "57712/57712_MF/57800/57800_MF/57810/57810_MF/"
85 "57840/57840_MF Driver");
86 MODULE_LICENSE("GPL");
87 MODULE_VERSION(DRV_MODULE_VERSION);
88 MODULE_FIRMWARE(FW_FILE_NAME_E1);
89 MODULE_FIRMWARE(FW_FILE_NAME_E1H);
90 MODULE_FIRMWARE(FW_FILE_NAME_E2);
92 static int multi_mode = 1;
93 module_param(multi_mode, int, 0);
94 MODULE_PARM_DESC(multi_mode, " Multi queue mode "
95 "(0 Disable; 1 Enable (default))");
98 module_param(num_queues, int, 0);
99 MODULE_PARM_DESC(num_queues, " Number of queues for multi_mode=1"
100 " (default is as a number of CPUs)");
102 static int disable_tpa;
103 module_param(disable_tpa, int, 0);
104 MODULE_PARM_DESC(disable_tpa, " Disable the TPA (LRO) feature");
106 #define INT_MODE_INTx 1
107 #define INT_MODE_MSI 2
109 module_param(int_mode, int, 0);
110 MODULE_PARM_DESC(int_mode, " Force interrupt mode other than MSI-X "
113 static int dropless_fc;
114 module_param(dropless_fc, int, 0);
115 MODULE_PARM_DESC(dropless_fc, " Pause on exhausted host ring");
118 module_param(poll, int, 0);
119 MODULE_PARM_DESC(poll, " Use polling (for debug)");
121 static int mrrs = -1;
122 module_param(mrrs, int, 0);
123 MODULE_PARM_DESC(mrrs, " Force Max Read Req Size (0..3) (for debug)");
126 module_param(debug, int, 0);
127 MODULE_PARM_DESC(debug, " Default debug msglevel");
131 struct workqueue_struct *bnx2x_wq;
133 enum bnx2x_board_type {
147 /* indexed by board_type, above */
150 } board_info[] __devinitdata = {
151 { "Broadcom NetXtreme II BCM57710 10 Gigabit PCIe [Everest]" },
152 { "Broadcom NetXtreme II BCM57711 10 Gigabit PCIe" },
153 { "Broadcom NetXtreme II BCM57711E 10 Gigabit PCIe" },
154 { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet" },
155 { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Multi Function" },
156 { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet" },
157 { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Multi Function" },
158 { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet" },
159 { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Multi Function" },
160 { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet" },
161 { "Broadcom NetXtreme II BCM57840 10/20 Gigabit "
162 "Ethernet Multi Function"}
165 #ifndef PCI_DEVICE_ID_NX2_57710
166 #define PCI_DEVICE_ID_NX2_57710 CHIP_NUM_57710
168 #ifndef PCI_DEVICE_ID_NX2_57711
169 #define PCI_DEVICE_ID_NX2_57711 CHIP_NUM_57711
171 #ifndef PCI_DEVICE_ID_NX2_57711E
172 #define PCI_DEVICE_ID_NX2_57711E CHIP_NUM_57711E
174 #ifndef PCI_DEVICE_ID_NX2_57712
175 #define PCI_DEVICE_ID_NX2_57712 CHIP_NUM_57712
177 #ifndef PCI_DEVICE_ID_NX2_57712_MF
178 #define PCI_DEVICE_ID_NX2_57712_MF CHIP_NUM_57712_MF
180 #ifndef PCI_DEVICE_ID_NX2_57800
181 #define PCI_DEVICE_ID_NX2_57800 CHIP_NUM_57800
183 #ifndef PCI_DEVICE_ID_NX2_57800_MF
184 #define PCI_DEVICE_ID_NX2_57800_MF CHIP_NUM_57800_MF
186 #ifndef PCI_DEVICE_ID_NX2_57810
187 #define PCI_DEVICE_ID_NX2_57810 CHIP_NUM_57810
189 #ifndef PCI_DEVICE_ID_NX2_57810_MF
190 #define PCI_DEVICE_ID_NX2_57810_MF CHIP_NUM_57810_MF
192 #ifndef PCI_DEVICE_ID_NX2_57840
193 #define PCI_DEVICE_ID_NX2_57840 CHIP_NUM_57840
195 #ifndef PCI_DEVICE_ID_NX2_57840_MF
196 #define PCI_DEVICE_ID_NX2_57840_MF CHIP_NUM_57840_MF
198 static DEFINE_PCI_DEVICE_TABLE(bnx2x_pci_tbl) = {
199 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57710), BCM57710 },
200 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711), BCM57711 },
201 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711E), BCM57711E },
202 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712), BCM57712 },
203 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_MF), BCM57712_MF },
204 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800), BCM57800 },
205 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_MF), BCM57800_MF },
206 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810), BCM57810 },
207 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_MF), BCM57810_MF },
208 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840), BCM57840 },
209 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MF), BCM57840_MF },
213 MODULE_DEVICE_TABLE(pci, bnx2x_pci_tbl);
215 /****************************************************************************
216 * General service functions
217 ****************************************************************************/
219 static inline void __storm_memset_dma_mapping(struct bnx2x *bp,
220 u32 addr, dma_addr_t mapping)
222 REG_WR(bp, addr, U64_LO(mapping));
223 REG_WR(bp, addr + 4, U64_HI(mapping));
226 static inline void storm_memset_spq_addr(struct bnx2x *bp,
227 dma_addr_t mapping, u16 abs_fid)
229 u32 addr = XSEM_REG_FAST_MEMORY +
230 XSTORM_SPQ_PAGE_BASE_OFFSET(abs_fid);
232 __storm_memset_dma_mapping(bp, addr, mapping);
235 static inline void storm_memset_vf_to_pf(struct bnx2x *bp, u16 abs_fid,
238 REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_VF_TO_PF_OFFSET(abs_fid),
240 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_VF_TO_PF_OFFSET(abs_fid),
242 REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_VF_TO_PF_OFFSET(abs_fid),
244 REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_VF_TO_PF_OFFSET(abs_fid),
248 static inline void storm_memset_func_en(struct bnx2x *bp, u16 abs_fid,
251 REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(abs_fid),
253 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(abs_fid),
255 REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(abs_fid),
257 REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(abs_fid),
261 static inline void storm_memset_eq_data(struct bnx2x *bp,
262 struct event_ring_data *eq_data,
265 size_t size = sizeof(struct event_ring_data);
267 u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_DATA_OFFSET(pfid);
269 __storm_memset_struct(bp, addr, size, (u32 *)eq_data);
272 static inline void storm_memset_eq_prod(struct bnx2x *bp, u16 eq_prod,
275 u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_PROD_OFFSET(pfid);
276 REG_WR16(bp, addr, eq_prod);
280 * locking is done by mcp
282 static void bnx2x_reg_wr_ind(struct bnx2x *bp, u32 addr, u32 val)
284 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
285 pci_write_config_dword(bp->pdev, PCICFG_GRC_DATA, val);
286 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
287 PCICFG_VENDOR_ID_OFFSET);
290 static u32 bnx2x_reg_rd_ind(struct bnx2x *bp, u32 addr)
294 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
295 pci_read_config_dword(bp->pdev, PCICFG_GRC_DATA, &val);
296 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
297 PCICFG_VENDOR_ID_OFFSET);
302 #define DMAE_DP_SRC_GRC "grc src_addr [%08x]"
303 #define DMAE_DP_SRC_PCI "pci src_addr [%x:%08x]"
304 #define DMAE_DP_DST_GRC "grc dst_addr [%08x]"
305 #define DMAE_DP_DST_PCI "pci dst_addr [%x:%08x]"
306 #define DMAE_DP_DST_NONE "dst_addr [none]"
308 static void bnx2x_dp_dmae(struct bnx2x *bp, struct dmae_command *dmae,
311 u32 src_type = dmae->opcode & DMAE_COMMAND_SRC;
313 switch (dmae->opcode & DMAE_COMMAND_DST) {
314 case DMAE_CMD_DST_PCI:
315 if (src_type == DMAE_CMD_SRC_PCI)
316 DP(msglvl, "DMAE: opcode 0x%08x\n"
317 "src [%x:%08x], len [%d*4], dst [%x:%08x]\n"
318 "comp_addr [%x:%08x], comp_val 0x%08x\n",
319 dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
320 dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
321 dmae->comp_addr_hi, dmae->comp_addr_lo,
324 DP(msglvl, "DMAE: opcode 0x%08x\n"
325 "src [%08x], len [%d*4], dst [%x:%08x]\n"
326 "comp_addr [%x:%08x], comp_val 0x%08x\n",
327 dmae->opcode, dmae->src_addr_lo >> 2,
328 dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
329 dmae->comp_addr_hi, dmae->comp_addr_lo,
332 case DMAE_CMD_DST_GRC:
333 if (src_type == DMAE_CMD_SRC_PCI)
334 DP(msglvl, "DMAE: opcode 0x%08x\n"
335 "src [%x:%08x], len [%d*4], dst_addr [%08x]\n"
336 "comp_addr [%x:%08x], comp_val 0x%08x\n",
337 dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
338 dmae->len, dmae->dst_addr_lo >> 2,
339 dmae->comp_addr_hi, dmae->comp_addr_lo,
342 DP(msglvl, "DMAE: opcode 0x%08x\n"
343 "src [%08x], len [%d*4], dst [%08x]\n"
344 "comp_addr [%x:%08x], comp_val 0x%08x\n",
345 dmae->opcode, dmae->src_addr_lo >> 2,
346 dmae->len, dmae->dst_addr_lo >> 2,
347 dmae->comp_addr_hi, dmae->comp_addr_lo,
351 if (src_type == DMAE_CMD_SRC_PCI)
352 DP(msglvl, "DMAE: opcode 0x%08x\n"
353 DP_LEVEL "src_addr [%x:%08x] len [%d * 4] "
355 DP_LEVEL "comp_addr [%x:%08x] comp_val 0x%08x\n",
356 dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
357 dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
360 DP(msglvl, "DMAE: opcode 0x%08x\n"
361 DP_LEVEL "src_addr [%08x] len [%d * 4] "
363 DP_LEVEL "comp_addr [%x:%08x] comp_val 0x%08x\n",
364 dmae->opcode, dmae->src_addr_lo >> 2,
365 dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
372 /* copy command into DMAE command memory and set DMAE command go */
373 void bnx2x_post_dmae(struct bnx2x *bp, struct dmae_command *dmae, int idx)
378 cmd_offset = (DMAE_REG_CMD_MEM + sizeof(struct dmae_command) * idx);
379 for (i = 0; i < (sizeof(struct dmae_command)/4); i++) {
380 REG_WR(bp, cmd_offset + i*4, *(((u32 *)dmae) + i));
382 DP(BNX2X_MSG_OFF, "DMAE cmd[%d].%d (0x%08x) : 0x%08x\n",
383 idx, i, cmd_offset + i*4, *(((u32 *)dmae) + i));
385 REG_WR(bp, dmae_reg_go_c[idx], 1);
388 u32 bnx2x_dmae_opcode_add_comp(u32 opcode, u8 comp_type)
390 return opcode | ((comp_type << DMAE_COMMAND_C_DST_SHIFT) |
394 u32 bnx2x_dmae_opcode_clr_src_reset(u32 opcode)
396 return opcode & ~DMAE_CMD_SRC_RESET;
399 u32 bnx2x_dmae_opcode(struct bnx2x *bp, u8 src_type, u8 dst_type,
400 bool with_comp, u8 comp_type)
404 opcode |= ((src_type << DMAE_COMMAND_SRC_SHIFT) |
405 (dst_type << DMAE_COMMAND_DST_SHIFT));
407 opcode |= (DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET);
409 opcode |= (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0);
410 opcode |= ((BP_E1HVN(bp) << DMAE_CMD_E1HVN_SHIFT) |
411 (BP_E1HVN(bp) << DMAE_COMMAND_DST_VN_SHIFT));
412 opcode |= (DMAE_COM_SET_ERR << DMAE_COMMAND_ERR_POLICY_SHIFT);
415 opcode |= DMAE_CMD_ENDIANITY_B_DW_SWAP;
417 opcode |= DMAE_CMD_ENDIANITY_DW_SWAP;
420 opcode = bnx2x_dmae_opcode_add_comp(opcode, comp_type);
424 static void bnx2x_prep_dmae_with_comp(struct bnx2x *bp,
425 struct dmae_command *dmae,
426 u8 src_type, u8 dst_type)
428 memset(dmae, 0, sizeof(struct dmae_command));
431 dmae->opcode = bnx2x_dmae_opcode(bp, src_type, dst_type,
432 true, DMAE_COMP_PCI);
434 /* fill in the completion parameters */
435 dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_comp));
436 dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_comp));
437 dmae->comp_val = DMAE_COMP_VAL;
440 /* issue a dmae command over the init-channel and wailt for completion */
441 static int bnx2x_issue_dmae_with_comp(struct bnx2x *bp,
442 struct dmae_command *dmae)
444 u32 *wb_comp = bnx2x_sp(bp, wb_comp);
445 int cnt = CHIP_REV_IS_SLOW(bp) ? (400000) : 4000;
448 DP(BNX2X_MSG_OFF, "data before [0x%08x 0x%08x 0x%08x 0x%08x]\n",
449 bp->slowpath->wb_data[0], bp->slowpath->wb_data[1],
450 bp->slowpath->wb_data[2], bp->slowpath->wb_data[3]);
453 * Lock the dmae channel. Disable BHs to prevent a dead-lock
454 * as long as this code is called both from syscall context and
455 * from ndo_set_rx_mode() flow that may be called from BH.
457 spin_lock_bh(&bp->dmae_lock);
459 /* reset completion */
462 /* post the command on the channel used for initializations */
463 bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp));
465 /* wait for completion */
467 while ((*wb_comp & ~DMAE_PCI_ERR_FLAG) != DMAE_COMP_VAL) {
468 DP(BNX2X_MSG_OFF, "wb_comp 0x%08x\n", *wb_comp);
471 BNX2X_ERR("DMAE timeout!\n");
478 if (*wb_comp & DMAE_PCI_ERR_FLAG) {
479 BNX2X_ERR("DMAE PCI error!\n");
483 DP(BNX2X_MSG_OFF, "data after [0x%08x 0x%08x 0x%08x 0x%08x]\n",
484 bp->slowpath->wb_data[0], bp->slowpath->wb_data[1],
485 bp->slowpath->wb_data[2], bp->slowpath->wb_data[3]);
488 spin_unlock_bh(&bp->dmae_lock);
492 void bnx2x_write_dmae(struct bnx2x *bp, dma_addr_t dma_addr, u32 dst_addr,
495 struct dmae_command dmae;
497 if (!bp->dmae_ready) {
498 u32 *data = bnx2x_sp(bp, wb_data[0]);
500 DP(BNX2X_MSG_OFF, "DMAE is not ready (dst_addr %08x len32 %d)"
501 " using indirect\n", dst_addr, len32);
502 bnx2x_init_ind_wr(bp, dst_addr, data, len32);
506 /* set opcode and fixed command fields */
507 bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_GRC);
509 /* fill in addresses and len */
510 dmae.src_addr_lo = U64_LO(dma_addr);
511 dmae.src_addr_hi = U64_HI(dma_addr);
512 dmae.dst_addr_lo = dst_addr >> 2;
513 dmae.dst_addr_hi = 0;
516 bnx2x_dp_dmae(bp, &dmae, BNX2X_MSG_OFF);
518 /* issue the command and wait for completion */
519 bnx2x_issue_dmae_with_comp(bp, &dmae);
522 void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32)
524 struct dmae_command dmae;
526 if (!bp->dmae_ready) {
527 u32 *data = bnx2x_sp(bp, wb_data[0]);
530 DP(BNX2X_MSG_OFF, "DMAE is not ready (src_addr %08x len32 %d)"
531 " using indirect\n", src_addr, len32);
532 for (i = 0; i < len32; i++)
533 data[i] = bnx2x_reg_rd_ind(bp, src_addr + i*4);
537 /* set opcode and fixed command fields */
538 bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_GRC, DMAE_DST_PCI);
540 /* fill in addresses and len */
541 dmae.src_addr_lo = src_addr >> 2;
542 dmae.src_addr_hi = 0;
543 dmae.dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_data));
544 dmae.dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_data));
547 bnx2x_dp_dmae(bp, &dmae, BNX2X_MSG_OFF);
549 /* issue the command and wait for completion */
550 bnx2x_issue_dmae_with_comp(bp, &dmae);
553 static void bnx2x_write_dmae_phys_len(struct bnx2x *bp, dma_addr_t phys_addr,
556 int dmae_wr_max = DMAE_LEN32_WR_MAX(bp);
559 while (len > dmae_wr_max) {
560 bnx2x_write_dmae(bp, phys_addr + offset,
561 addr + offset, dmae_wr_max);
562 offset += dmae_wr_max * 4;
566 bnx2x_write_dmae(bp, phys_addr + offset, addr + offset, len);
569 /* used only for slowpath so not inlined */
570 static void bnx2x_wb_wr(struct bnx2x *bp, int reg, u32 val_hi, u32 val_lo)
574 wb_write[0] = val_hi;
575 wb_write[1] = val_lo;
576 REG_WR_DMAE(bp, reg, wb_write, 2);
580 static u64 bnx2x_wb_rd(struct bnx2x *bp, int reg)
584 REG_RD_DMAE(bp, reg, wb_data, 2);
586 return HILO_U64(wb_data[0], wb_data[1]);
590 static int bnx2x_mc_assert(struct bnx2x *bp)
594 u32 row0, row1, row2, row3;
597 last_idx = REG_RD8(bp, BAR_XSTRORM_INTMEM +
598 XSTORM_ASSERT_LIST_INDEX_OFFSET);
600 BNX2X_ERR("XSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
602 /* print the asserts */
603 for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
605 row0 = REG_RD(bp, BAR_XSTRORM_INTMEM +
606 XSTORM_ASSERT_LIST_OFFSET(i));
607 row1 = REG_RD(bp, BAR_XSTRORM_INTMEM +
608 XSTORM_ASSERT_LIST_OFFSET(i) + 4);
609 row2 = REG_RD(bp, BAR_XSTRORM_INTMEM +
610 XSTORM_ASSERT_LIST_OFFSET(i) + 8);
611 row3 = REG_RD(bp, BAR_XSTRORM_INTMEM +
612 XSTORM_ASSERT_LIST_OFFSET(i) + 12);
614 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
615 BNX2X_ERR("XSTORM_ASSERT_INDEX 0x%x = 0x%08x"
616 " 0x%08x 0x%08x 0x%08x\n",
617 i, row3, row2, row1, row0);
625 last_idx = REG_RD8(bp, BAR_TSTRORM_INTMEM +
626 TSTORM_ASSERT_LIST_INDEX_OFFSET);
628 BNX2X_ERR("TSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
630 /* print the asserts */
631 for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
633 row0 = REG_RD(bp, BAR_TSTRORM_INTMEM +
634 TSTORM_ASSERT_LIST_OFFSET(i));
635 row1 = REG_RD(bp, BAR_TSTRORM_INTMEM +
636 TSTORM_ASSERT_LIST_OFFSET(i) + 4);
637 row2 = REG_RD(bp, BAR_TSTRORM_INTMEM +
638 TSTORM_ASSERT_LIST_OFFSET(i) + 8);
639 row3 = REG_RD(bp, BAR_TSTRORM_INTMEM +
640 TSTORM_ASSERT_LIST_OFFSET(i) + 12);
642 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
643 BNX2X_ERR("TSTORM_ASSERT_INDEX 0x%x = 0x%08x"
644 " 0x%08x 0x%08x 0x%08x\n",
645 i, row3, row2, row1, row0);
653 last_idx = REG_RD8(bp, BAR_CSTRORM_INTMEM +
654 CSTORM_ASSERT_LIST_INDEX_OFFSET);
656 BNX2X_ERR("CSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
658 /* print the asserts */
659 for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
661 row0 = REG_RD(bp, BAR_CSTRORM_INTMEM +
662 CSTORM_ASSERT_LIST_OFFSET(i));
663 row1 = REG_RD(bp, BAR_CSTRORM_INTMEM +
664 CSTORM_ASSERT_LIST_OFFSET(i) + 4);
665 row2 = REG_RD(bp, BAR_CSTRORM_INTMEM +
666 CSTORM_ASSERT_LIST_OFFSET(i) + 8);
667 row3 = REG_RD(bp, BAR_CSTRORM_INTMEM +
668 CSTORM_ASSERT_LIST_OFFSET(i) + 12);
670 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
671 BNX2X_ERR("CSTORM_ASSERT_INDEX 0x%x = 0x%08x"
672 " 0x%08x 0x%08x 0x%08x\n",
673 i, row3, row2, row1, row0);
681 last_idx = REG_RD8(bp, BAR_USTRORM_INTMEM +
682 USTORM_ASSERT_LIST_INDEX_OFFSET);
684 BNX2X_ERR("USTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
686 /* print the asserts */
687 for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
689 row0 = REG_RD(bp, BAR_USTRORM_INTMEM +
690 USTORM_ASSERT_LIST_OFFSET(i));
691 row1 = REG_RD(bp, BAR_USTRORM_INTMEM +
692 USTORM_ASSERT_LIST_OFFSET(i) + 4);
693 row2 = REG_RD(bp, BAR_USTRORM_INTMEM +
694 USTORM_ASSERT_LIST_OFFSET(i) + 8);
695 row3 = REG_RD(bp, BAR_USTRORM_INTMEM +
696 USTORM_ASSERT_LIST_OFFSET(i) + 12);
698 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
699 BNX2X_ERR("USTORM_ASSERT_INDEX 0x%x = 0x%08x"
700 " 0x%08x 0x%08x 0x%08x\n",
701 i, row3, row2, row1, row0);
711 void bnx2x_fw_dump_lvl(struct bnx2x *bp, const char *lvl)
717 u32 trace_shmem_base;
719 BNX2X_ERR("NO MCP - can not dump\n");
722 netdev_printk(lvl, bp->dev, "bc %d.%d.%d\n",
723 (bp->common.bc_ver & 0xff0000) >> 16,
724 (bp->common.bc_ver & 0xff00) >> 8,
725 (bp->common.bc_ver & 0xff));
727 val = REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER);
728 if (val == REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER))
729 printk("%s" "MCP PC at 0x%x\n", lvl, val);
731 if (BP_PATH(bp) == 0)
732 trace_shmem_base = bp->common.shmem_base;
734 trace_shmem_base = SHMEM2_RD(bp, other_shmem_base_addr);
735 addr = trace_shmem_base - 0x0800 + 4;
736 mark = REG_RD(bp, addr);
737 mark = (CHIP_IS_E1x(bp) ? MCP_REG_MCPR_SCRATCH : MCP_A_REG_MCPR_SCRATCH)
738 + ((mark + 0x3) & ~0x3) - 0x08000000;
739 printk("%s" "begin fw dump (mark 0x%x)\n", lvl, mark);
742 for (offset = mark; offset <= trace_shmem_base; offset += 0x8*4) {
743 for (word = 0; word < 8; word++)
744 data[word] = htonl(REG_RD(bp, offset + 4*word));
746 pr_cont("%s", (char *)data);
748 for (offset = addr + 4; offset <= mark; offset += 0x8*4) {
749 for (word = 0; word < 8; word++)
750 data[word] = htonl(REG_RD(bp, offset + 4*word));
752 pr_cont("%s", (char *)data);
754 printk("%s" "end of fw dump\n", lvl);
757 static inline void bnx2x_fw_dump(struct bnx2x *bp)
759 bnx2x_fw_dump_lvl(bp, KERN_ERR);
762 void bnx2x_panic_dump(struct bnx2x *bp)
766 struct hc_sp_status_block_data sp_sb_data;
767 int func = BP_FUNC(bp);
768 #ifdef BNX2X_STOP_ON_ERROR
769 u16 start = 0, end = 0;
773 bp->stats_state = STATS_STATE_DISABLED;
774 DP(BNX2X_MSG_STATS, "stats_state - DISABLED\n");
776 BNX2X_ERR("begin crash dump -----------------\n");
780 BNX2X_ERR("def_idx(0x%x) def_att_idx(0x%x) attn_state(0x%x)"
781 " spq_prod_idx(0x%x) next_stats_cnt(0x%x)\n",
782 bp->def_idx, bp->def_att_idx, bp->attn_state,
783 bp->spq_prod_idx, bp->stats_counter);
784 BNX2X_ERR("DSB: attn bits(0x%x) ack(0x%x) id(0x%x) idx(0x%x)\n",
785 bp->def_status_blk->atten_status_block.attn_bits,
786 bp->def_status_blk->atten_status_block.attn_bits_ack,
787 bp->def_status_blk->atten_status_block.status_block_id,
788 bp->def_status_blk->atten_status_block.attn_bits_index);
790 for (i = 0; i < HC_SP_SB_MAX_INDICES; i++)
792 bp->def_status_blk->sp_sb.index_values[i],
793 (i == HC_SP_SB_MAX_INDICES - 1) ? ") " : " ");
795 for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
796 *((u32 *)&sp_sb_data + i) = REG_RD(bp, BAR_CSTRORM_INTMEM +
797 CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
800 pr_cont("igu_sb_id(0x%x) igu_seg_id(0x%x) "
801 "pf_id(0x%x) vnic_id(0x%x) "
802 "vf_id(0x%x) vf_valid (0x%x) "
804 sp_sb_data.igu_sb_id,
805 sp_sb_data.igu_seg_id,
806 sp_sb_data.p_func.pf_id,
807 sp_sb_data.p_func.vnic_id,
808 sp_sb_data.p_func.vf_id,
809 sp_sb_data.p_func.vf_valid,
813 for_each_eth_queue(bp, i) {
814 struct bnx2x_fastpath *fp = &bp->fp[i];
816 struct hc_status_block_data_e2 sb_data_e2;
817 struct hc_status_block_data_e1x sb_data_e1x;
818 struct hc_status_block_sm *hc_sm_p =
820 sb_data_e1x.common.state_machine :
821 sb_data_e2.common.state_machine;
822 struct hc_index_data *hc_index_p =
824 sb_data_e1x.index_data :
825 sb_data_e2.index_data;
828 struct bnx2x_fp_txdata txdata;
831 BNX2X_ERR("fp%d: rx_bd_prod(0x%x) rx_bd_cons(0x%x)"
832 " rx_comp_prod(0x%x)"
833 " rx_comp_cons(0x%x) *rx_cons_sb(0x%x)\n",
834 i, fp->rx_bd_prod, fp->rx_bd_cons,
836 fp->rx_comp_cons, le16_to_cpu(*fp->rx_cons_sb));
837 BNX2X_ERR(" rx_sge_prod(0x%x) last_max_sge(0x%x)"
838 " fp_hc_idx(0x%x)\n",
839 fp->rx_sge_prod, fp->last_max_sge,
840 le16_to_cpu(fp->fp_hc_idx));
843 for_each_cos_in_tx_queue(fp, cos)
845 txdata = fp->txdata[cos];
846 BNX2X_ERR("fp%d: tx_pkt_prod(0x%x) tx_pkt_cons(0x%x)"
847 " tx_bd_prod(0x%x) tx_bd_cons(0x%x)"
848 " *tx_cons_sb(0x%x)\n",
849 i, txdata.tx_pkt_prod,
850 txdata.tx_pkt_cons, txdata.tx_bd_prod,
852 le16_to_cpu(*txdata.tx_cons_sb));
855 loop = CHIP_IS_E1x(bp) ?
856 HC_SB_MAX_INDICES_E1X : HC_SB_MAX_INDICES_E2;
864 BNX2X_ERR(" run indexes (");
865 for (j = 0; j < HC_SB_MAX_SM; j++)
867 fp->sb_running_index[j],
868 (j == HC_SB_MAX_SM - 1) ? ")" : " ");
870 BNX2X_ERR(" indexes (");
871 for (j = 0; j < loop; j++)
873 fp->sb_index_values[j],
874 (j == loop - 1) ? ")" : " ");
876 data_size = CHIP_IS_E1x(bp) ?
877 sizeof(struct hc_status_block_data_e1x) :
878 sizeof(struct hc_status_block_data_e2);
879 data_size /= sizeof(u32);
880 sb_data_p = CHIP_IS_E1x(bp) ?
881 (u32 *)&sb_data_e1x :
883 /* copy sb data in here */
884 for (j = 0; j < data_size; j++)
885 *(sb_data_p + j) = REG_RD(bp, BAR_CSTRORM_INTMEM +
886 CSTORM_STATUS_BLOCK_DATA_OFFSET(fp->fw_sb_id) +
889 if (!CHIP_IS_E1x(bp)) {
890 pr_cont("pf_id(0x%x) vf_id(0x%x) vf_valid(0x%x) "
891 "vnic_id(0x%x) same_igu_sb_1b(0x%x) "
893 sb_data_e2.common.p_func.pf_id,
894 sb_data_e2.common.p_func.vf_id,
895 sb_data_e2.common.p_func.vf_valid,
896 sb_data_e2.common.p_func.vnic_id,
897 sb_data_e2.common.same_igu_sb_1b,
898 sb_data_e2.common.state);
900 pr_cont("pf_id(0x%x) vf_id(0x%x) vf_valid(0x%x) "
901 "vnic_id(0x%x) same_igu_sb_1b(0x%x) "
903 sb_data_e1x.common.p_func.pf_id,
904 sb_data_e1x.common.p_func.vf_id,
905 sb_data_e1x.common.p_func.vf_valid,
906 sb_data_e1x.common.p_func.vnic_id,
907 sb_data_e1x.common.same_igu_sb_1b,
908 sb_data_e1x.common.state);
912 for (j = 0; j < HC_SB_MAX_SM; j++) {
913 pr_cont("SM[%d] __flags (0x%x) "
914 "igu_sb_id (0x%x) igu_seg_id(0x%x) "
915 "time_to_expire (0x%x) "
916 "timer_value(0x%x)\n", j,
918 hc_sm_p[j].igu_sb_id,
919 hc_sm_p[j].igu_seg_id,
920 hc_sm_p[j].time_to_expire,
921 hc_sm_p[j].timer_value);
925 for (j = 0; j < loop; j++) {
926 pr_cont("INDEX[%d] flags (0x%x) "
927 "timeout (0x%x)\n", j,
929 hc_index_p[j].timeout);
933 #ifdef BNX2X_STOP_ON_ERROR
936 for_each_rx_queue(bp, i) {
937 struct bnx2x_fastpath *fp = &bp->fp[i];
939 start = RX_BD(le16_to_cpu(*fp->rx_cons_sb) - 10);
940 end = RX_BD(le16_to_cpu(*fp->rx_cons_sb) + 503);
941 for (j = start; j != end; j = RX_BD(j + 1)) {
942 u32 *rx_bd = (u32 *)&fp->rx_desc_ring[j];
943 struct sw_rx_bd *sw_bd = &fp->rx_buf_ring[j];
945 BNX2X_ERR("fp%d: rx_bd[%x]=[%x:%x] sw_bd=[%p]\n",
946 i, j, rx_bd[1], rx_bd[0], sw_bd->skb);
949 start = RX_SGE(fp->rx_sge_prod);
950 end = RX_SGE(fp->last_max_sge);
951 for (j = start; j != end; j = RX_SGE(j + 1)) {
952 u32 *rx_sge = (u32 *)&fp->rx_sge_ring[j];
953 struct sw_rx_page *sw_page = &fp->rx_page_ring[j];
955 BNX2X_ERR("fp%d: rx_sge[%x]=[%x:%x] sw_page=[%p]\n",
956 i, j, rx_sge[1], rx_sge[0], sw_page->page);
959 start = RCQ_BD(fp->rx_comp_cons - 10);
960 end = RCQ_BD(fp->rx_comp_cons + 503);
961 for (j = start; j != end; j = RCQ_BD(j + 1)) {
962 u32 *cqe = (u32 *)&fp->rx_comp_ring[j];
964 BNX2X_ERR("fp%d: cqe[%x]=[%x:%x:%x:%x]\n",
965 i, j, cqe[0], cqe[1], cqe[2], cqe[3]);
970 for_each_tx_queue(bp, i) {
971 struct bnx2x_fastpath *fp = &bp->fp[i];
972 for_each_cos_in_tx_queue(fp, cos) {
973 struct bnx2x_fp_txdata *txdata = &fp->txdata[cos];
975 start = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) - 10);
976 end = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) + 245);
977 for (j = start; j != end; j = TX_BD(j + 1)) {
978 struct sw_tx_bd *sw_bd =
979 &txdata->tx_buf_ring[j];
981 BNX2X_ERR("fp%d: txdata %d, "
982 "packet[%x]=[%p,%x]\n",
983 i, cos, j, sw_bd->skb,
987 start = TX_BD(txdata->tx_bd_cons - 10);
988 end = TX_BD(txdata->tx_bd_cons + 254);
989 for (j = start; j != end; j = TX_BD(j + 1)) {
990 u32 *tx_bd = (u32 *)&txdata->tx_desc_ring[j];
992 BNX2X_ERR("fp%d: txdata %d, tx_bd[%x]="
994 i, cos, j, tx_bd[0], tx_bd[1],
1001 bnx2x_mc_assert(bp);
1002 BNX2X_ERR("end crash dump -----------------\n");
1006 * FLR Support for E2
1008 * bnx2x_pf_flr_clnup() is called during nic_load in the per function HW
1011 #define FLR_WAIT_USEC 10000 /* 10 miliseconds */
1012 #define FLR_WAIT_INTERAVAL 50 /* usec */
1013 #define FLR_POLL_CNT (FLR_WAIT_USEC/FLR_WAIT_INTERAVAL) /* 200 */
1015 struct pbf_pN_buf_regs {
1022 struct pbf_pN_cmd_regs {
1028 static void bnx2x_pbf_pN_buf_flushed(struct bnx2x *bp,
1029 struct pbf_pN_buf_regs *regs,
1032 u32 init_crd, crd, crd_start, crd_freed, crd_freed_start;
1033 u32 cur_cnt = poll_count;
1035 crd_freed = crd_freed_start = REG_RD(bp, regs->crd_freed);
1036 crd = crd_start = REG_RD(bp, regs->crd);
1037 init_crd = REG_RD(bp, regs->init_crd);
1039 DP(BNX2X_MSG_SP, "INIT CREDIT[%d] : %x\n", regs->pN, init_crd);
1040 DP(BNX2X_MSG_SP, "CREDIT[%d] : s:%x\n", regs->pN, crd);
1041 DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: s:%x\n", regs->pN, crd_freed);
1043 while ((crd != init_crd) && ((u32)SUB_S32(crd_freed, crd_freed_start) <
1044 (init_crd - crd_start))) {
1046 udelay(FLR_WAIT_INTERAVAL);
1047 crd = REG_RD(bp, regs->crd);
1048 crd_freed = REG_RD(bp, regs->crd_freed);
1050 DP(BNX2X_MSG_SP, "PBF tx buffer[%d] timed out\n",
1052 DP(BNX2X_MSG_SP, "CREDIT[%d] : c:%x\n",
1054 DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: c:%x\n",
1055 regs->pN, crd_freed);
1059 DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF tx buffer[%d]\n",
1060 poll_count-cur_cnt, FLR_WAIT_INTERAVAL, regs->pN);
1063 static void bnx2x_pbf_pN_cmd_flushed(struct bnx2x *bp,
1064 struct pbf_pN_cmd_regs *regs,
1067 u32 occup, to_free, freed, freed_start;
1068 u32 cur_cnt = poll_count;
1070 occup = to_free = REG_RD(bp, regs->lines_occup);
1071 freed = freed_start = REG_RD(bp, regs->lines_freed);
1073 DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n", regs->pN, occup);
1074 DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n", regs->pN, freed);
1076 while (occup && ((u32)SUB_S32(freed, freed_start) < to_free)) {
1078 udelay(FLR_WAIT_INTERAVAL);
1079 occup = REG_RD(bp, regs->lines_occup);
1080 freed = REG_RD(bp, regs->lines_freed);
1082 DP(BNX2X_MSG_SP, "PBF cmd queue[%d] timed out\n",
1084 DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n",
1086 DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n",
1091 DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF cmd queue[%d]\n",
1092 poll_count-cur_cnt, FLR_WAIT_INTERAVAL, regs->pN);
1095 static inline u32 bnx2x_flr_clnup_reg_poll(struct bnx2x *bp, u32 reg,
1096 u32 expected, u32 poll_count)
1098 u32 cur_cnt = poll_count;
1101 while ((val = REG_RD(bp, reg)) != expected && cur_cnt--)
1102 udelay(FLR_WAIT_INTERAVAL);
1107 static inline int bnx2x_flr_clnup_poll_hw_counter(struct bnx2x *bp, u32 reg,
1108 char *msg, u32 poll_cnt)
1110 u32 val = bnx2x_flr_clnup_reg_poll(bp, reg, 0, poll_cnt);
1112 BNX2X_ERR("%s usage count=%d\n", msg, val);
1118 static u32 bnx2x_flr_clnup_poll_count(struct bnx2x *bp)
1120 /* adjust polling timeout */
1121 if (CHIP_REV_IS_EMUL(bp))
1122 return FLR_POLL_CNT * 2000;
1124 if (CHIP_REV_IS_FPGA(bp))
1125 return FLR_POLL_CNT * 120;
1127 return FLR_POLL_CNT;
1130 static void bnx2x_tx_hw_flushed(struct bnx2x *bp, u32 poll_count)
1132 struct pbf_pN_cmd_regs cmd_regs[] = {
1133 {0, (CHIP_IS_E3B0(bp)) ?
1134 PBF_REG_TQ_OCCUPANCY_Q0 :
1135 PBF_REG_P0_TQ_OCCUPANCY,
1136 (CHIP_IS_E3B0(bp)) ?
1137 PBF_REG_TQ_LINES_FREED_CNT_Q0 :
1138 PBF_REG_P0_TQ_LINES_FREED_CNT},
1139 {1, (CHIP_IS_E3B0(bp)) ?
1140 PBF_REG_TQ_OCCUPANCY_Q1 :
1141 PBF_REG_P1_TQ_OCCUPANCY,
1142 (CHIP_IS_E3B0(bp)) ?
1143 PBF_REG_TQ_LINES_FREED_CNT_Q1 :
1144 PBF_REG_P1_TQ_LINES_FREED_CNT},
1145 {4, (CHIP_IS_E3B0(bp)) ?
1146 PBF_REG_TQ_OCCUPANCY_LB_Q :
1147 PBF_REG_P4_TQ_OCCUPANCY,
1148 (CHIP_IS_E3B0(bp)) ?
1149 PBF_REG_TQ_LINES_FREED_CNT_LB_Q :
1150 PBF_REG_P4_TQ_LINES_FREED_CNT}
1153 struct pbf_pN_buf_regs buf_regs[] = {
1154 {0, (CHIP_IS_E3B0(bp)) ?
1155 PBF_REG_INIT_CRD_Q0 :
1156 PBF_REG_P0_INIT_CRD ,
1157 (CHIP_IS_E3B0(bp)) ?
1160 (CHIP_IS_E3B0(bp)) ?
1161 PBF_REG_INTERNAL_CRD_FREED_CNT_Q0 :
1162 PBF_REG_P0_INTERNAL_CRD_FREED_CNT},
1163 {1, (CHIP_IS_E3B0(bp)) ?
1164 PBF_REG_INIT_CRD_Q1 :
1165 PBF_REG_P1_INIT_CRD,
1166 (CHIP_IS_E3B0(bp)) ?
1169 (CHIP_IS_E3B0(bp)) ?
1170 PBF_REG_INTERNAL_CRD_FREED_CNT_Q1 :
1171 PBF_REG_P1_INTERNAL_CRD_FREED_CNT},
1172 {4, (CHIP_IS_E3B0(bp)) ?
1173 PBF_REG_INIT_CRD_LB_Q :
1174 PBF_REG_P4_INIT_CRD,
1175 (CHIP_IS_E3B0(bp)) ?
1176 PBF_REG_CREDIT_LB_Q :
1178 (CHIP_IS_E3B0(bp)) ?
1179 PBF_REG_INTERNAL_CRD_FREED_CNT_LB_Q :
1180 PBF_REG_P4_INTERNAL_CRD_FREED_CNT},
1185 /* Verify the command queues are flushed P0, P1, P4 */
1186 for (i = 0; i < ARRAY_SIZE(cmd_regs); i++)
1187 bnx2x_pbf_pN_cmd_flushed(bp, &cmd_regs[i], poll_count);
1190 /* Verify the transmission buffers are flushed P0, P1, P4 */
1191 for (i = 0; i < ARRAY_SIZE(buf_regs); i++)
1192 bnx2x_pbf_pN_buf_flushed(bp, &buf_regs[i], poll_count);
1195 #define OP_GEN_PARAM(param) \
1196 (((param) << SDM_OP_GEN_COMP_PARAM_SHIFT) & SDM_OP_GEN_COMP_PARAM)
1198 #define OP_GEN_TYPE(type) \
1199 (((type) << SDM_OP_GEN_COMP_TYPE_SHIFT) & SDM_OP_GEN_COMP_TYPE)
1201 #define OP_GEN_AGG_VECT(index) \
1202 (((index) << SDM_OP_GEN_AGG_VECT_IDX_SHIFT) & SDM_OP_GEN_AGG_VECT_IDX)
1205 static inline int bnx2x_send_final_clnup(struct bnx2x *bp, u8 clnup_func,
1208 struct sdm_op_gen op_gen = {0};
1210 u32 comp_addr = BAR_CSTRORM_INTMEM +
1211 CSTORM_FINAL_CLEANUP_COMPLETE_OFFSET(clnup_func);
1214 if (REG_RD(bp, comp_addr)) {
1215 BNX2X_ERR("Cleanup complete is not 0\n");
1219 op_gen.command |= OP_GEN_PARAM(XSTORM_AGG_INT_FINAL_CLEANUP_INDEX);
1220 op_gen.command |= OP_GEN_TYPE(XSTORM_AGG_INT_FINAL_CLEANUP_COMP_TYPE);
1221 op_gen.command |= OP_GEN_AGG_VECT(clnup_func);
1222 op_gen.command |= 1 << SDM_OP_GEN_AGG_VECT_IDX_VALID_SHIFT;
1224 DP(BNX2X_MSG_SP, "FW Final cleanup\n");
1225 REG_WR(bp, XSDM_REG_OPERATION_GEN, op_gen.command);
1227 if (bnx2x_flr_clnup_reg_poll(bp, comp_addr, 1, poll_cnt) != 1) {
1228 BNX2X_ERR("FW final cleanup did not succeed\n");
1231 /* Zero completion for nxt FLR */
1232 REG_WR(bp, comp_addr, 0);
1237 static inline u8 bnx2x_is_pcie_pending(struct pci_dev *dev)
1242 pos = pci_pcie_cap(dev);
1246 pci_read_config_word(dev, pos + PCI_EXP_DEVSTA, &status);
1247 return status & PCI_EXP_DEVSTA_TRPND;
1250 /* PF FLR specific routines
1252 static int bnx2x_poll_hw_usage_counters(struct bnx2x *bp, u32 poll_cnt)
1255 /* wait for CFC PF usage-counter to zero (includes all the VFs) */
1256 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1257 CFC_REG_NUM_LCIDS_INSIDE_PF,
1258 "CFC PF usage counter timed out",
1263 /* Wait for DQ PF usage-counter to zero (until DQ cleanup) */
1264 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1265 DORQ_REG_PF_USAGE_CNT,
1266 "DQ PF usage counter timed out",
1270 /* Wait for QM PF usage-counter to zero (until DQ cleanup) */
1271 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1272 QM_REG_PF_USG_CNT_0 + 4*BP_FUNC(bp),
1273 "QM PF usage counter timed out",
1277 /* Wait for Timer PF usage-counters to zero (until DQ cleanup) */
1278 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1279 TM_REG_LIN0_VNIC_UC + 4*BP_PORT(bp),
1280 "Timers VNIC usage counter timed out",
1283 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1284 TM_REG_LIN0_NUM_SCANS + 4*BP_PORT(bp),
1285 "Timers NUM_SCANS usage counter timed out",
1289 /* Wait DMAE PF usage counter to zero */
1290 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1291 dmae_reg_go_c[INIT_DMAE_C(bp)],
1292 "DMAE dommand register timed out",
1299 static void bnx2x_hw_enable_status(struct bnx2x *bp)
1303 val = REG_RD(bp, CFC_REG_WEAK_ENABLE_PF);
1304 DP(BNX2X_MSG_SP, "CFC_REG_WEAK_ENABLE_PF is 0x%x\n", val);
1306 val = REG_RD(bp, PBF_REG_DISABLE_PF);
1307 DP(BNX2X_MSG_SP, "PBF_REG_DISABLE_PF is 0x%x\n", val);
1309 val = REG_RD(bp, IGU_REG_PCI_PF_MSI_EN);
1310 DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSI_EN is 0x%x\n", val);
1312 val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_EN);
1313 DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_EN is 0x%x\n", val);
1315 val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_FUNC_MASK);
1316 DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_FUNC_MASK is 0x%x\n", val);
1318 val = REG_RD(bp, PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR);
1319 DP(BNX2X_MSG_SP, "PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR is 0x%x\n", val);
1321 val = REG_RD(bp, PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR);
1322 DP(BNX2X_MSG_SP, "PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR is 0x%x\n", val);
1324 val = REG_RD(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER);
1325 DP(BNX2X_MSG_SP, "PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER is 0x%x\n",
1329 static int bnx2x_pf_flr_clnup(struct bnx2x *bp)
1331 u32 poll_cnt = bnx2x_flr_clnup_poll_count(bp);
1333 DP(BNX2X_MSG_SP, "Cleanup after FLR PF[%d]\n", BP_ABS_FUNC(bp));
1335 /* Re-enable PF target read access */
1336 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
1338 /* Poll HW usage counters */
1339 if (bnx2x_poll_hw_usage_counters(bp, poll_cnt))
1342 /* Zero the igu 'trailing edge' and 'leading edge' */
1344 /* Send the FW cleanup command */
1345 if (bnx2x_send_final_clnup(bp, (u8)BP_FUNC(bp), poll_cnt))
1350 /* Verify TX hw is flushed */
1351 bnx2x_tx_hw_flushed(bp, poll_cnt);
1353 /* Wait 100ms (not adjusted according to platform) */
1356 /* Verify no pending pci transactions */
1357 if (bnx2x_is_pcie_pending(bp->pdev))
1358 BNX2X_ERR("PCIE Transactions still pending\n");
1361 bnx2x_hw_enable_status(bp);
1364 * Master enable - Due to WB DMAE writes performed before this
1365 * register is re-initialized as part of the regular function init
1367 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
1372 static void bnx2x_hc_int_enable(struct bnx2x *bp)
1374 int port = BP_PORT(bp);
1375 u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
1376 u32 val = REG_RD(bp, addr);
1377 int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
1378 int msi = (bp->flags & USING_MSI_FLAG) ? 1 : 0;
1381 val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
1382 HC_CONFIG_0_REG_INT_LINE_EN_0);
1383 val |= (HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
1384 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
1386 val &= ~HC_CONFIG_0_REG_INT_LINE_EN_0;
1387 val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
1388 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
1389 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
1391 val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
1392 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
1393 HC_CONFIG_0_REG_INT_LINE_EN_0 |
1394 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
1396 if (!CHIP_IS_E1(bp)) {
1397 DP(NETIF_MSG_INTR, "write %x to HC %d (addr 0x%x)\n",
1400 REG_WR(bp, addr, val);
1402 val &= ~HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0;
1407 REG_WR(bp, HC_REG_INT_MASK + port*4, 0x1FFFF);
1409 DP(NETIF_MSG_INTR, "write %x to HC %d (addr 0x%x) mode %s\n",
1410 val, port, addr, (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
1412 REG_WR(bp, addr, val);
1414 * Ensure that HC_CONFIG is written before leading/trailing edge config
1419 if (!CHIP_IS_E1(bp)) {
1420 /* init leading/trailing edge */
1422 val = (0xee0f | (1 << (BP_E1HVN(bp) + 4)));
1424 /* enable nig and gpio3 attention */
1429 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
1430 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
1433 /* Make sure that interrupts are indeed enabled from here on */
1437 static void bnx2x_igu_int_enable(struct bnx2x *bp)
1440 int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
1441 int msi = (bp->flags & USING_MSI_FLAG) ? 1 : 0;
1443 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
1446 val &= ~(IGU_PF_CONF_INT_LINE_EN |
1447 IGU_PF_CONF_SINGLE_ISR_EN);
1448 val |= (IGU_PF_CONF_FUNC_EN |
1449 IGU_PF_CONF_MSI_MSIX_EN |
1450 IGU_PF_CONF_ATTN_BIT_EN);
1452 val &= ~IGU_PF_CONF_INT_LINE_EN;
1453 val |= (IGU_PF_CONF_FUNC_EN |
1454 IGU_PF_CONF_MSI_MSIX_EN |
1455 IGU_PF_CONF_ATTN_BIT_EN |
1456 IGU_PF_CONF_SINGLE_ISR_EN);
1458 val &= ~IGU_PF_CONF_MSI_MSIX_EN;
1459 val |= (IGU_PF_CONF_FUNC_EN |
1460 IGU_PF_CONF_INT_LINE_EN |
1461 IGU_PF_CONF_ATTN_BIT_EN |
1462 IGU_PF_CONF_SINGLE_ISR_EN);
1465 DP(NETIF_MSG_INTR, "write 0x%x to IGU mode %s\n",
1466 val, (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
1468 REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
1472 /* init leading/trailing edge */
1474 val = (0xee0f | (1 << (BP_E1HVN(bp) + 4)));
1476 /* enable nig and gpio3 attention */
1481 REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
1482 REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
1484 /* Make sure that interrupts are indeed enabled from here on */
1488 void bnx2x_int_enable(struct bnx2x *bp)
1490 if (bp->common.int_block == INT_BLOCK_HC)
1491 bnx2x_hc_int_enable(bp);
1493 bnx2x_igu_int_enable(bp);
1496 static void bnx2x_hc_int_disable(struct bnx2x *bp)
1498 int port = BP_PORT(bp);
1499 u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
1500 u32 val = REG_RD(bp, addr);
1503 * in E1 we must use only PCI configuration space to disable
1504 * MSI/MSIX capablility
1505 * It's forbitten to disable IGU_PF_CONF_MSI_MSIX_EN in HC block
1507 if (CHIP_IS_E1(bp)) {
1508 /* Since IGU_PF_CONF_MSI_MSIX_EN still always on
1509 * Use mask register to prevent from HC sending interrupts
1510 * after we exit the function
1512 REG_WR(bp, HC_REG_INT_MASK + port*4, 0);
1514 val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
1515 HC_CONFIG_0_REG_INT_LINE_EN_0 |
1516 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
1518 val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
1519 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
1520 HC_CONFIG_0_REG_INT_LINE_EN_0 |
1521 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
1523 DP(NETIF_MSG_INTR, "write %x to HC %d (addr 0x%x)\n",
1526 /* flush all outstanding writes */
1529 REG_WR(bp, addr, val);
1530 if (REG_RD(bp, addr) != val)
1531 BNX2X_ERR("BUG! proper val not read from IGU!\n");
1534 static void bnx2x_igu_int_disable(struct bnx2x *bp)
1536 u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
1538 val &= ~(IGU_PF_CONF_MSI_MSIX_EN |
1539 IGU_PF_CONF_INT_LINE_EN |
1540 IGU_PF_CONF_ATTN_BIT_EN);
1542 DP(NETIF_MSG_INTR, "write %x to IGU\n", val);
1544 /* flush all outstanding writes */
1547 REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
1548 if (REG_RD(bp, IGU_REG_PF_CONFIGURATION) != val)
1549 BNX2X_ERR("BUG! proper val not read from IGU!\n");
1552 void bnx2x_int_disable(struct bnx2x *bp)
1554 if (bp->common.int_block == INT_BLOCK_HC)
1555 bnx2x_hc_int_disable(bp);
1557 bnx2x_igu_int_disable(bp);
1560 void bnx2x_int_disable_sync(struct bnx2x *bp, int disable_hw)
1562 int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
1566 /* prevent the HW from sending interrupts */
1567 bnx2x_int_disable(bp);
1569 /* make sure all ISRs are done */
1571 synchronize_irq(bp->msix_table[0].vector);
1576 for_each_eth_queue(bp, i)
1577 synchronize_irq(bp->msix_table[offset++].vector);
1579 synchronize_irq(bp->pdev->irq);
1581 /* make sure sp_task is not running */
1582 cancel_delayed_work(&bp->sp_task);
1583 cancel_delayed_work(&bp->period_task);
1584 flush_workqueue(bnx2x_wq);
1590 * General service functions
1593 /* Return true if succeeded to acquire the lock */
1594 static bool bnx2x_trylock_hw_lock(struct bnx2x *bp, u32 resource)
1597 u32 resource_bit = (1 << resource);
1598 int func = BP_FUNC(bp);
1599 u32 hw_lock_control_reg;
1601 DP(NETIF_MSG_HW, "Trying to take a lock on resource %d\n", resource);
1603 /* Validating that the resource is within range */
1604 if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
1606 "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
1607 resource, HW_LOCK_MAX_RESOURCE_VALUE);
1612 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
1614 hw_lock_control_reg =
1615 (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
1617 /* Try to acquire the lock */
1618 REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
1619 lock_status = REG_RD(bp, hw_lock_control_reg);
1620 if (lock_status & resource_bit)
1623 DP(NETIF_MSG_HW, "Failed to get a lock on resource %d\n", resource);
1628 * bnx2x_get_leader_lock_resource - get the recovery leader resource id
1630 * @bp: driver handle
1632 * Returns the recovery leader resource id according to the engine this function
1633 * belongs to. Currently only only 2 engines is supported.
1635 static inline int bnx2x_get_leader_lock_resource(struct bnx2x *bp)
1638 return HW_LOCK_RESOURCE_RECOVERY_LEADER_1;
1640 return HW_LOCK_RESOURCE_RECOVERY_LEADER_0;
1644 * bnx2x_trylock_leader_lock- try to aquire a leader lock.
1646 * @bp: driver handle
1648 * Tries to aquire a leader lock for cuurent engine.
1650 static inline bool bnx2x_trylock_leader_lock(struct bnx2x *bp)
1652 return bnx2x_trylock_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
1656 static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err);
1659 void bnx2x_sp_event(struct bnx2x_fastpath *fp, union eth_rx_cqe *rr_cqe)
1661 struct bnx2x *bp = fp->bp;
1662 int cid = SW_CID(rr_cqe->ramrod_cqe.conn_and_cmd_data);
1663 int command = CQE_CMD(rr_cqe->ramrod_cqe.conn_and_cmd_data);
1664 enum bnx2x_queue_cmd drv_cmd = BNX2X_Q_CMD_MAX;
1665 struct bnx2x_queue_sp_obj *q_obj = &fp->q_obj;
1668 "fp %d cid %d got ramrod #%d state is %x type is %d\n",
1669 fp->index, cid, command, bp->state,
1670 rr_cqe->ramrod_cqe.ramrod_type);
1673 case (RAMROD_CMD_ID_ETH_CLIENT_UPDATE):
1674 DP(NETIF_MSG_IFUP, "got UPDATE ramrod. CID %d\n", cid);
1675 drv_cmd = BNX2X_Q_CMD_UPDATE;
1677 case (RAMROD_CMD_ID_ETH_CLIENT_SETUP):
1678 DP(NETIF_MSG_IFUP, "got MULTI[%d] setup ramrod\n", cid);
1679 drv_cmd = BNX2X_Q_CMD_SETUP;
1682 case (RAMROD_CMD_ID_ETH_TX_QUEUE_SETUP):
1683 DP(NETIF_MSG_IFUP, "got MULTI[%d] tx-only setup ramrod\n", cid);
1684 drv_cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
1687 case (RAMROD_CMD_ID_ETH_HALT):
1688 DP(NETIF_MSG_IFDOWN, "got MULTI[%d] halt ramrod\n", cid);
1689 drv_cmd = BNX2X_Q_CMD_HALT;
1692 case (RAMROD_CMD_ID_ETH_TERMINATE):
1693 DP(NETIF_MSG_IFDOWN, "got MULTI[%d] teminate ramrod\n", cid);
1694 drv_cmd = BNX2X_Q_CMD_TERMINATE;
1697 case (RAMROD_CMD_ID_ETH_EMPTY):
1698 DP(NETIF_MSG_IFDOWN, "got MULTI[%d] empty ramrod\n", cid);
1699 drv_cmd = BNX2X_Q_CMD_EMPTY;
1703 BNX2X_ERR("unexpected MC reply (%d) on fp[%d]\n",
1704 command, fp->index);
1708 if ((drv_cmd != BNX2X_Q_CMD_MAX) &&
1709 q_obj->complete_cmd(bp, q_obj, drv_cmd))
1710 /* q_obj->complete_cmd() failure means that this was
1711 * an unexpected completion.
1713 * In this case we don't want to increase the bp->spq_left
1714 * because apparently we haven't sent this command the first
1717 #ifdef BNX2X_STOP_ON_ERROR
1723 smp_mb__before_atomic_inc();
1724 atomic_inc(&bp->cq_spq_left);
1725 /* push the change in bp->spq_left and towards the memory */
1726 smp_mb__after_atomic_inc();
1731 void bnx2x_update_rx_prod(struct bnx2x *bp, struct bnx2x_fastpath *fp,
1732 u16 bd_prod, u16 rx_comp_prod, u16 rx_sge_prod)
1734 u32 start = BAR_USTRORM_INTMEM + fp->ustorm_rx_prods_offset;
1736 bnx2x_update_rx_prod_gen(bp, fp, bd_prod, rx_comp_prod, rx_sge_prod,
1740 irqreturn_t bnx2x_interrupt(int irq, void *dev_instance)
1742 struct bnx2x *bp = netdev_priv(dev_instance);
1743 u16 status = bnx2x_ack_int(bp);
1748 /* Return here if interrupt is shared and it's not for us */
1749 if (unlikely(status == 0)) {
1750 DP(NETIF_MSG_INTR, "not our interrupt!\n");
1753 DP(NETIF_MSG_INTR, "got an interrupt status 0x%x\n", status);
1755 #ifdef BNX2X_STOP_ON_ERROR
1756 if (unlikely(bp->panic))
1760 for_each_eth_queue(bp, i) {
1761 struct bnx2x_fastpath *fp = &bp->fp[i];
1763 mask = 0x2 << (fp->index + CNIC_PRESENT);
1764 if (status & mask) {
1765 /* Handle Rx or Tx according to SB id */
1766 prefetch(fp->rx_cons_sb);
1767 for_each_cos_in_tx_queue(fp, cos)
1768 prefetch(fp->txdata[cos].tx_cons_sb);
1769 prefetch(&fp->sb_running_index[SM_RX_ID]);
1770 napi_schedule(&bnx2x_fp(bp, fp->index, napi));
1777 if (status & (mask | 0x1)) {
1778 struct cnic_ops *c_ops = NULL;
1780 if (likely(bp->state == BNX2X_STATE_OPEN)) {
1782 c_ops = rcu_dereference(bp->cnic_ops);
1784 c_ops->cnic_handler(bp->cnic_data, NULL);
1792 if (unlikely(status & 0x1)) {
1793 queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
1800 if (unlikely(status))
1801 DP(NETIF_MSG_INTR, "got an unknown interrupt! (status 0x%x)\n",
1810 * General service functions
1813 int bnx2x_acquire_hw_lock(struct bnx2x *bp, u32 resource)
1816 u32 resource_bit = (1 << resource);
1817 int func = BP_FUNC(bp);
1818 u32 hw_lock_control_reg;
1821 /* Validating that the resource is within range */
1822 if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
1824 "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
1825 resource, HW_LOCK_MAX_RESOURCE_VALUE);
1830 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
1832 hw_lock_control_reg =
1833 (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
1836 /* Validating that the resource is not already taken */
1837 lock_status = REG_RD(bp, hw_lock_control_reg);
1838 if (lock_status & resource_bit) {
1839 DP(NETIF_MSG_HW, "lock_status 0x%x resource_bit 0x%x\n",
1840 lock_status, resource_bit);
1844 /* Try for 5 second every 5ms */
1845 for (cnt = 0; cnt < 1000; cnt++) {
1846 /* Try to acquire the lock */
1847 REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
1848 lock_status = REG_RD(bp, hw_lock_control_reg);
1849 if (lock_status & resource_bit)
1854 DP(NETIF_MSG_HW, "Timeout\n");
1858 int bnx2x_release_leader_lock(struct bnx2x *bp)
1860 return bnx2x_release_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
1863 int bnx2x_release_hw_lock(struct bnx2x *bp, u32 resource)
1866 u32 resource_bit = (1 << resource);
1867 int func = BP_FUNC(bp);
1868 u32 hw_lock_control_reg;
1870 DP(NETIF_MSG_HW, "Releasing a lock on resource %d\n", resource);
1872 /* Validating that the resource is within range */
1873 if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
1875 "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
1876 resource, HW_LOCK_MAX_RESOURCE_VALUE);
1881 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
1883 hw_lock_control_reg =
1884 (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
1887 /* Validating that the resource is currently taken */
1888 lock_status = REG_RD(bp, hw_lock_control_reg);
1889 if (!(lock_status & resource_bit)) {
1890 DP(NETIF_MSG_HW, "lock_status 0x%x resource_bit 0x%x\n",
1891 lock_status, resource_bit);
1895 REG_WR(bp, hw_lock_control_reg, resource_bit);
1900 int bnx2x_get_gpio(struct bnx2x *bp, int gpio_num, u8 port)
1902 /* The GPIO should be swapped if swap register is set and active */
1903 int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
1904 REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
1905 int gpio_shift = gpio_num +
1906 (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
1907 u32 gpio_mask = (1 << gpio_shift);
1911 if (gpio_num > MISC_REGISTERS_GPIO_3) {
1912 BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
1916 /* read GPIO value */
1917 gpio_reg = REG_RD(bp, MISC_REG_GPIO);
1919 /* get the requested pin value */
1920 if ((gpio_reg & gpio_mask) == gpio_mask)
1925 DP(NETIF_MSG_LINK, "pin %d value 0x%x\n", gpio_num, value);
1930 int bnx2x_set_gpio(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
1932 /* The GPIO should be swapped if swap register is set and active */
1933 int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
1934 REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
1935 int gpio_shift = gpio_num +
1936 (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
1937 u32 gpio_mask = (1 << gpio_shift);
1940 if (gpio_num > MISC_REGISTERS_GPIO_3) {
1941 BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
1945 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
1946 /* read GPIO and mask except the float bits */
1947 gpio_reg = (REG_RD(bp, MISC_REG_GPIO) & MISC_REGISTERS_GPIO_FLOAT);
1950 case MISC_REGISTERS_GPIO_OUTPUT_LOW:
1951 DP(NETIF_MSG_LINK, "Set GPIO %d (shift %d) -> output low\n",
1952 gpio_num, gpio_shift);
1953 /* clear FLOAT and set CLR */
1954 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
1955 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_CLR_POS);
1958 case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
1959 DP(NETIF_MSG_LINK, "Set GPIO %d (shift %d) -> output high\n",
1960 gpio_num, gpio_shift);
1961 /* clear FLOAT and set SET */
1962 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
1963 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_SET_POS);
1966 case MISC_REGISTERS_GPIO_INPUT_HI_Z:
1967 DP(NETIF_MSG_LINK, "Set GPIO %d (shift %d) -> input\n",
1968 gpio_num, gpio_shift);
1970 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
1977 REG_WR(bp, MISC_REG_GPIO, gpio_reg);
1978 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
1983 int bnx2x_set_mult_gpio(struct bnx2x *bp, u8 pins, u32 mode)
1988 /* Any port swapping should be handled by caller. */
1990 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
1991 /* read GPIO and mask except the float bits */
1992 gpio_reg = REG_RD(bp, MISC_REG_GPIO);
1993 gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_FLOAT_POS);
1994 gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_CLR_POS);
1995 gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_SET_POS);
1998 case MISC_REGISTERS_GPIO_OUTPUT_LOW:
1999 DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output low\n", pins);
2001 gpio_reg |= (pins << MISC_REGISTERS_GPIO_CLR_POS);
2004 case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
2005 DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output high\n", pins);
2007 gpio_reg |= (pins << MISC_REGISTERS_GPIO_SET_POS);
2010 case MISC_REGISTERS_GPIO_INPUT_HI_Z:
2011 DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> input\n", pins);
2013 gpio_reg |= (pins << MISC_REGISTERS_GPIO_FLOAT_POS);
2017 BNX2X_ERR("Invalid GPIO mode assignment %d\n", mode);
2023 REG_WR(bp, MISC_REG_GPIO, gpio_reg);
2025 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
2030 int bnx2x_set_gpio_int(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
2032 /* The GPIO should be swapped if swap register is set and active */
2033 int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
2034 REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
2035 int gpio_shift = gpio_num +
2036 (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
2037 u32 gpio_mask = (1 << gpio_shift);
2040 if (gpio_num > MISC_REGISTERS_GPIO_3) {
2041 BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
2045 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
2047 gpio_reg = REG_RD(bp, MISC_REG_GPIO_INT);
2050 case MISC_REGISTERS_GPIO_INT_OUTPUT_CLR:
2051 DP(NETIF_MSG_LINK, "Clear GPIO INT %d (shift %d) -> "
2052 "output low\n", gpio_num, gpio_shift);
2053 /* clear SET and set CLR */
2054 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
2055 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
2058 case MISC_REGISTERS_GPIO_INT_OUTPUT_SET:
2059 DP(NETIF_MSG_LINK, "Set GPIO INT %d (shift %d) -> "
2060 "output high\n", gpio_num, gpio_shift);
2061 /* clear CLR and set SET */
2062 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
2063 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
2070 REG_WR(bp, MISC_REG_GPIO_INT, gpio_reg);
2071 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
2076 static int bnx2x_set_spio(struct bnx2x *bp, int spio_num, u32 mode)
2078 u32 spio_mask = (1 << spio_num);
2081 if ((spio_num < MISC_REGISTERS_SPIO_4) ||
2082 (spio_num > MISC_REGISTERS_SPIO_7)) {
2083 BNX2X_ERR("Invalid SPIO %d\n", spio_num);
2087 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
2088 /* read SPIO and mask except the float bits */
2089 spio_reg = (REG_RD(bp, MISC_REG_SPIO) & MISC_REGISTERS_SPIO_FLOAT);
2092 case MISC_REGISTERS_SPIO_OUTPUT_LOW:
2093 DP(NETIF_MSG_LINK, "Set SPIO %d -> output low\n", spio_num);
2094 /* clear FLOAT and set CLR */
2095 spio_reg &= ~(spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS);
2096 spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_CLR_POS);
2099 case MISC_REGISTERS_SPIO_OUTPUT_HIGH:
2100 DP(NETIF_MSG_LINK, "Set SPIO %d -> output high\n", spio_num);
2101 /* clear FLOAT and set SET */
2102 spio_reg &= ~(spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS);
2103 spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_SET_POS);
2106 case MISC_REGISTERS_SPIO_INPUT_HI_Z:
2107 DP(NETIF_MSG_LINK, "Set SPIO %d -> input\n", spio_num);
2109 spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS);
2116 REG_WR(bp, MISC_REG_SPIO, spio_reg);
2117 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
2122 void bnx2x_calc_fc_adv(struct bnx2x *bp)
2124 u8 cfg_idx = bnx2x_get_link_cfg_idx(bp);
2125 switch (bp->link_vars.ieee_fc &
2126 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK) {
2127 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE:
2128 bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
2132 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH:
2133 bp->port.advertising[cfg_idx] |= (ADVERTISED_Asym_Pause |
2137 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC:
2138 bp->port.advertising[cfg_idx] |= ADVERTISED_Asym_Pause;
2142 bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
2148 u8 bnx2x_initial_phy_init(struct bnx2x *bp, int load_mode)
2150 if (!BP_NOMCP(bp)) {
2152 int cfx_idx = bnx2x_get_link_cfg_idx(bp);
2153 u16 req_line_speed = bp->link_params.req_line_speed[cfx_idx];
2154 /* Initialize link parameters structure variables */
2155 /* It is recommended to turn off RX FC for jumbo frames
2156 for better performance */
2157 if ((CHIP_IS_E1x(bp)) && (bp->dev->mtu > 5000))
2158 bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_TX;
2160 bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_BOTH;
2162 bnx2x_acquire_phy_lock(bp);
2164 if (load_mode == LOAD_DIAG) {
2165 bp->link_params.loopback_mode = LOOPBACK_XGXS;
2166 bp->link_params.req_line_speed[cfx_idx] = SPEED_10000;
2169 rc = bnx2x_phy_init(&bp->link_params, &bp->link_vars);
2171 bnx2x_release_phy_lock(bp);
2173 bnx2x_calc_fc_adv(bp);
2175 if (CHIP_REV_IS_SLOW(bp) && bp->link_vars.link_up) {
2176 bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
2177 bnx2x_link_report(bp);
2179 queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
2180 bp->link_params.req_line_speed[cfx_idx] = req_line_speed;
2183 BNX2X_ERR("Bootcode is missing - can not initialize link\n");
2187 void bnx2x_link_set(struct bnx2x *bp)
2189 if (!BP_NOMCP(bp)) {
2190 bnx2x_acquire_phy_lock(bp);
2191 bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
2192 bnx2x_phy_init(&bp->link_params, &bp->link_vars);
2193 bnx2x_release_phy_lock(bp);
2195 bnx2x_calc_fc_adv(bp);
2197 BNX2X_ERR("Bootcode is missing - can not set link\n");
2200 static void bnx2x__link_reset(struct bnx2x *bp)
2202 if (!BP_NOMCP(bp)) {
2203 bnx2x_acquire_phy_lock(bp);
2204 bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
2205 bnx2x_release_phy_lock(bp);
2207 BNX2X_ERR("Bootcode is missing - can not reset link\n");
2210 u8 bnx2x_link_test(struct bnx2x *bp, u8 is_serdes)
2214 if (!BP_NOMCP(bp)) {
2215 bnx2x_acquire_phy_lock(bp);
2216 rc = bnx2x_test_link(&bp->link_params, &bp->link_vars,
2218 bnx2x_release_phy_lock(bp);
2220 BNX2X_ERR("Bootcode is missing - can not test link\n");
2225 static void bnx2x_init_port_minmax(struct bnx2x *bp)
2227 u32 r_param = bp->link_vars.line_speed / 8;
2228 u32 fair_periodic_timeout_usec;
2231 memset(&(bp->cmng.rs_vars), 0,
2232 sizeof(struct rate_shaping_vars_per_port));
2233 memset(&(bp->cmng.fair_vars), 0, sizeof(struct fairness_vars_per_port));
2235 /* 100 usec in SDM ticks = 25 since each tick is 4 usec */
2236 bp->cmng.rs_vars.rs_periodic_timeout = RS_PERIODIC_TIMEOUT_USEC / 4;
2238 /* this is the threshold below which no timer arming will occur
2239 1.25 coefficient is for the threshold to be a little bigger
2240 than the real time, to compensate for timer in-accuracy */
2241 bp->cmng.rs_vars.rs_threshold =
2242 (RS_PERIODIC_TIMEOUT_USEC * r_param * 5) / 4;
2244 /* resolution of fairness timer */
2245 fair_periodic_timeout_usec = QM_ARB_BYTES / r_param;
2246 /* for 10G it is 1000usec. for 1G it is 10000usec. */
2247 t_fair = T_FAIR_COEF / bp->link_vars.line_speed;
2249 /* this is the threshold below which we won't arm the timer anymore */
2250 bp->cmng.fair_vars.fair_threshold = QM_ARB_BYTES;
2252 /* we multiply by 1e3/8 to get bytes/msec.
2253 We don't want the credits to pass a credit
2254 of the t_fair*FAIR_MEM (algorithm resolution) */
2255 bp->cmng.fair_vars.upper_bound = r_param * t_fair * FAIR_MEM;
2256 /* since each tick is 4 usec */
2257 bp->cmng.fair_vars.fairness_timeout = fair_periodic_timeout_usec / 4;
2260 /* Calculates the sum of vn_min_rates.
2261 It's needed for further normalizing of the min_rates.
2263 sum of vn_min_rates.
2265 0 - if all the min_rates are 0.
2266 In the later case fainess algorithm should be deactivated.
2267 If not all min_rates are zero then those that are zeroes will be set to 1.
2269 static void bnx2x_calc_vn_weight_sum(struct bnx2x *bp)
2274 bp->vn_weight_sum = 0;
2275 for (vn = VN_0; vn < E1HVN_MAX; vn++) {
2276 u32 vn_cfg = bp->mf_config[vn];
2277 u32 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
2278 FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
2280 /* Skip hidden vns */
2281 if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
2284 /* If min rate is zero - set it to 1 */
2286 vn_min_rate = DEF_MIN_RATE;
2290 bp->vn_weight_sum += vn_min_rate;
2293 /* if ETS or all min rates are zeros - disable fairness */
2294 if (BNX2X_IS_ETS_ENABLED(bp)) {
2295 bp->cmng.flags.cmng_enables &=
2296 ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
2297 DP(NETIF_MSG_IFUP, "Fairness will be disabled due to ETS\n");
2298 } else if (all_zero) {
2299 bp->cmng.flags.cmng_enables &=
2300 ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
2301 DP(NETIF_MSG_IFUP, "All MIN values are zeroes"
2302 " fairness will be disabled\n");
2304 bp->cmng.flags.cmng_enables |=
2305 CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
2308 static void bnx2x_init_vn_minmax(struct bnx2x *bp, int vn)
2310 struct rate_shaping_vars_per_vn m_rs_vn;
2311 struct fairness_vars_per_vn m_fair_vn;
2312 u32 vn_cfg = bp->mf_config[vn];
2313 int func = 2*vn + BP_PORT(bp);
2314 u16 vn_min_rate, vn_max_rate;
2317 /* If function is hidden - set min and max to zeroes */
2318 if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE) {
2323 u32 maxCfg = bnx2x_extract_max_cfg(bp, vn_cfg);
2325 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
2326 FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
2327 /* If fairness is enabled (not all min rates are zeroes) and
2328 if current min rate is zero - set it to 1.
2329 This is a requirement of the algorithm. */
2330 if (bp->vn_weight_sum && (vn_min_rate == 0))
2331 vn_min_rate = DEF_MIN_RATE;
2334 /* maxCfg in percents of linkspeed */
2335 vn_max_rate = (bp->link_vars.line_speed * maxCfg) / 100;
2337 /* maxCfg is absolute in 100Mb units */
2338 vn_max_rate = maxCfg * 100;
2342 "func %d: vn_min_rate %d vn_max_rate %d vn_weight_sum %d\n",
2343 func, vn_min_rate, vn_max_rate, bp->vn_weight_sum);
2345 memset(&m_rs_vn, 0, sizeof(struct rate_shaping_vars_per_vn));
2346 memset(&m_fair_vn, 0, sizeof(struct fairness_vars_per_vn));
2348 /* global vn counter - maximal Mbps for this vn */
2349 m_rs_vn.vn_counter.rate = vn_max_rate;
2351 /* quota - number of bytes transmitted in this period */
2352 m_rs_vn.vn_counter.quota =
2353 (vn_max_rate * RS_PERIODIC_TIMEOUT_USEC) / 8;
2355 if (bp->vn_weight_sum) {
2356 /* credit for each period of the fairness algorithm:
2357 number of bytes in T_FAIR (the vn share the port rate).
2358 vn_weight_sum should not be larger than 10000, thus
2359 T_FAIR_COEF / (8 * vn_weight_sum) will always be greater
2361 m_fair_vn.vn_credit_delta =
2362 max_t(u32, (vn_min_rate * (T_FAIR_COEF /
2363 (8 * bp->vn_weight_sum))),
2364 (bp->cmng.fair_vars.fair_threshold +
2366 DP(NETIF_MSG_IFUP, "m_fair_vn.vn_credit_delta %d\n",
2367 m_fair_vn.vn_credit_delta);
2370 /* Store it to internal memory */
2371 for (i = 0; i < sizeof(struct rate_shaping_vars_per_vn)/4; i++)
2372 REG_WR(bp, BAR_XSTRORM_INTMEM +
2373 XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(func) + i * 4,
2374 ((u32 *)(&m_rs_vn))[i]);
2376 for (i = 0; i < sizeof(struct fairness_vars_per_vn)/4; i++)
2377 REG_WR(bp, BAR_XSTRORM_INTMEM +
2378 XSTORM_FAIRNESS_PER_VN_VARS_OFFSET(func) + i * 4,
2379 ((u32 *)(&m_fair_vn))[i]);
2382 static int bnx2x_get_cmng_fns_mode(struct bnx2x *bp)
2384 if (CHIP_REV_IS_SLOW(bp))
2385 return CMNG_FNS_NONE;
2387 return CMNG_FNS_MINMAX;
2389 return CMNG_FNS_NONE;
2392 void bnx2x_read_mf_cfg(struct bnx2x *bp)
2394 int vn, n = (CHIP_MODE_IS_4_PORT(bp) ? 2 : 1);
2397 return; /* what should be the default bvalue in this case */
2399 /* For 2 port configuration the absolute function number formula
2401 * abs_func = 2 * vn + BP_PORT + BP_PATH
2403 * and there are 4 functions per port
2405 * For 4 port configuration it is
2406 * abs_func = 4 * vn + 2 * BP_PORT + BP_PATH
2408 * and there are 2 functions per port
2410 for (vn = VN_0; vn < E1HVN_MAX; vn++) {
2411 int /*abs*/func = n * (2 * vn + BP_PORT(bp)) + BP_PATH(bp);
2413 if (func >= E1H_FUNC_MAX)
2417 MF_CFG_RD(bp, func_mf_config[func].config);
2421 static void bnx2x_cmng_fns_init(struct bnx2x *bp, u8 read_cfg, u8 cmng_type)
2424 if (cmng_type == CMNG_FNS_MINMAX) {
2427 /* clear cmng_enables */
2428 bp->cmng.flags.cmng_enables = 0;
2430 /* read mf conf from shmem */
2432 bnx2x_read_mf_cfg(bp);
2434 /* Init rate shaping and fairness contexts */
2435 bnx2x_init_port_minmax(bp);
2437 /* vn_weight_sum and enable fairness if not 0 */
2438 bnx2x_calc_vn_weight_sum(bp);
2440 /* calculate and set min-max rate for each vn */
2442 for (vn = VN_0; vn < E1HVN_MAX; vn++)
2443 bnx2x_init_vn_minmax(bp, vn);
2445 /* always enable rate shaping and fairness */
2446 bp->cmng.flags.cmng_enables |=
2447 CMNG_FLAGS_PER_PORT_RATE_SHAPING_VN;
2448 if (!bp->vn_weight_sum)
2449 DP(NETIF_MSG_IFUP, "All MIN values are zeroes"
2450 " fairness will be disabled\n");
2454 /* rate shaping and fairness are disabled */
2456 "rate shaping and fairness are disabled\n");
2459 static inline void bnx2x_link_sync_notify(struct bnx2x *bp)
2461 int port = BP_PORT(bp);
2465 /* Set the attention towards other drivers on the same port */
2466 for (vn = VN_0; vn < E1HVN_MAX; vn++) {
2467 if (vn == BP_E1HVN(bp))
2470 func = ((vn << 1) | port);
2471 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_0 +
2472 (LINK_SYNC_ATTENTION_BIT_FUNC_0 + func)*4, 1);
2476 /* This function is called upon link interrupt */
2477 static void bnx2x_link_attn(struct bnx2x *bp)
2479 /* Make sure that we are synced with the current statistics */
2480 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
2482 bnx2x_link_update(&bp->link_params, &bp->link_vars);
2484 if (bp->link_vars.link_up) {
2486 /* dropless flow control */
2487 if (!CHIP_IS_E1(bp) && bp->dropless_fc) {
2488 int port = BP_PORT(bp);
2489 u32 pause_enabled = 0;
2491 if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX)
2494 REG_WR(bp, BAR_USTRORM_INTMEM +
2495 USTORM_ETH_PAUSE_ENABLED_OFFSET(port),
2499 if (bp->link_vars.mac_type != MAC_TYPE_EMAC) {
2500 struct host_port_stats *pstats;
2502 pstats = bnx2x_sp(bp, port_stats);
2503 /* reset old mac stats */
2504 memset(&(pstats->mac_stx[0]), 0,
2505 sizeof(struct mac_stx));
2507 if (bp->state == BNX2X_STATE_OPEN)
2508 bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
2511 if (bp->link_vars.link_up && bp->link_vars.line_speed) {
2512 int cmng_fns = bnx2x_get_cmng_fns_mode(bp);
2514 if (cmng_fns != CMNG_FNS_NONE) {
2515 bnx2x_cmng_fns_init(bp, false, cmng_fns);
2516 storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
2518 /* rate shaping and fairness are disabled */
2520 "single function mode without fairness\n");
2523 __bnx2x_link_report(bp);
2526 bnx2x_link_sync_notify(bp);
2529 void bnx2x__link_status_update(struct bnx2x *bp)
2531 if (bp->state != BNX2X_STATE_OPEN)
2534 bnx2x_link_status_update(&bp->link_params, &bp->link_vars);
2536 if (bp->link_vars.link_up)
2537 bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
2539 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
2541 /* indicate link status */
2542 bnx2x_link_report(bp);
2545 static void bnx2x_pmf_update(struct bnx2x *bp)
2547 int port = BP_PORT(bp);
2551 DP(NETIF_MSG_LINK, "pmf %d\n", bp->port.pmf);
2554 * We need the mb() to ensure the ordering between the writing to
2555 * bp->port.pmf here and reading it from the bnx2x_periodic_task().
2559 /* queue a periodic task */
2560 queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
2562 bnx2x_dcbx_pmf_update(bp);
2564 /* enable nig attention */
2565 val = (0xff0f | (1 << (BP_E1HVN(bp) + 4)));
2566 if (bp->common.int_block == INT_BLOCK_HC) {
2567 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
2568 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
2569 } else if (!CHIP_IS_E1x(bp)) {
2570 REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
2571 REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
2574 bnx2x_stats_handle(bp, STATS_EVENT_PMF);
2582 * General service functions
2585 /* send the MCP a request, block until there is a reply */
2586 u32 bnx2x_fw_command(struct bnx2x *bp, u32 command, u32 param)
2588 int mb_idx = BP_FW_MB_IDX(bp);
2592 u8 delay = CHIP_REV_IS_SLOW(bp) ? 100 : 10;
2594 mutex_lock(&bp->fw_mb_mutex);
2596 SHMEM_WR(bp, func_mb[mb_idx].drv_mb_param, param);
2597 SHMEM_WR(bp, func_mb[mb_idx].drv_mb_header, (command | seq));
2599 DP(BNX2X_MSG_MCP, "wrote command (%x) to FW MB param 0x%08x\n",
2600 (command | seq), param);
2603 /* let the FW do it's magic ... */
2606 rc = SHMEM_RD(bp, func_mb[mb_idx].fw_mb_header);
2608 /* Give the FW up to 5 second (500*10ms) */
2609 } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 500));
2611 DP(BNX2X_MSG_MCP, "[after %d ms] read (%x) seq is (%x) from FW MB\n",
2612 cnt*delay, rc, seq);
2614 /* is this a reply to our command? */
2615 if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK))
2616 rc &= FW_MSG_CODE_MASK;
2619 BNX2X_ERR("FW failed to respond!\n");
2623 mutex_unlock(&bp->fw_mb_mutex);
2628 static u8 stat_counter_valid(struct bnx2x *bp, struct bnx2x_fastpath *fp)
2631 /* Statistics are not supported for CNIC Clients at the moment */
2638 void bnx2x_func_init(struct bnx2x *bp, struct bnx2x_func_init_params *p)
2640 if (CHIP_IS_E1x(bp)) {
2641 struct tstorm_eth_function_common_config tcfg = {0};
2643 storm_memset_func_cfg(bp, &tcfg, p->func_id);
2646 /* Enable the function in the FW */
2647 storm_memset_vf_to_pf(bp, p->func_id, p->pf_id);
2648 storm_memset_func_en(bp, p->func_id, 1);
2651 if (p->func_flgs & FUNC_FLG_SPQ) {
2652 storm_memset_spq_addr(bp, p->spq_map, p->func_id);
2653 REG_WR(bp, XSEM_REG_FAST_MEMORY +
2654 XSTORM_SPQ_PROD_OFFSET(p->func_id), p->spq_prod);
2659 * bnx2x_get_tx_only_flags - Return common flags
2663 * @zero_stats TRUE if statistics zeroing is needed
2665 * Return the flags that are common for the Tx-only and not normal connections.
2667 static inline unsigned long bnx2x_get_common_flags(struct bnx2x *bp,
2668 struct bnx2x_fastpath *fp,
2671 unsigned long flags = 0;
2673 /* PF driver will always initialize the Queue to an ACTIVE state */
2674 __set_bit(BNX2X_Q_FLG_ACTIVE, &flags);
2676 /* tx only connections collect statistics (on the same index as the
2677 * parent connection). The statistics are zeroed when the parent
2678 * connection is initialized.
2680 if (stat_counter_valid(bp, fp)) {
2681 __set_bit(BNX2X_Q_FLG_STATS, &flags);
2683 __set_bit(BNX2X_Q_FLG_ZERO_STATS, &flags);
2689 static inline unsigned long bnx2x_get_q_flags(struct bnx2x *bp,
2690 struct bnx2x_fastpath *fp,
2693 unsigned long flags = 0;
2695 /* calculate other queue flags */
2697 __set_bit(BNX2X_Q_FLG_OV, &flags);
2700 __set_bit(BNX2X_Q_FLG_FCOE, &flags);
2702 if (!fp->disable_tpa)
2703 __set_bit(BNX2X_Q_FLG_TPA, &flags);
2706 __set_bit(BNX2X_Q_FLG_LEADING_RSS, &flags);
2707 __set_bit(BNX2X_Q_FLG_MCAST, &flags);
2710 /* Always set HW VLAN stripping */
2711 __set_bit(BNX2X_Q_FLG_VLAN, &flags);
2714 return flags | bnx2x_get_common_flags(bp, fp, true);
2717 static void bnx2x_pf_q_prep_general(struct bnx2x *bp,
2718 struct bnx2x_fastpath *fp, struct bnx2x_general_setup_params *gen_init,
2721 gen_init->stat_id = bnx2x_stats_id(fp);
2722 gen_init->spcl_id = fp->cl_id;
2724 /* Always use mini-jumbo MTU for FCoE L2 ring */
2726 gen_init->mtu = BNX2X_FCOE_MINI_JUMBO_MTU;
2728 gen_init->mtu = bp->dev->mtu;
2730 gen_init->cos = cos;
2733 static void bnx2x_pf_rx_q_prep(struct bnx2x *bp,
2734 struct bnx2x_fastpath *fp, struct rxq_pause_params *pause,
2735 struct bnx2x_rxq_setup_params *rxq_init)
2739 u16 tpa_agg_size = 0;
2741 if (!fp->disable_tpa) {
2742 pause->sge_th_hi = 250;
2743 pause->sge_th_lo = 150;
2744 tpa_agg_size = min_t(u32,
2745 (min_t(u32, 8, MAX_SKB_FRAGS) *
2746 SGE_PAGE_SIZE * PAGES_PER_SGE), 0xffff);
2747 max_sge = SGE_PAGE_ALIGN(bp->dev->mtu) >>
2749 max_sge = ((max_sge + PAGES_PER_SGE - 1) &
2750 (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
2751 sge_sz = (u16)min_t(u32, SGE_PAGE_SIZE * PAGES_PER_SGE,
2755 /* pause - not for e1 */
2756 if (!CHIP_IS_E1(bp)) {
2757 pause->bd_th_hi = 350;
2758 pause->bd_th_lo = 250;
2759 pause->rcq_th_hi = 350;
2760 pause->rcq_th_lo = 250;
2766 rxq_init->dscr_map = fp->rx_desc_mapping;
2767 rxq_init->sge_map = fp->rx_sge_mapping;
2768 rxq_init->rcq_map = fp->rx_comp_mapping;
2769 rxq_init->rcq_np_map = fp->rx_comp_mapping + BCM_PAGE_SIZE;
2771 /* This should be a maximum number of data bytes that may be
2772 * placed on the BD (not including paddings).
2774 rxq_init->buf_sz = fp->rx_buf_size - BNX2X_FW_RX_ALIGN -
2775 IP_HEADER_ALIGNMENT_PADDING;
2777 rxq_init->cl_qzone_id = fp->cl_qzone_id;
2778 rxq_init->tpa_agg_sz = tpa_agg_size;
2779 rxq_init->sge_buf_sz = sge_sz;
2780 rxq_init->max_sges_pkt = max_sge;
2781 rxq_init->rss_engine_id = BP_FUNC(bp);
2783 /* Maximum number or simultaneous TPA aggregation for this Queue.
2785 * For PF Clients it should be the maximum avaliable number.
2786 * VF driver(s) may want to define it to a smaller value.
2788 rxq_init->max_tpa_queues =
2789 (CHIP_IS_E1(bp) ? ETH_MAX_AGGREGATION_QUEUES_E1 :
2790 ETH_MAX_AGGREGATION_QUEUES_E1H_E2);
2792 rxq_init->cache_line_log = BNX2X_RX_ALIGN_SHIFT;
2793 rxq_init->fw_sb_id = fp->fw_sb_id;
2796 rxq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_RX_CQ_CONS;
2798 rxq_init->sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
2801 static void bnx2x_pf_tx_q_prep(struct bnx2x *bp,
2802 struct bnx2x_fastpath *fp, struct bnx2x_txq_setup_params *txq_init,
2805 txq_init->dscr_map = fp->txdata[cos].tx_desc_mapping;
2806 txq_init->sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS + cos;
2807 txq_init->traffic_type = LLFC_TRAFFIC_TYPE_NW;
2808 txq_init->fw_sb_id = fp->fw_sb_id;
2811 * set the tss leading client id for TX classfication ==
2812 * leading RSS client id
2814 txq_init->tss_leading_cl_id = bnx2x_fp(bp, 0, cl_id);
2816 if (IS_FCOE_FP(fp)) {
2817 txq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_TX_CQ_CONS;
2818 txq_init->traffic_type = LLFC_TRAFFIC_TYPE_FCOE;
2822 static void bnx2x_pf_init(struct bnx2x *bp)
2824 struct bnx2x_func_init_params func_init = {0};
2825 struct event_ring_data eq_data = { {0} };
2828 if (!CHIP_IS_E1x(bp)) {
2829 /* reset IGU PF statistics: MSIX + ATTN */
2831 REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
2832 BNX2X_IGU_STAS_MSG_VF_CNT*4 +
2833 (CHIP_MODE_IS_4_PORT(bp) ?
2834 BP_FUNC(bp) : BP_VN(bp))*4, 0);
2836 REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
2837 BNX2X_IGU_STAS_MSG_VF_CNT*4 +
2838 BNX2X_IGU_STAS_MSG_PF_CNT*4 +
2839 (CHIP_MODE_IS_4_PORT(bp) ?
2840 BP_FUNC(bp) : BP_VN(bp))*4, 0);
2843 /* function setup flags */
2844 flags = (FUNC_FLG_STATS | FUNC_FLG_LEADING | FUNC_FLG_SPQ);
2846 /* This flag is relevant for E1x only.
2847 * E2 doesn't have a TPA configuration in a function level.
2849 flags |= (bp->flags & TPA_ENABLE_FLAG) ? FUNC_FLG_TPA : 0;
2851 func_init.func_flgs = flags;
2852 func_init.pf_id = BP_FUNC(bp);
2853 func_init.func_id = BP_FUNC(bp);
2854 func_init.spq_map = bp->spq_mapping;
2855 func_init.spq_prod = bp->spq_prod_idx;
2857 bnx2x_func_init(bp, &func_init);
2859 memset(&(bp->cmng), 0, sizeof(struct cmng_struct_per_port));
2862 * Congestion management values depend on the link rate
2863 * There is no active link so initial link rate is set to 10 Gbps.
2864 * When the link comes up The congestion management values are
2865 * re-calculated according to the actual link rate.
2867 bp->link_vars.line_speed = SPEED_10000;
2868 bnx2x_cmng_fns_init(bp, true, bnx2x_get_cmng_fns_mode(bp));
2870 /* Only the PMF sets the HW */
2872 storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
2874 /* init Event Queue */
2875 eq_data.base_addr.hi = U64_HI(bp->eq_mapping);
2876 eq_data.base_addr.lo = U64_LO(bp->eq_mapping);
2877 eq_data.producer = bp->eq_prod;
2878 eq_data.index_id = HC_SP_INDEX_EQ_CONS;
2879 eq_data.sb_id = DEF_SB_ID;
2880 storm_memset_eq_data(bp, &eq_data, BP_FUNC(bp));
2884 static void bnx2x_e1h_disable(struct bnx2x *bp)
2886 int port = BP_PORT(bp);
2888 bnx2x_tx_disable(bp);
2890 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
2893 static void bnx2x_e1h_enable(struct bnx2x *bp)
2895 int port = BP_PORT(bp);
2897 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
2899 /* Tx queue should be only reenabled */
2900 netif_tx_wake_all_queues(bp->dev);
2903 * Should not call netif_carrier_on since it will be called if the link
2904 * is up when checking for link state
2908 /* called due to MCP event (on pmf):
2909 * reread new bandwidth configuration
2911 * notify others function about the change
2913 static inline void bnx2x_config_mf_bw(struct bnx2x *bp)
2915 if (bp->link_vars.link_up) {
2916 bnx2x_cmng_fns_init(bp, true, CMNG_FNS_MINMAX);
2917 bnx2x_link_sync_notify(bp);
2919 storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
2922 static inline void bnx2x_set_mf_bw(struct bnx2x *bp)
2924 bnx2x_config_mf_bw(bp);
2925 bnx2x_fw_command(bp, DRV_MSG_CODE_SET_MF_BW_ACK, 0);
2928 static void bnx2x_dcc_event(struct bnx2x *bp, u32 dcc_event)
2930 DP(BNX2X_MSG_MCP, "dcc_event 0x%x\n", dcc_event);
2932 if (dcc_event & DRV_STATUS_DCC_DISABLE_ENABLE_PF) {
2935 * This is the only place besides the function initialization
2936 * where the bp->flags can change so it is done without any
2939 if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
2940 DP(NETIF_MSG_IFDOWN, "mf_cfg function disabled\n");
2941 bp->flags |= MF_FUNC_DIS;
2943 bnx2x_e1h_disable(bp);
2945 DP(NETIF_MSG_IFUP, "mf_cfg function enabled\n");
2946 bp->flags &= ~MF_FUNC_DIS;
2948 bnx2x_e1h_enable(bp);
2950 dcc_event &= ~DRV_STATUS_DCC_DISABLE_ENABLE_PF;
2952 if (dcc_event & DRV_STATUS_DCC_BANDWIDTH_ALLOCATION) {
2953 bnx2x_config_mf_bw(bp);
2954 dcc_event &= ~DRV_STATUS_DCC_BANDWIDTH_ALLOCATION;
2957 /* Report results to MCP */
2959 bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_FAILURE, 0);
2961 bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_OK, 0);
2964 /* must be called under the spq lock */
2965 static inline struct eth_spe *bnx2x_sp_get_next(struct bnx2x *bp)
2967 struct eth_spe *next_spe = bp->spq_prod_bd;
2969 if (bp->spq_prod_bd == bp->spq_last_bd) {
2970 bp->spq_prod_bd = bp->spq;
2971 bp->spq_prod_idx = 0;
2972 DP(NETIF_MSG_TIMER, "end of spq\n");
2980 /* must be called under the spq lock */
2981 static inline void bnx2x_sp_prod_update(struct bnx2x *bp)
2983 int func = BP_FUNC(bp);
2985 /* Make sure that BD data is updated before writing the producer */
2988 REG_WR16(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func),
2994 * bnx2x_is_contextless_ramrod - check if the current command ends on EQ
2996 * @cmd: command to check
2997 * @cmd_type: command type
2999 static inline bool bnx2x_is_contextless_ramrod(int cmd, int cmd_type)
3001 if ((cmd_type == NONE_CONNECTION_TYPE) ||
3002 (cmd == RAMROD_CMD_ID_ETH_FORWARD_SETUP) ||
3003 (cmd == RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES) ||
3004 (cmd == RAMROD_CMD_ID_ETH_FILTER_RULES) ||
3005 (cmd == RAMROD_CMD_ID_ETH_MULTICAST_RULES) ||
3006 (cmd == RAMROD_CMD_ID_ETH_SET_MAC) ||
3007 (cmd == RAMROD_CMD_ID_ETH_RSS_UPDATE))
3016 * bnx2x_sp_post - place a single command on an SP ring
3018 * @bp: driver handle
3019 * @command: command to place (e.g. SETUP, FILTER_RULES, etc.)
3020 * @cid: SW CID the command is related to
3021 * @data_hi: command private data address (high 32 bits)
3022 * @data_lo: command private data address (low 32 bits)
3023 * @cmd_type: command type (e.g. NONE, ETH)
3025 * SP data is handled as if it's always an address pair, thus data fields are
3026 * not swapped to little endian in upper functions. Instead this function swaps
3027 * data as if it's two u32 fields.
3029 int bnx2x_sp_post(struct bnx2x *bp, int command, int cid,
3030 u32 data_hi, u32 data_lo, int cmd_type)
3032 struct eth_spe *spe;
3034 bool common = bnx2x_is_contextless_ramrod(command, cmd_type);
3036 #ifdef BNX2X_STOP_ON_ERROR
3037 if (unlikely(bp->panic))
3041 spin_lock_bh(&bp->spq_lock);
3044 if (!atomic_read(&bp->eq_spq_left)) {
3045 BNX2X_ERR("BUG! EQ ring full!\n");
3046 spin_unlock_bh(&bp->spq_lock);
3050 } else if (!atomic_read(&bp->cq_spq_left)) {
3051 BNX2X_ERR("BUG! SPQ ring full!\n");
3052 spin_unlock_bh(&bp->spq_lock);
3057 spe = bnx2x_sp_get_next(bp);
3059 /* CID needs port number to be encoded int it */
3060 spe->hdr.conn_and_cmd_data =
3061 cpu_to_le32((command << SPE_HDR_CMD_ID_SHIFT) |
3064 type = (cmd_type << SPE_HDR_CONN_TYPE_SHIFT) & SPE_HDR_CONN_TYPE;
3066 type |= ((BP_FUNC(bp) << SPE_HDR_FUNCTION_ID_SHIFT) &
3067 SPE_HDR_FUNCTION_ID);
3069 spe->hdr.type = cpu_to_le16(type);
3071 spe->data.update_data_addr.hi = cpu_to_le32(data_hi);
3072 spe->data.update_data_addr.lo = cpu_to_le32(data_lo);
3074 /* stats ramrod has it's own slot on the spq */
3075 if (command != RAMROD_CMD_ID_COMMON_STAT_QUERY) {
3077 * It's ok if the actual decrement is issued towards the memory
3078 * somewhere between the spin_lock and spin_unlock. Thus no
3079 * more explict memory barrier is needed.
3082 atomic_dec(&bp->eq_spq_left);
3084 atomic_dec(&bp->cq_spq_left);
3088 DP(BNX2X_MSG_SP/*NETIF_MSG_TIMER*/,
3089 "SPQE[%x] (%x:%x) command %d hw_cid %x data (%x:%x) "
3090 "type(0x%x) left (ETH, COMMON) (%x,%x)\n",
3091 bp->spq_prod_idx, (u32)U64_HI(bp->spq_mapping),
3092 (u32)(U64_LO(bp->spq_mapping) +
3093 (void *)bp->spq_prod_bd - (void *)bp->spq), command,
3094 HW_CID(bp, cid), data_hi, data_lo, type,
3095 atomic_read(&bp->cq_spq_left), atomic_read(&bp->eq_spq_left));
3097 bnx2x_sp_prod_update(bp);
3098 spin_unlock_bh(&bp->spq_lock);
3102 /* acquire split MCP access lock register */
3103 static int bnx2x_acquire_alr(struct bnx2x *bp)
3109 for (j = 0; j < 1000; j++) {
3111 REG_WR(bp, GRCBASE_MCP + 0x9c, val);
3112 val = REG_RD(bp, GRCBASE_MCP + 0x9c);
3113 if (val & (1L << 31))
3118 if (!(val & (1L << 31))) {
3119 BNX2X_ERR("Cannot acquire MCP access lock register\n");
3126 /* release split MCP access lock register */
3127 static void bnx2x_release_alr(struct bnx2x *bp)
3129 REG_WR(bp, GRCBASE_MCP + 0x9c, 0);
3132 #define BNX2X_DEF_SB_ATT_IDX 0x0001
3133 #define BNX2X_DEF_SB_IDX 0x0002
3135 static inline u16 bnx2x_update_dsb_idx(struct bnx2x *bp)
3137 struct host_sp_status_block *def_sb = bp->def_status_blk;
3140 barrier(); /* status block is written to by the chip */
3141 if (bp->def_att_idx != def_sb->atten_status_block.attn_bits_index) {
3142 bp->def_att_idx = def_sb->atten_status_block.attn_bits_index;
3143 rc |= BNX2X_DEF_SB_ATT_IDX;
3146 if (bp->def_idx != def_sb->sp_sb.running_index) {
3147 bp->def_idx = def_sb->sp_sb.running_index;
3148 rc |= BNX2X_DEF_SB_IDX;
3151 /* Do not reorder: indecies reading should complete before handling */
3157 * slow path service functions
3160 static void bnx2x_attn_int_asserted(struct bnx2x *bp, u32 asserted)
3162 int port = BP_PORT(bp);
3163 u32 aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
3164 MISC_REG_AEU_MASK_ATTN_FUNC_0;
3165 u32 nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 :
3166 NIG_REG_MASK_INTERRUPT_PORT0;
3171 if (bp->attn_state & asserted)
3172 BNX2X_ERR("IGU ERROR\n");
3174 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
3175 aeu_mask = REG_RD(bp, aeu_addr);
3177 DP(NETIF_MSG_HW, "aeu_mask %x newly asserted %x\n",
3178 aeu_mask, asserted);
3179 aeu_mask &= ~(asserted & 0x3ff);
3180 DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
3182 REG_WR(bp, aeu_addr, aeu_mask);
3183 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
3185 DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
3186 bp->attn_state |= asserted;
3187 DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
3189 if (asserted & ATTN_HARD_WIRED_MASK) {
3190 if (asserted & ATTN_NIG_FOR_FUNC) {
3192 bnx2x_acquire_phy_lock(bp);
3194 /* save nig interrupt mask */
3195 nig_mask = REG_RD(bp, nig_int_mask_addr);
3197 /* If nig_mask is not set, no need to call the update
3201 REG_WR(bp, nig_int_mask_addr, 0);
3203 bnx2x_link_attn(bp);
3206 /* handle unicore attn? */
3208 if (asserted & ATTN_SW_TIMER_4_FUNC)
3209 DP(NETIF_MSG_HW, "ATTN_SW_TIMER_4_FUNC!\n");
3211 if (asserted & GPIO_2_FUNC)
3212 DP(NETIF_MSG_HW, "GPIO_2_FUNC!\n");
3214 if (asserted & GPIO_3_FUNC)
3215 DP(NETIF_MSG_HW, "GPIO_3_FUNC!\n");
3217 if (asserted & GPIO_4_FUNC)
3218 DP(NETIF_MSG_HW, "GPIO_4_FUNC!\n");
3221 if (asserted & ATTN_GENERAL_ATTN_1) {
3222 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_1!\n");
3223 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_1, 0x0);
3225 if (asserted & ATTN_GENERAL_ATTN_2) {
3226 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_2!\n");
3227 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_2, 0x0);
3229 if (asserted & ATTN_GENERAL_ATTN_3) {
3230 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_3!\n");
3231 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_3, 0x0);
3234 if (asserted & ATTN_GENERAL_ATTN_4) {
3235 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_4!\n");
3236 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_4, 0x0);
3238 if (asserted & ATTN_GENERAL_ATTN_5) {
3239 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_5!\n");
3240 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_5, 0x0);
3242 if (asserted & ATTN_GENERAL_ATTN_6) {
3243 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_6!\n");
3244 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_6, 0x0);
3248 } /* if hardwired */
3250 if (bp->common.int_block == INT_BLOCK_HC)
3251 reg_addr = (HC_REG_COMMAND_REG + port*32 +
3252 COMMAND_REG_ATTN_BITS_SET);
3254 reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_SET_UPPER*8);
3256 DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", asserted,
3257 (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
3258 REG_WR(bp, reg_addr, asserted);
3260 /* now set back the mask */
3261 if (asserted & ATTN_NIG_FOR_FUNC) {
3262 REG_WR(bp, nig_int_mask_addr, nig_mask);
3263 bnx2x_release_phy_lock(bp);
3267 static inline void bnx2x_fan_failure(struct bnx2x *bp)
3269 int port = BP_PORT(bp);
3271 /* mark the failure */
3274 dev_info.port_hw_config[port].external_phy_config);
3276 ext_phy_config &= ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK;
3277 ext_phy_config |= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE;
3278 SHMEM_WR(bp, dev_info.port_hw_config[port].external_phy_config,
3281 /* log the failure */
3282 netdev_err(bp->dev, "Fan Failure on Network Controller has caused"
3283 " the driver to shutdown the card to prevent permanent"
3284 " damage. Please contact OEM Support for assistance\n");
3287 static inline void bnx2x_attn_int_deasserted0(struct bnx2x *bp, u32 attn)
3289 int port = BP_PORT(bp);
3293 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
3294 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
3296 if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) {
3298 val = REG_RD(bp, reg_offset);
3299 val &= ~AEU_INPUTS_ATTN_BITS_SPIO5;
3300 REG_WR(bp, reg_offset, val);
3302 BNX2X_ERR("SPIO5 hw attention\n");
3304 /* Fan failure attention */
3305 bnx2x_hw_reset_phy(&bp->link_params);
3306 bnx2x_fan_failure(bp);
3309 if ((attn & bp->link_vars.aeu_int_mask) && bp->port.pmf) {
3310 bnx2x_acquire_phy_lock(bp);
3311 bnx2x_handle_module_detect_int(&bp->link_params);
3312 bnx2x_release_phy_lock(bp);
3315 if (attn & HW_INTERRUT_ASSERT_SET_0) {
3317 val = REG_RD(bp, reg_offset);
3318 val &= ~(attn & HW_INTERRUT_ASSERT_SET_0);
3319 REG_WR(bp, reg_offset, val);
3321 BNX2X_ERR("FATAL HW block attention set0 0x%x\n",
3322 (u32)(attn & HW_INTERRUT_ASSERT_SET_0));
3327 static inline void bnx2x_attn_int_deasserted1(struct bnx2x *bp, u32 attn)
3331 if (attn & AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT) {
3333 val = REG_RD(bp, DORQ_REG_DORQ_INT_STS_CLR);
3334 BNX2X_ERR("DB hw attention 0x%x\n", val);
3335 /* DORQ discard attention */
3337 BNX2X_ERR("FATAL error from DORQ\n");
3340 if (attn & HW_INTERRUT_ASSERT_SET_1) {
3342 int port = BP_PORT(bp);
3345 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 :
3346 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1);
3348 val = REG_RD(bp, reg_offset);
3349 val &= ~(attn & HW_INTERRUT_ASSERT_SET_1);
3350 REG_WR(bp, reg_offset, val);
3352 BNX2X_ERR("FATAL HW block attention set1 0x%x\n",
3353 (u32)(attn & HW_INTERRUT_ASSERT_SET_1));
3358 static inline void bnx2x_attn_int_deasserted2(struct bnx2x *bp, u32 attn)
3362 if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) {
3364 val = REG_RD(bp, CFC_REG_CFC_INT_STS_CLR);
3365 BNX2X_ERR("CFC hw attention 0x%x\n", val);
3366 /* CFC error attention */
3368 BNX2X_ERR("FATAL error from CFC\n");
3371 if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) {
3372 val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_0);
3373 BNX2X_ERR("PXP hw attention-0 0x%x\n", val);
3374 /* RQ_USDMDP_FIFO_OVERFLOW */
3376 BNX2X_ERR("FATAL error from PXP\n");
3378 if (!CHIP_IS_E1x(bp)) {
3379 val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_1);
3380 BNX2X_ERR("PXP hw attention-1 0x%x\n", val);
3384 if (attn & HW_INTERRUT_ASSERT_SET_2) {
3386 int port = BP_PORT(bp);
3389 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 :
3390 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2);
3392 val = REG_RD(bp, reg_offset);
3393 val &= ~(attn & HW_INTERRUT_ASSERT_SET_2);
3394 REG_WR(bp, reg_offset, val);
3396 BNX2X_ERR("FATAL HW block attention set2 0x%x\n",
3397 (u32)(attn & HW_INTERRUT_ASSERT_SET_2));
3402 static inline void bnx2x_attn_int_deasserted3(struct bnx2x *bp, u32 attn)
3406 if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) {
3408 if (attn & BNX2X_PMF_LINK_ASSERT) {
3409 int func = BP_FUNC(bp);
3411 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
3412 bp->mf_config[BP_VN(bp)] = MF_CFG_RD(bp,
3413 func_mf_config[BP_ABS_FUNC(bp)].config);
3415 func_mb[BP_FW_MB_IDX(bp)].drv_status);
3416 if (val & DRV_STATUS_DCC_EVENT_MASK)
3418 (val & DRV_STATUS_DCC_EVENT_MASK));
3420 if (val & DRV_STATUS_SET_MF_BW)
3421 bnx2x_set_mf_bw(bp);
3423 if ((bp->port.pmf == 0) && (val & DRV_STATUS_PMF))
3424 bnx2x_pmf_update(bp);
3427 (val & DRV_STATUS_DCBX_NEGOTIATION_RESULTS) &&
3428 bp->dcbx_enabled > 0)
3429 /* start dcbx state machine */
3430 bnx2x_dcbx_set_params(bp,
3431 BNX2X_DCBX_STATE_NEG_RECEIVED);
3432 if (bp->link_vars.periodic_flags &
3433 PERIODIC_FLAGS_LINK_EVENT) {
3434 /* sync with link */
3435 bnx2x_acquire_phy_lock(bp);
3436 bp->link_vars.periodic_flags &=
3437 ~PERIODIC_FLAGS_LINK_EVENT;
3438 bnx2x_release_phy_lock(bp);
3440 bnx2x_link_sync_notify(bp);
3441 bnx2x_link_report(bp);
3443 /* Always call it here: bnx2x_link_report() will
3444 * prevent the link indication duplication.
3446 bnx2x__link_status_update(bp);
3447 } else if (attn & BNX2X_MC_ASSERT_BITS) {
3449 BNX2X_ERR("MC assert!\n");
3450 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_10, 0);
3451 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_9, 0);
3452 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_8, 0);
3453 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_7, 0);
3456 } else if (attn & BNX2X_MCP_ASSERT) {
3458 BNX2X_ERR("MCP assert!\n");
3459 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_11, 0);
3463 BNX2X_ERR("Unknown HW assert! (attn 0x%x)\n", attn);
3466 if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) {
3467 BNX2X_ERR("LATCHED attention 0x%08x (masked)\n", attn);
3468 if (attn & BNX2X_GRC_TIMEOUT) {
3469 val = CHIP_IS_E1(bp) ? 0 :
3470 REG_RD(bp, MISC_REG_GRC_TIMEOUT_ATTN);
3471 BNX2X_ERR("GRC time-out 0x%08x\n", val);
3473 if (attn & BNX2X_GRC_RSV) {
3474 val = CHIP_IS_E1(bp) ? 0 :
3475 REG_RD(bp, MISC_REG_GRC_RSV_ATTN);
3476 BNX2X_ERR("GRC reserved 0x%08x\n", val);
3478 REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff);
3484 * 0-7 - Engine0 load counter.
3485 * 8-15 - Engine1 load counter.
3486 * 16 - Engine0 RESET_IN_PROGRESS bit.
3487 * 17 - Engine1 RESET_IN_PROGRESS bit.
3488 * 18 - Engine0 ONE_IS_LOADED. Set when there is at least one active function
3490 * 19 - Engine1 ONE_IS_LOADED.
3491 * 20 - Chip reset flow bit. When set none-leader must wait for both engines
3492 * leader to complete (check for both RESET_IN_PROGRESS bits and not for
3493 * just the one belonging to its engine).
3496 #define BNX2X_RECOVERY_GLOB_REG MISC_REG_GENERIC_POR_1
3498 #define BNX2X_PATH0_LOAD_CNT_MASK 0x000000ff
3499 #define BNX2X_PATH0_LOAD_CNT_SHIFT 0
3500 #define BNX2X_PATH1_LOAD_CNT_MASK 0x0000ff00
3501 #define BNX2X_PATH1_LOAD_CNT_SHIFT 8
3502 #define BNX2X_PATH0_RST_IN_PROG_BIT 0x00010000
3503 #define BNX2X_PATH1_RST_IN_PROG_BIT 0x00020000
3504 #define BNX2X_GLOBAL_RESET_BIT 0x00040000
3507 * Set the GLOBAL_RESET bit.
3509 * Should be run under rtnl lock
3511 void bnx2x_set_reset_global(struct bnx2x *bp)
3513 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3515 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val | BNX2X_GLOBAL_RESET_BIT);
3521 * Clear the GLOBAL_RESET bit.
3523 * Should be run under rtnl lock
3525 static inline void bnx2x_clear_reset_global(struct bnx2x *bp)
3527 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3529 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~BNX2X_GLOBAL_RESET_BIT));
3535 * Checks the GLOBAL_RESET bit.
3537 * should be run under rtnl lock
3539 static inline bool bnx2x_reset_is_global(struct bnx2x *bp)
3541 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3543 DP(NETIF_MSG_HW, "GEN_REG_VAL=0x%08x\n", val);
3544 return (val & BNX2X_GLOBAL_RESET_BIT) ? true : false;
3548 * Clear RESET_IN_PROGRESS bit for the current engine.
3550 * Should be run under rtnl lock
3552 static inline void bnx2x_set_reset_done(struct bnx2x *bp)
3554 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3555 u32 bit = BP_PATH(bp) ?
3556 BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
3560 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
3566 * Set RESET_IN_PROGRESS for the current engine.
3568 * should be run under rtnl lock
3570 void bnx2x_set_reset_in_progress(struct bnx2x *bp)
3572 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3573 u32 bit = BP_PATH(bp) ?
3574 BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
3578 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
3584 * Checks the RESET_IN_PROGRESS bit for the given engine.
3585 * should be run under rtnl lock
3587 bool bnx2x_reset_is_done(struct bnx2x *bp, int engine)
3589 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3591 BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
3593 /* return false if bit is set */
3594 return (val & bit) ? false : true;
3598 * Increment the load counter for the current engine.
3600 * should be run under rtnl lock
3602 void bnx2x_inc_load_cnt(struct bnx2x *bp)
3604 u32 val1, val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3605 u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
3606 BNX2X_PATH0_LOAD_CNT_MASK;
3607 u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
3608 BNX2X_PATH0_LOAD_CNT_SHIFT;
3610 DP(NETIF_MSG_HW, "Old GEN_REG_VAL=0x%08x\n", val);
3612 /* get the current counter value */
3613 val1 = (val & mask) >> shift;
3618 /* clear the old value */
3621 /* set the new one */
3622 val |= ((val1 << shift) & mask);
3624 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
3630 * bnx2x_dec_load_cnt - decrement the load counter
3632 * @bp: driver handle
3634 * Should be run under rtnl lock.
3635 * Decrements the load counter for the current engine. Returns
3636 * the new counter value.
3638 u32 bnx2x_dec_load_cnt(struct bnx2x *bp)
3640 u32 val1, val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3641 u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
3642 BNX2X_PATH0_LOAD_CNT_MASK;
3643 u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
3644 BNX2X_PATH0_LOAD_CNT_SHIFT;
3646 DP(NETIF_MSG_HW, "Old GEN_REG_VAL=0x%08x\n", val);
3648 /* get the current counter value */
3649 val1 = (val & mask) >> shift;
3654 /* clear the old value */
3657 /* set the new one */
3658 val |= ((val1 << shift) & mask);
3660 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
3668 * Read the load counter for the current engine.
3670 * should be run under rtnl lock
3672 static inline u32 bnx2x_get_load_cnt(struct bnx2x *bp, int engine)
3674 u32 mask = (engine ? BNX2X_PATH1_LOAD_CNT_MASK :
3675 BNX2X_PATH0_LOAD_CNT_MASK);
3676 u32 shift = (engine ? BNX2X_PATH1_LOAD_CNT_SHIFT :
3677 BNX2X_PATH0_LOAD_CNT_SHIFT);
3678 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3680 DP(NETIF_MSG_HW, "GLOB_REG=0x%08x\n", val);
3682 val = (val & mask) >> shift;
3684 DP(NETIF_MSG_HW, "load_cnt for engine %d = %d\n", engine, val);
3690 * Reset the load counter for the current engine.
3692 * should be run under rtnl lock
3694 static inline void bnx2x_clear_load_cnt(struct bnx2x *bp)
3696 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3697 u32 mask = (BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
3698 BNX2X_PATH0_LOAD_CNT_MASK);
3700 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~mask));
3703 static inline void _print_next_block(int idx, const char *blk)
3710 static inline int bnx2x_check_blocks_with_parity0(u32 sig, int par_num,
3715 for (i = 0; sig; i++) {
3716 cur_bit = ((u32)0x1 << i);
3717 if (sig & cur_bit) {
3719 case AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR:
3721 _print_next_block(par_num++, "BRB");
3723 case AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR:
3725 _print_next_block(par_num++, "PARSER");
3727 case AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR:
3729 _print_next_block(par_num++, "TSDM");
3731 case AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR:
3733 _print_next_block(par_num++,
3736 case AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR:
3738 _print_next_block(par_num++, "TCM");
3740 case AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR:
3742 _print_next_block(par_num++, "TSEMI");
3744 case AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR:
3746 _print_next_block(par_num++, "XPB");
3758 static inline int bnx2x_check_blocks_with_parity1(u32 sig, int par_num,
3759 bool *global, bool print)
3763 for (i = 0; sig; i++) {
3764 cur_bit = ((u32)0x1 << i);
3765 if (sig & cur_bit) {
3767 case AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR:
3769 _print_next_block(par_num++, "PBF");
3771 case AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR:
3773 _print_next_block(par_num++, "QM");
3775 case AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR:
3777 _print_next_block(par_num++, "TM");
3779 case AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR:
3781 _print_next_block(par_num++, "XSDM");
3783 case AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR:
3785 _print_next_block(par_num++, "XCM");
3787 case AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR:
3789 _print_next_block(par_num++, "XSEMI");
3791 case AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR:
3793 _print_next_block(par_num++,
3796 case AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR:
3798 _print_next_block(par_num++, "NIG");
3800 case AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR:
3802 _print_next_block(par_num++,
3806 case AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR:
3808 _print_next_block(par_num++, "DEBUG");
3810 case AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR:
3812 _print_next_block(par_num++, "USDM");
3814 case AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR:
3816 _print_next_block(par_num++, "USEMI");
3818 case AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR:
3820 _print_next_block(par_num++, "UPB");
3822 case AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR:
3824 _print_next_block(par_num++, "CSDM");
3836 static inline int bnx2x_check_blocks_with_parity2(u32 sig, int par_num,
3841 for (i = 0; sig; i++) {
3842 cur_bit = ((u32)0x1 << i);
3843 if (sig & cur_bit) {
3845 case AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR:
3847 _print_next_block(par_num++, "CSEMI");
3849 case AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR:
3851 _print_next_block(par_num++, "PXP");
3853 case AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR:
3855 _print_next_block(par_num++,
3856 "PXPPCICLOCKCLIENT");
3858 case AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR:
3860 _print_next_block(par_num++, "CFC");
3862 case AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR:
3864 _print_next_block(par_num++, "CDU");
3866 case AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR:
3868 _print_next_block(par_num++, "DMAE");
3870 case AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR:
3872 _print_next_block(par_num++, "IGU");
3874 case AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR:
3876 _print_next_block(par_num++, "MISC");
3888 static inline int bnx2x_check_blocks_with_parity3(u32 sig, int par_num,
3889 bool *global, bool print)
3893 for (i = 0; sig; i++) {
3894 cur_bit = ((u32)0x1 << i);
3895 if (sig & cur_bit) {
3897 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY:
3899 _print_next_block(par_num++, "MCP ROM");
3902 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY:
3904 _print_next_block(par_num++,
3908 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY:
3910 _print_next_block(par_num++,
3914 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY:
3916 _print_next_block(par_num++,
3930 static inline bool bnx2x_parity_attn(struct bnx2x *bp, bool *global, bool print,
3931 u32 sig0, u32 sig1, u32 sig2, u32 sig3)
3933 if ((sig0 & HW_PRTY_ASSERT_SET_0) || (sig1 & HW_PRTY_ASSERT_SET_1) ||
3934 (sig2 & HW_PRTY_ASSERT_SET_2) || (sig3 & HW_PRTY_ASSERT_SET_3)) {
3936 DP(NETIF_MSG_HW, "Was parity error: HW block parity attention: "
3937 "[0]:0x%08x [1]:0x%08x "
3938 "[2]:0x%08x [3]:0x%08x\n",
3939 sig0 & HW_PRTY_ASSERT_SET_0,
3940 sig1 & HW_PRTY_ASSERT_SET_1,
3941 sig2 & HW_PRTY_ASSERT_SET_2,
3942 sig3 & HW_PRTY_ASSERT_SET_3);
3945 "Parity errors detected in blocks: ");
3946 par_num = bnx2x_check_blocks_with_parity0(
3947 sig0 & HW_PRTY_ASSERT_SET_0, par_num, print);
3948 par_num = bnx2x_check_blocks_with_parity1(
3949 sig1 & HW_PRTY_ASSERT_SET_1, par_num, global, print);
3950 par_num = bnx2x_check_blocks_with_parity2(
3951 sig2 & HW_PRTY_ASSERT_SET_2, par_num, print);
3952 par_num = bnx2x_check_blocks_with_parity3(
3953 sig3 & HW_PRTY_ASSERT_SET_3, par_num, global, print);
3962 * bnx2x_chk_parity_attn - checks for parity attentions.
3964 * @bp: driver handle
3965 * @global: true if there was a global attention
3966 * @print: show parity attention in syslog
3968 bool bnx2x_chk_parity_attn(struct bnx2x *bp, bool *global, bool print)
3970 struct attn_route attn;
3971 int port = BP_PORT(bp);
3973 attn.sig[0] = REG_RD(bp,
3974 MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 +
3976 attn.sig[1] = REG_RD(bp,
3977 MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 +
3979 attn.sig[2] = REG_RD(bp,
3980 MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 +
3982 attn.sig[3] = REG_RD(bp,
3983 MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 +
3986 return bnx2x_parity_attn(bp, global, print, attn.sig[0], attn.sig[1],
3987 attn.sig[2], attn.sig[3]);
3991 static inline void bnx2x_attn_int_deasserted4(struct bnx2x *bp, u32 attn)
3994 if (attn & AEU_INPUTS_ATTN_BITS_PGLUE_HW_INTERRUPT) {
3996 val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS_CLR);
3997 BNX2X_ERR("PGLUE hw attention 0x%x\n", val);
3998 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR)
3999 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_"
4001 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR)
4002 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_"
4003 "INCORRECT_RCV_BEHAVIOR\n");
4004 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN)
4005 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_"
4006 "WAS_ERROR_ATTN\n");
4007 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN)
4008 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_"
4009 "VF_LENGTH_VIOLATION_ATTN\n");
4011 PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN)
4012 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_"
4013 "VF_GRC_SPACE_VIOLATION_ATTN\n");
4015 PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN)
4016 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_"
4017 "VF_MSIX_BAR_VIOLATION_ATTN\n");
4018 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN)
4019 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_"
4020 "TCPL_ERROR_ATTN\n");
4021 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN)
4022 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_"
4023 "TCPL_IN_TWO_RCBS_ATTN\n");
4024 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW)
4025 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_"
4026 "CSSNOOP_FIFO_OVERFLOW\n");
4028 if (attn & AEU_INPUTS_ATTN_BITS_ATC_HW_INTERRUPT) {
4029 val = REG_RD(bp, ATC_REG_ATC_INT_STS_CLR);
4030 BNX2X_ERR("ATC hw attention 0x%x\n", val);
4031 if (val & ATC_ATC_INT_STS_REG_ADDRESS_ERROR)
4032 BNX2X_ERR("ATC_ATC_INT_STS_REG_ADDRESS_ERROR\n");
4033 if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND)
4034 BNX2X_ERR("ATC_ATC_INT_STS_REG"
4035 "_ATC_TCPL_TO_NOT_PEND\n");
4036 if (val & ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS)
4037 BNX2X_ERR("ATC_ATC_INT_STS_REG_"
4038 "ATC_GPA_MULTIPLE_HITS\n");
4039 if (val & ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT)
4040 BNX2X_ERR("ATC_ATC_INT_STS_REG_"
4041 "ATC_RCPL_TO_EMPTY_CNT\n");
4042 if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR)
4043 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR\n");
4044 if (val & ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU)
4045 BNX2X_ERR("ATC_ATC_INT_STS_REG_"
4046 "ATC_IREQ_LESS_THAN_STU\n");
4049 if (attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
4050 AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)) {
4051 BNX2X_ERR("FATAL parity attention set4 0x%x\n",
4052 (u32)(attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
4053 AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)));
4058 static void bnx2x_attn_int_deasserted(struct bnx2x *bp, u32 deasserted)
4060 struct attn_route attn, *group_mask;
4061 int port = BP_PORT(bp);
4066 bool global = false;
4068 /* need to take HW lock because MCP or other port might also
4069 try to handle this event */
4070 bnx2x_acquire_alr(bp);
4072 if (bnx2x_chk_parity_attn(bp, &global, true)) {
4073 #ifndef BNX2X_STOP_ON_ERROR
4074 bp->recovery_state = BNX2X_RECOVERY_INIT;
4075 schedule_delayed_work(&bp->sp_rtnl_task, 0);
4076 /* Disable HW interrupts */
4077 bnx2x_int_disable(bp);
4078 /* In case of parity errors don't handle attentions so that
4079 * other function would "see" parity errors.
4084 bnx2x_release_alr(bp);
4088 attn.sig[0] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4);
4089 attn.sig[1] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4);
4090 attn.sig[2] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4);
4091 attn.sig[3] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4);
4092 if (!CHIP_IS_E1x(bp))
4094 REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + port*4);
4098 DP(NETIF_MSG_HW, "attn: %08x %08x %08x %08x %08x\n",
4099 attn.sig[0], attn.sig[1], attn.sig[2], attn.sig[3], attn.sig[4]);
4101 for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
4102 if (deasserted & (1 << index)) {
4103 group_mask = &bp->attn_group[index];
4105 DP(NETIF_MSG_HW, "group[%d]: %08x %08x "
4108 group_mask->sig[0], group_mask->sig[1],
4109 group_mask->sig[2], group_mask->sig[3],
4110 group_mask->sig[4]);
4112 bnx2x_attn_int_deasserted4(bp,
4113 attn.sig[4] & group_mask->sig[4]);
4114 bnx2x_attn_int_deasserted3(bp,
4115 attn.sig[3] & group_mask->sig[3]);
4116 bnx2x_attn_int_deasserted1(bp,
4117 attn.sig[1] & group_mask->sig[1]);
4118 bnx2x_attn_int_deasserted2(bp,
4119 attn.sig[2] & group_mask->sig[2]);
4120 bnx2x_attn_int_deasserted0(bp,
4121 attn.sig[0] & group_mask->sig[0]);
4125 bnx2x_release_alr(bp);
4127 if (bp->common.int_block == INT_BLOCK_HC)
4128 reg_addr = (HC_REG_COMMAND_REG + port*32 +
4129 COMMAND_REG_ATTN_BITS_CLR);
4131 reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_CLR_UPPER*8);
4134 DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", val,
4135 (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
4136 REG_WR(bp, reg_addr, val);
4138 if (~bp->attn_state & deasserted)
4139 BNX2X_ERR("IGU ERROR\n");
4141 reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
4142 MISC_REG_AEU_MASK_ATTN_FUNC_0;
4144 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
4145 aeu_mask = REG_RD(bp, reg_addr);
4147 DP(NETIF_MSG_HW, "aeu_mask %x newly deasserted %x\n",
4148 aeu_mask, deasserted);
4149 aeu_mask |= (deasserted & 0x3ff);
4150 DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
4152 REG_WR(bp, reg_addr, aeu_mask);
4153 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
4155 DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
4156 bp->attn_state &= ~deasserted;
4157 DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
4160 static void bnx2x_attn_int(struct bnx2x *bp)
4162 /* read local copy of bits */
4163 u32 attn_bits = le32_to_cpu(bp->def_status_blk->atten_status_block.
4165 u32 attn_ack = le32_to_cpu(bp->def_status_blk->atten_status_block.
4167 u32 attn_state = bp->attn_state;
4169 /* look for changed bits */
4170 u32 asserted = attn_bits & ~attn_ack & ~attn_state;
4171 u32 deasserted = ~attn_bits & attn_ack & attn_state;
4174 "attn_bits %x attn_ack %x asserted %x deasserted %x\n",
4175 attn_bits, attn_ack, asserted, deasserted);
4177 if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state))
4178 BNX2X_ERR("BAD attention state\n");
4180 /* handle bits that were raised */
4182 bnx2x_attn_int_asserted(bp, asserted);
4185 bnx2x_attn_int_deasserted(bp, deasserted);
4188 void bnx2x_igu_ack_sb(struct bnx2x *bp, u8 igu_sb_id, u8 segment,
4189 u16 index, u8 op, u8 update)
4191 u32 igu_addr = BAR_IGU_INTMEM + (IGU_CMD_INT_ACK_BASE + igu_sb_id)*8;
4193 bnx2x_igu_ack_sb_gen(bp, igu_sb_id, segment, index, op, update,
4197 static inline void bnx2x_update_eq_prod(struct bnx2x *bp, u16 prod)
4199 /* No memory barriers */
4200 storm_memset_eq_prod(bp, prod, BP_FUNC(bp));
4201 mmiowb(); /* keep prod updates ordered */
4205 static int bnx2x_cnic_handle_cfc_del(struct bnx2x *bp, u32 cid,
4206 union event_ring_elem *elem)
4208 u8 err = elem->message.error;
4210 if (!bp->cnic_eth_dev.starting_cid ||
4211 (cid < bp->cnic_eth_dev.starting_cid &&
4212 cid != bp->cnic_eth_dev.iscsi_l2_cid))
4215 DP(BNX2X_MSG_SP, "got delete ramrod for CNIC CID %d\n", cid);
4217 if (unlikely(err)) {
4219 BNX2X_ERR("got delete ramrod for CNIC CID %d with error!\n",
4221 bnx2x_panic_dump(bp);
4223 bnx2x_cnic_cfc_comp(bp, cid, err);
4228 static inline void bnx2x_handle_mcast_eqe(struct bnx2x *bp)
4230 struct bnx2x_mcast_ramrod_params rparam;
4233 memset(&rparam, 0, sizeof(rparam));
4235 rparam.mcast_obj = &bp->mcast_obj;
4237 netif_addr_lock_bh(bp->dev);
4239 /* Clear pending state for the last command */
4240 bp->mcast_obj.raw.clear_pending(&bp->mcast_obj.raw);
4242 /* If there are pending mcast commands - send them */
4243 if (bp->mcast_obj.check_pending(&bp->mcast_obj)) {
4244 rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_CONT);
4246 BNX2X_ERR("Failed to send pending mcast commands: %d\n",
4250 netif_addr_unlock_bh(bp->dev);
4253 static inline void bnx2x_handle_classification_eqe(struct bnx2x *bp,
4254 union event_ring_elem *elem)
4256 unsigned long ramrod_flags = 0;
4258 u32 cid = elem->message.data.eth_event.echo & BNX2X_SWCID_MASK;
4259 struct bnx2x_vlan_mac_obj *vlan_mac_obj;
4261 /* Always push next commands out, don't wait here */
4262 __set_bit(RAMROD_CONT, &ramrod_flags);
4264 switch (elem->message.data.eth_event.echo >> BNX2X_SWCID_SHIFT) {
4265 case BNX2X_FILTER_MAC_PENDING:
4267 if (cid == BNX2X_ISCSI_ETH_CID)
4268 vlan_mac_obj = &bp->iscsi_l2_mac_obj;
4271 vlan_mac_obj = &bp->fp[cid].mac_obj;
4274 vlan_mac_obj = &bp->fp[cid].mac_obj;
4276 case BNX2X_FILTER_MCAST_PENDING:
4277 /* This is only relevant for 57710 where multicast MACs are
4278 * configured as unicast MACs using the same ramrod.
4280 bnx2x_handle_mcast_eqe(bp);
4283 BNX2X_ERR("Unsupported classification command: %d\n",
4284 elem->message.data.eth_event.echo);
4288 rc = vlan_mac_obj->complete(bp, vlan_mac_obj, elem, &ramrod_flags);
4291 BNX2X_ERR("Failed to schedule new commands: %d\n", rc);
4293 DP(BNX2X_MSG_SP, "Scheduled next pending commands...\n");
4298 static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start);
4301 static inline void bnx2x_handle_rx_mode_eqe(struct bnx2x *bp)
4303 netif_addr_lock_bh(bp->dev);
4305 clear_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
4307 /* Send rx_mode command again if was requested */
4308 if (test_and_clear_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state))
4309 bnx2x_set_storm_rx_mode(bp);
4311 else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED,
4313 bnx2x_set_iscsi_eth_rx_mode(bp, true);
4314 else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED,
4316 bnx2x_set_iscsi_eth_rx_mode(bp, false);
4319 netif_addr_unlock_bh(bp->dev);
4322 static inline struct bnx2x_queue_sp_obj *bnx2x_cid_to_q_obj(
4323 struct bnx2x *bp, u32 cid)
4325 DP(BNX2X_MSG_SP, "retrieving fp from cid %d", cid);
4327 if (cid == BNX2X_FCOE_ETH_CID)
4328 return &bnx2x_fcoe(bp, q_obj);
4331 return &bnx2x_fp(bp, CID_TO_FP(cid), q_obj);
4334 static void bnx2x_eq_int(struct bnx2x *bp)
4336 u16 hw_cons, sw_cons, sw_prod;
4337 union event_ring_elem *elem;
4341 struct bnx2x_queue_sp_obj *q_obj;
4342 struct bnx2x_func_sp_obj *f_obj = &bp->func_obj;
4343 struct bnx2x_raw_obj *rss_raw = &bp->rss_conf_obj.raw;
4345 hw_cons = le16_to_cpu(*bp->eq_cons_sb);
4347 /* The hw_cos range is 1-255, 257 - the sw_cons range is 0-254, 256.
4348 * when we get the the next-page we nned to adjust so the loop
4349 * condition below will be met. The next element is the size of a
4350 * regular element and hence incrementing by 1
4352 if ((hw_cons & EQ_DESC_MAX_PAGE) == EQ_DESC_MAX_PAGE)
4355 /* This function may never run in parallel with itself for a
4356 * specific bp, thus there is no need in "paired" read memory
4359 sw_cons = bp->eq_cons;
4360 sw_prod = bp->eq_prod;
4362 DP(BNX2X_MSG_SP, "EQ: hw_cons %u sw_cons %u bp->cq_spq_left %u\n",
4363 hw_cons, sw_cons, atomic_read(&bp->eq_spq_left));
4365 for (; sw_cons != hw_cons;
4366 sw_prod = NEXT_EQ_IDX(sw_prod), sw_cons = NEXT_EQ_IDX(sw_cons)) {
4369 elem = &bp->eq_ring[EQ_DESC(sw_cons)];
4371 cid = SW_CID(elem->message.data.cfc_del_event.cid);
4372 opcode = elem->message.opcode;
4375 /* handle eq element */
4377 case EVENT_RING_OPCODE_STAT_QUERY:
4378 DP(NETIF_MSG_TIMER, "got statistics comp event %d\n",
4380 /* nothing to do with stats comp */
4383 case EVENT_RING_OPCODE_CFC_DEL:
4384 /* handle according to cid range */
4386 * we may want to verify here that the bp state is
4389 DP(NETIF_MSG_IFDOWN,
4390 "got delete ramrod for MULTI[%d]\n", cid);
4392 if (!bnx2x_cnic_handle_cfc_del(bp, cid, elem))
4395 q_obj = bnx2x_cid_to_q_obj(bp, cid);
4397 if (q_obj->complete_cmd(bp, q_obj, BNX2X_Q_CMD_CFC_DEL))
4404 case EVENT_RING_OPCODE_STOP_TRAFFIC:
4405 DP(NETIF_MSG_IFUP, "got STOP TRAFFIC\n");
4406 if (f_obj->complete_cmd(bp, f_obj,
4407 BNX2X_F_CMD_TX_STOP))
4409 bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_PAUSED);
4412 case EVENT_RING_OPCODE_START_TRAFFIC:
4413 DP(NETIF_MSG_IFUP, "got START TRAFFIC\n");
4414 if (f_obj->complete_cmd(bp, f_obj,
4415 BNX2X_F_CMD_TX_START))
4417 bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_RELEASED);
4419 case EVENT_RING_OPCODE_FUNCTION_START:
4420 DP(NETIF_MSG_IFUP, "got FUNC_START ramrod\n");
4421 if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_START))
4426 case EVENT_RING_OPCODE_FUNCTION_STOP:
4427 DP(NETIF_MSG_IFDOWN, "got FUNC_STOP ramrod\n");
4428 if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_STOP))
4434 switch (opcode | bp->state) {
4435 case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
4437 case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
4438 BNX2X_STATE_OPENING_WAIT4_PORT):
4439 cid = elem->message.data.eth_event.echo &
4441 DP(NETIF_MSG_IFUP, "got RSS_UPDATE ramrod. CID %d\n",
4443 rss_raw->clear_pending(rss_raw);
4446 case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_OPEN):
4447 case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_DIAG):
4448 case (EVENT_RING_OPCODE_SET_MAC |
4449 BNX2X_STATE_CLOSING_WAIT4_HALT):
4450 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
4452 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
4454 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
4455 BNX2X_STATE_CLOSING_WAIT4_HALT):
4456 DP(NETIF_MSG_IFUP, "got (un)set mac ramrod\n");
4457 bnx2x_handle_classification_eqe(bp, elem);
4460 case (EVENT_RING_OPCODE_MULTICAST_RULES |
4462 case (EVENT_RING_OPCODE_MULTICAST_RULES |
4464 case (EVENT_RING_OPCODE_MULTICAST_RULES |
4465 BNX2X_STATE_CLOSING_WAIT4_HALT):
4466 DP(NETIF_MSG_IFUP, "got mcast ramrod\n");
4467 bnx2x_handle_mcast_eqe(bp);
4470 case (EVENT_RING_OPCODE_FILTERS_RULES |
4472 case (EVENT_RING_OPCODE_FILTERS_RULES |
4474 case (EVENT_RING_OPCODE_FILTERS_RULES |
4475 BNX2X_STATE_CLOSING_WAIT4_HALT):
4476 DP(NETIF_MSG_IFUP, "got rx_mode ramrod\n");
4477 bnx2x_handle_rx_mode_eqe(bp);
4480 /* unknown event log error and continue */
4481 BNX2X_ERR("Unknown EQ event %d, bp->state 0x%x\n",
4482 elem->message.opcode, bp->state);
4488 smp_mb__before_atomic_inc();
4489 atomic_add(spqe_cnt, &bp->eq_spq_left);
4491 bp->eq_cons = sw_cons;
4492 bp->eq_prod = sw_prod;
4493 /* Make sure that above mem writes were issued towards the memory */
4496 /* update producer */
4497 bnx2x_update_eq_prod(bp, bp->eq_prod);
4500 static void bnx2x_sp_task(struct work_struct *work)
4502 struct bnx2x *bp = container_of(work, struct bnx2x, sp_task.work);
4505 status = bnx2x_update_dsb_idx(bp);
4506 /* if (status == 0) */
4507 /* BNX2X_ERR("spurious slowpath interrupt!\n"); */
4509 DP(NETIF_MSG_INTR, "got a slowpath interrupt (status 0x%x)\n", status);
4512 if (status & BNX2X_DEF_SB_ATT_IDX) {
4514 status &= ~BNX2X_DEF_SB_ATT_IDX;
4517 /* SP events: STAT_QUERY and others */
4518 if (status & BNX2X_DEF_SB_IDX) {
4520 struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);
4522 if ((!NO_FCOE(bp)) &&
4523 (bnx2x_has_rx_work(fp) || bnx2x_has_tx_work(fp)))
4524 napi_schedule(&bnx2x_fcoe(bp, napi));
4526 /* Handle EQ completions */
4529 bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID,
4530 le16_to_cpu(bp->def_idx), IGU_INT_NOP, 1);
4532 status &= ~BNX2X_DEF_SB_IDX;
4535 if (unlikely(status))
4536 DP(NETIF_MSG_INTR, "got an unknown interrupt! (status 0x%x)\n",
4539 bnx2x_ack_sb(bp, bp->igu_dsb_id, ATTENTION_ID,
4540 le16_to_cpu(bp->def_att_idx), IGU_INT_ENABLE, 1);
4543 irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance)
4545 struct net_device *dev = dev_instance;
4546 struct bnx2x *bp = netdev_priv(dev);
4548 bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0,
4549 IGU_INT_DISABLE, 0);
4551 #ifdef BNX2X_STOP_ON_ERROR
4552 if (unlikely(bp->panic))
4558 struct cnic_ops *c_ops;
4561 c_ops = rcu_dereference(bp->cnic_ops);
4563 c_ops->cnic_handler(bp->cnic_data, NULL);
4567 queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
4572 /* end of slow path */
4575 void bnx2x_drv_pulse(struct bnx2x *bp)
4577 SHMEM_WR(bp, func_mb[BP_FW_MB_IDX(bp)].drv_pulse_mb,
4578 bp->fw_drv_pulse_wr_seq);
4582 static void bnx2x_timer(unsigned long data)
4585 struct bnx2x *bp = (struct bnx2x *) data;
4587 if (!netif_running(bp->dev))
4591 struct bnx2x_fastpath *fp = &bp->fp[0];
4593 for_each_cos_in_tx_queue(fp, cos)
4594 bnx2x_tx_int(bp, &fp->txdata[cos]);
4595 bnx2x_rx_int(fp, 1000);
4598 if (!BP_NOMCP(bp)) {
4599 int mb_idx = BP_FW_MB_IDX(bp);
4603 ++bp->fw_drv_pulse_wr_seq;
4604 bp->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK;
4605 /* TBD - add SYSTEM_TIME */
4606 drv_pulse = bp->fw_drv_pulse_wr_seq;
4607 bnx2x_drv_pulse(bp);
4609 mcp_pulse = (SHMEM_RD(bp, func_mb[mb_idx].mcp_pulse_mb) &
4610 MCP_PULSE_SEQ_MASK);
4611 /* The delta between driver pulse and mcp response
4612 * should be 1 (before mcp response) or 0 (after mcp response)
4614 if ((drv_pulse != mcp_pulse) &&
4615 (drv_pulse != ((mcp_pulse + 1) & MCP_PULSE_SEQ_MASK))) {
4616 /* someone lost a heartbeat... */
4617 BNX2X_ERR("drv_pulse (0x%x) != mcp_pulse (0x%x)\n",
4618 drv_pulse, mcp_pulse);
4622 if (bp->state == BNX2X_STATE_OPEN)
4623 bnx2x_stats_handle(bp, STATS_EVENT_UPDATE);
4625 mod_timer(&bp->timer, jiffies + bp->current_interval);
4628 /* end of Statistics */
4633 * nic init service functions
4636 static inline void bnx2x_fill(struct bnx2x *bp, u32 addr, int fill, u32 len)
4639 if (!(len%4) && !(addr%4))
4640 for (i = 0; i < len; i += 4)
4641 REG_WR(bp, addr + i, fill);
4643 for (i = 0; i < len; i++)
4644 REG_WR8(bp, addr + i, fill);
4648 /* helper: writes FP SP data to FW - data_size in dwords */
4649 static inline void bnx2x_wr_fp_sb_data(struct bnx2x *bp,
4655 for (index = 0; index < data_size; index++)
4656 REG_WR(bp, BAR_CSTRORM_INTMEM +
4657 CSTORM_STATUS_BLOCK_DATA_OFFSET(fw_sb_id) +
4659 *(sb_data_p + index));
4662 static inline void bnx2x_zero_fp_sb(struct bnx2x *bp, int fw_sb_id)
4666 struct hc_status_block_data_e2 sb_data_e2;
4667 struct hc_status_block_data_e1x sb_data_e1x;
4669 /* disable the function first */
4670 if (!CHIP_IS_E1x(bp)) {
4671 memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
4672 sb_data_e2.common.state = SB_DISABLED;
4673 sb_data_e2.common.p_func.vf_valid = false;
4674 sb_data_p = (u32 *)&sb_data_e2;
4675 data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
4677 memset(&sb_data_e1x, 0,
4678 sizeof(struct hc_status_block_data_e1x));
4679 sb_data_e1x.common.state = SB_DISABLED;
4680 sb_data_e1x.common.p_func.vf_valid = false;
4681 sb_data_p = (u32 *)&sb_data_e1x;
4682 data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
4684 bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
4686 bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
4687 CSTORM_STATUS_BLOCK_OFFSET(fw_sb_id), 0,
4688 CSTORM_STATUS_BLOCK_SIZE);
4689 bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
4690 CSTORM_SYNC_BLOCK_OFFSET(fw_sb_id), 0,
4691 CSTORM_SYNC_BLOCK_SIZE);
4694 /* helper: writes SP SB data to FW */
4695 static inline void bnx2x_wr_sp_sb_data(struct bnx2x *bp,
4696 struct hc_sp_status_block_data *sp_sb_data)
4698 int func = BP_FUNC(bp);
4700 for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
4701 REG_WR(bp, BAR_CSTRORM_INTMEM +
4702 CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
4704 *((u32 *)sp_sb_data + i));
4707 static inline void bnx2x_zero_sp_sb(struct bnx2x *bp)
4709 int func = BP_FUNC(bp);
4710 struct hc_sp_status_block_data sp_sb_data;
4711 memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
4713 sp_sb_data.state = SB_DISABLED;
4714 sp_sb_data.p_func.vf_valid = false;
4716 bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
4718 bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
4719 CSTORM_SP_STATUS_BLOCK_OFFSET(func), 0,
4720 CSTORM_SP_STATUS_BLOCK_SIZE);
4721 bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
4722 CSTORM_SP_SYNC_BLOCK_OFFSET(func), 0,
4723 CSTORM_SP_SYNC_BLOCK_SIZE);
4729 void bnx2x_setup_ndsb_state_machine(struct hc_status_block_sm *hc_sm,
4730 int igu_sb_id, int igu_seg_id)
4732 hc_sm->igu_sb_id = igu_sb_id;
4733 hc_sm->igu_seg_id = igu_seg_id;
4734 hc_sm->timer_value = 0xFF;
4735 hc_sm->time_to_expire = 0xFFFFFFFF;
4738 static void bnx2x_init_sb(struct bnx2x *bp, dma_addr_t mapping, int vfid,
4739 u8 vf_valid, int fw_sb_id, int igu_sb_id)
4743 struct hc_status_block_data_e2 sb_data_e2;
4744 struct hc_status_block_data_e1x sb_data_e1x;
4745 struct hc_status_block_sm *hc_sm_p;
4749 if (CHIP_INT_MODE_IS_BC(bp))
4750 igu_seg_id = HC_SEG_ACCESS_NORM;
4752 igu_seg_id = IGU_SEG_ACCESS_NORM;
4754 bnx2x_zero_fp_sb(bp, fw_sb_id);
4756 if (!CHIP_IS_E1x(bp)) {
4757 memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
4758 sb_data_e2.common.state = SB_ENABLED;
4759 sb_data_e2.common.p_func.pf_id = BP_FUNC(bp);
4760 sb_data_e2.common.p_func.vf_id = vfid;
4761 sb_data_e2.common.p_func.vf_valid = vf_valid;
4762 sb_data_e2.common.p_func.vnic_id = BP_VN(bp);
4763 sb_data_e2.common.same_igu_sb_1b = true;
4764 sb_data_e2.common.host_sb_addr.hi = U64_HI(mapping);
4765 sb_data_e2.common.host_sb_addr.lo = U64_LO(mapping);
4766 hc_sm_p = sb_data_e2.common.state_machine;
4767 sb_data_p = (u32 *)&sb_data_e2;
4768 data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
4770 memset(&sb_data_e1x, 0,
4771 sizeof(struct hc_status_block_data_e1x));
4772 sb_data_e1x.common.state = SB_ENABLED;
4773 sb_data_e1x.common.p_func.pf_id = BP_FUNC(bp);
4774 sb_data_e1x.common.p_func.vf_id = 0xff;
4775 sb_data_e1x.common.p_func.vf_valid = false;
4776 sb_data_e1x.common.p_func.vnic_id = BP_VN(bp);
4777 sb_data_e1x.common.same_igu_sb_1b = true;
4778 sb_data_e1x.common.host_sb_addr.hi = U64_HI(mapping);
4779 sb_data_e1x.common.host_sb_addr.lo = U64_LO(mapping);
4780 hc_sm_p = sb_data_e1x.common.state_machine;
4781 sb_data_p = (u32 *)&sb_data_e1x;
4782 data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
4785 bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_RX_ID],
4786 igu_sb_id, igu_seg_id);
4787 bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_TX_ID],
4788 igu_sb_id, igu_seg_id);
4790 DP(NETIF_MSG_HW, "Init FW SB %d\n", fw_sb_id);
4792 /* write indecies to HW */
4793 bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
4796 static void bnx2x_update_coalesce_sb(struct bnx2x *bp, u8 fw_sb_id,
4797 u16 tx_usec, u16 rx_usec)
4799 bnx2x_update_coalesce_sb_index(bp, fw_sb_id, HC_INDEX_ETH_RX_CQ_CONS,
4801 bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
4802 HC_INDEX_ETH_TX_CQ_CONS_COS0, false,
4804 bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
4805 HC_INDEX_ETH_TX_CQ_CONS_COS1, false,
4807 bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
4808 HC_INDEX_ETH_TX_CQ_CONS_COS2, false,
4812 static void bnx2x_init_def_sb(struct bnx2x *bp)
4814 struct host_sp_status_block *def_sb = bp->def_status_blk;
4815 dma_addr_t mapping = bp->def_status_blk_mapping;
4816 int igu_sp_sb_index;
4818 int port = BP_PORT(bp);
4819 int func = BP_FUNC(bp);
4823 struct hc_sp_status_block_data sp_sb_data;
4824 memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
4826 if (CHIP_INT_MODE_IS_BC(bp)) {
4827 igu_sp_sb_index = DEF_SB_IGU_ID;
4828 igu_seg_id = HC_SEG_ACCESS_DEF;
4830 igu_sp_sb_index = bp->igu_dsb_id;
4831 igu_seg_id = IGU_SEG_ACCESS_DEF;
4835 section = ((u64)mapping) + offsetof(struct host_sp_status_block,
4836 atten_status_block);
4837 def_sb->atten_status_block.status_block_id = igu_sp_sb_index;
4841 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
4842 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
4843 for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
4845 /* take care of sig[0]..sig[4] */
4846 for (sindex = 0; sindex < 4; sindex++)
4847 bp->attn_group[index].sig[sindex] =
4848 REG_RD(bp, reg_offset + sindex*0x4 + 0x10*index);
4850 if (!CHIP_IS_E1x(bp))
4852 * enable5 is separate from the rest of the registers,
4853 * and therefore the address skip is 4
4854 * and not 16 between the different groups
4856 bp->attn_group[index].sig[4] = REG_RD(bp,
4857 reg_offset + 0x10 + 0x4*index);
4859 bp->attn_group[index].sig[4] = 0;
4862 if (bp->common.int_block == INT_BLOCK_HC) {
4863 reg_offset = (port ? HC_REG_ATTN_MSG1_ADDR_L :
4864 HC_REG_ATTN_MSG0_ADDR_L);
4866 REG_WR(bp, reg_offset, U64_LO(section));
4867 REG_WR(bp, reg_offset + 4, U64_HI(section));
4868 } else if (!CHIP_IS_E1x(bp)) {
4869 REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_L, U64_LO(section));
4870 REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_H, U64_HI(section));
4873 section = ((u64)mapping) + offsetof(struct host_sp_status_block,
4876 bnx2x_zero_sp_sb(bp);
4878 sp_sb_data.state = SB_ENABLED;
4879 sp_sb_data.host_sb_addr.lo = U64_LO(section);
4880 sp_sb_data.host_sb_addr.hi = U64_HI(section);
4881 sp_sb_data.igu_sb_id = igu_sp_sb_index;
4882 sp_sb_data.igu_seg_id = igu_seg_id;
4883 sp_sb_data.p_func.pf_id = func;
4884 sp_sb_data.p_func.vnic_id = BP_VN(bp);
4885 sp_sb_data.p_func.vf_id = 0xff;
4887 bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
4889 bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0, IGU_INT_ENABLE, 0);
4892 void bnx2x_update_coalesce(struct bnx2x *bp)
4896 for_each_eth_queue(bp, i)
4897 bnx2x_update_coalesce_sb(bp, bp->fp[i].fw_sb_id,
4898 bp->tx_ticks, bp->rx_ticks);
4901 static void bnx2x_init_sp_ring(struct bnx2x *bp)
4903 spin_lock_init(&bp->spq_lock);
4904 atomic_set(&bp->cq_spq_left, MAX_SPQ_PENDING);
4906 bp->spq_prod_idx = 0;
4907 bp->dsb_sp_prod = BNX2X_SP_DSB_INDEX;
4908 bp->spq_prod_bd = bp->spq;
4909 bp->spq_last_bd = bp->spq_prod_bd + MAX_SP_DESC_CNT;
4912 static void bnx2x_init_eq_ring(struct bnx2x *bp)
4915 for (i = 1; i <= NUM_EQ_PAGES; i++) {
4916 union event_ring_elem *elem =
4917 &bp->eq_ring[EQ_DESC_CNT_PAGE * i - 1];
4919 elem->next_page.addr.hi =
4920 cpu_to_le32(U64_HI(bp->eq_mapping +
4921 BCM_PAGE_SIZE * (i % NUM_EQ_PAGES)));
4922 elem->next_page.addr.lo =
4923 cpu_to_le32(U64_LO(bp->eq_mapping +
4924 BCM_PAGE_SIZE*(i % NUM_EQ_PAGES)));
4927 bp->eq_prod = NUM_EQ_DESC;
4928 bp->eq_cons_sb = BNX2X_EQ_INDEX;
4929 /* we want a warning message before it gets rought... */
4930 atomic_set(&bp->eq_spq_left,
4931 min_t(int, MAX_SP_DESC_CNT - MAX_SPQ_PENDING, NUM_EQ_DESC) - 1);
4935 /* called with netif_addr_lock_bh() */
4936 void bnx2x_set_q_rx_mode(struct bnx2x *bp, u8 cl_id,
4937 unsigned long rx_mode_flags,
4938 unsigned long rx_accept_flags,
4939 unsigned long tx_accept_flags,
4940 unsigned long ramrod_flags)
4942 struct bnx2x_rx_mode_ramrod_params ramrod_param;
4945 memset(&ramrod_param, 0, sizeof(ramrod_param));
4947 /* Prepare ramrod parameters */
4948 ramrod_param.cid = 0;
4949 ramrod_param.cl_id = cl_id;
4950 ramrod_param.rx_mode_obj = &bp->rx_mode_obj;
4951 ramrod_param.func_id = BP_FUNC(bp);
4953 ramrod_param.pstate = &bp->sp_state;
4954 ramrod_param.state = BNX2X_FILTER_RX_MODE_PENDING;
4956 ramrod_param.rdata = bnx2x_sp(bp, rx_mode_rdata);
4957 ramrod_param.rdata_mapping = bnx2x_sp_mapping(bp, rx_mode_rdata);
4959 set_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
4961 ramrod_param.ramrod_flags = ramrod_flags;
4962 ramrod_param.rx_mode_flags = rx_mode_flags;
4964 ramrod_param.rx_accept_flags = rx_accept_flags;
4965 ramrod_param.tx_accept_flags = tx_accept_flags;
4967 rc = bnx2x_config_rx_mode(bp, &ramrod_param);
4969 BNX2X_ERR("Set rx_mode %d failed\n", bp->rx_mode);
4974 /* called with netif_addr_lock_bh() */
4975 void bnx2x_set_storm_rx_mode(struct bnx2x *bp)
4977 unsigned long rx_mode_flags = 0, ramrod_flags = 0;
4978 unsigned long rx_accept_flags = 0, tx_accept_flags = 0;
4983 /* Configure rx_mode of FCoE Queue */
4984 __set_bit(BNX2X_RX_MODE_FCOE_ETH, &rx_mode_flags);
4987 switch (bp->rx_mode) {
4988 case BNX2X_RX_MODE_NONE:
4990 * 'drop all' supersedes any accept flags that may have been
4991 * passed to the function.
4994 case BNX2X_RX_MODE_NORMAL:
4995 __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
4996 __set_bit(BNX2X_ACCEPT_MULTICAST, &rx_accept_flags);
4997 __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
4999 /* internal switching mode */
5000 __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
5001 __set_bit(BNX2X_ACCEPT_MULTICAST, &tx_accept_flags);
5002 __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
5005 case BNX2X_RX_MODE_ALLMULTI:
5006 __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
5007 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &rx_accept_flags);
5008 __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
5010 /* internal switching mode */
5011 __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
5012 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &tx_accept_flags);
5013 __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
5016 case BNX2X_RX_MODE_PROMISC:
5017 /* According to deffinition of SI mode, iface in promisc mode
5018 * should receive matched and unmatched (in resolution of port)
5021 __set_bit(BNX2X_ACCEPT_UNMATCHED, &rx_accept_flags);
5022 __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
5023 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &rx_accept_flags);
5024 __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
5026 /* internal switching mode */
5027 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &tx_accept_flags);
5028 __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
5031 __set_bit(BNX2X_ACCEPT_ALL_UNICAST, &tx_accept_flags);
5033 __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
5037 BNX2X_ERR("Unknown rx_mode: %d\n", bp->rx_mode);
5041 if (bp->rx_mode != BNX2X_RX_MODE_NONE) {
5042 __set_bit(BNX2X_ACCEPT_ANY_VLAN, &rx_accept_flags);
5043 __set_bit(BNX2X_ACCEPT_ANY_VLAN, &tx_accept_flags);
5046 __set_bit(RAMROD_RX, &ramrod_flags);
5047 __set_bit(RAMROD_TX, &ramrod_flags);
5049 bnx2x_set_q_rx_mode(bp, bp->fp->cl_id, rx_mode_flags, rx_accept_flags,
5050 tx_accept_flags, ramrod_flags);
5053 static void bnx2x_init_internal_common(struct bnx2x *bp)
5059 * In switch independent mode, the TSTORM needs to accept
5060 * packets that failed classification, since approximate match
5061 * mac addresses aren't written to NIG LLH
5063 REG_WR8(bp, BAR_TSTRORM_INTMEM +
5064 TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 2);
5065 else if (!CHIP_IS_E1(bp)) /* 57710 doesn't support MF */
5066 REG_WR8(bp, BAR_TSTRORM_INTMEM +
5067 TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 0);
5069 /* Zero this manually as its initialization is
5070 currently missing in the initTool */
5071 for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++)
5072 REG_WR(bp, BAR_USTRORM_INTMEM +
5073 USTORM_AGG_DATA_OFFSET + i * 4, 0);
5074 if (!CHIP_IS_E1x(bp)) {
5075 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_IGU_MODE_OFFSET,
5076 CHIP_INT_MODE_IS_BC(bp) ?
5077 HC_IGU_BC_MODE : HC_IGU_NBC_MODE);
5081 static void bnx2x_init_internal(struct bnx2x *bp, u32 load_code)
5083 switch (load_code) {
5084 case FW_MSG_CODE_DRV_LOAD_COMMON:
5085 case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP:
5086 bnx2x_init_internal_common(bp);
5089 case FW_MSG_CODE_DRV_LOAD_PORT:
5093 case FW_MSG_CODE_DRV_LOAD_FUNCTION:
5094 /* internal memory per function is
5095 initialized inside bnx2x_pf_init */
5099 BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code);
5104 static inline u8 bnx2x_fp_igu_sb_id(struct bnx2x_fastpath *fp)
5106 return fp->bp->igu_base_sb + fp->index + CNIC_PRESENT;
5109 static inline u8 bnx2x_fp_fw_sb_id(struct bnx2x_fastpath *fp)
5111 return fp->bp->base_fw_ndsb + fp->index + CNIC_PRESENT;
5114 static inline u8 bnx2x_fp_cl_id(struct bnx2x_fastpath *fp)
5116 if (CHIP_IS_E1x(fp->bp))
5117 return BP_L_ID(fp->bp) + fp->index;
5118 else /* We want Client ID to be the same as IGU SB ID for 57712 */
5119 return bnx2x_fp_igu_sb_id(fp);
5122 static void bnx2x_init_eth_fp(struct bnx2x *bp, int fp_idx)
5124 struct bnx2x_fastpath *fp = &bp->fp[fp_idx];
5126 unsigned long q_type = 0;
5127 u32 cids[BNX2X_MULTI_TX_COS] = { 0 };
5130 fp->cl_id = bnx2x_fp_cl_id(fp);
5131 fp->fw_sb_id = bnx2x_fp_fw_sb_id(fp);
5132 fp->igu_sb_id = bnx2x_fp_igu_sb_id(fp);
5133 /* qZone id equals to FW (per path) client id */
5134 fp->cl_qzone_id = bnx2x_fp_qzone_id(fp);
5137 fp->ustorm_rx_prods_offset = bnx2x_rx_ustorm_prods_offset(fp);
5138 /* Setup SB indicies */
5139 fp->rx_cons_sb = BNX2X_RX_SB_INDEX;
5141 /* Configure Queue State object */
5142 __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
5143 __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
5145 BUG_ON(fp->max_cos > BNX2X_MULTI_TX_COS);
5148 for_each_cos_in_tx_queue(fp, cos) {
5149 bnx2x_init_txdata(bp, &fp->txdata[cos],
5150 CID_COS_TO_TX_ONLY_CID(fp->cid, cos),
5151 FP_COS_TO_TXQ(fp, cos),
5152 BNX2X_TX_SB_INDEX_BASE + cos);
5153 cids[cos] = fp->txdata[cos].cid;
5156 bnx2x_init_queue_obj(bp, &fp->q_obj, fp->cl_id, cids, fp->max_cos,
5157 BP_FUNC(bp), bnx2x_sp(bp, q_rdata),
5158 bnx2x_sp_mapping(bp, q_rdata), q_type);
5161 * Configure classification DBs: Always enable Tx switching
5163 bnx2x_init_vlan_mac_fp_objs(fp, BNX2X_OBJ_TYPE_RX_TX);
5165 DP(NETIF_MSG_IFUP, "queue[%d]: bnx2x_init_sb(%p,%p) "
5166 "cl_id %d fw_sb %d igu_sb %d\n",
5167 fp_idx, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id,
5169 bnx2x_init_sb(bp, fp->status_blk_mapping, BNX2X_VF_ID_INVALID, false,
5170 fp->fw_sb_id, fp->igu_sb_id);
5172 bnx2x_update_fpsb_idx(fp);
5175 void bnx2x_nic_init(struct bnx2x *bp, u32 load_code)
5179 for_each_eth_queue(bp, i)
5180 bnx2x_init_eth_fp(bp, i);
5183 bnx2x_init_fcoe_fp(bp);
5185 bnx2x_init_sb(bp, bp->cnic_sb_mapping,
5186 BNX2X_VF_ID_INVALID, false,
5187 bnx2x_cnic_fw_sb_id(bp), bnx2x_cnic_igu_sb_id(bp));
5191 /* Initialize MOD_ABS interrupts */
5192 bnx2x_init_mod_abs_int(bp, &bp->link_vars, bp->common.chip_id,
5193 bp->common.shmem_base, bp->common.shmem2_base,
5195 /* ensure status block indices were read */
5198 bnx2x_init_def_sb(bp);
5199 bnx2x_update_dsb_idx(bp);
5200 bnx2x_init_rx_rings(bp);
5201 bnx2x_init_tx_rings(bp);
5202 bnx2x_init_sp_ring(bp);
5203 bnx2x_init_eq_ring(bp);
5204 bnx2x_init_internal(bp, load_code);
5206 bnx2x_stats_init(bp);
5208 /* flush all before enabling interrupts */
5212 bnx2x_int_enable(bp);
5214 /* Check for SPIO5 */
5215 bnx2x_attn_int_deasserted0(bp,
5216 REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + BP_PORT(bp)*4) &
5217 AEU_INPUTS_ATTN_BITS_SPIO5);
5220 /* end of nic init */
5223 * gzip service functions
5226 static int bnx2x_gunzip_init(struct bnx2x *bp)
5228 bp->gunzip_buf = dma_alloc_coherent(&bp->pdev->dev, FW_BUF_SIZE,
5229 &bp->gunzip_mapping, GFP_KERNEL);
5230 if (bp->gunzip_buf == NULL)
5233 bp->strm = kmalloc(sizeof(*bp->strm), GFP_KERNEL);
5234 if (bp->strm == NULL)
5237 bp->strm->workspace = vmalloc(zlib_inflate_workspacesize());
5238 if (bp->strm->workspace == NULL)
5248 dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
5249 bp->gunzip_mapping);
5250 bp->gunzip_buf = NULL;
5253 netdev_err(bp->dev, "Cannot allocate firmware buffer for"
5254 " un-compression\n");
5258 static void bnx2x_gunzip_end(struct bnx2x *bp)
5261 vfree(bp->strm->workspace);
5266 if (bp->gunzip_buf) {
5267 dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
5268 bp->gunzip_mapping);
5269 bp->gunzip_buf = NULL;
5273 static int bnx2x_gunzip(struct bnx2x *bp, const u8 *zbuf, int len)
5277 /* check gzip header */
5278 if ((zbuf[0] != 0x1f) || (zbuf[1] != 0x8b) || (zbuf[2] != Z_DEFLATED)) {
5279 BNX2X_ERR("Bad gzip header\n");
5287 if (zbuf[3] & FNAME)
5288 while ((zbuf[n++] != 0) && (n < len));
5290 bp->strm->next_in = (typeof(bp->strm->next_in))zbuf + n;
5291 bp->strm->avail_in = len - n;
5292 bp->strm->next_out = bp->gunzip_buf;
5293 bp->strm->avail_out = FW_BUF_SIZE;
5295 rc = zlib_inflateInit2(bp->strm, -MAX_WBITS);
5299 rc = zlib_inflate(bp->strm, Z_FINISH);
5300 if ((rc != Z_OK) && (rc != Z_STREAM_END))
5301 netdev_err(bp->dev, "Firmware decompression error: %s\n",
5304 bp->gunzip_outlen = (FW_BUF_SIZE - bp->strm->avail_out);
5305 if (bp->gunzip_outlen & 0x3)
5306 netdev_err(bp->dev, "Firmware decompression error:"
5307 " gunzip_outlen (%d) not aligned\n",
5309 bp->gunzip_outlen >>= 2;
5311 zlib_inflateEnd(bp->strm);
5313 if (rc == Z_STREAM_END)
5319 /* nic load/unload */
5322 * General service functions
5325 /* send a NIG loopback debug packet */
5326 static void bnx2x_lb_pckt(struct bnx2x *bp)
5330 /* Ethernet source and destination addresses */
5331 wb_write[0] = 0x55555555;
5332 wb_write[1] = 0x55555555;
5333 wb_write[2] = 0x20; /* SOP */
5334 REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
5336 /* NON-IP protocol */
5337 wb_write[0] = 0x09000000;
5338 wb_write[1] = 0x55555555;
5339 wb_write[2] = 0x10; /* EOP, eop_bvalid = 0 */
5340 REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
5343 /* some of the internal memories
5344 * are not directly readable from the driver
5345 * to test them we send debug packets
5347 static int bnx2x_int_mem_test(struct bnx2x *bp)
5353 if (CHIP_REV_IS_FPGA(bp))
5355 else if (CHIP_REV_IS_EMUL(bp))
5360 /* Disable inputs of parser neighbor blocks */
5361 REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
5362 REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
5363 REG_WR(bp, CFC_REG_DEBUG0, 0x1);
5364 REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
5366 /* Write 0 to parser credits for CFC search request */
5367 REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
5369 /* send Ethernet packet */
5372 /* TODO do i reset NIG statistic? */
5373 /* Wait until NIG register shows 1 packet of size 0x10 */
5374 count = 1000 * factor;
5377 bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
5378 val = *bnx2x_sp(bp, wb_data[0]);
5386 BNX2X_ERR("NIG timeout val = 0x%x\n", val);
5390 /* Wait until PRS register shows 1 packet */
5391 count = 1000 * factor;
5393 val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
5401 BNX2X_ERR("PRS timeout val = 0x%x\n", val);
5405 /* Reset and init BRB, PRS */
5406 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
5408 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
5410 bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
5411 bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
5413 DP(NETIF_MSG_HW, "part2\n");
5415 /* Disable inputs of parser neighbor blocks */
5416 REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
5417 REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
5418 REG_WR(bp, CFC_REG_DEBUG0, 0x1);
5419 REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
5421 /* Write 0 to parser credits for CFC search request */
5422 REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
5424 /* send 10 Ethernet packets */
5425 for (i = 0; i < 10; i++)
5428 /* Wait until NIG register shows 10 + 1
5429 packets of size 11*0x10 = 0xb0 */
5430 count = 1000 * factor;
5433 bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
5434 val = *bnx2x_sp(bp, wb_data[0]);
5442 BNX2X_ERR("NIG timeout val = 0x%x\n", val);
5446 /* Wait until PRS register shows 2 packets */
5447 val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
5449 BNX2X_ERR("PRS timeout val = 0x%x\n", val);
5451 /* Write 1 to parser credits for CFC search request */
5452 REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x1);
5454 /* Wait until PRS register shows 3 packets */
5455 msleep(10 * factor);
5456 /* Wait until NIG register shows 1 packet of size 0x10 */
5457 val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
5459 BNX2X_ERR("PRS timeout val = 0x%x\n", val);
5461 /* clear NIG EOP FIFO */
5462 for (i = 0; i < 11; i++)
5463 REG_RD(bp, NIG_REG_INGRESS_EOP_LB_FIFO);
5464 val = REG_RD(bp, NIG_REG_INGRESS_EOP_LB_EMPTY);
5466 BNX2X_ERR("clear of NIG failed\n");
5470 /* Reset and init BRB, PRS, NIG */
5471 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
5473 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
5475 bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
5476 bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
5479 REG_WR(bp, PRS_REG_NIC_MODE, 1);
5482 /* Enable inputs of parser neighbor blocks */
5483 REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x7fffffff);
5484 REG_WR(bp, TCM_REG_PRS_IFEN, 0x1);
5485 REG_WR(bp, CFC_REG_DEBUG0, 0x0);
5486 REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x1);
5488 DP(NETIF_MSG_HW, "done\n");
5493 static void bnx2x_enable_blocks_attention(struct bnx2x *bp)
5495 REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
5496 if (!CHIP_IS_E1x(bp))
5497 REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0x40);
5499 REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0);
5500 REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
5501 REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
5503 * mask read length error interrupts in brb for parser
5504 * (parsing unit and 'checksum and crc' unit)
5505 * these errors are legal (PU reads fixed length and CAC can cause
5506 * read length error on truncated packets)
5508 REG_WR(bp, BRB1_REG_BRB1_INT_MASK, 0xFC00);
5509 REG_WR(bp, QM_REG_QM_INT_MASK, 0);
5510 REG_WR(bp, TM_REG_TM_INT_MASK, 0);
5511 REG_WR(bp, XSDM_REG_XSDM_INT_MASK_0, 0);
5512 REG_WR(bp, XSDM_REG_XSDM_INT_MASK_1, 0);
5513 REG_WR(bp, XCM_REG_XCM_INT_MASK, 0);
5514 /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_0, 0); */
5515 /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_1, 0); */
5516 REG_WR(bp, USDM_REG_USDM_INT_MASK_0, 0);
5517 REG_WR(bp, USDM_REG_USDM_INT_MASK_1, 0);
5518 REG_WR(bp, UCM_REG_UCM_INT_MASK, 0);
5519 /* REG_WR(bp, USEM_REG_USEM_INT_MASK_0, 0); */
5520 /* REG_WR(bp, USEM_REG_USEM_INT_MASK_1, 0); */
5521 REG_WR(bp, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0);
5522 REG_WR(bp, CSDM_REG_CSDM_INT_MASK_0, 0);
5523 REG_WR(bp, CSDM_REG_CSDM_INT_MASK_1, 0);
5524 REG_WR(bp, CCM_REG_CCM_INT_MASK, 0);
5525 /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_0, 0); */
5526 /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_1, 0); */
5528 if (CHIP_REV_IS_FPGA(bp))
5529 REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, 0x580000);
5530 else if (!CHIP_IS_E1x(bp))
5531 REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0,
5532 (PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_OF
5533 | PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_AFT
5534 | PXP2_PXP2_INT_MASK_0_REG_PGL_PCIE_ATTN
5535 | PXP2_PXP2_INT_MASK_0_REG_PGL_READ_BLOCKED
5536 | PXP2_PXP2_INT_MASK_0_REG_PGL_WRITE_BLOCKED));
5538 REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, 0x480000);
5539 REG_WR(bp, TSDM_REG_TSDM_INT_MASK_0, 0);
5540 REG_WR(bp, TSDM_REG_TSDM_INT_MASK_1, 0);
5541 REG_WR(bp, TCM_REG_TCM_INT_MASK, 0);
5542 /* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_0, 0); */
5544 if (!CHIP_IS_E1x(bp))
5545 /* enable VFC attentions: bits 11 and 12, bits 31:13 reserved */
5546 REG_WR(bp, TSEM_REG_TSEM_INT_MASK_1, 0x07ff);
5548 REG_WR(bp, CDU_REG_CDU_INT_MASK, 0);
5549 REG_WR(bp, DMAE_REG_DMAE_INT_MASK, 0);
5550 /* REG_WR(bp, MISC_REG_MISC_INT_MASK, 0); */
5551 REG_WR(bp, PBF_REG_PBF_INT_MASK, 0x18); /* bit 3,4 masked */
5554 static void bnx2x_reset_common(struct bnx2x *bp)
5559 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
5562 if (CHIP_IS_E3(bp)) {
5563 val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
5564 val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
5567 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, val);
5570 static void bnx2x_setup_dmae(struct bnx2x *bp)
5573 spin_lock_init(&bp->dmae_lock);
5576 static void bnx2x_init_pxp(struct bnx2x *bp)
5579 int r_order, w_order;
5581 pci_read_config_word(bp->pdev,
5582 bp->pdev->pcie_cap + PCI_EXP_DEVCTL, &devctl);
5583 DP(NETIF_MSG_HW, "read 0x%x from devctl\n", devctl);
5584 w_order = ((devctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5);
5586 r_order = ((devctl & PCI_EXP_DEVCTL_READRQ) >> 12);
5588 DP(NETIF_MSG_HW, "force read order to %d\n", bp->mrrs);
5592 bnx2x_init_pxp_arb(bp, r_order, w_order);
5595 static void bnx2x_setup_fan_failure_detection(struct bnx2x *bp)
5605 val = SHMEM_RD(bp, dev_info.shared_hw_config.config2) &
5606 SHARED_HW_CFG_FAN_FAILURE_MASK;
5608 if (val == SHARED_HW_CFG_FAN_FAILURE_ENABLED)
5612 * The fan failure mechanism is usually related to the PHY type since
5613 * the power consumption of the board is affected by the PHY. Currently,
5614 * fan is required for most designs with SFX7101, BCM8727 and BCM8481.
5616 else if (val == SHARED_HW_CFG_FAN_FAILURE_PHY_TYPE)
5617 for (port = PORT_0; port < PORT_MAX; port++) {
5619 bnx2x_fan_failure_det_req(
5621 bp->common.shmem_base,
5622 bp->common.shmem2_base,
5626 DP(NETIF_MSG_HW, "fan detection setting: %d\n", is_required);
5628 if (is_required == 0)
5631 /* Fan failure is indicated by SPIO 5 */
5632 bnx2x_set_spio(bp, MISC_REGISTERS_SPIO_5,
5633 MISC_REGISTERS_SPIO_INPUT_HI_Z);
5635 /* set to active low mode */
5636 val = REG_RD(bp, MISC_REG_SPIO_INT);
5637 val |= ((1 << MISC_REGISTERS_SPIO_5) <<
5638 MISC_REGISTERS_SPIO_INT_OLD_SET_POS);
5639 REG_WR(bp, MISC_REG_SPIO_INT, val);
5641 /* enable interrupt to signal the IGU */
5642 val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
5643 val |= (1 << MISC_REGISTERS_SPIO_5);
5644 REG_WR(bp, MISC_REG_SPIO_EVENT_EN, val);
5647 static void bnx2x_pretend_func(struct bnx2x *bp, u8 pretend_func_num)
5653 if (CHIP_IS_E1H(bp) && (pretend_func_num >= E1H_FUNC_MAX))
5656 switch (BP_ABS_FUNC(bp)) {
5658 offset = PXP2_REG_PGL_PRETEND_FUNC_F0;
5661 offset = PXP2_REG_PGL_PRETEND_FUNC_F1;
5664 offset = PXP2_REG_PGL_PRETEND_FUNC_F2;
5667 offset = PXP2_REG_PGL_PRETEND_FUNC_F3;
5670 offset = PXP2_REG_PGL_PRETEND_FUNC_F4;
5673 offset = PXP2_REG_PGL_PRETEND_FUNC_F5;
5676 offset = PXP2_REG_PGL_PRETEND_FUNC_F6;
5679 offset = PXP2_REG_PGL_PRETEND_FUNC_F7;
5685 REG_WR(bp, offset, pretend_func_num);
5687 DP(NETIF_MSG_HW, "Pretending to func %d\n", pretend_func_num);
5690 void bnx2x_pf_disable(struct bnx2x *bp)
5692 u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
5693 val &= ~IGU_PF_CONF_FUNC_EN;
5695 REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
5696 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
5697 REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 0);
5700 static inline void bnx2x__common_init_phy(struct bnx2x *bp)
5702 u32 shmem_base[2], shmem2_base[2];
5703 shmem_base[0] = bp->common.shmem_base;
5704 shmem2_base[0] = bp->common.shmem2_base;
5705 if (!CHIP_IS_E1x(bp)) {
5707 SHMEM2_RD(bp, other_shmem_base_addr);
5709 SHMEM2_RD(bp, other_shmem2_base_addr);
5711 bnx2x_acquire_phy_lock(bp);
5712 bnx2x_common_init_phy(bp, shmem_base, shmem2_base,
5713 bp->common.chip_id);
5714 bnx2x_release_phy_lock(bp);
5718 * bnx2x_init_hw_common - initialize the HW at the COMMON phase.
5720 * @bp: driver handle
5722 static int bnx2x_init_hw_common(struct bnx2x *bp)
5726 DP(BNX2X_MSG_MCP, "starting common init func %d\n", BP_ABS_FUNC(bp));
5728 bnx2x_reset_common(bp);
5729 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0xffffffff);
5732 if (CHIP_IS_E3(bp)) {
5733 val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
5734 val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
5736 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, val);
5738 bnx2x_init_block(bp, BLOCK_MISC, PHASE_COMMON);
5740 if (!CHIP_IS_E1x(bp)) {
5744 * 4-port mode or 2-port mode we need to turn of master-enable
5745 * for everyone, after that, turn it back on for self.
5746 * so, we disregard multi-function or not, and always disable
5747 * for all functions on the given path, this means 0,2,4,6 for
5748 * path 0 and 1,3,5,7 for path 1
5750 for (abs_func_id = BP_PATH(bp);
5751 abs_func_id < E2_FUNC_MAX*2; abs_func_id += 2) {
5752 if (abs_func_id == BP_ABS_FUNC(bp)) {
5754 PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER,
5759 bnx2x_pretend_func(bp, abs_func_id);
5760 /* clear pf enable */
5761 bnx2x_pf_disable(bp);
5762 bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
5766 bnx2x_init_block(bp, BLOCK_PXP, PHASE_COMMON);
5767 if (CHIP_IS_E1(bp)) {
5768 /* enable HW interrupt from PXP on USDM overflow
5769 bit 16 on INT_MASK_0 */
5770 REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
5773 bnx2x_init_block(bp, BLOCK_PXP2, PHASE_COMMON);
5777 REG_WR(bp, PXP2_REG_RQ_QM_ENDIAN_M, 1);
5778 REG_WR(bp, PXP2_REG_RQ_TM_ENDIAN_M, 1);
5779 REG_WR(bp, PXP2_REG_RQ_SRC_ENDIAN_M, 1);
5780 REG_WR(bp, PXP2_REG_RQ_CDU_ENDIAN_M, 1);
5781 REG_WR(bp, PXP2_REG_RQ_DBG_ENDIAN_M, 1);
5782 /* make sure this value is 0 */
5783 REG_WR(bp, PXP2_REG_RQ_HC_ENDIAN_M, 0);
5785 /* REG_WR(bp, PXP2_REG_RD_PBF_SWAP_MODE, 1); */
5786 REG_WR(bp, PXP2_REG_RD_QM_SWAP_MODE, 1);
5787 REG_WR(bp, PXP2_REG_RD_TM_SWAP_MODE, 1);
5788 REG_WR(bp, PXP2_REG_RD_SRC_SWAP_MODE, 1);
5789 REG_WR(bp, PXP2_REG_RD_CDURD_SWAP_MODE, 1);
5792 bnx2x_ilt_init_page_size(bp, INITOP_SET);
5794 if (CHIP_REV_IS_FPGA(bp) && CHIP_IS_E1H(bp))
5795 REG_WR(bp, PXP2_REG_PGL_TAGS_LIMIT, 0x1);
5797 /* let the HW do it's magic ... */
5799 /* finish PXP init */
5800 val = REG_RD(bp, PXP2_REG_RQ_CFG_DONE);
5802 BNX2X_ERR("PXP2 CFG failed\n");
5805 val = REG_RD(bp, PXP2_REG_RD_INIT_DONE);
5807 BNX2X_ERR("PXP2 RD_INIT failed\n");
5811 /* Timers bug workaround E2 only. We need to set the entire ILT to
5812 * have entries with value "0" and valid bit on.
5813 * This needs to be done by the first PF that is loaded in a path
5814 * (i.e. common phase)
5816 if (!CHIP_IS_E1x(bp)) {
5817 /* In E2 there is a bug in the timers block that can cause function 6 / 7
5818 * (i.e. vnic3) to start even if it is marked as "scan-off".
5819 * This occurs when a different function (func2,3) is being marked
5820 * as "scan-off". Real-life scenario for example: if a driver is being
5821 * load-unloaded while func6,7 are down. This will cause the timer to access
5822 * the ilt, translate to a logical address and send a request to read/write.
5823 * Since the ilt for the function that is down is not valid, this will cause
5824 * a translation error which is unrecoverable.
5825 * The Workaround is intended to make sure that when this happens nothing fatal
5826 * will occur. The workaround:
5827 * 1. First PF driver which loads on a path will:
5828 * a. After taking the chip out of reset, by using pretend,
5829 * it will write "0" to the following registers of
5831 * REG_WR(pdev, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
5832 * REG_WR(pdev, CFC_REG_WEAK_ENABLE_PF,0);
5833 * REG_WR(pdev, CFC_REG_STRONG_ENABLE_PF,0);
5834 * And for itself it will write '1' to
5835 * PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER to enable
5836 * dmae-operations (writing to pram for example.)
5837 * note: can be done for only function 6,7 but cleaner this
5839 * b. Write zero+valid to the entire ILT.
5840 * c. Init the first_timers_ilt_entry, last_timers_ilt_entry of
5841 * VNIC3 (of that port). The range allocated will be the
5842 * entire ILT. This is needed to prevent ILT range error.
5843 * 2. Any PF driver load flow:
5844 * a. ILT update with the physical addresses of the allocated
5846 * b. Wait 20msec. - note that this timeout is needed to make
5847 * sure there are no requests in one of the PXP internal
5848 * queues with "old" ILT addresses.
5849 * c. PF enable in the PGLC.
5850 * d. Clear the was_error of the PF in the PGLC. (could have
5851 * occured while driver was down)
5852 * e. PF enable in the CFC (WEAK + STRONG)
5853 * f. Timers scan enable
5854 * 3. PF driver unload flow:
5855 * a. Clear the Timers scan_en.
5856 * b. Polling for scan_on=0 for that PF.
5857 * c. Clear the PF enable bit in the PXP.
5858 * d. Clear the PF enable in the CFC (WEAK + STRONG)
5859 * e. Write zero+valid to all ILT entries (The valid bit must
5861 * f. If this is VNIC 3 of a port then also init
5862 * first_timers_ilt_entry to zero and last_timers_ilt_entry
5863 * to the last enrty in the ILT.
5866 * Currently the PF error in the PGLC is non recoverable.
5867 * In the future the there will be a recovery routine for this error.
5868 * Currently attention is masked.
5869 * Having an MCP lock on the load/unload process does not guarantee that
5870 * there is no Timer disable during Func6/7 enable. This is because the
5871 * Timers scan is currently being cleared by the MCP on FLR.
5872 * Step 2.d can be done only for PF6/7 and the driver can also check if
5873 * there is error before clearing it. But the flow above is simpler and
5875 * All ILT entries are written by zero+valid and not just PF6/7
5876 * ILT entries since in the future the ILT entries allocation for
5877 * PF-s might be dynamic.
5879 struct ilt_client_info ilt_cli;
5880 struct bnx2x_ilt ilt;
5881 memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
5882 memset(&ilt, 0, sizeof(struct bnx2x_ilt));
5884 /* initialize dummy TM client */
5886 ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
5887 ilt_cli.client_num = ILT_CLIENT_TM;
5889 /* Step 1: set zeroes to all ilt page entries with valid bit on
5890 * Step 2: set the timers first/last ilt entry to point
5891 * to the entire range to prevent ILT range error for 3rd/4th
5892 * vnic (this code assumes existance of the vnic)
5894 * both steps performed by call to bnx2x_ilt_client_init_op()
5895 * with dummy TM client
5897 * we must use pretend since PXP2_REG_RQ_##blk##_FIRST_ILT
5898 * and his brother are split registers
5900 bnx2x_pretend_func(bp, (BP_PATH(bp) + 6));
5901 bnx2x_ilt_client_init_op_ilt(bp, &ilt, &ilt_cli, INITOP_CLEAR);
5902 bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
5904 REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN, BNX2X_PXP_DRAM_ALIGN);
5905 REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_RD, BNX2X_PXP_DRAM_ALIGN);
5906 REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_SEL, 1);
5910 REG_WR(bp, PXP2_REG_RQ_DISABLE_INPUTS, 0);
5911 REG_WR(bp, PXP2_REG_RD_DISABLE_INPUTS, 0);
5913 if (!CHIP_IS_E1x(bp)) {
5914 int factor = CHIP_REV_IS_EMUL(bp) ? 1000 :
5915 (CHIP_REV_IS_FPGA(bp) ? 400 : 0);
5916 bnx2x_init_block(bp, BLOCK_PGLUE_B, PHASE_COMMON);
5918 bnx2x_init_block(bp, BLOCK_ATC, PHASE_COMMON);
5920 /* let the HW do it's magic ... */
5923 val = REG_RD(bp, ATC_REG_ATC_INIT_DONE);
5924 } while (factor-- && (val != 1));
5927 BNX2X_ERR("ATC_INIT failed\n");
5932 bnx2x_init_block(bp, BLOCK_DMAE, PHASE_COMMON);
5934 /* clean the DMAE memory */
5936 bnx2x_init_fill(bp, TSEM_REG_PRAM, 0, 8, 1);
5938 bnx2x_init_block(bp, BLOCK_TCM, PHASE_COMMON);
5940 bnx2x_init_block(bp, BLOCK_UCM, PHASE_COMMON);
5942 bnx2x_init_block(bp, BLOCK_CCM, PHASE_COMMON);
5944 bnx2x_init_block(bp, BLOCK_XCM, PHASE_COMMON);
5946 bnx2x_read_dmae(bp, XSEM_REG_PASSIVE_BUFFER, 3);
5947 bnx2x_read_dmae(bp, CSEM_REG_PASSIVE_BUFFER, 3);
5948 bnx2x_read_dmae(bp, TSEM_REG_PASSIVE_BUFFER, 3);
5949 bnx2x_read_dmae(bp, USEM_REG_PASSIVE_BUFFER, 3);
5951 bnx2x_init_block(bp, BLOCK_QM, PHASE_COMMON);
5954 /* QM queues pointers table */
5955 bnx2x_qm_init_ptr_table(bp, bp->qm_cid_count, INITOP_SET);
5957 /* soft reset pulse */
5958 REG_WR(bp, QM_REG_SOFT_RESET, 1);
5959 REG_WR(bp, QM_REG_SOFT_RESET, 0);
5962 bnx2x_init_block(bp, BLOCK_TM, PHASE_COMMON);
5965 bnx2x_init_block(bp, BLOCK_DORQ, PHASE_COMMON);
5966 REG_WR(bp, DORQ_REG_DPM_CID_OFST, BNX2X_DB_SHIFT);
5967 if (!CHIP_REV_IS_SLOW(bp))
5968 /* enable hw interrupt from doorbell Q */
5969 REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
5971 bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
5973 bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
5974 REG_WR(bp, PRS_REG_A_PRSU_20, 0xf);
5976 if (!CHIP_IS_E1(bp))
5977 REG_WR(bp, PRS_REG_E1HOV_MODE, bp->path_has_ovlan);
5979 if (!CHIP_IS_E1x(bp) && !CHIP_IS_E3B0(bp))
5980 /* Bit-map indicating which L2 hdrs may appear
5981 * after the basic Ethernet header
5983 REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC,
5984 bp->path_has_ovlan ? 7 : 6);
5986 bnx2x_init_block(bp, BLOCK_TSDM, PHASE_COMMON);
5987 bnx2x_init_block(bp, BLOCK_CSDM, PHASE_COMMON);
5988 bnx2x_init_block(bp, BLOCK_USDM, PHASE_COMMON);
5989 bnx2x_init_block(bp, BLOCK_XSDM, PHASE_COMMON);
5991 if (!CHIP_IS_E1x(bp)) {
5992 /* reset VFC memories */
5993 REG_WR(bp, TSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
5994 VFC_MEMORIES_RST_REG_CAM_RST |
5995 VFC_MEMORIES_RST_REG_RAM_RST);
5996 REG_WR(bp, XSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
5997 VFC_MEMORIES_RST_REG_CAM_RST |
5998 VFC_MEMORIES_RST_REG_RAM_RST);
6003 bnx2x_init_block(bp, BLOCK_TSEM, PHASE_COMMON);
6004 bnx2x_init_block(bp, BLOCK_USEM, PHASE_COMMON);
6005 bnx2x_init_block(bp, BLOCK_CSEM, PHASE_COMMON);
6006 bnx2x_init_block(bp, BLOCK_XSEM, PHASE_COMMON);
6009 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
6011 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
6014 bnx2x_init_block(bp, BLOCK_UPB, PHASE_COMMON);
6015 bnx2x_init_block(bp, BLOCK_XPB, PHASE_COMMON);
6016 bnx2x_init_block(bp, BLOCK_PBF, PHASE_COMMON);
6018 if (!CHIP_IS_E1x(bp))
6019 REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC,
6020 bp->path_has_ovlan ? 7 : 6);
6022 REG_WR(bp, SRC_REG_SOFT_RST, 1);
6024 bnx2x_init_block(bp, BLOCK_SRC, PHASE_COMMON);
6027 REG_WR(bp, SRC_REG_KEYSEARCH_0, 0x63285672);
6028 REG_WR(bp, SRC_REG_KEYSEARCH_1, 0x24b8f2cc);
6029 REG_WR(bp, SRC_REG_KEYSEARCH_2, 0x223aef9b);
6030 REG_WR(bp, SRC_REG_KEYSEARCH_3, 0x26001e3a);
6031 REG_WR(bp, SRC_REG_KEYSEARCH_4, 0x7ae91116);
6032 REG_WR(bp, SRC_REG_KEYSEARCH_5, 0x5ce5230b);
6033 REG_WR(bp, SRC_REG_KEYSEARCH_6, 0x298d8adf);
6034 REG_WR(bp, SRC_REG_KEYSEARCH_7, 0x6eb0ff09);
6035 REG_WR(bp, SRC_REG_KEYSEARCH_8, 0x1830f82f);
6036 REG_WR(bp, SRC_REG_KEYSEARCH_9, 0x01e46be7);
6038 REG_WR(bp, SRC_REG_SOFT_RST, 0);
6040 if (sizeof(union cdu_context) != 1024)
6041 /* we currently assume that a context is 1024 bytes */
6042 dev_alert(&bp->pdev->dev, "please adjust the size "
6043 "of cdu_context(%ld)\n",
6044 (long)sizeof(union cdu_context));
6046 bnx2x_init_block(bp, BLOCK_CDU, PHASE_COMMON);
6047 val = (4 << 24) + (0 << 12) + 1024;
6048 REG_WR(bp, CDU_REG_CDU_GLOBAL_PARAMS, val);
6050 bnx2x_init_block(bp, BLOCK_CFC, PHASE_COMMON);
6051 REG_WR(bp, CFC_REG_INIT_REG, 0x7FF);
6052 /* enable context validation interrupt from CFC */
6053 REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
6055 /* set the thresholds to prevent CFC/CDU race */
6056 REG_WR(bp, CFC_REG_DEBUG0, 0x20020000);
6058 bnx2x_init_block(bp, BLOCK_HC, PHASE_COMMON);
6060 if (!CHIP_IS_E1x(bp) && BP_NOMCP(bp))
6061 REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x36);
6063 bnx2x_init_block(bp, BLOCK_IGU, PHASE_COMMON);
6064 bnx2x_init_block(bp, BLOCK_MISC_AEU, PHASE_COMMON);
6066 /* Reset PCIE errors for debug */
6067 REG_WR(bp, 0x2814, 0xffffffff);
6068 REG_WR(bp, 0x3820, 0xffffffff);
6070 if (!CHIP_IS_E1x(bp)) {
6071 REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_CONTROL_5,
6072 (PXPCS_TL_CONTROL_5_ERR_UNSPPORT1 |
6073 PXPCS_TL_CONTROL_5_ERR_UNSPPORT));
6074 REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC345_STAT,
6075 (PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT4 |
6076 PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT3 |
6077 PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT2));
6078 REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC678_STAT,
6079 (PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT7 |
6080 PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT6 |
6081 PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT5));
6084 bnx2x_init_block(bp, BLOCK_NIG, PHASE_COMMON);
6085 if (!CHIP_IS_E1(bp)) {
6086 /* in E3 this done in per-port section */
6087 if (!CHIP_IS_E3(bp))
6088 REG_WR(bp, NIG_REG_LLH_MF_MODE, IS_MF(bp));
6090 if (CHIP_IS_E1H(bp))
6091 /* not applicable for E2 (and above ...) */
6092 REG_WR(bp, NIG_REG_LLH_E1HOV_MODE, IS_MF_SD(bp));
6094 if (CHIP_REV_IS_SLOW(bp))
6097 /* finish CFC init */
6098 val = reg_poll(bp, CFC_REG_LL_INIT_DONE, 1, 100, 10);
6100 BNX2X_ERR("CFC LL_INIT failed\n");
6103 val = reg_poll(bp, CFC_REG_AC_INIT_DONE, 1, 100, 10);
6105 BNX2X_ERR("CFC AC_INIT failed\n");
6108 val = reg_poll(bp, CFC_REG_CAM_INIT_DONE, 1, 100, 10);
6110 BNX2X_ERR("CFC CAM_INIT failed\n");
6113 REG_WR(bp, CFC_REG_DEBUG0, 0);
6115 if (CHIP_IS_E1(bp)) {
6116 /* read NIG statistic
6117 to see if this is our first up since powerup */
6118 bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
6119 val = *bnx2x_sp(bp, wb_data[0]);
6121 /* do internal memory self test */
6122 if ((val == 0) && bnx2x_int_mem_test(bp)) {
6123 BNX2X_ERR("internal mem self test failed\n");
6128 bnx2x_setup_fan_failure_detection(bp);
6130 /* clear PXP2 attentions */
6131 REG_RD(bp, PXP2_REG_PXP2_INT_STS_CLR_0);
6133 bnx2x_enable_blocks_attention(bp);
6134 bnx2x_enable_blocks_parity(bp);
6136 if (!BP_NOMCP(bp)) {
6137 if (CHIP_IS_E1x(bp))
6138 bnx2x__common_init_phy(bp);
6140 BNX2X_ERR("Bootcode is missing - can not initialize link\n");
6146 * bnx2x_init_hw_common_chip - init HW at the COMMON_CHIP phase.
6148 * @bp: driver handle
6150 static int bnx2x_init_hw_common_chip(struct bnx2x *bp)
6152 int rc = bnx2x_init_hw_common(bp);
6157 /* In E2 2-PORT mode, same ext phy is used for the two paths */
6159 bnx2x__common_init_phy(bp);
6164 static int bnx2x_init_hw_port(struct bnx2x *bp)
6166 int port = BP_PORT(bp);
6167 int init_phase = port ? PHASE_PORT1 : PHASE_PORT0;
6171 bnx2x__link_reset(bp);
6173 DP(BNX2X_MSG_MCP, "starting port init port %d\n", port);
6175 REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
6177 bnx2x_init_block(bp, BLOCK_MISC, init_phase);
6178 bnx2x_init_block(bp, BLOCK_PXP, init_phase);
6179 bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
6181 /* Timers bug workaround: disables the pf_master bit in pglue at
6182 * common phase, we need to enable it here before any dmae access are
6183 * attempted. Therefore we manually added the enable-master to the
6184 * port phase (it also happens in the function phase)
6186 if (!CHIP_IS_E1x(bp))
6187 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
6189 bnx2x_init_block(bp, BLOCK_ATC, init_phase);
6190 bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
6191 bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
6192 bnx2x_init_block(bp, BLOCK_QM, init_phase);
6194 bnx2x_init_block(bp, BLOCK_TCM, init_phase);
6195 bnx2x_init_block(bp, BLOCK_UCM, init_phase);
6196 bnx2x_init_block(bp, BLOCK_CCM, init_phase);
6197 bnx2x_init_block(bp, BLOCK_XCM, init_phase);
6199 /* QM cid (connection) count */
6200 bnx2x_qm_init_cid_count(bp, bp->qm_cid_count, INITOP_SET);
6203 bnx2x_init_block(bp, BLOCK_TM, init_phase);
6204 REG_WR(bp, TM_REG_LIN0_SCAN_TIME + port*4, 20);
6205 REG_WR(bp, TM_REG_LIN0_MAX_ACTIVE_CID + port*4, 31);
6208 bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
6210 if (CHIP_IS_E1(bp) || CHIP_IS_E1H(bp)) {
6211 bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
6214 low = ((bp->flags & ONE_PORT_FLAG) ? 160 : 246);
6215 else if (bp->dev->mtu > 4096) {
6216 if (bp->flags & ONE_PORT_FLAG)
6220 /* (24*1024 + val*4)/256 */
6221 low = 96 + (val/64) +
6222 ((val % 64) ? 1 : 0);
6225 low = ((bp->flags & ONE_PORT_FLAG) ? 80 : 160);
6226 high = low + 56; /* 14*1024/256 */
6227 REG_WR(bp, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port*4, low);
6228 REG_WR(bp, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port*4, high);
6231 if (CHIP_MODE_IS_4_PORT(bp))
6232 REG_WR(bp, (BP_PORT(bp) ?
6233 BRB1_REG_MAC_GUARANTIED_1 :
6234 BRB1_REG_MAC_GUARANTIED_0), 40);
6237 bnx2x_init_block(bp, BLOCK_PRS, init_phase);
6238 if (CHIP_IS_E3B0(bp))
6239 /* Ovlan exists only if we are in multi-function +
6240 * switch-dependent mode, in switch-independent there
6241 * is no ovlan headers
6243 REG_WR(bp, BP_PORT(bp) ?
6244 PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
6245 PRS_REG_HDRS_AFTER_BASIC_PORT_0,
6246 (bp->path_has_ovlan ? 7 : 6));
6248 bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
6249 bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
6250 bnx2x_init_block(bp, BLOCK_USDM, init_phase);
6251 bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
6253 bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
6254 bnx2x_init_block(bp, BLOCK_USEM, init_phase);
6255 bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
6256 bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
6258 bnx2x_init_block(bp, BLOCK_UPB, init_phase);
6259 bnx2x_init_block(bp, BLOCK_XPB, init_phase);
6261 bnx2x_init_block(bp, BLOCK_PBF, init_phase);
6263 if (CHIP_IS_E1x(bp)) {
6264 /* configure PBF to work without PAUSE mtu 9000 */
6265 REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
6267 /* update threshold */
6268 REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, (9040/16));
6269 /* update init credit */
6270 REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, (9040/16) + 553 - 22);
6273 REG_WR(bp, PBF_REG_INIT_P0 + port*4, 1);
6275 REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0);
6279 bnx2x_init_block(bp, BLOCK_SRC, init_phase);
6281 bnx2x_init_block(bp, BLOCK_CDU, init_phase);
6282 bnx2x_init_block(bp, BLOCK_CFC, init_phase);
6284 if (CHIP_IS_E1(bp)) {
6285 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
6286 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
6288 bnx2x_init_block(bp, BLOCK_HC, init_phase);
6290 bnx2x_init_block(bp, BLOCK_IGU, init_phase);
6292 bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
6293 /* init aeu_mask_attn_func_0/1:
6294 * - SF mode: bits 3-7 are masked. only bits 0-2 are in use
6295 * - MF mode: bit 3 is masked. bits 0-2 are in use as in SF
6296 * bits 4-7 are used for "per vn group attention" */
6297 val = IS_MF(bp) ? 0xF7 : 0x7;
6298 /* Enable DCBX attention for all but E1 */
6299 val |= CHIP_IS_E1(bp) ? 0 : 0x10;
6300 REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, val);
6302 bnx2x_init_block(bp, BLOCK_NIG, init_phase);
6304 if (!CHIP_IS_E1x(bp)) {
6305 /* Bit-map indicating which L2 hdrs may appear after the
6306 * basic Ethernet header
6308 REG_WR(bp, BP_PORT(bp) ?
6309 NIG_REG_P1_HDRS_AFTER_BASIC :
6310 NIG_REG_P0_HDRS_AFTER_BASIC,
6311 IS_MF_SD(bp) ? 7 : 6);
6314 REG_WR(bp, BP_PORT(bp) ?
6315 NIG_REG_LLH1_MF_MODE :
6316 NIG_REG_LLH_MF_MODE, IS_MF(bp));
6318 if (!CHIP_IS_E3(bp))
6319 REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
6321 if (!CHIP_IS_E1(bp)) {
6322 /* 0x2 disable mf_ov, 0x1 enable */
6323 REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port*4,
6324 (IS_MF_SD(bp) ? 0x1 : 0x2));
6326 if (!CHIP_IS_E1x(bp)) {
6328 switch (bp->mf_mode) {
6329 case MULTI_FUNCTION_SD:
6332 case MULTI_FUNCTION_SI:
6337 REG_WR(bp, (BP_PORT(bp) ? NIG_REG_LLH1_CLS_TYPE :
6338 NIG_REG_LLH0_CLS_TYPE), val);
6341 REG_WR(bp, NIG_REG_LLFC_ENABLE_0 + port*4, 0);
6342 REG_WR(bp, NIG_REG_LLFC_OUT_EN_0 + port*4, 0);
6343 REG_WR(bp, NIG_REG_PAUSE_ENABLE_0 + port*4, 1);
6348 /* If SPIO5 is set to generate interrupts, enable it for this port */
6349 val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
6350 if (val & (1 << MISC_REGISTERS_SPIO_5)) {
6351 u32 reg_addr = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
6352 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
6353 val = REG_RD(bp, reg_addr);
6354 val |= AEU_INPUTS_ATTN_BITS_SPIO5;
6355 REG_WR(bp, reg_addr, val);
6361 static void bnx2x_ilt_wr(struct bnx2x *bp, u32 index, dma_addr_t addr)
6366 reg = PXP2_REG_RQ_ONCHIP_AT + index*8;
6368 reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index*8;
6370 bnx2x_wb_wr(bp, reg, ONCHIP_ADDR1(addr), ONCHIP_ADDR2(addr));
6373 static inline void bnx2x_igu_clear_sb(struct bnx2x *bp, u8 idu_sb_id)
6375 bnx2x_igu_clear_sb_gen(bp, BP_FUNC(bp), idu_sb_id, true /*PF*/);
6378 static inline void bnx2x_clear_func_ilt(struct bnx2x *bp, u32 func)
6380 u32 i, base = FUNC_ILT_BASE(func);
6381 for (i = base; i < base + ILT_PER_FUNC; i++)
6382 bnx2x_ilt_wr(bp, i, 0);
6385 static int bnx2x_init_hw_func(struct bnx2x *bp)
6387 int port = BP_PORT(bp);
6388 int func = BP_FUNC(bp);
6389 int init_phase = PHASE_PF0 + func;
6390 struct bnx2x_ilt *ilt = BP_ILT(bp);
6393 u32 main_mem_base, main_mem_size, main_mem_prty_clr;
6394 int i, main_mem_width;
6396 DP(BNX2X_MSG_MCP, "starting func init func %d\n", func);
6398 /* FLR cleanup - hmmm */
6399 if (!CHIP_IS_E1x(bp))
6400 bnx2x_pf_flr_clnup(bp);
6402 /* set MSI reconfigure capability */
6403 if (bp->common.int_block == INT_BLOCK_HC) {
6404 addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0);
6405 val = REG_RD(bp, addr);
6406 val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0;
6407 REG_WR(bp, addr, val);
6410 bnx2x_init_block(bp, BLOCK_PXP, init_phase);
6411 bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
6414 cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
6416 for (i = 0; i < L2_ILT_LINES(bp); i++) {
6417 ilt->lines[cdu_ilt_start + i].page =
6418 bp->context.vcxt + (ILT_PAGE_CIDS * i);
6419 ilt->lines[cdu_ilt_start + i].page_mapping =
6420 bp->context.cxt_mapping + (CDU_ILT_PAGE_SZ * i);
6421 /* cdu ilt pages are allocated manually so there's no need to
6424 bnx2x_ilt_init_op(bp, INITOP_SET);
6427 bnx2x_src_init_t2(bp, bp->t2, bp->t2_mapping, SRC_CONN_NUM);
6429 /* T1 hash bits value determines the T1 number of entries */
6430 REG_WR(bp, SRC_REG_NUMBER_HASH_BITS0 + port*4, SRC_HASH_BITS);
6435 REG_WR(bp, PRS_REG_NIC_MODE, 1);
6436 #endif /* BCM_CNIC */
6438 if (!CHIP_IS_E1x(bp)) {
6439 u32 pf_conf = IGU_PF_CONF_FUNC_EN;
6441 /* Turn on a single ISR mode in IGU if driver is going to use
6444 if (!(bp->flags & USING_MSIX_FLAG))
6445 pf_conf |= IGU_PF_CONF_SINGLE_ISR_EN;
6447 * Timers workaround bug: function init part.
6448 * Need to wait 20msec after initializing ILT,
6449 * needed to make sure there are no requests in
6450 * one of the PXP internal queues with "old" ILT addresses
6454 * Master enable - Due to WB DMAE writes performed before this
6455 * register is re-initialized as part of the regular function
6458 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
6459 /* Enable the function in IGU */
6460 REG_WR(bp, IGU_REG_PF_CONFIGURATION, pf_conf);
6465 bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
6467 if (!CHIP_IS_E1x(bp))
6468 REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR, func);
6470 bnx2x_init_block(bp, BLOCK_ATC, init_phase);
6471 bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
6472 bnx2x_init_block(bp, BLOCK_NIG, init_phase);
6473 bnx2x_init_block(bp, BLOCK_SRC, init_phase);
6474 bnx2x_init_block(bp, BLOCK_MISC, init_phase);
6475 bnx2x_init_block(bp, BLOCK_TCM, init_phase);
6476 bnx2x_init_block(bp, BLOCK_UCM, init_phase);
6477 bnx2x_init_block(bp, BLOCK_CCM, init_phase);
6478 bnx2x_init_block(bp, BLOCK_XCM, init_phase);
6479 bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
6480 bnx2x_init_block(bp, BLOCK_USEM, init_phase);
6481 bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
6482 bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
6484 if (!CHIP_IS_E1x(bp))
6485 REG_WR(bp, QM_REG_PF_EN, 1);
6487 if (!CHIP_IS_E1x(bp)) {
6488 REG_WR(bp, TSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
6489 REG_WR(bp, USEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
6490 REG_WR(bp, CSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
6491 REG_WR(bp, XSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
6493 bnx2x_init_block(bp, BLOCK_QM, init_phase);
6495 bnx2x_init_block(bp, BLOCK_TM, init_phase);
6496 bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
6497 bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
6498 bnx2x_init_block(bp, BLOCK_PRS, init_phase);
6499 bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
6500 bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
6501 bnx2x_init_block(bp, BLOCK_USDM, init_phase);
6502 bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
6503 bnx2x_init_block(bp, BLOCK_UPB, init_phase);
6504 bnx2x_init_block(bp, BLOCK_XPB, init_phase);
6505 bnx2x_init_block(bp, BLOCK_PBF, init_phase);
6506 if (!CHIP_IS_E1x(bp))
6507 REG_WR(bp, PBF_REG_DISABLE_PF, 0);
6509 bnx2x_init_block(bp, BLOCK_CDU, init_phase);
6511 bnx2x_init_block(bp, BLOCK_CFC, init_phase);
6513 if (!CHIP_IS_E1x(bp))
6514 REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 1);
6517 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
6518 REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + port*8, bp->mf_ov);
6521 bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
6523 /* HC init per function */
6524 if (bp->common.int_block == INT_BLOCK_HC) {
6525 if (CHIP_IS_E1H(bp)) {
6526 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
6528 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
6529 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
6531 bnx2x_init_block(bp, BLOCK_HC, init_phase);
6534 int num_segs, sb_idx, prod_offset;
6536 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
6538 if (!CHIP_IS_E1x(bp)) {
6539 REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
6540 REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
6543 bnx2x_init_block(bp, BLOCK_IGU, init_phase);
6545 if (!CHIP_IS_E1x(bp)) {
6549 * E2 mode: address 0-135 match to the mapping memory;
6550 * 136 - PF0 default prod; 137 - PF1 default prod;
6551 * 138 - PF2 default prod; 139 - PF3 default prod;
6552 * 140 - PF0 attn prod; 141 - PF1 attn prod;
6553 * 142 - PF2 attn prod; 143 - PF3 attn prod;
6556 * E1.5 mode - In backward compatible mode;
6557 * for non default SB; each even line in the memory
6558 * holds the U producer and each odd line hold
6559 * the C producer. The first 128 producers are for
6560 * NDSB (PF0 - 0-31; PF1 - 32-63 and so on). The last 20
6561 * producers are for the DSB for each PF.
6562 * Each PF has five segments: (the order inside each
6563 * segment is PF0; PF1; PF2; PF3) - 128-131 U prods;
6564 * 132-135 C prods; 136-139 X prods; 140-143 T prods;
6565 * 144-147 attn prods;
6567 /* non-default-status-blocks */
6568 num_segs = CHIP_INT_MODE_IS_BC(bp) ?
6569 IGU_BC_NDSB_NUM_SEGS : IGU_NORM_NDSB_NUM_SEGS;
6570 for (sb_idx = 0; sb_idx < bp->igu_sb_cnt; sb_idx++) {
6571 prod_offset = (bp->igu_base_sb + sb_idx) *
6574 for (i = 0; i < num_segs; i++) {
6575 addr = IGU_REG_PROD_CONS_MEMORY +
6576 (prod_offset + i) * 4;
6577 REG_WR(bp, addr, 0);
6579 /* send consumer update with value 0 */
6580 bnx2x_ack_sb(bp, bp->igu_base_sb + sb_idx,
6581 USTORM_ID, 0, IGU_INT_NOP, 1);
6582 bnx2x_igu_clear_sb(bp,
6583 bp->igu_base_sb + sb_idx);
6586 /* default-status-blocks */
6587 num_segs = CHIP_INT_MODE_IS_BC(bp) ?
6588 IGU_BC_DSB_NUM_SEGS : IGU_NORM_DSB_NUM_SEGS;
6590 if (CHIP_MODE_IS_4_PORT(bp))
6591 dsb_idx = BP_FUNC(bp);
6593 dsb_idx = BP_E1HVN(bp);
6595 prod_offset = (CHIP_INT_MODE_IS_BC(bp) ?
6596 IGU_BC_BASE_DSB_PROD + dsb_idx :
6597 IGU_NORM_BASE_DSB_PROD + dsb_idx);
6599 for (i = 0; i < (num_segs * E1HVN_MAX);
6601 addr = IGU_REG_PROD_CONS_MEMORY +
6602 (prod_offset + i)*4;
6603 REG_WR(bp, addr, 0);
6605 /* send consumer update with 0 */
6606 if (CHIP_INT_MODE_IS_BC(bp)) {
6607 bnx2x_ack_sb(bp, bp->igu_dsb_id,
6608 USTORM_ID, 0, IGU_INT_NOP, 1);
6609 bnx2x_ack_sb(bp, bp->igu_dsb_id,
6610 CSTORM_ID, 0, IGU_INT_NOP, 1);
6611 bnx2x_ack_sb(bp, bp->igu_dsb_id,
6612 XSTORM_ID, 0, IGU_INT_NOP, 1);
6613 bnx2x_ack_sb(bp, bp->igu_dsb_id,
6614 TSTORM_ID, 0, IGU_INT_NOP, 1);
6615 bnx2x_ack_sb(bp, bp->igu_dsb_id,
6616 ATTENTION_ID, 0, IGU_INT_NOP, 1);
6618 bnx2x_ack_sb(bp, bp->igu_dsb_id,
6619 USTORM_ID, 0, IGU_INT_NOP, 1);
6620 bnx2x_ack_sb(bp, bp->igu_dsb_id,
6621 ATTENTION_ID, 0, IGU_INT_NOP, 1);
6623 bnx2x_igu_clear_sb(bp, bp->igu_dsb_id);
6625 /* !!! these should become driver const once
6626 rf-tool supports split-68 const */
6627 REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_LSB, 0);
6628 REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_MSB, 0);
6629 REG_WR(bp, IGU_REG_SB_MASK_LSB, 0);
6630 REG_WR(bp, IGU_REG_SB_MASK_MSB, 0);
6631 REG_WR(bp, IGU_REG_PBA_STATUS_LSB, 0);
6632 REG_WR(bp, IGU_REG_PBA_STATUS_MSB, 0);
6636 /* Reset PCIE errors for debug */
6637 REG_WR(bp, 0x2114, 0xffffffff);
6638 REG_WR(bp, 0x2120, 0xffffffff);
6640 if (CHIP_IS_E1x(bp)) {
6641 main_mem_size = HC_REG_MAIN_MEMORY_SIZE / 2; /*dwords*/
6642 main_mem_base = HC_REG_MAIN_MEMORY +
6643 BP_PORT(bp) * (main_mem_size * 4);
6644 main_mem_prty_clr = HC_REG_HC_PRTY_STS_CLR;
6647 val = REG_RD(bp, main_mem_prty_clr);
6649 DP(BNX2X_MSG_MCP, "Hmmm... Parity errors in HC "
6651 "function init (0x%x)!\n", val);
6653 /* Clear "false" parity errors in MSI-X table */
6654 for (i = main_mem_base;
6655 i < main_mem_base + main_mem_size * 4;
6656 i += main_mem_width) {
6657 bnx2x_read_dmae(bp, i, main_mem_width / 4);
6658 bnx2x_write_dmae(bp, bnx2x_sp_mapping(bp, wb_data),
6659 i, main_mem_width / 4);
6661 /* Clear HC parity attention */
6662 REG_RD(bp, main_mem_prty_clr);
6665 #ifdef BNX2X_STOP_ON_ERROR
6666 /* Enable STORMs SP logging */
6667 REG_WR8(bp, BAR_USTRORM_INTMEM +
6668 USTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
6669 REG_WR8(bp, BAR_TSTRORM_INTMEM +
6670 TSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
6671 REG_WR8(bp, BAR_CSTRORM_INTMEM +
6672 CSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
6673 REG_WR8(bp, BAR_XSTRORM_INTMEM +
6674 XSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
6677 bnx2x_phy_probe(&bp->link_params);
6683 void bnx2x_free_mem(struct bnx2x *bp)
6686 bnx2x_free_fp_mem(bp);
6687 /* end of fastpath */
6689 BNX2X_PCI_FREE(bp->def_status_blk, bp->def_status_blk_mapping,
6690 sizeof(struct host_sp_status_block));
6692 BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
6693 bp->fw_stats_data_sz + bp->fw_stats_req_sz);
6695 BNX2X_PCI_FREE(bp->slowpath, bp->slowpath_mapping,
6696 sizeof(struct bnx2x_slowpath));
6698 BNX2X_PCI_FREE(bp->context.vcxt, bp->context.cxt_mapping,
6701 bnx2x_ilt_mem_op(bp, ILT_MEMOP_FREE);
6703 BNX2X_FREE(bp->ilt->lines);
6706 if (!CHIP_IS_E1x(bp))
6707 BNX2X_PCI_FREE(bp->cnic_sb.e2_sb, bp->cnic_sb_mapping,
6708 sizeof(struct host_hc_status_block_e2));
6710 BNX2X_PCI_FREE(bp->cnic_sb.e1x_sb, bp->cnic_sb_mapping,
6711 sizeof(struct host_hc_status_block_e1x));
6713 BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
6716 BNX2X_PCI_FREE(bp->spq, bp->spq_mapping, BCM_PAGE_SIZE);
6718 BNX2X_PCI_FREE(bp->eq_ring, bp->eq_mapping,
6719 BCM_PAGE_SIZE * NUM_EQ_PAGES);
6722 static inline int bnx2x_alloc_fw_stats_mem(struct bnx2x *bp)
6726 /* number of eth_queues */
6727 u8 num_queue_stats = BNX2X_NUM_ETH_QUEUES(bp);
6729 /* Total number of FW statistics requests =
6730 * 1 for port stats + 1 for PF stats + num_eth_queues */
6731 bp->fw_stats_num = 2 + num_queue_stats;
6734 /* Request is built from stats_query_header and an array of
6735 * stats_query_cmd_group each of which contains
6736 * STATS_QUERY_CMD_COUNT rules. The real number or requests is
6737 * configured in the stats_query_header.
6739 num_groups = (2 + num_queue_stats) / STATS_QUERY_CMD_COUNT +
6740 (((2 + num_queue_stats) % STATS_QUERY_CMD_COUNT) ? 1 : 0);
6742 bp->fw_stats_req_sz = sizeof(struct stats_query_header) +
6743 num_groups * sizeof(struct stats_query_cmd_group);
6745 /* Data for statistics requests + stats_conter
6747 * stats_counter holds per-STORM counters that are incremented
6748 * when STORM has finished with the current request.
6750 bp->fw_stats_data_sz = sizeof(struct per_port_stats) +
6751 sizeof(struct per_pf_stats) +
6752 sizeof(struct per_queue_stats) * num_queue_stats +
6753 sizeof(struct stats_counter);
6755 BNX2X_PCI_ALLOC(bp->fw_stats, &bp->fw_stats_mapping,
6756 bp->fw_stats_data_sz + bp->fw_stats_req_sz);
6759 bp->fw_stats_req = (struct bnx2x_fw_stats_req *)bp->fw_stats;
6760 bp->fw_stats_req_mapping = bp->fw_stats_mapping;
6762 bp->fw_stats_data = (struct bnx2x_fw_stats_data *)
6763 ((u8 *)bp->fw_stats + bp->fw_stats_req_sz);
6765 bp->fw_stats_data_mapping = bp->fw_stats_mapping +
6766 bp->fw_stats_req_sz;
6770 BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
6771 bp->fw_stats_data_sz + bp->fw_stats_req_sz);
6776 int bnx2x_alloc_mem(struct bnx2x *bp)
6779 if (!CHIP_IS_E1x(bp))
6780 /* size = the status block + ramrod buffers */
6781 BNX2X_PCI_ALLOC(bp->cnic_sb.e2_sb, &bp->cnic_sb_mapping,
6782 sizeof(struct host_hc_status_block_e2));
6784 BNX2X_PCI_ALLOC(bp->cnic_sb.e1x_sb, &bp->cnic_sb_mapping,
6785 sizeof(struct host_hc_status_block_e1x));
6787 /* allocate searcher T2 table */
6788 BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ);
6792 BNX2X_PCI_ALLOC(bp->def_status_blk, &bp->def_status_blk_mapping,
6793 sizeof(struct host_sp_status_block));
6795 BNX2X_PCI_ALLOC(bp->slowpath, &bp->slowpath_mapping,
6796 sizeof(struct bnx2x_slowpath));
6798 /* Allocated memory for FW statistics */
6799 if (bnx2x_alloc_fw_stats_mem(bp))
6802 bp->context.size = sizeof(union cdu_context) * BNX2X_L2_CID_COUNT(bp);
6804 BNX2X_PCI_ALLOC(bp->context.vcxt, &bp->context.cxt_mapping,
6807 BNX2X_ALLOC(bp->ilt->lines, sizeof(struct ilt_line) * ILT_MAX_LINES);
6809 if (bnx2x_ilt_mem_op(bp, ILT_MEMOP_ALLOC))
6812 /* Slow path ring */
6813 BNX2X_PCI_ALLOC(bp->spq, &bp->spq_mapping, BCM_PAGE_SIZE);
6816 BNX2X_PCI_ALLOC(bp->eq_ring, &bp->eq_mapping,
6817 BCM_PAGE_SIZE * NUM_EQ_PAGES);
6821 /* need to be done at the end, since it's self adjusting to amount
6822 * of memory available for RSS queues
6824 if (bnx2x_alloc_fp_mem(bp))
6834 * Init service functions
6837 int bnx2x_set_mac_one(struct bnx2x *bp, u8 *mac,
6838 struct bnx2x_vlan_mac_obj *obj, bool set,
6839 int mac_type, unsigned long *ramrod_flags)
6842 struct bnx2x_vlan_mac_ramrod_params ramrod_param;
6844 memset(&ramrod_param, 0, sizeof(ramrod_param));
6846 /* Fill general parameters */
6847 ramrod_param.vlan_mac_obj = obj;
6848 ramrod_param.ramrod_flags = *ramrod_flags;
6850 /* Fill a user request section if needed */
6851 if (!test_bit(RAMROD_CONT, ramrod_flags)) {
6852 memcpy(ramrod_param.user_req.u.mac.mac, mac, ETH_ALEN);
6854 __set_bit(mac_type, &ramrod_param.user_req.vlan_mac_flags);
6856 /* Set the command: ADD or DEL */
6858 ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_ADD;
6860 ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_DEL;
6863 rc = bnx2x_config_vlan_mac(bp, &ramrod_param);
6865 BNX2X_ERR("%s MAC failed\n", (set ? "Set" : "Del"));
6869 int bnx2x_del_all_macs(struct bnx2x *bp,
6870 struct bnx2x_vlan_mac_obj *mac_obj,
6871 int mac_type, bool wait_for_comp)
6874 unsigned long ramrod_flags = 0, vlan_mac_flags = 0;
6876 /* Wait for completion of requested */
6878 __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
6880 /* Set the mac type of addresses we want to clear */
6881 __set_bit(mac_type, &vlan_mac_flags);
6883 rc = mac_obj->delete_all(bp, mac_obj, &vlan_mac_flags, &ramrod_flags);
6885 BNX2X_ERR("Failed to delete MACs: %d\n", rc);
6890 int bnx2x_set_eth_mac(struct bnx2x *bp, bool set)
6892 unsigned long ramrod_flags = 0;
6894 DP(NETIF_MSG_IFUP, "Adding Eth MAC\n");
6896 __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
6897 /* Eth MAC is set on RSS leading client (fp[0]) */
6898 return bnx2x_set_mac_one(bp, bp->dev->dev_addr, &bp->fp->mac_obj, set,
6899 BNX2X_ETH_MAC, &ramrod_flags);
6902 int bnx2x_setup_leading(struct bnx2x *bp)
6904 return bnx2x_setup_queue(bp, &bp->fp[0], 1);
6908 * bnx2x_set_int_mode - configure interrupt mode
6910 * @bp: driver handle
6912 * In case of MSI-X it will also try to enable MSI-X.
6914 static void __devinit bnx2x_set_int_mode(struct bnx2x *bp)
6918 bnx2x_enable_msi(bp);
6919 /* falling through... */
6921 bp->num_queues = 1 + NON_ETH_CONTEXT_USE;
6922 DP(NETIF_MSG_IFUP, "set number of queues to 1\n");
6925 /* Set number of queues according to bp->multi_mode value */
6926 bnx2x_set_num_queues(bp);
6928 DP(NETIF_MSG_IFUP, "set number of queues to %d\n",
6931 /* if we can't use MSI-X we only need one fp,
6932 * so try to enable MSI-X with the requested number of fp's
6933 * and fallback to MSI or legacy INTx with one fp
6935 if (bnx2x_enable_msix(bp)) {
6936 /* failed to enable MSI-X */
6939 "Multi requested but failed to "
6940 "enable MSI-X (%d), "
6941 "set number of queues to %d\n",
6943 1 + NON_ETH_CONTEXT_USE);
6944 bp->num_queues = 1 + NON_ETH_CONTEXT_USE;
6946 /* Try to enable MSI */
6947 if (!(bp->flags & DISABLE_MSI_FLAG))
6948 bnx2x_enable_msi(bp);
6954 /* must be called prioir to any HW initializations */
6955 static inline u16 bnx2x_cid_ilt_lines(struct bnx2x *bp)
6957 return L2_ILT_LINES(bp);
6960 void bnx2x_ilt_set_info(struct bnx2x *bp)
6962 struct ilt_client_info *ilt_client;
6963 struct bnx2x_ilt *ilt = BP_ILT(bp);
6966 ilt->start_line = FUNC_ILT_BASE(BP_FUNC(bp));
6967 DP(BNX2X_MSG_SP, "ilt starts at line %d\n", ilt->start_line);
6970 ilt_client = &ilt->clients[ILT_CLIENT_CDU];
6971 ilt_client->client_num = ILT_CLIENT_CDU;
6972 ilt_client->page_size = CDU_ILT_PAGE_SZ;
6973 ilt_client->flags = ILT_CLIENT_SKIP_MEM;
6974 ilt_client->start = line;
6975 line += bnx2x_cid_ilt_lines(bp);
6977 line += CNIC_ILT_LINES;
6979 ilt_client->end = line - 1;
6981 DP(BNX2X_MSG_SP, "ilt client[CDU]: start %d, end %d, psz 0x%x, "
6982 "flags 0x%x, hw psz %d\n",
6985 ilt_client->page_size,
6987 ilog2(ilt_client->page_size >> 12));
6990 if (QM_INIT(bp->qm_cid_count)) {
6991 ilt_client = &ilt->clients[ILT_CLIENT_QM];
6992 ilt_client->client_num = ILT_CLIENT_QM;
6993 ilt_client->page_size = QM_ILT_PAGE_SZ;
6994 ilt_client->flags = 0;
6995 ilt_client->start = line;
6997 /* 4 bytes for each cid */
6998 line += DIV_ROUND_UP(bp->qm_cid_count * QM_QUEUES_PER_FUNC * 4,
7001 ilt_client->end = line - 1;
7003 DP(BNX2X_MSG_SP, "ilt client[QM]: start %d, end %d, psz 0x%x, "
7004 "flags 0x%x, hw psz %d\n",
7007 ilt_client->page_size,
7009 ilog2(ilt_client->page_size >> 12));
7013 ilt_client = &ilt->clients[ILT_CLIENT_SRC];
7015 ilt_client->client_num = ILT_CLIENT_SRC;
7016 ilt_client->page_size = SRC_ILT_PAGE_SZ;
7017 ilt_client->flags = 0;
7018 ilt_client->start = line;
7019 line += SRC_ILT_LINES;
7020 ilt_client->end = line - 1;
7022 DP(BNX2X_MSG_SP, "ilt client[SRC]: start %d, end %d, psz 0x%x, "
7023 "flags 0x%x, hw psz %d\n",
7026 ilt_client->page_size,
7028 ilog2(ilt_client->page_size >> 12));
7031 ilt_client->flags = (ILT_CLIENT_SKIP_INIT | ILT_CLIENT_SKIP_MEM);
7035 ilt_client = &ilt->clients[ILT_CLIENT_TM];
7037 ilt_client->client_num = ILT_CLIENT_TM;
7038 ilt_client->page_size = TM_ILT_PAGE_SZ;
7039 ilt_client->flags = 0;
7040 ilt_client->start = line;
7041 line += TM_ILT_LINES;
7042 ilt_client->end = line - 1;
7044 DP(BNX2X_MSG_SP, "ilt client[TM]: start %d, end %d, psz 0x%x, "
7045 "flags 0x%x, hw psz %d\n",
7048 ilt_client->page_size,
7050 ilog2(ilt_client->page_size >> 12));
7053 ilt_client->flags = (ILT_CLIENT_SKIP_INIT | ILT_CLIENT_SKIP_MEM);
7055 BUG_ON(line > ILT_MAX_LINES);
7059 * bnx2x_pf_q_prep_init - prepare INIT transition parameters
7061 * @bp: driver handle
7062 * @fp: pointer to fastpath
7063 * @init_params: pointer to parameters structure
7065 * parameters configured:
7066 * - HC configuration
7067 * - Queue's CDU context
7069 static inline void bnx2x_pf_q_prep_init(struct bnx2x *bp,
7070 struct bnx2x_fastpath *fp, struct bnx2x_queue_init_params *init_params)
7074 /* FCoE Queue uses Default SB, thus has no HC capabilities */
7075 if (!IS_FCOE_FP(fp)) {
7076 __set_bit(BNX2X_Q_FLG_HC, &init_params->rx.flags);
7077 __set_bit(BNX2X_Q_FLG_HC, &init_params->tx.flags);
7079 /* If HC is supporterd, enable host coalescing in the transition
7082 __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->rx.flags);
7083 __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->tx.flags);
7086 init_params->rx.hc_rate = bp->rx_ticks ?
7087 (1000000 / bp->rx_ticks) : 0;
7088 init_params->tx.hc_rate = bp->tx_ticks ?
7089 (1000000 / bp->tx_ticks) : 0;
7092 init_params->rx.fw_sb_id = init_params->tx.fw_sb_id =
7096 * CQ index among the SB indices: FCoE clients uses the default
7097 * SB, therefore it's different.
7099 init_params->rx.sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
7100 init_params->tx.sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS;
7103 /* set maximum number of COSs supported by this queue */
7104 init_params->max_cos = fp->max_cos;
7106 DP(BNX2X_MSG_SP, "fp: %d setting queue params max cos to: %d",
7107 fp->index, init_params->max_cos);
7109 /* set the context pointers queue object */
7110 for (cos = FIRST_TX_COS_INDEX; cos < init_params->max_cos; cos++)
7111 init_params->cxts[cos] =
7112 &bp->context.vcxt[fp->txdata[cos].cid].eth;
7115 int bnx2x_setup_tx_only(struct bnx2x *bp, struct bnx2x_fastpath *fp,
7116 struct bnx2x_queue_state_params *q_params,
7117 struct bnx2x_queue_setup_tx_only_params *tx_only_params,
7118 int tx_index, bool leading)
7120 memset(tx_only_params, 0, sizeof(*tx_only_params));
7122 /* Set the command */
7123 q_params->cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
7125 /* Set tx-only QUEUE flags: don't zero statistics */
7126 tx_only_params->flags = bnx2x_get_common_flags(bp, fp, false);
7128 /* choose the index of the cid to send the slow path on */
7129 tx_only_params->cid_index = tx_index;
7131 /* Set general TX_ONLY_SETUP parameters */
7132 bnx2x_pf_q_prep_general(bp, fp, &tx_only_params->gen_params, tx_index);
7134 /* Set Tx TX_ONLY_SETUP parameters */
7135 bnx2x_pf_tx_q_prep(bp, fp, &tx_only_params->txq_params, tx_index);
7137 DP(BNX2X_MSG_SP, "preparing to send tx-only ramrod for connection:"
7138 "cos %d, primary cid %d, cid %d, "
7139 "client id %d, sp-client id %d, flags %lx",
7140 tx_index, q_params->q_obj->cids[FIRST_TX_COS_INDEX],
7141 q_params->q_obj->cids[tx_index], q_params->q_obj->cl_id,
7142 tx_only_params->gen_params.spcl_id, tx_only_params->flags);
7144 /* send the ramrod */
7145 return bnx2x_queue_state_change(bp, q_params);
7150 * bnx2x_setup_queue - setup queue
7152 * @bp: driver handle
7153 * @fp: pointer to fastpath
7154 * @leading: is leading
7156 * This function performs 2 steps in a Queue state machine
7157 * actually: 1) RESET->INIT 2) INIT->SETUP
7160 int bnx2x_setup_queue(struct bnx2x *bp, struct bnx2x_fastpath *fp,
7163 struct bnx2x_queue_state_params q_params = {0};
7164 struct bnx2x_queue_setup_params *setup_params =
7165 &q_params.params.setup;
7166 struct bnx2x_queue_setup_tx_only_params *tx_only_params =
7167 &q_params.params.tx_only;
7171 DP(BNX2X_MSG_SP, "setting up queue %d", fp->index);
7173 /* reset IGU state skip FCoE L2 queue */
7174 if (!IS_FCOE_FP(fp))
7175 bnx2x_ack_sb(bp, fp->igu_sb_id, USTORM_ID, 0,
7178 q_params.q_obj = &fp->q_obj;
7179 /* We want to wait for completion in this context */
7180 __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
7182 /* Prepare the INIT parameters */
7183 bnx2x_pf_q_prep_init(bp, fp, &q_params.params.init);
7185 /* Set the command */
7186 q_params.cmd = BNX2X_Q_CMD_INIT;
7188 /* Change the state to INIT */
7189 rc = bnx2x_queue_state_change(bp, &q_params);
7191 BNX2X_ERR("Queue(%d) INIT failed\n", fp->index);
7195 DP(BNX2X_MSG_SP, "init complete");
7198 /* Now move the Queue to the SETUP state... */
7199 memset(setup_params, 0, sizeof(*setup_params));
7201 /* Set QUEUE flags */
7202 setup_params->flags = bnx2x_get_q_flags(bp, fp, leading);
7204 /* Set general SETUP parameters */
7205 bnx2x_pf_q_prep_general(bp, fp, &setup_params->gen_params,
7206 FIRST_TX_COS_INDEX);
7208 bnx2x_pf_rx_q_prep(bp, fp, &setup_params->pause_params,
7209 &setup_params->rxq_params);
7211 bnx2x_pf_tx_q_prep(bp, fp, &setup_params->txq_params,
7212 FIRST_TX_COS_INDEX);
7214 /* Set the command */
7215 q_params.cmd = BNX2X_Q_CMD_SETUP;
7217 /* Change the state to SETUP */
7218 rc = bnx2x_queue_state_change(bp, &q_params);
7220 BNX2X_ERR("Queue(%d) SETUP failed\n", fp->index);
7224 /* loop through the relevant tx-only indices */
7225 for (tx_index = FIRST_TX_ONLY_COS_INDEX;
7226 tx_index < fp->max_cos;
7229 /* prepare and send tx-only ramrod*/
7230 rc = bnx2x_setup_tx_only(bp, fp, &q_params,
7231 tx_only_params, tx_index, leading);
7233 BNX2X_ERR("Queue(%d.%d) TX_ONLY_SETUP failed\n",
7234 fp->index, tx_index);
7242 static int bnx2x_stop_queue(struct bnx2x *bp, int index)
7244 struct bnx2x_fastpath *fp = &bp->fp[index];
7245 struct bnx2x_fp_txdata *txdata;
7246 struct bnx2x_queue_state_params q_params = {0};
7249 DP(BNX2X_MSG_SP, "stopping queue %d cid %d", index, fp->cid);
7251 q_params.q_obj = &fp->q_obj;
7252 /* We want to wait for completion in this context */
7253 __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
7256 /* close tx-only connections */
7257 for (tx_index = FIRST_TX_ONLY_COS_INDEX;
7258 tx_index < fp->max_cos;
7261 /* ascertain this is a normal queue*/
7262 txdata = &fp->txdata[tx_index];
7264 DP(BNX2X_MSG_SP, "stopping tx-only queue %d",
7267 /* send halt terminate on tx-only connection */
7268 q_params.cmd = BNX2X_Q_CMD_TERMINATE;
7269 memset(&q_params.params.terminate, 0,
7270 sizeof(q_params.params.terminate));
7271 q_params.params.terminate.cid_index = tx_index;
7273 rc = bnx2x_queue_state_change(bp, &q_params);
7277 /* send halt terminate on tx-only connection */
7278 q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
7279 memset(&q_params.params.cfc_del, 0,
7280 sizeof(q_params.params.cfc_del));
7281 q_params.params.cfc_del.cid_index = tx_index;
7282 rc = bnx2x_queue_state_change(bp, &q_params);
7286 /* Stop the primary connection: */
7287 /* ...halt the connection */
7288 q_params.cmd = BNX2X_Q_CMD_HALT;
7289 rc = bnx2x_queue_state_change(bp, &q_params);
7293 /* ...terminate the connection */
7294 q_params.cmd = BNX2X_Q_CMD_TERMINATE;
7295 memset(&q_params.params.terminate, 0,
7296 sizeof(q_params.params.terminate));
7297 q_params.params.terminate.cid_index = FIRST_TX_COS_INDEX;
7298 rc = bnx2x_queue_state_change(bp, &q_params);
7301 /* ...delete cfc entry */
7302 q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
7303 memset(&q_params.params.cfc_del, 0,
7304 sizeof(q_params.params.cfc_del));
7305 q_params.params.cfc_del.cid_index = FIRST_TX_COS_INDEX;
7306 return bnx2x_queue_state_change(bp, &q_params);
7310 static void bnx2x_reset_func(struct bnx2x *bp)
7312 int port = BP_PORT(bp);
7313 int func = BP_FUNC(bp);
7316 /* Disable the function in the FW */
7317 REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(func), 0);
7318 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(func), 0);
7319 REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(func), 0);
7320 REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(func), 0);
7323 for_each_eth_queue(bp, i) {
7324 struct bnx2x_fastpath *fp = &bp->fp[i];
7325 REG_WR8(bp, BAR_CSTRORM_INTMEM +
7326 CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(fp->fw_sb_id),
7332 REG_WR8(bp, BAR_CSTRORM_INTMEM +
7333 CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(bnx2x_cnic_fw_sb_id(bp)),
7337 REG_WR8(bp, BAR_CSTRORM_INTMEM +
7338 CSTORM_SP_STATUS_BLOCK_DATA_STATE_OFFSET(func),
7341 for (i = 0; i < XSTORM_SPQ_DATA_SIZE / 4; i++)
7342 REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_DATA_OFFSET(func),
7346 if (bp->common.int_block == INT_BLOCK_HC) {
7347 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
7348 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
7350 REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
7351 REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
7355 /* Disable Timer scan */
7356 REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + port*4, 0);
7358 * Wait for at least 10ms and up to 2 second for the timers scan to
7361 for (i = 0; i < 200; i++) {
7363 if (!REG_RD(bp, TM_REG_LIN0_SCAN_ON + port*4))
7368 bnx2x_clear_func_ilt(bp, func);
7370 /* Timers workaround bug for E2: if this is vnic-3,
7371 * we need to set the entire ilt range for this timers.
7373 if (!CHIP_IS_E1x(bp) && BP_VN(bp) == 3) {
7374 struct ilt_client_info ilt_cli;
7375 /* use dummy TM client */
7376 memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
7378 ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
7379 ilt_cli.client_num = ILT_CLIENT_TM;
7381 bnx2x_ilt_boundry_init_op(bp, &ilt_cli, 0, INITOP_CLEAR);
7384 /* this assumes that reset_port() called before reset_func()*/
7385 if (!CHIP_IS_E1x(bp))
7386 bnx2x_pf_disable(bp);
7391 static void bnx2x_reset_port(struct bnx2x *bp)
7393 int port = BP_PORT(bp);
7396 /* Reset physical Link */
7397 bnx2x__link_reset(bp);
7399 REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
7401 /* Do not rcv packets to BRB */
7402 REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0);
7403 /* Do not direct rcv packets that are not for MCP to the BRB */
7404 REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
7405 NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
7408 REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0);
7411 /* Check for BRB port occupancy */
7412 val = REG_RD(bp, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4);
7414 DP(NETIF_MSG_IFDOWN,
7415 "BRB1 is not empty %d blocks are occupied\n", val);
7417 /* TODO: Close Doorbell port? */
7420 static inline int bnx2x_reset_hw(struct bnx2x *bp, u32 load_code)
7422 struct bnx2x_func_state_params func_params = {0};
7424 /* Prepare parameters for function state transitions */
7425 __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
7427 func_params.f_obj = &bp->func_obj;
7428 func_params.cmd = BNX2X_F_CMD_HW_RESET;
7430 func_params.params.hw_init.load_phase = load_code;
7432 return bnx2x_func_state_change(bp, &func_params);
7435 static inline int bnx2x_func_stop(struct bnx2x *bp)
7437 struct bnx2x_func_state_params func_params = {0};
7440 /* Prepare parameters for function state transitions */
7441 __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
7442 func_params.f_obj = &bp->func_obj;
7443 func_params.cmd = BNX2X_F_CMD_STOP;
7446 * Try to stop the function the 'good way'. If fails (in case
7447 * of a parity error during bnx2x_chip_cleanup()) and we are
7448 * not in a debug mode, perform a state transaction in order to
7449 * enable further HW_RESET transaction.
7451 rc = bnx2x_func_state_change(bp, &func_params);
7453 #ifdef BNX2X_STOP_ON_ERROR
7456 BNX2X_ERR("FUNC_STOP ramrod failed. Running a dry "
7458 __set_bit(RAMROD_DRV_CLR_ONLY, &func_params.ramrod_flags);
7459 return bnx2x_func_state_change(bp, &func_params);
7467 * bnx2x_send_unload_req - request unload mode from the MCP.
7469 * @bp: driver handle
7470 * @unload_mode: requested function's unload mode
7472 * Return unload mode returned by the MCP: COMMON, PORT or FUNC.
7474 u32 bnx2x_send_unload_req(struct bnx2x *bp, int unload_mode)
7477 int port = BP_PORT(bp);
7479 /* Select the UNLOAD request mode */
7480 if (unload_mode == UNLOAD_NORMAL)
7481 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
7483 else if (bp->flags & NO_WOL_FLAG)
7484 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP;
7487 u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
7488 u8 *mac_addr = bp->dev->dev_addr;
7490 /* The mac address is written to entries 1-4 to
7491 preserve entry 0 which is used by the PMF */
7492 u8 entry = (BP_E1HVN(bp) + 1)*8;
7494 val = (mac_addr[0] << 8) | mac_addr[1];
7495 EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry, val);
7497 val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
7498 (mac_addr[4] << 8) | mac_addr[5];
7499 EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry + 4, val);
7501 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_EN;
7504 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
7506 /* Send the request to the MCP */
7508 reset_code = bnx2x_fw_command(bp, reset_code, 0);
7510 int path = BP_PATH(bp);
7512 DP(NETIF_MSG_IFDOWN, "NO MCP - load counts[%d] "
7514 path, load_count[path][0], load_count[path][1],
7515 load_count[path][2]);
7516 load_count[path][0]--;
7517 load_count[path][1 + port]--;
7518 DP(NETIF_MSG_IFDOWN, "NO MCP - new load counts[%d] "
7520 path, load_count[path][0], load_count[path][1],
7521 load_count[path][2]);
7522 if (load_count[path][0] == 0)
7523 reset_code = FW_MSG_CODE_DRV_UNLOAD_COMMON;
7524 else if (load_count[path][1 + port] == 0)
7525 reset_code = FW_MSG_CODE_DRV_UNLOAD_PORT;
7527 reset_code = FW_MSG_CODE_DRV_UNLOAD_FUNCTION;
7534 * bnx2x_send_unload_done - send UNLOAD_DONE command to the MCP.
7536 * @bp: driver handle
7538 void bnx2x_send_unload_done(struct bnx2x *bp)
7540 /* Report UNLOAD_DONE to MCP */
7542 bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
7545 static inline int bnx2x_func_wait_started(struct bnx2x *bp)
7548 int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
7554 * (assumption: No Attention from MCP at this stage)
7555 * PMF probably in the middle of TXdisable/enable transaction
7556 * 1. Sync IRS for default SB
7557 * 2. Sync SP queue - this guarantes us that attention handling started
7558 * 3. Wait, that TXdisable/enable transaction completes
7560 * 1+2 guranty that if DCBx attention was scheduled it already changed
7561 * pending bit of transaction from STARTED-->TX_STOPPED, if we alredy
7562 * received complettion for the transaction the state is TX_STOPPED.
7563 * State will return to STARTED after completion of TX_STOPPED-->STARTED
7567 /* make sure default SB ISR is done */
7569 synchronize_irq(bp->msix_table[0].vector);
7571 synchronize_irq(bp->pdev->irq);
7573 flush_workqueue(bnx2x_wq);
7575 while (bnx2x_func_get_state(bp, &bp->func_obj) !=
7576 BNX2X_F_STATE_STARTED && tout--)
7579 if (bnx2x_func_get_state(bp, &bp->func_obj) !=
7580 BNX2X_F_STATE_STARTED) {
7581 #ifdef BNX2X_STOP_ON_ERROR
7585 * Failed to complete the transaction in a "good way"
7586 * Force both transactions with CLR bit
7588 struct bnx2x_func_state_params func_params = {0};
7590 DP(BNX2X_MSG_SP, "Hmmm... unexpected function state! "
7591 "Forcing STARTED-->TX_ST0PPED-->STARTED\n");
7593 func_params.f_obj = &bp->func_obj;
7594 __set_bit(RAMROD_DRV_CLR_ONLY,
7595 &func_params.ramrod_flags);
7597 /* STARTED-->TX_ST0PPED */
7598 func_params.cmd = BNX2X_F_CMD_TX_STOP;
7599 bnx2x_func_state_change(bp, &func_params);
7601 /* TX_ST0PPED-->STARTED */
7602 func_params.cmd = BNX2X_F_CMD_TX_START;
7603 return bnx2x_func_state_change(bp, &func_params);
7610 void bnx2x_chip_cleanup(struct bnx2x *bp, int unload_mode)
7612 int port = BP_PORT(bp);
7615 struct bnx2x_mcast_ramrod_params rparam = {0};
7618 /* Wait until tx fastpath tasks complete */
7619 for_each_tx_queue(bp, i) {
7620 struct bnx2x_fastpath *fp = &bp->fp[i];
7622 for_each_cos_in_tx_queue(fp, cos)
7623 rc = bnx2x_clean_tx_queue(bp, &fp->txdata[cos]);
7624 #ifdef BNX2X_STOP_ON_ERROR
7630 /* Give HW time to discard old tx messages */
7631 usleep_range(1000, 1000);
7633 /* Clean all ETH MACs */
7634 rc = bnx2x_del_all_macs(bp, &bp->fp[0].mac_obj, BNX2X_ETH_MAC, false);
7636 BNX2X_ERR("Failed to delete all ETH macs: %d\n", rc);
7638 /* Clean up UC list */
7639 rc = bnx2x_del_all_macs(bp, &bp->fp[0].mac_obj, BNX2X_UC_LIST_MAC,
7642 BNX2X_ERR("Failed to schedule DEL commands for UC MACs list: "
7646 if (!CHIP_IS_E1(bp))
7647 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
7649 /* Set "drop all" (stop Rx).
7650 * We need to take a netif_addr_lock() here in order to prevent
7651 * a race between the completion code and this code.
7653 netif_addr_lock_bh(bp->dev);
7654 /* Schedule the rx_mode command */
7655 if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
7656 set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
7658 bnx2x_set_storm_rx_mode(bp);
7660 /* Cleanup multicast configuration */
7661 rparam.mcast_obj = &bp->mcast_obj;
7662 rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
7664 BNX2X_ERR("Failed to send DEL multicast command: %d\n", rc);
7666 netif_addr_unlock_bh(bp->dev);
7671 * Send the UNLOAD_REQUEST to the MCP. This will return if
7672 * this function should perform FUNC, PORT or COMMON HW
7675 reset_code = bnx2x_send_unload_req(bp, unload_mode);
7678 * (assumption: No Attention from MCP at this stage)
7679 * PMF probably in the middle of TXdisable/enable transaction
7681 rc = bnx2x_func_wait_started(bp);
7683 BNX2X_ERR("bnx2x_func_wait_started failed\n");
7684 #ifdef BNX2X_STOP_ON_ERROR
7689 /* Close multi and leading connections
7690 * Completions for ramrods are collected in a synchronous way
7692 for_each_queue(bp, i)
7693 if (bnx2x_stop_queue(bp, i))
7694 #ifdef BNX2X_STOP_ON_ERROR
7699 /* If SP settings didn't get completed so far - something
7700 * very wrong has happen.
7702 if (!bnx2x_wait_sp_comp(bp, ~0x0UL))
7703 BNX2X_ERR("Hmmm... Common slow path ramrods got stuck!\n");
7705 #ifndef BNX2X_STOP_ON_ERROR
7708 rc = bnx2x_func_stop(bp);
7710 BNX2X_ERR("Function stop failed!\n");
7711 #ifdef BNX2X_STOP_ON_ERROR
7716 /* Disable HW interrupts, NAPI */
7717 bnx2x_netif_stop(bp, 1);
7722 /* Reset the chip */
7723 rc = bnx2x_reset_hw(bp, reset_code);
7725 BNX2X_ERR("HW_RESET failed\n");
7728 /* Report UNLOAD_DONE to MCP */
7729 bnx2x_send_unload_done(bp);
7732 void bnx2x_disable_close_the_gate(struct bnx2x *bp)
7736 DP(NETIF_MSG_HW, "Disabling \"close the gates\"\n");
7738 if (CHIP_IS_E1(bp)) {
7739 int port = BP_PORT(bp);
7740 u32 addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
7741 MISC_REG_AEU_MASK_ATTN_FUNC_0;
7743 val = REG_RD(bp, addr);
7745 REG_WR(bp, addr, val);
7747 val = REG_RD(bp, MISC_REG_AEU_GENERAL_MASK);
7748 val &= ~(MISC_AEU_GENERAL_MASK_REG_AEU_PXP_CLOSE_MASK |
7749 MISC_AEU_GENERAL_MASK_REG_AEU_NIG_CLOSE_MASK);
7750 REG_WR(bp, MISC_REG_AEU_GENERAL_MASK, val);
7754 /* Close gates #2, #3 and #4: */
7755 static void bnx2x_set_234_gates(struct bnx2x *bp, bool close)
7759 /* Gates #2 and #4a are closed/opened for "not E1" only */
7760 if (!CHIP_IS_E1(bp)) {
7762 REG_WR(bp, PXP_REG_HST_DISCARD_DOORBELLS, !!close);
7764 REG_WR(bp, PXP_REG_HST_DISCARD_INTERNAL_WRITES, !!close);
7768 if (CHIP_IS_E1x(bp)) {
7769 /* Prevent interrupts from HC on both ports */
7770 val = REG_RD(bp, HC_REG_CONFIG_1);
7771 REG_WR(bp, HC_REG_CONFIG_1,
7772 (!close) ? (val | HC_CONFIG_1_REG_BLOCK_DISABLE_1) :
7773 (val & ~(u32)HC_CONFIG_1_REG_BLOCK_DISABLE_1));
7775 val = REG_RD(bp, HC_REG_CONFIG_0);
7776 REG_WR(bp, HC_REG_CONFIG_0,
7777 (!close) ? (val | HC_CONFIG_0_REG_BLOCK_DISABLE_0) :
7778 (val & ~(u32)HC_CONFIG_0_REG_BLOCK_DISABLE_0));
7780 /* Prevent incomming interrupts in IGU */
7781 val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
7783 REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION,
7785 (val | IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE) :
7786 (val & ~(u32)IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE));
7789 DP(NETIF_MSG_HW, "%s gates #2, #3 and #4\n",
7790 close ? "closing" : "opening");
7794 #define SHARED_MF_CLP_MAGIC 0x80000000 /* `magic' bit */
7796 static void bnx2x_clp_reset_prep(struct bnx2x *bp, u32 *magic_val)
7798 /* Do some magic... */
7799 u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
7800 *magic_val = val & SHARED_MF_CLP_MAGIC;
7801 MF_CFG_WR(bp, shared_mf_config.clp_mb, val | SHARED_MF_CLP_MAGIC);
7805 * bnx2x_clp_reset_done - restore the value of the `magic' bit.
7807 * @bp: driver handle
7808 * @magic_val: old value of the `magic' bit.
7810 static void bnx2x_clp_reset_done(struct bnx2x *bp, u32 magic_val)
7812 /* Restore the `magic' bit value... */
7813 u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
7814 MF_CFG_WR(bp, shared_mf_config.clp_mb,
7815 (val & (~SHARED_MF_CLP_MAGIC)) | magic_val);
7819 * bnx2x_reset_mcp_prep - prepare for MCP reset.
7821 * @bp: driver handle
7822 * @magic_val: old value of 'magic' bit.
7824 * Takes care of CLP configurations.
7826 static void bnx2x_reset_mcp_prep(struct bnx2x *bp, u32 *magic_val)
7829 u32 validity_offset;
7831 DP(NETIF_MSG_HW, "Starting\n");
7833 /* Set `magic' bit in order to save MF config */
7834 if (!CHIP_IS_E1(bp))
7835 bnx2x_clp_reset_prep(bp, magic_val);
7837 /* Get shmem offset */
7838 shmem = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
7839 validity_offset = offsetof(struct shmem_region, validity_map[0]);
7841 /* Clear validity map flags */
7843 REG_WR(bp, shmem + validity_offset, 0);
7846 #define MCP_TIMEOUT 5000 /* 5 seconds (in ms) */
7847 #define MCP_ONE_TIMEOUT 100 /* 100 ms */
7850 * bnx2x_mcp_wait_one - wait for MCP_ONE_TIMEOUT
7852 * @bp: driver handle
7854 static inline void bnx2x_mcp_wait_one(struct bnx2x *bp)
7856 /* special handling for emulation and FPGA,
7857 wait 10 times longer */
7858 if (CHIP_REV_IS_SLOW(bp))
7859 msleep(MCP_ONE_TIMEOUT*10);
7861 msleep(MCP_ONE_TIMEOUT);
7865 * initializes bp->common.shmem_base and waits for validity signature to appear
7867 static int bnx2x_init_shmem(struct bnx2x *bp)
7873 bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
7874 if (bp->common.shmem_base) {
7875 val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
7876 if (val & SHR_MEM_VALIDITY_MB)
7880 bnx2x_mcp_wait_one(bp);
7882 } while (cnt++ < (MCP_TIMEOUT / MCP_ONE_TIMEOUT));
7884 BNX2X_ERR("BAD MCP validity signature\n");
7889 static int bnx2x_reset_mcp_comp(struct bnx2x *bp, u32 magic_val)
7891 int rc = bnx2x_init_shmem(bp);
7893 /* Restore the `magic' bit value */
7894 if (!CHIP_IS_E1(bp))
7895 bnx2x_clp_reset_done(bp, magic_val);
7900 static void bnx2x_pxp_prep(struct bnx2x *bp)
7902 if (!CHIP_IS_E1(bp)) {
7903 REG_WR(bp, PXP2_REG_RD_START_INIT, 0);
7904 REG_WR(bp, PXP2_REG_RQ_RBC_DONE, 0);
7910 * Reset the whole chip except for:
7912 * - PCI Glue, PSWHST, PXP/PXP2 RF (all controlled by
7915 * - MISC (including AEU)
7919 static void bnx2x_process_kill_chip_reset(struct bnx2x *bp, bool global)
7921 u32 not_reset_mask1, reset_mask1, not_reset_mask2, reset_mask2;
7925 * Bits that have to be set in reset_mask2 if we want to reset 'global'
7926 * (per chip) blocks.
7929 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CPU |
7930 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CORE;
7933 MISC_REGISTERS_RESET_REG_1_RST_HC |
7934 MISC_REGISTERS_RESET_REG_1_RST_PXPV |
7935 MISC_REGISTERS_RESET_REG_1_RST_PXP;
7938 MISC_REGISTERS_RESET_REG_2_RST_PCI_MDIO |
7939 MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE |
7940 MISC_REGISTERS_RESET_REG_2_RST_EMAC1_HARD_CORE |
7941 MISC_REGISTERS_RESET_REG_2_RST_MISC_CORE |
7942 MISC_REGISTERS_RESET_REG_2_RST_RBCN |
7943 MISC_REGISTERS_RESET_REG_2_RST_GRC |
7944 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_REG_HARD_CORE |
7945 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_HARD_CORE_RST_B;
7947 reset_mask1 = 0xffffffff;
7950 reset_mask2 = 0xffff;
7952 reset_mask2 = 0x1ffff;
7954 if (CHIP_IS_E3(bp)) {
7955 reset_mask2 |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
7956 reset_mask2 |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
7959 /* Don't reset global blocks unless we need to */
7961 reset_mask2 &= ~global_bits2;
7964 * In case of attention in the QM, we need to reset PXP
7965 * (MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR) before QM
7966 * because otherwise QM reset would release 'close the gates' shortly
7967 * before resetting the PXP, then the PSWRQ would send a write
7968 * request to PGLUE. Then when PXP is reset, PGLUE would try to
7969 * read the payload data from PSWWR, but PSWWR would not
7970 * respond. The write queue in PGLUE would stuck, dmae commands
7971 * would not return. Therefore it's important to reset the second
7972 * reset register (containing the
7973 * MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR bit) before the
7974 * first one (containing the MISC_REGISTERS_RESET_REG_1_RST_QM
7977 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
7978 reset_mask2 & (~not_reset_mask2));
7980 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
7981 reset_mask1 & (~not_reset_mask1));
7986 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, reset_mask2);
7987 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, reset_mask1);
7992 * bnx2x_er_poll_igu_vq - poll for pending writes bit.
7993 * It should get cleared in no more than 1s.
7995 * @bp: driver handle
7997 * It should get cleared in no more than 1s. Returns 0 if
7998 * pending writes bit gets cleared.
8000 static int bnx2x_er_poll_igu_vq(struct bnx2x *bp)
8006 pend_bits = REG_RD(bp, IGU_REG_PENDING_BITS_STATUS);
8011 usleep_range(1000, 1000);
8012 } while (cnt-- > 0);
8015 BNX2X_ERR("Still pending IGU requests pend_bits=%x!\n",
8023 static int bnx2x_process_kill(struct bnx2x *bp, bool global)
8027 u32 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, pgl_exp_rom2;
8030 /* Empty the Tetris buffer, wait for 1s */
8032 sr_cnt = REG_RD(bp, PXP2_REG_RD_SR_CNT);
8033 blk_cnt = REG_RD(bp, PXP2_REG_RD_BLK_CNT);
8034 port_is_idle_0 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_0);
8035 port_is_idle_1 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_1);
8036 pgl_exp_rom2 = REG_RD(bp, PXP2_REG_PGL_EXP_ROM2);
8037 if ((sr_cnt == 0x7e) && (blk_cnt == 0xa0) &&
8038 ((port_is_idle_0 & 0x1) == 0x1) &&
8039 ((port_is_idle_1 & 0x1) == 0x1) &&
8040 (pgl_exp_rom2 == 0xffffffff))
8042 usleep_range(1000, 1000);
8043 } while (cnt-- > 0);
8046 DP(NETIF_MSG_HW, "Tetris buffer didn't get empty or there"
8048 " outstanding read requests after 1s!\n");
8049 DP(NETIF_MSG_HW, "sr_cnt=0x%08x, blk_cnt=0x%08x,"
8050 " port_is_idle_0=0x%08x,"
8051 " port_is_idle_1=0x%08x, pgl_exp_rom2=0x%08x\n",
8052 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1,
8059 /* Close gates #2, #3 and #4 */
8060 bnx2x_set_234_gates(bp, true);
8062 /* Poll for IGU VQs for 57712 and newer chips */
8063 if (!CHIP_IS_E1x(bp) && bnx2x_er_poll_igu_vq(bp))
8067 /* TBD: Indicate that "process kill" is in progress to MCP */
8069 /* Clear "unprepared" bit */
8070 REG_WR(bp, MISC_REG_UNPREPARED, 0);
8073 /* Make sure all is written to the chip before the reset */
8076 /* Wait for 1ms to empty GLUE and PCI-E core queues,
8077 * PSWHST, GRC and PSWRD Tetris buffer.
8079 usleep_range(1000, 1000);
8081 /* Prepare to chip reset: */
8084 bnx2x_reset_mcp_prep(bp, &val);
8090 /* reset the chip */
8091 bnx2x_process_kill_chip_reset(bp, global);
8094 /* Recover after reset: */
8096 if (global && bnx2x_reset_mcp_comp(bp, val))
8099 /* TBD: Add resetting the NO_MCP mode DB here */
8104 /* Open the gates #2, #3 and #4 */
8105 bnx2x_set_234_gates(bp, false);
8107 /* TBD: IGU/AEU preparation bring back the AEU/IGU to a
8108 * reset state, re-enable attentions. */
8113 int bnx2x_leader_reset(struct bnx2x *bp)
8116 bool global = bnx2x_reset_is_global(bp);
8118 /* Try to recover after the failure */
8119 if (bnx2x_process_kill(bp, global)) {
8120 netdev_err(bp->dev, "Something bad had happen on engine %d! "
8121 "Aii!\n", BP_PATH(bp));
8123 goto exit_leader_reset;
8127 * Clear RESET_IN_PROGRES and RESET_GLOBAL bits and update the driver
8130 bnx2x_set_reset_done(bp);
8132 bnx2x_clear_reset_global(bp);
8136 bnx2x_release_leader_lock(bp);
8141 static inline void bnx2x_recovery_failed(struct bnx2x *bp)
8143 netdev_err(bp->dev, "Recovery has failed. Power cycle is needed.\n");
8145 /* Disconnect this device */
8146 netif_device_detach(bp->dev);
8149 * Block ifup for all function on this engine until "process kill"
8152 bnx2x_set_reset_in_progress(bp);
8154 /* Shut down the power */
8155 bnx2x_set_power_state(bp, PCI_D3hot);
8157 bp->recovery_state = BNX2X_RECOVERY_FAILED;
8163 * Assumption: runs under rtnl lock. This together with the fact
8164 * that it's called only from bnx2x_sp_rtnl() ensure that it
8165 * will never be called when netif_running(bp->dev) is false.
8167 static void bnx2x_parity_recover(struct bnx2x *bp)
8169 bool global = false;
8171 DP(NETIF_MSG_HW, "Handling parity\n");
8173 switch (bp->recovery_state) {
8174 case BNX2X_RECOVERY_INIT:
8175 DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_INIT\n");
8176 bnx2x_chk_parity_attn(bp, &global, false);
8178 /* Try to get a LEADER_LOCK HW lock */
8179 if (bnx2x_trylock_leader_lock(bp)) {
8180 bnx2x_set_reset_in_progress(bp);
8182 * Check if there is a global attention and if
8183 * there was a global attention, set the global
8188 bnx2x_set_reset_global(bp);
8193 /* Stop the driver */
8194 /* If interface has been removed - break */
8195 if (bnx2x_nic_unload(bp, UNLOAD_RECOVERY))
8198 bp->recovery_state = BNX2X_RECOVERY_WAIT;
8201 * Reset MCP command sequence number and MCP mail box
8202 * sequence as we are going to reset the MCP.
8206 bp->fw_drv_pulse_wr_seq = 0;
8209 /* Ensure "is_leader", MCP command sequence and
8210 * "recovery_state" update values are seen on other
8216 case BNX2X_RECOVERY_WAIT:
8217 DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_WAIT\n");
8218 if (bp->is_leader) {
8219 int other_engine = BP_PATH(bp) ? 0 : 1;
8220 u32 other_load_counter =
8221 bnx2x_get_load_cnt(bp, other_engine);
8223 bnx2x_get_load_cnt(bp, BP_PATH(bp));
8224 global = bnx2x_reset_is_global(bp);
8227 * In case of a parity in a global block, let
8228 * the first leader that performs a
8229 * leader_reset() reset the global blocks in
8230 * order to clear global attentions. Otherwise
8231 * the the gates will remain closed for that
8235 (global && other_load_counter)) {
8236 /* Wait until all other functions get
8239 schedule_delayed_work(&bp->sp_rtnl_task,
8243 /* If all other functions got down -
8244 * try to bring the chip back to
8245 * normal. In any case it's an exit
8246 * point for a leader.
8248 if (bnx2x_leader_reset(bp)) {
8249 bnx2x_recovery_failed(bp);
8253 /* If we are here, means that the
8254 * leader has succeeded and doesn't
8255 * want to be a leader any more. Try
8256 * to continue as a none-leader.
8260 } else { /* non-leader */
8261 if (!bnx2x_reset_is_done(bp, BP_PATH(bp))) {
8262 /* Try to get a LEADER_LOCK HW lock as
8263 * long as a former leader may have
8264 * been unloaded by the user or
8265 * released a leadership by another
8268 if (bnx2x_trylock_leader_lock(bp)) {
8269 /* I'm a leader now! Restart a
8276 schedule_delayed_work(&bp->sp_rtnl_task,
8282 * If there was a global attention, wait
8283 * for it to be cleared.
8285 if (bnx2x_reset_is_global(bp)) {
8286 schedule_delayed_work(
8292 if (bnx2x_nic_load(bp, LOAD_NORMAL))
8293 bnx2x_recovery_failed(bp);
8295 bp->recovery_state =
8296 BNX2X_RECOVERY_DONE;
8309 /* bnx2x_nic_unload() flushes the bnx2x_wq, thus reset task is
8310 * scheduled on a general queue in order to prevent a dead lock.
8312 static void bnx2x_sp_rtnl_task(struct work_struct *work)
8314 struct bnx2x *bp = container_of(work, struct bnx2x, sp_rtnl_task.work);
8318 if (!netif_running(bp->dev))
8321 if (test_and_clear_bit(BNX2X_SP_RTNL_SETUP_TC, &bp->sp_rtnl_state))
8322 bnx2x_setup_tc(bp->dev, bp->dcbx_port_params.ets.num_of_cos);
8324 /* if stop on error is defined no recovery flows should be executed */
8325 #ifdef BNX2X_STOP_ON_ERROR
8326 BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined "
8327 "so reset not done to allow debug dump,\n"
8328 "you will need to reboot when done\n");
8332 if (unlikely(bp->recovery_state != BNX2X_RECOVERY_DONE)) {
8334 * Clear TX_TIMEOUT bit as we are going to reset the function
8337 smp_mb__before_clear_bit();
8338 clear_bit(BNX2X_SP_RTNL_TX_TIMEOUT, &bp->sp_rtnl_state);
8339 smp_mb__after_clear_bit();
8340 bnx2x_parity_recover(bp);
8341 } else if (test_and_clear_bit(BNX2X_SP_RTNL_TX_TIMEOUT,
8342 &bp->sp_rtnl_state)){
8343 bnx2x_nic_unload(bp, UNLOAD_NORMAL);
8344 bnx2x_nic_load(bp, LOAD_NORMAL);
8351 /* end of nic load/unload */
8353 static void bnx2x_period_task(struct work_struct *work)
8355 struct bnx2x *bp = container_of(work, struct bnx2x, period_task.work);
8357 if (!netif_running(bp->dev))
8358 goto period_task_exit;
8360 if (CHIP_REV_IS_SLOW(bp)) {
8361 BNX2X_ERR("period task called on emulation, ignoring\n");
8362 goto period_task_exit;
8365 bnx2x_acquire_phy_lock(bp);
8367 * The barrier is needed to ensure the ordering between the writing to
8368 * the bp->port.pmf in the bnx2x_nic_load() or bnx2x_pmf_update() and
8373 bnx2x_period_func(&bp->link_params, &bp->link_vars);
8375 /* Re-queue task in 1 sec */
8376 queue_delayed_work(bnx2x_wq, &bp->period_task, 1*HZ);
8379 bnx2x_release_phy_lock(bp);
8385 * Init service functions
8388 static u32 bnx2x_get_pretend_reg(struct bnx2x *bp)
8390 u32 base = PXP2_REG_PGL_PRETEND_FUNC_F0;
8391 u32 stride = PXP2_REG_PGL_PRETEND_FUNC_F1 - base;
8392 return base + (BP_ABS_FUNC(bp)) * stride;
8395 static void bnx2x_undi_int_disable_e1h(struct bnx2x *bp)
8397 u32 reg = bnx2x_get_pretend_reg(bp);
8399 /* Flush all outstanding writes */
8402 /* Pretend to be function 0 */
8404 REG_RD(bp, reg); /* Flush the GRC transaction (in the chip) */
8406 /* From now we are in the "like-E1" mode */
8407 bnx2x_int_disable(bp);
8409 /* Flush all outstanding writes */
8412 /* Restore the original function */
8413 REG_WR(bp, reg, BP_ABS_FUNC(bp));
8417 static inline void bnx2x_undi_int_disable(struct bnx2x *bp)
8420 bnx2x_int_disable(bp);
8422 bnx2x_undi_int_disable_e1h(bp);
8425 static void __devinit bnx2x_undi_unload(struct bnx2x *bp)
8429 /* Check if there is any driver already loaded */
8430 val = REG_RD(bp, MISC_REG_UNPREPARED);
8432 /* Check if it is the UNDI driver
8433 * UNDI driver initializes CID offset for normal bell to 0x7
8435 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_UNDI);
8436 val = REG_RD(bp, DORQ_REG_NORM_CID_OFST);
8438 u32 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
8439 /* save our pf_num */
8440 int orig_pf_num = bp->pf_num;
8442 u32 swap_en, swap_val, value;
8444 /* clear the UNDI indication */
8445 REG_WR(bp, DORQ_REG_NORM_CID_OFST, 0);
8447 BNX2X_DEV_INFO("UNDI is active! reset device\n");
8449 /* try unload UNDI on port 0 */
8452 (SHMEM_RD(bp, func_mb[bp->pf_num].drv_mb_header) &
8453 DRV_MSG_SEQ_NUMBER_MASK);
8454 reset_code = bnx2x_fw_command(bp, reset_code, 0);
8456 /* if UNDI is loaded on the other port */
8457 if (reset_code != FW_MSG_CODE_DRV_UNLOAD_COMMON) {
8459 /* send "DONE" for previous unload */
8460 bnx2x_fw_command(bp,
8461 DRV_MSG_CODE_UNLOAD_DONE, 0);
8463 /* unload UNDI on port 1 */
8466 (SHMEM_RD(bp, func_mb[bp->pf_num].drv_mb_header) &
8467 DRV_MSG_SEQ_NUMBER_MASK);
8468 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
8470 bnx2x_fw_command(bp, reset_code, 0);
8473 /* now it's safe to release the lock */
8474 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_UNDI);
8476 bnx2x_undi_int_disable(bp);
8479 /* close input traffic and wait for it */
8480 /* Do not rcv packets to BRB */
8481 REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_DRV_MASK :
8482 NIG_REG_LLH0_BRB1_DRV_MASK), 0x0);
8483 /* Do not direct rcv packets that are not for MCP to
8485 REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
8486 NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
8488 REG_WR(bp, (port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
8489 MISC_REG_AEU_MASK_ATTN_FUNC_0), 0);
8492 /* save NIG port swap info */
8493 swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
8494 swap_en = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
8497 GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
8501 if (CHIP_IS_E3(bp)) {
8502 value |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
8503 value |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
8507 GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
8510 /* take the NIG out of reset and restore swap values */
8512 GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
8513 MISC_REGISTERS_RESET_REG_1_RST_NIG);
8514 REG_WR(bp, NIG_REG_PORT_SWAP, swap_val);
8515 REG_WR(bp, NIG_REG_STRAP_OVERRIDE, swap_en);
8517 /* send unload done to the MCP */
8518 bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
8520 /* restore our func and fw_seq */
8521 bp->pf_num = orig_pf_num;
8523 (SHMEM_RD(bp, func_mb[bp->pf_num].drv_mb_header) &
8524 DRV_MSG_SEQ_NUMBER_MASK);
8526 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_UNDI);
8530 static void __devinit bnx2x_get_common_hwinfo(struct bnx2x *bp)
8532 u32 val, val2, val3, val4, id;
8535 /* Get the chip revision id and number. */
8536 /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
8537 val = REG_RD(bp, MISC_REG_CHIP_NUM);
8538 id = ((val & 0xffff) << 16);
8539 val = REG_RD(bp, MISC_REG_CHIP_REV);
8540 id |= ((val & 0xf) << 12);
8541 val = REG_RD(bp, MISC_REG_CHIP_METAL);
8542 id |= ((val & 0xff) << 4);
8543 val = REG_RD(bp, MISC_REG_BOND_ID);
8545 bp->common.chip_id = id;
8547 /* Set doorbell size */
8548 bp->db_size = (1 << BNX2X_DB_SHIFT);
8550 if (!CHIP_IS_E1x(bp)) {
8551 val = REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR);
8553 val = REG_RD(bp, MISC_REG_PORT4MODE_EN);
8555 val = (val >> 1) & 1;
8556 BNX2X_DEV_INFO("chip is in %s\n", val ? "4_PORT_MODE" :
8558 bp->common.chip_port_mode = val ? CHIP_4_PORT_MODE :
8561 if (CHIP_MODE_IS_4_PORT(bp))
8562 bp->pfid = (bp->pf_num >> 1); /* 0..3 */
8564 bp->pfid = (bp->pf_num & 0x6); /* 0, 2, 4, 6 */
8566 bp->common.chip_port_mode = CHIP_PORT_MODE_NONE; /* N/A */
8567 bp->pfid = bp->pf_num; /* 0..7 */
8570 bp->link_params.chip_id = bp->common.chip_id;
8571 BNX2X_DEV_INFO("chip ID is 0x%x\n", id);
8573 val = (REG_RD(bp, 0x2874) & 0x55);
8574 if ((bp->common.chip_id & 0x1) ||
8575 (CHIP_IS_E1(bp) && val) || (CHIP_IS_E1H(bp) && (val == 0x55))) {
8576 bp->flags |= ONE_PORT_FLAG;
8577 BNX2X_DEV_INFO("single port device\n");
8580 val = REG_RD(bp, MCP_REG_MCPR_NVM_CFG4);
8581 bp->common.flash_size = (BNX2X_NVRAM_1MB_SIZE <<
8582 (val & MCPR_NVM_CFG4_FLASH_SIZE));
8583 BNX2X_DEV_INFO("flash_size 0x%x (%d)\n",
8584 bp->common.flash_size, bp->common.flash_size);
8586 bnx2x_init_shmem(bp);
8590 bp->common.shmem2_base = REG_RD(bp, (BP_PATH(bp) ?
8591 MISC_REG_GENERIC_CR_1 :
8592 MISC_REG_GENERIC_CR_0));
8594 bp->link_params.shmem_base = bp->common.shmem_base;
8595 bp->link_params.shmem2_base = bp->common.shmem2_base;
8596 BNX2X_DEV_INFO("shmem offset 0x%x shmem2 offset 0x%x\n",
8597 bp->common.shmem_base, bp->common.shmem2_base);
8599 if (!bp->common.shmem_base) {
8600 BNX2X_DEV_INFO("MCP not active\n");
8601 bp->flags |= NO_MCP_FLAG;
8605 bp->common.hw_config = SHMEM_RD(bp, dev_info.shared_hw_config.config);
8606 BNX2X_DEV_INFO("hw_config 0x%08x\n", bp->common.hw_config);
8608 bp->link_params.hw_led_mode = ((bp->common.hw_config &
8609 SHARED_HW_CFG_LED_MODE_MASK) >>
8610 SHARED_HW_CFG_LED_MODE_SHIFT);
8612 bp->link_params.feature_config_flags = 0;
8613 val = SHMEM_RD(bp, dev_info.shared_feature_config.config);
8614 if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED)
8615 bp->link_params.feature_config_flags |=
8616 FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
8618 bp->link_params.feature_config_flags &=
8619 ~FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
8621 val = SHMEM_RD(bp, dev_info.bc_rev) >> 8;
8622 bp->common.bc_ver = val;
8623 BNX2X_DEV_INFO("bc_ver %X\n", val);
8624 if (val < BNX2X_BC_VER) {
8625 /* for now only warn
8626 * later we might need to enforce this */
8627 BNX2X_ERR("This driver needs bc_ver %X but found %X, "
8628 "please upgrade BC\n", BNX2X_BC_VER, val);
8630 bp->link_params.feature_config_flags |=
8631 (val >= REQ_BC_VER_4_VRFY_FIRST_PHY_OPT_MDL) ?
8632 FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY : 0;
8634 bp->link_params.feature_config_flags |=
8635 (val >= REQ_BC_VER_4_VRFY_SPECIFIC_PHY_OPT_MDL) ?
8636 FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY : 0;
8638 bp->link_params.feature_config_flags |=
8639 (val >= REQ_BC_VER_4_SFP_TX_DISABLE_SUPPORTED) ?
8640 FEATURE_CONFIG_BC_SUPPORTS_SFP_TX_DISABLED : 0;
8642 pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_PMC, &pmc);
8643 bp->flags |= (pmc & PCI_PM_CAP_PME_D3cold) ? 0 : NO_WOL_FLAG;
8645 BNX2X_DEV_INFO("%sWoL capable\n",
8646 (bp->flags & NO_WOL_FLAG) ? "not " : "");
8648 val = SHMEM_RD(bp, dev_info.shared_hw_config.part_num);
8649 val2 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[4]);
8650 val3 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[8]);
8651 val4 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[12]);
8653 dev_info(&bp->pdev->dev, "part number %X-%X-%X-%X\n",
8654 val, val2, val3, val4);
8657 #define IGU_FID(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID)
8658 #define IGU_VEC(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR)
8660 static void __devinit bnx2x_get_igu_cam_info(struct bnx2x *bp)
8662 int pfid = BP_FUNC(bp);
8663 int vn = BP_E1HVN(bp);
8666 u8 fid, igu_sb_cnt = 0;
8668 bp->igu_base_sb = 0xff;
8669 if (CHIP_INT_MODE_IS_BC(bp)) {
8670 igu_sb_cnt = bp->igu_sb_cnt;
8671 bp->igu_base_sb = (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn) *
8674 bp->igu_dsb_id = E1HVN_MAX * FP_SB_MAX_E1x +
8675 (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn);
8680 /* IGU in normal mode - read CAM */
8681 for (igu_sb_id = 0; igu_sb_id < IGU_REG_MAPPING_MEMORY_SIZE;
8683 val = REG_RD(bp, IGU_REG_MAPPING_MEMORY + igu_sb_id * 4);
8684 if (!(val & IGU_REG_MAPPING_MEMORY_VALID))
8687 if ((fid & IGU_FID_ENCODE_IS_PF)) {
8688 if ((fid & IGU_FID_PF_NUM_MASK) != pfid)
8690 if (IGU_VEC(val) == 0)
8691 /* default status block */
8692 bp->igu_dsb_id = igu_sb_id;
8694 if (bp->igu_base_sb == 0xff)
8695 bp->igu_base_sb = igu_sb_id;
8701 #ifdef CONFIG_PCI_MSI
8703 * It's expected that number of CAM entries for this functions is equal
8704 * to the number evaluated based on the MSI-X table size. We want a
8705 * harsh warning if these values are different!
8707 WARN_ON(bp->igu_sb_cnt != igu_sb_cnt);
8710 if (igu_sb_cnt == 0)
8711 BNX2X_ERR("CAM configuration error\n");
8714 static void __devinit bnx2x_link_settings_supported(struct bnx2x *bp,
8717 int cfg_size = 0, idx, port = BP_PORT(bp);
8719 /* Aggregation of supported attributes of all external phys */
8720 bp->port.supported[0] = 0;
8721 bp->port.supported[1] = 0;
8722 switch (bp->link_params.num_phys) {
8724 bp->port.supported[0] = bp->link_params.phy[INT_PHY].supported;
8728 bp->port.supported[0] = bp->link_params.phy[EXT_PHY1].supported;
8732 if (bp->link_params.multi_phy_config &
8733 PORT_HW_CFG_PHY_SWAPPED_ENABLED) {
8734 bp->port.supported[1] =
8735 bp->link_params.phy[EXT_PHY1].supported;
8736 bp->port.supported[0] =
8737 bp->link_params.phy[EXT_PHY2].supported;
8739 bp->port.supported[0] =
8740 bp->link_params.phy[EXT_PHY1].supported;
8741 bp->port.supported[1] =
8742 bp->link_params.phy[EXT_PHY2].supported;
8748 if (!(bp->port.supported[0] || bp->port.supported[1])) {
8749 BNX2X_ERR("NVRAM config error. BAD phy config."
8750 "PHY1 config 0x%x, PHY2 config 0x%x\n",
8752 dev_info.port_hw_config[port].external_phy_config),
8754 dev_info.port_hw_config[port].external_phy_config2));
8759 bp->port.phy_addr = REG_RD(bp, MISC_REG_WC0_CTRL_PHY_ADDR);
8761 switch (switch_cfg) {
8763 bp->port.phy_addr = REG_RD(
8764 bp, NIG_REG_SERDES0_CTRL_PHY_ADDR + port*0x10);
8766 case SWITCH_CFG_10G:
8767 bp->port.phy_addr = REG_RD(
8768 bp, NIG_REG_XGXS0_CTRL_PHY_ADDR + port*0x18);
8771 BNX2X_ERR("BAD switch_cfg link_config 0x%x\n",
8772 bp->port.link_config[0]);
8776 BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr);
8777 /* mask what we support according to speed_cap_mask per configuration */
8778 for (idx = 0; idx < cfg_size; idx++) {
8779 if (!(bp->link_params.speed_cap_mask[idx] &
8780 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF))
8781 bp->port.supported[idx] &= ~SUPPORTED_10baseT_Half;
8783 if (!(bp->link_params.speed_cap_mask[idx] &
8784 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL))
8785 bp->port.supported[idx] &= ~SUPPORTED_10baseT_Full;
8787 if (!(bp->link_params.speed_cap_mask[idx] &
8788 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF))
8789 bp->port.supported[idx] &= ~SUPPORTED_100baseT_Half;
8791 if (!(bp->link_params.speed_cap_mask[idx] &
8792 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL))
8793 bp->port.supported[idx] &= ~SUPPORTED_100baseT_Full;
8795 if (!(bp->link_params.speed_cap_mask[idx] &
8796 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G))
8797 bp->port.supported[idx] &= ~(SUPPORTED_1000baseT_Half |
8798 SUPPORTED_1000baseT_Full);
8800 if (!(bp->link_params.speed_cap_mask[idx] &
8801 PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
8802 bp->port.supported[idx] &= ~SUPPORTED_2500baseX_Full;
8804 if (!(bp->link_params.speed_cap_mask[idx] &
8805 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G))
8806 bp->port.supported[idx] &= ~SUPPORTED_10000baseT_Full;
8810 BNX2X_DEV_INFO("supported 0x%x 0x%x\n", bp->port.supported[0],
8811 bp->port.supported[1]);
8814 static void __devinit bnx2x_link_settings_requested(struct bnx2x *bp)
8816 u32 link_config, idx, cfg_size = 0;
8817 bp->port.advertising[0] = 0;
8818 bp->port.advertising[1] = 0;
8819 switch (bp->link_params.num_phys) {
8828 for (idx = 0; idx < cfg_size; idx++) {
8829 bp->link_params.req_duplex[idx] = DUPLEX_FULL;
8830 link_config = bp->port.link_config[idx];
8831 switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) {
8832 case PORT_FEATURE_LINK_SPEED_AUTO:
8833 if (bp->port.supported[idx] & SUPPORTED_Autoneg) {
8834 bp->link_params.req_line_speed[idx] =
8836 bp->port.advertising[idx] |=
8837 bp->port.supported[idx];
8839 /* force 10G, no AN */
8840 bp->link_params.req_line_speed[idx] =
8842 bp->port.advertising[idx] |=
8843 (ADVERTISED_10000baseT_Full |
8849 case PORT_FEATURE_LINK_SPEED_10M_FULL:
8850 if (bp->port.supported[idx] & SUPPORTED_10baseT_Full) {
8851 bp->link_params.req_line_speed[idx] =
8853 bp->port.advertising[idx] |=
8854 (ADVERTISED_10baseT_Full |
8857 BNX2X_ERR("NVRAM config error. "
8858 "Invalid link_config 0x%x"
8859 " speed_cap_mask 0x%x\n",
8861 bp->link_params.speed_cap_mask[idx]);
8866 case PORT_FEATURE_LINK_SPEED_10M_HALF:
8867 if (bp->port.supported[idx] & SUPPORTED_10baseT_Half) {
8868 bp->link_params.req_line_speed[idx] =
8870 bp->link_params.req_duplex[idx] =
8872 bp->port.advertising[idx] |=
8873 (ADVERTISED_10baseT_Half |
8876 BNX2X_ERR("NVRAM config error. "
8877 "Invalid link_config 0x%x"
8878 " speed_cap_mask 0x%x\n",
8880 bp->link_params.speed_cap_mask[idx]);
8885 case PORT_FEATURE_LINK_SPEED_100M_FULL:
8886 if (bp->port.supported[idx] &
8887 SUPPORTED_100baseT_Full) {
8888 bp->link_params.req_line_speed[idx] =
8890 bp->port.advertising[idx] |=
8891 (ADVERTISED_100baseT_Full |
8894 BNX2X_ERR("NVRAM config error. "
8895 "Invalid link_config 0x%x"
8896 " speed_cap_mask 0x%x\n",
8898 bp->link_params.speed_cap_mask[idx]);
8903 case PORT_FEATURE_LINK_SPEED_100M_HALF:
8904 if (bp->port.supported[idx] &
8905 SUPPORTED_100baseT_Half) {
8906 bp->link_params.req_line_speed[idx] =
8908 bp->link_params.req_duplex[idx] =
8910 bp->port.advertising[idx] |=
8911 (ADVERTISED_100baseT_Half |
8914 BNX2X_ERR("NVRAM config error. "
8915 "Invalid link_config 0x%x"
8916 " speed_cap_mask 0x%x\n",
8918 bp->link_params.speed_cap_mask[idx]);
8923 case PORT_FEATURE_LINK_SPEED_1G:
8924 if (bp->port.supported[idx] &
8925 SUPPORTED_1000baseT_Full) {
8926 bp->link_params.req_line_speed[idx] =
8928 bp->port.advertising[idx] |=
8929 (ADVERTISED_1000baseT_Full |
8932 BNX2X_ERR("NVRAM config error. "
8933 "Invalid link_config 0x%x"
8934 " speed_cap_mask 0x%x\n",
8936 bp->link_params.speed_cap_mask[idx]);
8941 case PORT_FEATURE_LINK_SPEED_2_5G:
8942 if (bp->port.supported[idx] &
8943 SUPPORTED_2500baseX_Full) {
8944 bp->link_params.req_line_speed[idx] =
8946 bp->port.advertising[idx] |=
8947 (ADVERTISED_2500baseX_Full |
8950 BNX2X_ERR("NVRAM config error. "
8951 "Invalid link_config 0x%x"
8952 " speed_cap_mask 0x%x\n",
8954 bp->link_params.speed_cap_mask[idx]);
8959 case PORT_FEATURE_LINK_SPEED_10G_CX4:
8960 if (bp->port.supported[idx] &
8961 SUPPORTED_10000baseT_Full) {
8962 bp->link_params.req_line_speed[idx] =
8964 bp->port.advertising[idx] |=
8965 (ADVERTISED_10000baseT_Full |
8968 BNX2X_ERR("NVRAM config error. "
8969 "Invalid link_config 0x%x"
8970 " speed_cap_mask 0x%x\n",
8972 bp->link_params.speed_cap_mask[idx]);
8976 case PORT_FEATURE_LINK_SPEED_20G:
8977 bp->link_params.req_line_speed[idx] = SPEED_20000;
8981 BNX2X_ERR("NVRAM config error. "
8982 "BAD link speed link_config 0x%x\n",
8984 bp->link_params.req_line_speed[idx] =
8986 bp->port.advertising[idx] =
8987 bp->port.supported[idx];
8991 bp->link_params.req_flow_ctrl[idx] = (link_config &
8992 PORT_FEATURE_FLOW_CONTROL_MASK);
8993 if ((bp->link_params.req_flow_ctrl[idx] ==
8994 BNX2X_FLOW_CTRL_AUTO) &&
8995 !(bp->port.supported[idx] & SUPPORTED_Autoneg)) {
8996 bp->link_params.req_flow_ctrl[idx] =
8997 BNX2X_FLOW_CTRL_NONE;
9000 BNX2X_DEV_INFO("req_line_speed %d req_duplex %d req_flow_ctrl"
9001 " 0x%x advertising 0x%x\n",
9002 bp->link_params.req_line_speed[idx],
9003 bp->link_params.req_duplex[idx],
9004 bp->link_params.req_flow_ctrl[idx],
9005 bp->port.advertising[idx]);
9009 static void __devinit bnx2x_set_mac_buf(u8 *mac_buf, u32 mac_lo, u16 mac_hi)
9011 mac_hi = cpu_to_be16(mac_hi);
9012 mac_lo = cpu_to_be32(mac_lo);
9013 memcpy(mac_buf, &mac_hi, sizeof(mac_hi));
9014 memcpy(mac_buf + sizeof(mac_hi), &mac_lo, sizeof(mac_lo));
9017 static void __devinit bnx2x_get_port_hwinfo(struct bnx2x *bp)
9019 int port = BP_PORT(bp);
9021 u32 ext_phy_type, ext_phy_config;
9023 bp->link_params.bp = bp;
9024 bp->link_params.port = port;
9026 bp->link_params.lane_config =
9027 SHMEM_RD(bp, dev_info.port_hw_config[port].lane_config);
9029 bp->link_params.speed_cap_mask[0] =
9031 dev_info.port_hw_config[port].speed_capability_mask);
9032 bp->link_params.speed_cap_mask[1] =
9034 dev_info.port_hw_config[port].speed_capability_mask2);
9035 bp->port.link_config[0] =
9036 SHMEM_RD(bp, dev_info.port_feature_config[port].link_config);
9038 bp->port.link_config[1] =
9039 SHMEM_RD(bp, dev_info.port_feature_config[port].link_config2);
9041 bp->link_params.multi_phy_config =
9042 SHMEM_RD(bp, dev_info.port_hw_config[port].multi_phy_config);
9043 /* If the device is capable of WoL, set the default state according
9046 config = SHMEM_RD(bp, dev_info.port_feature_config[port].config);
9047 bp->wol = (!(bp->flags & NO_WOL_FLAG) &&
9048 (config & PORT_FEATURE_WOL_ENABLED));
9050 BNX2X_DEV_INFO("lane_config 0x%08x "
9051 "speed_cap_mask0 0x%08x link_config0 0x%08x\n",
9052 bp->link_params.lane_config,
9053 bp->link_params.speed_cap_mask[0],
9054 bp->port.link_config[0]);
9056 bp->link_params.switch_cfg = (bp->port.link_config[0] &
9057 PORT_FEATURE_CONNECTED_SWITCH_MASK);
9058 bnx2x_phy_probe(&bp->link_params);
9059 bnx2x_link_settings_supported(bp, bp->link_params.switch_cfg);
9061 bnx2x_link_settings_requested(bp);
9064 * If connected directly, work with the internal PHY, otherwise, work
9065 * with the external PHY
9069 dev_info.port_hw_config[port].external_phy_config);
9070 ext_phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
9071 if (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
9072 bp->mdio.prtad = bp->port.phy_addr;
9074 else if ((ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) &&
9075 (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN))
9077 XGXS_EXT_PHY_ADDR(ext_phy_config);
9080 * Check if hw lock is required to access MDC/MDIO bus to the PHY(s)
9081 * In MF mode, it is set to cover self test cases
9084 bp->port.need_hw_lock = 1;
9086 bp->port.need_hw_lock = bnx2x_hw_lock_required(bp,
9087 bp->common.shmem_base,
9088 bp->common.shmem2_base);
9092 static void __devinit bnx2x_get_cnic_info(struct bnx2x *bp)
9094 u32 max_iscsi_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
9095 drv_lic_key[BP_PORT(bp)].max_iscsi_conn);
9096 u32 max_fcoe_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
9097 drv_lic_key[BP_PORT(bp)].max_fcoe_conn);
9099 /* Get the number of maximum allowed iSCSI and FCoE connections */
9100 bp->cnic_eth_dev.max_iscsi_conn =
9101 (max_iscsi_conn & BNX2X_MAX_ISCSI_INIT_CONN_MASK) >>
9102 BNX2X_MAX_ISCSI_INIT_CONN_SHIFT;
9104 bp->cnic_eth_dev.max_fcoe_conn =
9105 (max_fcoe_conn & BNX2X_MAX_FCOE_INIT_CONN_MASK) >>
9106 BNX2X_MAX_FCOE_INIT_CONN_SHIFT;
9108 BNX2X_DEV_INFO("max_iscsi_conn 0x%x max_fcoe_conn 0x%x\n",
9109 bp->cnic_eth_dev.max_iscsi_conn,
9110 bp->cnic_eth_dev.max_fcoe_conn);
9112 /* If mamimum allowed number of connections is zero -
9113 * disable the feature.
9115 if (!bp->cnic_eth_dev.max_iscsi_conn)
9116 bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
9118 if (!bp->cnic_eth_dev.max_fcoe_conn)
9119 bp->flags |= NO_FCOE_FLAG;
9123 static void __devinit bnx2x_get_mac_hwinfo(struct bnx2x *bp)
9126 int func = BP_ABS_FUNC(bp);
9127 int port = BP_PORT(bp);
9129 u8 *iscsi_mac = bp->cnic_eth_dev.iscsi_mac;
9130 u8 *fip_mac = bp->fip_mac;
9133 /* Zero primary MAC configuration */
9134 memset(bp->dev->dev_addr, 0, ETH_ALEN);
9137 BNX2X_ERROR("warning: random MAC workaround active\n");
9138 random_ether_addr(bp->dev->dev_addr);
9139 } else if (IS_MF(bp)) {
9140 val2 = MF_CFG_RD(bp, func_mf_config[func].mac_upper);
9141 val = MF_CFG_RD(bp, func_mf_config[func].mac_lower);
9142 if ((val2 != FUNC_MF_CFG_UPPERMAC_DEFAULT) &&
9143 (val != FUNC_MF_CFG_LOWERMAC_DEFAULT))
9144 bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
9147 /* iSCSI and FCoE NPAR MACs: if there is no either iSCSI or
9148 * FCoE MAC then the appropriate feature should be disabled.
9151 u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg);
9152 if (cfg & MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD) {
9153 val2 = MF_CFG_RD(bp, func_ext_config[func].
9154 iscsi_mac_addr_upper);
9155 val = MF_CFG_RD(bp, func_ext_config[func].
9156 iscsi_mac_addr_lower);
9157 bnx2x_set_mac_buf(iscsi_mac, val, val2);
9158 BNX2X_DEV_INFO("Read iSCSI MAC: "
9160 BNX2X_MAC_PRN_LIST(iscsi_mac));
9162 bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
9164 if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD) {
9165 val2 = MF_CFG_RD(bp, func_ext_config[func].
9166 fcoe_mac_addr_upper);
9167 val = MF_CFG_RD(bp, func_ext_config[func].
9168 fcoe_mac_addr_lower);
9169 bnx2x_set_mac_buf(fip_mac, val, val2);
9170 BNX2X_DEV_INFO("Read FCoE L2 MAC to "
9172 BNX2X_MAC_PRN_LIST(fip_mac));
9175 bp->flags |= NO_FCOE_FLAG;
9179 /* in SF read MACs from port configuration */
9180 val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
9181 val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
9182 bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
9185 val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
9187 val = SHMEM_RD(bp, dev_info.port_hw_config[port].
9189 bnx2x_set_mac_buf(iscsi_mac, val, val2);
9193 memcpy(bp->link_params.mac_addr, bp->dev->dev_addr, ETH_ALEN);
9194 memcpy(bp->dev->perm_addr, bp->dev->dev_addr, ETH_ALEN);
9197 /* Set the FCoE MAC in modes other then MF_SI */
9198 if (!CHIP_IS_E1x(bp)) {
9200 memcpy(fip_mac, bp->dev->dev_addr, ETH_ALEN);
9201 else if (!IS_MF(bp))
9202 memcpy(fip_mac, iscsi_mac, ETH_ALEN);
9205 /* Disable iSCSI if MAC configuration is
9208 if (!is_valid_ether_addr(iscsi_mac)) {
9209 bp->flags |= NO_ISCSI_FLAG;
9210 memset(iscsi_mac, 0, ETH_ALEN);
9213 /* Disable FCoE if MAC configuration is
9216 if (!is_valid_ether_addr(fip_mac)) {
9217 bp->flags |= NO_FCOE_FLAG;
9218 memset(bp->fip_mac, 0, ETH_ALEN);
9222 if (!is_valid_ether_addr(bp->dev->dev_addr))
9223 dev_err(&bp->pdev->dev,
9224 "bad Ethernet MAC address configuration: "
9225 BNX2X_MAC_FMT", change it manually before bringing up "
9226 "the appropriate network interface\n",
9227 BNX2X_MAC_PRN_LIST(bp->dev->dev_addr));
9230 static int __devinit bnx2x_get_hwinfo(struct bnx2x *bp)
9232 int /*abs*/func = BP_ABS_FUNC(bp);
9237 bnx2x_get_common_hwinfo(bp);
9240 * initialize IGU parameters
9242 if (CHIP_IS_E1x(bp)) {
9243 bp->common.int_block = INT_BLOCK_HC;
9245 bp->igu_dsb_id = DEF_SB_IGU_ID;
9246 bp->igu_base_sb = 0;
9248 bp->common.int_block = INT_BLOCK_IGU;
9249 val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
9251 if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
9254 BNX2X_DEV_INFO("FORCING Normal Mode\n");
9256 val &= ~(IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN);
9257 REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION, val);
9258 REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x7f);
9260 while (tout && REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
9262 usleep_range(1000, 1000);
9265 if (REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
9266 dev_err(&bp->pdev->dev,
9267 "FORCING Normal Mode failed!!!\n");
9272 if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
9273 BNX2X_DEV_INFO("IGU Backward Compatible Mode\n");
9274 bp->common.int_block |= INT_BLOCK_MODE_BW_COMP;
9276 BNX2X_DEV_INFO("IGU Normal Mode\n");
9278 bnx2x_get_igu_cam_info(bp);
9283 * set base FW non-default (fast path) status block id, this value is
9284 * used to initialize the fw_sb_id saved on the fp/queue structure to
9285 * determine the id used by the FW.
9287 if (CHIP_IS_E1x(bp))
9288 bp->base_fw_ndsb = BP_PORT(bp) * FP_SB_MAX_E1x + BP_L_ID(bp);
9290 * 57712 - we currently use one FW SB per IGU SB (Rx and Tx of
9291 * the same queue are indicated on the same IGU SB). So we prefer
9292 * FW and IGU SBs to be the same value.
9294 bp->base_fw_ndsb = bp->igu_base_sb;
9296 BNX2X_DEV_INFO("igu_dsb_id %d igu_base_sb %d igu_sb_cnt %d\n"
9297 "base_fw_ndsb %d\n", bp->igu_dsb_id, bp->igu_base_sb,
9298 bp->igu_sb_cnt, bp->base_fw_ndsb);
9301 * Initialize MF configuration
9308 if (!CHIP_IS_E1(bp) && !BP_NOMCP(bp)) {
9309 BNX2X_DEV_INFO("shmem2base 0x%x, size %d, mfcfg offset %d\n",
9310 bp->common.shmem2_base, SHMEM2_RD(bp, size),
9311 (u32)offsetof(struct shmem2_region, mf_cfg_addr));
9313 if (SHMEM2_HAS(bp, mf_cfg_addr))
9314 bp->common.mf_cfg_base = SHMEM2_RD(bp, mf_cfg_addr);
9316 bp->common.mf_cfg_base = bp->common.shmem_base +
9317 offsetof(struct shmem_region, func_mb) +
9318 E1H_FUNC_MAX * sizeof(struct drv_func_mb);
9320 * get mf configuration:
9321 * 1. existence of MF configuration
9322 * 2. MAC address must be legal (check only upper bytes)
9323 * for Switch-Independent mode;
9324 * OVLAN must be legal for Switch-Dependent mode
9325 * 3. SF_MODE configures specific MF mode
9327 if (bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
9328 /* get mf configuration */
9330 dev_info.shared_feature_config.config);
9331 val &= SHARED_FEAT_CFG_FORCE_SF_MODE_MASK;
9334 case SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT:
9335 val = MF_CFG_RD(bp, func_mf_config[func].
9337 /* check for legal mac (upper bytes)*/
9338 if (val != 0xffff) {
9339 bp->mf_mode = MULTI_FUNCTION_SI;
9340 bp->mf_config[vn] = MF_CFG_RD(bp,
9341 func_mf_config[func].config);
9343 BNX2X_DEV_INFO("illegal MAC address "
9346 case SHARED_FEAT_CFG_FORCE_SF_MODE_MF_ALLOWED:
9347 /* get OV configuration */
9349 func_mf_config[FUNC_0].e1hov_tag);
9350 val &= FUNC_MF_CFG_E1HOV_TAG_MASK;
9352 if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
9353 bp->mf_mode = MULTI_FUNCTION_SD;
9354 bp->mf_config[vn] = MF_CFG_RD(bp,
9355 func_mf_config[func].config);
9357 BNX2X_DEV_INFO("illegal OV for SD\n");
9360 /* Unknown configuration: reset mf_config */
9361 bp->mf_config[vn] = 0;
9362 BNX2X_DEV_INFO("unkown MF mode 0x%x\n", val);
9366 BNX2X_DEV_INFO("%s function mode\n",
9367 IS_MF(bp) ? "multi" : "single");
9369 switch (bp->mf_mode) {
9370 case MULTI_FUNCTION_SD:
9371 val = MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
9372 FUNC_MF_CFG_E1HOV_TAG_MASK;
9373 if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
9375 bp->path_has_ovlan = true;
9377 BNX2X_DEV_INFO("MF OV for func %d is %d "
9378 "(0x%04x)\n", func, bp->mf_ov,
9381 dev_err(&bp->pdev->dev,
9382 "No valid MF OV for func %d, "
9383 "aborting\n", func);
9387 case MULTI_FUNCTION_SI:
9388 BNX2X_DEV_INFO("func %d is in MF "
9389 "switch-independent mode\n", func);
9393 dev_err(&bp->pdev->dev,
9394 "VN %d is in a single function mode, "
9401 /* check if other port on the path needs ovlan:
9402 * Since MF configuration is shared between ports
9403 * Possible mixed modes are only
9404 * {SF, SI} {SF, SD} {SD, SF} {SI, SF}
9406 if (CHIP_MODE_IS_4_PORT(bp) &&
9407 !bp->path_has_ovlan &&
9409 bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
9410 u8 other_port = !BP_PORT(bp);
9411 u8 other_func = BP_PATH(bp) + 2*other_port;
9413 func_mf_config[other_func].e1hov_tag);
9414 if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT)
9415 bp->path_has_ovlan = true;
9419 /* adjust igu_sb_cnt to MF for E1x */
9420 if (CHIP_IS_E1x(bp) && IS_MF(bp))
9421 bp->igu_sb_cnt /= E1HVN_MAX;
9424 bnx2x_get_port_hwinfo(bp);
9426 if (!BP_NOMCP(bp)) {
9428 (SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
9429 DRV_MSG_SEQ_NUMBER_MASK);
9430 BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
9433 /* Get MAC addresses */
9434 bnx2x_get_mac_hwinfo(bp);
9437 bnx2x_get_cnic_info(bp);
9440 /* Get current FW pulse sequence */
9441 if (!BP_NOMCP(bp)) {
9442 int mb_idx = BP_FW_MB_IDX(bp);
9444 bp->fw_drv_pulse_wr_seq =
9445 (SHMEM_RD(bp, func_mb[mb_idx].drv_pulse_mb) &
9446 DRV_PULSE_SEQ_MASK);
9447 BNX2X_DEV_INFO("drv_pulse 0x%x\n", bp->fw_drv_pulse_wr_seq);
9453 static void __devinit bnx2x_read_fwinfo(struct bnx2x *bp)
9455 int cnt, i, block_end, rodi;
9456 char vpd_data[BNX2X_VPD_LEN+1];
9457 char str_id_reg[VENDOR_ID_LEN+1];
9458 char str_id_cap[VENDOR_ID_LEN+1];
9461 cnt = pci_read_vpd(bp->pdev, 0, BNX2X_VPD_LEN, vpd_data);
9462 memset(bp->fw_ver, 0, sizeof(bp->fw_ver));
9464 if (cnt < BNX2X_VPD_LEN)
9467 i = pci_vpd_find_tag(vpd_data, 0, BNX2X_VPD_LEN,
9468 PCI_VPD_LRDT_RO_DATA);
9473 block_end = i + PCI_VPD_LRDT_TAG_SIZE +
9474 pci_vpd_lrdt_size(&vpd_data[i]);
9476 i += PCI_VPD_LRDT_TAG_SIZE;
9478 if (block_end > BNX2X_VPD_LEN)
9481 rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
9482 PCI_VPD_RO_KEYWORD_MFR_ID);
9486 len = pci_vpd_info_field_size(&vpd_data[rodi]);
9488 if (len != VENDOR_ID_LEN)
9491 rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
9493 /* vendor specific info */
9494 snprintf(str_id_reg, VENDOR_ID_LEN + 1, "%04x", PCI_VENDOR_ID_DELL);
9495 snprintf(str_id_cap, VENDOR_ID_LEN + 1, "%04X", PCI_VENDOR_ID_DELL);
9496 if (!strncmp(str_id_reg, &vpd_data[rodi], VENDOR_ID_LEN) ||
9497 !strncmp(str_id_cap, &vpd_data[rodi], VENDOR_ID_LEN)) {
9499 rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
9500 PCI_VPD_RO_KEYWORD_VENDOR0);
9502 len = pci_vpd_info_field_size(&vpd_data[rodi]);
9504 rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
9506 if (len < 32 && (len + rodi) <= BNX2X_VPD_LEN) {
9507 memcpy(bp->fw_ver, &vpd_data[rodi], len);
9508 bp->fw_ver[len] = ' ';
9517 static void __devinit bnx2x_set_modes_bitmap(struct bnx2x *bp)
9521 if (CHIP_REV_IS_FPGA(bp))
9522 SET_FLAGS(flags, MODE_FPGA);
9523 else if (CHIP_REV_IS_EMUL(bp))
9524 SET_FLAGS(flags, MODE_EMUL);
9526 SET_FLAGS(flags, MODE_ASIC);
9528 if (CHIP_MODE_IS_4_PORT(bp))
9529 SET_FLAGS(flags, MODE_PORT4);
9531 SET_FLAGS(flags, MODE_PORT2);
9534 SET_FLAGS(flags, MODE_E2);
9535 else if (CHIP_IS_E3(bp)) {
9536 SET_FLAGS(flags, MODE_E3);
9537 if (CHIP_REV(bp) == CHIP_REV_Ax)
9538 SET_FLAGS(flags, MODE_E3_A0);
9539 else /*if (CHIP_REV(bp) == CHIP_REV_Bx)*/
9540 SET_FLAGS(flags, MODE_E3_B0 | MODE_COS3);
9544 SET_FLAGS(flags, MODE_MF);
9545 switch (bp->mf_mode) {
9546 case MULTI_FUNCTION_SD:
9547 SET_FLAGS(flags, MODE_MF_SD);
9549 case MULTI_FUNCTION_SI:
9550 SET_FLAGS(flags, MODE_MF_SI);
9554 SET_FLAGS(flags, MODE_SF);
9556 #if defined(__LITTLE_ENDIAN)
9557 SET_FLAGS(flags, MODE_LITTLE_ENDIAN);
9558 #else /*(__BIG_ENDIAN)*/
9559 SET_FLAGS(flags, MODE_BIG_ENDIAN);
9561 INIT_MODE_FLAGS(bp) = flags;
9564 static int __devinit bnx2x_init_bp(struct bnx2x *bp)
9570 mutex_init(&bp->port.phy_mutex);
9571 mutex_init(&bp->fw_mb_mutex);
9572 spin_lock_init(&bp->stats_lock);
9574 mutex_init(&bp->cnic_mutex);
9577 INIT_DELAYED_WORK(&bp->sp_task, bnx2x_sp_task);
9578 INIT_DELAYED_WORK(&bp->sp_rtnl_task, bnx2x_sp_rtnl_task);
9579 INIT_DELAYED_WORK(&bp->period_task, bnx2x_period_task);
9580 rc = bnx2x_get_hwinfo(bp);
9584 bnx2x_set_modes_bitmap(bp);
9586 rc = bnx2x_alloc_mem_bp(bp);
9590 bnx2x_read_fwinfo(bp);
9594 /* need to reset chip if undi was active */
9596 bnx2x_undi_unload(bp);
9598 if (CHIP_REV_IS_FPGA(bp))
9599 dev_err(&bp->pdev->dev, "FPGA detected\n");
9601 if (BP_NOMCP(bp) && (func == 0))
9602 dev_err(&bp->pdev->dev, "MCP disabled, "
9603 "must load devices in order!\n");
9605 bp->multi_mode = multi_mode;
9609 bp->flags &= ~TPA_ENABLE_FLAG;
9610 bp->dev->features &= ~NETIF_F_LRO;
9612 bp->flags |= TPA_ENABLE_FLAG;
9613 bp->dev->features |= NETIF_F_LRO;
9615 bp->disable_tpa = disable_tpa;
9618 bp->dropless_fc = 0;
9620 bp->dropless_fc = dropless_fc;
9624 bp->tx_ring_size = MAX_TX_AVAIL;
9626 /* make sure that the numbers are in the right granularity */
9627 bp->tx_ticks = (50 / BNX2X_BTR) * BNX2X_BTR;
9628 bp->rx_ticks = (25 / BNX2X_BTR) * BNX2X_BTR;
9630 timer_interval = (CHIP_REV_IS_SLOW(bp) ? 5*HZ : HZ);
9631 bp->current_interval = (poll ? poll : timer_interval);
9633 init_timer(&bp->timer);
9634 bp->timer.expires = jiffies + bp->current_interval;
9635 bp->timer.data = (unsigned long) bp;
9636 bp->timer.function = bnx2x_timer;
9638 bnx2x_dcbx_set_state(bp, true, BNX2X_DCBX_ENABLED_ON_NEG_ON);
9639 bnx2x_dcbx_init_params(bp);
9642 if (CHIP_IS_E1x(bp))
9643 bp->cnic_base_cl_id = FP_SB_MAX_E1x;
9645 bp->cnic_base_cl_id = FP_SB_MAX_E2;
9648 /* multiple tx priority */
9649 if (CHIP_IS_E1x(bp))
9650 bp->max_cos = BNX2X_MULTI_TX_COS_E1X;
9651 if (CHIP_IS_E2(bp) || CHIP_IS_E3A0(bp))
9652 bp->max_cos = BNX2X_MULTI_TX_COS_E2_E3A0;
9653 if (CHIP_IS_E3B0(bp))
9654 bp->max_cos = BNX2X_MULTI_TX_COS_E3B0;
9660 /****************************************************************************
9661 * General service functions
9662 ****************************************************************************/
9665 * net_device service functions
9668 /* called with rtnl_lock */
9669 static int bnx2x_open(struct net_device *dev)
9671 struct bnx2x *bp = netdev_priv(dev);
9672 bool global = false;
9673 int other_engine = BP_PATH(bp) ? 0 : 1;
9674 u32 other_load_counter, load_counter;
9676 netif_carrier_off(dev);
9678 bnx2x_set_power_state(bp, PCI_D0);
9680 other_load_counter = bnx2x_get_load_cnt(bp, other_engine);
9681 load_counter = bnx2x_get_load_cnt(bp, BP_PATH(bp));
9684 * If parity had happen during the unload, then attentions
9685 * and/or RECOVERY_IN_PROGRES may still be set. In this case we
9686 * want the first function loaded on the current engine to
9687 * complete the recovery.
9689 if (!bnx2x_reset_is_done(bp, BP_PATH(bp)) ||
9690 bnx2x_chk_parity_attn(bp, &global, true))
9693 * If there are attentions and they are in a global
9694 * blocks, set the GLOBAL_RESET bit regardless whether
9695 * it will be this function that will complete the
9699 bnx2x_set_reset_global(bp);
9702 * Only the first function on the current engine should
9703 * try to recover in open. In case of attentions in
9704 * global blocks only the first in the chip should try
9707 if ((!load_counter &&
9708 (!global || !other_load_counter)) &&
9709 bnx2x_trylock_leader_lock(bp) &&
9710 !bnx2x_leader_reset(bp)) {
9711 netdev_info(bp->dev, "Recovered in open\n");
9715 /* recovery has failed... */
9716 bnx2x_set_power_state(bp, PCI_D3hot);
9717 bp->recovery_state = BNX2X_RECOVERY_FAILED;
9719 netdev_err(bp->dev, "Recovery flow hasn't been properly"
9720 " completed yet. Try again later. If u still see this"
9721 " message after a few retries then power cycle is"
9727 bp->recovery_state = BNX2X_RECOVERY_DONE;
9728 return bnx2x_nic_load(bp, LOAD_OPEN);
9731 /* called with rtnl_lock */
9732 static int bnx2x_close(struct net_device *dev)
9734 struct bnx2x *bp = netdev_priv(dev);
9736 /* Unload the driver, release IRQs */
9737 bnx2x_nic_unload(bp, UNLOAD_CLOSE);
9740 bnx2x_set_power_state(bp, PCI_D3hot);
9745 static inline int bnx2x_init_mcast_macs_list(struct bnx2x *bp,
9746 struct bnx2x_mcast_ramrod_params *p)
9748 int mc_count = netdev_mc_count(bp->dev);
9749 struct bnx2x_mcast_list_elem *mc_mac =
9750 kzalloc(sizeof(*mc_mac) * mc_count, GFP_ATOMIC);
9751 struct netdev_hw_addr *ha;
9756 INIT_LIST_HEAD(&p->mcast_list);
9758 netdev_for_each_mc_addr(ha, bp->dev) {
9759 mc_mac->mac = bnx2x_mc_addr(ha);
9760 list_add_tail(&mc_mac->link, &p->mcast_list);
9764 p->mcast_list_len = mc_count;
9769 static inline void bnx2x_free_mcast_macs_list(
9770 struct bnx2x_mcast_ramrod_params *p)
9772 struct bnx2x_mcast_list_elem *mc_mac =
9773 list_first_entry(&p->mcast_list, struct bnx2x_mcast_list_elem,
9781 * bnx2x_set_uc_list - configure a new unicast MACs list.
9783 * @bp: driver handle
9785 * We will use zero (0) as a MAC type for these MACs.
9787 static inline int bnx2x_set_uc_list(struct bnx2x *bp)
9790 struct net_device *dev = bp->dev;
9791 struct netdev_hw_addr *ha;
9792 struct bnx2x_vlan_mac_obj *mac_obj = &bp->fp->mac_obj;
9793 unsigned long ramrod_flags = 0;
9795 /* First schedule a cleanup up of old configuration */
9796 rc = bnx2x_del_all_macs(bp, mac_obj, BNX2X_UC_LIST_MAC, false);
9798 BNX2X_ERR("Failed to schedule DELETE operations: %d\n", rc);
9802 netdev_for_each_uc_addr(ha, dev) {
9803 rc = bnx2x_set_mac_one(bp, bnx2x_uc_addr(ha), mac_obj, true,
9804 BNX2X_UC_LIST_MAC, &ramrod_flags);
9806 BNX2X_ERR("Failed to schedule ADD operations: %d\n",
9812 /* Execute the pending commands */
9813 __set_bit(RAMROD_CONT, &ramrod_flags);
9814 return bnx2x_set_mac_one(bp, NULL, mac_obj, false /* don't care */,
9815 BNX2X_UC_LIST_MAC, &ramrod_flags);
9818 static inline int bnx2x_set_mc_list(struct bnx2x *bp)
9820 struct net_device *dev = bp->dev;
9821 struct bnx2x_mcast_ramrod_params rparam = {0};
9824 rparam.mcast_obj = &bp->mcast_obj;
9826 /* first, clear all configured multicast MACs */
9827 rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
9829 BNX2X_ERR("Failed to clear multicast "
9830 "configuration: %d\n", rc);
9834 /* then, configure a new MACs list */
9835 if (netdev_mc_count(dev)) {
9836 rc = bnx2x_init_mcast_macs_list(bp, &rparam);
9838 BNX2X_ERR("Failed to create multicast MACs "
9843 /* Now add the new MACs */
9844 rc = bnx2x_config_mcast(bp, &rparam,
9845 BNX2X_MCAST_CMD_ADD);
9847 BNX2X_ERR("Failed to set a new multicast "
9848 "configuration: %d\n", rc);
9850 bnx2x_free_mcast_macs_list(&rparam);
9857 /* If bp->state is OPEN, should be called with netif_addr_lock_bh() */
9858 void bnx2x_set_rx_mode(struct net_device *dev)
9860 struct bnx2x *bp = netdev_priv(dev);
9861 u32 rx_mode = BNX2X_RX_MODE_NORMAL;
9863 if (bp->state != BNX2X_STATE_OPEN) {
9864 DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
9868 DP(NETIF_MSG_IFUP, "dev->flags = %x\n", bp->dev->flags);
9870 if (dev->flags & IFF_PROMISC)
9871 rx_mode = BNX2X_RX_MODE_PROMISC;
9872 else if ((dev->flags & IFF_ALLMULTI) ||
9873 ((netdev_mc_count(dev) > BNX2X_MAX_MULTICAST) &&
9875 rx_mode = BNX2X_RX_MODE_ALLMULTI;
9877 /* some multicasts */
9878 if (bnx2x_set_mc_list(bp) < 0)
9879 rx_mode = BNX2X_RX_MODE_ALLMULTI;
9881 if (bnx2x_set_uc_list(bp) < 0)
9882 rx_mode = BNX2X_RX_MODE_PROMISC;
9885 bp->rx_mode = rx_mode;
9887 /* Schedule the rx_mode command */
9888 if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state)) {
9889 set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
9893 bnx2x_set_storm_rx_mode(bp);
9896 /* called with rtnl_lock */
9897 static int bnx2x_mdio_read(struct net_device *netdev, int prtad,
9898 int devad, u16 addr)
9900 struct bnx2x *bp = netdev_priv(netdev);
9904 DP(NETIF_MSG_LINK, "mdio_read: prtad 0x%x, devad 0x%x, addr 0x%x\n",
9905 prtad, devad, addr);
9907 /* The HW expects different devad if CL22 is used */
9908 devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
9910 bnx2x_acquire_phy_lock(bp);
9911 rc = bnx2x_phy_read(&bp->link_params, prtad, devad, addr, &value);
9912 bnx2x_release_phy_lock(bp);
9913 DP(NETIF_MSG_LINK, "mdio_read_val 0x%x rc = 0x%x\n", value, rc);
9920 /* called with rtnl_lock */
9921 static int bnx2x_mdio_write(struct net_device *netdev, int prtad, int devad,
9922 u16 addr, u16 value)
9924 struct bnx2x *bp = netdev_priv(netdev);
9927 DP(NETIF_MSG_LINK, "mdio_write: prtad 0x%x, devad 0x%x, addr 0x%x,"
9928 " value 0x%x\n", prtad, devad, addr, value);
9930 /* The HW expects different devad if CL22 is used */
9931 devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
9933 bnx2x_acquire_phy_lock(bp);
9934 rc = bnx2x_phy_write(&bp->link_params, prtad, devad, addr, value);
9935 bnx2x_release_phy_lock(bp);
9939 /* called with rtnl_lock */
9940 static int bnx2x_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
9942 struct bnx2x *bp = netdev_priv(dev);
9943 struct mii_ioctl_data *mdio = if_mii(ifr);
9945 DP(NETIF_MSG_LINK, "ioctl: phy id 0x%x, reg 0x%x, val_in 0x%x\n",
9946 mdio->phy_id, mdio->reg_num, mdio->val_in);
9948 if (!netif_running(dev))
9951 return mdio_mii_ioctl(&bp->mdio, mdio, cmd);
9954 #ifdef CONFIG_NET_POLL_CONTROLLER
9955 static void poll_bnx2x(struct net_device *dev)
9957 struct bnx2x *bp = netdev_priv(dev);
9959 disable_irq(bp->pdev->irq);
9960 bnx2x_interrupt(bp->pdev->irq, dev);
9961 enable_irq(bp->pdev->irq);
9965 static const struct net_device_ops bnx2x_netdev_ops = {
9966 .ndo_open = bnx2x_open,
9967 .ndo_stop = bnx2x_close,
9968 .ndo_start_xmit = bnx2x_start_xmit,
9969 .ndo_select_queue = bnx2x_select_queue,
9970 .ndo_set_rx_mode = bnx2x_set_rx_mode,
9971 .ndo_set_mac_address = bnx2x_change_mac_addr,
9972 .ndo_validate_addr = eth_validate_addr,
9973 .ndo_do_ioctl = bnx2x_ioctl,
9974 .ndo_change_mtu = bnx2x_change_mtu,
9975 .ndo_fix_features = bnx2x_fix_features,
9976 .ndo_set_features = bnx2x_set_features,
9977 .ndo_tx_timeout = bnx2x_tx_timeout,
9978 #ifdef CONFIG_NET_POLL_CONTROLLER
9979 .ndo_poll_controller = poll_bnx2x,
9981 .ndo_setup_tc = bnx2x_setup_tc,
9985 static inline int bnx2x_set_coherency_mask(struct bnx2x *bp)
9987 struct device *dev = &bp->pdev->dev;
9989 if (dma_set_mask(dev, DMA_BIT_MASK(64)) == 0) {
9990 bp->flags |= USING_DAC_FLAG;
9991 if (dma_set_coherent_mask(dev, DMA_BIT_MASK(64)) != 0) {
9992 dev_err(dev, "dma_set_coherent_mask failed, "
9996 } else if (dma_set_mask(dev, DMA_BIT_MASK(32)) != 0) {
9997 dev_err(dev, "System does not support DMA, aborting\n");
10004 static int __devinit bnx2x_init_dev(struct pci_dev *pdev,
10005 struct net_device *dev,
10006 unsigned long board_type)
10011 SET_NETDEV_DEV(dev, &pdev->dev);
10012 bp = netdev_priv(dev);
10017 bp->pf_num = PCI_FUNC(pdev->devfn);
10019 rc = pci_enable_device(pdev);
10021 dev_err(&bp->pdev->dev,
10022 "Cannot enable PCI device, aborting\n");
10026 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
10027 dev_err(&bp->pdev->dev,
10028 "Cannot find PCI device base address, aborting\n");
10030 goto err_out_disable;
10033 if (!(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
10034 dev_err(&bp->pdev->dev, "Cannot find second PCI device"
10035 " base address, aborting\n");
10037 goto err_out_disable;
10040 if (atomic_read(&pdev->enable_cnt) == 1) {
10041 rc = pci_request_regions(pdev, DRV_MODULE_NAME);
10043 dev_err(&bp->pdev->dev,
10044 "Cannot obtain PCI resources, aborting\n");
10045 goto err_out_disable;
10048 pci_set_master(pdev);
10049 pci_save_state(pdev);
10052 bp->pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
10053 if (bp->pm_cap == 0) {
10054 dev_err(&bp->pdev->dev,
10055 "Cannot find power management capability, aborting\n");
10057 goto err_out_release;
10060 if (!pci_is_pcie(pdev)) {
10061 dev_err(&bp->pdev->dev, "Not PCI Express, aborting\n");
10063 goto err_out_release;
10066 rc = bnx2x_set_coherency_mask(bp);
10068 goto err_out_release;
10070 dev->mem_start = pci_resource_start(pdev, 0);
10071 dev->base_addr = dev->mem_start;
10072 dev->mem_end = pci_resource_end(pdev, 0);
10074 dev->irq = pdev->irq;
10076 bp->regview = pci_ioremap_bar(pdev, 0);
10077 if (!bp->regview) {
10078 dev_err(&bp->pdev->dev,
10079 "Cannot map register space, aborting\n");
10081 goto err_out_release;
10084 bnx2x_set_power_state(bp, PCI_D0);
10086 /* clean indirect addresses */
10087 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
10088 PCICFG_VENDOR_ID_OFFSET);
10089 REG_WR(bp, PXP2_REG_PGL_ADDR_88_F0 + BP_PORT(bp)*16, 0);
10090 REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F0 + BP_PORT(bp)*16, 0);
10091 REG_WR(bp, PXP2_REG_PGL_ADDR_90_F0 + BP_PORT(bp)*16, 0);
10092 REG_WR(bp, PXP2_REG_PGL_ADDR_94_F0 + BP_PORT(bp)*16, 0);
10095 * Enable internal target-read (in case we are probed after PF FLR).
10096 * Must be done prior to any BAR read access
10098 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
10100 /* Reset the load counter */
10101 bnx2x_clear_load_cnt(bp);
10103 dev->watchdog_timeo = TX_TIMEOUT;
10105 dev->netdev_ops = &bnx2x_netdev_ops;
10106 bnx2x_set_ethtool_ops(dev);
10108 dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
10109 NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
10110 NETIF_F_RXCSUM | NETIF_F_LRO | NETIF_F_HW_VLAN_TX;
10112 dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
10113 NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 | NETIF_F_HIGHDMA;
10115 dev->features |= dev->hw_features | NETIF_F_HW_VLAN_RX;
10116 if (bp->flags & USING_DAC_FLAG)
10117 dev->features |= NETIF_F_HIGHDMA;
10119 /* Add Loopback capability to the device */
10120 dev->hw_features |= NETIF_F_LOOPBACK;
10123 dev->dcbnl_ops = &bnx2x_dcbnl_ops;
10126 /* get_port_hwinfo() will set prtad and mmds properly */
10127 bp->mdio.prtad = MDIO_PRTAD_NONE;
10129 bp->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
10130 bp->mdio.dev = dev;
10131 bp->mdio.mdio_read = bnx2x_mdio_read;
10132 bp->mdio.mdio_write = bnx2x_mdio_write;
10137 if (atomic_read(&pdev->enable_cnt) == 1)
10138 pci_release_regions(pdev);
10141 pci_disable_device(pdev);
10142 pci_set_drvdata(pdev, NULL);
10148 static void __devinit bnx2x_get_pcie_width_speed(struct bnx2x *bp,
10149 int *width, int *speed)
10151 u32 val = REG_RD(bp, PCICFG_OFFSET + PCICFG_LINK_CONTROL);
10153 *width = (val & PCICFG_LINK_WIDTH) >> PCICFG_LINK_WIDTH_SHIFT;
10155 /* return value of 1=2.5GHz 2=5GHz */
10156 *speed = (val & PCICFG_LINK_SPEED) >> PCICFG_LINK_SPEED_SHIFT;
10159 static int bnx2x_check_firmware(struct bnx2x *bp)
10161 const struct firmware *firmware = bp->firmware;
10162 struct bnx2x_fw_file_hdr *fw_hdr;
10163 struct bnx2x_fw_file_section *sections;
10164 u32 offset, len, num_ops;
10169 if (firmware->size < sizeof(struct bnx2x_fw_file_hdr))
10172 fw_hdr = (struct bnx2x_fw_file_hdr *)firmware->data;
10173 sections = (struct bnx2x_fw_file_section *)fw_hdr;
10175 /* Make sure none of the offsets and sizes make us read beyond
10176 * the end of the firmware data */
10177 for (i = 0; i < sizeof(*fw_hdr) / sizeof(*sections); i++) {
10178 offset = be32_to_cpu(sections[i].offset);
10179 len = be32_to_cpu(sections[i].len);
10180 if (offset + len > firmware->size) {
10181 dev_err(&bp->pdev->dev,
10182 "Section %d length is out of bounds\n", i);
10187 /* Likewise for the init_ops offsets */
10188 offset = be32_to_cpu(fw_hdr->init_ops_offsets.offset);
10189 ops_offsets = (u16 *)(firmware->data + offset);
10190 num_ops = be32_to_cpu(fw_hdr->init_ops.len) / sizeof(struct raw_op);
10192 for (i = 0; i < be32_to_cpu(fw_hdr->init_ops_offsets.len) / 2; i++) {
10193 if (be16_to_cpu(ops_offsets[i]) > num_ops) {
10194 dev_err(&bp->pdev->dev,
10195 "Section offset %d is out of bounds\n", i);
10200 /* Check FW version */
10201 offset = be32_to_cpu(fw_hdr->fw_version.offset);
10202 fw_ver = firmware->data + offset;
10203 if ((fw_ver[0] != BCM_5710_FW_MAJOR_VERSION) ||
10204 (fw_ver[1] != BCM_5710_FW_MINOR_VERSION) ||
10205 (fw_ver[2] != BCM_5710_FW_REVISION_VERSION) ||
10206 (fw_ver[3] != BCM_5710_FW_ENGINEERING_VERSION)) {
10207 dev_err(&bp->pdev->dev,
10208 "Bad FW version:%d.%d.%d.%d. Should be %d.%d.%d.%d\n",
10209 fw_ver[0], fw_ver[1], fw_ver[2],
10210 fw_ver[3], BCM_5710_FW_MAJOR_VERSION,
10211 BCM_5710_FW_MINOR_VERSION,
10212 BCM_5710_FW_REVISION_VERSION,
10213 BCM_5710_FW_ENGINEERING_VERSION);
10220 static inline void be32_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
10222 const __be32 *source = (const __be32 *)_source;
10223 u32 *target = (u32 *)_target;
10226 for (i = 0; i < n/4; i++)
10227 target[i] = be32_to_cpu(source[i]);
10231 Ops array is stored in the following format:
10232 {op(8bit), offset(24bit, big endian), data(32bit, big endian)}
10234 static inline void bnx2x_prep_ops(const u8 *_source, u8 *_target, u32 n)
10236 const __be32 *source = (const __be32 *)_source;
10237 struct raw_op *target = (struct raw_op *)_target;
10240 for (i = 0, j = 0; i < n/8; i++, j += 2) {
10241 tmp = be32_to_cpu(source[j]);
10242 target[i].op = (tmp >> 24) & 0xff;
10243 target[i].offset = tmp & 0xffffff;
10244 target[i].raw_data = be32_to_cpu(source[j + 1]);
10249 * IRO array is stored in the following format:
10250 * {base(24bit), m1(16bit), m2(16bit), m3(16bit), size(16bit) }
10252 static inline void bnx2x_prep_iro(const u8 *_source, u8 *_target, u32 n)
10254 const __be32 *source = (const __be32 *)_source;
10255 struct iro *target = (struct iro *)_target;
10258 for (i = 0, j = 0; i < n/sizeof(struct iro); i++) {
10259 target[i].base = be32_to_cpu(source[j]);
10261 tmp = be32_to_cpu(source[j]);
10262 target[i].m1 = (tmp >> 16) & 0xffff;
10263 target[i].m2 = tmp & 0xffff;
10265 tmp = be32_to_cpu(source[j]);
10266 target[i].m3 = (tmp >> 16) & 0xffff;
10267 target[i].size = tmp & 0xffff;
10272 static inline void be16_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
10274 const __be16 *source = (const __be16 *)_source;
10275 u16 *target = (u16 *)_target;
10278 for (i = 0; i < n/2; i++)
10279 target[i] = be16_to_cpu(source[i]);
10282 #define BNX2X_ALLOC_AND_SET(arr, lbl, func) \
10284 u32 len = be32_to_cpu(fw_hdr->arr.len); \
10285 bp->arr = kmalloc(len, GFP_KERNEL); \
10287 pr_err("Failed to allocate %d bytes for "#arr"\n", len); \
10290 func(bp->firmware->data + be32_to_cpu(fw_hdr->arr.offset), \
10291 (u8 *)bp->arr, len); \
10294 int bnx2x_init_firmware(struct bnx2x *bp)
10296 const char *fw_file_name;
10297 struct bnx2x_fw_file_hdr *fw_hdr;
10300 if (CHIP_IS_E1(bp))
10301 fw_file_name = FW_FILE_NAME_E1;
10302 else if (CHIP_IS_E1H(bp))
10303 fw_file_name = FW_FILE_NAME_E1H;
10304 else if (!CHIP_IS_E1x(bp))
10305 fw_file_name = FW_FILE_NAME_E2;
10307 BNX2X_ERR("Unsupported chip revision\n");
10311 BNX2X_DEV_INFO("Loading %s\n", fw_file_name);
10313 rc = request_firmware(&bp->firmware, fw_file_name, &bp->pdev->dev);
10315 BNX2X_ERR("Can't load firmware file %s\n", fw_file_name);
10316 goto request_firmware_exit;
10319 rc = bnx2x_check_firmware(bp);
10321 BNX2X_ERR("Corrupt firmware file %s\n", fw_file_name);
10322 goto request_firmware_exit;
10325 fw_hdr = (struct bnx2x_fw_file_hdr *)bp->firmware->data;
10327 /* Initialize the pointers to the init arrays */
10329 BNX2X_ALLOC_AND_SET(init_data, request_firmware_exit, be32_to_cpu_n);
10332 BNX2X_ALLOC_AND_SET(init_ops, init_ops_alloc_err, bnx2x_prep_ops);
10335 BNX2X_ALLOC_AND_SET(init_ops_offsets, init_offsets_alloc_err,
10338 /* STORMs firmware */
10339 INIT_TSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
10340 be32_to_cpu(fw_hdr->tsem_int_table_data.offset);
10341 INIT_TSEM_PRAM_DATA(bp) = bp->firmware->data +
10342 be32_to_cpu(fw_hdr->tsem_pram_data.offset);
10343 INIT_USEM_INT_TABLE_DATA(bp) = bp->firmware->data +
10344 be32_to_cpu(fw_hdr->usem_int_table_data.offset);
10345 INIT_USEM_PRAM_DATA(bp) = bp->firmware->data +
10346 be32_to_cpu(fw_hdr->usem_pram_data.offset);
10347 INIT_XSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
10348 be32_to_cpu(fw_hdr->xsem_int_table_data.offset);
10349 INIT_XSEM_PRAM_DATA(bp) = bp->firmware->data +
10350 be32_to_cpu(fw_hdr->xsem_pram_data.offset);
10351 INIT_CSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
10352 be32_to_cpu(fw_hdr->csem_int_table_data.offset);
10353 INIT_CSEM_PRAM_DATA(bp) = bp->firmware->data +
10354 be32_to_cpu(fw_hdr->csem_pram_data.offset);
10356 BNX2X_ALLOC_AND_SET(iro_arr, iro_alloc_err, bnx2x_prep_iro);
10361 kfree(bp->init_ops_offsets);
10362 init_offsets_alloc_err:
10363 kfree(bp->init_ops);
10364 init_ops_alloc_err:
10365 kfree(bp->init_data);
10366 request_firmware_exit:
10367 release_firmware(bp->firmware);
10372 static void bnx2x_release_firmware(struct bnx2x *bp)
10374 kfree(bp->init_ops_offsets);
10375 kfree(bp->init_ops);
10376 kfree(bp->init_data);
10377 release_firmware(bp->firmware);
10381 static struct bnx2x_func_sp_drv_ops bnx2x_func_sp_drv = {
10382 .init_hw_cmn_chip = bnx2x_init_hw_common_chip,
10383 .init_hw_cmn = bnx2x_init_hw_common,
10384 .init_hw_port = bnx2x_init_hw_port,
10385 .init_hw_func = bnx2x_init_hw_func,
10387 .reset_hw_cmn = bnx2x_reset_common,
10388 .reset_hw_port = bnx2x_reset_port,
10389 .reset_hw_func = bnx2x_reset_func,
10391 .gunzip_init = bnx2x_gunzip_init,
10392 .gunzip_end = bnx2x_gunzip_end,
10394 .init_fw = bnx2x_init_firmware,
10395 .release_fw = bnx2x_release_firmware,
10398 void bnx2x__init_func_obj(struct bnx2x *bp)
10400 /* Prepare DMAE related driver resources */
10401 bnx2x_setup_dmae(bp);
10403 bnx2x_init_func_obj(bp, &bp->func_obj,
10404 bnx2x_sp(bp, func_rdata),
10405 bnx2x_sp_mapping(bp, func_rdata),
10406 &bnx2x_func_sp_drv);
10409 /* must be called after sriov-enable */
10410 static inline int bnx2x_set_qm_cid_count(struct bnx2x *bp)
10412 int cid_count = BNX2X_L2_CID_COUNT(bp);
10415 cid_count += CNIC_CID_MAX;
10417 return roundup(cid_count, QM_CID_ROUND);
10421 * bnx2x_get_num_none_def_sbs - return the number of none default SBs
10426 static inline int bnx2x_get_num_non_def_sbs(struct pci_dev *pdev)
10431 pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
10434 * If MSI-X is not supported - return number of SBs needed to support
10435 * one fast path queue: one FP queue + SB for CNIC
10438 return 1 + CNIC_PRESENT;
10441 * The value in the PCI configuration space is the index of the last
10442 * entry, namely one less than the actual size of the table, which is
10443 * exactly what we want to return from this function: number of all SBs
10444 * without the default SB.
10446 pci_read_config_word(pdev, pos + PCI_MSI_FLAGS, &control);
10447 return control & PCI_MSIX_FLAGS_QSIZE;
10450 static int __devinit bnx2x_init_one(struct pci_dev *pdev,
10451 const struct pci_device_id *ent)
10453 struct net_device *dev = NULL;
10455 int pcie_width, pcie_speed;
10456 int rc, max_non_def_sbs;
10457 int rx_count, tx_count, rss_count;
10459 * An estimated maximum supported CoS number according to the chip
10461 * We will try to roughly estimate the maximum number of CoSes this chip
10462 * may support in order to minimize the memory allocated for Tx
10463 * netdev_queue's. This number will be accurately calculated during the
10464 * initialization of bp->max_cos based on the chip versions AND chip
10465 * revision in the bnx2x_init_bp().
10467 u8 max_cos_est = 0;
10469 switch (ent->driver_data) {
10473 max_cos_est = BNX2X_MULTI_TX_COS_E1X;
10478 max_cos_est = BNX2X_MULTI_TX_COS_E2_E3A0;
10487 max_cos_est = BNX2X_MULTI_TX_COS_E3B0;
10491 pr_err("Unknown board_type (%ld), aborting\n",
10496 max_non_def_sbs = bnx2x_get_num_non_def_sbs(pdev);
10499 * Do not allow the maximum SB count to grow above 16
10500 * since Special CIDs starts from 16*BNX2X_MULTI_TX_COS=48.
10501 * We will use the FP_SB_MAX_E1x macro for this matter.
10503 max_non_def_sbs = min_t(int, FP_SB_MAX_E1x, max_non_def_sbs);
10505 WARN_ON(!max_non_def_sbs);
10507 /* Maximum number of RSS queues: one IGU SB goes to CNIC */
10508 rss_count = max_non_def_sbs - CNIC_PRESENT;
10510 /* Maximum number of netdev Rx queues: RSS + FCoE L2 */
10511 rx_count = rss_count + FCOE_PRESENT;
10514 * Maximum number of netdev Tx queues:
10515 * Maximum TSS queues * Maximum supported number of CoS + FCoE L2
10517 tx_count = MAX_TXQS_PER_COS * max_cos_est + FCOE_PRESENT;
10519 /* dev zeroed in init_etherdev */
10520 dev = alloc_etherdev_mqs(sizeof(*bp), tx_count, rx_count);
10522 dev_err(&pdev->dev, "Cannot allocate net device\n");
10526 bp = netdev_priv(dev);
10528 DP(NETIF_MSG_DRV, "Allocated netdev with %d tx and %d rx queues\n",
10529 tx_count, rx_count);
10531 bp->igu_sb_cnt = max_non_def_sbs;
10532 bp->msg_enable = debug;
10533 pci_set_drvdata(pdev, dev);
10535 rc = bnx2x_init_dev(pdev, dev, ent->driver_data);
10541 DP(NETIF_MSG_DRV, "max_non_def_sbs %d", max_non_def_sbs);
10543 rc = bnx2x_init_bp(bp);
10545 goto init_one_exit;
10548 * Map doorbels here as we need the real value of bp->max_cos which
10549 * is initialized in bnx2x_init_bp().
10551 bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2),
10552 min_t(u64, BNX2X_DB_SIZE(bp),
10553 pci_resource_len(pdev, 2)));
10554 if (!bp->doorbells) {
10555 dev_err(&bp->pdev->dev,
10556 "Cannot map doorbell space, aborting\n");
10558 goto init_one_exit;
10561 /* calc qm_cid_count */
10562 bp->qm_cid_count = bnx2x_set_qm_cid_count(bp);
10565 /* disable FCOE L2 queue for E1x*/
10566 if (CHIP_IS_E1x(bp))
10567 bp->flags |= NO_FCOE_FLAG;
10571 /* Configure interrupt mode: try to enable MSI-X/MSI if
10572 * needed, set bp->num_queues appropriately.
10574 bnx2x_set_int_mode(bp);
10576 /* Add all NAPI objects */
10577 bnx2x_add_all_napi(bp);
10579 rc = register_netdev(dev);
10581 dev_err(&pdev->dev, "Cannot register net device\n");
10582 goto init_one_exit;
10586 if (!NO_FCOE(bp)) {
10587 /* Add storage MAC address */
10589 dev_addr_add(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
10594 bnx2x_get_pcie_width_speed(bp, &pcie_width, &pcie_speed);
10596 netdev_info(dev, "%s (%c%d) PCI-E x%d %s found at mem %lx,"
10597 " IRQ %d, ", board_info[ent->driver_data].name,
10598 (CHIP_REV(bp) >> 12) + 'A', (CHIP_METAL(bp) >> 4),
10600 ((!CHIP_IS_E2(bp) && pcie_speed == 2) ||
10601 (CHIP_IS_E2(bp) && pcie_speed == 1)) ?
10602 "5GHz (Gen2)" : "2.5GHz",
10603 dev->base_addr, bp->pdev->irq);
10604 pr_cont("node addr %pM\n", dev->dev_addr);
10610 iounmap(bp->regview);
10613 iounmap(bp->doorbells);
10617 if (atomic_read(&pdev->enable_cnt) == 1)
10618 pci_release_regions(pdev);
10620 pci_disable_device(pdev);
10621 pci_set_drvdata(pdev, NULL);
10626 static void __devexit bnx2x_remove_one(struct pci_dev *pdev)
10628 struct net_device *dev = pci_get_drvdata(pdev);
10632 dev_err(&pdev->dev, "BAD net device from bnx2x_init_one\n");
10635 bp = netdev_priv(dev);
10638 /* Delete storage MAC address */
10639 if (!NO_FCOE(bp)) {
10641 dev_addr_del(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
10647 /* Delete app tlvs from dcbnl */
10648 bnx2x_dcbnl_update_applist(bp, true);
10651 unregister_netdev(dev);
10653 /* Delete all NAPI objects */
10654 bnx2x_del_all_napi(bp);
10656 /* Power on: we can't let PCI layer write to us while we are in D3 */
10657 bnx2x_set_power_state(bp, PCI_D0);
10659 /* Disable MSI/MSI-X */
10660 bnx2x_disable_msi(bp);
10663 bnx2x_set_power_state(bp, PCI_D3hot);
10665 /* Make sure RESET task is not scheduled before continuing */
10666 cancel_delayed_work_sync(&bp->sp_rtnl_task);
10669 iounmap(bp->regview);
10672 iounmap(bp->doorbells);
10674 bnx2x_free_mem_bp(bp);
10678 if (atomic_read(&pdev->enable_cnt) == 1)
10679 pci_release_regions(pdev);
10681 pci_disable_device(pdev);
10682 pci_set_drvdata(pdev, NULL);
10685 static int bnx2x_eeh_nic_unload(struct bnx2x *bp)
10689 bp->state = BNX2X_STATE_ERROR;
10691 bp->rx_mode = BNX2X_RX_MODE_NONE;
10694 bnx2x_cnic_notify(bp, CNIC_CTL_STOP_CMD);
10697 bnx2x_tx_disable(bp);
10699 bnx2x_netif_stop(bp, 0);
10701 del_timer_sync(&bp->timer);
10703 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
10706 bnx2x_free_irq(bp);
10708 /* Free SKBs, SGEs, TPA pool and driver internals */
10709 bnx2x_free_skbs(bp);
10711 for_each_rx_queue(bp, i)
10712 bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
10714 bnx2x_free_mem(bp);
10716 bp->state = BNX2X_STATE_CLOSED;
10718 netif_carrier_off(bp->dev);
10723 static void bnx2x_eeh_recover(struct bnx2x *bp)
10727 mutex_init(&bp->port.phy_mutex);
10729 bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
10730 bp->link_params.shmem_base = bp->common.shmem_base;
10731 BNX2X_DEV_INFO("shmem offset is 0x%x\n", bp->common.shmem_base);
10733 if (!bp->common.shmem_base ||
10734 (bp->common.shmem_base < 0xA0000) ||
10735 (bp->common.shmem_base >= 0xC0000)) {
10736 BNX2X_DEV_INFO("MCP not active\n");
10737 bp->flags |= NO_MCP_FLAG;
10741 val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
10742 if ((val & (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
10743 != (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
10744 BNX2X_ERR("BAD MCP validity signature\n");
10746 if (!BP_NOMCP(bp)) {
10748 (SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
10749 DRV_MSG_SEQ_NUMBER_MASK);
10750 BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
10755 * bnx2x_io_error_detected - called when PCI error is detected
10756 * @pdev: Pointer to PCI device
10757 * @state: The current pci connection state
10759 * This function is called after a PCI bus error affecting
10760 * this device has been detected.
10762 static pci_ers_result_t bnx2x_io_error_detected(struct pci_dev *pdev,
10763 pci_channel_state_t state)
10765 struct net_device *dev = pci_get_drvdata(pdev);
10766 struct bnx2x *bp = netdev_priv(dev);
10770 netif_device_detach(dev);
10772 if (state == pci_channel_io_perm_failure) {
10774 return PCI_ERS_RESULT_DISCONNECT;
10777 if (netif_running(dev))
10778 bnx2x_eeh_nic_unload(bp);
10780 pci_disable_device(pdev);
10784 /* Request a slot reset */
10785 return PCI_ERS_RESULT_NEED_RESET;
10789 * bnx2x_io_slot_reset - called after the PCI bus has been reset
10790 * @pdev: Pointer to PCI device
10792 * Restart the card from scratch, as if from a cold-boot.
10794 static pci_ers_result_t bnx2x_io_slot_reset(struct pci_dev *pdev)
10796 struct net_device *dev = pci_get_drvdata(pdev);
10797 struct bnx2x *bp = netdev_priv(dev);
10801 if (pci_enable_device(pdev)) {
10802 dev_err(&pdev->dev,
10803 "Cannot re-enable PCI device after reset\n");
10805 return PCI_ERS_RESULT_DISCONNECT;
10808 pci_set_master(pdev);
10809 pci_restore_state(pdev);
10811 if (netif_running(dev))
10812 bnx2x_set_power_state(bp, PCI_D0);
10816 return PCI_ERS_RESULT_RECOVERED;
10820 * bnx2x_io_resume - called when traffic can start flowing again
10821 * @pdev: Pointer to PCI device
10823 * This callback is called when the error recovery driver tells us that
10824 * its OK to resume normal operation.
10826 static void bnx2x_io_resume(struct pci_dev *pdev)
10828 struct net_device *dev = pci_get_drvdata(pdev);
10829 struct bnx2x *bp = netdev_priv(dev);
10831 if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
10832 netdev_err(bp->dev, "Handling parity error recovery. "
10833 "Try again later\n");
10839 bnx2x_eeh_recover(bp);
10841 if (netif_running(dev))
10842 bnx2x_nic_load(bp, LOAD_NORMAL);
10844 netif_device_attach(dev);
10849 static struct pci_error_handlers bnx2x_err_handler = {
10850 .error_detected = bnx2x_io_error_detected,
10851 .slot_reset = bnx2x_io_slot_reset,
10852 .resume = bnx2x_io_resume,
10855 static struct pci_driver bnx2x_pci_driver = {
10856 .name = DRV_MODULE_NAME,
10857 .id_table = bnx2x_pci_tbl,
10858 .probe = bnx2x_init_one,
10859 .remove = __devexit_p(bnx2x_remove_one),
10860 .suspend = bnx2x_suspend,
10861 .resume = bnx2x_resume,
10862 .err_handler = &bnx2x_err_handler,
10865 static int __init bnx2x_init(void)
10869 pr_info("%s", version);
10871 bnx2x_wq = create_singlethread_workqueue("bnx2x");
10872 if (bnx2x_wq == NULL) {
10873 pr_err("Cannot create workqueue\n");
10877 ret = pci_register_driver(&bnx2x_pci_driver);
10879 pr_err("Cannot register driver\n");
10880 destroy_workqueue(bnx2x_wq);
10885 static void __exit bnx2x_cleanup(void)
10887 pci_unregister_driver(&bnx2x_pci_driver);
10889 destroy_workqueue(bnx2x_wq);
10892 void bnx2x_notify_link_changed(struct bnx2x *bp)
10894 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + BP_FUNC(bp)*sizeof(u32), 1);
10897 module_init(bnx2x_init);
10898 module_exit(bnx2x_cleanup);
10902 * bnx2x_set_iscsi_eth_mac_addr - set iSCSI MAC(s).
10904 * @bp: driver handle
10905 * @set: set or clear the CAM entry
10907 * This function will wait until the ramdord completion returns.
10908 * Return 0 if success, -ENODEV if ramrod doesn't return.
10910 static inline int bnx2x_set_iscsi_eth_mac_addr(struct bnx2x *bp)
10912 unsigned long ramrod_flags = 0;
10914 __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
10915 return bnx2x_set_mac_one(bp, bp->cnic_eth_dev.iscsi_mac,
10916 &bp->iscsi_l2_mac_obj, true,
10917 BNX2X_ISCSI_ETH_MAC, &ramrod_flags);
10920 /* count denotes the number of new completions we have seen */
10921 static void bnx2x_cnic_sp_post(struct bnx2x *bp, int count)
10923 struct eth_spe *spe;
10925 #ifdef BNX2X_STOP_ON_ERROR
10926 if (unlikely(bp->panic))
10930 spin_lock_bh(&bp->spq_lock);
10931 BUG_ON(bp->cnic_spq_pending < count);
10932 bp->cnic_spq_pending -= count;
10935 for (; bp->cnic_kwq_pending; bp->cnic_kwq_pending--) {
10936 u16 type = (le16_to_cpu(bp->cnic_kwq_cons->hdr.type)
10937 & SPE_HDR_CONN_TYPE) >>
10938 SPE_HDR_CONN_TYPE_SHIFT;
10939 u8 cmd = (le32_to_cpu(bp->cnic_kwq_cons->hdr.conn_and_cmd_data)
10940 >> SPE_HDR_CMD_ID_SHIFT) & 0xff;
10942 /* Set validation for iSCSI L2 client before sending SETUP
10945 if (type == ETH_CONNECTION_TYPE) {
10946 if (cmd == RAMROD_CMD_ID_ETH_CLIENT_SETUP)
10947 bnx2x_set_ctx_validation(bp, &bp->context.
10948 vcxt[BNX2X_ISCSI_ETH_CID].eth,
10949 BNX2X_ISCSI_ETH_CID);
10953 * There may be not more than 8 L2, not more than 8 L5 SPEs
10954 * and in the air. We also check that number of outstanding
10955 * COMMON ramrods is not more than the EQ and SPQ can
10958 if (type == ETH_CONNECTION_TYPE) {
10959 if (!atomic_read(&bp->cq_spq_left))
10962 atomic_dec(&bp->cq_spq_left);
10963 } else if (type == NONE_CONNECTION_TYPE) {
10964 if (!atomic_read(&bp->eq_spq_left))
10967 atomic_dec(&bp->eq_spq_left);
10968 } else if ((type == ISCSI_CONNECTION_TYPE) ||
10969 (type == FCOE_CONNECTION_TYPE)) {
10970 if (bp->cnic_spq_pending >=
10971 bp->cnic_eth_dev.max_kwqe_pending)
10974 bp->cnic_spq_pending++;
10976 BNX2X_ERR("Unknown SPE type: %d\n", type);
10981 spe = bnx2x_sp_get_next(bp);
10982 *spe = *bp->cnic_kwq_cons;
10984 DP(NETIF_MSG_TIMER, "pending on SPQ %d, on KWQ %d count %d\n",
10985 bp->cnic_spq_pending, bp->cnic_kwq_pending, count);
10987 if (bp->cnic_kwq_cons == bp->cnic_kwq_last)
10988 bp->cnic_kwq_cons = bp->cnic_kwq;
10990 bp->cnic_kwq_cons++;
10992 bnx2x_sp_prod_update(bp);
10993 spin_unlock_bh(&bp->spq_lock);
10996 static int bnx2x_cnic_sp_queue(struct net_device *dev,
10997 struct kwqe_16 *kwqes[], u32 count)
10999 struct bnx2x *bp = netdev_priv(dev);
11002 #ifdef BNX2X_STOP_ON_ERROR
11003 if (unlikely(bp->panic))
11007 spin_lock_bh(&bp->spq_lock);
11009 for (i = 0; i < count; i++) {
11010 struct eth_spe *spe = (struct eth_spe *)kwqes[i];
11012 if (bp->cnic_kwq_pending == MAX_SP_DESC_CNT)
11015 *bp->cnic_kwq_prod = *spe;
11017 bp->cnic_kwq_pending++;
11019 DP(NETIF_MSG_TIMER, "L5 SPQE %x %x %x:%x pos %d\n",
11020 spe->hdr.conn_and_cmd_data, spe->hdr.type,
11021 spe->data.update_data_addr.hi,
11022 spe->data.update_data_addr.lo,
11023 bp->cnic_kwq_pending);
11025 if (bp->cnic_kwq_prod == bp->cnic_kwq_last)
11026 bp->cnic_kwq_prod = bp->cnic_kwq;
11028 bp->cnic_kwq_prod++;
11031 spin_unlock_bh(&bp->spq_lock);
11033 if (bp->cnic_spq_pending < bp->cnic_eth_dev.max_kwqe_pending)
11034 bnx2x_cnic_sp_post(bp, 0);
11039 static int bnx2x_cnic_ctl_send(struct bnx2x *bp, struct cnic_ctl_info *ctl)
11041 struct cnic_ops *c_ops;
11044 mutex_lock(&bp->cnic_mutex);
11045 c_ops = rcu_dereference_protected(bp->cnic_ops,
11046 lockdep_is_held(&bp->cnic_mutex));
11048 rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
11049 mutex_unlock(&bp->cnic_mutex);
11054 static int bnx2x_cnic_ctl_send_bh(struct bnx2x *bp, struct cnic_ctl_info *ctl)
11056 struct cnic_ops *c_ops;
11060 c_ops = rcu_dereference(bp->cnic_ops);
11062 rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
11069 * for commands that have no data
11071 int bnx2x_cnic_notify(struct bnx2x *bp, int cmd)
11073 struct cnic_ctl_info ctl = {0};
11077 return bnx2x_cnic_ctl_send(bp, &ctl);
11080 static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err)
11082 struct cnic_ctl_info ctl = {0};
11084 /* first we tell CNIC and only then we count this as a completion */
11085 ctl.cmd = CNIC_CTL_COMPLETION_CMD;
11086 ctl.data.comp.cid = cid;
11087 ctl.data.comp.error = err;
11089 bnx2x_cnic_ctl_send_bh(bp, &ctl);
11090 bnx2x_cnic_sp_post(bp, 0);
11094 /* Called with netif_addr_lock_bh() taken.
11095 * Sets an rx_mode config for an iSCSI ETH client.
11097 * Completion should be checked outside.
11099 static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start)
11101 unsigned long accept_flags = 0, ramrod_flags = 0;
11102 u8 cl_id = bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
11103 int sched_state = BNX2X_FILTER_ISCSI_ETH_STOP_SCHED;
11106 /* Start accepting on iSCSI L2 ring. Accept all multicasts
11107 * because it's the only way for UIO Queue to accept
11108 * multicasts (in non-promiscuous mode only one Queue per
11109 * function will receive multicast packets (leading in our
11112 __set_bit(BNX2X_ACCEPT_UNICAST, &accept_flags);
11113 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept_flags);
11114 __set_bit(BNX2X_ACCEPT_BROADCAST, &accept_flags);
11115 __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept_flags);
11117 /* Clear STOP_PENDING bit if START is requested */
11118 clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &bp->sp_state);
11120 sched_state = BNX2X_FILTER_ISCSI_ETH_START_SCHED;
11122 /* Clear START_PENDING bit if STOP is requested */
11123 clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &bp->sp_state);
11125 if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
11126 set_bit(sched_state, &bp->sp_state);
11128 __set_bit(RAMROD_RX, &ramrod_flags);
11129 bnx2x_set_q_rx_mode(bp, cl_id, 0, accept_flags, 0,
11135 static int bnx2x_drv_ctl(struct net_device *dev, struct drv_ctl_info *ctl)
11137 struct bnx2x *bp = netdev_priv(dev);
11140 switch (ctl->cmd) {
11141 case DRV_CTL_CTXTBL_WR_CMD: {
11142 u32 index = ctl->data.io.offset;
11143 dma_addr_t addr = ctl->data.io.dma_addr;
11145 bnx2x_ilt_wr(bp, index, addr);
11149 case DRV_CTL_RET_L5_SPQ_CREDIT_CMD: {
11150 int count = ctl->data.credit.credit_count;
11152 bnx2x_cnic_sp_post(bp, count);
11156 /* rtnl_lock is held. */
11157 case DRV_CTL_START_L2_CMD: {
11158 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
11159 unsigned long sp_bits = 0;
11161 /* Configure the iSCSI classification object */
11162 bnx2x_init_mac_obj(bp, &bp->iscsi_l2_mac_obj,
11163 cp->iscsi_l2_client_id,
11164 cp->iscsi_l2_cid, BP_FUNC(bp),
11165 bnx2x_sp(bp, mac_rdata),
11166 bnx2x_sp_mapping(bp, mac_rdata),
11167 BNX2X_FILTER_MAC_PENDING,
11168 &bp->sp_state, BNX2X_OBJ_TYPE_RX,
11171 /* Set iSCSI MAC address */
11172 rc = bnx2x_set_iscsi_eth_mac_addr(bp);
11179 /* Start accepting on iSCSI L2 ring */
11181 netif_addr_lock_bh(dev);
11182 bnx2x_set_iscsi_eth_rx_mode(bp, true);
11183 netif_addr_unlock_bh(dev);
11185 /* bits to wait on */
11186 __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
11187 __set_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &sp_bits);
11189 if (!bnx2x_wait_sp_comp(bp, sp_bits))
11190 BNX2X_ERR("rx_mode completion timed out!\n");
11195 /* rtnl_lock is held. */
11196 case DRV_CTL_STOP_L2_CMD: {
11197 unsigned long sp_bits = 0;
11199 /* Stop accepting on iSCSI L2 ring */
11200 netif_addr_lock_bh(dev);
11201 bnx2x_set_iscsi_eth_rx_mode(bp, false);
11202 netif_addr_unlock_bh(dev);
11204 /* bits to wait on */
11205 __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
11206 __set_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &sp_bits);
11208 if (!bnx2x_wait_sp_comp(bp, sp_bits))
11209 BNX2X_ERR("rx_mode completion timed out!\n");
11214 /* Unset iSCSI L2 MAC */
11215 rc = bnx2x_del_all_macs(bp, &bp->iscsi_l2_mac_obj,
11216 BNX2X_ISCSI_ETH_MAC, true);
11219 case DRV_CTL_RET_L2_SPQ_CREDIT_CMD: {
11220 int count = ctl->data.credit.credit_count;
11222 smp_mb__before_atomic_inc();
11223 atomic_add(count, &bp->cq_spq_left);
11224 smp_mb__after_atomic_inc();
11229 BNX2X_ERR("unknown command %x\n", ctl->cmd);
11236 void bnx2x_setup_cnic_irq_info(struct bnx2x *bp)
11238 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
11240 if (bp->flags & USING_MSIX_FLAG) {
11241 cp->drv_state |= CNIC_DRV_STATE_USING_MSIX;
11242 cp->irq_arr[0].irq_flags |= CNIC_IRQ_FL_MSIX;
11243 cp->irq_arr[0].vector = bp->msix_table[1].vector;
11245 cp->drv_state &= ~CNIC_DRV_STATE_USING_MSIX;
11246 cp->irq_arr[0].irq_flags &= ~CNIC_IRQ_FL_MSIX;
11248 if (!CHIP_IS_E1x(bp))
11249 cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e2_sb;
11251 cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e1x_sb;
11253 cp->irq_arr[0].status_blk_num = bnx2x_cnic_fw_sb_id(bp);
11254 cp->irq_arr[0].status_blk_num2 = bnx2x_cnic_igu_sb_id(bp);
11255 cp->irq_arr[1].status_blk = bp->def_status_blk;
11256 cp->irq_arr[1].status_blk_num = DEF_SB_ID;
11257 cp->irq_arr[1].status_blk_num2 = DEF_SB_IGU_ID;
11262 static int bnx2x_register_cnic(struct net_device *dev, struct cnic_ops *ops,
11265 struct bnx2x *bp = netdev_priv(dev);
11266 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
11271 bp->cnic_kwq = kzalloc(PAGE_SIZE, GFP_KERNEL);
11275 bp->cnic_kwq_cons = bp->cnic_kwq;
11276 bp->cnic_kwq_prod = bp->cnic_kwq;
11277 bp->cnic_kwq_last = bp->cnic_kwq + MAX_SP_DESC_CNT;
11279 bp->cnic_spq_pending = 0;
11280 bp->cnic_kwq_pending = 0;
11282 bp->cnic_data = data;
11285 cp->drv_state |= CNIC_DRV_STATE_REGD;
11286 cp->iro_arr = bp->iro_arr;
11288 bnx2x_setup_cnic_irq_info(bp);
11290 rcu_assign_pointer(bp->cnic_ops, ops);
11295 static int bnx2x_unregister_cnic(struct net_device *dev)
11297 struct bnx2x *bp = netdev_priv(dev);
11298 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
11300 mutex_lock(&bp->cnic_mutex);
11302 rcu_assign_pointer(bp->cnic_ops, NULL);
11303 mutex_unlock(&bp->cnic_mutex);
11305 kfree(bp->cnic_kwq);
11306 bp->cnic_kwq = NULL;
11311 struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev)
11313 struct bnx2x *bp = netdev_priv(dev);
11314 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
11316 /* If both iSCSI and FCoE are disabled - return NULL in
11317 * order to indicate CNIC that it should not try to work
11318 * with this device.
11320 if (NO_ISCSI(bp) && NO_FCOE(bp))
11323 cp->drv_owner = THIS_MODULE;
11324 cp->chip_id = CHIP_ID(bp);
11325 cp->pdev = bp->pdev;
11326 cp->io_base = bp->regview;
11327 cp->io_base2 = bp->doorbells;
11328 cp->max_kwqe_pending = 8;
11329 cp->ctx_blk_size = CDU_ILT_PAGE_SZ;
11330 cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
11331 bnx2x_cid_ilt_lines(bp);
11332 cp->ctx_tbl_len = CNIC_ILT_LINES;
11333 cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
11334 cp->drv_submit_kwqes_16 = bnx2x_cnic_sp_queue;
11335 cp->drv_ctl = bnx2x_drv_ctl;
11336 cp->drv_register_cnic = bnx2x_register_cnic;
11337 cp->drv_unregister_cnic = bnx2x_unregister_cnic;
11338 cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID;
11339 cp->iscsi_l2_client_id =
11340 bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
11341 cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID;
11343 if (NO_ISCSI_OOO(bp))
11344 cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
11347 cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI;
11350 cp->drv_state |= CNIC_DRV_STATE_NO_FCOE;
11352 DP(BNX2X_MSG_SP, "page_size %d, tbl_offset %d, tbl_lines %d, "
11353 "starting cid %d\n",
11355 cp->ctx_tbl_offset,
11360 EXPORT_SYMBOL(bnx2x_cnic_probe);
11362 #endif /* BCM_CNIC */