1 /* bnx2x_main.c: Broadcom Everest network driver.
3 * Copyright (c) 2007-2013 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: Ariel Elior <ariel.elior@qlogic.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/aer.h>
31 #include <linux/init.h>
32 #include <linux/netdevice.h>
33 #include <linux/etherdevice.h>
34 #include <linux/skbuff.h>
35 #include <linux/dma-mapping.h>
36 #include <linux/bitops.h>
37 #include <linux/irq.h>
38 #include <linux/delay.h>
39 #include <asm/byteorder.h>
40 #include <linux/time.h>
41 #include <linux/ethtool.h>
42 #include <linux/mii.h>
43 #include <linux/if_vlan.h>
47 #include <net/checksum.h>
48 #include <net/ip6_checksum.h>
49 #include <linux/workqueue.h>
50 #include <linux/crc32.h>
51 #include <linux/crc32c.h>
52 #include <linux/prefetch.h>
53 #include <linux/zlib.h>
55 #include <linux/semaphore.h>
56 #include <linux/stringify.h>
57 #include <linux/vmalloc.h>
60 #include "bnx2x_init.h"
61 #include "bnx2x_init_ops.h"
62 #include "bnx2x_cmn.h"
63 #include "bnx2x_vfpf.h"
64 #include "bnx2x_dcb.h"
66 #include <linux/firmware.h>
67 #include "bnx2x_fw_file_hdr.h"
69 #define FW_FILE_VERSION \
70 __stringify(BCM_5710_FW_MAJOR_VERSION) "." \
71 __stringify(BCM_5710_FW_MINOR_VERSION) "." \
72 __stringify(BCM_5710_FW_REVISION_VERSION) "." \
73 __stringify(BCM_5710_FW_ENGINEERING_VERSION)
74 #define FW_FILE_NAME_E1 "bnx2x/bnx2x-e1-" FW_FILE_VERSION ".fw"
75 #define FW_FILE_NAME_E1H "bnx2x/bnx2x-e1h-" FW_FILE_VERSION ".fw"
76 #define FW_FILE_NAME_E2 "bnx2x/bnx2x-e2-" FW_FILE_VERSION ".fw"
78 /* Time in jiffies before concluding the transmitter is hung */
79 #define TX_TIMEOUT (5*HZ)
81 static char version[] =
82 "Broadcom NetXtreme II 5771x/578xx 10/20-Gigabit Ethernet Driver "
83 DRV_MODULE_NAME " " DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
85 MODULE_AUTHOR("Eliezer Tamir");
86 MODULE_DESCRIPTION("Broadcom NetXtreme II "
87 "BCM57710/57711/57711E/"
88 "57712/57712_MF/57800/57800_MF/57810/57810_MF/"
89 "57840/57840_MF Driver");
90 MODULE_LICENSE("GPL");
91 MODULE_VERSION(DRV_MODULE_VERSION);
92 MODULE_FIRMWARE(FW_FILE_NAME_E1);
93 MODULE_FIRMWARE(FW_FILE_NAME_E1H);
94 MODULE_FIRMWARE(FW_FILE_NAME_E2);
97 module_param_named(num_queues, bnx2x_num_queues, int, S_IRUGO);
98 MODULE_PARM_DESC(num_queues,
99 " Set number of queues (default is as a number of CPUs)");
101 static int disable_tpa;
102 module_param(disable_tpa, int, S_IRUGO);
103 MODULE_PARM_DESC(disable_tpa, " Disable the TPA (LRO) feature");
106 module_param(int_mode, int, S_IRUGO);
107 MODULE_PARM_DESC(int_mode, " Force interrupt mode other than MSI-X "
110 static int dropless_fc;
111 module_param(dropless_fc, int, S_IRUGO);
112 MODULE_PARM_DESC(dropless_fc, " Pause on exhausted host ring");
114 static int mrrs = -1;
115 module_param(mrrs, int, S_IRUGO);
116 MODULE_PARM_DESC(mrrs, " Force Max Read Req Size (0..3) (for debug)");
119 module_param(debug, int, S_IRUGO);
120 MODULE_PARM_DESC(debug, " Default debug msglevel");
122 static struct workqueue_struct *bnx2x_wq;
123 struct workqueue_struct *bnx2x_iov_wq;
125 struct bnx2x_mac_vals {
136 enum bnx2x_board_type {
160 /* indexed by board_type, above */
164 [BCM57710] = { "Broadcom NetXtreme II BCM57710 10 Gigabit PCIe [Everest]" },
165 [BCM57711] = { "Broadcom NetXtreme II BCM57711 10 Gigabit PCIe" },
166 [BCM57711E] = { "Broadcom NetXtreme II BCM57711E 10 Gigabit PCIe" },
167 [BCM57712] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet" },
168 [BCM57712_MF] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Multi Function" },
169 [BCM57712_VF] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Virtual Function" },
170 [BCM57800] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet" },
171 [BCM57800_MF] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Multi Function" },
172 [BCM57800_VF] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Virtual Function" },
173 [BCM57810] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet" },
174 [BCM57810_MF] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Multi Function" },
175 [BCM57810_VF] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Virtual Function" },
176 [BCM57840_4_10] = { "Broadcom NetXtreme II BCM57840 10 Gigabit Ethernet" },
177 [BCM57840_2_20] = { "Broadcom NetXtreme II BCM57840 20 Gigabit Ethernet" },
178 [BCM57840_MF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Multi Function" },
179 [BCM57840_VF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Virtual Function" },
180 [BCM57811] = { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet" },
181 [BCM57811_MF] = { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet Multi Function" },
182 [BCM57840_O] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet" },
183 [BCM57840_MFO] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Multi Function" },
184 [BCM57811_VF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Virtual Function" }
187 #ifndef PCI_DEVICE_ID_NX2_57710
188 #define PCI_DEVICE_ID_NX2_57710 CHIP_NUM_57710
190 #ifndef PCI_DEVICE_ID_NX2_57711
191 #define PCI_DEVICE_ID_NX2_57711 CHIP_NUM_57711
193 #ifndef PCI_DEVICE_ID_NX2_57711E
194 #define PCI_DEVICE_ID_NX2_57711E CHIP_NUM_57711E
196 #ifndef PCI_DEVICE_ID_NX2_57712
197 #define PCI_DEVICE_ID_NX2_57712 CHIP_NUM_57712
199 #ifndef PCI_DEVICE_ID_NX2_57712_MF
200 #define PCI_DEVICE_ID_NX2_57712_MF CHIP_NUM_57712_MF
202 #ifndef PCI_DEVICE_ID_NX2_57712_VF
203 #define PCI_DEVICE_ID_NX2_57712_VF CHIP_NUM_57712_VF
205 #ifndef PCI_DEVICE_ID_NX2_57800
206 #define PCI_DEVICE_ID_NX2_57800 CHIP_NUM_57800
208 #ifndef PCI_DEVICE_ID_NX2_57800_MF
209 #define PCI_DEVICE_ID_NX2_57800_MF CHIP_NUM_57800_MF
211 #ifndef PCI_DEVICE_ID_NX2_57800_VF
212 #define PCI_DEVICE_ID_NX2_57800_VF CHIP_NUM_57800_VF
214 #ifndef PCI_DEVICE_ID_NX2_57810
215 #define PCI_DEVICE_ID_NX2_57810 CHIP_NUM_57810
217 #ifndef PCI_DEVICE_ID_NX2_57810_MF
218 #define PCI_DEVICE_ID_NX2_57810_MF CHIP_NUM_57810_MF
220 #ifndef PCI_DEVICE_ID_NX2_57840_O
221 #define PCI_DEVICE_ID_NX2_57840_O CHIP_NUM_57840_OBSOLETE
223 #ifndef PCI_DEVICE_ID_NX2_57810_VF
224 #define PCI_DEVICE_ID_NX2_57810_VF CHIP_NUM_57810_VF
226 #ifndef PCI_DEVICE_ID_NX2_57840_4_10
227 #define PCI_DEVICE_ID_NX2_57840_4_10 CHIP_NUM_57840_4_10
229 #ifndef PCI_DEVICE_ID_NX2_57840_2_20
230 #define PCI_DEVICE_ID_NX2_57840_2_20 CHIP_NUM_57840_2_20
232 #ifndef PCI_DEVICE_ID_NX2_57840_MFO
233 #define PCI_DEVICE_ID_NX2_57840_MFO CHIP_NUM_57840_MF_OBSOLETE
235 #ifndef PCI_DEVICE_ID_NX2_57840_MF
236 #define PCI_DEVICE_ID_NX2_57840_MF CHIP_NUM_57840_MF
238 #ifndef PCI_DEVICE_ID_NX2_57840_VF
239 #define PCI_DEVICE_ID_NX2_57840_VF CHIP_NUM_57840_VF
241 #ifndef PCI_DEVICE_ID_NX2_57811
242 #define PCI_DEVICE_ID_NX2_57811 CHIP_NUM_57811
244 #ifndef PCI_DEVICE_ID_NX2_57811_MF
245 #define PCI_DEVICE_ID_NX2_57811_MF CHIP_NUM_57811_MF
247 #ifndef PCI_DEVICE_ID_NX2_57811_VF
248 #define PCI_DEVICE_ID_NX2_57811_VF CHIP_NUM_57811_VF
251 static const struct pci_device_id bnx2x_pci_tbl[] = {
252 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57710), BCM57710 },
253 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711), BCM57711 },
254 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711E), BCM57711E },
255 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712), BCM57712 },
256 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_MF), BCM57712_MF },
257 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_VF), BCM57712_VF },
258 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800), BCM57800 },
259 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_MF), BCM57800_MF },
260 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_VF), BCM57800_VF },
261 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810), BCM57810 },
262 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_MF), BCM57810_MF },
263 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_O), BCM57840_O },
264 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_4_10), BCM57840_4_10 },
265 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_2_20), BCM57840_2_20 },
266 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_VF), BCM57810_VF },
267 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MFO), BCM57840_MFO },
268 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MF), BCM57840_MF },
269 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_VF), BCM57840_VF },
270 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811), BCM57811 },
271 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811_MF), BCM57811_MF },
272 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811_VF), BCM57811_VF },
276 MODULE_DEVICE_TABLE(pci, bnx2x_pci_tbl);
278 /* Global resources for unloading a previously loaded device */
279 #define BNX2X_PREV_WAIT_NEEDED 1
280 static DEFINE_SEMAPHORE(bnx2x_prev_sem);
281 static LIST_HEAD(bnx2x_prev_list);
283 /* Forward declaration */
284 static struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev);
285 static u32 bnx2x_rx_ustorm_prods_offset(struct bnx2x_fastpath *fp);
286 static int bnx2x_set_storm_rx_mode(struct bnx2x *bp);
288 /****************************************************************************
289 * General service functions
290 ****************************************************************************/
292 static int bnx2x_hwtstamp_ioctl(struct bnx2x *bp, struct ifreq *ifr);
294 static void __storm_memset_dma_mapping(struct bnx2x *bp,
295 u32 addr, dma_addr_t mapping)
297 REG_WR(bp, addr, U64_LO(mapping));
298 REG_WR(bp, addr + 4, U64_HI(mapping));
301 static void storm_memset_spq_addr(struct bnx2x *bp,
302 dma_addr_t mapping, u16 abs_fid)
304 u32 addr = XSEM_REG_FAST_MEMORY +
305 XSTORM_SPQ_PAGE_BASE_OFFSET(abs_fid);
307 __storm_memset_dma_mapping(bp, addr, mapping);
310 static void storm_memset_vf_to_pf(struct bnx2x *bp, u16 abs_fid,
313 REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_VF_TO_PF_OFFSET(abs_fid),
315 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_VF_TO_PF_OFFSET(abs_fid),
317 REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_VF_TO_PF_OFFSET(abs_fid),
319 REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_VF_TO_PF_OFFSET(abs_fid),
323 static void storm_memset_func_en(struct bnx2x *bp, u16 abs_fid,
326 REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(abs_fid),
328 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(abs_fid),
330 REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(abs_fid),
332 REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(abs_fid),
336 static void storm_memset_eq_data(struct bnx2x *bp,
337 struct event_ring_data *eq_data,
340 size_t size = sizeof(struct event_ring_data);
342 u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_DATA_OFFSET(pfid);
344 __storm_memset_struct(bp, addr, size, (u32 *)eq_data);
347 static void storm_memset_eq_prod(struct bnx2x *bp, u16 eq_prod,
350 u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_PROD_OFFSET(pfid);
351 REG_WR16(bp, addr, eq_prod);
355 * locking is done by mcp
357 static void bnx2x_reg_wr_ind(struct bnx2x *bp, u32 addr, u32 val)
359 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
360 pci_write_config_dword(bp->pdev, PCICFG_GRC_DATA, val);
361 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
362 PCICFG_VENDOR_ID_OFFSET);
365 static u32 bnx2x_reg_rd_ind(struct bnx2x *bp, u32 addr)
369 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
370 pci_read_config_dword(bp->pdev, PCICFG_GRC_DATA, &val);
371 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
372 PCICFG_VENDOR_ID_OFFSET);
377 #define DMAE_DP_SRC_GRC "grc src_addr [%08x]"
378 #define DMAE_DP_SRC_PCI "pci src_addr [%x:%08x]"
379 #define DMAE_DP_DST_GRC "grc dst_addr [%08x]"
380 #define DMAE_DP_DST_PCI "pci dst_addr [%x:%08x]"
381 #define DMAE_DP_DST_NONE "dst_addr [none]"
383 static void bnx2x_dp_dmae(struct bnx2x *bp,
384 struct dmae_command *dmae, int msglvl)
386 u32 src_type = dmae->opcode & DMAE_COMMAND_SRC;
389 switch (dmae->opcode & DMAE_COMMAND_DST) {
390 case DMAE_CMD_DST_PCI:
391 if (src_type == DMAE_CMD_SRC_PCI)
392 DP(msglvl, "DMAE: opcode 0x%08x\n"
393 "src [%x:%08x], len [%d*4], dst [%x:%08x]\n"
394 "comp_addr [%x:%08x], comp_val 0x%08x\n",
395 dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
396 dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
397 dmae->comp_addr_hi, dmae->comp_addr_lo,
400 DP(msglvl, "DMAE: opcode 0x%08x\n"
401 "src [%08x], len [%d*4], dst [%x:%08x]\n"
402 "comp_addr [%x:%08x], comp_val 0x%08x\n",
403 dmae->opcode, dmae->src_addr_lo >> 2,
404 dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
405 dmae->comp_addr_hi, dmae->comp_addr_lo,
408 case DMAE_CMD_DST_GRC:
409 if (src_type == DMAE_CMD_SRC_PCI)
410 DP(msglvl, "DMAE: opcode 0x%08x\n"
411 "src [%x:%08x], len [%d*4], dst_addr [%08x]\n"
412 "comp_addr [%x:%08x], comp_val 0x%08x\n",
413 dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
414 dmae->len, dmae->dst_addr_lo >> 2,
415 dmae->comp_addr_hi, dmae->comp_addr_lo,
418 DP(msglvl, "DMAE: opcode 0x%08x\n"
419 "src [%08x], len [%d*4], dst [%08x]\n"
420 "comp_addr [%x:%08x], comp_val 0x%08x\n",
421 dmae->opcode, dmae->src_addr_lo >> 2,
422 dmae->len, dmae->dst_addr_lo >> 2,
423 dmae->comp_addr_hi, dmae->comp_addr_lo,
427 if (src_type == DMAE_CMD_SRC_PCI)
428 DP(msglvl, "DMAE: opcode 0x%08x\n"
429 "src_addr [%x:%08x] len [%d * 4] dst_addr [none]\n"
430 "comp_addr [%x:%08x] comp_val 0x%08x\n",
431 dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
432 dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
435 DP(msglvl, "DMAE: opcode 0x%08x\n"
436 "src_addr [%08x] len [%d * 4] dst_addr [none]\n"
437 "comp_addr [%x:%08x] comp_val 0x%08x\n",
438 dmae->opcode, dmae->src_addr_lo >> 2,
439 dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
444 for (i = 0; i < (sizeof(struct dmae_command)/4); i++)
445 DP(msglvl, "DMAE RAW [%02d]: 0x%08x\n",
446 i, *(((u32 *)dmae) + i));
449 /* copy command into DMAE command memory and set DMAE command go */
450 void bnx2x_post_dmae(struct bnx2x *bp, struct dmae_command *dmae, int idx)
455 cmd_offset = (DMAE_REG_CMD_MEM + sizeof(struct dmae_command) * idx);
456 for (i = 0; i < (sizeof(struct dmae_command)/4); i++) {
457 REG_WR(bp, cmd_offset + i*4, *(((u32 *)dmae) + i));
459 REG_WR(bp, dmae_reg_go_c[idx], 1);
462 u32 bnx2x_dmae_opcode_add_comp(u32 opcode, u8 comp_type)
464 return opcode | ((comp_type << DMAE_COMMAND_C_DST_SHIFT) |
468 u32 bnx2x_dmae_opcode_clr_src_reset(u32 opcode)
470 return opcode & ~DMAE_CMD_SRC_RESET;
473 u32 bnx2x_dmae_opcode(struct bnx2x *bp, u8 src_type, u8 dst_type,
474 bool with_comp, u8 comp_type)
478 opcode |= ((src_type << DMAE_COMMAND_SRC_SHIFT) |
479 (dst_type << DMAE_COMMAND_DST_SHIFT));
481 opcode |= (DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET);
483 opcode |= (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0);
484 opcode |= ((BP_VN(bp) << DMAE_CMD_E1HVN_SHIFT) |
485 (BP_VN(bp) << DMAE_COMMAND_DST_VN_SHIFT));
486 opcode |= (DMAE_COM_SET_ERR << DMAE_COMMAND_ERR_POLICY_SHIFT);
489 opcode |= DMAE_CMD_ENDIANITY_B_DW_SWAP;
491 opcode |= DMAE_CMD_ENDIANITY_DW_SWAP;
494 opcode = bnx2x_dmae_opcode_add_comp(opcode, comp_type);
498 void bnx2x_prep_dmae_with_comp(struct bnx2x *bp,
499 struct dmae_command *dmae,
500 u8 src_type, u8 dst_type)
502 memset(dmae, 0, sizeof(struct dmae_command));
505 dmae->opcode = bnx2x_dmae_opcode(bp, src_type, dst_type,
506 true, DMAE_COMP_PCI);
508 /* fill in the completion parameters */
509 dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_comp));
510 dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_comp));
511 dmae->comp_val = DMAE_COMP_VAL;
514 /* issue a dmae command over the init-channel and wait for completion */
515 int bnx2x_issue_dmae_with_comp(struct bnx2x *bp, struct dmae_command *dmae,
518 int cnt = CHIP_REV_IS_SLOW(bp) ? (400000) : 4000;
521 bnx2x_dp_dmae(bp, dmae, BNX2X_MSG_DMAE);
523 /* Lock the dmae channel. Disable BHs to prevent a dead-lock
524 * as long as this code is called both from syscall context and
525 * from ndo_set_rx_mode() flow that may be called from BH.
528 spin_lock_bh(&bp->dmae_lock);
530 /* reset completion */
533 /* post the command on the channel used for initializations */
534 bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp));
536 /* wait for completion */
538 while ((*comp & ~DMAE_PCI_ERR_FLAG) != DMAE_COMP_VAL) {
541 (bp->recovery_state != BNX2X_RECOVERY_DONE &&
542 bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
543 BNX2X_ERR("DMAE timeout!\n");
550 if (*comp & DMAE_PCI_ERR_FLAG) {
551 BNX2X_ERR("DMAE PCI error!\n");
557 spin_unlock_bh(&bp->dmae_lock);
562 void bnx2x_write_dmae(struct bnx2x *bp, dma_addr_t dma_addr, u32 dst_addr,
566 struct dmae_command dmae;
568 if (!bp->dmae_ready) {
569 u32 *data = bnx2x_sp(bp, wb_data[0]);
572 bnx2x_init_ind_wr(bp, dst_addr, data, len32);
574 bnx2x_init_str_wr(bp, dst_addr, data, len32);
578 /* set opcode and fixed command fields */
579 bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_GRC);
581 /* fill in addresses and len */
582 dmae.src_addr_lo = U64_LO(dma_addr);
583 dmae.src_addr_hi = U64_HI(dma_addr);
584 dmae.dst_addr_lo = dst_addr >> 2;
585 dmae.dst_addr_hi = 0;
588 /* issue the command and wait for completion */
589 rc = bnx2x_issue_dmae_with_comp(bp, &dmae, bnx2x_sp(bp, wb_comp));
591 BNX2X_ERR("DMAE returned failure %d\n", rc);
592 #ifdef BNX2X_STOP_ON_ERROR
598 void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32)
601 struct dmae_command dmae;
603 if (!bp->dmae_ready) {
604 u32 *data = bnx2x_sp(bp, wb_data[0]);
608 for (i = 0; i < len32; i++)
609 data[i] = bnx2x_reg_rd_ind(bp, src_addr + i*4);
611 for (i = 0; i < len32; i++)
612 data[i] = REG_RD(bp, src_addr + i*4);
617 /* set opcode and fixed command fields */
618 bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_GRC, DMAE_DST_PCI);
620 /* fill in addresses and len */
621 dmae.src_addr_lo = src_addr >> 2;
622 dmae.src_addr_hi = 0;
623 dmae.dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_data));
624 dmae.dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_data));
627 /* issue the command and wait for completion */
628 rc = bnx2x_issue_dmae_with_comp(bp, &dmae, bnx2x_sp(bp, wb_comp));
630 BNX2X_ERR("DMAE returned failure %d\n", rc);
631 #ifdef BNX2X_STOP_ON_ERROR
637 static void bnx2x_write_dmae_phys_len(struct bnx2x *bp, dma_addr_t phys_addr,
640 int dmae_wr_max = DMAE_LEN32_WR_MAX(bp);
643 while (len > dmae_wr_max) {
644 bnx2x_write_dmae(bp, phys_addr + offset,
645 addr + offset, dmae_wr_max);
646 offset += dmae_wr_max * 4;
650 bnx2x_write_dmae(bp, phys_addr + offset, addr + offset, len);
662 #define REGS_IN_ENTRY 4
664 static inline int bnx2x_get_assert_list_entry(struct bnx2x *bp,
670 return XSTORM_ASSERT_LIST_OFFSET(entry);
672 return TSTORM_ASSERT_LIST_OFFSET(entry);
674 return CSTORM_ASSERT_LIST_OFFSET(entry);
676 return USTORM_ASSERT_LIST_OFFSET(entry);
679 BNX2X_ERR("unknown storm\n");
684 static int bnx2x_mc_assert(struct bnx2x *bp)
689 u32 regs[REGS_IN_ENTRY];
690 u32 bar_storm_intmem[STORMS_NUM] = {
696 u32 storm_assert_list_index[STORMS_NUM] = {
697 XSTORM_ASSERT_LIST_INDEX_OFFSET,
698 TSTORM_ASSERT_LIST_INDEX_OFFSET,
699 CSTORM_ASSERT_LIST_INDEX_OFFSET,
700 USTORM_ASSERT_LIST_INDEX_OFFSET
702 char *storms_string[STORMS_NUM] = {
709 for (storm = XSTORM; storm < MAX_STORMS; storm++) {
710 last_idx = REG_RD8(bp, bar_storm_intmem[storm] +
711 storm_assert_list_index[storm]);
713 BNX2X_ERR("%s_ASSERT_LIST_INDEX 0x%x\n",
714 storms_string[storm], last_idx);
716 /* print the asserts */
717 for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
718 /* read a single assert entry */
719 for (j = 0; j < REGS_IN_ENTRY; j++)
720 regs[j] = REG_RD(bp, bar_storm_intmem[storm] +
721 bnx2x_get_assert_list_entry(bp,
726 /* log entry if it contains a valid assert */
727 if (regs[0] != COMMON_ASM_INVALID_ASSERT_OPCODE) {
728 BNX2X_ERR("%s_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
729 storms_string[storm], i, regs[3],
730 regs[2], regs[1], regs[0]);
738 BNX2X_ERR("Chip Revision: %s, FW Version: %d_%d_%d\n",
739 CHIP_IS_E1(bp) ? "everest1" :
740 CHIP_IS_E1H(bp) ? "everest1h" :
741 CHIP_IS_E2(bp) ? "everest2" : "everest3",
742 BCM_5710_FW_MAJOR_VERSION,
743 BCM_5710_FW_MINOR_VERSION,
744 BCM_5710_FW_REVISION_VERSION);
749 #define MCPR_TRACE_BUFFER_SIZE (0x800)
750 #define SCRATCH_BUFFER_SIZE(bp) \
751 (CHIP_IS_E1(bp) ? 0x10000 : (CHIP_IS_E1H(bp) ? 0x20000 : 0x28000))
753 void bnx2x_fw_dump_lvl(struct bnx2x *bp, const char *lvl)
759 u32 trace_shmem_base;
761 BNX2X_ERR("NO MCP - can not dump\n");
764 netdev_printk(lvl, bp->dev, "bc %d.%d.%d\n",
765 (bp->common.bc_ver & 0xff0000) >> 16,
766 (bp->common.bc_ver & 0xff00) >> 8,
767 (bp->common.bc_ver & 0xff));
769 val = REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER);
770 if (val == REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER))
771 BNX2X_ERR("%s" "MCP PC at 0x%x\n", lvl, val);
773 if (BP_PATH(bp) == 0)
774 trace_shmem_base = bp->common.shmem_base;
776 trace_shmem_base = SHMEM2_RD(bp, other_shmem_base_addr);
779 if (trace_shmem_base < MCPR_SCRATCH_BASE(bp) + MCPR_TRACE_BUFFER_SIZE ||
780 trace_shmem_base >= MCPR_SCRATCH_BASE(bp) +
781 SCRATCH_BUFFER_SIZE(bp)) {
782 BNX2X_ERR("Unable to dump trace buffer (mark %x)\n",
787 addr = trace_shmem_base - MCPR_TRACE_BUFFER_SIZE;
789 /* validate TRCB signature */
790 mark = REG_RD(bp, addr);
791 if (mark != MFW_TRACE_SIGNATURE) {
792 BNX2X_ERR("Trace buffer signature is missing.");
796 /* read cyclic buffer pointer */
798 mark = REG_RD(bp, addr);
799 mark = MCPR_SCRATCH_BASE(bp) + ((mark + 0x3) & ~0x3) - 0x08000000;
800 if (mark >= trace_shmem_base || mark < addr + 4) {
801 BNX2X_ERR("Mark doesn't fall inside Trace Buffer\n");
804 printk("%s" "begin fw dump (mark 0x%x)\n", lvl, mark);
808 /* dump buffer after the mark */
809 for (offset = mark; offset < trace_shmem_base; offset += 0x8*4) {
810 for (word = 0; word < 8; word++)
811 data[word] = htonl(REG_RD(bp, offset + 4*word));
813 pr_cont("%s", (char *)data);
816 /* dump buffer before the mark */
817 for (offset = addr + 4; offset <= mark; offset += 0x8*4) {
818 for (word = 0; word < 8; word++)
819 data[word] = htonl(REG_RD(bp, offset + 4*word));
821 pr_cont("%s", (char *)data);
823 printk("%s" "end of fw dump\n", lvl);
826 static void bnx2x_fw_dump(struct bnx2x *bp)
828 bnx2x_fw_dump_lvl(bp, KERN_ERR);
831 static void bnx2x_hc_int_disable(struct bnx2x *bp)
833 int port = BP_PORT(bp);
834 u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
835 u32 val = REG_RD(bp, addr);
837 /* in E1 we must use only PCI configuration space to disable
838 * MSI/MSIX capability
839 * It's forbidden to disable IGU_PF_CONF_MSI_MSIX_EN in HC block
841 if (CHIP_IS_E1(bp)) {
842 /* Since IGU_PF_CONF_MSI_MSIX_EN still always on
843 * Use mask register to prevent from HC sending interrupts
844 * after we exit the function
846 REG_WR(bp, HC_REG_INT_MASK + port*4, 0);
848 val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
849 HC_CONFIG_0_REG_INT_LINE_EN_0 |
850 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
852 val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
853 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
854 HC_CONFIG_0_REG_INT_LINE_EN_0 |
855 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
858 "write %x to HC %d (addr 0x%x)\n",
861 /* flush all outstanding writes */
864 REG_WR(bp, addr, val);
865 if (REG_RD(bp, addr) != val)
866 BNX2X_ERR("BUG! Proper val not read from IGU!\n");
869 static void bnx2x_igu_int_disable(struct bnx2x *bp)
871 u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
873 val &= ~(IGU_PF_CONF_MSI_MSIX_EN |
874 IGU_PF_CONF_INT_LINE_EN |
875 IGU_PF_CONF_ATTN_BIT_EN);
877 DP(NETIF_MSG_IFDOWN, "write %x to IGU\n", val);
879 /* flush all outstanding writes */
882 REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
883 if (REG_RD(bp, IGU_REG_PF_CONFIGURATION) != val)
884 BNX2X_ERR("BUG! Proper val not read from IGU!\n");
887 static void bnx2x_int_disable(struct bnx2x *bp)
889 if (bp->common.int_block == INT_BLOCK_HC)
890 bnx2x_hc_int_disable(bp);
892 bnx2x_igu_int_disable(bp);
895 void bnx2x_panic_dump(struct bnx2x *bp, bool disable_int)
899 struct hc_sp_status_block_data sp_sb_data;
900 int func = BP_FUNC(bp);
901 #ifdef BNX2X_STOP_ON_ERROR
902 u16 start = 0, end = 0;
905 if (IS_PF(bp) && disable_int)
906 bnx2x_int_disable(bp);
908 bp->stats_state = STATS_STATE_DISABLED;
909 bp->eth_stats.unrecoverable_error++;
910 DP(BNX2X_MSG_STATS, "stats_state - DISABLED\n");
912 BNX2X_ERR("begin crash dump -----------------\n");
917 struct host_sp_status_block *def_sb = bp->def_status_blk;
918 int data_size, cstorm_offset;
920 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",
921 bp->def_idx, bp->def_att_idx, bp->attn_state,
922 bp->spq_prod_idx, bp->stats_counter);
923 BNX2X_ERR("DSB: attn bits(0x%x) ack(0x%x) id(0x%x) idx(0x%x)\n",
924 def_sb->atten_status_block.attn_bits,
925 def_sb->atten_status_block.attn_bits_ack,
926 def_sb->atten_status_block.status_block_id,
927 def_sb->atten_status_block.attn_bits_index);
929 for (i = 0; i < HC_SP_SB_MAX_INDICES; i++)
931 def_sb->sp_sb.index_values[i],
932 (i == HC_SP_SB_MAX_INDICES - 1) ? ") " : " ");
934 data_size = sizeof(struct hc_sp_status_block_data) /
936 cstorm_offset = CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func);
937 for (i = 0; i < data_size; i++)
938 *((u32 *)&sp_sb_data + i) =
939 REG_RD(bp, BAR_CSTRORM_INTMEM + cstorm_offset +
942 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",
943 sp_sb_data.igu_sb_id,
944 sp_sb_data.igu_seg_id,
945 sp_sb_data.p_func.pf_id,
946 sp_sb_data.p_func.vnic_id,
947 sp_sb_data.p_func.vf_id,
948 sp_sb_data.p_func.vf_valid,
952 for_each_eth_queue(bp, i) {
953 struct bnx2x_fastpath *fp = &bp->fp[i];
955 struct hc_status_block_data_e2 sb_data_e2;
956 struct hc_status_block_data_e1x sb_data_e1x;
957 struct hc_status_block_sm *hc_sm_p =
959 sb_data_e1x.common.state_machine :
960 sb_data_e2.common.state_machine;
961 struct hc_index_data *hc_index_p =
963 sb_data_e1x.index_data :
964 sb_data_e2.index_data;
967 struct bnx2x_fp_txdata txdata;
976 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",
977 i, fp->rx_bd_prod, fp->rx_bd_cons,
979 fp->rx_comp_cons, le16_to_cpu(*fp->rx_cons_sb));
980 BNX2X_ERR(" rx_sge_prod(0x%x) last_max_sge(0x%x) fp_hc_idx(0x%x)\n",
981 fp->rx_sge_prod, fp->last_max_sge,
982 le16_to_cpu(fp->fp_hc_idx));
985 for_each_cos_in_tx_queue(fp, cos)
990 txdata = *fp->txdata_ptr[cos];
992 if (!txdata.tx_cons_sb)
995 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",
996 i, txdata.tx_pkt_prod,
997 txdata.tx_pkt_cons, txdata.tx_bd_prod,
999 le16_to_cpu(*txdata.tx_cons_sb));
1002 loop = CHIP_IS_E1x(bp) ?
1003 HC_SB_MAX_INDICES_E1X : HC_SB_MAX_INDICES_E2;
1010 BNX2X_ERR(" run indexes (");
1011 for (j = 0; j < HC_SB_MAX_SM; j++)
1013 fp->sb_running_index[j],
1014 (j == HC_SB_MAX_SM - 1) ? ")" : " ");
1016 BNX2X_ERR(" indexes (");
1017 for (j = 0; j < loop; j++)
1019 fp->sb_index_values[j],
1020 (j == loop - 1) ? ")" : " ");
1022 /* VF cannot access FW refelection for status block */
1027 data_size = CHIP_IS_E1x(bp) ?
1028 sizeof(struct hc_status_block_data_e1x) :
1029 sizeof(struct hc_status_block_data_e2);
1030 data_size /= sizeof(u32);
1031 sb_data_p = CHIP_IS_E1x(bp) ?
1032 (u32 *)&sb_data_e1x :
1034 /* copy sb data in here */
1035 for (j = 0; j < data_size; j++)
1036 *(sb_data_p + j) = REG_RD(bp, BAR_CSTRORM_INTMEM +
1037 CSTORM_STATUS_BLOCK_DATA_OFFSET(fp->fw_sb_id) +
1040 if (!CHIP_IS_E1x(bp)) {
1041 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",
1042 sb_data_e2.common.p_func.pf_id,
1043 sb_data_e2.common.p_func.vf_id,
1044 sb_data_e2.common.p_func.vf_valid,
1045 sb_data_e2.common.p_func.vnic_id,
1046 sb_data_e2.common.same_igu_sb_1b,
1047 sb_data_e2.common.state);
1049 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",
1050 sb_data_e1x.common.p_func.pf_id,
1051 sb_data_e1x.common.p_func.vf_id,
1052 sb_data_e1x.common.p_func.vf_valid,
1053 sb_data_e1x.common.p_func.vnic_id,
1054 sb_data_e1x.common.same_igu_sb_1b,
1055 sb_data_e1x.common.state);
1059 for (j = 0; j < HC_SB_MAX_SM; j++) {
1060 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",
1061 j, hc_sm_p[j].__flags,
1062 hc_sm_p[j].igu_sb_id,
1063 hc_sm_p[j].igu_seg_id,
1064 hc_sm_p[j].time_to_expire,
1065 hc_sm_p[j].timer_value);
1069 for (j = 0; j < loop; j++) {
1070 pr_cont("INDEX[%d] flags (0x%x) timeout (0x%x)\n", j,
1071 hc_index_p[j].flags,
1072 hc_index_p[j].timeout);
1076 #ifdef BNX2X_STOP_ON_ERROR
1079 BNX2X_ERR("eq cons %x prod %x\n", bp->eq_cons, bp->eq_prod);
1080 for (i = 0; i < NUM_EQ_DESC; i++) {
1081 u32 *data = (u32 *)&bp->eq_ring[i].message.data;
1083 BNX2X_ERR("event queue [%d]: header: opcode %d, error %d\n",
1084 i, bp->eq_ring[i].message.opcode,
1085 bp->eq_ring[i].message.error);
1086 BNX2X_ERR("data: %x %x %x\n",
1087 data[0], data[1], data[2]);
1093 for_each_valid_rx_queue(bp, i) {
1094 struct bnx2x_fastpath *fp = &bp->fp[i];
1099 if (!fp->rx_cons_sb)
1102 start = RX_BD(le16_to_cpu(*fp->rx_cons_sb) - 10);
1103 end = RX_BD(le16_to_cpu(*fp->rx_cons_sb) + 503);
1104 for (j = start; j != end; j = RX_BD(j + 1)) {
1105 u32 *rx_bd = (u32 *)&fp->rx_desc_ring[j];
1106 struct sw_rx_bd *sw_bd = &fp->rx_buf_ring[j];
1108 BNX2X_ERR("fp%d: rx_bd[%x]=[%x:%x] sw_bd=[%p]\n",
1109 i, j, rx_bd[1], rx_bd[0], sw_bd->data);
1112 start = RX_SGE(fp->rx_sge_prod);
1113 end = RX_SGE(fp->last_max_sge);
1114 for (j = start; j != end; j = RX_SGE(j + 1)) {
1115 u32 *rx_sge = (u32 *)&fp->rx_sge_ring[j];
1116 struct sw_rx_page *sw_page = &fp->rx_page_ring[j];
1118 BNX2X_ERR("fp%d: rx_sge[%x]=[%x:%x] sw_page=[%p]\n",
1119 i, j, rx_sge[1], rx_sge[0], sw_page->page);
1122 start = RCQ_BD(fp->rx_comp_cons - 10);
1123 end = RCQ_BD(fp->rx_comp_cons + 503);
1124 for (j = start; j != end; j = RCQ_BD(j + 1)) {
1125 u32 *cqe = (u32 *)&fp->rx_comp_ring[j];
1127 BNX2X_ERR("fp%d: cqe[%x]=[%x:%x:%x:%x]\n",
1128 i, j, cqe[0], cqe[1], cqe[2], cqe[3]);
1133 for_each_valid_tx_queue(bp, i) {
1134 struct bnx2x_fastpath *fp = &bp->fp[i];
1139 for_each_cos_in_tx_queue(fp, cos) {
1140 struct bnx2x_fp_txdata *txdata = fp->txdata_ptr[cos];
1142 if (!fp->txdata_ptr)
1145 if (!txdata.tx_cons_sb)
1148 start = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) - 10);
1149 end = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) + 245);
1150 for (j = start; j != end; j = TX_BD(j + 1)) {
1151 struct sw_tx_bd *sw_bd =
1152 &txdata->tx_buf_ring[j];
1154 BNX2X_ERR("fp%d: txdata %d, packet[%x]=[%p,%x]\n",
1155 i, cos, j, sw_bd->skb,
1159 start = TX_BD(txdata->tx_bd_cons - 10);
1160 end = TX_BD(txdata->tx_bd_cons + 254);
1161 for (j = start; j != end; j = TX_BD(j + 1)) {
1162 u32 *tx_bd = (u32 *)&txdata->tx_desc_ring[j];
1164 BNX2X_ERR("fp%d: txdata %d, tx_bd[%x]=[%x:%x:%x:%x]\n",
1165 i, cos, j, tx_bd[0], tx_bd[1],
1166 tx_bd[2], tx_bd[3]);
1173 bnx2x_mc_assert(bp);
1175 BNX2X_ERR("end crash dump -----------------\n");
1179 * FLR Support for E2
1181 * bnx2x_pf_flr_clnup() is called during nic_load in the per function HW
1184 #define FLR_WAIT_USEC 10000 /* 10 milliseconds */
1185 #define FLR_WAIT_INTERVAL 50 /* usec */
1186 #define FLR_POLL_CNT (FLR_WAIT_USEC/FLR_WAIT_INTERVAL) /* 200 */
1188 struct pbf_pN_buf_regs {
1195 struct pbf_pN_cmd_regs {
1201 static void bnx2x_pbf_pN_buf_flushed(struct bnx2x *bp,
1202 struct pbf_pN_buf_regs *regs,
1205 u32 init_crd, crd, crd_start, crd_freed, crd_freed_start;
1206 u32 cur_cnt = poll_count;
1208 crd_freed = crd_freed_start = REG_RD(bp, regs->crd_freed);
1209 crd = crd_start = REG_RD(bp, regs->crd);
1210 init_crd = REG_RD(bp, regs->init_crd);
1212 DP(BNX2X_MSG_SP, "INIT CREDIT[%d] : %x\n", regs->pN, init_crd);
1213 DP(BNX2X_MSG_SP, "CREDIT[%d] : s:%x\n", regs->pN, crd);
1214 DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: s:%x\n", regs->pN, crd_freed);
1216 while ((crd != init_crd) && ((u32)SUB_S32(crd_freed, crd_freed_start) <
1217 (init_crd - crd_start))) {
1219 udelay(FLR_WAIT_INTERVAL);
1220 crd = REG_RD(bp, regs->crd);
1221 crd_freed = REG_RD(bp, regs->crd_freed);
1223 DP(BNX2X_MSG_SP, "PBF tx buffer[%d] timed out\n",
1225 DP(BNX2X_MSG_SP, "CREDIT[%d] : c:%x\n",
1227 DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: c:%x\n",
1228 regs->pN, crd_freed);
1232 DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF tx buffer[%d]\n",
1233 poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
1236 static void bnx2x_pbf_pN_cmd_flushed(struct bnx2x *bp,
1237 struct pbf_pN_cmd_regs *regs,
1240 u32 occup, to_free, freed, freed_start;
1241 u32 cur_cnt = poll_count;
1243 occup = to_free = REG_RD(bp, regs->lines_occup);
1244 freed = freed_start = REG_RD(bp, regs->lines_freed);
1246 DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n", regs->pN, occup);
1247 DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n", regs->pN, freed);
1249 while (occup && ((u32)SUB_S32(freed, freed_start) < to_free)) {
1251 udelay(FLR_WAIT_INTERVAL);
1252 occup = REG_RD(bp, regs->lines_occup);
1253 freed = REG_RD(bp, regs->lines_freed);
1255 DP(BNX2X_MSG_SP, "PBF cmd queue[%d] timed out\n",
1257 DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n",
1259 DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n",
1264 DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF cmd queue[%d]\n",
1265 poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
1268 static u32 bnx2x_flr_clnup_reg_poll(struct bnx2x *bp, u32 reg,
1269 u32 expected, u32 poll_count)
1271 u32 cur_cnt = poll_count;
1274 while ((val = REG_RD(bp, reg)) != expected && cur_cnt--)
1275 udelay(FLR_WAIT_INTERVAL);
1280 int bnx2x_flr_clnup_poll_hw_counter(struct bnx2x *bp, u32 reg,
1281 char *msg, u32 poll_cnt)
1283 u32 val = bnx2x_flr_clnup_reg_poll(bp, reg, 0, poll_cnt);
1285 BNX2X_ERR("%s usage count=%d\n", msg, val);
1291 /* Common routines with VF FLR cleanup */
1292 u32 bnx2x_flr_clnup_poll_count(struct bnx2x *bp)
1294 /* adjust polling timeout */
1295 if (CHIP_REV_IS_EMUL(bp))
1296 return FLR_POLL_CNT * 2000;
1298 if (CHIP_REV_IS_FPGA(bp))
1299 return FLR_POLL_CNT * 120;
1301 return FLR_POLL_CNT;
1304 void bnx2x_tx_hw_flushed(struct bnx2x *bp, u32 poll_count)
1306 struct pbf_pN_cmd_regs cmd_regs[] = {
1307 {0, (CHIP_IS_E3B0(bp)) ?
1308 PBF_REG_TQ_OCCUPANCY_Q0 :
1309 PBF_REG_P0_TQ_OCCUPANCY,
1310 (CHIP_IS_E3B0(bp)) ?
1311 PBF_REG_TQ_LINES_FREED_CNT_Q0 :
1312 PBF_REG_P0_TQ_LINES_FREED_CNT},
1313 {1, (CHIP_IS_E3B0(bp)) ?
1314 PBF_REG_TQ_OCCUPANCY_Q1 :
1315 PBF_REG_P1_TQ_OCCUPANCY,
1316 (CHIP_IS_E3B0(bp)) ?
1317 PBF_REG_TQ_LINES_FREED_CNT_Q1 :
1318 PBF_REG_P1_TQ_LINES_FREED_CNT},
1319 {4, (CHIP_IS_E3B0(bp)) ?
1320 PBF_REG_TQ_OCCUPANCY_LB_Q :
1321 PBF_REG_P4_TQ_OCCUPANCY,
1322 (CHIP_IS_E3B0(bp)) ?
1323 PBF_REG_TQ_LINES_FREED_CNT_LB_Q :
1324 PBF_REG_P4_TQ_LINES_FREED_CNT}
1327 struct pbf_pN_buf_regs buf_regs[] = {
1328 {0, (CHIP_IS_E3B0(bp)) ?
1329 PBF_REG_INIT_CRD_Q0 :
1330 PBF_REG_P0_INIT_CRD ,
1331 (CHIP_IS_E3B0(bp)) ?
1334 (CHIP_IS_E3B0(bp)) ?
1335 PBF_REG_INTERNAL_CRD_FREED_CNT_Q0 :
1336 PBF_REG_P0_INTERNAL_CRD_FREED_CNT},
1337 {1, (CHIP_IS_E3B0(bp)) ?
1338 PBF_REG_INIT_CRD_Q1 :
1339 PBF_REG_P1_INIT_CRD,
1340 (CHIP_IS_E3B0(bp)) ?
1343 (CHIP_IS_E3B0(bp)) ?
1344 PBF_REG_INTERNAL_CRD_FREED_CNT_Q1 :
1345 PBF_REG_P1_INTERNAL_CRD_FREED_CNT},
1346 {4, (CHIP_IS_E3B0(bp)) ?
1347 PBF_REG_INIT_CRD_LB_Q :
1348 PBF_REG_P4_INIT_CRD,
1349 (CHIP_IS_E3B0(bp)) ?
1350 PBF_REG_CREDIT_LB_Q :
1352 (CHIP_IS_E3B0(bp)) ?
1353 PBF_REG_INTERNAL_CRD_FREED_CNT_LB_Q :
1354 PBF_REG_P4_INTERNAL_CRD_FREED_CNT},
1359 /* Verify the command queues are flushed P0, P1, P4 */
1360 for (i = 0; i < ARRAY_SIZE(cmd_regs); i++)
1361 bnx2x_pbf_pN_cmd_flushed(bp, &cmd_regs[i], poll_count);
1363 /* Verify the transmission buffers are flushed P0, P1, P4 */
1364 for (i = 0; i < ARRAY_SIZE(buf_regs); i++)
1365 bnx2x_pbf_pN_buf_flushed(bp, &buf_regs[i], poll_count);
1368 #define OP_GEN_PARAM(param) \
1369 (((param) << SDM_OP_GEN_COMP_PARAM_SHIFT) & SDM_OP_GEN_COMP_PARAM)
1371 #define OP_GEN_TYPE(type) \
1372 (((type) << SDM_OP_GEN_COMP_TYPE_SHIFT) & SDM_OP_GEN_COMP_TYPE)
1374 #define OP_GEN_AGG_VECT(index) \
1375 (((index) << SDM_OP_GEN_AGG_VECT_IDX_SHIFT) & SDM_OP_GEN_AGG_VECT_IDX)
1377 int bnx2x_send_final_clnup(struct bnx2x *bp, u8 clnup_func, u32 poll_cnt)
1379 u32 op_gen_command = 0;
1380 u32 comp_addr = BAR_CSTRORM_INTMEM +
1381 CSTORM_FINAL_CLEANUP_COMPLETE_OFFSET(clnup_func);
1384 if (REG_RD(bp, comp_addr)) {
1385 BNX2X_ERR("Cleanup complete was not 0 before sending\n");
1389 op_gen_command |= OP_GEN_PARAM(XSTORM_AGG_INT_FINAL_CLEANUP_INDEX);
1390 op_gen_command |= OP_GEN_TYPE(XSTORM_AGG_INT_FINAL_CLEANUP_COMP_TYPE);
1391 op_gen_command |= OP_GEN_AGG_VECT(clnup_func);
1392 op_gen_command |= 1 << SDM_OP_GEN_AGG_VECT_IDX_VALID_SHIFT;
1394 DP(BNX2X_MSG_SP, "sending FW Final cleanup\n");
1395 REG_WR(bp, XSDM_REG_OPERATION_GEN, op_gen_command);
1397 if (bnx2x_flr_clnup_reg_poll(bp, comp_addr, 1, poll_cnt) != 1) {
1398 BNX2X_ERR("FW final cleanup did not succeed\n");
1399 DP(BNX2X_MSG_SP, "At timeout completion address contained %x\n",
1400 (REG_RD(bp, comp_addr)));
1404 /* Zero completion for next FLR */
1405 REG_WR(bp, comp_addr, 0);
1410 u8 bnx2x_is_pcie_pending(struct pci_dev *dev)
1414 pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &status);
1415 return status & PCI_EXP_DEVSTA_TRPND;
1418 /* PF FLR specific routines
1420 static int bnx2x_poll_hw_usage_counters(struct bnx2x *bp, u32 poll_cnt)
1422 /* wait for CFC PF usage-counter to zero (includes all the VFs) */
1423 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1424 CFC_REG_NUM_LCIDS_INSIDE_PF,
1425 "CFC PF usage counter timed out",
1429 /* Wait for DQ PF usage-counter to zero (until DQ cleanup) */
1430 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1431 DORQ_REG_PF_USAGE_CNT,
1432 "DQ PF usage counter timed out",
1436 /* Wait for QM PF usage-counter to zero (until DQ cleanup) */
1437 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1438 QM_REG_PF_USG_CNT_0 + 4*BP_FUNC(bp),
1439 "QM PF usage counter timed out",
1443 /* Wait for Timer PF usage-counters to zero (until DQ cleanup) */
1444 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1445 TM_REG_LIN0_VNIC_UC + 4*BP_PORT(bp),
1446 "Timers VNIC usage counter timed out",
1449 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1450 TM_REG_LIN0_NUM_SCANS + 4*BP_PORT(bp),
1451 "Timers NUM_SCANS usage counter timed out",
1455 /* Wait DMAE PF usage counter to zero */
1456 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1457 dmae_reg_go_c[INIT_DMAE_C(bp)],
1458 "DMAE command register timed out",
1465 static void bnx2x_hw_enable_status(struct bnx2x *bp)
1469 val = REG_RD(bp, CFC_REG_WEAK_ENABLE_PF);
1470 DP(BNX2X_MSG_SP, "CFC_REG_WEAK_ENABLE_PF is 0x%x\n", val);
1472 val = REG_RD(bp, PBF_REG_DISABLE_PF);
1473 DP(BNX2X_MSG_SP, "PBF_REG_DISABLE_PF is 0x%x\n", val);
1475 val = REG_RD(bp, IGU_REG_PCI_PF_MSI_EN);
1476 DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSI_EN is 0x%x\n", val);
1478 val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_EN);
1479 DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_EN is 0x%x\n", val);
1481 val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_FUNC_MASK);
1482 DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_FUNC_MASK is 0x%x\n", val);
1484 val = REG_RD(bp, PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR);
1485 DP(BNX2X_MSG_SP, "PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR is 0x%x\n", val);
1487 val = REG_RD(bp, PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR);
1488 DP(BNX2X_MSG_SP, "PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR is 0x%x\n", val);
1490 val = REG_RD(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER);
1491 DP(BNX2X_MSG_SP, "PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER is 0x%x\n",
1495 static int bnx2x_pf_flr_clnup(struct bnx2x *bp)
1497 u32 poll_cnt = bnx2x_flr_clnup_poll_count(bp);
1499 DP(BNX2X_MSG_SP, "Cleanup after FLR PF[%d]\n", BP_ABS_FUNC(bp));
1501 /* Re-enable PF target read access */
1502 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
1504 /* Poll HW usage counters */
1505 DP(BNX2X_MSG_SP, "Polling usage counters\n");
1506 if (bnx2x_poll_hw_usage_counters(bp, poll_cnt))
1509 /* Zero the igu 'trailing edge' and 'leading edge' */
1511 /* Send the FW cleanup command */
1512 if (bnx2x_send_final_clnup(bp, (u8)BP_FUNC(bp), poll_cnt))
1517 /* Verify TX hw is flushed */
1518 bnx2x_tx_hw_flushed(bp, poll_cnt);
1520 /* Wait 100ms (not adjusted according to platform) */
1523 /* Verify no pending pci transactions */
1524 if (bnx2x_is_pcie_pending(bp->pdev))
1525 BNX2X_ERR("PCIE Transactions still pending\n");
1528 bnx2x_hw_enable_status(bp);
1531 * Master enable - Due to WB DMAE writes performed before this
1532 * register is re-initialized as part of the regular function init
1534 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
1539 static void bnx2x_hc_int_enable(struct bnx2x *bp)
1541 int port = BP_PORT(bp);
1542 u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
1543 u32 val = REG_RD(bp, addr);
1544 bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
1545 bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
1546 bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
1549 val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
1550 HC_CONFIG_0_REG_INT_LINE_EN_0);
1551 val |= (HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
1552 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
1554 val |= HC_CONFIG_0_REG_SINGLE_ISR_EN_0;
1556 val &= ~HC_CONFIG_0_REG_INT_LINE_EN_0;
1557 val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
1558 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
1559 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
1561 val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
1562 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
1563 HC_CONFIG_0_REG_INT_LINE_EN_0 |
1564 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
1566 if (!CHIP_IS_E1(bp)) {
1568 "write %x to HC %d (addr 0x%x)\n", val, port, addr);
1570 REG_WR(bp, addr, val);
1572 val &= ~HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0;
1577 REG_WR(bp, HC_REG_INT_MASK + port*4, 0x1FFFF);
1580 "write %x to HC %d (addr 0x%x) mode %s\n", val, port, addr,
1581 (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
1583 REG_WR(bp, addr, val);
1585 * Ensure that HC_CONFIG is written before leading/trailing edge config
1590 if (!CHIP_IS_E1(bp)) {
1591 /* init leading/trailing edge */
1593 val = (0xee0f | (1 << (BP_VN(bp) + 4)));
1595 /* enable nig and gpio3 attention */
1600 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
1601 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
1604 /* Make sure that interrupts are indeed enabled from here on */
1608 static void bnx2x_igu_int_enable(struct bnx2x *bp)
1611 bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
1612 bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
1613 bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
1615 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
1618 val &= ~(IGU_PF_CONF_INT_LINE_EN |
1619 IGU_PF_CONF_SINGLE_ISR_EN);
1620 val |= (IGU_PF_CONF_MSI_MSIX_EN |
1621 IGU_PF_CONF_ATTN_BIT_EN);
1624 val |= IGU_PF_CONF_SINGLE_ISR_EN;
1626 val &= ~IGU_PF_CONF_INT_LINE_EN;
1627 val |= (IGU_PF_CONF_MSI_MSIX_EN |
1628 IGU_PF_CONF_ATTN_BIT_EN |
1629 IGU_PF_CONF_SINGLE_ISR_EN);
1631 val &= ~IGU_PF_CONF_MSI_MSIX_EN;
1632 val |= (IGU_PF_CONF_INT_LINE_EN |
1633 IGU_PF_CONF_ATTN_BIT_EN |
1634 IGU_PF_CONF_SINGLE_ISR_EN);
1637 /* Clean previous status - need to configure igu prior to ack*/
1638 if ((!msix) || single_msix) {
1639 REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
1643 val |= IGU_PF_CONF_FUNC_EN;
1645 DP(NETIF_MSG_IFUP, "write 0x%x to IGU mode %s\n",
1646 val, (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
1648 REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
1650 if (val & IGU_PF_CONF_INT_LINE_EN)
1651 pci_intx(bp->pdev, true);
1655 /* init leading/trailing edge */
1657 val = (0xee0f | (1 << (BP_VN(bp) + 4)));
1659 /* enable nig and gpio3 attention */
1664 REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
1665 REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
1667 /* Make sure that interrupts are indeed enabled from here on */
1671 void bnx2x_int_enable(struct bnx2x *bp)
1673 if (bp->common.int_block == INT_BLOCK_HC)
1674 bnx2x_hc_int_enable(bp);
1676 bnx2x_igu_int_enable(bp);
1679 void bnx2x_int_disable_sync(struct bnx2x *bp, int disable_hw)
1681 int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
1685 /* prevent the HW from sending interrupts */
1686 bnx2x_int_disable(bp);
1688 /* make sure all ISRs are done */
1690 synchronize_irq(bp->msix_table[0].vector);
1692 if (CNIC_SUPPORT(bp))
1694 for_each_eth_queue(bp, i)
1695 synchronize_irq(bp->msix_table[offset++].vector);
1697 synchronize_irq(bp->pdev->irq);
1699 /* make sure sp_task is not running */
1700 cancel_delayed_work(&bp->sp_task);
1701 cancel_delayed_work(&bp->period_task);
1702 flush_workqueue(bnx2x_wq);
1708 * General service functions
1711 /* Return true if succeeded to acquire the lock */
1712 static bool bnx2x_trylock_hw_lock(struct bnx2x *bp, u32 resource)
1715 u32 resource_bit = (1 << resource);
1716 int func = BP_FUNC(bp);
1717 u32 hw_lock_control_reg;
1719 DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
1720 "Trying to take a lock on resource %d\n", resource);
1722 /* Validating that the resource is within range */
1723 if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
1724 DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
1725 "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
1726 resource, HW_LOCK_MAX_RESOURCE_VALUE);
1731 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
1733 hw_lock_control_reg =
1734 (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
1736 /* Try to acquire the lock */
1737 REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
1738 lock_status = REG_RD(bp, hw_lock_control_reg);
1739 if (lock_status & resource_bit)
1742 DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
1743 "Failed to get a lock on resource %d\n", resource);
1748 * bnx2x_get_leader_lock_resource - get the recovery leader resource id
1750 * @bp: driver handle
1752 * Returns the recovery leader resource id according to the engine this function
1753 * belongs to. Currently only only 2 engines is supported.
1755 static int bnx2x_get_leader_lock_resource(struct bnx2x *bp)
1758 return HW_LOCK_RESOURCE_RECOVERY_LEADER_1;
1760 return HW_LOCK_RESOURCE_RECOVERY_LEADER_0;
1764 * bnx2x_trylock_leader_lock- try to acquire a leader lock.
1766 * @bp: driver handle
1768 * Tries to acquire a leader lock for current engine.
1770 static bool bnx2x_trylock_leader_lock(struct bnx2x *bp)
1772 return bnx2x_trylock_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
1775 static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err);
1777 /* schedule the sp task and mark that interrupt occurred (runs from ISR) */
1778 static int bnx2x_schedule_sp_task(struct bnx2x *bp)
1780 /* Set the interrupt occurred bit for the sp-task to recognize it
1781 * must ack the interrupt and transition according to the IGU
1784 atomic_set(&bp->interrupt_occurred, 1);
1786 /* The sp_task must execute only after this bit
1787 * is set, otherwise we will get out of sync and miss all
1788 * further interrupts. Hence, the barrier.
1792 /* schedule sp_task to workqueue */
1793 return queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
1796 void bnx2x_sp_event(struct bnx2x_fastpath *fp, union eth_rx_cqe *rr_cqe)
1798 struct bnx2x *bp = fp->bp;
1799 int cid = SW_CID(rr_cqe->ramrod_cqe.conn_and_cmd_data);
1800 int command = CQE_CMD(rr_cqe->ramrod_cqe.conn_and_cmd_data);
1801 enum bnx2x_queue_cmd drv_cmd = BNX2X_Q_CMD_MAX;
1802 struct bnx2x_queue_sp_obj *q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
1805 "fp %d cid %d got ramrod #%d state is %x type is %d\n",
1806 fp->index, cid, command, bp->state,
1807 rr_cqe->ramrod_cqe.ramrod_type);
1809 /* If cid is within VF range, replace the slowpath object with the
1810 * one corresponding to this VF
1812 if (cid >= BNX2X_FIRST_VF_CID &&
1813 cid < BNX2X_FIRST_VF_CID + BNX2X_VF_CIDS)
1814 bnx2x_iov_set_queue_sp_obj(bp, cid, &q_obj);
1817 case (RAMROD_CMD_ID_ETH_CLIENT_UPDATE):
1818 DP(BNX2X_MSG_SP, "got UPDATE ramrod. CID %d\n", cid);
1819 drv_cmd = BNX2X_Q_CMD_UPDATE;
1822 case (RAMROD_CMD_ID_ETH_CLIENT_SETUP):
1823 DP(BNX2X_MSG_SP, "got MULTI[%d] setup ramrod\n", cid);
1824 drv_cmd = BNX2X_Q_CMD_SETUP;
1827 case (RAMROD_CMD_ID_ETH_TX_QUEUE_SETUP):
1828 DP(BNX2X_MSG_SP, "got MULTI[%d] tx-only setup ramrod\n", cid);
1829 drv_cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
1832 case (RAMROD_CMD_ID_ETH_HALT):
1833 DP(BNX2X_MSG_SP, "got MULTI[%d] halt ramrod\n", cid);
1834 drv_cmd = BNX2X_Q_CMD_HALT;
1837 case (RAMROD_CMD_ID_ETH_TERMINATE):
1838 DP(BNX2X_MSG_SP, "got MULTI[%d] terminate ramrod\n", cid);
1839 drv_cmd = BNX2X_Q_CMD_TERMINATE;
1842 case (RAMROD_CMD_ID_ETH_EMPTY):
1843 DP(BNX2X_MSG_SP, "got MULTI[%d] empty ramrod\n", cid);
1844 drv_cmd = BNX2X_Q_CMD_EMPTY;
1847 case (RAMROD_CMD_ID_ETH_TPA_UPDATE):
1848 DP(BNX2X_MSG_SP, "got tpa update ramrod CID=%d\n", cid);
1849 drv_cmd = BNX2X_Q_CMD_UPDATE_TPA;
1853 BNX2X_ERR("unexpected MC reply (%d) on fp[%d]\n",
1854 command, fp->index);
1858 if ((drv_cmd != BNX2X_Q_CMD_MAX) &&
1859 q_obj->complete_cmd(bp, q_obj, drv_cmd))
1860 /* q_obj->complete_cmd() failure means that this was
1861 * an unexpected completion.
1863 * In this case we don't want to increase the bp->spq_left
1864 * because apparently we haven't sent this command the first
1867 #ifdef BNX2X_STOP_ON_ERROR
1873 smp_mb__before_atomic();
1874 atomic_inc(&bp->cq_spq_left);
1875 /* push the change in bp->spq_left and towards the memory */
1876 smp_mb__after_atomic();
1878 DP(BNX2X_MSG_SP, "bp->cq_spq_left %x\n", atomic_read(&bp->cq_spq_left));
1880 if ((drv_cmd == BNX2X_Q_CMD_UPDATE) && (IS_FCOE_FP(fp)) &&
1881 (!!test_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state))) {
1882 /* if Q update ramrod is completed for last Q in AFEX vif set
1883 * flow, then ACK MCP at the end
1885 * mark pending ACK to MCP bit.
1886 * prevent case that both bits are cleared.
1887 * At the end of load/unload driver checks that
1888 * sp_state is cleared, and this order prevents
1891 smp_mb__before_atomic();
1892 set_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK, &bp->sp_state);
1894 clear_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
1895 smp_mb__after_atomic();
1897 /* schedule the sp task as mcp ack is required */
1898 bnx2x_schedule_sp_task(bp);
1904 irqreturn_t bnx2x_interrupt(int irq, void *dev_instance)
1906 struct bnx2x *bp = netdev_priv(dev_instance);
1907 u16 status = bnx2x_ack_int(bp);
1912 /* Return here if interrupt is shared and it's not for us */
1913 if (unlikely(status == 0)) {
1914 DP(NETIF_MSG_INTR, "not our interrupt!\n");
1917 DP(NETIF_MSG_INTR, "got an interrupt status 0x%x\n", status);
1919 #ifdef BNX2X_STOP_ON_ERROR
1920 if (unlikely(bp->panic))
1924 for_each_eth_queue(bp, i) {
1925 struct bnx2x_fastpath *fp = &bp->fp[i];
1927 mask = 0x2 << (fp->index + CNIC_SUPPORT(bp));
1928 if (status & mask) {
1929 /* Handle Rx or Tx according to SB id */
1930 for_each_cos_in_tx_queue(fp, cos)
1931 prefetch(fp->txdata_ptr[cos]->tx_cons_sb);
1932 prefetch(&fp->sb_running_index[SM_RX_ID]);
1933 napi_schedule(&bnx2x_fp(bp, fp->index, napi));
1938 if (CNIC_SUPPORT(bp)) {
1940 if (status & (mask | 0x1)) {
1941 struct cnic_ops *c_ops = NULL;
1944 c_ops = rcu_dereference(bp->cnic_ops);
1945 if (c_ops && (bp->cnic_eth_dev.drv_state &
1946 CNIC_DRV_STATE_HANDLES_IRQ))
1947 c_ops->cnic_handler(bp->cnic_data, NULL);
1954 if (unlikely(status & 0x1)) {
1956 /* schedule sp task to perform default status block work, ack
1957 * attentions and enable interrupts.
1959 bnx2x_schedule_sp_task(bp);
1966 if (unlikely(status))
1967 DP(NETIF_MSG_INTR, "got an unknown interrupt! (status 0x%x)\n",
1976 * General service functions
1979 int bnx2x_acquire_hw_lock(struct bnx2x *bp, u32 resource)
1982 u32 resource_bit = (1 << resource);
1983 int func = BP_FUNC(bp);
1984 u32 hw_lock_control_reg;
1987 /* Validating that the resource is within range */
1988 if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
1989 BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
1990 resource, HW_LOCK_MAX_RESOURCE_VALUE);
1995 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
1997 hw_lock_control_reg =
1998 (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
2001 /* Validating that the resource is not already taken */
2002 lock_status = REG_RD(bp, hw_lock_control_reg);
2003 if (lock_status & resource_bit) {
2004 BNX2X_ERR("lock_status 0x%x resource_bit 0x%x\n",
2005 lock_status, resource_bit);
2009 /* Try for 5 second every 5ms */
2010 for (cnt = 0; cnt < 1000; cnt++) {
2011 /* Try to acquire the lock */
2012 REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
2013 lock_status = REG_RD(bp, hw_lock_control_reg);
2014 if (lock_status & resource_bit)
2017 usleep_range(5000, 10000);
2019 BNX2X_ERR("Timeout\n");
2023 int bnx2x_release_leader_lock(struct bnx2x *bp)
2025 return bnx2x_release_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
2028 int bnx2x_release_hw_lock(struct bnx2x *bp, u32 resource)
2031 u32 resource_bit = (1 << resource);
2032 int func = BP_FUNC(bp);
2033 u32 hw_lock_control_reg;
2035 /* Validating that the resource is within range */
2036 if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
2037 BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
2038 resource, HW_LOCK_MAX_RESOURCE_VALUE);
2043 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
2045 hw_lock_control_reg =
2046 (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
2049 /* Validating that the resource is currently taken */
2050 lock_status = REG_RD(bp, hw_lock_control_reg);
2051 if (!(lock_status & resource_bit)) {
2052 BNX2X_ERR("lock_status 0x%x resource_bit 0x%x. Unlock was called but lock wasn't taken!\n",
2053 lock_status, resource_bit);
2057 REG_WR(bp, hw_lock_control_reg, resource_bit);
2061 int bnx2x_get_gpio(struct bnx2x *bp, int gpio_num, u8 port)
2063 /* The GPIO should be swapped if swap register is set and active */
2064 int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
2065 REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
2066 int gpio_shift = gpio_num +
2067 (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
2068 u32 gpio_mask = (1 << gpio_shift);
2072 if (gpio_num > MISC_REGISTERS_GPIO_3) {
2073 BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
2077 /* read GPIO value */
2078 gpio_reg = REG_RD(bp, MISC_REG_GPIO);
2080 /* get the requested pin value */
2081 if ((gpio_reg & gpio_mask) == gpio_mask)
2089 int bnx2x_set_gpio(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
2091 /* The GPIO should be swapped if swap register is set and active */
2092 int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
2093 REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
2094 int gpio_shift = gpio_num +
2095 (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
2096 u32 gpio_mask = (1 << gpio_shift);
2099 if (gpio_num > MISC_REGISTERS_GPIO_3) {
2100 BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
2104 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
2105 /* read GPIO and mask except the float bits */
2106 gpio_reg = (REG_RD(bp, MISC_REG_GPIO) & MISC_REGISTERS_GPIO_FLOAT);
2109 case MISC_REGISTERS_GPIO_OUTPUT_LOW:
2111 "Set GPIO %d (shift %d) -> output low\n",
2112 gpio_num, gpio_shift);
2113 /* clear FLOAT and set CLR */
2114 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
2115 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_CLR_POS);
2118 case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
2120 "Set GPIO %d (shift %d) -> output high\n",
2121 gpio_num, gpio_shift);
2122 /* clear FLOAT and set SET */
2123 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
2124 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_SET_POS);
2127 case MISC_REGISTERS_GPIO_INPUT_HI_Z:
2129 "Set GPIO %d (shift %d) -> input\n",
2130 gpio_num, gpio_shift);
2132 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
2139 REG_WR(bp, MISC_REG_GPIO, gpio_reg);
2140 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
2145 int bnx2x_set_mult_gpio(struct bnx2x *bp, u8 pins, u32 mode)
2150 /* Any port swapping should be handled by caller. */
2152 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
2153 /* read GPIO and mask except the float bits */
2154 gpio_reg = REG_RD(bp, MISC_REG_GPIO);
2155 gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_FLOAT_POS);
2156 gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_CLR_POS);
2157 gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_SET_POS);
2160 case MISC_REGISTERS_GPIO_OUTPUT_LOW:
2161 DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output low\n", pins);
2163 gpio_reg |= (pins << MISC_REGISTERS_GPIO_CLR_POS);
2166 case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
2167 DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output high\n", pins);
2169 gpio_reg |= (pins << MISC_REGISTERS_GPIO_SET_POS);
2172 case MISC_REGISTERS_GPIO_INPUT_HI_Z:
2173 DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> input\n", pins);
2175 gpio_reg |= (pins << MISC_REGISTERS_GPIO_FLOAT_POS);
2179 BNX2X_ERR("Invalid GPIO mode assignment %d\n", mode);
2185 REG_WR(bp, MISC_REG_GPIO, gpio_reg);
2187 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
2192 int bnx2x_set_gpio_int(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
2194 /* The GPIO should be swapped if swap register is set and active */
2195 int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
2196 REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
2197 int gpio_shift = gpio_num +
2198 (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
2199 u32 gpio_mask = (1 << gpio_shift);
2202 if (gpio_num > MISC_REGISTERS_GPIO_3) {
2203 BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
2207 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
2209 gpio_reg = REG_RD(bp, MISC_REG_GPIO_INT);
2212 case MISC_REGISTERS_GPIO_INT_OUTPUT_CLR:
2214 "Clear GPIO INT %d (shift %d) -> output low\n",
2215 gpio_num, gpio_shift);
2216 /* clear SET and set CLR */
2217 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
2218 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
2221 case MISC_REGISTERS_GPIO_INT_OUTPUT_SET:
2223 "Set GPIO INT %d (shift %d) -> output high\n",
2224 gpio_num, gpio_shift);
2225 /* clear CLR and set SET */
2226 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
2227 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
2234 REG_WR(bp, MISC_REG_GPIO_INT, gpio_reg);
2235 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
2240 static int bnx2x_set_spio(struct bnx2x *bp, int spio, u32 mode)
2244 /* Only 2 SPIOs are configurable */
2245 if ((spio != MISC_SPIO_SPIO4) && (spio != MISC_SPIO_SPIO5)) {
2246 BNX2X_ERR("Invalid SPIO 0x%x\n", spio);
2250 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
2251 /* read SPIO and mask except the float bits */
2252 spio_reg = (REG_RD(bp, MISC_REG_SPIO) & MISC_SPIO_FLOAT);
2255 case MISC_SPIO_OUTPUT_LOW:
2256 DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output low\n", spio);
2257 /* clear FLOAT and set CLR */
2258 spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
2259 spio_reg |= (spio << MISC_SPIO_CLR_POS);
2262 case MISC_SPIO_OUTPUT_HIGH:
2263 DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output high\n", spio);
2264 /* clear FLOAT and set SET */
2265 spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
2266 spio_reg |= (spio << MISC_SPIO_SET_POS);
2269 case MISC_SPIO_INPUT_HI_Z:
2270 DP(NETIF_MSG_HW, "Set SPIO 0x%x -> input\n", spio);
2272 spio_reg |= (spio << MISC_SPIO_FLOAT_POS);
2279 REG_WR(bp, MISC_REG_SPIO, spio_reg);
2280 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
2285 void bnx2x_calc_fc_adv(struct bnx2x *bp)
2287 u8 cfg_idx = bnx2x_get_link_cfg_idx(bp);
2288 switch (bp->link_vars.ieee_fc &
2289 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK) {
2290 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE:
2291 bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
2295 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH:
2296 bp->port.advertising[cfg_idx] |= (ADVERTISED_Asym_Pause |
2300 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC:
2301 bp->port.advertising[cfg_idx] |= ADVERTISED_Asym_Pause;
2305 bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
2311 static void bnx2x_set_requested_fc(struct bnx2x *bp)
2313 /* Initialize link parameters structure variables
2314 * It is recommended to turn off RX FC for jumbo frames
2315 * for better performance
2317 if (CHIP_IS_E1x(bp) && (bp->dev->mtu > 5000))
2318 bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_TX;
2320 bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_BOTH;
2323 static void bnx2x_init_dropless_fc(struct bnx2x *bp)
2325 u32 pause_enabled = 0;
2327 if (!CHIP_IS_E1(bp) && bp->dropless_fc && bp->link_vars.link_up) {
2328 if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX)
2331 REG_WR(bp, BAR_USTRORM_INTMEM +
2332 USTORM_ETH_PAUSE_ENABLED_OFFSET(BP_PORT(bp)),
2336 DP(NETIF_MSG_IFUP | NETIF_MSG_LINK, "dropless_fc is %s\n",
2337 pause_enabled ? "enabled" : "disabled");
2340 int bnx2x_initial_phy_init(struct bnx2x *bp, int load_mode)
2342 int rc, cfx_idx = bnx2x_get_link_cfg_idx(bp);
2343 u16 req_line_speed = bp->link_params.req_line_speed[cfx_idx];
2345 if (!BP_NOMCP(bp)) {
2346 bnx2x_set_requested_fc(bp);
2347 bnx2x_acquire_phy_lock(bp);
2349 if (load_mode == LOAD_DIAG) {
2350 struct link_params *lp = &bp->link_params;
2351 lp->loopback_mode = LOOPBACK_XGXS;
2352 /* do PHY loopback at 10G speed, if possible */
2353 if (lp->req_line_speed[cfx_idx] < SPEED_10000) {
2354 if (lp->speed_cap_mask[cfx_idx] &
2355 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
2356 lp->req_line_speed[cfx_idx] =
2359 lp->req_line_speed[cfx_idx] =
2364 if (load_mode == LOAD_LOOPBACK_EXT) {
2365 struct link_params *lp = &bp->link_params;
2366 lp->loopback_mode = LOOPBACK_EXT;
2369 rc = bnx2x_phy_init(&bp->link_params, &bp->link_vars);
2371 bnx2x_release_phy_lock(bp);
2373 bnx2x_init_dropless_fc(bp);
2375 bnx2x_calc_fc_adv(bp);
2377 if (bp->link_vars.link_up) {
2378 bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
2379 bnx2x_link_report(bp);
2381 queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
2382 bp->link_params.req_line_speed[cfx_idx] = req_line_speed;
2385 BNX2X_ERR("Bootcode is missing - can not initialize link\n");
2389 void bnx2x_link_set(struct bnx2x *bp)
2391 if (!BP_NOMCP(bp)) {
2392 bnx2x_acquire_phy_lock(bp);
2393 bnx2x_phy_init(&bp->link_params, &bp->link_vars);
2394 bnx2x_release_phy_lock(bp);
2396 bnx2x_init_dropless_fc(bp);
2398 bnx2x_calc_fc_adv(bp);
2400 BNX2X_ERR("Bootcode is missing - can not set link\n");
2403 static void bnx2x__link_reset(struct bnx2x *bp)
2405 if (!BP_NOMCP(bp)) {
2406 bnx2x_acquire_phy_lock(bp);
2407 bnx2x_lfa_reset(&bp->link_params, &bp->link_vars);
2408 bnx2x_release_phy_lock(bp);
2410 BNX2X_ERR("Bootcode is missing - can not reset link\n");
2413 void bnx2x_force_link_reset(struct bnx2x *bp)
2415 bnx2x_acquire_phy_lock(bp);
2416 bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
2417 bnx2x_release_phy_lock(bp);
2420 u8 bnx2x_link_test(struct bnx2x *bp, u8 is_serdes)
2424 if (!BP_NOMCP(bp)) {
2425 bnx2x_acquire_phy_lock(bp);
2426 rc = bnx2x_test_link(&bp->link_params, &bp->link_vars,
2428 bnx2x_release_phy_lock(bp);
2430 BNX2X_ERR("Bootcode is missing - can not test link\n");
2435 /* Calculates the sum of vn_min_rates.
2436 It's needed for further normalizing of the min_rates.
2438 sum of vn_min_rates.
2440 0 - if all the min_rates are 0.
2441 In the later case fairness algorithm should be deactivated.
2442 If not all min_rates are zero then those that are zeroes will be set to 1.
2444 static void bnx2x_calc_vn_min(struct bnx2x *bp,
2445 struct cmng_init_input *input)
2450 for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
2451 u32 vn_cfg = bp->mf_config[vn];
2452 u32 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
2453 FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
2455 /* Skip hidden vns */
2456 if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
2458 /* If min rate is zero - set it to 1 */
2459 else if (!vn_min_rate)
2460 vn_min_rate = DEF_MIN_RATE;
2464 input->vnic_min_rate[vn] = vn_min_rate;
2467 /* if ETS or all min rates are zeros - disable fairness */
2468 if (BNX2X_IS_ETS_ENABLED(bp)) {
2469 input->flags.cmng_enables &=
2470 ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
2471 DP(NETIF_MSG_IFUP, "Fairness will be disabled due to ETS\n");
2472 } else if (all_zero) {
2473 input->flags.cmng_enables &=
2474 ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
2476 "All MIN values are zeroes fairness will be disabled\n");
2478 input->flags.cmng_enables |=
2479 CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
2482 static void bnx2x_calc_vn_max(struct bnx2x *bp, int vn,
2483 struct cmng_init_input *input)
2486 u32 vn_cfg = bp->mf_config[vn];
2488 if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
2491 u32 maxCfg = bnx2x_extract_max_cfg(bp, vn_cfg);
2494 /* maxCfg in percents of linkspeed */
2495 vn_max_rate = (bp->link_vars.line_speed * maxCfg) / 100;
2496 } else /* SD modes */
2497 /* maxCfg is absolute in 100Mb units */
2498 vn_max_rate = maxCfg * 100;
2501 DP(NETIF_MSG_IFUP, "vn %d: vn_max_rate %d\n", vn, vn_max_rate);
2503 input->vnic_max_rate[vn] = vn_max_rate;
2506 static int bnx2x_get_cmng_fns_mode(struct bnx2x *bp)
2508 if (CHIP_REV_IS_SLOW(bp))
2509 return CMNG_FNS_NONE;
2511 return CMNG_FNS_MINMAX;
2513 return CMNG_FNS_NONE;
2516 void bnx2x_read_mf_cfg(struct bnx2x *bp)
2518 int vn, n = (CHIP_MODE_IS_4_PORT(bp) ? 2 : 1);
2521 return; /* what should be the default value in this case */
2523 /* For 2 port configuration the absolute function number formula
2525 * abs_func = 2 * vn + BP_PORT + BP_PATH
2527 * and there are 4 functions per port
2529 * For 4 port configuration it is
2530 * abs_func = 4 * vn + 2 * BP_PORT + BP_PATH
2532 * and there are 2 functions per port
2534 for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
2535 int /*abs*/func = n * (2 * vn + BP_PORT(bp)) + BP_PATH(bp);
2537 if (func >= E1H_FUNC_MAX)
2541 MF_CFG_RD(bp, func_mf_config[func].config);
2543 if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
2544 DP(NETIF_MSG_IFUP, "mf_cfg function disabled\n");
2545 bp->flags |= MF_FUNC_DIS;
2547 DP(NETIF_MSG_IFUP, "mf_cfg function enabled\n");
2548 bp->flags &= ~MF_FUNC_DIS;
2552 static void bnx2x_cmng_fns_init(struct bnx2x *bp, u8 read_cfg, u8 cmng_type)
2554 struct cmng_init_input input;
2555 memset(&input, 0, sizeof(struct cmng_init_input));
2557 input.port_rate = bp->link_vars.line_speed;
2559 if (cmng_type == CMNG_FNS_MINMAX && input.port_rate) {
2562 /* read mf conf from shmem */
2564 bnx2x_read_mf_cfg(bp);
2566 /* vn_weight_sum and enable fairness if not 0 */
2567 bnx2x_calc_vn_min(bp, &input);
2569 /* calculate and set min-max rate for each vn */
2571 for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++)
2572 bnx2x_calc_vn_max(bp, vn, &input);
2574 /* always enable rate shaping and fairness */
2575 input.flags.cmng_enables |=
2576 CMNG_FLAGS_PER_PORT_RATE_SHAPING_VN;
2578 bnx2x_init_cmng(&input, &bp->cmng);
2582 /* rate shaping and fairness are disabled */
2584 "rate shaping and fairness are disabled\n");
2587 static void storm_memset_cmng(struct bnx2x *bp,
2588 struct cmng_init *cmng,
2592 size_t size = sizeof(struct cmng_struct_per_port);
2594 u32 addr = BAR_XSTRORM_INTMEM +
2595 XSTORM_CMNG_PER_PORT_VARS_OFFSET(port);
2597 __storm_memset_struct(bp, addr, size, (u32 *)&cmng->port);
2599 for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
2600 int func = func_by_vn(bp, vn);
2602 addr = BAR_XSTRORM_INTMEM +
2603 XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(func);
2604 size = sizeof(struct rate_shaping_vars_per_vn);
2605 __storm_memset_struct(bp, addr, size,
2606 (u32 *)&cmng->vnic.vnic_max_rate[vn]);
2608 addr = BAR_XSTRORM_INTMEM +
2609 XSTORM_FAIRNESS_PER_VN_VARS_OFFSET(func);
2610 size = sizeof(struct fairness_vars_per_vn);
2611 __storm_memset_struct(bp, addr, size,
2612 (u32 *)&cmng->vnic.vnic_min_rate[vn]);
2616 /* init cmng mode in HW according to local configuration */
2617 void bnx2x_set_local_cmng(struct bnx2x *bp)
2619 int cmng_fns = bnx2x_get_cmng_fns_mode(bp);
2621 if (cmng_fns != CMNG_FNS_NONE) {
2622 bnx2x_cmng_fns_init(bp, false, cmng_fns);
2623 storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
2625 /* rate shaping and fairness are disabled */
2627 "single function mode without fairness\n");
2631 /* This function is called upon link interrupt */
2632 static void bnx2x_link_attn(struct bnx2x *bp)
2634 /* Make sure that we are synced with the current statistics */
2635 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
2637 bnx2x_link_update(&bp->link_params, &bp->link_vars);
2639 bnx2x_init_dropless_fc(bp);
2641 if (bp->link_vars.link_up) {
2643 if (bp->link_vars.mac_type != MAC_TYPE_EMAC) {
2644 struct host_port_stats *pstats;
2646 pstats = bnx2x_sp(bp, port_stats);
2647 /* reset old mac stats */
2648 memset(&(pstats->mac_stx[0]), 0,
2649 sizeof(struct mac_stx));
2651 if (bp->state == BNX2X_STATE_OPEN)
2652 bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
2655 if (bp->link_vars.link_up && bp->link_vars.line_speed)
2656 bnx2x_set_local_cmng(bp);
2658 __bnx2x_link_report(bp);
2661 bnx2x_link_sync_notify(bp);
2664 void bnx2x__link_status_update(struct bnx2x *bp)
2666 if (bp->state != BNX2X_STATE_OPEN)
2669 /* read updated dcb configuration */
2671 bnx2x_dcbx_pmf_update(bp);
2672 bnx2x_link_status_update(&bp->link_params, &bp->link_vars);
2673 if (bp->link_vars.link_up)
2674 bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
2676 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
2677 /* indicate link status */
2678 bnx2x_link_report(bp);
2681 bp->port.supported[0] |= (SUPPORTED_10baseT_Half |
2682 SUPPORTED_10baseT_Full |
2683 SUPPORTED_100baseT_Half |
2684 SUPPORTED_100baseT_Full |
2685 SUPPORTED_1000baseT_Full |
2686 SUPPORTED_2500baseX_Full |
2687 SUPPORTED_10000baseT_Full |
2692 SUPPORTED_Asym_Pause);
2693 bp->port.advertising[0] = bp->port.supported[0];
2695 bp->link_params.bp = bp;
2696 bp->link_params.port = BP_PORT(bp);
2697 bp->link_params.req_duplex[0] = DUPLEX_FULL;
2698 bp->link_params.req_flow_ctrl[0] = BNX2X_FLOW_CTRL_NONE;
2699 bp->link_params.req_line_speed[0] = SPEED_10000;
2700 bp->link_params.speed_cap_mask[0] = 0x7f0000;
2701 bp->link_params.switch_cfg = SWITCH_CFG_10G;
2702 bp->link_vars.mac_type = MAC_TYPE_BMAC;
2703 bp->link_vars.line_speed = SPEED_10000;
2704 bp->link_vars.link_status =
2705 (LINK_STATUS_LINK_UP |
2706 LINK_STATUS_SPEED_AND_DUPLEX_10GTFD);
2707 bp->link_vars.link_up = 1;
2708 bp->link_vars.duplex = DUPLEX_FULL;
2709 bp->link_vars.flow_ctrl = BNX2X_FLOW_CTRL_NONE;
2710 __bnx2x_link_report(bp);
2712 bnx2x_sample_bulletin(bp);
2714 /* if bulletin board did not have an update for link status
2715 * __bnx2x_link_report will report current status
2716 * but it will NOT duplicate report in case of already reported
2717 * during sampling bulletin board.
2719 bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
2723 static int bnx2x_afex_func_update(struct bnx2x *bp, u16 vifid,
2724 u16 vlan_val, u8 allowed_prio)
2726 struct bnx2x_func_state_params func_params = {NULL};
2727 struct bnx2x_func_afex_update_params *f_update_params =
2728 &func_params.params.afex_update;
2730 func_params.f_obj = &bp->func_obj;
2731 func_params.cmd = BNX2X_F_CMD_AFEX_UPDATE;
2733 /* no need to wait for RAMROD completion, so don't
2734 * set RAMROD_COMP_WAIT flag
2737 f_update_params->vif_id = vifid;
2738 f_update_params->afex_default_vlan = vlan_val;
2739 f_update_params->allowed_priorities = allowed_prio;
2741 /* if ramrod can not be sent, response to MCP immediately */
2742 if (bnx2x_func_state_change(bp, &func_params) < 0)
2743 bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
2748 static int bnx2x_afex_handle_vif_list_cmd(struct bnx2x *bp, u8 cmd_type,
2749 u16 vif_index, u8 func_bit_map)
2751 struct bnx2x_func_state_params func_params = {NULL};
2752 struct bnx2x_func_afex_viflists_params *update_params =
2753 &func_params.params.afex_viflists;
2757 /* validate only LIST_SET and LIST_GET are received from switch */
2758 if ((cmd_type != VIF_LIST_RULE_GET) && (cmd_type != VIF_LIST_RULE_SET))
2759 BNX2X_ERR("BUG! afex_handle_vif_list_cmd invalid type 0x%x\n",
2762 func_params.f_obj = &bp->func_obj;
2763 func_params.cmd = BNX2X_F_CMD_AFEX_VIFLISTS;
2765 /* set parameters according to cmd_type */
2766 update_params->afex_vif_list_command = cmd_type;
2767 update_params->vif_list_index = vif_index;
2768 update_params->func_bit_map =
2769 (cmd_type == VIF_LIST_RULE_GET) ? 0 : func_bit_map;
2770 update_params->func_to_clear = 0;
2772 (cmd_type == VIF_LIST_RULE_GET) ?
2773 DRV_MSG_CODE_AFEX_LISTGET_ACK :
2774 DRV_MSG_CODE_AFEX_LISTSET_ACK;
2776 /* if ramrod can not be sent, respond to MCP immediately for
2777 * SET and GET requests (other are not triggered from MCP)
2779 rc = bnx2x_func_state_change(bp, &func_params);
2781 bnx2x_fw_command(bp, drv_msg_code, 0);
2786 static void bnx2x_handle_afex_cmd(struct bnx2x *bp, u32 cmd)
2788 struct afex_stats afex_stats;
2789 u32 func = BP_ABS_FUNC(bp);
2796 u32 addr_to_write, vifid, addrs, stats_type, i;
2798 if (cmd & DRV_STATUS_AFEX_LISTGET_REQ) {
2799 vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
2801 "afex: got MCP req LISTGET_REQ for vifid 0x%x\n", vifid);
2802 bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_GET, vifid, 0);
2805 if (cmd & DRV_STATUS_AFEX_LISTSET_REQ) {
2806 vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
2807 addrs = SHMEM2_RD(bp, afex_param2_to_driver[BP_FW_MB_IDX(bp)]);
2809 "afex: got MCP req LISTSET_REQ for vifid 0x%x addrs 0x%x\n",
2811 bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_SET, vifid,
2815 if (cmd & DRV_STATUS_AFEX_STATSGET_REQ) {
2816 addr_to_write = SHMEM2_RD(bp,
2817 afex_scratchpad_addr_to_write[BP_FW_MB_IDX(bp)]);
2818 stats_type = SHMEM2_RD(bp,
2819 afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
2822 "afex: got MCP req STATSGET_REQ, write to addr 0x%x\n",
2825 bnx2x_afex_collect_stats(bp, (void *)&afex_stats, stats_type);
2827 /* write response to scratchpad, for MCP */
2828 for (i = 0; i < (sizeof(struct afex_stats)/sizeof(u32)); i++)
2829 REG_WR(bp, addr_to_write + i*sizeof(u32),
2830 *(((u32 *)(&afex_stats))+i));
2832 /* send ack message to MCP */
2833 bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_STATSGET_ACK, 0);
2836 if (cmd & DRV_STATUS_AFEX_VIFSET_REQ) {
2837 mf_config = MF_CFG_RD(bp, func_mf_config[func].config);
2838 bp->mf_config[BP_VN(bp)] = mf_config;
2840 "afex: got MCP req VIFSET_REQ, mf_config 0x%x\n",
2843 /* if VIF_SET is "enabled" */
2844 if (!(mf_config & FUNC_MF_CFG_FUNC_DISABLED)) {
2845 /* set rate limit directly to internal RAM */
2846 struct cmng_init_input cmng_input;
2847 struct rate_shaping_vars_per_vn m_rs_vn;
2848 size_t size = sizeof(struct rate_shaping_vars_per_vn);
2849 u32 addr = BAR_XSTRORM_INTMEM +
2850 XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(BP_FUNC(bp));
2852 bp->mf_config[BP_VN(bp)] = mf_config;
2854 bnx2x_calc_vn_max(bp, BP_VN(bp), &cmng_input);
2855 m_rs_vn.vn_counter.rate =
2856 cmng_input.vnic_max_rate[BP_VN(bp)];
2857 m_rs_vn.vn_counter.quota =
2858 (m_rs_vn.vn_counter.rate *
2859 RS_PERIODIC_TIMEOUT_USEC) / 8;
2861 __storm_memset_struct(bp, addr, size, (u32 *)&m_rs_vn);
2863 /* read relevant values from mf_cfg struct in shmem */
2865 (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
2866 FUNC_MF_CFG_E1HOV_TAG_MASK) >>
2867 FUNC_MF_CFG_E1HOV_TAG_SHIFT;
2869 (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
2870 FUNC_MF_CFG_AFEX_VLAN_MASK) >>
2871 FUNC_MF_CFG_AFEX_VLAN_SHIFT;
2872 vlan_prio = (mf_config &
2873 FUNC_MF_CFG_TRANSMIT_PRIORITY_MASK) >>
2874 FUNC_MF_CFG_TRANSMIT_PRIORITY_SHIFT;
2875 vlan_val |= (vlan_prio << VLAN_PRIO_SHIFT);
2878 func_mf_config[func].afex_config) &
2879 FUNC_MF_CFG_AFEX_VLAN_MODE_MASK) >>
2880 FUNC_MF_CFG_AFEX_VLAN_MODE_SHIFT;
2883 func_mf_config[func].afex_config) &
2884 FUNC_MF_CFG_AFEX_COS_FILTER_MASK) >>
2885 FUNC_MF_CFG_AFEX_COS_FILTER_SHIFT;
2887 /* send ramrod to FW, return in case of failure */
2888 if (bnx2x_afex_func_update(bp, vif_id, vlan_val,
2892 bp->afex_def_vlan_tag = vlan_val;
2893 bp->afex_vlan_mode = vlan_mode;
2895 /* notify link down because BP->flags is disabled */
2896 bnx2x_link_report(bp);
2898 /* send INVALID VIF ramrod to FW */
2899 bnx2x_afex_func_update(bp, 0xFFFF, 0, 0);
2901 /* Reset the default afex VLAN */
2902 bp->afex_def_vlan_tag = -1;
2907 static void bnx2x_pmf_update(struct bnx2x *bp)
2909 int port = BP_PORT(bp);
2913 DP(BNX2X_MSG_MCP, "pmf %d\n", bp->port.pmf);
2916 * We need the mb() to ensure the ordering between the writing to
2917 * bp->port.pmf here and reading it from the bnx2x_periodic_task().
2921 /* queue a periodic task */
2922 queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
2924 bnx2x_dcbx_pmf_update(bp);
2926 /* enable nig attention */
2927 val = (0xff0f | (1 << (BP_VN(bp) + 4)));
2928 if (bp->common.int_block == INT_BLOCK_HC) {
2929 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
2930 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
2931 } else if (!CHIP_IS_E1x(bp)) {
2932 REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
2933 REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
2936 bnx2x_stats_handle(bp, STATS_EVENT_PMF);
2944 * General service functions
2947 /* send the MCP a request, block until there is a reply */
2948 u32 bnx2x_fw_command(struct bnx2x *bp, u32 command, u32 param)
2950 int mb_idx = BP_FW_MB_IDX(bp);
2954 u8 delay = CHIP_REV_IS_SLOW(bp) ? 100 : 10;
2956 mutex_lock(&bp->fw_mb_mutex);
2958 SHMEM_WR(bp, func_mb[mb_idx].drv_mb_param, param);
2959 SHMEM_WR(bp, func_mb[mb_idx].drv_mb_header, (command | seq));
2961 DP(BNX2X_MSG_MCP, "wrote command (%x) to FW MB param 0x%08x\n",
2962 (command | seq), param);
2965 /* let the FW do it's magic ... */
2968 rc = SHMEM_RD(bp, func_mb[mb_idx].fw_mb_header);
2970 /* Give the FW up to 5 second (500*10ms) */
2971 } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 500));
2973 DP(BNX2X_MSG_MCP, "[after %d ms] read (%x) seq is (%x) from FW MB\n",
2974 cnt*delay, rc, seq);
2976 /* is this a reply to our command? */
2977 if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK))
2978 rc &= FW_MSG_CODE_MASK;
2981 BNX2X_ERR("FW failed to respond!\n");
2985 mutex_unlock(&bp->fw_mb_mutex);
2990 static void storm_memset_func_cfg(struct bnx2x *bp,
2991 struct tstorm_eth_function_common_config *tcfg,
2994 size_t size = sizeof(struct tstorm_eth_function_common_config);
2996 u32 addr = BAR_TSTRORM_INTMEM +
2997 TSTORM_FUNCTION_COMMON_CONFIG_OFFSET(abs_fid);
2999 __storm_memset_struct(bp, addr, size, (u32 *)tcfg);
3002 void bnx2x_func_init(struct bnx2x *bp, struct bnx2x_func_init_params *p)
3004 if (CHIP_IS_E1x(bp)) {
3005 struct tstorm_eth_function_common_config tcfg = {0};
3007 storm_memset_func_cfg(bp, &tcfg, p->func_id);
3010 /* Enable the function in the FW */
3011 storm_memset_vf_to_pf(bp, p->func_id, p->pf_id);
3012 storm_memset_func_en(bp, p->func_id, 1);
3015 if (p->func_flgs & FUNC_FLG_SPQ) {
3016 storm_memset_spq_addr(bp, p->spq_map, p->func_id);
3017 REG_WR(bp, XSEM_REG_FAST_MEMORY +
3018 XSTORM_SPQ_PROD_OFFSET(p->func_id), p->spq_prod);
3023 * bnx2x_get_common_flags - Return common flags
3027 * @zero_stats TRUE if statistics zeroing is needed
3029 * Return the flags that are common for the Tx-only and not normal connections.
3031 static unsigned long bnx2x_get_common_flags(struct bnx2x *bp,
3032 struct bnx2x_fastpath *fp,
3035 unsigned long flags = 0;
3037 /* PF driver will always initialize the Queue to an ACTIVE state */
3038 __set_bit(BNX2X_Q_FLG_ACTIVE, &flags);
3040 /* tx only connections collect statistics (on the same index as the
3041 * parent connection). The statistics are zeroed when the parent
3042 * connection is initialized.
3045 __set_bit(BNX2X_Q_FLG_STATS, &flags);
3047 __set_bit(BNX2X_Q_FLG_ZERO_STATS, &flags);
3049 if (bp->flags & TX_SWITCHING)
3050 __set_bit(BNX2X_Q_FLG_TX_SWITCH, &flags);
3052 __set_bit(BNX2X_Q_FLG_PCSUM_ON_PKT, &flags);
3053 __set_bit(BNX2X_Q_FLG_TUN_INC_INNER_IP_ID, &flags);
3055 #ifdef BNX2X_STOP_ON_ERROR
3056 __set_bit(BNX2X_Q_FLG_TX_SEC, &flags);
3062 static unsigned long bnx2x_get_q_flags(struct bnx2x *bp,
3063 struct bnx2x_fastpath *fp,
3066 unsigned long flags = 0;
3068 /* calculate other queue flags */
3070 __set_bit(BNX2X_Q_FLG_OV, &flags);
3072 if (IS_FCOE_FP(fp)) {
3073 __set_bit(BNX2X_Q_FLG_FCOE, &flags);
3074 /* For FCoE - force usage of default priority (for afex) */
3075 __set_bit(BNX2X_Q_FLG_FORCE_DEFAULT_PRI, &flags);
3078 if (!fp->disable_tpa) {
3079 __set_bit(BNX2X_Q_FLG_TPA, &flags);
3080 __set_bit(BNX2X_Q_FLG_TPA_IPV6, &flags);
3081 if (fp->mode == TPA_MODE_GRO)
3082 __set_bit(BNX2X_Q_FLG_TPA_GRO, &flags);
3086 __set_bit(BNX2X_Q_FLG_LEADING_RSS, &flags);
3087 __set_bit(BNX2X_Q_FLG_MCAST, &flags);
3090 /* Always set HW VLAN stripping */
3091 __set_bit(BNX2X_Q_FLG_VLAN, &flags);
3093 /* configure silent vlan removal */
3095 __set_bit(BNX2X_Q_FLG_SILENT_VLAN_REM, &flags);
3097 return flags | bnx2x_get_common_flags(bp, fp, true);
3100 static void bnx2x_pf_q_prep_general(struct bnx2x *bp,
3101 struct bnx2x_fastpath *fp, struct bnx2x_general_setup_params *gen_init,
3104 gen_init->stat_id = bnx2x_stats_id(fp);
3105 gen_init->spcl_id = fp->cl_id;
3107 /* Always use mini-jumbo MTU for FCoE L2 ring */
3109 gen_init->mtu = BNX2X_FCOE_MINI_JUMBO_MTU;
3111 gen_init->mtu = bp->dev->mtu;
3113 gen_init->cos = cos;
3116 static void bnx2x_pf_rx_q_prep(struct bnx2x *bp,
3117 struct bnx2x_fastpath *fp, struct rxq_pause_params *pause,
3118 struct bnx2x_rxq_setup_params *rxq_init)
3122 u16 tpa_agg_size = 0;
3124 if (!fp->disable_tpa) {
3125 pause->sge_th_lo = SGE_TH_LO(bp);
3126 pause->sge_th_hi = SGE_TH_HI(bp);
3128 /* validate SGE ring has enough to cross high threshold */
3129 WARN_ON(bp->dropless_fc &&
3130 pause->sge_th_hi + FW_PREFETCH_CNT >
3131 MAX_RX_SGE_CNT * NUM_RX_SGE_PAGES);
3133 tpa_agg_size = TPA_AGG_SIZE;
3134 max_sge = SGE_PAGE_ALIGN(bp->dev->mtu) >>
3136 max_sge = ((max_sge + PAGES_PER_SGE - 1) &
3137 (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
3138 sge_sz = (u16)min_t(u32, SGE_PAGES, 0xffff);
3141 /* pause - not for e1 */
3142 if (!CHIP_IS_E1(bp)) {
3143 pause->bd_th_lo = BD_TH_LO(bp);
3144 pause->bd_th_hi = BD_TH_HI(bp);
3146 pause->rcq_th_lo = RCQ_TH_LO(bp);
3147 pause->rcq_th_hi = RCQ_TH_HI(bp);
3149 * validate that rings have enough entries to cross
3152 WARN_ON(bp->dropless_fc &&
3153 pause->bd_th_hi + FW_PREFETCH_CNT >
3155 WARN_ON(bp->dropless_fc &&
3156 pause->rcq_th_hi + FW_PREFETCH_CNT >
3157 NUM_RCQ_RINGS * MAX_RCQ_DESC_CNT);
3163 rxq_init->dscr_map = fp->rx_desc_mapping;
3164 rxq_init->sge_map = fp->rx_sge_mapping;
3165 rxq_init->rcq_map = fp->rx_comp_mapping;
3166 rxq_init->rcq_np_map = fp->rx_comp_mapping + BCM_PAGE_SIZE;
3168 /* This should be a maximum number of data bytes that may be
3169 * placed on the BD (not including paddings).
3171 rxq_init->buf_sz = fp->rx_buf_size - BNX2X_FW_RX_ALIGN_START -
3172 BNX2X_FW_RX_ALIGN_END - IP_HEADER_ALIGNMENT_PADDING;
3174 rxq_init->cl_qzone_id = fp->cl_qzone_id;
3175 rxq_init->tpa_agg_sz = tpa_agg_size;
3176 rxq_init->sge_buf_sz = sge_sz;
3177 rxq_init->max_sges_pkt = max_sge;
3178 rxq_init->rss_engine_id = BP_FUNC(bp);
3179 rxq_init->mcast_engine_id = BP_FUNC(bp);
3181 /* Maximum number or simultaneous TPA aggregation for this Queue.
3183 * For PF Clients it should be the maximum available number.
3184 * VF driver(s) may want to define it to a smaller value.
3186 rxq_init->max_tpa_queues = MAX_AGG_QS(bp);
3188 rxq_init->cache_line_log = BNX2X_RX_ALIGN_SHIFT;
3189 rxq_init->fw_sb_id = fp->fw_sb_id;
3192 rxq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_RX_CQ_CONS;
3194 rxq_init->sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
3195 /* configure silent vlan removal
3196 * if multi function mode is afex, then mask default vlan
3198 if (IS_MF_AFEX(bp)) {
3199 rxq_init->silent_removal_value = bp->afex_def_vlan_tag;
3200 rxq_init->silent_removal_mask = VLAN_VID_MASK;
3204 static void bnx2x_pf_tx_q_prep(struct bnx2x *bp,
3205 struct bnx2x_fastpath *fp, struct bnx2x_txq_setup_params *txq_init,
3208 txq_init->dscr_map = fp->txdata_ptr[cos]->tx_desc_mapping;
3209 txq_init->sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS + cos;
3210 txq_init->traffic_type = LLFC_TRAFFIC_TYPE_NW;
3211 txq_init->fw_sb_id = fp->fw_sb_id;
3214 * set the tss leading client id for TX classification ==
3215 * leading RSS client id
3217 txq_init->tss_leading_cl_id = bnx2x_fp(bp, 0, cl_id);
3219 if (IS_FCOE_FP(fp)) {
3220 txq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_TX_CQ_CONS;
3221 txq_init->traffic_type = LLFC_TRAFFIC_TYPE_FCOE;
3225 static void bnx2x_pf_init(struct bnx2x *bp)
3227 struct bnx2x_func_init_params func_init = {0};
3228 struct event_ring_data eq_data = { {0} };
3231 if (!CHIP_IS_E1x(bp)) {
3232 /* reset IGU PF statistics: MSIX + ATTN */
3234 REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
3235 BNX2X_IGU_STAS_MSG_VF_CNT*4 +
3236 (CHIP_MODE_IS_4_PORT(bp) ?
3237 BP_FUNC(bp) : BP_VN(bp))*4, 0);
3239 REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
3240 BNX2X_IGU_STAS_MSG_VF_CNT*4 +
3241 BNX2X_IGU_STAS_MSG_PF_CNT*4 +
3242 (CHIP_MODE_IS_4_PORT(bp) ?
3243 BP_FUNC(bp) : BP_VN(bp))*4, 0);
3246 /* function setup flags */
3247 flags = (FUNC_FLG_STATS | FUNC_FLG_LEADING | FUNC_FLG_SPQ);
3249 /* This flag is relevant for E1x only.
3250 * E2 doesn't have a TPA configuration in a function level.
3252 flags |= (bp->flags & TPA_ENABLE_FLAG) ? FUNC_FLG_TPA : 0;
3254 func_init.func_flgs = flags;
3255 func_init.pf_id = BP_FUNC(bp);
3256 func_init.func_id = BP_FUNC(bp);
3257 func_init.spq_map = bp->spq_mapping;
3258 func_init.spq_prod = bp->spq_prod_idx;
3260 bnx2x_func_init(bp, &func_init);
3262 memset(&(bp->cmng), 0, sizeof(struct cmng_struct_per_port));
3265 * Congestion management values depend on the link rate
3266 * There is no active link so initial link rate is set to 10 Gbps.
3267 * When the link comes up The congestion management values are
3268 * re-calculated according to the actual link rate.
3270 bp->link_vars.line_speed = SPEED_10000;
3271 bnx2x_cmng_fns_init(bp, true, bnx2x_get_cmng_fns_mode(bp));
3273 /* Only the PMF sets the HW */
3275 storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
3277 /* init Event Queue - PCI bus guarantees correct endianity*/
3278 eq_data.base_addr.hi = U64_HI(bp->eq_mapping);
3279 eq_data.base_addr.lo = U64_LO(bp->eq_mapping);
3280 eq_data.producer = bp->eq_prod;
3281 eq_data.index_id = HC_SP_INDEX_EQ_CONS;
3282 eq_data.sb_id = DEF_SB_ID;
3283 storm_memset_eq_data(bp, &eq_data, BP_FUNC(bp));
3286 static void bnx2x_e1h_disable(struct bnx2x *bp)
3288 int port = BP_PORT(bp);
3290 bnx2x_tx_disable(bp);
3292 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
3295 static void bnx2x_e1h_enable(struct bnx2x *bp)
3297 int port = BP_PORT(bp);
3299 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
3301 /* Tx queue should be only re-enabled */
3302 netif_tx_wake_all_queues(bp->dev);
3305 * Should not call netif_carrier_on since it will be called if the link
3306 * is up when checking for link state
3310 #define DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED 3
3312 static void bnx2x_drv_info_ether_stat(struct bnx2x *bp)
3314 struct eth_stats_info *ether_stat =
3315 &bp->slowpath->drv_info_to_mcp.ether_stat;
3316 struct bnx2x_vlan_mac_obj *mac_obj =
3317 &bp->sp_objs->mac_obj;
3320 strlcpy(ether_stat->version, DRV_MODULE_VERSION,
3321 ETH_STAT_INFO_VERSION_LEN);
3323 /* get DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED macs, placing them in the
3324 * mac_local field in ether_stat struct. The base address is offset by 2
3325 * bytes to account for the field being 8 bytes but a mac address is
3326 * only 6 bytes. Likewise, the stride for the get_n_elements function is
3327 * 2 bytes to compensate from the 6 bytes of a mac to the 8 bytes
3328 * allocated by the ether_stat struct, so the macs will land in their
3331 for (i = 0; i < DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED; i++)
3332 memset(ether_stat->mac_local + i, 0,
3333 sizeof(ether_stat->mac_local[0]));
3334 mac_obj->get_n_elements(bp, &bp->sp_objs[0].mac_obj,
3335 DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED,
3336 ether_stat->mac_local + MAC_PAD, MAC_PAD,
3338 ether_stat->mtu_size = bp->dev->mtu;
3339 if (bp->dev->features & NETIF_F_RXCSUM)
3340 ether_stat->feature_flags |= FEATURE_ETH_CHKSUM_OFFLOAD_MASK;
3341 if (bp->dev->features & NETIF_F_TSO)
3342 ether_stat->feature_flags |= FEATURE_ETH_LSO_MASK;
3343 ether_stat->feature_flags |= bp->common.boot_mode;
3345 ether_stat->promiscuous_mode = (bp->dev->flags & IFF_PROMISC) ? 1 : 0;
3347 ether_stat->txq_size = bp->tx_ring_size;
3348 ether_stat->rxq_size = bp->rx_ring_size;
3350 #ifdef CONFIG_BNX2X_SRIOV
3351 ether_stat->vf_cnt = IS_SRIOV(bp) ? bp->vfdb->sriov.nr_virtfn : 0;
3355 static void bnx2x_drv_info_fcoe_stat(struct bnx2x *bp)
3357 struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
3358 struct fcoe_stats_info *fcoe_stat =
3359 &bp->slowpath->drv_info_to_mcp.fcoe_stat;
3361 if (!CNIC_LOADED(bp))
3364 memcpy(fcoe_stat->mac_local + MAC_PAD, bp->fip_mac, ETH_ALEN);
3366 fcoe_stat->qos_priority =
3367 app->traffic_type_priority[LLFC_TRAFFIC_TYPE_FCOE];
3369 /* insert FCoE stats from ramrod response */
3371 struct tstorm_per_queue_stats *fcoe_q_tstorm_stats =
3372 &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
3373 tstorm_queue_statistics;
3375 struct xstorm_per_queue_stats *fcoe_q_xstorm_stats =
3376 &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
3377 xstorm_queue_statistics;
3379 struct fcoe_statistics_params *fw_fcoe_stat =
3380 &bp->fw_stats_data->fcoe;
3382 ADD_64_LE(fcoe_stat->rx_bytes_hi, LE32_0,
3383 fcoe_stat->rx_bytes_lo,
3384 fw_fcoe_stat->rx_stat0.fcoe_rx_byte_cnt);
3386 ADD_64_LE(fcoe_stat->rx_bytes_hi,
3387 fcoe_q_tstorm_stats->rcv_ucast_bytes.hi,
3388 fcoe_stat->rx_bytes_lo,
3389 fcoe_q_tstorm_stats->rcv_ucast_bytes.lo);
3391 ADD_64_LE(fcoe_stat->rx_bytes_hi,
3392 fcoe_q_tstorm_stats->rcv_bcast_bytes.hi,
3393 fcoe_stat->rx_bytes_lo,
3394 fcoe_q_tstorm_stats->rcv_bcast_bytes.lo);
3396 ADD_64_LE(fcoe_stat->rx_bytes_hi,
3397 fcoe_q_tstorm_stats->rcv_mcast_bytes.hi,
3398 fcoe_stat->rx_bytes_lo,
3399 fcoe_q_tstorm_stats->rcv_mcast_bytes.lo);
3401 ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
3402 fcoe_stat->rx_frames_lo,
3403 fw_fcoe_stat->rx_stat0.fcoe_rx_pkt_cnt);
3405 ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
3406 fcoe_stat->rx_frames_lo,
3407 fcoe_q_tstorm_stats->rcv_ucast_pkts);
3409 ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
3410 fcoe_stat->rx_frames_lo,
3411 fcoe_q_tstorm_stats->rcv_bcast_pkts);
3413 ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
3414 fcoe_stat->rx_frames_lo,
3415 fcoe_q_tstorm_stats->rcv_mcast_pkts);
3417 ADD_64_LE(fcoe_stat->tx_bytes_hi, LE32_0,
3418 fcoe_stat->tx_bytes_lo,
3419 fw_fcoe_stat->tx_stat.fcoe_tx_byte_cnt);
3421 ADD_64_LE(fcoe_stat->tx_bytes_hi,
3422 fcoe_q_xstorm_stats->ucast_bytes_sent.hi,
3423 fcoe_stat->tx_bytes_lo,
3424 fcoe_q_xstorm_stats->ucast_bytes_sent.lo);
3426 ADD_64_LE(fcoe_stat->tx_bytes_hi,
3427 fcoe_q_xstorm_stats->bcast_bytes_sent.hi,
3428 fcoe_stat->tx_bytes_lo,
3429 fcoe_q_xstorm_stats->bcast_bytes_sent.lo);
3431 ADD_64_LE(fcoe_stat->tx_bytes_hi,
3432 fcoe_q_xstorm_stats->mcast_bytes_sent.hi,
3433 fcoe_stat->tx_bytes_lo,
3434 fcoe_q_xstorm_stats->mcast_bytes_sent.lo);
3436 ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
3437 fcoe_stat->tx_frames_lo,
3438 fw_fcoe_stat->tx_stat.fcoe_tx_pkt_cnt);
3440 ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
3441 fcoe_stat->tx_frames_lo,
3442 fcoe_q_xstorm_stats->ucast_pkts_sent);
3444 ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
3445 fcoe_stat->tx_frames_lo,
3446 fcoe_q_xstorm_stats->bcast_pkts_sent);
3448 ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
3449 fcoe_stat->tx_frames_lo,
3450 fcoe_q_xstorm_stats->mcast_pkts_sent);
3453 /* ask L5 driver to add data to the struct */
3454 bnx2x_cnic_notify(bp, CNIC_CTL_FCOE_STATS_GET_CMD);
3457 static void bnx2x_drv_info_iscsi_stat(struct bnx2x *bp)
3459 struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
3460 struct iscsi_stats_info *iscsi_stat =
3461 &bp->slowpath->drv_info_to_mcp.iscsi_stat;
3463 if (!CNIC_LOADED(bp))
3466 memcpy(iscsi_stat->mac_local + MAC_PAD, bp->cnic_eth_dev.iscsi_mac,
3469 iscsi_stat->qos_priority =
3470 app->traffic_type_priority[LLFC_TRAFFIC_TYPE_ISCSI];
3472 /* ask L5 driver to add data to the struct */
3473 bnx2x_cnic_notify(bp, CNIC_CTL_ISCSI_STATS_GET_CMD);
3476 /* called due to MCP event (on pmf):
3477 * reread new bandwidth configuration
3479 * notify others function about the change
3481 static void bnx2x_config_mf_bw(struct bnx2x *bp)
3483 if (bp->link_vars.link_up) {
3484 bnx2x_cmng_fns_init(bp, true, CMNG_FNS_MINMAX);
3485 bnx2x_link_sync_notify(bp);
3487 storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
3490 static void bnx2x_set_mf_bw(struct bnx2x *bp)
3492 bnx2x_config_mf_bw(bp);
3493 bnx2x_fw_command(bp, DRV_MSG_CODE_SET_MF_BW_ACK, 0);
3496 static void bnx2x_handle_eee_event(struct bnx2x *bp)
3498 DP(BNX2X_MSG_MCP, "EEE - LLDP event\n");
3499 bnx2x_fw_command(bp, DRV_MSG_CODE_EEE_RESULTS_ACK, 0);
3502 #define BNX2X_UPDATE_DRV_INFO_IND_LENGTH (20)
3503 #define BNX2X_UPDATE_DRV_INFO_IND_COUNT (25)
3505 static void bnx2x_handle_drv_info_req(struct bnx2x *bp)
3507 enum drv_info_opcode op_code;
3508 u32 drv_info_ctl = SHMEM2_RD(bp, drv_info_control);
3509 bool release = false;
3512 /* if drv_info version supported by MFW doesn't match - send NACK */
3513 if ((drv_info_ctl & DRV_INFO_CONTROL_VER_MASK) != DRV_INFO_CUR_VER) {
3514 bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
3518 op_code = (drv_info_ctl & DRV_INFO_CONTROL_OP_CODE_MASK) >>
3519 DRV_INFO_CONTROL_OP_CODE_SHIFT;
3521 /* Must prevent other flows from accessing drv_info_to_mcp */
3522 mutex_lock(&bp->drv_info_mutex);
3524 memset(&bp->slowpath->drv_info_to_mcp, 0,
3525 sizeof(union drv_info_to_mcp));
3528 case ETH_STATS_OPCODE:
3529 bnx2x_drv_info_ether_stat(bp);
3531 case FCOE_STATS_OPCODE:
3532 bnx2x_drv_info_fcoe_stat(bp);
3534 case ISCSI_STATS_OPCODE:
3535 bnx2x_drv_info_iscsi_stat(bp);
3538 /* if op code isn't supported - send NACK */
3539 bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
3543 /* if we got drv_info attn from MFW then these fields are defined in
3546 SHMEM2_WR(bp, drv_info_host_addr_lo,
3547 U64_LO(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
3548 SHMEM2_WR(bp, drv_info_host_addr_hi,
3549 U64_HI(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
3551 bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_ACK, 0);
3553 /* Since possible management wants both this and get_driver_version
3554 * need to wait until management notifies us it finished utilizing
3557 if (!SHMEM2_HAS(bp, mfw_drv_indication)) {
3558 DP(BNX2X_MSG_MCP, "Management does not support indication\n");
3559 } else if (!bp->drv_info_mng_owner) {
3560 u32 bit = MFW_DRV_IND_READ_DONE_OFFSET((BP_ABS_FUNC(bp) >> 1));
3562 for (wait = 0; wait < BNX2X_UPDATE_DRV_INFO_IND_COUNT; wait++) {
3563 u32 indication = SHMEM2_RD(bp, mfw_drv_indication);
3565 /* Management is done; need to clear indication */
3566 if (indication & bit) {
3567 SHMEM2_WR(bp, mfw_drv_indication,
3573 msleep(BNX2X_UPDATE_DRV_INFO_IND_LENGTH);
3577 DP(BNX2X_MSG_MCP, "Management did not release indication\n");
3578 bp->drv_info_mng_owner = true;
3582 mutex_unlock(&bp->drv_info_mutex);
3585 static u32 bnx2x_update_mng_version_utility(u8 *version, bool bnx2x_format)
3591 i = sscanf(version, "1.%c%hhd.%hhd.%hhd",
3592 &vals[0], &vals[1], &vals[2], &vals[3]);
3596 i = sscanf(version, "%hhd.%hhd.%hhd.%hhd",
3597 &vals[0], &vals[1], &vals[2], &vals[3]);
3603 return (vals[0] << 24) | (vals[1] << 16) | (vals[2] << 8) | vals[3];
3606 void bnx2x_update_mng_version(struct bnx2x *bp)
3608 u32 iscsiver = DRV_VER_NOT_LOADED;
3609 u32 fcoever = DRV_VER_NOT_LOADED;
3610 u32 ethver = DRV_VER_NOT_LOADED;
3611 int idx = BP_FW_MB_IDX(bp);
3614 if (!SHMEM2_HAS(bp, func_os_drv_ver))
3617 mutex_lock(&bp->drv_info_mutex);
3618 /* Must not proceed when `bnx2x_handle_drv_info_req' is feasible */
3619 if (bp->drv_info_mng_owner)
3622 if (bp->state != BNX2X_STATE_OPEN)
3625 /* Parse ethernet driver version */
3626 ethver = bnx2x_update_mng_version_utility(DRV_MODULE_VERSION, true);
3627 if (!CNIC_LOADED(bp))
3630 /* Try getting storage driver version via cnic */
3631 memset(&bp->slowpath->drv_info_to_mcp, 0,
3632 sizeof(union drv_info_to_mcp));
3633 bnx2x_drv_info_iscsi_stat(bp);
3634 version = bp->slowpath->drv_info_to_mcp.iscsi_stat.version;
3635 iscsiver = bnx2x_update_mng_version_utility(version, false);
3637 memset(&bp->slowpath->drv_info_to_mcp, 0,
3638 sizeof(union drv_info_to_mcp));
3639 bnx2x_drv_info_fcoe_stat(bp);
3640 version = bp->slowpath->drv_info_to_mcp.fcoe_stat.version;
3641 fcoever = bnx2x_update_mng_version_utility(version, false);
3644 SHMEM2_WR(bp, func_os_drv_ver[idx].versions[DRV_PERS_ETHERNET], ethver);
3645 SHMEM2_WR(bp, func_os_drv_ver[idx].versions[DRV_PERS_ISCSI], iscsiver);
3646 SHMEM2_WR(bp, func_os_drv_ver[idx].versions[DRV_PERS_FCOE], fcoever);
3648 mutex_unlock(&bp->drv_info_mutex);
3650 DP(BNX2X_MSG_MCP, "Setting driver version: ETH [%08x] iSCSI [%08x] FCoE [%08x]\n",
3651 ethver, iscsiver, fcoever);
3654 static void bnx2x_dcc_event(struct bnx2x *bp, u32 dcc_event)
3656 DP(BNX2X_MSG_MCP, "dcc_event 0x%x\n", dcc_event);
3658 if (dcc_event & DRV_STATUS_DCC_DISABLE_ENABLE_PF) {
3661 * This is the only place besides the function initialization
3662 * where the bp->flags can change so it is done without any
3665 if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
3666 DP(BNX2X_MSG_MCP, "mf_cfg function disabled\n");
3667 bp->flags |= MF_FUNC_DIS;
3669 bnx2x_e1h_disable(bp);
3671 DP(BNX2X_MSG_MCP, "mf_cfg function enabled\n");
3672 bp->flags &= ~MF_FUNC_DIS;
3674 bnx2x_e1h_enable(bp);
3676 dcc_event &= ~DRV_STATUS_DCC_DISABLE_ENABLE_PF;
3678 if (dcc_event & DRV_STATUS_DCC_BANDWIDTH_ALLOCATION) {
3679 bnx2x_config_mf_bw(bp);
3680 dcc_event &= ~DRV_STATUS_DCC_BANDWIDTH_ALLOCATION;
3683 /* Report results to MCP */
3685 bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_FAILURE, 0);
3687 bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_OK, 0);
3690 /* must be called under the spq lock */
3691 static struct eth_spe *bnx2x_sp_get_next(struct bnx2x *bp)
3693 struct eth_spe *next_spe = bp->spq_prod_bd;
3695 if (bp->spq_prod_bd == bp->spq_last_bd) {
3696 bp->spq_prod_bd = bp->spq;
3697 bp->spq_prod_idx = 0;
3698 DP(BNX2X_MSG_SP, "end of spq\n");
3706 /* must be called under the spq lock */
3707 static void bnx2x_sp_prod_update(struct bnx2x *bp)
3709 int func = BP_FUNC(bp);
3712 * Make sure that BD data is updated before writing the producer:
3713 * BD data is written to the memory, the producer is read from the
3714 * memory, thus we need a full memory barrier to ensure the ordering.
3718 REG_WR16(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func),
3724 * bnx2x_is_contextless_ramrod - check if the current command ends on EQ
3726 * @cmd: command to check
3727 * @cmd_type: command type
3729 static bool bnx2x_is_contextless_ramrod(int cmd, int cmd_type)
3731 if ((cmd_type == NONE_CONNECTION_TYPE) ||
3732 (cmd == RAMROD_CMD_ID_ETH_FORWARD_SETUP) ||
3733 (cmd == RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES) ||
3734 (cmd == RAMROD_CMD_ID_ETH_FILTER_RULES) ||
3735 (cmd == RAMROD_CMD_ID_ETH_MULTICAST_RULES) ||
3736 (cmd == RAMROD_CMD_ID_ETH_SET_MAC) ||
3737 (cmd == RAMROD_CMD_ID_ETH_RSS_UPDATE))
3744 * bnx2x_sp_post - place a single command on an SP ring
3746 * @bp: driver handle
3747 * @command: command to place (e.g. SETUP, FILTER_RULES, etc.)
3748 * @cid: SW CID the command is related to
3749 * @data_hi: command private data address (high 32 bits)
3750 * @data_lo: command private data address (low 32 bits)
3751 * @cmd_type: command type (e.g. NONE, ETH)
3753 * SP data is handled as if it's always an address pair, thus data fields are
3754 * not swapped to little endian in upper functions. Instead this function swaps
3755 * data as if it's two u32 fields.
3757 int bnx2x_sp_post(struct bnx2x *bp, int command, int cid,
3758 u32 data_hi, u32 data_lo, int cmd_type)
3760 struct eth_spe *spe;
3762 bool common = bnx2x_is_contextless_ramrod(command, cmd_type);
3764 #ifdef BNX2X_STOP_ON_ERROR
3765 if (unlikely(bp->panic)) {
3766 BNX2X_ERR("Can't post SP when there is panic\n");
3771 spin_lock_bh(&bp->spq_lock);
3774 if (!atomic_read(&bp->eq_spq_left)) {
3775 BNX2X_ERR("BUG! EQ ring full!\n");
3776 spin_unlock_bh(&bp->spq_lock);
3780 } else if (!atomic_read(&bp->cq_spq_left)) {
3781 BNX2X_ERR("BUG! SPQ ring full!\n");
3782 spin_unlock_bh(&bp->spq_lock);
3787 spe = bnx2x_sp_get_next(bp);
3789 /* CID needs port number to be encoded int it */
3790 spe->hdr.conn_and_cmd_data =
3791 cpu_to_le32((command << SPE_HDR_CMD_ID_SHIFT) |
3794 /* In some cases, type may already contain the func-id
3795 * mainly in SRIOV related use cases, so we add it here only
3796 * if it's not already set.
3798 if (!(cmd_type & SPE_HDR_FUNCTION_ID)) {
3799 type = (cmd_type << SPE_HDR_CONN_TYPE_SHIFT) &
3801 type |= ((BP_FUNC(bp) << SPE_HDR_FUNCTION_ID_SHIFT) &
3802 SPE_HDR_FUNCTION_ID);
3807 spe->hdr.type = cpu_to_le16(type);
3809 spe->data.update_data_addr.hi = cpu_to_le32(data_hi);
3810 spe->data.update_data_addr.lo = cpu_to_le32(data_lo);
3813 * It's ok if the actual decrement is issued towards the memory
3814 * somewhere between the spin_lock and spin_unlock. Thus no
3815 * more explicit memory barrier is needed.
3818 atomic_dec(&bp->eq_spq_left);
3820 atomic_dec(&bp->cq_spq_left);
3823 "SPQE[%x] (%x:%x) (cmd, common?) (%d,%d) hw_cid %x data (%x:%x) type(0x%x) left (CQ, EQ) (%x,%x)\n",
3824 bp->spq_prod_idx, (u32)U64_HI(bp->spq_mapping),
3825 (u32)(U64_LO(bp->spq_mapping) +
3826 (void *)bp->spq_prod_bd - (void *)bp->spq), command, common,
3827 HW_CID(bp, cid), data_hi, data_lo, type,
3828 atomic_read(&bp->cq_spq_left), atomic_read(&bp->eq_spq_left));
3830 bnx2x_sp_prod_update(bp);
3831 spin_unlock_bh(&bp->spq_lock);
3835 /* acquire split MCP access lock register */
3836 static int bnx2x_acquire_alr(struct bnx2x *bp)
3842 for (j = 0; j < 1000; j++) {
3843 REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, MCPR_ACCESS_LOCK_LOCK);
3844 val = REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK);
3845 if (val & MCPR_ACCESS_LOCK_LOCK)
3848 usleep_range(5000, 10000);
3850 if (!(val & MCPR_ACCESS_LOCK_LOCK)) {
3851 BNX2X_ERR("Cannot acquire MCP access lock register\n");
3858 /* release split MCP access lock register */
3859 static void bnx2x_release_alr(struct bnx2x *bp)
3861 REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, 0);
3864 #define BNX2X_DEF_SB_ATT_IDX 0x0001
3865 #define BNX2X_DEF_SB_IDX 0x0002
3867 static u16 bnx2x_update_dsb_idx(struct bnx2x *bp)
3869 struct host_sp_status_block *def_sb = bp->def_status_blk;
3872 barrier(); /* status block is written to by the chip */
3873 if (bp->def_att_idx != def_sb->atten_status_block.attn_bits_index) {
3874 bp->def_att_idx = def_sb->atten_status_block.attn_bits_index;
3875 rc |= BNX2X_DEF_SB_ATT_IDX;
3878 if (bp->def_idx != def_sb->sp_sb.running_index) {
3879 bp->def_idx = def_sb->sp_sb.running_index;
3880 rc |= BNX2X_DEF_SB_IDX;
3883 /* Do not reorder: indices reading should complete before handling */
3889 * slow path service functions
3892 static void bnx2x_attn_int_asserted(struct bnx2x *bp, u32 asserted)
3894 int port = BP_PORT(bp);
3895 u32 aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
3896 MISC_REG_AEU_MASK_ATTN_FUNC_0;
3897 u32 nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 :
3898 NIG_REG_MASK_INTERRUPT_PORT0;
3903 if (bp->attn_state & asserted)
3904 BNX2X_ERR("IGU ERROR\n");
3906 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
3907 aeu_mask = REG_RD(bp, aeu_addr);
3909 DP(NETIF_MSG_HW, "aeu_mask %x newly asserted %x\n",
3910 aeu_mask, asserted);
3911 aeu_mask &= ~(asserted & 0x3ff);
3912 DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
3914 REG_WR(bp, aeu_addr, aeu_mask);
3915 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
3917 DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
3918 bp->attn_state |= asserted;
3919 DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
3921 if (asserted & ATTN_HARD_WIRED_MASK) {
3922 if (asserted & ATTN_NIG_FOR_FUNC) {
3924 bnx2x_acquire_phy_lock(bp);
3926 /* save nig interrupt mask */
3927 nig_mask = REG_RD(bp, nig_int_mask_addr);
3929 /* If nig_mask is not set, no need to call the update
3933 REG_WR(bp, nig_int_mask_addr, 0);
3935 bnx2x_link_attn(bp);
3938 /* handle unicore attn? */
3940 if (asserted & ATTN_SW_TIMER_4_FUNC)
3941 DP(NETIF_MSG_HW, "ATTN_SW_TIMER_4_FUNC!\n");
3943 if (asserted & GPIO_2_FUNC)
3944 DP(NETIF_MSG_HW, "GPIO_2_FUNC!\n");
3946 if (asserted & GPIO_3_FUNC)
3947 DP(NETIF_MSG_HW, "GPIO_3_FUNC!\n");
3949 if (asserted & GPIO_4_FUNC)
3950 DP(NETIF_MSG_HW, "GPIO_4_FUNC!\n");
3953 if (asserted & ATTN_GENERAL_ATTN_1) {
3954 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_1!\n");
3955 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_1, 0x0);
3957 if (asserted & ATTN_GENERAL_ATTN_2) {
3958 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_2!\n");
3959 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_2, 0x0);
3961 if (asserted & ATTN_GENERAL_ATTN_3) {
3962 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_3!\n");
3963 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_3, 0x0);
3966 if (asserted & ATTN_GENERAL_ATTN_4) {
3967 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_4!\n");
3968 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_4, 0x0);
3970 if (asserted & ATTN_GENERAL_ATTN_5) {
3971 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_5!\n");
3972 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_5, 0x0);
3974 if (asserted & ATTN_GENERAL_ATTN_6) {
3975 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_6!\n");
3976 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_6, 0x0);
3980 } /* if hardwired */
3982 if (bp->common.int_block == INT_BLOCK_HC)
3983 reg_addr = (HC_REG_COMMAND_REG + port*32 +
3984 COMMAND_REG_ATTN_BITS_SET);
3986 reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_SET_UPPER*8);
3988 DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", asserted,
3989 (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
3990 REG_WR(bp, reg_addr, asserted);
3992 /* now set back the mask */
3993 if (asserted & ATTN_NIG_FOR_FUNC) {
3994 /* Verify that IGU ack through BAR was written before restoring
3995 * NIG mask. This loop should exit after 2-3 iterations max.
3997 if (bp->common.int_block != INT_BLOCK_HC) {
3998 u32 cnt = 0, igu_acked;
4000 igu_acked = REG_RD(bp,
4001 IGU_REG_ATTENTION_ACK_BITS);
4002 } while (((igu_acked & ATTN_NIG_FOR_FUNC) == 0) &&
4003 (++cnt < MAX_IGU_ATTN_ACK_TO));
4006 "Failed to verify IGU ack on time\n");
4009 REG_WR(bp, nig_int_mask_addr, nig_mask);
4010 bnx2x_release_phy_lock(bp);
4014 static void bnx2x_fan_failure(struct bnx2x *bp)
4016 int port = BP_PORT(bp);
4018 /* mark the failure */
4021 dev_info.port_hw_config[port].external_phy_config);
4023 ext_phy_config &= ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK;
4024 ext_phy_config |= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE;
4025 SHMEM_WR(bp, dev_info.port_hw_config[port].external_phy_config,
4028 /* log the failure */
4029 netdev_err(bp->dev, "Fan Failure on Network Controller has caused the driver to shutdown the card to prevent permanent damage.\n"
4030 "Please contact OEM Support for assistance\n");
4032 /* Schedule device reset (unload)
4033 * This is due to some boards consuming sufficient power when driver is
4034 * up to overheat if fan fails.
4036 bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_FAN_FAILURE, 0);
4039 static void bnx2x_attn_int_deasserted0(struct bnx2x *bp, u32 attn)
4041 int port = BP_PORT(bp);
4045 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
4046 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
4048 if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) {
4050 val = REG_RD(bp, reg_offset);
4051 val &= ~AEU_INPUTS_ATTN_BITS_SPIO5;
4052 REG_WR(bp, reg_offset, val);
4054 BNX2X_ERR("SPIO5 hw attention\n");
4056 /* Fan failure attention */
4057 bnx2x_hw_reset_phy(&bp->link_params);
4058 bnx2x_fan_failure(bp);
4061 if ((attn & bp->link_vars.aeu_int_mask) && bp->port.pmf) {
4062 bnx2x_acquire_phy_lock(bp);
4063 bnx2x_handle_module_detect_int(&bp->link_params);
4064 bnx2x_release_phy_lock(bp);
4067 if (attn & HW_INTERRUT_ASSERT_SET_0) {
4069 val = REG_RD(bp, reg_offset);
4070 val &= ~(attn & HW_INTERRUT_ASSERT_SET_0);
4071 REG_WR(bp, reg_offset, val);
4073 BNX2X_ERR("FATAL HW block attention set0 0x%x\n",
4074 (u32)(attn & HW_INTERRUT_ASSERT_SET_0));
4079 static void bnx2x_attn_int_deasserted1(struct bnx2x *bp, u32 attn)
4083 if (attn & AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT) {
4085 val = REG_RD(bp, DORQ_REG_DORQ_INT_STS_CLR);
4086 BNX2X_ERR("DB hw attention 0x%x\n", val);
4087 /* DORQ discard attention */
4089 BNX2X_ERR("FATAL error from DORQ\n");
4092 if (attn & HW_INTERRUT_ASSERT_SET_1) {
4094 int port = BP_PORT(bp);
4097 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 :
4098 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1);
4100 val = REG_RD(bp, reg_offset);
4101 val &= ~(attn & HW_INTERRUT_ASSERT_SET_1);
4102 REG_WR(bp, reg_offset, val);
4104 BNX2X_ERR("FATAL HW block attention set1 0x%x\n",
4105 (u32)(attn & HW_INTERRUT_ASSERT_SET_1));
4110 static void bnx2x_attn_int_deasserted2(struct bnx2x *bp, u32 attn)
4114 if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) {
4116 val = REG_RD(bp, CFC_REG_CFC_INT_STS_CLR);
4117 BNX2X_ERR("CFC hw attention 0x%x\n", val);
4118 /* CFC error attention */
4120 BNX2X_ERR("FATAL error from CFC\n");
4123 if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) {
4124 val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_0);
4125 BNX2X_ERR("PXP hw attention-0 0x%x\n", val);
4126 /* RQ_USDMDP_FIFO_OVERFLOW */
4128 BNX2X_ERR("FATAL error from PXP\n");
4130 if (!CHIP_IS_E1x(bp)) {
4131 val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_1);
4132 BNX2X_ERR("PXP hw attention-1 0x%x\n", val);
4136 if (attn & HW_INTERRUT_ASSERT_SET_2) {
4138 int port = BP_PORT(bp);
4141 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 :
4142 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2);
4144 val = REG_RD(bp, reg_offset);
4145 val &= ~(attn & HW_INTERRUT_ASSERT_SET_2);
4146 REG_WR(bp, reg_offset, val);
4148 BNX2X_ERR("FATAL HW block attention set2 0x%x\n",
4149 (u32)(attn & HW_INTERRUT_ASSERT_SET_2));
4154 static void bnx2x_attn_int_deasserted3(struct bnx2x *bp, u32 attn)
4158 if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) {
4160 if (attn & BNX2X_PMF_LINK_ASSERT) {
4161 int func = BP_FUNC(bp);
4163 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
4164 bnx2x_read_mf_cfg(bp);
4165 bp->mf_config[BP_VN(bp)] = MF_CFG_RD(bp,
4166 func_mf_config[BP_ABS_FUNC(bp)].config);
4168 func_mb[BP_FW_MB_IDX(bp)].drv_status);
4169 if (val & DRV_STATUS_DCC_EVENT_MASK)
4171 (val & DRV_STATUS_DCC_EVENT_MASK));
4173 if (val & DRV_STATUS_SET_MF_BW)
4174 bnx2x_set_mf_bw(bp);
4176 if (val & DRV_STATUS_DRV_INFO_REQ)
4177 bnx2x_handle_drv_info_req(bp);
4179 if (val & DRV_STATUS_VF_DISABLED)
4180 bnx2x_schedule_iov_task(bp,
4181 BNX2X_IOV_HANDLE_FLR);
4183 if ((bp->port.pmf == 0) && (val & DRV_STATUS_PMF))
4184 bnx2x_pmf_update(bp);
4187 (val & DRV_STATUS_DCBX_NEGOTIATION_RESULTS) &&
4188 bp->dcbx_enabled > 0)
4189 /* start dcbx state machine */
4190 bnx2x_dcbx_set_params(bp,
4191 BNX2X_DCBX_STATE_NEG_RECEIVED);
4192 if (val & DRV_STATUS_AFEX_EVENT_MASK)
4193 bnx2x_handle_afex_cmd(bp,
4194 val & DRV_STATUS_AFEX_EVENT_MASK);
4195 if (val & DRV_STATUS_EEE_NEGOTIATION_RESULTS)
4196 bnx2x_handle_eee_event(bp);
4197 if (bp->link_vars.periodic_flags &
4198 PERIODIC_FLAGS_LINK_EVENT) {
4199 /* sync with link */
4200 bnx2x_acquire_phy_lock(bp);
4201 bp->link_vars.periodic_flags &=
4202 ~PERIODIC_FLAGS_LINK_EVENT;
4203 bnx2x_release_phy_lock(bp);
4205 bnx2x_link_sync_notify(bp);
4206 bnx2x_link_report(bp);
4208 /* Always call it here: bnx2x_link_report() will
4209 * prevent the link indication duplication.
4211 bnx2x__link_status_update(bp);
4212 } else if (attn & BNX2X_MC_ASSERT_BITS) {
4214 BNX2X_ERR("MC assert!\n");
4215 bnx2x_mc_assert(bp);
4216 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_10, 0);
4217 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_9, 0);
4218 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_8, 0);
4219 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_7, 0);
4222 } else if (attn & BNX2X_MCP_ASSERT) {
4224 BNX2X_ERR("MCP assert!\n");
4225 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_11, 0);
4229 BNX2X_ERR("Unknown HW assert! (attn 0x%x)\n", attn);
4232 if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) {
4233 BNX2X_ERR("LATCHED attention 0x%08x (masked)\n", attn);
4234 if (attn & BNX2X_GRC_TIMEOUT) {
4235 val = CHIP_IS_E1(bp) ? 0 :
4236 REG_RD(bp, MISC_REG_GRC_TIMEOUT_ATTN);
4237 BNX2X_ERR("GRC time-out 0x%08x\n", val);
4239 if (attn & BNX2X_GRC_RSV) {
4240 val = CHIP_IS_E1(bp) ? 0 :
4241 REG_RD(bp, MISC_REG_GRC_RSV_ATTN);
4242 BNX2X_ERR("GRC reserved 0x%08x\n", val);
4244 REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff);
4250 * 0-7 - Engine0 load counter.
4251 * 8-15 - Engine1 load counter.
4252 * 16 - Engine0 RESET_IN_PROGRESS bit.
4253 * 17 - Engine1 RESET_IN_PROGRESS bit.
4254 * 18 - Engine0 ONE_IS_LOADED. Set when there is at least one active function
4256 * 19 - Engine1 ONE_IS_LOADED.
4257 * 20 - Chip reset flow bit. When set none-leader must wait for both engines
4258 * leader to complete (check for both RESET_IN_PROGRESS bits and not for
4259 * just the one belonging to its engine).
4262 #define BNX2X_RECOVERY_GLOB_REG MISC_REG_GENERIC_POR_1
4264 #define BNX2X_PATH0_LOAD_CNT_MASK 0x000000ff
4265 #define BNX2X_PATH0_LOAD_CNT_SHIFT 0
4266 #define BNX2X_PATH1_LOAD_CNT_MASK 0x0000ff00
4267 #define BNX2X_PATH1_LOAD_CNT_SHIFT 8
4268 #define BNX2X_PATH0_RST_IN_PROG_BIT 0x00010000
4269 #define BNX2X_PATH1_RST_IN_PROG_BIT 0x00020000
4270 #define BNX2X_GLOBAL_RESET_BIT 0x00040000
4273 * Set the GLOBAL_RESET bit.
4275 * Should be run under rtnl lock
4277 void bnx2x_set_reset_global(struct bnx2x *bp)
4280 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
4281 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
4282 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val | BNX2X_GLOBAL_RESET_BIT);
4283 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
4287 * Clear the GLOBAL_RESET bit.
4289 * Should be run under rtnl lock
4291 static void bnx2x_clear_reset_global(struct bnx2x *bp)
4294 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
4295 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
4296 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~BNX2X_GLOBAL_RESET_BIT));
4297 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
4301 * Checks the GLOBAL_RESET bit.
4303 * should be run under rtnl lock
4305 static bool bnx2x_reset_is_global(struct bnx2x *bp)
4307 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
4309 DP(NETIF_MSG_HW, "GEN_REG_VAL=0x%08x\n", val);
4310 return (val & BNX2X_GLOBAL_RESET_BIT) ? true : false;
4314 * Clear RESET_IN_PROGRESS bit for the current engine.
4316 * Should be run under rtnl lock
4318 static void bnx2x_set_reset_done(struct bnx2x *bp)
4321 u32 bit = BP_PATH(bp) ?
4322 BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
4323 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
4324 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
4328 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
4330 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
4334 * Set RESET_IN_PROGRESS for the current engine.
4336 * should be run under rtnl lock
4338 void bnx2x_set_reset_in_progress(struct bnx2x *bp)
4341 u32 bit = BP_PATH(bp) ?
4342 BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
4343 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
4344 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
4348 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
4349 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
4353 * Checks the RESET_IN_PROGRESS bit for the given engine.
4354 * should be run under rtnl lock
4356 bool bnx2x_reset_is_done(struct bnx2x *bp, int engine)
4358 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
4360 BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
4362 /* return false if bit is set */
4363 return (val & bit) ? false : true;
4367 * set pf load for the current pf.
4369 * should be run under rtnl lock
4371 void bnx2x_set_pf_load(struct bnx2x *bp)
4374 u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
4375 BNX2X_PATH0_LOAD_CNT_MASK;
4376 u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
4377 BNX2X_PATH0_LOAD_CNT_SHIFT;
4379 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
4380 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
4382 DP(NETIF_MSG_IFUP, "Old GEN_REG_VAL=0x%08x\n", val);
4384 /* get the current counter value */
4385 val1 = (val & mask) >> shift;
4387 /* set bit of that PF */
4388 val1 |= (1 << bp->pf_num);
4390 /* clear the old value */
4393 /* set the new one */
4394 val |= ((val1 << shift) & mask);
4396 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
4397 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
4401 * bnx2x_clear_pf_load - clear pf load mark
4403 * @bp: driver handle
4405 * Should be run under rtnl lock.
4406 * Decrements the load counter for the current engine. Returns
4407 * whether other functions are still loaded
4409 bool bnx2x_clear_pf_load(struct bnx2x *bp)
4412 u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
4413 BNX2X_PATH0_LOAD_CNT_MASK;
4414 u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
4415 BNX2X_PATH0_LOAD_CNT_SHIFT;
4417 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
4418 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
4419 DP(NETIF_MSG_IFDOWN, "Old GEN_REG_VAL=0x%08x\n", val);
4421 /* get the current counter value */
4422 val1 = (val & mask) >> shift;
4424 /* clear bit of that PF */
4425 val1 &= ~(1 << bp->pf_num);
4427 /* clear the old value */
4430 /* set the new one */
4431 val |= ((val1 << shift) & mask);
4433 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
4434 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
4439 * Read the load status for the current engine.
4441 * should be run under rtnl lock
4443 static bool bnx2x_get_load_status(struct bnx2x *bp, int engine)
4445 u32 mask = (engine ? BNX2X_PATH1_LOAD_CNT_MASK :
4446 BNX2X_PATH0_LOAD_CNT_MASK);
4447 u32 shift = (engine ? BNX2X_PATH1_LOAD_CNT_SHIFT :
4448 BNX2X_PATH0_LOAD_CNT_SHIFT);
4449 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
4451 DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "GLOB_REG=0x%08x\n", val);
4453 val = (val & mask) >> shift;
4455 DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "load mask for engine %d = 0x%x\n",
4461 static void _print_parity(struct bnx2x *bp, u32 reg)
4463 pr_cont(" [0x%08x] ", REG_RD(bp, reg));
4466 static void _print_next_block(int idx, const char *blk)
4468 pr_cont("%s%s", idx ? ", " : "", blk);
4471 static bool bnx2x_check_blocks_with_parity0(struct bnx2x *bp, u32 sig,
4472 int *par_num, bool print)
4480 for (i = 0; sig; i++) {
4481 cur_bit = (0x1UL << i);
4482 if (sig & cur_bit) {
4483 res |= true; /* Each bit is real error! */
4487 case AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR:
4488 _print_next_block((*par_num)++, "BRB");
4490 BRB1_REG_BRB1_PRTY_STS);
4492 case AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR:
4493 _print_next_block((*par_num)++,
4495 _print_parity(bp, PRS_REG_PRS_PRTY_STS);
4497 case AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR:
4498 _print_next_block((*par_num)++, "TSDM");
4500 TSDM_REG_TSDM_PRTY_STS);
4502 case AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR:
4503 _print_next_block((*par_num)++,
4505 _print_parity(bp, SRC_REG_SRC_PRTY_STS);
4507 case AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR:
4508 _print_next_block((*par_num)++, "TCM");
4509 _print_parity(bp, TCM_REG_TCM_PRTY_STS);
4511 case AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR:
4512 _print_next_block((*par_num)++,
4515 TSEM_REG_TSEM_PRTY_STS_0);
4517 TSEM_REG_TSEM_PRTY_STS_1);
4519 case AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR:
4520 _print_next_block((*par_num)++, "XPB");
4521 _print_parity(bp, GRCBASE_XPB +
4522 PB_REG_PB_PRTY_STS);
4535 static bool bnx2x_check_blocks_with_parity1(struct bnx2x *bp, u32 sig,
4536 int *par_num, bool *global,
4545 for (i = 0; sig; i++) {
4546 cur_bit = (0x1UL << i);
4547 if (sig & cur_bit) {
4548 res |= true; /* Each bit is real error! */
4550 case AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR:
4552 _print_next_block((*par_num)++, "PBF");
4553 _print_parity(bp, PBF_REG_PBF_PRTY_STS);
4556 case AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR:
4558 _print_next_block((*par_num)++, "QM");
4559 _print_parity(bp, QM_REG_QM_PRTY_STS);
4562 case AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR:
4564 _print_next_block((*par_num)++, "TM");
4565 _print_parity(bp, TM_REG_TM_PRTY_STS);
4568 case AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR:
4570 _print_next_block((*par_num)++, "XSDM");
4572 XSDM_REG_XSDM_PRTY_STS);
4575 case AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR:
4577 _print_next_block((*par_num)++, "XCM");
4578 _print_parity(bp, XCM_REG_XCM_PRTY_STS);
4581 case AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR:
4583 _print_next_block((*par_num)++,
4586 XSEM_REG_XSEM_PRTY_STS_0);
4588 XSEM_REG_XSEM_PRTY_STS_1);
4591 case AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR:
4593 _print_next_block((*par_num)++,
4596 DORQ_REG_DORQ_PRTY_STS);
4599 case AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR:
4601 _print_next_block((*par_num)++, "NIG");
4602 if (CHIP_IS_E1x(bp)) {
4604 NIG_REG_NIG_PRTY_STS);
4607 NIG_REG_NIG_PRTY_STS_0);
4609 NIG_REG_NIG_PRTY_STS_1);
4613 case AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR:
4615 _print_next_block((*par_num)++,
4619 case AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR:
4621 _print_next_block((*par_num)++,
4623 _print_parity(bp, DBG_REG_DBG_PRTY_STS);
4626 case AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR:
4628 _print_next_block((*par_num)++, "USDM");
4630 USDM_REG_USDM_PRTY_STS);
4633 case AEU_INPUTS_ATTN_BITS_UCM_PARITY_ERROR:
4635 _print_next_block((*par_num)++, "UCM");
4636 _print_parity(bp, UCM_REG_UCM_PRTY_STS);
4639 case AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR:
4641 _print_next_block((*par_num)++,
4644 USEM_REG_USEM_PRTY_STS_0);
4646 USEM_REG_USEM_PRTY_STS_1);
4649 case AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR:
4651 _print_next_block((*par_num)++, "UPB");
4652 _print_parity(bp, GRCBASE_UPB +
4653 PB_REG_PB_PRTY_STS);
4656 case AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR:
4658 _print_next_block((*par_num)++, "CSDM");
4660 CSDM_REG_CSDM_PRTY_STS);
4663 case AEU_INPUTS_ATTN_BITS_CCM_PARITY_ERROR:
4665 _print_next_block((*par_num)++, "CCM");
4666 _print_parity(bp, CCM_REG_CCM_PRTY_STS);
4679 static bool bnx2x_check_blocks_with_parity2(struct bnx2x *bp, u32 sig,
4680 int *par_num, bool print)
4688 for (i = 0; sig; i++) {
4689 cur_bit = (0x1UL << i);
4690 if (sig & cur_bit) {
4691 res = true; /* Each bit is real error! */
4694 case AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR:
4695 _print_next_block((*par_num)++,
4698 CSEM_REG_CSEM_PRTY_STS_0);
4700 CSEM_REG_CSEM_PRTY_STS_1);
4702 case AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR:
4703 _print_next_block((*par_num)++, "PXP");
4704 _print_parity(bp, PXP_REG_PXP_PRTY_STS);
4706 PXP2_REG_PXP2_PRTY_STS_0);
4708 PXP2_REG_PXP2_PRTY_STS_1);
4710 case AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR:
4711 _print_next_block((*par_num)++,
4712 "PXPPCICLOCKCLIENT");
4714 case AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR:
4715 _print_next_block((*par_num)++, "CFC");
4717 CFC_REG_CFC_PRTY_STS);
4719 case AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR:
4720 _print_next_block((*par_num)++, "CDU");
4721 _print_parity(bp, CDU_REG_CDU_PRTY_STS);
4723 case AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR:
4724 _print_next_block((*par_num)++, "DMAE");
4726 DMAE_REG_DMAE_PRTY_STS);
4728 case AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR:
4729 _print_next_block((*par_num)++, "IGU");
4730 if (CHIP_IS_E1x(bp))
4732 HC_REG_HC_PRTY_STS);
4735 IGU_REG_IGU_PRTY_STS);
4737 case AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR:
4738 _print_next_block((*par_num)++, "MISC");
4740 MISC_REG_MISC_PRTY_STS);
4753 static bool bnx2x_check_blocks_with_parity3(struct bnx2x *bp, u32 sig,
4754 int *par_num, bool *global,
4761 for (i = 0; sig; i++) {
4762 cur_bit = (0x1UL << i);
4763 if (sig & cur_bit) {
4765 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY:
4767 _print_next_block((*par_num)++,
4772 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY:
4774 _print_next_block((*par_num)++,
4779 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY:
4781 _print_next_block((*par_num)++,
4786 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY:
4788 _print_next_block((*par_num)++,
4790 /* clear latched SCPAD PATIRY from MCP */
4791 REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL,
4804 static bool bnx2x_check_blocks_with_parity4(struct bnx2x *bp, u32 sig,
4805 int *par_num, bool print)
4813 for (i = 0; sig; i++) {
4814 cur_bit = (0x1UL << i);
4815 if (sig & cur_bit) {
4816 res = true; /* Each bit is real error! */
4819 case AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR:
4820 _print_next_block((*par_num)++,
4823 PGLUE_B_REG_PGLUE_B_PRTY_STS);
4825 case AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR:
4826 _print_next_block((*par_num)++, "ATC");
4828 ATC_REG_ATC_PRTY_STS);
4840 static bool bnx2x_parity_attn(struct bnx2x *bp, bool *global, bool print,
4845 if ((sig[0] & HW_PRTY_ASSERT_SET_0) ||
4846 (sig[1] & HW_PRTY_ASSERT_SET_1) ||
4847 (sig[2] & HW_PRTY_ASSERT_SET_2) ||
4848 (sig[3] & HW_PRTY_ASSERT_SET_3) ||
4849 (sig[4] & HW_PRTY_ASSERT_SET_4)) {
4851 DP(NETIF_MSG_HW, "Was parity error: HW block parity attention:\n"
4852 "[0]:0x%08x [1]:0x%08x [2]:0x%08x [3]:0x%08x [4]:0x%08x\n",
4853 sig[0] & HW_PRTY_ASSERT_SET_0,
4854 sig[1] & HW_PRTY_ASSERT_SET_1,
4855 sig[2] & HW_PRTY_ASSERT_SET_2,
4856 sig[3] & HW_PRTY_ASSERT_SET_3,
4857 sig[4] & HW_PRTY_ASSERT_SET_4);
4860 "Parity errors detected in blocks: ");
4861 res |= bnx2x_check_blocks_with_parity0(bp,
4862 sig[0] & HW_PRTY_ASSERT_SET_0, &par_num, print);
4863 res |= bnx2x_check_blocks_with_parity1(bp,
4864 sig[1] & HW_PRTY_ASSERT_SET_1, &par_num, global, print);
4865 res |= bnx2x_check_blocks_with_parity2(bp,
4866 sig[2] & HW_PRTY_ASSERT_SET_2, &par_num, print);
4867 res |= bnx2x_check_blocks_with_parity3(bp,
4868 sig[3] & HW_PRTY_ASSERT_SET_3, &par_num, global, print);
4869 res |= bnx2x_check_blocks_with_parity4(bp,
4870 sig[4] & HW_PRTY_ASSERT_SET_4, &par_num, print);
4880 * bnx2x_chk_parity_attn - checks for parity attentions.
4882 * @bp: driver handle
4883 * @global: true if there was a global attention
4884 * @print: show parity attention in syslog
4886 bool bnx2x_chk_parity_attn(struct bnx2x *bp, bool *global, bool print)
4888 struct attn_route attn = { {0} };
4889 int port = BP_PORT(bp);
4891 attn.sig[0] = REG_RD(bp,
4892 MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 +
4894 attn.sig[1] = REG_RD(bp,
4895 MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 +
4897 attn.sig[2] = REG_RD(bp,
4898 MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 +
4900 attn.sig[3] = REG_RD(bp,
4901 MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 +
4903 /* Since MCP attentions can't be disabled inside the block, we need to
4904 * read AEU registers to see whether they're currently disabled
4906 attn.sig[3] &= ((REG_RD(bp,
4907 !port ? MISC_REG_AEU_ENABLE4_FUNC_0_OUT_0
4908 : MISC_REG_AEU_ENABLE4_FUNC_1_OUT_0) &
4909 MISC_AEU_ENABLE_MCP_PRTY_BITS) |
4910 ~MISC_AEU_ENABLE_MCP_PRTY_BITS);
4912 if (!CHIP_IS_E1x(bp))
4913 attn.sig[4] = REG_RD(bp,
4914 MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 +
4917 return bnx2x_parity_attn(bp, global, print, attn.sig);
4920 static void bnx2x_attn_int_deasserted4(struct bnx2x *bp, u32 attn)
4923 if (attn & AEU_INPUTS_ATTN_BITS_PGLUE_HW_INTERRUPT) {
4925 val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS_CLR);
4926 BNX2X_ERR("PGLUE hw attention 0x%x\n", val);
4927 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR)
4928 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR\n");
4929 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR)
4930 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR\n");
4931 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN)
4932 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN\n");
4933 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN)
4934 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN\n");
4936 PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN)
4937 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN\n");
4939 PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN)
4940 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN\n");
4941 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN)
4942 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN\n");
4943 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN)
4944 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN\n");
4945 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW)
4946 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW\n");
4948 if (attn & AEU_INPUTS_ATTN_BITS_ATC_HW_INTERRUPT) {
4949 val = REG_RD(bp, ATC_REG_ATC_INT_STS_CLR);
4950 BNX2X_ERR("ATC hw attention 0x%x\n", val);
4951 if (val & ATC_ATC_INT_STS_REG_ADDRESS_ERROR)
4952 BNX2X_ERR("ATC_ATC_INT_STS_REG_ADDRESS_ERROR\n");
4953 if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND)
4954 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND\n");
4955 if (val & ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS)
4956 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS\n");
4957 if (val & ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT)
4958 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT\n");
4959 if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR)
4960 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR\n");
4961 if (val & ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU)
4962 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU\n");
4965 if (attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
4966 AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)) {
4967 BNX2X_ERR("FATAL parity attention set4 0x%x\n",
4968 (u32)(attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
4969 AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)));
4973 static void bnx2x_attn_int_deasserted(struct bnx2x *bp, u32 deasserted)
4975 struct attn_route attn, *group_mask;
4976 int port = BP_PORT(bp);
4981 bool global = false;
4983 /* need to take HW lock because MCP or other port might also
4984 try to handle this event */
4985 bnx2x_acquire_alr(bp);
4987 if (bnx2x_chk_parity_attn(bp, &global, true)) {
4988 #ifndef BNX2X_STOP_ON_ERROR
4989 bp->recovery_state = BNX2X_RECOVERY_INIT;
4990 schedule_delayed_work(&bp->sp_rtnl_task, 0);
4991 /* Disable HW interrupts */
4992 bnx2x_int_disable(bp);
4993 /* In case of parity errors don't handle attentions so that
4994 * other function would "see" parity errors.
4999 bnx2x_release_alr(bp);
5003 attn.sig[0] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4);
5004 attn.sig[1] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4);
5005 attn.sig[2] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4);
5006 attn.sig[3] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4);
5007 if (!CHIP_IS_E1x(bp))
5009 REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + port*4);
5013 DP(NETIF_MSG_HW, "attn: %08x %08x %08x %08x %08x\n",
5014 attn.sig[0], attn.sig[1], attn.sig[2], attn.sig[3], attn.sig[4]);
5016 for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
5017 if (deasserted & (1 << index)) {
5018 group_mask = &bp->attn_group[index];
5020 DP(NETIF_MSG_HW, "group[%d]: %08x %08x %08x %08x %08x\n",
5022 group_mask->sig[0], group_mask->sig[1],
5023 group_mask->sig[2], group_mask->sig[3],
5024 group_mask->sig[4]);
5026 bnx2x_attn_int_deasserted4(bp,
5027 attn.sig[4] & group_mask->sig[4]);
5028 bnx2x_attn_int_deasserted3(bp,
5029 attn.sig[3] & group_mask->sig[3]);
5030 bnx2x_attn_int_deasserted1(bp,
5031 attn.sig[1] & group_mask->sig[1]);
5032 bnx2x_attn_int_deasserted2(bp,
5033 attn.sig[2] & group_mask->sig[2]);
5034 bnx2x_attn_int_deasserted0(bp,
5035 attn.sig[0] & group_mask->sig[0]);
5039 bnx2x_release_alr(bp);
5041 if (bp->common.int_block == INT_BLOCK_HC)
5042 reg_addr = (HC_REG_COMMAND_REG + port*32 +
5043 COMMAND_REG_ATTN_BITS_CLR);
5045 reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_CLR_UPPER*8);
5048 DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", val,
5049 (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
5050 REG_WR(bp, reg_addr, val);
5052 if (~bp->attn_state & deasserted)
5053 BNX2X_ERR("IGU ERROR\n");
5055 reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
5056 MISC_REG_AEU_MASK_ATTN_FUNC_0;
5058 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
5059 aeu_mask = REG_RD(bp, reg_addr);
5061 DP(NETIF_MSG_HW, "aeu_mask %x newly deasserted %x\n",
5062 aeu_mask, deasserted);
5063 aeu_mask |= (deasserted & 0x3ff);
5064 DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
5066 REG_WR(bp, reg_addr, aeu_mask);
5067 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
5069 DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
5070 bp->attn_state &= ~deasserted;
5071 DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
5074 static void bnx2x_attn_int(struct bnx2x *bp)
5076 /* read local copy of bits */
5077 u32 attn_bits = le32_to_cpu(bp->def_status_blk->atten_status_block.
5079 u32 attn_ack = le32_to_cpu(bp->def_status_blk->atten_status_block.
5081 u32 attn_state = bp->attn_state;
5083 /* look for changed bits */
5084 u32 asserted = attn_bits & ~attn_ack & ~attn_state;
5085 u32 deasserted = ~attn_bits & attn_ack & attn_state;
5088 "attn_bits %x attn_ack %x asserted %x deasserted %x\n",
5089 attn_bits, attn_ack, asserted, deasserted);
5091 if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state))
5092 BNX2X_ERR("BAD attention state\n");
5094 /* handle bits that were raised */
5096 bnx2x_attn_int_asserted(bp, asserted);
5099 bnx2x_attn_int_deasserted(bp, deasserted);
5102 void bnx2x_igu_ack_sb(struct bnx2x *bp, u8 igu_sb_id, u8 segment,
5103 u16 index, u8 op, u8 update)
5105 u32 igu_addr = bp->igu_base_addr;
5106 igu_addr += (IGU_CMD_INT_ACK_BASE + igu_sb_id)*8;
5107 bnx2x_igu_ack_sb_gen(bp, igu_sb_id, segment, index, op, update,
5111 static void bnx2x_update_eq_prod(struct bnx2x *bp, u16 prod)
5113 /* No memory barriers */
5114 storm_memset_eq_prod(bp, prod, BP_FUNC(bp));
5115 mmiowb(); /* keep prod updates ordered */
5118 static int bnx2x_cnic_handle_cfc_del(struct bnx2x *bp, u32 cid,
5119 union event_ring_elem *elem)
5121 u8 err = elem->message.error;
5123 if (!bp->cnic_eth_dev.starting_cid ||
5124 (cid < bp->cnic_eth_dev.starting_cid &&
5125 cid != bp->cnic_eth_dev.iscsi_l2_cid))
5128 DP(BNX2X_MSG_SP, "got delete ramrod for CNIC CID %d\n", cid);
5130 if (unlikely(err)) {
5132 BNX2X_ERR("got delete ramrod for CNIC CID %d with error!\n",
5134 bnx2x_panic_dump(bp, false);
5136 bnx2x_cnic_cfc_comp(bp, cid, err);
5140 static void bnx2x_handle_mcast_eqe(struct bnx2x *bp)
5142 struct bnx2x_mcast_ramrod_params rparam;
5145 memset(&rparam, 0, sizeof(rparam));
5147 rparam.mcast_obj = &bp->mcast_obj;
5149 netif_addr_lock_bh(bp->dev);
5151 /* Clear pending state for the last command */
5152 bp->mcast_obj.raw.clear_pending(&bp->mcast_obj.raw);
5154 /* If there are pending mcast commands - send them */
5155 if (bp->mcast_obj.check_pending(&bp->mcast_obj)) {
5156 rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_CONT);
5158 BNX2X_ERR("Failed to send pending mcast commands: %d\n",
5162 netif_addr_unlock_bh(bp->dev);
5165 static void bnx2x_handle_classification_eqe(struct bnx2x *bp,
5166 union event_ring_elem *elem)
5168 unsigned long ramrod_flags = 0;
5170 u32 cid = elem->message.data.eth_event.echo & BNX2X_SWCID_MASK;
5171 struct bnx2x_vlan_mac_obj *vlan_mac_obj;
5173 /* Always push next commands out, don't wait here */
5174 __set_bit(RAMROD_CONT, &ramrod_flags);
5176 switch (le32_to_cpu((__force __le32)elem->message.data.eth_event.echo)
5177 >> BNX2X_SWCID_SHIFT) {
5178 case BNX2X_FILTER_MAC_PENDING:
5179 DP(BNX2X_MSG_SP, "Got SETUP_MAC completions\n");
5180 if (CNIC_LOADED(bp) && (cid == BNX2X_ISCSI_ETH_CID(bp)))
5181 vlan_mac_obj = &bp->iscsi_l2_mac_obj;
5183 vlan_mac_obj = &bp->sp_objs[cid].mac_obj;
5186 case BNX2X_FILTER_MCAST_PENDING:
5187 DP(BNX2X_MSG_SP, "Got SETUP_MCAST completions\n");
5188 /* This is only relevant for 57710 where multicast MACs are
5189 * configured as unicast MACs using the same ramrod.
5191 bnx2x_handle_mcast_eqe(bp);
5194 BNX2X_ERR("Unsupported classification command: %d\n",
5195 elem->message.data.eth_event.echo);
5199 rc = vlan_mac_obj->complete(bp, vlan_mac_obj, elem, &ramrod_flags);
5202 BNX2X_ERR("Failed to schedule new commands: %d\n", rc);
5204 DP(BNX2X_MSG_SP, "Scheduled next pending commands...\n");
5207 static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start);
5209 static void bnx2x_handle_rx_mode_eqe(struct bnx2x *bp)
5211 netif_addr_lock_bh(bp->dev);
5213 clear_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
5215 /* Send rx_mode command again if was requested */
5216 if (test_and_clear_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state))
5217 bnx2x_set_storm_rx_mode(bp);
5218 else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED,
5220 bnx2x_set_iscsi_eth_rx_mode(bp, true);
5221 else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED,
5223 bnx2x_set_iscsi_eth_rx_mode(bp, false);
5225 netif_addr_unlock_bh(bp->dev);
5228 static void bnx2x_after_afex_vif_lists(struct bnx2x *bp,
5229 union event_ring_elem *elem)
5231 if (elem->message.data.vif_list_event.echo == VIF_LIST_RULE_GET) {
5233 "afex: ramrod completed VIF LIST_GET, addrs 0x%x\n",
5234 elem->message.data.vif_list_event.func_bit_map);
5235 bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTGET_ACK,
5236 elem->message.data.vif_list_event.func_bit_map);
5237 } else if (elem->message.data.vif_list_event.echo ==
5238 VIF_LIST_RULE_SET) {
5239 DP(BNX2X_MSG_SP, "afex: ramrod completed VIF LIST_SET\n");
5240 bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTSET_ACK, 0);
5244 /* called with rtnl_lock */
5245 static void bnx2x_after_function_update(struct bnx2x *bp)
5248 struct bnx2x_fastpath *fp;
5249 struct bnx2x_queue_state_params queue_params = {NULL};
5250 struct bnx2x_queue_update_params *q_update_params =
5251 &queue_params.params.update;
5253 /* Send Q update command with afex vlan removal values for all Qs */
5254 queue_params.cmd = BNX2X_Q_CMD_UPDATE;
5256 /* set silent vlan removal values according to vlan mode */
5257 __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM_CHNG,
5258 &q_update_params->update_flags);
5259 __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM,
5260 &q_update_params->update_flags);
5261 __set_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
5263 /* in access mode mark mask and value are 0 to strip all vlans */
5264 if (bp->afex_vlan_mode == FUNC_MF_CFG_AFEX_VLAN_ACCESS_MODE) {
5265 q_update_params->silent_removal_value = 0;
5266 q_update_params->silent_removal_mask = 0;
5268 q_update_params->silent_removal_value =
5269 (bp->afex_def_vlan_tag & VLAN_VID_MASK);
5270 q_update_params->silent_removal_mask = VLAN_VID_MASK;
5273 for_each_eth_queue(bp, q) {
5274 /* Set the appropriate Queue object */
5276 queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
5278 /* send the ramrod */
5279 rc = bnx2x_queue_state_change(bp, &queue_params);
5281 BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
5285 if (!NO_FCOE(bp) && CNIC_ENABLED(bp)) {
5286 fp = &bp->fp[FCOE_IDX(bp)];
5287 queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
5289 /* clear pending completion bit */
5290 __clear_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
5292 /* mark latest Q bit */
5293 smp_mb__before_atomic();
5294 set_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
5295 smp_mb__after_atomic();
5297 /* send Q update ramrod for FCoE Q */
5298 rc = bnx2x_queue_state_change(bp, &queue_params);
5300 BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
5303 /* If no FCoE ring - ACK MCP now */
5304 bnx2x_link_report(bp);
5305 bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
5309 static struct bnx2x_queue_sp_obj *bnx2x_cid_to_q_obj(
5310 struct bnx2x *bp, u32 cid)
5312 DP(BNX2X_MSG_SP, "retrieving fp from cid %d\n", cid);
5314 if (CNIC_LOADED(bp) && (cid == BNX2X_FCOE_ETH_CID(bp)))
5315 return &bnx2x_fcoe_sp_obj(bp, q_obj);
5317 return &bp->sp_objs[CID_TO_FP(cid, bp)].q_obj;
5320 static void bnx2x_eq_int(struct bnx2x *bp)
5322 u16 hw_cons, sw_cons, sw_prod;
5323 union event_ring_elem *elem;
5327 int rc, spqe_cnt = 0;
5328 struct bnx2x_queue_sp_obj *q_obj;
5329 struct bnx2x_func_sp_obj *f_obj = &bp->func_obj;
5330 struct bnx2x_raw_obj *rss_raw = &bp->rss_conf_obj.raw;
5332 hw_cons = le16_to_cpu(*bp->eq_cons_sb);
5334 /* The hw_cos range is 1-255, 257 - the sw_cons range is 0-254, 256.
5335 * when we get the next-page we need to adjust so the loop
5336 * condition below will be met. The next element is the size of a
5337 * regular element and hence incrementing by 1
5339 if ((hw_cons & EQ_DESC_MAX_PAGE) == EQ_DESC_MAX_PAGE)
5342 /* This function may never run in parallel with itself for a
5343 * specific bp, thus there is no need in "paired" read memory
5346 sw_cons = bp->eq_cons;
5347 sw_prod = bp->eq_prod;
5349 DP(BNX2X_MSG_SP, "EQ: hw_cons %u sw_cons %u bp->eq_spq_left %x\n",
5350 hw_cons, sw_cons, atomic_read(&bp->eq_spq_left));
5352 for (; sw_cons != hw_cons;
5353 sw_prod = NEXT_EQ_IDX(sw_prod), sw_cons = NEXT_EQ_IDX(sw_cons)) {
5355 elem = &bp->eq_ring[EQ_DESC(sw_cons)];
5357 rc = bnx2x_iov_eq_sp_event(bp, elem);
5359 DP(BNX2X_MSG_IOV, "bnx2x_iov_eq_sp_event returned %d\n",
5364 /* elem CID originates from FW; actually LE */
5365 cid = SW_CID((__force __le32)
5366 elem->message.data.cfc_del_event.cid);
5367 opcode = elem->message.opcode;
5369 /* handle eq element */
5371 case EVENT_RING_OPCODE_VF_PF_CHANNEL:
5372 bnx2x_vf_mbx_schedule(bp,
5373 &elem->message.data.vf_pf_event);
5376 case EVENT_RING_OPCODE_STAT_QUERY:
5377 DP_AND((BNX2X_MSG_SP | BNX2X_MSG_STATS),
5378 "got statistics comp event %d\n",
5380 /* nothing to do with stats comp */
5383 case EVENT_RING_OPCODE_CFC_DEL:
5384 /* handle according to cid range */
5386 * we may want to verify here that the bp state is
5390 "got delete ramrod for MULTI[%d]\n", cid);
5392 if (CNIC_LOADED(bp) &&
5393 !bnx2x_cnic_handle_cfc_del(bp, cid, elem))
5396 q_obj = bnx2x_cid_to_q_obj(bp, cid);
5398 if (q_obj->complete_cmd(bp, q_obj, BNX2X_Q_CMD_CFC_DEL))
5403 case EVENT_RING_OPCODE_STOP_TRAFFIC:
5404 DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got STOP TRAFFIC\n");
5405 bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_PAUSED);
5406 if (f_obj->complete_cmd(bp, f_obj,
5407 BNX2X_F_CMD_TX_STOP))
5411 case EVENT_RING_OPCODE_START_TRAFFIC:
5412 DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got START TRAFFIC\n");
5413 bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_RELEASED);
5414 if (f_obj->complete_cmd(bp, f_obj,
5415 BNX2X_F_CMD_TX_START))
5419 case EVENT_RING_OPCODE_FUNCTION_UPDATE:
5420 echo = elem->message.data.function_update_event.echo;
5421 if (echo == SWITCH_UPDATE) {
5422 DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
5423 "got FUNC_SWITCH_UPDATE ramrod\n");
5424 if (f_obj->complete_cmd(
5425 bp, f_obj, BNX2X_F_CMD_SWITCH_UPDATE))
5429 int cmd = BNX2X_SP_RTNL_AFEX_F_UPDATE;
5431 DP(BNX2X_MSG_SP | BNX2X_MSG_MCP,
5432 "AFEX: ramrod completed FUNCTION_UPDATE\n");
5433 f_obj->complete_cmd(bp, f_obj,
5434 BNX2X_F_CMD_AFEX_UPDATE);
5436 /* We will perform the Queues update from
5437 * sp_rtnl task as all Queue SP operations
5438 * should run under rtnl_lock.
5440 bnx2x_schedule_sp_rtnl(bp, cmd, 0);
5445 case EVENT_RING_OPCODE_AFEX_VIF_LISTS:
5446 f_obj->complete_cmd(bp, f_obj,
5447 BNX2X_F_CMD_AFEX_VIFLISTS);
5448 bnx2x_after_afex_vif_lists(bp, elem);
5450 case EVENT_RING_OPCODE_FUNCTION_START:
5451 DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
5452 "got FUNC_START ramrod\n");
5453 if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_START))
5458 case EVENT_RING_OPCODE_FUNCTION_STOP:
5459 DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
5460 "got FUNC_STOP ramrod\n");
5461 if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_STOP))
5466 case EVENT_RING_OPCODE_SET_TIMESYNC:
5467 DP(BNX2X_MSG_SP | BNX2X_MSG_PTP,
5468 "got set_timesync ramrod completion\n");
5469 if (f_obj->complete_cmd(bp, f_obj,
5470 BNX2X_F_CMD_SET_TIMESYNC))
5475 switch (opcode | bp->state) {
5476 case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
5478 case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
5479 BNX2X_STATE_OPENING_WAIT4_PORT):
5480 cid = elem->message.data.eth_event.echo &
5482 DP(BNX2X_MSG_SP, "got RSS_UPDATE ramrod. CID %d\n",
5484 rss_raw->clear_pending(rss_raw);
5487 case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_OPEN):
5488 case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_DIAG):
5489 case (EVENT_RING_OPCODE_SET_MAC |
5490 BNX2X_STATE_CLOSING_WAIT4_HALT):
5491 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
5493 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
5495 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
5496 BNX2X_STATE_CLOSING_WAIT4_HALT):
5497 DP(BNX2X_MSG_SP, "got (un)set mac ramrod\n");
5498 bnx2x_handle_classification_eqe(bp, elem);
5501 case (EVENT_RING_OPCODE_MULTICAST_RULES |
5503 case (EVENT_RING_OPCODE_MULTICAST_RULES |
5505 case (EVENT_RING_OPCODE_MULTICAST_RULES |
5506 BNX2X_STATE_CLOSING_WAIT4_HALT):
5507 DP(BNX2X_MSG_SP, "got mcast ramrod\n");
5508 bnx2x_handle_mcast_eqe(bp);
5511 case (EVENT_RING_OPCODE_FILTERS_RULES |
5513 case (EVENT_RING_OPCODE_FILTERS_RULES |
5515 case (EVENT_RING_OPCODE_FILTERS_RULES |
5516 BNX2X_STATE_CLOSING_WAIT4_HALT):
5517 DP(BNX2X_MSG_SP, "got rx_mode ramrod\n");
5518 bnx2x_handle_rx_mode_eqe(bp);
5521 /* unknown event log error and continue */
5522 BNX2X_ERR("Unknown EQ event %d, bp->state 0x%x\n",
5523 elem->message.opcode, bp->state);
5529 smp_mb__before_atomic();
5530 atomic_add(spqe_cnt, &bp->eq_spq_left);
5532 bp->eq_cons = sw_cons;
5533 bp->eq_prod = sw_prod;
5534 /* Make sure that above mem writes were issued towards the memory */
5537 /* update producer */
5538 bnx2x_update_eq_prod(bp, bp->eq_prod);
5541 static void bnx2x_sp_task(struct work_struct *work)
5543 struct bnx2x *bp = container_of(work, struct bnx2x, sp_task.work);
5545 DP(BNX2X_MSG_SP, "sp task invoked\n");
5547 /* make sure the atomic interrupt_occurred has been written */
5549 if (atomic_read(&bp->interrupt_occurred)) {
5551 /* what work needs to be performed? */
5552 u16 status = bnx2x_update_dsb_idx(bp);
5554 DP(BNX2X_MSG_SP, "status %x\n", status);
5555 DP(BNX2X_MSG_SP, "setting interrupt_occurred to 0\n");
5556 atomic_set(&bp->interrupt_occurred, 0);
5559 if (status & BNX2X_DEF_SB_ATT_IDX) {
5561 status &= ~BNX2X_DEF_SB_ATT_IDX;
5564 /* SP events: STAT_QUERY and others */
5565 if (status & BNX2X_DEF_SB_IDX) {
5566 struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);
5568 if (FCOE_INIT(bp) &&
5569 (bnx2x_has_rx_work(fp) || bnx2x_has_tx_work(fp))) {
5570 /* Prevent local bottom-halves from running as
5571 * we are going to change the local NAPI list.
5574 napi_schedule(&bnx2x_fcoe(bp, napi));
5578 /* Handle EQ completions */
5580 bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID,
5581 le16_to_cpu(bp->def_idx), IGU_INT_NOP, 1);
5583 status &= ~BNX2X_DEF_SB_IDX;
5586 /* if status is non zero then perhaps something went wrong */
5587 if (unlikely(status))
5589 "got an unknown interrupt! (status 0x%x)\n", status);
5591 /* ack status block only if something was actually handled */
5592 bnx2x_ack_sb(bp, bp->igu_dsb_id, ATTENTION_ID,
5593 le16_to_cpu(bp->def_att_idx), IGU_INT_ENABLE, 1);
5596 /* afex - poll to check if VIFSET_ACK should be sent to MFW */
5597 if (test_and_clear_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK,
5599 bnx2x_link_report(bp);
5600 bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
5604 irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance)
5606 struct net_device *dev = dev_instance;
5607 struct bnx2x *bp = netdev_priv(dev);
5609 bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0,
5610 IGU_INT_DISABLE, 0);
5612 #ifdef BNX2X_STOP_ON_ERROR
5613 if (unlikely(bp->panic))
5617 if (CNIC_LOADED(bp)) {
5618 struct cnic_ops *c_ops;
5621 c_ops = rcu_dereference(bp->cnic_ops);
5623 c_ops->cnic_handler(bp->cnic_data, NULL);
5627 /* schedule sp task to perform default status block work, ack
5628 * attentions and enable interrupts.
5630 bnx2x_schedule_sp_task(bp);
5635 /* end of slow path */
5637 void bnx2x_drv_pulse(struct bnx2x *bp)
5639 SHMEM_WR(bp, func_mb[BP_FW_MB_IDX(bp)].drv_pulse_mb,
5640 bp->fw_drv_pulse_wr_seq);
5643 static void bnx2x_timer(unsigned long data)
5645 struct bnx2x *bp = (struct bnx2x *) data;
5647 if (!netif_running(bp->dev))
5652 int mb_idx = BP_FW_MB_IDX(bp);
5656 ++bp->fw_drv_pulse_wr_seq;
5657 bp->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK;
5658 drv_pulse = bp->fw_drv_pulse_wr_seq;
5659 bnx2x_drv_pulse(bp);
5661 mcp_pulse = (SHMEM_RD(bp, func_mb[mb_idx].mcp_pulse_mb) &
5662 MCP_PULSE_SEQ_MASK);
5663 /* The delta between driver pulse and mcp response
5664 * should not get too big. If the MFW is more than 5 pulses
5665 * behind, we should worry about it enough to generate an error
5668 if (((drv_pulse - mcp_pulse) & MCP_PULSE_SEQ_MASK) > 5)
5669 BNX2X_ERR("MFW seems hanged: drv_pulse (0x%x) != mcp_pulse (0x%x)\n",
5670 drv_pulse, mcp_pulse);
5673 if (bp->state == BNX2X_STATE_OPEN)
5674 bnx2x_stats_handle(bp, STATS_EVENT_UPDATE);
5676 /* sample pf vf bulletin board for new posts from pf */
5678 bnx2x_timer_sriov(bp);
5680 mod_timer(&bp->timer, jiffies + bp->current_interval);
5683 /* end of Statistics */
5688 * nic init service functions
5691 static void bnx2x_fill(struct bnx2x *bp, u32 addr, int fill, u32 len)
5694 if (!(len%4) && !(addr%4))
5695 for (i = 0; i < len; i += 4)
5696 REG_WR(bp, addr + i, fill);
5698 for (i = 0; i < len; i++)
5699 REG_WR8(bp, addr + i, fill);
5702 /* helper: writes FP SP data to FW - data_size in dwords */
5703 static void bnx2x_wr_fp_sb_data(struct bnx2x *bp,
5709 for (index = 0; index < data_size; index++)
5710 REG_WR(bp, BAR_CSTRORM_INTMEM +
5711 CSTORM_STATUS_BLOCK_DATA_OFFSET(fw_sb_id) +
5713 *(sb_data_p + index));
5716 static void bnx2x_zero_fp_sb(struct bnx2x *bp, int fw_sb_id)
5720 struct hc_status_block_data_e2 sb_data_e2;
5721 struct hc_status_block_data_e1x sb_data_e1x;
5723 /* disable the function first */
5724 if (!CHIP_IS_E1x(bp)) {
5725 memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
5726 sb_data_e2.common.state = SB_DISABLED;
5727 sb_data_e2.common.p_func.vf_valid = false;
5728 sb_data_p = (u32 *)&sb_data_e2;
5729 data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
5731 memset(&sb_data_e1x, 0,
5732 sizeof(struct hc_status_block_data_e1x));
5733 sb_data_e1x.common.state = SB_DISABLED;
5734 sb_data_e1x.common.p_func.vf_valid = false;
5735 sb_data_p = (u32 *)&sb_data_e1x;
5736 data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
5738 bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
5740 bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
5741 CSTORM_STATUS_BLOCK_OFFSET(fw_sb_id), 0,
5742 CSTORM_STATUS_BLOCK_SIZE);
5743 bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
5744 CSTORM_SYNC_BLOCK_OFFSET(fw_sb_id), 0,
5745 CSTORM_SYNC_BLOCK_SIZE);
5748 /* helper: writes SP SB data to FW */
5749 static void bnx2x_wr_sp_sb_data(struct bnx2x *bp,
5750 struct hc_sp_status_block_data *sp_sb_data)
5752 int func = BP_FUNC(bp);
5754 for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
5755 REG_WR(bp, BAR_CSTRORM_INTMEM +
5756 CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
5758 *((u32 *)sp_sb_data + i));
5761 static void bnx2x_zero_sp_sb(struct bnx2x *bp)
5763 int func = BP_FUNC(bp);
5764 struct hc_sp_status_block_data sp_sb_data;
5765 memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
5767 sp_sb_data.state = SB_DISABLED;
5768 sp_sb_data.p_func.vf_valid = false;
5770 bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
5772 bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
5773 CSTORM_SP_STATUS_BLOCK_OFFSET(func), 0,
5774 CSTORM_SP_STATUS_BLOCK_SIZE);
5775 bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
5776 CSTORM_SP_SYNC_BLOCK_OFFSET(func), 0,
5777 CSTORM_SP_SYNC_BLOCK_SIZE);
5780 static void bnx2x_setup_ndsb_state_machine(struct hc_status_block_sm *hc_sm,
5781 int igu_sb_id, int igu_seg_id)
5783 hc_sm->igu_sb_id = igu_sb_id;
5784 hc_sm->igu_seg_id = igu_seg_id;
5785 hc_sm->timer_value = 0xFF;
5786 hc_sm->time_to_expire = 0xFFFFFFFF;
5789 /* allocates state machine ids. */
5790 static void bnx2x_map_sb_state_machines(struct hc_index_data *index_data)
5792 /* zero out state machine indices */
5794 index_data[HC_INDEX_ETH_RX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
5797 index_data[HC_INDEX_OOO_TX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
5798 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags &= ~HC_INDEX_DATA_SM_ID;
5799 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags &= ~HC_INDEX_DATA_SM_ID;
5800 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags &= ~HC_INDEX_DATA_SM_ID;
5804 index_data[HC_INDEX_ETH_RX_CQ_CONS].flags |=
5805 SM_RX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
5808 index_data[HC_INDEX_OOO_TX_CQ_CONS].flags |=
5809 SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
5810 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags |=
5811 SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
5812 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags |=
5813 SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
5814 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags |=
5815 SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
5818 void bnx2x_init_sb(struct bnx2x *bp, dma_addr_t mapping, int vfid,
5819 u8 vf_valid, int fw_sb_id, int igu_sb_id)
5823 struct hc_status_block_data_e2 sb_data_e2;
5824 struct hc_status_block_data_e1x sb_data_e1x;
5825 struct hc_status_block_sm *hc_sm_p;
5829 if (CHIP_INT_MODE_IS_BC(bp))
5830 igu_seg_id = HC_SEG_ACCESS_NORM;
5832 igu_seg_id = IGU_SEG_ACCESS_NORM;
5834 bnx2x_zero_fp_sb(bp, fw_sb_id);
5836 if (!CHIP_IS_E1x(bp)) {
5837 memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
5838 sb_data_e2.common.state = SB_ENABLED;
5839 sb_data_e2.common.p_func.pf_id = BP_FUNC(bp);
5840 sb_data_e2.common.p_func.vf_id = vfid;
5841 sb_data_e2.common.p_func.vf_valid = vf_valid;
5842 sb_data_e2.common.p_func.vnic_id = BP_VN(bp);
5843 sb_data_e2.common.same_igu_sb_1b = true;
5844 sb_data_e2.common.host_sb_addr.hi = U64_HI(mapping);
5845 sb_data_e2.common.host_sb_addr.lo = U64_LO(mapping);
5846 hc_sm_p = sb_data_e2.common.state_machine;
5847 sb_data_p = (u32 *)&sb_data_e2;
5848 data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
5849 bnx2x_map_sb_state_machines(sb_data_e2.index_data);
5851 memset(&sb_data_e1x, 0,
5852 sizeof(struct hc_status_block_data_e1x));
5853 sb_data_e1x.common.state = SB_ENABLED;
5854 sb_data_e1x.common.p_func.pf_id = BP_FUNC(bp);
5855 sb_data_e1x.common.p_func.vf_id = 0xff;
5856 sb_data_e1x.common.p_func.vf_valid = false;
5857 sb_data_e1x.common.p_func.vnic_id = BP_VN(bp);
5858 sb_data_e1x.common.same_igu_sb_1b = true;
5859 sb_data_e1x.common.host_sb_addr.hi = U64_HI(mapping);
5860 sb_data_e1x.common.host_sb_addr.lo = U64_LO(mapping);
5861 hc_sm_p = sb_data_e1x.common.state_machine;
5862 sb_data_p = (u32 *)&sb_data_e1x;
5863 data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
5864 bnx2x_map_sb_state_machines(sb_data_e1x.index_data);
5867 bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_RX_ID],
5868 igu_sb_id, igu_seg_id);
5869 bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_TX_ID],
5870 igu_sb_id, igu_seg_id);
5872 DP(NETIF_MSG_IFUP, "Init FW SB %d\n", fw_sb_id);
5874 /* write indices to HW - PCI guarantees endianity of regpairs */
5875 bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
5878 static void bnx2x_update_coalesce_sb(struct bnx2x *bp, u8 fw_sb_id,
5879 u16 tx_usec, u16 rx_usec)
5881 bnx2x_update_coalesce_sb_index(bp, fw_sb_id, HC_INDEX_ETH_RX_CQ_CONS,
5883 bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
5884 HC_INDEX_ETH_TX_CQ_CONS_COS0, false,
5886 bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
5887 HC_INDEX_ETH_TX_CQ_CONS_COS1, false,
5889 bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
5890 HC_INDEX_ETH_TX_CQ_CONS_COS2, false,
5894 static void bnx2x_init_def_sb(struct bnx2x *bp)
5896 struct host_sp_status_block *def_sb = bp->def_status_blk;
5897 dma_addr_t mapping = bp->def_status_blk_mapping;
5898 int igu_sp_sb_index;
5900 int port = BP_PORT(bp);
5901 int func = BP_FUNC(bp);
5902 int reg_offset, reg_offset_en5;
5905 struct hc_sp_status_block_data sp_sb_data;
5906 memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
5908 if (CHIP_INT_MODE_IS_BC(bp)) {
5909 igu_sp_sb_index = DEF_SB_IGU_ID;
5910 igu_seg_id = HC_SEG_ACCESS_DEF;
5912 igu_sp_sb_index = bp->igu_dsb_id;
5913 igu_seg_id = IGU_SEG_ACCESS_DEF;
5917 section = ((u64)mapping) + offsetof(struct host_sp_status_block,
5918 atten_status_block);
5919 def_sb->atten_status_block.status_block_id = igu_sp_sb_index;
5923 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
5924 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
5925 reg_offset_en5 = (port ? MISC_REG_AEU_ENABLE5_FUNC_1_OUT_0 :
5926 MISC_REG_AEU_ENABLE5_FUNC_0_OUT_0);
5927 for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
5929 /* take care of sig[0]..sig[4] */
5930 for (sindex = 0; sindex < 4; sindex++)
5931 bp->attn_group[index].sig[sindex] =
5932 REG_RD(bp, reg_offset + sindex*0x4 + 0x10*index);
5934 if (!CHIP_IS_E1x(bp))
5936 * enable5 is separate from the rest of the registers,
5937 * and therefore the address skip is 4
5938 * and not 16 between the different groups
5940 bp->attn_group[index].sig[4] = REG_RD(bp,
5941 reg_offset_en5 + 0x4*index);
5943 bp->attn_group[index].sig[4] = 0;
5946 if (bp->common.int_block == INT_BLOCK_HC) {
5947 reg_offset = (port ? HC_REG_ATTN_MSG1_ADDR_L :
5948 HC_REG_ATTN_MSG0_ADDR_L);
5950 REG_WR(bp, reg_offset, U64_LO(section));
5951 REG_WR(bp, reg_offset + 4, U64_HI(section));
5952 } else if (!CHIP_IS_E1x(bp)) {
5953 REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_L, U64_LO(section));
5954 REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_H, U64_HI(section));
5957 section = ((u64)mapping) + offsetof(struct host_sp_status_block,
5960 bnx2x_zero_sp_sb(bp);
5962 /* PCI guarantees endianity of regpairs */
5963 sp_sb_data.state = SB_ENABLED;
5964 sp_sb_data.host_sb_addr.lo = U64_LO(section);
5965 sp_sb_data.host_sb_addr.hi = U64_HI(section);
5966 sp_sb_data.igu_sb_id = igu_sp_sb_index;
5967 sp_sb_data.igu_seg_id = igu_seg_id;
5968 sp_sb_data.p_func.pf_id = func;
5969 sp_sb_data.p_func.vnic_id = BP_VN(bp);
5970 sp_sb_data.p_func.vf_id = 0xff;
5972 bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
5974 bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0, IGU_INT_ENABLE, 0);
5977 void bnx2x_update_coalesce(struct bnx2x *bp)
5981 for_each_eth_queue(bp, i)
5982 bnx2x_update_coalesce_sb(bp, bp->fp[i].fw_sb_id,
5983 bp->tx_ticks, bp->rx_ticks);
5986 static void bnx2x_init_sp_ring(struct bnx2x *bp)
5988 spin_lock_init(&bp->spq_lock);
5989 atomic_set(&bp->cq_spq_left, MAX_SPQ_PENDING);
5991 bp->spq_prod_idx = 0;
5992 bp->dsb_sp_prod = BNX2X_SP_DSB_INDEX;
5993 bp->spq_prod_bd = bp->spq;
5994 bp->spq_last_bd = bp->spq_prod_bd + MAX_SP_DESC_CNT;
5997 static void bnx2x_init_eq_ring(struct bnx2x *bp)
6000 for (i = 1; i <= NUM_EQ_PAGES; i++) {
6001 union event_ring_elem *elem =
6002 &bp->eq_ring[EQ_DESC_CNT_PAGE * i - 1];
6004 elem->next_page.addr.hi =
6005 cpu_to_le32(U64_HI(bp->eq_mapping +
6006 BCM_PAGE_SIZE * (i % NUM_EQ_PAGES)));
6007 elem->next_page.addr.lo =
6008 cpu_to_le32(U64_LO(bp->eq_mapping +
6009 BCM_PAGE_SIZE*(i % NUM_EQ_PAGES)));
6012 bp->eq_prod = NUM_EQ_DESC;
6013 bp->eq_cons_sb = BNX2X_EQ_INDEX;
6014 /* we want a warning message before it gets wrought... */
6015 atomic_set(&bp->eq_spq_left,
6016 min_t(int, MAX_SP_DESC_CNT - MAX_SPQ_PENDING, NUM_EQ_DESC) - 1);
6019 /* called with netif_addr_lock_bh() */
6020 static int bnx2x_set_q_rx_mode(struct bnx2x *bp, u8 cl_id,
6021 unsigned long rx_mode_flags,
6022 unsigned long rx_accept_flags,
6023 unsigned long tx_accept_flags,
6024 unsigned long ramrod_flags)
6026 struct bnx2x_rx_mode_ramrod_params ramrod_param;
6029 memset(&ramrod_param, 0, sizeof(ramrod_param));
6031 /* Prepare ramrod parameters */
6032 ramrod_param.cid = 0;
6033 ramrod_param.cl_id = cl_id;
6034 ramrod_param.rx_mode_obj = &bp->rx_mode_obj;
6035 ramrod_param.func_id = BP_FUNC(bp);
6037 ramrod_param.pstate = &bp->sp_state;
6038 ramrod_param.state = BNX2X_FILTER_RX_MODE_PENDING;
6040 ramrod_param.rdata = bnx2x_sp(bp, rx_mode_rdata);
6041 ramrod_param.rdata_mapping = bnx2x_sp_mapping(bp, rx_mode_rdata);
6043 set_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
6045 ramrod_param.ramrod_flags = ramrod_flags;
6046 ramrod_param.rx_mode_flags = rx_mode_flags;
6048 ramrod_param.rx_accept_flags = rx_accept_flags;
6049 ramrod_param.tx_accept_flags = tx_accept_flags;
6051 rc = bnx2x_config_rx_mode(bp, &ramrod_param);
6053 BNX2X_ERR("Set rx_mode %d failed\n", bp->rx_mode);
6060 static int bnx2x_fill_accept_flags(struct bnx2x *bp, u32 rx_mode,
6061 unsigned long *rx_accept_flags,
6062 unsigned long *tx_accept_flags)
6064 /* Clear the flags first */
6065 *rx_accept_flags = 0;
6066 *tx_accept_flags = 0;
6069 case BNX2X_RX_MODE_NONE:
6071 * 'drop all' supersedes any accept flags that may have been
6072 * passed to the function.
6075 case BNX2X_RX_MODE_NORMAL:
6076 __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
6077 __set_bit(BNX2X_ACCEPT_MULTICAST, rx_accept_flags);
6078 __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
6080 /* internal switching mode */
6081 __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
6082 __set_bit(BNX2X_ACCEPT_MULTICAST, tx_accept_flags);
6083 __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
6086 case BNX2X_RX_MODE_ALLMULTI:
6087 __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
6088 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, rx_accept_flags);
6089 __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
6091 /* internal switching mode */
6092 __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
6093 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, tx_accept_flags);
6094 __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
6097 case BNX2X_RX_MODE_PROMISC:
6098 /* According to definition of SI mode, iface in promisc mode
6099 * should receive matched and unmatched (in resolution of port)
6102 __set_bit(BNX2X_ACCEPT_UNMATCHED, rx_accept_flags);
6103 __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
6104 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, rx_accept_flags);
6105 __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
6107 /* internal switching mode */
6108 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, tx_accept_flags);
6109 __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
6112 __set_bit(BNX2X_ACCEPT_ALL_UNICAST, tx_accept_flags);
6114 __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
6118 BNX2X_ERR("Unknown rx_mode: %d\n", rx_mode);
6122 /* Set ACCEPT_ANY_VLAN as we do not enable filtering by VLAN */
6123 if (rx_mode != BNX2X_RX_MODE_NONE) {
6124 __set_bit(BNX2X_ACCEPT_ANY_VLAN, rx_accept_flags);
6125 __set_bit(BNX2X_ACCEPT_ANY_VLAN, tx_accept_flags);
6131 /* called with netif_addr_lock_bh() */
6132 static int bnx2x_set_storm_rx_mode(struct bnx2x *bp)
6134 unsigned long rx_mode_flags = 0, ramrod_flags = 0;
6135 unsigned long rx_accept_flags = 0, tx_accept_flags = 0;
6139 /* Configure rx_mode of FCoE Queue */
6140 __set_bit(BNX2X_RX_MODE_FCOE_ETH, &rx_mode_flags);
6142 rc = bnx2x_fill_accept_flags(bp, bp->rx_mode, &rx_accept_flags,
6147 __set_bit(RAMROD_RX, &ramrod_flags);
6148 __set_bit(RAMROD_TX, &ramrod_flags);
6150 return bnx2x_set_q_rx_mode(bp, bp->fp->cl_id, rx_mode_flags,
6151 rx_accept_flags, tx_accept_flags,
6155 static void bnx2x_init_internal_common(struct bnx2x *bp)
6159 /* Zero this manually as its initialization is
6160 currently missing in the initTool */
6161 for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++)
6162 REG_WR(bp, BAR_USTRORM_INTMEM +
6163 USTORM_AGG_DATA_OFFSET + i * 4, 0);
6164 if (!CHIP_IS_E1x(bp)) {
6165 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_IGU_MODE_OFFSET,
6166 CHIP_INT_MODE_IS_BC(bp) ?
6167 HC_IGU_BC_MODE : HC_IGU_NBC_MODE);
6171 static void bnx2x_init_internal(struct bnx2x *bp, u32 load_code)
6173 switch (load_code) {
6174 case FW_MSG_CODE_DRV_LOAD_COMMON:
6175 case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP:
6176 bnx2x_init_internal_common(bp);
6179 case FW_MSG_CODE_DRV_LOAD_PORT:
6183 case FW_MSG_CODE_DRV_LOAD_FUNCTION:
6184 /* internal memory per function is
6185 initialized inside bnx2x_pf_init */
6189 BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code);
6194 static inline u8 bnx2x_fp_igu_sb_id(struct bnx2x_fastpath *fp)
6196 return fp->bp->igu_base_sb + fp->index + CNIC_SUPPORT(fp->bp);
6199 static inline u8 bnx2x_fp_fw_sb_id(struct bnx2x_fastpath *fp)
6201 return fp->bp->base_fw_ndsb + fp->index + CNIC_SUPPORT(fp->bp);
6204 static u8 bnx2x_fp_cl_id(struct bnx2x_fastpath *fp)
6206 if (CHIP_IS_E1x(fp->bp))
6207 return BP_L_ID(fp->bp) + fp->index;
6208 else /* We want Client ID to be the same as IGU SB ID for 57712 */
6209 return bnx2x_fp_igu_sb_id(fp);
6212 static void bnx2x_init_eth_fp(struct bnx2x *bp, int fp_idx)
6214 struct bnx2x_fastpath *fp = &bp->fp[fp_idx];
6216 unsigned long q_type = 0;
6217 u32 cids[BNX2X_MULTI_TX_COS] = { 0 };
6218 fp->rx_queue = fp_idx;
6220 fp->cl_id = bnx2x_fp_cl_id(fp);
6221 fp->fw_sb_id = bnx2x_fp_fw_sb_id(fp);
6222 fp->igu_sb_id = bnx2x_fp_igu_sb_id(fp);
6223 /* qZone id equals to FW (per path) client id */
6224 fp->cl_qzone_id = bnx2x_fp_qzone_id(fp);
6227 fp->ustorm_rx_prods_offset = bnx2x_rx_ustorm_prods_offset(fp);
6229 /* Setup SB indices */
6230 fp->rx_cons_sb = BNX2X_RX_SB_INDEX;
6232 /* Configure Queue State object */
6233 __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
6234 __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
6236 BUG_ON(fp->max_cos > BNX2X_MULTI_TX_COS);
6239 for_each_cos_in_tx_queue(fp, cos) {
6240 bnx2x_init_txdata(bp, fp->txdata_ptr[cos],
6241 CID_COS_TO_TX_ONLY_CID(fp->cid, cos, bp),
6242 FP_COS_TO_TXQ(fp, cos, bp),
6243 BNX2X_TX_SB_INDEX_BASE + cos, fp);
6244 cids[cos] = fp->txdata_ptr[cos]->cid;
6247 /* nothing more for vf to do here */
6251 bnx2x_init_sb(bp, fp->status_blk_mapping, BNX2X_VF_ID_INVALID, false,
6252 fp->fw_sb_id, fp->igu_sb_id);
6253 bnx2x_update_fpsb_idx(fp);
6254 bnx2x_init_queue_obj(bp, &bnx2x_sp_obj(bp, fp).q_obj, fp->cl_id, cids,
6255 fp->max_cos, BP_FUNC(bp), bnx2x_sp(bp, q_rdata),
6256 bnx2x_sp_mapping(bp, q_rdata), q_type);
6259 * Configure classification DBs: Always enable Tx switching
6261 bnx2x_init_vlan_mac_fp_objs(fp, BNX2X_OBJ_TYPE_RX_TX);
6264 "queue[%d]: bnx2x_init_sb(%p,%p) cl_id %d fw_sb %d igu_sb %d\n",
6265 fp_idx, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id,
6269 static void bnx2x_init_tx_ring_one(struct bnx2x_fp_txdata *txdata)
6273 for (i = 1; i <= NUM_TX_RINGS; i++) {
6274 struct eth_tx_next_bd *tx_next_bd =
6275 &txdata->tx_desc_ring[TX_DESC_CNT * i - 1].next_bd;
6277 tx_next_bd->addr_hi =
6278 cpu_to_le32(U64_HI(txdata->tx_desc_mapping +
6279 BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
6280 tx_next_bd->addr_lo =
6281 cpu_to_le32(U64_LO(txdata->tx_desc_mapping +
6282 BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
6285 *txdata->tx_cons_sb = cpu_to_le16(0);
6287 SET_FLAG(txdata->tx_db.data.header.header, DOORBELL_HDR_DB_TYPE, 1);
6288 txdata->tx_db.data.zero_fill1 = 0;
6289 txdata->tx_db.data.prod = 0;
6291 txdata->tx_pkt_prod = 0;
6292 txdata->tx_pkt_cons = 0;
6293 txdata->tx_bd_prod = 0;
6294 txdata->tx_bd_cons = 0;
6298 static void bnx2x_init_tx_rings_cnic(struct bnx2x *bp)
6302 for_each_tx_queue_cnic(bp, i)
6303 bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[0]);
6306 static void bnx2x_init_tx_rings(struct bnx2x *bp)
6311 for_each_eth_queue(bp, i)
6312 for_each_cos_in_tx_queue(&bp->fp[i], cos)
6313 bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[cos]);
6316 static void bnx2x_init_fcoe_fp(struct bnx2x *bp)
6318 struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);
6319 unsigned long q_type = 0;
6321 bnx2x_fcoe(bp, rx_queue) = BNX2X_NUM_ETH_QUEUES(bp);
6322 bnx2x_fcoe(bp, cl_id) = bnx2x_cnic_eth_cl_id(bp,
6323 BNX2X_FCOE_ETH_CL_ID_IDX);
6324 bnx2x_fcoe(bp, cid) = BNX2X_FCOE_ETH_CID(bp);
6325 bnx2x_fcoe(bp, fw_sb_id) = DEF_SB_ID;
6326 bnx2x_fcoe(bp, igu_sb_id) = bp->igu_dsb_id;
6327 bnx2x_fcoe(bp, rx_cons_sb) = BNX2X_FCOE_L2_RX_INDEX;
6328 bnx2x_init_txdata(bp, bnx2x_fcoe(bp, txdata_ptr[0]),
6329 fp->cid, FCOE_TXQ_IDX(bp), BNX2X_FCOE_L2_TX_INDEX,
6332 DP(NETIF_MSG_IFUP, "created fcoe tx data (fp index %d)\n", fp->index);
6334 /* qZone id equals to FW (per path) client id */
6335 bnx2x_fcoe(bp, cl_qzone_id) = bnx2x_fp_qzone_id(fp);
6337 bnx2x_fcoe(bp, ustorm_rx_prods_offset) =
6338 bnx2x_rx_ustorm_prods_offset(fp);
6340 /* Configure Queue State object */
6341 __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
6342 __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
6344 /* No multi-CoS for FCoE L2 client */
6345 BUG_ON(fp->max_cos != 1);
6347 bnx2x_init_queue_obj(bp, &bnx2x_sp_obj(bp, fp).q_obj, fp->cl_id,
6348 &fp->cid, 1, BP_FUNC(bp), bnx2x_sp(bp, q_rdata),
6349 bnx2x_sp_mapping(bp, q_rdata), q_type);
6352 "queue[%d]: bnx2x_init_sb(%p,%p) cl_id %d fw_sb %d igu_sb %d\n",
6353 fp->index, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id,
6357 void bnx2x_nic_init_cnic(struct bnx2x *bp)
6360 bnx2x_init_fcoe_fp(bp);
6362 bnx2x_init_sb(bp, bp->cnic_sb_mapping,
6363 BNX2X_VF_ID_INVALID, false,
6364 bnx2x_cnic_fw_sb_id(bp), bnx2x_cnic_igu_sb_id(bp));
6366 /* ensure status block indices were read */
6368 bnx2x_init_rx_rings_cnic(bp);
6369 bnx2x_init_tx_rings_cnic(bp);
6376 void bnx2x_pre_irq_nic_init(struct bnx2x *bp)
6380 /* Setup NIC internals and enable interrupts */
6381 for_each_eth_queue(bp, i)
6382 bnx2x_init_eth_fp(bp, i);
6384 /* ensure status block indices were read */
6386 bnx2x_init_rx_rings(bp);
6387 bnx2x_init_tx_rings(bp);
6390 /* Initialize MOD_ABS interrupts */
6391 bnx2x_init_mod_abs_int(bp, &bp->link_vars, bp->common.chip_id,
6392 bp->common.shmem_base,
6393 bp->common.shmem2_base, BP_PORT(bp));
6395 /* initialize the default status block and sp ring */
6396 bnx2x_init_def_sb(bp);
6397 bnx2x_update_dsb_idx(bp);
6398 bnx2x_init_sp_ring(bp);
6400 bnx2x_memset_stats(bp);
6404 void bnx2x_post_irq_nic_init(struct bnx2x *bp, u32 load_code)
6406 bnx2x_init_eq_ring(bp);
6407 bnx2x_init_internal(bp, load_code);
6409 bnx2x_stats_init(bp);
6411 /* flush all before enabling interrupts */
6415 bnx2x_int_enable(bp);
6417 /* Check for SPIO5 */
6418 bnx2x_attn_int_deasserted0(bp,
6419 REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + BP_PORT(bp)*4) &
6420 AEU_INPUTS_ATTN_BITS_SPIO5);
6423 /* gzip service functions */
6424 static int bnx2x_gunzip_init(struct bnx2x *bp)
6426 bp->gunzip_buf = dma_alloc_coherent(&bp->pdev->dev, FW_BUF_SIZE,
6427 &bp->gunzip_mapping, GFP_KERNEL);
6428 if (bp->gunzip_buf == NULL)
6431 bp->strm = kmalloc(sizeof(*bp->strm), GFP_KERNEL);
6432 if (bp->strm == NULL)
6435 bp->strm->workspace = vmalloc(zlib_inflate_workspacesize());
6436 if (bp->strm->workspace == NULL)
6446 dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
6447 bp->gunzip_mapping);
6448 bp->gunzip_buf = NULL;
6451 BNX2X_ERR("Cannot allocate firmware buffer for un-compression\n");
6455 static void bnx2x_gunzip_end(struct bnx2x *bp)
6458 vfree(bp->strm->workspace);
6463 if (bp->gunzip_buf) {
6464 dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
6465 bp->gunzip_mapping);
6466 bp->gunzip_buf = NULL;
6470 static int bnx2x_gunzip(struct bnx2x *bp, const u8 *zbuf, int len)
6474 /* check gzip header */
6475 if ((zbuf[0] != 0x1f) || (zbuf[1] != 0x8b) || (zbuf[2] != Z_DEFLATED)) {
6476 BNX2X_ERR("Bad gzip header\n");
6484 if (zbuf[3] & FNAME)
6485 while ((zbuf[n++] != 0) && (n < len));
6487 bp->strm->next_in = (typeof(bp->strm->next_in))zbuf + n;
6488 bp->strm->avail_in = len - n;
6489 bp->strm->next_out = bp->gunzip_buf;
6490 bp->strm->avail_out = FW_BUF_SIZE;
6492 rc = zlib_inflateInit2(bp->strm, -MAX_WBITS);
6496 rc = zlib_inflate(bp->strm, Z_FINISH);
6497 if ((rc != Z_OK) && (rc != Z_STREAM_END))
6498 netdev_err(bp->dev, "Firmware decompression error: %s\n",
6501 bp->gunzip_outlen = (FW_BUF_SIZE - bp->strm->avail_out);
6502 if (bp->gunzip_outlen & 0x3)
6504 "Firmware decompression error: gunzip_outlen (%d) not aligned\n",
6506 bp->gunzip_outlen >>= 2;
6508 zlib_inflateEnd(bp->strm);
6510 if (rc == Z_STREAM_END)
6516 /* nic load/unload */
6519 * General service functions
6522 /* send a NIG loopback debug packet */
6523 static void bnx2x_lb_pckt(struct bnx2x *bp)
6527 /* Ethernet source and destination addresses */
6528 wb_write[0] = 0x55555555;
6529 wb_write[1] = 0x55555555;
6530 wb_write[2] = 0x20; /* SOP */
6531 REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
6533 /* NON-IP protocol */
6534 wb_write[0] = 0x09000000;
6535 wb_write[1] = 0x55555555;
6536 wb_write[2] = 0x10; /* EOP, eop_bvalid = 0 */
6537 REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
6540 /* some of the internal memories
6541 * are not directly readable from the driver
6542 * to test them we send debug packets
6544 static int bnx2x_int_mem_test(struct bnx2x *bp)
6550 if (CHIP_REV_IS_FPGA(bp))
6552 else if (CHIP_REV_IS_EMUL(bp))
6557 /* Disable inputs of parser neighbor blocks */
6558 REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
6559 REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
6560 REG_WR(bp, CFC_REG_DEBUG0, 0x1);
6561 REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
6563 /* Write 0 to parser credits for CFC search request */
6564 REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
6566 /* send Ethernet packet */
6569 /* TODO do i reset NIG statistic? */
6570 /* Wait until NIG register shows 1 packet of size 0x10 */
6571 count = 1000 * factor;
6574 bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
6575 val = *bnx2x_sp(bp, wb_data[0]);
6579 usleep_range(10000, 20000);
6583 BNX2X_ERR("NIG timeout val = 0x%x\n", val);
6587 /* Wait until PRS register shows 1 packet */
6588 count = 1000 * factor;
6590 val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
6594 usleep_range(10000, 20000);
6598 BNX2X_ERR("PRS timeout val = 0x%x\n", val);
6602 /* Reset and init BRB, PRS */
6603 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
6605 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
6607 bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
6608 bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
6610 DP(NETIF_MSG_HW, "part2\n");
6612 /* Disable inputs of parser neighbor blocks */
6613 REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
6614 REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
6615 REG_WR(bp, CFC_REG_DEBUG0, 0x1);
6616 REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
6618 /* Write 0 to parser credits for CFC search request */
6619 REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
6621 /* send 10 Ethernet packets */
6622 for (i = 0; i < 10; i++)
6625 /* Wait until NIG register shows 10 + 1
6626 packets of size 11*0x10 = 0xb0 */
6627 count = 1000 * factor;
6630 bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
6631 val = *bnx2x_sp(bp, wb_data[0]);
6635 usleep_range(10000, 20000);
6639 BNX2X_ERR("NIG timeout val = 0x%x\n", val);
6643 /* Wait until PRS register shows 2 packets */
6644 val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
6646 BNX2X_ERR("PRS timeout val = 0x%x\n", val);
6648 /* Write 1 to parser credits for CFC search request */
6649 REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x1);
6651 /* Wait until PRS register shows 3 packets */
6652 msleep(10 * factor);
6653 /* Wait until NIG register shows 1 packet of size 0x10 */
6654 val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
6656 BNX2X_ERR("PRS timeout val = 0x%x\n", val);
6658 /* clear NIG EOP FIFO */
6659 for (i = 0; i < 11; i++)
6660 REG_RD(bp, NIG_REG_INGRESS_EOP_LB_FIFO);
6661 val = REG_RD(bp, NIG_REG_INGRESS_EOP_LB_EMPTY);
6663 BNX2X_ERR("clear of NIG failed\n");
6667 /* Reset and init BRB, PRS, NIG */
6668 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
6670 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
6672 bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
6673 bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
6674 if (!CNIC_SUPPORT(bp))
6676 REG_WR(bp, PRS_REG_NIC_MODE, 1);
6678 /* Enable inputs of parser neighbor blocks */
6679 REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x7fffffff);
6680 REG_WR(bp, TCM_REG_PRS_IFEN, 0x1);
6681 REG_WR(bp, CFC_REG_DEBUG0, 0x0);
6682 REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x1);
6684 DP(NETIF_MSG_HW, "done\n");
6689 static void bnx2x_enable_blocks_attention(struct bnx2x *bp)
6693 REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
6694 if (!CHIP_IS_E1x(bp))
6695 REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0x40);
6697 REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0);
6698 REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
6699 REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
6701 * mask read length error interrupts in brb for parser
6702 * (parsing unit and 'checksum and crc' unit)
6703 * these errors are legal (PU reads fixed length and CAC can cause
6704 * read length error on truncated packets)
6706 REG_WR(bp, BRB1_REG_BRB1_INT_MASK, 0xFC00);
6707 REG_WR(bp, QM_REG_QM_INT_MASK, 0);
6708 REG_WR(bp, TM_REG_TM_INT_MASK, 0);
6709 REG_WR(bp, XSDM_REG_XSDM_INT_MASK_0, 0);
6710 REG_WR(bp, XSDM_REG_XSDM_INT_MASK_1, 0);
6711 REG_WR(bp, XCM_REG_XCM_INT_MASK, 0);
6712 /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_0, 0); */
6713 /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_1, 0); */
6714 REG_WR(bp, USDM_REG_USDM_INT_MASK_0, 0);
6715 REG_WR(bp, USDM_REG_USDM_INT_MASK_1, 0);
6716 REG_WR(bp, UCM_REG_UCM_INT_MASK, 0);
6717 /* REG_WR(bp, USEM_REG_USEM_INT_MASK_0, 0); */
6718 /* REG_WR(bp, USEM_REG_USEM_INT_MASK_1, 0); */
6719 REG_WR(bp, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0);
6720 REG_WR(bp, CSDM_REG_CSDM_INT_MASK_0, 0);
6721 REG_WR(bp, CSDM_REG_CSDM_INT_MASK_1, 0);
6722 REG_WR(bp, CCM_REG_CCM_INT_MASK, 0);
6723 /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_0, 0); */
6724 /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_1, 0); */
6726 val = PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_AFT |
6727 PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_OF |
6728 PXP2_PXP2_INT_MASK_0_REG_PGL_PCIE_ATTN;
6729 if (!CHIP_IS_E1x(bp))
6730 val |= PXP2_PXP2_INT_MASK_0_REG_PGL_READ_BLOCKED |
6731 PXP2_PXP2_INT_MASK_0_REG_PGL_WRITE_BLOCKED;
6732 REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, val);
6734 REG_WR(bp, TSDM_REG_TSDM_INT_MASK_0, 0);
6735 REG_WR(bp, TSDM_REG_TSDM_INT_MASK_1, 0);
6736 REG_WR(bp, TCM_REG_TCM_INT_MASK, 0);
6737 /* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_0, 0); */
6739 if (!CHIP_IS_E1x(bp))
6740 /* enable VFC attentions: bits 11 and 12, bits 31:13 reserved */
6741 REG_WR(bp, TSEM_REG_TSEM_INT_MASK_1, 0x07ff);
6743 REG_WR(bp, CDU_REG_CDU_INT_MASK, 0);
6744 REG_WR(bp, DMAE_REG_DMAE_INT_MASK, 0);
6745 /* REG_WR(bp, MISC_REG_MISC_INT_MASK, 0); */
6746 REG_WR(bp, PBF_REG_PBF_INT_MASK, 0x18); /* bit 3,4 masked */
6749 static void bnx2x_reset_common(struct bnx2x *bp)
6754 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
6757 if (CHIP_IS_E3(bp)) {
6758 val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
6759 val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
6762 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, val);
6765 static void bnx2x_setup_dmae(struct bnx2x *bp)
6768 spin_lock_init(&bp->dmae_lock);
6771 static void bnx2x_init_pxp(struct bnx2x *bp)
6774 int r_order, w_order;
6776 pcie_capability_read_word(bp->pdev, PCI_EXP_DEVCTL, &devctl);
6777 DP(NETIF_MSG_HW, "read 0x%x from devctl\n", devctl);
6778 w_order = ((devctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5);
6780 r_order = ((devctl & PCI_EXP_DEVCTL_READRQ) >> 12);
6782 DP(NETIF_MSG_HW, "force read order to %d\n", bp->mrrs);
6786 bnx2x_init_pxp_arb(bp, r_order, w_order);
6789 static void bnx2x_setup_fan_failure_detection(struct bnx2x *bp)
6799 val = SHMEM_RD(bp, dev_info.shared_hw_config.config2) &
6800 SHARED_HW_CFG_FAN_FAILURE_MASK;
6802 if (val == SHARED_HW_CFG_FAN_FAILURE_ENABLED)
6806 * The fan failure mechanism is usually related to the PHY type since
6807 * the power consumption of the board is affected by the PHY. Currently,
6808 * fan is required for most designs with SFX7101, BCM8727 and BCM8481.
6810 else if (val == SHARED_HW_CFG_FAN_FAILURE_PHY_TYPE)
6811 for (port = PORT_0; port < PORT_MAX; port++) {
6813 bnx2x_fan_failure_det_req(
6815 bp->common.shmem_base,
6816 bp->common.shmem2_base,
6820 DP(NETIF_MSG_HW, "fan detection setting: %d\n", is_required);
6822 if (is_required == 0)
6825 /* Fan failure is indicated by SPIO 5 */
6826 bnx2x_set_spio(bp, MISC_SPIO_SPIO5, MISC_SPIO_INPUT_HI_Z);
6828 /* set to active low mode */
6829 val = REG_RD(bp, MISC_REG_SPIO_INT);
6830 val |= (MISC_SPIO_SPIO5 << MISC_SPIO_INT_OLD_SET_POS);
6831 REG_WR(bp, MISC_REG_SPIO_INT, val);
6833 /* enable interrupt to signal the IGU */
6834 val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
6835 val |= MISC_SPIO_SPIO5;
6836 REG_WR(bp, MISC_REG_SPIO_EVENT_EN, val);
6839 void bnx2x_pf_disable(struct bnx2x *bp)
6841 u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
6842 val &= ~IGU_PF_CONF_FUNC_EN;
6844 REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
6845 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
6846 REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 0);
6849 static void bnx2x__common_init_phy(struct bnx2x *bp)
6851 u32 shmem_base[2], shmem2_base[2];
6852 /* Avoid common init in case MFW supports LFA */
6853 if (SHMEM2_RD(bp, size) >
6854 (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
6856 shmem_base[0] = bp->common.shmem_base;
6857 shmem2_base[0] = bp->common.shmem2_base;
6858 if (!CHIP_IS_E1x(bp)) {
6860 SHMEM2_RD(bp, other_shmem_base_addr);
6862 SHMEM2_RD(bp, other_shmem2_base_addr);
6864 bnx2x_acquire_phy_lock(bp);
6865 bnx2x_common_init_phy(bp, shmem_base, shmem2_base,
6866 bp->common.chip_id);
6867 bnx2x_release_phy_lock(bp);
6871 * bnx2x_init_hw_common - initialize the HW at the COMMON phase.
6873 * @bp: driver handle
6875 static int bnx2x_init_hw_common(struct bnx2x *bp)
6879 DP(NETIF_MSG_HW, "starting common init func %d\n", BP_ABS_FUNC(bp));
6882 * take the RESET lock to protect undi_unload flow from accessing
6883 * registers while we're resetting the chip
6885 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
6887 bnx2x_reset_common(bp);
6888 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0xffffffff);
6891 if (CHIP_IS_E3(bp)) {
6892 val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
6893 val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
6895 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, val);
6897 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
6899 bnx2x_init_block(bp, BLOCK_MISC, PHASE_COMMON);
6901 if (!CHIP_IS_E1x(bp)) {
6905 * 4-port mode or 2-port mode we need to turn of master-enable
6906 * for everyone, after that, turn it back on for self.
6907 * so, we disregard multi-function or not, and always disable
6908 * for all functions on the given path, this means 0,2,4,6 for
6909 * path 0 and 1,3,5,7 for path 1
6911 for (abs_func_id = BP_PATH(bp);
6912 abs_func_id < E2_FUNC_MAX*2; abs_func_id += 2) {
6913 if (abs_func_id == BP_ABS_FUNC(bp)) {
6915 PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER,
6920 bnx2x_pretend_func(bp, abs_func_id);
6921 /* clear pf enable */
6922 bnx2x_pf_disable(bp);
6923 bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
6927 bnx2x_init_block(bp, BLOCK_PXP, PHASE_COMMON);
6928 if (CHIP_IS_E1(bp)) {
6929 /* enable HW interrupt from PXP on USDM overflow
6930 bit 16 on INT_MASK_0 */
6931 REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
6934 bnx2x_init_block(bp, BLOCK_PXP2, PHASE_COMMON);
6938 REG_WR(bp, PXP2_REG_RQ_QM_ENDIAN_M, 1);
6939 REG_WR(bp, PXP2_REG_RQ_TM_ENDIAN_M, 1);
6940 REG_WR(bp, PXP2_REG_RQ_SRC_ENDIAN_M, 1);
6941 REG_WR(bp, PXP2_REG_RQ_CDU_ENDIAN_M, 1);
6942 REG_WR(bp, PXP2_REG_RQ_DBG_ENDIAN_M, 1);
6943 /* make sure this value is 0 */
6944 REG_WR(bp, PXP2_REG_RQ_HC_ENDIAN_M, 0);
6946 /* REG_WR(bp, PXP2_REG_RD_PBF_SWAP_MODE, 1); */
6947 REG_WR(bp, PXP2_REG_RD_QM_SWAP_MODE, 1);
6948 REG_WR(bp, PXP2_REG_RD_TM_SWAP_MODE, 1);
6949 REG_WR(bp, PXP2_REG_RD_SRC_SWAP_MODE, 1);
6950 REG_WR(bp, PXP2_REG_RD_CDURD_SWAP_MODE, 1);
6953 bnx2x_ilt_init_page_size(bp, INITOP_SET);
6955 if (CHIP_REV_IS_FPGA(bp) && CHIP_IS_E1H(bp))
6956 REG_WR(bp, PXP2_REG_PGL_TAGS_LIMIT, 0x1);
6958 /* let the HW do it's magic ... */
6960 /* finish PXP init */
6961 val = REG_RD(bp, PXP2_REG_RQ_CFG_DONE);
6963 BNX2X_ERR("PXP2 CFG failed\n");
6966 val = REG_RD(bp, PXP2_REG_RD_INIT_DONE);
6968 BNX2X_ERR("PXP2 RD_INIT failed\n");
6972 /* Timers bug workaround E2 only. We need to set the entire ILT to
6973 * have entries with value "0" and valid bit on.
6974 * This needs to be done by the first PF that is loaded in a path
6975 * (i.e. common phase)
6977 if (!CHIP_IS_E1x(bp)) {
6978 /* In E2 there is a bug in the timers block that can cause function 6 / 7
6979 * (i.e. vnic3) to start even if it is marked as "scan-off".
6980 * This occurs when a different function (func2,3) is being marked
6981 * as "scan-off". Real-life scenario for example: if a driver is being
6982 * load-unloaded while func6,7 are down. This will cause the timer to access
6983 * the ilt, translate to a logical address and send a request to read/write.
6984 * Since the ilt for the function that is down is not valid, this will cause
6985 * a translation error which is unrecoverable.
6986 * The Workaround is intended to make sure that when this happens nothing fatal
6987 * will occur. The workaround:
6988 * 1. First PF driver which loads on a path will:
6989 * a. After taking the chip out of reset, by using pretend,
6990 * it will write "0" to the following registers of
6992 * REG_WR(pdev, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
6993 * REG_WR(pdev, CFC_REG_WEAK_ENABLE_PF,0);
6994 * REG_WR(pdev, CFC_REG_STRONG_ENABLE_PF,0);
6995 * And for itself it will write '1' to
6996 * PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER to enable
6997 * dmae-operations (writing to pram for example.)
6998 * note: can be done for only function 6,7 but cleaner this
7000 * b. Write zero+valid to the entire ILT.
7001 * c. Init the first_timers_ilt_entry, last_timers_ilt_entry of
7002 * VNIC3 (of that port). The range allocated will be the
7003 * entire ILT. This is needed to prevent ILT range error.
7004 * 2. Any PF driver load flow:
7005 * a. ILT update with the physical addresses of the allocated
7007 * b. Wait 20msec. - note that this timeout is needed to make
7008 * sure there are no requests in one of the PXP internal
7009 * queues with "old" ILT addresses.
7010 * c. PF enable in the PGLC.
7011 * d. Clear the was_error of the PF in the PGLC. (could have
7012 * occurred while driver was down)
7013 * e. PF enable in the CFC (WEAK + STRONG)
7014 * f. Timers scan enable
7015 * 3. PF driver unload flow:
7016 * a. Clear the Timers scan_en.
7017 * b. Polling for scan_on=0 for that PF.
7018 * c. Clear the PF enable bit in the PXP.
7019 * d. Clear the PF enable in the CFC (WEAK + STRONG)
7020 * e. Write zero+valid to all ILT entries (The valid bit must
7022 * f. If this is VNIC 3 of a port then also init
7023 * first_timers_ilt_entry to zero and last_timers_ilt_entry
7024 * to the last entry in the ILT.
7027 * Currently the PF error in the PGLC is non recoverable.
7028 * In the future the there will be a recovery routine for this error.
7029 * Currently attention is masked.
7030 * Having an MCP lock on the load/unload process does not guarantee that
7031 * there is no Timer disable during Func6/7 enable. This is because the
7032 * Timers scan is currently being cleared by the MCP on FLR.
7033 * Step 2.d can be done only for PF6/7 and the driver can also check if
7034 * there is error before clearing it. But the flow above is simpler and
7036 * All ILT entries are written by zero+valid and not just PF6/7
7037 * ILT entries since in the future the ILT entries allocation for
7038 * PF-s might be dynamic.
7040 struct ilt_client_info ilt_cli;
7041 struct bnx2x_ilt ilt;
7042 memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
7043 memset(&ilt, 0, sizeof(struct bnx2x_ilt));
7045 /* initialize dummy TM client */
7047 ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
7048 ilt_cli.client_num = ILT_CLIENT_TM;
7050 /* Step 1: set zeroes to all ilt page entries with valid bit on
7051 * Step 2: set the timers first/last ilt entry to point
7052 * to the entire range to prevent ILT range error for 3rd/4th
7053 * vnic (this code assumes existence of the vnic)
7055 * both steps performed by call to bnx2x_ilt_client_init_op()
7056 * with dummy TM client
7058 * we must use pretend since PXP2_REG_RQ_##blk##_FIRST_ILT
7059 * and his brother are split registers
7061 bnx2x_pretend_func(bp, (BP_PATH(bp) + 6));
7062 bnx2x_ilt_client_init_op_ilt(bp, &ilt, &ilt_cli, INITOP_CLEAR);
7063 bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
7065 REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN, BNX2X_PXP_DRAM_ALIGN);
7066 REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_RD, BNX2X_PXP_DRAM_ALIGN);
7067 REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_SEL, 1);
7070 REG_WR(bp, PXP2_REG_RQ_DISABLE_INPUTS, 0);
7071 REG_WR(bp, PXP2_REG_RD_DISABLE_INPUTS, 0);
7073 if (!CHIP_IS_E1x(bp)) {
7074 int factor = CHIP_REV_IS_EMUL(bp) ? 1000 :
7075 (CHIP_REV_IS_FPGA(bp) ? 400 : 0);
7076 bnx2x_init_block(bp, BLOCK_PGLUE_B, PHASE_COMMON);
7078 bnx2x_init_block(bp, BLOCK_ATC, PHASE_COMMON);
7080 /* let the HW do it's magic ... */
7083 val = REG_RD(bp, ATC_REG_ATC_INIT_DONE);
7084 } while (factor-- && (val != 1));
7087 BNX2X_ERR("ATC_INIT failed\n");
7092 bnx2x_init_block(bp, BLOCK_DMAE, PHASE_COMMON);
7094 bnx2x_iov_init_dmae(bp);
7096 /* clean the DMAE memory */
7098 bnx2x_init_fill(bp, TSEM_REG_PRAM, 0, 8, 1);
7100 bnx2x_init_block(bp, BLOCK_TCM, PHASE_COMMON);
7102 bnx2x_init_block(bp, BLOCK_UCM, PHASE_COMMON);
7104 bnx2x_init_block(bp, BLOCK_CCM, PHASE_COMMON);
7106 bnx2x_init_block(bp, BLOCK_XCM, PHASE_COMMON);
7108 bnx2x_read_dmae(bp, XSEM_REG_PASSIVE_BUFFER, 3);
7109 bnx2x_read_dmae(bp, CSEM_REG_PASSIVE_BUFFER, 3);
7110 bnx2x_read_dmae(bp, TSEM_REG_PASSIVE_BUFFER, 3);
7111 bnx2x_read_dmae(bp, USEM_REG_PASSIVE_BUFFER, 3);
7113 bnx2x_init_block(bp, BLOCK_QM, PHASE_COMMON);
7115 /* QM queues pointers table */
7116 bnx2x_qm_init_ptr_table(bp, bp->qm_cid_count, INITOP_SET);
7118 /* soft reset pulse */
7119 REG_WR(bp, QM_REG_SOFT_RESET, 1);
7120 REG_WR(bp, QM_REG_SOFT_RESET, 0);
7122 if (CNIC_SUPPORT(bp))
7123 bnx2x_init_block(bp, BLOCK_TM, PHASE_COMMON);
7125 bnx2x_init_block(bp, BLOCK_DORQ, PHASE_COMMON);
7127 if (!CHIP_REV_IS_SLOW(bp))
7128 /* enable hw interrupt from doorbell Q */
7129 REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
7131 bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
7133 bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
7134 REG_WR(bp, PRS_REG_A_PRSU_20, 0xf);
7136 if (!CHIP_IS_E1(bp))
7137 REG_WR(bp, PRS_REG_E1HOV_MODE, bp->path_has_ovlan);
7139 if (!CHIP_IS_E1x(bp) && !CHIP_IS_E3B0(bp)) {
7140 if (IS_MF_AFEX(bp)) {
7141 /* configure that VNTag and VLAN headers must be
7142 * received in afex mode
7144 REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC, 0xE);
7145 REG_WR(bp, PRS_REG_MUST_HAVE_HDRS, 0xA);
7146 REG_WR(bp, PRS_REG_HDRS_AFTER_TAG_0, 0x6);
7147 REG_WR(bp, PRS_REG_TAG_ETHERTYPE_0, 0x8926);
7148 REG_WR(bp, PRS_REG_TAG_LEN_0, 0x4);
7150 /* Bit-map indicating which L2 hdrs may appear
7151 * after the basic Ethernet header
7153 REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC,
7154 bp->path_has_ovlan ? 7 : 6);
7158 bnx2x_init_block(bp, BLOCK_TSDM, PHASE_COMMON);
7159 bnx2x_init_block(bp, BLOCK_CSDM, PHASE_COMMON);
7160 bnx2x_init_block(bp, BLOCK_USDM, PHASE_COMMON);
7161 bnx2x_init_block(bp, BLOCK_XSDM, PHASE_COMMON);
7163 if (!CHIP_IS_E1x(bp)) {
7164 /* reset VFC memories */
7165 REG_WR(bp, TSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
7166 VFC_MEMORIES_RST_REG_CAM_RST |
7167 VFC_MEMORIES_RST_REG_RAM_RST);
7168 REG_WR(bp, XSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
7169 VFC_MEMORIES_RST_REG_CAM_RST |
7170 VFC_MEMORIES_RST_REG_RAM_RST);
7175 bnx2x_init_block(bp, BLOCK_TSEM, PHASE_COMMON);
7176 bnx2x_init_block(bp, BLOCK_USEM, PHASE_COMMON);
7177 bnx2x_init_block(bp, BLOCK_CSEM, PHASE_COMMON);
7178 bnx2x_init_block(bp, BLOCK_XSEM, PHASE_COMMON);
7181 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
7183 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
7186 bnx2x_init_block(bp, BLOCK_UPB, PHASE_COMMON);
7187 bnx2x_init_block(bp, BLOCK_XPB, PHASE_COMMON);
7188 bnx2x_init_block(bp, BLOCK_PBF, PHASE_COMMON);
7190 if (!CHIP_IS_E1x(bp)) {
7191 if (IS_MF_AFEX(bp)) {
7192 /* configure that VNTag and VLAN headers must be
7195 REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC, 0xE);
7196 REG_WR(bp, PBF_REG_MUST_HAVE_HDRS, 0xA);
7197 REG_WR(bp, PBF_REG_HDRS_AFTER_TAG_0, 0x6);
7198 REG_WR(bp, PBF_REG_TAG_ETHERTYPE_0, 0x8926);
7199 REG_WR(bp, PBF_REG_TAG_LEN_0, 0x4);
7201 REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC,
7202 bp->path_has_ovlan ? 7 : 6);
7206 REG_WR(bp, SRC_REG_SOFT_RST, 1);
7208 bnx2x_init_block(bp, BLOCK_SRC, PHASE_COMMON);
7210 if (CNIC_SUPPORT(bp)) {
7211 REG_WR(bp, SRC_REG_KEYSEARCH_0, 0x63285672);
7212 REG_WR(bp, SRC_REG_KEYSEARCH_1, 0x24b8f2cc);
7213 REG_WR(bp, SRC_REG_KEYSEARCH_2, 0x223aef9b);
7214 REG_WR(bp, SRC_REG_KEYSEARCH_3, 0x26001e3a);
7215 REG_WR(bp, SRC_REG_KEYSEARCH_4, 0x7ae91116);
7216 REG_WR(bp, SRC_REG_KEYSEARCH_5, 0x5ce5230b);
7217 REG_WR(bp, SRC_REG_KEYSEARCH_6, 0x298d8adf);
7218 REG_WR(bp, SRC_REG_KEYSEARCH_7, 0x6eb0ff09);
7219 REG_WR(bp, SRC_REG_KEYSEARCH_8, 0x1830f82f);
7220 REG_WR(bp, SRC_REG_KEYSEARCH_9, 0x01e46be7);
7222 REG_WR(bp, SRC_REG_SOFT_RST, 0);
7224 if (sizeof(union cdu_context) != 1024)
7225 /* we currently assume that a context is 1024 bytes */
7226 dev_alert(&bp->pdev->dev,
7227 "please adjust the size of cdu_context(%ld)\n",
7228 (long)sizeof(union cdu_context));
7230 bnx2x_init_block(bp, BLOCK_CDU, PHASE_COMMON);
7231 val = (4 << 24) + (0 << 12) + 1024;
7232 REG_WR(bp, CDU_REG_CDU_GLOBAL_PARAMS, val);
7234 bnx2x_init_block(bp, BLOCK_CFC, PHASE_COMMON);
7235 REG_WR(bp, CFC_REG_INIT_REG, 0x7FF);
7236 /* enable context validation interrupt from CFC */
7237 REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
7239 /* set the thresholds to prevent CFC/CDU race */
7240 REG_WR(bp, CFC_REG_DEBUG0, 0x20020000);
7242 bnx2x_init_block(bp, BLOCK_HC, PHASE_COMMON);
7244 if (!CHIP_IS_E1x(bp) && BP_NOMCP(bp))
7245 REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x36);
7247 bnx2x_init_block(bp, BLOCK_IGU, PHASE_COMMON);
7248 bnx2x_init_block(bp, BLOCK_MISC_AEU, PHASE_COMMON);
7250 /* Reset PCIE errors for debug */
7251 REG_WR(bp, 0x2814, 0xffffffff);
7252 REG_WR(bp, 0x3820, 0xffffffff);
7254 if (!CHIP_IS_E1x(bp)) {
7255 REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_CONTROL_5,
7256 (PXPCS_TL_CONTROL_5_ERR_UNSPPORT1 |
7257 PXPCS_TL_CONTROL_5_ERR_UNSPPORT));
7258 REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC345_STAT,
7259 (PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT4 |
7260 PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT3 |
7261 PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT2));
7262 REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC678_STAT,
7263 (PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT7 |
7264 PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT6 |
7265 PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT5));
7268 bnx2x_init_block(bp, BLOCK_NIG, PHASE_COMMON);
7269 if (!CHIP_IS_E1(bp)) {
7270 /* in E3 this done in per-port section */
7271 if (!CHIP_IS_E3(bp))
7272 REG_WR(bp, NIG_REG_LLH_MF_MODE, IS_MF(bp));
7274 if (CHIP_IS_E1H(bp))
7275 /* not applicable for E2 (and above ...) */
7276 REG_WR(bp, NIG_REG_LLH_E1HOV_MODE, IS_MF_SD(bp));
7278 if (CHIP_REV_IS_SLOW(bp))
7281 /* finish CFC init */
7282 val = reg_poll(bp, CFC_REG_LL_INIT_DONE, 1, 100, 10);
7284 BNX2X_ERR("CFC LL_INIT failed\n");
7287 val = reg_poll(bp, CFC_REG_AC_INIT_DONE, 1, 100, 10);
7289 BNX2X_ERR("CFC AC_INIT failed\n");
7292 val = reg_poll(bp, CFC_REG_CAM_INIT_DONE, 1, 100, 10);
7294 BNX2X_ERR("CFC CAM_INIT failed\n");
7297 REG_WR(bp, CFC_REG_DEBUG0, 0);
7299 if (CHIP_IS_E1(bp)) {
7300 /* read NIG statistic
7301 to see if this is our first up since powerup */
7302 bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
7303 val = *bnx2x_sp(bp, wb_data[0]);
7305 /* do internal memory self test */
7306 if ((val == 0) && bnx2x_int_mem_test(bp)) {
7307 BNX2X_ERR("internal mem self test failed\n");
7312 bnx2x_setup_fan_failure_detection(bp);
7314 /* clear PXP2 attentions */
7315 REG_RD(bp, PXP2_REG_PXP2_INT_STS_CLR_0);
7317 bnx2x_enable_blocks_attention(bp);
7318 bnx2x_enable_blocks_parity(bp);
7320 if (!BP_NOMCP(bp)) {
7321 if (CHIP_IS_E1x(bp))
7322 bnx2x__common_init_phy(bp);
7324 BNX2X_ERR("Bootcode is missing - can not initialize link\n");
7330 * bnx2x_init_hw_common_chip - init HW at the COMMON_CHIP phase.
7332 * @bp: driver handle
7334 static int bnx2x_init_hw_common_chip(struct bnx2x *bp)
7336 int rc = bnx2x_init_hw_common(bp);
7341 /* In E2 2-PORT mode, same ext phy is used for the two paths */
7343 bnx2x__common_init_phy(bp);
7348 static int bnx2x_init_hw_port(struct bnx2x *bp)
7350 int port = BP_PORT(bp);
7351 int init_phase = port ? PHASE_PORT1 : PHASE_PORT0;
7355 DP(NETIF_MSG_HW, "starting port init port %d\n", port);
7357 REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
7359 bnx2x_init_block(bp, BLOCK_MISC, init_phase);
7360 bnx2x_init_block(bp, BLOCK_PXP, init_phase);
7361 bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
7363 /* Timers bug workaround: disables the pf_master bit in pglue at
7364 * common phase, we need to enable it here before any dmae access are
7365 * attempted. Therefore we manually added the enable-master to the
7366 * port phase (it also happens in the function phase)
7368 if (!CHIP_IS_E1x(bp))
7369 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
7371 bnx2x_init_block(bp, BLOCK_ATC, init_phase);
7372 bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
7373 bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
7374 bnx2x_init_block(bp, BLOCK_QM, init_phase);
7376 bnx2x_init_block(bp, BLOCK_TCM, init_phase);
7377 bnx2x_init_block(bp, BLOCK_UCM, init_phase);
7378 bnx2x_init_block(bp, BLOCK_CCM, init_phase);
7379 bnx2x_init_block(bp, BLOCK_XCM, init_phase);
7381 /* QM cid (connection) count */
7382 bnx2x_qm_init_cid_count(bp, bp->qm_cid_count, INITOP_SET);
7384 if (CNIC_SUPPORT(bp)) {
7385 bnx2x_init_block(bp, BLOCK_TM, init_phase);
7386 REG_WR(bp, TM_REG_LIN0_SCAN_TIME + port*4, 20);
7387 REG_WR(bp, TM_REG_LIN0_MAX_ACTIVE_CID + port*4, 31);
7390 bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
7392 bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
7394 if (CHIP_IS_E1(bp) || CHIP_IS_E1H(bp)) {
7397 low = ((bp->flags & ONE_PORT_FLAG) ? 160 : 246);
7398 else if (bp->dev->mtu > 4096) {
7399 if (bp->flags & ONE_PORT_FLAG)
7403 /* (24*1024 + val*4)/256 */
7404 low = 96 + (val/64) +
7405 ((val % 64) ? 1 : 0);
7408 low = ((bp->flags & ONE_PORT_FLAG) ? 80 : 160);
7409 high = low + 56; /* 14*1024/256 */
7410 REG_WR(bp, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port*4, low);
7411 REG_WR(bp, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port*4, high);
7414 if (CHIP_MODE_IS_4_PORT(bp))
7415 REG_WR(bp, (BP_PORT(bp) ?
7416 BRB1_REG_MAC_GUARANTIED_1 :
7417 BRB1_REG_MAC_GUARANTIED_0), 40);
7419 bnx2x_init_block(bp, BLOCK_PRS, init_phase);
7420 if (CHIP_IS_E3B0(bp)) {
7421 if (IS_MF_AFEX(bp)) {
7422 /* configure headers for AFEX mode */
7423 REG_WR(bp, BP_PORT(bp) ?
7424 PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
7425 PRS_REG_HDRS_AFTER_BASIC_PORT_0, 0xE);
7426 REG_WR(bp, BP_PORT(bp) ?
7427 PRS_REG_HDRS_AFTER_TAG_0_PORT_1 :
7428 PRS_REG_HDRS_AFTER_TAG_0_PORT_0, 0x6);
7429 REG_WR(bp, BP_PORT(bp) ?
7430 PRS_REG_MUST_HAVE_HDRS_PORT_1 :
7431 PRS_REG_MUST_HAVE_HDRS_PORT_0, 0xA);
7433 /* Ovlan exists only if we are in multi-function +
7434 * switch-dependent mode, in switch-independent there
7435 * is no ovlan headers
7437 REG_WR(bp, BP_PORT(bp) ?
7438 PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
7439 PRS_REG_HDRS_AFTER_BASIC_PORT_0,
7440 (bp->path_has_ovlan ? 7 : 6));
7444 bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
7445 bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
7446 bnx2x_init_block(bp, BLOCK_USDM, init_phase);
7447 bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
7449 bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
7450 bnx2x_init_block(bp, BLOCK_USEM, init_phase);
7451 bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
7452 bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
7454 bnx2x_init_block(bp, BLOCK_UPB, init_phase);
7455 bnx2x_init_block(bp, BLOCK_XPB, init_phase);
7457 bnx2x_init_block(bp, BLOCK_PBF, init_phase);
7459 if (CHIP_IS_E1x(bp)) {
7460 /* configure PBF to work without PAUSE mtu 9000 */
7461 REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
7463 /* update threshold */
7464 REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, (9040/16));
7465 /* update init credit */
7466 REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, (9040/16) + 553 - 22);
7469 REG_WR(bp, PBF_REG_INIT_P0 + port*4, 1);
7471 REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0);
7474 if (CNIC_SUPPORT(bp))
7475 bnx2x_init_block(bp, BLOCK_SRC, init_phase);
7477 bnx2x_init_block(bp, BLOCK_CDU, init_phase);
7478 bnx2x_init_block(bp, BLOCK_CFC, init_phase);
7480 if (CHIP_IS_E1(bp)) {
7481 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
7482 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
7484 bnx2x_init_block(bp, BLOCK_HC, init_phase);
7486 bnx2x_init_block(bp, BLOCK_IGU, init_phase);
7488 bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
7489 /* init aeu_mask_attn_func_0/1:
7490 * - SF mode: bits 3-7 are masked. Only bits 0-2 are in use
7491 * - MF mode: bit 3 is masked. Bits 0-2 are in use as in SF
7492 * bits 4-7 are used for "per vn group attention" */
7493 val = IS_MF(bp) ? 0xF7 : 0x7;
7494 /* Enable DCBX attention for all but E1 */
7495 val |= CHIP_IS_E1(bp) ? 0 : 0x10;
7496 REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, val);
7498 /* SCPAD_PARITY should NOT trigger close the gates */
7499 reg = port ? MISC_REG_AEU_ENABLE4_NIG_1 : MISC_REG_AEU_ENABLE4_NIG_0;
7502 ~AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY);
7504 reg = port ? MISC_REG_AEU_ENABLE4_PXP_1 : MISC_REG_AEU_ENABLE4_PXP_0;
7507 ~AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY);
7509 bnx2x_init_block(bp, BLOCK_NIG, init_phase);
7511 if (!CHIP_IS_E1x(bp)) {
7512 /* Bit-map indicating which L2 hdrs may appear after the
7513 * basic Ethernet header
7516 REG_WR(bp, BP_PORT(bp) ?
7517 NIG_REG_P1_HDRS_AFTER_BASIC :
7518 NIG_REG_P0_HDRS_AFTER_BASIC, 0xE);
7520 REG_WR(bp, BP_PORT(bp) ?
7521 NIG_REG_P1_HDRS_AFTER_BASIC :
7522 NIG_REG_P0_HDRS_AFTER_BASIC,
7523 IS_MF_SD(bp) ? 7 : 6);
7526 REG_WR(bp, BP_PORT(bp) ?
7527 NIG_REG_LLH1_MF_MODE :
7528 NIG_REG_LLH_MF_MODE, IS_MF(bp));
7530 if (!CHIP_IS_E3(bp))
7531 REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
7533 if (!CHIP_IS_E1(bp)) {
7534 /* 0x2 disable mf_ov, 0x1 enable */
7535 REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port*4,
7536 (IS_MF_SD(bp) ? 0x1 : 0x2));
7538 if (!CHIP_IS_E1x(bp)) {
7540 switch (bp->mf_mode) {
7541 case MULTI_FUNCTION_SD:
7544 case MULTI_FUNCTION_SI:
7545 case MULTI_FUNCTION_AFEX:
7550 REG_WR(bp, (BP_PORT(bp) ? NIG_REG_LLH1_CLS_TYPE :
7551 NIG_REG_LLH0_CLS_TYPE), val);
7554 REG_WR(bp, NIG_REG_LLFC_ENABLE_0 + port*4, 0);
7555 REG_WR(bp, NIG_REG_LLFC_OUT_EN_0 + port*4, 0);
7556 REG_WR(bp, NIG_REG_PAUSE_ENABLE_0 + port*4, 1);
7560 /* If SPIO5 is set to generate interrupts, enable it for this port */
7561 val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
7562 if (val & MISC_SPIO_SPIO5) {
7563 u32 reg_addr = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
7564 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
7565 val = REG_RD(bp, reg_addr);
7566 val |= AEU_INPUTS_ATTN_BITS_SPIO5;
7567 REG_WR(bp, reg_addr, val);
7573 static void bnx2x_ilt_wr(struct bnx2x *bp, u32 index, dma_addr_t addr)
7579 reg = PXP2_REG_RQ_ONCHIP_AT + index*8;
7581 reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index*8;
7583 wb_write[0] = ONCHIP_ADDR1(addr);
7584 wb_write[1] = ONCHIP_ADDR2(addr);
7585 REG_WR_DMAE(bp, reg, wb_write, 2);
7588 void bnx2x_igu_clear_sb_gen(struct bnx2x *bp, u8 func, u8 idu_sb_id, bool is_pf)
7590 u32 data, ctl, cnt = 100;
7591 u32 igu_addr_data = IGU_REG_COMMAND_REG_32LSB_DATA;
7592 u32 igu_addr_ctl = IGU_REG_COMMAND_REG_CTRL;
7593 u32 igu_addr_ack = IGU_REG_CSTORM_TYPE_0_SB_CLEANUP + (idu_sb_id/32)*4;
7594 u32 sb_bit = 1 << (idu_sb_id%32);
7595 u32 func_encode = func | (is_pf ? 1 : 0) << IGU_FID_ENCODE_IS_PF_SHIFT;
7596 u32 addr_encode = IGU_CMD_E2_PROD_UPD_BASE + idu_sb_id;
7598 /* Not supported in BC mode */
7599 if (CHIP_INT_MODE_IS_BC(bp))
7602 data = (IGU_USE_REGISTER_cstorm_type_0_sb_cleanup
7603 << IGU_REGULAR_CLEANUP_TYPE_SHIFT) |
7604 IGU_REGULAR_CLEANUP_SET |
7605 IGU_REGULAR_BCLEANUP;
7607 ctl = addr_encode << IGU_CTRL_REG_ADDRESS_SHIFT |
7608 func_encode << IGU_CTRL_REG_FID_SHIFT |
7609 IGU_CTRL_CMD_TYPE_WR << IGU_CTRL_REG_TYPE_SHIFT;
7611 DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
7612 data, igu_addr_data);
7613 REG_WR(bp, igu_addr_data, data);
7616 DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
7618 REG_WR(bp, igu_addr_ctl, ctl);
7622 /* wait for clean up to finish */
7623 while (!(REG_RD(bp, igu_addr_ack) & sb_bit) && --cnt)
7626 if (!(REG_RD(bp, igu_addr_ack) & sb_bit)) {
7628 "Unable to finish IGU cleanup: idu_sb_id %d offset %d bit %d (cnt %d)\n",
7629 idu_sb_id, idu_sb_id/32, idu_sb_id%32, cnt);
7633 static void bnx2x_igu_clear_sb(struct bnx2x *bp, u8 idu_sb_id)
7635 bnx2x_igu_clear_sb_gen(bp, BP_FUNC(bp), idu_sb_id, true /*PF*/);
7638 static void bnx2x_clear_func_ilt(struct bnx2x *bp, u32 func)
7640 u32 i, base = FUNC_ILT_BASE(func);
7641 for (i = base; i < base + ILT_PER_FUNC; i++)
7642 bnx2x_ilt_wr(bp, i, 0);
7645 static void bnx2x_init_searcher(struct bnx2x *bp)
7647 int port = BP_PORT(bp);
7648 bnx2x_src_init_t2(bp, bp->t2, bp->t2_mapping, SRC_CONN_NUM);
7649 /* T1 hash bits value determines the T1 number of entries */
7650 REG_WR(bp, SRC_REG_NUMBER_HASH_BITS0 + port*4, SRC_HASH_BITS);
7653 static inline int bnx2x_func_switch_update(struct bnx2x *bp, int suspend)
7656 struct bnx2x_func_state_params func_params = {NULL};
7657 struct bnx2x_func_switch_update_params *switch_update_params =
7658 &func_params.params.switch_update;
7660 /* Prepare parameters for function state transitions */
7661 __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
7662 __set_bit(RAMROD_RETRY, &func_params.ramrod_flags);
7664 func_params.f_obj = &bp->func_obj;
7665 func_params.cmd = BNX2X_F_CMD_SWITCH_UPDATE;
7667 /* Function parameters */
7668 __set_bit(BNX2X_F_UPDATE_TX_SWITCH_SUSPEND_CHNG,
7669 &switch_update_params->changes);
7671 __set_bit(BNX2X_F_UPDATE_TX_SWITCH_SUSPEND,
7672 &switch_update_params->changes);
7674 rc = bnx2x_func_state_change(bp, &func_params);
7679 static int bnx2x_reset_nic_mode(struct bnx2x *bp)
7681 int rc, i, port = BP_PORT(bp);
7682 int vlan_en = 0, mac_en[NUM_MACS];
7684 /* Close input from network */
7685 if (bp->mf_mode == SINGLE_FUNCTION) {
7686 bnx2x_set_rx_filter(&bp->link_params, 0);
7688 vlan_en = REG_RD(bp, port ? NIG_REG_LLH1_FUNC_EN :
7689 NIG_REG_LLH0_FUNC_EN);
7690 REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
7691 NIG_REG_LLH0_FUNC_EN, 0);
7692 for (i = 0; i < NUM_MACS; i++) {
7693 mac_en[i] = REG_RD(bp, port ?
7694 (NIG_REG_LLH1_FUNC_MEM_ENABLE +
7696 (NIG_REG_LLH0_FUNC_MEM_ENABLE +
7698 REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
7700 (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i), 0);
7704 /* Close BMC to host */
7705 REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
7706 NIG_REG_P1_TX_MNG_HOST_ENABLE, 0);
7708 /* Suspend Tx switching to the PF. Completion of this ramrod
7709 * further guarantees that all the packets of that PF / child
7710 * VFs in BRB were processed by the Parser, so it is safe to
7711 * change the NIC_MODE register.
7713 rc = bnx2x_func_switch_update(bp, 1);
7715 BNX2X_ERR("Can't suspend tx-switching!\n");
7719 /* Change NIC_MODE register */
7720 REG_WR(bp, PRS_REG_NIC_MODE, 0);
7722 /* Open input from network */
7723 if (bp->mf_mode == SINGLE_FUNCTION) {
7724 bnx2x_set_rx_filter(&bp->link_params, 1);
7726 REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
7727 NIG_REG_LLH0_FUNC_EN, vlan_en);
7728 for (i = 0; i < NUM_MACS; i++) {
7729 REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
7731 (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i),
7736 /* Enable BMC to host */
7737 REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
7738 NIG_REG_P1_TX_MNG_HOST_ENABLE, 1);
7740 /* Resume Tx switching to the PF */
7741 rc = bnx2x_func_switch_update(bp, 0);
7743 BNX2X_ERR("Can't resume tx-switching!\n");
7747 DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
7751 int bnx2x_init_hw_func_cnic(struct bnx2x *bp)
7755 bnx2x_ilt_init_op_cnic(bp, INITOP_SET);
7757 if (CONFIGURE_NIC_MODE(bp)) {
7758 /* Configure searcher as part of function hw init */
7759 bnx2x_init_searcher(bp);
7761 /* Reset NIC mode */
7762 rc = bnx2x_reset_nic_mode(bp);
7764 BNX2X_ERR("Can't change NIC mode!\n");
7771 static int bnx2x_init_hw_func(struct bnx2x *bp)
7773 int port = BP_PORT(bp);
7774 int func = BP_FUNC(bp);
7775 int init_phase = PHASE_PF0 + func;
7776 struct bnx2x_ilt *ilt = BP_ILT(bp);
7779 u32 main_mem_base, main_mem_size, main_mem_prty_clr;
7780 int i, main_mem_width, rc;
7782 DP(NETIF_MSG_HW, "starting func init func %d\n", func);
7784 /* FLR cleanup - hmmm */
7785 if (!CHIP_IS_E1x(bp)) {
7786 rc = bnx2x_pf_flr_clnup(bp);
7793 /* set MSI reconfigure capability */
7794 if (bp->common.int_block == INT_BLOCK_HC) {
7795 addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0);
7796 val = REG_RD(bp, addr);
7797 val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0;
7798 REG_WR(bp, addr, val);
7801 bnx2x_init_block(bp, BLOCK_PXP, init_phase);
7802 bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
7805 cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
7808 cdu_ilt_start += BNX2X_FIRST_VF_CID/ILT_PAGE_CIDS;
7809 cdu_ilt_start = bnx2x_iov_init_ilt(bp, cdu_ilt_start);
7811 /* since BNX2X_FIRST_VF_CID > 0 the PF L2 cids precedes
7812 * those of the VFs, so start line should be reset
7814 cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
7815 for (i = 0; i < L2_ILT_LINES(bp); i++) {
7816 ilt->lines[cdu_ilt_start + i].page = bp->context[i].vcxt;
7817 ilt->lines[cdu_ilt_start + i].page_mapping =
7818 bp->context[i].cxt_mapping;
7819 ilt->lines[cdu_ilt_start + i].size = bp->context[i].size;
7822 bnx2x_ilt_init_op(bp, INITOP_SET);
7824 if (!CONFIGURE_NIC_MODE(bp)) {
7825 bnx2x_init_searcher(bp);
7826 REG_WR(bp, PRS_REG_NIC_MODE, 0);
7827 DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
7830 REG_WR(bp, PRS_REG_NIC_MODE, 1);
7831 DP(NETIF_MSG_IFUP, "NIC MODE configured\n");
7834 if (!CHIP_IS_E1x(bp)) {
7835 u32 pf_conf = IGU_PF_CONF_FUNC_EN;
7837 /* Turn on a single ISR mode in IGU if driver is going to use
7840 if (!(bp->flags & USING_MSIX_FLAG))
7841 pf_conf |= IGU_PF_CONF_SINGLE_ISR_EN;
7843 * Timers workaround bug: function init part.
7844 * Need to wait 20msec after initializing ILT,
7845 * needed to make sure there are no requests in
7846 * one of the PXP internal queues with "old" ILT addresses
7850 * Master enable - Due to WB DMAE writes performed before this
7851 * register is re-initialized as part of the regular function
7854 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
7855 /* Enable the function in IGU */
7856 REG_WR(bp, IGU_REG_PF_CONFIGURATION, pf_conf);
7861 bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
7863 if (!CHIP_IS_E1x(bp))
7864 REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR, func);
7866 bnx2x_init_block(bp, BLOCK_ATC, init_phase);
7867 bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
7868 bnx2x_init_block(bp, BLOCK_NIG, init_phase);
7869 bnx2x_init_block(bp, BLOCK_SRC, init_phase);
7870 bnx2x_init_block(bp, BLOCK_MISC, init_phase);
7871 bnx2x_init_block(bp, BLOCK_TCM, init_phase);
7872 bnx2x_init_block(bp, BLOCK_UCM, init_phase);
7873 bnx2x_init_block(bp, BLOCK_CCM, init_phase);
7874 bnx2x_init_block(bp, BLOCK_XCM, init_phase);
7875 bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
7876 bnx2x_init_block(bp, BLOCK_USEM, init_phase);
7877 bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
7878 bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
7880 if (!CHIP_IS_E1x(bp))
7881 REG_WR(bp, QM_REG_PF_EN, 1);
7883 if (!CHIP_IS_E1x(bp)) {
7884 REG_WR(bp, TSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
7885 REG_WR(bp, USEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
7886 REG_WR(bp, CSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
7887 REG_WR(bp, XSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
7889 bnx2x_init_block(bp, BLOCK_QM, init_phase);
7891 bnx2x_init_block(bp, BLOCK_TM, init_phase);
7892 bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
7893 REG_WR(bp, DORQ_REG_MODE_ACT, 1); /* no dpm */
7895 bnx2x_iov_init_dq(bp);
7897 bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
7898 bnx2x_init_block(bp, BLOCK_PRS, init_phase);
7899 bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
7900 bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
7901 bnx2x_init_block(bp, BLOCK_USDM, init_phase);
7902 bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
7903 bnx2x_init_block(bp, BLOCK_UPB, init_phase);
7904 bnx2x_init_block(bp, BLOCK_XPB, init_phase);
7905 bnx2x_init_block(bp, BLOCK_PBF, init_phase);
7906 if (!CHIP_IS_E1x(bp))
7907 REG_WR(bp, PBF_REG_DISABLE_PF, 0);
7909 bnx2x_init_block(bp, BLOCK_CDU, init_phase);
7911 bnx2x_init_block(bp, BLOCK_CFC, init_phase);
7913 if (!CHIP_IS_E1x(bp))
7914 REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 1);
7917 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
7918 REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + port*8, bp->mf_ov);
7921 bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
7923 /* HC init per function */
7924 if (bp->common.int_block == INT_BLOCK_HC) {
7925 if (CHIP_IS_E1H(bp)) {
7926 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
7928 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
7929 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
7931 bnx2x_init_block(bp, BLOCK_HC, init_phase);
7934 int num_segs, sb_idx, prod_offset;
7936 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
7938 if (!CHIP_IS_E1x(bp)) {
7939 REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
7940 REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
7943 bnx2x_init_block(bp, BLOCK_IGU, init_phase);
7945 if (!CHIP_IS_E1x(bp)) {
7949 * E2 mode: address 0-135 match to the mapping memory;
7950 * 136 - PF0 default prod; 137 - PF1 default prod;
7951 * 138 - PF2 default prod; 139 - PF3 default prod;
7952 * 140 - PF0 attn prod; 141 - PF1 attn prod;
7953 * 142 - PF2 attn prod; 143 - PF3 attn prod;
7956 * E1.5 mode - In backward compatible mode;
7957 * for non default SB; each even line in the memory
7958 * holds the U producer and each odd line hold
7959 * the C producer. The first 128 producers are for
7960 * NDSB (PF0 - 0-31; PF1 - 32-63 and so on). The last 20
7961 * producers are for the DSB for each PF.
7962 * Each PF has five segments: (the order inside each
7963 * segment is PF0; PF1; PF2; PF3) - 128-131 U prods;
7964 * 132-135 C prods; 136-139 X prods; 140-143 T prods;
7965 * 144-147 attn prods;
7967 /* non-default-status-blocks */
7968 num_segs = CHIP_INT_MODE_IS_BC(bp) ?
7969 IGU_BC_NDSB_NUM_SEGS : IGU_NORM_NDSB_NUM_SEGS;
7970 for (sb_idx = 0; sb_idx < bp->igu_sb_cnt; sb_idx++) {
7971 prod_offset = (bp->igu_base_sb + sb_idx) *
7974 for (i = 0; i < num_segs; i++) {
7975 addr = IGU_REG_PROD_CONS_MEMORY +
7976 (prod_offset + i) * 4;
7977 REG_WR(bp, addr, 0);
7979 /* send consumer update with value 0 */
7980 bnx2x_ack_sb(bp, bp->igu_base_sb + sb_idx,
7981 USTORM_ID, 0, IGU_INT_NOP, 1);
7982 bnx2x_igu_clear_sb(bp,
7983 bp->igu_base_sb + sb_idx);
7986 /* default-status-blocks */
7987 num_segs = CHIP_INT_MODE_IS_BC(bp) ?
7988 IGU_BC_DSB_NUM_SEGS : IGU_NORM_DSB_NUM_SEGS;
7990 if (CHIP_MODE_IS_4_PORT(bp))
7991 dsb_idx = BP_FUNC(bp);
7993 dsb_idx = BP_VN(bp);
7995 prod_offset = (CHIP_INT_MODE_IS_BC(bp) ?
7996 IGU_BC_BASE_DSB_PROD + dsb_idx :
7997 IGU_NORM_BASE_DSB_PROD + dsb_idx);
8000 * igu prods come in chunks of E1HVN_MAX (4) -
8001 * does not matters what is the current chip mode
8003 for (i = 0; i < (num_segs * E1HVN_MAX);
8005 addr = IGU_REG_PROD_CONS_MEMORY +
8006 (prod_offset + i)*4;
8007 REG_WR(bp, addr, 0);
8009 /* send consumer update with 0 */
8010 if (CHIP_INT_MODE_IS_BC(bp)) {
8011 bnx2x_ack_sb(bp, bp->igu_dsb_id,
8012 USTORM_ID, 0, IGU_INT_NOP, 1);
8013 bnx2x_ack_sb(bp, bp->igu_dsb_id,
8014 CSTORM_ID, 0, IGU_INT_NOP, 1);
8015 bnx2x_ack_sb(bp, bp->igu_dsb_id,
8016 XSTORM_ID, 0, IGU_INT_NOP, 1);
8017 bnx2x_ack_sb(bp, bp->igu_dsb_id,
8018 TSTORM_ID, 0, IGU_INT_NOP, 1);
8019 bnx2x_ack_sb(bp, bp->igu_dsb_id,
8020 ATTENTION_ID, 0, IGU_INT_NOP, 1);
8022 bnx2x_ack_sb(bp, bp->igu_dsb_id,
8023 USTORM_ID, 0, IGU_INT_NOP, 1);
8024 bnx2x_ack_sb(bp, bp->igu_dsb_id,
8025 ATTENTION_ID, 0, IGU_INT_NOP, 1);
8027 bnx2x_igu_clear_sb(bp, bp->igu_dsb_id);
8029 /* !!! These should become driver const once
8030 rf-tool supports split-68 const */
8031 REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_LSB, 0);
8032 REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_MSB, 0);
8033 REG_WR(bp, IGU_REG_SB_MASK_LSB, 0);
8034 REG_WR(bp, IGU_REG_SB_MASK_MSB, 0);
8035 REG_WR(bp, IGU_REG_PBA_STATUS_LSB, 0);
8036 REG_WR(bp, IGU_REG_PBA_STATUS_MSB, 0);
8040 /* Reset PCIE errors for debug */
8041 REG_WR(bp, 0x2114, 0xffffffff);
8042 REG_WR(bp, 0x2120, 0xffffffff);
8044 if (CHIP_IS_E1x(bp)) {
8045 main_mem_size = HC_REG_MAIN_MEMORY_SIZE / 2; /*dwords*/
8046 main_mem_base = HC_REG_MAIN_MEMORY +
8047 BP_PORT(bp) * (main_mem_size * 4);
8048 main_mem_prty_clr = HC_REG_HC_PRTY_STS_CLR;
8051 val = REG_RD(bp, main_mem_prty_clr);
8054 "Hmmm... Parity errors in HC block during function init (0x%x)!\n",
8057 /* Clear "false" parity errors in MSI-X table */
8058 for (i = main_mem_base;
8059 i < main_mem_base + main_mem_size * 4;
8060 i += main_mem_width) {
8061 bnx2x_read_dmae(bp, i, main_mem_width / 4);
8062 bnx2x_write_dmae(bp, bnx2x_sp_mapping(bp, wb_data),
8063 i, main_mem_width / 4);
8065 /* Clear HC parity attention */
8066 REG_RD(bp, main_mem_prty_clr);
8069 #ifdef BNX2X_STOP_ON_ERROR
8070 /* Enable STORMs SP logging */
8071 REG_WR8(bp, BAR_USTRORM_INTMEM +
8072 USTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
8073 REG_WR8(bp, BAR_TSTRORM_INTMEM +
8074 TSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
8075 REG_WR8(bp, BAR_CSTRORM_INTMEM +
8076 CSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
8077 REG_WR8(bp, BAR_XSTRORM_INTMEM +
8078 XSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
8081 bnx2x_phy_probe(&bp->link_params);
8086 void bnx2x_free_mem_cnic(struct bnx2x *bp)
8088 bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_FREE);
8090 if (!CHIP_IS_E1x(bp))
8091 BNX2X_PCI_FREE(bp->cnic_sb.e2_sb, bp->cnic_sb_mapping,
8092 sizeof(struct host_hc_status_block_e2));
8094 BNX2X_PCI_FREE(bp->cnic_sb.e1x_sb, bp->cnic_sb_mapping,
8095 sizeof(struct host_hc_status_block_e1x));
8097 BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
8100 void bnx2x_free_mem(struct bnx2x *bp)
8104 BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
8105 bp->fw_stats_data_sz + bp->fw_stats_req_sz);
8110 BNX2X_PCI_FREE(bp->def_status_blk, bp->def_status_blk_mapping,
8111 sizeof(struct host_sp_status_block));
8113 BNX2X_PCI_FREE(bp->slowpath, bp->slowpath_mapping,
8114 sizeof(struct bnx2x_slowpath));
8116 for (i = 0; i < L2_ILT_LINES(bp); i++)
8117 BNX2X_PCI_FREE(bp->context[i].vcxt, bp->context[i].cxt_mapping,
8118 bp->context[i].size);
8119 bnx2x_ilt_mem_op(bp, ILT_MEMOP_FREE);
8121 BNX2X_FREE(bp->ilt->lines);
8123 BNX2X_PCI_FREE(bp->spq, bp->spq_mapping, BCM_PAGE_SIZE);
8125 BNX2X_PCI_FREE(bp->eq_ring, bp->eq_mapping,
8126 BCM_PAGE_SIZE * NUM_EQ_PAGES);
8128 BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
8130 bnx2x_iov_free_mem(bp);
8133 int bnx2x_alloc_mem_cnic(struct bnx2x *bp)
8135 if (!CHIP_IS_E1x(bp)) {
8136 /* size = the status block + ramrod buffers */
8137 bp->cnic_sb.e2_sb = BNX2X_PCI_ALLOC(&bp->cnic_sb_mapping,
8138 sizeof(struct host_hc_status_block_e2));
8139 if (!bp->cnic_sb.e2_sb)
8142 bp->cnic_sb.e1x_sb = BNX2X_PCI_ALLOC(&bp->cnic_sb_mapping,
8143 sizeof(struct host_hc_status_block_e1x));
8144 if (!bp->cnic_sb.e1x_sb)
8148 if (CONFIGURE_NIC_MODE(bp) && !bp->t2) {
8149 /* allocate searcher T2 table, as it wasn't allocated before */
8150 bp->t2 = BNX2X_PCI_ALLOC(&bp->t2_mapping, SRC_T2_SZ);
8155 /* write address to which L5 should insert its values */
8156 bp->cnic_eth_dev.addr_drv_info_to_mcp =
8157 &bp->slowpath->drv_info_to_mcp;
8159 if (bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_ALLOC))
8165 bnx2x_free_mem_cnic(bp);
8166 BNX2X_ERR("Can't allocate memory\n");
8170 int bnx2x_alloc_mem(struct bnx2x *bp)
8172 int i, allocated, context_size;
8174 if (!CONFIGURE_NIC_MODE(bp) && !bp->t2) {
8175 /* allocate searcher T2 table */
8176 bp->t2 = BNX2X_PCI_ALLOC(&bp->t2_mapping, SRC_T2_SZ);
8181 bp->def_status_blk = BNX2X_PCI_ALLOC(&bp->def_status_blk_mapping,
8182 sizeof(struct host_sp_status_block));
8183 if (!bp->def_status_blk)
8186 bp->slowpath = BNX2X_PCI_ALLOC(&bp->slowpath_mapping,
8187 sizeof(struct bnx2x_slowpath));
8191 /* Allocate memory for CDU context:
8192 * This memory is allocated separately and not in the generic ILT
8193 * functions because CDU differs in few aspects:
8194 * 1. There are multiple entities allocating memory for context -
8195 * 'regular' driver, CNIC and SRIOV driver. Each separately controls
8196 * its own ILT lines.
8197 * 2. Since CDU page-size is not a single 4KB page (which is the case
8198 * for the other ILT clients), to be efficient we want to support
8199 * allocation of sub-page-size in the last entry.
8200 * 3. Context pointers are used by the driver to pass to FW / update
8201 * the context (for the other ILT clients the pointers are used just to
8202 * free the memory during unload).
8204 context_size = sizeof(union cdu_context) * BNX2X_L2_CID_COUNT(bp);
8206 for (i = 0, allocated = 0; allocated < context_size; i++) {
8207 bp->context[i].size = min(CDU_ILT_PAGE_SZ,
8208 (context_size - allocated));
8209 bp->context[i].vcxt = BNX2X_PCI_ALLOC(&bp->context[i].cxt_mapping,
8210 bp->context[i].size);
8211 if (!bp->context[i].vcxt)
8213 allocated += bp->context[i].size;
8215 bp->ilt->lines = kcalloc(ILT_MAX_LINES, sizeof(struct ilt_line),
8217 if (!bp->ilt->lines)
8220 if (bnx2x_ilt_mem_op(bp, ILT_MEMOP_ALLOC))
8223 if (bnx2x_iov_alloc_mem(bp))
8226 /* Slow path ring */
8227 bp->spq = BNX2X_PCI_ALLOC(&bp->spq_mapping, BCM_PAGE_SIZE);
8232 bp->eq_ring = BNX2X_PCI_ALLOC(&bp->eq_mapping,
8233 BCM_PAGE_SIZE * NUM_EQ_PAGES);
8241 BNX2X_ERR("Can't allocate memory\n");
8246 * Init service functions
8249 int bnx2x_set_mac_one(struct bnx2x *bp, u8 *mac,
8250 struct bnx2x_vlan_mac_obj *obj, bool set,
8251 int mac_type, unsigned long *ramrod_flags)
8254 struct bnx2x_vlan_mac_ramrod_params ramrod_param;
8256 memset(&ramrod_param, 0, sizeof(ramrod_param));
8258 /* Fill general parameters */
8259 ramrod_param.vlan_mac_obj = obj;
8260 ramrod_param.ramrod_flags = *ramrod_flags;
8262 /* Fill a user request section if needed */
8263 if (!test_bit(RAMROD_CONT, ramrod_flags)) {
8264 memcpy(ramrod_param.user_req.u.mac.mac, mac, ETH_ALEN);
8266 __set_bit(mac_type, &ramrod_param.user_req.vlan_mac_flags);
8268 /* Set the command: ADD or DEL */
8270 ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_ADD;
8272 ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_DEL;
8275 rc = bnx2x_config_vlan_mac(bp, &ramrod_param);
8277 if (rc == -EEXIST) {
8278 DP(BNX2X_MSG_SP, "Failed to schedule ADD operations: %d\n", rc);
8279 /* do not treat adding same MAC as error */
8282 BNX2X_ERR("%s MAC failed\n", (set ? "Set" : "Del"));
8287 int bnx2x_del_all_macs(struct bnx2x *bp,
8288 struct bnx2x_vlan_mac_obj *mac_obj,
8289 int mac_type, bool wait_for_comp)
8292 unsigned long ramrod_flags = 0, vlan_mac_flags = 0;
8294 /* Wait for completion of requested */
8296 __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
8298 /* Set the mac type of addresses we want to clear */
8299 __set_bit(mac_type, &vlan_mac_flags);
8301 rc = mac_obj->delete_all(bp, mac_obj, &vlan_mac_flags, &ramrod_flags);
8303 BNX2X_ERR("Failed to delete MACs: %d\n", rc);
8308 int bnx2x_set_eth_mac(struct bnx2x *bp, bool set)
8310 if (is_zero_ether_addr(bp->dev->dev_addr) &&
8311 (IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp))) {
8312 DP(NETIF_MSG_IFUP | NETIF_MSG_IFDOWN,
8313 "Ignoring Zero MAC for STORAGE SD mode\n");
8318 unsigned long ramrod_flags = 0;
8320 DP(NETIF_MSG_IFUP, "Adding Eth MAC\n");
8321 __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
8322 return bnx2x_set_mac_one(bp, bp->dev->dev_addr,
8323 &bp->sp_objs->mac_obj, set,
8324 BNX2X_ETH_MAC, &ramrod_flags);
8326 return bnx2x_vfpf_config_mac(bp, bp->dev->dev_addr,
8327 bp->fp->index, true);
8331 int bnx2x_setup_leading(struct bnx2x *bp)
8334 return bnx2x_setup_queue(bp, &bp->fp[0], true);
8336 return bnx2x_vfpf_setup_q(bp, &bp->fp[0], true);
8340 * bnx2x_set_int_mode - configure interrupt mode
8342 * @bp: driver handle
8344 * In case of MSI-X it will also try to enable MSI-X.
8346 int bnx2x_set_int_mode(struct bnx2x *bp)
8350 if (IS_VF(bp) && int_mode != BNX2X_INT_MODE_MSIX) {
8351 BNX2X_ERR("VF not loaded since interrupt mode not msix\n");
8356 case BNX2X_INT_MODE_MSIX:
8357 /* attempt to enable msix */
8358 rc = bnx2x_enable_msix(bp);
8364 /* vfs use only msix */
8365 if (rc && IS_VF(bp))
8368 /* failed to enable multiple MSI-X */
8369 BNX2X_DEV_INFO("Failed to enable multiple MSI-X (%d), set number of queues to %d\n",
8371 1 + bp->num_cnic_queues);
8373 /* falling through... */
8374 case BNX2X_INT_MODE_MSI:
8375 bnx2x_enable_msi(bp);
8377 /* falling through... */
8378 case BNX2X_INT_MODE_INTX:
8379 bp->num_ethernet_queues = 1;
8380 bp->num_queues = bp->num_ethernet_queues + bp->num_cnic_queues;
8381 BNX2X_DEV_INFO("set number of queues to 1\n");
8384 BNX2X_DEV_INFO("unknown value in int_mode module parameter\n");
8390 /* must be called prior to any HW initializations */
8391 static inline u16 bnx2x_cid_ilt_lines(struct bnx2x *bp)
8394 return (BNX2X_FIRST_VF_CID + BNX2X_VF_CIDS)/ILT_PAGE_CIDS;
8395 return L2_ILT_LINES(bp);
8398 void bnx2x_ilt_set_info(struct bnx2x *bp)
8400 struct ilt_client_info *ilt_client;
8401 struct bnx2x_ilt *ilt = BP_ILT(bp);
8404 ilt->start_line = FUNC_ILT_BASE(BP_FUNC(bp));
8405 DP(BNX2X_MSG_SP, "ilt starts at line %d\n", ilt->start_line);
8408 ilt_client = &ilt->clients[ILT_CLIENT_CDU];
8409 ilt_client->client_num = ILT_CLIENT_CDU;
8410 ilt_client->page_size = CDU_ILT_PAGE_SZ;
8411 ilt_client->flags = ILT_CLIENT_SKIP_MEM;
8412 ilt_client->start = line;
8413 line += bnx2x_cid_ilt_lines(bp);
8415 if (CNIC_SUPPORT(bp))
8416 line += CNIC_ILT_LINES;
8417 ilt_client->end = line - 1;
8419 DP(NETIF_MSG_IFUP, "ilt client[CDU]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
8422 ilt_client->page_size,
8424 ilog2(ilt_client->page_size >> 12));
8427 if (QM_INIT(bp->qm_cid_count)) {
8428 ilt_client = &ilt->clients[ILT_CLIENT_QM];
8429 ilt_client->client_num = ILT_CLIENT_QM;
8430 ilt_client->page_size = QM_ILT_PAGE_SZ;
8431 ilt_client->flags = 0;
8432 ilt_client->start = line;
8434 /* 4 bytes for each cid */
8435 line += DIV_ROUND_UP(bp->qm_cid_count * QM_QUEUES_PER_FUNC * 4,
8438 ilt_client->end = line - 1;
8441 "ilt client[QM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
8444 ilt_client->page_size,
8446 ilog2(ilt_client->page_size >> 12));
8449 if (CNIC_SUPPORT(bp)) {
8451 ilt_client = &ilt->clients[ILT_CLIENT_SRC];
8452 ilt_client->client_num = ILT_CLIENT_SRC;
8453 ilt_client->page_size = SRC_ILT_PAGE_SZ;
8454 ilt_client->flags = 0;
8455 ilt_client->start = line;
8456 line += SRC_ILT_LINES;
8457 ilt_client->end = line - 1;
8460 "ilt client[SRC]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
8463 ilt_client->page_size,
8465 ilog2(ilt_client->page_size >> 12));
8468 ilt_client = &ilt->clients[ILT_CLIENT_TM];
8469 ilt_client->client_num = ILT_CLIENT_TM;
8470 ilt_client->page_size = TM_ILT_PAGE_SZ;
8471 ilt_client->flags = 0;
8472 ilt_client->start = line;
8473 line += TM_ILT_LINES;
8474 ilt_client->end = line - 1;
8477 "ilt client[TM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
8480 ilt_client->page_size,
8482 ilog2(ilt_client->page_size >> 12));
8485 BUG_ON(line > ILT_MAX_LINES);
8489 * bnx2x_pf_q_prep_init - prepare INIT transition parameters
8491 * @bp: driver handle
8492 * @fp: pointer to fastpath
8493 * @init_params: pointer to parameters structure
8495 * parameters configured:
8496 * - HC configuration
8497 * - Queue's CDU context
8499 static void bnx2x_pf_q_prep_init(struct bnx2x *bp,
8500 struct bnx2x_fastpath *fp, struct bnx2x_queue_init_params *init_params)
8503 int cxt_index, cxt_offset;
8505 /* FCoE Queue uses Default SB, thus has no HC capabilities */
8506 if (!IS_FCOE_FP(fp)) {
8507 __set_bit(BNX2X_Q_FLG_HC, &init_params->rx.flags);
8508 __set_bit(BNX2X_Q_FLG_HC, &init_params->tx.flags);
8510 /* If HC is supported, enable host coalescing in the transition
8513 __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->rx.flags);
8514 __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->tx.flags);
8517 init_params->rx.hc_rate = bp->rx_ticks ?
8518 (1000000 / bp->rx_ticks) : 0;
8519 init_params->tx.hc_rate = bp->tx_ticks ?
8520 (1000000 / bp->tx_ticks) : 0;
8523 init_params->rx.fw_sb_id = init_params->tx.fw_sb_id =
8527 * CQ index among the SB indices: FCoE clients uses the default
8528 * SB, therefore it's different.
8530 init_params->rx.sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
8531 init_params->tx.sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS;
8534 /* set maximum number of COSs supported by this queue */
8535 init_params->max_cos = fp->max_cos;
8537 DP(NETIF_MSG_IFUP, "fp: %d setting queue params max cos to: %d\n",
8538 fp->index, init_params->max_cos);
8540 /* set the context pointers queue object */
8541 for (cos = FIRST_TX_COS_INDEX; cos < init_params->max_cos; cos++) {
8542 cxt_index = fp->txdata_ptr[cos]->cid / ILT_PAGE_CIDS;
8543 cxt_offset = fp->txdata_ptr[cos]->cid - (cxt_index *
8545 init_params->cxts[cos] =
8546 &bp->context[cxt_index].vcxt[cxt_offset].eth;
8550 static int bnx2x_setup_tx_only(struct bnx2x *bp, struct bnx2x_fastpath *fp,
8551 struct bnx2x_queue_state_params *q_params,
8552 struct bnx2x_queue_setup_tx_only_params *tx_only_params,
8553 int tx_index, bool leading)
8555 memset(tx_only_params, 0, sizeof(*tx_only_params));
8557 /* Set the command */
8558 q_params->cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
8560 /* Set tx-only QUEUE flags: don't zero statistics */
8561 tx_only_params->flags = bnx2x_get_common_flags(bp, fp, false);
8563 /* choose the index of the cid to send the slow path on */
8564 tx_only_params->cid_index = tx_index;
8566 /* Set general TX_ONLY_SETUP parameters */
8567 bnx2x_pf_q_prep_general(bp, fp, &tx_only_params->gen_params, tx_index);
8569 /* Set Tx TX_ONLY_SETUP parameters */
8570 bnx2x_pf_tx_q_prep(bp, fp, &tx_only_params->txq_params, tx_index);
8573 "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",
8574 tx_index, q_params->q_obj->cids[FIRST_TX_COS_INDEX],
8575 q_params->q_obj->cids[tx_index], q_params->q_obj->cl_id,
8576 tx_only_params->gen_params.spcl_id, tx_only_params->flags);
8578 /* send the ramrod */
8579 return bnx2x_queue_state_change(bp, q_params);
8583 * bnx2x_setup_queue - setup queue
8585 * @bp: driver handle
8586 * @fp: pointer to fastpath
8587 * @leading: is leading
8589 * This function performs 2 steps in a Queue state machine
8590 * actually: 1) RESET->INIT 2) INIT->SETUP
8593 int bnx2x_setup_queue(struct bnx2x *bp, struct bnx2x_fastpath *fp,
8596 struct bnx2x_queue_state_params q_params = {NULL};
8597 struct bnx2x_queue_setup_params *setup_params =
8598 &q_params.params.setup;
8599 struct bnx2x_queue_setup_tx_only_params *tx_only_params =
8600 &q_params.params.tx_only;
8604 DP(NETIF_MSG_IFUP, "setting up queue %d\n", fp->index);
8606 /* reset IGU state skip FCoE L2 queue */
8607 if (!IS_FCOE_FP(fp))
8608 bnx2x_ack_sb(bp, fp->igu_sb_id, USTORM_ID, 0,
8611 q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
8612 /* We want to wait for completion in this context */
8613 __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
8615 /* Prepare the INIT parameters */
8616 bnx2x_pf_q_prep_init(bp, fp, &q_params.params.init);
8618 /* Set the command */
8619 q_params.cmd = BNX2X_Q_CMD_INIT;
8621 /* Change the state to INIT */
8622 rc = bnx2x_queue_state_change(bp, &q_params);
8624 BNX2X_ERR("Queue(%d) INIT failed\n", fp->index);
8628 DP(NETIF_MSG_IFUP, "init complete\n");
8630 /* Now move the Queue to the SETUP state... */
8631 memset(setup_params, 0, sizeof(*setup_params));
8633 /* Set QUEUE flags */
8634 setup_params->flags = bnx2x_get_q_flags(bp, fp, leading);
8636 /* Set general SETUP parameters */
8637 bnx2x_pf_q_prep_general(bp, fp, &setup_params->gen_params,
8638 FIRST_TX_COS_INDEX);
8640 bnx2x_pf_rx_q_prep(bp, fp, &setup_params->pause_params,
8641 &setup_params->rxq_params);
8643 bnx2x_pf_tx_q_prep(bp, fp, &setup_params->txq_params,
8644 FIRST_TX_COS_INDEX);
8646 /* Set the command */
8647 q_params.cmd = BNX2X_Q_CMD_SETUP;
8650 bp->fcoe_init = true;
8652 /* Change the state to SETUP */
8653 rc = bnx2x_queue_state_change(bp, &q_params);
8655 BNX2X_ERR("Queue(%d) SETUP failed\n", fp->index);
8659 /* loop through the relevant tx-only indices */
8660 for (tx_index = FIRST_TX_ONLY_COS_INDEX;
8661 tx_index < fp->max_cos;
8664 /* prepare and send tx-only ramrod*/
8665 rc = bnx2x_setup_tx_only(bp, fp, &q_params,
8666 tx_only_params, tx_index, leading);
8668 BNX2X_ERR("Queue(%d.%d) TX_ONLY_SETUP failed\n",
8669 fp->index, tx_index);
8677 static int bnx2x_stop_queue(struct bnx2x *bp, int index)
8679 struct bnx2x_fastpath *fp = &bp->fp[index];
8680 struct bnx2x_fp_txdata *txdata;
8681 struct bnx2x_queue_state_params q_params = {NULL};
8684 DP(NETIF_MSG_IFDOWN, "stopping queue %d cid %d\n", index, fp->cid);
8686 q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
8687 /* We want to wait for completion in this context */
8688 __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
8690 /* close tx-only connections */
8691 for (tx_index = FIRST_TX_ONLY_COS_INDEX;
8692 tx_index < fp->max_cos;
8695 /* ascertain this is a normal queue*/
8696 txdata = fp->txdata_ptr[tx_index];
8698 DP(NETIF_MSG_IFDOWN, "stopping tx-only queue %d\n",
8701 /* send halt terminate on tx-only connection */
8702 q_params.cmd = BNX2X_Q_CMD_TERMINATE;
8703 memset(&q_params.params.terminate, 0,
8704 sizeof(q_params.params.terminate));
8705 q_params.params.terminate.cid_index = tx_index;
8707 rc = bnx2x_queue_state_change(bp, &q_params);
8711 /* send halt terminate on tx-only connection */
8712 q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
8713 memset(&q_params.params.cfc_del, 0,
8714 sizeof(q_params.params.cfc_del));
8715 q_params.params.cfc_del.cid_index = tx_index;
8716 rc = bnx2x_queue_state_change(bp, &q_params);
8720 /* Stop the primary connection: */
8721 /* ...halt the connection */
8722 q_params.cmd = BNX2X_Q_CMD_HALT;
8723 rc = bnx2x_queue_state_change(bp, &q_params);
8727 /* ...terminate the connection */
8728 q_params.cmd = BNX2X_Q_CMD_TERMINATE;
8729 memset(&q_params.params.terminate, 0,
8730 sizeof(q_params.params.terminate));
8731 q_params.params.terminate.cid_index = FIRST_TX_COS_INDEX;
8732 rc = bnx2x_queue_state_change(bp, &q_params);
8735 /* ...delete cfc entry */
8736 q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
8737 memset(&q_params.params.cfc_del, 0,
8738 sizeof(q_params.params.cfc_del));
8739 q_params.params.cfc_del.cid_index = FIRST_TX_COS_INDEX;
8740 return bnx2x_queue_state_change(bp, &q_params);
8743 static void bnx2x_reset_func(struct bnx2x *bp)
8745 int port = BP_PORT(bp);
8746 int func = BP_FUNC(bp);
8749 /* Disable the function in the FW */
8750 REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(func), 0);
8751 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(func), 0);
8752 REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(func), 0);
8753 REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(func), 0);
8756 for_each_eth_queue(bp, i) {
8757 struct bnx2x_fastpath *fp = &bp->fp[i];
8758 REG_WR8(bp, BAR_CSTRORM_INTMEM +
8759 CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(fp->fw_sb_id),
8763 if (CNIC_LOADED(bp))
8765 REG_WR8(bp, BAR_CSTRORM_INTMEM +
8766 CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET
8767 (bnx2x_cnic_fw_sb_id(bp)), SB_DISABLED);
8770 REG_WR8(bp, BAR_CSTRORM_INTMEM +
8771 CSTORM_SP_STATUS_BLOCK_DATA_STATE_OFFSET(func),
8774 for (i = 0; i < XSTORM_SPQ_DATA_SIZE / 4; i++)
8775 REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_DATA_OFFSET(func),
8779 if (bp->common.int_block == INT_BLOCK_HC) {
8780 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
8781 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
8783 REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
8784 REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
8787 if (CNIC_LOADED(bp)) {
8788 /* Disable Timer scan */
8789 REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + port*4, 0);
8791 * Wait for at least 10ms and up to 2 second for the timers
8794 for (i = 0; i < 200; i++) {
8795 usleep_range(10000, 20000);
8796 if (!REG_RD(bp, TM_REG_LIN0_SCAN_ON + port*4))
8801 bnx2x_clear_func_ilt(bp, func);
8803 /* Timers workaround bug for E2: if this is vnic-3,
8804 * we need to set the entire ilt range for this timers.
8806 if (!CHIP_IS_E1x(bp) && BP_VN(bp) == 3) {
8807 struct ilt_client_info ilt_cli;
8808 /* use dummy TM client */
8809 memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
8811 ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
8812 ilt_cli.client_num = ILT_CLIENT_TM;
8814 bnx2x_ilt_boundry_init_op(bp, &ilt_cli, 0, INITOP_CLEAR);
8817 /* this assumes that reset_port() called before reset_func()*/
8818 if (!CHIP_IS_E1x(bp))
8819 bnx2x_pf_disable(bp);
8824 static void bnx2x_reset_port(struct bnx2x *bp)
8826 int port = BP_PORT(bp);
8829 /* Reset physical Link */
8830 bnx2x__link_reset(bp);
8832 REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
8834 /* Do not rcv packets to BRB */
8835 REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0);
8836 /* Do not direct rcv packets that are not for MCP to the BRB */
8837 REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
8838 NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
8841 REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0);
8844 /* Check for BRB port occupancy */
8845 val = REG_RD(bp, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4);
8847 DP(NETIF_MSG_IFDOWN,
8848 "BRB1 is not empty %d blocks are occupied\n", val);
8850 /* TODO: Close Doorbell port? */
8853 static int bnx2x_reset_hw(struct bnx2x *bp, u32 load_code)
8855 struct bnx2x_func_state_params func_params = {NULL};
8857 /* Prepare parameters for function state transitions */
8858 __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
8860 func_params.f_obj = &bp->func_obj;
8861 func_params.cmd = BNX2X_F_CMD_HW_RESET;
8863 func_params.params.hw_init.load_phase = load_code;
8865 return bnx2x_func_state_change(bp, &func_params);
8868 static int bnx2x_func_stop(struct bnx2x *bp)
8870 struct bnx2x_func_state_params func_params = {NULL};
8873 /* Prepare parameters for function state transitions */
8874 __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
8875 func_params.f_obj = &bp->func_obj;
8876 func_params.cmd = BNX2X_F_CMD_STOP;
8879 * Try to stop the function the 'good way'. If fails (in case
8880 * of a parity error during bnx2x_chip_cleanup()) and we are
8881 * not in a debug mode, perform a state transaction in order to
8882 * enable further HW_RESET transaction.
8884 rc = bnx2x_func_state_change(bp, &func_params);
8886 #ifdef BNX2X_STOP_ON_ERROR
8889 BNX2X_ERR("FUNC_STOP ramrod failed. Running a dry transaction\n");
8890 __set_bit(RAMROD_DRV_CLR_ONLY, &func_params.ramrod_flags);
8891 return bnx2x_func_state_change(bp, &func_params);
8899 * bnx2x_send_unload_req - request unload mode from the MCP.
8901 * @bp: driver handle
8902 * @unload_mode: requested function's unload mode
8904 * Return unload mode returned by the MCP: COMMON, PORT or FUNC.
8906 u32 bnx2x_send_unload_req(struct bnx2x *bp, int unload_mode)
8909 int port = BP_PORT(bp);
8911 /* Select the UNLOAD request mode */
8912 if (unload_mode == UNLOAD_NORMAL)
8913 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
8915 else if (bp->flags & NO_WOL_FLAG)
8916 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP;
8919 u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
8920 u8 *mac_addr = bp->dev->dev_addr;
8921 struct pci_dev *pdev = bp->pdev;
8925 /* The mac address is written to entries 1-4 to
8926 * preserve entry 0 which is used by the PMF
8928 u8 entry = (BP_VN(bp) + 1)*8;
8930 val = (mac_addr[0] << 8) | mac_addr[1];
8931 EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry, val);
8933 val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
8934 (mac_addr[4] << 8) | mac_addr[5];
8935 EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry + 4, val);
8937 /* Enable the PME and clear the status */
8938 pci_read_config_word(pdev, pdev->pm_cap + PCI_PM_CTRL, &pmc);
8939 pmc |= PCI_PM_CTRL_PME_ENABLE | PCI_PM_CTRL_PME_STATUS;
8940 pci_write_config_word(pdev, pdev->pm_cap + PCI_PM_CTRL, pmc);
8942 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_EN;
8945 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
8947 /* Send the request to the MCP */
8949 reset_code = bnx2x_fw_command(bp, reset_code, 0);
8951 int path = BP_PATH(bp);
8953 DP(NETIF_MSG_IFDOWN, "NO MCP - load counts[%d] %d, %d, %d\n",
8954 path, bnx2x_load_count[path][0], bnx2x_load_count[path][1],
8955 bnx2x_load_count[path][2]);
8956 bnx2x_load_count[path][0]--;
8957 bnx2x_load_count[path][1 + port]--;
8958 DP(NETIF_MSG_IFDOWN, "NO MCP - new load counts[%d] %d, %d, %d\n",
8959 path, bnx2x_load_count[path][0], bnx2x_load_count[path][1],
8960 bnx2x_load_count[path][2]);
8961 if (bnx2x_load_count[path][0] == 0)
8962 reset_code = FW_MSG_CODE_DRV_UNLOAD_COMMON;
8963 else if (bnx2x_load_count[path][1 + port] == 0)
8964 reset_code = FW_MSG_CODE_DRV_UNLOAD_PORT;
8966 reset_code = FW_MSG_CODE_DRV_UNLOAD_FUNCTION;
8973 * bnx2x_send_unload_done - send UNLOAD_DONE command to the MCP.
8975 * @bp: driver handle
8976 * @keep_link: true iff link should be kept up
8978 void bnx2x_send_unload_done(struct bnx2x *bp, bool keep_link)
8980 u32 reset_param = keep_link ? DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET : 0;
8982 /* Report UNLOAD_DONE to MCP */
8984 bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, reset_param);
8987 static int bnx2x_func_wait_started(struct bnx2x *bp)
8990 int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
8996 * (assumption: No Attention from MCP at this stage)
8997 * PMF probably in the middle of TX disable/enable transaction
8998 * 1. Sync IRS for default SB
8999 * 2. Sync SP queue - this guarantees us that attention handling started
9000 * 3. Wait, that TX disable/enable transaction completes
9002 * 1+2 guarantee that if DCBx attention was scheduled it already changed
9003 * pending bit of transaction from STARTED-->TX_STOPPED, if we already
9004 * received completion for the transaction the state is TX_STOPPED.
9005 * State will return to STARTED after completion of TX_STOPPED-->STARTED
9009 /* make sure default SB ISR is done */
9011 synchronize_irq(bp->msix_table[0].vector);
9013 synchronize_irq(bp->pdev->irq);
9015 flush_workqueue(bnx2x_wq);
9016 flush_workqueue(bnx2x_iov_wq);
9018 while (bnx2x_func_get_state(bp, &bp->func_obj) !=
9019 BNX2X_F_STATE_STARTED && tout--)
9022 if (bnx2x_func_get_state(bp, &bp->func_obj) !=
9023 BNX2X_F_STATE_STARTED) {
9024 #ifdef BNX2X_STOP_ON_ERROR
9025 BNX2X_ERR("Wrong function state\n");
9029 * Failed to complete the transaction in a "good way"
9030 * Force both transactions with CLR bit
9032 struct bnx2x_func_state_params func_params = {NULL};
9034 DP(NETIF_MSG_IFDOWN,
9035 "Hmmm... Unexpected function state! Forcing STARTED-->TX_STOPPED-->STARTED\n");
9037 func_params.f_obj = &bp->func_obj;
9038 __set_bit(RAMROD_DRV_CLR_ONLY,
9039 &func_params.ramrod_flags);
9041 /* STARTED-->TX_ST0PPED */
9042 func_params.cmd = BNX2X_F_CMD_TX_STOP;
9043 bnx2x_func_state_change(bp, &func_params);
9045 /* TX_ST0PPED-->STARTED */
9046 func_params.cmd = BNX2X_F_CMD_TX_START;
9047 return bnx2x_func_state_change(bp, &func_params);
9054 static void bnx2x_disable_ptp(struct bnx2x *bp)
9056 int port = BP_PORT(bp);
9058 /* Disable sending PTP packets to host */
9059 REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_TO_HOST :
9060 NIG_REG_P0_LLH_PTP_TO_HOST, 0x0);
9062 /* Reset PTP event detection rules */
9063 REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_PARAM_MASK :
9064 NIG_REG_P0_LLH_PTP_PARAM_MASK, 0x7FF);
9065 REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_RULE_MASK :
9066 NIG_REG_P0_LLH_PTP_RULE_MASK, 0x3FFF);
9067 REG_WR(bp, port ? NIG_REG_P1_TLLH_PTP_PARAM_MASK :
9068 NIG_REG_P0_TLLH_PTP_PARAM_MASK, 0x7FF);
9069 REG_WR(bp, port ? NIG_REG_P1_TLLH_PTP_RULE_MASK :
9070 NIG_REG_P0_TLLH_PTP_RULE_MASK, 0x3FFF);
9072 /* Disable the PTP feature */
9073 REG_WR(bp, port ? NIG_REG_P1_PTP_EN :
9074 NIG_REG_P0_PTP_EN, 0x0);
9077 /* Called during unload, to stop PTP-related stuff */
9078 void bnx2x_stop_ptp(struct bnx2x *bp)
9080 /* Cancel PTP work queue. Should be done after the Tx queues are
9081 * drained to prevent additional scheduling.
9083 cancel_work_sync(&bp->ptp_task);
9085 if (bp->ptp_tx_skb) {
9086 dev_kfree_skb_any(bp->ptp_tx_skb);
9087 bp->ptp_tx_skb = NULL;
9090 /* Disable PTP in HW */
9091 bnx2x_disable_ptp(bp);
9093 DP(BNX2X_MSG_PTP, "PTP stop ended successfully\n");
9096 void bnx2x_chip_cleanup(struct bnx2x *bp, int unload_mode, bool keep_link)
9098 int port = BP_PORT(bp);
9101 struct bnx2x_mcast_ramrod_params rparam = {NULL};
9104 /* Wait until tx fastpath tasks complete */
9105 for_each_tx_queue(bp, i) {
9106 struct bnx2x_fastpath *fp = &bp->fp[i];
9108 for_each_cos_in_tx_queue(fp, cos)
9109 rc = bnx2x_clean_tx_queue(bp, fp->txdata_ptr[cos]);
9110 #ifdef BNX2X_STOP_ON_ERROR
9116 /* Give HW time to discard old tx messages */
9117 usleep_range(1000, 2000);
9119 /* Clean all ETH MACs */
9120 rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_ETH_MAC,
9123 BNX2X_ERR("Failed to delete all ETH macs: %d\n", rc);
9125 /* Clean up UC list */
9126 rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_UC_LIST_MAC,
9129 BNX2X_ERR("Failed to schedule DEL commands for UC MACs list: %d\n",
9133 if (!CHIP_IS_E1(bp))
9134 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
9136 /* Set "drop all" (stop Rx).
9137 * We need to take a netif_addr_lock() here in order to prevent
9138 * a race between the completion code and this code.
9140 netif_addr_lock_bh(bp->dev);
9141 /* Schedule the rx_mode command */
9142 if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
9143 set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
9145 bnx2x_set_storm_rx_mode(bp);
9147 /* Cleanup multicast configuration */
9148 rparam.mcast_obj = &bp->mcast_obj;
9149 rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
9151 BNX2X_ERR("Failed to send DEL multicast command: %d\n", rc);
9153 netif_addr_unlock_bh(bp->dev);
9155 bnx2x_iov_chip_cleanup(bp);
9158 * Send the UNLOAD_REQUEST to the MCP. This will return if
9159 * this function should perform FUNC, PORT or COMMON HW
9162 reset_code = bnx2x_send_unload_req(bp, unload_mode);
9165 * (assumption: No Attention from MCP at this stage)
9166 * PMF probably in the middle of TX disable/enable transaction
9168 rc = bnx2x_func_wait_started(bp);
9170 BNX2X_ERR("bnx2x_func_wait_started failed\n");
9171 #ifdef BNX2X_STOP_ON_ERROR
9176 /* Close multi and leading connections
9177 * Completions for ramrods are collected in a synchronous way
9179 for_each_eth_queue(bp, i)
9180 if (bnx2x_stop_queue(bp, i))
9181 #ifdef BNX2X_STOP_ON_ERROR
9187 if (CNIC_LOADED(bp)) {
9188 for_each_cnic_queue(bp, i)
9189 if (bnx2x_stop_queue(bp, i))
9190 #ifdef BNX2X_STOP_ON_ERROR
9197 /* If SP settings didn't get completed so far - something
9198 * very wrong has happen.
9200 if (!bnx2x_wait_sp_comp(bp, ~0x0UL))
9201 BNX2X_ERR("Hmmm... Common slow path ramrods got stuck!\n");
9203 #ifndef BNX2X_STOP_ON_ERROR
9206 rc = bnx2x_func_stop(bp);
9208 BNX2X_ERR("Function stop failed!\n");
9209 #ifdef BNX2X_STOP_ON_ERROR
9214 /* stop_ptp should be after the Tx queues are drained to prevent
9215 * scheduling to the cancelled PTP work queue. It should also be after
9216 * function stop ramrod is sent, since as part of this ramrod FW access
9221 /* Disable HW interrupts, NAPI */
9222 bnx2x_netif_stop(bp, 1);
9223 /* Delete all NAPI objects */
9224 bnx2x_del_all_napi(bp);
9225 if (CNIC_LOADED(bp))
9226 bnx2x_del_all_napi_cnic(bp);
9231 /* Reset the chip */
9232 rc = bnx2x_reset_hw(bp, reset_code);
9234 BNX2X_ERR("HW_RESET failed\n");
9236 /* Report UNLOAD_DONE to MCP */
9237 bnx2x_send_unload_done(bp, keep_link);
9240 void bnx2x_disable_close_the_gate(struct bnx2x *bp)
9244 DP(NETIF_MSG_IFDOWN, "Disabling \"close the gates\"\n");
9246 if (CHIP_IS_E1(bp)) {
9247 int port = BP_PORT(bp);
9248 u32 addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
9249 MISC_REG_AEU_MASK_ATTN_FUNC_0;
9251 val = REG_RD(bp, addr);
9253 REG_WR(bp, addr, val);
9255 val = REG_RD(bp, MISC_REG_AEU_GENERAL_MASK);
9256 val &= ~(MISC_AEU_GENERAL_MASK_REG_AEU_PXP_CLOSE_MASK |
9257 MISC_AEU_GENERAL_MASK_REG_AEU_NIG_CLOSE_MASK);
9258 REG_WR(bp, MISC_REG_AEU_GENERAL_MASK, val);
9262 /* Close gates #2, #3 and #4: */
9263 static void bnx2x_set_234_gates(struct bnx2x *bp, bool close)
9267 /* Gates #2 and #4a are closed/opened for "not E1" only */
9268 if (!CHIP_IS_E1(bp)) {
9270 REG_WR(bp, PXP_REG_HST_DISCARD_DOORBELLS, !!close);
9272 REG_WR(bp, PXP_REG_HST_DISCARD_INTERNAL_WRITES, !!close);
9276 if (CHIP_IS_E1x(bp)) {
9277 /* Prevent interrupts from HC on both ports */
9278 val = REG_RD(bp, HC_REG_CONFIG_1);
9279 REG_WR(bp, HC_REG_CONFIG_1,
9280 (!close) ? (val | HC_CONFIG_1_REG_BLOCK_DISABLE_1) :
9281 (val & ~(u32)HC_CONFIG_1_REG_BLOCK_DISABLE_1));
9283 val = REG_RD(bp, HC_REG_CONFIG_0);
9284 REG_WR(bp, HC_REG_CONFIG_0,
9285 (!close) ? (val | HC_CONFIG_0_REG_BLOCK_DISABLE_0) :
9286 (val & ~(u32)HC_CONFIG_0_REG_BLOCK_DISABLE_0));
9288 /* Prevent incoming interrupts in IGU */
9289 val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
9291 REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION,
9293 (val | IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE) :
9294 (val & ~(u32)IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE));
9297 DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "%s gates #2, #3 and #4\n",
9298 close ? "closing" : "opening");
9302 #define SHARED_MF_CLP_MAGIC 0x80000000 /* `magic' bit */
9304 static void bnx2x_clp_reset_prep(struct bnx2x *bp, u32 *magic_val)
9306 /* Do some magic... */
9307 u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
9308 *magic_val = val & SHARED_MF_CLP_MAGIC;
9309 MF_CFG_WR(bp, shared_mf_config.clp_mb, val | SHARED_MF_CLP_MAGIC);
9313 * bnx2x_clp_reset_done - restore the value of the `magic' bit.
9315 * @bp: driver handle
9316 * @magic_val: old value of the `magic' bit.
9318 static void bnx2x_clp_reset_done(struct bnx2x *bp, u32 magic_val)
9320 /* Restore the `magic' bit value... */
9321 u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
9322 MF_CFG_WR(bp, shared_mf_config.clp_mb,
9323 (val & (~SHARED_MF_CLP_MAGIC)) | magic_val);
9327 * bnx2x_reset_mcp_prep - prepare for MCP reset.
9329 * @bp: driver handle
9330 * @magic_val: old value of 'magic' bit.
9332 * Takes care of CLP configurations.
9334 static void bnx2x_reset_mcp_prep(struct bnx2x *bp, u32 *magic_val)
9337 u32 validity_offset;
9339 DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "Starting\n");
9341 /* Set `magic' bit in order to save MF config */
9342 if (!CHIP_IS_E1(bp))
9343 bnx2x_clp_reset_prep(bp, magic_val);
9345 /* Get shmem offset */
9346 shmem = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
9348 offsetof(struct shmem_region, validity_map[BP_PORT(bp)]);
9350 /* Clear validity map flags */
9352 REG_WR(bp, shmem + validity_offset, 0);
9355 #define MCP_TIMEOUT 5000 /* 5 seconds (in ms) */
9356 #define MCP_ONE_TIMEOUT 100 /* 100 ms */
9359 * bnx2x_mcp_wait_one - wait for MCP_ONE_TIMEOUT
9361 * @bp: driver handle
9363 static void bnx2x_mcp_wait_one(struct bnx2x *bp)
9365 /* special handling for emulation and FPGA,
9366 wait 10 times longer */
9367 if (CHIP_REV_IS_SLOW(bp))
9368 msleep(MCP_ONE_TIMEOUT*10);
9370 msleep(MCP_ONE_TIMEOUT);
9374 * initializes bp->common.shmem_base and waits for validity signature to appear
9376 static int bnx2x_init_shmem(struct bnx2x *bp)
9382 bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
9383 if (bp->common.shmem_base) {
9384 val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
9385 if (val & SHR_MEM_VALIDITY_MB)
9389 bnx2x_mcp_wait_one(bp);
9391 } while (cnt++ < (MCP_TIMEOUT / MCP_ONE_TIMEOUT));
9393 BNX2X_ERR("BAD MCP validity signature\n");
9398 static int bnx2x_reset_mcp_comp(struct bnx2x *bp, u32 magic_val)
9400 int rc = bnx2x_init_shmem(bp);
9402 /* Restore the `magic' bit value */
9403 if (!CHIP_IS_E1(bp))
9404 bnx2x_clp_reset_done(bp, magic_val);
9409 static void bnx2x_pxp_prep(struct bnx2x *bp)
9411 if (!CHIP_IS_E1(bp)) {
9412 REG_WR(bp, PXP2_REG_RD_START_INIT, 0);
9413 REG_WR(bp, PXP2_REG_RQ_RBC_DONE, 0);
9419 * Reset the whole chip except for:
9421 * - PCI Glue, PSWHST, PXP/PXP2 RF (all controlled by
9424 * - MISC (including AEU)
9428 static void bnx2x_process_kill_chip_reset(struct bnx2x *bp, bool global)
9430 u32 not_reset_mask1, reset_mask1, not_reset_mask2, reset_mask2;
9431 u32 global_bits2, stay_reset2;
9434 * Bits that have to be set in reset_mask2 if we want to reset 'global'
9435 * (per chip) blocks.
9438 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CPU |
9439 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CORE;
9441 /* Don't reset the following blocks.
9442 * Important: per port blocks (such as EMAC, BMAC, UMAC) can't be
9443 * reset, as in 4 port device they might still be owned
9444 * by the MCP (there is only one leader per path).
9447 MISC_REGISTERS_RESET_REG_1_RST_HC |
9448 MISC_REGISTERS_RESET_REG_1_RST_PXPV |
9449 MISC_REGISTERS_RESET_REG_1_RST_PXP;
9452 MISC_REGISTERS_RESET_REG_2_RST_PCI_MDIO |
9453 MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE |
9454 MISC_REGISTERS_RESET_REG_2_RST_EMAC1_HARD_CORE |
9455 MISC_REGISTERS_RESET_REG_2_RST_MISC_CORE |
9456 MISC_REGISTERS_RESET_REG_2_RST_RBCN |
9457 MISC_REGISTERS_RESET_REG_2_RST_GRC |
9458 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_REG_HARD_CORE |
9459 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_HARD_CORE_RST_B |
9460 MISC_REGISTERS_RESET_REG_2_RST_ATC |
9461 MISC_REGISTERS_RESET_REG_2_PGLC |
9462 MISC_REGISTERS_RESET_REG_2_RST_BMAC0 |
9463 MISC_REGISTERS_RESET_REG_2_RST_BMAC1 |
9464 MISC_REGISTERS_RESET_REG_2_RST_EMAC0 |
9465 MISC_REGISTERS_RESET_REG_2_RST_EMAC1 |
9466 MISC_REGISTERS_RESET_REG_2_UMAC0 |
9467 MISC_REGISTERS_RESET_REG_2_UMAC1;
9470 * Keep the following blocks in reset:
9471 * - all xxMACs are handled by the bnx2x_link code.
9474 MISC_REGISTERS_RESET_REG_2_XMAC |
9475 MISC_REGISTERS_RESET_REG_2_XMAC_SOFT;
9477 /* Full reset masks according to the chip */
9478 reset_mask1 = 0xffffffff;
9481 reset_mask2 = 0xffff;
9482 else if (CHIP_IS_E1H(bp))
9483 reset_mask2 = 0x1ffff;
9484 else if (CHIP_IS_E2(bp))
9485 reset_mask2 = 0xfffff;
9486 else /* CHIP_IS_E3 */
9487 reset_mask2 = 0x3ffffff;
9489 /* Don't reset global blocks unless we need to */
9491 reset_mask2 &= ~global_bits2;
9494 * In case of attention in the QM, we need to reset PXP
9495 * (MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR) before QM
9496 * because otherwise QM reset would release 'close the gates' shortly
9497 * before resetting the PXP, then the PSWRQ would send a write
9498 * request to PGLUE. Then when PXP is reset, PGLUE would try to
9499 * read the payload data from PSWWR, but PSWWR would not
9500 * respond. The write queue in PGLUE would stuck, dmae commands
9501 * would not return. Therefore it's important to reset the second
9502 * reset register (containing the
9503 * MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR bit) before the
9504 * first one (containing the MISC_REGISTERS_RESET_REG_1_RST_QM
9507 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
9508 reset_mask2 & (~not_reset_mask2));
9510 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
9511 reset_mask1 & (~not_reset_mask1));
9516 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
9517 reset_mask2 & (~stay_reset2));
9522 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, reset_mask1);
9527 * bnx2x_er_poll_igu_vq - poll for pending writes bit.
9528 * It should get cleared in no more than 1s.
9530 * @bp: driver handle
9532 * It should get cleared in no more than 1s. Returns 0 if
9533 * pending writes bit gets cleared.
9535 static int bnx2x_er_poll_igu_vq(struct bnx2x *bp)
9541 pend_bits = REG_RD(bp, IGU_REG_PENDING_BITS_STATUS);
9546 usleep_range(1000, 2000);
9547 } while (cnt-- > 0);
9550 BNX2X_ERR("Still pending IGU requests pend_bits=%x!\n",
9558 static int bnx2x_process_kill(struct bnx2x *bp, bool global)
9562 u32 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, pgl_exp_rom2;
9565 /* Empty the Tetris buffer, wait for 1s */
9567 sr_cnt = REG_RD(bp, PXP2_REG_RD_SR_CNT);
9568 blk_cnt = REG_RD(bp, PXP2_REG_RD_BLK_CNT);
9569 port_is_idle_0 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_0);
9570 port_is_idle_1 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_1);
9571 pgl_exp_rom2 = REG_RD(bp, PXP2_REG_PGL_EXP_ROM2);
9573 tags_63_32 = REG_RD(bp, PGLUE_B_REG_TAGS_63_32);
9575 if ((sr_cnt == 0x7e) && (blk_cnt == 0xa0) &&
9576 ((port_is_idle_0 & 0x1) == 0x1) &&
9577 ((port_is_idle_1 & 0x1) == 0x1) &&
9578 (pgl_exp_rom2 == 0xffffffff) &&
9579 (!CHIP_IS_E3(bp) || (tags_63_32 == 0xffffffff)))
9581 usleep_range(1000, 2000);
9582 } while (cnt-- > 0);
9585 BNX2X_ERR("Tetris buffer didn't get empty or there are still outstanding read requests after 1s!\n");
9586 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",
9587 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1,
9594 /* Close gates #2, #3 and #4 */
9595 bnx2x_set_234_gates(bp, true);
9597 /* Poll for IGU VQs for 57712 and newer chips */
9598 if (!CHIP_IS_E1x(bp) && bnx2x_er_poll_igu_vq(bp))
9601 /* TBD: Indicate that "process kill" is in progress to MCP */
9603 /* Clear "unprepared" bit */
9604 REG_WR(bp, MISC_REG_UNPREPARED, 0);
9607 /* Make sure all is written to the chip before the reset */
9610 /* Wait for 1ms to empty GLUE and PCI-E core queues,
9611 * PSWHST, GRC and PSWRD Tetris buffer.
9613 usleep_range(1000, 2000);
9615 /* Prepare to chip reset: */
9618 bnx2x_reset_mcp_prep(bp, &val);
9624 /* reset the chip */
9625 bnx2x_process_kill_chip_reset(bp, global);
9628 /* clear errors in PGB */
9629 if (!CHIP_IS_E1x(bp))
9630 REG_WR(bp, PGLUE_B_REG_LATCHED_ERRORS_CLR, 0x7f);
9632 /* Recover after reset: */
9634 if (global && bnx2x_reset_mcp_comp(bp, val))
9637 /* TBD: Add resetting the NO_MCP mode DB here */
9639 /* Open the gates #2, #3 and #4 */
9640 bnx2x_set_234_gates(bp, false);
9642 /* TBD: IGU/AEU preparation bring back the AEU/IGU to a
9643 * reset state, re-enable attentions. */
9648 static int bnx2x_leader_reset(struct bnx2x *bp)
9651 bool global = bnx2x_reset_is_global(bp);
9654 /* if not going to reset MCP - load "fake" driver to reset HW while
9655 * driver is owner of the HW
9657 if (!global && !BP_NOMCP(bp)) {
9658 load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_REQ,
9659 DRV_MSG_CODE_LOAD_REQ_WITH_LFA);
9661 BNX2X_ERR("MCP response failure, aborting\n");
9663 goto exit_leader_reset;
9665 if ((load_code != FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) &&
9666 (load_code != FW_MSG_CODE_DRV_LOAD_COMMON)) {
9667 BNX2X_ERR("MCP unexpected resp, aborting\n");
9669 goto exit_leader_reset2;
9671 load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_DONE, 0);
9673 BNX2X_ERR("MCP response failure, aborting\n");
9675 goto exit_leader_reset2;
9679 /* Try to recover after the failure */
9680 if (bnx2x_process_kill(bp, global)) {
9681 BNX2X_ERR("Something bad had happen on engine %d! Aii!\n",
9684 goto exit_leader_reset2;
9688 * Clear RESET_IN_PROGRES and RESET_GLOBAL bits and update the driver
9691 bnx2x_set_reset_done(bp);
9693 bnx2x_clear_reset_global(bp);
9696 /* unload "fake driver" if it was loaded */
9697 if (!global && !BP_NOMCP(bp)) {
9698 bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP, 0);
9699 bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
9703 bnx2x_release_leader_lock(bp);
9708 static void bnx2x_recovery_failed(struct bnx2x *bp)
9710 netdev_err(bp->dev, "Recovery has failed. Power cycle is needed.\n");
9712 /* Disconnect this device */
9713 netif_device_detach(bp->dev);
9716 * Block ifup for all function on this engine until "process kill"
9719 bnx2x_set_reset_in_progress(bp);
9721 /* Shut down the power */
9722 bnx2x_set_power_state(bp, PCI_D3hot);
9724 bp->recovery_state = BNX2X_RECOVERY_FAILED;
9730 * Assumption: runs under rtnl lock. This together with the fact
9731 * that it's called only from bnx2x_sp_rtnl() ensure that it
9732 * will never be called when netif_running(bp->dev) is false.
9734 static void bnx2x_parity_recover(struct bnx2x *bp)
9736 bool global = false;
9737 u32 error_recovered, error_unrecovered;
9740 DP(NETIF_MSG_HW, "Handling parity\n");
9742 switch (bp->recovery_state) {
9743 case BNX2X_RECOVERY_INIT:
9744 DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_INIT\n");
9745 is_parity = bnx2x_chk_parity_attn(bp, &global, false);
9746 WARN_ON(!is_parity);
9748 /* Try to get a LEADER_LOCK HW lock */
9749 if (bnx2x_trylock_leader_lock(bp)) {
9750 bnx2x_set_reset_in_progress(bp);
9752 * Check if there is a global attention and if
9753 * there was a global attention, set the global
9758 bnx2x_set_reset_global(bp);
9763 /* Stop the driver */
9764 /* If interface has been removed - break */
9765 if (bnx2x_nic_unload(bp, UNLOAD_RECOVERY, false))
9768 bp->recovery_state = BNX2X_RECOVERY_WAIT;
9770 /* Ensure "is_leader", MCP command sequence and
9771 * "recovery_state" update values are seen on other
9777 case BNX2X_RECOVERY_WAIT:
9778 DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_WAIT\n");
9779 if (bp->is_leader) {
9780 int other_engine = BP_PATH(bp) ? 0 : 1;
9781 bool other_load_status =
9782 bnx2x_get_load_status(bp, other_engine);
9784 bnx2x_get_load_status(bp, BP_PATH(bp));
9785 global = bnx2x_reset_is_global(bp);
9788 * In case of a parity in a global block, let
9789 * the first leader that performs a
9790 * leader_reset() reset the global blocks in
9791 * order to clear global attentions. Otherwise
9792 * the gates will remain closed for that
9796 (global && other_load_status)) {
9797 /* Wait until all other functions get
9800 schedule_delayed_work(&bp->sp_rtnl_task,
9804 /* If all other functions got down -
9805 * try to bring the chip back to
9806 * normal. In any case it's an exit
9807 * point for a leader.
9809 if (bnx2x_leader_reset(bp)) {
9810 bnx2x_recovery_failed(bp);
9814 /* If we are here, means that the
9815 * leader has succeeded and doesn't
9816 * want to be a leader any more. Try
9817 * to continue as a none-leader.
9821 } else { /* non-leader */
9822 if (!bnx2x_reset_is_done(bp, BP_PATH(bp))) {
9823 /* Try to get a LEADER_LOCK HW lock as
9824 * long as a former leader may have
9825 * been unloaded by the user or
9826 * released a leadership by another
9829 if (bnx2x_trylock_leader_lock(bp)) {
9830 /* I'm a leader now! Restart a
9837 schedule_delayed_work(&bp->sp_rtnl_task,
9843 * If there was a global attention, wait
9844 * for it to be cleared.
9846 if (bnx2x_reset_is_global(bp)) {
9847 schedule_delayed_work(
9854 bp->eth_stats.recoverable_error;
9856 bp->eth_stats.unrecoverable_error;
9857 bp->recovery_state =
9858 BNX2X_RECOVERY_NIC_LOADING;
9859 if (bnx2x_nic_load(bp, LOAD_NORMAL)) {
9860 error_unrecovered++;
9862 "Recovery failed. Power cycle needed\n");
9863 /* Disconnect this device */
9864 netif_device_detach(bp->dev);
9865 /* Shut down the power */
9866 bnx2x_set_power_state(
9870 bp->recovery_state =
9871 BNX2X_RECOVERY_DONE;
9875 bp->eth_stats.recoverable_error =
9877 bp->eth_stats.unrecoverable_error =
9889 static int bnx2x_close(struct net_device *dev);
9891 /* bnx2x_nic_unload() flushes the bnx2x_wq, thus reset task is
9892 * scheduled on a general queue in order to prevent a dead lock.
9894 static void bnx2x_sp_rtnl_task(struct work_struct *work)
9896 struct bnx2x *bp = container_of(work, struct bnx2x, sp_rtnl_task.work);
9900 if (!netif_running(bp->dev)) {
9905 if (unlikely(bp->recovery_state != BNX2X_RECOVERY_DONE)) {
9906 #ifdef BNX2X_STOP_ON_ERROR
9907 BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n"
9908 "you will need to reboot when done\n");
9909 goto sp_rtnl_not_reset;
9912 * Clear all pending SP commands as we are going to reset the
9915 bp->sp_rtnl_state = 0;
9918 bnx2x_parity_recover(bp);
9924 if (test_and_clear_bit(BNX2X_SP_RTNL_TX_TIMEOUT, &bp->sp_rtnl_state)) {
9925 #ifdef BNX2X_STOP_ON_ERROR
9926 BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n"
9927 "you will need to reboot when done\n");
9928 goto sp_rtnl_not_reset;
9932 * Clear all pending SP commands as we are going to reset the
9935 bp->sp_rtnl_state = 0;
9938 bnx2x_nic_unload(bp, UNLOAD_NORMAL, true);
9939 bnx2x_nic_load(bp, LOAD_NORMAL);
9944 #ifdef BNX2X_STOP_ON_ERROR
9947 if (test_and_clear_bit(BNX2X_SP_RTNL_SETUP_TC, &bp->sp_rtnl_state))
9948 bnx2x_setup_tc(bp->dev, bp->dcbx_port_params.ets.num_of_cos);
9949 if (test_and_clear_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE, &bp->sp_rtnl_state))
9950 bnx2x_after_function_update(bp);
9952 * in case of fan failure we need to reset id if the "stop on error"
9953 * debug flag is set, since we trying to prevent permanent overheating
9956 if (test_and_clear_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state)) {
9957 DP(NETIF_MSG_HW, "fan failure detected. Unloading driver\n");
9958 netif_device_detach(bp->dev);
9959 bnx2x_close(bp->dev);
9964 if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_MCAST, &bp->sp_rtnl_state)) {
9966 "sending set mcast vf pf channel message from rtnl sp-task\n");
9967 bnx2x_vfpf_set_mcast(bp->dev);
9969 if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_CHANNEL_DOWN,
9970 &bp->sp_rtnl_state)){
9971 if (!test_bit(__LINK_STATE_NOCARRIER, &bp->dev->state)) {
9972 bnx2x_tx_disable(bp);
9973 BNX2X_ERR("PF indicated channel is not servicable anymore. This means this VF device is no longer operational\n");
9977 if (test_and_clear_bit(BNX2X_SP_RTNL_RX_MODE, &bp->sp_rtnl_state)) {
9978 DP(BNX2X_MSG_SP, "Handling Rx Mode setting\n");
9979 bnx2x_set_rx_mode_inner(bp);
9982 if (test_and_clear_bit(BNX2X_SP_RTNL_HYPERVISOR_VLAN,
9983 &bp->sp_rtnl_state))
9984 bnx2x_pf_set_vfs_vlan(bp);
9986 if (test_and_clear_bit(BNX2X_SP_RTNL_TX_STOP, &bp->sp_rtnl_state)) {
9987 bnx2x_dcbx_stop_hw_tx(bp);
9988 bnx2x_dcbx_resume_hw_tx(bp);
9991 if (test_and_clear_bit(BNX2X_SP_RTNL_GET_DRV_VERSION,
9992 &bp->sp_rtnl_state))
9993 bnx2x_update_mng_version(bp);
9995 /* work which needs rtnl lock not-taken (as it takes the lock itself and
9996 * can be called from other contexts as well)
10000 /* enable SR-IOV if applicable */
10001 if (IS_SRIOV(bp) && test_and_clear_bit(BNX2X_SP_RTNL_ENABLE_SRIOV,
10002 &bp->sp_rtnl_state)) {
10003 bnx2x_disable_sriov(bp);
10004 bnx2x_enable_sriov(bp);
10008 static void bnx2x_period_task(struct work_struct *work)
10010 struct bnx2x *bp = container_of(work, struct bnx2x, period_task.work);
10012 if (!netif_running(bp->dev))
10013 goto period_task_exit;
10015 if (CHIP_REV_IS_SLOW(bp)) {
10016 BNX2X_ERR("period task called on emulation, ignoring\n");
10017 goto period_task_exit;
10020 bnx2x_acquire_phy_lock(bp);
10022 * The barrier is needed to ensure the ordering between the writing to
10023 * the bp->port.pmf in the bnx2x_nic_load() or bnx2x_pmf_update() and
10024 * the reading here.
10027 if (bp->port.pmf) {
10028 bnx2x_period_func(&bp->link_params, &bp->link_vars);
10030 /* Re-queue task in 1 sec */
10031 queue_delayed_work(bnx2x_wq, &bp->period_task, 1*HZ);
10034 bnx2x_release_phy_lock(bp);
10040 * Init service functions
10043 static u32 bnx2x_get_pretend_reg(struct bnx2x *bp)
10045 u32 base = PXP2_REG_PGL_PRETEND_FUNC_F0;
10046 u32 stride = PXP2_REG_PGL_PRETEND_FUNC_F1 - base;
10047 return base + (BP_ABS_FUNC(bp)) * stride;
10050 static void bnx2x_prev_unload_close_mac(struct bnx2x *bp,
10051 struct bnx2x_mac_vals *vals)
10053 u32 val, base_addr, offset, mask, reset_reg;
10054 bool mac_stopped = false;
10055 u8 port = BP_PORT(bp);
10057 /* reset addresses as they also mark which values were changed */
10058 vals->bmac_addr = 0;
10059 vals->umac_addr = 0;
10060 vals->xmac_addr = 0;
10061 vals->emac_addr = 0;
10063 reset_reg = REG_RD(bp, MISC_REG_RESET_REG_2);
10065 if (!CHIP_IS_E3(bp)) {
10066 val = REG_RD(bp, NIG_REG_BMAC0_REGS_OUT_EN + port * 4);
10067 mask = MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port;
10068 if ((mask & reset_reg) && val) {
10070 BNX2X_DEV_INFO("Disable bmac Rx\n");
10071 base_addr = BP_PORT(bp) ? NIG_REG_INGRESS_BMAC1_MEM
10072 : NIG_REG_INGRESS_BMAC0_MEM;
10073 offset = CHIP_IS_E2(bp) ? BIGMAC2_REGISTER_BMAC_CONTROL
10074 : BIGMAC_REGISTER_BMAC_CONTROL;
10077 * use rd/wr since we cannot use dmae. This is safe
10078 * since MCP won't access the bus due to the request
10079 * to unload, and no function on the path can be
10080 * loaded at this time.
10082 wb_data[0] = REG_RD(bp, base_addr + offset);
10083 wb_data[1] = REG_RD(bp, base_addr + offset + 0x4);
10084 vals->bmac_addr = base_addr + offset;
10085 vals->bmac_val[0] = wb_data[0];
10086 vals->bmac_val[1] = wb_data[1];
10087 wb_data[0] &= ~BMAC_CONTROL_RX_ENABLE;
10088 REG_WR(bp, vals->bmac_addr, wb_data[0]);
10089 REG_WR(bp, vals->bmac_addr + 0x4, wb_data[1]);
10091 BNX2X_DEV_INFO("Disable emac Rx\n");
10092 vals->emac_addr = NIG_REG_NIG_EMAC0_EN + BP_PORT(bp)*4;
10093 vals->emac_val = REG_RD(bp, vals->emac_addr);
10094 REG_WR(bp, vals->emac_addr, 0);
10095 mac_stopped = true;
10097 if (reset_reg & MISC_REGISTERS_RESET_REG_2_XMAC) {
10098 BNX2X_DEV_INFO("Disable xmac Rx\n");
10099 base_addr = BP_PORT(bp) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
10100 val = REG_RD(bp, base_addr + XMAC_REG_PFC_CTRL_HI);
10101 REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
10103 REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
10105 vals->xmac_addr = base_addr + XMAC_REG_CTRL;
10106 vals->xmac_val = REG_RD(bp, vals->xmac_addr);
10107 REG_WR(bp, vals->xmac_addr, 0);
10108 mac_stopped = true;
10110 mask = MISC_REGISTERS_RESET_REG_2_UMAC0 << port;
10111 if (mask & reset_reg) {
10112 BNX2X_DEV_INFO("Disable umac Rx\n");
10113 base_addr = BP_PORT(bp) ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
10114 vals->umac_addr = base_addr + UMAC_REG_COMMAND_CONFIG;
10115 vals->umac_val = REG_RD(bp, vals->umac_addr);
10116 REG_WR(bp, vals->umac_addr, 0);
10117 mac_stopped = true;
10125 #define BNX2X_PREV_UNDI_PROD_ADDR(p) (BAR_TSTRORM_INTMEM + 0x1508 + ((p) << 4))
10126 #define BNX2X_PREV_UNDI_RCQ(val) ((val) & 0xffff)
10127 #define BNX2X_PREV_UNDI_BD(val) ((val) >> 16 & 0xffff)
10128 #define BNX2X_PREV_UNDI_PROD(rcq, bd) ((bd) << 16 | (rcq))
10130 #define BCM_5710_UNDI_FW_MF_MAJOR (0x07)
10131 #define BCM_5710_UNDI_FW_MF_MINOR (0x08)
10132 #define BCM_5710_UNDI_FW_MF_VERS (0x05)
10133 #define BNX2X_PREV_UNDI_MF_PORT(p) (BAR_TSTRORM_INTMEM + 0x150c + ((p) << 4))
10134 #define BNX2X_PREV_UNDI_MF_FUNC(f) (BAR_TSTRORM_INTMEM + 0x184c + ((f) << 4))
10136 static bool bnx2x_prev_is_after_undi(struct bnx2x *bp)
10138 /* UNDI marks its presence in DORQ -
10139 * it initializes CID offset for normal bell to 0x7
10141 if (!(REG_RD(bp, MISC_REG_RESET_REG_1) &
10142 MISC_REGISTERS_RESET_REG_1_RST_DORQ))
10145 if (REG_RD(bp, DORQ_REG_NORM_CID_OFST) == 0x7) {
10146 BNX2X_DEV_INFO("UNDI previously loaded\n");
10153 static bool bnx2x_prev_unload_undi_fw_supports_mf(struct bnx2x *bp)
10155 u8 major, minor, version;
10158 /* Must check that FW is loaded */
10159 if (!(REG_RD(bp, MISC_REG_RESET_REG_1) &
10160 MISC_REGISTERS_RESET_REG_1_RST_XSEM)) {
10161 BNX2X_DEV_INFO("XSEM is reset - UNDI MF FW is not loaded\n");
10165 /* Read Currently loaded FW version */
10166 fw = REG_RD(bp, XSEM_REG_PRAM);
10168 minor = (fw >> 0x8) & 0xff;
10169 version = (fw >> 0x10) & 0xff;
10170 BNX2X_DEV_INFO("Loaded FW: 0x%08x: Major 0x%02x Minor 0x%02x Version 0x%02x\n",
10171 fw, major, minor, version);
10173 if (major > BCM_5710_UNDI_FW_MF_MAJOR)
10176 if ((major == BCM_5710_UNDI_FW_MF_MAJOR) &&
10177 (minor > BCM_5710_UNDI_FW_MF_MINOR))
10180 if ((major == BCM_5710_UNDI_FW_MF_MAJOR) &&
10181 (minor == BCM_5710_UNDI_FW_MF_MINOR) &&
10182 (version >= BCM_5710_UNDI_FW_MF_VERS))
10188 static void bnx2x_prev_unload_undi_mf(struct bnx2x *bp)
10192 /* Due to legacy (FW) code, the first function on each engine has a
10193 * different offset macro from the rest of the functions.
10194 * Setting this for all 8 functions is harmless regardless of whether
10195 * this is actually a multi-function device.
10197 for (i = 0; i < 2; i++)
10198 REG_WR(bp, BNX2X_PREV_UNDI_MF_PORT(i), 1);
10200 for (i = 2; i < 8; i++)
10201 REG_WR(bp, BNX2X_PREV_UNDI_MF_FUNC(i - 2), 1);
10203 BNX2X_DEV_INFO("UNDI FW (MF) set to discard\n");
10206 static void bnx2x_prev_unload_undi_inc(struct bnx2x *bp, u8 port, u8 inc)
10209 u32 tmp_reg = REG_RD(bp, BNX2X_PREV_UNDI_PROD_ADDR(port));
10211 rcq = BNX2X_PREV_UNDI_RCQ(tmp_reg) + inc;
10212 bd = BNX2X_PREV_UNDI_BD(tmp_reg) + inc;
10214 tmp_reg = BNX2X_PREV_UNDI_PROD(rcq, bd);
10215 REG_WR(bp, BNX2X_PREV_UNDI_PROD_ADDR(port), tmp_reg);
10217 BNX2X_DEV_INFO("UNDI producer [%d] rings bd -> 0x%04x, rcq -> 0x%04x\n",
10221 static int bnx2x_prev_mcp_done(struct bnx2x *bp)
10223 u32 rc = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE,
10224 DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET);
10226 BNX2X_ERR("MCP response failure, aborting\n");
10233 static struct bnx2x_prev_path_list *
10234 bnx2x_prev_path_get_entry(struct bnx2x *bp)
10236 struct bnx2x_prev_path_list *tmp_list;
10238 list_for_each_entry(tmp_list, &bnx2x_prev_list, list)
10239 if (PCI_SLOT(bp->pdev->devfn) == tmp_list->slot &&
10240 bp->pdev->bus->number == tmp_list->bus &&
10241 BP_PATH(bp) == tmp_list->path)
10247 static int bnx2x_prev_path_mark_eeh(struct bnx2x *bp)
10249 struct bnx2x_prev_path_list *tmp_list;
10252 rc = down_interruptible(&bnx2x_prev_sem);
10254 BNX2X_ERR("Received %d when tried to take lock\n", rc);
10258 tmp_list = bnx2x_prev_path_get_entry(bp);
10263 BNX2X_ERR("path %d: Entry does not exist for eeh; Flow occurs before initial insmod is over ?\n",
10267 up(&bnx2x_prev_sem);
10272 static bool bnx2x_prev_is_path_marked(struct bnx2x *bp)
10274 struct bnx2x_prev_path_list *tmp_list;
10277 if (down_trylock(&bnx2x_prev_sem))
10280 tmp_list = bnx2x_prev_path_get_entry(bp);
10282 if (tmp_list->aer) {
10283 DP(NETIF_MSG_HW, "Path %d was marked by AER\n",
10287 BNX2X_DEV_INFO("Path %d was already cleaned from previous drivers\n",
10292 up(&bnx2x_prev_sem);
10297 bool bnx2x_port_after_undi(struct bnx2x *bp)
10299 struct bnx2x_prev_path_list *entry;
10302 down(&bnx2x_prev_sem);
10304 entry = bnx2x_prev_path_get_entry(bp);
10305 val = !!(entry && (entry->undi & (1 << BP_PORT(bp))));
10307 up(&bnx2x_prev_sem);
10312 static int bnx2x_prev_mark_path(struct bnx2x *bp, bool after_undi)
10314 struct bnx2x_prev_path_list *tmp_list;
10317 rc = down_interruptible(&bnx2x_prev_sem);
10319 BNX2X_ERR("Received %d when tried to take lock\n", rc);
10323 /* Check whether the entry for this path already exists */
10324 tmp_list = bnx2x_prev_path_get_entry(bp);
10326 if (!tmp_list->aer) {
10327 BNX2X_ERR("Re-Marking the path.\n");
10329 DP(NETIF_MSG_HW, "Removing AER indication from path %d\n",
10333 up(&bnx2x_prev_sem);
10336 up(&bnx2x_prev_sem);
10338 /* Create an entry for this path and add it */
10339 tmp_list = kmalloc(sizeof(struct bnx2x_prev_path_list), GFP_KERNEL);
10341 BNX2X_ERR("Failed to allocate 'bnx2x_prev_path_list'\n");
10345 tmp_list->bus = bp->pdev->bus->number;
10346 tmp_list->slot = PCI_SLOT(bp->pdev->devfn);
10347 tmp_list->path = BP_PATH(bp);
10349 tmp_list->undi = after_undi ? (1 << BP_PORT(bp)) : 0;
10351 rc = down_interruptible(&bnx2x_prev_sem);
10353 BNX2X_ERR("Received %d when tried to take lock\n", rc);
10356 DP(NETIF_MSG_HW, "Marked path [%d] - finished previous unload\n",
10358 list_add(&tmp_list->list, &bnx2x_prev_list);
10359 up(&bnx2x_prev_sem);
10365 static int bnx2x_do_flr(struct bnx2x *bp)
10367 struct pci_dev *dev = bp->pdev;
10369 if (CHIP_IS_E1x(bp)) {
10370 BNX2X_DEV_INFO("FLR not supported in E1/E1H\n");
10374 /* only bootcode REQ_BC_VER_4_INITIATE_FLR and onwards support flr */
10375 if (bp->common.bc_ver < REQ_BC_VER_4_INITIATE_FLR) {
10376 BNX2X_ERR("FLR not supported by BC_VER: 0x%x\n",
10377 bp->common.bc_ver);
10381 if (!pci_wait_for_pending_transaction(dev))
10382 dev_err(&dev->dev, "transaction is not cleared; proceeding with reset anyway\n");
10384 BNX2X_DEV_INFO("Initiating FLR\n");
10385 bnx2x_fw_command(bp, DRV_MSG_CODE_INITIATE_FLR, 0);
10390 static int bnx2x_prev_unload_uncommon(struct bnx2x *bp)
10394 BNX2X_DEV_INFO("Uncommon unload Flow\n");
10396 /* Test if previous unload process was already finished for this path */
10397 if (bnx2x_prev_is_path_marked(bp))
10398 return bnx2x_prev_mcp_done(bp);
10400 BNX2X_DEV_INFO("Path is unmarked\n");
10402 /* Cannot proceed with FLR if UNDI is loaded, since FW does not match */
10403 if (bnx2x_prev_is_after_undi(bp))
10406 /* If function has FLR capabilities, and existing FW version matches
10407 * the one required, then FLR will be sufficient to clean any residue
10408 * left by previous driver
10410 rc = bnx2x_compare_fw_ver(bp, FW_MSG_CODE_DRV_LOAD_FUNCTION, false);
10413 /* fw version is good */
10414 BNX2X_DEV_INFO("FW version matches our own. Attempting FLR\n");
10415 rc = bnx2x_do_flr(bp);
10419 /* FLR was performed */
10420 BNX2X_DEV_INFO("FLR successful\n");
10424 BNX2X_DEV_INFO("Could not FLR\n");
10427 /* Close the MCP request, return failure*/
10428 rc = bnx2x_prev_mcp_done(bp);
10430 rc = BNX2X_PREV_WAIT_NEEDED;
10435 static int bnx2x_prev_unload_common(struct bnx2x *bp)
10437 u32 reset_reg, tmp_reg = 0, rc;
10438 bool prev_undi = false;
10439 struct bnx2x_mac_vals mac_vals;
10441 /* It is possible a previous function received 'common' answer,
10442 * but hasn't loaded yet, therefore creating a scenario of
10443 * multiple functions receiving 'common' on the same path.
10445 BNX2X_DEV_INFO("Common unload Flow\n");
10447 memset(&mac_vals, 0, sizeof(mac_vals));
10449 if (bnx2x_prev_is_path_marked(bp))
10450 return bnx2x_prev_mcp_done(bp);
10452 reset_reg = REG_RD(bp, MISC_REG_RESET_REG_1);
10454 /* Reset should be performed after BRB is emptied */
10455 if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_BRB1) {
10456 u32 timer_count = 1000;
10457 bool need_write = true;
10459 /* Close the MAC Rx to prevent BRB from filling up */
10460 bnx2x_prev_unload_close_mac(bp, &mac_vals);
10462 /* close LLH filters towards the BRB */
10463 bnx2x_set_rx_filter(&bp->link_params, 0);
10465 /* Check if the UNDI driver was previously loaded */
10466 if (bnx2x_prev_is_after_undi(bp)) {
10468 /* clear the UNDI indication */
10469 REG_WR(bp, DORQ_REG_NORM_CID_OFST, 0);
10470 /* clear possible idle check errors */
10471 REG_RD(bp, NIG_REG_NIG_INT_STS_CLR_0);
10473 if (!CHIP_IS_E1x(bp))
10474 /* block FW from writing to host */
10475 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
10477 /* wait until BRB is empty */
10478 tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
10479 while (timer_count) {
10480 u32 prev_brb = tmp_reg;
10482 tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
10486 BNX2X_DEV_INFO("BRB still has 0x%08x\n", tmp_reg);
10488 /* reset timer as long as BRB actually gets emptied */
10489 if (prev_brb > tmp_reg)
10490 timer_count = 1000;
10494 /* New UNDI FW supports MF and contains better
10495 * cleaning methods - might be redundant but harmless.
10497 if (bnx2x_prev_unload_undi_fw_supports_mf(bp)) {
10499 bnx2x_prev_unload_undi_mf(bp);
10500 need_write = false;
10502 } else if (prev_undi) {
10503 /* If UNDI resides in memory,
10504 * manually increment it
10506 bnx2x_prev_unload_undi_inc(bp, BP_PORT(bp), 1);
10512 BNX2X_ERR("Failed to empty BRB, hope for the best\n");
10515 /* No packets are in the pipeline, path is ready for reset */
10516 bnx2x_reset_common(bp);
10518 if (mac_vals.xmac_addr)
10519 REG_WR(bp, mac_vals.xmac_addr, mac_vals.xmac_val);
10520 if (mac_vals.umac_addr)
10521 REG_WR(bp, mac_vals.umac_addr, mac_vals.umac_val);
10522 if (mac_vals.emac_addr)
10523 REG_WR(bp, mac_vals.emac_addr, mac_vals.emac_val);
10524 if (mac_vals.bmac_addr) {
10525 REG_WR(bp, mac_vals.bmac_addr, mac_vals.bmac_val[0]);
10526 REG_WR(bp, mac_vals.bmac_addr + 4, mac_vals.bmac_val[1]);
10529 rc = bnx2x_prev_mark_path(bp, prev_undi);
10531 bnx2x_prev_mcp_done(bp);
10535 return bnx2x_prev_mcp_done(bp);
10538 /* previous driver DMAE transaction may have occurred when pre-boot stage ended
10539 * and boot began, or when kdump kernel was loaded. Either case would invalidate
10540 * the addresses of the transaction, resulting in was-error bit set in the pci
10541 * causing all hw-to-host pcie transactions to timeout. If this happened we want
10542 * to clear the interrupt which detected this from the pglueb and the was done
10545 static void bnx2x_prev_interrupted_dmae(struct bnx2x *bp)
10547 if (!CHIP_IS_E1x(bp)) {
10548 u32 val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS);
10549 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN) {
10551 "'was error' bit was found to be set in pglueb upon startup. Clearing\n");
10552 REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR,
10558 static int bnx2x_prev_unload(struct bnx2x *bp)
10560 int time_counter = 10;
10561 u32 rc, fw, hw_lock_reg, hw_lock_val;
10562 BNX2X_DEV_INFO("Entering Previous Unload Flow\n");
10564 /* clear hw from errors which may have resulted from an interrupted
10565 * dmae transaction.
10567 bnx2x_prev_interrupted_dmae(bp);
10569 /* Release previously held locks */
10570 hw_lock_reg = (BP_FUNC(bp) <= 5) ?
10571 (MISC_REG_DRIVER_CONTROL_1 + BP_FUNC(bp) * 8) :
10572 (MISC_REG_DRIVER_CONTROL_7 + (BP_FUNC(bp) - 6) * 8);
10574 hw_lock_val = REG_RD(bp, hw_lock_reg);
10576 if (hw_lock_val & HW_LOCK_RESOURCE_NVRAM) {
10577 BNX2X_DEV_INFO("Release Previously held NVRAM lock\n");
10578 REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
10579 (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << BP_PORT(bp)));
10582 BNX2X_DEV_INFO("Release Previously held hw lock\n");
10583 REG_WR(bp, hw_lock_reg, 0xffffffff);
10585 BNX2X_DEV_INFO("No need to release hw/nvram locks\n");
10587 if (MCPR_ACCESS_LOCK_LOCK & REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK)) {
10588 BNX2X_DEV_INFO("Release previously held alr\n");
10589 bnx2x_release_alr(bp);
10594 /* Lock MCP using an unload request */
10595 fw = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS, 0);
10597 BNX2X_ERR("MCP response failure, aborting\n");
10602 rc = down_interruptible(&bnx2x_prev_sem);
10604 BNX2X_ERR("Cannot check for AER; Received %d when tried to take lock\n",
10607 /* If Path is marked by EEH, ignore unload status */
10608 aer = !!(bnx2x_prev_path_get_entry(bp) &&
10609 bnx2x_prev_path_get_entry(bp)->aer);
10610 up(&bnx2x_prev_sem);
10613 if (fw == FW_MSG_CODE_DRV_UNLOAD_COMMON || aer) {
10614 rc = bnx2x_prev_unload_common(bp);
10618 /* non-common reply from MCP might require looping */
10619 rc = bnx2x_prev_unload_uncommon(bp);
10620 if (rc != BNX2X_PREV_WAIT_NEEDED)
10624 } while (--time_counter);
10626 if (!time_counter || rc) {
10627 BNX2X_DEV_INFO("Unloading previous driver did not occur, Possibly due to MF UNDI\n");
10628 rc = -EPROBE_DEFER;
10631 /* Mark function if its port was used to boot from SAN */
10632 if (bnx2x_port_after_undi(bp))
10633 bp->link_params.feature_config_flags |=
10634 FEATURE_CONFIG_BOOT_FROM_SAN;
10636 BNX2X_DEV_INFO("Finished Previous Unload Flow [%d]\n", rc);
10641 static void bnx2x_get_common_hwinfo(struct bnx2x *bp)
10643 u32 val, val2, val3, val4, id, boot_mode;
10646 /* Get the chip revision id and number. */
10647 /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
10648 val = REG_RD(bp, MISC_REG_CHIP_NUM);
10649 id = ((val & 0xffff) << 16);
10650 val = REG_RD(bp, MISC_REG_CHIP_REV);
10651 id |= ((val & 0xf) << 12);
10653 /* Metal is read from PCI regs, but we can't access >=0x400 from
10654 * the configuration space (so we need to reg_rd)
10656 val = REG_RD(bp, PCICFG_OFFSET + PCI_ID_VAL3);
10657 id |= (((val >> 24) & 0xf) << 4);
10658 val = REG_RD(bp, MISC_REG_BOND_ID);
10660 bp->common.chip_id = id;
10662 /* force 57811 according to MISC register */
10663 if (REG_RD(bp, MISC_REG_CHIP_TYPE) & MISC_REG_CHIP_TYPE_57811_MASK) {
10664 if (CHIP_IS_57810(bp))
10665 bp->common.chip_id = (CHIP_NUM_57811 << 16) |
10666 (bp->common.chip_id & 0x0000FFFF);
10667 else if (CHIP_IS_57810_MF(bp))
10668 bp->common.chip_id = (CHIP_NUM_57811_MF << 16) |
10669 (bp->common.chip_id & 0x0000FFFF);
10670 bp->common.chip_id |= 0x1;
10673 /* Set doorbell size */
10674 bp->db_size = (1 << BNX2X_DB_SHIFT);
10676 if (!CHIP_IS_E1x(bp)) {
10677 val = REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR);
10678 if ((val & 1) == 0)
10679 val = REG_RD(bp, MISC_REG_PORT4MODE_EN);
10681 val = (val >> 1) & 1;
10682 BNX2X_DEV_INFO("chip is in %s\n", val ? "4_PORT_MODE" :
10684 bp->common.chip_port_mode = val ? CHIP_4_PORT_MODE :
10687 if (CHIP_MODE_IS_4_PORT(bp))
10688 bp->pfid = (bp->pf_num >> 1); /* 0..3 */
10690 bp->pfid = (bp->pf_num & 0x6); /* 0, 2, 4, 6 */
10692 bp->common.chip_port_mode = CHIP_PORT_MODE_NONE; /* N/A */
10693 bp->pfid = bp->pf_num; /* 0..7 */
10696 BNX2X_DEV_INFO("pf_id: %x", bp->pfid);
10698 bp->link_params.chip_id = bp->common.chip_id;
10699 BNX2X_DEV_INFO("chip ID is 0x%x\n", id);
10701 val = (REG_RD(bp, 0x2874) & 0x55);
10702 if ((bp->common.chip_id & 0x1) ||
10703 (CHIP_IS_E1(bp) && val) || (CHIP_IS_E1H(bp) && (val == 0x55))) {
10704 bp->flags |= ONE_PORT_FLAG;
10705 BNX2X_DEV_INFO("single port device\n");
10708 val = REG_RD(bp, MCP_REG_MCPR_NVM_CFG4);
10709 bp->common.flash_size = (BNX2X_NVRAM_1MB_SIZE <<
10710 (val & MCPR_NVM_CFG4_FLASH_SIZE));
10711 BNX2X_DEV_INFO("flash_size 0x%x (%d)\n",
10712 bp->common.flash_size, bp->common.flash_size);
10714 bnx2x_init_shmem(bp);
10716 bp->common.shmem2_base = REG_RD(bp, (BP_PATH(bp) ?
10717 MISC_REG_GENERIC_CR_1 :
10718 MISC_REG_GENERIC_CR_0));
10720 bp->link_params.shmem_base = bp->common.shmem_base;
10721 bp->link_params.shmem2_base = bp->common.shmem2_base;
10722 if (SHMEM2_RD(bp, size) >
10723 (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
10724 bp->link_params.lfa_base =
10725 REG_RD(bp, bp->common.shmem2_base +
10726 (u32)offsetof(struct shmem2_region,
10727 lfa_host_addr[BP_PORT(bp)]));
10729 bp->link_params.lfa_base = 0;
10730 BNX2X_DEV_INFO("shmem offset 0x%x shmem2 offset 0x%x\n",
10731 bp->common.shmem_base, bp->common.shmem2_base);
10733 if (!bp->common.shmem_base) {
10734 BNX2X_DEV_INFO("MCP not active\n");
10735 bp->flags |= NO_MCP_FLAG;
10739 bp->common.hw_config = SHMEM_RD(bp, dev_info.shared_hw_config.config);
10740 BNX2X_DEV_INFO("hw_config 0x%08x\n", bp->common.hw_config);
10742 bp->link_params.hw_led_mode = ((bp->common.hw_config &
10743 SHARED_HW_CFG_LED_MODE_MASK) >>
10744 SHARED_HW_CFG_LED_MODE_SHIFT);
10746 bp->link_params.feature_config_flags = 0;
10747 val = SHMEM_RD(bp, dev_info.shared_feature_config.config);
10748 if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED)
10749 bp->link_params.feature_config_flags |=
10750 FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
10752 bp->link_params.feature_config_flags &=
10753 ~FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
10755 val = SHMEM_RD(bp, dev_info.bc_rev) >> 8;
10756 bp->common.bc_ver = val;
10757 BNX2X_DEV_INFO("bc_ver %X\n", val);
10758 if (val < BNX2X_BC_VER) {
10759 /* for now only warn
10760 * later we might need to enforce this */
10761 BNX2X_ERR("This driver needs bc_ver %X but found %X, please upgrade BC\n",
10762 BNX2X_BC_VER, val);
10764 bp->link_params.feature_config_flags |=
10765 (val >= REQ_BC_VER_4_VRFY_FIRST_PHY_OPT_MDL) ?
10766 FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY : 0;
10768 bp->link_params.feature_config_flags |=
10769 (val >= REQ_BC_VER_4_VRFY_SPECIFIC_PHY_OPT_MDL) ?
10770 FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY : 0;
10771 bp->link_params.feature_config_flags |=
10772 (val >= REQ_BC_VER_4_VRFY_AFEX_SUPPORTED) ?
10773 FEATURE_CONFIG_BC_SUPPORTS_AFEX : 0;
10774 bp->link_params.feature_config_flags |=
10775 (val >= REQ_BC_VER_4_SFP_TX_DISABLE_SUPPORTED) ?
10776 FEATURE_CONFIG_BC_SUPPORTS_SFP_TX_DISABLED : 0;
10778 bp->link_params.feature_config_flags |=
10779 (val >= REQ_BC_VER_4_MT_SUPPORTED) ?
10780 FEATURE_CONFIG_MT_SUPPORT : 0;
10782 bp->flags |= (val >= REQ_BC_VER_4_PFC_STATS_SUPPORTED) ?
10783 BC_SUPPORTS_PFC_STATS : 0;
10785 bp->flags |= (val >= REQ_BC_VER_4_FCOE_FEATURES) ?
10786 BC_SUPPORTS_FCOE_FEATURES : 0;
10788 bp->flags |= (val >= REQ_BC_VER_4_DCBX_ADMIN_MSG_NON_PMF) ?
10789 BC_SUPPORTS_DCBX_MSG_NON_PMF : 0;
10791 bp->flags |= (val >= REQ_BC_VER_4_RMMOD_CMD) ?
10792 BC_SUPPORTS_RMMOD_CMD : 0;
10794 boot_mode = SHMEM_RD(bp,
10795 dev_info.port_feature_config[BP_PORT(bp)].mba_config) &
10796 PORT_FEATURE_MBA_BOOT_AGENT_TYPE_MASK;
10797 switch (boot_mode) {
10798 case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_PXE:
10799 bp->common.boot_mode = FEATURE_ETH_BOOTMODE_PXE;
10801 case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_ISCSIB:
10802 bp->common.boot_mode = FEATURE_ETH_BOOTMODE_ISCSI;
10804 case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_FCOE_BOOT:
10805 bp->common.boot_mode = FEATURE_ETH_BOOTMODE_FCOE;
10807 case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_NONE:
10808 bp->common.boot_mode = FEATURE_ETH_BOOTMODE_NONE;
10812 pci_read_config_word(bp->pdev, bp->pdev->pm_cap + PCI_PM_PMC, &pmc);
10813 bp->flags |= (pmc & PCI_PM_CAP_PME_D3cold) ? 0 : NO_WOL_FLAG;
10815 BNX2X_DEV_INFO("%sWoL capable\n",
10816 (bp->flags & NO_WOL_FLAG) ? "not " : "");
10818 val = SHMEM_RD(bp, dev_info.shared_hw_config.part_num);
10819 val2 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[4]);
10820 val3 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[8]);
10821 val4 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[12]);
10823 dev_info(&bp->pdev->dev, "part number %X-%X-%X-%X\n",
10824 val, val2, val3, val4);
10827 #define IGU_FID(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID)
10828 #define IGU_VEC(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR)
10830 static int bnx2x_get_igu_cam_info(struct bnx2x *bp)
10832 int pfid = BP_FUNC(bp);
10835 u8 fid, igu_sb_cnt = 0;
10837 bp->igu_base_sb = 0xff;
10838 if (CHIP_INT_MODE_IS_BC(bp)) {
10839 int vn = BP_VN(bp);
10840 igu_sb_cnt = bp->igu_sb_cnt;
10841 bp->igu_base_sb = (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn) *
10844 bp->igu_dsb_id = E1HVN_MAX * FP_SB_MAX_E1x +
10845 (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn);
10850 /* IGU in normal mode - read CAM */
10851 for (igu_sb_id = 0; igu_sb_id < IGU_REG_MAPPING_MEMORY_SIZE;
10853 val = REG_RD(bp, IGU_REG_MAPPING_MEMORY + igu_sb_id * 4);
10854 if (!(val & IGU_REG_MAPPING_MEMORY_VALID))
10856 fid = IGU_FID(val);
10857 if ((fid & IGU_FID_ENCODE_IS_PF)) {
10858 if ((fid & IGU_FID_PF_NUM_MASK) != pfid)
10860 if (IGU_VEC(val) == 0)
10861 /* default status block */
10862 bp->igu_dsb_id = igu_sb_id;
10864 if (bp->igu_base_sb == 0xff)
10865 bp->igu_base_sb = igu_sb_id;
10871 #ifdef CONFIG_PCI_MSI
10872 /* Due to new PF resource allocation by MFW T7.4 and above, it's
10873 * optional that number of CAM entries will not be equal to the value
10874 * advertised in PCI.
10875 * Driver should use the minimal value of both as the actual status
10878 bp->igu_sb_cnt = min_t(int, bp->igu_sb_cnt, igu_sb_cnt);
10881 if (igu_sb_cnt == 0) {
10882 BNX2X_ERR("CAM configuration error\n");
10889 static void bnx2x_link_settings_supported(struct bnx2x *bp, u32 switch_cfg)
10891 int cfg_size = 0, idx, port = BP_PORT(bp);
10893 /* Aggregation of supported attributes of all external phys */
10894 bp->port.supported[0] = 0;
10895 bp->port.supported[1] = 0;
10896 switch (bp->link_params.num_phys) {
10898 bp->port.supported[0] = bp->link_params.phy[INT_PHY].supported;
10902 bp->port.supported[0] = bp->link_params.phy[EXT_PHY1].supported;
10906 if (bp->link_params.multi_phy_config &
10907 PORT_HW_CFG_PHY_SWAPPED_ENABLED) {
10908 bp->port.supported[1] =
10909 bp->link_params.phy[EXT_PHY1].supported;
10910 bp->port.supported[0] =
10911 bp->link_params.phy[EXT_PHY2].supported;
10913 bp->port.supported[0] =
10914 bp->link_params.phy[EXT_PHY1].supported;
10915 bp->port.supported[1] =
10916 bp->link_params.phy[EXT_PHY2].supported;
10922 if (!(bp->port.supported[0] || bp->port.supported[1])) {
10923 BNX2X_ERR("NVRAM config error. BAD phy config. PHY1 config 0x%x, PHY2 config 0x%x\n",
10925 dev_info.port_hw_config[port].external_phy_config),
10927 dev_info.port_hw_config[port].external_phy_config2));
10931 if (CHIP_IS_E3(bp))
10932 bp->port.phy_addr = REG_RD(bp, MISC_REG_WC0_CTRL_PHY_ADDR);
10934 switch (switch_cfg) {
10935 case SWITCH_CFG_1G:
10936 bp->port.phy_addr = REG_RD(
10937 bp, NIG_REG_SERDES0_CTRL_PHY_ADDR + port*0x10);
10939 case SWITCH_CFG_10G:
10940 bp->port.phy_addr = REG_RD(
10941 bp, NIG_REG_XGXS0_CTRL_PHY_ADDR + port*0x18);
10944 BNX2X_ERR("BAD switch_cfg link_config 0x%x\n",
10945 bp->port.link_config[0]);
10949 BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr);
10950 /* mask what we support according to speed_cap_mask per configuration */
10951 for (idx = 0; idx < cfg_size; idx++) {
10952 if (!(bp->link_params.speed_cap_mask[idx] &
10953 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF))
10954 bp->port.supported[idx] &= ~SUPPORTED_10baseT_Half;
10956 if (!(bp->link_params.speed_cap_mask[idx] &
10957 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL))
10958 bp->port.supported[idx] &= ~SUPPORTED_10baseT_Full;
10960 if (!(bp->link_params.speed_cap_mask[idx] &
10961 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF))
10962 bp->port.supported[idx] &= ~SUPPORTED_100baseT_Half;
10964 if (!(bp->link_params.speed_cap_mask[idx] &
10965 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL))
10966 bp->port.supported[idx] &= ~SUPPORTED_100baseT_Full;
10968 if (!(bp->link_params.speed_cap_mask[idx] &
10969 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G))
10970 bp->port.supported[idx] &= ~(SUPPORTED_1000baseT_Half |
10971 SUPPORTED_1000baseT_Full);
10973 if (!(bp->link_params.speed_cap_mask[idx] &
10974 PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
10975 bp->port.supported[idx] &= ~SUPPORTED_2500baseX_Full;
10977 if (!(bp->link_params.speed_cap_mask[idx] &
10978 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G))
10979 bp->port.supported[idx] &= ~SUPPORTED_10000baseT_Full;
10981 if (!(bp->link_params.speed_cap_mask[idx] &
10982 PORT_HW_CFG_SPEED_CAPABILITY_D0_20G))
10983 bp->port.supported[idx] &= ~SUPPORTED_20000baseKR2_Full;
10986 BNX2X_DEV_INFO("supported 0x%x 0x%x\n", bp->port.supported[0],
10987 bp->port.supported[1]);
10990 static void bnx2x_link_settings_requested(struct bnx2x *bp)
10992 u32 link_config, idx, cfg_size = 0;
10993 bp->port.advertising[0] = 0;
10994 bp->port.advertising[1] = 0;
10995 switch (bp->link_params.num_phys) {
11004 for (idx = 0; idx < cfg_size; idx++) {
11005 bp->link_params.req_duplex[idx] = DUPLEX_FULL;
11006 link_config = bp->port.link_config[idx];
11007 switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) {
11008 case PORT_FEATURE_LINK_SPEED_AUTO:
11009 if (bp->port.supported[idx] & SUPPORTED_Autoneg) {
11010 bp->link_params.req_line_speed[idx] =
11012 bp->port.advertising[idx] |=
11013 bp->port.supported[idx];
11014 if (bp->link_params.phy[EXT_PHY1].type ==
11015 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
11016 bp->port.advertising[idx] |=
11017 (SUPPORTED_100baseT_Half |
11018 SUPPORTED_100baseT_Full);
11020 /* force 10G, no AN */
11021 bp->link_params.req_line_speed[idx] =
11023 bp->port.advertising[idx] |=
11024 (ADVERTISED_10000baseT_Full |
11030 case PORT_FEATURE_LINK_SPEED_10M_FULL:
11031 if (bp->port.supported[idx] & SUPPORTED_10baseT_Full) {
11032 bp->link_params.req_line_speed[idx] =
11034 bp->port.advertising[idx] |=
11035 (ADVERTISED_10baseT_Full |
11038 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
11040 bp->link_params.speed_cap_mask[idx]);
11045 case PORT_FEATURE_LINK_SPEED_10M_HALF:
11046 if (bp->port.supported[idx] & SUPPORTED_10baseT_Half) {
11047 bp->link_params.req_line_speed[idx] =
11049 bp->link_params.req_duplex[idx] =
11051 bp->port.advertising[idx] |=
11052 (ADVERTISED_10baseT_Half |
11055 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
11057 bp->link_params.speed_cap_mask[idx]);
11062 case PORT_FEATURE_LINK_SPEED_100M_FULL:
11063 if (bp->port.supported[idx] &
11064 SUPPORTED_100baseT_Full) {
11065 bp->link_params.req_line_speed[idx] =
11067 bp->port.advertising[idx] |=
11068 (ADVERTISED_100baseT_Full |
11071 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
11073 bp->link_params.speed_cap_mask[idx]);
11078 case PORT_FEATURE_LINK_SPEED_100M_HALF:
11079 if (bp->port.supported[idx] &
11080 SUPPORTED_100baseT_Half) {
11081 bp->link_params.req_line_speed[idx] =
11083 bp->link_params.req_duplex[idx] =
11085 bp->port.advertising[idx] |=
11086 (ADVERTISED_100baseT_Half |
11089 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
11091 bp->link_params.speed_cap_mask[idx]);
11096 case PORT_FEATURE_LINK_SPEED_1G:
11097 if (bp->port.supported[idx] &
11098 SUPPORTED_1000baseT_Full) {
11099 bp->link_params.req_line_speed[idx] =
11101 bp->port.advertising[idx] |=
11102 (ADVERTISED_1000baseT_Full |
11105 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
11107 bp->link_params.speed_cap_mask[idx]);
11112 case PORT_FEATURE_LINK_SPEED_2_5G:
11113 if (bp->port.supported[idx] &
11114 SUPPORTED_2500baseX_Full) {
11115 bp->link_params.req_line_speed[idx] =
11117 bp->port.advertising[idx] |=
11118 (ADVERTISED_2500baseX_Full |
11121 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
11123 bp->link_params.speed_cap_mask[idx]);
11128 case PORT_FEATURE_LINK_SPEED_10G_CX4:
11129 if (bp->port.supported[idx] &
11130 SUPPORTED_10000baseT_Full) {
11131 bp->link_params.req_line_speed[idx] =
11133 bp->port.advertising[idx] |=
11134 (ADVERTISED_10000baseT_Full |
11137 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
11139 bp->link_params.speed_cap_mask[idx]);
11143 case PORT_FEATURE_LINK_SPEED_20G:
11144 bp->link_params.req_line_speed[idx] = SPEED_20000;
11148 BNX2X_ERR("NVRAM config error. BAD link speed link_config 0x%x\n",
11150 bp->link_params.req_line_speed[idx] =
11152 bp->port.advertising[idx] =
11153 bp->port.supported[idx];
11157 bp->link_params.req_flow_ctrl[idx] = (link_config &
11158 PORT_FEATURE_FLOW_CONTROL_MASK);
11159 if (bp->link_params.req_flow_ctrl[idx] ==
11160 BNX2X_FLOW_CTRL_AUTO) {
11161 if (!(bp->port.supported[idx] & SUPPORTED_Autoneg))
11162 bp->link_params.req_flow_ctrl[idx] =
11163 BNX2X_FLOW_CTRL_NONE;
11165 bnx2x_set_requested_fc(bp);
11168 BNX2X_DEV_INFO("req_line_speed %d req_duplex %d req_flow_ctrl 0x%x advertising 0x%x\n",
11169 bp->link_params.req_line_speed[idx],
11170 bp->link_params.req_duplex[idx],
11171 bp->link_params.req_flow_ctrl[idx],
11172 bp->port.advertising[idx]);
11176 static void bnx2x_set_mac_buf(u8 *mac_buf, u32 mac_lo, u16 mac_hi)
11178 __be16 mac_hi_be = cpu_to_be16(mac_hi);
11179 __be32 mac_lo_be = cpu_to_be32(mac_lo);
11180 memcpy(mac_buf, &mac_hi_be, sizeof(mac_hi_be));
11181 memcpy(mac_buf + sizeof(mac_hi_be), &mac_lo_be, sizeof(mac_lo_be));
11184 static void bnx2x_get_port_hwinfo(struct bnx2x *bp)
11186 int port = BP_PORT(bp);
11188 u32 ext_phy_type, ext_phy_config, eee_mode;
11190 bp->link_params.bp = bp;
11191 bp->link_params.port = port;
11193 bp->link_params.lane_config =
11194 SHMEM_RD(bp, dev_info.port_hw_config[port].lane_config);
11196 bp->link_params.speed_cap_mask[0] =
11198 dev_info.port_hw_config[port].speed_capability_mask) &
11199 PORT_HW_CFG_SPEED_CAPABILITY_D0_MASK;
11200 bp->link_params.speed_cap_mask[1] =
11202 dev_info.port_hw_config[port].speed_capability_mask2) &
11203 PORT_HW_CFG_SPEED_CAPABILITY_D0_MASK;
11204 bp->port.link_config[0] =
11205 SHMEM_RD(bp, dev_info.port_feature_config[port].link_config);
11207 bp->port.link_config[1] =
11208 SHMEM_RD(bp, dev_info.port_feature_config[port].link_config2);
11210 bp->link_params.multi_phy_config =
11211 SHMEM_RD(bp, dev_info.port_hw_config[port].multi_phy_config);
11212 /* If the device is capable of WoL, set the default state according
11215 config = SHMEM_RD(bp, dev_info.port_feature_config[port].config);
11216 bp->wol = (!(bp->flags & NO_WOL_FLAG) &&
11217 (config & PORT_FEATURE_WOL_ENABLED));
11219 if ((config & PORT_FEAT_CFG_STORAGE_PERSONALITY_MASK) ==
11220 PORT_FEAT_CFG_STORAGE_PERSONALITY_FCOE && !IS_MF(bp))
11221 bp->flags |= NO_ISCSI_FLAG;
11222 if ((config & PORT_FEAT_CFG_STORAGE_PERSONALITY_MASK) ==
11223 PORT_FEAT_CFG_STORAGE_PERSONALITY_ISCSI && !(IS_MF(bp)))
11224 bp->flags |= NO_FCOE_FLAG;
11226 BNX2X_DEV_INFO("lane_config 0x%08x speed_cap_mask0 0x%08x link_config0 0x%08x\n",
11227 bp->link_params.lane_config,
11228 bp->link_params.speed_cap_mask[0],
11229 bp->port.link_config[0]);
11231 bp->link_params.switch_cfg = (bp->port.link_config[0] &
11232 PORT_FEATURE_CONNECTED_SWITCH_MASK);
11233 bnx2x_phy_probe(&bp->link_params);
11234 bnx2x_link_settings_supported(bp, bp->link_params.switch_cfg);
11236 bnx2x_link_settings_requested(bp);
11239 * If connected directly, work with the internal PHY, otherwise, work
11240 * with the external PHY
11244 dev_info.port_hw_config[port].external_phy_config);
11245 ext_phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
11246 if (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
11247 bp->mdio.prtad = bp->port.phy_addr;
11249 else if ((ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) &&
11250 (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN))
11252 XGXS_EXT_PHY_ADDR(ext_phy_config);
11254 /* Configure link feature according to nvram value */
11255 eee_mode = (((SHMEM_RD(bp, dev_info.
11256 port_feature_config[port].eee_power_mode)) &
11257 PORT_FEAT_CFG_EEE_POWER_MODE_MASK) >>
11258 PORT_FEAT_CFG_EEE_POWER_MODE_SHIFT);
11259 if (eee_mode != PORT_FEAT_CFG_EEE_POWER_MODE_DISABLED) {
11260 bp->link_params.eee_mode = EEE_MODE_ADV_LPI |
11261 EEE_MODE_ENABLE_LPI |
11262 EEE_MODE_OUTPUT_TIME;
11264 bp->link_params.eee_mode = 0;
11268 void bnx2x_get_iscsi_info(struct bnx2x *bp)
11270 u32 no_flags = NO_ISCSI_FLAG;
11271 int port = BP_PORT(bp);
11272 u32 max_iscsi_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
11273 drv_lic_key[port].max_iscsi_conn);
11275 if (!CNIC_SUPPORT(bp)) {
11276 bp->flags |= no_flags;
11280 /* Get the number of maximum allowed iSCSI connections */
11281 bp->cnic_eth_dev.max_iscsi_conn =
11282 (max_iscsi_conn & BNX2X_MAX_ISCSI_INIT_CONN_MASK) >>
11283 BNX2X_MAX_ISCSI_INIT_CONN_SHIFT;
11285 BNX2X_DEV_INFO("max_iscsi_conn 0x%x\n",
11286 bp->cnic_eth_dev.max_iscsi_conn);
11289 * If maximum allowed number of connections is zero -
11290 * disable the feature.
11292 if (!bp->cnic_eth_dev.max_iscsi_conn)
11293 bp->flags |= no_flags;
11296 static void bnx2x_get_ext_wwn_info(struct bnx2x *bp, int func)
11299 bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
11300 MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_upper);
11301 bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
11302 MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_lower);
11305 bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
11306 MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_upper);
11307 bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
11308 MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_lower);
11311 static int bnx2x_shared_fcoe_funcs(struct bnx2x *bp)
11318 /* iterate over absolute function ids for this path: */
11319 for (fid = BP_PATH(bp); fid < E2_FUNC_MAX * 2; fid += 2) {
11320 if (IS_MF_SD(bp)) {
11321 u32 cfg = MF_CFG_RD(bp,
11322 func_mf_config[fid].config);
11324 if (!(cfg & FUNC_MF_CFG_FUNC_HIDE) &&
11325 ((cfg & FUNC_MF_CFG_PROTOCOL_MASK) ==
11326 FUNC_MF_CFG_PROTOCOL_FCOE))
11329 u32 cfg = MF_CFG_RD(bp,
11330 func_ext_config[fid].
11333 if ((cfg & MACP_FUNC_CFG_FLAGS_ENABLED) &&
11334 (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD))
11339 int port, port_cnt = CHIP_MODE_IS_4_PORT(bp) ? 2 : 1;
11341 for (port = 0; port < port_cnt; port++) {
11342 u32 lic = SHMEM_RD(bp,
11343 drv_lic_key[port].max_fcoe_conn) ^
11344 FW_ENCODE_32BIT_PATTERN;
11353 static void bnx2x_get_fcoe_info(struct bnx2x *bp)
11355 int port = BP_PORT(bp);
11356 int func = BP_ABS_FUNC(bp);
11357 u32 max_fcoe_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
11358 drv_lic_key[port].max_fcoe_conn);
11359 u8 num_fcoe_func = bnx2x_shared_fcoe_funcs(bp);
11361 if (!CNIC_SUPPORT(bp)) {
11362 bp->flags |= NO_FCOE_FLAG;
11366 /* Get the number of maximum allowed FCoE connections */
11367 bp->cnic_eth_dev.max_fcoe_conn =
11368 (max_fcoe_conn & BNX2X_MAX_FCOE_INIT_CONN_MASK) >>
11369 BNX2X_MAX_FCOE_INIT_CONN_SHIFT;
11371 /* Calculate the number of maximum allowed FCoE tasks */
11372 bp->cnic_eth_dev.max_fcoe_exchanges = MAX_NUM_FCOE_TASKS_PER_ENGINE;
11374 /* check if FCoE resources must be shared between different functions */
11376 bp->cnic_eth_dev.max_fcoe_exchanges /= num_fcoe_func;
11378 /* Read the WWN: */
11381 bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
11383 dev_info.port_hw_config[port].
11384 fcoe_wwn_port_name_upper);
11385 bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
11387 dev_info.port_hw_config[port].
11388 fcoe_wwn_port_name_lower);
11391 bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
11393 dev_info.port_hw_config[port].
11394 fcoe_wwn_node_name_upper);
11395 bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
11397 dev_info.port_hw_config[port].
11398 fcoe_wwn_node_name_lower);
11399 } else if (!IS_MF_SD(bp)) {
11401 * Read the WWN info only if the FCoE feature is enabled for
11404 if (BNX2X_MF_EXT_PROTOCOL_FCOE(bp) && !CHIP_IS_E1x(bp))
11405 bnx2x_get_ext_wwn_info(bp, func);
11407 } else if (IS_MF_FCOE_SD(bp) && !CHIP_IS_E1x(bp)) {
11408 bnx2x_get_ext_wwn_info(bp, func);
11411 BNX2X_DEV_INFO("max_fcoe_conn 0x%x\n", bp->cnic_eth_dev.max_fcoe_conn);
11414 * If maximum allowed number of connections is zero -
11415 * disable the feature.
11417 if (!bp->cnic_eth_dev.max_fcoe_conn)
11418 bp->flags |= NO_FCOE_FLAG;
11421 static void bnx2x_get_cnic_info(struct bnx2x *bp)
11424 * iSCSI may be dynamically disabled but reading
11425 * info here we will decrease memory usage by driver
11426 * if the feature is disabled for good
11428 bnx2x_get_iscsi_info(bp);
11429 bnx2x_get_fcoe_info(bp);
11432 static void bnx2x_get_cnic_mac_hwinfo(struct bnx2x *bp)
11435 int func = BP_ABS_FUNC(bp);
11436 int port = BP_PORT(bp);
11437 u8 *iscsi_mac = bp->cnic_eth_dev.iscsi_mac;
11438 u8 *fip_mac = bp->fip_mac;
11441 /* iSCSI and FCoE NPAR MACs: if there is no either iSCSI or
11442 * FCoE MAC then the appropriate feature should be disabled.
11443 * In non SD mode features configuration comes from struct
11446 if (!IS_MF_SD(bp) && !CHIP_IS_E1x(bp)) {
11447 u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg);
11448 if (cfg & MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD) {
11449 val2 = MF_CFG_RD(bp, func_ext_config[func].
11450 iscsi_mac_addr_upper);
11451 val = MF_CFG_RD(bp, func_ext_config[func].
11452 iscsi_mac_addr_lower);
11453 bnx2x_set_mac_buf(iscsi_mac, val, val2);
11455 ("Read iSCSI MAC: %pM\n", iscsi_mac);
11457 bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
11460 if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD) {
11461 val2 = MF_CFG_RD(bp, func_ext_config[func].
11462 fcoe_mac_addr_upper);
11463 val = MF_CFG_RD(bp, func_ext_config[func].
11464 fcoe_mac_addr_lower);
11465 bnx2x_set_mac_buf(fip_mac, val, val2);
11467 ("Read FCoE L2 MAC: %pM\n", fip_mac);
11469 bp->flags |= NO_FCOE_FLAG;
11472 bp->mf_ext_config = cfg;
11474 } else { /* SD MODE */
11475 if (BNX2X_IS_MF_SD_PROTOCOL_ISCSI(bp)) {
11476 /* use primary mac as iscsi mac */
11477 memcpy(iscsi_mac, bp->dev->dev_addr, ETH_ALEN);
11479 BNX2X_DEV_INFO("SD ISCSI MODE\n");
11481 ("Read iSCSI MAC: %pM\n", iscsi_mac);
11482 } else if (BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp)) {
11483 /* use primary mac as fip mac */
11484 memcpy(fip_mac, bp->dev->dev_addr, ETH_ALEN);
11485 BNX2X_DEV_INFO("SD FCoE MODE\n");
11487 ("Read FIP MAC: %pM\n", fip_mac);
11491 /* If this is a storage-only interface, use SAN mac as
11492 * primary MAC. Notice that for SD this is already the case,
11493 * as the SAN mac was copied from the primary MAC.
11495 if (IS_MF_FCOE_AFEX(bp))
11496 memcpy(bp->dev->dev_addr, fip_mac, ETH_ALEN);
11498 val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
11500 val = SHMEM_RD(bp, dev_info.port_hw_config[port].
11502 bnx2x_set_mac_buf(iscsi_mac, val, val2);
11504 val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
11505 fcoe_fip_mac_upper);
11506 val = SHMEM_RD(bp, dev_info.port_hw_config[port].
11507 fcoe_fip_mac_lower);
11508 bnx2x_set_mac_buf(fip_mac, val, val2);
11511 /* Disable iSCSI OOO if MAC configuration is invalid. */
11512 if (!is_valid_ether_addr(iscsi_mac)) {
11513 bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
11514 memset(iscsi_mac, 0, ETH_ALEN);
11517 /* Disable FCoE if MAC configuration is invalid. */
11518 if (!is_valid_ether_addr(fip_mac)) {
11519 bp->flags |= NO_FCOE_FLAG;
11520 memset(bp->fip_mac, 0, ETH_ALEN);
11524 static void bnx2x_get_mac_hwinfo(struct bnx2x *bp)
11527 int func = BP_ABS_FUNC(bp);
11528 int port = BP_PORT(bp);
11530 /* Zero primary MAC configuration */
11531 memset(bp->dev->dev_addr, 0, ETH_ALEN);
11533 if (BP_NOMCP(bp)) {
11534 BNX2X_ERROR("warning: random MAC workaround active\n");
11535 eth_hw_addr_random(bp->dev);
11536 } else if (IS_MF(bp)) {
11537 val2 = MF_CFG_RD(bp, func_mf_config[func].mac_upper);
11538 val = MF_CFG_RD(bp, func_mf_config[func].mac_lower);
11539 if ((val2 != FUNC_MF_CFG_UPPERMAC_DEFAULT) &&
11540 (val != FUNC_MF_CFG_LOWERMAC_DEFAULT))
11541 bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
11543 if (CNIC_SUPPORT(bp))
11544 bnx2x_get_cnic_mac_hwinfo(bp);
11546 /* in SF read MACs from port configuration */
11547 val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
11548 val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
11549 bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
11551 if (CNIC_SUPPORT(bp))
11552 bnx2x_get_cnic_mac_hwinfo(bp);
11555 if (!BP_NOMCP(bp)) {
11556 /* Read physical port identifier from shmem */
11557 val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
11558 val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
11559 bnx2x_set_mac_buf(bp->phys_port_id, val, val2);
11560 bp->flags |= HAS_PHYS_PORT_ID;
11563 memcpy(bp->link_params.mac_addr, bp->dev->dev_addr, ETH_ALEN);
11565 if (!bnx2x_is_valid_ether_addr(bp, bp->dev->dev_addr))
11566 dev_err(&bp->pdev->dev,
11567 "bad Ethernet MAC address configuration: %pM\n"
11568 "change it manually before bringing up the appropriate network interface\n",
11569 bp->dev->dev_addr);
11572 static bool bnx2x_get_dropless_info(struct bnx2x *bp)
11580 if (IS_MF(bp) && !CHIP_IS_E1x(bp)) {
11581 /* Take function: tmp = func */
11582 tmp = BP_ABS_FUNC(bp);
11583 cfg = MF_CFG_RD(bp, func_ext_config[tmp].func_cfg);
11584 cfg = !!(cfg & MACP_FUNC_CFG_PAUSE_ON_HOST_RING);
11586 /* Take port: tmp = port */
11589 dev_info.port_hw_config[tmp].generic_features);
11590 cfg = !!(cfg & PORT_HW_CFG_PAUSE_ON_HOST_RING_ENABLED);
11595 static int bnx2x_get_hwinfo(struct bnx2x *bp)
11597 int /*abs*/func = BP_ABS_FUNC(bp);
11602 bnx2x_get_common_hwinfo(bp);
11605 * initialize IGU parameters
11607 if (CHIP_IS_E1x(bp)) {
11608 bp->common.int_block = INT_BLOCK_HC;
11610 bp->igu_dsb_id = DEF_SB_IGU_ID;
11611 bp->igu_base_sb = 0;
11613 bp->common.int_block = INT_BLOCK_IGU;
11615 /* do not allow device reset during IGU info processing */
11616 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
11618 val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
11620 if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
11623 BNX2X_DEV_INFO("FORCING Normal Mode\n");
11625 val &= ~(IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN);
11626 REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION, val);
11627 REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x7f);
11629 while (tout && REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
11631 usleep_range(1000, 2000);
11634 if (REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
11635 dev_err(&bp->pdev->dev,
11636 "FORCING Normal Mode failed!!!\n");
11637 bnx2x_release_hw_lock(bp,
11638 HW_LOCK_RESOURCE_RESET);
11643 if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
11644 BNX2X_DEV_INFO("IGU Backward Compatible Mode\n");
11645 bp->common.int_block |= INT_BLOCK_MODE_BW_COMP;
11647 BNX2X_DEV_INFO("IGU Normal Mode\n");
11649 rc = bnx2x_get_igu_cam_info(bp);
11650 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
11656 * set base FW non-default (fast path) status block id, this value is
11657 * used to initialize the fw_sb_id saved on the fp/queue structure to
11658 * determine the id used by the FW.
11660 if (CHIP_IS_E1x(bp))
11661 bp->base_fw_ndsb = BP_PORT(bp) * FP_SB_MAX_E1x + BP_L_ID(bp);
11663 * 57712 - we currently use one FW SB per IGU SB (Rx and Tx of
11664 * the same queue are indicated on the same IGU SB). So we prefer
11665 * FW and IGU SBs to be the same value.
11667 bp->base_fw_ndsb = bp->igu_base_sb;
11669 BNX2X_DEV_INFO("igu_dsb_id %d igu_base_sb %d igu_sb_cnt %d\n"
11670 "base_fw_ndsb %d\n", bp->igu_dsb_id, bp->igu_base_sb,
11671 bp->igu_sb_cnt, bp->base_fw_ndsb);
11674 * Initialize MF configuration
11681 if (!CHIP_IS_E1(bp) && !BP_NOMCP(bp)) {
11682 BNX2X_DEV_INFO("shmem2base 0x%x, size %d, mfcfg offset %d\n",
11683 bp->common.shmem2_base, SHMEM2_RD(bp, size),
11684 (u32)offsetof(struct shmem2_region, mf_cfg_addr));
11686 if (SHMEM2_HAS(bp, mf_cfg_addr))
11687 bp->common.mf_cfg_base = SHMEM2_RD(bp, mf_cfg_addr);
11689 bp->common.mf_cfg_base = bp->common.shmem_base +
11690 offsetof(struct shmem_region, func_mb) +
11691 E1H_FUNC_MAX * sizeof(struct drv_func_mb);
11693 * get mf configuration:
11694 * 1. Existence of MF configuration
11695 * 2. MAC address must be legal (check only upper bytes)
11696 * for Switch-Independent mode;
11697 * OVLAN must be legal for Switch-Dependent mode
11698 * 3. SF_MODE configures specific MF mode
11700 if (bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
11701 /* get mf configuration */
11703 dev_info.shared_feature_config.config);
11704 val &= SHARED_FEAT_CFG_FORCE_SF_MODE_MASK;
11707 case SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT:
11708 val = MF_CFG_RD(bp, func_mf_config[func].
11710 /* check for legal mac (upper bytes)*/
11711 if (val != 0xffff) {
11712 bp->mf_mode = MULTI_FUNCTION_SI;
11713 bp->mf_config[vn] = MF_CFG_RD(bp,
11714 func_mf_config[func].config);
11716 BNX2X_DEV_INFO("illegal MAC address for SI\n");
11718 case SHARED_FEAT_CFG_FORCE_SF_MODE_AFEX_MODE:
11719 if ((!CHIP_IS_E1x(bp)) &&
11720 (MF_CFG_RD(bp, func_mf_config[func].
11721 mac_upper) != 0xffff) &&
11723 afex_driver_support))) {
11724 bp->mf_mode = MULTI_FUNCTION_AFEX;
11725 bp->mf_config[vn] = MF_CFG_RD(bp,
11726 func_mf_config[func].config);
11728 BNX2X_DEV_INFO("can not configure afex mode\n");
11731 case SHARED_FEAT_CFG_FORCE_SF_MODE_MF_ALLOWED:
11732 /* get OV configuration */
11733 val = MF_CFG_RD(bp,
11734 func_mf_config[FUNC_0].e1hov_tag);
11735 val &= FUNC_MF_CFG_E1HOV_TAG_MASK;
11737 if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
11738 bp->mf_mode = MULTI_FUNCTION_SD;
11739 bp->mf_config[vn] = MF_CFG_RD(bp,
11740 func_mf_config[func].config);
11742 BNX2X_DEV_INFO("illegal OV for SD\n");
11744 case SHARED_FEAT_CFG_FORCE_SF_MODE_FORCED_SF:
11745 bp->mf_config[vn] = 0;
11748 /* Unknown configuration: reset mf_config */
11749 bp->mf_config[vn] = 0;
11750 BNX2X_DEV_INFO("unknown MF mode 0x%x\n", val);
11754 BNX2X_DEV_INFO("%s function mode\n",
11755 IS_MF(bp) ? "multi" : "single");
11757 switch (bp->mf_mode) {
11758 case MULTI_FUNCTION_SD:
11759 val = MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
11760 FUNC_MF_CFG_E1HOV_TAG_MASK;
11761 if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
11763 bp->path_has_ovlan = true;
11765 BNX2X_DEV_INFO("MF OV for func %d is %d (0x%04x)\n",
11766 func, bp->mf_ov, bp->mf_ov);
11768 dev_err(&bp->pdev->dev,
11769 "No valid MF OV for func %d, aborting\n",
11774 case MULTI_FUNCTION_AFEX:
11775 BNX2X_DEV_INFO("func %d is in MF afex mode\n", func);
11777 case MULTI_FUNCTION_SI:
11778 BNX2X_DEV_INFO("func %d is in MF switch-independent mode\n",
11783 dev_err(&bp->pdev->dev,
11784 "VN %d is in a single function mode, aborting\n",
11791 /* check if other port on the path needs ovlan:
11792 * Since MF configuration is shared between ports
11793 * Possible mixed modes are only
11794 * {SF, SI} {SF, SD} {SD, SF} {SI, SF}
11796 if (CHIP_MODE_IS_4_PORT(bp) &&
11797 !bp->path_has_ovlan &&
11799 bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
11800 u8 other_port = !BP_PORT(bp);
11801 u8 other_func = BP_PATH(bp) + 2*other_port;
11802 val = MF_CFG_RD(bp,
11803 func_mf_config[other_func].e1hov_tag);
11804 if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT)
11805 bp->path_has_ovlan = true;
11809 /* adjust igu_sb_cnt to MF for E1H */
11810 if (CHIP_IS_E1H(bp) && IS_MF(bp))
11811 bp->igu_sb_cnt = min_t(u8, bp->igu_sb_cnt, E1H_MAX_MF_SB_COUNT);
11814 bnx2x_get_port_hwinfo(bp);
11816 /* Get MAC addresses */
11817 bnx2x_get_mac_hwinfo(bp);
11819 bnx2x_get_cnic_info(bp);
11824 static void bnx2x_read_fwinfo(struct bnx2x *bp)
11826 int cnt, i, block_end, rodi;
11827 char vpd_start[BNX2X_VPD_LEN+1];
11828 char str_id_reg[VENDOR_ID_LEN+1];
11829 char str_id_cap[VENDOR_ID_LEN+1];
11831 char *vpd_extended_data = NULL;
11834 cnt = pci_read_vpd(bp->pdev, 0, BNX2X_VPD_LEN, vpd_start);
11835 memset(bp->fw_ver, 0, sizeof(bp->fw_ver));
11837 if (cnt < BNX2X_VPD_LEN)
11838 goto out_not_found;
11840 /* VPD RO tag should be first tag after identifier string, hence
11841 * we should be able to find it in first BNX2X_VPD_LEN chars
11843 i = pci_vpd_find_tag(vpd_start, 0, BNX2X_VPD_LEN,
11844 PCI_VPD_LRDT_RO_DATA);
11846 goto out_not_found;
11848 block_end = i + PCI_VPD_LRDT_TAG_SIZE +
11849 pci_vpd_lrdt_size(&vpd_start[i]);
11851 i += PCI_VPD_LRDT_TAG_SIZE;
11853 if (block_end > BNX2X_VPD_LEN) {
11854 vpd_extended_data = kmalloc(block_end, GFP_KERNEL);
11855 if (vpd_extended_data == NULL)
11856 goto out_not_found;
11858 /* read rest of vpd image into vpd_extended_data */
11859 memcpy(vpd_extended_data, vpd_start, BNX2X_VPD_LEN);
11860 cnt = pci_read_vpd(bp->pdev, BNX2X_VPD_LEN,
11861 block_end - BNX2X_VPD_LEN,
11862 vpd_extended_data + BNX2X_VPD_LEN);
11863 if (cnt < (block_end - BNX2X_VPD_LEN))
11864 goto out_not_found;
11865 vpd_data = vpd_extended_data;
11867 vpd_data = vpd_start;
11869 /* now vpd_data holds full vpd content in both cases */
11871 rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
11872 PCI_VPD_RO_KEYWORD_MFR_ID);
11874 goto out_not_found;
11876 len = pci_vpd_info_field_size(&vpd_data[rodi]);
11878 if (len != VENDOR_ID_LEN)
11879 goto out_not_found;
11881 rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
11883 /* vendor specific info */
11884 snprintf(str_id_reg, VENDOR_ID_LEN + 1, "%04x", PCI_VENDOR_ID_DELL);
11885 snprintf(str_id_cap, VENDOR_ID_LEN + 1, "%04X", PCI_VENDOR_ID_DELL);
11886 if (!strncmp(str_id_reg, &vpd_data[rodi], VENDOR_ID_LEN) ||
11887 !strncmp(str_id_cap, &vpd_data[rodi], VENDOR_ID_LEN)) {
11889 rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
11890 PCI_VPD_RO_KEYWORD_VENDOR0);
11892 len = pci_vpd_info_field_size(&vpd_data[rodi]);
11894 rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
11896 if (len < 32 && (len + rodi) <= BNX2X_VPD_LEN) {
11897 memcpy(bp->fw_ver, &vpd_data[rodi], len);
11898 bp->fw_ver[len] = ' ';
11901 kfree(vpd_extended_data);
11905 kfree(vpd_extended_data);
11909 static void bnx2x_set_modes_bitmap(struct bnx2x *bp)
11913 if (CHIP_REV_IS_FPGA(bp))
11914 SET_FLAGS(flags, MODE_FPGA);
11915 else if (CHIP_REV_IS_EMUL(bp))
11916 SET_FLAGS(flags, MODE_EMUL);
11918 SET_FLAGS(flags, MODE_ASIC);
11920 if (CHIP_MODE_IS_4_PORT(bp))
11921 SET_FLAGS(flags, MODE_PORT4);
11923 SET_FLAGS(flags, MODE_PORT2);
11925 if (CHIP_IS_E2(bp))
11926 SET_FLAGS(flags, MODE_E2);
11927 else if (CHIP_IS_E3(bp)) {
11928 SET_FLAGS(flags, MODE_E3);
11929 if (CHIP_REV(bp) == CHIP_REV_Ax)
11930 SET_FLAGS(flags, MODE_E3_A0);
11931 else /*if (CHIP_REV(bp) == CHIP_REV_Bx)*/
11932 SET_FLAGS(flags, MODE_E3_B0 | MODE_COS3);
11936 SET_FLAGS(flags, MODE_MF);
11937 switch (bp->mf_mode) {
11938 case MULTI_FUNCTION_SD:
11939 SET_FLAGS(flags, MODE_MF_SD);
11941 case MULTI_FUNCTION_SI:
11942 SET_FLAGS(flags, MODE_MF_SI);
11944 case MULTI_FUNCTION_AFEX:
11945 SET_FLAGS(flags, MODE_MF_AFEX);
11949 SET_FLAGS(flags, MODE_SF);
11951 #if defined(__LITTLE_ENDIAN)
11952 SET_FLAGS(flags, MODE_LITTLE_ENDIAN);
11953 #else /*(__BIG_ENDIAN)*/
11954 SET_FLAGS(flags, MODE_BIG_ENDIAN);
11956 INIT_MODE_FLAGS(bp) = flags;
11959 static int bnx2x_init_bp(struct bnx2x *bp)
11964 mutex_init(&bp->port.phy_mutex);
11965 mutex_init(&bp->fw_mb_mutex);
11966 mutex_init(&bp->drv_info_mutex);
11967 bp->drv_info_mng_owner = false;
11968 spin_lock_init(&bp->stats_lock);
11969 sema_init(&bp->stats_sema, 1);
11971 INIT_DELAYED_WORK(&bp->sp_task, bnx2x_sp_task);
11972 INIT_DELAYED_WORK(&bp->sp_rtnl_task, bnx2x_sp_rtnl_task);
11973 INIT_DELAYED_WORK(&bp->period_task, bnx2x_period_task);
11974 INIT_DELAYED_WORK(&bp->iov_task, bnx2x_iov_task);
11976 rc = bnx2x_get_hwinfo(bp);
11980 eth_zero_addr(bp->dev->dev_addr);
11983 bnx2x_set_modes_bitmap(bp);
11985 rc = bnx2x_alloc_mem_bp(bp);
11989 bnx2x_read_fwinfo(bp);
11991 func = BP_FUNC(bp);
11993 /* need to reset chip if undi was active */
11994 if (IS_PF(bp) && !BP_NOMCP(bp)) {
11997 SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
11998 DRV_MSG_SEQ_NUMBER_MASK;
11999 BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
12001 rc = bnx2x_prev_unload(bp);
12003 bnx2x_free_mem_bp(bp);
12008 if (CHIP_REV_IS_FPGA(bp))
12009 dev_err(&bp->pdev->dev, "FPGA detected\n");
12011 if (BP_NOMCP(bp) && (func == 0))
12012 dev_err(&bp->pdev->dev, "MCP disabled, must load devices in order!\n");
12014 bp->disable_tpa = disable_tpa;
12015 bp->disable_tpa |= IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp);
12016 /* Reduce memory usage in kdump environment by disabling TPA */
12017 bp->disable_tpa |= reset_devices;
12019 /* Set TPA flags */
12020 if (bp->disable_tpa) {
12021 bp->flags &= ~(TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
12022 bp->dev->features &= ~NETIF_F_LRO;
12024 bp->flags |= (TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
12025 bp->dev->features |= NETIF_F_LRO;
12028 if (CHIP_IS_E1(bp))
12029 bp->dropless_fc = 0;
12031 bp->dropless_fc = dropless_fc | bnx2x_get_dropless_info(bp);
12035 bp->tx_ring_size = IS_MF_FCOE_AFEX(bp) ? 0 : MAX_TX_AVAIL;
12037 bp->rx_ring_size = MAX_RX_AVAIL;
12039 /* make sure that the numbers are in the right granularity */
12040 bp->tx_ticks = (50 / BNX2X_BTR) * BNX2X_BTR;
12041 bp->rx_ticks = (25 / BNX2X_BTR) * BNX2X_BTR;
12043 bp->current_interval = CHIP_REV_IS_SLOW(bp) ? 5*HZ : HZ;
12045 init_timer(&bp->timer);
12046 bp->timer.expires = jiffies + bp->current_interval;
12047 bp->timer.data = (unsigned long) bp;
12048 bp->timer.function = bnx2x_timer;
12050 if (SHMEM2_HAS(bp, dcbx_lldp_params_offset) &&
12051 SHMEM2_HAS(bp, dcbx_lldp_dcbx_stat_offset) &&
12052 SHMEM2_RD(bp, dcbx_lldp_params_offset) &&
12053 SHMEM2_RD(bp, dcbx_lldp_dcbx_stat_offset)) {
12054 bnx2x_dcbx_set_state(bp, true, BNX2X_DCBX_ENABLED_ON_NEG_ON);
12055 bnx2x_dcbx_init_params(bp);
12057 bnx2x_dcbx_set_state(bp, false, BNX2X_DCBX_ENABLED_OFF);
12060 if (CHIP_IS_E1x(bp))
12061 bp->cnic_base_cl_id = FP_SB_MAX_E1x;
12063 bp->cnic_base_cl_id = FP_SB_MAX_E2;
12065 /* multiple tx priority */
12068 else if (CHIP_IS_E1x(bp))
12069 bp->max_cos = BNX2X_MULTI_TX_COS_E1X;
12070 else if (CHIP_IS_E2(bp) || CHIP_IS_E3A0(bp))
12071 bp->max_cos = BNX2X_MULTI_TX_COS_E2_E3A0;
12072 else if (CHIP_IS_E3B0(bp))
12073 bp->max_cos = BNX2X_MULTI_TX_COS_E3B0;
12075 BNX2X_ERR("unknown chip %x revision %x\n",
12076 CHIP_NUM(bp), CHIP_REV(bp));
12077 BNX2X_DEV_INFO("set bp->max_cos to %d\n", bp->max_cos);
12079 /* We need at least one default status block for slow-path events,
12080 * second status block for the L2 queue, and a third status block for
12081 * CNIC if supported.
12084 bp->min_msix_vec_cnt = 1;
12085 else if (CNIC_SUPPORT(bp))
12086 bp->min_msix_vec_cnt = 3;
12087 else /* PF w/o cnic */
12088 bp->min_msix_vec_cnt = 2;
12089 BNX2X_DEV_INFO("bp->min_msix_vec_cnt %d", bp->min_msix_vec_cnt);
12091 bp->dump_preset_idx = 1;
12093 if (CHIP_IS_E3B0(bp))
12094 bp->flags |= PTP_SUPPORTED;
12099 /****************************************************************************
12100 * General service functions
12101 ****************************************************************************/
12104 * net_device service functions
12107 /* called with rtnl_lock */
12108 static int bnx2x_open(struct net_device *dev)
12110 struct bnx2x *bp = netdev_priv(dev);
12113 bp->stats_init = true;
12115 netif_carrier_off(dev);
12117 bnx2x_set_power_state(bp, PCI_D0);
12119 /* If parity had happen during the unload, then attentions
12120 * and/or RECOVERY_IN_PROGRES may still be set. In this case we
12121 * want the first function loaded on the current engine to
12122 * complete the recovery.
12123 * Parity recovery is only relevant for PF driver.
12126 int other_engine = BP_PATH(bp) ? 0 : 1;
12127 bool other_load_status, load_status;
12128 bool global = false;
12130 other_load_status = bnx2x_get_load_status(bp, other_engine);
12131 load_status = bnx2x_get_load_status(bp, BP_PATH(bp));
12132 if (!bnx2x_reset_is_done(bp, BP_PATH(bp)) ||
12133 bnx2x_chk_parity_attn(bp, &global, true)) {
12135 /* If there are attentions and they are in a
12136 * global blocks, set the GLOBAL_RESET bit
12137 * regardless whether it will be this function
12138 * that will complete the recovery or not.
12141 bnx2x_set_reset_global(bp);
12143 /* Only the first function on the current
12144 * engine should try to recover in open. In case
12145 * of attentions in global blocks only the first
12146 * in the chip should try to recover.
12148 if ((!load_status &&
12149 (!global || !other_load_status)) &&
12150 bnx2x_trylock_leader_lock(bp) &&
12151 !bnx2x_leader_reset(bp)) {
12152 netdev_info(bp->dev,
12153 "Recovered in open\n");
12157 /* recovery has failed... */
12158 bnx2x_set_power_state(bp, PCI_D3hot);
12159 bp->recovery_state = BNX2X_RECOVERY_FAILED;
12161 BNX2X_ERR("Recovery flow hasn't been properly completed yet. Try again later.\n"
12162 "If you still see this message after a few retries then power cycle is required.\n");
12169 bp->recovery_state = BNX2X_RECOVERY_DONE;
12170 rc = bnx2x_nic_load(bp, LOAD_OPEN);
12176 /* called with rtnl_lock */
12177 static int bnx2x_close(struct net_device *dev)
12179 struct bnx2x *bp = netdev_priv(dev);
12181 /* Unload the driver, release IRQs */
12182 bnx2x_nic_unload(bp, UNLOAD_CLOSE, false);
12187 static int bnx2x_init_mcast_macs_list(struct bnx2x *bp,
12188 struct bnx2x_mcast_ramrod_params *p)
12190 int mc_count = netdev_mc_count(bp->dev);
12191 struct bnx2x_mcast_list_elem *mc_mac =
12192 kcalloc(mc_count, sizeof(*mc_mac), GFP_ATOMIC);
12193 struct netdev_hw_addr *ha;
12198 INIT_LIST_HEAD(&p->mcast_list);
12200 netdev_for_each_mc_addr(ha, bp->dev) {
12201 mc_mac->mac = bnx2x_mc_addr(ha);
12202 list_add_tail(&mc_mac->link, &p->mcast_list);
12206 p->mcast_list_len = mc_count;
12211 static void bnx2x_free_mcast_macs_list(
12212 struct bnx2x_mcast_ramrod_params *p)
12214 struct bnx2x_mcast_list_elem *mc_mac =
12215 list_first_entry(&p->mcast_list, struct bnx2x_mcast_list_elem,
12223 * bnx2x_set_uc_list - configure a new unicast MACs list.
12225 * @bp: driver handle
12227 * We will use zero (0) as a MAC type for these MACs.
12229 static int bnx2x_set_uc_list(struct bnx2x *bp)
12232 struct net_device *dev = bp->dev;
12233 struct netdev_hw_addr *ha;
12234 struct bnx2x_vlan_mac_obj *mac_obj = &bp->sp_objs->mac_obj;
12235 unsigned long ramrod_flags = 0;
12237 /* First schedule a cleanup up of old configuration */
12238 rc = bnx2x_del_all_macs(bp, mac_obj, BNX2X_UC_LIST_MAC, false);
12240 BNX2X_ERR("Failed to schedule DELETE operations: %d\n", rc);
12244 netdev_for_each_uc_addr(ha, dev) {
12245 rc = bnx2x_set_mac_one(bp, bnx2x_uc_addr(ha), mac_obj, true,
12246 BNX2X_UC_LIST_MAC, &ramrod_flags);
12247 if (rc == -EEXIST) {
12249 "Failed to schedule ADD operations: %d\n", rc);
12250 /* do not treat adding same MAC as error */
12253 } else if (rc < 0) {
12255 BNX2X_ERR("Failed to schedule ADD operations: %d\n",
12261 /* Execute the pending commands */
12262 __set_bit(RAMROD_CONT, &ramrod_flags);
12263 return bnx2x_set_mac_one(bp, NULL, mac_obj, false /* don't care */,
12264 BNX2X_UC_LIST_MAC, &ramrod_flags);
12267 static int bnx2x_set_mc_list(struct bnx2x *bp)
12269 struct net_device *dev = bp->dev;
12270 struct bnx2x_mcast_ramrod_params rparam = {NULL};
12273 rparam.mcast_obj = &bp->mcast_obj;
12275 /* first, clear all configured multicast MACs */
12276 rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
12278 BNX2X_ERR("Failed to clear multicast configuration: %d\n", rc);
12282 /* then, configure a new MACs list */
12283 if (netdev_mc_count(dev)) {
12284 rc = bnx2x_init_mcast_macs_list(bp, &rparam);
12286 BNX2X_ERR("Failed to create multicast MACs list: %d\n",
12291 /* Now add the new MACs */
12292 rc = bnx2x_config_mcast(bp, &rparam,
12293 BNX2X_MCAST_CMD_ADD);
12295 BNX2X_ERR("Failed to set a new multicast configuration: %d\n",
12298 bnx2x_free_mcast_macs_list(&rparam);
12304 /* If bp->state is OPEN, should be called with netif_addr_lock_bh() */
12305 static void bnx2x_set_rx_mode(struct net_device *dev)
12307 struct bnx2x *bp = netdev_priv(dev);
12309 if (bp->state != BNX2X_STATE_OPEN) {
12310 DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
12313 /* Schedule an SP task to handle rest of change */
12314 bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_RX_MODE,
12319 void bnx2x_set_rx_mode_inner(struct bnx2x *bp)
12321 u32 rx_mode = BNX2X_RX_MODE_NORMAL;
12323 DP(NETIF_MSG_IFUP, "dev->flags = %x\n", bp->dev->flags);
12325 netif_addr_lock_bh(bp->dev);
12327 if (bp->dev->flags & IFF_PROMISC) {
12328 rx_mode = BNX2X_RX_MODE_PROMISC;
12329 } else if ((bp->dev->flags & IFF_ALLMULTI) ||
12330 ((netdev_mc_count(bp->dev) > BNX2X_MAX_MULTICAST) &&
12332 rx_mode = BNX2X_RX_MODE_ALLMULTI;
12335 /* some multicasts */
12336 if (bnx2x_set_mc_list(bp) < 0)
12337 rx_mode = BNX2X_RX_MODE_ALLMULTI;
12339 /* release bh lock, as bnx2x_set_uc_list might sleep */
12340 netif_addr_unlock_bh(bp->dev);
12341 if (bnx2x_set_uc_list(bp) < 0)
12342 rx_mode = BNX2X_RX_MODE_PROMISC;
12343 netif_addr_lock_bh(bp->dev);
12345 /* configuring mcast to a vf involves sleeping (when we
12346 * wait for the pf's response).
12348 bnx2x_schedule_sp_rtnl(bp,
12349 BNX2X_SP_RTNL_VFPF_MCAST, 0);
12353 bp->rx_mode = rx_mode;
12354 /* handle ISCSI SD mode */
12355 if (IS_MF_ISCSI_SD(bp))
12356 bp->rx_mode = BNX2X_RX_MODE_NONE;
12358 /* Schedule the rx_mode command */
12359 if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state)) {
12360 set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
12361 netif_addr_unlock_bh(bp->dev);
12366 bnx2x_set_storm_rx_mode(bp);
12367 netif_addr_unlock_bh(bp->dev);
12369 /* VF will need to request the PF to make this change, and so
12370 * the VF needs to release the bottom-half lock prior to the
12371 * request (as it will likely require sleep on the VF side)
12373 netif_addr_unlock_bh(bp->dev);
12374 bnx2x_vfpf_storm_rx_mode(bp);
12378 /* called with rtnl_lock */
12379 static int bnx2x_mdio_read(struct net_device *netdev, int prtad,
12380 int devad, u16 addr)
12382 struct bnx2x *bp = netdev_priv(netdev);
12386 DP(NETIF_MSG_LINK, "mdio_read: prtad 0x%x, devad 0x%x, addr 0x%x\n",
12387 prtad, devad, addr);
12389 /* The HW expects different devad if CL22 is used */
12390 devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
12392 bnx2x_acquire_phy_lock(bp);
12393 rc = bnx2x_phy_read(&bp->link_params, prtad, devad, addr, &value);
12394 bnx2x_release_phy_lock(bp);
12395 DP(NETIF_MSG_LINK, "mdio_read_val 0x%x rc = 0x%x\n", value, rc);
12402 /* called with rtnl_lock */
12403 static int bnx2x_mdio_write(struct net_device *netdev, int prtad, int devad,
12404 u16 addr, u16 value)
12406 struct bnx2x *bp = netdev_priv(netdev);
12410 "mdio_write: prtad 0x%x, devad 0x%x, addr 0x%x, value 0x%x\n",
12411 prtad, devad, addr, value);
12413 /* The HW expects different devad if CL22 is used */
12414 devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
12416 bnx2x_acquire_phy_lock(bp);
12417 rc = bnx2x_phy_write(&bp->link_params, prtad, devad, addr, value);
12418 bnx2x_release_phy_lock(bp);
12422 /* called with rtnl_lock */
12423 static int bnx2x_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
12425 struct bnx2x *bp = netdev_priv(dev);
12426 struct mii_ioctl_data *mdio = if_mii(ifr);
12428 if (!netif_running(dev))
12432 case SIOCSHWTSTAMP:
12433 return bnx2x_hwtstamp_ioctl(bp, ifr);
12435 DP(NETIF_MSG_LINK, "ioctl: phy id 0x%x, reg 0x%x, val_in 0x%x\n",
12436 mdio->phy_id, mdio->reg_num, mdio->val_in);
12437 return mdio_mii_ioctl(&bp->mdio, mdio, cmd);
12441 #ifdef CONFIG_NET_POLL_CONTROLLER
12442 static void poll_bnx2x(struct net_device *dev)
12444 struct bnx2x *bp = netdev_priv(dev);
12447 for_each_eth_queue(bp, i) {
12448 struct bnx2x_fastpath *fp = &bp->fp[i];
12449 napi_schedule(&bnx2x_fp(bp, fp->index, napi));
12454 static int bnx2x_validate_addr(struct net_device *dev)
12456 struct bnx2x *bp = netdev_priv(dev);
12458 /* query the bulletin board for mac address configured by the PF */
12460 bnx2x_sample_bulletin(bp);
12462 if (!bnx2x_is_valid_ether_addr(bp, dev->dev_addr)) {
12463 BNX2X_ERR("Non-valid Ethernet address\n");
12464 return -EADDRNOTAVAIL;
12469 static int bnx2x_get_phys_port_id(struct net_device *netdev,
12470 struct netdev_phys_port_id *ppid)
12472 struct bnx2x *bp = netdev_priv(netdev);
12474 if (!(bp->flags & HAS_PHYS_PORT_ID))
12475 return -EOPNOTSUPP;
12477 ppid->id_len = sizeof(bp->phys_port_id);
12478 memcpy(ppid->id, bp->phys_port_id, ppid->id_len);
12483 static const struct net_device_ops bnx2x_netdev_ops = {
12484 .ndo_open = bnx2x_open,
12485 .ndo_stop = bnx2x_close,
12486 .ndo_start_xmit = bnx2x_start_xmit,
12487 .ndo_select_queue = bnx2x_select_queue,
12488 .ndo_set_rx_mode = bnx2x_set_rx_mode,
12489 .ndo_set_mac_address = bnx2x_change_mac_addr,
12490 .ndo_validate_addr = bnx2x_validate_addr,
12491 .ndo_do_ioctl = bnx2x_ioctl,
12492 .ndo_change_mtu = bnx2x_change_mtu,
12493 .ndo_fix_features = bnx2x_fix_features,
12494 .ndo_set_features = bnx2x_set_features,
12495 .ndo_tx_timeout = bnx2x_tx_timeout,
12496 #ifdef CONFIG_NET_POLL_CONTROLLER
12497 .ndo_poll_controller = poll_bnx2x,
12499 .ndo_setup_tc = bnx2x_setup_tc,
12500 #ifdef CONFIG_BNX2X_SRIOV
12501 .ndo_set_vf_mac = bnx2x_set_vf_mac,
12502 .ndo_set_vf_vlan = bnx2x_set_vf_vlan,
12503 .ndo_get_vf_config = bnx2x_get_vf_config,
12505 #ifdef NETDEV_FCOE_WWNN
12506 .ndo_fcoe_get_wwn = bnx2x_fcoe_get_wwn,
12509 #ifdef CONFIG_NET_RX_BUSY_POLL
12510 .ndo_busy_poll = bnx2x_low_latency_recv,
12512 .ndo_get_phys_port_id = bnx2x_get_phys_port_id,
12513 .ndo_set_vf_link_state = bnx2x_set_vf_link_state,
12516 static int bnx2x_set_coherency_mask(struct bnx2x *bp)
12518 struct device *dev = &bp->pdev->dev;
12520 if (dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64)) != 0 &&
12521 dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32)) != 0) {
12522 dev_err(dev, "System does not support DMA, aborting\n");
12529 static void bnx2x_disable_pcie_error_reporting(struct bnx2x *bp)
12531 if (bp->flags & AER_ENABLED) {
12532 pci_disable_pcie_error_reporting(bp->pdev);
12533 bp->flags &= ~AER_ENABLED;
12537 static int bnx2x_init_dev(struct bnx2x *bp, struct pci_dev *pdev,
12538 struct net_device *dev, unsigned long board_type)
12542 bool chip_is_e1x = (board_type == BCM57710 ||
12543 board_type == BCM57711 ||
12544 board_type == BCM57711E);
12546 SET_NETDEV_DEV(dev, &pdev->dev);
12551 rc = pci_enable_device(pdev);
12553 dev_err(&bp->pdev->dev,
12554 "Cannot enable PCI device, aborting\n");
12558 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
12559 dev_err(&bp->pdev->dev,
12560 "Cannot find PCI device base address, aborting\n");
12562 goto err_out_disable;
12565 if (IS_PF(bp) && !(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
12566 dev_err(&bp->pdev->dev, "Cannot find second PCI device base address, aborting\n");
12568 goto err_out_disable;
12571 pci_read_config_dword(pdev, PCICFG_REVISION_ID_OFFSET, &pci_cfg_dword);
12572 if ((pci_cfg_dword & PCICFG_REVESION_ID_MASK) ==
12573 PCICFG_REVESION_ID_ERROR_VAL) {
12574 pr_err("PCI device error, probably due to fan failure, aborting\n");
12576 goto err_out_disable;
12579 if (atomic_read(&pdev->enable_cnt) == 1) {
12580 rc = pci_request_regions(pdev, DRV_MODULE_NAME);
12582 dev_err(&bp->pdev->dev,
12583 "Cannot obtain PCI resources, aborting\n");
12584 goto err_out_disable;
12587 pci_set_master(pdev);
12588 pci_save_state(pdev);
12592 if (!pdev->pm_cap) {
12593 dev_err(&bp->pdev->dev,
12594 "Cannot find power management capability, aborting\n");
12596 goto err_out_release;
12600 if (!pci_is_pcie(pdev)) {
12601 dev_err(&bp->pdev->dev, "Not PCI Express, aborting\n");
12603 goto err_out_release;
12606 rc = bnx2x_set_coherency_mask(bp);
12608 goto err_out_release;
12610 dev->mem_start = pci_resource_start(pdev, 0);
12611 dev->base_addr = dev->mem_start;
12612 dev->mem_end = pci_resource_end(pdev, 0);
12614 dev->irq = pdev->irq;
12616 bp->regview = pci_ioremap_bar(pdev, 0);
12617 if (!bp->regview) {
12618 dev_err(&bp->pdev->dev,
12619 "Cannot map register space, aborting\n");
12621 goto err_out_release;
12624 /* In E1/E1H use pci device function given by kernel.
12625 * In E2/E3 read physical function from ME register since these chips
12626 * support Physical Device Assignment where kernel BDF maybe arbitrary
12627 * (depending on hypervisor).
12630 bp->pf_num = PCI_FUNC(pdev->devfn);
12633 pci_read_config_dword(bp->pdev,
12634 PCICFG_ME_REGISTER, &pci_cfg_dword);
12635 bp->pf_num = (u8)((pci_cfg_dword & ME_REG_ABS_PF_NUM) >>
12636 ME_REG_ABS_PF_NUM_SHIFT);
12638 BNX2X_DEV_INFO("me reg PF num: %d\n", bp->pf_num);
12640 /* clean indirect addresses */
12641 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
12642 PCICFG_VENDOR_ID_OFFSET);
12644 /* AER (Advanced Error reporting) configuration */
12645 rc = pci_enable_pcie_error_reporting(pdev);
12647 bp->flags |= AER_ENABLED;
12649 BNX2X_DEV_INFO("Failed To configure PCIe AER [%d]\n", rc);
12652 * Clean the following indirect addresses for all functions since it
12653 * is not used by the driver.
12656 REG_WR(bp, PXP2_REG_PGL_ADDR_88_F0, 0);
12657 REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F0, 0);
12658 REG_WR(bp, PXP2_REG_PGL_ADDR_90_F0, 0);
12659 REG_WR(bp, PXP2_REG_PGL_ADDR_94_F0, 0);
12662 REG_WR(bp, PXP2_REG_PGL_ADDR_88_F1, 0);
12663 REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F1, 0);
12664 REG_WR(bp, PXP2_REG_PGL_ADDR_90_F1, 0);
12665 REG_WR(bp, PXP2_REG_PGL_ADDR_94_F1, 0);
12668 /* Enable internal target-read (in case we are probed after PF
12669 * FLR). Must be done prior to any BAR read access. Only for
12674 PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
12677 dev->watchdog_timeo = TX_TIMEOUT;
12679 dev->netdev_ops = &bnx2x_netdev_ops;
12680 bnx2x_set_ethtool_ops(bp, dev);
12682 dev->priv_flags |= IFF_UNICAST_FLT;
12684 dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
12685 NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
12686 NETIF_F_RXCSUM | NETIF_F_LRO | NETIF_F_GRO |
12687 NETIF_F_RXHASH | NETIF_F_HW_VLAN_CTAG_TX;
12688 if (!CHIP_IS_E1x(bp)) {
12689 dev->hw_features |= NETIF_F_GSO_GRE | NETIF_F_GSO_UDP_TUNNEL |
12690 NETIF_F_GSO_IPIP | NETIF_F_GSO_SIT;
12691 dev->hw_enc_features =
12692 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | NETIF_F_SG |
12693 NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
12696 NETIF_F_GSO_GRE | NETIF_F_GSO_UDP_TUNNEL;
12699 dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
12700 NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 | NETIF_F_HIGHDMA;
12702 dev->features |= dev->hw_features | NETIF_F_HW_VLAN_CTAG_RX;
12703 dev->features |= NETIF_F_HIGHDMA;
12705 /* Add Loopback capability to the device */
12706 dev->hw_features |= NETIF_F_LOOPBACK;
12709 dev->dcbnl_ops = &bnx2x_dcbnl_ops;
12712 /* get_port_hwinfo() will set prtad and mmds properly */
12713 bp->mdio.prtad = MDIO_PRTAD_NONE;
12715 bp->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
12716 bp->mdio.dev = dev;
12717 bp->mdio.mdio_read = bnx2x_mdio_read;
12718 bp->mdio.mdio_write = bnx2x_mdio_write;
12723 if (atomic_read(&pdev->enable_cnt) == 1)
12724 pci_release_regions(pdev);
12727 pci_disable_device(pdev);
12733 static int bnx2x_check_firmware(struct bnx2x *bp)
12735 const struct firmware *firmware = bp->firmware;
12736 struct bnx2x_fw_file_hdr *fw_hdr;
12737 struct bnx2x_fw_file_section *sections;
12738 u32 offset, len, num_ops;
12739 __be16 *ops_offsets;
12743 if (firmware->size < sizeof(struct bnx2x_fw_file_hdr)) {
12744 BNX2X_ERR("Wrong FW size\n");
12748 fw_hdr = (struct bnx2x_fw_file_hdr *)firmware->data;
12749 sections = (struct bnx2x_fw_file_section *)fw_hdr;
12751 /* Make sure none of the offsets and sizes make us read beyond
12752 * the end of the firmware data */
12753 for (i = 0; i < sizeof(*fw_hdr) / sizeof(*sections); i++) {
12754 offset = be32_to_cpu(sections[i].offset);
12755 len = be32_to_cpu(sections[i].len);
12756 if (offset + len > firmware->size) {
12757 BNX2X_ERR("Section %d length is out of bounds\n", i);
12762 /* Likewise for the init_ops offsets */
12763 offset = be32_to_cpu(fw_hdr->init_ops_offsets.offset);
12764 ops_offsets = (__force __be16 *)(firmware->data + offset);
12765 num_ops = be32_to_cpu(fw_hdr->init_ops.len) / sizeof(struct raw_op);
12767 for (i = 0; i < be32_to_cpu(fw_hdr->init_ops_offsets.len) / 2; i++) {
12768 if (be16_to_cpu(ops_offsets[i]) > num_ops) {
12769 BNX2X_ERR("Section offset %d is out of bounds\n", i);
12774 /* Check FW version */
12775 offset = be32_to_cpu(fw_hdr->fw_version.offset);
12776 fw_ver = firmware->data + offset;
12777 if ((fw_ver[0] != BCM_5710_FW_MAJOR_VERSION) ||
12778 (fw_ver[1] != BCM_5710_FW_MINOR_VERSION) ||
12779 (fw_ver[2] != BCM_5710_FW_REVISION_VERSION) ||
12780 (fw_ver[3] != BCM_5710_FW_ENGINEERING_VERSION)) {
12781 BNX2X_ERR("Bad FW version:%d.%d.%d.%d. Should be %d.%d.%d.%d\n",
12782 fw_ver[0], fw_ver[1], fw_ver[2], fw_ver[3],
12783 BCM_5710_FW_MAJOR_VERSION,
12784 BCM_5710_FW_MINOR_VERSION,
12785 BCM_5710_FW_REVISION_VERSION,
12786 BCM_5710_FW_ENGINEERING_VERSION);
12793 static void be32_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
12795 const __be32 *source = (const __be32 *)_source;
12796 u32 *target = (u32 *)_target;
12799 for (i = 0; i < n/4; i++)
12800 target[i] = be32_to_cpu(source[i]);
12804 Ops array is stored in the following format:
12805 {op(8bit), offset(24bit, big endian), data(32bit, big endian)}
12807 static void bnx2x_prep_ops(const u8 *_source, u8 *_target, u32 n)
12809 const __be32 *source = (const __be32 *)_source;
12810 struct raw_op *target = (struct raw_op *)_target;
12813 for (i = 0, j = 0; i < n/8; i++, j += 2) {
12814 tmp = be32_to_cpu(source[j]);
12815 target[i].op = (tmp >> 24) & 0xff;
12816 target[i].offset = tmp & 0xffffff;
12817 target[i].raw_data = be32_to_cpu(source[j + 1]);
12821 /* IRO array is stored in the following format:
12822 * {base(24bit), m1(16bit), m2(16bit), m3(16bit), size(16bit) }
12824 static void bnx2x_prep_iro(const u8 *_source, u8 *_target, u32 n)
12826 const __be32 *source = (const __be32 *)_source;
12827 struct iro *target = (struct iro *)_target;
12830 for (i = 0, j = 0; i < n/sizeof(struct iro); i++) {
12831 target[i].base = be32_to_cpu(source[j]);
12833 tmp = be32_to_cpu(source[j]);
12834 target[i].m1 = (tmp >> 16) & 0xffff;
12835 target[i].m2 = tmp & 0xffff;
12837 tmp = be32_to_cpu(source[j]);
12838 target[i].m3 = (tmp >> 16) & 0xffff;
12839 target[i].size = tmp & 0xffff;
12844 static void be16_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
12846 const __be16 *source = (const __be16 *)_source;
12847 u16 *target = (u16 *)_target;
12850 for (i = 0; i < n/2; i++)
12851 target[i] = be16_to_cpu(source[i]);
12854 #define BNX2X_ALLOC_AND_SET(arr, lbl, func) \
12856 u32 len = be32_to_cpu(fw_hdr->arr.len); \
12857 bp->arr = kmalloc(len, GFP_KERNEL); \
12860 func(bp->firmware->data + be32_to_cpu(fw_hdr->arr.offset), \
12861 (u8 *)bp->arr, len); \
12864 static int bnx2x_init_firmware(struct bnx2x *bp)
12866 const char *fw_file_name;
12867 struct bnx2x_fw_file_hdr *fw_hdr;
12873 if (CHIP_IS_E1(bp))
12874 fw_file_name = FW_FILE_NAME_E1;
12875 else if (CHIP_IS_E1H(bp))
12876 fw_file_name = FW_FILE_NAME_E1H;
12877 else if (!CHIP_IS_E1x(bp))
12878 fw_file_name = FW_FILE_NAME_E2;
12880 BNX2X_ERR("Unsupported chip revision\n");
12883 BNX2X_DEV_INFO("Loading %s\n", fw_file_name);
12885 rc = request_firmware(&bp->firmware, fw_file_name, &bp->pdev->dev);
12887 BNX2X_ERR("Can't load firmware file %s\n",
12889 goto request_firmware_exit;
12892 rc = bnx2x_check_firmware(bp);
12894 BNX2X_ERR("Corrupt firmware file %s\n", fw_file_name);
12895 goto request_firmware_exit;
12898 fw_hdr = (struct bnx2x_fw_file_hdr *)bp->firmware->data;
12900 /* Initialize the pointers to the init arrays */
12902 BNX2X_ALLOC_AND_SET(init_data, request_firmware_exit, be32_to_cpu_n);
12905 BNX2X_ALLOC_AND_SET(init_ops, init_ops_alloc_err, bnx2x_prep_ops);
12908 BNX2X_ALLOC_AND_SET(init_ops_offsets, init_offsets_alloc_err,
12911 /* STORMs firmware */
12912 INIT_TSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
12913 be32_to_cpu(fw_hdr->tsem_int_table_data.offset);
12914 INIT_TSEM_PRAM_DATA(bp) = bp->firmware->data +
12915 be32_to_cpu(fw_hdr->tsem_pram_data.offset);
12916 INIT_USEM_INT_TABLE_DATA(bp) = bp->firmware->data +
12917 be32_to_cpu(fw_hdr->usem_int_table_data.offset);
12918 INIT_USEM_PRAM_DATA(bp) = bp->firmware->data +
12919 be32_to_cpu(fw_hdr->usem_pram_data.offset);
12920 INIT_XSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
12921 be32_to_cpu(fw_hdr->xsem_int_table_data.offset);
12922 INIT_XSEM_PRAM_DATA(bp) = bp->firmware->data +
12923 be32_to_cpu(fw_hdr->xsem_pram_data.offset);
12924 INIT_CSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
12925 be32_to_cpu(fw_hdr->csem_int_table_data.offset);
12926 INIT_CSEM_PRAM_DATA(bp) = bp->firmware->data +
12927 be32_to_cpu(fw_hdr->csem_pram_data.offset);
12929 BNX2X_ALLOC_AND_SET(iro_arr, iro_alloc_err, bnx2x_prep_iro);
12934 kfree(bp->init_ops_offsets);
12935 init_offsets_alloc_err:
12936 kfree(bp->init_ops);
12937 init_ops_alloc_err:
12938 kfree(bp->init_data);
12939 request_firmware_exit:
12940 release_firmware(bp->firmware);
12941 bp->firmware = NULL;
12946 static void bnx2x_release_firmware(struct bnx2x *bp)
12948 kfree(bp->init_ops_offsets);
12949 kfree(bp->init_ops);
12950 kfree(bp->init_data);
12951 release_firmware(bp->firmware);
12952 bp->firmware = NULL;
12955 static struct bnx2x_func_sp_drv_ops bnx2x_func_sp_drv = {
12956 .init_hw_cmn_chip = bnx2x_init_hw_common_chip,
12957 .init_hw_cmn = bnx2x_init_hw_common,
12958 .init_hw_port = bnx2x_init_hw_port,
12959 .init_hw_func = bnx2x_init_hw_func,
12961 .reset_hw_cmn = bnx2x_reset_common,
12962 .reset_hw_port = bnx2x_reset_port,
12963 .reset_hw_func = bnx2x_reset_func,
12965 .gunzip_init = bnx2x_gunzip_init,
12966 .gunzip_end = bnx2x_gunzip_end,
12968 .init_fw = bnx2x_init_firmware,
12969 .release_fw = bnx2x_release_firmware,
12972 void bnx2x__init_func_obj(struct bnx2x *bp)
12974 /* Prepare DMAE related driver resources */
12975 bnx2x_setup_dmae(bp);
12977 bnx2x_init_func_obj(bp, &bp->func_obj,
12978 bnx2x_sp(bp, func_rdata),
12979 bnx2x_sp_mapping(bp, func_rdata),
12980 bnx2x_sp(bp, func_afex_rdata),
12981 bnx2x_sp_mapping(bp, func_afex_rdata),
12982 &bnx2x_func_sp_drv);
12985 /* must be called after sriov-enable */
12986 static int bnx2x_set_qm_cid_count(struct bnx2x *bp)
12988 int cid_count = BNX2X_L2_MAX_CID(bp);
12991 cid_count += BNX2X_VF_CIDS;
12993 if (CNIC_SUPPORT(bp))
12994 cid_count += CNIC_CID_MAX;
12996 return roundup(cid_count, QM_CID_ROUND);
13000 * bnx2x_get_num_none_def_sbs - return the number of none default SBs
13005 static int bnx2x_get_num_non_def_sbs(struct pci_dev *pdev, int cnic_cnt)
13011 * If MSI-X is not supported - return number of SBs needed to support
13012 * one fast path queue: one FP queue + SB for CNIC
13014 if (!pdev->msix_cap) {
13015 dev_info(&pdev->dev, "no msix capability found\n");
13016 return 1 + cnic_cnt;
13018 dev_info(&pdev->dev, "msix capability found\n");
13021 * The value in the PCI configuration space is the index of the last
13022 * entry, namely one less than the actual size of the table, which is
13023 * exactly what we want to return from this function: number of all SBs
13024 * without the default SB.
13025 * For VFs there is no default SB, then we return (index+1).
13027 pci_read_config_word(pdev, pdev->msix_cap + PCI_MSIX_FLAGS, &control);
13029 index = control & PCI_MSIX_FLAGS_QSIZE;
13034 static int set_max_cos_est(int chip_id)
13040 return BNX2X_MULTI_TX_COS_E1X;
13043 return BNX2X_MULTI_TX_COS_E2_E3A0;
13048 case BCM57840_4_10:
13049 case BCM57840_2_20:
13055 return BNX2X_MULTI_TX_COS_E3B0;
13063 pr_err("Unknown board_type (%d), aborting\n", chip_id);
13068 static int set_is_vf(int chip_id)
13082 /* nig_tsgen registers relative address */
13083 #define tsgen_ctrl 0x0
13084 #define tsgen_freecount 0x10
13085 #define tsgen_synctime_t0 0x20
13086 #define tsgen_offset_t0 0x28
13087 #define tsgen_drift_t0 0x30
13088 #define tsgen_synctime_t1 0x58
13089 #define tsgen_offset_t1 0x60
13090 #define tsgen_drift_t1 0x68
13092 /* FW workaround for setting drift */
13093 static int bnx2x_send_update_drift_ramrod(struct bnx2x *bp, int drift_dir,
13094 int best_val, int best_period)
13096 struct bnx2x_func_state_params func_params = {NULL};
13097 struct bnx2x_func_set_timesync_params *set_timesync_params =
13098 &func_params.params.set_timesync;
13100 /* Prepare parameters for function state transitions */
13101 __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
13102 __set_bit(RAMROD_RETRY, &func_params.ramrod_flags);
13104 func_params.f_obj = &bp->func_obj;
13105 func_params.cmd = BNX2X_F_CMD_SET_TIMESYNC;
13107 /* Function parameters */
13108 set_timesync_params->drift_adjust_cmd = TS_DRIFT_ADJUST_SET;
13109 set_timesync_params->offset_cmd = TS_OFFSET_KEEP;
13110 set_timesync_params->add_sub_drift_adjust_value =
13111 drift_dir ? TS_ADD_VALUE : TS_SUB_VALUE;
13112 set_timesync_params->drift_adjust_value = best_val;
13113 set_timesync_params->drift_adjust_period = best_period;
13115 return bnx2x_func_state_change(bp, &func_params);
13118 static int bnx2x_ptp_adjfreq(struct ptp_clock_info *ptp, s32 ppb)
13120 struct bnx2x *bp = container_of(ptp, struct bnx2x, ptp_clock_info);
13123 int val, period, period1, period2, dif, dif1, dif2;
13124 int best_dif = BNX2X_MAX_PHC_DRIFT, best_period = 0, best_val = 0;
13126 DP(BNX2X_MSG_PTP, "PTP adjfreq called, ppb = %d\n", ppb);
13128 if (!netif_running(bp->dev)) {
13130 "PTP adjfreq called while the interface is down\n");
13141 best_period = 0x1FFFFFF;
13142 } else if (ppb >= BNX2X_MAX_PHC_DRIFT) {
13146 /* Changed not to allow val = 8, 16, 24 as these values
13147 * are not supported in workaround.
13149 for (val = 0; val <= 31; val++) {
13150 if ((val & 0x7) == 0)
13152 period1 = val * 1000000 / ppb;
13153 period2 = period1 + 1;
13155 dif1 = ppb - (val * 1000000 / period1);
13157 dif1 = BNX2X_MAX_PHC_DRIFT;
13160 dif2 = ppb - (val * 1000000 / period2);
13163 dif = (dif1 < dif2) ? dif1 : dif2;
13164 period = (dif1 < dif2) ? period1 : period2;
13165 if (dif < best_dif) {
13168 best_period = period;
13173 rc = bnx2x_send_update_drift_ramrod(bp, drift_dir, best_val,
13176 BNX2X_ERR("Failed to set drift\n");
13180 DP(BNX2X_MSG_PTP, "Configrued val = %d, period = %d\n", best_val,
13186 static int bnx2x_ptp_adjtime(struct ptp_clock_info *ptp, s64 delta)
13188 struct bnx2x *bp = container_of(ptp, struct bnx2x, ptp_clock_info);
13191 DP(BNX2X_MSG_PTP, "PTP adjtime called, delta = %llx\n", delta);
13193 now = timecounter_read(&bp->timecounter);
13195 /* Re-init the timecounter */
13196 timecounter_init(&bp->timecounter, &bp->cyclecounter, now);
13201 static int bnx2x_ptp_gettime(struct ptp_clock_info *ptp, struct timespec *ts)
13203 struct bnx2x *bp = container_of(ptp, struct bnx2x, ptp_clock_info);
13207 ns = timecounter_read(&bp->timecounter);
13209 DP(BNX2X_MSG_PTP, "PTP gettime called, ns = %llu\n", ns);
13211 ts->tv_sec = div_u64_rem(ns, 1000000000ULL, &remainder);
13212 ts->tv_nsec = remainder;
13217 static int bnx2x_ptp_settime(struct ptp_clock_info *ptp,
13218 const struct timespec *ts)
13220 struct bnx2x *bp = container_of(ptp, struct bnx2x, ptp_clock_info);
13223 ns = ts->tv_sec * 1000000000ULL;
13226 DP(BNX2X_MSG_PTP, "PTP settime called, ns = %llu\n", ns);
13228 /* Re-init the timecounter */
13229 timecounter_init(&bp->timecounter, &bp->cyclecounter, ns);
13234 /* Enable (or disable) ancillary features of the phc subsystem */
13235 static int bnx2x_ptp_enable(struct ptp_clock_info *ptp,
13236 struct ptp_clock_request *rq, int on)
13238 struct bnx2x *bp = container_of(ptp, struct bnx2x, ptp_clock_info);
13240 BNX2X_ERR("PHC ancillary features are not supported\n");
13244 void bnx2x_register_phc(struct bnx2x *bp)
13246 /* Fill the ptp_clock_info struct and register PTP clock*/
13247 bp->ptp_clock_info.owner = THIS_MODULE;
13248 snprintf(bp->ptp_clock_info.name, 16, "%s", bp->dev->name);
13249 bp->ptp_clock_info.max_adj = BNX2X_MAX_PHC_DRIFT; /* In PPB */
13250 bp->ptp_clock_info.n_alarm = 0;
13251 bp->ptp_clock_info.n_ext_ts = 0;
13252 bp->ptp_clock_info.n_per_out = 0;
13253 bp->ptp_clock_info.pps = 0;
13254 bp->ptp_clock_info.adjfreq = bnx2x_ptp_adjfreq;
13255 bp->ptp_clock_info.adjtime = bnx2x_ptp_adjtime;
13256 bp->ptp_clock_info.gettime = bnx2x_ptp_gettime;
13257 bp->ptp_clock_info.settime = bnx2x_ptp_settime;
13258 bp->ptp_clock_info.enable = bnx2x_ptp_enable;
13260 bp->ptp_clock = ptp_clock_register(&bp->ptp_clock_info, &bp->pdev->dev);
13261 if (IS_ERR(bp->ptp_clock)) {
13262 bp->ptp_clock = NULL;
13263 BNX2X_ERR("PTP clock registeration failed\n");
13267 static int bnx2x_init_one(struct pci_dev *pdev,
13268 const struct pci_device_id *ent)
13270 struct net_device *dev = NULL;
13272 enum pcie_link_width pcie_width;
13273 enum pci_bus_speed pcie_speed;
13274 int rc, max_non_def_sbs;
13275 int rx_count, tx_count, rss_count, doorbell_size;
13280 /* An estimated maximum supported CoS number according to the chip
13282 * We will try to roughly estimate the maximum number of CoSes this chip
13283 * may support in order to minimize the memory allocated for Tx
13284 * netdev_queue's. This number will be accurately calculated during the
13285 * initialization of bp->max_cos based on the chip versions AND chip
13286 * revision in the bnx2x_init_bp().
13288 max_cos_est = set_max_cos_est(ent->driver_data);
13289 if (max_cos_est < 0)
13290 return max_cos_est;
13291 is_vf = set_is_vf(ent->driver_data);
13292 cnic_cnt = is_vf ? 0 : 1;
13294 max_non_def_sbs = bnx2x_get_num_non_def_sbs(pdev, cnic_cnt);
13296 /* add another SB for VF as it has no default SB */
13297 max_non_def_sbs += is_vf ? 1 : 0;
13299 /* Maximum number of RSS queues: one IGU SB goes to CNIC */
13300 rss_count = max_non_def_sbs - cnic_cnt;
13305 /* Maximum number of netdev Rx queues: RSS + FCoE L2 */
13306 rx_count = rss_count + cnic_cnt;
13308 /* Maximum number of netdev Tx queues:
13309 * Maximum TSS queues * Maximum supported number of CoS + FCoE L2
13311 tx_count = rss_count * max_cos_est + cnic_cnt;
13313 /* dev zeroed in init_etherdev */
13314 dev = alloc_etherdev_mqs(sizeof(*bp), tx_count, rx_count);
13318 bp = netdev_priv(dev);
13322 bp->flags |= IS_VF_FLAG;
13324 bp->igu_sb_cnt = max_non_def_sbs;
13325 bp->igu_base_addr = IS_VF(bp) ? PXP_VF_ADDR_IGU_START : BAR_IGU_INTMEM;
13326 bp->msg_enable = debug;
13327 bp->cnic_support = cnic_cnt;
13328 bp->cnic_probe = bnx2x_cnic_probe;
13330 pci_set_drvdata(pdev, dev);
13332 rc = bnx2x_init_dev(bp, pdev, dev, ent->driver_data);
13338 BNX2X_DEV_INFO("This is a %s function\n",
13339 IS_PF(bp) ? "physical" : "virtual");
13340 BNX2X_DEV_INFO("Cnic support is %s\n", CNIC_SUPPORT(bp) ? "on" : "off");
13341 BNX2X_DEV_INFO("Max num of status blocks %d\n", max_non_def_sbs);
13342 BNX2X_DEV_INFO("Allocated netdev with %d tx and %d rx queues\n",
13343 tx_count, rx_count);
13345 rc = bnx2x_init_bp(bp);
13347 goto init_one_exit;
13349 /* Map doorbells here as we need the real value of bp->max_cos which
13350 * is initialized in bnx2x_init_bp() to determine the number of
13354 bp->doorbells = bnx2x_vf_doorbells(bp);
13355 rc = bnx2x_vf_pci_alloc(bp);
13357 goto init_one_exit;
13359 doorbell_size = BNX2X_L2_MAX_CID(bp) * (1 << BNX2X_DB_SHIFT);
13360 if (doorbell_size > pci_resource_len(pdev, 2)) {
13361 dev_err(&bp->pdev->dev,
13362 "Cannot map doorbells, bar size too small, aborting\n");
13364 goto init_one_exit;
13366 bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2),
13369 if (!bp->doorbells) {
13370 dev_err(&bp->pdev->dev,
13371 "Cannot map doorbell space, aborting\n");
13373 goto init_one_exit;
13377 rc = bnx2x_vfpf_acquire(bp, tx_count, rx_count);
13379 goto init_one_exit;
13382 /* Enable SRIOV if capability found in configuration space */
13383 rc = bnx2x_iov_init_one(bp, int_mode, BNX2X_MAX_NUM_OF_VFS);
13385 goto init_one_exit;
13387 /* calc qm_cid_count */
13388 bp->qm_cid_count = bnx2x_set_qm_cid_count(bp);
13389 BNX2X_DEV_INFO("qm_cid_count %d\n", bp->qm_cid_count);
13391 /* disable FCOE L2 queue for E1x*/
13392 if (CHIP_IS_E1x(bp))
13393 bp->flags |= NO_FCOE_FLAG;
13395 /* Set bp->num_queues for MSI-X mode*/
13396 bnx2x_set_num_queues(bp);
13398 /* Configure interrupt mode: try to enable MSI-X/MSI if
13401 rc = bnx2x_set_int_mode(bp);
13403 dev_err(&pdev->dev, "Cannot set interrupts\n");
13404 goto init_one_exit;
13406 BNX2X_DEV_INFO("set interrupts successfully\n");
13408 /* register the net device */
13409 rc = register_netdev(dev);
13411 dev_err(&pdev->dev, "Cannot register net device\n");
13412 goto init_one_exit;
13414 BNX2X_DEV_INFO("device name after netdev register %s\n", dev->name);
13416 if (!NO_FCOE(bp)) {
13417 /* Add storage MAC address */
13419 dev_addr_add(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
13422 if (pcie_get_minimum_link(bp->pdev, &pcie_speed, &pcie_width) ||
13423 pcie_speed == PCI_SPEED_UNKNOWN ||
13424 pcie_width == PCIE_LNK_WIDTH_UNKNOWN)
13425 BNX2X_DEV_INFO("Failed to determine PCI Express Bandwidth\n");
13428 "%s (%c%d) PCI-E x%d %s found at mem %lx, IRQ %d, node addr %pM\n",
13429 board_info[ent->driver_data].name,
13430 (CHIP_REV(bp) >> 12) + 'A', (CHIP_METAL(bp) >> 4),
13432 pcie_speed == PCIE_SPEED_2_5GT ? "2.5GHz" :
13433 pcie_speed == PCIE_SPEED_5_0GT ? "5.0GHz" :
13434 pcie_speed == PCIE_SPEED_8_0GT ? "8.0GHz" :
13436 dev->base_addr, bp->pdev->irq, dev->dev_addr);
13438 bnx2x_register_phc(bp);
13443 bnx2x_disable_pcie_error_reporting(bp);
13446 iounmap(bp->regview);
13448 if (IS_PF(bp) && bp->doorbells)
13449 iounmap(bp->doorbells);
13453 if (atomic_read(&pdev->enable_cnt) == 1)
13454 pci_release_regions(pdev);
13456 pci_disable_device(pdev);
13461 static void __bnx2x_remove(struct pci_dev *pdev,
13462 struct net_device *dev,
13464 bool remove_netdev)
13466 if (bp->ptp_clock) {
13467 ptp_clock_unregister(bp->ptp_clock);
13468 bp->ptp_clock = NULL;
13471 /* Delete storage MAC address */
13472 if (!NO_FCOE(bp)) {
13474 dev_addr_del(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
13479 /* Delete app tlvs from dcbnl */
13480 bnx2x_dcbnl_update_applist(bp, true);
13485 (bp->flags & BC_SUPPORTS_RMMOD_CMD))
13486 bnx2x_fw_command(bp, DRV_MSG_CODE_RMMOD, 0);
13488 /* Close the interface - either directly or implicitly */
13489 if (remove_netdev) {
13490 unregister_netdev(dev);
13497 bnx2x_iov_remove_one(bp);
13499 /* Power on: we can't let PCI layer write to us while we are in D3 */
13501 bnx2x_set_power_state(bp, PCI_D0);
13503 /* Disable MSI/MSI-X */
13504 bnx2x_disable_msi(bp);
13508 bnx2x_set_power_state(bp, PCI_D3hot);
13510 /* Make sure RESET task is not scheduled before continuing */
13511 cancel_delayed_work_sync(&bp->sp_rtnl_task);
13513 /* send message via vfpf channel to release the resources of this vf */
13515 bnx2x_vfpf_release(bp);
13517 /* Assumes no further PCIe PM changes will occur */
13518 if (system_state == SYSTEM_POWER_OFF) {
13519 pci_wake_from_d3(pdev, bp->wol);
13520 pci_set_power_state(pdev, PCI_D3hot);
13523 bnx2x_disable_pcie_error_reporting(bp);
13524 if (remove_netdev) {
13526 iounmap(bp->regview);
13528 /* For vfs, doorbells are part of the regview and were unmapped
13529 * along with it. FW is only loaded by PF.
13533 iounmap(bp->doorbells);
13535 bnx2x_release_firmware(bp);
13537 bnx2x_vf_pci_dealloc(bp);
13539 bnx2x_free_mem_bp(bp);
13543 if (atomic_read(&pdev->enable_cnt) == 1)
13544 pci_release_regions(pdev);
13546 pci_disable_device(pdev);
13550 static void bnx2x_remove_one(struct pci_dev *pdev)
13552 struct net_device *dev = pci_get_drvdata(pdev);
13556 dev_err(&pdev->dev, "BAD net device from bnx2x_init_one\n");
13559 bp = netdev_priv(dev);
13561 __bnx2x_remove(pdev, dev, bp, true);
13564 static int bnx2x_eeh_nic_unload(struct bnx2x *bp)
13566 bp->state = BNX2X_STATE_CLOSING_WAIT4_HALT;
13568 bp->rx_mode = BNX2X_RX_MODE_NONE;
13570 if (CNIC_LOADED(bp))
13571 bnx2x_cnic_notify(bp, CNIC_CTL_STOP_CMD);
13574 bnx2x_tx_disable(bp);
13575 /* Delete all NAPI objects */
13576 bnx2x_del_all_napi(bp);
13577 if (CNIC_LOADED(bp))
13578 bnx2x_del_all_napi_cnic(bp);
13579 netdev_reset_tc(bp->dev);
13581 del_timer_sync(&bp->timer);
13582 cancel_delayed_work_sync(&bp->sp_task);
13583 cancel_delayed_work_sync(&bp->period_task);
13585 spin_lock_bh(&bp->stats_lock);
13586 bp->stats_state = STATS_STATE_DISABLED;
13587 spin_unlock_bh(&bp->stats_lock);
13589 bnx2x_save_statistics(bp);
13591 netif_carrier_off(bp->dev);
13597 * bnx2x_io_error_detected - called when PCI error is detected
13598 * @pdev: Pointer to PCI device
13599 * @state: The current pci connection state
13601 * This function is called after a PCI bus error affecting
13602 * this device has been detected.
13604 static pci_ers_result_t bnx2x_io_error_detected(struct pci_dev *pdev,
13605 pci_channel_state_t state)
13607 struct net_device *dev = pci_get_drvdata(pdev);
13608 struct bnx2x *bp = netdev_priv(dev);
13612 BNX2X_ERR("IO error detected\n");
13614 netif_device_detach(dev);
13616 if (state == pci_channel_io_perm_failure) {
13618 return PCI_ERS_RESULT_DISCONNECT;
13621 if (netif_running(dev))
13622 bnx2x_eeh_nic_unload(bp);
13624 bnx2x_prev_path_mark_eeh(bp);
13626 pci_disable_device(pdev);
13630 /* Request a slot reset */
13631 return PCI_ERS_RESULT_NEED_RESET;
13635 * bnx2x_io_slot_reset - called after the PCI bus has been reset
13636 * @pdev: Pointer to PCI device
13638 * Restart the card from scratch, as if from a cold-boot.
13640 static pci_ers_result_t bnx2x_io_slot_reset(struct pci_dev *pdev)
13642 struct net_device *dev = pci_get_drvdata(pdev);
13643 struct bnx2x *bp = netdev_priv(dev);
13647 BNX2X_ERR("IO slot reset initializing...\n");
13648 if (pci_enable_device(pdev)) {
13649 dev_err(&pdev->dev,
13650 "Cannot re-enable PCI device after reset\n");
13652 return PCI_ERS_RESULT_DISCONNECT;
13655 pci_set_master(pdev);
13656 pci_restore_state(pdev);
13657 pci_save_state(pdev);
13659 if (netif_running(dev))
13660 bnx2x_set_power_state(bp, PCI_D0);
13662 if (netif_running(dev)) {
13663 BNX2X_ERR("IO slot reset --> driver unload\n");
13665 /* MCP should have been reset; Need to wait for validity */
13666 bnx2x_init_shmem(bp);
13668 if (IS_PF(bp) && SHMEM2_HAS(bp, drv_capabilities_flag)) {
13672 drv_capabilities_flag[BP_FW_MB_IDX(bp)]);
13673 SHMEM2_WR(bp, drv_capabilities_flag[BP_FW_MB_IDX(bp)],
13674 v & ~DRV_FLAGS_CAPABILITIES_LOADED_L2);
13676 bnx2x_drain_tx_queues(bp);
13677 bnx2x_send_unload_req(bp, UNLOAD_RECOVERY);
13678 bnx2x_netif_stop(bp, 1);
13679 bnx2x_free_irq(bp);
13681 /* Report UNLOAD_DONE to MCP */
13682 bnx2x_send_unload_done(bp, true);
13687 bnx2x_prev_unload(bp);
13689 /* We should have reseted the engine, so It's fair to
13690 * assume the FW will no longer write to the bnx2x driver.
13692 bnx2x_squeeze_objects(bp);
13693 bnx2x_free_skbs(bp);
13694 for_each_rx_queue(bp, i)
13695 bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
13696 bnx2x_free_fp_mem(bp);
13697 bnx2x_free_mem(bp);
13699 bp->state = BNX2X_STATE_CLOSED;
13704 /* If AER, perform cleanup of the PCIe registers */
13705 if (bp->flags & AER_ENABLED) {
13706 if (pci_cleanup_aer_uncorrect_error_status(pdev))
13707 BNX2X_ERR("pci_cleanup_aer_uncorrect_error_status failed\n");
13709 DP(NETIF_MSG_HW, "pci_cleanup_aer_uncorrect_error_status succeeded\n");
13712 return PCI_ERS_RESULT_RECOVERED;
13716 * bnx2x_io_resume - called when traffic can start flowing again
13717 * @pdev: Pointer to PCI device
13719 * This callback is called when the error recovery driver tells us that
13720 * its OK to resume normal operation.
13722 static void bnx2x_io_resume(struct pci_dev *pdev)
13724 struct net_device *dev = pci_get_drvdata(pdev);
13725 struct bnx2x *bp = netdev_priv(dev);
13727 if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
13728 netdev_err(bp->dev, "Handling parity error recovery. Try again later\n");
13734 bp->fw_seq = SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
13735 DRV_MSG_SEQ_NUMBER_MASK;
13737 if (netif_running(dev))
13738 bnx2x_nic_load(bp, LOAD_NORMAL);
13740 netif_device_attach(dev);
13745 static const struct pci_error_handlers bnx2x_err_handler = {
13746 .error_detected = bnx2x_io_error_detected,
13747 .slot_reset = bnx2x_io_slot_reset,
13748 .resume = bnx2x_io_resume,
13751 static void bnx2x_shutdown(struct pci_dev *pdev)
13753 struct net_device *dev = pci_get_drvdata(pdev);
13759 bp = netdev_priv(dev);
13764 netif_device_detach(dev);
13767 /* Don't remove the netdevice, as there are scenarios which will cause
13768 * the kernel to hang, e.g., when trying to remove bnx2i while the
13769 * rootfs is mounted from SAN.
13771 __bnx2x_remove(pdev, dev, bp, false);
13774 static struct pci_driver bnx2x_pci_driver = {
13775 .name = DRV_MODULE_NAME,
13776 .id_table = bnx2x_pci_tbl,
13777 .probe = bnx2x_init_one,
13778 .remove = bnx2x_remove_one,
13779 .suspend = bnx2x_suspend,
13780 .resume = bnx2x_resume,
13781 .err_handler = &bnx2x_err_handler,
13782 #ifdef CONFIG_BNX2X_SRIOV
13783 .sriov_configure = bnx2x_sriov_configure,
13785 .shutdown = bnx2x_shutdown,
13788 static int __init bnx2x_init(void)
13792 pr_info("%s", version);
13794 bnx2x_wq = create_singlethread_workqueue("bnx2x");
13795 if (bnx2x_wq == NULL) {
13796 pr_err("Cannot create workqueue\n");
13799 bnx2x_iov_wq = create_singlethread_workqueue("bnx2x_iov");
13800 if (!bnx2x_iov_wq) {
13801 pr_err("Cannot create iov workqueue\n");
13802 destroy_workqueue(bnx2x_wq);
13806 ret = pci_register_driver(&bnx2x_pci_driver);
13808 pr_err("Cannot register driver\n");
13809 destroy_workqueue(bnx2x_wq);
13810 destroy_workqueue(bnx2x_iov_wq);
13815 static void __exit bnx2x_cleanup(void)
13817 struct list_head *pos, *q;
13819 pci_unregister_driver(&bnx2x_pci_driver);
13821 destroy_workqueue(bnx2x_wq);
13822 destroy_workqueue(bnx2x_iov_wq);
13824 /* Free globally allocated resources */
13825 list_for_each_safe(pos, q, &bnx2x_prev_list) {
13826 struct bnx2x_prev_path_list *tmp =
13827 list_entry(pos, struct bnx2x_prev_path_list, list);
13833 void bnx2x_notify_link_changed(struct bnx2x *bp)
13835 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + BP_FUNC(bp)*sizeof(u32), 1);
13838 module_init(bnx2x_init);
13839 module_exit(bnx2x_cleanup);
13842 * bnx2x_set_iscsi_eth_mac_addr - set iSCSI MAC(s).
13844 * @bp: driver handle
13845 * @set: set or clear the CAM entry
13847 * This function will wait until the ramrod completion returns.
13848 * Return 0 if success, -ENODEV if ramrod doesn't return.
13850 static int bnx2x_set_iscsi_eth_mac_addr(struct bnx2x *bp)
13852 unsigned long ramrod_flags = 0;
13854 __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
13855 return bnx2x_set_mac_one(bp, bp->cnic_eth_dev.iscsi_mac,
13856 &bp->iscsi_l2_mac_obj, true,
13857 BNX2X_ISCSI_ETH_MAC, &ramrod_flags);
13860 /* count denotes the number of new completions we have seen */
13861 static void bnx2x_cnic_sp_post(struct bnx2x *bp, int count)
13863 struct eth_spe *spe;
13864 int cxt_index, cxt_offset;
13866 #ifdef BNX2X_STOP_ON_ERROR
13867 if (unlikely(bp->panic))
13871 spin_lock_bh(&bp->spq_lock);
13872 BUG_ON(bp->cnic_spq_pending < count);
13873 bp->cnic_spq_pending -= count;
13875 for (; bp->cnic_kwq_pending; bp->cnic_kwq_pending--) {
13876 u16 type = (le16_to_cpu(bp->cnic_kwq_cons->hdr.type)
13877 & SPE_HDR_CONN_TYPE) >>
13878 SPE_HDR_CONN_TYPE_SHIFT;
13879 u8 cmd = (le32_to_cpu(bp->cnic_kwq_cons->hdr.conn_and_cmd_data)
13880 >> SPE_HDR_CMD_ID_SHIFT) & 0xff;
13882 /* Set validation for iSCSI L2 client before sending SETUP
13885 if (type == ETH_CONNECTION_TYPE) {
13886 if (cmd == RAMROD_CMD_ID_ETH_CLIENT_SETUP) {
13887 cxt_index = BNX2X_ISCSI_ETH_CID(bp) /
13889 cxt_offset = BNX2X_ISCSI_ETH_CID(bp) -
13890 (cxt_index * ILT_PAGE_CIDS);
13891 bnx2x_set_ctx_validation(bp,
13892 &bp->context[cxt_index].
13893 vcxt[cxt_offset].eth,
13894 BNX2X_ISCSI_ETH_CID(bp));
13899 * There may be not more than 8 L2, not more than 8 L5 SPEs
13900 * and in the air. We also check that number of outstanding
13901 * COMMON ramrods is not more than the EQ and SPQ can
13904 if (type == ETH_CONNECTION_TYPE) {
13905 if (!atomic_read(&bp->cq_spq_left))
13908 atomic_dec(&bp->cq_spq_left);
13909 } else if (type == NONE_CONNECTION_TYPE) {
13910 if (!atomic_read(&bp->eq_spq_left))
13913 atomic_dec(&bp->eq_spq_left);
13914 } else if ((type == ISCSI_CONNECTION_TYPE) ||
13915 (type == FCOE_CONNECTION_TYPE)) {
13916 if (bp->cnic_spq_pending >=
13917 bp->cnic_eth_dev.max_kwqe_pending)
13920 bp->cnic_spq_pending++;
13922 BNX2X_ERR("Unknown SPE type: %d\n", type);
13927 spe = bnx2x_sp_get_next(bp);
13928 *spe = *bp->cnic_kwq_cons;
13930 DP(BNX2X_MSG_SP, "pending on SPQ %d, on KWQ %d count %d\n",
13931 bp->cnic_spq_pending, bp->cnic_kwq_pending, count);
13933 if (bp->cnic_kwq_cons == bp->cnic_kwq_last)
13934 bp->cnic_kwq_cons = bp->cnic_kwq;
13936 bp->cnic_kwq_cons++;
13938 bnx2x_sp_prod_update(bp);
13939 spin_unlock_bh(&bp->spq_lock);
13942 static int bnx2x_cnic_sp_queue(struct net_device *dev,
13943 struct kwqe_16 *kwqes[], u32 count)
13945 struct bnx2x *bp = netdev_priv(dev);
13948 #ifdef BNX2X_STOP_ON_ERROR
13949 if (unlikely(bp->panic)) {
13950 BNX2X_ERR("Can't post to SP queue while panic\n");
13955 if ((bp->recovery_state != BNX2X_RECOVERY_DONE) &&
13956 (bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
13957 BNX2X_ERR("Handling parity error recovery. Try again later\n");
13961 spin_lock_bh(&bp->spq_lock);
13963 for (i = 0; i < count; i++) {
13964 struct eth_spe *spe = (struct eth_spe *)kwqes[i];
13966 if (bp->cnic_kwq_pending == MAX_SP_DESC_CNT)
13969 *bp->cnic_kwq_prod = *spe;
13971 bp->cnic_kwq_pending++;
13973 DP(BNX2X_MSG_SP, "L5 SPQE %x %x %x:%x pos %d\n",
13974 spe->hdr.conn_and_cmd_data, spe->hdr.type,
13975 spe->data.update_data_addr.hi,
13976 spe->data.update_data_addr.lo,
13977 bp->cnic_kwq_pending);
13979 if (bp->cnic_kwq_prod == bp->cnic_kwq_last)
13980 bp->cnic_kwq_prod = bp->cnic_kwq;
13982 bp->cnic_kwq_prod++;
13985 spin_unlock_bh(&bp->spq_lock);
13987 if (bp->cnic_spq_pending < bp->cnic_eth_dev.max_kwqe_pending)
13988 bnx2x_cnic_sp_post(bp, 0);
13993 static int bnx2x_cnic_ctl_send(struct bnx2x *bp, struct cnic_ctl_info *ctl)
13995 struct cnic_ops *c_ops;
13998 mutex_lock(&bp->cnic_mutex);
13999 c_ops = rcu_dereference_protected(bp->cnic_ops,
14000 lockdep_is_held(&bp->cnic_mutex));
14002 rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
14003 mutex_unlock(&bp->cnic_mutex);
14008 static int bnx2x_cnic_ctl_send_bh(struct bnx2x *bp, struct cnic_ctl_info *ctl)
14010 struct cnic_ops *c_ops;
14014 c_ops = rcu_dereference(bp->cnic_ops);
14016 rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
14023 * for commands that have no data
14025 int bnx2x_cnic_notify(struct bnx2x *bp, int cmd)
14027 struct cnic_ctl_info ctl = {0};
14031 return bnx2x_cnic_ctl_send(bp, &ctl);
14034 static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err)
14036 struct cnic_ctl_info ctl = {0};
14038 /* first we tell CNIC and only then we count this as a completion */
14039 ctl.cmd = CNIC_CTL_COMPLETION_CMD;
14040 ctl.data.comp.cid = cid;
14041 ctl.data.comp.error = err;
14043 bnx2x_cnic_ctl_send_bh(bp, &ctl);
14044 bnx2x_cnic_sp_post(bp, 0);
14047 /* Called with netif_addr_lock_bh() taken.
14048 * Sets an rx_mode config for an iSCSI ETH client.
14050 * Completion should be checked outside.
14052 static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start)
14054 unsigned long accept_flags = 0, ramrod_flags = 0;
14055 u8 cl_id = bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
14056 int sched_state = BNX2X_FILTER_ISCSI_ETH_STOP_SCHED;
14059 /* Start accepting on iSCSI L2 ring. Accept all multicasts
14060 * because it's the only way for UIO Queue to accept
14061 * multicasts (in non-promiscuous mode only one Queue per
14062 * function will receive multicast packets (leading in our
14065 __set_bit(BNX2X_ACCEPT_UNICAST, &accept_flags);
14066 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept_flags);
14067 __set_bit(BNX2X_ACCEPT_BROADCAST, &accept_flags);
14068 __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept_flags);
14070 /* Clear STOP_PENDING bit if START is requested */
14071 clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &bp->sp_state);
14073 sched_state = BNX2X_FILTER_ISCSI_ETH_START_SCHED;
14075 /* Clear START_PENDING bit if STOP is requested */
14076 clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &bp->sp_state);
14078 if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
14079 set_bit(sched_state, &bp->sp_state);
14081 __set_bit(RAMROD_RX, &ramrod_flags);
14082 bnx2x_set_q_rx_mode(bp, cl_id, 0, accept_flags, 0,
14087 static int bnx2x_drv_ctl(struct net_device *dev, struct drv_ctl_info *ctl)
14089 struct bnx2x *bp = netdev_priv(dev);
14092 switch (ctl->cmd) {
14093 case DRV_CTL_CTXTBL_WR_CMD: {
14094 u32 index = ctl->data.io.offset;
14095 dma_addr_t addr = ctl->data.io.dma_addr;
14097 bnx2x_ilt_wr(bp, index, addr);
14101 case DRV_CTL_RET_L5_SPQ_CREDIT_CMD: {
14102 int count = ctl->data.credit.credit_count;
14104 bnx2x_cnic_sp_post(bp, count);
14108 /* rtnl_lock is held. */
14109 case DRV_CTL_START_L2_CMD: {
14110 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
14111 unsigned long sp_bits = 0;
14113 /* Configure the iSCSI classification object */
14114 bnx2x_init_mac_obj(bp, &bp->iscsi_l2_mac_obj,
14115 cp->iscsi_l2_client_id,
14116 cp->iscsi_l2_cid, BP_FUNC(bp),
14117 bnx2x_sp(bp, mac_rdata),
14118 bnx2x_sp_mapping(bp, mac_rdata),
14119 BNX2X_FILTER_MAC_PENDING,
14120 &bp->sp_state, BNX2X_OBJ_TYPE_RX,
14123 /* Set iSCSI MAC address */
14124 rc = bnx2x_set_iscsi_eth_mac_addr(bp);
14131 /* Start accepting on iSCSI L2 ring */
14133 netif_addr_lock_bh(dev);
14134 bnx2x_set_iscsi_eth_rx_mode(bp, true);
14135 netif_addr_unlock_bh(dev);
14137 /* bits to wait on */
14138 __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
14139 __set_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &sp_bits);
14141 if (!bnx2x_wait_sp_comp(bp, sp_bits))
14142 BNX2X_ERR("rx_mode completion timed out!\n");
14147 /* rtnl_lock is held. */
14148 case DRV_CTL_STOP_L2_CMD: {
14149 unsigned long sp_bits = 0;
14151 /* Stop accepting on iSCSI L2 ring */
14152 netif_addr_lock_bh(dev);
14153 bnx2x_set_iscsi_eth_rx_mode(bp, false);
14154 netif_addr_unlock_bh(dev);
14156 /* bits to wait on */
14157 __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
14158 __set_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &sp_bits);
14160 if (!bnx2x_wait_sp_comp(bp, sp_bits))
14161 BNX2X_ERR("rx_mode completion timed out!\n");
14166 /* Unset iSCSI L2 MAC */
14167 rc = bnx2x_del_all_macs(bp, &bp->iscsi_l2_mac_obj,
14168 BNX2X_ISCSI_ETH_MAC, true);
14171 case DRV_CTL_RET_L2_SPQ_CREDIT_CMD: {
14172 int count = ctl->data.credit.credit_count;
14174 smp_mb__before_atomic();
14175 atomic_add(count, &bp->cq_spq_left);
14176 smp_mb__after_atomic();
14179 case DRV_CTL_ULP_REGISTER_CMD: {
14180 int ulp_type = ctl->data.register_data.ulp_type;
14182 if (CHIP_IS_E3(bp)) {
14183 int idx = BP_FW_MB_IDX(bp);
14184 u32 cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
14185 int path = BP_PATH(bp);
14186 int port = BP_PORT(bp);
14188 u32 scratch_offset;
14191 /* first write capability to shmem2 */
14192 if (ulp_type == CNIC_ULP_ISCSI)
14193 cap |= DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
14194 else if (ulp_type == CNIC_ULP_FCOE)
14195 cap |= DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
14196 SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
14198 if ((ulp_type != CNIC_ULP_FCOE) ||
14199 (!SHMEM2_HAS(bp, ncsi_oem_data_addr)) ||
14200 (!(bp->flags & BC_SUPPORTS_FCOE_FEATURES)))
14203 /* if reached here - should write fcoe capabilities */
14204 scratch_offset = SHMEM2_RD(bp, ncsi_oem_data_addr);
14205 if (!scratch_offset)
14207 scratch_offset += offsetof(struct glob_ncsi_oem_data,
14208 fcoe_features[path][port]);
14209 host_addr = (u32 *) &(ctl->data.register_data.
14211 for (i = 0; i < sizeof(struct fcoe_capabilities);
14213 REG_WR(bp, scratch_offset + i,
14214 *(host_addr + i/4));
14216 bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_GET_DRV_VERSION, 0);
14220 case DRV_CTL_ULP_UNREGISTER_CMD: {
14221 int ulp_type = ctl->data.ulp_type;
14223 if (CHIP_IS_E3(bp)) {
14224 int idx = BP_FW_MB_IDX(bp);
14227 cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
14228 if (ulp_type == CNIC_ULP_ISCSI)
14229 cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
14230 else if (ulp_type == CNIC_ULP_FCOE)
14231 cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
14232 SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
14234 bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_GET_DRV_VERSION, 0);
14239 BNX2X_ERR("unknown command %x\n", ctl->cmd);
14246 void bnx2x_setup_cnic_irq_info(struct bnx2x *bp)
14248 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
14250 if (bp->flags & USING_MSIX_FLAG) {
14251 cp->drv_state |= CNIC_DRV_STATE_USING_MSIX;
14252 cp->irq_arr[0].irq_flags |= CNIC_IRQ_FL_MSIX;
14253 cp->irq_arr[0].vector = bp->msix_table[1].vector;
14255 cp->drv_state &= ~CNIC_DRV_STATE_USING_MSIX;
14256 cp->irq_arr[0].irq_flags &= ~CNIC_IRQ_FL_MSIX;
14258 if (!CHIP_IS_E1x(bp))
14259 cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e2_sb;
14261 cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e1x_sb;
14263 cp->irq_arr[0].status_blk_num = bnx2x_cnic_fw_sb_id(bp);
14264 cp->irq_arr[0].status_blk_num2 = bnx2x_cnic_igu_sb_id(bp);
14265 cp->irq_arr[1].status_blk = bp->def_status_blk;
14266 cp->irq_arr[1].status_blk_num = DEF_SB_ID;
14267 cp->irq_arr[1].status_blk_num2 = DEF_SB_IGU_ID;
14272 void bnx2x_setup_cnic_info(struct bnx2x *bp)
14274 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
14276 cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
14277 bnx2x_cid_ilt_lines(bp);
14278 cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
14279 cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
14280 cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
14282 DP(NETIF_MSG_IFUP, "BNX2X_1st_NON_L2_ETH_CID(bp) %x, cp->starting_cid %x, cp->fcoe_init_cid %x, cp->iscsi_l2_cid %x\n",
14283 BNX2X_1st_NON_L2_ETH_CID(bp), cp->starting_cid, cp->fcoe_init_cid,
14286 if (NO_ISCSI_OOO(bp))
14287 cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
14290 static int bnx2x_register_cnic(struct net_device *dev, struct cnic_ops *ops,
14293 struct bnx2x *bp = netdev_priv(dev);
14294 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
14297 DP(NETIF_MSG_IFUP, "Register_cnic called\n");
14300 BNX2X_ERR("NULL ops received\n");
14304 if (!CNIC_SUPPORT(bp)) {
14305 BNX2X_ERR("Can't register CNIC when not supported\n");
14306 return -EOPNOTSUPP;
14309 if (!CNIC_LOADED(bp)) {
14310 rc = bnx2x_load_cnic(bp);
14312 BNX2X_ERR("CNIC-related load failed\n");
14317 bp->cnic_enabled = true;
14319 bp->cnic_kwq = kzalloc(PAGE_SIZE, GFP_KERNEL);
14323 bp->cnic_kwq_cons = bp->cnic_kwq;
14324 bp->cnic_kwq_prod = bp->cnic_kwq;
14325 bp->cnic_kwq_last = bp->cnic_kwq + MAX_SP_DESC_CNT;
14327 bp->cnic_spq_pending = 0;
14328 bp->cnic_kwq_pending = 0;
14330 bp->cnic_data = data;
14333 cp->drv_state |= CNIC_DRV_STATE_REGD;
14334 cp->iro_arr = bp->iro_arr;
14336 bnx2x_setup_cnic_irq_info(bp);
14338 rcu_assign_pointer(bp->cnic_ops, ops);
14340 /* Schedule driver to read CNIC driver versions */
14341 bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_GET_DRV_VERSION, 0);
14346 static int bnx2x_unregister_cnic(struct net_device *dev)
14348 struct bnx2x *bp = netdev_priv(dev);
14349 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
14351 mutex_lock(&bp->cnic_mutex);
14353 RCU_INIT_POINTER(bp->cnic_ops, NULL);
14354 mutex_unlock(&bp->cnic_mutex);
14356 bp->cnic_enabled = false;
14357 kfree(bp->cnic_kwq);
14358 bp->cnic_kwq = NULL;
14363 static struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev)
14365 struct bnx2x *bp = netdev_priv(dev);
14366 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
14368 /* If both iSCSI and FCoE are disabled - return NULL in
14369 * order to indicate CNIC that it should not try to work
14370 * with this device.
14372 if (NO_ISCSI(bp) && NO_FCOE(bp))
14375 cp->drv_owner = THIS_MODULE;
14376 cp->chip_id = CHIP_ID(bp);
14377 cp->pdev = bp->pdev;
14378 cp->io_base = bp->regview;
14379 cp->io_base2 = bp->doorbells;
14380 cp->max_kwqe_pending = 8;
14381 cp->ctx_blk_size = CDU_ILT_PAGE_SZ;
14382 cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
14383 bnx2x_cid_ilt_lines(bp);
14384 cp->ctx_tbl_len = CNIC_ILT_LINES;
14385 cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
14386 cp->drv_submit_kwqes_16 = bnx2x_cnic_sp_queue;
14387 cp->drv_ctl = bnx2x_drv_ctl;
14388 cp->drv_register_cnic = bnx2x_register_cnic;
14389 cp->drv_unregister_cnic = bnx2x_unregister_cnic;
14390 cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
14391 cp->iscsi_l2_client_id =
14392 bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
14393 cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
14395 if (NO_ISCSI_OOO(bp))
14396 cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
14399 cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI;
14402 cp->drv_state |= CNIC_DRV_STATE_NO_FCOE;
14405 "page_size %d, tbl_offset %d, tbl_lines %d, starting cid %d\n",
14407 cp->ctx_tbl_offset,
14413 static u32 bnx2x_rx_ustorm_prods_offset(struct bnx2x_fastpath *fp)
14415 struct bnx2x *bp = fp->bp;
14416 u32 offset = BAR_USTRORM_INTMEM;
14419 return bnx2x_vf_ustorm_prods_offset(bp, fp);
14420 else if (!CHIP_IS_E1x(bp))
14421 offset += USTORM_RX_PRODS_E2_OFFSET(fp->cl_qzone_id);
14423 offset += USTORM_RX_PRODS_E1X_OFFSET(BP_PORT(bp), fp->cl_id);
14428 /* called only on E1H or E2.
14429 * When pretending to be PF, the pretend value is the function number 0...7
14430 * When pretending to be VF, the pretend val is the PF-num:VF-valid:ABS-VFID
14433 int bnx2x_pretend_func(struct bnx2x *bp, u16 pretend_func_val)
14437 if (CHIP_IS_E1H(bp) && pretend_func_val >= E1H_FUNC_MAX)
14440 /* get my own pretend register */
14441 pretend_reg = bnx2x_get_pretend_reg(bp);
14442 REG_WR(bp, pretend_reg, pretend_func_val);
14443 REG_RD(bp, pretend_reg);
14447 static void bnx2x_ptp_task(struct work_struct *work)
14449 struct bnx2x *bp = container_of(work, struct bnx2x, ptp_task);
14450 int port = BP_PORT(bp);
14453 struct skb_shared_hwtstamps shhwtstamps;
14455 /* Read Tx timestamp registers */
14456 val_seq = REG_RD(bp, port ? NIG_REG_P1_TLLH_PTP_BUF_SEQID :
14457 NIG_REG_P0_TLLH_PTP_BUF_SEQID);
14458 if (val_seq & 0x10000) {
14459 /* There is a valid timestamp value */
14460 timestamp = REG_RD(bp, port ? NIG_REG_P1_TLLH_PTP_BUF_TS_MSB :
14461 NIG_REG_P0_TLLH_PTP_BUF_TS_MSB);
14463 timestamp |= REG_RD(bp, port ? NIG_REG_P1_TLLH_PTP_BUF_TS_LSB :
14464 NIG_REG_P0_TLLH_PTP_BUF_TS_LSB);
14465 /* Reset timestamp register to allow new timestamp */
14466 REG_WR(bp, port ? NIG_REG_P1_TLLH_PTP_BUF_SEQID :
14467 NIG_REG_P0_TLLH_PTP_BUF_SEQID, 0x10000);
14468 ns = timecounter_cyc2time(&bp->timecounter, timestamp);
14470 memset(&shhwtstamps, 0, sizeof(shhwtstamps));
14471 shhwtstamps.hwtstamp = ns_to_ktime(ns);
14472 skb_tstamp_tx(bp->ptp_tx_skb, &shhwtstamps);
14473 dev_kfree_skb_any(bp->ptp_tx_skb);
14474 bp->ptp_tx_skb = NULL;
14476 DP(BNX2X_MSG_PTP, "Tx timestamp, timestamp cycles = %llu, ns = %llu\n",
14479 DP(BNX2X_MSG_PTP, "There is no valid Tx timestamp yet\n");
14480 /* Reschedule to keep checking for a valid timestamp value */
14481 schedule_work(&bp->ptp_task);
14485 void bnx2x_set_rx_ts(struct bnx2x *bp, struct sk_buff *skb)
14487 int port = BP_PORT(bp);
14490 timestamp = REG_RD(bp, port ? NIG_REG_P1_LLH_PTP_HOST_BUF_TS_MSB :
14491 NIG_REG_P0_LLH_PTP_HOST_BUF_TS_MSB);
14493 timestamp |= REG_RD(bp, port ? NIG_REG_P1_LLH_PTP_HOST_BUF_TS_LSB :
14494 NIG_REG_P0_LLH_PTP_HOST_BUF_TS_LSB);
14496 /* Reset timestamp register to allow new timestamp */
14497 REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_HOST_BUF_SEQID :
14498 NIG_REG_P0_LLH_PTP_HOST_BUF_SEQID, 0x10000);
14500 ns = timecounter_cyc2time(&bp->timecounter, timestamp);
14502 skb_hwtstamps(skb)->hwtstamp = ns_to_ktime(ns);
14504 DP(BNX2X_MSG_PTP, "Rx timestamp, timestamp cycles = %llu, ns = %llu\n",
14509 static cycle_t bnx2x_cyclecounter_read(const struct cyclecounter *cc)
14511 struct bnx2x *bp = container_of(cc, struct bnx2x, cyclecounter);
14512 int port = BP_PORT(bp);
14516 REG_RD_DMAE(bp, port ? NIG_REG_TIMESYNC_GEN_REG + tsgen_synctime_t1 :
14517 NIG_REG_TIMESYNC_GEN_REG + tsgen_synctime_t0, wb_data, 2);
14518 phc_cycles = wb_data[1];
14519 phc_cycles = (phc_cycles << 32) + wb_data[0];
14521 DP(BNX2X_MSG_PTP, "PHC read cycles = %llu\n", phc_cycles);
14526 static void bnx2x_init_cyclecounter(struct bnx2x *bp)
14528 memset(&bp->cyclecounter, 0, sizeof(bp->cyclecounter));
14529 bp->cyclecounter.read = bnx2x_cyclecounter_read;
14530 bp->cyclecounter.mask = CLOCKSOURCE_MASK(64);
14531 bp->cyclecounter.shift = 1;
14532 bp->cyclecounter.mult = 1;
14535 static int bnx2x_send_reset_timesync_ramrod(struct bnx2x *bp)
14537 struct bnx2x_func_state_params func_params = {NULL};
14538 struct bnx2x_func_set_timesync_params *set_timesync_params =
14539 &func_params.params.set_timesync;
14541 /* Prepare parameters for function state transitions */
14542 __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
14543 __set_bit(RAMROD_RETRY, &func_params.ramrod_flags);
14545 func_params.f_obj = &bp->func_obj;
14546 func_params.cmd = BNX2X_F_CMD_SET_TIMESYNC;
14548 /* Function parameters */
14549 set_timesync_params->drift_adjust_cmd = TS_DRIFT_ADJUST_RESET;
14550 set_timesync_params->offset_cmd = TS_OFFSET_KEEP;
14552 return bnx2x_func_state_change(bp, &func_params);
14555 int bnx2x_enable_ptp_packets(struct bnx2x *bp)
14557 struct bnx2x_queue_state_params q_params;
14560 /* send queue update ramrod to enable PTP packets */
14561 memset(&q_params, 0, sizeof(q_params));
14562 __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
14563 q_params.cmd = BNX2X_Q_CMD_UPDATE;
14564 __set_bit(BNX2X_Q_UPDATE_PTP_PKTS_CHNG,
14565 &q_params.params.update.update_flags);
14566 __set_bit(BNX2X_Q_UPDATE_PTP_PKTS,
14567 &q_params.params.update.update_flags);
14569 /* send the ramrod on all the queues of the PF */
14570 for_each_eth_queue(bp, i) {
14571 struct bnx2x_fastpath *fp = &bp->fp[i];
14573 /* Set the appropriate Queue object */
14574 q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
14576 /* Update the Queue state */
14577 rc = bnx2x_queue_state_change(bp, &q_params);
14579 BNX2X_ERR("Failed to enable PTP packets\n");
14587 int bnx2x_configure_ptp_filters(struct bnx2x *bp)
14589 int port = BP_PORT(bp);
14592 if (!bp->hwtstamp_ioctl_called)
14595 switch (bp->tx_type) {
14596 case HWTSTAMP_TX_ON:
14597 bp->flags |= TX_TIMESTAMPING_EN;
14598 REG_WR(bp, port ? NIG_REG_P1_TLLH_PTP_PARAM_MASK :
14599 NIG_REG_P0_TLLH_PTP_PARAM_MASK, 0x6AA);
14600 REG_WR(bp, port ? NIG_REG_P1_TLLH_PTP_RULE_MASK :
14601 NIG_REG_P0_TLLH_PTP_RULE_MASK, 0x3EEE);
14603 case HWTSTAMP_TX_ONESTEP_SYNC:
14604 BNX2X_ERR("One-step timestamping is not supported\n");
14608 switch (bp->rx_filter) {
14609 case HWTSTAMP_FILTER_NONE:
14611 case HWTSTAMP_FILTER_ALL:
14612 case HWTSTAMP_FILTER_SOME:
14613 bp->rx_filter = HWTSTAMP_FILTER_NONE;
14615 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
14616 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
14617 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
14618 bp->rx_filter = HWTSTAMP_FILTER_PTP_V1_L4_EVENT;
14619 /* Initialize PTP detection for UDP/IPv4 events */
14620 REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_PARAM_MASK :
14621 NIG_REG_P0_LLH_PTP_PARAM_MASK, 0x7EE);
14622 REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_RULE_MASK :
14623 NIG_REG_P0_LLH_PTP_RULE_MASK, 0x3FFE);
14625 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
14626 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
14627 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
14628 bp->rx_filter = HWTSTAMP_FILTER_PTP_V2_L4_EVENT;
14629 /* Initialize PTP detection for UDP/IPv4 or UDP/IPv6 events */
14630 REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_PARAM_MASK :
14631 NIG_REG_P0_LLH_PTP_PARAM_MASK, 0x7EA);
14632 REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_RULE_MASK :
14633 NIG_REG_P0_LLH_PTP_RULE_MASK, 0x3FEE);
14635 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
14636 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
14637 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
14638 bp->rx_filter = HWTSTAMP_FILTER_PTP_V2_L2_EVENT;
14639 /* Initialize PTP detection L2 events */
14640 REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_PARAM_MASK :
14641 NIG_REG_P0_LLH_PTP_PARAM_MASK, 0x6BF);
14642 REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_RULE_MASK :
14643 NIG_REG_P0_LLH_PTP_RULE_MASK, 0x3EFF);
14646 case HWTSTAMP_FILTER_PTP_V2_EVENT:
14647 case HWTSTAMP_FILTER_PTP_V2_SYNC:
14648 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
14649 bp->rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT;
14650 /* Initialize PTP detection L2, UDP/IPv4 or UDP/IPv6 events */
14651 REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_PARAM_MASK :
14652 NIG_REG_P0_LLH_PTP_PARAM_MASK, 0x6AA);
14653 REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_RULE_MASK :
14654 NIG_REG_P0_LLH_PTP_RULE_MASK, 0x3EEE);
14658 /* Indicate to FW that this PF expects recorded PTP packets */
14659 rc = bnx2x_enable_ptp_packets(bp);
14663 /* Enable sending PTP packets to host */
14664 REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_TO_HOST :
14665 NIG_REG_P0_LLH_PTP_TO_HOST, 0x1);
14670 static int bnx2x_hwtstamp_ioctl(struct bnx2x *bp, struct ifreq *ifr)
14672 struct hwtstamp_config config;
14675 DP(BNX2X_MSG_PTP, "HWTSTAMP IOCTL called\n");
14677 if (copy_from_user(&config, ifr->ifr_data, sizeof(config)))
14680 DP(BNX2X_MSG_PTP, "Requested tx_type: %d, requested rx_filters = %d\n",
14681 config.tx_type, config.rx_filter);
14683 if (config.flags) {
14684 BNX2X_ERR("config.flags is reserved for future use\n");
14688 bp->hwtstamp_ioctl_called = 1;
14689 bp->tx_type = config.tx_type;
14690 bp->rx_filter = config.rx_filter;
14692 rc = bnx2x_configure_ptp_filters(bp);
14696 config.rx_filter = bp->rx_filter;
14698 return copy_to_user(ifr->ifr_data, &config, sizeof(config)) ?
14702 /* Configrues HW for PTP */
14703 static int bnx2x_configure_ptp(struct bnx2x *bp)
14705 int rc, port = BP_PORT(bp);
14708 /* Reset PTP event detection rules - will be configured in the IOCTL */
14709 REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_PARAM_MASK :
14710 NIG_REG_P0_LLH_PTP_PARAM_MASK, 0x7FF);
14711 REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_RULE_MASK :
14712 NIG_REG_P0_LLH_PTP_RULE_MASK, 0x3FFF);
14713 REG_WR(bp, port ? NIG_REG_P1_TLLH_PTP_PARAM_MASK :
14714 NIG_REG_P0_TLLH_PTP_PARAM_MASK, 0x7FF);
14715 REG_WR(bp, port ? NIG_REG_P1_TLLH_PTP_RULE_MASK :
14716 NIG_REG_P0_TLLH_PTP_RULE_MASK, 0x3FFF);
14718 /* Disable PTP packets to host - will be configured in the IOCTL*/
14719 REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_TO_HOST :
14720 NIG_REG_P0_LLH_PTP_TO_HOST, 0x0);
14722 /* Enable the PTP feature */
14723 REG_WR(bp, port ? NIG_REG_P1_PTP_EN :
14724 NIG_REG_P0_PTP_EN, 0x3F);
14726 /* Enable the free-running counter */
14729 REG_WR_DMAE(bp, NIG_REG_TIMESYNC_GEN_REG + tsgen_ctrl, wb_data, 2);
14731 /* Reset drift register (offset register is not reset) */
14732 rc = bnx2x_send_reset_timesync_ramrod(bp);
14734 BNX2X_ERR("Failed to reset PHC drift register\n");
14738 /* Reset possibly old timestamps */
14739 REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_HOST_BUF_SEQID :
14740 NIG_REG_P0_LLH_PTP_HOST_BUF_SEQID, 0x10000);
14741 REG_WR(bp, port ? NIG_REG_P1_TLLH_PTP_BUF_SEQID :
14742 NIG_REG_P0_TLLH_PTP_BUF_SEQID, 0x10000);
14747 /* Called during load, to initialize PTP-related stuff */
14748 void bnx2x_init_ptp(struct bnx2x *bp)
14752 /* Configure PTP in HW */
14753 rc = bnx2x_configure_ptp(bp);
14755 BNX2X_ERR("Stopping PTP initialization\n");
14759 /* Init work queue for Tx timestamping */
14760 INIT_WORK(&bp->ptp_task, bnx2x_ptp_task);
14762 /* Init cyclecounter and timecounter. This is done only in the first
14763 * load. If done in every load, PTP application will fail when doing
14764 * unload / load (e.g. MTU change) while it is running.
14766 if (!bp->timecounter_init_done) {
14767 bnx2x_init_cyclecounter(bp);
14768 timecounter_init(&bp->timecounter, &bp->cyclecounter,
14769 ktime_to_ns(ktime_get_real()));
14770 bp->timecounter_init_done = 1;
14773 DP(BNX2X_MSG_PTP, "PTP initialization ended successfully\n");