1 /* bnx2x_main.c: Broadcom Everest network driver.
3 * Copyright (c) 2007-2012 Broadcom Corporation
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation.
9 * Maintained by: Eilon Greenstein <eilong@broadcom.com>
10 * Written by: Eliezer Tamir
11 * Based on code from Michael Chan's bnx2 driver
12 * UDP CSUM errata workaround by Arik Gendelman
13 * Slowpath and fastpath rework by Vladislav Zolotarov
14 * Statistics and Link management by Yitchak Gertner
18 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
20 #include <linux/module.h>
21 #include <linux/moduleparam.h>
22 #include <linux/kernel.h>
23 #include <linux/device.h> /* for dev_info() */
24 #include <linux/timer.h>
25 #include <linux/errno.h>
26 #include <linux/ioport.h>
27 #include <linux/slab.h>
28 #include <linux/interrupt.h>
29 #include <linux/pci.h>
30 #include <linux/init.h>
31 #include <linux/netdevice.h>
32 #include <linux/etherdevice.h>
33 #include <linux/skbuff.h>
34 #include <linux/dma-mapping.h>
35 #include <linux/bitops.h>
36 #include <linux/irq.h>
37 #include <linux/delay.h>
38 #include <asm/byteorder.h>
39 #include <linux/time.h>
40 #include <linux/ethtool.h>
41 #include <linux/mii.h>
42 #include <linux/if_vlan.h>
46 #include <net/checksum.h>
47 #include <net/ip6_checksum.h>
48 #include <linux/workqueue.h>
49 #include <linux/crc32.h>
50 #include <linux/crc32c.h>
51 #include <linux/prefetch.h>
52 #include <linux/zlib.h>
54 #include <linux/semaphore.h>
55 #include <linux/stringify.h>
56 #include <linux/vmalloc.h>
59 #include "bnx2x_init.h"
60 #include "bnx2x_init_ops.h"
61 #include "bnx2x_cmn.h"
62 #include "bnx2x_dcb.h"
65 #include <linux/firmware.h>
66 #include "bnx2x_fw_file_hdr.h"
68 #define FW_FILE_VERSION \
69 __stringify(BCM_5710_FW_MAJOR_VERSION) "." \
70 __stringify(BCM_5710_FW_MINOR_VERSION) "." \
71 __stringify(BCM_5710_FW_REVISION_VERSION) "." \
72 __stringify(BCM_5710_FW_ENGINEERING_VERSION)
73 #define FW_FILE_NAME_E1 "bnx2x/bnx2x-e1-" FW_FILE_VERSION ".fw"
74 #define FW_FILE_NAME_E1H "bnx2x/bnx2x-e1h-" FW_FILE_VERSION ".fw"
75 #define FW_FILE_NAME_E2 "bnx2x/bnx2x-e2-" FW_FILE_VERSION ".fw"
77 #define MAC_LEADING_ZERO_CNT (ALIGN(ETH_ALEN, sizeof(u32)) - ETH_ALEN)
79 /* Time in jiffies before concluding the transmitter is hung */
80 #define TX_TIMEOUT (5*HZ)
82 static char version
[] =
83 "Broadcom NetXtreme II 5771x/578xx 10/20-Gigabit Ethernet Driver "
84 DRV_MODULE_NAME
" " DRV_MODULE_VERSION
" (" DRV_MODULE_RELDATE
")\n";
86 MODULE_AUTHOR("Eliezer Tamir");
87 MODULE_DESCRIPTION("Broadcom NetXtreme II "
88 "BCM57710/57711/57711E/"
89 "57712/57712_MF/57800/57800_MF/57810/57810_MF/"
90 "57840/57840_MF Driver");
91 MODULE_LICENSE("GPL");
92 MODULE_VERSION(DRV_MODULE_VERSION
);
93 MODULE_FIRMWARE(FW_FILE_NAME_E1
);
94 MODULE_FIRMWARE(FW_FILE_NAME_E1H
);
95 MODULE_FIRMWARE(FW_FILE_NAME_E2
);
99 module_param(num_queues
, int, 0);
100 MODULE_PARM_DESC(num_queues
,
101 " Set number of queues (default is as a number of CPUs)");
103 static int disable_tpa
;
104 module_param(disable_tpa
, int, 0);
105 MODULE_PARM_DESC(disable_tpa
, " Disable the TPA (LRO) feature");
107 #define INT_MODE_INTx 1
108 #define INT_MODE_MSI 2
110 module_param(int_mode
, int, 0);
111 MODULE_PARM_DESC(int_mode
, " Force interrupt mode other than MSI-X "
114 static int dropless_fc
;
115 module_param(dropless_fc
, int, 0);
116 MODULE_PARM_DESC(dropless_fc
, " Pause on exhausted host ring");
118 static int mrrs
= -1;
119 module_param(mrrs
, int, 0);
120 MODULE_PARM_DESC(mrrs
, " Force Max Read Req Size (0..3) (for debug)");
123 module_param(debug
, int, 0);
124 MODULE_PARM_DESC(debug
, " Default debug msglevel");
128 struct workqueue_struct
*bnx2x_wq
;
130 struct bnx2x_mac_vals
{
141 enum bnx2x_board_type
{
160 /* indexed by board_type, above */
164 { "Broadcom NetXtreme II BCM57710 10 Gigabit PCIe [Everest]" },
165 { "Broadcom NetXtreme II BCM57711 10 Gigabit PCIe" },
166 { "Broadcom NetXtreme II BCM57711E 10 Gigabit PCIe" },
167 { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet" },
168 { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Multi Function" },
169 { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet" },
170 { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Multi Function" },
171 { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet" },
172 { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Multi Function" },
173 { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet" },
174 { "Broadcom NetXtreme II BCM57840 10 Gigabit Ethernet" },
175 { "Broadcom NetXtreme II BCM57840 20 Gigabit Ethernet" },
176 { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Multi Function"},
177 { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Multi Function"},
178 { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet"},
179 { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet Multi Function"},
182 #ifndef PCI_DEVICE_ID_NX2_57710
183 #define PCI_DEVICE_ID_NX2_57710 CHIP_NUM_57710
185 #ifndef PCI_DEVICE_ID_NX2_57711
186 #define PCI_DEVICE_ID_NX2_57711 CHIP_NUM_57711
188 #ifndef PCI_DEVICE_ID_NX2_57711E
189 #define PCI_DEVICE_ID_NX2_57711E CHIP_NUM_57711E
191 #ifndef PCI_DEVICE_ID_NX2_57712
192 #define PCI_DEVICE_ID_NX2_57712 CHIP_NUM_57712
194 #ifndef PCI_DEVICE_ID_NX2_57712_MF
195 #define PCI_DEVICE_ID_NX2_57712_MF CHIP_NUM_57712_MF
197 #ifndef PCI_DEVICE_ID_NX2_57800
198 #define PCI_DEVICE_ID_NX2_57800 CHIP_NUM_57800
200 #ifndef PCI_DEVICE_ID_NX2_57800_MF
201 #define PCI_DEVICE_ID_NX2_57800_MF CHIP_NUM_57800_MF
203 #ifndef PCI_DEVICE_ID_NX2_57810
204 #define PCI_DEVICE_ID_NX2_57810 CHIP_NUM_57810
206 #ifndef PCI_DEVICE_ID_NX2_57810_MF
207 #define PCI_DEVICE_ID_NX2_57810_MF CHIP_NUM_57810_MF
209 #ifndef PCI_DEVICE_ID_NX2_57840_O
210 #define PCI_DEVICE_ID_NX2_57840_O CHIP_NUM_57840_OBSOLETE
212 #ifndef PCI_DEVICE_ID_NX2_57840_4_10
213 #define PCI_DEVICE_ID_NX2_57840_4_10 CHIP_NUM_57840_4_10
215 #ifndef PCI_DEVICE_ID_NX2_57840_2_20
216 #define PCI_DEVICE_ID_NX2_57840_2_20 CHIP_NUM_57840_2_20
218 #ifndef PCI_DEVICE_ID_NX2_57840_MFO
219 #define PCI_DEVICE_ID_NX2_57840_MFO CHIP_NUM_57840_MF_OBSOLETE
221 #ifndef PCI_DEVICE_ID_NX2_57840_MF
222 #define PCI_DEVICE_ID_NX2_57840_MF CHIP_NUM_57840_MF
224 #ifndef PCI_DEVICE_ID_NX2_57811
225 #define PCI_DEVICE_ID_NX2_57811 CHIP_NUM_57811
227 #ifndef PCI_DEVICE_ID_NX2_57811_MF
228 #define PCI_DEVICE_ID_NX2_57811_MF CHIP_NUM_57811_MF
230 static DEFINE_PCI_DEVICE_TABLE(bnx2x_pci_tbl
) = {
231 { PCI_VDEVICE(BROADCOM
, PCI_DEVICE_ID_NX2_57710
), BCM57710
},
232 { PCI_VDEVICE(BROADCOM
, PCI_DEVICE_ID_NX2_57711
), BCM57711
},
233 { PCI_VDEVICE(BROADCOM
, PCI_DEVICE_ID_NX2_57711E
), BCM57711E
},
234 { PCI_VDEVICE(BROADCOM
, PCI_DEVICE_ID_NX2_57712
), BCM57712
},
235 { PCI_VDEVICE(BROADCOM
, PCI_DEVICE_ID_NX2_57712_MF
), BCM57712_MF
},
236 { PCI_VDEVICE(BROADCOM
, PCI_DEVICE_ID_NX2_57800
), BCM57800
},
237 { PCI_VDEVICE(BROADCOM
, PCI_DEVICE_ID_NX2_57800_MF
), BCM57800_MF
},
238 { PCI_VDEVICE(BROADCOM
, PCI_DEVICE_ID_NX2_57810
), BCM57810
},
239 { PCI_VDEVICE(BROADCOM
, PCI_DEVICE_ID_NX2_57810_MF
), BCM57810_MF
},
240 { PCI_VDEVICE(BROADCOM
, PCI_DEVICE_ID_NX2_57840_O
), BCM57840_O
},
241 { PCI_VDEVICE(BROADCOM
, PCI_DEVICE_ID_NX2_57840_4_10
), BCM57840_4_10
},
242 { PCI_VDEVICE(BROADCOM
, PCI_DEVICE_ID_NX2_57840_2_20
), BCM57840_2_20
},
243 { PCI_VDEVICE(BROADCOM
, PCI_DEVICE_ID_NX2_57840_MFO
), BCM57840_MFO
},
244 { PCI_VDEVICE(BROADCOM
, PCI_DEVICE_ID_NX2_57840_MF
), BCM57840_MF
},
245 { PCI_VDEVICE(BROADCOM
, PCI_DEVICE_ID_NX2_57811
), BCM57811
},
246 { PCI_VDEVICE(BROADCOM
, PCI_DEVICE_ID_NX2_57811_MF
), BCM57811_MF
},
250 MODULE_DEVICE_TABLE(pci
, bnx2x_pci_tbl
);
252 /* Global resources for unloading a previously loaded device */
253 #define BNX2X_PREV_WAIT_NEEDED 1
254 static DEFINE_SEMAPHORE(bnx2x_prev_sem
);
255 static LIST_HEAD(bnx2x_prev_list
);
256 /****************************************************************************
257 * General service functions
258 ****************************************************************************/
260 static void __storm_memset_dma_mapping(struct bnx2x
*bp
,
261 u32 addr
, dma_addr_t mapping
)
263 REG_WR(bp
, addr
, U64_LO(mapping
));
264 REG_WR(bp
, addr
+ 4, U64_HI(mapping
));
267 static void storm_memset_spq_addr(struct bnx2x
*bp
,
268 dma_addr_t mapping
, u16 abs_fid
)
270 u32 addr
= XSEM_REG_FAST_MEMORY
+
271 XSTORM_SPQ_PAGE_BASE_OFFSET(abs_fid
);
273 __storm_memset_dma_mapping(bp
, addr
, mapping
);
276 static void storm_memset_vf_to_pf(struct bnx2x
*bp
, u16 abs_fid
,
279 REG_WR8(bp
, BAR_XSTRORM_INTMEM
+ XSTORM_VF_TO_PF_OFFSET(abs_fid
),
281 REG_WR8(bp
, BAR_CSTRORM_INTMEM
+ CSTORM_VF_TO_PF_OFFSET(abs_fid
),
283 REG_WR8(bp
, BAR_TSTRORM_INTMEM
+ TSTORM_VF_TO_PF_OFFSET(abs_fid
),
285 REG_WR8(bp
, BAR_USTRORM_INTMEM
+ USTORM_VF_TO_PF_OFFSET(abs_fid
),
289 static void storm_memset_func_en(struct bnx2x
*bp
, u16 abs_fid
,
292 REG_WR8(bp
, BAR_XSTRORM_INTMEM
+ XSTORM_FUNC_EN_OFFSET(abs_fid
),
294 REG_WR8(bp
, BAR_CSTRORM_INTMEM
+ CSTORM_FUNC_EN_OFFSET(abs_fid
),
296 REG_WR8(bp
, BAR_TSTRORM_INTMEM
+ TSTORM_FUNC_EN_OFFSET(abs_fid
),
298 REG_WR8(bp
, BAR_USTRORM_INTMEM
+ USTORM_FUNC_EN_OFFSET(abs_fid
),
302 static void storm_memset_eq_data(struct bnx2x
*bp
,
303 struct event_ring_data
*eq_data
,
306 size_t size
= sizeof(struct event_ring_data
);
308 u32 addr
= BAR_CSTRORM_INTMEM
+ CSTORM_EVENT_RING_DATA_OFFSET(pfid
);
310 __storm_memset_struct(bp
, addr
, size
, (u32
*)eq_data
);
313 static void storm_memset_eq_prod(struct bnx2x
*bp
, u16 eq_prod
,
316 u32 addr
= BAR_CSTRORM_INTMEM
+ CSTORM_EVENT_RING_PROD_OFFSET(pfid
);
317 REG_WR16(bp
, addr
, eq_prod
);
321 * locking is done by mcp
323 static void bnx2x_reg_wr_ind(struct bnx2x
*bp
, u32 addr
, u32 val
)
325 pci_write_config_dword(bp
->pdev
, PCICFG_GRC_ADDRESS
, addr
);
326 pci_write_config_dword(bp
->pdev
, PCICFG_GRC_DATA
, val
);
327 pci_write_config_dword(bp
->pdev
, PCICFG_GRC_ADDRESS
,
328 PCICFG_VENDOR_ID_OFFSET
);
331 static u32
bnx2x_reg_rd_ind(struct bnx2x
*bp
, u32 addr
)
335 pci_write_config_dword(bp
->pdev
, PCICFG_GRC_ADDRESS
, addr
);
336 pci_read_config_dword(bp
->pdev
, PCICFG_GRC_DATA
, &val
);
337 pci_write_config_dword(bp
->pdev
, PCICFG_GRC_ADDRESS
,
338 PCICFG_VENDOR_ID_OFFSET
);
343 #define DMAE_DP_SRC_GRC "grc src_addr [%08x]"
344 #define DMAE_DP_SRC_PCI "pci src_addr [%x:%08x]"
345 #define DMAE_DP_DST_GRC "grc dst_addr [%08x]"
346 #define DMAE_DP_DST_PCI "pci dst_addr [%x:%08x]"
347 #define DMAE_DP_DST_NONE "dst_addr [none]"
350 /* copy command into DMAE command memory and set DMAE command go */
351 void bnx2x_post_dmae(struct bnx2x
*bp
, struct dmae_command
*dmae
, int idx
)
356 cmd_offset
= (DMAE_REG_CMD_MEM
+ sizeof(struct dmae_command
) * idx
);
357 for (i
= 0; i
< (sizeof(struct dmae_command
)/4); i
++) {
358 REG_WR(bp
, cmd_offset
+ i
*4, *(((u32
*)dmae
) + i
));
360 REG_WR(bp
, dmae_reg_go_c
[idx
], 1);
363 u32
bnx2x_dmae_opcode_add_comp(u32 opcode
, u8 comp_type
)
365 return opcode
| ((comp_type
<< DMAE_COMMAND_C_DST_SHIFT
) |
369 u32
bnx2x_dmae_opcode_clr_src_reset(u32 opcode
)
371 return opcode
& ~DMAE_CMD_SRC_RESET
;
374 u32
bnx2x_dmae_opcode(struct bnx2x
*bp
, u8 src_type
, u8 dst_type
,
375 bool with_comp
, u8 comp_type
)
379 opcode
|= ((src_type
<< DMAE_COMMAND_SRC_SHIFT
) |
380 (dst_type
<< DMAE_COMMAND_DST_SHIFT
));
382 opcode
|= (DMAE_CMD_SRC_RESET
| DMAE_CMD_DST_RESET
);
384 opcode
|= (BP_PORT(bp
) ? DMAE_CMD_PORT_1
: DMAE_CMD_PORT_0
);
385 opcode
|= ((BP_VN(bp
) << DMAE_CMD_E1HVN_SHIFT
) |
386 (BP_VN(bp
) << DMAE_COMMAND_DST_VN_SHIFT
));
387 opcode
|= (DMAE_COM_SET_ERR
<< DMAE_COMMAND_ERR_POLICY_SHIFT
);
390 opcode
|= DMAE_CMD_ENDIANITY_B_DW_SWAP
;
392 opcode
|= DMAE_CMD_ENDIANITY_DW_SWAP
;
395 opcode
= bnx2x_dmae_opcode_add_comp(opcode
, comp_type
);
399 static void bnx2x_prep_dmae_with_comp(struct bnx2x
*bp
,
400 struct dmae_command
*dmae
,
401 u8 src_type
, u8 dst_type
)
403 memset(dmae
, 0, sizeof(struct dmae_command
));
406 dmae
->opcode
= bnx2x_dmae_opcode(bp
, src_type
, dst_type
,
407 true, DMAE_COMP_PCI
);
409 /* fill in the completion parameters */
410 dmae
->comp_addr_lo
= U64_LO(bnx2x_sp_mapping(bp
, wb_comp
));
411 dmae
->comp_addr_hi
= U64_HI(bnx2x_sp_mapping(bp
, wb_comp
));
412 dmae
->comp_val
= DMAE_COMP_VAL
;
415 /* issue a dmae command over the init-channel and wailt for completion */
416 static int bnx2x_issue_dmae_with_comp(struct bnx2x
*bp
,
417 struct dmae_command
*dmae
)
419 u32
*wb_comp
= bnx2x_sp(bp
, wb_comp
);
420 int cnt
= CHIP_REV_IS_SLOW(bp
) ? (400000) : 4000;
424 * Lock the dmae channel. Disable BHs to prevent a dead-lock
425 * as long as this code is called both from syscall context and
426 * from ndo_set_rx_mode() flow that may be called from BH.
428 spin_lock_bh(&bp
->dmae_lock
);
430 /* reset completion */
433 /* post the command on the channel used for initializations */
434 bnx2x_post_dmae(bp
, dmae
, INIT_DMAE_C(bp
));
436 /* wait for completion */
438 while ((*wb_comp
& ~DMAE_PCI_ERR_FLAG
) != DMAE_COMP_VAL
) {
441 (bp
->recovery_state
!= BNX2X_RECOVERY_DONE
&&
442 bp
->recovery_state
!= BNX2X_RECOVERY_NIC_LOADING
)) {
443 BNX2X_ERR("DMAE timeout!\n");
450 if (*wb_comp
& DMAE_PCI_ERR_FLAG
) {
451 BNX2X_ERR("DMAE PCI error!\n");
456 spin_unlock_bh(&bp
->dmae_lock
);
460 void bnx2x_write_dmae(struct bnx2x
*bp
, dma_addr_t dma_addr
, u32 dst_addr
,
463 struct dmae_command dmae
;
465 if (!bp
->dmae_ready
) {
466 u32
*data
= bnx2x_sp(bp
, wb_data
[0]);
469 bnx2x_init_ind_wr(bp
, dst_addr
, data
, len32
);
471 bnx2x_init_str_wr(bp
, dst_addr
, data
, len32
);
475 /* set opcode and fixed command fields */
476 bnx2x_prep_dmae_with_comp(bp
, &dmae
, DMAE_SRC_PCI
, DMAE_DST_GRC
);
478 /* fill in addresses and len */
479 dmae
.src_addr_lo
= U64_LO(dma_addr
);
480 dmae
.src_addr_hi
= U64_HI(dma_addr
);
481 dmae
.dst_addr_lo
= dst_addr
>> 2;
482 dmae
.dst_addr_hi
= 0;
485 /* issue the command and wait for completion */
486 bnx2x_issue_dmae_with_comp(bp
, &dmae
);
489 void bnx2x_read_dmae(struct bnx2x
*bp
, u32 src_addr
, u32 len32
)
491 struct dmae_command dmae
;
493 if (!bp
->dmae_ready
) {
494 u32
*data
= bnx2x_sp(bp
, wb_data
[0]);
498 for (i
= 0; i
< len32
; i
++)
499 data
[i
] = bnx2x_reg_rd_ind(bp
, src_addr
+ i
*4);
501 for (i
= 0; i
< len32
; i
++)
502 data
[i
] = REG_RD(bp
, src_addr
+ i
*4);
507 /* set opcode and fixed command fields */
508 bnx2x_prep_dmae_with_comp(bp
, &dmae
, DMAE_SRC_GRC
, DMAE_DST_PCI
);
510 /* fill in addresses and len */
511 dmae
.src_addr_lo
= src_addr
>> 2;
512 dmae
.src_addr_hi
= 0;
513 dmae
.dst_addr_lo
= U64_LO(bnx2x_sp_mapping(bp
, wb_data
));
514 dmae
.dst_addr_hi
= U64_HI(bnx2x_sp_mapping(bp
, wb_data
));
517 /* issue the command and wait for completion */
518 bnx2x_issue_dmae_with_comp(bp
, &dmae
);
521 static void bnx2x_write_dmae_phys_len(struct bnx2x
*bp
, dma_addr_t phys_addr
,
524 int dmae_wr_max
= DMAE_LEN32_WR_MAX(bp
);
527 while (len
> dmae_wr_max
) {
528 bnx2x_write_dmae(bp
, phys_addr
+ offset
,
529 addr
+ offset
, dmae_wr_max
);
530 offset
+= dmae_wr_max
* 4;
534 bnx2x_write_dmae(bp
, phys_addr
+ offset
, addr
+ offset
, len
);
537 static int bnx2x_mc_assert(struct bnx2x
*bp
)
541 u32 row0
, row1
, row2
, row3
;
544 last_idx
= REG_RD8(bp
, BAR_XSTRORM_INTMEM
+
545 XSTORM_ASSERT_LIST_INDEX_OFFSET
);
547 BNX2X_ERR("XSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx
);
549 /* print the asserts */
550 for (i
= 0; i
< STROM_ASSERT_ARRAY_SIZE
; i
++) {
552 row0
= REG_RD(bp
, BAR_XSTRORM_INTMEM
+
553 XSTORM_ASSERT_LIST_OFFSET(i
));
554 row1
= REG_RD(bp
, BAR_XSTRORM_INTMEM
+
555 XSTORM_ASSERT_LIST_OFFSET(i
) + 4);
556 row2
= REG_RD(bp
, BAR_XSTRORM_INTMEM
+
557 XSTORM_ASSERT_LIST_OFFSET(i
) + 8);
558 row3
= REG_RD(bp
, BAR_XSTRORM_INTMEM
+
559 XSTORM_ASSERT_LIST_OFFSET(i
) + 12);
561 if (row0
!= COMMON_ASM_INVALID_ASSERT_OPCODE
) {
562 BNX2X_ERR("XSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
563 i
, row3
, row2
, row1
, row0
);
571 last_idx
= REG_RD8(bp
, BAR_TSTRORM_INTMEM
+
572 TSTORM_ASSERT_LIST_INDEX_OFFSET
);
574 BNX2X_ERR("TSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx
);
576 /* print the asserts */
577 for (i
= 0; i
< STROM_ASSERT_ARRAY_SIZE
; i
++) {
579 row0
= REG_RD(bp
, BAR_TSTRORM_INTMEM
+
580 TSTORM_ASSERT_LIST_OFFSET(i
));
581 row1
= REG_RD(bp
, BAR_TSTRORM_INTMEM
+
582 TSTORM_ASSERT_LIST_OFFSET(i
) + 4);
583 row2
= REG_RD(bp
, BAR_TSTRORM_INTMEM
+
584 TSTORM_ASSERT_LIST_OFFSET(i
) + 8);
585 row3
= REG_RD(bp
, BAR_TSTRORM_INTMEM
+
586 TSTORM_ASSERT_LIST_OFFSET(i
) + 12);
588 if (row0
!= COMMON_ASM_INVALID_ASSERT_OPCODE
) {
589 BNX2X_ERR("TSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
590 i
, row3
, row2
, row1
, row0
);
598 last_idx
= REG_RD8(bp
, BAR_CSTRORM_INTMEM
+
599 CSTORM_ASSERT_LIST_INDEX_OFFSET
);
601 BNX2X_ERR("CSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx
);
603 /* print the asserts */
604 for (i
= 0; i
< STROM_ASSERT_ARRAY_SIZE
; i
++) {
606 row0
= REG_RD(bp
, BAR_CSTRORM_INTMEM
+
607 CSTORM_ASSERT_LIST_OFFSET(i
));
608 row1
= REG_RD(bp
, BAR_CSTRORM_INTMEM
+
609 CSTORM_ASSERT_LIST_OFFSET(i
) + 4);
610 row2
= REG_RD(bp
, BAR_CSTRORM_INTMEM
+
611 CSTORM_ASSERT_LIST_OFFSET(i
) + 8);
612 row3
= REG_RD(bp
, BAR_CSTRORM_INTMEM
+
613 CSTORM_ASSERT_LIST_OFFSET(i
) + 12);
615 if (row0
!= COMMON_ASM_INVALID_ASSERT_OPCODE
) {
616 BNX2X_ERR("CSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
617 i
, row3
, row2
, row1
, row0
);
625 last_idx
= REG_RD8(bp
, BAR_USTRORM_INTMEM
+
626 USTORM_ASSERT_LIST_INDEX_OFFSET
);
628 BNX2X_ERR("USTORM_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_USTRORM_INTMEM
+
634 USTORM_ASSERT_LIST_OFFSET(i
));
635 row1
= REG_RD(bp
, BAR_USTRORM_INTMEM
+
636 USTORM_ASSERT_LIST_OFFSET(i
) + 4);
637 row2
= REG_RD(bp
, BAR_USTRORM_INTMEM
+
638 USTORM_ASSERT_LIST_OFFSET(i
) + 8);
639 row3
= REG_RD(bp
, BAR_USTRORM_INTMEM
+
640 USTORM_ASSERT_LIST_OFFSET(i
) + 12);
642 if (row0
!= COMMON_ASM_INVALID_ASSERT_OPCODE
) {
643 BNX2X_ERR("USTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
644 i
, row3
, row2
, row1
, row0
);
654 void bnx2x_fw_dump_lvl(struct bnx2x
*bp
, const char *lvl
)
660 u32 trace_shmem_base
;
662 BNX2X_ERR("NO MCP - can not dump\n");
665 netdev_printk(lvl
, bp
->dev
, "bc %d.%d.%d\n",
666 (bp
->common
.bc_ver
& 0xff0000) >> 16,
667 (bp
->common
.bc_ver
& 0xff00) >> 8,
668 (bp
->common
.bc_ver
& 0xff));
670 val
= REG_RD(bp
, MCP_REG_MCPR_CPU_PROGRAM_COUNTER
);
671 if (val
== REG_RD(bp
, MCP_REG_MCPR_CPU_PROGRAM_COUNTER
))
672 BNX2X_ERR("%s" "MCP PC at 0x%x\n", lvl
, val
);
674 if (BP_PATH(bp
) == 0)
675 trace_shmem_base
= bp
->common
.shmem_base
;
677 trace_shmem_base
= SHMEM2_RD(bp
, other_shmem_base_addr
);
678 addr
= trace_shmem_base
- 0x800;
680 /* validate TRCB signature */
681 mark
= REG_RD(bp
, addr
);
682 if (mark
!= MFW_TRACE_SIGNATURE
) {
683 BNX2X_ERR("Trace buffer signature is missing.");
687 /* read cyclic buffer pointer */
689 mark
= REG_RD(bp
, addr
);
690 mark
= (CHIP_IS_E1x(bp
) ? MCP_REG_MCPR_SCRATCH
: MCP_A_REG_MCPR_SCRATCH
)
691 + ((mark
+ 0x3) & ~0x3) - 0x08000000;
692 printk("%s" "begin fw dump (mark 0x%x)\n", lvl
, mark
);
695 for (offset
= mark
; offset
<= trace_shmem_base
; offset
+= 0x8*4) {
696 for (word
= 0; word
< 8; word
++)
697 data
[word
] = htonl(REG_RD(bp
, offset
+ 4*word
));
699 pr_cont("%s", (char *)data
);
701 for (offset
= addr
+ 4; offset
<= mark
; offset
+= 0x8*4) {
702 for (word
= 0; word
< 8; word
++)
703 data
[word
] = htonl(REG_RD(bp
, offset
+ 4*word
));
705 pr_cont("%s", (char *)data
);
707 printk("%s" "end of fw dump\n", lvl
);
710 static void bnx2x_fw_dump(struct bnx2x
*bp
)
712 bnx2x_fw_dump_lvl(bp
, KERN_ERR
);
715 void bnx2x_panic_dump(struct bnx2x
*bp
)
719 struct hc_sp_status_block_data sp_sb_data
;
720 int func
= BP_FUNC(bp
);
721 #ifdef BNX2X_STOP_ON_ERROR
722 u16 start
= 0, end
= 0;
726 bp
->stats_state
= STATS_STATE_DISABLED
;
727 bp
->eth_stats
.unrecoverable_error
++;
728 DP(BNX2X_MSG_STATS
, "stats_state - DISABLED\n");
730 BNX2X_ERR("begin crash dump -----------------\n");
734 BNX2X_ERR("def_idx(0x%x) def_att_idx(0x%x) attn_state(0x%x) spq_prod_idx(0x%x) next_stats_cnt(0x%x)\n",
735 bp
->def_idx
, bp
->def_att_idx
, bp
->attn_state
,
736 bp
->spq_prod_idx
, bp
->stats_counter
);
737 BNX2X_ERR("DSB: attn bits(0x%x) ack(0x%x) id(0x%x) idx(0x%x)\n",
738 bp
->def_status_blk
->atten_status_block
.attn_bits
,
739 bp
->def_status_blk
->atten_status_block
.attn_bits_ack
,
740 bp
->def_status_blk
->atten_status_block
.status_block_id
,
741 bp
->def_status_blk
->atten_status_block
.attn_bits_index
);
743 for (i
= 0; i
< HC_SP_SB_MAX_INDICES
; i
++)
745 bp
->def_status_blk
->sp_sb
.index_values
[i
],
746 (i
== HC_SP_SB_MAX_INDICES
- 1) ? ") " : " ");
748 for (i
= 0; i
< sizeof(struct hc_sp_status_block_data
)/sizeof(u32
); i
++)
749 *((u32
*)&sp_sb_data
+ i
) = REG_RD(bp
, BAR_CSTRORM_INTMEM
+
750 CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func
) +
753 pr_cont("igu_sb_id(0x%x) igu_seg_id(0x%x) pf_id(0x%x) vnic_id(0x%x) vf_id(0x%x) vf_valid (0x%x) state(0x%x)\n",
754 sp_sb_data
.igu_sb_id
,
755 sp_sb_data
.igu_seg_id
,
756 sp_sb_data
.p_func
.pf_id
,
757 sp_sb_data
.p_func
.vnic_id
,
758 sp_sb_data
.p_func
.vf_id
,
759 sp_sb_data
.p_func
.vf_valid
,
763 for_each_eth_queue(bp
, i
) {
764 struct bnx2x_fastpath
*fp
= &bp
->fp
[i
];
766 struct hc_status_block_data_e2 sb_data_e2
;
767 struct hc_status_block_data_e1x sb_data_e1x
;
768 struct hc_status_block_sm
*hc_sm_p
=
770 sb_data_e1x
.common
.state_machine
:
771 sb_data_e2
.common
.state_machine
;
772 struct hc_index_data
*hc_index_p
=
774 sb_data_e1x
.index_data
:
775 sb_data_e2
.index_data
;
778 struct bnx2x_fp_txdata txdata
;
781 BNX2X_ERR("fp%d: rx_bd_prod(0x%x) rx_bd_cons(0x%x) rx_comp_prod(0x%x) rx_comp_cons(0x%x) *rx_cons_sb(0x%x)\n",
782 i
, fp
->rx_bd_prod
, fp
->rx_bd_cons
,
784 fp
->rx_comp_cons
, le16_to_cpu(*fp
->rx_cons_sb
));
785 BNX2X_ERR(" rx_sge_prod(0x%x) last_max_sge(0x%x) fp_hc_idx(0x%x)\n",
786 fp
->rx_sge_prod
, fp
->last_max_sge
,
787 le16_to_cpu(fp
->fp_hc_idx
));
790 for_each_cos_in_tx_queue(fp
, cos
)
792 txdata
= *fp
->txdata_ptr
[cos
];
793 BNX2X_ERR("fp%d: tx_pkt_prod(0x%x) tx_pkt_cons(0x%x) tx_bd_prod(0x%x) tx_bd_cons(0x%x) *tx_cons_sb(0x%x)\n",
794 i
, txdata
.tx_pkt_prod
,
795 txdata
.tx_pkt_cons
, txdata
.tx_bd_prod
,
797 le16_to_cpu(*txdata
.tx_cons_sb
));
800 loop
= CHIP_IS_E1x(bp
) ?
801 HC_SB_MAX_INDICES_E1X
: HC_SB_MAX_INDICES_E2
;
808 BNX2X_ERR(" run indexes (");
809 for (j
= 0; j
< HC_SB_MAX_SM
; j
++)
811 fp
->sb_running_index
[j
],
812 (j
== HC_SB_MAX_SM
- 1) ? ")" : " ");
814 BNX2X_ERR(" indexes (");
815 for (j
= 0; j
< loop
; j
++)
817 fp
->sb_index_values
[j
],
818 (j
== loop
- 1) ? ")" : " ");
820 data_size
= CHIP_IS_E1x(bp
) ?
821 sizeof(struct hc_status_block_data_e1x
) :
822 sizeof(struct hc_status_block_data_e2
);
823 data_size
/= sizeof(u32
);
824 sb_data_p
= CHIP_IS_E1x(bp
) ?
825 (u32
*)&sb_data_e1x
:
827 /* copy sb data in here */
828 for (j
= 0; j
< data_size
; j
++)
829 *(sb_data_p
+ j
) = REG_RD(bp
, BAR_CSTRORM_INTMEM
+
830 CSTORM_STATUS_BLOCK_DATA_OFFSET(fp
->fw_sb_id
) +
833 if (!CHIP_IS_E1x(bp
)) {
834 pr_cont("pf_id(0x%x) vf_id(0x%x) vf_valid(0x%x) vnic_id(0x%x) same_igu_sb_1b(0x%x) state(0x%x)\n",
835 sb_data_e2
.common
.p_func
.pf_id
,
836 sb_data_e2
.common
.p_func
.vf_id
,
837 sb_data_e2
.common
.p_func
.vf_valid
,
838 sb_data_e2
.common
.p_func
.vnic_id
,
839 sb_data_e2
.common
.same_igu_sb_1b
,
840 sb_data_e2
.common
.state
);
842 pr_cont("pf_id(0x%x) vf_id(0x%x) vf_valid(0x%x) vnic_id(0x%x) same_igu_sb_1b(0x%x) state(0x%x)\n",
843 sb_data_e1x
.common
.p_func
.pf_id
,
844 sb_data_e1x
.common
.p_func
.vf_id
,
845 sb_data_e1x
.common
.p_func
.vf_valid
,
846 sb_data_e1x
.common
.p_func
.vnic_id
,
847 sb_data_e1x
.common
.same_igu_sb_1b
,
848 sb_data_e1x
.common
.state
);
852 for (j
= 0; j
< HC_SB_MAX_SM
; j
++) {
853 pr_cont("SM[%d] __flags (0x%x) igu_sb_id (0x%x) igu_seg_id(0x%x) time_to_expire (0x%x) timer_value(0x%x)\n",
854 j
, hc_sm_p
[j
].__flags
,
855 hc_sm_p
[j
].igu_sb_id
,
856 hc_sm_p
[j
].igu_seg_id
,
857 hc_sm_p
[j
].time_to_expire
,
858 hc_sm_p
[j
].timer_value
);
862 for (j
= 0; j
< loop
; j
++) {
863 pr_cont("INDEX[%d] flags (0x%x) timeout (0x%x)\n", j
,
865 hc_index_p
[j
].timeout
);
869 #ifdef BNX2X_STOP_ON_ERROR
872 for_each_valid_rx_queue(bp
, i
) {
873 struct bnx2x_fastpath
*fp
= &bp
->fp
[i
];
875 start
= RX_BD(le16_to_cpu(*fp
->rx_cons_sb
) - 10);
876 end
= RX_BD(le16_to_cpu(*fp
->rx_cons_sb
) + 503);
877 for (j
= start
; j
!= end
; j
= RX_BD(j
+ 1)) {
878 u32
*rx_bd
= (u32
*)&fp
->rx_desc_ring
[j
];
879 struct sw_rx_bd
*sw_bd
= &fp
->rx_buf_ring
[j
];
881 BNX2X_ERR("fp%d: rx_bd[%x]=[%x:%x] sw_bd=[%p]\n",
882 i
, j
, rx_bd
[1], rx_bd
[0], sw_bd
->data
);
885 start
= RX_SGE(fp
->rx_sge_prod
);
886 end
= RX_SGE(fp
->last_max_sge
);
887 for (j
= start
; j
!= end
; j
= RX_SGE(j
+ 1)) {
888 u32
*rx_sge
= (u32
*)&fp
->rx_sge_ring
[j
];
889 struct sw_rx_page
*sw_page
= &fp
->rx_page_ring
[j
];
891 BNX2X_ERR("fp%d: rx_sge[%x]=[%x:%x] sw_page=[%p]\n",
892 i
, j
, rx_sge
[1], rx_sge
[0], sw_page
->page
);
895 start
= RCQ_BD(fp
->rx_comp_cons
- 10);
896 end
= RCQ_BD(fp
->rx_comp_cons
+ 503);
897 for (j
= start
; j
!= end
; j
= RCQ_BD(j
+ 1)) {
898 u32
*cqe
= (u32
*)&fp
->rx_comp_ring
[j
];
900 BNX2X_ERR("fp%d: cqe[%x]=[%x:%x:%x:%x]\n",
901 i
, j
, cqe
[0], cqe
[1], cqe
[2], cqe
[3]);
906 for_each_valid_tx_queue(bp
, i
) {
907 struct bnx2x_fastpath
*fp
= &bp
->fp
[i
];
908 for_each_cos_in_tx_queue(fp
, cos
) {
909 struct bnx2x_fp_txdata
*txdata
= fp
->txdata_ptr
[cos
];
911 start
= TX_BD(le16_to_cpu(*txdata
->tx_cons_sb
) - 10);
912 end
= TX_BD(le16_to_cpu(*txdata
->tx_cons_sb
) + 245);
913 for (j
= start
; j
!= end
; j
= TX_BD(j
+ 1)) {
914 struct sw_tx_bd
*sw_bd
=
915 &txdata
->tx_buf_ring
[j
];
917 BNX2X_ERR("fp%d: txdata %d, packet[%x]=[%p,%x]\n",
918 i
, cos
, j
, sw_bd
->skb
,
922 start
= TX_BD(txdata
->tx_bd_cons
- 10);
923 end
= TX_BD(txdata
->tx_bd_cons
+ 254);
924 for (j
= start
; j
!= end
; j
= TX_BD(j
+ 1)) {
925 u32
*tx_bd
= (u32
*)&txdata
->tx_desc_ring
[j
];
927 BNX2X_ERR("fp%d: txdata %d, tx_bd[%x]=[%x:%x:%x:%x]\n",
928 i
, cos
, j
, tx_bd
[0], tx_bd
[1],
936 BNX2X_ERR("end crash dump -----------------\n");
942 * bnx2x_pf_flr_clnup() is called during nic_load in the per function HW
945 #define FLR_WAIT_USEC 10000 /* 10 miliseconds */
946 #define FLR_WAIT_INTERVAL 50 /* usec */
947 #define FLR_POLL_CNT (FLR_WAIT_USEC/FLR_WAIT_INTERVAL) /* 200 */
949 struct pbf_pN_buf_regs
{
956 struct pbf_pN_cmd_regs
{
962 static void bnx2x_pbf_pN_buf_flushed(struct bnx2x
*bp
,
963 struct pbf_pN_buf_regs
*regs
,
966 u32 init_crd
, crd
, crd_start
, crd_freed
, crd_freed_start
;
967 u32 cur_cnt
= poll_count
;
969 crd_freed
= crd_freed_start
= REG_RD(bp
, regs
->crd_freed
);
970 crd
= crd_start
= REG_RD(bp
, regs
->crd
);
971 init_crd
= REG_RD(bp
, regs
->init_crd
);
973 DP(BNX2X_MSG_SP
, "INIT CREDIT[%d] : %x\n", regs
->pN
, init_crd
);
974 DP(BNX2X_MSG_SP
, "CREDIT[%d] : s:%x\n", regs
->pN
, crd
);
975 DP(BNX2X_MSG_SP
, "CREDIT_FREED[%d]: s:%x\n", regs
->pN
, crd_freed
);
977 while ((crd
!= init_crd
) && ((u32
)SUB_S32(crd_freed
, crd_freed_start
) <
978 (init_crd
- crd_start
))) {
980 udelay(FLR_WAIT_INTERVAL
);
981 crd
= REG_RD(bp
, regs
->crd
);
982 crd_freed
= REG_RD(bp
, regs
->crd_freed
);
984 DP(BNX2X_MSG_SP
, "PBF tx buffer[%d] timed out\n",
986 DP(BNX2X_MSG_SP
, "CREDIT[%d] : c:%x\n",
988 DP(BNX2X_MSG_SP
, "CREDIT_FREED[%d]: c:%x\n",
989 regs
->pN
, crd_freed
);
993 DP(BNX2X_MSG_SP
, "Waited %d*%d usec for PBF tx buffer[%d]\n",
994 poll_count
-cur_cnt
, FLR_WAIT_INTERVAL
, regs
->pN
);
997 static void bnx2x_pbf_pN_cmd_flushed(struct bnx2x
*bp
,
998 struct pbf_pN_cmd_regs
*regs
,
1001 u32 occup
, to_free
, freed
, freed_start
;
1002 u32 cur_cnt
= poll_count
;
1004 occup
= to_free
= REG_RD(bp
, regs
->lines_occup
);
1005 freed
= freed_start
= REG_RD(bp
, regs
->lines_freed
);
1007 DP(BNX2X_MSG_SP
, "OCCUPANCY[%d] : s:%x\n", regs
->pN
, occup
);
1008 DP(BNX2X_MSG_SP
, "LINES_FREED[%d] : s:%x\n", regs
->pN
, freed
);
1010 while (occup
&& ((u32
)SUB_S32(freed
, freed_start
) < to_free
)) {
1012 udelay(FLR_WAIT_INTERVAL
);
1013 occup
= REG_RD(bp
, regs
->lines_occup
);
1014 freed
= REG_RD(bp
, regs
->lines_freed
);
1016 DP(BNX2X_MSG_SP
, "PBF cmd queue[%d] timed out\n",
1018 DP(BNX2X_MSG_SP
, "OCCUPANCY[%d] : s:%x\n",
1020 DP(BNX2X_MSG_SP
, "LINES_FREED[%d] : s:%x\n",
1025 DP(BNX2X_MSG_SP
, "Waited %d*%d usec for PBF cmd queue[%d]\n",
1026 poll_count
-cur_cnt
, FLR_WAIT_INTERVAL
, regs
->pN
);
1029 static u32
bnx2x_flr_clnup_reg_poll(struct bnx2x
*bp
, u32 reg
,
1030 u32 expected
, u32 poll_count
)
1032 u32 cur_cnt
= poll_count
;
1035 while ((val
= REG_RD(bp
, reg
)) != expected
&& cur_cnt
--)
1036 udelay(FLR_WAIT_INTERVAL
);
1041 static int bnx2x_flr_clnup_poll_hw_counter(struct bnx2x
*bp
, u32 reg
,
1042 char *msg
, u32 poll_cnt
)
1044 u32 val
= bnx2x_flr_clnup_reg_poll(bp
, reg
, 0, poll_cnt
);
1046 BNX2X_ERR("%s usage count=%d\n", msg
, val
);
1052 static u32
bnx2x_flr_clnup_poll_count(struct bnx2x
*bp
)
1054 /* adjust polling timeout */
1055 if (CHIP_REV_IS_EMUL(bp
))
1056 return FLR_POLL_CNT
* 2000;
1058 if (CHIP_REV_IS_FPGA(bp
))
1059 return FLR_POLL_CNT
* 120;
1061 return FLR_POLL_CNT
;
1064 static void bnx2x_tx_hw_flushed(struct bnx2x
*bp
, u32 poll_count
)
1066 struct pbf_pN_cmd_regs cmd_regs
[] = {
1067 {0, (CHIP_IS_E3B0(bp
)) ?
1068 PBF_REG_TQ_OCCUPANCY_Q0
:
1069 PBF_REG_P0_TQ_OCCUPANCY
,
1070 (CHIP_IS_E3B0(bp
)) ?
1071 PBF_REG_TQ_LINES_FREED_CNT_Q0
:
1072 PBF_REG_P0_TQ_LINES_FREED_CNT
},
1073 {1, (CHIP_IS_E3B0(bp
)) ?
1074 PBF_REG_TQ_OCCUPANCY_Q1
:
1075 PBF_REG_P1_TQ_OCCUPANCY
,
1076 (CHIP_IS_E3B0(bp
)) ?
1077 PBF_REG_TQ_LINES_FREED_CNT_Q1
:
1078 PBF_REG_P1_TQ_LINES_FREED_CNT
},
1079 {4, (CHIP_IS_E3B0(bp
)) ?
1080 PBF_REG_TQ_OCCUPANCY_LB_Q
:
1081 PBF_REG_P4_TQ_OCCUPANCY
,
1082 (CHIP_IS_E3B0(bp
)) ?
1083 PBF_REG_TQ_LINES_FREED_CNT_LB_Q
:
1084 PBF_REG_P4_TQ_LINES_FREED_CNT
}
1087 struct pbf_pN_buf_regs buf_regs
[] = {
1088 {0, (CHIP_IS_E3B0(bp
)) ?
1089 PBF_REG_INIT_CRD_Q0
:
1090 PBF_REG_P0_INIT_CRD
,
1091 (CHIP_IS_E3B0(bp
)) ?
1094 (CHIP_IS_E3B0(bp
)) ?
1095 PBF_REG_INTERNAL_CRD_FREED_CNT_Q0
:
1096 PBF_REG_P0_INTERNAL_CRD_FREED_CNT
},
1097 {1, (CHIP_IS_E3B0(bp
)) ?
1098 PBF_REG_INIT_CRD_Q1
:
1099 PBF_REG_P1_INIT_CRD
,
1100 (CHIP_IS_E3B0(bp
)) ?
1103 (CHIP_IS_E3B0(bp
)) ?
1104 PBF_REG_INTERNAL_CRD_FREED_CNT_Q1
:
1105 PBF_REG_P1_INTERNAL_CRD_FREED_CNT
},
1106 {4, (CHIP_IS_E3B0(bp
)) ?
1107 PBF_REG_INIT_CRD_LB_Q
:
1108 PBF_REG_P4_INIT_CRD
,
1109 (CHIP_IS_E3B0(bp
)) ?
1110 PBF_REG_CREDIT_LB_Q
:
1112 (CHIP_IS_E3B0(bp
)) ?
1113 PBF_REG_INTERNAL_CRD_FREED_CNT_LB_Q
:
1114 PBF_REG_P4_INTERNAL_CRD_FREED_CNT
},
1119 /* Verify the command queues are flushed P0, P1, P4 */
1120 for (i
= 0; i
< ARRAY_SIZE(cmd_regs
); i
++)
1121 bnx2x_pbf_pN_cmd_flushed(bp
, &cmd_regs
[i
], poll_count
);
1124 /* Verify the transmission buffers are flushed P0, P1, P4 */
1125 for (i
= 0; i
< ARRAY_SIZE(buf_regs
); i
++)
1126 bnx2x_pbf_pN_buf_flushed(bp
, &buf_regs
[i
], poll_count
);
1129 #define OP_GEN_PARAM(param) \
1130 (((param) << SDM_OP_GEN_COMP_PARAM_SHIFT) & SDM_OP_GEN_COMP_PARAM)
1132 #define OP_GEN_TYPE(type) \
1133 (((type) << SDM_OP_GEN_COMP_TYPE_SHIFT) & SDM_OP_GEN_COMP_TYPE)
1135 #define OP_GEN_AGG_VECT(index) \
1136 (((index) << SDM_OP_GEN_AGG_VECT_IDX_SHIFT) & SDM_OP_GEN_AGG_VECT_IDX)
1139 static int bnx2x_send_final_clnup(struct bnx2x
*bp
, u8 clnup_func
,
1142 struct sdm_op_gen op_gen
= {0};
1144 u32 comp_addr
= BAR_CSTRORM_INTMEM
+
1145 CSTORM_FINAL_CLEANUP_COMPLETE_OFFSET(clnup_func
);
1148 if (REG_RD(bp
, comp_addr
)) {
1149 BNX2X_ERR("Cleanup complete was not 0 before sending\n");
1153 op_gen
.command
|= OP_GEN_PARAM(XSTORM_AGG_INT_FINAL_CLEANUP_INDEX
);
1154 op_gen
.command
|= OP_GEN_TYPE(XSTORM_AGG_INT_FINAL_CLEANUP_COMP_TYPE
);
1155 op_gen
.command
|= OP_GEN_AGG_VECT(clnup_func
);
1156 op_gen
.command
|= 1 << SDM_OP_GEN_AGG_VECT_IDX_VALID_SHIFT
;
1158 DP(BNX2X_MSG_SP
, "sending FW Final cleanup\n");
1159 REG_WR(bp
, XSDM_REG_OPERATION_GEN
, op_gen
.command
);
1161 if (bnx2x_flr_clnup_reg_poll(bp
, comp_addr
, 1, poll_cnt
) != 1) {
1162 BNX2X_ERR("FW final cleanup did not succeed\n");
1163 DP(BNX2X_MSG_SP
, "At timeout completion address contained %x\n",
1164 (REG_RD(bp
, comp_addr
)));
1167 /* Zero completion for nxt FLR */
1168 REG_WR(bp
, comp_addr
, 0);
1173 static u8
bnx2x_is_pcie_pending(struct pci_dev
*dev
)
1177 pcie_capability_read_word(dev
, PCI_EXP_DEVSTA
, &status
);
1178 return status
& PCI_EXP_DEVSTA_TRPND
;
1181 /* PF FLR specific routines
1183 static int bnx2x_poll_hw_usage_counters(struct bnx2x
*bp
, u32 poll_cnt
)
1186 /* wait for CFC PF usage-counter to zero (includes all the VFs) */
1187 if (bnx2x_flr_clnup_poll_hw_counter(bp
,
1188 CFC_REG_NUM_LCIDS_INSIDE_PF
,
1189 "CFC PF usage counter timed out",
1194 /* Wait for DQ PF usage-counter to zero (until DQ cleanup) */
1195 if (bnx2x_flr_clnup_poll_hw_counter(bp
,
1196 DORQ_REG_PF_USAGE_CNT
,
1197 "DQ PF usage counter timed out",
1201 /* Wait for QM PF usage-counter to zero (until DQ cleanup) */
1202 if (bnx2x_flr_clnup_poll_hw_counter(bp
,
1203 QM_REG_PF_USG_CNT_0
+ 4*BP_FUNC(bp
),
1204 "QM PF usage counter timed out",
1208 /* Wait for Timer PF usage-counters to zero (until DQ cleanup) */
1209 if (bnx2x_flr_clnup_poll_hw_counter(bp
,
1210 TM_REG_LIN0_VNIC_UC
+ 4*BP_PORT(bp
),
1211 "Timers VNIC usage counter timed out",
1214 if (bnx2x_flr_clnup_poll_hw_counter(bp
,
1215 TM_REG_LIN0_NUM_SCANS
+ 4*BP_PORT(bp
),
1216 "Timers NUM_SCANS usage counter timed out",
1220 /* Wait DMAE PF usage counter to zero */
1221 if (bnx2x_flr_clnup_poll_hw_counter(bp
,
1222 dmae_reg_go_c
[INIT_DMAE_C(bp
)],
1223 "DMAE dommand register timed out",
1230 static void bnx2x_hw_enable_status(struct bnx2x
*bp
)
1234 val
= REG_RD(bp
, CFC_REG_WEAK_ENABLE_PF
);
1235 DP(BNX2X_MSG_SP
, "CFC_REG_WEAK_ENABLE_PF is 0x%x\n", val
);
1237 val
= REG_RD(bp
, PBF_REG_DISABLE_PF
);
1238 DP(BNX2X_MSG_SP
, "PBF_REG_DISABLE_PF is 0x%x\n", val
);
1240 val
= REG_RD(bp
, IGU_REG_PCI_PF_MSI_EN
);
1241 DP(BNX2X_MSG_SP
, "IGU_REG_PCI_PF_MSI_EN is 0x%x\n", val
);
1243 val
= REG_RD(bp
, IGU_REG_PCI_PF_MSIX_EN
);
1244 DP(BNX2X_MSG_SP
, "IGU_REG_PCI_PF_MSIX_EN is 0x%x\n", val
);
1246 val
= REG_RD(bp
, IGU_REG_PCI_PF_MSIX_FUNC_MASK
);
1247 DP(BNX2X_MSG_SP
, "IGU_REG_PCI_PF_MSIX_FUNC_MASK is 0x%x\n", val
);
1249 val
= REG_RD(bp
, PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR
);
1250 DP(BNX2X_MSG_SP
, "PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR is 0x%x\n", val
);
1252 val
= REG_RD(bp
, PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR
);
1253 DP(BNX2X_MSG_SP
, "PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR is 0x%x\n", val
);
1255 val
= REG_RD(bp
, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER
);
1256 DP(BNX2X_MSG_SP
, "PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER is 0x%x\n",
1260 static int bnx2x_pf_flr_clnup(struct bnx2x
*bp
)
1262 u32 poll_cnt
= bnx2x_flr_clnup_poll_count(bp
);
1264 DP(BNX2X_MSG_SP
, "Cleanup after FLR PF[%d]\n", BP_ABS_FUNC(bp
));
1266 /* Re-enable PF target read access */
1267 REG_WR(bp
, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ
, 1);
1269 /* Poll HW usage counters */
1270 DP(BNX2X_MSG_SP
, "Polling usage counters\n");
1271 if (bnx2x_poll_hw_usage_counters(bp
, poll_cnt
))
1274 /* Zero the igu 'trailing edge' and 'leading edge' */
1276 /* Send the FW cleanup command */
1277 if (bnx2x_send_final_clnup(bp
, (u8
)BP_FUNC(bp
), poll_cnt
))
1282 /* Verify TX hw is flushed */
1283 bnx2x_tx_hw_flushed(bp
, poll_cnt
);
1285 /* Wait 100ms (not adjusted according to platform) */
1288 /* Verify no pending pci transactions */
1289 if (bnx2x_is_pcie_pending(bp
->pdev
))
1290 BNX2X_ERR("PCIE Transactions still pending\n");
1293 bnx2x_hw_enable_status(bp
);
1296 * Master enable - Due to WB DMAE writes performed before this
1297 * register is re-initialized as part of the regular function init
1299 REG_WR(bp
, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER
, 1);
1304 static void bnx2x_hc_int_enable(struct bnx2x
*bp
)
1306 int port
= BP_PORT(bp
);
1307 u32 addr
= port
? HC_REG_CONFIG_1
: HC_REG_CONFIG_0
;
1308 u32 val
= REG_RD(bp
, addr
);
1309 bool msix
= (bp
->flags
& USING_MSIX_FLAG
) ? true : false;
1310 bool single_msix
= (bp
->flags
& USING_SINGLE_MSIX_FLAG
) ? true : false;
1311 bool msi
= (bp
->flags
& USING_MSI_FLAG
) ? true : false;
1314 val
&= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0
|
1315 HC_CONFIG_0_REG_INT_LINE_EN_0
);
1316 val
|= (HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0
|
1317 HC_CONFIG_0_REG_ATTN_BIT_EN_0
);
1319 val
|= HC_CONFIG_0_REG_SINGLE_ISR_EN_0
;
1321 val
&= ~HC_CONFIG_0_REG_INT_LINE_EN_0
;
1322 val
|= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0
|
1323 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0
|
1324 HC_CONFIG_0_REG_ATTN_BIT_EN_0
);
1326 val
|= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0
|
1327 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0
|
1328 HC_CONFIG_0_REG_INT_LINE_EN_0
|
1329 HC_CONFIG_0_REG_ATTN_BIT_EN_0
);
1331 if (!CHIP_IS_E1(bp
)) {
1333 "write %x to HC %d (addr 0x%x)\n", val
, port
, addr
);
1335 REG_WR(bp
, addr
, val
);
1337 val
&= ~HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0
;
1342 REG_WR(bp
, HC_REG_INT_MASK
+ port
*4, 0x1FFFF);
1345 "write %x to HC %d (addr 0x%x) mode %s\n", val
, port
, addr
,
1346 (msix
? "MSI-X" : (msi
? "MSI" : "INTx")));
1348 REG_WR(bp
, addr
, val
);
1350 * Ensure that HC_CONFIG is written before leading/trailing edge config
1355 if (!CHIP_IS_E1(bp
)) {
1356 /* init leading/trailing edge */
1358 val
= (0xee0f | (1 << (BP_VN(bp
) + 4)));
1360 /* enable nig and gpio3 attention */
1365 REG_WR(bp
, HC_REG_TRAILING_EDGE_0
+ port
*8, val
);
1366 REG_WR(bp
, HC_REG_LEADING_EDGE_0
+ port
*8, val
);
1369 /* Make sure that interrupts are indeed enabled from here on */
1373 static void bnx2x_igu_int_enable(struct bnx2x
*bp
)
1376 bool msix
= (bp
->flags
& USING_MSIX_FLAG
) ? true : false;
1377 bool single_msix
= (bp
->flags
& USING_SINGLE_MSIX_FLAG
) ? true : false;
1378 bool msi
= (bp
->flags
& USING_MSI_FLAG
) ? true : false;
1380 val
= REG_RD(bp
, IGU_REG_PF_CONFIGURATION
);
1383 val
&= ~(IGU_PF_CONF_INT_LINE_EN
|
1384 IGU_PF_CONF_SINGLE_ISR_EN
);
1385 val
|= (IGU_PF_CONF_FUNC_EN
|
1386 IGU_PF_CONF_MSI_MSIX_EN
|
1387 IGU_PF_CONF_ATTN_BIT_EN
);
1390 val
|= IGU_PF_CONF_SINGLE_ISR_EN
;
1392 val
&= ~IGU_PF_CONF_INT_LINE_EN
;
1393 val
|= (IGU_PF_CONF_FUNC_EN
|
1394 IGU_PF_CONF_MSI_MSIX_EN
|
1395 IGU_PF_CONF_ATTN_BIT_EN
|
1396 IGU_PF_CONF_SINGLE_ISR_EN
);
1398 val
&= ~IGU_PF_CONF_MSI_MSIX_EN
;
1399 val
|= (IGU_PF_CONF_FUNC_EN
|
1400 IGU_PF_CONF_INT_LINE_EN
|
1401 IGU_PF_CONF_ATTN_BIT_EN
|
1402 IGU_PF_CONF_SINGLE_ISR_EN
);
1405 DP(NETIF_MSG_IFUP
, "write 0x%x to IGU mode %s\n",
1406 val
, (msix
? "MSI-X" : (msi
? "MSI" : "INTx")));
1408 REG_WR(bp
, IGU_REG_PF_CONFIGURATION
, val
);
1410 if (val
& IGU_PF_CONF_INT_LINE_EN
)
1411 pci_intx(bp
->pdev
, true);
1415 /* init leading/trailing edge */
1417 val
= (0xee0f | (1 << (BP_VN(bp
) + 4)));
1419 /* enable nig and gpio3 attention */
1424 REG_WR(bp
, IGU_REG_TRAILING_EDGE_LATCH
, val
);
1425 REG_WR(bp
, IGU_REG_LEADING_EDGE_LATCH
, val
);
1427 /* Make sure that interrupts are indeed enabled from here on */
1431 void bnx2x_int_enable(struct bnx2x
*bp
)
1433 if (bp
->common
.int_block
== INT_BLOCK_HC
)
1434 bnx2x_hc_int_enable(bp
);
1436 bnx2x_igu_int_enable(bp
);
1439 static void bnx2x_hc_int_disable(struct bnx2x
*bp
)
1441 int port
= BP_PORT(bp
);
1442 u32 addr
= port
? HC_REG_CONFIG_1
: HC_REG_CONFIG_0
;
1443 u32 val
= REG_RD(bp
, addr
);
1446 * in E1 we must use only PCI configuration space to disable
1447 * MSI/MSIX capablility
1448 * It's forbitten to disable IGU_PF_CONF_MSI_MSIX_EN in HC block
1450 if (CHIP_IS_E1(bp
)) {
1451 /* Since IGU_PF_CONF_MSI_MSIX_EN still always on
1452 * Use mask register to prevent from HC sending interrupts
1453 * after we exit the function
1455 REG_WR(bp
, HC_REG_INT_MASK
+ port
*4, 0);
1457 val
&= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0
|
1458 HC_CONFIG_0_REG_INT_LINE_EN_0
|
1459 HC_CONFIG_0_REG_ATTN_BIT_EN_0
);
1461 val
&= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0
|
1462 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0
|
1463 HC_CONFIG_0_REG_INT_LINE_EN_0
|
1464 HC_CONFIG_0_REG_ATTN_BIT_EN_0
);
1466 DP(NETIF_MSG_IFDOWN
,
1467 "write %x to HC %d (addr 0x%x)\n",
1470 /* flush all outstanding writes */
1473 REG_WR(bp
, addr
, val
);
1474 if (REG_RD(bp
, addr
) != val
)
1475 BNX2X_ERR("BUG! proper val not read from IGU!\n");
1478 static void bnx2x_igu_int_disable(struct bnx2x
*bp
)
1480 u32 val
= REG_RD(bp
, IGU_REG_PF_CONFIGURATION
);
1482 val
&= ~(IGU_PF_CONF_MSI_MSIX_EN
|
1483 IGU_PF_CONF_INT_LINE_EN
|
1484 IGU_PF_CONF_ATTN_BIT_EN
);
1486 DP(NETIF_MSG_IFDOWN
, "write %x to IGU\n", val
);
1488 /* flush all outstanding writes */
1491 REG_WR(bp
, IGU_REG_PF_CONFIGURATION
, val
);
1492 if (REG_RD(bp
, IGU_REG_PF_CONFIGURATION
) != val
)
1493 BNX2X_ERR("BUG! proper val not read from IGU!\n");
1496 static void bnx2x_int_disable(struct bnx2x
*bp
)
1498 if (bp
->common
.int_block
== INT_BLOCK_HC
)
1499 bnx2x_hc_int_disable(bp
);
1501 bnx2x_igu_int_disable(bp
);
1504 void bnx2x_int_disable_sync(struct bnx2x
*bp
, int disable_hw
)
1506 int msix
= (bp
->flags
& USING_MSIX_FLAG
) ? 1 : 0;
1510 /* prevent the HW from sending interrupts */
1511 bnx2x_int_disable(bp
);
1513 /* make sure all ISRs are done */
1515 synchronize_irq(bp
->msix_table
[0].vector
);
1517 if (CNIC_SUPPORT(bp
))
1519 for_each_eth_queue(bp
, i
)
1520 synchronize_irq(bp
->msix_table
[offset
++].vector
);
1522 synchronize_irq(bp
->pdev
->irq
);
1524 /* make sure sp_task is not running */
1525 cancel_delayed_work(&bp
->sp_task
);
1526 cancel_delayed_work(&bp
->period_task
);
1527 flush_workqueue(bnx2x_wq
);
1533 * General service functions
1536 /* Return true if succeeded to acquire the lock */
1537 static bool bnx2x_trylock_hw_lock(struct bnx2x
*bp
, u32 resource
)
1540 u32 resource_bit
= (1 << resource
);
1541 int func
= BP_FUNC(bp
);
1542 u32 hw_lock_control_reg
;
1544 DP(NETIF_MSG_HW
| NETIF_MSG_IFUP
,
1545 "Trying to take a lock on resource %d\n", resource
);
1547 /* Validating that the resource is within range */
1548 if (resource
> HW_LOCK_MAX_RESOURCE_VALUE
) {
1549 DP(NETIF_MSG_HW
| NETIF_MSG_IFUP
,
1550 "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
1551 resource
, HW_LOCK_MAX_RESOURCE_VALUE
);
1556 hw_lock_control_reg
= (MISC_REG_DRIVER_CONTROL_1
+ func
*8);
1558 hw_lock_control_reg
=
1559 (MISC_REG_DRIVER_CONTROL_7
+ (func
- 6)*8);
1561 /* Try to acquire the lock */
1562 REG_WR(bp
, hw_lock_control_reg
+ 4, resource_bit
);
1563 lock_status
= REG_RD(bp
, hw_lock_control_reg
);
1564 if (lock_status
& resource_bit
)
1567 DP(NETIF_MSG_HW
| NETIF_MSG_IFUP
,
1568 "Failed to get a lock on resource %d\n", resource
);
1573 * bnx2x_get_leader_lock_resource - get the recovery leader resource id
1575 * @bp: driver handle
1577 * Returns the recovery leader resource id according to the engine this function
1578 * belongs to. Currently only only 2 engines is supported.
1580 static int bnx2x_get_leader_lock_resource(struct bnx2x
*bp
)
1583 return HW_LOCK_RESOURCE_RECOVERY_LEADER_1
;
1585 return HW_LOCK_RESOURCE_RECOVERY_LEADER_0
;
1589 * bnx2x_trylock_leader_lock- try to aquire a leader lock.
1591 * @bp: driver handle
1593 * Tries to aquire a leader lock for current engine.
1595 static bool bnx2x_trylock_leader_lock(struct bnx2x
*bp
)
1597 return bnx2x_trylock_hw_lock(bp
, bnx2x_get_leader_lock_resource(bp
));
1600 static void bnx2x_cnic_cfc_comp(struct bnx2x
*bp
, int cid
, u8 err
);
1603 void bnx2x_sp_event(struct bnx2x_fastpath
*fp
, union eth_rx_cqe
*rr_cqe
)
1605 struct bnx2x
*bp
= fp
->bp
;
1606 int cid
= SW_CID(rr_cqe
->ramrod_cqe
.conn_and_cmd_data
);
1607 int command
= CQE_CMD(rr_cqe
->ramrod_cqe
.conn_and_cmd_data
);
1608 enum bnx2x_queue_cmd drv_cmd
= BNX2X_Q_CMD_MAX
;
1609 struct bnx2x_queue_sp_obj
*q_obj
= &bnx2x_sp_obj(bp
, fp
).q_obj
;
1612 "fp %d cid %d got ramrod #%d state is %x type is %d\n",
1613 fp
->index
, cid
, command
, bp
->state
,
1614 rr_cqe
->ramrod_cqe
.ramrod_type
);
1617 case (RAMROD_CMD_ID_ETH_CLIENT_UPDATE
):
1618 DP(BNX2X_MSG_SP
, "got UPDATE ramrod. CID %d\n", cid
);
1619 drv_cmd
= BNX2X_Q_CMD_UPDATE
;
1622 case (RAMROD_CMD_ID_ETH_CLIENT_SETUP
):
1623 DP(BNX2X_MSG_SP
, "got MULTI[%d] setup ramrod\n", cid
);
1624 drv_cmd
= BNX2X_Q_CMD_SETUP
;
1627 case (RAMROD_CMD_ID_ETH_TX_QUEUE_SETUP
):
1628 DP(BNX2X_MSG_SP
, "got MULTI[%d] tx-only setup ramrod\n", cid
);
1629 drv_cmd
= BNX2X_Q_CMD_SETUP_TX_ONLY
;
1632 case (RAMROD_CMD_ID_ETH_HALT
):
1633 DP(BNX2X_MSG_SP
, "got MULTI[%d] halt ramrod\n", cid
);
1634 drv_cmd
= BNX2X_Q_CMD_HALT
;
1637 case (RAMROD_CMD_ID_ETH_TERMINATE
):
1638 DP(BNX2X_MSG_SP
, "got MULTI[%d] teminate ramrod\n", cid
);
1639 drv_cmd
= BNX2X_Q_CMD_TERMINATE
;
1642 case (RAMROD_CMD_ID_ETH_EMPTY
):
1643 DP(BNX2X_MSG_SP
, "got MULTI[%d] empty ramrod\n", cid
);
1644 drv_cmd
= BNX2X_Q_CMD_EMPTY
;
1648 BNX2X_ERR("unexpected MC reply (%d) on fp[%d]\n",
1649 command
, fp
->index
);
1653 if ((drv_cmd
!= BNX2X_Q_CMD_MAX
) &&
1654 q_obj
->complete_cmd(bp
, q_obj
, drv_cmd
))
1655 /* q_obj->complete_cmd() failure means that this was
1656 * an unexpected completion.
1658 * In this case we don't want to increase the bp->spq_left
1659 * because apparently we haven't sent this command the first
1662 #ifdef BNX2X_STOP_ON_ERROR
1668 smp_mb__before_atomic_inc();
1669 atomic_inc(&bp
->cq_spq_left
);
1670 /* push the change in bp->spq_left and towards the memory */
1671 smp_mb__after_atomic_inc();
1673 DP(BNX2X_MSG_SP
, "bp->cq_spq_left %x\n", atomic_read(&bp
->cq_spq_left
));
1675 if ((drv_cmd
== BNX2X_Q_CMD_UPDATE
) && (IS_FCOE_FP(fp
)) &&
1676 (!!test_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING
, &bp
->sp_state
))) {
1677 /* if Q update ramrod is completed for last Q in AFEX vif set
1678 * flow, then ACK MCP at the end
1680 * mark pending ACK to MCP bit.
1681 * prevent case that both bits are cleared.
1682 * At the end of load/unload driver checks that
1683 * sp_state is cleaerd, and this order prevents
1686 smp_mb__before_clear_bit();
1687 set_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK
, &bp
->sp_state
);
1689 clear_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING
, &bp
->sp_state
);
1690 smp_mb__after_clear_bit();
1692 /* schedule workqueue to send ack to MCP */
1693 queue_delayed_work(bnx2x_wq
, &bp
->sp_task
, 0);
1699 void bnx2x_update_rx_prod(struct bnx2x
*bp
, struct bnx2x_fastpath
*fp
,
1700 u16 bd_prod
, u16 rx_comp_prod
, u16 rx_sge_prod
)
1702 u32 start
= BAR_USTRORM_INTMEM
+ fp
->ustorm_rx_prods_offset
;
1704 bnx2x_update_rx_prod_gen(bp
, fp
, bd_prod
, rx_comp_prod
, rx_sge_prod
,
1708 irqreturn_t
bnx2x_interrupt(int irq
, void *dev_instance
)
1710 struct bnx2x
*bp
= netdev_priv(dev_instance
);
1711 u16 status
= bnx2x_ack_int(bp
);
1716 /* Return here if interrupt is shared and it's not for us */
1717 if (unlikely(status
== 0)) {
1718 DP(NETIF_MSG_INTR
, "not our interrupt!\n");
1721 DP(NETIF_MSG_INTR
, "got an interrupt status 0x%x\n", status
);
1723 #ifdef BNX2X_STOP_ON_ERROR
1724 if (unlikely(bp
->panic
))
1728 for_each_eth_queue(bp
, i
) {
1729 struct bnx2x_fastpath
*fp
= &bp
->fp
[i
];
1731 mask
= 0x2 << (fp
->index
+ CNIC_SUPPORT(bp
));
1732 if (status
& mask
) {
1733 /* Handle Rx or Tx according to SB id */
1734 prefetch(fp
->rx_cons_sb
);
1735 for_each_cos_in_tx_queue(fp
, cos
)
1736 prefetch(fp
->txdata_ptr
[cos
]->tx_cons_sb
);
1737 prefetch(&fp
->sb_running_index
[SM_RX_ID
]);
1738 napi_schedule(&bnx2x_fp(bp
, fp
->index
, napi
));
1743 if (CNIC_SUPPORT(bp
)) {
1745 if (status
& (mask
| 0x1)) {
1746 struct cnic_ops
*c_ops
= NULL
;
1748 if (likely(bp
->state
== BNX2X_STATE_OPEN
)) {
1750 c_ops
= rcu_dereference(bp
->cnic_ops
);
1752 c_ops
->cnic_handler(bp
->cnic_data
,
1761 if (unlikely(status
& 0x1)) {
1762 queue_delayed_work(bnx2x_wq
, &bp
->sp_task
, 0);
1769 if (unlikely(status
))
1770 DP(NETIF_MSG_INTR
, "got an unknown interrupt! (status 0x%x)\n",
1779 * General service functions
1782 int bnx2x_acquire_hw_lock(struct bnx2x
*bp
, u32 resource
)
1785 u32 resource_bit
= (1 << resource
);
1786 int func
= BP_FUNC(bp
);
1787 u32 hw_lock_control_reg
;
1790 /* Validating that the resource is within range */
1791 if (resource
> HW_LOCK_MAX_RESOURCE_VALUE
) {
1792 BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
1793 resource
, HW_LOCK_MAX_RESOURCE_VALUE
);
1798 hw_lock_control_reg
= (MISC_REG_DRIVER_CONTROL_1
+ func
*8);
1800 hw_lock_control_reg
=
1801 (MISC_REG_DRIVER_CONTROL_7
+ (func
- 6)*8);
1804 /* Validating that the resource is not already taken */
1805 lock_status
= REG_RD(bp
, hw_lock_control_reg
);
1806 if (lock_status
& resource_bit
) {
1807 BNX2X_ERR("lock_status 0x%x resource_bit 0x%x\n",
1808 lock_status
, resource_bit
);
1812 /* Try for 5 second every 5ms */
1813 for (cnt
= 0; cnt
< 1000; cnt
++) {
1814 /* Try to acquire the lock */
1815 REG_WR(bp
, hw_lock_control_reg
+ 4, resource_bit
);
1816 lock_status
= REG_RD(bp
, hw_lock_control_reg
);
1817 if (lock_status
& resource_bit
)
1822 BNX2X_ERR("Timeout\n");
1826 int bnx2x_release_leader_lock(struct bnx2x
*bp
)
1828 return bnx2x_release_hw_lock(bp
, bnx2x_get_leader_lock_resource(bp
));
1831 int bnx2x_release_hw_lock(struct bnx2x
*bp
, u32 resource
)
1834 u32 resource_bit
= (1 << resource
);
1835 int func
= BP_FUNC(bp
);
1836 u32 hw_lock_control_reg
;
1838 /* Validating that the resource is within range */
1839 if (resource
> HW_LOCK_MAX_RESOURCE_VALUE
) {
1840 BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
1841 resource
, HW_LOCK_MAX_RESOURCE_VALUE
);
1846 hw_lock_control_reg
= (MISC_REG_DRIVER_CONTROL_1
+ func
*8);
1848 hw_lock_control_reg
=
1849 (MISC_REG_DRIVER_CONTROL_7
+ (func
- 6)*8);
1852 /* Validating that the resource is currently taken */
1853 lock_status
= REG_RD(bp
, hw_lock_control_reg
);
1854 if (!(lock_status
& resource_bit
)) {
1855 BNX2X_ERR("lock_status 0x%x resource_bit 0x%x. unlock was called but lock wasn't taken!\n",
1856 lock_status
, resource_bit
);
1860 REG_WR(bp
, hw_lock_control_reg
, resource_bit
);
1865 int bnx2x_get_gpio(struct bnx2x
*bp
, int gpio_num
, u8 port
)
1867 /* The GPIO should be swapped if swap register is set and active */
1868 int gpio_port
= (REG_RD(bp
, NIG_REG_PORT_SWAP
) &&
1869 REG_RD(bp
, NIG_REG_STRAP_OVERRIDE
)) ^ port
;
1870 int gpio_shift
= gpio_num
+
1871 (gpio_port
? MISC_REGISTERS_GPIO_PORT_SHIFT
: 0);
1872 u32 gpio_mask
= (1 << gpio_shift
);
1876 if (gpio_num
> MISC_REGISTERS_GPIO_3
) {
1877 BNX2X_ERR("Invalid GPIO %d\n", gpio_num
);
1881 /* read GPIO value */
1882 gpio_reg
= REG_RD(bp
, MISC_REG_GPIO
);
1884 /* get the requested pin value */
1885 if ((gpio_reg
& gpio_mask
) == gpio_mask
)
1890 DP(NETIF_MSG_LINK
, "pin %d value 0x%x\n", gpio_num
, value
);
1895 int bnx2x_set_gpio(struct bnx2x
*bp
, int gpio_num
, u32 mode
, u8 port
)
1897 /* The GPIO should be swapped if swap register is set and active */
1898 int gpio_port
= (REG_RD(bp
, NIG_REG_PORT_SWAP
) &&
1899 REG_RD(bp
, NIG_REG_STRAP_OVERRIDE
)) ^ port
;
1900 int gpio_shift
= gpio_num
+
1901 (gpio_port
? MISC_REGISTERS_GPIO_PORT_SHIFT
: 0);
1902 u32 gpio_mask
= (1 << gpio_shift
);
1905 if (gpio_num
> MISC_REGISTERS_GPIO_3
) {
1906 BNX2X_ERR("Invalid GPIO %d\n", gpio_num
);
1910 bnx2x_acquire_hw_lock(bp
, HW_LOCK_RESOURCE_GPIO
);
1911 /* read GPIO and mask except the float bits */
1912 gpio_reg
= (REG_RD(bp
, MISC_REG_GPIO
) & MISC_REGISTERS_GPIO_FLOAT
);
1915 case MISC_REGISTERS_GPIO_OUTPUT_LOW
:
1917 "Set GPIO %d (shift %d) -> output low\n",
1918 gpio_num
, gpio_shift
);
1919 /* clear FLOAT and set CLR */
1920 gpio_reg
&= ~(gpio_mask
<< MISC_REGISTERS_GPIO_FLOAT_POS
);
1921 gpio_reg
|= (gpio_mask
<< MISC_REGISTERS_GPIO_CLR_POS
);
1924 case MISC_REGISTERS_GPIO_OUTPUT_HIGH
:
1926 "Set GPIO %d (shift %d) -> output high\n",
1927 gpio_num
, gpio_shift
);
1928 /* clear FLOAT and set SET */
1929 gpio_reg
&= ~(gpio_mask
<< MISC_REGISTERS_GPIO_FLOAT_POS
);
1930 gpio_reg
|= (gpio_mask
<< MISC_REGISTERS_GPIO_SET_POS
);
1933 case MISC_REGISTERS_GPIO_INPUT_HI_Z
:
1935 "Set GPIO %d (shift %d) -> input\n",
1936 gpio_num
, gpio_shift
);
1938 gpio_reg
|= (gpio_mask
<< MISC_REGISTERS_GPIO_FLOAT_POS
);
1945 REG_WR(bp
, MISC_REG_GPIO
, gpio_reg
);
1946 bnx2x_release_hw_lock(bp
, HW_LOCK_RESOURCE_GPIO
);
1951 int bnx2x_set_mult_gpio(struct bnx2x
*bp
, u8 pins
, u32 mode
)
1956 /* Any port swapping should be handled by caller. */
1958 bnx2x_acquire_hw_lock(bp
, HW_LOCK_RESOURCE_GPIO
);
1959 /* read GPIO and mask except the float bits */
1960 gpio_reg
= REG_RD(bp
, MISC_REG_GPIO
);
1961 gpio_reg
&= ~(pins
<< MISC_REGISTERS_GPIO_FLOAT_POS
);
1962 gpio_reg
&= ~(pins
<< MISC_REGISTERS_GPIO_CLR_POS
);
1963 gpio_reg
&= ~(pins
<< MISC_REGISTERS_GPIO_SET_POS
);
1966 case MISC_REGISTERS_GPIO_OUTPUT_LOW
:
1967 DP(NETIF_MSG_LINK
, "Set GPIO 0x%x -> output low\n", pins
);
1969 gpio_reg
|= (pins
<< MISC_REGISTERS_GPIO_CLR_POS
);
1972 case MISC_REGISTERS_GPIO_OUTPUT_HIGH
:
1973 DP(NETIF_MSG_LINK
, "Set GPIO 0x%x -> output high\n", pins
);
1975 gpio_reg
|= (pins
<< MISC_REGISTERS_GPIO_SET_POS
);
1978 case MISC_REGISTERS_GPIO_INPUT_HI_Z
:
1979 DP(NETIF_MSG_LINK
, "Set GPIO 0x%x -> input\n", pins
);
1981 gpio_reg
|= (pins
<< MISC_REGISTERS_GPIO_FLOAT_POS
);
1985 BNX2X_ERR("Invalid GPIO mode assignment %d\n", mode
);
1991 REG_WR(bp
, MISC_REG_GPIO
, gpio_reg
);
1993 bnx2x_release_hw_lock(bp
, HW_LOCK_RESOURCE_GPIO
);
1998 int bnx2x_set_gpio_int(struct bnx2x
*bp
, int gpio_num
, u32 mode
, u8 port
)
2000 /* The GPIO should be swapped if swap register is set and active */
2001 int gpio_port
= (REG_RD(bp
, NIG_REG_PORT_SWAP
) &&
2002 REG_RD(bp
, NIG_REG_STRAP_OVERRIDE
)) ^ port
;
2003 int gpio_shift
= gpio_num
+
2004 (gpio_port
? MISC_REGISTERS_GPIO_PORT_SHIFT
: 0);
2005 u32 gpio_mask
= (1 << gpio_shift
);
2008 if (gpio_num
> MISC_REGISTERS_GPIO_3
) {
2009 BNX2X_ERR("Invalid GPIO %d\n", gpio_num
);
2013 bnx2x_acquire_hw_lock(bp
, HW_LOCK_RESOURCE_GPIO
);
2015 gpio_reg
= REG_RD(bp
, MISC_REG_GPIO_INT
);
2018 case MISC_REGISTERS_GPIO_INT_OUTPUT_CLR
:
2020 "Clear GPIO INT %d (shift %d) -> output low\n",
2021 gpio_num
, gpio_shift
);
2022 /* clear SET and set CLR */
2023 gpio_reg
&= ~(gpio_mask
<< MISC_REGISTERS_GPIO_INT_SET_POS
);
2024 gpio_reg
|= (gpio_mask
<< MISC_REGISTERS_GPIO_INT_CLR_POS
);
2027 case MISC_REGISTERS_GPIO_INT_OUTPUT_SET
:
2029 "Set GPIO INT %d (shift %d) -> output high\n",
2030 gpio_num
, gpio_shift
);
2031 /* clear CLR and set SET */
2032 gpio_reg
&= ~(gpio_mask
<< MISC_REGISTERS_GPIO_INT_CLR_POS
);
2033 gpio_reg
|= (gpio_mask
<< MISC_REGISTERS_GPIO_INT_SET_POS
);
2040 REG_WR(bp
, MISC_REG_GPIO_INT
, gpio_reg
);
2041 bnx2x_release_hw_lock(bp
, HW_LOCK_RESOURCE_GPIO
);
2046 static int bnx2x_set_spio(struct bnx2x
*bp
, int spio
, u32 mode
)
2050 /* Only 2 SPIOs are configurable */
2051 if ((spio
!= MISC_SPIO_SPIO4
) && (spio
!= MISC_SPIO_SPIO5
)) {
2052 BNX2X_ERR("Invalid SPIO 0x%x\n", spio
);
2056 bnx2x_acquire_hw_lock(bp
, HW_LOCK_RESOURCE_SPIO
);
2057 /* read SPIO and mask except the float bits */
2058 spio_reg
= (REG_RD(bp
, MISC_REG_SPIO
) & MISC_SPIO_FLOAT
);
2061 case MISC_SPIO_OUTPUT_LOW
:
2062 DP(NETIF_MSG_HW
, "Set SPIO 0x%x -> output low\n", spio
);
2063 /* clear FLOAT and set CLR */
2064 spio_reg
&= ~(spio
<< MISC_SPIO_FLOAT_POS
);
2065 spio_reg
|= (spio
<< MISC_SPIO_CLR_POS
);
2068 case MISC_SPIO_OUTPUT_HIGH
:
2069 DP(NETIF_MSG_HW
, "Set SPIO 0x%x -> output high\n", spio
);
2070 /* clear FLOAT and set SET */
2071 spio_reg
&= ~(spio
<< MISC_SPIO_FLOAT_POS
);
2072 spio_reg
|= (spio
<< MISC_SPIO_SET_POS
);
2075 case MISC_SPIO_INPUT_HI_Z
:
2076 DP(NETIF_MSG_HW
, "Set SPIO 0x%x -> input\n", spio
);
2078 spio_reg
|= (spio
<< MISC_SPIO_FLOAT_POS
);
2085 REG_WR(bp
, MISC_REG_SPIO
, spio_reg
);
2086 bnx2x_release_hw_lock(bp
, HW_LOCK_RESOURCE_SPIO
);
2091 void bnx2x_calc_fc_adv(struct bnx2x
*bp
)
2093 u8 cfg_idx
= bnx2x_get_link_cfg_idx(bp
);
2094 switch (bp
->link_vars
.ieee_fc
&
2095 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK
) {
2096 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE
:
2097 bp
->port
.advertising
[cfg_idx
] &= ~(ADVERTISED_Asym_Pause
|
2101 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH
:
2102 bp
->port
.advertising
[cfg_idx
] |= (ADVERTISED_Asym_Pause
|
2106 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC
:
2107 bp
->port
.advertising
[cfg_idx
] |= ADVERTISED_Asym_Pause
;
2111 bp
->port
.advertising
[cfg_idx
] &= ~(ADVERTISED_Asym_Pause
|
2117 static void bnx2x_set_requested_fc(struct bnx2x
*bp
)
2119 /* Initialize link parameters structure variables
2120 * It is recommended to turn off RX FC for jumbo frames
2121 * for better performance
2123 if (CHIP_IS_E1x(bp
) && (bp
->dev
->mtu
> 5000))
2124 bp
->link_params
.req_fc_auto_adv
= BNX2X_FLOW_CTRL_TX
;
2126 bp
->link_params
.req_fc_auto_adv
= BNX2X_FLOW_CTRL_BOTH
;
2129 int bnx2x_initial_phy_init(struct bnx2x
*bp
, int load_mode
)
2131 int rc
, cfx_idx
= bnx2x_get_link_cfg_idx(bp
);
2132 u16 req_line_speed
= bp
->link_params
.req_line_speed
[cfx_idx
];
2134 if (!BP_NOMCP(bp
)) {
2135 bnx2x_set_requested_fc(bp
);
2136 bnx2x_acquire_phy_lock(bp
);
2138 if (load_mode
== LOAD_DIAG
) {
2139 struct link_params
*lp
= &bp
->link_params
;
2140 lp
->loopback_mode
= LOOPBACK_XGXS
;
2141 /* do PHY loopback at 10G speed, if possible */
2142 if (lp
->req_line_speed
[cfx_idx
] < SPEED_10000
) {
2143 if (lp
->speed_cap_mask
[cfx_idx
] &
2144 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G
)
2145 lp
->req_line_speed
[cfx_idx
] =
2148 lp
->req_line_speed
[cfx_idx
] =
2153 if (load_mode
== LOAD_LOOPBACK_EXT
) {
2154 struct link_params
*lp
= &bp
->link_params
;
2155 lp
->loopback_mode
= LOOPBACK_EXT
;
2158 rc
= bnx2x_phy_init(&bp
->link_params
, &bp
->link_vars
);
2160 bnx2x_release_phy_lock(bp
);
2162 bnx2x_calc_fc_adv(bp
);
2164 if (bp
->link_vars
.link_up
) {
2165 bnx2x_stats_handle(bp
, STATS_EVENT_LINK_UP
);
2166 bnx2x_link_report(bp
);
2168 queue_delayed_work(bnx2x_wq
, &bp
->period_task
, 0);
2169 bp
->link_params
.req_line_speed
[cfx_idx
] = req_line_speed
;
2172 BNX2X_ERR("Bootcode is missing - can not initialize link\n");
2176 void bnx2x_link_set(struct bnx2x
*bp
)
2178 if (!BP_NOMCP(bp
)) {
2179 bnx2x_acquire_phy_lock(bp
);
2180 bnx2x_phy_init(&bp
->link_params
, &bp
->link_vars
);
2181 bnx2x_release_phy_lock(bp
);
2183 bnx2x_calc_fc_adv(bp
);
2185 BNX2X_ERR("Bootcode is missing - can not set link\n");
2188 static void bnx2x__link_reset(struct bnx2x
*bp
)
2190 if (!BP_NOMCP(bp
)) {
2191 bnx2x_acquire_phy_lock(bp
);
2192 bnx2x_lfa_reset(&bp
->link_params
, &bp
->link_vars
);
2193 bnx2x_release_phy_lock(bp
);
2195 BNX2X_ERR("Bootcode is missing - can not reset link\n");
2198 void bnx2x_force_link_reset(struct bnx2x
*bp
)
2200 bnx2x_acquire_phy_lock(bp
);
2201 bnx2x_link_reset(&bp
->link_params
, &bp
->link_vars
, 1);
2202 bnx2x_release_phy_lock(bp
);
2205 u8
bnx2x_link_test(struct bnx2x
*bp
, u8 is_serdes
)
2209 if (!BP_NOMCP(bp
)) {
2210 bnx2x_acquire_phy_lock(bp
);
2211 rc
= bnx2x_test_link(&bp
->link_params
, &bp
->link_vars
,
2213 bnx2x_release_phy_lock(bp
);
2215 BNX2X_ERR("Bootcode is missing - can not test link\n");
2221 /* Calculates the sum of vn_min_rates.
2222 It's needed for further normalizing of the min_rates.
2224 sum of vn_min_rates.
2226 0 - if all the min_rates are 0.
2227 In the later case fainess algorithm should be deactivated.
2228 If not all min_rates are zero then those that are zeroes will be set to 1.
2230 static void bnx2x_calc_vn_min(struct bnx2x
*bp
,
2231 struct cmng_init_input
*input
)
2236 for (vn
= VN_0
; vn
< BP_MAX_VN_NUM(bp
); vn
++) {
2237 u32 vn_cfg
= bp
->mf_config
[vn
];
2238 u32 vn_min_rate
= ((vn_cfg
& FUNC_MF_CFG_MIN_BW_MASK
) >>
2239 FUNC_MF_CFG_MIN_BW_SHIFT
) * 100;
2241 /* Skip hidden vns */
2242 if (vn_cfg
& FUNC_MF_CFG_FUNC_HIDE
)
2244 /* If min rate is zero - set it to 1 */
2245 else if (!vn_min_rate
)
2246 vn_min_rate
= DEF_MIN_RATE
;
2250 input
->vnic_min_rate
[vn
] = vn_min_rate
;
2253 /* if ETS or all min rates are zeros - disable fairness */
2254 if (BNX2X_IS_ETS_ENABLED(bp
)) {
2255 input
->flags
.cmng_enables
&=
2256 ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN
;
2257 DP(NETIF_MSG_IFUP
, "Fairness will be disabled due to ETS\n");
2258 } else if (all_zero
) {
2259 input
->flags
.cmng_enables
&=
2260 ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN
;
2262 "All MIN values are zeroes fairness will be disabled\n");
2264 input
->flags
.cmng_enables
|=
2265 CMNG_FLAGS_PER_PORT_FAIRNESS_VN
;
2268 static void bnx2x_calc_vn_max(struct bnx2x
*bp
, int vn
,
2269 struct cmng_init_input
*input
)
2272 u32 vn_cfg
= bp
->mf_config
[vn
];
2274 if (vn_cfg
& FUNC_MF_CFG_FUNC_HIDE
)
2277 u32 maxCfg
= bnx2x_extract_max_cfg(bp
, vn_cfg
);
2280 /* maxCfg in percents of linkspeed */
2281 vn_max_rate
= (bp
->link_vars
.line_speed
* maxCfg
) / 100;
2282 } else /* SD modes */
2283 /* maxCfg is absolute in 100Mb units */
2284 vn_max_rate
= maxCfg
* 100;
2287 DP(NETIF_MSG_IFUP
, "vn %d: vn_max_rate %d\n", vn
, vn_max_rate
);
2289 input
->vnic_max_rate
[vn
] = vn_max_rate
;
2293 static int bnx2x_get_cmng_fns_mode(struct bnx2x
*bp
)
2295 if (CHIP_REV_IS_SLOW(bp
))
2296 return CMNG_FNS_NONE
;
2298 return CMNG_FNS_MINMAX
;
2300 return CMNG_FNS_NONE
;
2303 void bnx2x_read_mf_cfg(struct bnx2x
*bp
)
2305 int vn
, n
= (CHIP_MODE_IS_4_PORT(bp
) ? 2 : 1);
2308 return; /* what should be the default bvalue in this case */
2310 /* For 2 port configuration the absolute function number formula
2312 * abs_func = 2 * vn + BP_PORT + BP_PATH
2314 * and there are 4 functions per port
2316 * For 4 port configuration it is
2317 * abs_func = 4 * vn + 2 * BP_PORT + BP_PATH
2319 * and there are 2 functions per port
2321 for (vn
= VN_0
; vn
< BP_MAX_VN_NUM(bp
); vn
++) {
2322 int /*abs*/func
= n
* (2 * vn
+ BP_PORT(bp
)) + BP_PATH(bp
);
2324 if (func
>= E1H_FUNC_MAX
)
2328 MF_CFG_RD(bp
, func_mf_config
[func
].config
);
2330 if (bp
->mf_config
[BP_VN(bp
)] & FUNC_MF_CFG_FUNC_DISABLED
) {
2331 DP(NETIF_MSG_IFUP
, "mf_cfg function disabled\n");
2332 bp
->flags
|= MF_FUNC_DIS
;
2334 DP(NETIF_MSG_IFUP
, "mf_cfg function enabled\n");
2335 bp
->flags
&= ~MF_FUNC_DIS
;
2339 static void bnx2x_cmng_fns_init(struct bnx2x
*bp
, u8 read_cfg
, u8 cmng_type
)
2341 struct cmng_init_input input
;
2342 memset(&input
, 0, sizeof(struct cmng_init_input
));
2344 input
.port_rate
= bp
->link_vars
.line_speed
;
2346 if (cmng_type
== CMNG_FNS_MINMAX
) {
2349 /* read mf conf from shmem */
2351 bnx2x_read_mf_cfg(bp
);
2353 /* vn_weight_sum and enable fairness if not 0 */
2354 bnx2x_calc_vn_min(bp
, &input
);
2356 /* calculate and set min-max rate for each vn */
2358 for (vn
= VN_0
; vn
< BP_MAX_VN_NUM(bp
); vn
++)
2359 bnx2x_calc_vn_max(bp
, vn
, &input
);
2361 /* always enable rate shaping and fairness */
2362 input
.flags
.cmng_enables
|=
2363 CMNG_FLAGS_PER_PORT_RATE_SHAPING_VN
;
2365 bnx2x_init_cmng(&input
, &bp
->cmng
);
2369 /* rate shaping and fairness are disabled */
2371 "rate shaping and fairness are disabled\n");
2374 static void storm_memset_cmng(struct bnx2x
*bp
,
2375 struct cmng_init
*cmng
,
2379 size_t size
= sizeof(struct cmng_struct_per_port
);
2381 u32 addr
= BAR_XSTRORM_INTMEM
+
2382 XSTORM_CMNG_PER_PORT_VARS_OFFSET(port
);
2384 __storm_memset_struct(bp
, addr
, size
, (u32
*)&cmng
->port
);
2386 for (vn
= VN_0
; vn
< BP_MAX_VN_NUM(bp
); vn
++) {
2387 int func
= func_by_vn(bp
, vn
);
2389 addr
= BAR_XSTRORM_INTMEM
+
2390 XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(func
);
2391 size
= sizeof(struct rate_shaping_vars_per_vn
);
2392 __storm_memset_struct(bp
, addr
, size
,
2393 (u32
*)&cmng
->vnic
.vnic_max_rate
[vn
]);
2395 addr
= BAR_XSTRORM_INTMEM
+
2396 XSTORM_FAIRNESS_PER_VN_VARS_OFFSET(func
);
2397 size
= sizeof(struct fairness_vars_per_vn
);
2398 __storm_memset_struct(bp
, addr
, size
,
2399 (u32
*)&cmng
->vnic
.vnic_min_rate
[vn
]);
2403 /* This function is called upon link interrupt */
2404 static void bnx2x_link_attn(struct bnx2x
*bp
)
2406 /* Make sure that we are synced with the current statistics */
2407 bnx2x_stats_handle(bp
, STATS_EVENT_STOP
);
2409 bnx2x_link_update(&bp
->link_params
, &bp
->link_vars
);
2411 if (bp
->link_vars
.link_up
) {
2413 /* dropless flow control */
2414 if (!CHIP_IS_E1(bp
) && bp
->dropless_fc
) {
2415 int port
= BP_PORT(bp
);
2416 u32 pause_enabled
= 0;
2418 if (bp
->link_vars
.flow_ctrl
& BNX2X_FLOW_CTRL_TX
)
2421 REG_WR(bp
, BAR_USTRORM_INTMEM
+
2422 USTORM_ETH_PAUSE_ENABLED_OFFSET(port
),
2426 if (bp
->link_vars
.mac_type
!= MAC_TYPE_EMAC
) {
2427 struct host_port_stats
*pstats
;
2429 pstats
= bnx2x_sp(bp
, port_stats
);
2430 /* reset old mac stats */
2431 memset(&(pstats
->mac_stx
[0]), 0,
2432 sizeof(struct mac_stx
));
2434 if (bp
->state
== BNX2X_STATE_OPEN
)
2435 bnx2x_stats_handle(bp
, STATS_EVENT_LINK_UP
);
2438 if (bp
->link_vars
.link_up
&& bp
->link_vars
.line_speed
) {
2439 int cmng_fns
= bnx2x_get_cmng_fns_mode(bp
);
2441 if (cmng_fns
!= CMNG_FNS_NONE
) {
2442 bnx2x_cmng_fns_init(bp
, false, cmng_fns
);
2443 storm_memset_cmng(bp
, &bp
->cmng
, BP_PORT(bp
));
2445 /* rate shaping and fairness are disabled */
2447 "single function mode without fairness\n");
2450 __bnx2x_link_report(bp
);
2453 bnx2x_link_sync_notify(bp
);
2456 void bnx2x__link_status_update(struct bnx2x
*bp
)
2458 if (bp
->state
!= BNX2X_STATE_OPEN
)
2461 /* read updated dcb configuration */
2462 bnx2x_dcbx_pmf_update(bp
);
2464 bnx2x_link_status_update(&bp
->link_params
, &bp
->link_vars
);
2466 if (bp
->link_vars
.link_up
)
2467 bnx2x_stats_handle(bp
, STATS_EVENT_LINK_UP
);
2469 bnx2x_stats_handle(bp
, STATS_EVENT_STOP
);
2471 /* indicate link status */
2472 bnx2x_link_report(bp
);
2475 static int bnx2x_afex_func_update(struct bnx2x
*bp
, u16 vifid
,
2476 u16 vlan_val
, u8 allowed_prio
)
2478 struct bnx2x_func_state_params func_params
= {0};
2479 struct bnx2x_func_afex_update_params
*f_update_params
=
2480 &func_params
.params
.afex_update
;
2482 func_params
.f_obj
= &bp
->func_obj
;
2483 func_params
.cmd
= BNX2X_F_CMD_AFEX_UPDATE
;
2485 /* no need to wait for RAMROD completion, so don't
2486 * set RAMROD_COMP_WAIT flag
2489 f_update_params
->vif_id
= vifid
;
2490 f_update_params
->afex_default_vlan
= vlan_val
;
2491 f_update_params
->allowed_priorities
= allowed_prio
;
2493 /* if ramrod can not be sent, response to MCP immediately */
2494 if (bnx2x_func_state_change(bp
, &func_params
) < 0)
2495 bnx2x_fw_command(bp
, DRV_MSG_CODE_AFEX_VIFSET_ACK
, 0);
2500 static int bnx2x_afex_handle_vif_list_cmd(struct bnx2x
*bp
, u8 cmd_type
,
2501 u16 vif_index
, u8 func_bit_map
)
2503 struct bnx2x_func_state_params func_params
= {0};
2504 struct bnx2x_func_afex_viflists_params
*update_params
=
2505 &func_params
.params
.afex_viflists
;
2509 /* validate only LIST_SET and LIST_GET are received from switch */
2510 if ((cmd_type
!= VIF_LIST_RULE_GET
) && (cmd_type
!= VIF_LIST_RULE_SET
))
2511 BNX2X_ERR("BUG! afex_handle_vif_list_cmd invalid type 0x%x\n",
2514 func_params
.f_obj
= &bp
->func_obj
;
2515 func_params
.cmd
= BNX2X_F_CMD_AFEX_VIFLISTS
;
2517 /* set parameters according to cmd_type */
2518 update_params
->afex_vif_list_command
= cmd_type
;
2519 update_params
->vif_list_index
= cpu_to_le16(vif_index
);
2520 update_params
->func_bit_map
=
2521 (cmd_type
== VIF_LIST_RULE_GET
) ? 0 : func_bit_map
;
2522 update_params
->func_to_clear
= 0;
2524 (cmd_type
== VIF_LIST_RULE_GET
) ?
2525 DRV_MSG_CODE_AFEX_LISTGET_ACK
:
2526 DRV_MSG_CODE_AFEX_LISTSET_ACK
;
2528 /* if ramrod can not be sent, respond to MCP immediately for
2529 * SET and GET requests (other are not triggered from MCP)
2531 rc
= bnx2x_func_state_change(bp
, &func_params
);
2533 bnx2x_fw_command(bp
, drv_msg_code
, 0);
2538 static void bnx2x_handle_afex_cmd(struct bnx2x
*bp
, u32 cmd
)
2540 struct afex_stats afex_stats
;
2541 u32 func
= BP_ABS_FUNC(bp
);
2548 u32 addr_to_write
, vifid
, addrs
, stats_type
, i
;
2550 if (cmd
& DRV_STATUS_AFEX_LISTGET_REQ
) {
2551 vifid
= SHMEM2_RD(bp
, afex_param1_to_driver
[BP_FW_MB_IDX(bp
)]);
2553 "afex: got MCP req LISTGET_REQ for vifid 0x%x\n", vifid
);
2554 bnx2x_afex_handle_vif_list_cmd(bp
, VIF_LIST_RULE_GET
, vifid
, 0);
2557 if (cmd
& DRV_STATUS_AFEX_LISTSET_REQ
) {
2558 vifid
= SHMEM2_RD(bp
, afex_param1_to_driver
[BP_FW_MB_IDX(bp
)]);
2559 addrs
= SHMEM2_RD(bp
, afex_param2_to_driver
[BP_FW_MB_IDX(bp
)]);
2561 "afex: got MCP req LISTSET_REQ for vifid 0x%x addrs 0x%x\n",
2563 bnx2x_afex_handle_vif_list_cmd(bp
, VIF_LIST_RULE_SET
, vifid
,
2567 if (cmd
& DRV_STATUS_AFEX_STATSGET_REQ
) {
2568 addr_to_write
= SHMEM2_RD(bp
,
2569 afex_scratchpad_addr_to_write
[BP_FW_MB_IDX(bp
)]);
2570 stats_type
= SHMEM2_RD(bp
,
2571 afex_param1_to_driver
[BP_FW_MB_IDX(bp
)]);
2574 "afex: got MCP req STATSGET_REQ, write to addr 0x%x\n",
2577 bnx2x_afex_collect_stats(bp
, (void *)&afex_stats
, stats_type
);
2579 /* write response to scratchpad, for MCP */
2580 for (i
= 0; i
< (sizeof(struct afex_stats
)/sizeof(u32
)); i
++)
2581 REG_WR(bp
, addr_to_write
+ i
*sizeof(u32
),
2582 *(((u32
*)(&afex_stats
))+i
));
2584 /* send ack message to MCP */
2585 bnx2x_fw_command(bp
, DRV_MSG_CODE_AFEX_STATSGET_ACK
, 0);
2588 if (cmd
& DRV_STATUS_AFEX_VIFSET_REQ
) {
2589 mf_config
= MF_CFG_RD(bp
, func_mf_config
[func
].config
);
2590 bp
->mf_config
[BP_VN(bp
)] = mf_config
;
2592 "afex: got MCP req VIFSET_REQ, mf_config 0x%x\n",
2595 /* if VIF_SET is "enabled" */
2596 if (!(mf_config
& FUNC_MF_CFG_FUNC_DISABLED
)) {
2597 /* set rate limit directly to internal RAM */
2598 struct cmng_init_input cmng_input
;
2599 struct rate_shaping_vars_per_vn m_rs_vn
;
2600 size_t size
= sizeof(struct rate_shaping_vars_per_vn
);
2601 u32 addr
= BAR_XSTRORM_INTMEM
+
2602 XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(BP_FUNC(bp
));
2604 bp
->mf_config
[BP_VN(bp
)] = mf_config
;
2606 bnx2x_calc_vn_max(bp
, BP_VN(bp
), &cmng_input
);
2607 m_rs_vn
.vn_counter
.rate
=
2608 cmng_input
.vnic_max_rate
[BP_VN(bp
)];
2609 m_rs_vn
.vn_counter
.quota
=
2610 (m_rs_vn
.vn_counter
.rate
*
2611 RS_PERIODIC_TIMEOUT_USEC
) / 8;
2613 __storm_memset_struct(bp
, addr
, size
, (u32
*)&m_rs_vn
);
2615 /* read relevant values from mf_cfg struct in shmem */
2617 (MF_CFG_RD(bp
, func_mf_config
[func
].e1hov_tag
) &
2618 FUNC_MF_CFG_E1HOV_TAG_MASK
) >>
2619 FUNC_MF_CFG_E1HOV_TAG_SHIFT
;
2621 (MF_CFG_RD(bp
, func_mf_config
[func
].e1hov_tag
) &
2622 FUNC_MF_CFG_AFEX_VLAN_MASK
) >>
2623 FUNC_MF_CFG_AFEX_VLAN_SHIFT
;
2624 vlan_prio
= (mf_config
&
2625 FUNC_MF_CFG_TRANSMIT_PRIORITY_MASK
) >>
2626 FUNC_MF_CFG_TRANSMIT_PRIORITY_SHIFT
;
2627 vlan_val
|= (vlan_prio
<< VLAN_PRIO_SHIFT
);
2630 func_mf_config
[func
].afex_config
) &
2631 FUNC_MF_CFG_AFEX_VLAN_MODE_MASK
) >>
2632 FUNC_MF_CFG_AFEX_VLAN_MODE_SHIFT
;
2635 func_mf_config
[func
].afex_config
) &
2636 FUNC_MF_CFG_AFEX_COS_FILTER_MASK
) >>
2637 FUNC_MF_CFG_AFEX_COS_FILTER_SHIFT
;
2639 /* send ramrod to FW, return in case of failure */
2640 if (bnx2x_afex_func_update(bp
, vif_id
, vlan_val
,
2644 bp
->afex_def_vlan_tag
= vlan_val
;
2645 bp
->afex_vlan_mode
= vlan_mode
;
2647 /* notify link down because BP->flags is disabled */
2648 bnx2x_link_report(bp
);
2650 /* send INVALID VIF ramrod to FW */
2651 bnx2x_afex_func_update(bp
, 0xFFFF, 0, 0);
2653 /* Reset the default afex VLAN */
2654 bp
->afex_def_vlan_tag
= -1;
2659 static void bnx2x_pmf_update(struct bnx2x
*bp
)
2661 int port
= BP_PORT(bp
);
2665 DP(BNX2X_MSG_MCP
, "pmf %d\n", bp
->port
.pmf
);
2668 * We need the mb() to ensure the ordering between the writing to
2669 * bp->port.pmf here and reading it from the bnx2x_periodic_task().
2673 /* queue a periodic task */
2674 queue_delayed_work(bnx2x_wq
, &bp
->period_task
, 0);
2676 bnx2x_dcbx_pmf_update(bp
);
2678 /* enable nig attention */
2679 val
= (0xff0f | (1 << (BP_VN(bp
) + 4)));
2680 if (bp
->common
.int_block
== INT_BLOCK_HC
) {
2681 REG_WR(bp
, HC_REG_TRAILING_EDGE_0
+ port
*8, val
);
2682 REG_WR(bp
, HC_REG_LEADING_EDGE_0
+ port
*8, val
);
2683 } else if (!CHIP_IS_E1x(bp
)) {
2684 REG_WR(bp
, IGU_REG_TRAILING_EDGE_LATCH
, val
);
2685 REG_WR(bp
, IGU_REG_LEADING_EDGE_LATCH
, val
);
2688 bnx2x_stats_handle(bp
, STATS_EVENT_PMF
);
2696 * General service functions
2699 /* send the MCP a request, block until there is a reply */
2700 u32
bnx2x_fw_command(struct bnx2x
*bp
, u32 command
, u32 param
)
2702 int mb_idx
= BP_FW_MB_IDX(bp
);
2706 u8 delay
= CHIP_REV_IS_SLOW(bp
) ? 100 : 10;
2708 mutex_lock(&bp
->fw_mb_mutex
);
2710 SHMEM_WR(bp
, func_mb
[mb_idx
].drv_mb_param
, param
);
2711 SHMEM_WR(bp
, func_mb
[mb_idx
].drv_mb_header
, (command
| seq
));
2713 DP(BNX2X_MSG_MCP
, "wrote command (%x) to FW MB param 0x%08x\n",
2714 (command
| seq
), param
);
2717 /* let the FW do it's magic ... */
2720 rc
= SHMEM_RD(bp
, func_mb
[mb_idx
].fw_mb_header
);
2722 /* Give the FW up to 5 second (500*10ms) */
2723 } while ((seq
!= (rc
& FW_MSG_SEQ_NUMBER_MASK
)) && (cnt
++ < 500));
2725 DP(BNX2X_MSG_MCP
, "[after %d ms] read (%x) seq is (%x) from FW MB\n",
2726 cnt
*delay
, rc
, seq
);
2728 /* is this a reply to our command? */
2729 if (seq
== (rc
& FW_MSG_SEQ_NUMBER_MASK
))
2730 rc
&= FW_MSG_CODE_MASK
;
2733 BNX2X_ERR("FW failed to respond!\n");
2737 mutex_unlock(&bp
->fw_mb_mutex
);
2743 static void storm_memset_func_cfg(struct bnx2x
*bp
,
2744 struct tstorm_eth_function_common_config
*tcfg
,
2747 size_t size
= sizeof(struct tstorm_eth_function_common_config
);
2749 u32 addr
= BAR_TSTRORM_INTMEM
+
2750 TSTORM_FUNCTION_COMMON_CONFIG_OFFSET(abs_fid
);
2752 __storm_memset_struct(bp
, addr
, size
, (u32
*)tcfg
);
2755 void bnx2x_func_init(struct bnx2x
*bp
, struct bnx2x_func_init_params
*p
)
2757 if (CHIP_IS_E1x(bp
)) {
2758 struct tstorm_eth_function_common_config tcfg
= {0};
2760 storm_memset_func_cfg(bp
, &tcfg
, p
->func_id
);
2763 /* Enable the function in the FW */
2764 storm_memset_vf_to_pf(bp
, p
->func_id
, p
->pf_id
);
2765 storm_memset_func_en(bp
, p
->func_id
, 1);
2768 if (p
->func_flgs
& FUNC_FLG_SPQ
) {
2769 storm_memset_spq_addr(bp
, p
->spq_map
, p
->func_id
);
2770 REG_WR(bp
, XSEM_REG_FAST_MEMORY
+
2771 XSTORM_SPQ_PROD_OFFSET(p
->func_id
), p
->spq_prod
);
2776 * bnx2x_get_tx_only_flags - Return common flags
2780 * @zero_stats TRUE if statistics zeroing is needed
2782 * Return the flags that are common for the Tx-only and not normal connections.
2784 static unsigned long bnx2x_get_common_flags(struct bnx2x
*bp
,
2785 struct bnx2x_fastpath
*fp
,
2788 unsigned long flags
= 0;
2790 /* PF driver will always initialize the Queue to an ACTIVE state */
2791 __set_bit(BNX2X_Q_FLG_ACTIVE
, &flags
);
2793 /* tx only connections collect statistics (on the same index as the
2794 * parent connection). The statistics are zeroed when the parent
2795 * connection is initialized.
2798 __set_bit(BNX2X_Q_FLG_STATS
, &flags
);
2800 __set_bit(BNX2X_Q_FLG_ZERO_STATS
, &flags
);
2806 static unsigned long bnx2x_get_q_flags(struct bnx2x
*bp
,
2807 struct bnx2x_fastpath
*fp
,
2810 unsigned long flags
= 0;
2812 /* calculate other queue flags */
2814 __set_bit(BNX2X_Q_FLG_OV
, &flags
);
2816 if (IS_FCOE_FP(fp
)) {
2817 __set_bit(BNX2X_Q_FLG_FCOE
, &flags
);
2818 /* For FCoE - force usage of default priority (for afex) */
2819 __set_bit(BNX2X_Q_FLG_FORCE_DEFAULT_PRI
, &flags
);
2822 if (!fp
->disable_tpa
) {
2823 __set_bit(BNX2X_Q_FLG_TPA
, &flags
);
2824 __set_bit(BNX2X_Q_FLG_TPA_IPV6
, &flags
);
2825 if (fp
->mode
== TPA_MODE_GRO
)
2826 __set_bit(BNX2X_Q_FLG_TPA_GRO
, &flags
);
2830 __set_bit(BNX2X_Q_FLG_LEADING_RSS
, &flags
);
2831 __set_bit(BNX2X_Q_FLG_MCAST
, &flags
);
2834 /* Always set HW VLAN stripping */
2835 __set_bit(BNX2X_Q_FLG_VLAN
, &flags
);
2837 /* configure silent vlan removal */
2839 __set_bit(BNX2X_Q_FLG_SILENT_VLAN_REM
, &flags
);
2842 return flags
| bnx2x_get_common_flags(bp
, fp
, true);
2845 static void bnx2x_pf_q_prep_general(struct bnx2x
*bp
,
2846 struct bnx2x_fastpath
*fp
, struct bnx2x_general_setup_params
*gen_init
,
2849 gen_init
->stat_id
= bnx2x_stats_id(fp
);
2850 gen_init
->spcl_id
= fp
->cl_id
;
2852 /* Always use mini-jumbo MTU for FCoE L2 ring */
2854 gen_init
->mtu
= BNX2X_FCOE_MINI_JUMBO_MTU
;
2856 gen_init
->mtu
= bp
->dev
->mtu
;
2858 gen_init
->cos
= cos
;
2861 static void bnx2x_pf_rx_q_prep(struct bnx2x
*bp
,
2862 struct bnx2x_fastpath
*fp
, struct rxq_pause_params
*pause
,
2863 struct bnx2x_rxq_setup_params
*rxq_init
)
2867 u16 tpa_agg_size
= 0;
2869 if (!fp
->disable_tpa
) {
2870 pause
->sge_th_lo
= SGE_TH_LO(bp
);
2871 pause
->sge_th_hi
= SGE_TH_HI(bp
);
2873 /* validate SGE ring has enough to cross high threshold */
2874 WARN_ON(bp
->dropless_fc
&&
2875 pause
->sge_th_hi
+ FW_PREFETCH_CNT
>
2876 MAX_RX_SGE_CNT
* NUM_RX_SGE_PAGES
);
2878 tpa_agg_size
= min_t(u32
,
2879 (min_t(u32
, 8, MAX_SKB_FRAGS
) *
2880 SGE_PAGE_SIZE
* PAGES_PER_SGE
), 0xffff);
2881 max_sge
= SGE_PAGE_ALIGN(bp
->dev
->mtu
) >>
2883 max_sge
= ((max_sge
+ PAGES_PER_SGE
- 1) &
2884 (~(PAGES_PER_SGE
-1))) >> PAGES_PER_SGE_SHIFT
;
2885 sge_sz
= (u16
)min_t(u32
, SGE_PAGE_SIZE
* PAGES_PER_SGE
,
2889 /* pause - not for e1 */
2890 if (!CHIP_IS_E1(bp
)) {
2891 pause
->bd_th_lo
= BD_TH_LO(bp
);
2892 pause
->bd_th_hi
= BD_TH_HI(bp
);
2894 pause
->rcq_th_lo
= RCQ_TH_LO(bp
);
2895 pause
->rcq_th_hi
= RCQ_TH_HI(bp
);
2897 * validate that rings have enough entries to cross
2900 WARN_ON(bp
->dropless_fc
&&
2901 pause
->bd_th_hi
+ FW_PREFETCH_CNT
>
2903 WARN_ON(bp
->dropless_fc
&&
2904 pause
->rcq_th_hi
+ FW_PREFETCH_CNT
>
2905 NUM_RCQ_RINGS
* MAX_RCQ_DESC_CNT
);
2911 rxq_init
->dscr_map
= fp
->rx_desc_mapping
;
2912 rxq_init
->sge_map
= fp
->rx_sge_mapping
;
2913 rxq_init
->rcq_map
= fp
->rx_comp_mapping
;
2914 rxq_init
->rcq_np_map
= fp
->rx_comp_mapping
+ BCM_PAGE_SIZE
;
2916 /* This should be a maximum number of data bytes that may be
2917 * placed on the BD (not including paddings).
2919 rxq_init
->buf_sz
= fp
->rx_buf_size
- BNX2X_FW_RX_ALIGN_START
-
2920 BNX2X_FW_RX_ALIGN_END
- IP_HEADER_ALIGNMENT_PADDING
;
2922 rxq_init
->cl_qzone_id
= fp
->cl_qzone_id
;
2923 rxq_init
->tpa_agg_sz
= tpa_agg_size
;
2924 rxq_init
->sge_buf_sz
= sge_sz
;
2925 rxq_init
->max_sges_pkt
= max_sge
;
2926 rxq_init
->rss_engine_id
= BP_FUNC(bp
);
2927 rxq_init
->mcast_engine_id
= BP_FUNC(bp
);
2929 /* Maximum number or simultaneous TPA aggregation for this Queue.
2931 * For PF Clients it should be the maximum avaliable number.
2932 * VF driver(s) may want to define it to a smaller value.
2934 rxq_init
->max_tpa_queues
= MAX_AGG_QS(bp
);
2936 rxq_init
->cache_line_log
= BNX2X_RX_ALIGN_SHIFT
;
2937 rxq_init
->fw_sb_id
= fp
->fw_sb_id
;
2940 rxq_init
->sb_cq_index
= HC_SP_INDEX_ETH_FCOE_RX_CQ_CONS
;
2942 rxq_init
->sb_cq_index
= HC_INDEX_ETH_RX_CQ_CONS
;
2943 /* configure silent vlan removal
2944 * if multi function mode is afex, then mask default vlan
2946 if (IS_MF_AFEX(bp
)) {
2947 rxq_init
->silent_removal_value
= bp
->afex_def_vlan_tag
;
2948 rxq_init
->silent_removal_mask
= VLAN_VID_MASK
;
2952 static void bnx2x_pf_tx_q_prep(struct bnx2x
*bp
,
2953 struct bnx2x_fastpath
*fp
, struct bnx2x_txq_setup_params
*txq_init
,
2956 txq_init
->dscr_map
= fp
->txdata_ptr
[cos
]->tx_desc_mapping
;
2957 txq_init
->sb_cq_index
= HC_INDEX_ETH_FIRST_TX_CQ_CONS
+ cos
;
2958 txq_init
->traffic_type
= LLFC_TRAFFIC_TYPE_NW
;
2959 txq_init
->fw_sb_id
= fp
->fw_sb_id
;
2962 * set the tss leading client id for TX classfication ==
2963 * leading RSS client id
2965 txq_init
->tss_leading_cl_id
= bnx2x_fp(bp
, 0, cl_id
);
2967 if (IS_FCOE_FP(fp
)) {
2968 txq_init
->sb_cq_index
= HC_SP_INDEX_ETH_FCOE_TX_CQ_CONS
;
2969 txq_init
->traffic_type
= LLFC_TRAFFIC_TYPE_FCOE
;
2973 static void bnx2x_pf_init(struct bnx2x
*bp
)
2975 struct bnx2x_func_init_params func_init
= {0};
2976 struct event_ring_data eq_data
= { {0} };
2979 if (!CHIP_IS_E1x(bp
)) {
2980 /* reset IGU PF statistics: MSIX + ATTN */
2982 REG_WR(bp
, IGU_REG_STATISTIC_NUM_MESSAGE_SENT
+
2983 BNX2X_IGU_STAS_MSG_VF_CNT
*4 +
2984 (CHIP_MODE_IS_4_PORT(bp
) ?
2985 BP_FUNC(bp
) : BP_VN(bp
))*4, 0);
2987 REG_WR(bp
, IGU_REG_STATISTIC_NUM_MESSAGE_SENT
+
2988 BNX2X_IGU_STAS_MSG_VF_CNT
*4 +
2989 BNX2X_IGU_STAS_MSG_PF_CNT
*4 +
2990 (CHIP_MODE_IS_4_PORT(bp
) ?
2991 BP_FUNC(bp
) : BP_VN(bp
))*4, 0);
2994 /* function setup flags */
2995 flags
= (FUNC_FLG_STATS
| FUNC_FLG_LEADING
| FUNC_FLG_SPQ
);
2997 /* This flag is relevant for E1x only.
2998 * E2 doesn't have a TPA configuration in a function level.
3000 flags
|= (bp
->flags
& TPA_ENABLE_FLAG
) ? FUNC_FLG_TPA
: 0;
3002 func_init
.func_flgs
= flags
;
3003 func_init
.pf_id
= BP_FUNC(bp
);
3004 func_init
.func_id
= BP_FUNC(bp
);
3005 func_init
.spq_map
= bp
->spq_mapping
;
3006 func_init
.spq_prod
= bp
->spq_prod_idx
;
3008 bnx2x_func_init(bp
, &func_init
);
3010 memset(&(bp
->cmng
), 0, sizeof(struct cmng_struct_per_port
));
3013 * Congestion management values depend on the link rate
3014 * There is no active link so initial link rate is set to 10 Gbps.
3015 * When the link comes up The congestion management values are
3016 * re-calculated according to the actual link rate.
3018 bp
->link_vars
.line_speed
= SPEED_10000
;
3019 bnx2x_cmng_fns_init(bp
, true, bnx2x_get_cmng_fns_mode(bp
));
3021 /* Only the PMF sets the HW */
3023 storm_memset_cmng(bp
, &bp
->cmng
, BP_PORT(bp
));
3025 /* init Event Queue */
3026 eq_data
.base_addr
.hi
= U64_HI(bp
->eq_mapping
);
3027 eq_data
.base_addr
.lo
= U64_LO(bp
->eq_mapping
);
3028 eq_data
.producer
= bp
->eq_prod
;
3029 eq_data
.index_id
= HC_SP_INDEX_EQ_CONS
;
3030 eq_data
.sb_id
= DEF_SB_ID
;
3031 storm_memset_eq_data(bp
, &eq_data
, BP_FUNC(bp
));
3035 static void bnx2x_e1h_disable(struct bnx2x
*bp
)
3037 int port
= BP_PORT(bp
);
3039 bnx2x_tx_disable(bp
);
3041 REG_WR(bp
, NIG_REG_LLH0_FUNC_EN
+ port
*8, 0);
3044 static void bnx2x_e1h_enable(struct bnx2x
*bp
)
3046 int port
= BP_PORT(bp
);
3048 REG_WR(bp
, NIG_REG_LLH0_FUNC_EN
+ port
*8, 1);
3050 /* Tx queue should be only reenabled */
3051 netif_tx_wake_all_queues(bp
->dev
);
3054 * Should not call netif_carrier_on since it will be called if the link
3055 * is up when checking for link state
3059 #define DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED 3
3061 static void bnx2x_drv_info_ether_stat(struct bnx2x
*bp
)
3063 struct eth_stats_info
*ether_stat
=
3064 &bp
->slowpath
->drv_info_to_mcp
.ether_stat
;
3066 strlcpy(ether_stat
->version
, DRV_MODULE_VERSION
,
3067 ETH_STAT_INFO_VERSION_LEN
);
3069 bp
->sp_objs
[0].mac_obj
.get_n_elements(bp
, &bp
->sp_objs
[0].mac_obj
,
3070 DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED
,
3071 ether_stat
->mac_local
);
3073 ether_stat
->mtu_size
= bp
->dev
->mtu
;
3075 if (bp
->dev
->features
& NETIF_F_RXCSUM
)
3076 ether_stat
->feature_flags
|= FEATURE_ETH_CHKSUM_OFFLOAD_MASK
;
3077 if (bp
->dev
->features
& NETIF_F_TSO
)
3078 ether_stat
->feature_flags
|= FEATURE_ETH_LSO_MASK
;
3079 ether_stat
->feature_flags
|= bp
->common
.boot_mode
;
3081 ether_stat
->promiscuous_mode
= (bp
->dev
->flags
& IFF_PROMISC
) ? 1 : 0;
3083 ether_stat
->txq_size
= bp
->tx_ring_size
;
3084 ether_stat
->rxq_size
= bp
->rx_ring_size
;
3087 static void bnx2x_drv_info_fcoe_stat(struct bnx2x
*bp
)
3089 struct bnx2x_dcbx_app_params
*app
= &bp
->dcbx_port_params
.app
;
3090 struct fcoe_stats_info
*fcoe_stat
=
3091 &bp
->slowpath
->drv_info_to_mcp
.fcoe_stat
;
3093 if (!CNIC_LOADED(bp
))
3096 memcpy(fcoe_stat
->mac_local
+ MAC_LEADING_ZERO_CNT
,
3097 bp
->fip_mac
, ETH_ALEN
);
3099 fcoe_stat
->qos_priority
=
3100 app
->traffic_type_priority
[LLFC_TRAFFIC_TYPE_FCOE
];
3102 /* insert FCoE stats from ramrod response */
3104 struct tstorm_per_queue_stats
*fcoe_q_tstorm_stats
=
3105 &bp
->fw_stats_data
->queue_stats
[FCOE_IDX(bp
)].
3106 tstorm_queue_statistics
;
3108 struct xstorm_per_queue_stats
*fcoe_q_xstorm_stats
=
3109 &bp
->fw_stats_data
->queue_stats
[FCOE_IDX(bp
)].
3110 xstorm_queue_statistics
;
3112 struct fcoe_statistics_params
*fw_fcoe_stat
=
3113 &bp
->fw_stats_data
->fcoe
;
3115 ADD_64(fcoe_stat
->rx_bytes_hi
, 0, fcoe_stat
->rx_bytes_lo
,
3116 fw_fcoe_stat
->rx_stat0
.fcoe_rx_byte_cnt
);
3118 ADD_64(fcoe_stat
->rx_bytes_hi
,
3119 fcoe_q_tstorm_stats
->rcv_ucast_bytes
.hi
,
3120 fcoe_stat
->rx_bytes_lo
,
3121 fcoe_q_tstorm_stats
->rcv_ucast_bytes
.lo
);
3123 ADD_64(fcoe_stat
->rx_bytes_hi
,
3124 fcoe_q_tstorm_stats
->rcv_bcast_bytes
.hi
,
3125 fcoe_stat
->rx_bytes_lo
,
3126 fcoe_q_tstorm_stats
->rcv_bcast_bytes
.lo
);
3128 ADD_64(fcoe_stat
->rx_bytes_hi
,
3129 fcoe_q_tstorm_stats
->rcv_mcast_bytes
.hi
,
3130 fcoe_stat
->rx_bytes_lo
,
3131 fcoe_q_tstorm_stats
->rcv_mcast_bytes
.lo
);
3133 ADD_64(fcoe_stat
->rx_frames_hi
, 0, fcoe_stat
->rx_frames_lo
,
3134 fw_fcoe_stat
->rx_stat0
.fcoe_rx_pkt_cnt
);
3136 ADD_64(fcoe_stat
->rx_frames_hi
, 0, fcoe_stat
->rx_frames_lo
,
3137 fcoe_q_tstorm_stats
->rcv_ucast_pkts
);
3139 ADD_64(fcoe_stat
->rx_frames_hi
, 0, fcoe_stat
->rx_frames_lo
,
3140 fcoe_q_tstorm_stats
->rcv_bcast_pkts
);
3142 ADD_64(fcoe_stat
->rx_frames_hi
, 0, fcoe_stat
->rx_frames_lo
,
3143 fcoe_q_tstorm_stats
->rcv_mcast_pkts
);
3145 ADD_64(fcoe_stat
->tx_bytes_hi
, 0, fcoe_stat
->tx_bytes_lo
,
3146 fw_fcoe_stat
->tx_stat
.fcoe_tx_byte_cnt
);
3148 ADD_64(fcoe_stat
->tx_bytes_hi
,
3149 fcoe_q_xstorm_stats
->ucast_bytes_sent
.hi
,
3150 fcoe_stat
->tx_bytes_lo
,
3151 fcoe_q_xstorm_stats
->ucast_bytes_sent
.lo
);
3153 ADD_64(fcoe_stat
->tx_bytes_hi
,
3154 fcoe_q_xstorm_stats
->bcast_bytes_sent
.hi
,
3155 fcoe_stat
->tx_bytes_lo
,
3156 fcoe_q_xstorm_stats
->bcast_bytes_sent
.lo
);
3158 ADD_64(fcoe_stat
->tx_bytes_hi
,
3159 fcoe_q_xstorm_stats
->mcast_bytes_sent
.hi
,
3160 fcoe_stat
->tx_bytes_lo
,
3161 fcoe_q_xstorm_stats
->mcast_bytes_sent
.lo
);
3163 ADD_64(fcoe_stat
->tx_frames_hi
, 0, fcoe_stat
->tx_frames_lo
,
3164 fw_fcoe_stat
->tx_stat
.fcoe_tx_pkt_cnt
);
3166 ADD_64(fcoe_stat
->tx_frames_hi
, 0, fcoe_stat
->tx_frames_lo
,
3167 fcoe_q_xstorm_stats
->ucast_pkts_sent
);
3169 ADD_64(fcoe_stat
->tx_frames_hi
, 0, fcoe_stat
->tx_frames_lo
,
3170 fcoe_q_xstorm_stats
->bcast_pkts_sent
);
3172 ADD_64(fcoe_stat
->tx_frames_hi
, 0, fcoe_stat
->tx_frames_lo
,
3173 fcoe_q_xstorm_stats
->mcast_pkts_sent
);
3176 /* ask L5 driver to add data to the struct */
3177 bnx2x_cnic_notify(bp
, CNIC_CTL_FCOE_STATS_GET_CMD
);
3180 static void bnx2x_drv_info_iscsi_stat(struct bnx2x
*bp
)
3182 struct bnx2x_dcbx_app_params
*app
= &bp
->dcbx_port_params
.app
;
3183 struct iscsi_stats_info
*iscsi_stat
=
3184 &bp
->slowpath
->drv_info_to_mcp
.iscsi_stat
;
3186 if (!CNIC_LOADED(bp
))
3189 memcpy(iscsi_stat
->mac_local
+ MAC_LEADING_ZERO_CNT
,
3190 bp
->cnic_eth_dev
.iscsi_mac
, ETH_ALEN
);
3192 iscsi_stat
->qos_priority
=
3193 app
->traffic_type_priority
[LLFC_TRAFFIC_TYPE_ISCSI
];
3195 /* ask L5 driver to add data to the struct */
3196 bnx2x_cnic_notify(bp
, CNIC_CTL_ISCSI_STATS_GET_CMD
);
3199 /* called due to MCP event (on pmf):
3200 * reread new bandwidth configuration
3202 * notify others function about the change
3204 static void bnx2x_config_mf_bw(struct bnx2x
*bp
)
3206 if (bp
->link_vars
.link_up
) {
3207 bnx2x_cmng_fns_init(bp
, true, CMNG_FNS_MINMAX
);
3208 bnx2x_link_sync_notify(bp
);
3210 storm_memset_cmng(bp
, &bp
->cmng
, BP_PORT(bp
));
3213 static void bnx2x_set_mf_bw(struct bnx2x
*bp
)
3215 bnx2x_config_mf_bw(bp
);
3216 bnx2x_fw_command(bp
, DRV_MSG_CODE_SET_MF_BW_ACK
, 0);
3219 static void bnx2x_handle_eee_event(struct bnx2x
*bp
)
3221 DP(BNX2X_MSG_MCP
, "EEE - LLDP event\n");
3222 bnx2x_fw_command(bp
, DRV_MSG_CODE_EEE_RESULTS_ACK
, 0);
3225 static void bnx2x_handle_drv_info_req(struct bnx2x
*bp
)
3227 enum drv_info_opcode op_code
;
3228 u32 drv_info_ctl
= SHMEM2_RD(bp
, drv_info_control
);
3230 /* if drv_info version supported by MFW doesn't match - send NACK */
3231 if ((drv_info_ctl
& DRV_INFO_CONTROL_VER_MASK
) != DRV_INFO_CUR_VER
) {
3232 bnx2x_fw_command(bp
, DRV_MSG_CODE_DRV_INFO_NACK
, 0);
3236 op_code
= (drv_info_ctl
& DRV_INFO_CONTROL_OP_CODE_MASK
) >>
3237 DRV_INFO_CONTROL_OP_CODE_SHIFT
;
3239 memset(&bp
->slowpath
->drv_info_to_mcp
, 0,
3240 sizeof(union drv_info_to_mcp
));
3243 case ETH_STATS_OPCODE
:
3244 bnx2x_drv_info_ether_stat(bp
);
3246 case FCOE_STATS_OPCODE
:
3247 bnx2x_drv_info_fcoe_stat(bp
);
3249 case ISCSI_STATS_OPCODE
:
3250 bnx2x_drv_info_iscsi_stat(bp
);
3253 /* if op code isn't supported - send NACK */
3254 bnx2x_fw_command(bp
, DRV_MSG_CODE_DRV_INFO_NACK
, 0);
3258 /* if we got drv_info attn from MFW then these fields are defined in
3261 SHMEM2_WR(bp
, drv_info_host_addr_lo
,
3262 U64_LO(bnx2x_sp_mapping(bp
, drv_info_to_mcp
)));
3263 SHMEM2_WR(bp
, drv_info_host_addr_hi
,
3264 U64_HI(bnx2x_sp_mapping(bp
, drv_info_to_mcp
)));
3266 bnx2x_fw_command(bp
, DRV_MSG_CODE_DRV_INFO_ACK
, 0);
3269 static void bnx2x_dcc_event(struct bnx2x
*bp
, u32 dcc_event
)
3271 DP(BNX2X_MSG_MCP
, "dcc_event 0x%x\n", dcc_event
);
3273 if (dcc_event
& DRV_STATUS_DCC_DISABLE_ENABLE_PF
) {
3276 * This is the only place besides the function initialization
3277 * where the bp->flags can change so it is done without any
3280 if (bp
->mf_config
[BP_VN(bp
)] & FUNC_MF_CFG_FUNC_DISABLED
) {
3281 DP(BNX2X_MSG_MCP
, "mf_cfg function disabled\n");
3282 bp
->flags
|= MF_FUNC_DIS
;
3284 bnx2x_e1h_disable(bp
);
3286 DP(BNX2X_MSG_MCP
, "mf_cfg function enabled\n");
3287 bp
->flags
&= ~MF_FUNC_DIS
;
3289 bnx2x_e1h_enable(bp
);
3291 dcc_event
&= ~DRV_STATUS_DCC_DISABLE_ENABLE_PF
;
3293 if (dcc_event
& DRV_STATUS_DCC_BANDWIDTH_ALLOCATION
) {
3294 bnx2x_config_mf_bw(bp
);
3295 dcc_event
&= ~DRV_STATUS_DCC_BANDWIDTH_ALLOCATION
;
3298 /* Report results to MCP */
3300 bnx2x_fw_command(bp
, DRV_MSG_CODE_DCC_FAILURE
, 0);
3302 bnx2x_fw_command(bp
, DRV_MSG_CODE_DCC_OK
, 0);
3305 /* must be called under the spq lock */
3306 static struct eth_spe
*bnx2x_sp_get_next(struct bnx2x
*bp
)
3308 struct eth_spe
*next_spe
= bp
->spq_prod_bd
;
3310 if (bp
->spq_prod_bd
== bp
->spq_last_bd
) {
3311 bp
->spq_prod_bd
= bp
->spq
;
3312 bp
->spq_prod_idx
= 0;
3313 DP(BNX2X_MSG_SP
, "end of spq\n");
3321 /* must be called under the spq lock */
3322 static void bnx2x_sp_prod_update(struct bnx2x
*bp
)
3324 int func
= BP_FUNC(bp
);
3327 * Make sure that BD data is updated before writing the producer:
3328 * BD data is written to the memory, the producer is read from the
3329 * memory, thus we need a full memory barrier to ensure the ordering.
3333 REG_WR16(bp
, BAR_XSTRORM_INTMEM
+ XSTORM_SPQ_PROD_OFFSET(func
),
3339 * bnx2x_is_contextless_ramrod - check if the current command ends on EQ
3341 * @cmd: command to check
3342 * @cmd_type: command type
3344 static bool bnx2x_is_contextless_ramrod(int cmd
, int cmd_type
)
3346 if ((cmd_type
== NONE_CONNECTION_TYPE
) ||
3347 (cmd
== RAMROD_CMD_ID_ETH_FORWARD_SETUP
) ||
3348 (cmd
== RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES
) ||
3349 (cmd
== RAMROD_CMD_ID_ETH_FILTER_RULES
) ||
3350 (cmd
== RAMROD_CMD_ID_ETH_MULTICAST_RULES
) ||
3351 (cmd
== RAMROD_CMD_ID_ETH_SET_MAC
) ||
3352 (cmd
== RAMROD_CMD_ID_ETH_RSS_UPDATE
))
3361 * bnx2x_sp_post - place a single command on an SP ring
3363 * @bp: driver handle
3364 * @command: command to place (e.g. SETUP, FILTER_RULES, etc.)
3365 * @cid: SW CID the command is related to
3366 * @data_hi: command private data address (high 32 bits)
3367 * @data_lo: command private data address (low 32 bits)
3368 * @cmd_type: command type (e.g. NONE, ETH)
3370 * SP data is handled as if it's always an address pair, thus data fields are
3371 * not swapped to little endian in upper functions. Instead this function swaps
3372 * data as if it's two u32 fields.
3374 int bnx2x_sp_post(struct bnx2x
*bp
, int command
, int cid
,
3375 u32 data_hi
, u32 data_lo
, int cmd_type
)
3377 struct eth_spe
*spe
;
3379 bool common
= bnx2x_is_contextless_ramrod(command
, cmd_type
);
3381 #ifdef BNX2X_STOP_ON_ERROR
3382 if (unlikely(bp
->panic
)) {
3383 BNX2X_ERR("Can't post SP when there is panic\n");
3388 spin_lock_bh(&bp
->spq_lock
);
3391 if (!atomic_read(&bp
->eq_spq_left
)) {
3392 BNX2X_ERR("BUG! EQ ring full!\n");
3393 spin_unlock_bh(&bp
->spq_lock
);
3397 } else if (!atomic_read(&bp
->cq_spq_left
)) {
3398 BNX2X_ERR("BUG! SPQ ring full!\n");
3399 spin_unlock_bh(&bp
->spq_lock
);
3404 spe
= bnx2x_sp_get_next(bp
);
3406 /* CID needs port number to be encoded int it */
3407 spe
->hdr
.conn_and_cmd_data
=
3408 cpu_to_le32((command
<< SPE_HDR_CMD_ID_SHIFT
) |
3411 type
= (cmd_type
<< SPE_HDR_CONN_TYPE_SHIFT
) & SPE_HDR_CONN_TYPE
;
3413 type
|= ((BP_FUNC(bp
) << SPE_HDR_FUNCTION_ID_SHIFT
) &
3414 SPE_HDR_FUNCTION_ID
);
3416 spe
->hdr
.type
= cpu_to_le16(type
);
3418 spe
->data
.update_data_addr
.hi
= cpu_to_le32(data_hi
);
3419 spe
->data
.update_data_addr
.lo
= cpu_to_le32(data_lo
);
3422 * It's ok if the actual decrement is issued towards the memory
3423 * somewhere between the spin_lock and spin_unlock. Thus no
3424 * more explict memory barrier is needed.
3427 atomic_dec(&bp
->eq_spq_left
);
3429 atomic_dec(&bp
->cq_spq_left
);
3433 "SPQE[%x] (%x:%x) (cmd, common?) (%d,%d) hw_cid %x data (%x:%x) type(0x%x) left (CQ, EQ) (%x,%x)\n",
3434 bp
->spq_prod_idx
, (u32
)U64_HI(bp
->spq_mapping
),
3435 (u32
)(U64_LO(bp
->spq_mapping
) +
3436 (void *)bp
->spq_prod_bd
- (void *)bp
->spq
), command
, common
,
3437 HW_CID(bp
, cid
), data_hi
, data_lo
, type
,
3438 atomic_read(&bp
->cq_spq_left
), atomic_read(&bp
->eq_spq_left
));
3440 bnx2x_sp_prod_update(bp
);
3441 spin_unlock_bh(&bp
->spq_lock
);
3445 /* acquire split MCP access lock register */
3446 static int bnx2x_acquire_alr(struct bnx2x
*bp
)
3452 for (j
= 0; j
< 1000; j
++) {
3454 REG_WR(bp
, GRCBASE_MCP
+ 0x9c, val
);
3455 val
= REG_RD(bp
, GRCBASE_MCP
+ 0x9c);
3456 if (val
& (1L << 31))
3461 if (!(val
& (1L << 31))) {
3462 BNX2X_ERR("Cannot acquire MCP access lock register\n");
3469 /* release split MCP access lock register */
3470 static void bnx2x_release_alr(struct bnx2x
*bp
)
3472 REG_WR(bp
, GRCBASE_MCP
+ 0x9c, 0);
3475 #define BNX2X_DEF_SB_ATT_IDX 0x0001
3476 #define BNX2X_DEF_SB_IDX 0x0002
3478 static u16
bnx2x_update_dsb_idx(struct bnx2x
*bp
)
3480 struct host_sp_status_block
*def_sb
= bp
->def_status_blk
;
3483 barrier(); /* status block is written to by the chip */
3484 if (bp
->def_att_idx
!= def_sb
->atten_status_block
.attn_bits_index
) {
3485 bp
->def_att_idx
= def_sb
->atten_status_block
.attn_bits_index
;
3486 rc
|= BNX2X_DEF_SB_ATT_IDX
;
3489 if (bp
->def_idx
!= def_sb
->sp_sb
.running_index
) {
3490 bp
->def_idx
= def_sb
->sp_sb
.running_index
;
3491 rc
|= BNX2X_DEF_SB_IDX
;
3494 /* Do not reorder: indecies reading should complete before handling */
3500 * slow path service functions
3503 static void bnx2x_attn_int_asserted(struct bnx2x
*bp
, u32 asserted
)
3505 int port
= BP_PORT(bp
);
3506 u32 aeu_addr
= port
? MISC_REG_AEU_MASK_ATTN_FUNC_1
:
3507 MISC_REG_AEU_MASK_ATTN_FUNC_0
;
3508 u32 nig_int_mask_addr
= port
? NIG_REG_MASK_INTERRUPT_PORT1
:
3509 NIG_REG_MASK_INTERRUPT_PORT0
;
3514 if (bp
->attn_state
& asserted
)
3515 BNX2X_ERR("IGU ERROR\n");
3517 bnx2x_acquire_hw_lock(bp
, HW_LOCK_RESOURCE_PORT0_ATT_MASK
+ port
);
3518 aeu_mask
= REG_RD(bp
, aeu_addr
);
3520 DP(NETIF_MSG_HW
, "aeu_mask %x newly asserted %x\n",
3521 aeu_mask
, asserted
);
3522 aeu_mask
&= ~(asserted
& 0x3ff);
3523 DP(NETIF_MSG_HW
, "new mask %x\n", aeu_mask
);
3525 REG_WR(bp
, aeu_addr
, aeu_mask
);
3526 bnx2x_release_hw_lock(bp
, HW_LOCK_RESOURCE_PORT0_ATT_MASK
+ port
);
3528 DP(NETIF_MSG_HW
, "attn_state %x\n", bp
->attn_state
);
3529 bp
->attn_state
|= asserted
;
3530 DP(NETIF_MSG_HW
, "new state %x\n", bp
->attn_state
);
3532 if (asserted
& ATTN_HARD_WIRED_MASK
) {
3533 if (asserted
& ATTN_NIG_FOR_FUNC
) {
3535 bnx2x_acquire_phy_lock(bp
);
3537 /* save nig interrupt mask */
3538 nig_mask
= REG_RD(bp
, nig_int_mask_addr
);
3540 /* If nig_mask is not set, no need to call the update
3544 REG_WR(bp
, nig_int_mask_addr
, 0);
3546 bnx2x_link_attn(bp
);
3549 /* handle unicore attn? */
3551 if (asserted
& ATTN_SW_TIMER_4_FUNC
)
3552 DP(NETIF_MSG_HW
, "ATTN_SW_TIMER_4_FUNC!\n");
3554 if (asserted
& GPIO_2_FUNC
)
3555 DP(NETIF_MSG_HW
, "GPIO_2_FUNC!\n");
3557 if (asserted
& GPIO_3_FUNC
)
3558 DP(NETIF_MSG_HW
, "GPIO_3_FUNC!\n");
3560 if (asserted
& GPIO_4_FUNC
)
3561 DP(NETIF_MSG_HW
, "GPIO_4_FUNC!\n");
3564 if (asserted
& ATTN_GENERAL_ATTN_1
) {
3565 DP(NETIF_MSG_HW
, "ATTN_GENERAL_ATTN_1!\n");
3566 REG_WR(bp
, MISC_REG_AEU_GENERAL_ATTN_1
, 0x0);
3568 if (asserted
& ATTN_GENERAL_ATTN_2
) {
3569 DP(NETIF_MSG_HW
, "ATTN_GENERAL_ATTN_2!\n");
3570 REG_WR(bp
, MISC_REG_AEU_GENERAL_ATTN_2
, 0x0);
3572 if (asserted
& ATTN_GENERAL_ATTN_3
) {
3573 DP(NETIF_MSG_HW
, "ATTN_GENERAL_ATTN_3!\n");
3574 REG_WR(bp
, MISC_REG_AEU_GENERAL_ATTN_3
, 0x0);
3577 if (asserted
& ATTN_GENERAL_ATTN_4
) {
3578 DP(NETIF_MSG_HW
, "ATTN_GENERAL_ATTN_4!\n");
3579 REG_WR(bp
, MISC_REG_AEU_GENERAL_ATTN_4
, 0x0);
3581 if (asserted
& ATTN_GENERAL_ATTN_5
) {
3582 DP(NETIF_MSG_HW
, "ATTN_GENERAL_ATTN_5!\n");
3583 REG_WR(bp
, MISC_REG_AEU_GENERAL_ATTN_5
, 0x0);
3585 if (asserted
& ATTN_GENERAL_ATTN_6
) {
3586 DP(NETIF_MSG_HW
, "ATTN_GENERAL_ATTN_6!\n");
3587 REG_WR(bp
, MISC_REG_AEU_GENERAL_ATTN_6
, 0x0);
3591 } /* if hardwired */
3593 if (bp
->common
.int_block
== INT_BLOCK_HC
)
3594 reg_addr
= (HC_REG_COMMAND_REG
+ port
*32 +
3595 COMMAND_REG_ATTN_BITS_SET
);
3597 reg_addr
= (BAR_IGU_INTMEM
+ IGU_CMD_ATTN_BIT_SET_UPPER
*8);
3599 DP(NETIF_MSG_HW
, "about to mask 0x%08x at %s addr 0x%x\n", asserted
,
3600 (bp
->common
.int_block
== INT_BLOCK_HC
) ? "HC" : "IGU", reg_addr
);
3601 REG_WR(bp
, reg_addr
, asserted
);
3603 /* now set back the mask */
3604 if (asserted
& ATTN_NIG_FOR_FUNC
) {
3605 /* Verify that IGU ack through BAR was written before restoring
3606 * NIG mask. This loop should exit after 2-3 iterations max.
3608 if (bp
->common
.int_block
!= INT_BLOCK_HC
) {
3609 u32 cnt
= 0, igu_acked
;
3611 igu_acked
= REG_RD(bp
,
3612 IGU_REG_ATTENTION_ACK_BITS
);
3613 } while (((igu_acked
& ATTN_NIG_FOR_FUNC
) == 0) &&
3614 (++cnt
< MAX_IGU_ATTN_ACK_TO
));
3617 "Failed to verify IGU ack on time\n");
3620 REG_WR(bp
, nig_int_mask_addr
, nig_mask
);
3621 bnx2x_release_phy_lock(bp
);
3625 static void bnx2x_fan_failure(struct bnx2x
*bp
)
3627 int port
= BP_PORT(bp
);
3629 /* mark the failure */
3632 dev_info
.port_hw_config
[port
].external_phy_config
);
3634 ext_phy_config
&= ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK
;
3635 ext_phy_config
|= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE
;
3636 SHMEM_WR(bp
, dev_info
.port_hw_config
[port
].external_phy_config
,
3639 /* log the failure */
3640 netdev_err(bp
->dev
, "Fan Failure on Network Controller has caused the driver to shutdown the card to prevent permanent damage.\n"
3641 "Please contact OEM Support for assistance\n");
3644 * Scheudle device reset (unload)
3645 * This is due to some boards consuming sufficient power when driver is
3646 * up to overheat if fan fails.
3648 smp_mb__before_clear_bit();
3649 set_bit(BNX2X_SP_RTNL_FAN_FAILURE
, &bp
->sp_rtnl_state
);
3650 smp_mb__after_clear_bit();
3651 schedule_delayed_work(&bp
->sp_rtnl_task
, 0);
3655 static void bnx2x_attn_int_deasserted0(struct bnx2x
*bp
, u32 attn
)
3657 int port
= BP_PORT(bp
);
3661 reg_offset
= (port
? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0
:
3662 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0
);
3664 if (attn
& AEU_INPUTS_ATTN_BITS_SPIO5
) {
3666 val
= REG_RD(bp
, reg_offset
);
3667 val
&= ~AEU_INPUTS_ATTN_BITS_SPIO5
;
3668 REG_WR(bp
, reg_offset
, val
);
3670 BNX2X_ERR("SPIO5 hw attention\n");
3672 /* Fan failure attention */
3673 bnx2x_hw_reset_phy(&bp
->link_params
);
3674 bnx2x_fan_failure(bp
);
3677 if ((attn
& bp
->link_vars
.aeu_int_mask
) && bp
->port
.pmf
) {
3678 bnx2x_acquire_phy_lock(bp
);
3679 bnx2x_handle_module_detect_int(&bp
->link_params
);
3680 bnx2x_release_phy_lock(bp
);
3683 if (attn
& HW_INTERRUT_ASSERT_SET_0
) {
3685 val
= REG_RD(bp
, reg_offset
);
3686 val
&= ~(attn
& HW_INTERRUT_ASSERT_SET_0
);
3687 REG_WR(bp
, reg_offset
, val
);
3689 BNX2X_ERR("FATAL HW block attention set0 0x%x\n",
3690 (u32
)(attn
& HW_INTERRUT_ASSERT_SET_0
));
3695 static void bnx2x_attn_int_deasserted1(struct bnx2x
*bp
, u32 attn
)
3699 if (attn
& AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT
) {
3701 val
= REG_RD(bp
, DORQ_REG_DORQ_INT_STS_CLR
);
3702 BNX2X_ERR("DB hw attention 0x%x\n", val
);
3703 /* DORQ discard attention */
3705 BNX2X_ERR("FATAL error from DORQ\n");
3708 if (attn
& HW_INTERRUT_ASSERT_SET_1
) {
3710 int port
= BP_PORT(bp
);
3713 reg_offset
= (port
? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1
:
3714 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1
);
3716 val
= REG_RD(bp
, reg_offset
);
3717 val
&= ~(attn
& HW_INTERRUT_ASSERT_SET_1
);
3718 REG_WR(bp
, reg_offset
, val
);
3720 BNX2X_ERR("FATAL HW block attention set1 0x%x\n",
3721 (u32
)(attn
& HW_INTERRUT_ASSERT_SET_1
));
3726 static void bnx2x_attn_int_deasserted2(struct bnx2x
*bp
, u32 attn
)
3730 if (attn
& AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT
) {
3732 val
= REG_RD(bp
, CFC_REG_CFC_INT_STS_CLR
);
3733 BNX2X_ERR("CFC hw attention 0x%x\n", val
);
3734 /* CFC error attention */
3736 BNX2X_ERR("FATAL error from CFC\n");
3739 if (attn
& AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT
) {
3740 val
= REG_RD(bp
, PXP_REG_PXP_INT_STS_CLR_0
);
3741 BNX2X_ERR("PXP hw attention-0 0x%x\n", val
);
3742 /* RQ_USDMDP_FIFO_OVERFLOW */
3744 BNX2X_ERR("FATAL error from PXP\n");
3746 if (!CHIP_IS_E1x(bp
)) {
3747 val
= REG_RD(bp
, PXP_REG_PXP_INT_STS_CLR_1
);
3748 BNX2X_ERR("PXP hw attention-1 0x%x\n", val
);
3752 if (attn
& HW_INTERRUT_ASSERT_SET_2
) {
3754 int port
= BP_PORT(bp
);
3757 reg_offset
= (port
? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2
:
3758 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2
);
3760 val
= REG_RD(bp
, reg_offset
);
3761 val
&= ~(attn
& HW_INTERRUT_ASSERT_SET_2
);
3762 REG_WR(bp
, reg_offset
, val
);
3764 BNX2X_ERR("FATAL HW block attention set2 0x%x\n",
3765 (u32
)(attn
& HW_INTERRUT_ASSERT_SET_2
));
3770 static void bnx2x_attn_int_deasserted3(struct bnx2x
*bp
, u32 attn
)
3774 if (attn
& EVEREST_GEN_ATTN_IN_USE_MASK
) {
3776 if (attn
& BNX2X_PMF_LINK_ASSERT
) {
3777 int func
= BP_FUNC(bp
);
3779 REG_WR(bp
, MISC_REG_AEU_GENERAL_ATTN_12
+ func
*4, 0);
3780 bnx2x_read_mf_cfg(bp
);
3781 bp
->mf_config
[BP_VN(bp
)] = MF_CFG_RD(bp
,
3782 func_mf_config
[BP_ABS_FUNC(bp
)].config
);
3784 func_mb
[BP_FW_MB_IDX(bp
)].drv_status
);
3785 if (val
& DRV_STATUS_DCC_EVENT_MASK
)
3787 (val
& DRV_STATUS_DCC_EVENT_MASK
));
3789 if (val
& DRV_STATUS_SET_MF_BW
)
3790 bnx2x_set_mf_bw(bp
);
3792 if (val
& DRV_STATUS_DRV_INFO_REQ
)
3793 bnx2x_handle_drv_info_req(bp
);
3794 if ((bp
->port
.pmf
== 0) && (val
& DRV_STATUS_PMF
))
3795 bnx2x_pmf_update(bp
);
3798 (val
& DRV_STATUS_DCBX_NEGOTIATION_RESULTS
) &&
3799 bp
->dcbx_enabled
> 0)
3800 /* start dcbx state machine */
3801 bnx2x_dcbx_set_params(bp
,
3802 BNX2X_DCBX_STATE_NEG_RECEIVED
);
3803 if (val
& DRV_STATUS_AFEX_EVENT_MASK
)
3804 bnx2x_handle_afex_cmd(bp
,
3805 val
& DRV_STATUS_AFEX_EVENT_MASK
);
3806 if (val
& DRV_STATUS_EEE_NEGOTIATION_RESULTS
)
3807 bnx2x_handle_eee_event(bp
);
3808 if (bp
->link_vars
.periodic_flags
&
3809 PERIODIC_FLAGS_LINK_EVENT
) {
3810 /* sync with link */
3811 bnx2x_acquire_phy_lock(bp
);
3812 bp
->link_vars
.periodic_flags
&=
3813 ~PERIODIC_FLAGS_LINK_EVENT
;
3814 bnx2x_release_phy_lock(bp
);
3816 bnx2x_link_sync_notify(bp
);
3817 bnx2x_link_report(bp
);
3819 /* Always call it here: bnx2x_link_report() will
3820 * prevent the link indication duplication.
3822 bnx2x__link_status_update(bp
);
3823 } else if (attn
& BNX2X_MC_ASSERT_BITS
) {
3825 BNX2X_ERR("MC assert!\n");
3826 bnx2x_mc_assert(bp
);
3827 REG_WR(bp
, MISC_REG_AEU_GENERAL_ATTN_10
, 0);
3828 REG_WR(bp
, MISC_REG_AEU_GENERAL_ATTN_9
, 0);
3829 REG_WR(bp
, MISC_REG_AEU_GENERAL_ATTN_8
, 0);
3830 REG_WR(bp
, MISC_REG_AEU_GENERAL_ATTN_7
, 0);
3833 } else if (attn
& BNX2X_MCP_ASSERT
) {
3835 BNX2X_ERR("MCP assert!\n");
3836 REG_WR(bp
, MISC_REG_AEU_GENERAL_ATTN_11
, 0);
3840 BNX2X_ERR("Unknown HW assert! (attn 0x%x)\n", attn
);
3843 if (attn
& EVEREST_LATCHED_ATTN_IN_USE_MASK
) {
3844 BNX2X_ERR("LATCHED attention 0x%08x (masked)\n", attn
);
3845 if (attn
& BNX2X_GRC_TIMEOUT
) {
3846 val
= CHIP_IS_E1(bp
) ? 0 :
3847 REG_RD(bp
, MISC_REG_GRC_TIMEOUT_ATTN
);
3848 BNX2X_ERR("GRC time-out 0x%08x\n", val
);
3850 if (attn
& BNX2X_GRC_RSV
) {
3851 val
= CHIP_IS_E1(bp
) ? 0 :
3852 REG_RD(bp
, MISC_REG_GRC_RSV_ATTN
);
3853 BNX2X_ERR("GRC reserved 0x%08x\n", val
);
3855 REG_WR(bp
, MISC_REG_AEU_CLR_LATCH_SIGNAL
, 0x7ff);
3861 * 0-7 - Engine0 load counter.
3862 * 8-15 - Engine1 load counter.
3863 * 16 - Engine0 RESET_IN_PROGRESS bit.
3864 * 17 - Engine1 RESET_IN_PROGRESS bit.
3865 * 18 - Engine0 ONE_IS_LOADED. Set when there is at least one active function
3867 * 19 - Engine1 ONE_IS_LOADED.
3868 * 20 - Chip reset flow bit. When set none-leader must wait for both engines
3869 * leader to complete (check for both RESET_IN_PROGRESS bits and not for
3870 * just the one belonging to its engine).
3873 #define BNX2X_RECOVERY_GLOB_REG MISC_REG_GENERIC_POR_1
3875 #define BNX2X_PATH0_LOAD_CNT_MASK 0x000000ff
3876 #define BNX2X_PATH0_LOAD_CNT_SHIFT 0
3877 #define BNX2X_PATH1_LOAD_CNT_MASK 0x0000ff00
3878 #define BNX2X_PATH1_LOAD_CNT_SHIFT 8
3879 #define BNX2X_PATH0_RST_IN_PROG_BIT 0x00010000
3880 #define BNX2X_PATH1_RST_IN_PROG_BIT 0x00020000
3881 #define BNX2X_GLOBAL_RESET_BIT 0x00040000
3884 * Set the GLOBAL_RESET bit.
3886 * Should be run under rtnl lock
3888 void bnx2x_set_reset_global(struct bnx2x
*bp
)
3891 bnx2x_acquire_hw_lock(bp
, HW_LOCK_RESOURCE_RECOVERY_REG
);
3892 val
= REG_RD(bp
, BNX2X_RECOVERY_GLOB_REG
);
3893 REG_WR(bp
, BNX2X_RECOVERY_GLOB_REG
, val
| BNX2X_GLOBAL_RESET_BIT
);
3894 bnx2x_release_hw_lock(bp
, HW_LOCK_RESOURCE_RECOVERY_REG
);
3898 * Clear the GLOBAL_RESET bit.
3900 * Should be run under rtnl lock
3902 static void bnx2x_clear_reset_global(struct bnx2x
*bp
)
3905 bnx2x_acquire_hw_lock(bp
, HW_LOCK_RESOURCE_RECOVERY_REG
);
3906 val
= REG_RD(bp
, BNX2X_RECOVERY_GLOB_REG
);
3907 REG_WR(bp
, BNX2X_RECOVERY_GLOB_REG
, val
& (~BNX2X_GLOBAL_RESET_BIT
));
3908 bnx2x_release_hw_lock(bp
, HW_LOCK_RESOURCE_RECOVERY_REG
);
3912 * Checks the GLOBAL_RESET bit.
3914 * should be run under rtnl lock
3916 static bool bnx2x_reset_is_global(struct bnx2x
*bp
)
3918 u32 val
= REG_RD(bp
, BNX2X_RECOVERY_GLOB_REG
);
3920 DP(NETIF_MSG_HW
, "GEN_REG_VAL=0x%08x\n", val
);
3921 return (val
& BNX2X_GLOBAL_RESET_BIT
) ? true : false;
3925 * Clear RESET_IN_PROGRESS bit for the current engine.
3927 * Should be run under rtnl lock
3929 static void bnx2x_set_reset_done(struct bnx2x
*bp
)
3932 u32 bit
= BP_PATH(bp
) ?
3933 BNX2X_PATH1_RST_IN_PROG_BIT
: BNX2X_PATH0_RST_IN_PROG_BIT
;
3934 bnx2x_acquire_hw_lock(bp
, HW_LOCK_RESOURCE_RECOVERY_REG
);
3935 val
= REG_RD(bp
, BNX2X_RECOVERY_GLOB_REG
);
3939 REG_WR(bp
, BNX2X_RECOVERY_GLOB_REG
, val
);
3941 bnx2x_release_hw_lock(bp
, HW_LOCK_RESOURCE_RECOVERY_REG
);
3945 * Set RESET_IN_PROGRESS for the current engine.
3947 * should be run under rtnl lock
3949 void bnx2x_set_reset_in_progress(struct bnx2x
*bp
)
3952 u32 bit
= BP_PATH(bp
) ?
3953 BNX2X_PATH1_RST_IN_PROG_BIT
: BNX2X_PATH0_RST_IN_PROG_BIT
;
3954 bnx2x_acquire_hw_lock(bp
, HW_LOCK_RESOURCE_RECOVERY_REG
);
3955 val
= REG_RD(bp
, BNX2X_RECOVERY_GLOB_REG
);
3959 REG_WR(bp
, BNX2X_RECOVERY_GLOB_REG
, val
);
3960 bnx2x_release_hw_lock(bp
, HW_LOCK_RESOURCE_RECOVERY_REG
);
3964 * Checks the RESET_IN_PROGRESS bit for the given engine.
3965 * should be run under rtnl lock
3967 bool bnx2x_reset_is_done(struct bnx2x
*bp
, int engine
)
3969 u32 val
= REG_RD(bp
, BNX2X_RECOVERY_GLOB_REG
);
3971 BNX2X_PATH1_RST_IN_PROG_BIT
: BNX2X_PATH0_RST_IN_PROG_BIT
;
3973 /* return false if bit is set */
3974 return (val
& bit
) ? false : true;
3978 * set pf load for the current pf.
3980 * should be run under rtnl lock
3982 void bnx2x_set_pf_load(struct bnx2x
*bp
)
3985 u32 mask
= BP_PATH(bp
) ? BNX2X_PATH1_LOAD_CNT_MASK
:
3986 BNX2X_PATH0_LOAD_CNT_MASK
;
3987 u32 shift
= BP_PATH(bp
) ? BNX2X_PATH1_LOAD_CNT_SHIFT
:
3988 BNX2X_PATH0_LOAD_CNT_SHIFT
;
3990 bnx2x_acquire_hw_lock(bp
, HW_LOCK_RESOURCE_RECOVERY_REG
);
3991 val
= REG_RD(bp
, BNX2X_RECOVERY_GLOB_REG
);
3993 DP(NETIF_MSG_IFUP
, "Old GEN_REG_VAL=0x%08x\n", val
);
3995 /* get the current counter value */
3996 val1
= (val
& mask
) >> shift
;
3998 /* set bit of that PF */
3999 val1
|= (1 << bp
->pf_num
);
4001 /* clear the old value */
4004 /* set the new one */
4005 val
|= ((val1
<< shift
) & mask
);
4007 REG_WR(bp
, BNX2X_RECOVERY_GLOB_REG
, val
);
4008 bnx2x_release_hw_lock(bp
, HW_LOCK_RESOURCE_RECOVERY_REG
);
4012 * bnx2x_clear_pf_load - clear pf load mark
4014 * @bp: driver handle
4016 * Should be run under rtnl lock.
4017 * Decrements the load counter for the current engine. Returns
4018 * whether other functions are still loaded
4020 bool bnx2x_clear_pf_load(struct bnx2x
*bp
)
4023 u32 mask
= BP_PATH(bp
) ? BNX2X_PATH1_LOAD_CNT_MASK
:
4024 BNX2X_PATH0_LOAD_CNT_MASK
;
4025 u32 shift
= BP_PATH(bp
) ? BNX2X_PATH1_LOAD_CNT_SHIFT
:
4026 BNX2X_PATH0_LOAD_CNT_SHIFT
;
4028 bnx2x_acquire_hw_lock(bp
, HW_LOCK_RESOURCE_RECOVERY_REG
);
4029 val
= REG_RD(bp
, BNX2X_RECOVERY_GLOB_REG
);
4030 DP(NETIF_MSG_IFDOWN
, "Old GEN_REG_VAL=0x%08x\n", val
);
4032 /* get the current counter value */
4033 val1
= (val
& mask
) >> shift
;
4035 /* clear bit of that PF */
4036 val1
&= ~(1 << bp
->pf_num
);
4038 /* clear the old value */
4041 /* set the new one */
4042 val
|= ((val1
<< shift
) & mask
);
4044 REG_WR(bp
, BNX2X_RECOVERY_GLOB_REG
, val
);
4045 bnx2x_release_hw_lock(bp
, HW_LOCK_RESOURCE_RECOVERY_REG
);
4050 * Read the load status for the current engine.
4052 * should be run under rtnl lock
4054 static bool bnx2x_get_load_status(struct bnx2x
*bp
, int engine
)
4056 u32 mask
= (engine
? BNX2X_PATH1_LOAD_CNT_MASK
:
4057 BNX2X_PATH0_LOAD_CNT_MASK
);
4058 u32 shift
= (engine
? BNX2X_PATH1_LOAD_CNT_SHIFT
:
4059 BNX2X_PATH0_LOAD_CNT_SHIFT
);
4060 u32 val
= REG_RD(bp
, BNX2X_RECOVERY_GLOB_REG
);
4062 DP(NETIF_MSG_HW
| NETIF_MSG_IFUP
, "GLOB_REG=0x%08x\n", val
);
4064 val
= (val
& mask
) >> shift
;
4066 DP(NETIF_MSG_HW
| NETIF_MSG_IFUP
, "load mask for engine %d = 0x%x\n",
4072 static void _print_next_block(int idx
, const char *blk
)
4074 pr_cont("%s%s", idx
? ", " : "", blk
);
4077 static int bnx2x_check_blocks_with_parity0(u32 sig
, int par_num
,
4082 for (i
= 0; sig
; i
++) {
4083 cur_bit
= ((u32
)0x1 << i
);
4084 if (sig
& cur_bit
) {
4086 case AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR
:
4088 _print_next_block(par_num
++, "BRB");
4090 case AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR
:
4092 _print_next_block(par_num
++, "PARSER");
4094 case AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR
:
4096 _print_next_block(par_num
++, "TSDM");
4098 case AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR
:
4100 _print_next_block(par_num
++,
4103 case AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR
:
4105 _print_next_block(par_num
++, "TCM");
4107 case AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR
:
4109 _print_next_block(par_num
++, "TSEMI");
4111 case AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR
:
4113 _print_next_block(par_num
++, "XPB");
4125 static int bnx2x_check_blocks_with_parity1(u32 sig
, int par_num
,
4126 bool *global
, bool print
)
4130 for (i
= 0; sig
; i
++) {
4131 cur_bit
= ((u32
)0x1 << i
);
4132 if (sig
& cur_bit
) {
4134 case AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR
:
4136 _print_next_block(par_num
++, "PBF");
4138 case AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR
:
4140 _print_next_block(par_num
++, "QM");
4142 case AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR
:
4144 _print_next_block(par_num
++, "TM");
4146 case AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR
:
4148 _print_next_block(par_num
++, "XSDM");
4150 case AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR
:
4152 _print_next_block(par_num
++, "XCM");
4154 case AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR
:
4156 _print_next_block(par_num
++, "XSEMI");
4158 case AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR
:
4160 _print_next_block(par_num
++,
4163 case AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR
:
4165 _print_next_block(par_num
++, "NIG");
4167 case AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR
:
4169 _print_next_block(par_num
++,
4173 case AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR
:
4175 _print_next_block(par_num
++, "DEBUG");
4177 case AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR
:
4179 _print_next_block(par_num
++, "USDM");
4181 case AEU_INPUTS_ATTN_BITS_UCM_PARITY_ERROR
:
4183 _print_next_block(par_num
++, "UCM");
4185 case AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR
:
4187 _print_next_block(par_num
++, "USEMI");
4189 case AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR
:
4191 _print_next_block(par_num
++, "UPB");
4193 case AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR
:
4195 _print_next_block(par_num
++, "CSDM");
4197 case AEU_INPUTS_ATTN_BITS_CCM_PARITY_ERROR
:
4199 _print_next_block(par_num
++, "CCM");
4211 static int bnx2x_check_blocks_with_parity2(u32 sig
, int par_num
,
4216 for (i
= 0; sig
; i
++) {
4217 cur_bit
= ((u32
)0x1 << i
);
4218 if (sig
& cur_bit
) {
4220 case AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR
:
4222 _print_next_block(par_num
++, "CSEMI");
4224 case AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR
:
4226 _print_next_block(par_num
++, "PXP");
4228 case AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR
:
4230 _print_next_block(par_num
++,
4231 "PXPPCICLOCKCLIENT");
4233 case AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR
:
4235 _print_next_block(par_num
++, "CFC");
4237 case AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR
:
4239 _print_next_block(par_num
++, "CDU");
4241 case AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR
:
4243 _print_next_block(par_num
++, "DMAE");
4245 case AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR
:
4247 _print_next_block(par_num
++, "IGU");
4249 case AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR
:
4251 _print_next_block(par_num
++, "MISC");
4263 static int bnx2x_check_blocks_with_parity3(u32 sig
, int par_num
,
4264 bool *global
, bool print
)
4268 for (i
= 0; sig
; i
++) {
4269 cur_bit
= ((u32
)0x1 << i
);
4270 if (sig
& cur_bit
) {
4272 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY
:
4274 _print_next_block(par_num
++, "MCP ROM");
4277 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY
:
4279 _print_next_block(par_num
++,
4283 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY
:
4285 _print_next_block(par_num
++,
4289 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY
:
4291 _print_next_block(par_num
++,
4305 static int bnx2x_check_blocks_with_parity4(u32 sig
, int par_num
,
4310 for (i
= 0; sig
; i
++) {
4311 cur_bit
= ((u32
)0x1 << i
);
4312 if (sig
& cur_bit
) {
4314 case AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR
:
4316 _print_next_block(par_num
++, "PGLUE_B");
4318 case AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR
:
4320 _print_next_block(par_num
++, "ATC");
4332 static bool bnx2x_parity_attn(struct bnx2x
*bp
, bool *global
, bool print
,
4335 if ((sig
[0] & HW_PRTY_ASSERT_SET_0
) ||
4336 (sig
[1] & HW_PRTY_ASSERT_SET_1
) ||
4337 (sig
[2] & HW_PRTY_ASSERT_SET_2
) ||
4338 (sig
[3] & HW_PRTY_ASSERT_SET_3
) ||
4339 (sig
[4] & HW_PRTY_ASSERT_SET_4
)) {
4341 DP(NETIF_MSG_HW
, "Was parity error: HW block parity attention:\n"
4342 "[0]:0x%08x [1]:0x%08x [2]:0x%08x [3]:0x%08x [4]:0x%08x\n",
4343 sig
[0] & HW_PRTY_ASSERT_SET_0
,
4344 sig
[1] & HW_PRTY_ASSERT_SET_1
,
4345 sig
[2] & HW_PRTY_ASSERT_SET_2
,
4346 sig
[3] & HW_PRTY_ASSERT_SET_3
,
4347 sig
[4] & HW_PRTY_ASSERT_SET_4
);
4350 "Parity errors detected in blocks: ");
4351 par_num
= bnx2x_check_blocks_with_parity0(
4352 sig
[0] & HW_PRTY_ASSERT_SET_0
, par_num
, print
);
4353 par_num
= bnx2x_check_blocks_with_parity1(
4354 sig
[1] & HW_PRTY_ASSERT_SET_1
, par_num
, global
, print
);
4355 par_num
= bnx2x_check_blocks_with_parity2(
4356 sig
[2] & HW_PRTY_ASSERT_SET_2
, par_num
, print
);
4357 par_num
= bnx2x_check_blocks_with_parity3(
4358 sig
[3] & HW_PRTY_ASSERT_SET_3
, par_num
, global
, print
);
4359 par_num
= bnx2x_check_blocks_with_parity4(
4360 sig
[4] & HW_PRTY_ASSERT_SET_4
, par_num
, print
);
4371 * bnx2x_chk_parity_attn - checks for parity attentions.
4373 * @bp: driver handle
4374 * @global: true if there was a global attention
4375 * @print: show parity attention in syslog
4377 bool bnx2x_chk_parity_attn(struct bnx2x
*bp
, bool *global
, bool print
)
4379 struct attn_route attn
= { {0} };
4380 int port
= BP_PORT(bp
);
4382 attn
.sig
[0] = REG_RD(bp
,
4383 MISC_REG_AEU_AFTER_INVERT_1_FUNC_0
+
4385 attn
.sig
[1] = REG_RD(bp
,
4386 MISC_REG_AEU_AFTER_INVERT_2_FUNC_0
+
4388 attn
.sig
[2] = REG_RD(bp
,
4389 MISC_REG_AEU_AFTER_INVERT_3_FUNC_0
+
4391 attn
.sig
[3] = REG_RD(bp
,
4392 MISC_REG_AEU_AFTER_INVERT_4_FUNC_0
+
4395 if (!CHIP_IS_E1x(bp
))
4396 attn
.sig
[4] = REG_RD(bp
,
4397 MISC_REG_AEU_AFTER_INVERT_5_FUNC_0
+
4400 return bnx2x_parity_attn(bp
, global
, print
, attn
.sig
);
4404 static void bnx2x_attn_int_deasserted4(struct bnx2x
*bp
, u32 attn
)
4407 if (attn
& AEU_INPUTS_ATTN_BITS_PGLUE_HW_INTERRUPT
) {
4409 val
= REG_RD(bp
, PGLUE_B_REG_PGLUE_B_INT_STS_CLR
);
4410 BNX2X_ERR("PGLUE hw attention 0x%x\n", val
);
4411 if (val
& PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR
)
4412 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR\n");
4413 if (val
& PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR
)
4414 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR\n");
4415 if (val
& PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN
)
4416 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN\n");
4417 if (val
& PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN
)
4418 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN\n");
4420 PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN
)
4421 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN\n");
4423 PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN
)
4424 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN\n");
4425 if (val
& PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN
)
4426 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN\n");
4427 if (val
& PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN
)
4428 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN\n");
4429 if (val
& PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW
)
4430 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW\n");
4432 if (attn
& AEU_INPUTS_ATTN_BITS_ATC_HW_INTERRUPT
) {
4433 val
= REG_RD(bp
, ATC_REG_ATC_INT_STS_CLR
);
4434 BNX2X_ERR("ATC hw attention 0x%x\n", val
);
4435 if (val
& ATC_ATC_INT_STS_REG_ADDRESS_ERROR
)
4436 BNX2X_ERR("ATC_ATC_INT_STS_REG_ADDRESS_ERROR\n");
4437 if (val
& ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND
)
4438 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND\n");
4439 if (val
& ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS
)
4440 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS\n");
4441 if (val
& ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT
)
4442 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT\n");
4443 if (val
& ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR
)
4444 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR\n");
4445 if (val
& ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU
)
4446 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU\n");
4449 if (attn
& (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR
|
4450 AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR
)) {
4451 BNX2X_ERR("FATAL parity attention set4 0x%x\n",
4452 (u32
)(attn
& (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR
|
4453 AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR
)));
4458 static void bnx2x_attn_int_deasserted(struct bnx2x
*bp
, u32 deasserted
)
4460 struct attn_route attn
, *group_mask
;
4461 int port
= BP_PORT(bp
);
4466 bool global
= false;
4468 /* need to take HW lock because MCP or other port might also
4469 try to handle this event */
4470 bnx2x_acquire_alr(bp
);
4472 if (bnx2x_chk_parity_attn(bp
, &global
, true)) {
4473 #ifndef BNX2X_STOP_ON_ERROR
4474 bp
->recovery_state
= BNX2X_RECOVERY_INIT
;
4475 schedule_delayed_work(&bp
->sp_rtnl_task
, 0);
4476 /* Disable HW interrupts */
4477 bnx2x_int_disable(bp
);
4478 /* In case of parity errors don't handle attentions so that
4479 * other function would "see" parity errors.
4484 bnx2x_release_alr(bp
);
4488 attn
.sig
[0] = REG_RD(bp
, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0
+ port
*4);
4489 attn
.sig
[1] = REG_RD(bp
, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0
+ port
*4);
4490 attn
.sig
[2] = REG_RD(bp
, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0
+ port
*4);
4491 attn
.sig
[3] = REG_RD(bp
, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0
+ port
*4);
4492 if (!CHIP_IS_E1x(bp
))
4494 REG_RD(bp
, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0
+ port
*4);
4498 DP(NETIF_MSG_HW
, "attn: %08x %08x %08x %08x %08x\n",
4499 attn
.sig
[0], attn
.sig
[1], attn
.sig
[2], attn
.sig
[3], attn
.sig
[4]);
4501 for (index
= 0; index
< MAX_DYNAMIC_ATTN_GRPS
; index
++) {
4502 if (deasserted
& (1 << index
)) {
4503 group_mask
= &bp
->attn_group
[index
];
4505 DP(NETIF_MSG_HW
, "group[%d]: %08x %08x %08x %08x %08x\n",
4507 group_mask
->sig
[0], group_mask
->sig
[1],
4508 group_mask
->sig
[2], group_mask
->sig
[3],
4509 group_mask
->sig
[4]);
4511 bnx2x_attn_int_deasserted4(bp
,
4512 attn
.sig
[4] & group_mask
->sig
[4]);
4513 bnx2x_attn_int_deasserted3(bp
,
4514 attn
.sig
[3] & group_mask
->sig
[3]);
4515 bnx2x_attn_int_deasserted1(bp
,
4516 attn
.sig
[1] & group_mask
->sig
[1]);
4517 bnx2x_attn_int_deasserted2(bp
,
4518 attn
.sig
[2] & group_mask
->sig
[2]);
4519 bnx2x_attn_int_deasserted0(bp
,
4520 attn
.sig
[0] & group_mask
->sig
[0]);
4524 bnx2x_release_alr(bp
);
4526 if (bp
->common
.int_block
== INT_BLOCK_HC
)
4527 reg_addr
= (HC_REG_COMMAND_REG
+ port
*32 +
4528 COMMAND_REG_ATTN_BITS_CLR
);
4530 reg_addr
= (BAR_IGU_INTMEM
+ IGU_CMD_ATTN_BIT_CLR_UPPER
*8);
4533 DP(NETIF_MSG_HW
, "about to mask 0x%08x at %s addr 0x%x\n", val
,
4534 (bp
->common
.int_block
== INT_BLOCK_HC
) ? "HC" : "IGU", reg_addr
);
4535 REG_WR(bp
, reg_addr
, val
);
4537 if (~bp
->attn_state
& deasserted
)
4538 BNX2X_ERR("IGU ERROR\n");
4540 reg_addr
= port
? MISC_REG_AEU_MASK_ATTN_FUNC_1
:
4541 MISC_REG_AEU_MASK_ATTN_FUNC_0
;
4543 bnx2x_acquire_hw_lock(bp
, HW_LOCK_RESOURCE_PORT0_ATT_MASK
+ port
);
4544 aeu_mask
= REG_RD(bp
, reg_addr
);
4546 DP(NETIF_MSG_HW
, "aeu_mask %x newly deasserted %x\n",
4547 aeu_mask
, deasserted
);
4548 aeu_mask
|= (deasserted
& 0x3ff);
4549 DP(NETIF_MSG_HW
, "new mask %x\n", aeu_mask
);
4551 REG_WR(bp
, reg_addr
, aeu_mask
);
4552 bnx2x_release_hw_lock(bp
, HW_LOCK_RESOURCE_PORT0_ATT_MASK
+ port
);
4554 DP(NETIF_MSG_HW
, "attn_state %x\n", bp
->attn_state
);
4555 bp
->attn_state
&= ~deasserted
;
4556 DP(NETIF_MSG_HW
, "new state %x\n", bp
->attn_state
);
4559 static void bnx2x_attn_int(struct bnx2x
*bp
)
4561 /* read local copy of bits */
4562 u32 attn_bits
= le32_to_cpu(bp
->def_status_blk
->atten_status_block
.
4564 u32 attn_ack
= le32_to_cpu(bp
->def_status_blk
->atten_status_block
.
4566 u32 attn_state
= bp
->attn_state
;
4568 /* look for changed bits */
4569 u32 asserted
= attn_bits
& ~attn_ack
& ~attn_state
;
4570 u32 deasserted
= ~attn_bits
& attn_ack
& attn_state
;
4573 "attn_bits %x attn_ack %x asserted %x deasserted %x\n",
4574 attn_bits
, attn_ack
, asserted
, deasserted
);
4576 if (~(attn_bits
^ attn_ack
) & (attn_bits
^ attn_state
))
4577 BNX2X_ERR("BAD attention state\n");
4579 /* handle bits that were raised */
4581 bnx2x_attn_int_asserted(bp
, asserted
);
4584 bnx2x_attn_int_deasserted(bp
, deasserted
);
4587 void bnx2x_igu_ack_sb(struct bnx2x
*bp
, u8 igu_sb_id
, u8 segment
,
4588 u16 index
, u8 op
, u8 update
)
4590 u32 igu_addr
= BAR_IGU_INTMEM
+ (IGU_CMD_INT_ACK_BASE
+ igu_sb_id
)*8;
4592 bnx2x_igu_ack_sb_gen(bp
, igu_sb_id
, segment
, index
, op
, update
,
4596 static void bnx2x_update_eq_prod(struct bnx2x
*bp
, u16 prod
)
4598 /* No memory barriers */
4599 storm_memset_eq_prod(bp
, prod
, BP_FUNC(bp
));
4600 mmiowb(); /* keep prod updates ordered */
4603 static int bnx2x_cnic_handle_cfc_del(struct bnx2x
*bp
, u32 cid
,
4604 union event_ring_elem
*elem
)
4606 u8 err
= elem
->message
.error
;
4608 if (!bp
->cnic_eth_dev
.starting_cid
||
4609 (cid
< bp
->cnic_eth_dev
.starting_cid
&&
4610 cid
!= bp
->cnic_eth_dev
.iscsi_l2_cid
))
4613 DP(BNX2X_MSG_SP
, "got delete ramrod for CNIC CID %d\n", cid
);
4615 if (unlikely(err
)) {
4617 BNX2X_ERR("got delete ramrod for CNIC CID %d with error!\n",
4619 bnx2x_panic_dump(bp
);
4621 bnx2x_cnic_cfc_comp(bp
, cid
, err
);
4625 static void bnx2x_handle_mcast_eqe(struct bnx2x
*bp
)
4627 struct bnx2x_mcast_ramrod_params rparam
;
4630 memset(&rparam
, 0, sizeof(rparam
));
4632 rparam
.mcast_obj
= &bp
->mcast_obj
;
4634 netif_addr_lock_bh(bp
->dev
);
4636 /* Clear pending state for the last command */
4637 bp
->mcast_obj
.raw
.clear_pending(&bp
->mcast_obj
.raw
);
4639 /* If there are pending mcast commands - send them */
4640 if (bp
->mcast_obj
.check_pending(&bp
->mcast_obj
)) {
4641 rc
= bnx2x_config_mcast(bp
, &rparam
, BNX2X_MCAST_CMD_CONT
);
4643 BNX2X_ERR("Failed to send pending mcast commands: %d\n",
4647 netif_addr_unlock_bh(bp
->dev
);
4650 static void bnx2x_handle_classification_eqe(struct bnx2x
*bp
,
4651 union event_ring_elem
*elem
)
4653 unsigned long ramrod_flags
= 0;
4655 u32 cid
= elem
->message
.data
.eth_event
.echo
& BNX2X_SWCID_MASK
;
4656 struct bnx2x_vlan_mac_obj
*vlan_mac_obj
;
4658 /* Always push next commands out, don't wait here */
4659 __set_bit(RAMROD_CONT
, &ramrod_flags
);
4661 switch (elem
->message
.data
.eth_event
.echo
>> BNX2X_SWCID_SHIFT
) {
4662 case BNX2X_FILTER_MAC_PENDING
:
4663 DP(BNX2X_MSG_SP
, "Got SETUP_MAC completions\n");
4664 if (CNIC_LOADED(bp
) && (cid
== BNX2X_ISCSI_ETH_CID(bp
)))
4665 vlan_mac_obj
= &bp
->iscsi_l2_mac_obj
;
4667 vlan_mac_obj
= &bp
->sp_objs
[cid
].mac_obj
;
4670 case BNX2X_FILTER_MCAST_PENDING
:
4671 DP(BNX2X_MSG_SP
, "Got SETUP_MCAST completions\n");
4672 /* This is only relevant for 57710 where multicast MACs are
4673 * configured as unicast MACs using the same ramrod.
4675 bnx2x_handle_mcast_eqe(bp
);
4678 BNX2X_ERR("Unsupported classification command: %d\n",
4679 elem
->message
.data
.eth_event
.echo
);
4683 rc
= vlan_mac_obj
->complete(bp
, vlan_mac_obj
, elem
, &ramrod_flags
);
4686 BNX2X_ERR("Failed to schedule new commands: %d\n", rc
);
4688 DP(BNX2X_MSG_SP
, "Scheduled next pending commands...\n");
4692 static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x
*bp
, bool start
);
4694 static void bnx2x_handle_rx_mode_eqe(struct bnx2x
*bp
)
4696 netif_addr_lock_bh(bp
->dev
);
4698 clear_bit(BNX2X_FILTER_RX_MODE_PENDING
, &bp
->sp_state
);
4700 /* Send rx_mode command again if was requested */
4701 if (test_and_clear_bit(BNX2X_FILTER_RX_MODE_SCHED
, &bp
->sp_state
))
4702 bnx2x_set_storm_rx_mode(bp
);
4703 else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED
,
4705 bnx2x_set_iscsi_eth_rx_mode(bp
, true);
4706 else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED
,
4708 bnx2x_set_iscsi_eth_rx_mode(bp
, false);
4710 netif_addr_unlock_bh(bp
->dev
);
4713 static void bnx2x_after_afex_vif_lists(struct bnx2x
*bp
,
4714 union event_ring_elem
*elem
)
4716 if (elem
->message
.data
.vif_list_event
.echo
== VIF_LIST_RULE_GET
) {
4718 "afex: ramrod completed VIF LIST_GET, addrs 0x%x\n",
4719 elem
->message
.data
.vif_list_event
.func_bit_map
);
4720 bnx2x_fw_command(bp
, DRV_MSG_CODE_AFEX_LISTGET_ACK
,
4721 elem
->message
.data
.vif_list_event
.func_bit_map
);
4722 } else if (elem
->message
.data
.vif_list_event
.echo
==
4723 VIF_LIST_RULE_SET
) {
4724 DP(BNX2X_MSG_SP
, "afex: ramrod completed VIF LIST_SET\n");
4725 bnx2x_fw_command(bp
, DRV_MSG_CODE_AFEX_LISTSET_ACK
, 0);
4729 /* called with rtnl_lock */
4730 static void bnx2x_after_function_update(struct bnx2x
*bp
)
4733 struct bnx2x_fastpath
*fp
;
4734 struct bnx2x_queue_state_params queue_params
= {NULL
};
4735 struct bnx2x_queue_update_params
*q_update_params
=
4736 &queue_params
.params
.update
;
4738 /* Send Q update command with afex vlan removal values for all Qs */
4739 queue_params
.cmd
= BNX2X_Q_CMD_UPDATE
;
4741 /* set silent vlan removal values according to vlan mode */
4742 __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM_CHNG
,
4743 &q_update_params
->update_flags
);
4744 __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM
,
4745 &q_update_params
->update_flags
);
4746 __set_bit(RAMROD_COMP_WAIT
, &queue_params
.ramrod_flags
);
4748 /* in access mode mark mask and value are 0 to strip all vlans */
4749 if (bp
->afex_vlan_mode
== FUNC_MF_CFG_AFEX_VLAN_ACCESS_MODE
) {
4750 q_update_params
->silent_removal_value
= 0;
4751 q_update_params
->silent_removal_mask
= 0;
4753 q_update_params
->silent_removal_value
=
4754 (bp
->afex_def_vlan_tag
& VLAN_VID_MASK
);
4755 q_update_params
->silent_removal_mask
= VLAN_VID_MASK
;
4758 for_each_eth_queue(bp
, q
) {
4759 /* Set the appropriate Queue object */
4761 queue_params
.q_obj
= &bnx2x_sp_obj(bp
, fp
).q_obj
;
4763 /* send the ramrod */
4764 rc
= bnx2x_queue_state_change(bp
, &queue_params
);
4766 BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
4771 fp
= &bp
->fp
[FCOE_IDX(bp
)];
4772 queue_params
.q_obj
= &bnx2x_sp_obj(bp
, fp
).q_obj
;
4774 /* clear pending completion bit */
4775 __clear_bit(RAMROD_COMP_WAIT
, &queue_params
.ramrod_flags
);
4777 /* mark latest Q bit */
4778 smp_mb__before_clear_bit();
4779 set_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING
, &bp
->sp_state
);
4780 smp_mb__after_clear_bit();
4782 /* send Q update ramrod for FCoE Q */
4783 rc
= bnx2x_queue_state_change(bp
, &queue_params
);
4785 BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
4788 /* If no FCoE ring - ACK MCP now */
4789 bnx2x_link_report(bp
);
4790 bnx2x_fw_command(bp
, DRV_MSG_CODE_AFEX_VIFSET_ACK
, 0);
4794 static struct bnx2x_queue_sp_obj
*bnx2x_cid_to_q_obj(
4795 struct bnx2x
*bp
, u32 cid
)
4797 DP(BNX2X_MSG_SP
, "retrieving fp from cid %d\n", cid
);
4799 if (CNIC_LOADED(bp
) && (cid
== BNX2X_FCOE_ETH_CID(bp
)))
4800 return &bnx2x_fcoe_sp_obj(bp
, q_obj
);
4802 return &bp
->sp_objs
[CID_TO_FP(cid
, bp
)].q_obj
;
4805 static void bnx2x_eq_int(struct bnx2x
*bp
)
4807 u16 hw_cons
, sw_cons
, sw_prod
;
4808 union event_ring_elem
*elem
;
4813 struct bnx2x_queue_sp_obj
*q_obj
;
4814 struct bnx2x_func_sp_obj
*f_obj
= &bp
->func_obj
;
4815 struct bnx2x_raw_obj
*rss_raw
= &bp
->rss_conf_obj
.raw
;
4817 hw_cons
= le16_to_cpu(*bp
->eq_cons_sb
);
4819 /* The hw_cos range is 1-255, 257 - the sw_cons range is 0-254, 256.
4820 * when we get the the next-page we nned to adjust so the loop
4821 * condition below will be met. The next element is the size of a
4822 * regular element and hence incrementing by 1
4824 if ((hw_cons
& EQ_DESC_MAX_PAGE
) == EQ_DESC_MAX_PAGE
)
4827 /* This function may never run in parallel with itself for a
4828 * specific bp, thus there is no need in "paired" read memory
4831 sw_cons
= bp
->eq_cons
;
4832 sw_prod
= bp
->eq_prod
;
4834 DP(BNX2X_MSG_SP
, "EQ: hw_cons %u sw_cons %u bp->eq_spq_left %x\n",
4835 hw_cons
, sw_cons
, atomic_read(&bp
->eq_spq_left
));
4837 for (; sw_cons
!= hw_cons
;
4838 sw_prod
= NEXT_EQ_IDX(sw_prod
), sw_cons
= NEXT_EQ_IDX(sw_cons
)) {
4841 elem
= &bp
->eq_ring
[EQ_DESC(sw_cons
)];
4843 cid
= SW_CID(elem
->message
.data
.cfc_del_event
.cid
);
4844 opcode
= elem
->message
.opcode
;
4847 /* handle eq element */
4849 case EVENT_RING_OPCODE_STAT_QUERY
:
4850 DP(BNX2X_MSG_SP
| BNX2X_MSG_STATS
,
4851 "got statistics comp event %d\n",
4853 /* nothing to do with stats comp */
4856 case EVENT_RING_OPCODE_CFC_DEL
:
4857 /* handle according to cid range */
4859 * we may want to verify here that the bp state is
4863 "got delete ramrod for MULTI[%d]\n", cid
);
4865 if (CNIC_LOADED(bp
) &&
4866 !bnx2x_cnic_handle_cfc_del(bp
, cid
, elem
))
4869 q_obj
= bnx2x_cid_to_q_obj(bp
, cid
);
4871 if (q_obj
->complete_cmd(bp
, q_obj
, BNX2X_Q_CMD_CFC_DEL
))
4878 case EVENT_RING_OPCODE_STOP_TRAFFIC
:
4879 DP(BNX2X_MSG_SP
| BNX2X_MSG_DCB
, "got STOP TRAFFIC\n");
4880 if (f_obj
->complete_cmd(bp
, f_obj
,
4881 BNX2X_F_CMD_TX_STOP
))
4883 bnx2x_dcbx_set_params(bp
, BNX2X_DCBX_STATE_TX_PAUSED
);
4886 case EVENT_RING_OPCODE_START_TRAFFIC
:
4887 DP(BNX2X_MSG_SP
| BNX2X_MSG_DCB
, "got START TRAFFIC\n");
4888 if (f_obj
->complete_cmd(bp
, f_obj
,
4889 BNX2X_F_CMD_TX_START
))
4891 bnx2x_dcbx_set_params(bp
, BNX2X_DCBX_STATE_TX_RELEASED
);
4894 case EVENT_RING_OPCODE_FUNCTION_UPDATE
:
4895 echo
= elem
->message
.data
.function_update_event
.echo
;
4896 if (echo
== SWITCH_UPDATE
) {
4897 DP(BNX2X_MSG_SP
| NETIF_MSG_IFUP
,
4898 "got FUNC_SWITCH_UPDATE ramrod\n");
4899 if (f_obj
->complete_cmd(
4900 bp
, f_obj
, BNX2X_F_CMD_SWITCH_UPDATE
))
4904 DP(BNX2X_MSG_SP
| BNX2X_MSG_MCP
,
4905 "AFEX: ramrod completed FUNCTION_UPDATE\n");
4906 f_obj
->complete_cmd(bp
, f_obj
,
4907 BNX2X_F_CMD_AFEX_UPDATE
);
4909 /* We will perform the Queues update from
4910 * sp_rtnl task as all Queue SP operations
4911 * should run under rtnl_lock.
4913 smp_mb__before_clear_bit();
4914 set_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE
,
4915 &bp
->sp_rtnl_state
);
4916 smp_mb__after_clear_bit();
4918 schedule_delayed_work(&bp
->sp_rtnl_task
, 0);
4923 case EVENT_RING_OPCODE_AFEX_VIF_LISTS
:
4924 f_obj
->complete_cmd(bp
, f_obj
,
4925 BNX2X_F_CMD_AFEX_VIFLISTS
);
4926 bnx2x_after_afex_vif_lists(bp
, elem
);
4928 case EVENT_RING_OPCODE_FUNCTION_START
:
4929 DP(BNX2X_MSG_SP
| NETIF_MSG_IFUP
,
4930 "got FUNC_START ramrod\n");
4931 if (f_obj
->complete_cmd(bp
, f_obj
, BNX2X_F_CMD_START
))
4936 case EVENT_RING_OPCODE_FUNCTION_STOP
:
4937 DP(BNX2X_MSG_SP
| NETIF_MSG_IFUP
,
4938 "got FUNC_STOP ramrod\n");
4939 if (f_obj
->complete_cmd(bp
, f_obj
, BNX2X_F_CMD_STOP
))
4945 switch (opcode
| bp
->state
) {
4946 case (EVENT_RING_OPCODE_RSS_UPDATE_RULES
|
4948 case (EVENT_RING_OPCODE_RSS_UPDATE_RULES
|
4949 BNX2X_STATE_OPENING_WAIT4_PORT
):
4950 cid
= elem
->message
.data
.eth_event
.echo
&
4952 DP(BNX2X_MSG_SP
, "got RSS_UPDATE ramrod. CID %d\n",
4954 rss_raw
->clear_pending(rss_raw
);
4957 case (EVENT_RING_OPCODE_SET_MAC
| BNX2X_STATE_OPEN
):
4958 case (EVENT_RING_OPCODE_SET_MAC
| BNX2X_STATE_DIAG
):
4959 case (EVENT_RING_OPCODE_SET_MAC
|
4960 BNX2X_STATE_CLOSING_WAIT4_HALT
):
4961 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES
|
4963 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES
|
4965 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES
|
4966 BNX2X_STATE_CLOSING_WAIT4_HALT
):
4967 DP(BNX2X_MSG_SP
, "got (un)set mac ramrod\n");
4968 bnx2x_handle_classification_eqe(bp
, elem
);
4971 case (EVENT_RING_OPCODE_MULTICAST_RULES
|
4973 case (EVENT_RING_OPCODE_MULTICAST_RULES
|
4975 case (EVENT_RING_OPCODE_MULTICAST_RULES
|
4976 BNX2X_STATE_CLOSING_WAIT4_HALT
):
4977 DP(BNX2X_MSG_SP
, "got mcast ramrod\n");
4978 bnx2x_handle_mcast_eqe(bp
);
4981 case (EVENT_RING_OPCODE_FILTERS_RULES
|
4983 case (EVENT_RING_OPCODE_FILTERS_RULES
|
4985 case (EVENT_RING_OPCODE_FILTERS_RULES
|
4986 BNX2X_STATE_CLOSING_WAIT4_HALT
):
4987 DP(BNX2X_MSG_SP
, "got rx_mode ramrod\n");
4988 bnx2x_handle_rx_mode_eqe(bp
);
4991 /* unknown event log error and continue */
4992 BNX2X_ERR("Unknown EQ event %d, bp->state 0x%x\n",
4993 elem
->message
.opcode
, bp
->state
);
4999 smp_mb__before_atomic_inc();
5000 atomic_add(spqe_cnt
, &bp
->eq_spq_left
);
5002 bp
->eq_cons
= sw_cons
;
5003 bp
->eq_prod
= sw_prod
;
5004 /* Make sure that above mem writes were issued towards the memory */
5007 /* update producer */
5008 bnx2x_update_eq_prod(bp
, bp
->eq_prod
);
5011 static void bnx2x_sp_task(struct work_struct
*work
)
5013 struct bnx2x
*bp
= container_of(work
, struct bnx2x
, sp_task
.work
);
5016 status
= bnx2x_update_dsb_idx(bp
);
5017 /* if (status == 0) */
5018 /* BNX2X_ERR("spurious slowpath interrupt!\n"); */
5020 DP(BNX2X_MSG_SP
, "got a slowpath interrupt (status 0x%x)\n", status
);
5023 if (status
& BNX2X_DEF_SB_ATT_IDX
) {
5025 status
&= ~BNX2X_DEF_SB_ATT_IDX
;
5028 /* SP events: STAT_QUERY and others */
5029 if (status
& BNX2X_DEF_SB_IDX
) {
5030 struct bnx2x_fastpath
*fp
= bnx2x_fcoe_fp(bp
);
5032 if (FCOE_INIT(bp
) &&
5033 (bnx2x_has_rx_work(fp
) || bnx2x_has_tx_work(fp
))) {
5035 * Prevent local bottom-halves from running as
5036 * we are going to change the local NAPI list.
5039 napi_schedule(&bnx2x_fcoe(bp
, napi
));
5043 /* Handle EQ completions */
5046 bnx2x_ack_sb(bp
, bp
->igu_dsb_id
, USTORM_ID
,
5047 le16_to_cpu(bp
->def_idx
), IGU_INT_NOP
, 1);
5049 status
&= ~BNX2X_DEF_SB_IDX
;
5052 if (unlikely(status
))
5053 DP(BNX2X_MSG_SP
, "got an unknown interrupt! (status 0x%x)\n",
5056 bnx2x_ack_sb(bp
, bp
->igu_dsb_id
, ATTENTION_ID
,
5057 le16_to_cpu(bp
->def_att_idx
), IGU_INT_ENABLE
, 1);
5059 /* afex - poll to check if VIFSET_ACK should be sent to MFW */
5060 if (test_and_clear_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK
,
5062 bnx2x_link_report(bp
);
5063 bnx2x_fw_command(bp
, DRV_MSG_CODE_AFEX_VIFSET_ACK
, 0);
5067 irqreturn_t
bnx2x_msix_sp_int(int irq
, void *dev_instance
)
5069 struct net_device
*dev
= dev_instance
;
5070 struct bnx2x
*bp
= netdev_priv(dev
);
5072 bnx2x_ack_sb(bp
, bp
->igu_dsb_id
, USTORM_ID
, 0,
5073 IGU_INT_DISABLE
, 0);
5075 #ifdef BNX2X_STOP_ON_ERROR
5076 if (unlikely(bp
->panic
))
5080 if (CNIC_LOADED(bp
)) {
5081 struct cnic_ops
*c_ops
;
5084 c_ops
= rcu_dereference(bp
->cnic_ops
);
5086 c_ops
->cnic_handler(bp
->cnic_data
, NULL
);
5090 queue_delayed_work(bnx2x_wq
, &bp
->sp_task
, 0);
5095 /* end of slow path */
5098 void bnx2x_drv_pulse(struct bnx2x
*bp
)
5100 SHMEM_WR(bp
, func_mb
[BP_FW_MB_IDX(bp
)].drv_pulse_mb
,
5101 bp
->fw_drv_pulse_wr_seq
);
5105 static void bnx2x_timer(unsigned long data
)
5107 struct bnx2x
*bp
= (struct bnx2x
*) data
;
5109 if (!netif_running(bp
->dev
))
5112 if (!BP_NOMCP(bp
)) {
5113 int mb_idx
= BP_FW_MB_IDX(bp
);
5117 ++bp
->fw_drv_pulse_wr_seq
;
5118 bp
->fw_drv_pulse_wr_seq
&= DRV_PULSE_SEQ_MASK
;
5119 /* TBD - add SYSTEM_TIME */
5120 drv_pulse
= bp
->fw_drv_pulse_wr_seq
;
5121 bnx2x_drv_pulse(bp
);
5123 mcp_pulse
= (SHMEM_RD(bp
, func_mb
[mb_idx
].mcp_pulse_mb
) &
5124 MCP_PULSE_SEQ_MASK
);
5125 /* The delta between driver pulse and mcp response
5126 * should be 1 (before mcp response) or 0 (after mcp response)
5128 if ((drv_pulse
!= mcp_pulse
) &&
5129 (drv_pulse
!= ((mcp_pulse
+ 1) & MCP_PULSE_SEQ_MASK
))) {
5130 /* someone lost a heartbeat... */
5131 BNX2X_ERR("drv_pulse (0x%x) != mcp_pulse (0x%x)\n",
5132 drv_pulse
, mcp_pulse
);
5136 if (bp
->state
== BNX2X_STATE_OPEN
)
5137 bnx2x_stats_handle(bp
, STATS_EVENT_UPDATE
);
5139 mod_timer(&bp
->timer
, jiffies
+ bp
->current_interval
);
5142 /* end of Statistics */
5147 * nic init service functions
5150 static void bnx2x_fill(struct bnx2x
*bp
, u32 addr
, int fill
, u32 len
)
5153 if (!(len
%4) && !(addr
%4))
5154 for (i
= 0; i
< len
; i
+= 4)
5155 REG_WR(bp
, addr
+ i
, fill
);
5157 for (i
= 0; i
< len
; i
++)
5158 REG_WR8(bp
, addr
+ i
, fill
);
5162 /* helper: writes FP SP data to FW - data_size in dwords */
5163 static void bnx2x_wr_fp_sb_data(struct bnx2x
*bp
,
5169 for (index
= 0; index
< data_size
; index
++)
5170 REG_WR(bp
, BAR_CSTRORM_INTMEM
+
5171 CSTORM_STATUS_BLOCK_DATA_OFFSET(fw_sb_id
) +
5173 *(sb_data_p
+ index
));
5176 static void bnx2x_zero_fp_sb(struct bnx2x
*bp
, int fw_sb_id
)
5180 struct hc_status_block_data_e2 sb_data_e2
;
5181 struct hc_status_block_data_e1x sb_data_e1x
;
5183 /* disable the function first */
5184 if (!CHIP_IS_E1x(bp
)) {
5185 memset(&sb_data_e2
, 0, sizeof(struct hc_status_block_data_e2
));
5186 sb_data_e2
.common
.state
= SB_DISABLED
;
5187 sb_data_e2
.common
.p_func
.vf_valid
= false;
5188 sb_data_p
= (u32
*)&sb_data_e2
;
5189 data_size
= sizeof(struct hc_status_block_data_e2
)/sizeof(u32
);
5191 memset(&sb_data_e1x
, 0,
5192 sizeof(struct hc_status_block_data_e1x
));
5193 sb_data_e1x
.common
.state
= SB_DISABLED
;
5194 sb_data_e1x
.common
.p_func
.vf_valid
= false;
5195 sb_data_p
= (u32
*)&sb_data_e1x
;
5196 data_size
= sizeof(struct hc_status_block_data_e1x
)/sizeof(u32
);
5198 bnx2x_wr_fp_sb_data(bp
, fw_sb_id
, sb_data_p
, data_size
);
5200 bnx2x_fill(bp
, BAR_CSTRORM_INTMEM
+
5201 CSTORM_STATUS_BLOCK_OFFSET(fw_sb_id
), 0,
5202 CSTORM_STATUS_BLOCK_SIZE
);
5203 bnx2x_fill(bp
, BAR_CSTRORM_INTMEM
+
5204 CSTORM_SYNC_BLOCK_OFFSET(fw_sb_id
), 0,
5205 CSTORM_SYNC_BLOCK_SIZE
);
5208 /* helper: writes SP SB data to FW */
5209 static void bnx2x_wr_sp_sb_data(struct bnx2x
*bp
,
5210 struct hc_sp_status_block_data
*sp_sb_data
)
5212 int func
= BP_FUNC(bp
);
5214 for (i
= 0; i
< sizeof(struct hc_sp_status_block_data
)/sizeof(u32
); i
++)
5215 REG_WR(bp
, BAR_CSTRORM_INTMEM
+
5216 CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func
) +
5218 *((u32
*)sp_sb_data
+ i
));
5221 static void bnx2x_zero_sp_sb(struct bnx2x
*bp
)
5223 int func
= BP_FUNC(bp
);
5224 struct hc_sp_status_block_data sp_sb_data
;
5225 memset(&sp_sb_data
, 0, sizeof(struct hc_sp_status_block_data
));
5227 sp_sb_data
.state
= SB_DISABLED
;
5228 sp_sb_data
.p_func
.vf_valid
= false;
5230 bnx2x_wr_sp_sb_data(bp
, &sp_sb_data
);
5232 bnx2x_fill(bp
, BAR_CSTRORM_INTMEM
+
5233 CSTORM_SP_STATUS_BLOCK_OFFSET(func
), 0,
5234 CSTORM_SP_STATUS_BLOCK_SIZE
);
5235 bnx2x_fill(bp
, BAR_CSTRORM_INTMEM
+
5236 CSTORM_SP_SYNC_BLOCK_OFFSET(func
), 0,
5237 CSTORM_SP_SYNC_BLOCK_SIZE
);
5242 static void bnx2x_setup_ndsb_state_machine(struct hc_status_block_sm
*hc_sm
,
5243 int igu_sb_id
, int igu_seg_id
)
5245 hc_sm
->igu_sb_id
= igu_sb_id
;
5246 hc_sm
->igu_seg_id
= igu_seg_id
;
5247 hc_sm
->timer_value
= 0xFF;
5248 hc_sm
->time_to_expire
= 0xFFFFFFFF;
5252 /* allocates state machine ids. */
5253 static void bnx2x_map_sb_state_machines(struct hc_index_data
*index_data
)
5255 /* zero out state machine indices */
5257 index_data
[HC_INDEX_ETH_RX_CQ_CONS
].flags
&= ~HC_INDEX_DATA_SM_ID
;
5260 index_data
[HC_INDEX_OOO_TX_CQ_CONS
].flags
&= ~HC_INDEX_DATA_SM_ID
;
5261 index_data
[HC_INDEX_ETH_TX_CQ_CONS_COS0
].flags
&= ~HC_INDEX_DATA_SM_ID
;
5262 index_data
[HC_INDEX_ETH_TX_CQ_CONS_COS1
].flags
&= ~HC_INDEX_DATA_SM_ID
;
5263 index_data
[HC_INDEX_ETH_TX_CQ_CONS_COS2
].flags
&= ~HC_INDEX_DATA_SM_ID
;
5267 index_data
[HC_INDEX_ETH_RX_CQ_CONS
].flags
|=
5268 SM_RX_ID
<< HC_INDEX_DATA_SM_ID_SHIFT
;
5271 index_data
[HC_INDEX_OOO_TX_CQ_CONS
].flags
|=
5272 SM_TX_ID
<< HC_INDEX_DATA_SM_ID_SHIFT
;
5273 index_data
[HC_INDEX_ETH_TX_CQ_CONS_COS0
].flags
|=
5274 SM_TX_ID
<< HC_INDEX_DATA_SM_ID_SHIFT
;
5275 index_data
[HC_INDEX_ETH_TX_CQ_CONS_COS1
].flags
|=
5276 SM_TX_ID
<< HC_INDEX_DATA_SM_ID_SHIFT
;
5277 index_data
[HC_INDEX_ETH_TX_CQ_CONS_COS2
].flags
|=
5278 SM_TX_ID
<< HC_INDEX_DATA_SM_ID_SHIFT
;
5281 static void bnx2x_init_sb(struct bnx2x
*bp
, dma_addr_t mapping
, int vfid
,
5282 u8 vf_valid
, int fw_sb_id
, int igu_sb_id
)
5286 struct hc_status_block_data_e2 sb_data_e2
;
5287 struct hc_status_block_data_e1x sb_data_e1x
;
5288 struct hc_status_block_sm
*hc_sm_p
;
5292 if (CHIP_INT_MODE_IS_BC(bp
))
5293 igu_seg_id
= HC_SEG_ACCESS_NORM
;
5295 igu_seg_id
= IGU_SEG_ACCESS_NORM
;
5297 bnx2x_zero_fp_sb(bp
, fw_sb_id
);
5299 if (!CHIP_IS_E1x(bp
)) {
5300 memset(&sb_data_e2
, 0, sizeof(struct hc_status_block_data_e2
));
5301 sb_data_e2
.common
.state
= SB_ENABLED
;
5302 sb_data_e2
.common
.p_func
.pf_id
= BP_FUNC(bp
);
5303 sb_data_e2
.common
.p_func
.vf_id
= vfid
;
5304 sb_data_e2
.common
.p_func
.vf_valid
= vf_valid
;
5305 sb_data_e2
.common
.p_func
.vnic_id
= BP_VN(bp
);
5306 sb_data_e2
.common
.same_igu_sb_1b
= true;
5307 sb_data_e2
.common
.host_sb_addr
.hi
= U64_HI(mapping
);
5308 sb_data_e2
.common
.host_sb_addr
.lo
= U64_LO(mapping
);
5309 hc_sm_p
= sb_data_e2
.common
.state_machine
;
5310 sb_data_p
= (u32
*)&sb_data_e2
;
5311 data_size
= sizeof(struct hc_status_block_data_e2
)/sizeof(u32
);
5312 bnx2x_map_sb_state_machines(sb_data_e2
.index_data
);
5314 memset(&sb_data_e1x
, 0,
5315 sizeof(struct hc_status_block_data_e1x
));
5316 sb_data_e1x
.common
.state
= SB_ENABLED
;
5317 sb_data_e1x
.common
.p_func
.pf_id
= BP_FUNC(bp
);
5318 sb_data_e1x
.common
.p_func
.vf_id
= 0xff;
5319 sb_data_e1x
.common
.p_func
.vf_valid
= false;
5320 sb_data_e1x
.common
.p_func
.vnic_id
= BP_VN(bp
);
5321 sb_data_e1x
.common
.same_igu_sb_1b
= true;
5322 sb_data_e1x
.common
.host_sb_addr
.hi
= U64_HI(mapping
);
5323 sb_data_e1x
.common
.host_sb_addr
.lo
= U64_LO(mapping
);
5324 hc_sm_p
= sb_data_e1x
.common
.state_machine
;
5325 sb_data_p
= (u32
*)&sb_data_e1x
;
5326 data_size
= sizeof(struct hc_status_block_data_e1x
)/sizeof(u32
);
5327 bnx2x_map_sb_state_machines(sb_data_e1x
.index_data
);
5330 bnx2x_setup_ndsb_state_machine(&hc_sm_p
[SM_RX_ID
],
5331 igu_sb_id
, igu_seg_id
);
5332 bnx2x_setup_ndsb_state_machine(&hc_sm_p
[SM_TX_ID
],
5333 igu_sb_id
, igu_seg_id
);
5335 DP(NETIF_MSG_IFUP
, "Init FW SB %d\n", fw_sb_id
);
5337 /* write indecies to HW */
5338 bnx2x_wr_fp_sb_data(bp
, fw_sb_id
, sb_data_p
, data_size
);
5341 static void bnx2x_update_coalesce_sb(struct bnx2x
*bp
, u8 fw_sb_id
,
5342 u16 tx_usec
, u16 rx_usec
)
5344 bnx2x_update_coalesce_sb_index(bp
, fw_sb_id
, HC_INDEX_ETH_RX_CQ_CONS
,
5346 bnx2x_update_coalesce_sb_index(bp
, fw_sb_id
,
5347 HC_INDEX_ETH_TX_CQ_CONS_COS0
, false,
5349 bnx2x_update_coalesce_sb_index(bp
, fw_sb_id
,
5350 HC_INDEX_ETH_TX_CQ_CONS_COS1
, false,
5352 bnx2x_update_coalesce_sb_index(bp
, fw_sb_id
,
5353 HC_INDEX_ETH_TX_CQ_CONS_COS2
, false,
5357 static void bnx2x_init_def_sb(struct bnx2x
*bp
)
5359 struct host_sp_status_block
*def_sb
= bp
->def_status_blk
;
5360 dma_addr_t mapping
= bp
->def_status_blk_mapping
;
5361 int igu_sp_sb_index
;
5363 int port
= BP_PORT(bp
);
5364 int func
= BP_FUNC(bp
);
5365 int reg_offset
, reg_offset_en5
;
5368 struct hc_sp_status_block_data sp_sb_data
;
5369 memset(&sp_sb_data
, 0, sizeof(struct hc_sp_status_block_data
));
5371 if (CHIP_INT_MODE_IS_BC(bp
)) {
5372 igu_sp_sb_index
= DEF_SB_IGU_ID
;
5373 igu_seg_id
= HC_SEG_ACCESS_DEF
;
5375 igu_sp_sb_index
= bp
->igu_dsb_id
;
5376 igu_seg_id
= IGU_SEG_ACCESS_DEF
;
5380 section
= ((u64
)mapping
) + offsetof(struct host_sp_status_block
,
5381 atten_status_block
);
5382 def_sb
->atten_status_block
.status_block_id
= igu_sp_sb_index
;
5386 reg_offset
= (port
? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0
:
5387 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0
);
5388 reg_offset_en5
= (port
? MISC_REG_AEU_ENABLE5_FUNC_1_OUT_0
:
5389 MISC_REG_AEU_ENABLE5_FUNC_0_OUT_0
);
5390 for (index
= 0; index
< MAX_DYNAMIC_ATTN_GRPS
; index
++) {
5392 /* take care of sig[0]..sig[4] */
5393 for (sindex
= 0; sindex
< 4; sindex
++)
5394 bp
->attn_group
[index
].sig
[sindex
] =
5395 REG_RD(bp
, reg_offset
+ sindex
*0x4 + 0x10*index
);
5397 if (!CHIP_IS_E1x(bp
))
5399 * enable5 is separate from the rest of the registers,
5400 * and therefore the address skip is 4
5401 * and not 16 between the different groups
5403 bp
->attn_group
[index
].sig
[4] = REG_RD(bp
,
5404 reg_offset_en5
+ 0x4*index
);
5406 bp
->attn_group
[index
].sig
[4] = 0;
5409 if (bp
->common
.int_block
== INT_BLOCK_HC
) {
5410 reg_offset
= (port
? HC_REG_ATTN_MSG1_ADDR_L
:
5411 HC_REG_ATTN_MSG0_ADDR_L
);
5413 REG_WR(bp
, reg_offset
, U64_LO(section
));
5414 REG_WR(bp
, reg_offset
+ 4, U64_HI(section
));
5415 } else if (!CHIP_IS_E1x(bp
)) {
5416 REG_WR(bp
, IGU_REG_ATTN_MSG_ADDR_L
, U64_LO(section
));
5417 REG_WR(bp
, IGU_REG_ATTN_MSG_ADDR_H
, U64_HI(section
));
5420 section
= ((u64
)mapping
) + offsetof(struct host_sp_status_block
,
5423 bnx2x_zero_sp_sb(bp
);
5425 sp_sb_data
.state
= SB_ENABLED
;
5426 sp_sb_data
.host_sb_addr
.lo
= U64_LO(section
);
5427 sp_sb_data
.host_sb_addr
.hi
= U64_HI(section
);
5428 sp_sb_data
.igu_sb_id
= igu_sp_sb_index
;
5429 sp_sb_data
.igu_seg_id
= igu_seg_id
;
5430 sp_sb_data
.p_func
.pf_id
= func
;
5431 sp_sb_data
.p_func
.vnic_id
= BP_VN(bp
);
5432 sp_sb_data
.p_func
.vf_id
= 0xff;
5434 bnx2x_wr_sp_sb_data(bp
, &sp_sb_data
);
5436 bnx2x_ack_sb(bp
, bp
->igu_dsb_id
, USTORM_ID
, 0, IGU_INT_ENABLE
, 0);
5439 void bnx2x_update_coalesce(struct bnx2x
*bp
)
5443 for_each_eth_queue(bp
, i
)
5444 bnx2x_update_coalesce_sb(bp
, bp
->fp
[i
].fw_sb_id
,
5445 bp
->tx_ticks
, bp
->rx_ticks
);
5448 static void bnx2x_init_sp_ring(struct bnx2x
*bp
)
5450 spin_lock_init(&bp
->spq_lock
);
5451 atomic_set(&bp
->cq_spq_left
, MAX_SPQ_PENDING
);
5453 bp
->spq_prod_idx
= 0;
5454 bp
->dsb_sp_prod
= BNX2X_SP_DSB_INDEX
;
5455 bp
->spq_prod_bd
= bp
->spq
;
5456 bp
->spq_last_bd
= bp
->spq_prod_bd
+ MAX_SP_DESC_CNT
;
5459 static void bnx2x_init_eq_ring(struct bnx2x
*bp
)
5462 for (i
= 1; i
<= NUM_EQ_PAGES
; i
++) {
5463 union event_ring_elem
*elem
=
5464 &bp
->eq_ring
[EQ_DESC_CNT_PAGE
* i
- 1];
5466 elem
->next_page
.addr
.hi
=
5467 cpu_to_le32(U64_HI(bp
->eq_mapping
+
5468 BCM_PAGE_SIZE
* (i
% NUM_EQ_PAGES
)));
5469 elem
->next_page
.addr
.lo
=
5470 cpu_to_le32(U64_LO(bp
->eq_mapping
+
5471 BCM_PAGE_SIZE
*(i
% NUM_EQ_PAGES
)));
5474 bp
->eq_prod
= NUM_EQ_DESC
;
5475 bp
->eq_cons_sb
= BNX2X_EQ_INDEX
;
5476 /* we want a warning message before it gets rought... */
5477 atomic_set(&bp
->eq_spq_left
,
5478 min_t(int, MAX_SP_DESC_CNT
- MAX_SPQ_PENDING
, NUM_EQ_DESC
) - 1);
5482 /* called with netif_addr_lock_bh() */
5483 void bnx2x_set_q_rx_mode(struct bnx2x
*bp
, u8 cl_id
,
5484 unsigned long rx_mode_flags
,
5485 unsigned long rx_accept_flags
,
5486 unsigned long tx_accept_flags
,
5487 unsigned long ramrod_flags
)
5489 struct bnx2x_rx_mode_ramrod_params ramrod_param
;
5492 memset(&ramrod_param
, 0, sizeof(ramrod_param
));
5494 /* Prepare ramrod parameters */
5495 ramrod_param
.cid
= 0;
5496 ramrod_param
.cl_id
= cl_id
;
5497 ramrod_param
.rx_mode_obj
= &bp
->rx_mode_obj
;
5498 ramrod_param
.func_id
= BP_FUNC(bp
);
5500 ramrod_param
.pstate
= &bp
->sp_state
;
5501 ramrod_param
.state
= BNX2X_FILTER_RX_MODE_PENDING
;
5503 ramrod_param
.rdata
= bnx2x_sp(bp
, rx_mode_rdata
);
5504 ramrod_param
.rdata_mapping
= bnx2x_sp_mapping(bp
, rx_mode_rdata
);
5506 set_bit(BNX2X_FILTER_RX_MODE_PENDING
, &bp
->sp_state
);
5508 ramrod_param
.ramrod_flags
= ramrod_flags
;
5509 ramrod_param
.rx_mode_flags
= rx_mode_flags
;
5511 ramrod_param
.rx_accept_flags
= rx_accept_flags
;
5512 ramrod_param
.tx_accept_flags
= tx_accept_flags
;
5514 rc
= bnx2x_config_rx_mode(bp
, &ramrod_param
);
5516 BNX2X_ERR("Set rx_mode %d failed\n", bp
->rx_mode
);
5521 /* called with netif_addr_lock_bh() */
5522 void bnx2x_set_storm_rx_mode(struct bnx2x
*bp
)
5524 unsigned long rx_mode_flags
= 0, ramrod_flags
= 0;
5525 unsigned long rx_accept_flags
= 0, tx_accept_flags
= 0;
5529 /* Configure rx_mode of FCoE Queue */
5530 __set_bit(BNX2X_RX_MODE_FCOE_ETH
, &rx_mode_flags
);
5532 switch (bp
->rx_mode
) {
5533 case BNX2X_RX_MODE_NONE
:
5535 * 'drop all' supersedes any accept flags that may have been
5536 * passed to the function.
5539 case BNX2X_RX_MODE_NORMAL
:
5540 __set_bit(BNX2X_ACCEPT_UNICAST
, &rx_accept_flags
);
5541 __set_bit(BNX2X_ACCEPT_MULTICAST
, &rx_accept_flags
);
5542 __set_bit(BNX2X_ACCEPT_BROADCAST
, &rx_accept_flags
);
5544 /* internal switching mode */
5545 __set_bit(BNX2X_ACCEPT_UNICAST
, &tx_accept_flags
);
5546 __set_bit(BNX2X_ACCEPT_MULTICAST
, &tx_accept_flags
);
5547 __set_bit(BNX2X_ACCEPT_BROADCAST
, &tx_accept_flags
);
5550 case BNX2X_RX_MODE_ALLMULTI
:
5551 __set_bit(BNX2X_ACCEPT_UNICAST
, &rx_accept_flags
);
5552 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST
, &rx_accept_flags
);
5553 __set_bit(BNX2X_ACCEPT_BROADCAST
, &rx_accept_flags
);
5555 /* internal switching mode */
5556 __set_bit(BNX2X_ACCEPT_UNICAST
, &tx_accept_flags
);
5557 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST
, &tx_accept_flags
);
5558 __set_bit(BNX2X_ACCEPT_BROADCAST
, &tx_accept_flags
);
5561 case BNX2X_RX_MODE_PROMISC
:
5562 /* According to deffinition of SI mode, iface in promisc mode
5563 * should receive matched and unmatched (in resolution of port)
5566 __set_bit(BNX2X_ACCEPT_UNMATCHED
, &rx_accept_flags
);
5567 __set_bit(BNX2X_ACCEPT_UNICAST
, &rx_accept_flags
);
5568 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST
, &rx_accept_flags
);
5569 __set_bit(BNX2X_ACCEPT_BROADCAST
, &rx_accept_flags
);
5571 /* internal switching mode */
5572 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST
, &tx_accept_flags
);
5573 __set_bit(BNX2X_ACCEPT_BROADCAST
, &tx_accept_flags
);
5576 __set_bit(BNX2X_ACCEPT_ALL_UNICAST
, &tx_accept_flags
);
5578 __set_bit(BNX2X_ACCEPT_UNICAST
, &tx_accept_flags
);
5582 BNX2X_ERR("Unknown rx_mode: %d\n", bp
->rx_mode
);
5586 if (bp
->rx_mode
!= BNX2X_RX_MODE_NONE
) {
5587 __set_bit(BNX2X_ACCEPT_ANY_VLAN
, &rx_accept_flags
);
5588 __set_bit(BNX2X_ACCEPT_ANY_VLAN
, &tx_accept_flags
);
5591 __set_bit(RAMROD_RX
, &ramrod_flags
);
5592 __set_bit(RAMROD_TX
, &ramrod_flags
);
5594 bnx2x_set_q_rx_mode(bp
, bp
->fp
->cl_id
, rx_mode_flags
, rx_accept_flags
,
5595 tx_accept_flags
, ramrod_flags
);
5598 static void bnx2x_init_internal_common(struct bnx2x
*bp
)
5604 * In switch independent mode, the TSTORM needs to accept
5605 * packets that failed classification, since approximate match
5606 * mac addresses aren't written to NIG LLH
5608 REG_WR8(bp
, BAR_TSTRORM_INTMEM
+
5609 TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET
, 2);
5610 else if (!CHIP_IS_E1(bp
)) /* 57710 doesn't support MF */
5611 REG_WR8(bp
, BAR_TSTRORM_INTMEM
+
5612 TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET
, 0);
5614 /* Zero this manually as its initialization is
5615 currently missing in the initTool */
5616 for (i
= 0; i
< (USTORM_AGG_DATA_SIZE
>> 2); i
++)
5617 REG_WR(bp
, BAR_USTRORM_INTMEM
+
5618 USTORM_AGG_DATA_OFFSET
+ i
* 4, 0);
5619 if (!CHIP_IS_E1x(bp
)) {
5620 REG_WR8(bp
, BAR_CSTRORM_INTMEM
+ CSTORM_IGU_MODE_OFFSET
,
5621 CHIP_INT_MODE_IS_BC(bp
) ?
5622 HC_IGU_BC_MODE
: HC_IGU_NBC_MODE
);
5626 static void bnx2x_init_internal(struct bnx2x
*bp
, u32 load_code
)
5628 switch (load_code
) {
5629 case FW_MSG_CODE_DRV_LOAD_COMMON
:
5630 case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP
:
5631 bnx2x_init_internal_common(bp
);
5634 case FW_MSG_CODE_DRV_LOAD_PORT
:
5638 case FW_MSG_CODE_DRV_LOAD_FUNCTION
:
5639 /* internal memory per function is
5640 initialized inside bnx2x_pf_init */
5644 BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code
);
5649 static inline u8
bnx2x_fp_igu_sb_id(struct bnx2x_fastpath
*fp
)
5651 return fp
->bp
->igu_base_sb
+ fp
->index
+ CNIC_SUPPORT(fp
->bp
);
5654 static inline u8
bnx2x_fp_fw_sb_id(struct bnx2x_fastpath
*fp
)
5656 return fp
->bp
->base_fw_ndsb
+ fp
->index
+ CNIC_SUPPORT(fp
->bp
);
5659 static u8
bnx2x_fp_cl_id(struct bnx2x_fastpath
*fp
)
5661 if (CHIP_IS_E1x(fp
->bp
))
5662 return BP_L_ID(fp
->bp
) + fp
->index
;
5663 else /* We want Client ID to be the same as IGU SB ID for 57712 */
5664 return bnx2x_fp_igu_sb_id(fp
);
5667 static void bnx2x_init_eth_fp(struct bnx2x
*bp
, int fp_idx
)
5669 struct bnx2x_fastpath
*fp
= &bp
->fp
[fp_idx
];
5671 unsigned long q_type
= 0;
5672 u32 cids
[BNX2X_MULTI_TX_COS
] = { 0 };
5673 fp
->rx_queue
= fp_idx
;
5675 fp
->cl_id
= bnx2x_fp_cl_id(fp
);
5676 fp
->fw_sb_id
= bnx2x_fp_fw_sb_id(fp
);
5677 fp
->igu_sb_id
= bnx2x_fp_igu_sb_id(fp
);
5678 /* qZone id equals to FW (per path) client id */
5679 fp
->cl_qzone_id
= bnx2x_fp_qzone_id(fp
);
5682 fp
->ustorm_rx_prods_offset
= bnx2x_rx_ustorm_prods_offset(fp
);
5684 /* Setup SB indicies */
5685 fp
->rx_cons_sb
= BNX2X_RX_SB_INDEX
;
5687 /* Configure Queue State object */
5688 __set_bit(BNX2X_Q_TYPE_HAS_RX
, &q_type
);
5689 __set_bit(BNX2X_Q_TYPE_HAS_TX
, &q_type
);
5691 BUG_ON(fp
->max_cos
> BNX2X_MULTI_TX_COS
);
5694 for_each_cos_in_tx_queue(fp
, cos
) {
5695 bnx2x_init_txdata(bp
, fp
->txdata_ptr
[cos
],
5696 CID_COS_TO_TX_ONLY_CID(fp
->cid
, cos
, bp
),
5697 FP_COS_TO_TXQ(fp
, cos
, bp
),
5698 BNX2X_TX_SB_INDEX_BASE
+ cos
, fp
);
5699 cids
[cos
] = fp
->txdata_ptr
[cos
]->cid
;
5702 bnx2x_init_queue_obj(bp
, &bnx2x_sp_obj(bp
, fp
).q_obj
, fp
->cl_id
, cids
,
5703 fp
->max_cos
, BP_FUNC(bp
), bnx2x_sp(bp
, q_rdata
),
5704 bnx2x_sp_mapping(bp
, q_rdata
), q_type
);
5707 * Configure classification DBs: Always enable Tx switching
5709 bnx2x_init_vlan_mac_fp_objs(fp
, BNX2X_OBJ_TYPE_RX_TX
);
5711 DP(NETIF_MSG_IFUP
, "queue[%d]: bnx2x_init_sb(%p,%p) cl_id %d fw_sb %d igu_sb %d\n",
5712 fp_idx
, bp
, fp
->status_blk
.e2_sb
, fp
->cl_id
, fp
->fw_sb_id
,
5714 bnx2x_init_sb(bp
, fp
->status_blk_mapping
, BNX2X_VF_ID_INVALID
, false,
5715 fp
->fw_sb_id
, fp
->igu_sb_id
);
5717 bnx2x_update_fpsb_idx(fp
);
5720 static void bnx2x_init_tx_ring_one(struct bnx2x_fp_txdata
*txdata
)
5724 for (i
= 1; i
<= NUM_TX_RINGS
; i
++) {
5725 struct eth_tx_next_bd
*tx_next_bd
=
5726 &txdata
->tx_desc_ring
[TX_DESC_CNT
* i
- 1].next_bd
;
5728 tx_next_bd
->addr_hi
=
5729 cpu_to_le32(U64_HI(txdata
->tx_desc_mapping
+
5730 BCM_PAGE_SIZE
*(i
% NUM_TX_RINGS
)));
5731 tx_next_bd
->addr_lo
=
5732 cpu_to_le32(U64_LO(txdata
->tx_desc_mapping
+
5733 BCM_PAGE_SIZE
*(i
% NUM_TX_RINGS
)));
5736 SET_FLAG(txdata
->tx_db
.data
.header
.header
, DOORBELL_HDR_DB_TYPE
, 1);
5737 txdata
->tx_db
.data
.zero_fill1
= 0;
5738 txdata
->tx_db
.data
.prod
= 0;
5740 txdata
->tx_pkt_prod
= 0;
5741 txdata
->tx_pkt_cons
= 0;
5742 txdata
->tx_bd_prod
= 0;
5743 txdata
->tx_bd_cons
= 0;
5747 static void bnx2x_init_tx_rings_cnic(struct bnx2x
*bp
)
5751 for_each_tx_queue_cnic(bp
, i
)
5752 bnx2x_init_tx_ring_one(bp
->fp
[i
].txdata_ptr
[0]);
5754 static void bnx2x_init_tx_rings(struct bnx2x
*bp
)
5759 for_each_eth_queue(bp
, i
)
5760 for_each_cos_in_tx_queue(&bp
->fp
[i
], cos
)
5761 bnx2x_init_tx_ring_one(bp
->fp
[i
].txdata_ptr
[cos
]);
5764 void bnx2x_nic_init_cnic(struct bnx2x
*bp
)
5767 bnx2x_init_fcoe_fp(bp
);
5769 bnx2x_init_sb(bp
, bp
->cnic_sb_mapping
,
5770 BNX2X_VF_ID_INVALID
, false,
5771 bnx2x_cnic_fw_sb_id(bp
), bnx2x_cnic_igu_sb_id(bp
));
5773 /* ensure status block indices were read */
5775 bnx2x_init_rx_rings_cnic(bp
);
5776 bnx2x_init_tx_rings_cnic(bp
);
5783 void bnx2x_nic_init(struct bnx2x
*bp
, u32 load_code
)
5787 for_each_eth_queue(bp
, i
)
5788 bnx2x_init_eth_fp(bp
, i
);
5789 /* Initialize MOD_ABS interrupts */
5790 bnx2x_init_mod_abs_int(bp
, &bp
->link_vars
, bp
->common
.chip_id
,
5791 bp
->common
.shmem_base
, bp
->common
.shmem2_base
,
5793 /* ensure status block indices were read */
5796 bnx2x_init_def_sb(bp
);
5797 bnx2x_update_dsb_idx(bp
);
5798 bnx2x_init_rx_rings(bp
);
5799 bnx2x_init_tx_rings(bp
);
5800 bnx2x_init_sp_ring(bp
);
5801 bnx2x_init_eq_ring(bp
);
5802 bnx2x_init_internal(bp
, load_code
);
5804 bnx2x_stats_init(bp
);
5806 /* flush all before enabling interrupts */
5810 bnx2x_int_enable(bp
);
5812 /* Check for SPIO5 */
5813 bnx2x_attn_int_deasserted0(bp
,
5814 REG_RD(bp
, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0
+ BP_PORT(bp
)*4) &
5815 AEU_INPUTS_ATTN_BITS_SPIO5
);
5818 /* end of nic init */
5821 * gzip service functions
5824 static int bnx2x_gunzip_init(struct bnx2x
*bp
)
5826 bp
->gunzip_buf
= dma_alloc_coherent(&bp
->pdev
->dev
, FW_BUF_SIZE
,
5827 &bp
->gunzip_mapping
, GFP_KERNEL
);
5828 if (bp
->gunzip_buf
== NULL
)
5831 bp
->strm
= kmalloc(sizeof(*bp
->strm
), GFP_KERNEL
);
5832 if (bp
->strm
== NULL
)
5835 bp
->strm
->workspace
= vmalloc(zlib_inflate_workspacesize());
5836 if (bp
->strm
->workspace
== NULL
)
5846 dma_free_coherent(&bp
->pdev
->dev
, FW_BUF_SIZE
, bp
->gunzip_buf
,
5847 bp
->gunzip_mapping
);
5848 bp
->gunzip_buf
= NULL
;
5851 BNX2X_ERR("Cannot allocate firmware buffer for un-compression\n");
5855 static void bnx2x_gunzip_end(struct bnx2x
*bp
)
5858 vfree(bp
->strm
->workspace
);
5863 if (bp
->gunzip_buf
) {
5864 dma_free_coherent(&bp
->pdev
->dev
, FW_BUF_SIZE
, bp
->gunzip_buf
,
5865 bp
->gunzip_mapping
);
5866 bp
->gunzip_buf
= NULL
;
5870 static int bnx2x_gunzip(struct bnx2x
*bp
, const u8
*zbuf
, int len
)
5874 /* check gzip header */
5875 if ((zbuf
[0] != 0x1f) || (zbuf
[1] != 0x8b) || (zbuf
[2] != Z_DEFLATED
)) {
5876 BNX2X_ERR("Bad gzip header\n");
5884 if (zbuf
[3] & FNAME
)
5885 while ((zbuf
[n
++] != 0) && (n
< len
));
5887 bp
->strm
->next_in
= (typeof(bp
->strm
->next_in
))zbuf
+ n
;
5888 bp
->strm
->avail_in
= len
- n
;
5889 bp
->strm
->next_out
= bp
->gunzip_buf
;
5890 bp
->strm
->avail_out
= FW_BUF_SIZE
;
5892 rc
= zlib_inflateInit2(bp
->strm
, -MAX_WBITS
);
5896 rc
= zlib_inflate(bp
->strm
, Z_FINISH
);
5897 if ((rc
!= Z_OK
) && (rc
!= Z_STREAM_END
))
5898 netdev_err(bp
->dev
, "Firmware decompression error: %s\n",
5901 bp
->gunzip_outlen
= (FW_BUF_SIZE
- bp
->strm
->avail_out
);
5902 if (bp
->gunzip_outlen
& 0x3)
5904 "Firmware decompression error: gunzip_outlen (%d) not aligned\n",
5906 bp
->gunzip_outlen
>>= 2;
5908 zlib_inflateEnd(bp
->strm
);
5910 if (rc
== Z_STREAM_END
)
5916 /* nic load/unload */
5919 * General service functions
5922 /* send a NIG loopback debug packet */
5923 static void bnx2x_lb_pckt(struct bnx2x
*bp
)
5927 /* Ethernet source and destination addresses */
5928 wb_write
[0] = 0x55555555;
5929 wb_write
[1] = 0x55555555;
5930 wb_write
[2] = 0x20; /* SOP */
5931 REG_WR_DMAE(bp
, NIG_REG_DEBUG_PACKET_LB
, wb_write
, 3);
5933 /* NON-IP protocol */
5934 wb_write
[0] = 0x09000000;
5935 wb_write
[1] = 0x55555555;
5936 wb_write
[2] = 0x10; /* EOP, eop_bvalid = 0 */
5937 REG_WR_DMAE(bp
, NIG_REG_DEBUG_PACKET_LB
, wb_write
, 3);
5940 /* some of the internal memories
5941 * are not directly readable from the driver
5942 * to test them we send debug packets
5944 static int bnx2x_int_mem_test(struct bnx2x
*bp
)
5950 if (CHIP_REV_IS_FPGA(bp
))
5952 else if (CHIP_REV_IS_EMUL(bp
))
5957 /* Disable inputs of parser neighbor blocks */
5958 REG_WR(bp
, TSDM_REG_ENABLE_IN1
, 0x0);
5959 REG_WR(bp
, TCM_REG_PRS_IFEN
, 0x0);
5960 REG_WR(bp
, CFC_REG_DEBUG0
, 0x1);
5961 REG_WR(bp
, NIG_REG_PRS_REQ_IN_EN
, 0x0);
5963 /* Write 0 to parser credits for CFC search request */
5964 REG_WR(bp
, PRS_REG_CFC_SEARCH_INITIAL_CREDIT
, 0x0);
5966 /* send Ethernet packet */
5969 /* TODO do i reset NIG statistic? */
5970 /* Wait until NIG register shows 1 packet of size 0x10 */
5971 count
= 1000 * factor
;
5974 bnx2x_read_dmae(bp
, NIG_REG_STAT2_BRB_OCTET
, 2);
5975 val
= *bnx2x_sp(bp
, wb_data
[0]);
5983 BNX2X_ERR("NIG timeout val = 0x%x\n", val
);
5987 /* Wait until PRS register shows 1 packet */
5988 count
= 1000 * factor
;
5990 val
= REG_RD(bp
, PRS_REG_NUM_OF_PACKETS
);
5998 BNX2X_ERR("PRS timeout val = 0x%x\n", val
);
6002 /* Reset and init BRB, PRS */
6003 REG_WR(bp
, GRCBASE_MISC
+ MISC_REGISTERS_RESET_REG_1_CLEAR
, 0x03);
6005 REG_WR(bp
, GRCBASE_MISC
+ MISC_REGISTERS_RESET_REG_1_SET
, 0x03);
6007 bnx2x_init_block(bp
, BLOCK_BRB1
, PHASE_COMMON
);
6008 bnx2x_init_block(bp
, BLOCK_PRS
, PHASE_COMMON
);
6010 DP(NETIF_MSG_HW
, "part2\n");
6012 /* Disable inputs of parser neighbor blocks */
6013 REG_WR(bp
, TSDM_REG_ENABLE_IN1
, 0x0);
6014 REG_WR(bp
, TCM_REG_PRS_IFEN
, 0x0);
6015 REG_WR(bp
, CFC_REG_DEBUG0
, 0x1);
6016 REG_WR(bp
, NIG_REG_PRS_REQ_IN_EN
, 0x0);
6018 /* Write 0 to parser credits for CFC search request */
6019 REG_WR(bp
, PRS_REG_CFC_SEARCH_INITIAL_CREDIT
, 0x0);
6021 /* send 10 Ethernet packets */
6022 for (i
= 0; i
< 10; i
++)
6025 /* Wait until NIG register shows 10 + 1
6026 packets of size 11*0x10 = 0xb0 */
6027 count
= 1000 * factor
;
6030 bnx2x_read_dmae(bp
, NIG_REG_STAT2_BRB_OCTET
, 2);
6031 val
= *bnx2x_sp(bp
, wb_data
[0]);
6039 BNX2X_ERR("NIG timeout val = 0x%x\n", val
);
6043 /* Wait until PRS register shows 2 packets */
6044 val
= REG_RD(bp
, PRS_REG_NUM_OF_PACKETS
);
6046 BNX2X_ERR("PRS timeout val = 0x%x\n", val
);
6048 /* Write 1 to parser credits for CFC search request */
6049 REG_WR(bp
, PRS_REG_CFC_SEARCH_INITIAL_CREDIT
, 0x1);
6051 /* Wait until PRS register shows 3 packets */
6052 msleep(10 * factor
);
6053 /* Wait until NIG register shows 1 packet of size 0x10 */
6054 val
= REG_RD(bp
, PRS_REG_NUM_OF_PACKETS
);
6056 BNX2X_ERR("PRS timeout val = 0x%x\n", val
);
6058 /* clear NIG EOP FIFO */
6059 for (i
= 0; i
< 11; i
++)
6060 REG_RD(bp
, NIG_REG_INGRESS_EOP_LB_FIFO
);
6061 val
= REG_RD(bp
, NIG_REG_INGRESS_EOP_LB_EMPTY
);
6063 BNX2X_ERR("clear of NIG failed\n");
6067 /* Reset and init BRB, PRS, NIG */
6068 REG_WR(bp
, GRCBASE_MISC
+ MISC_REGISTERS_RESET_REG_1_CLEAR
, 0x03);
6070 REG_WR(bp
, GRCBASE_MISC
+ MISC_REGISTERS_RESET_REG_1_SET
, 0x03);
6072 bnx2x_init_block(bp
, BLOCK_BRB1
, PHASE_COMMON
);
6073 bnx2x_init_block(bp
, BLOCK_PRS
, PHASE_COMMON
);
6074 if (!CNIC_SUPPORT(bp
))
6076 REG_WR(bp
, PRS_REG_NIC_MODE
, 1);
6078 /* Enable inputs of parser neighbor blocks */
6079 REG_WR(bp
, TSDM_REG_ENABLE_IN1
, 0x7fffffff);
6080 REG_WR(bp
, TCM_REG_PRS_IFEN
, 0x1);
6081 REG_WR(bp
, CFC_REG_DEBUG0
, 0x0);
6082 REG_WR(bp
, NIG_REG_PRS_REQ_IN_EN
, 0x1);
6084 DP(NETIF_MSG_HW
, "done\n");
6089 static void bnx2x_enable_blocks_attention(struct bnx2x
*bp
)
6093 REG_WR(bp
, PXP_REG_PXP_INT_MASK_0
, 0);
6094 if (!CHIP_IS_E1x(bp
))
6095 REG_WR(bp
, PXP_REG_PXP_INT_MASK_1
, 0x40);
6097 REG_WR(bp
, PXP_REG_PXP_INT_MASK_1
, 0);
6098 REG_WR(bp
, DORQ_REG_DORQ_INT_MASK
, 0);
6099 REG_WR(bp
, CFC_REG_CFC_INT_MASK
, 0);
6101 * mask read length error interrupts in brb for parser
6102 * (parsing unit and 'checksum and crc' unit)
6103 * these errors are legal (PU reads fixed length and CAC can cause
6104 * read length error on truncated packets)
6106 REG_WR(bp
, BRB1_REG_BRB1_INT_MASK
, 0xFC00);
6107 REG_WR(bp
, QM_REG_QM_INT_MASK
, 0);
6108 REG_WR(bp
, TM_REG_TM_INT_MASK
, 0);
6109 REG_WR(bp
, XSDM_REG_XSDM_INT_MASK_0
, 0);
6110 REG_WR(bp
, XSDM_REG_XSDM_INT_MASK_1
, 0);
6111 REG_WR(bp
, XCM_REG_XCM_INT_MASK
, 0);
6112 /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_0, 0); */
6113 /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_1, 0); */
6114 REG_WR(bp
, USDM_REG_USDM_INT_MASK_0
, 0);
6115 REG_WR(bp
, USDM_REG_USDM_INT_MASK_1
, 0);
6116 REG_WR(bp
, UCM_REG_UCM_INT_MASK
, 0);
6117 /* REG_WR(bp, USEM_REG_USEM_INT_MASK_0, 0); */
6118 /* REG_WR(bp, USEM_REG_USEM_INT_MASK_1, 0); */
6119 REG_WR(bp
, GRCBASE_UPB
+ PB_REG_PB_INT_MASK
, 0);
6120 REG_WR(bp
, CSDM_REG_CSDM_INT_MASK_0
, 0);
6121 REG_WR(bp
, CSDM_REG_CSDM_INT_MASK_1
, 0);
6122 REG_WR(bp
, CCM_REG_CCM_INT_MASK
, 0);
6123 /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_0, 0); */
6124 /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_1, 0); */
6126 val
= PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_AFT
|
6127 PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_OF
|
6128 PXP2_PXP2_INT_MASK_0_REG_PGL_PCIE_ATTN
;
6129 if (!CHIP_IS_E1x(bp
))
6130 val
|= PXP2_PXP2_INT_MASK_0_REG_PGL_READ_BLOCKED
|
6131 PXP2_PXP2_INT_MASK_0_REG_PGL_WRITE_BLOCKED
;
6132 REG_WR(bp
, PXP2_REG_PXP2_INT_MASK_0
, val
);
6134 REG_WR(bp
, TSDM_REG_TSDM_INT_MASK_0
, 0);
6135 REG_WR(bp
, TSDM_REG_TSDM_INT_MASK_1
, 0);
6136 REG_WR(bp
, TCM_REG_TCM_INT_MASK
, 0);
6137 /* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_0, 0); */
6139 if (!CHIP_IS_E1x(bp
))
6140 /* enable VFC attentions: bits 11 and 12, bits 31:13 reserved */
6141 REG_WR(bp
, TSEM_REG_TSEM_INT_MASK_1
, 0x07ff);
6143 REG_WR(bp
, CDU_REG_CDU_INT_MASK
, 0);
6144 REG_WR(bp
, DMAE_REG_DMAE_INT_MASK
, 0);
6145 /* REG_WR(bp, MISC_REG_MISC_INT_MASK, 0); */
6146 REG_WR(bp
, PBF_REG_PBF_INT_MASK
, 0x18); /* bit 3,4 masked */
6149 static void bnx2x_reset_common(struct bnx2x
*bp
)
6154 REG_WR(bp
, GRCBASE_MISC
+ MISC_REGISTERS_RESET_REG_1_CLEAR
,
6157 if (CHIP_IS_E3(bp
)) {
6158 val
|= MISC_REGISTERS_RESET_REG_2_MSTAT0
;
6159 val
|= MISC_REGISTERS_RESET_REG_2_MSTAT1
;
6162 REG_WR(bp
, GRCBASE_MISC
+ MISC_REGISTERS_RESET_REG_2_CLEAR
, val
);
6165 static void bnx2x_setup_dmae(struct bnx2x
*bp
)
6168 spin_lock_init(&bp
->dmae_lock
);
6171 static void bnx2x_init_pxp(struct bnx2x
*bp
)
6174 int r_order
, w_order
;
6176 pcie_capability_read_word(bp
->pdev
, PCI_EXP_DEVCTL
, &devctl
);
6177 DP(NETIF_MSG_HW
, "read 0x%x from devctl\n", devctl
);
6178 w_order
= ((devctl
& PCI_EXP_DEVCTL_PAYLOAD
) >> 5);
6180 r_order
= ((devctl
& PCI_EXP_DEVCTL_READRQ
) >> 12);
6182 DP(NETIF_MSG_HW
, "force read order to %d\n", bp
->mrrs
);
6186 bnx2x_init_pxp_arb(bp
, r_order
, w_order
);
6189 static void bnx2x_setup_fan_failure_detection(struct bnx2x
*bp
)
6199 val
= SHMEM_RD(bp
, dev_info
.shared_hw_config
.config2
) &
6200 SHARED_HW_CFG_FAN_FAILURE_MASK
;
6202 if (val
== SHARED_HW_CFG_FAN_FAILURE_ENABLED
)
6206 * The fan failure mechanism is usually related to the PHY type since
6207 * the power consumption of the board is affected by the PHY. Currently,
6208 * fan is required for most designs with SFX7101, BCM8727 and BCM8481.
6210 else if (val
== SHARED_HW_CFG_FAN_FAILURE_PHY_TYPE
)
6211 for (port
= PORT_0
; port
< PORT_MAX
; port
++) {
6213 bnx2x_fan_failure_det_req(
6215 bp
->common
.shmem_base
,
6216 bp
->common
.shmem2_base
,
6220 DP(NETIF_MSG_HW
, "fan detection setting: %d\n", is_required
);
6222 if (is_required
== 0)
6225 /* Fan failure is indicated by SPIO 5 */
6226 bnx2x_set_spio(bp
, MISC_SPIO_SPIO5
, MISC_SPIO_INPUT_HI_Z
);
6228 /* set to active low mode */
6229 val
= REG_RD(bp
, MISC_REG_SPIO_INT
);
6230 val
|= (MISC_SPIO_SPIO5
<< MISC_SPIO_INT_OLD_SET_POS
);
6231 REG_WR(bp
, MISC_REG_SPIO_INT
, val
);
6233 /* enable interrupt to signal the IGU */
6234 val
= REG_RD(bp
, MISC_REG_SPIO_EVENT_EN
);
6235 val
|= MISC_SPIO_SPIO5
;
6236 REG_WR(bp
, MISC_REG_SPIO_EVENT_EN
, val
);
6239 static void bnx2x_pretend_func(struct bnx2x
*bp
, u8 pretend_func_num
)
6245 if (CHIP_IS_E1H(bp
) && (pretend_func_num
>= E1H_FUNC_MAX
))
6248 switch (BP_ABS_FUNC(bp
)) {
6250 offset
= PXP2_REG_PGL_PRETEND_FUNC_F0
;
6253 offset
= PXP2_REG_PGL_PRETEND_FUNC_F1
;
6256 offset
= PXP2_REG_PGL_PRETEND_FUNC_F2
;
6259 offset
= PXP2_REG_PGL_PRETEND_FUNC_F3
;
6262 offset
= PXP2_REG_PGL_PRETEND_FUNC_F4
;
6265 offset
= PXP2_REG_PGL_PRETEND_FUNC_F5
;
6268 offset
= PXP2_REG_PGL_PRETEND_FUNC_F6
;
6271 offset
= PXP2_REG_PGL_PRETEND_FUNC_F7
;
6277 REG_WR(bp
, offset
, pretend_func_num
);
6279 DP(NETIF_MSG_HW
, "Pretending to func %d\n", pretend_func_num
);
6282 void bnx2x_pf_disable(struct bnx2x
*bp
)
6284 u32 val
= REG_RD(bp
, IGU_REG_PF_CONFIGURATION
);
6285 val
&= ~IGU_PF_CONF_FUNC_EN
;
6287 REG_WR(bp
, IGU_REG_PF_CONFIGURATION
, val
);
6288 REG_WR(bp
, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER
, 0);
6289 REG_WR(bp
, CFC_REG_WEAK_ENABLE_PF
, 0);
6292 static void bnx2x__common_init_phy(struct bnx2x
*bp
)
6294 u32 shmem_base
[2], shmem2_base
[2];
6295 /* Avoid common init in case MFW supports LFA */
6296 if (SHMEM2_RD(bp
, size
) >
6297 (u32
)offsetof(struct shmem2_region
, lfa_host_addr
[BP_PORT(bp
)]))
6299 shmem_base
[0] = bp
->common
.shmem_base
;
6300 shmem2_base
[0] = bp
->common
.shmem2_base
;
6301 if (!CHIP_IS_E1x(bp
)) {
6303 SHMEM2_RD(bp
, other_shmem_base_addr
);
6305 SHMEM2_RD(bp
, other_shmem2_base_addr
);
6307 bnx2x_acquire_phy_lock(bp
);
6308 bnx2x_common_init_phy(bp
, shmem_base
, shmem2_base
,
6309 bp
->common
.chip_id
);
6310 bnx2x_release_phy_lock(bp
);
6314 * bnx2x_init_hw_common - initialize the HW at the COMMON phase.
6316 * @bp: driver handle
6318 static int bnx2x_init_hw_common(struct bnx2x
*bp
)
6322 DP(NETIF_MSG_HW
, "starting common init func %d\n", BP_ABS_FUNC(bp
));
6325 * take the UNDI lock to protect undi_unload flow from accessing
6326 * registers while we're resetting the chip
6328 bnx2x_acquire_hw_lock(bp
, HW_LOCK_RESOURCE_RESET
);
6330 bnx2x_reset_common(bp
);
6331 REG_WR(bp
, GRCBASE_MISC
+ MISC_REGISTERS_RESET_REG_1_SET
, 0xffffffff);
6334 if (CHIP_IS_E3(bp
)) {
6335 val
|= MISC_REGISTERS_RESET_REG_2_MSTAT0
;
6336 val
|= MISC_REGISTERS_RESET_REG_2_MSTAT1
;
6338 REG_WR(bp
, GRCBASE_MISC
+ MISC_REGISTERS_RESET_REG_2_SET
, val
);
6340 bnx2x_release_hw_lock(bp
, HW_LOCK_RESOURCE_RESET
);
6342 bnx2x_init_block(bp
, BLOCK_MISC
, PHASE_COMMON
);
6344 if (!CHIP_IS_E1x(bp
)) {
6348 * 4-port mode or 2-port mode we need to turn of master-enable
6349 * for everyone, after that, turn it back on for self.
6350 * so, we disregard multi-function or not, and always disable
6351 * for all functions on the given path, this means 0,2,4,6 for
6352 * path 0 and 1,3,5,7 for path 1
6354 for (abs_func_id
= BP_PATH(bp
);
6355 abs_func_id
< E2_FUNC_MAX
*2; abs_func_id
+= 2) {
6356 if (abs_func_id
== BP_ABS_FUNC(bp
)) {
6358 PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER
,
6363 bnx2x_pretend_func(bp
, abs_func_id
);
6364 /* clear pf enable */
6365 bnx2x_pf_disable(bp
);
6366 bnx2x_pretend_func(bp
, BP_ABS_FUNC(bp
));
6370 bnx2x_init_block(bp
, BLOCK_PXP
, PHASE_COMMON
);
6371 if (CHIP_IS_E1(bp
)) {
6372 /* enable HW interrupt from PXP on USDM overflow
6373 bit 16 on INT_MASK_0 */
6374 REG_WR(bp
, PXP_REG_PXP_INT_MASK_0
, 0);
6377 bnx2x_init_block(bp
, BLOCK_PXP2
, PHASE_COMMON
);
6381 REG_WR(bp
, PXP2_REG_RQ_QM_ENDIAN_M
, 1);
6382 REG_WR(bp
, PXP2_REG_RQ_TM_ENDIAN_M
, 1);
6383 REG_WR(bp
, PXP2_REG_RQ_SRC_ENDIAN_M
, 1);
6384 REG_WR(bp
, PXP2_REG_RQ_CDU_ENDIAN_M
, 1);
6385 REG_WR(bp
, PXP2_REG_RQ_DBG_ENDIAN_M
, 1);
6386 /* make sure this value is 0 */
6387 REG_WR(bp
, PXP2_REG_RQ_HC_ENDIAN_M
, 0);
6389 /* REG_WR(bp, PXP2_REG_RD_PBF_SWAP_MODE, 1); */
6390 REG_WR(bp
, PXP2_REG_RD_QM_SWAP_MODE
, 1);
6391 REG_WR(bp
, PXP2_REG_RD_TM_SWAP_MODE
, 1);
6392 REG_WR(bp
, PXP2_REG_RD_SRC_SWAP_MODE
, 1);
6393 REG_WR(bp
, PXP2_REG_RD_CDURD_SWAP_MODE
, 1);
6396 bnx2x_ilt_init_page_size(bp
, INITOP_SET
);
6398 if (CHIP_REV_IS_FPGA(bp
) && CHIP_IS_E1H(bp
))
6399 REG_WR(bp
, PXP2_REG_PGL_TAGS_LIMIT
, 0x1);
6401 /* let the HW do it's magic ... */
6403 /* finish PXP init */
6404 val
= REG_RD(bp
, PXP2_REG_RQ_CFG_DONE
);
6406 BNX2X_ERR("PXP2 CFG failed\n");
6409 val
= REG_RD(bp
, PXP2_REG_RD_INIT_DONE
);
6411 BNX2X_ERR("PXP2 RD_INIT failed\n");
6415 /* Timers bug workaround E2 only. We need to set the entire ILT to
6416 * have entries with value "0" and valid bit on.
6417 * This needs to be done by the first PF that is loaded in a path
6418 * (i.e. common phase)
6420 if (!CHIP_IS_E1x(bp
)) {
6421 /* In E2 there is a bug in the timers block that can cause function 6 / 7
6422 * (i.e. vnic3) to start even if it is marked as "scan-off".
6423 * This occurs when a different function (func2,3) is being marked
6424 * as "scan-off". Real-life scenario for example: if a driver is being
6425 * load-unloaded while func6,7 are down. This will cause the timer to access
6426 * the ilt, translate to a logical address and send a request to read/write.
6427 * Since the ilt for the function that is down is not valid, this will cause
6428 * a translation error which is unrecoverable.
6429 * The Workaround is intended to make sure that when this happens nothing fatal
6430 * will occur. The workaround:
6431 * 1. First PF driver which loads on a path will:
6432 * a. After taking the chip out of reset, by using pretend,
6433 * it will write "0" to the following registers of
6435 * REG_WR(pdev, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
6436 * REG_WR(pdev, CFC_REG_WEAK_ENABLE_PF,0);
6437 * REG_WR(pdev, CFC_REG_STRONG_ENABLE_PF,0);
6438 * And for itself it will write '1' to
6439 * PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER to enable
6440 * dmae-operations (writing to pram for example.)
6441 * note: can be done for only function 6,7 but cleaner this
6443 * b. Write zero+valid to the entire ILT.
6444 * c. Init the first_timers_ilt_entry, last_timers_ilt_entry of
6445 * VNIC3 (of that port). The range allocated will be the
6446 * entire ILT. This is needed to prevent ILT range error.
6447 * 2. Any PF driver load flow:
6448 * a. ILT update with the physical addresses of the allocated
6450 * b. Wait 20msec. - note that this timeout is needed to make
6451 * sure there are no requests in one of the PXP internal
6452 * queues with "old" ILT addresses.
6453 * c. PF enable in the PGLC.
6454 * d. Clear the was_error of the PF in the PGLC. (could have
6455 * occured while driver was down)
6456 * e. PF enable in the CFC (WEAK + STRONG)
6457 * f. Timers scan enable
6458 * 3. PF driver unload flow:
6459 * a. Clear the Timers scan_en.
6460 * b. Polling for scan_on=0 for that PF.
6461 * c. Clear the PF enable bit in the PXP.
6462 * d. Clear the PF enable in the CFC (WEAK + STRONG)
6463 * e. Write zero+valid to all ILT entries (The valid bit must
6465 * f. If this is VNIC 3 of a port then also init
6466 * first_timers_ilt_entry to zero and last_timers_ilt_entry
6467 * to the last enrty in the ILT.
6470 * Currently the PF error in the PGLC is non recoverable.
6471 * In the future the there will be a recovery routine for this error.
6472 * Currently attention is masked.
6473 * Having an MCP lock on the load/unload process does not guarantee that
6474 * there is no Timer disable during Func6/7 enable. This is because the
6475 * Timers scan is currently being cleared by the MCP on FLR.
6476 * Step 2.d can be done only for PF6/7 and the driver can also check if
6477 * there is error before clearing it. But the flow above is simpler and
6479 * All ILT entries are written by zero+valid and not just PF6/7
6480 * ILT entries since in the future the ILT entries allocation for
6481 * PF-s might be dynamic.
6483 struct ilt_client_info ilt_cli
;
6484 struct bnx2x_ilt ilt
;
6485 memset(&ilt_cli
, 0, sizeof(struct ilt_client_info
));
6486 memset(&ilt
, 0, sizeof(struct bnx2x_ilt
));
6488 /* initialize dummy TM client */
6490 ilt_cli
.end
= ILT_NUM_PAGE_ENTRIES
- 1;
6491 ilt_cli
.client_num
= ILT_CLIENT_TM
;
6493 /* Step 1: set zeroes to all ilt page entries with valid bit on
6494 * Step 2: set the timers first/last ilt entry to point
6495 * to the entire range to prevent ILT range error for 3rd/4th
6496 * vnic (this code assumes existance of the vnic)
6498 * both steps performed by call to bnx2x_ilt_client_init_op()
6499 * with dummy TM client
6501 * we must use pretend since PXP2_REG_RQ_##blk##_FIRST_ILT
6502 * and his brother are split registers
6504 bnx2x_pretend_func(bp
, (BP_PATH(bp
) + 6));
6505 bnx2x_ilt_client_init_op_ilt(bp
, &ilt
, &ilt_cli
, INITOP_CLEAR
);
6506 bnx2x_pretend_func(bp
, BP_ABS_FUNC(bp
));
6508 REG_WR(bp
, PXP2_REG_RQ_DRAM_ALIGN
, BNX2X_PXP_DRAM_ALIGN
);
6509 REG_WR(bp
, PXP2_REG_RQ_DRAM_ALIGN_RD
, BNX2X_PXP_DRAM_ALIGN
);
6510 REG_WR(bp
, PXP2_REG_RQ_DRAM_ALIGN_SEL
, 1);
6514 REG_WR(bp
, PXP2_REG_RQ_DISABLE_INPUTS
, 0);
6515 REG_WR(bp
, PXP2_REG_RD_DISABLE_INPUTS
, 0);
6517 if (!CHIP_IS_E1x(bp
)) {
6518 int factor
= CHIP_REV_IS_EMUL(bp
) ? 1000 :
6519 (CHIP_REV_IS_FPGA(bp
) ? 400 : 0);
6520 bnx2x_init_block(bp
, BLOCK_PGLUE_B
, PHASE_COMMON
);
6522 bnx2x_init_block(bp
, BLOCK_ATC
, PHASE_COMMON
);
6524 /* let the HW do it's magic ... */
6527 val
= REG_RD(bp
, ATC_REG_ATC_INIT_DONE
);
6528 } while (factor
-- && (val
!= 1));
6531 BNX2X_ERR("ATC_INIT failed\n");
6536 bnx2x_init_block(bp
, BLOCK_DMAE
, PHASE_COMMON
);
6538 /* clean the DMAE memory */
6540 bnx2x_init_fill(bp
, TSEM_REG_PRAM
, 0, 8, 1);
6542 bnx2x_init_block(bp
, BLOCK_TCM
, PHASE_COMMON
);
6544 bnx2x_init_block(bp
, BLOCK_UCM
, PHASE_COMMON
);
6546 bnx2x_init_block(bp
, BLOCK_CCM
, PHASE_COMMON
);
6548 bnx2x_init_block(bp
, BLOCK_XCM
, PHASE_COMMON
);
6550 bnx2x_read_dmae(bp
, XSEM_REG_PASSIVE_BUFFER
, 3);
6551 bnx2x_read_dmae(bp
, CSEM_REG_PASSIVE_BUFFER
, 3);
6552 bnx2x_read_dmae(bp
, TSEM_REG_PASSIVE_BUFFER
, 3);
6553 bnx2x_read_dmae(bp
, USEM_REG_PASSIVE_BUFFER
, 3);
6555 bnx2x_init_block(bp
, BLOCK_QM
, PHASE_COMMON
);
6558 /* QM queues pointers table */
6559 bnx2x_qm_init_ptr_table(bp
, bp
->qm_cid_count
, INITOP_SET
);
6561 /* soft reset pulse */
6562 REG_WR(bp
, QM_REG_SOFT_RESET
, 1);
6563 REG_WR(bp
, QM_REG_SOFT_RESET
, 0);
6565 if (CNIC_SUPPORT(bp
))
6566 bnx2x_init_block(bp
, BLOCK_TM
, PHASE_COMMON
);
6568 bnx2x_init_block(bp
, BLOCK_DORQ
, PHASE_COMMON
);
6569 REG_WR(bp
, DORQ_REG_DPM_CID_OFST
, BNX2X_DB_SHIFT
);
6570 if (!CHIP_REV_IS_SLOW(bp
))
6571 /* enable hw interrupt from doorbell Q */
6572 REG_WR(bp
, DORQ_REG_DORQ_INT_MASK
, 0);
6574 bnx2x_init_block(bp
, BLOCK_BRB1
, PHASE_COMMON
);
6576 bnx2x_init_block(bp
, BLOCK_PRS
, PHASE_COMMON
);
6577 REG_WR(bp
, PRS_REG_A_PRSU_20
, 0xf);
6579 if (!CHIP_IS_E1(bp
))
6580 REG_WR(bp
, PRS_REG_E1HOV_MODE
, bp
->path_has_ovlan
);
6582 if (!CHIP_IS_E1x(bp
) && !CHIP_IS_E3B0(bp
)) {
6583 if (IS_MF_AFEX(bp
)) {
6584 /* configure that VNTag and VLAN headers must be
6585 * received in afex mode
6587 REG_WR(bp
, PRS_REG_HDRS_AFTER_BASIC
, 0xE);
6588 REG_WR(bp
, PRS_REG_MUST_HAVE_HDRS
, 0xA);
6589 REG_WR(bp
, PRS_REG_HDRS_AFTER_TAG_0
, 0x6);
6590 REG_WR(bp
, PRS_REG_TAG_ETHERTYPE_0
, 0x8926);
6591 REG_WR(bp
, PRS_REG_TAG_LEN_0
, 0x4);
6593 /* Bit-map indicating which L2 hdrs may appear
6594 * after the basic Ethernet header
6596 REG_WR(bp
, PRS_REG_HDRS_AFTER_BASIC
,
6597 bp
->path_has_ovlan
? 7 : 6);
6601 bnx2x_init_block(bp
, BLOCK_TSDM
, PHASE_COMMON
);
6602 bnx2x_init_block(bp
, BLOCK_CSDM
, PHASE_COMMON
);
6603 bnx2x_init_block(bp
, BLOCK_USDM
, PHASE_COMMON
);
6604 bnx2x_init_block(bp
, BLOCK_XSDM
, PHASE_COMMON
);
6606 if (!CHIP_IS_E1x(bp
)) {
6607 /* reset VFC memories */
6608 REG_WR(bp
, TSEM_REG_FAST_MEMORY
+ VFC_REG_MEMORIES_RST
,
6609 VFC_MEMORIES_RST_REG_CAM_RST
|
6610 VFC_MEMORIES_RST_REG_RAM_RST
);
6611 REG_WR(bp
, XSEM_REG_FAST_MEMORY
+ VFC_REG_MEMORIES_RST
,
6612 VFC_MEMORIES_RST_REG_CAM_RST
|
6613 VFC_MEMORIES_RST_REG_RAM_RST
);
6618 bnx2x_init_block(bp
, BLOCK_TSEM
, PHASE_COMMON
);
6619 bnx2x_init_block(bp
, BLOCK_USEM
, PHASE_COMMON
);
6620 bnx2x_init_block(bp
, BLOCK_CSEM
, PHASE_COMMON
);
6621 bnx2x_init_block(bp
, BLOCK_XSEM
, PHASE_COMMON
);
6624 REG_WR(bp
, GRCBASE_MISC
+ MISC_REGISTERS_RESET_REG_1_CLEAR
,
6626 REG_WR(bp
, GRCBASE_MISC
+ MISC_REGISTERS_RESET_REG_1_SET
,
6629 bnx2x_init_block(bp
, BLOCK_UPB
, PHASE_COMMON
);
6630 bnx2x_init_block(bp
, BLOCK_XPB
, PHASE_COMMON
);
6631 bnx2x_init_block(bp
, BLOCK_PBF
, PHASE_COMMON
);
6633 if (!CHIP_IS_E1x(bp
)) {
6634 if (IS_MF_AFEX(bp
)) {
6635 /* configure that VNTag and VLAN headers must be
6638 REG_WR(bp
, PBF_REG_HDRS_AFTER_BASIC
, 0xE);
6639 REG_WR(bp
, PBF_REG_MUST_HAVE_HDRS
, 0xA);
6640 REG_WR(bp
, PBF_REG_HDRS_AFTER_TAG_0
, 0x6);
6641 REG_WR(bp
, PBF_REG_TAG_ETHERTYPE_0
, 0x8926);
6642 REG_WR(bp
, PBF_REG_TAG_LEN_0
, 0x4);
6644 REG_WR(bp
, PBF_REG_HDRS_AFTER_BASIC
,
6645 bp
->path_has_ovlan
? 7 : 6);
6649 REG_WR(bp
, SRC_REG_SOFT_RST
, 1);
6651 bnx2x_init_block(bp
, BLOCK_SRC
, PHASE_COMMON
);
6653 if (CNIC_SUPPORT(bp
)) {
6654 REG_WR(bp
, SRC_REG_KEYSEARCH_0
, 0x63285672);
6655 REG_WR(bp
, SRC_REG_KEYSEARCH_1
, 0x24b8f2cc);
6656 REG_WR(bp
, SRC_REG_KEYSEARCH_2
, 0x223aef9b);
6657 REG_WR(bp
, SRC_REG_KEYSEARCH_3
, 0x26001e3a);
6658 REG_WR(bp
, SRC_REG_KEYSEARCH_4
, 0x7ae91116);
6659 REG_WR(bp
, SRC_REG_KEYSEARCH_5
, 0x5ce5230b);
6660 REG_WR(bp
, SRC_REG_KEYSEARCH_6
, 0x298d8adf);
6661 REG_WR(bp
, SRC_REG_KEYSEARCH_7
, 0x6eb0ff09);
6662 REG_WR(bp
, SRC_REG_KEYSEARCH_8
, 0x1830f82f);
6663 REG_WR(bp
, SRC_REG_KEYSEARCH_9
, 0x01e46be7);
6665 REG_WR(bp
, SRC_REG_SOFT_RST
, 0);
6667 if (sizeof(union cdu_context
) != 1024)
6668 /* we currently assume that a context is 1024 bytes */
6669 dev_alert(&bp
->pdev
->dev
,
6670 "please adjust the size of cdu_context(%ld)\n",
6671 (long)sizeof(union cdu_context
));
6673 bnx2x_init_block(bp
, BLOCK_CDU
, PHASE_COMMON
);
6674 val
= (4 << 24) + (0 << 12) + 1024;
6675 REG_WR(bp
, CDU_REG_CDU_GLOBAL_PARAMS
, val
);
6677 bnx2x_init_block(bp
, BLOCK_CFC
, PHASE_COMMON
);
6678 REG_WR(bp
, CFC_REG_INIT_REG
, 0x7FF);
6679 /* enable context validation interrupt from CFC */
6680 REG_WR(bp
, CFC_REG_CFC_INT_MASK
, 0);
6682 /* set the thresholds to prevent CFC/CDU race */
6683 REG_WR(bp
, CFC_REG_DEBUG0
, 0x20020000);
6685 bnx2x_init_block(bp
, BLOCK_HC
, PHASE_COMMON
);
6687 if (!CHIP_IS_E1x(bp
) && BP_NOMCP(bp
))
6688 REG_WR(bp
, IGU_REG_RESET_MEMORIES
, 0x36);
6690 bnx2x_init_block(bp
, BLOCK_IGU
, PHASE_COMMON
);
6691 bnx2x_init_block(bp
, BLOCK_MISC_AEU
, PHASE_COMMON
);
6693 /* Reset PCIE errors for debug */
6694 REG_WR(bp
, 0x2814, 0xffffffff);
6695 REG_WR(bp
, 0x3820, 0xffffffff);
6697 if (!CHIP_IS_E1x(bp
)) {
6698 REG_WR(bp
, PCICFG_OFFSET
+ PXPCS_TL_CONTROL_5
,
6699 (PXPCS_TL_CONTROL_5_ERR_UNSPPORT1
|
6700 PXPCS_TL_CONTROL_5_ERR_UNSPPORT
));
6701 REG_WR(bp
, PCICFG_OFFSET
+ PXPCS_TL_FUNC345_STAT
,
6702 (PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT4
|
6703 PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT3
|
6704 PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT2
));
6705 REG_WR(bp
, PCICFG_OFFSET
+ PXPCS_TL_FUNC678_STAT
,
6706 (PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT7
|
6707 PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT6
|
6708 PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT5
));
6711 bnx2x_init_block(bp
, BLOCK_NIG
, PHASE_COMMON
);
6712 if (!CHIP_IS_E1(bp
)) {
6713 /* in E3 this done in per-port section */
6714 if (!CHIP_IS_E3(bp
))
6715 REG_WR(bp
, NIG_REG_LLH_MF_MODE
, IS_MF(bp
));
6717 if (CHIP_IS_E1H(bp
))
6718 /* not applicable for E2 (and above ...) */
6719 REG_WR(bp
, NIG_REG_LLH_E1HOV_MODE
, IS_MF_SD(bp
));
6721 if (CHIP_REV_IS_SLOW(bp
))
6724 /* finish CFC init */
6725 val
= reg_poll(bp
, CFC_REG_LL_INIT_DONE
, 1, 100, 10);
6727 BNX2X_ERR("CFC LL_INIT failed\n");
6730 val
= reg_poll(bp
, CFC_REG_AC_INIT_DONE
, 1, 100, 10);
6732 BNX2X_ERR("CFC AC_INIT failed\n");
6735 val
= reg_poll(bp
, CFC_REG_CAM_INIT_DONE
, 1, 100, 10);
6737 BNX2X_ERR("CFC CAM_INIT failed\n");
6740 REG_WR(bp
, CFC_REG_DEBUG0
, 0);
6742 if (CHIP_IS_E1(bp
)) {
6743 /* read NIG statistic
6744 to see if this is our first up since powerup */
6745 bnx2x_read_dmae(bp
, NIG_REG_STAT2_BRB_OCTET
, 2);
6746 val
= *bnx2x_sp(bp
, wb_data
[0]);
6748 /* do internal memory self test */
6749 if ((val
== 0) && bnx2x_int_mem_test(bp
)) {
6750 BNX2X_ERR("internal mem self test failed\n");
6755 bnx2x_setup_fan_failure_detection(bp
);
6757 /* clear PXP2 attentions */
6758 REG_RD(bp
, PXP2_REG_PXP2_INT_STS_CLR_0
);
6760 bnx2x_enable_blocks_attention(bp
);
6761 bnx2x_enable_blocks_parity(bp
);
6763 if (!BP_NOMCP(bp
)) {
6764 if (CHIP_IS_E1x(bp
))
6765 bnx2x__common_init_phy(bp
);
6767 BNX2X_ERR("Bootcode is missing - can not initialize link\n");
6773 * bnx2x_init_hw_common_chip - init HW at the COMMON_CHIP phase.
6775 * @bp: driver handle
6777 static int bnx2x_init_hw_common_chip(struct bnx2x
*bp
)
6779 int rc
= bnx2x_init_hw_common(bp
);
6784 /* In E2 2-PORT mode, same ext phy is used for the two paths */
6786 bnx2x__common_init_phy(bp
);
6791 static int bnx2x_init_hw_port(struct bnx2x
*bp
)
6793 int port
= BP_PORT(bp
);
6794 int init_phase
= port
? PHASE_PORT1
: PHASE_PORT0
;
6799 DP(NETIF_MSG_HW
, "starting port init port %d\n", port
);
6801 REG_WR(bp
, NIG_REG_MASK_INTERRUPT_PORT0
+ port
*4, 0);
6803 bnx2x_init_block(bp
, BLOCK_MISC
, init_phase
);
6804 bnx2x_init_block(bp
, BLOCK_PXP
, init_phase
);
6805 bnx2x_init_block(bp
, BLOCK_PXP2
, init_phase
);
6807 /* Timers bug workaround: disables the pf_master bit in pglue at
6808 * common phase, we need to enable it here before any dmae access are
6809 * attempted. Therefore we manually added the enable-master to the
6810 * port phase (it also happens in the function phase)
6812 if (!CHIP_IS_E1x(bp
))
6813 REG_WR(bp
, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER
, 1);
6815 bnx2x_init_block(bp
, BLOCK_ATC
, init_phase
);
6816 bnx2x_init_block(bp
, BLOCK_DMAE
, init_phase
);
6817 bnx2x_init_block(bp
, BLOCK_PGLUE_B
, init_phase
);
6818 bnx2x_init_block(bp
, BLOCK_QM
, init_phase
);
6820 bnx2x_init_block(bp
, BLOCK_TCM
, init_phase
);
6821 bnx2x_init_block(bp
, BLOCK_UCM
, init_phase
);
6822 bnx2x_init_block(bp
, BLOCK_CCM
, init_phase
);
6823 bnx2x_init_block(bp
, BLOCK_XCM
, init_phase
);
6825 /* QM cid (connection) count */
6826 bnx2x_qm_init_cid_count(bp
, bp
->qm_cid_count
, INITOP_SET
);
6828 if (CNIC_SUPPORT(bp
)) {
6829 bnx2x_init_block(bp
, BLOCK_TM
, init_phase
);
6830 REG_WR(bp
, TM_REG_LIN0_SCAN_TIME
+ port
*4, 20);
6831 REG_WR(bp
, TM_REG_LIN0_MAX_ACTIVE_CID
+ port
*4, 31);
6834 bnx2x_init_block(bp
, BLOCK_DORQ
, init_phase
);
6836 bnx2x_init_block(bp
, BLOCK_BRB1
, init_phase
);
6838 if (CHIP_IS_E1(bp
) || CHIP_IS_E1H(bp
)) {
6841 low
= ((bp
->flags
& ONE_PORT_FLAG
) ? 160 : 246);
6842 else if (bp
->dev
->mtu
> 4096) {
6843 if (bp
->flags
& ONE_PORT_FLAG
)
6847 /* (24*1024 + val*4)/256 */
6848 low
= 96 + (val
/64) +
6849 ((val
% 64) ? 1 : 0);
6852 low
= ((bp
->flags
& ONE_PORT_FLAG
) ? 80 : 160);
6853 high
= low
+ 56; /* 14*1024/256 */
6854 REG_WR(bp
, BRB1_REG_PAUSE_LOW_THRESHOLD_0
+ port
*4, low
);
6855 REG_WR(bp
, BRB1_REG_PAUSE_HIGH_THRESHOLD_0
+ port
*4, high
);
6858 if (CHIP_MODE_IS_4_PORT(bp
))
6859 REG_WR(bp
, (BP_PORT(bp
) ?
6860 BRB1_REG_MAC_GUARANTIED_1
:
6861 BRB1_REG_MAC_GUARANTIED_0
), 40);
6864 bnx2x_init_block(bp
, BLOCK_PRS
, init_phase
);
6865 if (CHIP_IS_E3B0(bp
)) {
6866 if (IS_MF_AFEX(bp
)) {
6867 /* configure headers for AFEX mode */
6868 REG_WR(bp
, BP_PORT(bp
) ?
6869 PRS_REG_HDRS_AFTER_BASIC_PORT_1
:
6870 PRS_REG_HDRS_AFTER_BASIC_PORT_0
, 0xE);
6871 REG_WR(bp
, BP_PORT(bp
) ?
6872 PRS_REG_HDRS_AFTER_TAG_0_PORT_1
:
6873 PRS_REG_HDRS_AFTER_TAG_0_PORT_0
, 0x6);
6874 REG_WR(bp
, BP_PORT(bp
) ?
6875 PRS_REG_MUST_HAVE_HDRS_PORT_1
:
6876 PRS_REG_MUST_HAVE_HDRS_PORT_0
, 0xA);
6878 /* Ovlan exists only if we are in multi-function +
6879 * switch-dependent mode, in switch-independent there
6880 * is no ovlan headers
6882 REG_WR(bp
, BP_PORT(bp
) ?
6883 PRS_REG_HDRS_AFTER_BASIC_PORT_1
:
6884 PRS_REG_HDRS_AFTER_BASIC_PORT_0
,
6885 (bp
->path_has_ovlan
? 7 : 6));
6889 bnx2x_init_block(bp
, BLOCK_TSDM
, init_phase
);
6890 bnx2x_init_block(bp
, BLOCK_CSDM
, init_phase
);
6891 bnx2x_init_block(bp
, BLOCK_USDM
, init_phase
);
6892 bnx2x_init_block(bp
, BLOCK_XSDM
, init_phase
);
6894 bnx2x_init_block(bp
, BLOCK_TSEM
, init_phase
);
6895 bnx2x_init_block(bp
, BLOCK_USEM
, init_phase
);
6896 bnx2x_init_block(bp
, BLOCK_CSEM
, init_phase
);
6897 bnx2x_init_block(bp
, BLOCK_XSEM
, init_phase
);
6899 bnx2x_init_block(bp
, BLOCK_UPB
, init_phase
);
6900 bnx2x_init_block(bp
, BLOCK_XPB
, init_phase
);
6902 bnx2x_init_block(bp
, BLOCK_PBF
, init_phase
);
6904 if (CHIP_IS_E1x(bp
)) {
6905 /* configure PBF to work without PAUSE mtu 9000 */
6906 REG_WR(bp
, PBF_REG_P0_PAUSE_ENABLE
+ port
*4, 0);
6908 /* update threshold */
6909 REG_WR(bp
, PBF_REG_P0_ARB_THRSH
+ port
*4, (9040/16));
6910 /* update init credit */
6911 REG_WR(bp
, PBF_REG_P0_INIT_CRD
+ port
*4, (9040/16) + 553 - 22);
6914 REG_WR(bp
, PBF_REG_INIT_P0
+ port
*4, 1);
6916 REG_WR(bp
, PBF_REG_INIT_P0
+ port
*4, 0);
6919 if (CNIC_SUPPORT(bp
))
6920 bnx2x_init_block(bp
, BLOCK_SRC
, init_phase
);
6922 bnx2x_init_block(bp
, BLOCK_CDU
, init_phase
);
6923 bnx2x_init_block(bp
, BLOCK_CFC
, init_phase
);
6925 if (CHIP_IS_E1(bp
)) {
6926 REG_WR(bp
, HC_REG_LEADING_EDGE_0
+ port
*8, 0);
6927 REG_WR(bp
, HC_REG_TRAILING_EDGE_0
+ port
*8, 0);
6929 bnx2x_init_block(bp
, BLOCK_HC
, init_phase
);
6931 bnx2x_init_block(bp
, BLOCK_IGU
, init_phase
);
6933 bnx2x_init_block(bp
, BLOCK_MISC_AEU
, init_phase
);
6934 /* init aeu_mask_attn_func_0/1:
6935 * - SF mode: bits 3-7 are masked. only bits 0-2 are in use
6936 * - MF mode: bit 3 is masked. bits 0-2 are in use as in SF
6937 * bits 4-7 are used for "per vn group attention" */
6938 val
= IS_MF(bp
) ? 0xF7 : 0x7;
6939 /* Enable DCBX attention for all but E1 */
6940 val
|= CHIP_IS_E1(bp
) ? 0 : 0x10;
6941 REG_WR(bp
, MISC_REG_AEU_MASK_ATTN_FUNC_0
+ port
*4, val
);
6943 bnx2x_init_block(bp
, BLOCK_NIG
, init_phase
);
6945 if (!CHIP_IS_E1x(bp
)) {
6946 /* Bit-map indicating which L2 hdrs may appear after the
6947 * basic Ethernet header
6950 REG_WR(bp
, BP_PORT(bp
) ?
6951 NIG_REG_P1_HDRS_AFTER_BASIC
:
6952 NIG_REG_P0_HDRS_AFTER_BASIC
, 0xE);
6954 REG_WR(bp
, BP_PORT(bp
) ?
6955 NIG_REG_P1_HDRS_AFTER_BASIC
:
6956 NIG_REG_P0_HDRS_AFTER_BASIC
,
6957 IS_MF_SD(bp
) ? 7 : 6);
6960 REG_WR(bp
, BP_PORT(bp
) ?
6961 NIG_REG_LLH1_MF_MODE
:
6962 NIG_REG_LLH_MF_MODE
, IS_MF(bp
));
6964 if (!CHIP_IS_E3(bp
))
6965 REG_WR(bp
, NIG_REG_XGXS_SERDES0_MODE_SEL
+ port
*4, 1);
6967 if (!CHIP_IS_E1(bp
)) {
6968 /* 0x2 disable mf_ov, 0x1 enable */
6969 REG_WR(bp
, NIG_REG_LLH0_BRB1_DRV_MASK_MF
+ port
*4,
6970 (IS_MF_SD(bp
) ? 0x1 : 0x2));
6972 if (!CHIP_IS_E1x(bp
)) {
6974 switch (bp
->mf_mode
) {
6975 case MULTI_FUNCTION_SD
:
6978 case MULTI_FUNCTION_SI
:
6979 case MULTI_FUNCTION_AFEX
:
6984 REG_WR(bp
, (BP_PORT(bp
) ? NIG_REG_LLH1_CLS_TYPE
:
6985 NIG_REG_LLH0_CLS_TYPE
), val
);
6988 REG_WR(bp
, NIG_REG_LLFC_ENABLE_0
+ port
*4, 0);
6989 REG_WR(bp
, NIG_REG_LLFC_OUT_EN_0
+ port
*4, 0);
6990 REG_WR(bp
, NIG_REG_PAUSE_ENABLE_0
+ port
*4, 1);
6995 /* If SPIO5 is set to generate interrupts, enable it for this port */
6996 val
= REG_RD(bp
, MISC_REG_SPIO_EVENT_EN
);
6997 if (val
& MISC_SPIO_SPIO5
) {
6998 u32 reg_addr
= (port
? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0
:
6999 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0
);
7000 val
= REG_RD(bp
, reg_addr
);
7001 val
|= AEU_INPUTS_ATTN_BITS_SPIO5
;
7002 REG_WR(bp
, reg_addr
, val
);
7008 static void bnx2x_ilt_wr(struct bnx2x
*bp
, u32 index
, dma_addr_t addr
)
7014 reg
= PXP2_REG_RQ_ONCHIP_AT
+ index
*8;
7016 reg
= PXP2_REG_RQ_ONCHIP_AT_B0
+ index
*8;
7018 wb_write
[0] = ONCHIP_ADDR1(addr
);
7019 wb_write
[1] = ONCHIP_ADDR2(addr
);
7020 REG_WR_DMAE(bp
, reg
, wb_write
, 2);
7023 static void bnx2x_igu_clear_sb_gen(struct bnx2x
*bp
, u8 func
,
7024 u8 idu_sb_id
, bool is_Pf
)
7026 u32 data
, ctl
, cnt
= 100;
7027 u32 igu_addr_data
= IGU_REG_COMMAND_REG_32LSB_DATA
;
7028 u32 igu_addr_ctl
= IGU_REG_COMMAND_REG_CTRL
;
7029 u32 igu_addr_ack
= IGU_REG_CSTORM_TYPE_0_SB_CLEANUP
+ (idu_sb_id
/32)*4;
7030 u32 sb_bit
= 1 << (idu_sb_id
%32);
7031 u32 func_encode
= func
| (is_Pf
? 1 : 0) << IGU_FID_ENCODE_IS_PF_SHIFT
;
7032 u32 addr_encode
= IGU_CMD_E2_PROD_UPD_BASE
+ idu_sb_id
;
7034 /* Not supported in BC mode */
7035 if (CHIP_INT_MODE_IS_BC(bp
))
7038 data
= (IGU_USE_REGISTER_cstorm_type_0_sb_cleanup
7039 << IGU_REGULAR_CLEANUP_TYPE_SHIFT
) |
7040 IGU_REGULAR_CLEANUP_SET
|
7041 IGU_REGULAR_BCLEANUP
;
7043 ctl
= addr_encode
<< IGU_CTRL_REG_ADDRESS_SHIFT
|
7044 func_encode
<< IGU_CTRL_REG_FID_SHIFT
|
7045 IGU_CTRL_CMD_TYPE_WR
<< IGU_CTRL_REG_TYPE_SHIFT
;
7047 DP(NETIF_MSG_HW
, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
7048 data
, igu_addr_data
);
7049 REG_WR(bp
, igu_addr_data
, data
);
7052 DP(NETIF_MSG_HW
, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
7054 REG_WR(bp
, igu_addr_ctl
, ctl
);
7058 /* wait for clean up to finish */
7059 while (!(REG_RD(bp
, igu_addr_ack
) & sb_bit
) && --cnt
)
7063 if (!(REG_RD(bp
, igu_addr_ack
) & sb_bit
)) {
7065 "Unable to finish IGU cleanup: idu_sb_id %d offset %d bit %d (cnt %d)\n",
7066 idu_sb_id
, idu_sb_id
/32, idu_sb_id
%32, cnt
);
7070 static void bnx2x_igu_clear_sb(struct bnx2x
*bp
, u8 idu_sb_id
)
7072 bnx2x_igu_clear_sb_gen(bp
, BP_FUNC(bp
), idu_sb_id
, true /*PF*/);
7075 static void bnx2x_clear_func_ilt(struct bnx2x
*bp
, u32 func
)
7077 u32 i
, base
= FUNC_ILT_BASE(func
);
7078 for (i
= base
; i
< base
+ ILT_PER_FUNC
; i
++)
7079 bnx2x_ilt_wr(bp
, i
, 0);
7083 static void bnx2x_init_searcher(struct bnx2x
*bp
)
7085 int port
= BP_PORT(bp
);
7086 bnx2x_src_init_t2(bp
, bp
->t2
, bp
->t2_mapping
, SRC_CONN_NUM
);
7087 /* T1 hash bits value determines the T1 number of entries */
7088 REG_WR(bp
, SRC_REG_NUMBER_HASH_BITS0
+ port
*4, SRC_HASH_BITS
);
7091 static inline int bnx2x_func_switch_update(struct bnx2x
*bp
, int suspend
)
7094 struct bnx2x_func_state_params func_params
= {NULL
};
7095 struct bnx2x_func_switch_update_params
*switch_update_params
=
7096 &func_params
.params
.switch_update
;
7098 /* Prepare parameters for function state transitions */
7099 __set_bit(RAMROD_COMP_WAIT
, &func_params
.ramrod_flags
);
7100 __set_bit(RAMROD_RETRY
, &func_params
.ramrod_flags
);
7102 func_params
.f_obj
= &bp
->func_obj
;
7103 func_params
.cmd
= BNX2X_F_CMD_SWITCH_UPDATE
;
7105 /* Function parameters */
7106 switch_update_params
->suspend
= suspend
;
7108 rc
= bnx2x_func_state_change(bp
, &func_params
);
7113 static int bnx2x_reset_nic_mode(struct bnx2x
*bp
)
7115 int rc
, i
, port
= BP_PORT(bp
);
7116 int vlan_en
= 0, mac_en
[NUM_MACS
];
7119 /* Close input from network */
7120 if (bp
->mf_mode
== SINGLE_FUNCTION
) {
7121 bnx2x_set_rx_filter(&bp
->link_params
, 0);
7123 vlan_en
= REG_RD(bp
, port
? NIG_REG_LLH1_FUNC_EN
:
7124 NIG_REG_LLH0_FUNC_EN
);
7125 REG_WR(bp
, port
? NIG_REG_LLH1_FUNC_EN
:
7126 NIG_REG_LLH0_FUNC_EN
, 0);
7127 for (i
= 0; i
< NUM_MACS
; i
++) {
7128 mac_en
[i
] = REG_RD(bp
, port
?
7129 (NIG_REG_LLH1_FUNC_MEM_ENABLE
+
7131 (NIG_REG_LLH0_FUNC_MEM_ENABLE
+
7133 REG_WR(bp
, port
? (NIG_REG_LLH1_FUNC_MEM_ENABLE
+
7135 (NIG_REG_LLH0_FUNC_MEM_ENABLE
+ 4 * i
), 0);
7139 /* Close BMC to host */
7140 REG_WR(bp
, port
? NIG_REG_P0_TX_MNG_HOST_ENABLE
:
7141 NIG_REG_P1_TX_MNG_HOST_ENABLE
, 0);
7143 /* Suspend Tx switching to the PF. Completion of this ramrod
7144 * further guarantees that all the packets of that PF / child
7145 * VFs in BRB were processed by the Parser, so it is safe to
7146 * change the NIC_MODE register.
7148 rc
= bnx2x_func_switch_update(bp
, 1);
7150 BNX2X_ERR("Can't suspend tx-switching!\n");
7154 /* Change NIC_MODE register */
7155 REG_WR(bp
, PRS_REG_NIC_MODE
, 0);
7157 /* Open input from network */
7158 if (bp
->mf_mode
== SINGLE_FUNCTION
) {
7159 bnx2x_set_rx_filter(&bp
->link_params
, 1);
7161 REG_WR(bp
, port
? NIG_REG_LLH1_FUNC_EN
:
7162 NIG_REG_LLH0_FUNC_EN
, vlan_en
);
7163 for (i
= 0; i
< NUM_MACS
; i
++) {
7164 REG_WR(bp
, port
? (NIG_REG_LLH1_FUNC_MEM_ENABLE
+
7166 (NIG_REG_LLH0_FUNC_MEM_ENABLE
+ 4 * i
),
7171 /* Enable BMC to host */
7172 REG_WR(bp
, port
? NIG_REG_P0_TX_MNG_HOST_ENABLE
:
7173 NIG_REG_P1_TX_MNG_HOST_ENABLE
, 1);
7175 /* Resume Tx switching to the PF */
7176 rc
= bnx2x_func_switch_update(bp
, 0);
7178 BNX2X_ERR("Can't resume tx-switching!\n");
7182 DP(NETIF_MSG_IFUP
, "NIC MODE disabled\n");
7186 int bnx2x_init_hw_func_cnic(struct bnx2x
*bp
)
7190 bnx2x_ilt_init_op_cnic(bp
, INITOP_SET
);
7192 if (CONFIGURE_NIC_MODE(bp
)) {
7193 /* Configrue searcher as part of function hw init */
7194 bnx2x_init_searcher(bp
);
7196 /* Reset NIC mode */
7197 rc
= bnx2x_reset_nic_mode(bp
);
7199 BNX2X_ERR("Can't change NIC mode!\n");
7206 static int bnx2x_init_hw_func(struct bnx2x
*bp
)
7208 int port
= BP_PORT(bp
);
7209 int func
= BP_FUNC(bp
);
7210 int init_phase
= PHASE_PF0
+ func
;
7211 struct bnx2x_ilt
*ilt
= BP_ILT(bp
);
7214 u32 main_mem_base
, main_mem_size
, main_mem_prty_clr
;
7215 int i
, main_mem_width
, rc
;
7217 DP(NETIF_MSG_HW
, "starting func init func %d\n", func
);
7219 /* FLR cleanup - hmmm */
7220 if (!CHIP_IS_E1x(bp
)) {
7221 rc
= bnx2x_pf_flr_clnup(bp
);
7226 /* set MSI reconfigure capability */
7227 if (bp
->common
.int_block
== INT_BLOCK_HC
) {
7228 addr
= (port
? HC_REG_CONFIG_1
: HC_REG_CONFIG_0
);
7229 val
= REG_RD(bp
, addr
);
7230 val
|= HC_CONFIG_0_REG_MSI_ATTN_EN_0
;
7231 REG_WR(bp
, addr
, val
);
7234 bnx2x_init_block(bp
, BLOCK_PXP
, init_phase
);
7235 bnx2x_init_block(bp
, BLOCK_PXP2
, init_phase
);
7238 cdu_ilt_start
= ilt
->clients
[ILT_CLIENT_CDU
].start
;
7240 for (i
= 0; i
< L2_ILT_LINES(bp
); i
++) {
7241 ilt
->lines
[cdu_ilt_start
+ i
].page
= bp
->context
[i
].vcxt
;
7242 ilt
->lines
[cdu_ilt_start
+ i
].page_mapping
=
7243 bp
->context
[i
].cxt_mapping
;
7244 ilt
->lines
[cdu_ilt_start
+ i
].size
= bp
->context
[i
].size
;
7246 bnx2x_ilt_init_op(bp
, INITOP_SET
);
7248 if (!CONFIGURE_NIC_MODE(bp
)) {
7249 bnx2x_init_searcher(bp
);
7250 REG_WR(bp
, PRS_REG_NIC_MODE
, 0);
7251 DP(NETIF_MSG_IFUP
, "NIC MODE disabled\n");
7254 REG_WR(bp
, PRS_REG_NIC_MODE
, 1);
7255 DP(NETIF_MSG_IFUP
, "NIC MODE configrued\n");
7259 if (!CHIP_IS_E1x(bp
)) {
7260 u32 pf_conf
= IGU_PF_CONF_FUNC_EN
;
7262 /* Turn on a single ISR mode in IGU if driver is going to use
7265 if (!(bp
->flags
& USING_MSIX_FLAG
))
7266 pf_conf
|= IGU_PF_CONF_SINGLE_ISR_EN
;
7268 * Timers workaround bug: function init part.
7269 * Need to wait 20msec after initializing ILT,
7270 * needed to make sure there are no requests in
7271 * one of the PXP internal queues with "old" ILT addresses
7275 * Master enable - Due to WB DMAE writes performed before this
7276 * register is re-initialized as part of the regular function
7279 REG_WR(bp
, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER
, 1);
7280 /* Enable the function in IGU */
7281 REG_WR(bp
, IGU_REG_PF_CONFIGURATION
, pf_conf
);
7286 bnx2x_init_block(bp
, BLOCK_PGLUE_B
, init_phase
);
7288 if (!CHIP_IS_E1x(bp
))
7289 REG_WR(bp
, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR
, func
);
7291 bnx2x_init_block(bp
, BLOCK_ATC
, init_phase
);
7292 bnx2x_init_block(bp
, BLOCK_DMAE
, init_phase
);
7293 bnx2x_init_block(bp
, BLOCK_NIG
, init_phase
);
7294 bnx2x_init_block(bp
, BLOCK_SRC
, init_phase
);
7295 bnx2x_init_block(bp
, BLOCK_MISC
, init_phase
);
7296 bnx2x_init_block(bp
, BLOCK_TCM
, init_phase
);
7297 bnx2x_init_block(bp
, BLOCK_UCM
, init_phase
);
7298 bnx2x_init_block(bp
, BLOCK_CCM
, init_phase
);
7299 bnx2x_init_block(bp
, BLOCK_XCM
, init_phase
);
7300 bnx2x_init_block(bp
, BLOCK_TSEM
, init_phase
);
7301 bnx2x_init_block(bp
, BLOCK_USEM
, init_phase
);
7302 bnx2x_init_block(bp
, BLOCK_CSEM
, init_phase
);
7303 bnx2x_init_block(bp
, BLOCK_XSEM
, init_phase
);
7305 if (!CHIP_IS_E1x(bp
))
7306 REG_WR(bp
, QM_REG_PF_EN
, 1);
7308 if (!CHIP_IS_E1x(bp
)) {
7309 REG_WR(bp
, TSEM_REG_VFPF_ERR_NUM
, BNX2X_MAX_NUM_OF_VFS
+ func
);
7310 REG_WR(bp
, USEM_REG_VFPF_ERR_NUM
, BNX2X_MAX_NUM_OF_VFS
+ func
);
7311 REG_WR(bp
, CSEM_REG_VFPF_ERR_NUM
, BNX2X_MAX_NUM_OF_VFS
+ func
);
7312 REG_WR(bp
, XSEM_REG_VFPF_ERR_NUM
, BNX2X_MAX_NUM_OF_VFS
+ func
);
7314 bnx2x_init_block(bp
, BLOCK_QM
, init_phase
);
7316 bnx2x_init_block(bp
, BLOCK_TM
, init_phase
);
7317 bnx2x_init_block(bp
, BLOCK_DORQ
, init_phase
);
7318 bnx2x_init_block(bp
, BLOCK_BRB1
, init_phase
);
7319 bnx2x_init_block(bp
, BLOCK_PRS
, init_phase
);
7320 bnx2x_init_block(bp
, BLOCK_TSDM
, init_phase
);
7321 bnx2x_init_block(bp
, BLOCK_CSDM
, init_phase
);
7322 bnx2x_init_block(bp
, BLOCK_USDM
, init_phase
);
7323 bnx2x_init_block(bp
, BLOCK_XSDM
, init_phase
);
7324 bnx2x_init_block(bp
, BLOCK_UPB
, init_phase
);
7325 bnx2x_init_block(bp
, BLOCK_XPB
, init_phase
);
7326 bnx2x_init_block(bp
, BLOCK_PBF
, init_phase
);
7327 if (!CHIP_IS_E1x(bp
))
7328 REG_WR(bp
, PBF_REG_DISABLE_PF
, 0);
7330 bnx2x_init_block(bp
, BLOCK_CDU
, init_phase
);
7332 bnx2x_init_block(bp
, BLOCK_CFC
, init_phase
);
7334 if (!CHIP_IS_E1x(bp
))
7335 REG_WR(bp
, CFC_REG_WEAK_ENABLE_PF
, 1);
7338 REG_WR(bp
, NIG_REG_LLH0_FUNC_EN
+ port
*8, 1);
7339 REG_WR(bp
, NIG_REG_LLH0_FUNC_VLAN_ID
+ port
*8, bp
->mf_ov
);
7342 bnx2x_init_block(bp
, BLOCK_MISC_AEU
, init_phase
);
7344 /* HC init per function */
7345 if (bp
->common
.int_block
== INT_BLOCK_HC
) {
7346 if (CHIP_IS_E1H(bp
)) {
7347 REG_WR(bp
, MISC_REG_AEU_GENERAL_ATTN_12
+ func
*4, 0);
7349 REG_WR(bp
, HC_REG_LEADING_EDGE_0
+ port
*8, 0);
7350 REG_WR(bp
, HC_REG_TRAILING_EDGE_0
+ port
*8, 0);
7352 bnx2x_init_block(bp
, BLOCK_HC
, init_phase
);
7355 int num_segs
, sb_idx
, prod_offset
;
7357 REG_WR(bp
, MISC_REG_AEU_GENERAL_ATTN_12
+ func
*4, 0);
7359 if (!CHIP_IS_E1x(bp
)) {
7360 REG_WR(bp
, IGU_REG_LEADING_EDGE_LATCH
, 0);
7361 REG_WR(bp
, IGU_REG_TRAILING_EDGE_LATCH
, 0);
7364 bnx2x_init_block(bp
, BLOCK_IGU
, init_phase
);
7366 if (!CHIP_IS_E1x(bp
)) {
7370 * E2 mode: address 0-135 match to the mapping memory;
7371 * 136 - PF0 default prod; 137 - PF1 default prod;
7372 * 138 - PF2 default prod; 139 - PF3 default prod;
7373 * 140 - PF0 attn prod; 141 - PF1 attn prod;
7374 * 142 - PF2 attn prod; 143 - PF3 attn prod;
7377 * E1.5 mode - In backward compatible mode;
7378 * for non default SB; each even line in the memory
7379 * holds the U producer and each odd line hold
7380 * the C producer. The first 128 producers are for
7381 * NDSB (PF0 - 0-31; PF1 - 32-63 and so on). The last 20
7382 * producers are for the DSB for each PF.
7383 * Each PF has five segments: (the order inside each
7384 * segment is PF0; PF1; PF2; PF3) - 128-131 U prods;
7385 * 132-135 C prods; 136-139 X prods; 140-143 T prods;
7386 * 144-147 attn prods;
7388 /* non-default-status-blocks */
7389 num_segs
= CHIP_INT_MODE_IS_BC(bp
) ?
7390 IGU_BC_NDSB_NUM_SEGS
: IGU_NORM_NDSB_NUM_SEGS
;
7391 for (sb_idx
= 0; sb_idx
< bp
->igu_sb_cnt
; sb_idx
++) {
7392 prod_offset
= (bp
->igu_base_sb
+ sb_idx
) *
7395 for (i
= 0; i
< num_segs
; i
++) {
7396 addr
= IGU_REG_PROD_CONS_MEMORY
+
7397 (prod_offset
+ i
) * 4;
7398 REG_WR(bp
, addr
, 0);
7400 /* send consumer update with value 0 */
7401 bnx2x_ack_sb(bp
, bp
->igu_base_sb
+ sb_idx
,
7402 USTORM_ID
, 0, IGU_INT_NOP
, 1);
7403 bnx2x_igu_clear_sb(bp
,
7404 bp
->igu_base_sb
+ sb_idx
);
7407 /* default-status-blocks */
7408 num_segs
= CHIP_INT_MODE_IS_BC(bp
) ?
7409 IGU_BC_DSB_NUM_SEGS
: IGU_NORM_DSB_NUM_SEGS
;
7411 if (CHIP_MODE_IS_4_PORT(bp
))
7412 dsb_idx
= BP_FUNC(bp
);
7414 dsb_idx
= BP_VN(bp
);
7416 prod_offset
= (CHIP_INT_MODE_IS_BC(bp
) ?
7417 IGU_BC_BASE_DSB_PROD
+ dsb_idx
:
7418 IGU_NORM_BASE_DSB_PROD
+ dsb_idx
);
7421 * igu prods come in chunks of E1HVN_MAX (4) -
7422 * does not matters what is the current chip mode
7424 for (i
= 0; i
< (num_segs
* E1HVN_MAX
);
7426 addr
= IGU_REG_PROD_CONS_MEMORY
+
7427 (prod_offset
+ i
)*4;
7428 REG_WR(bp
, addr
, 0);
7430 /* send consumer update with 0 */
7431 if (CHIP_INT_MODE_IS_BC(bp
)) {
7432 bnx2x_ack_sb(bp
, bp
->igu_dsb_id
,
7433 USTORM_ID
, 0, IGU_INT_NOP
, 1);
7434 bnx2x_ack_sb(bp
, bp
->igu_dsb_id
,
7435 CSTORM_ID
, 0, IGU_INT_NOP
, 1);
7436 bnx2x_ack_sb(bp
, bp
->igu_dsb_id
,
7437 XSTORM_ID
, 0, IGU_INT_NOP
, 1);
7438 bnx2x_ack_sb(bp
, bp
->igu_dsb_id
,
7439 TSTORM_ID
, 0, IGU_INT_NOP
, 1);
7440 bnx2x_ack_sb(bp
, bp
->igu_dsb_id
,
7441 ATTENTION_ID
, 0, IGU_INT_NOP
, 1);
7443 bnx2x_ack_sb(bp
, bp
->igu_dsb_id
,
7444 USTORM_ID
, 0, IGU_INT_NOP
, 1);
7445 bnx2x_ack_sb(bp
, bp
->igu_dsb_id
,
7446 ATTENTION_ID
, 0, IGU_INT_NOP
, 1);
7448 bnx2x_igu_clear_sb(bp
, bp
->igu_dsb_id
);
7450 /* !!! these should become driver const once
7451 rf-tool supports split-68 const */
7452 REG_WR(bp
, IGU_REG_SB_INT_BEFORE_MASK_LSB
, 0);
7453 REG_WR(bp
, IGU_REG_SB_INT_BEFORE_MASK_MSB
, 0);
7454 REG_WR(bp
, IGU_REG_SB_MASK_LSB
, 0);
7455 REG_WR(bp
, IGU_REG_SB_MASK_MSB
, 0);
7456 REG_WR(bp
, IGU_REG_PBA_STATUS_LSB
, 0);
7457 REG_WR(bp
, IGU_REG_PBA_STATUS_MSB
, 0);
7461 /* Reset PCIE errors for debug */
7462 REG_WR(bp
, 0x2114, 0xffffffff);
7463 REG_WR(bp
, 0x2120, 0xffffffff);
7465 if (CHIP_IS_E1x(bp
)) {
7466 main_mem_size
= HC_REG_MAIN_MEMORY_SIZE
/ 2; /*dwords*/
7467 main_mem_base
= HC_REG_MAIN_MEMORY
+
7468 BP_PORT(bp
) * (main_mem_size
* 4);
7469 main_mem_prty_clr
= HC_REG_HC_PRTY_STS_CLR
;
7472 val
= REG_RD(bp
, main_mem_prty_clr
);
7475 "Hmmm... Parity errors in HC block during function init (0x%x)!\n",
7478 /* Clear "false" parity errors in MSI-X table */
7479 for (i
= main_mem_base
;
7480 i
< main_mem_base
+ main_mem_size
* 4;
7481 i
+= main_mem_width
) {
7482 bnx2x_read_dmae(bp
, i
, main_mem_width
/ 4);
7483 bnx2x_write_dmae(bp
, bnx2x_sp_mapping(bp
, wb_data
),
7484 i
, main_mem_width
/ 4);
7486 /* Clear HC parity attention */
7487 REG_RD(bp
, main_mem_prty_clr
);
7490 #ifdef BNX2X_STOP_ON_ERROR
7491 /* Enable STORMs SP logging */
7492 REG_WR8(bp
, BAR_USTRORM_INTMEM
+
7493 USTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp
)), 1);
7494 REG_WR8(bp
, BAR_TSTRORM_INTMEM
+
7495 TSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp
)), 1);
7496 REG_WR8(bp
, BAR_CSTRORM_INTMEM
+
7497 CSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp
)), 1);
7498 REG_WR8(bp
, BAR_XSTRORM_INTMEM
+
7499 XSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp
)), 1);
7502 bnx2x_phy_probe(&bp
->link_params
);
7508 void bnx2x_free_mem_cnic(struct bnx2x
*bp
)
7510 bnx2x_ilt_mem_op_cnic(bp
, ILT_MEMOP_FREE
);
7512 if (!CHIP_IS_E1x(bp
))
7513 BNX2X_PCI_FREE(bp
->cnic_sb
.e2_sb
, bp
->cnic_sb_mapping
,
7514 sizeof(struct host_hc_status_block_e2
));
7516 BNX2X_PCI_FREE(bp
->cnic_sb
.e1x_sb
, bp
->cnic_sb_mapping
,
7517 sizeof(struct host_hc_status_block_e1x
));
7519 BNX2X_PCI_FREE(bp
->t2
, bp
->t2_mapping
, SRC_T2_SZ
);
7522 void bnx2x_free_mem(struct bnx2x
*bp
)
7527 bnx2x_free_fp_mem(bp
);
7528 /* end of fastpath */
7530 BNX2X_PCI_FREE(bp
->def_status_blk
, bp
->def_status_blk_mapping
,
7531 sizeof(struct host_sp_status_block
));
7533 BNX2X_PCI_FREE(bp
->fw_stats
, bp
->fw_stats_mapping
,
7534 bp
->fw_stats_data_sz
+ bp
->fw_stats_req_sz
);
7536 BNX2X_PCI_FREE(bp
->slowpath
, bp
->slowpath_mapping
,
7537 sizeof(struct bnx2x_slowpath
));
7539 for (i
= 0; i
< L2_ILT_LINES(bp
); i
++)
7540 BNX2X_PCI_FREE(bp
->context
[i
].vcxt
, bp
->context
[i
].cxt_mapping
,
7541 bp
->context
[i
].size
);
7542 bnx2x_ilt_mem_op(bp
, ILT_MEMOP_FREE
);
7544 BNX2X_FREE(bp
->ilt
->lines
);
7546 BNX2X_PCI_FREE(bp
->spq
, bp
->spq_mapping
, BCM_PAGE_SIZE
);
7548 BNX2X_PCI_FREE(bp
->eq_ring
, bp
->eq_mapping
,
7549 BCM_PAGE_SIZE
* NUM_EQ_PAGES
);
7552 static int bnx2x_alloc_fw_stats_mem(struct bnx2x
*bp
)
7555 int is_fcoe_stats
= NO_FCOE(bp
) ? 0 : 1;
7557 /* number of queues for statistics is number of eth queues + FCoE */
7558 u8 num_queue_stats
= BNX2X_NUM_ETH_QUEUES(bp
) + is_fcoe_stats
;
7560 /* Total number of FW statistics requests =
7561 * 1 for port stats + 1 for PF stats + potential 1 for FCoE stats +
7564 bp
->fw_stats_num
= 2 + is_fcoe_stats
+ num_queue_stats
;
7567 /* Request is built from stats_query_header and an array of
7568 * stats_query_cmd_group each of which contains
7569 * STATS_QUERY_CMD_COUNT rules. The real number or requests is
7570 * configured in the stats_query_header.
7572 num_groups
= ((bp
->fw_stats_num
) / STATS_QUERY_CMD_COUNT
) +
7573 (((bp
->fw_stats_num
) % STATS_QUERY_CMD_COUNT
) ? 1 : 0);
7575 bp
->fw_stats_req_sz
= sizeof(struct stats_query_header
) +
7576 num_groups
* sizeof(struct stats_query_cmd_group
);
7578 /* Data for statistics requests + stats_conter
7580 * stats_counter holds per-STORM counters that are incremented
7581 * when STORM has finished with the current request.
7583 * memory for FCoE offloaded statistics are counted anyway,
7584 * even if they will not be sent.
7586 bp
->fw_stats_data_sz
= sizeof(struct per_port_stats
) +
7587 sizeof(struct per_pf_stats
) +
7588 sizeof(struct fcoe_statistics_params
) +
7589 sizeof(struct per_queue_stats
) * num_queue_stats
+
7590 sizeof(struct stats_counter
);
7592 BNX2X_PCI_ALLOC(bp
->fw_stats
, &bp
->fw_stats_mapping
,
7593 bp
->fw_stats_data_sz
+ bp
->fw_stats_req_sz
);
7596 bp
->fw_stats_req
= (struct bnx2x_fw_stats_req
*)bp
->fw_stats
;
7597 bp
->fw_stats_req_mapping
= bp
->fw_stats_mapping
;
7599 bp
->fw_stats_data
= (struct bnx2x_fw_stats_data
*)
7600 ((u8
*)bp
->fw_stats
+ bp
->fw_stats_req_sz
);
7602 bp
->fw_stats_data_mapping
= bp
->fw_stats_mapping
+
7603 bp
->fw_stats_req_sz
;
7607 BNX2X_PCI_FREE(bp
->fw_stats
, bp
->fw_stats_mapping
,
7608 bp
->fw_stats_data_sz
+ bp
->fw_stats_req_sz
);
7609 BNX2X_ERR("Can't allocate memory\n");
7613 int bnx2x_alloc_mem_cnic(struct bnx2x
*bp
)
7615 if (!CHIP_IS_E1x(bp
))
7616 /* size = the status block + ramrod buffers */
7617 BNX2X_PCI_ALLOC(bp
->cnic_sb
.e2_sb
, &bp
->cnic_sb_mapping
,
7618 sizeof(struct host_hc_status_block_e2
));
7620 BNX2X_PCI_ALLOC(bp
->cnic_sb
.e1x_sb
,
7621 &bp
->cnic_sb_mapping
,
7623 host_hc_status_block_e1x
));
7625 if (CONFIGURE_NIC_MODE(bp
))
7626 /* allocate searcher T2 table, as it wan't allocated before */
7627 BNX2X_PCI_ALLOC(bp
->t2
, &bp
->t2_mapping
, SRC_T2_SZ
);
7629 /* write address to which L5 should insert its values */
7630 bp
->cnic_eth_dev
.addr_drv_info_to_mcp
=
7631 &bp
->slowpath
->drv_info_to_mcp
;
7633 if (bnx2x_ilt_mem_op_cnic(bp
, ILT_MEMOP_ALLOC
))
7639 bnx2x_free_mem_cnic(bp
);
7640 BNX2X_ERR("Can't allocate memory\n");
7644 int bnx2x_alloc_mem(struct bnx2x
*bp
)
7646 int i
, allocated
, context_size
;
7648 if (!CONFIGURE_NIC_MODE(bp
))
7649 /* allocate searcher T2 table */
7650 BNX2X_PCI_ALLOC(bp
->t2
, &bp
->t2_mapping
, SRC_T2_SZ
);
7652 BNX2X_PCI_ALLOC(bp
->def_status_blk
, &bp
->def_status_blk_mapping
,
7653 sizeof(struct host_sp_status_block
));
7655 BNX2X_PCI_ALLOC(bp
->slowpath
, &bp
->slowpath_mapping
,
7656 sizeof(struct bnx2x_slowpath
));
7658 /* Allocated memory for FW statistics */
7659 if (bnx2x_alloc_fw_stats_mem(bp
))
7662 /* Allocate memory for CDU context:
7663 * This memory is allocated separately and not in the generic ILT
7664 * functions because CDU differs in few aspects:
7665 * 1. There are multiple entities allocating memory for context -
7666 * 'regular' driver, CNIC and SRIOV driver. Each separately controls
7667 * its own ILT lines.
7668 * 2. Since CDU page-size is not a single 4KB page (which is the case
7669 * for the other ILT clients), to be efficient we want to support
7670 * allocation of sub-page-size in the last entry.
7671 * 3. Context pointers are used by the driver to pass to FW / update
7672 * the context (for the other ILT clients the pointers are used just to
7673 * free the memory during unload).
7675 context_size
= sizeof(union cdu_context
) * BNX2X_L2_CID_COUNT(bp
);
7677 for (i
= 0, allocated
= 0; allocated
< context_size
; i
++) {
7678 bp
->context
[i
].size
= min(CDU_ILT_PAGE_SZ
,
7679 (context_size
- allocated
));
7680 BNX2X_PCI_ALLOC(bp
->context
[i
].vcxt
,
7681 &bp
->context
[i
].cxt_mapping
,
7682 bp
->context
[i
].size
);
7683 allocated
+= bp
->context
[i
].size
;
7685 BNX2X_ALLOC(bp
->ilt
->lines
, sizeof(struct ilt_line
) * ILT_MAX_LINES
);
7687 if (bnx2x_ilt_mem_op(bp
, ILT_MEMOP_ALLOC
))
7690 /* Slow path ring */
7691 BNX2X_PCI_ALLOC(bp
->spq
, &bp
->spq_mapping
, BCM_PAGE_SIZE
);
7694 BNX2X_PCI_ALLOC(bp
->eq_ring
, &bp
->eq_mapping
,
7695 BCM_PAGE_SIZE
* NUM_EQ_PAGES
);
7699 /* need to be done at the end, since it's self adjusting to amount
7700 * of memory available for RSS queues
7702 if (bnx2x_alloc_fp_mem(bp
))
7708 BNX2X_ERR("Can't allocate memory\n");
7713 * Init service functions
7716 int bnx2x_set_mac_one(struct bnx2x
*bp
, u8
*mac
,
7717 struct bnx2x_vlan_mac_obj
*obj
, bool set
,
7718 int mac_type
, unsigned long *ramrod_flags
)
7721 struct bnx2x_vlan_mac_ramrod_params ramrod_param
;
7723 memset(&ramrod_param
, 0, sizeof(ramrod_param
));
7725 /* Fill general parameters */
7726 ramrod_param
.vlan_mac_obj
= obj
;
7727 ramrod_param
.ramrod_flags
= *ramrod_flags
;
7729 /* Fill a user request section if needed */
7730 if (!test_bit(RAMROD_CONT
, ramrod_flags
)) {
7731 memcpy(ramrod_param
.user_req
.u
.mac
.mac
, mac
, ETH_ALEN
);
7733 __set_bit(mac_type
, &ramrod_param
.user_req
.vlan_mac_flags
);
7735 /* Set the command: ADD or DEL */
7737 ramrod_param
.user_req
.cmd
= BNX2X_VLAN_MAC_ADD
;
7739 ramrod_param
.user_req
.cmd
= BNX2X_VLAN_MAC_DEL
;
7742 rc
= bnx2x_config_vlan_mac(bp
, &ramrod_param
);
7744 if (rc
== -EEXIST
) {
7745 DP(BNX2X_MSG_SP
, "Failed to schedule ADD operations: %d\n", rc
);
7746 /* do not treat adding same MAC as error */
7749 BNX2X_ERR("%s MAC failed\n", (set
? "Set" : "Del"));
7754 int bnx2x_del_all_macs(struct bnx2x
*bp
,
7755 struct bnx2x_vlan_mac_obj
*mac_obj
,
7756 int mac_type
, bool wait_for_comp
)
7759 unsigned long ramrod_flags
= 0, vlan_mac_flags
= 0;
7761 /* Wait for completion of requested */
7763 __set_bit(RAMROD_COMP_WAIT
, &ramrod_flags
);
7765 /* Set the mac type of addresses we want to clear */
7766 __set_bit(mac_type
, &vlan_mac_flags
);
7768 rc
= mac_obj
->delete_all(bp
, mac_obj
, &vlan_mac_flags
, &ramrod_flags
);
7770 BNX2X_ERR("Failed to delete MACs: %d\n", rc
);
7775 int bnx2x_set_eth_mac(struct bnx2x
*bp
, bool set
)
7777 unsigned long ramrod_flags
= 0;
7779 if (is_zero_ether_addr(bp
->dev
->dev_addr
) &&
7780 (IS_MF_STORAGE_SD(bp
) || IS_MF_FCOE_AFEX(bp
))) {
7781 DP(NETIF_MSG_IFUP
| NETIF_MSG_IFDOWN
,
7782 "Ignoring Zero MAC for STORAGE SD mode\n");
7786 DP(NETIF_MSG_IFUP
, "Adding Eth MAC\n");
7788 __set_bit(RAMROD_COMP_WAIT
, &ramrod_flags
);
7789 /* Eth MAC is set on RSS leading client (fp[0]) */
7790 return bnx2x_set_mac_one(bp
, bp
->dev
->dev_addr
, &bp
->sp_objs
->mac_obj
,
7791 set
, BNX2X_ETH_MAC
, &ramrod_flags
);
7794 int bnx2x_setup_leading(struct bnx2x
*bp
)
7796 return bnx2x_setup_queue(bp
, &bp
->fp
[0], 1);
7800 * bnx2x_set_int_mode - configure interrupt mode
7802 * @bp: driver handle
7804 * In case of MSI-X it will also try to enable MSI-X.
7806 void bnx2x_set_int_mode(struct bnx2x
*bp
)
7810 bnx2x_enable_msi(bp
);
7811 /* falling through... */
7813 bp
->num_ethernet_queues
= 1;
7814 bp
->num_queues
= bp
->num_ethernet_queues
+ bp
->num_cnic_queues
;
7815 BNX2X_DEV_INFO("set number of queues to 1\n");
7818 /* if we can't use MSI-X we only need one fp,
7819 * so try to enable MSI-X with the requested number of fp's
7820 * and fallback to MSI or legacy INTx with one fp
7822 if (bnx2x_enable_msix(bp
) ||
7823 bp
->flags
& USING_SINGLE_MSIX_FLAG
) {
7824 /* failed to enable multiple MSI-X */
7825 BNX2X_DEV_INFO("Failed to enable multiple MSI-X (%d), set number of queues to %d\n",
7827 1 + bp
->num_cnic_queues
);
7829 bp
->num_queues
= 1 + bp
->num_cnic_queues
;
7831 /* Try to enable MSI */
7832 if (!(bp
->flags
& USING_SINGLE_MSIX_FLAG
) &&
7833 !(bp
->flags
& DISABLE_MSI_FLAG
))
7834 bnx2x_enable_msi(bp
);
7840 /* must be called prioir to any HW initializations */
7841 static inline u16
bnx2x_cid_ilt_lines(struct bnx2x
*bp
)
7843 return L2_ILT_LINES(bp
);
7846 void bnx2x_ilt_set_info(struct bnx2x
*bp
)
7848 struct ilt_client_info
*ilt_client
;
7849 struct bnx2x_ilt
*ilt
= BP_ILT(bp
);
7852 ilt
->start_line
= FUNC_ILT_BASE(BP_FUNC(bp
));
7853 DP(BNX2X_MSG_SP
, "ilt starts at line %d\n", ilt
->start_line
);
7856 ilt_client
= &ilt
->clients
[ILT_CLIENT_CDU
];
7857 ilt_client
->client_num
= ILT_CLIENT_CDU
;
7858 ilt_client
->page_size
= CDU_ILT_PAGE_SZ
;
7859 ilt_client
->flags
= ILT_CLIENT_SKIP_MEM
;
7860 ilt_client
->start
= line
;
7861 line
+= bnx2x_cid_ilt_lines(bp
);
7863 if (CNIC_SUPPORT(bp
))
7864 line
+= CNIC_ILT_LINES
;
7865 ilt_client
->end
= line
- 1;
7867 DP(NETIF_MSG_IFUP
, "ilt client[CDU]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
7870 ilt_client
->page_size
,
7872 ilog2(ilt_client
->page_size
>> 12));
7875 if (QM_INIT(bp
->qm_cid_count
)) {
7876 ilt_client
= &ilt
->clients
[ILT_CLIENT_QM
];
7877 ilt_client
->client_num
= ILT_CLIENT_QM
;
7878 ilt_client
->page_size
= QM_ILT_PAGE_SZ
;
7879 ilt_client
->flags
= 0;
7880 ilt_client
->start
= line
;
7882 /* 4 bytes for each cid */
7883 line
+= DIV_ROUND_UP(bp
->qm_cid_count
* QM_QUEUES_PER_FUNC
* 4,
7886 ilt_client
->end
= line
- 1;
7889 "ilt client[QM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
7892 ilt_client
->page_size
,
7894 ilog2(ilt_client
->page_size
>> 12));
7898 if (CNIC_SUPPORT(bp
)) {
7900 ilt_client
= &ilt
->clients
[ILT_CLIENT_SRC
];
7901 ilt_client
->client_num
= ILT_CLIENT_SRC
;
7902 ilt_client
->page_size
= SRC_ILT_PAGE_SZ
;
7903 ilt_client
->flags
= 0;
7904 ilt_client
->start
= line
;
7905 line
+= SRC_ILT_LINES
;
7906 ilt_client
->end
= line
- 1;
7909 "ilt client[SRC]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
7912 ilt_client
->page_size
,
7914 ilog2(ilt_client
->page_size
>> 12));
7917 ilt_client
= &ilt
->clients
[ILT_CLIENT_TM
];
7918 ilt_client
->client_num
= ILT_CLIENT_TM
;
7919 ilt_client
->page_size
= TM_ILT_PAGE_SZ
;
7920 ilt_client
->flags
= 0;
7921 ilt_client
->start
= line
;
7922 line
+= TM_ILT_LINES
;
7923 ilt_client
->end
= line
- 1;
7926 "ilt client[TM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
7929 ilt_client
->page_size
,
7931 ilog2(ilt_client
->page_size
>> 12));
7934 BUG_ON(line
> ILT_MAX_LINES
);
7938 * bnx2x_pf_q_prep_init - prepare INIT transition parameters
7940 * @bp: driver handle
7941 * @fp: pointer to fastpath
7942 * @init_params: pointer to parameters structure
7944 * parameters configured:
7945 * - HC configuration
7946 * - Queue's CDU context
7948 static void bnx2x_pf_q_prep_init(struct bnx2x
*bp
,
7949 struct bnx2x_fastpath
*fp
, struct bnx2x_queue_init_params
*init_params
)
7953 int cxt_index
, cxt_offset
;
7955 /* FCoE Queue uses Default SB, thus has no HC capabilities */
7956 if (!IS_FCOE_FP(fp
)) {
7957 __set_bit(BNX2X_Q_FLG_HC
, &init_params
->rx
.flags
);
7958 __set_bit(BNX2X_Q_FLG_HC
, &init_params
->tx
.flags
);
7960 /* If HC is supporterd, enable host coalescing in the transition
7963 __set_bit(BNX2X_Q_FLG_HC_EN
, &init_params
->rx
.flags
);
7964 __set_bit(BNX2X_Q_FLG_HC_EN
, &init_params
->tx
.flags
);
7967 init_params
->rx
.hc_rate
= bp
->rx_ticks
?
7968 (1000000 / bp
->rx_ticks
) : 0;
7969 init_params
->tx
.hc_rate
= bp
->tx_ticks
?
7970 (1000000 / bp
->tx_ticks
) : 0;
7973 init_params
->rx
.fw_sb_id
= init_params
->tx
.fw_sb_id
=
7977 * CQ index among the SB indices: FCoE clients uses the default
7978 * SB, therefore it's different.
7980 init_params
->rx
.sb_cq_index
= HC_INDEX_ETH_RX_CQ_CONS
;
7981 init_params
->tx
.sb_cq_index
= HC_INDEX_ETH_FIRST_TX_CQ_CONS
;
7984 /* set maximum number of COSs supported by this queue */
7985 init_params
->max_cos
= fp
->max_cos
;
7987 DP(NETIF_MSG_IFUP
, "fp: %d setting queue params max cos to: %d\n",
7988 fp
->index
, init_params
->max_cos
);
7990 /* set the context pointers queue object */
7991 for (cos
= FIRST_TX_COS_INDEX
; cos
< init_params
->max_cos
; cos
++) {
7992 cxt_index
= fp
->txdata_ptr
[cos
]->cid
/ ILT_PAGE_CIDS
;
7993 cxt_offset
= fp
->txdata_ptr
[cos
]->cid
- (cxt_index
*
7995 init_params
->cxts
[cos
] =
7996 &bp
->context
[cxt_index
].vcxt
[cxt_offset
].eth
;
8000 static int bnx2x_setup_tx_only(struct bnx2x
*bp
, struct bnx2x_fastpath
*fp
,
8001 struct bnx2x_queue_state_params
*q_params
,
8002 struct bnx2x_queue_setup_tx_only_params
*tx_only_params
,
8003 int tx_index
, bool leading
)
8005 memset(tx_only_params
, 0, sizeof(*tx_only_params
));
8007 /* Set the command */
8008 q_params
->cmd
= BNX2X_Q_CMD_SETUP_TX_ONLY
;
8010 /* Set tx-only QUEUE flags: don't zero statistics */
8011 tx_only_params
->flags
= bnx2x_get_common_flags(bp
, fp
, false);
8013 /* choose the index of the cid to send the slow path on */
8014 tx_only_params
->cid_index
= tx_index
;
8016 /* Set general TX_ONLY_SETUP parameters */
8017 bnx2x_pf_q_prep_general(bp
, fp
, &tx_only_params
->gen_params
, tx_index
);
8019 /* Set Tx TX_ONLY_SETUP parameters */
8020 bnx2x_pf_tx_q_prep(bp
, fp
, &tx_only_params
->txq_params
, tx_index
);
8023 "preparing to send tx-only ramrod for connection: cos %d, primary cid %d, cid %d, client id %d, sp-client id %d, flags %lx\n",
8024 tx_index
, q_params
->q_obj
->cids
[FIRST_TX_COS_INDEX
],
8025 q_params
->q_obj
->cids
[tx_index
], q_params
->q_obj
->cl_id
,
8026 tx_only_params
->gen_params
.spcl_id
, tx_only_params
->flags
);
8028 /* send the ramrod */
8029 return bnx2x_queue_state_change(bp
, q_params
);
8034 * bnx2x_setup_queue - setup queue
8036 * @bp: driver handle
8037 * @fp: pointer to fastpath
8038 * @leading: is leading
8040 * This function performs 2 steps in a Queue state machine
8041 * actually: 1) RESET->INIT 2) INIT->SETUP
8044 int bnx2x_setup_queue(struct bnx2x
*bp
, struct bnx2x_fastpath
*fp
,
8047 struct bnx2x_queue_state_params q_params
= {NULL
};
8048 struct bnx2x_queue_setup_params
*setup_params
=
8049 &q_params
.params
.setup
;
8050 struct bnx2x_queue_setup_tx_only_params
*tx_only_params
=
8051 &q_params
.params
.tx_only
;
8055 DP(NETIF_MSG_IFUP
, "setting up queue %d\n", fp
->index
);
8057 /* reset IGU state skip FCoE L2 queue */
8058 if (!IS_FCOE_FP(fp
))
8059 bnx2x_ack_sb(bp
, fp
->igu_sb_id
, USTORM_ID
, 0,
8062 q_params
.q_obj
= &bnx2x_sp_obj(bp
, fp
).q_obj
;
8063 /* We want to wait for completion in this context */
8064 __set_bit(RAMROD_COMP_WAIT
, &q_params
.ramrod_flags
);
8066 /* Prepare the INIT parameters */
8067 bnx2x_pf_q_prep_init(bp
, fp
, &q_params
.params
.init
);
8069 /* Set the command */
8070 q_params
.cmd
= BNX2X_Q_CMD_INIT
;
8072 /* Change the state to INIT */
8073 rc
= bnx2x_queue_state_change(bp
, &q_params
);
8075 BNX2X_ERR("Queue(%d) INIT failed\n", fp
->index
);
8079 DP(NETIF_MSG_IFUP
, "init complete\n");
8082 /* Now move the Queue to the SETUP state... */
8083 memset(setup_params
, 0, sizeof(*setup_params
));
8085 /* Set QUEUE flags */
8086 setup_params
->flags
= bnx2x_get_q_flags(bp
, fp
, leading
);
8088 /* Set general SETUP parameters */
8089 bnx2x_pf_q_prep_general(bp
, fp
, &setup_params
->gen_params
,
8090 FIRST_TX_COS_INDEX
);
8092 bnx2x_pf_rx_q_prep(bp
, fp
, &setup_params
->pause_params
,
8093 &setup_params
->rxq_params
);
8095 bnx2x_pf_tx_q_prep(bp
, fp
, &setup_params
->txq_params
,
8096 FIRST_TX_COS_INDEX
);
8098 /* Set the command */
8099 q_params
.cmd
= BNX2X_Q_CMD_SETUP
;
8102 bp
->fcoe_init
= true;
8104 /* Change the state to SETUP */
8105 rc
= bnx2x_queue_state_change(bp
, &q_params
);
8107 BNX2X_ERR("Queue(%d) SETUP failed\n", fp
->index
);
8111 /* loop through the relevant tx-only indices */
8112 for (tx_index
= FIRST_TX_ONLY_COS_INDEX
;
8113 tx_index
< fp
->max_cos
;
8116 /* prepare and send tx-only ramrod*/
8117 rc
= bnx2x_setup_tx_only(bp
, fp
, &q_params
,
8118 tx_only_params
, tx_index
, leading
);
8120 BNX2X_ERR("Queue(%d.%d) TX_ONLY_SETUP failed\n",
8121 fp
->index
, tx_index
);
8129 static int bnx2x_stop_queue(struct bnx2x
*bp
, int index
)
8131 struct bnx2x_fastpath
*fp
= &bp
->fp
[index
];
8132 struct bnx2x_fp_txdata
*txdata
;
8133 struct bnx2x_queue_state_params q_params
= {NULL
};
8136 DP(NETIF_MSG_IFDOWN
, "stopping queue %d cid %d\n", index
, fp
->cid
);
8138 q_params
.q_obj
= &bnx2x_sp_obj(bp
, fp
).q_obj
;
8139 /* We want to wait for completion in this context */
8140 __set_bit(RAMROD_COMP_WAIT
, &q_params
.ramrod_flags
);
8143 /* close tx-only connections */
8144 for (tx_index
= FIRST_TX_ONLY_COS_INDEX
;
8145 tx_index
< fp
->max_cos
;
8148 /* ascertain this is a normal queue*/
8149 txdata
= fp
->txdata_ptr
[tx_index
];
8151 DP(NETIF_MSG_IFDOWN
, "stopping tx-only queue %d\n",
8154 /* send halt terminate on tx-only connection */
8155 q_params
.cmd
= BNX2X_Q_CMD_TERMINATE
;
8156 memset(&q_params
.params
.terminate
, 0,
8157 sizeof(q_params
.params
.terminate
));
8158 q_params
.params
.terminate
.cid_index
= tx_index
;
8160 rc
= bnx2x_queue_state_change(bp
, &q_params
);
8164 /* send halt terminate on tx-only connection */
8165 q_params
.cmd
= BNX2X_Q_CMD_CFC_DEL
;
8166 memset(&q_params
.params
.cfc_del
, 0,
8167 sizeof(q_params
.params
.cfc_del
));
8168 q_params
.params
.cfc_del
.cid_index
= tx_index
;
8169 rc
= bnx2x_queue_state_change(bp
, &q_params
);
8173 /* Stop the primary connection: */
8174 /* ...halt the connection */
8175 q_params
.cmd
= BNX2X_Q_CMD_HALT
;
8176 rc
= bnx2x_queue_state_change(bp
, &q_params
);
8180 /* ...terminate the connection */
8181 q_params
.cmd
= BNX2X_Q_CMD_TERMINATE
;
8182 memset(&q_params
.params
.terminate
, 0,
8183 sizeof(q_params
.params
.terminate
));
8184 q_params
.params
.terminate
.cid_index
= FIRST_TX_COS_INDEX
;
8185 rc
= bnx2x_queue_state_change(bp
, &q_params
);
8188 /* ...delete cfc entry */
8189 q_params
.cmd
= BNX2X_Q_CMD_CFC_DEL
;
8190 memset(&q_params
.params
.cfc_del
, 0,
8191 sizeof(q_params
.params
.cfc_del
));
8192 q_params
.params
.cfc_del
.cid_index
= FIRST_TX_COS_INDEX
;
8193 return bnx2x_queue_state_change(bp
, &q_params
);
8197 static void bnx2x_reset_func(struct bnx2x
*bp
)
8199 int port
= BP_PORT(bp
);
8200 int func
= BP_FUNC(bp
);
8203 /* Disable the function in the FW */
8204 REG_WR8(bp
, BAR_XSTRORM_INTMEM
+ XSTORM_FUNC_EN_OFFSET(func
), 0);
8205 REG_WR8(bp
, BAR_CSTRORM_INTMEM
+ CSTORM_FUNC_EN_OFFSET(func
), 0);
8206 REG_WR8(bp
, BAR_TSTRORM_INTMEM
+ TSTORM_FUNC_EN_OFFSET(func
), 0);
8207 REG_WR8(bp
, BAR_USTRORM_INTMEM
+ USTORM_FUNC_EN_OFFSET(func
), 0);
8210 for_each_eth_queue(bp
, i
) {
8211 struct bnx2x_fastpath
*fp
= &bp
->fp
[i
];
8212 REG_WR8(bp
, BAR_CSTRORM_INTMEM
+
8213 CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(fp
->fw_sb_id
),
8217 if (CNIC_LOADED(bp
))
8219 REG_WR8(bp
, BAR_CSTRORM_INTMEM
+
8220 CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET
8221 (bnx2x_cnic_fw_sb_id(bp
)), SB_DISABLED
);
8224 REG_WR8(bp
, BAR_CSTRORM_INTMEM
+
8225 CSTORM_SP_STATUS_BLOCK_DATA_STATE_OFFSET(func
),
8228 for (i
= 0; i
< XSTORM_SPQ_DATA_SIZE
/ 4; i
++)
8229 REG_WR(bp
, BAR_XSTRORM_INTMEM
+ XSTORM_SPQ_DATA_OFFSET(func
),
8233 if (bp
->common
.int_block
== INT_BLOCK_HC
) {
8234 REG_WR(bp
, HC_REG_LEADING_EDGE_0
+ port
*8, 0);
8235 REG_WR(bp
, HC_REG_TRAILING_EDGE_0
+ port
*8, 0);
8237 REG_WR(bp
, IGU_REG_LEADING_EDGE_LATCH
, 0);
8238 REG_WR(bp
, IGU_REG_TRAILING_EDGE_LATCH
, 0);
8241 if (CNIC_LOADED(bp
)) {
8242 /* Disable Timer scan */
8243 REG_WR(bp
, TM_REG_EN_LINEAR0_TIMER
+ port
*4, 0);
8245 * Wait for at least 10ms and up to 2 second for the timers
8248 for (i
= 0; i
< 200; i
++) {
8250 if (!REG_RD(bp
, TM_REG_LIN0_SCAN_ON
+ port
*4))
8255 bnx2x_clear_func_ilt(bp
, func
);
8257 /* Timers workaround bug for E2: if this is vnic-3,
8258 * we need to set the entire ilt range for this timers.
8260 if (!CHIP_IS_E1x(bp
) && BP_VN(bp
) == 3) {
8261 struct ilt_client_info ilt_cli
;
8262 /* use dummy TM client */
8263 memset(&ilt_cli
, 0, sizeof(struct ilt_client_info
));
8265 ilt_cli
.end
= ILT_NUM_PAGE_ENTRIES
- 1;
8266 ilt_cli
.client_num
= ILT_CLIENT_TM
;
8268 bnx2x_ilt_boundry_init_op(bp
, &ilt_cli
, 0, INITOP_CLEAR
);
8271 /* this assumes that reset_port() called before reset_func()*/
8272 if (!CHIP_IS_E1x(bp
))
8273 bnx2x_pf_disable(bp
);
8278 static void bnx2x_reset_port(struct bnx2x
*bp
)
8280 int port
= BP_PORT(bp
);
8283 /* Reset physical Link */
8284 bnx2x__link_reset(bp
);
8286 REG_WR(bp
, NIG_REG_MASK_INTERRUPT_PORT0
+ port
*4, 0);
8288 /* Do not rcv packets to BRB */
8289 REG_WR(bp
, NIG_REG_LLH0_BRB1_DRV_MASK
+ port
*4, 0x0);
8290 /* Do not direct rcv packets that are not for MCP to the BRB */
8291 REG_WR(bp
, (port
? NIG_REG_LLH1_BRB1_NOT_MCP
:
8292 NIG_REG_LLH0_BRB1_NOT_MCP
), 0x0);
8295 REG_WR(bp
, MISC_REG_AEU_MASK_ATTN_FUNC_0
+ port
*4, 0);
8298 /* Check for BRB port occupancy */
8299 val
= REG_RD(bp
, BRB1_REG_PORT_NUM_OCC_BLOCKS_0
+ port
*4);
8301 DP(NETIF_MSG_IFDOWN
,
8302 "BRB1 is not empty %d blocks are occupied\n", val
);
8304 /* TODO: Close Doorbell port? */
8307 static int bnx2x_reset_hw(struct bnx2x
*bp
, u32 load_code
)
8309 struct bnx2x_func_state_params func_params
= {NULL
};
8311 /* Prepare parameters for function state transitions */
8312 __set_bit(RAMROD_COMP_WAIT
, &func_params
.ramrod_flags
);
8314 func_params
.f_obj
= &bp
->func_obj
;
8315 func_params
.cmd
= BNX2X_F_CMD_HW_RESET
;
8317 func_params
.params
.hw_init
.load_phase
= load_code
;
8319 return bnx2x_func_state_change(bp
, &func_params
);
8322 static int bnx2x_func_stop(struct bnx2x
*bp
)
8324 struct bnx2x_func_state_params func_params
= {NULL
};
8327 /* Prepare parameters for function state transitions */
8328 __set_bit(RAMROD_COMP_WAIT
, &func_params
.ramrod_flags
);
8329 func_params
.f_obj
= &bp
->func_obj
;
8330 func_params
.cmd
= BNX2X_F_CMD_STOP
;
8333 * Try to stop the function the 'good way'. If fails (in case
8334 * of a parity error during bnx2x_chip_cleanup()) and we are
8335 * not in a debug mode, perform a state transaction in order to
8336 * enable further HW_RESET transaction.
8338 rc
= bnx2x_func_state_change(bp
, &func_params
);
8340 #ifdef BNX2X_STOP_ON_ERROR
8343 BNX2X_ERR("FUNC_STOP ramrod failed. Running a dry transaction\n");
8344 __set_bit(RAMROD_DRV_CLR_ONLY
, &func_params
.ramrod_flags
);
8345 return bnx2x_func_state_change(bp
, &func_params
);
8353 * bnx2x_send_unload_req - request unload mode from the MCP.
8355 * @bp: driver handle
8356 * @unload_mode: requested function's unload mode
8358 * Return unload mode returned by the MCP: COMMON, PORT or FUNC.
8360 u32
bnx2x_send_unload_req(struct bnx2x
*bp
, int unload_mode
)
8363 int port
= BP_PORT(bp
);
8365 /* Select the UNLOAD request mode */
8366 if (unload_mode
== UNLOAD_NORMAL
)
8367 reset_code
= DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS
;
8369 else if (bp
->flags
& NO_WOL_FLAG
)
8370 reset_code
= DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP
;
8373 u32 emac_base
= port
? GRCBASE_EMAC1
: GRCBASE_EMAC0
;
8374 u8
*mac_addr
= bp
->dev
->dev_addr
;
8378 /* The mac address is written to entries 1-4 to
8379 * preserve entry 0 which is used by the PMF
8381 u8 entry
= (BP_VN(bp
) + 1)*8;
8383 val
= (mac_addr
[0] << 8) | mac_addr
[1];
8384 EMAC_WR(bp
, EMAC_REG_EMAC_MAC_MATCH
+ entry
, val
);
8386 val
= (mac_addr
[2] << 24) | (mac_addr
[3] << 16) |
8387 (mac_addr
[4] << 8) | mac_addr
[5];
8388 EMAC_WR(bp
, EMAC_REG_EMAC_MAC_MATCH
+ entry
+ 4, val
);
8390 /* Enable the PME and clear the status */
8391 pci_read_config_word(bp
->pdev
, bp
->pm_cap
+ PCI_PM_CTRL
, &pmc
);
8392 pmc
|= PCI_PM_CTRL_PME_ENABLE
| PCI_PM_CTRL_PME_STATUS
;
8393 pci_write_config_word(bp
->pdev
, bp
->pm_cap
+ PCI_PM_CTRL
, pmc
);
8395 reset_code
= DRV_MSG_CODE_UNLOAD_REQ_WOL_EN
;
8398 reset_code
= DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS
;
8400 /* Send the request to the MCP */
8402 reset_code
= bnx2x_fw_command(bp
, reset_code
, 0);
8404 int path
= BP_PATH(bp
);
8406 DP(NETIF_MSG_IFDOWN
, "NO MCP - load counts[%d] %d, %d, %d\n",
8407 path
, load_count
[path
][0], load_count
[path
][1],
8408 load_count
[path
][2]);
8409 load_count
[path
][0]--;
8410 load_count
[path
][1 + port
]--;
8411 DP(NETIF_MSG_IFDOWN
, "NO MCP - new load counts[%d] %d, %d, %d\n",
8412 path
, load_count
[path
][0], load_count
[path
][1],
8413 load_count
[path
][2]);
8414 if (load_count
[path
][0] == 0)
8415 reset_code
= FW_MSG_CODE_DRV_UNLOAD_COMMON
;
8416 else if (load_count
[path
][1 + port
] == 0)
8417 reset_code
= FW_MSG_CODE_DRV_UNLOAD_PORT
;
8419 reset_code
= FW_MSG_CODE_DRV_UNLOAD_FUNCTION
;
8426 * bnx2x_send_unload_done - send UNLOAD_DONE command to the MCP.
8428 * @bp: driver handle
8429 * @keep_link: true iff link should be kept up
8431 void bnx2x_send_unload_done(struct bnx2x
*bp
, bool keep_link
)
8433 u32 reset_param
= keep_link
? DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET
: 0;
8435 /* Report UNLOAD_DONE to MCP */
8437 bnx2x_fw_command(bp
, DRV_MSG_CODE_UNLOAD_DONE
, reset_param
);
8440 static int bnx2x_func_wait_started(struct bnx2x
*bp
)
8443 int msix
= (bp
->flags
& USING_MSIX_FLAG
) ? 1 : 0;
8449 * (assumption: No Attention from MCP at this stage)
8450 * PMF probably in the middle of TXdisable/enable transaction
8451 * 1. Sync IRS for default SB
8452 * 2. Sync SP queue - this guarantes us that attention handling started
8453 * 3. Wait, that TXdisable/enable transaction completes
8455 * 1+2 guranty that if DCBx attention was scheduled it already changed
8456 * pending bit of transaction from STARTED-->TX_STOPPED, if we alredy
8457 * received complettion for the transaction the state is TX_STOPPED.
8458 * State will return to STARTED after completion of TX_STOPPED-->STARTED
8462 /* make sure default SB ISR is done */
8464 synchronize_irq(bp
->msix_table
[0].vector
);
8466 synchronize_irq(bp
->pdev
->irq
);
8468 flush_workqueue(bnx2x_wq
);
8470 while (bnx2x_func_get_state(bp
, &bp
->func_obj
) !=
8471 BNX2X_F_STATE_STARTED
&& tout
--)
8474 if (bnx2x_func_get_state(bp
, &bp
->func_obj
) !=
8475 BNX2X_F_STATE_STARTED
) {
8476 #ifdef BNX2X_STOP_ON_ERROR
8477 BNX2X_ERR("Wrong function state\n");
8481 * Failed to complete the transaction in a "good way"
8482 * Force both transactions with CLR bit
8484 struct bnx2x_func_state_params func_params
= {NULL
};
8486 DP(NETIF_MSG_IFDOWN
,
8487 "Hmmm... unexpected function state! Forcing STARTED-->TX_ST0PPED-->STARTED\n");
8489 func_params
.f_obj
= &bp
->func_obj
;
8490 __set_bit(RAMROD_DRV_CLR_ONLY
,
8491 &func_params
.ramrod_flags
);
8493 /* STARTED-->TX_ST0PPED */
8494 func_params
.cmd
= BNX2X_F_CMD_TX_STOP
;
8495 bnx2x_func_state_change(bp
, &func_params
);
8497 /* TX_ST0PPED-->STARTED */
8498 func_params
.cmd
= BNX2X_F_CMD_TX_START
;
8499 return bnx2x_func_state_change(bp
, &func_params
);
8506 void bnx2x_chip_cleanup(struct bnx2x
*bp
, int unload_mode
, bool keep_link
)
8508 int port
= BP_PORT(bp
);
8511 struct bnx2x_mcast_ramrod_params rparam
= {NULL
};
8514 /* Wait until tx fastpath tasks complete */
8515 for_each_tx_queue(bp
, i
) {
8516 struct bnx2x_fastpath
*fp
= &bp
->fp
[i
];
8518 for_each_cos_in_tx_queue(fp
, cos
)
8519 rc
= bnx2x_clean_tx_queue(bp
, fp
->txdata_ptr
[cos
]);
8520 #ifdef BNX2X_STOP_ON_ERROR
8526 /* Give HW time to discard old tx messages */
8527 usleep_range(1000, 1000);
8529 /* Clean all ETH MACs */
8530 rc
= bnx2x_del_all_macs(bp
, &bp
->sp_objs
[0].mac_obj
, BNX2X_ETH_MAC
,
8533 BNX2X_ERR("Failed to delete all ETH macs: %d\n", rc
);
8535 /* Clean up UC list */
8536 rc
= bnx2x_del_all_macs(bp
, &bp
->sp_objs
[0].mac_obj
, BNX2X_UC_LIST_MAC
,
8539 BNX2X_ERR("Failed to schedule DEL commands for UC MACs list: %d\n",
8543 if (!CHIP_IS_E1(bp
))
8544 REG_WR(bp
, NIG_REG_LLH0_FUNC_EN
+ port
*8, 0);
8546 /* Set "drop all" (stop Rx).
8547 * We need to take a netif_addr_lock() here in order to prevent
8548 * a race between the completion code and this code.
8550 netif_addr_lock_bh(bp
->dev
);
8551 /* Schedule the rx_mode command */
8552 if (test_bit(BNX2X_FILTER_RX_MODE_PENDING
, &bp
->sp_state
))
8553 set_bit(BNX2X_FILTER_RX_MODE_SCHED
, &bp
->sp_state
);
8555 bnx2x_set_storm_rx_mode(bp
);
8557 /* Cleanup multicast configuration */
8558 rparam
.mcast_obj
= &bp
->mcast_obj
;
8559 rc
= bnx2x_config_mcast(bp
, &rparam
, BNX2X_MCAST_CMD_DEL
);
8561 BNX2X_ERR("Failed to send DEL multicast command: %d\n", rc
);
8563 netif_addr_unlock_bh(bp
->dev
);
8568 * Send the UNLOAD_REQUEST to the MCP. This will return if
8569 * this function should perform FUNC, PORT or COMMON HW
8572 reset_code
= bnx2x_send_unload_req(bp
, unload_mode
);
8575 * (assumption: No Attention from MCP at this stage)
8576 * PMF probably in the middle of TXdisable/enable transaction
8578 rc
= bnx2x_func_wait_started(bp
);
8580 BNX2X_ERR("bnx2x_func_wait_started failed\n");
8581 #ifdef BNX2X_STOP_ON_ERROR
8586 /* Close multi and leading connections
8587 * Completions for ramrods are collected in a synchronous way
8589 for_each_eth_queue(bp
, i
)
8590 if (bnx2x_stop_queue(bp
, i
))
8591 #ifdef BNX2X_STOP_ON_ERROR
8597 if (CNIC_LOADED(bp
)) {
8598 for_each_cnic_queue(bp
, i
)
8599 if (bnx2x_stop_queue(bp
, i
))
8600 #ifdef BNX2X_STOP_ON_ERROR
8607 /* If SP settings didn't get completed so far - something
8608 * very wrong has happen.
8610 if (!bnx2x_wait_sp_comp(bp
, ~0x0UL
))
8611 BNX2X_ERR("Hmmm... Common slow path ramrods got stuck!\n");
8613 #ifndef BNX2X_STOP_ON_ERROR
8616 rc
= bnx2x_func_stop(bp
);
8618 BNX2X_ERR("Function stop failed!\n");
8619 #ifdef BNX2X_STOP_ON_ERROR
8624 /* Disable HW interrupts, NAPI */
8625 bnx2x_netif_stop(bp
, 1);
8626 /* Delete all NAPI objects */
8627 bnx2x_del_all_napi(bp
);
8628 if (CNIC_LOADED(bp
))
8629 bnx2x_del_all_napi_cnic(bp
);
8634 /* Reset the chip */
8635 rc
= bnx2x_reset_hw(bp
, reset_code
);
8637 BNX2X_ERR("HW_RESET failed\n");
8640 /* Report UNLOAD_DONE to MCP */
8641 bnx2x_send_unload_done(bp
, keep_link
);
8644 void bnx2x_disable_close_the_gate(struct bnx2x
*bp
)
8648 DP(NETIF_MSG_IFDOWN
, "Disabling \"close the gates\"\n");
8650 if (CHIP_IS_E1(bp
)) {
8651 int port
= BP_PORT(bp
);
8652 u32 addr
= port
? MISC_REG_AEU_MASK_ATTN_FUNC_1
:
8653 MISC_REG_AEU_MASK_ATTN_FUNC_0
;
8655 val
= REG_RD(bp
, addr
);
8657 REG_WR(bp
, addr
, val
);
8659 val
= REG_RD(bp
, MISC_REG_AEU_GENERAL_MASK
);
8660 val
&= ~(MISC_AEU_GENERAL_MASK_REG_AEU_PXP_CLOSE_MASK
|
8661 MISC_AEU_GENERAL_MASK_REG_AEU_NIG_CLOSE_MASK
);
8662 REG_WR(bp
, MISC_REG_AEU_GENERAL_MASK
, val
);
8666 /* Close gates #2, #3 and #4: */
8667 static void bnx2x_set_234_gates(struct bnx2x
*bp
, bool close
)
8671 /* Gates #2 and #4a are closed/opened for "not E1" only */
8672 if (!CHIP_IS_E1(bp
)) {
8674 REG_WR(bp
, PXP_REG_HST_DISCARD_DOORBELLS
, !!close
);
8676 REG_WR(bp
, PXP_REG_HST_DISCARD_INTERNAL_WRITES
, !!close
);
8680 if (CHIP_IS_E1x(bp
)) {
8681 /* Prevent interrupts from HC on both ports */
8682 val
= REG_RD(bp
, HC_REG_CONFIG_1
);
8683 REG_WR(bp
, HC_REG_CONFIG_1
,
8684 (!close
) ? (val
| HC_CONFIG_1_REG_BLOCK_DISABLE_1
) :
8685 (val
& ~(u32
)HC_CONFIG_1_REG_BLOCK_DISABLE_1
));
8687 val
= REG_RD(bp
, HC_REG_CONFIG_0
);
8688 REG_WR(bp
, HC_REG_CONFIG_0
,
8689 (!close
) ? (val
| HC_CONFIG_0_REG_BLOCK_DISABLE_0
) :
8690 (val
& ~(u32
)HC_CONFIG_0_REG_BLOCK_DISABLE_0
));
8692 /* Prevent incomming interrupts in IGU */
8693 val
= REG_RD(bp
, IGU_REG_BLOCK_CONFIGURATION
);
8695 REG_WR(bp
, IGU_REG_BLOCK_CONFIGURATION
,
8697 (val
| IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE
) :
8698 (val
& ~(u32
)IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE
));
8701 DP(NETIF_MSG_HW
| NETIF_MSG_IFUP
, "%s gates #2, #3 and #4\n",
8702 close
? "closing" : "opening");
8706 #define SHARED_MF_CLP_MAGIC 0x80000000 /* `magic' bit */
8708 static void bnx2x_clp_reset_prep(struct bnx2x
*bp
, u32
*magic_val
)
8710 /* Do some magic... */
8711 u32 val
= MF_CFG_RD(bp
, shared_mf_config
.clp_mb
);
8712 *magic_val
= val
& SHARED_MF_CLP_MAGIC
;
8713 MF_CFG_WR(bp
, shared_mf_config
.clp_mb
, val
| SHARED_MF_CLP_MAGIC
);
8717 * bnx2x_clp_reset_done - restore the value of the `magic' bit.
8719 * @bp: driver handle
8720 * @magic_val: old value of the `magic' bit.
8722 static void bnx2x_clp_reset_done(struct bnx2x
*bp
, u32 magic_val
)
8724 /* Restore the `magic' bit value... */
8725 u32 val
= MF_CFG_RD(bp
, shared_mf_config
.clp_mb
);
8726 MF_CFG_WR(bp
, shared_mf_config
.clp_mb
,
8727 (val
& (~SHARED_MF_CLP_MAGIC
)) | magic_val
);
8731 * bnx2x_reset_mcp_prep - prepare for MCP reset.
8733 * @bp: driver handle
8734 * @magic_val: old value of 'magic' bit.
8736 * Takes care of CLP configurations.
8738 static void bnx2x_reset_mcp_prep(struct bnx2x
*bp
, u32
*magic_val
)
8741 u32 validity_offset
;
8743 DP(NETIF_MSG_HW
| NETIF_MSG_IFUP
, "Starting\n");
8745 /* Set `magic' bit in order to save MF config */
8746 if (!CHIP_IS_E1(bp
))
8747 bnx2x_clp_reset_prep(bp
, magic_val
);
8749 /* Get shmem offset */
8750 shmem
= REG_RD(bp
, MISC_REG_SHARED_MEM_ADDR
);
8752 offsetof(struct shmem_region
, validity_map
[BP_PORT(bp
)]);
8754 /* Clear validity map flags */
8756 REG_WR(bp
, shmem
+ validity_offset
, 0);
8759 #define MCP_TIMEOUT 5000 /* 5 seconds (in ms) */
8760 #define MCP_ONE_TIMEOUT 100 /* 100 ms */
8763 * bnx2x_mcp_wait_one - wait for MCP_ONE_TIMEOUT
8765 * @bp: driver handle
8767 static void bnx2x_mcp_wait_one(struct bnx2x
*bp
)
8769 /* special handling for emulation and FPGA,
8770 wait 10 times longer */
8771 if (CHIP_REV_IS_SLOW(bp
))
8772 msleep(MCP_ONE_TIMEOUT
*10);
8774 msleep(MCP_ONE_TIMEOUT
);
8778 * initializes bp->common.shmem_base and waits for validity signature to appear
8780 static int bnx2x_init_shmem(struct bnx2x
*bp
)
8786 bp
->common
.shmem_base
= REG_RD(bp
, MISC_REG_SHARED_MEM_ADDR
);
8787 if (bp
->common
.shmem_base
) {
8788 val
= SHMEM_RD(bp
, validity_map
[BP_PORT(bp
)]);
8789 if (val
& SHR_MEM_VALIDITY_MB
)
8793 bnx2x_mcp_wait_one(bp
);
8795 } while (cnt
++ < (MCP_TIMEOUT
/ MCP_ONE_TIMEOUT
));
8797 BNX2X_ERR("BAD MCP validity signature\n");
8802 static int bnx2x_reset_mcp_comp(struct bnx2x
*bp
, u32 magic_val
)
8804 int rc
= bnx2x_init_shmem(bp
);
8806 /* Restore the `magic' bit value */
8807 if (!CHIP_IS_E1(bp
))
8808 bnx2x_clp_reset_done(bp
, magic_val
);
8813 static void bnx2x_pxp_prep(struct bnx2x
*bp
)
8815 if (!CHIP_IS_E1(bp
)) {
8816 REG_WR(bp
, PXP2_REG_RD_START_INIT
, 0);
8817 REG_WR(bp
, PXP2_REG_RQ_RBC_DONE
, 0);
8823 * Reset the whole chip except for:
8825 * - PCI Glue, PSWHST, PXP/PXP2 RF (all controlled by
8828 * - MISC (including AEU)
8832 static void bnx2x_process_kill_chip_reset(struct bnx2x
*bp
, bool global
)
8834 u32 not_reset_mask1
, reset_mask1
, not_reset_mask2
, reset_mask2
;
8835 u32 global_bits2
, stay_reset2
;
8838 * Bits that have to be set in reset_mask2 if we want to reset 'global'
8839 * (per chip) blocks.
8842 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CPU
|
8843 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CORE
;
8845 /* Don't reset the following blocks.
8846 * Important: per port blocks (such as EMAC, BMAC, UMAC) can't be
8847 * reset, as in 4 port device they might still be owned
8848 * by the MCP (there is only one leader per path).
8851 MISC_REGISTERS_RESET_REG_1_RST_HC
|
8852 MISC_REGISTERS_RESET_REG_1_RST_PXPV
|
8853 MISC_REGISTERS_RESET_REG_1_RST_PXP
;
8856 MISC_REGISTERS_RESET_REG_2_RST_PCI_MDIO
|
8857 MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE
|
8858 MISC_REGISTERS_RESET_REG_2_RST_EMAC1_HARD_CORE
|
8859 MISC_REGISTERS_RESET_REG_2_RST_MISC_CORE
|
8860 MISC_REGISTERS_RESET_REG_2_RST_RBCN
|
8861 MISC_REGISTERS_RESET_REG_2_RST_GRC
|
8862 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_REG_HARD_CORE
|
8863 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_HARD_CORE_RST_B
|
8864 MISC_REGISTERS_RESET_REG_2_RST_ATC
|
8865 MISC_REGISTERS_RESET_REG_2_PGLC
|
8866 MISC_REGISTERS_RESET_REG_2_RST_BMAC0
|
8867 MISC_REGISTERS_RESET_REG_2_RST_BMAC1
|
8868 MISC_REGISTERS_RESET_REG_2_RST_EMAC0
|
8869 MISC_REGISTERS_RESET_REG_2_RST_EMAC1
|
8870 MISC_REGISTERS_RESET_REG_2_UMAC0
|
8871 MISC_REGISTERS_RESET_REG_2_UMAC1
;
8874 * Keep the following blocks in reset:
8875 * - all xxMACs are handled by the bnx2x_link code.
8878 MISC_REGISTERS_RESET_REG_2_XMAC
|
8879 MISC_REGISTERS_RESET_REG_2_XMAC_SOFT
;
8881 /* Full reset masks according to the chip */
8882 reset_mask1
= 0xffffffff;
8885 reset_mask2
= 0xffff;
8886 else if (CHIP_IS_E1H(bp
))
8887 reset_mask2
= 0x1ffff;
8888 else if (CHIP_IS_E2(bp
))
8889 reset_mask2
= 0xfffff;
8890 else /* CHIP_IS_E3 */
8891 reset_mask2
= 0x3ffffff;
8893 /* Don't reset global blocks unless we need to */
8895 reset_mask2
&= ~global_bits2
;
8898 * In case of attention in the QM, we need to reset PXP
8899 * (MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR) before QM
8900 * because otherwise QM reset would release 'close the gates' shortly
8901 * before resetting the PXP, then the PSWRQ would send a write
8902 * request to PGLUE. Then when PXP is reset, PGLUE would try to
8903 * read the payload data from PSWWR, but PSWWR would not
8904 * respond. The write queue in PGLUE would stuck, dmae commands
8905 * would not return. Therefore it's important to reset the second
8906 * reset register (containing the
8907 * MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR bit) before the
8908 * first one (containing the MISC_REGISTERS_RESET_REG_1_RST_QM
8911 REG_WR(bp
, GRCBASE_MISC
+ MISC_REGISTERS_RESET_REG_2_CLEAR
,
8912 reset_mask2
& (~not_reset_mask2
));
8914 REG_WR(bp
, GRCBASE_MISC
+ MISC_REGISTERS_RESET_REG_1_CLEAR
,
8915 reset_mask1
& (~not_reset_mask1
));
8920 REG_WR(bp
, GRCBASE_MISC
+ MISC_REGISTERS_RESET_REG_2_SET
,
8921 reset_mask2
& (~stay_reset2
));
8926 REG_WR(bp
, GRCBASE_MISC
+ MISC_REGISTERS_RESET_REG_1_SET
, reset_mask1
);
8931 * bnx2x_er_poll_igu_vq - poll for pending writes bit.
8932 * It should get cleared in no more than 1s.
8934 * @bp: driver handle
8936 * It should get cleared in no more than 1s. Returns 0 if
8937 * pending writes bit gets cleared.
8939 static int bnx2x_er_poll_igu_vq(struct bnx2x
*bp
)
8945 pend_bits
= REG_RD(bp
, IGU_REG_PENDING_BITS_STATUS
);
8950 usleep_range(1000, 1000);
8951 } while (cnt
-- > 0);
8954 BNX2X_ERR("Still pending IGU requests pend_bits=%x!\n",
8962 static int bnx2x_process_kill(struct bnx2x
*bp
, bool global
)
8966 u32 sr_cnt
, blk_cnt
, port_is_idle_0
, port_is_idle_1
, pgl_exp_rom2
;
8970 /* Empty the Tetris buffer, wait for 1s */
8972 sr_cnt
= REG_RD(bp
, PXP2_REG_RD_SR_CNT
);
8973 blk_cnt
= REG_RD(bp
, PXP2_REG_RD_BLK_CNT
);
8974 port_is_idle_0
= REG_RD(bp
, PXP2_REG_RD_PORT_IS_IDLE_0
);
8975 port_is_idle_1
= REG_RD(bp
, PXP2_REG_RD_PORT_IS_IDLE_1
);
8976 pgl_exp_rom2
= REG_RD(bp
, PXP2_REG_PGL_EXP_ROM2
);
8978 tags_63_32
= REG_RD(bp
, PGLUE_B_REG_TAGS_63_32
);
8980 if ((sr_cnt
== 0x7e) && (blk_cnt
== 0xa0) &&
8981 ((port_is_idle_0
& 0x1) == 0x1) &&
8982 ((port_is_idle_1
& 0x1) == 0x1) &&
8983 (pgl_exp_rom2
== 0xffffffff) &&
8984 (!CHIP_IS_E3(bp
) || (tags_63_32
== 0xffffffff)))
8986 usleep_range(1000, 1000);
8987 } while (cnt
-- > 0);
8990 BNX2X_ERR("Tetris buffer didn't get empty or there are still outstanding read requests after 1s!\n");
8991 BNX2X_ERR("sr_cnt=0x%08x, blk_cnt=0x%08x, port_is_idle_0=0x%08x, port_is_idle_1=0x%08x, pgl_exp_rom2=0x%08x\n",
8992 sr_cnt
, blk_cnt
, port_is_idle_0
, port_is_idle_1
,
8999 /* Close gates #2, #3 and #4 */
9000 bnx2x_set_234_gates(bp
, true);
9002 /* Poll for IGU VQs for 57712 and newer chips */
9003 if (!CHIP_IS_E1x(bp
) && bnx2x_er_poll_igu_vq(bp
))
9007 /* TBD: Indicate that "process kill" is in progress to MCP */
9009 /* Clear "unprepared" bit */
9010 REG_WR(bp
, MISC_REG_UNPREPARED
, 0);
9013 /* Make sure all is written to the chip before the reset */
9016 /* Wait for 1ms to empty GLUE and PCI-E core queues,
9017 * PSWHST, GRC and PSWRD Tetris buffer.
9019 usleep_range(1000, 1000);
9021 /* Prepare to chip reset: */
9024 bnx2x_reset_mcp_prep(bp
, &val
);
9030 /* reset the chip */
9031 bnx2x_process_kill_chip_reset(bp
, global
);
9034 /* Recover after reset: */
9036 if (global
&& bnx2x_reset_mcp_comp(bp
, val
))
9039 /* TBD: Add resetting the NO_MCP mode DB here */
9041 /* Open the gates #2, #3 and #4 */
9042 bnx2x_set_234_gates(bp
, false);
9044 /* TBD: IGU/AEU preparation bring back the AEU/IGU to a
9045 * reset state, re-enable attentions. */
9050 static int bnx2x_leader_reset(struct bnx2x
*bp
)
9053 bool global
= bnx2x_reset_is_global(bp
);
9056 /* if not going to reset MCP - load "fake" driver to reset HW while
9057 * driver is owner of the HW
9059 if (!global
&& !BP_NOMCP(bp
)) {
9060 load_code
= bnx2x_fw_command(bp
, DRV_MSG_CODE_LOAD_REQ
,
9061 DRV_MSG_CODE_LOAD_REQ_WITH_LFA
);
9063 BNX2X_ERR("MCP response failure, aborting\n");
9065 goto exit_leader_reset
;
9067 if ((load_code
!= FW_MSG_CODE_DRV_LOAD_COMMON_CHIP
) &&
9068 (load_code
!= FW_MSG_CODE_DRV_LOAD_COMMON
)) {
9069 BNX2X_ERR("MCP unexpected resp, aborting\n");
9071 goto exit_leader_reset2
;
9073 load_code
= bnx2x_fw_command(bp
, DRV_MSG_CODE_LOAD_DONE
, 0);
9075 BNX2X_ERR("MCP response failure, aborting\n");
9077 goto exit_leader_reset2
;
9081 /* Try to recover after the failure */
9082 if (bnx2x_process_kill(bp
, global
)) {
9083 BNX2X_ERR("Something bad had happen on engine %d! Aii!\n",
9086 goto exit_leader_reset2
;
9090 * Clear RESET_IN_PROGRES and RESET_GLOBAL bits and update the driver
9093 bnx2x_set_reset_done(bp
);
9095 bnx2x_clear_reset_global(bp
);
9098 /* unload "fake driver" if it was loaded */
9099 if (!global
&& !BP_NOMCP(bp
)) {
9100 bnx2x_fw_command(bp
, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP
, 0);
9101 bnx2x_fw_command(bp
, DRV_MSG_CODE_UNLOAD_DONE
, 0);
9105 bnx2x_release_leader_lock(bp
);
9110 static void bnx2x_recovery_failed(struct bnx2x
*bp
)
9112 netdev_err(bp
->dev
, "Recovery has failed. Power cycle is needed.\n");
9114 /* Disconnect this device */
9115 netif_device_detach(bp
->dev
);
9118 * Block ifup for all function on this engine until "process kill"
9121 bnx2x_set_reset_in_progress(bp
);
9123 /* Shut down the power */
9124 bnx2x_set_power_state(bp
, PCI_D3hot
);
9126 bp
->recovery_state
= BNX2X_RECOVERY_FAILED
;
9132 * Assumption: runs under rtnl lock. This together with the fact
9133 * that it's called only from bnx2x_sp_rtnl() ensure that it
9134 * will never be called when netif_running(bp->dev) is false.
9136 static void bnx2x_parity_recover(struct bnx2x
*bp
)
9138 bool global
= false;
9139 u32 error_recovered
, error_unrecovered
;
9142 DP(NETIF_MSG_HW
, "Handling parity\n");
9144 switch (bp
->recovery_state
) {
9145 case BNX2X_RECOVERY_INIT
:
9146 DP(NETIF_MSG_HW
, "State is BNX2X_RECOVERY_INIT\n");
9147 is_parity
= bnx2x_chk_parity_attn(bp
, &global
, false);
9148 WARN_ON(!is_parity
);
9150 /* Try to get a LEADER_LOCK HW lock */
9151 if (bnx2x_trylock_leader_lock(bp
)) {
9152 bnx2x_set_reset_in_progress(bp
);
9154 * Check if there is a global attention and if
9155 * there was a global attention, set the global
9160 bnx2x_set_reset_global(bp
);
9165 /* Stop the driver */
9166 /* If interface has been removed - break */
9167 if (bnx2x_nic_unload(bp
, UNLOAD_RECOVERY
, false))
9170 bp
->recovery_state
= BNX2X_RECOVERY_WAIT
;
9172 /* Ensure "is_leader", MCP command sequence and
9173 * "recovery_state" update values are seen on other
9179 case BNX2X_RECOVERY_WAIT
:
9180 DP(NETIF_MSG_HW
, "State is BNX2X_RECOVERY_WAIT\n");
9181 if (bp
->is_leader
) {
9182 int other_engine
= BP_PATH(bp
) ? 0 : 1;
9183 bool other_load_status
=
9184 bnx2x_get_load_status(bp
, other_engine
);
9186 bnx2x_get_load_status(bp
, BP_PATH(bp
));
9187 global
= bnx2x_reset_is_global(bp
);
9190 * In case of a parity in a global block, let
9191 * the first leader that performs a
9192 * leader_reset() reset the global blocks in
9193 * order to clear global attentions. Otherwise
9194 * the the gates will remain closed for that
9198 (global
&& other_load_status
)) {
9199 /* Wait until all other functions get
9202 schedule_delayed_work(&bp
->sp_rtnl_task
,
9206 /* If all other functions got down -
9207 * try to bring the chip back to
9208 * normal. In any case it's an exit
9209 * point for a leader.
9211 if (bnx2x_leader_reset(bp
)) {
9212 bnx2x_recovery_failed(bp
);
9216 /* If we are here, means that the
9217 * leader has succeeded and doesn't
9218 * want to be a leader any more. Try
9219 * to continue as a none-leader.
9223 } else { /* non-leader */
9224 if (!bnx2x_reset_is_done(bp
, BP_PATH(bp
))) {
9225 /* Try to get a LEADER_LOCK HW lock as
9226 * long as a former leader may have
9227 * been unloaded by the user or
9228 * released a leadership by another
9231 if (bnx2x_trylock_leader_lock(bp
)) {
9232 /* I'm a leader now! Restart a
9239 schedule_delayed_work(&bp
->sp_rtnl_task
,
9245 * If there was a global attention, wait
9246 * for it to be cleared.
9248 if (bnx2x_reset_is_global(bp
)) {
9249 schedule_delayed_work(
9256 bp
->eth_stats
.recoverable_error
;
9258 bp
->eth_stats
.unrecoverable_error
;
9259 bp
->recovery_state
=
9260 BNX2X_RECOVERY_NIC_LOADING
;
9261 if (bnx2x_nic_load(bp
, LOAD_NORMAL
)) {
9262 error_unrecovered
++;
9264 "Recovery failed. Power cycle needed\n");
9265 /* Disconnect this device */
9266 netif_device_detach(bp
->dev
);
9267 /* Shut down the power */
9268 bnx2x_set_power_state(
9272 bp
->recovery_state
=
9273 BNX2X_RECOVERY_DONE
;
9277 bp
->eth_stats
.recoverable_error
=
9279 bp
->eth_stats
.unrecoverable_error
=
9291 static int bnx2x_close(struct net_device
*dev
);
9293 /* bnx2x_nic_unload() flushes the bnx2x_wq, thus reset task is
9294 * scheduled on a general queue in order to prevent a dead lock.
9296 static void bnx2x_sp_rtnl_task(struct work_struct
*work
)
9298 struct bnx2x
*bp
= container_of(work
, struct bnx2x
, sp_rtnl_task
.work
);
9302 if (!netif_running(bp
->dev
))
9305 /* if stop on error is defined no recovery flows should be executed */
9306 #ifdef BNX2X_STOP_ON_ERROR
9307 BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n"
9308 "you will need to reboot when done\n");
9309 goto sp_rtnl_not_reset
;
9312 if (unlikely(bp
->recovery_state
!= BNX2X_RECOVERY_DONE
)) {
9314 * Clear all pending SP commands as we are going to reset the
9317 bp
->sp_rtnl_state
= 0;
9320 bnx2x_parity_recover(bp
);
9325 if (test_and_clear_bit(BNX2X_SP_RTNL_TX_TIMEOUT
, &bp
->sp_rtnl_state
)) {
9327 * Clear all pending SP commands as we are going to reset the
9330 bp
->sp_rtnl_state
= 0;
9333 bnx2x_nic_unload(bp
, UNLOAD_NORMAL
, true);
9334 bnx2x_nic_load(bp
, LOAD_NORMAL
);
9338 #ifdef BNX2X_STOP_ON_ERROR
9341 if (test_and_clear_bit(BNX2X_SP_RTNL_SETUP_TC
, &bp
->sp_rtnl_state
))
9342 bnx2x_setup_tc(bp
->dev
, bp
->dcbx_port_params
.ets
.num_of_cos
);
9343 if (test_and_clear_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE
, &bp
->sp_rtnl_state
))
9344 bnx2x_after_function_update(bp
);
9346 * in case of fan failure we need to reset id if the "stop on error"
9347 * debug flag is set, since we trying to prevent permanent overheating
9350 if (test_and_clear_bit(BNX2X_SP_RTNL_FAN_FAILURE
, &bp
->sp_rtnl_state
)) {
9351 DP(NETIF_MSG_HW
, "fan failure detected. Unloading driver\n");
9352 netif_device_detach(bp
->dev
);
9353 bnx2x_close(bp
->dev
);
9360 /* end of nic load/unload */
9362 static void bnx2x_period_task(struct work_struct
*work
)
9364 struct bnx2x
*bp
= container_of(work
, struct bnx2x
, period_task
.work
);
9366 if (!netif_running(bp
->dev
))
9367 goto period_task_exit
;
9369 if (CHIP_REV_IS_SLOW(bp
)) {
9370 BNX2X_ERR("period task called on emulation, ignoring\n");
9371 goto period_task_exit
;
9374 bnx2x_acquire_phy_lock(bp
);
9376 * The barrier is needed to ensure the ordering between the writing to
9377 * the bp->port.pmf in the bnx2x_nic_load() or bnx2x_pmf_update() and
9382 bnx2x_period_func(&bp
->link_params
, &bp
->link_vars
);
9384 /* Re-queue task in 1 sec */
9385 queue_delayed_work(bnx2x_wq
, &bp
->period_task
, 1*HZ
);
9388 bnx2x_release_phy_lock(bp
);
9394 * Init service functions
9397 static u32
bnx2x_get_pretend_reg(struct bnx2x
*bp
)
9399 u32 base
= PXP2_REG_PGL_PRETEND_FUNC_F0
;
9400 u32 stride
= PXP2_REG_PGL_PRETEND_FUNC_F1
- base
;
9401 return base
+ (BP_ABS_FUNC(bp
)) * stride
;
9404 static void bnx2x_undi_int_disable_e1h(struct bnx2x
*bp
)
9406 u32 reg
= bnx2x_get_pretend_reg(bp
);
9408 /* Flush all outstanding writes */
9411 /* Pretend to be function 0 */
9413 REG_RD(bp
, reg
); /* Flush the GRC transaction (in the chip) */
9415 /* From now we are in the "like-E1" mode */
9416 bnx2x_int_disable(bp
);
9418 /* Flush all outstanding writes */
9421 /* Restore the original function */
9422 REG_WR(bp
, reg
, BP_ABS_FUNC(bp
));
9426 static inline void bnx2x_undi_int_disable(struct bnx2x
*bp
)
9429 bnx2x_int_disable(bp
);
9431 bnx2x_undi_int_disable_e1h(bp
);
9434 static void bnx2x_prev_unload_close_mac(struct bnx2x
*bp
,
9435 struct bnx2x_mac_vals
*vals
)
9437 u32 val
, base_addr
, offset
, mask
, reset_reg
;
9438 bool mac_stopped
= false;
9439 u8 port
= BP_PORT(bp
);
9441 /* reset addresses as they also mark which values were changed */
9442 vals
->bmac_addr
= 0;
9443 vals
->umac_addr
= 0;
9444 vals
->xmac_addr
= 0;
9445 vals
->emac_addr
= 0;
9447 reset_reg
= REG_RD(bp
, MISC_REG_RESET_REG_2
);
9449 if (!CHIP_IS_E3(bp
)) {
9450 val
= REG_RD(bp
, NIG_REG_BMAC0_REGS_OUT_EN
+ port
* 4);
9451 mask
= MISC_REGISTERS_RESET_REG_2_RST_BMAC0
<< port
;
9452 if ((mask
& reset_reg
) && val
) {
9454 BNX2X_DEV_INFO("Disable bmac Rx\n");
9455 base_addr
= BP_PORT(bp
) ? NIG_REG_INGRESS_BMAC1_MEM
9456 : NIG_REG_INGRESS_BMAC0_MEM
;
9457 offset
= CHIP_IS_E2(bp
) ? BIGMAC2_REGISTER_BMAC_CONTROL
9458 : BIGMAC_REGISTER_BMAC_CONTROL
;
9461 * use rd/wr since we cannot use dmae. This is safe
9462 * since MCP won't access the bus due to the request
9463 * to unload, and no function on the path can be
9464 * loaded at this time.
9466 wb_data
[0] = REG_RD(bp
, base_addr
+ offset
);
9467 wb_data
[1] = REG_RD(bp
, base_addr
+ offset
+ 0x4);
9468 vals
->bmac_addr
= base_addr
+ offset
;
9469 vals
->bmac_val
[0] = wb_data
[0];
9470 vals
->bmac_val
[1] = wb_data
[1];
9471 wb_data
[0] &= ~BMAC_CONTROL_RX_ENABLE
;
9472 REG_WR(bp
, vals
->bmac_addr
, wb_data
[0]);
9473 REG_WR(bp
, vals
->bmac_addr
+ 0x4, wb_data
[1]);
9476 BNX2X_DEV_INFO("Disable emac Rx\n");
9477 vals
->emac_addr
= NIG_REG_NIG_EMAC0_EN
+ BP_PORT(bp
)*4;
9478 vals
->emac_val
= REG_RD(bp
, vals
->emac_addr
);
9479 REG_WR(bp
, vals
->emac_addr
, 0);
9482 if (reset_reg
& MISC_REGISTERS_RESET_REG_2_XMAC
) {
9483 BNX2X_DEV_INFO("Disable xmac Rx\n");
9484 base_addr
= BP_PORT(bp
) ? GRCBASE_XMAC1
: GRCBASE_XMAC0
;
9485 val
= REG_RD(bp
, base_addr
+ XMAC_REG_PFC_CTRL_HI
);
9486 REG_WR(bp
, base_addr
+ XMAC_REG_PFC_CTRL_HI
,
9488 REG_WR(bp
, base_addr
+ XMAC_REG_PFC_CTRL_HI
,
9490 vals
->xmac_addr
= base_addr
+ XMAC_REG_CTRL
;
9491 vals
->xmac_val
= REG_RD(bp
, vals
->xmac_addr
);
9492 REG_WR(bp
, vals
->xmac_addr
, 0);
9495 mask
= MISC_REGISTERS_RESET_REG_2_UMAC0
<< port
;
9496 if (mask
& reset_reg
) {
9497 BNX2X_DEV_INFO("Disable umac Rx\n");
9498 base_addr
= BP_PORT(bp
) ? GRCBASE_UMAC1
: GRCBASE_UMAC0
;
9499 vals
->umac_addr
= base_addr
+ UMAC_REG_COMMAND_CONFIG
;
9500 vals
->umac_val
= REG_RD(bp
, vals
->umac_addr
);
9501 REG_WR(bp
, vals
->umac_addr
, 0);
9511 #define BNX2X_PREV_UNDI_PROD_ADDR(p) (BAR_TSTRORM_INTMEM + 0x1508 + ((p) << 4))
9512 #define BNX2X_PREV_UNDI_RCQ(val) ((val) & 0xffff)
9513 #define BNX2X_PREV_UNDI_BD(val) ((val) >> 16 & 0xffff)
9514 #define BNX2X_PREV_UNDI_PROD(rcq, bd) ((bd) << 16 | (rcq))
9516 static void bnx2x_prev_unload_undi_inc(struct bnx2x
*bp
, u8 port
, u8 inc
)
9519 u32 tmp_reg
= REG_RD(bp
, BNX2X_PREV_UNDI_PROD_ADDR(port
));
9521 rcq
= BNX2X_PREV_UNDI_RCQ(tmp_reg
) + inc
;
9522 bd
= BNX2X_PREV_UNDI_BD(tmp_reg
) + inc
;
9524 tmp_reg
= BNX2X_PREV_UNDI_PROD(rcq
, bd
);
9525 REG_WR(bp
, BNX2X_PREV_UNDI_PROD_ADDR(port
), tmp_reg
);
9527 BNX2X_DEV_INFO("UNDI producer [%d] rings bd -> 0x%04x, rcq -> 0x%04x\n",
9531 static int bnx2x_prev_mcp_done(struct bnx2x
*bp
)
9533 u32 rc
= bnx2x_fw_command(bp
, DRV_MSG_CODE_UNLOAD_DONE
,
9534 DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET
);
9536 BNX2X_ERR("MCP response failure, aborting\n");
9543 static struct bnx2x_prev_path_list
*
9544 bnx2x_prev_path_get_entry(struct bnx2x
*bp
)
9546 struct bnx2x_prev_path_list
*tmp_list
;
9548 list_for_each_entry(tmp_list
, &bnx2x_prev_list
, list
)
9549 if (PCI_SLOT(bp
->pdev
->devfn
) == tmp_list
->slot
&&
9550 bp
->pdev
->bus
->number
== tmp_list
->bus
&&
9551 BP_PATH(bp
) == tmp_list
->path
)
9557 static bool bnx2x_prev_is_path_marked(struct bnx2x
*bp
)
9559 struct bnx2x_prev_path_list
*tmp_list
;
9562 if (down_trylock(&bnx2x_prev_sem
))
9565 list_for_each_entry(tmp_list
, &bnx2x_prev_list
, list
) {
9566 if (PCI_SLOT(bp
->pdev
->devfn
) == tmp_list
->slot
&&
9567 bp
->pdev
->bus
->number
== tmp_list
->bus
&&
9568 BP_PATH(bp
) == tmp_list
->path
) {
9570 BNX2X_DEV_INFO("Path %d was already cleaned from previous drivers\n",
9576 up(&bnx2x_prev_sem
);
9581 static int bnx2x_prev_mark_path(struct bnx2x
*bp
, bool after_undi
)
9583 struct bnx2x_prev_path_list
*tmp_list
;
9586 tmp_list
= kmalloc(sizeof(struct bnx2x_prev_path_list
), GFP_KERNEL
);
9588 BNX2X_ERR("Failed to allocate 'bnx2x_prev_path_list'\n");
9592 tmp_list
->bus
= bp
->pdev
->bus
->number
;
9593 tmp_list
->slot
= PCI_SLOT(bp
->pdev
->devfn
);
9594 tmp_list
->path
= BP_PATH(bp
);
9595 tmp_list
->undi
= after_undi
? (1 << BP_PORT(bp
)) : 0;
9597 rc
= down_interruptible(&bnx2x_prev_sem
);
9599 BNX2X_ERR("Received %d when tried to take lock\n", rc
);
9602 BNX2X_DEV_INFO("Marked path [%d] - finished previous unload\n",
9604 list_add(&tmp_list
->list
, &bnx2x_prev_list
);
9605 up(&bnx2x_prev_sem
);
9611 static int bnx2x_do_flr(struct bnx2x
*bp
)
9615 struct pci_dev
*dev
= bp
->pdev
;
9618 if (CHIP_IS_E1x(bp
)) {
9619 BNX2X_DEV_INFO("FLR not supported in E1/E1H\n");
9623 /* only bootcode REQ_BC_VER_4_INITIATE_FLR and onwards support flr */
9624 if (bp
->common
.bc_ver
< REQ_BC_VER_4_INITIATE_FLR
) {
9625 BNX2X_ERR("FLR not supported by BC_VER: 0x%x\n",
9630 /* Wait for Transaction Pending bit clean */
9631 for (i
= 0; i
< 4; i
++) {
9633 msleep((1 << (i
- 1)) * 100);
9635 pcie_capability_read_word(dev
, PCI_EXP_DEVSTA
, &status
);
9636 if (!(status
& PCI_EXP_DEVSTA_TRPND
))
9641 "transaction is not cleared; proceeding with reset anyway\n");
9645 BNX2X_DEV_INFO("Initiating FLR\n");
9646 bnx2x_fw_command(bp
, DRV_MSG_CODE_INITIATE_FLR
, 0);
9651 static int bnx2x_prev_unload_uncommon(struct bnx2x
*bp
)
9655 BNX2X_DEV_INFO("Uncommon unload Flow\n");
9657 /* Test if previous unload process was already finished for this path */
9658 if (bnx2x_prev_is_path_marked(bp
))
9659 return bnx2x_prev_mcp_done(bp
);
9661 /* If function has FLR capabilities, and existing FW version matches
9662 * the one required, then FLR will be sufficient to clean any residue
9663 * left by previous driver
9665 rc
= bnx2x_test_firmware_version(bp
, false);
9668 /* fw version is good */
9669 BNX2X_DEV_INFO("FW version matches our own. Attempting FLR\n");
9670 rc
= bnx2x_do_flr(bp
);
9674 /* FLR was performed */
9675 BNX2X_DEV_INFO("FLR successful\n");
9679 BNX2X_DEV_INFO("Could not FLR\n");
9681 /* Close the MCP request, return failure*/
9682 rc
= bnx2x_prev_mcp_done(bp
);
9684 rc
= BNX2X_PREV_WAIT_NEEDED
;
9689 static int bnx2x_prev_unload_common(struct bnx2x
*bp
)
9691 u32 reset_reg
, tmp_reg
= 0, rc
;
9692 bool prev_undi
= false;
9693 struct bnx2x_mac_vals mac_vals
;
9695 /* It is possible a previous function received 'common' answer,
9696 * but hasn't loaded yet, therefore creating a scenario of
9697 * multiple functions receiving 'common' on the same path.
9699 BNX2X_DEV_INFO("Common unload Flow\n");
9701 memset(&mac_vals
, 0, sizeof(mac_vals
));
9703 if (bnx2x_prev_is_path_marked(bp
))
9704 return bnx2x_prev_mcp_done(bp
);
9706 reset_reg
= REG_RD(bp
, MISC_REG_RESET_REG_1
);
9708 /* Reset should be performed after BRB is emptied */
9709 if (reset_reg
& MISC_REGISTERS_RESET_REG_1_RST_BRB1
) {
9710 u32 timer_count
= 1000;
9712 /* Close the MAC Rx to prevent BRB from filling up */
9713 bnx2x_prev_unload_close_mac(bp
, &mac_vals
);
9715 /* close LLH filters towards the BRB */
9716 bnx2x_set_rx_filter(&bp
->link_params
, 0);
9718 /* Check if the UNDI driver was previously loaded
9719 * UNDI driver initializes CID offset for normal bell to 0x7
9721 reset_reg
= REG_RD(bp
, MISC_REG_RESET_REG_1
);
9722 if (reset_reg
& MISC_REGISTERS_RESET_REG_1_RST_DORQ
) {
9723 tmp_reg
= REG_RD(bp
, DORQ_REG_NORM_CID_OFST
);
9724 if (tmp_reg
== 0x7) {
9725 BNX2X_DEV_INFO("UNDI previously loaded\n");
9727 /* clear the UNDI indication */
9728 REG_WR(bp
, DORQ_REG_NORM_CID_OFST
, 0);
9731 /* wait until BRB is empty */
9732 tmp_reg
= REG_RD(bp
, BRB1_REG_NUM_OF_FULL_BLOCKS
);
9733 while (timer_count
) {
9734 u32 prev_brb
= tmp_reg
;
9736 tmp_reg
= REG_RD(bp
, BRB1_REG_NUM_OF_FULL_BLOCKS
);
9740 BNX2X_DEV_INFO("BRB still has 0x%08x\n", tmp_reg
);
9742 /* reset timer as long as BRB actually gets emptied */
9743 if (prev_brb
> tmp_reg
)
9748 /* If UNDI resides in memory, manually increment it */
9750 bnx2x_prev_unload_undi_inc(bp
, BP_PORT(bp
), 1);
9756 BNX2X_ERR("Failed to empty BRB, hope for the best\n");
9760 /* No packets are in the pipeline, path is ready for reset */
9761 bnx2x_reset_common(bp
);
9763 if (mac_vals
.xmac_addr
)
9764 REG_WR(bp
, mac_vals
.xmac_addr
, mac_vals
.xmac_val
);
9765 if (mac_vals
.umac_addr
)
9766 REG_WR(bp
, mac_vals
.umac_addr
, mac_vals
.umac_val
);
9767 if (mac_vals
.emac_addr
)
9768 REG_WR(bp
, mac_vals
.emac_addr
, mac_vals
.emac_val
);
9769 if (mac_vals
.bmac_addr
) {
9770 REG_WR(bp
, mac_vals
.bmac_addr
, mac_vals
.bmac_val
[0]);
9771 REG_WR(bp
, mac_vals
.bmac_addr
+ 4, mac_vals
.bmac_val
[1]);
9774 rc
= bnx2x_prev_mark_path(bp
, prev_undi
);
9776 bnx2x_prev_mcp_done(bp
);
9780 return bnx2x_prev_mcp_done(bp
);
9783 /* previous driver DMAE transaction may have occurred when pre-boot stage ended
9784 * and boot began, or when kdump kernel was loaded. Either case would invalidate
9785 * the addresses of the transaction, resulting in was-error bit set in the pci
9786 * causing all hw-to-host pcie transactions to timeout. If this happened we want
9787 * to clear the interrupt which detected this from the pglueb and the was done
9790 static void bnx2x_prev_interrupted_dmae(struct bnx2x
*bp
)
9792 if (!CHIP_IS_E1x(bp
)) {
9793 u32 val
= REG_RD(bp
, PGLUE_B_REG_PGLUE_B_INT_STS
);
9794 if (val
& PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN
) {
9795 BNX2X_ERR("was error bit was found to be set in pglueb upon startup. Clearing");
9796 REG_WR(bp
, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR
,
9802 static int bnx2x_prev_unload(struct bnx2x
*bp
)
9804 int time_counter
= 10;
9805 u32 rc
, fw
, hw_lock_reg
, hw_lock_val
;
9806 struct bnx2x_prev_path_list
*prev_list
;
9807 BNX2X_DEV_INFO("Entering Previous Unload Flow\n");
9809 /* clear hw from errors which may have resulted from an interrupted
9812 bnx2x_prev_interrupted_dmae(bp
);
9814 /* Release previously held locks */
9815 hw_lock_reg
= (BP_FUNC(bp
) <= 5) ?
9816 (MISC_REG_DRIVER_CONTROL_1
+ BP_FUNC(bp
) * 8) :
9817 (MISC_REG_DRIVER_CONTROL_7
+ (BP_FUNC(bp
) - 6) * 8);
9819 hw_lock_val
= (REG_RD(bp
, hw_lock_reg
));
9821 if (hw_lock_val
& HW_LOCK_RESOURCE_NVRAM
) {
9822 BNX2X_DEV_INFO("Release Previously held NVRAM lock\n");
9823 REG_WR(bp
, MCP_REG_MCPR_NVM_SW_ARB
,
9824 (MCPR_NVM_SW_ARB_ARB_REQ_CLR1
<< BP_PORT(bp
)));
9827 BNX2X_DEV_INFO("Release Previously held hw lock\n");
9828 REG_WR(bp
, hw_lock_reg
, 0xffffffff);
9830 BNX2X_DEV_INFO("No need to release hw/nvram locks\n");
9832 if (MCPR_ACCESS_LOCK_LOCK
& REG_RD(bp
, MCP_REG_MCPR_ACCESS_LOCK
)) {
9833 BNX2X_DEV_INFO("Release previously held alr\n");
9834 REG_WR(bp
, MCP_REG_MCPR_ACCESS_LOCK
, 0);
9839 /* Lock MCP using an unload request */
9840 fw
= bnx2x_fw_command(bp
, DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS
, 0);
9842 BNX2X_ERR("MCP response failure, aborting\n");
9847 if (fw
== FW_MSG_CODE_DRV_UNLOAD_COMMON
) {
9848 rc
= bnx2x_prev_unload_common(bp
);
9852 /* non-common reply from MCP night require looping */
9853 rc
= bnx2x_prev_unload_uncommon(bp
);
9854 if (rc
!= BNX2X_PREV_WAIT_NEEDED
)
9858 } while (--time_counter
);
9860 if (!time_counter
|| rc
) {
9861 BNX2X_ERR("Failed unloading previous driver, aborting\n");
9865 /* Mark function if its port was used to boot from SAN */
9866 prev_list
= bnx2x_prev_path_get_entry(bp
);
9867 if (prev_list
&& (prev_list
->undi
& (1 << BP_PORT(bp
))))
9868 bp
->link_params
.feature_config_flags
|=
9869 FEATURE_CONFIG_BOOT_FROM_SAN
;
9871 BNX2X_DEV_INFO("Finished Previous Unload Flow [%d]\n", rc
);
9876 static void bnx2x_get_common_hwinfo(struct bnx2x
*bp
)
9878 u32 val
, val2
, val3
, val4
, id
, boot_mode
;
9881 /* Get the chip revision id and number. */
9882 /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
9883 val
= REG_RD(bp
, MISC_REG_CHIP_NUM
);
9884 id
= ((val
& 0xffff) << 16);
9885 val
= REG_RD(bp
, MISC_REG_CHIP_REV
);
9886 id
|= ((val
& 0xf) << 12);
9887 val
= REG_RD(bp
, MISC_REG_CHIP_METAL
);
9888 id
|= ((val
& 0xff) << 4);
9889 val
= REG_RD(bp
, MISC_REG_BOND_ID
);
9891 bp
->common
.chip_id
= id
;
9893 /* force 57811 according to MISC register */
9894 if (REG_RD(bp
, MISC_REG_CHIP_TYPE
) & MISC_REG_CHIP_TYPE_57811_MASK
) {
9895 if (CHIP_IS_57810(bp
))
9896 bp
->common
.chip_id
= (CHIP_NUM_57811
<< 16) |
9897 (bp
->common
.chip_id
& 0x0000FFFF);
9898 else if (CHIP_IS_57810_MF(bp
))
9899 bp
->common
.chip_id
= (CHIP_NUM_57811_MF
<< 16) |
9900 (bp
->common
.chip_id
& 0x0000FFFF);
9901 bp
->common
.chip_id
|= 0x1;
9904 /* Set doorbell size */
9905 bp
->db_size
= (1 << BNX2X_DB_SHIFT
);
9907 if (!CHIP_IS_E1x(bp
)) {
9908 val
= REG_RD(bp
, MISC_REG_PORT4MODE_EN_OVWR
);
9910 val
= REG_RD(bp
, MISC_REG_PORT4MODE_EN
);
9912 val
= (val
>> 1) & 1;
9913 BNX2X_DEV_INFO("chip is in %s\n", val
? "4_PORT_MODE" :
9915 bp
->common
.chip_port_mode
= val
? CHIP_4_PORT_MODE
:
9918 if (CHIP_MODE_IS_4_PORT(bp
))
9919 bp
->pfid
= (bp
->pf_num
>> 1); /* 0..3 */
9921 bp
->pfid
= (bp
->pf_num
& 0x6); /* 0, 2, 4, 6 */
9923 bp
->common
.chip_port_mode
= CHIP_PORT_MODE_NONE
; /* N/A */
9924 bp
->pfid
= bp
->pf_num
; /* 0..7 */
9927 BNX2X_DEV_INFO("pf_id: %x", bp
->pfid
);
9929 bp
->link_params
.chip_id
= bp
->common
.chip_id
;
9930 BNX2X_DEV_INFO("chip ID is 0x%x\n", id
);
9932 val
= (REG_RD(bp
, 0x2874) & 0x55);
9933 if ((bp
->common
.chip_id
& 0x1) ||
9934 (CHIP_IS_E1(bp
) && val
) || (CHIP_IS_E1H(bp
) && (val
== 0x55))) {
9935 bp
->flags
|= ONE_PORT_FLAG
;
9936 BNX2X_DEV_INFO("single port device\n");
9939 val
= REG_RD(bp
, MCP_REG_MCPR_NVM_CFG4
);
9940 bp
->common
.flash_size
= (BNX2X_NVRAM_1MB_SIZE
<<
9941 (val
& MCPR_NVM_CFG4_FLASH_SIZE
));
9942 BNX2X_DEV_INFO("flash_size 0x%x (%d)\n",
9943 bp
->common
.flash_size
, bp
->common
.flash_size
);
9945 bnx2x_init_shmem(bp
);
9949 bp
->common
.shmem2_base
= REG_RD(bp
, (BP_PATH(bp
) ?
9950 MISC_REG_GENERIC_CR_1
:
9951 MISC_REG_GENERIC_CR_0
));
9953 bp
->link_params
.shmem_base
= bp
->common
.shmem_base
;
9954 bp
->link_params
.shmem2_base
= bp
->common
.shmem2_base
;
9955 if (SHMEM2_RD(bp
, size
) >
9956 (u32
)offsetof(struct shmem2_region
, lfa_host_addr
[BP_PORT(bp
)]))
9957 bp
->link_params
.lfa_base
=
9958 REG_RD(bp
, bp
->common
.shmem2_base
+
9959 (u32
)offsetof(struct shmem2_region
,
9960 lfa_host_addr
[BP_PORT(bp
)]));
9962 bp
->link_params
.lfa_base
= 0;
9963 BNX2X_DEV_INFO("shmem offset 0x%x shmem2 offset 0x%x\n",
9964 bp
->common
.shmem_base
, bp
->common
.shmem2_base
);
9966 if (!bp
->common
.shmem_base
) {
9967 BNX2X_DEV_INFO("MCP not active\n");
9968 bp
->flags
|= NO_MCP_FLAG
;
9972 bp
->common
.hw_config
= SHMEM_RD(bp
, dev_info
.shared_hw_config
.config
);
9973 BNX2X_DEV_INFO("hw_config 0x%08x\n", bp
->common
.hw_config
);
9975 bp
->link_params
.hw_led_mode
= ((bp
->common
.hw_config
&
9976 SHARED_HW_CFG_LED_MODE_MASK
) >>
9977 SHARED_HW_CFG_LED_MODE_SHIFT
);
9979 bp
->link_params
.feature_config_flags
= 0;
9980 val
= SHMEM_RD(bp
, dev_info
.shared_feature_config
.config
);
9981 if (val
& SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED
)
9982 bp
->link_params
.feature_config_flags
|=
9983 FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED
;
9985 bp
->link_params
.feature_config_flags
&=
9986 ~FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED
;
9988 val
= SHMEM_RD(bp
, dev_info
.bc_rev
) >> 8;
9989 bp
->common
.bc_ver
= val
;
9990 BNX2X_DEV_INFO("bc_ver %X\n", val
);
9991 if (val
< BNX2X_BC_VER
) {
9992 /* for now only warn
9993 * later we might need to enforce this */
9994 BNX2X_ERR("This driver needs bc_ver %X but found %X, please upgrade BC\n",
9997 bp
->link_params
.feature_config_flags
|=
9998 (val
>= REQ_BC_VER_4_VRFY_FIRST_PHY_OPT_MDL
) ?
9999 FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY
: 0;
10001 bp
->link_params
.feature_config_flags
|=
10002 (val
>= REQ_BC_VER_4_VRFY_SPECIFIC_PHY_OPT_MDL
) ?
10003 FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY
: 0;
10004 bp
->link_params
.feature_config_flags
|=
10005 (val
>= REQ_BC_VER_4_VRFY_AFEX_SUPPORTED
) ?
10006 FEATURE_CONFIG_BC_SUPPORTS_AFEX
: 0;
10007 bp
->link_params
.feature_config_flags
|=
10008 (val
>= REQ_BC_VER_4_SFP_TX_DISABLE_SUPPORTED
) ?
10009 FEATURE_CONFIG_BC_SUPPORTS_SFP_TX_DISABLED
: 0;
10011 bp
->link_params
.feature_config_flags
|=
10012 (val
>= REQ_BC_VER_4_MT_SUPPORTED
) ?
10013 FEATURE_CONFIG_MT_SUPPORT
: 0;
10015 bp
->flags
|= (val
>= REQ_BC_VER_4_PFC_STATS_SUPPORTED
) ?
10016 BC_SUPPORTS_PFC_STATS
: 0;
10018 bp
->flags
|= (val
>= REQ_BC_VER_4_FCOE_FEATURES
) ?
10019 BC_SUPPORTS_FCOE_FEATURES
: 0;
10021 bp
->flags
|= (val
>= REQ_BC_VER_4_DCBX_ADMIN_MSG_NON_PMF
) ?
10022 BC_SUPPORTS_DCBX_MSG_NON_PMF
: 0;
10023 boot_mode
= SHMEM_RD(bp
,
10024 dev_info
.port_feature_config
[BP_PORT(bp
)].mba_config
) &
10025 PORT_FEATURE_MBA_BOOT_AGENT_TYPE_MASK
;
10026 switch (boot_mode
) {
10027 case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_PXE
:
10028 bp
->common
.boot_mode
= FEATURE_ETH_BOOTMODE_PXE
;
10030 case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_ISCSIB
:
10031 bp
->common
.boot_mode
= FEATURE_ETH_BOOTMODE_ISCSI
;
10033 case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_FCOE_BOOT
:
10034 bp
->common
.boot_mode
= FEATURE_ETH_BOOTMODE_FCOE
;
10036 case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_NONE
:
10037 bp
->common
.boot_mode
= FEATURE_ETH_BOOTMODE_NONE
;
10041 pci_read_config_word(bp
->pdev
, bp
->pm_cap
+ PCI_PM_PMC
, &pmc
);
10042 bp
->flags
|= (pmc
& PCI_PM_CAP_PME_D3cold
) ? 0 : NO_WOL_FLAG
;
10044 BNX2X_DEV_INFO("%sWoL capable\n",
10045 (bp
->flags
& NO_WOL_FLAG
) ? "not " : "");
10047 val
= SHMEM_RD(bp
, dev_info
.shared_hw_config
.part_num
);
10048 val2
= SHMEM_RD(bp
, dev_info
.shared_hw_config
.part_num
[4]);
10049 val3
= SHMEM_RD(bp
, dev_info
.shared_hw_config
.part_num
[8]);
10050 val4
= SHMEM_RD(bp
, dev_info
.shared_hw_config
.part_num
[12]);
10052 dev_info(&bp
->pdev
->dev
, "part number %X-%X-%X-%X\n",
10053 val
, val2
, val3
, val4
);
10056 #define IGU_FID(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID)
10057 #define IGU_VEC(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR)
10059 static int bnx2x_get_igu_cam_info(struct bnx2x
*bp
)
10061 int pfid
= BP_FUNC(bp
);
10064 u8 fid
, igu_sb_cnt
= 0;
10066 bp
->igu_base_sb
= 0xff;
10067 if (CHIP_INT_MODE_IS_BC(bp
)) {
10068 int vn
= BP_VN(bp
);
10069 igu_sb_cnt
= bp
->igu_sb_cnt
;
10070 bp
->igu_base_sb
= (CHIP_MODE_IS_4_PORT(bp
) ? pfid
: vn
) *
10073 bp
->igu_dsb_id
= E1HVN_MAX
* FP_SB_MAX_E1x
+
10074 (CHIP_MODE_IS_4_PORT(bp
) ? pfid
: vn
);
10079 /* IGU in normal mode - read CAM */
10080 for (igu_sb_id
= 0; igu_sb_id
< IGU_REG_MAPPING_MEMORY_SIZE
;
10082 val
= REG_RD(bp
, IGU_REG_MAPPING_MEMORY
+ igu_sb_id
* 4);
10083 if (!(val
& IGU_REG_MAPPING_MEMORY_VALID
))
10085 fid
= IGU_FID(val
);
10086 if ((fid
& IGU_FID_ENCODE_IS_PF
)) {
10087 if ((fid
& IGU_FID_PF_NUM_MASK
) != pfid
)
10089 if (IGU_VEC(val
) == 0)
10090 /* default status block */
10091 bp
->igu_dsb_id
= igu_sb_id
;
10093 if (bp
->igu_base_sb
== 0xff)
10094 bp
->igu_base_sb
= igu_sb_id
;
10100 #ifdef CONFIG_PCI_MSI
10101 /* Due to new PF resource allocation by MFW T7.4 and above, it's
10102 * optional that number of CAM entries will not be equal to the value
10103 * advertised in PCI.
10104 * Driver should use the minimal value of both as the actual status
10107 bp
->igu_sb_cnt
= min_t(int, bp
->igu_sb_cnt
, igu_sb_cnt
);
10110 if (igu_sb_cnt
== 0) {
10111 BNX2X_ERR("CAM configuration error\n");
10118 static void bnx2x_link_settings_supported(struct bnx2x
*bp
, u32 switch_cfg
)
10120 int cfg_size
= 0, idx
, port
= BP_PORT(bp
);
10122 /* Aggregation of supported attributes of all external phys */
10123 bp
->port
.supported
[0] = 0;
10124 bp
->port
.supported
[1] = 0;
10125 switch (bp
->link_params
.num_phys
) {
10127 bp
->port
.supported
[0] = bp
->link_params
.phy
[INT_PHY
].supported
;
10131 bp
->port
.supported
[0] = bp
->link_params
.phy
[EXT_PHY1
].supported
;
10135 if (bp
->link_params
.multi_phy_config
&
10136 PORT_HW_CFG_PHY_SWAPPED_ENABLED
) {
10137 bp
->port
.supported
[1] =
10138 bp
->link_params
.phy
[EXT_PHY1
].supported
;
10139 bp
->port
.supported
[0] =
10140 bp
->link_params
.phy
[EXT_PHY2
].supported
;
10142 bp
->port
.supported
[0] =
10143 bp
->link_params
.phy
[EXT_PHY1
].supported
;
10144 bp
->port
.supported
[1] =
10145 bp
->link_params
.phy
[EXT_PHY2
].supported
;
10151 if (!(bp
->port
.supported
[0] || bp
->port
.supported
[1])) {
10152 BNX2X_ERR("NVRAM config error. BAD phy config. PHY1 config 0x%x, PHY2 config 0x%x\n",
10154 dev_info
.port_hw_config
[port
].external_phy_config
),
10156 dev_info
.port_hw_config
[port
].external_phy_config2
));
10160 if (CHIP_IS_E3(bp
))
10161 bp
->port
.phy_addr
= REG_RD(bp
, MISC_REG_WC0_CTRL_PHY_ADDR
);
10163 switch (switch_cfg
) {
10164 case SWITCH_CFG_1G
:
10165 bp
->port
.phy_addr
= REG_RD(
10166 bp
, NIG_REG_SERDES0_CTRL_PHY_ADDR
+ port
*0x10);
10168 case SWITCH_CFG_10G
:
10169 bp
->port
.phy_addr
= REG_RD(
10170 bp
, NIG_REG_XGXS0_CTRL_PHY_ADDR
+ port
*0x18);
10173 BNX2X_ERR("BAD switch_cfg link_config 0x%x\n",
10174 bp
->port
.link_config
[0]);
10178 BNX2X_DEV_INFO("phy_addr 0x%x\n", bp
->port
.phy_addr
);
10179 /* mask what we support according to speed_cap_mask per configuration */
10180 for (idx
= 0; idx
< cfg_size
; idx
++) {
10181 if (!(bp
->link_params
.speed_cap_mask
[idx
] &
10182 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF
))
10183 bp
->port
.supported
[idx
] &= ~SUPPORTED_10baseT_Half
;
10185 if (!(bp
->link_params
.speed_cap_mask
[idx
] &
10186 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL
))
10187 bp
->port
.supported
[idx
] &= ~SUPPORTED_10baseT_Full
;
10189 if (!(bp
->link_params
.speed_cap_mask
[idx
] &
10190 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF
))
10191 bp
->port
.supported
[idx
] &= ~SUPPORTED_100baseT_Half
;
10193 if (!(bp
->link_params
.speed_cap_mask
[idx
] &
10194 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL
))
10195 bp
->port
.supported
[idx
] &= ~SUPPORTED_100baseT_Full
;
10197 if (!(bp
->link_params
.speed_cap_mask
[idx
] &
10198 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G
))
10199 bp
->port
.supported
[idx
] &= ~(SUPPORTED_1000baseT_Half
|
10200 SUPPORTED_1000baseT_Full
);
10202 if (!(bp
->link_params
.speed_cap_mask
[idx
] &
10203 PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G
))
10204 bp
->port
.supported
[idx
] &= ~SUPPORTED_2500baseX_Full
;
10206 if (!(bp
->link_params
.speed_cap_mask
[idx
] &
10207 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G
))
10208 bp
->port
.supported
[idx
] &= ~SUPPORTED_10000baseT_Full
;
10212 BNX2X_DEV_INFO("supported 0x%x 0x%x\n", bp
->port
.supported
[0],
10213 bp
->port
.supported
[1]);
10216 static void bnx2x_link_settings_requested(struct bnx2x
*bp
)
10218 u32 link_config
, idx
, cfg_size
= 0;
10219 bp
->port
.advertising
[0] = 0;
10220 bp
->port
.advertising
[1] = 0;
10221 switch (bp
->link_params
.num_phys
) {
10230 for (idx
= 0; idx
< cfg_size
; idx
++) {
10231 bp
->link_params
.req_duplex
[idx
] = DUPLEX_FULL
;
10232 link_config
= bp
->port
.link_config
[idx
];
10233 switch (link_config
& PORT_FEATURE_LINK_SPEED_MASK
) {
10234 case PORT_FEATURE_LINK_SPEED_AUTO
:
10235 if (bp
->port
.supported
[idx
] & SUPPORTED_Autoneg
) {
10236 bp
->link_params
.req_line_speed
[idx
] =
10238 bp
->port
.advertising
[idx
] |=
10239 bp
->port
.supported
[idx
];
10240 if (bp
->link_params
.phy
[EXT_PHY1
].type
==
10241 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833
)
10242 bp
->port
.advertising
[idx
] |=
10243 (SUPPORTED_100baseT_Half
|
10244 SUPPORTED_100baseT_Full
);
10246 /* force 10G, no AN */
10247 bp
->link_params
.req_line_speed
[idx
] =
10249 bp
->port
.advertising
[idx
] |=
10250 (ADVERTISED_10000baseT_Full
|
10256 case PORT_FEATURE_LINK_SPEED_10M_FULL
:
10257 if (bp
->port
.supported
[idx
] & SUPPORTED_10baseT_Full
) {
10258 bp
->link_params
.req_line_speed
[idx
] =
10260 bp
->port
.advertising
[idx
] |=
10261 (ADVERTISED_10baseT_Full
|
10264 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
10266 bp
->link_params
.speed_cap_mask
[idx
]);
10271 case PORT_FEATURE_LINK_SPEED_10M_HALF
:
10272 if (bp
->port
.supported
[idx
] & SUPPORTED_10baseT_Half
) {
10273 bp
->link_params
.req_line_speed
[idx
] =
10275 bp
->link_params
.req_duplex
[idx
] =
10277 bp
->port
.advertising
[idx
] |=
10278 (ADVERTISED_10baseT_Half
|
10281 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
10283 bp
->link_params
.speed_cap_mask
[idx
]);
10288 case PORT_FEATURE_LINK_SPEED_100M_FULL
:
10289 if (bp
->port
.supported
[idx
] &
10290 SUPPORTED_100baseT_Full
) {
10291 bp
->link_params
.req_line_speed
[idx
] =
10293 bp
->port
.advertising
[idx
] |=
10294 (ADVERTISED_100baseT_Full
|
10297 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
10299 bp
->link_params
.speed_cap_mask
[idx
]);
10304 case PORT_FEATURE_LINK_SPEED_100M_HALF
:
10305 if (bp
->port
.supported
[idx
] &
10306 SUPPORTED_100baseT_Half
) {
10307 bp
->link_params
.req_line_speed
[idx
] =
10309 bp
->link_params
.req_duplex
[idx
] =
10311 bp
->port
.advertising
[idx
] |=
10312 (ADVERTISED_100baseT_Half
|
10315 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
10317 bp
->link_params
.speed_cap_mask
[idx
]);
10322 case PORT_FEATURE_LINK_SPEED_1G
:
10323 if (bp
->port
.supported
[idx
] &
10324 SUPPORTED_1000baseT_Full
) {
10325 bp
->link_params
.req_line_speed
[idx
] =
10327 bp
->port
.advertising
[idx
] |=
10328 (ADVERTISED_1000baseT_Full
|
10331 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
10333 bp
->link_params
.speed_cap_mask
[idx
]);
10338 case PORT_FEATURE_LINK_SPEED_2_5G
:
10339 if (bp
->port
.supported
[idx
] &
10340 SUPPORTED_2500baseX_Full
) {
10341 bp
->link_params
.req_line_speed
[idx
] =
10343 bp
->port
.advertising
[idx
] |=
10344 (ADVERTISED_2500baseX_Full
|
10347 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
10349 bp
->link_params
.speed_cap_mask
[idx
]);
10354 case PORT_FEATURE_LINK_SPEED_10G_CX4
:
10355 if (bp
->port
.supported
[idx
] &
10356 SUPPORTED_10000baseT_Full
) {
10357 bp
->link_params
.req_line_speed
[idx
] =
10359 bp
->port
.advertising
[idx
] |=
10360 (ADVERTISED_10000baseT_Full
|
10363 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
10365 bp
->link_params
.speed_cap_mask
[idx
]);
10369 case PORT_FEATURE_LINK_SPEED_20G
:
10370 bp
->link_params
.req_line_speed
[idx
] = SPEED_20000
;
10374 BNX2X_ERR("NVRAM config error. BAD link speed link_config 0x%x\n",
10376 bp
->link_params
.req_line_speed
[idx
] =
10378 bp
->port
.advertising
[idx
] =
10379 bp
->port
.supported
[idx
];
10383 bp
->link_params
.req_flow_ctrl
[idx
] = (link_config
&
10384 PORT_FEATURE_FLOW_CONTROL_MASK
);
10385 if (bp
->link_params
.req_flow_ctrl
[idx
] ==
10386 BNX2X_FLOW_CTRL_AUTO
) {
10387 if (!(bp
->port
.supported
[idx
] & SUPPORTED_Autoneg
))
10388 bp
->link_params
.req_flow_ctrl
[idx
] =
10389 BNX2X_FLOW_CTRL_NONE
;
10391 bnx2x_set_requested_fc(bp
);
10394 BNX2X_DEV_INFO("req_line_speed %d req_duplex %d req_flow_ctrl 0x%x advertising 0x%x\n",
10395 bp
->link_params
.req_line_speed
[idx
],
10396 bp
->link_params
.req_duplex
[idx
],
10397 bp
->link_params
.req_flow_ctrl
[idx
],
10398 bp
->port
.advertising
[idx
]);
10402 static void bnx2x_set_mac_buf(u8
*mac_buf
, u32 mac_lo
, u16 mac_hi
)
10404 mac_hi
= cpu_to_be16(mac_hi
);
10405 mac_lo
= cpu_to_be32(mac_lo
);
10406 memcpy(mac_buf
, &mac_hi
, sizeof(mac_hi
));
10407 memcpy(mac_buf
+ sizeof(mac_hi
), &mac_lo
, sizeof(mac_lo
));
10410 static void bnx2x_get_port_hwinfo(struct bnx2x
*bp
)
10412 int port
= BP_PORT(bp
);
10414 u32 ext_phy_type
, ext_phy_config
, eee_mode
;
10416 bp
->link_params
.bp
= bp
;
10417 bp
->link_params
.port
= port
;
10419 bp
->link_params
.lane_config
=
10420 SHMEM_RD(bp
, dev_info
.port_hw_config
[port
].lane_config
);
10422 bp
->link_params
.speed_cap_mask
[0] =
10424 dev_info
.port_hw_config
[port
].speed_capability_mask
);
10425 bp
->link_params
.speed_cap_mask
[1] =
10427 dev_info
.port_hw_config
[port
].speed_capability_mask2
);
10428 bp
->port
.link_config
[0] =
10429 SHMEM_RD(bp
, dev_info
.port_feature_config
[port
].link_config
);
10431 bp
->port
.link_config
[1] =
10432 SHMEM_RD(bp
, dev_info
.port_feature_config
[port
].link_config2
);
10434 bp
->link_params
.multi_phy_config
=
10435 SHMEM_RD(bp
, dev_info
.port_hw_config
[port
].multi_phy_config
);
10436 /* If the device is capable of WoL, set the default state according
10439 config
= SHMEM_RD(bp
, dev_info
.port_feature_config
[port
].config
);
10440 bp
->wol
= (!(bp
->flags
& NO_WOL_FLAG
) &&
10441 (config
& PORT_FEATURE_WOL_ENABLED
));
10443 BNX2X_DEV_INFO("lane_config 0x%08x speed_cap_mask0 0x%08x link_config0 0x%08x\n",
10444 bp
->link_params
.lane_config
,
10445 bp
->link_params
.speed_cap_mask
[0],
10446 bp
->port
.link_config
[0]);
10448 bp
->link_params
.switch_cfg
= (bp
->port
.link_config
[0] &
10449 PORT_FEATURE_CONNECTED_SWITCH_MASK
);
10450 bnx2x_phy_probe(&bp
->link_params
);
10451 bnx2x_link_settings_supported(bp
, bp
->link_params
.switch_cfg
);
10453 bnx2x_link_settings_requested(bp
);
10456 * If connected directly, work with the internal PHY, otherwise, work
10457 * with the external PHY
10461 dev_info
.port_hw_config
[port
].external_phy_config
);
10462 ext_phy_type
= XGXS_EXT_PHY_TYPE(ext_phy_config
);
10463 if (ext_phy_type
== PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT
)
10464 bp
->mdio
.prtad
= bp
->port
.phy_addr
;
10466 else if ((ext_phy_type
!= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE
) &&
10467 (ext_phy_type
!= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN
))
10469 XGXS_EXT_PHY_ADDR(ext_phy_config
);
10471 /* Configure link feature according to nvram value */
10472 eee_mode
= (((SHMEM_RD(bp
, dev_info
.
10473 port_feature_config
[port
].eee_power_mode
)) &
10474 PORT_FEAT_CFG_EEE_POWER_MODE_MASK
) >>
10475 PORT_FEAT_CFG_EEE_POWER_MODE_SHIFT
);
10476 if (eee_mode
!= PORT_FEAT_CFG_EEE_POWER_MODE_DISABLED
) {
10477 bp
->link_params
.eee_mode
= EEE_MODE_ADV_LPI
|
10478 EEE_MODE_ENABLE_LPI
|
10479 EEE_MODE_OUTPUT_TIME
;
10481 bp
->link_params
.eee_mode
= 0;
10485 void bnx2x_get_iscsi_info(struct bnx2x
*bp
)
10487 u32 no_flags
= NO_ISCSI_FLAG
;
10488 int port
= BP_PORT(bp
);
10489 u32 max_iscsi_conn
= FW_ENCODE_32BIT_PATTERN
^ SHMEM_RD(bp
,
10490 drv_lic_key
[port
].max_iscsi_conn
);
10492 if (!CNIC_SUPPORT(bp
)) {
10493 bp
->flags
|= no_flags
;
10497 /* Get the number of maximum allowed iSCSI connections */
10498 bp
->cnic_eth_dev
.max_iscsi_conn
=
10499 (max_iscsi_conn
& BNX2X_MAX_ISCSI_INIT_CONN_MASK
) >>
10500 BNX2X_MAX_ISCSI_INIT_CONN_SHIFT
;
10502 BNX2X_DEV_INFO("max_iscsi_conn 0x%x\n",
10503 bp
->cnic_eth_dev
.max_iscsi_conn
);
10506 * If maximum allowed number of connections is zero -
10507 * disable the feature.
10509 if (!bp
->cnic_eth_dev
.max_iscsi_conn
)
10510 bp
->flags
|= no_flags
;
10514 static void bnx2x_get_ext_wwn_info(struct bnx2x
*bp
, int func
)
10517 bp
->cnic_eth_dev
.fcoe_wwn_port_name_hi
=
10518 MF_CFG_RD(bp
, func_ext_config
[func
].fcoe_wwn_port_name_upper
);
10519 bp
->cnic_eth_dev
.fcoe_wwn_port_name_lo
=
10520 MF_CFG_RD(bp
, func_ext_config
[func
].fcoe_wwn_port_name_lower
);
10523 bp
->cnic_eth_dev
.fcoe_wwn_node_name_hi
=
10524 MF_CFG_RD(bp
, func_ext_config
[func
].fcoe_wwn_node_name_upper
);
10525 bp
->cnic_eth_dev
.fcoe_wwn_node_name_lo
=
10526 MF_CFG_RD(bp
, func_ext_config
[func
].fcoe_wwn_node_name_lower
);
10528 static void bnx2x_get_fcoe_info(struct bnx2x
*bp
)
10530 int port
= BP_PORT(bp
);
10531 int func
= BP_ABS_FUNC(bp
);
10532 u32 max_fcoe_conn
= FW_ENCODE_32BIT_PATTERN
^ SHMEM_RD(bp
,
10533 drv_lic_key
[port
].max_fcoe_conn
);
10535 if (!CNIC_SUPPORT(bp
)) {
10536 bp
->flags
|= NO_FCOE_FLAG
;
10540 /* Get the number of maximum allowed FCoE connections */
10541 bp
->cnic_eth_dev
.max_fcoe_conn
=
10542 (max_fcoe_conn
& BNX2X_MAX_FCOE_INIT_CONN_MASK
) >>
10543 BNX2X_MAX_FCOE_INIT_CONN_SHIFT
;
10545 /* Read the WWN: */
10548 bp
->cnic_eth_dev
.fcoe_wwn_port_name_hi
=
10550 dev_info
.port_hw_config
[port
].
10551 fcoe_wwn_port_name_upper
);
10552 bp
->cnic_eth_dev
.fcoe_wwn_port_name_lo
=
10554 dev_info
.port_hw_config
[port
].
10555 fcoe_wwn_port_name_lower
);
10558 bp
->cnic_eth_dev
.fcoe_wwn_node_name_hi
=
10560 dev_info
.port_hw_config
[port
].
10561 fcoe_wwn_node_name_upper
);
10562 bp
->cnic_eth_dev
.fcoe_wwn_node_name_lo
=
10564 dev_info
.port_hw_config
[port
].
10565 fcoe_wwn_node_name_lower
);
10566 } else if (!IS_MF_SD(bp
)) {
10568 * Read the WWN info only if the FCoE feature is enabled for
10571 if (BNX2X_MF_EXT_PROTOCOL_FCOE(bp
) && !CHIP_IS_E1x(bp
))
10572 bnx2x_get_ext_wwn_info(bp
, func
);
10574 } else if (IS_MF_FCOE_SD(bp
) && !CHIP_IS_E1x(bp
)) {
10575 bnx2x_get_ext_wwn_info(bp
, func
);
10578 BNX2X_DEV_INFO("max_fcoe_conn 0x%x\n", bp
->cnic_eth_dev
.max_fcoe_conn
);
10581 * If maximum allowed number of connections is zero -
10582 * disable the feature.
10584 if (!bp
->cnic_eth_dev
.max_fcoe_conn
)
10585 bp
->flags
|= NO_FCOE_FLAG
;
10588 static void bnx2x_get_cnic_info(struct bnx2x
*bp
)
10591 * iSCSI may be dynamically disabled but reading
10592 * info here we will decrease memory usage by driver
10593 * if the feature is disabled for good
10595 bnx2x_get_iscsi_info(bp
);
10596 bnx2x_get_fcoe_info(bp
);
10599 static void bnx2x_get_cnic_mac_hwinfo(struct bnx2x
*bp
)
10602 int func
= BP_ABS_FUNC(bp
);
10603 int port
= BP_PORT(bp
);
10604 u8
*iscsi_mac
= bp
->cnic_eth_dev
.iscsi_mac
;
10605 u8
*fip_mac
= bp
->fip_mac
;
10608 /* iSCSI and FCoE NPAR MACs: if there is no either iSCSI or
10609 * FCoE MAC then the appropriate feature should be disabled.
10610 * In non SD mode features configuration comes from struct
10613 if (!IS_MF_SD(bp
) && !CHIP_IS_E1x(bp
)) {
10614 u32 cfg
= MF_CFG_RD(bp
, func_ext_config
[func
].func_cfg
);
10615 if (cfg
& MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD
) {
10616 val2
= MF_CFG_RD(bp
, func_ext_config
[func
].
10617 iscsi_mac_addr_upper
);
10618 val
= MF_CFG_RD(bp
, func_ext_config
[func
].
10619 iscsi_mac_addr_lower
);
10620 bnx2x_set_mac_buf(iscsi_mac
, val
, val2
);
10622 ("Read iSCSI MAC: %pM\n", iscsi_mac
);
10624 bp
->flags
|= NO_ISCSI_OOO_FLAG
| NO_ISCSI_FLAG
;
10627 if (cfg
& MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD
) {
10628 val2
= MF_CFG_RD(bp
, func_ext_config
[func
].
10629 fcoe_mac_addr_upper
);
10630 val
= MF_CFG_RD(bp
, func_ext_config
[func
].
10631 fcoe_mac_addr_lower
);
10632 bnx2x_set_mac_buf(fip_mac
, val
, val2
);
10634 ("Read FCoE L2 MAC: %pM\n", fip_mac
);
10636 bp
->flags
|= NO_FCOE_FLAG
;
10639 bp
->mf_ext_config
= cfg
;
10641 } else { /* SD MODE */
10642 if (BNX2X_IS_MF_SD_PROTOCOL_ISCSI(bp
)) {
10643 /* use primary mac as iscsi mac */
10644 memcpy(iscsi_mac
, bp
->dev
->dev_addr
, ETH_ALEN
);
10646 BNX2X_DEV_INFO("SD ISCSI MODE\n");
10648 ("Read iSCSI MAC: %pM\n", iscsi_mac
);
10649 } else if (BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp
)) {
10650 /* use primary mac as fip mac */
10651 memcpy(fip_mac
, bp
->dev
->dev_addr
, ETH_ALEN
);
10652 BNX2X_DEV_INFO("SD FCoE MODE\n");
10654 ("Read FIP MAC: %pM\n", fip_mac
);
10658 if (IS_MF_STORAGE_SD(bp
))
10659 /* Zero primary MAC configuration */
10660 memset(bp
->dev
->dev_addr
, 0, ETH_ALEN
);
10662 if (IS_MF_FCOE_AFEX(bp
))
10663 /* use FIP MAC as primary MAC */
10664 memcpy(bp
->dev
->dev_addr
, fip_mac
, ETH_ALEN
);
10667 val2
= SHMEM_RD(bp
, dev_info
.port_hw_config
[port
].
10669 val
= SHMEM_RD(bp
, dev_info
.port_hw_config
[port
].
10671 bnx2x_set_mac_buf(iscsi_mac
, val
, val2
);
10673 val2
= SHMEM_RD(bp
, dev_info
.port_hw_config
[port
].
10674 fcoe_fip_mac_upper
);
10675 val
= SHMEM_RD(bp
, dev_info
.port_hw_config
[port
].
10676 fcoe_fip_mac_lower
);
10677 bnx2x_set_mac_buf(fip_mac
, val
, val2
);
10680 /* Disable iSCSI OOO if MAC configuration is invalid. */
10681 if (!is_valid_ether_addr(iscsi_mac
)) {
10682 bp
->flags
|= NO_ISCSI_OOO_FLAG
| NO_ISCSI_FLAG
;
10683 memset(iscsi_mac
, 0, ETH_ALEN
);
10686 /* Disable FCoE if MAC configuration is invalid. */
10687 if (!is_valid_ether_addr(fip_mac
)) {
10688 bp
->flags
|= NO_FCOE_FLAG
;
10689 memset(bp
->fip_mac
, 0, ETH_ALEN
);
10693 static void bnx2x_get_mac_hwinfo(struct bnx2x
*bp
)
10696 int func
= BP_ABS_FUNC(bp
);
10697 int port
= BP_PORT(bp
);
10699 /* Zero primary MAC configuration */
10700 memset(bp
->dev
->dev_addr
, 0, ETH_ALEN
);
10702 if (BP_NOMCP(bp
)) {
10703 BNX2X_ERROR("warning: random MAC workaround active\n");
10704 eth_hw_addr_random(bp
->dev
);
10705 } else if (IS_MF(bp
)) {
10706 val2
= MF_CFG_RD(bp
, func_mf_config
[func
].mac_upper
);
10707 val
= MF_CFG_RD(bp
, func_mf_config
[func
].mac_lower
);
10708 if ((val2
!= FUNC_MF_CFG_UPPERMAC_DEFAULT
) &&
10709 (val
!= FUNC_MF_CFG_LOWERMAC_DEFAULT
))
10710 bnx2x_set_mac_buf(bp
->dev
->dev_addr
, val
, val2
);
10712 if (CNIC_SUPPORT(bp
))
10713 bnx2x_get_cnic_mac_hwinfo(bp
);
10715 /* in SF read MACs from port configuration */
10716 val2
= SHMEM_RD(bp
, dev_info
.port_hw_config
[port
].mac_upper
);
10717 val
= SHMEM_RD(bp
, dev_info
.port_hw_config
[port
].mac_lower
);
10718 bnx2x_set_mac_buf(bp
->dev
->dev_addr
, val
, val2
);
10720 if (CNIC_SUPPORT(bp
))
10721 bnx2x_get_cnic_mac_hwinfo(bp
);
10724 memcpy(bp
->link_params
.mac_addr
, bp
->dev
->dev_addr
, ETH_ALEN
);
10725 memcpy(bp
->dev
->perm_addr
, bp
->dev
->dev_addr
, ETH_ALEN
);
10727 if (!bnx2x_is_valid_ether_addr(bp
, bp
->dev
->dev_addr
))
10728 dev_err(&bp
->pdev
->dev
,
10729 "bad Ethernet MAC address configuration: %pM\n"
10730 "change it manually before bringing up the appropriate network interface\n",
10731 bp
->dev
->dev_addr
);
10734 static bool bnx2x_get_dropless_info(struct bnx2x
*bp
)
10739 if (IS_MF(bp
) && !CHIP_IS_E1x(bp
)) {
10740 /* Take function: tmp = func */
10741 tmp
= BP_ABS_FUNC(bp
);
10742 cfg
= MF_CFG_RD(bp
, func_ext_config
[tmp
].func_cfg
);
10743 cfg
= !!(cfg
& MACP_FUNC_CFG_PAUSE_ON_HOST_RING
);
10745 /* Take port: tmp = port */
10748 dev_info
.port_hw_config
[tmp
].generic_features
);
10749 cfg
= !!(cfg
& PORT_HW_CFG_PAUSE_ON_HOST_RING_ENABLED
);
10754 static int bnx2x_get_hwinfo(struct bnx2x
*bp
)
10756 int /*abs*/func
= BP_ABS_FUNC(bp
);
10761 bnx2x_get_common_hwinfo(bp
);
10764 * initialize IGU parameters
10766 if (CHIP_IS_E1x(bp
)) {
10767 bp
->common
.int_block
= INT_BLOCK_HC
;
10769 bp
->igu_dsb_id
= DEF_SB_IGU_ID
;
10770 bp
->igu_base_sb
= 0;
10772 bp
->common
.int_block
= INT_BLOCK_IGU
;
10774 /* do not allow device reset during IGU info preocessing */
10775 bnx2x_acquire_hw_lock(bp
, HW_LOCK_RESOURCE_RESET
);
10777 val
= REG_RD(bp
, IGU_REG_BLOCK_CONFIGURATION
);
10779 if (val
& IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN
) {
10782 BNX2X_DEV_INFO("FORCING Normal Mode\n");
10784 val
&= ~(IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN
);
10785 REG_WR(bp
, IGU_REG_BLOCK_CONFIGURATION
, val
);
10786 REG_WR(bp
, IGU_REG_RESET_MEMORIES
, 0x7f);
10788 while (tout
&& REG_RD(bp
, IGU_REG_RESET_MEMORIES
)) {
10790 usleep_range(1000, 1000);
10793 if (REG_RD(bp
, IGU_REG_RESET_MEMORIES
)) {
10794 dev_err(&bp
->pdev
->dev
,
10795 "FORCING Normal Mode failed!!!\n");
10796 bnx2x_release_hw_lock(bp
,
10797 HW_LOCK_RESOURCE_RESET
);
10802 if (val
& IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN
) {
10803 BNX2X_DEV_INFO("IGU Backward Compatible Mode\n");
10804 bp
->common
.int_block
|= INT_BLOCK_MODE_BW_COMP
;
10806 BNX2X_DEV_INFO("IGU Normal Mode\n");
10808 rc
= bnx2x_get_igu_cam_info(bp
);
10809 bnx2x_release_hw_lock(bp
, HW_LOCK_RESOURCE_RESET
);
10815 * set base FW non-default (fast path) status block id, this value is
10816 * used to initialize the fw_sb_id saved on the fp/queue structure to
10817 * determine the id used by the FW.
10819 if (CHIP_IS_E1x(bp
))
10820 bp
->base_fw_ndsb
= BP_PORT(bp
) * FP_SB_MAX_E1x
+ BP_L_ID(bp
);
10822 * 57712 - we currently use one FW SB per IGU SB (Rx and Tx of
10823 * the same queue are indicated on the same IGU SB). So we prefer
10824 * FW and IGU SBs to be the same value.
10826 bp
->base_fw_ndsb
= bp
->igu_base_sb
;
10828 BNX2X_DEV_INFO("igu_dsb_id %d igu_base_sb %d igu_sb_cnt %d\n"
10829 "base_fw_ndsb %d\n", bp
->igu_dsb_id
, bp
->igu_base_sb
,
10830 bp
->igu_sb_cnt
, bp
->base_fw_ndsb
);
10833 * Initialize MF configuration
10840 if (!CHIP_IS_E1(bp
) && !BP_NOMCP(bp
)) {
10841 BNX2X_DEV_INFO("shmem2base 0x%x, size %d, mfcfg offset %d\n",
10842 bp
->common
.shmem2_base
, SHMEM2_RD(bp
, size
),
10843 (u32
)offsetof(struct shmem2_region
, mf_cfg_addr
));
10845 if (SHMEM2_HAS(bp
, mf_cfg_addr
))
10846 bp
->common
.mf_cfg_base
= SHMEM2_RD(bp
, mf_cfg_addr
);
10848 bp
->common
.mf_cfg_base
= bp
->common
.shmem_base
+
10849 offsetof(struct shmem_region
, func_mb
) +
10850 E1H_FUNC_MAX
* sizeof(struct drv_func_mb
);
10852 * get mf configuration:
10853 * 1. existence of MF configuration
10854 * 2. MAC address must be legal (check only upper bytes)
10855 * for Switch-Independent mode;
10856 * OVLAN must be legal for Switch-Dependent mode
10857 * 3. SF_MODE configures specific MF mode
10859 if (bp
->common
.mf_cfg_base
!= SHMEM_MF_CFG_ADDR_NONE
) {
10860 /* get mf configuration */
10862 dev_info
.shared_feature_config
.config
);
10863 val
&= SHARED_FEAT_CFG_FORCE_SF_MODE_MASK
;
10866 case SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT
:
10867 val
= MF_CFG_RD(bp
, func_mf_config
[func
].
10869 /* check for legal mac (upper bytes)*/
10870 if (val
!= 0xffff) {
10871 bp
->mf_mode
= MULTI_FUNCTION_SI
;
10872 bp
->mf_config
[vn
] = MF_CFG_RD(bp
,
10873 func_mf_config
[func
].config
);
10875 BNX2X_DEV_INFO("illegal MAC address for SI\n");
10877 case SHARED_FEAT_CFG_FORCE_SF_MODE_AFEX_MODE
:
10878 if ((!CHIP_IS_E1x(bp
)) &&
10879 (MF_CFG_RD(bp
, func_mf_config
[func
].
10880 mac_upper
) != 0xffff) &&
10882 afex_driver_support
))) {
10883 bp
->mf_mode
= MULTI_FUNCTION_AFEX
;
10884 bp
->mf_config
[vn
] = MF_CFG_RD(bp
,
10885 func_mf_config
[func
].config
);
10887 BNX2X_DEV_INFO("can not configure afex mode\n");
10890 case SHARED_FEAT_CFG_FORCE_SF_MODE_MF_ALLOWED
:
10891 /* get OV configuration */
10892 val
= MF_CFG_RD(bp
,
10893 func_mf_config
[FUNC_0
].e1hov_tag
);
10894 val
&= FUNC_MF_CFG_E1HOV_TAG_MASK
;
10896 if (val
!= FUNC_MF_CFG_E1HOV_TAG_DEFAULT
) {
10897 bp
->mf_mode
= MULTI_FUNCTION_SD
;
10898 bp
->mf_config
[vn
] = MF_CFG_RD(bp
,
10899 func_mf_config
[func
].config
);
10901 BNX2X_DEV_INFO("illegal OV for SD\n");
10904 /* Unknown configuration: reset mf_config */
10905 bp
->mf_config
[vn
] = 0;
10906 BNX2X_DEV_INFO("unknown MF mode 0x%x\n", val
);
10910 BNX2X_DEV_INFO("%s function mode\n",
10911 IS_MF(bp
) ? "multi" : "single");
10913 switch (bp
->mf_mode
) {
10914 case MULTI_FUNCTION_SD
:
10915 val
= MF_CFG_RD(bp
, func_mf_config
[func
].e1hov_tag
) &
10916 FUNC_MF_CFG_E1HOV_TAG_MASK
;
10917 if (val
!= FUNC_MF_CFG_E1HOV_TAG_DEFAULT
) {
10919 bp
->path_has_ovlan
= true;
10921 BNX2X_DEV_INFO("MF OV for func %d is %d (0x%04x)\n",
10922 func
, bp
->mf_ov
, bp
->mf_ov
);
10924 dev_err(&bp
->pdev
->dev
,
10925 "No valid MF OV for func %d, aborting\n",
10930 case MULTI_FUNCTION_AFEX
:
10931 BNX2X_DEV_INFO("func %d is in MF afex mode\n", func
);
10933 case MULTI_FUNCTION_SI
:
10934 BNX2X_DEV_INFO("func %d is in MF switch-independent mode\n",
10939 dev_err(&bp
->pdev
->dev
,
10940 "VN %d is in a single function mode, aborting\n",
10947 /* check if other port on the path needs ovlan:
10948 * Since MF configuration is shared between ports
10949 * Possible mixed modes are only
10950 * {SF, SI} {SF, SD} {SD, SF} {SI, SF}
10952 if (CHIP_MODE_IS_4_PORT(bp
) &&
10953 !bp
->path_has_ovlan
&&
10955 bp
->common
.mf_cfg_base
!= SHMEM_MF_CFG_ADDR_NONE
) {
10956 u8 other_port
= !BP_PORT(bp
);
10957 u8 other_func
= BP_PATH(bp
) + 2*other_port
;
10958 val
= MF_CFG_RD(bp
,
10959 func_mf_config
[other_func
].e1hov_tag
);
10960 if (val
!= FUNC_MF_CFG_E1HOV_TAG_DEFAULT
)
10961 bp
->path_has_ovlan
= true;
10965 /* adjust igu_sb_cnt to MF for E1x */
10966 if (CHIP_IS_E1x(bp
) && IS_MF(bp
))
10967 bp
->igu_sb_cnt
/= E1HVN_MAX
;
10970 bnx2x_get_port_hwinfo(bp
);
10972 /* Get MAC addresses */
10973 bnx2x_get_mac_hwinfo(bp
);
10975 bnx2x_get_cnic_info(bp
);
10980 static void bnx2x_read_fwinfo(struct bnx2x
*bp
)
10982 int cnt
, i
, block_end
, rodi
;
10983 char vpd_start
[BNX2X_VPD_LEN
+1];
10984 char str_id_reg
[VENDOR_ID_LEN
+1];
10985 char str_id_cap
[VENDOR_ID_LEN
+1];
10987 char *vpd_extended_data
= NULL
;
10990 cnt
= pci_read_vpd(bp
->pdev
, 0, BNX2X_VPD_LEN
, vpd_start
);
10991 memset(bp
->fw_ver
, 0, sizeof(bp
->fw_ver
));
10993 if (cnt
< BNX2X_VPD_LEN
)
10994 goto out_not_found
;
10996 /* VPD RO tag should be first tag after identifier string, hence
10997 * we should be able to find it in first BNX2X_VPD_LEN chars
10999 i
= pci_vpd_find_tag(vpd_start
, 0, BNX2X_VPD_LEN
,
11000 PCI_VPD_LRDT_RO_DATA
);
11002 goto out_not_found
;
11004 block_end
= i
+ PCI_VPD_LRDT_TAG_SIZE
+
11005 pci_vpd_lrdt_size(&vpd_start
[i
]);
11007 i
+= PCI_VPD_LRDT_TAG_SIZE
;
11009 if (block_end
> BNX2X_VPD_LEN
) {
11010 vpd_extended_data
= kmalloc(block_end
, GFP_KERNEL
);
11011 if (vpd_extended_data
== NULL
)
11012 goto out_not_found
;
11014 /* read rest of vpd image into vpd_extended_data */
11015 memcpy(vpd_extended_data
, vpd_start
, BNX2X_VPD_LEN
);
11016 cnt
= pci_read_vpd(bp
->pdev
, BNX2X_VPD_LEN
,
11017 block_end
- BNX2X_VPD_LEN
,
11018 vpd_extended_data
+ BNX2X_VPD_LEN
);
11019 if (cnt
< (block_end
- BNX2X_VPD_LEN
))
11020 goto out_not_found
;
11021 vpd_data
= vpd_extended_data
;
11023 vpd_data
= vpd_start
;
11025 /* now vpd_data holds full vpd content in both cases */
11027 rodi
= pci_vpd_find_info_keyword(vpd_data
, i
, block_end
,
11028 PCI_VPD_RO_KEYWORD_MFR_ID
);
11030 goto out_not_found
;
11032 len
= pci_vpd_info_field_size(&vpd_data
[rodi
]);
11034 if (len
!= VENDOR_ID_LEN
)
11035 goto out_not_found
;
11037 rodi
+= PCI_VPD_INFO_FLD_HDR_SIZE
;
11039 /* vendor specific info */
11040 snprintf(str_id_reg
, VENDOR_ID_LEN
+ 1, "%04x", PCI_VENDOR_ID_DELL
);
11041 snprintf(str_id_cap
, VENDOR_ID_LEN
+ 1, "%04X", PCI_VENDOR_ID_DELL
);
11042 if (!strncmp(str_id_reg
, &vpd_data
[rodi
], VENDOR_ID_LEN
) ||
11043 !strncmp(str_id_cap
, &vpd_data
[rodi
], VENDOR_ID_LEN
)) {
11045 rodi
= pci_vpd_find_info_keyword(vpd_data
, i
, block_end
,
11046 PCI_VPD_RO_KEYWORD_VENDOR0
);
11048 len
= pci_vpd_info_field_size(&vpd_data
[rodi
]);
11050 rodi
+= PCI_VPD_INFO_FLD_HDR_SIZE
;
11052 if (len
< 32 && (len
+ rodi
) <= BNX2X_VPD_LEN
) {
11053 memcpy(bp
->fw_ver
, &vpd_data
[rodi
], len
);
11054 bp
->fw_ver
[len
] = ' ';
11057 kfree(vpd_extended_data
);
11061 kfree(vpd_extended_data
);
11065 static void bnx2x_set_modes_bitmap(struct bnx2x
*bp
)
11069 if (CHIP_REV_IS_FPGA(bp
))
11070 SET_FLAGS(flags
, MODE_FPGA
);
11071 else if (CHIP_REV_IS_EMUL(bp
))
11072 SET_FLAGS(flags
, MODE_EMUL
);
11074 SET_FLAGS(flags
, MODE_ASIC
);
11076 if (CHIP_MODE_IS_4_PORT(bp
))
11077 SET_FLAGS(flags
, MODE_PORT4
);
11079 SET_FLAGS(flags
, MODE_PORT2
);
11081 if (CHIP_IS_E2(bp
))
11082 SET_FLAGS(flags
, MODE_E2
);
11083 else if (CHIP_IS_E3(bp
)) {
11084 SET_FLAGS(flags
, MODE_E3
);
11085 if (CHIP_REV(bp
) == CHIP_REV_Ax
)
11086 SET_FLAGS(flags
, MODE_E3_A0
);
11087 else /*if (CHIP_REV(bp) == CHIP_REV_Bx)*/
11088 SET_FLAGS(flags
, MODE_E3_B0
| MODE_COS3
);
11092 SET_FLAGS(flags
, MODE_MF
);
11093 switch (bp
->mf_mode
) {
11094 case MULTI_FUNCTION_SD
:
11095 SET_FLAGS(flags
, MODE_MF_SD
);
11097 case MULTI_FUNCTION_SI
:
11098 SET_FLAGS(flags
, MODE_MF_SI
);
11100 case MULTI_FUNCTION_AFEX
:
11101 SET_FLAGS(flags
, MODE_MF_AFEX
);
11105 SET_FLAGS(flags
, MODE_SF
);
11107 #if defined(__LITTLE_ENDIAN)
11108 SET_FLAGS(flags
, MODE_LITTLE_ENDIAN
);
11109 #else /*(__BIG_ENDIAN)*/
11110 SET_FLAGS(flags
, MODE_BIG_ENDIAN
);
11112 INIT_MODE_FLAGS(bp
) = flags
;
11115 static int bnx2x_init_bp(struct bnx2x
*bp
)
11120 mutex_init(&bp
->port
.phy_mutex
);
11121 mutex_init(&bp
->fw_mb_mutex
);
11122 spin_lock_init(&bp
->stats_lock
);
11125 INIT_DELAYED_WORK(&bp
->sp_task
, bnx2x_sp_task
);
11126 INIT_DELAYED_WORK(&bp
->sp_rtnl_task
, bnx2x_sp_rtnl_task
);
11127 INIT_DELAYED_WORK(&bp
->period_task
, bnx2x_period_task
);
11128 rc
= bnx2x_get_hwinfo(bp
);
11132 bnx2x_set_modes_bitmap(bp
);
11134 rc
= bnx2x_alloc_mem_bp(bp
);
11138 bnx2x_read_fwinfo(bp
);
11140 func
= BP_FUNC(bp
);
11142 /* need to reset chip if undi was active */
11143 if (!BP_NOMCP(bp
)) {
11146 SHMEM_RD(bp
, func_mb
[BP_FW_MB_IDX(bp
)].drv_mb_header
) &
11147 DRV_MSG_SEQ_NUMBER_MASK
;
11148 BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp
->fw_seq
);
11150 bnx2x_prev_unload(bp
);
11154 if (CHIP_REV_IS_FPGA(bp
))
11155 dev_err(&bp
->pdev
->dev
, "FPGA detected\n");
11157 if (BP_NOMCP(bp
) && (func
== 0))
11158 dev_err(&bp
->pdev
->dev
, "MCP disabled, must load devices in order!\n");
11160 bp
->disable_tpa
= disable_tpa
;
11161 bp
->disable_tpa
|= IS_MF_STORAGE_SD(bp
) || IS_MF_FCOE_AFEX(bp
);
11163 /* Set TPA flags */
11164 if (bp
->disable_tpa
) {
11165 bp
->flags
&= ~(TPA_ENABLE_FLAG
| GRO_ENABLE_FLAG
);
11166 bp
->dev
->features
&= ~NETIF_F_LRO
;
11168 bp
->flags
|= (TPA_ENABLE_FLAG
| GRO_ENABLE_FLAG
);
11169 bp
->dev
->features
|= NETIF_F_LRO
;
11172 if (CHIP_IS_E1(bp
))
11173 bp
->dropless_fc
= 0;
11175 bp
->dropless_fc
= dropless_fc
| bnx2x_get_dropless_info(bp
);
11179 bp
->tx_ring_size
= IS_MF_FCOE_AFEX(bp
) ? 0 : MAX_TX_AVAIL
;
11181 /* make sure that the numbers are in the right granularity */
11182 bp
->tx_ticks
= (50 / BNX2X_BTR
) * BNX2X_BTR
;
11183 bp
->rx_ticks
= (25 / BNX2X_BTR
) * BNX2X_BTR
;
11185 bp
->current_interval
= CHIP_REV_IS_SLOW(bp
) ? 5*HZ
: HZ
;
11187 init_timer(&bp
->timer
);
11188 bp
->timer
.expires
= jiffies
+ bp
->current_interval
;
11189 bp
->timer
.data
= (unsigned long) bp
;
11190 bp
->timer
.function
= bnx2x_timer
;
11192 if (SHMEM2_HAS(bp
, dcbx_lldp_params_offset
) &&
11193 SHMEM2_HAS(bp
, dcbx_lldp_dcbx_stat_offset
) &&
11194 SHMEM2_RD(bp
, dcbx_lldp_params_offset
) &&
11195 SHMEM2_RD(bp
, dcbx_lldp_dcbx_stat_offset
)) {
11196 bnx2x_dcbx_set_state(bp
, true, BNX2X_DCBX_ENABLED_ON_NEG_ON
);
11197 bnx2x_dcbx_init_params(bp
);
11199 bnx2x_dcbx_set_state(bp
, false, BNX2X_DCBX_ENABLED_OFF
);
11202 if (CHIP_IS_E1x(bp
))
11203 bp
->cnic_base_cl_id
= FP_SB_MAX_E1x
;
11205 bp
->cnic_base_cl_id
= FP_SB_MAX_E2
;
11207 /* multiple tx priority */
11208 if (CHIP_IS_E1x(bp
))
11209 bp
->max_cos
= BNX2X_MULTI_TX_COS_E1X
;
11210 if (CHIP_IS_E2(bp
) || CHIP_IS_E3A0(bp
))
11211 bp
->max_cos
= BNX2X_MULTI_TX_COS_E2_E3A0
;
11212 if (CHIP_IS_E3B0(bp
))
11213 bp
->max_cos
= BNX2X_MULTI_TX_COS_E3B0
;
11215 /* We need at least one default status block for slow-path events,
11216 * second status block for the L2 queue, and a third status block for
11217 * CNIC if supproted.
11219 if (CNIC_SUPPORT(bp
))
11220 bp
->min_msix_vec_cnt
= 3;
11222 bp
->min_msix_vec_cnt
= 2;
11223 BNX2X_DEV_INFO("bp->min_msix_vec_cnt %d", bp
->min_msix_vec_cnt
);
11229 /****************************************************************************
11230 * General service functions
11231 ****************************************************************************/
11234 * net_device service functions
11237 /* called with rtnl_lock */
11238 static int bnx2x_open(struct net_device
*dev
)
11240 struct bnx2x
*bp
= netdev_priv(dev
);
11241 bool global
= false;
11242 int other_engine
= BP_PATH(bp
) ? 0 : 1;
11243 bool other_load_status
, load_status
;
11245 bp
->stats_init
= true;
11247 netif_carrier_off(dev
);
11249 bnx2x_set_power_state(bp
, PCI_D0
);
11251 other_load_status
= bnx2x_get_load_status(bp
, other_engine
);
11252 load_status
= bnx2x_get_load_status(bp
, BP_PATH(bp
));
11255 * If parity had happen during the unload, then attentions
11256 * and/or RECOVERY_IN_PROGRES may still be set. In this case we
11257 * want the first function loaded on the current engine to
11258 * complete the recovery.
11260 if (!bnx2x_reset_is_done(bp
, BP_PATH(bp
)) ||
11261 bnx2x_chk_parity_attn(bp
, &global
, true))
11264 * If there are attentions and they are in a global
11265 * blocks, set the GLOBAL_RESET bit regardless whether
11266 * it will be this function that will complete the
11270 bnx2x_set_reset_global(bp
);
11273 * Only the first function on the current engine should
11274 * try to recover in open. In case of attentions in
11275 * global blocks only the first in the chip should try
11278 if ((!load_status
&&
11279 (!global
|| !other_load_status
)) &&
11280 bnx2x_trylock_leader_lock(bp
) &&
11281 !bnx2x_leader_reset(bp
)) {
11282 netdev_info(bp
->dev
, "Recovered in open\n");
11286 /* recovery has failed... */
11287 bnx2x_set_power_state(bp
, PCI_D3hot
);
11288 bp
->recovery_state
= BNX2X_RECOVERY_FAILED
;
11290 BNX2X_ERR("Recovery flow hasn't been properly completed yet. Try again later.\n"
11291 "If you still see this message after a few retries then power cycle is required.\n");
11296 bp
->recovery_state
= BNX2X_RECOVERY_DONE
;
11297 return bnx2x_nic_load(bp
, LOAD_OPEN
);
11300 /* called with rtnl_lock */
11301 static int bnx2x_close(struct net_device
*dev
)
11303 struct bnx2x
*bp
= netdev_priv(dev
);
11305 /* Unload the driver, release IRQs */
11306 bnx2x_nic_unload(bp
, UNLOAD_CLOSE
, false);
11309 bnx2x_set_power_state(bp
, PCI_D3hot
);
11314 static int bnx2x_init_mcast_macs_list(struct bnx2x
*bp
,
11315 struct bnx2x_mcast_ramrod_params
*p
)
11317 int mc_count
= netdev_mc_count(bp
->dev
);
11318 struct bnx2x_mcast_list_elem
*mc_mac
=
11319 kzalloc(sizeof(*mc_mac
) * mc_count
, GFP_ATOMIC
);
11320 struct netdev_hw_addr
*ha
;
11325 INIT_LIST_HEAD(&p
->mcast_list
);
11327 netdev_for_each_mc_addr(ha
, bp
->dev
) {
11328 mc_mac
->mac
= bnx2x_mc_addr(ha
);
11329 list_add_tail(&mc_mac
->link
, &p
->mcast_list
);
11333 p
->mcast_list_len
= mc_count
;
11338 static void bnx2x_free_mcast_macs_list(
11339 struct bnx2x_mcast_ramrod_params
*p
)
11341 struct bnx2x_mcast_list_elem
*mc_mac
=
11342 list_first_entry(&p
->mcast_list
, struct bnx2x_mcast_list_elem
,
11350 * bnx2x_set_uc_list - configure a new unicast MACs list.
11352 * @bp: driver handle
11354 * We will use zero (0) as a MAC type for these MACs.
11356 static int bnx2x_set_uc_list(struct bnx2x
*bp
)
11359 struct net_device
*dev
= bp
->dev
;
11360 struct netdev_hw_addr
*ha
;
11361 struct bnx2x_vlan_mac_obj
*mac_obj
= &bp
->sp_objs
->mac_obj
;
11362 unsigned long ramrod_flags
= 0;
11364 /* First schedule a cleanup up of old configuration */
11365 rc
= bnx2x_del_all_macs(bp
, mac_obj
, BNX2X_UC_LIST_MAC
, false);
11367 BNX2X_ERR("Failed to schedule DELETE operations: %d\n", rc
);
11371 netdev_for_each_uc_addr(ha
, dev
) {
11372 rc
= bnx2x_set_mac_one(bp
, bnx2x_uc_addr(ha
), mac_obj
, true,
11373 BNX2X_UC_LIST_MAC
, &ramrod_flags
);
11374 if (rc
== -EEXIST
) {
11376 "Failed to schedule ADD operations: %d\n", rc
);
11377 /* do not treat adding same MAC as error */
11380 } else if (rc
< 0) {
11382 BNX2X_ERR("Failed to schedule ADD operations: %d\n",
11388 /* Execute the pending commands */
11389 __set_bit(RAMROD_CONT
, &ramrod_flags
);
11390 return bnx2x_set_mac_one(bp
, NULL
, mac_obj
, false /* don't care */,
11391 BNX2X_UC_LIST_MAC
, &ramrod_flags
);
11394 static int bnx2x_set_mc_list(struct bnx2x
*bp
)
11396 struct net_device
*dev
= bp
->dev
;
11397 struct bnx2x_mcast_ramrod_params rparam
= {NULL
};
11400 rparam
.mcast_obj
= &bp
->mcast_obj
;
11402 /* first, clear all configured multicast MACs */
11403 rc
= bnx2x_config_mcast(bp
, &rparam
, BNX2X_MCAST_CMD_DEL
);
11405 BNX2X_ERR("Failed to clear multicast configuration: %d\n", rc
);
11409 /* then, configure a new MACs list */
11410 if (netdev_mc_count(dev
)) {
11411 rc
= bnx2x_init_mcast_macs_list(bp
, &rparam
);
11413 BNX2X_ERR("Failed to create multicast MACs list: %d\n",
11418 /* Now add the new MACs */
11419 rc
= bnx2x_config_mcast(bp
, &rparam
,
11420 BNX2X_MCAST_CMD_ADD
);
11422 BNX2X_ERR("Failed to set a new multicast configuration: %d\n",
11425 bnx2x_free_mcast_macs_list(&rparam
);
11432 /* If bp->state is OPEN, should be called with netif_addr_lock_bh() */
11433 void bnx2x_set_rx_mode(struct net_device
*dev
)
11435 struct bnx2x
*bp
= netdev_priv(dev
);
11436 u32 rx_mode
= BNX2X_RX_MODE_NORMAL
;
11438 if (bp
->state
!= BNX2X_STATE_OPEN
) {
11439 DP(NETIF_MSG_IFUP
, "state is %x, returning\n", bp
->state
);
11443 DP(NETIF_MSG_IFUP
, "dev->flags = %x\n", bp
->dev
->flags
);
11445 if (dev
->flags
& IFF_PROMISC
)
11446 rx_mode
= BNX2X_RX_MODE_PROMISC
;
11447 else if ((dev
->flags
& IFF_ALLMULTI
) ||
11448 ((netdev_mc_count(dev
) > BNX2X_MAX_MULTICAST
) &&
11450 rx_mode
= BNX2X_RX_MODE_ALLMULTI
;
11452 /* some multicasts */
11453 if (bnx2x_set_mc_list(bp
) < 0)
11454 rx_mode
= BNX2X_RX_MODE_ALLMULTI
;
11456 if (bnx2x_set_uc_list(bp
) < 0)
11457 rx_mode
= BNX2X_RX_MODE_PROMISC
;
11460 bp
->rx_mode
= rx_mode
;
11461 /* handle ISCSI SD mode */
11462 if (IS_MF_ISCSI_SD(bp
))
11463 bp
->rx_mode
= BNX2X_RX_MODE_NONE
;
11465 /* Schedule the rx_mode command */
11466 if (test_bit(BNX2X_FILTER_RX_MODE_PENDING
, &bp
->sp_state
)) {
11467 set_bit(BNX2X_FILTER_RX_MODE_SCHED
, &bp
->sp_state
);
11471 bnx2x_set_storm_rx_mode(bp
);
11474 /* called with rtnl_lock */
11475 static int bnx2x_mdio_read(struct net_device
*netdev
, int prtad
,
11476 int devad
, u16 addr
)
11478 struct bnx2x
*bp
= netdev_priv(netdev
);
11482 DP(NETIF_MSG_LINK
, "mdio_read: prtad 0x%x, devad 0x%x, addr 0x%x\n",
11483 prtad
, devad
, addr
);
11485 /* The HW expects different devad if CL22 is used */
11486 devad
= (devad
== MDIO_DEVAD_NONE
) ? DEFAULT_PHY_DEV_ADDR
: devad
;
11488 bnx2x_acquire_phy_lock(bp
);
11489 rc
= bnx2x_phy_read(&bp
->link_params
, prtad
, devad
, addr
, &value
);
11490 bnx2x_release_phy_lock(bp
);
11491 DP(NETIF_MSG_LINK
, "mdio_read_val 0x%x rc = 0x%x\n", value
, rc
);
11498 /* called with rtnl_lock */
11499 static int bnx2x_mdio_write(struct net_device
*netdev
, int prtad
, int devad
,
11500 u16 addr
, u16 value
)
11502 struct bnx2x
*bp
= netdev_priv(netdev
);
11506 "mdio_write: prtad 0x%x, devad 0x%x, addr 0x%x, value 0x%x\n",
11507 prtad
, devad
, addr
, value
);
11509 /* The HW expects different devad if CL22 is used */
11510 devad
= (devad
== MDIO_DEVAD_NONE
) ? DEFAULT_PHY_DEV_ADDR
: devad
;
11512 bnx2x_acquire_phy_lock(bp
);
11513 rc
= bnx2x_phy_write(&bp
->link_params
, prtad
, devad
, addr
, value
);
11514 bnx2x_release_phy_lock(bp
);
11518 /* called with rtnl_lock */
11519 static int bnx2x_ioctl(struct net_device
*dev
, struct ifreq
*ifr
, int cmd
)
11521 struct bnx2x
*bp
= netdev_priv(dev
);
11522 struct mii_ioctl_data
*mdio
= if_mii(ifr
);
11524 DP(NETIF_MSG_LINK
, "ioctl: phy id 0x%x, reg 0x%x, val_in 0x%x\n",
11525 mdio
->phy_id
, mdio
->reg_num
, mdio
->val_in
);
11527 if (!netif_running(dev
))
11530 return mdio_mii_ioctl(&bp
->mdio
, mdio
, cmd
);
11533 #ifdef CONFIG_NET_POLL_CONTROLLER
11534 static void poll_bnx2x(struct net_device
*dev
)
11536 struct bnx2x
*bp
= netdev_priv(dev
);
11539 for_each_eth_queue(bp
, i
) {
11540 struct bnx2x_fastpath
*fp
= &bp
->fp
[i
];
11541 napi_schedule(&bnx2x_fp(bp
, fp
->index
, napi
));
11546 static int bnx2x_validate_addr(struct net_device
*dev
)
11548 struct bnx2x
*bp
= netdev_priv(dev
);
11550 if (!bnx2x_is_valid_ether_addr(bp
, dev
->dev_addr
)) {
11551 BNX2X_ERR("Non-valid Ethernet address\n");
11552 return -EADDRNOTAVAIL
;
11557 static const struct net_device_ops bnx2x_netdev_ops
= {
11558 .ndo_open
= bnx2x_open
,
11559 .ndo_stop
= bnx2x_close
,
11560 .ndo_start_xmit
= bnx2x_start_xmit
,
11561 .ndo_select_queue
= bnx2x_select_queue
,
11562 .ndo_set_rx_mode
= bnx2x_set_rx_mode
,
11563 .ndo_set_mac_address
= bnx2x_change_mac_addr
,
11564 .ndo_validate_addr
= bnx2x_validate_addr
,
11565 .ndo_do_ioctl
= bnx2x_ioctl
,
11566 .ndo_change_mtu
= bnx2x_change_mtu
,
11567 .ndo_fix_features
= bnx2x_fix_features
,
11568 .ndo_set_features
= bnx2x_set_features
,
11569 .ndo_tx_timeout
= bnx2x_tx_timeout
,
11570 #ifdef CONFIG_NET_POLL_CONTROLLER
11571 .ndo_poll_controller
= poll_bnx2x
,
11573 .ndo_setup_tc
= bnx2x_setup_tc
,
11575 #ifdef NETDEV_FCOE_WWNN
11576 .ndo_fcoe_get_wwn
= bnx2x_fcoe_get_wwn
,
11580 static int bnx2x_set_coherency_mask(struct bnx2x
*bp
)
11582 struct device
*dev
= &bp
->pdev
->dev
;
11584 if (dma_set_mask(dev
, DMA_BIT_MASK(64)) == 0) {
11585 bp
->flags
|= USING_DAC_FLAG
;
11586 if (dma_set_coherent_mask(dev
, DMA_BIT_MASK(64)) != 0) {
11587 dev_err(dev
, "dma_set_coherent_mask failed, aborting\n");
11590 } else if (dma_set_mask(dev
, DMA_BIT_MASK(32)) != 0) {
11591 dev_err(dev
, "System does not support DMA, aborting\n");
11598 static int bnx2x_init_dev(struct pci_dev
*pdev
, struct net_device
*dev
,
11599 unsigned long board_type
)
11604 bool chip_is_e1x
= (board_type
== BCM57710
||
11605 board_type
== BCM57711
||
11606 board_type
== BCM57711E
);
11608 SET_NETDEV_DEV(dev
, &pdev
->dev
);
11609 bp
= netdev_priv(dev
);
11615 rc
= pci_enable_device(pdev
);
11617 dev_err(&bp
->pdev
->dev
,
11618 "Cannot enable PCI device, aborting\n");
11622 if (!(pci_resource_flags(pdev
, 0) & IORESOURCE_MEM
)) {
11623 dev_err(&bp
->pdev
->dev
,
11624 "Cannot find PCI device base address, aborting\n");
11626 goto err_out_disable
;
11629 if (!(pci_resource_flags(pdev
, 2) & IORESOURCE_MEM
)) {
11630 dev_err(&bp
->pdev
->dev
, "Cannot find second PCI device"
11631 " base address, aborting\n");
11633 goto err_out_disable
;
11636 pci_read_config_dword(pdev
, PCICFG_REVISION_ID_OFFSET
, &pci_cfg_dword
);
11637 if ((pci_cfg_dword
& PCICFG_REVESION_ID_MASK
) ==
11638 PCICFG_REVESION_ID_ERROR_VAL
) {
11639 pr_err("PCI device error, probably due to fan failure, aborting\n");
11641 goto err_out_disable
;
11644 if (atomic_read(&pdev
->enable_cnt
) == 1) {
11645 rc
= pci_request_regions(pdev
, DRV_MODULE_NAME
);
11647 dev_err(&bp
->pdev
->dev
,
11648 "Cannot obtain PCI resources, aborting\n");
11649 goto err_out_disable
;
11652 pci_set_master(pdev
);
11653 pci_save_state(pdev
);
11656 bp
->pm_cap
= pci_find_capability(pdev
, PCI_CAP_ID_PM
);
11657 if (bp
->pm_cap
== 0) {
11658 dev_err(&bp
->pdev
->dev
,
11659 "Cannot find power management capability, aborting\n");
11661 goto err_out_release
;
11664 if (!pci_is_pcie(pdev
)) {
11665 dev_err(&bp
->pdev
->dev
, "Not PCI Express, aborting\n");
11667 goto err_out_release
;
11670 rc
= bnx2x_set_coherency_mask(bp
);
11672 goto err_out_release
;
11674 dev
->mem_start
= pci_resource_start(pdev
, 0);
11675 dev
->base_addr
= dev
->mem_start
;
11676 dev
->mem_end
= pci_resource_end(pdev
, 0);
11678 dev
->irq
= pdev
->irq
;
11680 bp
->regview
= pci_ioremap_bar(pdev
, 0);
11681 if (!bp
->regview
) {
11682 dev_err(&bp
->pdev
->dev
,
11683 "Cannot map register space, aborting\n");
11685 goto err_out_release
;
11688 /* In E1/E1H use pci device function given by kernel.
11689 * In E2/E3 read physical function from ME register since these chips
11690 * support Physical Device Assignment where kernel BDF maybe arbitrary
11691 * (depending on hypervisor).
11694 bp
->pf_num
= PCI_FUNC(pdev
->devfn
);
11695 else {/* chip is E2/3*/
11696 pci_read_config_dword(bp
->pdev
,
11697 PCICFG_ME_REGISTER
, &pci_cfg_dword
);
11698 bp
->pf_num
= (u8
)((pci_cfg_dword
& ME_REG_ABS_PF_NUM
) >>
11699 ME_REG_ABS_PF_NUM_SHIFT
);
11701 BNX2X_DEV_INFO("me reg PF num: %d\n", bp
->pf_num
);
11703 bnx2x_set_power_state(bp
, PCI_D0
);
11705 /* clean indirect addresses */
11706 pci_write_config_dword(bp
->pdev
, PCICFG_GRC_ADDRESS
,
11707 PCICFG_VENDOR_ID_OFFSET
);
11709 * Clean the following indirect addresses for all functions since it
11710 * is not used by the driver.
11712 REG_WR(bp
, PXP2_REG_PGL_ADDR_88_F0
, 0);
11713 REG_WR(bp
, PXP2_REG_PGL_ADDR_8C_F0
, 0);
11714 REG_WR(bp
, PXP2_REG_PGL_ADDR_90_F0
, 0);
11715 REG_WR(bp
, PXP2_REG_PGL_ADDR_94_F0
, 0);
11718 REG_WR(bp
, PXP2_REG_PGL_ADDR_88_F1
, 0);
11719 REG_WR(bp
, PXP2_REG_PGL_ADDR_8C_F1
, 0);
11720 REG_WR(bp
, PXP2_REG_PGL_ADDR_90_F1
, 0);
11721 REG_WR(bp
, PXP2_REG_PGL_ADDR_94_F1
, 0);
11725 * Enable internal target-read (in case we are probed after PF FLR).
11726 * Must be done prior to any BAR read access. Only for 57712 and up
11729 REG_WR(bp
, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ
, 1);
11731 dev
->watchdog_timeo
= TX_TIMEOUT
;
11733 dev
->netdev_ops
= &bnx2x_netdev_ops
;
11734 bnx2x_set_ethtool_ops(dev
);
11736 dev
->priv_flags
|= IFF_UNICAST_FLT
;
11738 dev
->hw_features
= NETIF_F_SG
| NETIF_F_IP_CSUM
| NETIF_F_IPV6_CSUM
|
11739 NETIF_F_TSO
| NETIF_F_TSO_ECN
| NETIF_F_TSO6
|
11740 NETIF_F_RXCSUM
| NETIF_F_LRO
| NETIF_F_GRO
|
11741 NETIF_F_RXHASH
| NETIF_F_HW_VLAN_TX
;
11743 dev
->vlan_features
= NETIF_F_SG
| NETIF_F_IP_CSUM
| NETIF_F_IPV6_CSUM
|
11744 NETIF_F_TSO
| NETIF_F_TSO_ECN
| NETIF_F_TSO6
| NETIF_F_HIGHDMA
;
11746 dev
->features
|= dev
->hw_features
| NETIF_F_HW_VLAN_RX
;
11747 if (bp
->flags
& USING_DAC_FLAG
)
11748 dev
->features
|= NETIF_F_HIGHDMA
;
11750 /* Add Loopback capability to the device */
11751 dev
->hw_features
|= NETIF_F_LOOPBACK
;
11754 dev
->dcbnl_ops
= &bnx2x_dcbnl_ops
;
11757 /* get_port_hwinfo() will set prtad and mmds properly */
11758 bp
->mdio
.prtad
= MDIO_PRTAD_NONE
;
11760 bp
->mdio
.mode_support
= MDIO_SUPPORTS_C45
| MDIO_EMULATE_C22
;
11761 bp
->mdio
.dev
= dev
;
11762 bp
->mdio
.mdio_read
= bnx2x_mdio_read
;
11763 bp
->mdio
.mdio_write
= bnx2x_mdio_write
;
11768 if (atomic_read(&pdev
->enable_cnt
) == 1)
11769 pci_release_regions(pdev
);
11772 pci_disable_device(pdev
);
11773 pci_set_drvdata(pdev
, NULL
);
11779 static void bnx2x_get_pcie_width_speed(struct bnx2x
*bp
, int *width
, int *speed
)
11781 u32 val
= REG_RD(bp
, PCICFG_OFFSET
+ PCICFG_LINK_CONTROL
);
11783 *width
= (val
& PCICFG_LINK_WIDTH
) >> PCICFG_LINK_WIDTH_SHIFT
;
11785 /* return value of 1=2.5GHz 2=5GHz */
11786 *speed
= (val
& PCICFG_LINK_SPEED
) >> PCICFG_LINK_SPEED_SHIFT
;
11789 static int bnx2x_check_firmware(struct bnx2x
*bp
)
11791 const struct firmware
*firmware
= bp
->firmware
;
11792 struct bnx2x_fw_file_hdr
*fw_hdr
;
11793 struct bnx2x_fw_file_section
*sections
;
11794 u32 offset
, len
, num_ops
;
11799 if (firmware
->size
< sizeof(struct bnx2x_fw_file_hdr
)) {
11800 BNX2X_ERR("Wrong FW size\n");
11804 fw_hdr
= (struct bnx2x_fw_file_hdr
*)firmware
->data
;
11805 sections
= (struct bnx2x_fw_file_section
*)fw_hdr
;
11807 /* Make sure none of the offsets and sizes make us read beyond
11808 * the end of the firmware data */
11809 for (i
= 0; i
< sizeof(*fw_hdr
) / sizeof(*sections
); i
++) {
11810 offset
= be32_to_cpu(sections
[i
].offset
);
11811 len
= be32_to_cpu(sections
[i
].len
);
11812 if (offset
+ len
> firmware
->size
) {
11813 BNX2X_ERR("Section %d length is out of bounds\n", i
);
11818 /* Likewise for the init_ops offsets */
11819 offset
= be32_to_cpu(fw_hdr
->init_ops_offsets
.offset
);
11820 ops_offsets
= (u16
*)(firmware
->data
+ offset
);
11821 num_ops
= be32_to_cpu(fw_hdr
->init_ops
.len
) / sizeof(struct raw_op
);
11823 for (i
= 0; i
< be32_to_cpu(fw_hdr
->init_ops_offsets
.len
) / 2; i
++) {
11824 if (be16_to_cpu(ops_offsets
[i
]) > num_ops
) {
11825 BNX2X_ERR("Section offset %d is out of bounds\n", i
);
11830 /* Check FW version */
11831 offset
= be32_to_cpu(fw_hdr
->fw_version
.offset
);
11832 fw_ver
= firmware
->data
+ offset
;
11833 if ((fw_ver
[0] != BCM_5710_FW_MAJOR_VERSION
) ||
11834 (fw_ver
[1] != BCM_5710_FW_MINOR_VERSION
) ||
11835 (fw_ver
[2] != BCM_5710_FW_REVISION_VERSION
) ||
11836 (fw_ver
[3] != BCM_5710_FW_ENGINEERING_VERSION
)) {
11837 BNX2X_ERR("Bad FW version:%d.%d.%d.%d. Should be %d.%d.%d.%d\n",
11838 fw_ver
[0], fw_ver
[1], fw_ver
[2], fw_ver
[3],
11839 BCM_5710_FW_MAJOR_VERSION
,
11840 BCM_5710_FW_MINOR_VERSION
,
11841 BCM_5710_FW_REVISION_VERSION
,
11842 BCM_5710_FW_ENGINEERING_VERSION
);
11849 static void be32_to_cpu_n(const u8
*_source
, u8
*_target
, u32 n
)
11851 const __be32
*source
= (const __be32
*)_source
;
11852 u32
*target
= (u32
*)_target
;
11855 for (i
= 0; i
< n
/4; i
++)
11856 target
[i
] = be32_to_cpu(source
[i
]);
11860 Ops array is stored in the following format:
11861 {op(8bit), offset(24bit, big endian), data(32bit, big endian)}
11863 static void bnx2x_prep_ops(const u8
*_source
, u8
*_target
, u32 n
)
11865 const __be32
*source
= (const __be32
*)_source
;
11866 struct raw_op
*target
= (struct raw_op
*)_target
;
11869 for (i
= 0, j
= 0; i
< n
/8; i
++, j
+= 2) {
11870 tmp
= be32_to_cpu(source
[j
]);
11871 target
[i
].op
= (tmp
>> 24) & 0xff;
11872 target
[i
].offset
= tmp
& 0xffffff;
11873 target
[i
].raw_data
= be32_to_cpu(source
[j
+ 1]);
11877 /* IRO array is stored in the following format:
11878 * {base(24bit), m1(16bit), m2(16bit), m3(16bit), size(16bit) }
11880 static void bnx2x_prep_iro(const u8
*_source
, u8
*_target
, u32 n
)
11882 const __be32
*source
= (const __be32
*)_source
;
11883 struct iro
*target
= (struct iro
*)_target
;
11886 for (i
= 0, j
= 0; i
< n
/sizeof(struct iro
); i
++) {
11887 target
[i
].base
= be32_to_cpu(source
[j
]);
11889 tmp
= be32_to_cpu(source
[j
]);
11890 target
[i
].m1
= (tmp
>> 16) & 0xffff;
11891 target
[i
].m2
= tmp
& 0xffff;
11893 tmp
= be32_to_cpu(source
[j
]);
11894 target
[i
].m3
= (tmp
>> 16) & 0xffff;
11895 target
[i
].size
= tmp
& 0xffff;
11900 static void be16_to_cpu_n(const u8
*_source
, u8
*_target
, u32 n
)
11902 const __be16
*source
= (const __be16
*)_source
;
11903 u16
*target
= (u16
*)_target
;
11906 for (i
= 0; i
< n
/2; i
++)
11907 target
[i
] = be16_to_cpu(source
[i
]);
11910 #define BNX2X_ALLOC_AND_SET(arr, lbl, func) \
11912 u32 len = be32_to_cpu(fw_hdr->arr.len); \
11913 bp->arr = kmalloc(len, GFP_KERNEL); \
11916 func(bp->firmware->data + be32_to_cpu(fw_hdr->arr.offset), \
11917 (u8 *)bp->arr, len); \
11920 static int bnx2x_init_firmware(struct bnx2x
*bp
)
11922 const char *fw_file_name
;
11923 struct bnx2x_fw_file_hdr
*fw_hdr
;
11929 if (CHIP_IS_E1(bp
))
11930 fw_file_name
= FW_FILE_NAME_E1
;
11931 else if (CHIP_IS_E1H(bp
))
11932 fw_file_name
= FW_FILE_NAME_E1H
;
11933 else if (!CHIP_IS_E1x(bp
))
11934 fw_file_name
= FW_FILE_NAME_E2
;
11936 BNX2X_ERR("Unsupported chip revision\n");
11939 BNX2X_DEV_INFO("Loading %s\n", fw_file_name
);
11941 rc
= request_firmware(&bp
->firmware
, fw_file_name
, &bp
->pdev
->dev
);
11943 BNX2X_ERR("Can't load firmware file %s\n",
11945 goto request_firmware_exit
;
11948 rc
= bnx2x_check_firmware(bp
);
11950 BNX2X_ERR("Corrupt firmware file %s\n", fw_file_name
);
11951 goto request_firmware_exit
;
11954 fw_hdr
= (struct bnx2x_fw_file_hdr
*)bp
->firmware
->data
;
11956 /* Initialize the pointers to the init arrays */
11958 BNX2X_ALLOC_AND_SET(init_data
, request_firmware_exit
, be32_to_cpu_n
);
11961 BNX2X_ALLOC_AND_SET(init_ops
, init_ops_alloc_err
, bnx2x_prep_ops
);
11964 BNX2X_ALLOC_AND_SET(init_ops_offsets
, init_offsets_alloc_err
,
11967 /* STORMs firmware */
11968 INIT_TSEM_INT_TABLE_DATA(bp
) = bp
->firmware
->data
+
11969 be32_to_cpu(fw_hdr
->tsem_int_table_data
.offset
);
11970 INIT_TSEM_PRAM_DATA(bp
) = bp
->firmware
->data
+
11971 be32_to_cpu(fw_hdr
->tsem_pram_data
.offset
);
11972 INIT_USEM_INT_TABLE_DATA(bp
) = bp
->firmware
->data
+
11973 be32_to_cpu(fw_hdr
->usem_int_table_data
.offset
);
11974 INIT_USEM_PRAM_DATA(bp
) = bp
->firmware
->data
+
11975 be32_to_cpu(fw_hdr
->usem_pram_data
.offset
);
11976 INIT_XSEM_INT_TABLE_DATA(bp
) = bp
->firmware
->data
+
11977 be32_to_cpu(fw_hdr
->xsem_int_table_data
.offset
);
11978 INIT_XSEM_PRAM_DATA(bp
) = bp
->firmware
->data
+
11979 be32_to_cpu(fw_hdr
->xsem_pram_data
.offset
);
11980 INIT_CSEM_INT_TABLE_DATA(bp
) = bp
->firmware
->data
+
11981 be32_to_cpu(fw_hdr
->csem_int_table_data
.offset
);
11982 INIT_CSEM_PRAM_DATA(bp
) = bp
->firmware
->data
+
11983 be32_to_cpu(fw_hdr
->csem_pram_data
.offset
);
11985 BNX2X_ALLOC_AND_SET(iro_arr
, iro_alloc_err
, bnx2x_prep_iro
);
11990 kfree(bp
->init_ops_offsets
);
11991 init_offsets_alloc_err
:
11992 kfree(bp
->init_ops
);
11993 init_ops_alloc_err
:
11994 kfree(bp
->init_data
);
11995 request_firmware_exit
:
11996 release_firmware(bp
->firmware
);
11997 bp
->firmware
= NULL
;
12002 static void bnx2x_release_firmware(struct bnx2x
*bp
)
12004 kfree(bp
->init_ops_offsets
);
12005 kfree(bp
->init_ops
);
12006 kfree(bp
->init_data
);
12007 release_firmware(bp
->firmware
);
12008 bp
->firmware
= NULL
;
12012 static struct bnx2x_func_sp_drv_ops bnx2x_func_sp_drv
= {
12013 .init_hw_cmn_chip
= bnx2x_init_hw_common_chip
,
12014 .init_hw_cmn
= bnx2x_init_hw_common
,
12015 .init_hw_port
= bnx2x_init_hw_port
,
12016 .init_hw_func
= bnx2x_init_hw_func
,
12018 .reset_hw_cmn
= bnx2x_reset_common
,
12019 .reset_hw_port
= bnx2x_reset_port
,
12020 .reset_hw_func
= bnx2x_reset_func
,
12022 .gunzip_init
= bnx2x_gunzip_init
,
12023 .gunzip_end
= bnx2x_gunzip_end
,
12025 .init_fw
= bnx2x_init_firmware
,
12026 .release_fw
= bnx2x_release_firmware
,
12029 void bnx2x__init_func_obj(struct bnx2x
*bp
)
12031 /* Prepare DMAE related driver resources */
12032 bnx2x_setup_dmae(bp
);
12034 bnx2x_init_func_obj(bp
, &bp
->func_obj
,
12035 bnx2x_sp(bp
, func_rdata
),
12036 bnx2x_sp_mapping(bp
, func_rdata
),
12037 bnx2x_sp(bp
, func_afex_rdata
),
12038 bnx2x_sp_mapping(bp
, func_afex_rdata
),
12039 &bnx2x_func_sp_drv
);
12042 /* must be called after sriov-enable */
12043 static int bnx2x_set_qm_cid_count(struct bnx2x
*bp
)
12045 int cid_count
= BNX2X_L2_MAX_CID(bp
);
12047 if (CNIC_SUPPORT(bp
))
12048 cid_count
+= CNIC_CID_MAX
;
12049 return roundup(cid_count
, QM_CID_ROUND
);
12053 * bnx2x_get_num_none_def_sbs - return the number of none default SBs
12058 static int bnx2x_get_num_non_def_sbs(struct pci_dev
*pdev
,
12064 pos
= pci_find_capability(pdev
, PCI_CAP_ID_MSIX
);
12067 * If MSI-X is not supported - return number of SBs needed to support
12068 * one fast path queue: one FP queue + SB for CNIC
12071 return 1 + cnic_cnt
;
12074 * The value in the PCI configuration space is the index of the last
12075 * entry, namely one less than the actual size of the table, which is
12076 * exactly what we want to return from this function: number of all SBs
12077 * without the default SB.
12079 pci_read_config_word(pdev
, pos
+ PCI_MSI_FLAGS
, &control
);
12080 return control
& PCI_MSIX_FLAGS_QSIZE
;
12083 struct cnic_eth_dev
*bnx2x_cnic_probe(struct net_device
*);
12085 static int bnx2x_init_one(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
12087 struct net_device
*dev
= NULL
;
12089 int pcie_width
, pcie_speed
;
12090 int rc
, max_non_def_sbs
;
12091 int rx_count
, tx_count
, rss_count
, doorbell_size
;
12094 * An estimated maximum supported CoS number according to the chip
12096 * We will try to roughly estimate the maximum number of CoSes this chip
12097 * may support in order to minimize the memory allocated for Tx
12098 * netdev_queue's. This number will be accurately calculated during the
12099 * initialization of bp->max_cos based on the chip versions AND chip
12100 * revision in the bnx2x_init_bp().
12102 u8 max_cos_est
= 0;
12104 switch (ent
->driver_data
) {
12108 max_cos_est
= BNX2X_MULTI_TX_COS_E1X
;
12113 max_cos_est
= BNX2X_MULTI_TX_COS_E2_E3A0
;
12121 case BCM57840_4_10
:
12122 case BCM57840_2_20
:
12127 max_cos_est
= BNX2X_MULTI_TX_COS_E3B0
;
12131 pr_err("Unknown board_type (%ld), aborting\n",
12137 max_non_def_sbs
= bnx2x_get_num_non_def_sbs(pdev
, cnic_cnt
);
12139 WARN_ON(!max_non_def_sbs
);
12141 /* Maximum number of RSS queues: one IGU SB goes to CNIC */
12142 rss_count
= max_non_def_sbs
- cnic_cnt
;
12144 /* Maximum number of netdev Rx queues: RSS + FCoE L2 */
12145 rx_count
= rss_count
+ cnic_cnt
;
12148 * Maximum number of netdev Tx queues:
12149 * Maximum TSS queues * Maximum supported number of CoS + FCoE L2
12151 tx_count
= rss_count
* max_cos_est
+ cnic_cnt
;
12153 /* dev zeroed in init_etherdev */
12154 dev
= alloc_etherdev_mqs(sizeof(*bp
), tx_count
, rx_count
);
12158 bp
= netdev_priv(dev
);
12160 bp
->igu_sb_cnt
= max_non_def_sbs
;
12161 bp
->msg_enable
= debug
;
12162 bp
->cnic_support
= cnic_cnt
;
12163 bp
->cnic_probe
= bnx2x_cnic_probe
;
12165 pci_set_drvdata(pdev
, dev
);
12167 rc
= bnx2x_init_dev(pdev
, dev
, ent
->driver_data
);
12173 BNX2X_DEV_INFO("Cnic support is %s\n", CNIC_SUPPORT(bp
) ? "on" : "off");
12174 BNX2X_DEV_INFO("max_non_def_sbs %d\n", max_non_def_sbs
);
12176 BNX2X_DEV_INFO("Allocated netdev with %d tx and %d rx queues\n",
12177 tx_count
, rx_count
);
12179 rc
= bnx2x_init_bp(bp
);
12181 goto init_one_exit
;
12184 * Map doorbels here as we need the real value of bp->max_cos which
12185 * is initialized in bnx2x_init_bp().
12187 doorbell_size
= BNX2X_L2_MAX_CID(bp
) * (1 << BNX2X_DB_SHIFT
);
12188 if (doorbell_size
> pci_resource_len(pdev
, 2)) {
12189 dev_err(&bp
->pdev
->dev
,
12190 "Cannot map doorbells, bar size too small, aborting\n");
12192 goto init_one_exit
;
12194 bp
->doorbells
= ioremap_nocache(pci_resource_start(pdev
, 2),
12196 if (!bp
->doorbells
) {
12197 dev_err(&bp
->pdev
->dev
,
12198 "Cannot map doorbell space, aborting\n");
12200 goto init_one_exit
;
12203 /* calc qm_cid_count */
12204 bp
->qm_cid_count
= bnx2x_set_qm_cid_count(bp
);
12206 /* disable FCOE L2 queue for E1x*/
12207 if (CHIP_IS_E1x(bp
))
12208 bp
->flags
|= NO_FCOE_FLAG
;
12210 /* disable FCOE for 57840 device, until FW supports it */
12211 switch (ent
->driver_data
) {
12213 case BCM57840_4_10
:
12214 case BCM57840_2_20
:
12217 bp
->flags
|= NO_FCOE_FLAG
;
12220 /* Set bp->num_queues for MSI-X mode*/
12221 bnx2x_set_num_queues(bp
);
12223 /* Configure interrupt mode: try to enable MSI-X/MSI if
12226 bnx2x_set_int_mode(bp
);
12228 rc
= register_netdev(dev
);
12230 dev_err(&pdev
->dev
, "Cannot register net device\n");
12231 goto init_one_exit
;
12235 if (!NO_FCOE(bp
)) {
12236 /* Add storage MAC address */
12238 dev_addr_add(bp
->dev
, bp
->fip_mac
, NETDEV_HW_ADDR_T_SAN
);
12242 bnx2x_get_pcie_width_speed(bp
, &pcie_width
, &pcie_speed
);
12245 "%s (%c%d) PCI-E x%d %s found at mem %lx, IRQ %d, node addr %pM\n",
12246 board_info
[ent
->driver_data
].name
,
12247 (CHIP_REV(bp
) >> 12) + 'A', (CHIP_METAL(bp
) >> 4),
12249 ((!CHIP_IS_E2(bp
) && pcie_speed
== 2) ||
12250 (CHIP_IS_E2(bp
) && pcie_speed
== 1)) ?
12251 "5GHz (Gen2)" : "2.5GHz",
12252 dev
->base_addr
, bp
->pdev
->irq
, dev
->dev_addr
);
12258 iounmap(bp
->regview
);
12261 iounmap(bp
->doorbells
);
12265 if (atomic_read(&pdev
->enable_cnt
) == 1)
12266 pci_release_regions(pdev
);
12268 pci_disable_device(pdev
);
12269 pci_set_drvdata(pdev
, NULL
);
12274 static void bnx2x_remove_one(struct pci_dev
*pdev
)
12276 struct net_device
*dev
= pci_get_drvdata(pdev
);
12280 dev_err(&pdev
->dev
, "BAD net device from bnx2x_init_one\n");
12283 bp
= netdev_priv(dev
);
12285 /* Delete storage MAC address */
12286 if (!NO_FCOE(bp
)) {
12288 dev_addr_del(bp
->dev
, bp
->fip_mac
, NETDEV_HW_ADDR_T_SAN
);
12293 /* Delete app tlvs from dcbnl */
12294 bnx2x_dcbnl_update_applist(bp
, true);
12297 unregister_netdev(dev
);
12299 /* Power on: we can't let PCI layer write to us while we are in D3 */
12300 bnx2x_set_power_state(bp
, PCI_D0
);
12302 /* Disable MSI/MSI-X */
12303 bnx2x_disable_msi(bp
);
12306 bnx2x_set_power_state(bp
, PCI_D3hot
);
12308 /* Make sure RESET task is not scheduled before continuing */
12309 cancel_delayed_work_sync(&bp
->sp_rtnl_task
);
12312 iounmap(bp
->regview
);
12315 iounmap(bp
->doorbells
);
12317 bnx2x_release_firmware(bp
);
12319 bnx2x_free_mem_bp(bp
);
12323 if (atomic_read(&pdev
->enable_cnt
) == 1)
12324 pci_release_regions(pdev
);
12326 pci_disable_device(pdev
);
12327 pci_set_drvdata(pdev
, NULL
);
12330 static int bnx2x_eeh_nic_unload(struct bnx2x
*bp
)
12334 bp
->state
= BNX2X_STATE_ERROR
;
12336 bp
->rx_mode
= BNX2X_RX_MODE_NONE
;
12338 if (CNIC_LOADED(bp
))
12339 bnx2x_cnic_notify(bp
, CNIC_CTL_STOP_CMD
);
12342 bnx2x_tx_disable(bp
);
12344 bnx2x_netif_stop(bp
, 0);
12345 /* Delete all NAPI objects */
12346 bnx2x_del_all_napi(bp
);
12347 if (CNIC_LOADED(bp
))
12348 bnx2x_del_all_napi_cnic(bp
);
12350 del_timer_sync(&bp
->timer
);
12352 bnx2x_stats_handle(bp
, STATS_EVENT_STOP
);
12355 bnx2x_free_irq(bp
);
12357 /* Free SKBs, SGEs, TPA pool and driver internals */
12358 bnx2x_free_skbs(bp
);
12360 for_each_rx_queue(bp
, i
)
12361 bnx2x_free_rx_sge_range(bp
, bp
->fp
+ i
, NUM_RX_SGE
);
12363 bnx2x_free_mem(bp
);
12365 bp
->state
= BNX2X_STATE_CLOSED
;
12367 netif_carrier_off(bp
->dev
);
12372 static void bnx2x_eeh_recover(struct bnx2x
*bp
)
12376 mutex_init(&bp
->port
.phy_mutex
);
12379 val
= SHMEM_RD(bp
, validity_map
[BP_PORT(bp
)]);
12380 if ((val
& (SHR_MEM_VALIDITY_DEV_INFO
| SHR_MEM_VALIDITY_MB
))
12381 != (SHR_MEM_VALIDITY_DEV_INFO
| SHR_MEM_VALIDITY_MB
))
12382 BNX2X_ERR("BAD MCP validity signature\n");
12386 * bnx2x_io_error_detected - called when PCI error is detected
12387 * @pdev: Pointer to PCI device
12388 * @state: The current pci connection state
12390 * This function is called after a PCI bus error affecting
12391 * this device has been detected.
12393 static pci_ers_result_t
bnx2x_io_error_detected(struct pci_dev
*pdev
,
12394 pci_channel_state_t state
)
12396 struct net_device
*dev
= pci_get_drvdata(pdev
);
12397 struct bnx2x
*bp
= netdev_priv(dev
);
12401 netif_device_detach(dev
);
12403 if (state
== pci_channel_io_perm_failure
) {
12405 return PCI_ERS_RESULT_DISCONNECT
;
12408 if (netif_running(dev
))
12409 bnx2x_eeh_nic_unload(bp
);
12411 pci_disable_device(pdev
);
12415 /* Request a slot reset */
12416 return PCI_ERS_RESULT_NEED_RESET
;
12420 * bnx2x_io_slot_reset - called after the PCI bus has been reset
12421 * @pdev: Pointer to PCI device
12423 * Restart the card from scratch, as if from a cold-boot.
12425 static pci_ers_result_t
bnx2x_io_slot_reset(struct pci_dev
*pdev
)
12427 struct net_device
*dev
= pci_get_drvdata(pdev
);
12428 struct bnx2x
*bp
= netdev_priv(dev
);
12432 if (pci_enable_device(pdev
)) {
12433 dev_err(&pdev
->dev
,
12434 "Cannot re-enable PCI device after reset\n");
12436 return PCI_ERS_RESULT_DISCONNECT
;
12439 pci_set_master(pdev
);
12440 pci_restore_state(pdev
);
12442 if (netif_running(dev
))
12443 bnx2x_set_power_state(bp
, PCI_D0
);
12447 return PCI_ERS_RESULT_RECOVERED
;
12451 * bnx2x_io_resume - called when traffic can start flowing again
12452 * @pdev: Pointer to PCI device
12454 * This callback is called when the error recovery driver tells us that
12455 * its OK to resume normal operation.
12457 static void bnx2x_io_resume(struct pci_dev
*pdev
)
12459 struct net_device
*dev
= pci_get_drvdata(pdev
);
12460 struct bnx2x
*bp
= netdev_priv(dev
);
12462 if (bp
->recovery_state
!= BNX2X_RECOVERY_DONE
) {
12463 netdev_err(bp
->dev
, "Handling parity error recovery. Try again later\n");
12469 bnx2x_eeh_recover(bp
);
12471 if (netif_running(dev
))
12472 bnx2x_nic_load(bp
, LOAD_NORMAL
);
12474 netif_device_attach(dev
);
12479 static const struct pci_error_handlers bnx2x_err_handler
= {
12480 .error_detected
= bnx2x_io_error_detected
,
12481 .slot_reset
= bnx2x_io_slot_reset
,
12482 .resume
= bnx2x_io_resume
,
12485 static struct pci_driver bnx2x_pci_driver
= {
12486 .name
= DRV_MODULE_NAME
,
12487 .id_table
= bnx2x_pci_tbl
,
12488 .probe
= bnx2x_init_one
,
12489 .remove
= bnx2x_remove_one
,
12490 .suspend
= bnx2x_suspend
,
12491 .resume
= bnx2x_resume
,
12492 .err_handler
= &bnx2x_err_handler
,
12495 static int __init
bnx2x_init(void)
12499 pr_info("%s", version
);
12501 bnx2x_wq
= create_singlethread_workqueue("bnx2x");
12502 if (bnx2x_wq
== NULL
) {
12503 pr_err("Cannot create workqueue\n");
12507 ret
= pci_register_driver(&bnx2x_pci_driver
);
12509 pr_err("Cannot register driver\n");
12510 destroy_workqueue(bnx2x_wq
);
12515 static void __exit
bnx2x_cleanup(void)
12517 struct list_head
*pos
, *q
;
12518 pci_unregister_driver(&bnx2x_pci_driver
);
12520 destroy_workqueue(bnx2x_wq
);
12522 /* Free globablly allocated resources */
12523 list_for_each_safe(pos
, q
, &bnx2x_prev_list
) {
12524 struct bnx2x_prev_path_list
*tmp
=
12525 list_entry(pos
, struct bnx2x_prev_path_list
, list
);
12531 void bnx2x_notify_link_changed(struct bnx2x
*bp
)
12533 REG_WR(bp
, MISC_REG_AEU_GENERAL_ATTN_12
+ BP_FUNC(bp
)*sizeof(u32
), 1);
12536 module_init(bnx2x_init
);
12537 module_exit(bnx2x_cleanup
);
12540 * bnx2x_set_iscsi_eth_mac_addr - set iSCSI MAC(s).
12542 * @bp: driver handle
12543 * @set: set or clear the CAM entry
12545 * This function will wait until the ramdord completion returns.
12546 * Return 0 if success, -ENODEV if ramrod doesn't return.
12548 static int bnx2x_set_iscsi_eth_mac_addr(struct bnx2x
*bp
)
12550 unsigned long ramrod_flags
= 0;
12552 __set_bit(RAMROD_COMP_WAIT
, &ramrod_flags
);
12553 return bnx2x_set_mac_one(bp
, bp
->cnic_eth_dev
.iscsi_mac
,
12554 &bp
->iscsi_l2_mac_obj
, true,
12555 BNX2X_ISCSI_ETH_MAC
, &ramrod_flags
);
12558 /* count denotes the number of new completions we have seen */
12559 static void bnx2x_cnic_sp_post(struct bnx2x
*bp
, int count
)
12561 struct eth_spe
*spe
;
12562 int cxt_index
, cxt_offset
;
12564 #ifdef BNX2X_STOP_ON_ERROR
12565 if (unlikely(bp
->panic
))
12569 spin_lock_bh(&bp
->spq_lock
);
12570 BUG_ON(bp
->cnic_spq_pending
< count
);
12571 bp
->cnic_spq_pending
-= count
;
12574 for (; bp
->cnic_kwq_pending
; bp
->cnic_kwq_pending
--) {
12575 u16 type
= (le16_to_cpu(bp
->cnic_kwq_cons
->hdr
.type
)
12576 & SPE_HDR_CONN_TYPE
) >>
12577 SPE_HDR_CONN_TYPE_SHIFT
;
12578 u8 cmd
= (le32_to_cpu(bp
->cnic_kwq_cons
->hdr
.conn_and_cmd_data
)
12579 >> SPE_HDR_CMD_ID_SHIFT
) & 0xff;
12581 /* Set validation for iSCSI L2 client before sending SETUP
12584 if (type
== ETH_CONNECTION_TYPE
) {
12585 if (cmd
== RAMROD_CMD_ID_ETH_CLIENT_SETUP
) {
12586 cxt_index
= BNX2X_ISCSI_ETH_CID(bp
) /
12588 cxt_offset
= BNX2X_ISCSI_ETH_CID(bp
) -
12589 (cxt_index
* ILT_PAGE_CIDS
);
12590 bnx2x_set_ctx_validation(bp
,
12591 &bp
->context
[cxt_index
].
12592 vcxt
[cxt_offset
].eth
,
12593 BNX2X_ISCSI_ETH_CID(bp
));
12598 * There may be not more than 8 L2, not more than 8 L5 SPEs
12599 * and in the air. We also check that number of outstanding
12600 * COMMON ramrods is not more than the EQ and SPQ can
12603 if (type
== ETH_CONNECTION_TYPE
) {
12604 if (!atomic_read(&bp
->cq_spq_left
))
12607 atomic_dec(&bp
->cq_spq_left
);
12608 } else if (type
== NONE_CONNECTION_TYPE
) {
12609 if (!atomic_read(&bp
->eq_spq_left
))
12612 atomic_dec(&bp
->eq_spq_left
);
12613 } else if ((type
== ISCSI_CONNECTION_TYPE
) ||
12614 (type
== FCOE_CONNECTION_TYPE
)) {
12615 if (bp
->cnic_spq_pending
>=
12616 bp
->cnic_eth_dev
.max_kwqe_pending
)
12619 bp
->cnic_spq_pending
++;
12621 BNX2X_ERR("Unknown SPE type: %d\n", type
);
12626 spe
= bnx2x_sp_get_next(bp
);
12627 *spe
= *bp
->cnic_kwq_cons
;
12629 DP(BNX2X_MSG_SP
, "pending on SPQ %d, on KWQ %d count %d\n",
12630 bp
->cnic_spq_pending
, bp
->cnic_kwq_pending
, count
);
12632 if (bp
->cnic_kwq_cons
== bp
->cnic_kwq_last
)
12633 bp
->cnic_kwq_cons
= bp
->cnic_kwq
;
12635 bp
->cnic_kwq_cons
++;
12637 bnx2x_sp_prod_update(bp
);
12638 spin_unlock_bh(&bp
->spq_lock
);
12641 static int bnx2x_cnic_sp_queue(struct net_device
*dev
,
12642 struct kwqe_16
*kwqes
[], u32 count
)
12644 struct bnx2x
*bp
= netdev_priv(dev
);
12647 #ifdef BNX2X_STOP_ON_ERROR
12648 if (unlikely(bp
->panic
)) {
12649 BNX2X_ERR("Can't post to SP queue while panic\n");
12654 if ((bp
->recovery_state
!= BNX2X_RECOVERY_DONE
) &&
12655 (bp
->recovery_state
!= BNX2X_RECOVERY_NIC_LOADING
)) {
12656 BNX2X_ERR("Handling parity error recovery. Try again later\n");
12660 spin_lock_bh(&bp
->spq_lock
);
12662 for (i
= 0; i
< count
; i
++) {
12663 struct eth_spe
*spe
= (struct eth_spe
*)kwqes
[i
];
12665 if (bp
->cnic_kwq_pending
== MAX_SP_DESC_CNT
)
12668 *bp
->cnic_kwq_prod
= *spe
;
12670 bp
->cnic_kwq_pending
++;
12672 DP(BNX2X_MSG_SP
, "L5 SPQE %x %x %x:%x pos %d\n",
12673 spe
->hdr
.conn_and_cmd_data
, spe
->hdr
.type
,
12674 spe
->data
.update_data_addr
.hi
,
12675 spe
->data
.update_data_addr
.lo
,
12676 bp
->cnic_kwq_pending
);
12678 if (bp
->cnic_kwq_prod
== bp
->cnic_kwq_last
)
12679 bp
->cnic_kwq_prod
= bp
->cnic_kwq
;
12681 bp
->cnic_kwq_prod
++;
12684 spin_unlock_bh(&bp
->spq_lock
);
12686 if (bp
->cnic_spq_pending
< bp
->cnic_eth_dev
.max_kwqe_pending
)
12687 bnx2x_cnic_sp_post(bp
, 0);
12692 static int bnx2x_cnic_ctl_send(struct bnx2x
*bp
, struct cnic_ctl_info
*ctl
)
12694 struct cnic_ops
*c_ops
;
12697 mutex_lock(&bp
->cnic_mutex
);
12698 c_ops
= rcu_dereference_protected(bp
->cnic_ops
,
12699 lockdep_is_held(&bp
->cnic_mutex
));
12701 rc
= c_ops
->cnic_ctl(bp
->cnic_data
, ctl
);
12702 mutex_unlock(&bp
->cnic_mutex
);
12707 static int bnx2x_cnic_ctl_send_bh(struct bnx2x
*bp
, struct cnic_ctl_info
*ctl
)
12709 struct cnic_ops
*c_ops
;
12713 c_ops
= rcu_dereference(bp
->cnic_ops
);
12715 rc
= c_ops
->cnic_ctl(bp
->cnic_data
, ctl
);
12722 * for commands that have no data
12724 int bnx2x_cnic_notify(struct bnx2x
*bp
, int cmd
)
12726 struct cnic_ctl_info ctl
= {0};
12730 return bnx2x_cnic_ctl_send(bp
, &ctl
);
12733 static void bnx2x_cnic_cfc_comp(struct bnx2x
*bp
, int cid
, u8 err
)
12735 struct cnic_ctl_info ctl
= {0};
12737 /* first we tell CNIC and only then we count this as a completion */
12738 ctl
.cmd
= CNIC_CTL_COMPLETION_CMD
;
12739 ctl
.data
.comp
.cid
= cid
;
12740 ctl
.data
.comp
.error
= err
;
12742 bnx2x_cnic_ctl_send_bh(bp
, &ctl
);
12743 bnx2x_cnic_sp_post(bp
, 0);
12747 /* Called with netif_addr_lock_bh() taken.
12748 * Sets an rx_mode config for an iSCSI ETH client.
12750 * Completion should be checked outside.
12752 static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x
*bp
, bool start
)
12754 unsigned long accept_flags
= 0, ramrod_flags
= 0;
12755 u8 cl_id
= bnx2x_cnic_eth_cl_id(bp
, BNX2X_ISCSI_ETH_CL_ID_IDX
);
12756 int sched_state
= BNX2X_FILTER_ISCSI_ETH_STOP_SCHED
;
12759 /* Start accepting on iSCSI L2 ring. Accept all multicasts
12760 * because it's the only way for UIO Queue to accept
12761 * multicasts (in non-promiscuous mode only one Queue per
12762 * function will receive multicast packets (leading in our
12765 __set_bit(BNX2X_ACCEPT_UNICAST
, &accept_flags
);
12766 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST
, &accept_flags
);
12767 __set_bit(BNX2X_ACCEPT_BROADCAST
, &accept_flags
);
12768 __set_bit(BNX2X_ACCEPT_ANY_VLAN
, &accept_flags
);
12770 /* Clear STOP_PENDING bit if START is requested */
12771 clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED
, &bp
->sp_state
);
12773 sched_state
= BNX2X_FILTER_ISCSI_ETH_START_SCHED
;
12775 /* Clear START_PENDING bit if STOP is requested */
12776 clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED
, &bp
->sp_state
);
12778 if (test_bit(BNX2X_FILTER_RX_MODE_PENDING
, &bp
->sp_state
))
12779 set_bit(sched_state
, &bp
->sp_state
);
12781 __set_bit(RAMROD_RX
, &ramrod_flags
);
12782 bnx2x_set_q_rx_mode(bp
, cl_id
, 0, accept_flags
, 0,
12788 static int bnx2x_drv_ctl(struct net_device
*dev
, struct drv_ctl_info
*ctl
)
12790 struct bnx2x
*bp
= netdev_priv(dev
);
12793 switch (ctl
->cmd
) {
12794 case DRV_CTL_CTXTBL_WR_CMD
: {
12795 u32 index
= ctl
->data
.io
.offset
;
12796 dma_addr_t addr
= ctl
->data
.io
.dma_addr
;
12798 bnx2x_ilt_wr(bp
, index
, addr
);
12802 case DRV_CTL_RET_L5_SPQ_CREDIT_CMD
: {
12803 int count
= ctl
->data
.credit
.credit_count
;
12805 bnx2x_cnic_sp_post(bp
, count
);
12809 /* rtnl_lock is held. */
12810 case DRV_CTL_START_L2_CMD
: {
12811 struct cnic_eth_dev
*cp
= &bp
->cnic_eth_dev
;
12812 unsigned long sp_bits
= 0;
12814 /* Configure the iSCSI classification object */
12815 bnx2x_init_mac_obj(bp
, &bp
->iscsi_l2_mac_obj
,
12816 cp
->iscsi_l2_client_id
,
12817 cp
->iscsi_l2_cid
, BP_FUNC(bp
),
12818 bnx2x_sp(bp
, mac_rdata
),
12819 bnx2x_sp_mapping(bp
, mac_rdata
),
12820 BNX2X_FILTER_MAC_PENDING
,
12821 &bp
->sp_state
, BNX2X_OBJ_TYPE_RX
,
12824 /* Set iSCSI MAC address */
12825 rc
= bnx2x_set_iscsi_eth_mac_addr(bp
);
12832 /* Start accepting on iSCSI L2 ring */
12834 netif_addr_lock_bh(dev
);
12835 bnx2x_set_iscsi_eth_rx_mode(bp
, true);
12836 netif_addr_unlock_bh(dev
);
12838 /* bits to wait on */
12839 __set_bit(BNX2X_FILTER_RX_MODE_PENDING
, &sp_bits
);
12840 __set_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED
, &sp_bits
);
12842 if (!bnx2x_wait_sp_comp(bp
, sp_bits
))
12843 BNX2X_ERR("rx_mode completion timed out!\n");
12848 /* rtnl_lock is held. */
12849 case DRV_CTL_STOP_L2_CMD
: {
12850 unsigned long sp_bits
= 0;
12852 /* Stop accepting on iSCSI L2 ring */
12853 netif_addr_lock_bh(dev
);
12854 bnx2x_set_iscsi_eth_rx_mode(bp
, false);
12855 netif_addr_unlock_bh(dev
);
12857 /* bits to wait on */
12858 __set_bit(BNX2X_FILTER_RX_MODE_PENDING
, &sp_bits
);
12859 __set_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED
, &sp_bits
);
12861 if (!bnx2x_wait_sp_comp(bp
, sp_bits
))
12862 BNX2X_ERR("rx_mode completion timed out!\n");
12867 /* Unset iSCSI L2 MAC */
12868 rc
= bnx2x_del_all_macs(bp
, &bp
->iscsi_l2_mac_obj
,
12869 BNX2X_ISCSI_ETH_MAC
, true);
12872 case DRV_CTL_RET_L2_SPQ_CREDIT_CMD
: {
12873 int count
= ctl
->data
.credit
.credit_count
;
12875 smp_mb__before_atomic_inc();
12876 atomic_add(count
, &bp
->cq_spq_left
);
12877 smp_mb__after_atomic_inc();
12880 case DRV_CTL_ULP_REGISTER_CMD
: {
12881 int ulp_type
= ctl
->data
.register_data
.ulp_type
;
12883 if (CHIP_IS_E3(bp
)) {
12884 int idx
= BP_FW_MB_IDX(bp
);
12885 u32 cap
= SHMEM2_RD(bp
, drv_capabilities_flag
[idx
]);
12886 int path
= BP_PATH(bp
);
12887 int port
= BP_PORT(bp
);
12889 u32 scratch_offset
;
12892 /* first write capability to shmem2 */
12893 if (ulp_type
== CNIC_ULP_ISCSI
)
12894 cap
|= DRV_FLAGS_CAPABILITIES_LOADED_ISCSI
;
12895 else if (ulp_type
== CNIC_ULP_FCOE
)
12896 cap
|= DRV_FLAGS_CAPABILITIES_LOADED_FCOE
;
12897 SHMEM2_WR(bp
, drv_capabilities_flag
[idx
], cap
);
12899 if ((ulp_type
!= CNIC_ULP_FCOE
) ||
12900 (!SHMEM2_HAS(bp
, ncsi_oem_data_addr
)) ||
12901 (!(bp
->flags
& BC_SUPPORTS_FCOE_FEATURES
)))
12904 /* if reached here - should write fcoe capabilities */
12905 scratch_offset
= SHMEM2_RD(bp
, ncsi_oem_data_addr
);
12906 if (!scratch_offset
)
12908 scratch_offset
+= offsetof(struct glob_ncsi_oem_data
,
12909 fcoe_features
[path
][port
]);
12910 host_addr
= (u32
*) &(ctl
->data
.register_data
.
12912 for (i
= 0; i
< sizeof(struct fcoe_capabilities
);
12914 REG_WR(bp
, scratch_offset
+ i
,
12915 *(host_addr
+ i
/4));
12920 case DRV_CTL_ULP_UNREGISTER_CMD
: {
12921 int ulp_type
= ctl
->data
.ulp_type
;
12923 if (CHIP_IS_E3(bp
)) {
12924 int idx
= BP_FW_MB_IDX(bp
);
12927 cap
= SHMEM2_RD(bp
, drv_capabilities_flag
[idx
]);
12928 if (ulp_type
== CNIC_ULP_ISCSI
)
12929 cap
&= ~DRV_FLAGS_CAPABILITIES_LOADED_ISCSI
;
12930 else if (ulp_type
== CNIC_ULP_FCOE
)
12931 cap
&= ~DRV_FLAGS_CAPABILITIES_LOADED_FCOE
;
12932 SHMEM2_WR(bp
, drv_capabilities_flag
[idx
], cap
);
12938 BNX2X_ERR("unknown command %x\n", ctl
->cmd
);
12945 void bnx2x_setup_cnic_irq_info(struct bnx2x
*bp
)
12947 struct cnic_eth_dev
*cp
= &bp
->cnic_eth_dev
;
12949 if (bp
->flags
& USING_MSIX_FLAG
) {
12950 cp
->drv_state
|= CNIC_DRV_STATE_USING_MSIX
;
12951 cp
->irq_arr
[0].irq_flags
|= CNIC_IRQ_FL_MSIX
;
12952 cp
->irq_arr
[0].vector
= bp
->msix_table
[1].vector
;
12954 cp
->drv_state
&= ~CNIC_DRV_STATE_USING_MSIX
;
12955 cp
->irq_arr
[0].irq_flags
&= ~CNIC_IRQ_FL_MSIX
;
12957 if (!CHIP_IS_E1x(bp
))
12958 cp
->irq_arr
[0].status_blk
= (void *)bp
->cnic_sb
.e2_sb
;
12960 cp
->irq_arr
[0].status_blk
= (void *)bp
->cnic_sb
.e1x_sb
;
12962 cp
->irq_arr
[0].status_blk_num
= bnx2x_cnic_fw_sb_id(bp
);
12963 cp
->irq_arr
[0].status_blk_num2
= bnx2x_cnic_igu_sb_id(bp
);
12964 cp
->irq_arr
[1].status_blk
= bp
->def_status_blk
;
12965 cp
->irq_arr
[1].status_blk_num
= DEF_SB_ID
;
12966 cp
->irq_arr
[1].status_blk_num2
= DEF_SB_IGU_ID
;
12971 void bnx2x_setup_cnic_info(struct bnx2x
*bp
)
12973 struct cnic_eth_dev
*cp
= &bp
->cnic_eth_dev
;
12976 cp
->ctx_tbl_offset
= FUNC_ILT_BASE(BP_FUNC(bp
)) +
12977 bnx2x_cid_ilt_lines(bp
);
12978 cp
->starting_cid
= bnx2x_cid_ilt_lines(bp
) * ILT_PAGE_CIDS
;
12979 cp
->fcoe_init_cid
= BNX2X_FCOE_ETH_CID(bp
);
12980 cp
->iscsi_l2_cid
= BNX2X_ISCSI_ETH_CID(bp
);
12982 if (NO_ISCSI_OOO(bp
))
12983 cp
->drv_state
|= CNIC_DRV_STATE_NO_ISCSI_OOO
;
12986 static int bnx2x_register_cnic(struct net_device
*dev
, struct cnic_ops
*ops
,
12989 struct bnx2x
*bp
= netdev_priv(dev
);
12990 struct cnic_eth_dev
*cp
= &bp
->cnic_eth_dev
;
12993 DP(NETIF_MSG_IFUP
, "Register_cnic called\n");
12996 BNX2X_ERR("NULL ops received\n");
13000 if (!CNIC_SUPPORT(bp
)) {
13001 BNX2X_ERR("Can't register CNIC when not supported\n");
13002 return -EOPNOTSUPP
;
13005 if (!CNIC_LOADED(bp
)) {
13006 rc
= bnx2x_load_cnic(bp
);
13008 BNX2X_ERR("CNIC-related load failed\n");
13014 bp
->cnic_enabled
= true;
13016 bp
->cnic_kwq
= kzalloc(PAGE_SIZE
, GFP_KERNEL
);
13020 bp
->cnic_kwq_cons
= bp
->cnic_kwq
;
13021 bp
->cnic_kwq_prod
= bp
->cnic_kwq
;
13022 bp
->cnic_kwq_last
= bp
->cnic_kwq
+ MAX_SP_DESC_CNT
;
13024 bp
->cnic_spq_pending
= 0;
13025 bp
->cnic_kwq_pending
= 0;
13027 bp
->cnic_data
= data
;
13030 cp
->drv_state
|= CNIC_DRV_STATE_REGD
;
13031 cp
->iro_arr
= bp
->iro_arr
;
13033 bnx2x_setup_cnic_irq_info(bp
);
13035 rcu_assign_pointer(bp
->cnic_ops
, ops
);
13040 static int bnx2x_unregister_cnic(struct net_device
*dev
)
13042 struct bnx2x
*bp
= netdev_priv(dev
);
13043 struct cnic_eth_dev
*cp
= &bp
->cnic_eth_dev
;
13045 mutex_lock(&bp
->cnic_mutex
);
13047 RCU_INIT_POINTER(bp
->cnic_ops
, NULL
);
13048 mutex_unlock(&bp
->cnic_mutex
);
13050 kfree(bp
->cnic_kwq
);
13051 bp
->cnic_kwq
= NULL
;
13056 struct cnic_eth_dev
*bnx2x_cnic_probe(struct net_device
*dev
)
13058 struct bnx2x
*bp
= netdev_priv(dev
);
13059 struct cnic_eth_dev
*cp
= &bp
->cnic_eth_dev
;
13061 /* If both iSCSI and FCoE are disabled - return NULL in
13062 * order to indicate CNIC that it should not try to work
13063 * with this device.
13065 if (NO_ISCSI(bp
) && NO_FCOE(bp
))
13068 cp
->drv_owner
= THIS_MODULE
;
13069 cp
->chip_id
= CHIP_ID(bp
);
13070 cp
->pdev
= bp
->pdev
;
13071 cp
->io_base
= bp
->regview
;
13072 cp
->io_base2
= bp
->doorbells
;
13073 cp
->max_kwqe_pending
= 8;
13074 cp
->ctx_blk_size
= CDU_ILT_PAGE_SZ
;
13075 cp
->ctx_tbl_offset
= FUNC_ILT_BASE(BP_FUNC(bp
)) +
13076 bnx2x_cid_ilt_lines(bp
);
13077 cp
->ctx_tbl_len
= CNIC_ILT_LINES
;
13078 cp
->starting_cid
= bnx2x_cid_ilt_lines(bp
) * ILT_PAGE_CIDS
;
13079 cp
->drv_submit_kwqes_16
= bnx2x_cnic_sp_queue
;
13080 cp
->drv_ctl
= bnx2x_drv_ctl
;
13081 cp
->drv_register_cnic
= bnx2x_register_cnic
;
13082 cp
->drv_unregister_cnic
= bnx2x_unregister_cnic
;
13083 cp
->fcoe_init_cid
= BNX2X_FCOE_ETH_CID(bp
);
13084 cp
->iscsi_l2_client_id
=
13085 bnx2x_cnic_eth_cl_id(bp
, BNX2X_ISCSI_ETH_CL_ID_IDX
);
13086 cp
->iscsi_l2_cid
= BNX2X_ISCSI_ETH_CID(bp
);
13088 if (NO_ISCSI_OOO(bp
))
13089 cp
->drv_state
|= CNIC_DRV_STATE_NO_ISCSI_OOO
;
13092 cp
->drv_state
|= CNIC_DRV_STATE_NO_ISCSI
;
13095 cp
->drv_state
|= CNIC_DRV_STATE_NO_FCOE
;
13098 "page_size %d, tbl_offset %d, tbl_lines %d, starting cid %d\n",
13100 cp
->ctx_tbl_offset
,