1 /* bnx2x.c: Broadcom Everest network driver.
3 * Copyright (c) 2007 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 * Written by: Eliezer Tamir <eliezert@broadcom.com>
10 * Based on code from Michael Chan's bnx2 driver
11 * UDP CSUM errata workaround by Arik Gendelman
12 * Slowpath rework by Vladislav Zolotarov
13 * Statistics and Link managment by Yitchak Gertner
17 /* define this to make the driver freeze on error
18 * to allow getting debug info
19 * (you will need to reboot afterwords)
21 /*#define BNX2X_STOP_ON_ERROR*/
23 #include <linux/module.h>
24 #include <linux/moduleparam.h>
25 #include <linux/kernel.h>
26 #include <linux/device.h> /* for dev_info() */
27 #include <linux/timer.h>
28 #include <linux/errno.h>
29 #include <linux/ioport.h>
30 #include <linux/slab.h>
31 #include <linux/vmalloc.h>
32 #include <linux/interrupt.h>
33 #include <linux/pci.h>
34 #include <linux/init.h>
35 #include <linux/netdevice.h>
36 #include <linux/etherdevice.h>
37 #include <linux/skbuff.h>
38 #include <linux/dma-mapping.h>
39 #include <linux/bitops.h>
40 #include <linux/irq.h>
41 #include <linux/delay.h>
42 #include <asm/byteorder.h>
43 #include <linux/time.h>
44 #include <linux/ethtool.h>
45 #include <linux/mii.h>
46 #ifdef NETIF_F_HW_VLAN_TX
47 #include <linux/if_vlan.h>
52 #include <net/checksum.h>
53 #include <linux/workqueue.h>
54 #include <linux/crc32.h>
55 #include <linux/prefetch.h>
56 #include <linux/zlib.h>
57 #include <linux/version.h>
60 #include "bnx2x_reg.h"
61 #include "bnx2x_fw_defs.h"
62 #include "bnx2x_hsi.h"
64 #include "bnx2x_init.h"
66 #define DRV_MODULE_VERSION "0.40.15"
67 #define DRV_MODULE_RELDATE "$DateTime: 2007/11/15 07:28:37 $"
68 #define BNX2X_BC_VER 0x040009
70 /* Time in jiffies before concluding the transmitter is hung. */
71 #define TX_TIMEOUT (5*HZ)
73 static char version
[] __devinitdata
=
74 "Broadcom NetXtreme II 577xx 10Gigabit Ethernet Driver "
75 DRV_MODULE_NAME
" " DRV_MODULE_VERSION
" (" DRV_MODULE_RELDATE
")\n";
77 MODULE_AUTHOR("Eliezer Tamir <eliezert@broadcom.com>");
78 MODULE_DESCRIPTION("Broadcom NetXtreme II BCM57710 Driver");
79 MODULE_LICENSE("GPL");
80 MODULE_VERSION(DRV_MODULE_VERSION
);
81 MODULE_INFO(cvs_version
, "$Revision: #356 $");
90 module_param(use_inta
, int, 0);
91 module_param(poll
, int, 0);
92 module_param(onefunc
, int, 0);
93 module_param(debug
, int, 0);
94 MODULE_PARM_DESC(use_inta
, "use INT#A instead of MSI-X");
95 MODULE_PARM_DESC(poll
, "use polling (for debug)");
96 MODULE_PARM_DESC(onefunc
, "enable only first function");
97 MODULE_PARM_DESC(nomcp
, "ignore managment CPU (Implies onefunc)");
98 MODULE_PARM_DESC(debug
, "defualt debug msglevel");
101 module_param(use_multi
, int, 0);
102 MODULE_PARM_DESC(use_multi
, "use per-CPU queues");
105 enum bnx2x_board_type
{
109 /* indexed by board_t, above */
112 } board_info
[] __devinitdata
= {
113 { "Broadcom NetXtreme II BCM57710 XGb" }
116 static const struct pci_device_id bnx2x_pci_tbl
[] = {
117 { PCI_VENDOR_ID_BROADCOM
, PCI_DEVICE_ID_NX2_57710
,
118 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, BCM57710
},
122 MODULE_DEVICE_TABLE(pci
, bnx2x_pci_tbl
);
124 /****************************************************************************
125 * General service functions
126 ****************************************************************************/
129 * locking is done by mcp
131 static void bnx2x_reg_wr_ind(struct bnx2x
*bp
, u32 addr
, u32 val
)
133 pci_write_config_dword(bp
->pdev
, PCICFG_GRC_ADDRESS
, addr
);
134 pci_write_config_dword(bp
->pdev
, PCICFG_GRC_DATA
, val
);
135 pci_write_config_dword(bp
->pdev
, PCICFG_GRC_ADDRESS
,
136 PCICFG_VENDOR_ID_OFFSET
);
140 static u32
bnx2x_reg_rd_ind(struct bnx2x
*bp
, u32 addr
)
144 pci_write_config_dword(bp
->pdev
, PCICFG_GRC_ADDRESS
, addr
);
145 pci_read_config_dword(bp
->pdev
, PCICFG_GRC_DATA
, &val
);
146 pci_write_config_dword(bp
->pdev
, PCICFG_GRC_ADDRESS
,
147 PCICFG_VENDOR_ID_OFFSET
);
153 static const u32 dmae_reg_go_c
[] = {
154 DMAE_REG_GO_C0
, DMAE_REG_GO_C1
, DMAE_REG_GO_C2
, DMAE_REG_GO_C3
,
155 DMAE_REG_GO_C4
, DMAE_REG_GO_C5
, DMAE_REG_GO_C6
, DMAE_REG_GO_C7
,
156 DMAE_REG_GO_C8
, DMAE_REG_GO_C9
, DMAE_REG_GO_C10
, DMAE_REG_GO_C11
,
157 DMAE_REG_GO_C12
, DMAE_REG_GO_C13
, DMAE_REG_GO_C14
, DMAE_REG_GO_C15
160 /* copy command into DMAE command memory and set DMAE command go */
161 static void bnx2x_post_dmae(struct bnx2x
*bp
, struct dmae_command
*dmae
,
167 cmd_offset
= (DMAE_REG_CMD_MEM
+ sizeof(struct dmae_command
) * idx
);
168 for (i
= 0; i
< (sizeof(struct dmae_command
)/4); i
++) {
169 REG_WR(bp
, cmd_offset
+ i
*4, *(((u32
*)dmae
) + i
));
171 /* DP(NETIF_MSG_DMAE, "DMAE cmd[%d].%d (0x%08x) : 0x%08x\n",
172 idx, i, cmd_offset + i*4, *(((u32 *)dmae) + i)); */
174 REG_WR(bp
, dmae_reg_go_c
[idx
], 1);
177 static void bnx2x_write_dmae(struct bnx2x
*bp
, dma_addr_t dma_addr
,
178 u32 dst_addr
, u32 len32
)
180 struct dmae_command
*dmae
= &bp
->dmae
;
182 u32
*wb_comp
= bnx2x_sp(bp
, wb_comp
);
185 memset(dmae
, 0, sizeof(struct dmae_command
));
187 dmae
->opcode
= (DMAE_CMD_SRC_PCI
| DMAE_CMD_DST_GRC
|
188 DMAE_CMD_C_DST_PCI
| DMAE_CMD_C_ENABLE
|
189 DMAE_CMD_SRC_RESET
| DMAE_CMD_DST_RESET
|
191 DMAE_CMD_ENDIANITY_B_DW_SWAP
|
193 DMAE_CMD_ENDIANITY_DW_SWAP
|
195 (port
? DMAE_CMD_PORT_1
: DMAE_CMD_PORT_0
));
196 dmae
->src_addr_lo
= U64_LO(dma_addr
);
197 dmae
->src_addr_hi
= U64_HI(dma_addr
);
198 dmae
->dst_addr_lo
= dst_addr
>> 2;
199 dmae
->dst_addr_hi
= 0;
201 dmae
->comp_addr_lo
= U64_LO(bnx2x_sp_mapping(bp
, wb_comp
));
202 dmae
->comp_addr_hi
= U64_HI(bnx2x_sp_mapping(bp
, wb_comp
));
203 dmae
->comp_val
= BNX2X_WB_COMP_VAL
;
206 DP(NETIF_MSG_DMAE, "dmae: opcode 0x%08x\n"
207 DP_LEVEL "src_addr [%x:%08x] len [%d *4] "
208 "dst_addr [%x:%08x (%08x)]\n"
209 DP_LEVEL "comp_addr [%x:%08x] comp_val 0x%08x\n",
210 dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
211 dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo, dst_addr,
212 dmae->comp_addr_hi, dmae->comp_addr_lo, dmae->comp_val);
215 DP(NETIF_MSG_DMAE, "data [0x%08x 0x%08x 0x%08x 0x%08x]\n",
216 bp->slowpath->wb_data[0], bp->slowpath->wb_data[1],
217 bp->slowpath->wb_data[2], bp->slowpath->wb_data[3]);
222 bnx2x_post_dmae(bp
, dmae
, port
* 8);
225 /* adjust timeout for emulation/FPGA */
226 if (CHIP_REV_IS_SLOW(bp
))
228 while (*wb_comp
!= BNX2X_WB_COMP_VAL
) {
229 /* DP(NETIF_MSG_DMAE, "wb_comp 0x%08x\n", *wb_comp); */
232 BNX2X_ERR("dmae timeout!\n");
240 static void bnx2x_read_dmae(struct bnx2x
*bp
, u32 src_addr
, u32 len32
)
242 struct dmae_command
*dmae
= &bp
->dmae
;
244 u32
*wb_comp
= bnx2x_sp(bp
, wb_comp
);
247 memset(bnx2x_sp(bp
, wb_data
[0]), 0, sizeof(u32
) * 4);
248 memset(dmae
, 0, sizeof(struct dmae_command
));
250 dmae
->opcode
= (DMAE_CMD_SRC_GRC
| DMAE_CMD_DST_PCI
|
251 DMAE_CMD_C_DST_PCI
| DMAE_CMD_C_ENABLE
|
252 DMAE_CMD_SRC_RESET
| DMAE_CMD_DST_RESET
|
254 DMAE_CMD_ENDIANITY_B_DW_SWAP
|
256 DMAE_CMD_ENDIANITY_DW_SWAP
|
258 (port
? DMAE_CMD_PORT_1
: DMAE_CMD_PORT_0
));
259 dmae
->src_addr_lo
= src_addr
>> 2;
260 dmae
->src_addr_hi
= 0;
261 dmae
->dst_addr_lo
= U64_LO(bnx2x_sp_mapping(bp
, wb_data
));
262 dmae
->dst_addr_hi
= U64_HI(bnx2x_sp_mapping(bp
, wb_data
));
264 dmae
->comp_addr_lo
= U64_LO(bnx2x_sp_mapping(bp
, wb_comp
));
265 dmae
->comp_addr_hi
= U64_HI(bnx2x_sp_mapping(bp
, wb_comp
));
266 dmae
->comp_val
= BNX2X_WB_COMP_VAL
;
269 DP(NETIF_MSG_DMAE, "dmae: opcode 0x%08x\n"
270 DP_LEVEL "src_addr [%x:%08x] len [%d *4] "
271 "dst_addr [%x:%08x (%08x)]\n"
272 DP_LEVEL "comp_addr [%x:%08x] comp_val 0x%08x\n",
273 dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
274 dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo, src_addr,
275 dmae->comp_addr_hi, dmae->comp_addr_lo, dmae->comp_val);
280 bnx2x_post_dmae(bp
, dmae
, port
* 8);
283 while (*wb_comp
!= BNX2X_WB_COMP_VAL
) {
286 BNX2X_ERR("dmae timeout!\n");
292 DP(NETIF_MSG_DMAE, "data [0x%08x 0x%08x 0x%08x 0x%08x]\n",
293 bp->slowpath->wb_data[0], bp->slowpath->wb_data[1],
294 bp->slowpath->wb_data[2], bp->slowpath->wb_data[3]);
299 static int bnx2x_mc_assert(struct bnx2x
*bp
)
304 const char storm
[] = {"XTCU"};
305 const u32 intmem_base
[] = {
312 /* Go through all instances of all SEMIs */
313 for (i
= 0; i
< 4; i
++) {
314 last_idx
= REG_RD8(bp
, XSTORM_ASSERT_LIST_INDEX_OFFSET
+
316 BNX2X_ERR("DATA %cSTORM_ASSERT_LIST_INDEX 0x%x\n",
319 /* print the asserts */
320 for (j
= 0; j
< STROM_ASSERT_ARRAY_SIZE
; j
++) {
321 u32 row0
, row1
, row2
, row3
;
323 row0
= REG_RD(bp
, XSTORM_ASSERT_LIST_OFFSET(j
) +
325 row1
= REG_RD(bp
, XSTORM_ASSERT_LIST_OFFSET(j
) + 4 +
327 row2
= REG_RD(bp
, XSTORM_ASSERT_LIST_OFFSET(j
) + 8 +
329 row3
= REG_RD(bp
, XSTORM_ASSERT_LIST_OFFSET(j
) + 12 +
332 if (row0
!= COMMON_ASM_INVALID_ASSERT_OPCODE
) {
333 BNX2X_ERR("DATA %cSTORM_ASSERT_INDEX 0x%x ="
334 " 0x%08x 0x%08x 0x%08x 0x%08x\n",
335 storm
[i
], j
, row3
, row2
, row1
, row0
);
344 static void bnx2x_fw_dump(struct bnx2x
*bp
)
350 mark
= REG_RD(bp
, MCP_REG_MCPR_SCRATCH
+ 0xf104);
351 printk(KERN_ERR PFX
"begin fw dump (mark 0x%x)\n", mark
);
353 for (offset
= mark
- 0x08000000; offset
<= 0xF900; offset
+= 0x8*4) {
354 for (word
= 0; word
< 8; word
++)
355 data
[word
] = htonl(REG_RD(bp
, MCP_REG_MCPR_SCRATCH
+
358 printk(KERN_ERR PFX
"%s", (char *)data
);
360 for (offset
= 0xF108; offset
<= mark
- 0x08000000; offset
+= 0x8*4) {
361 for (word
= 0; word
< 8; word
++)
362 data
[word
] = htonl(REG_RD(bp
, MCP_REG_MCPR_SCRATCH
+
365 printk(KERN_ERR PFX
"%s", (char *)data
);
367 printk("\n" KERN_ERR PFX
"end of fw dump\n");
370 static void bnx2x_panic_dump(struct bnx2x
*bp
)
375 BNX2X_ERR("begin crash dump -----------------\n");
377 for_each_queue(bp
, i
) {
378 struct bnx2x_fastpath
*fp
= &bp
->fp
[i
];
379 struct eth_tx_db_data
*hw_prods
= fp
->hw_tx_prods
;
381 BNX2X_ERR("queue[%d]: tx_pkt_prod(%x) tx_pkt_cons(%x)"
382 " tx_bd_prod(%x) tx_bd_cons(%x) *tx_cons_sb(%x)"
383 " *rx_cons_sb(%x) rx_comp_prod(%x)"
384 " rx_comp_cons(%x) fp_c_idx(%x) fp_u_idx(%x)"
386 i
, fp
->tx_pkt_prod
, fp
->tx_pkt_cons
, fp
->tx_bd_prod
,
387 fp
->tx_bd_cons
, *fp
->tx_cons_sb
, *fp
->rx_cons_sb
,
388 fp
->rx_comp_prod
, fp
->rx_comp_cons
, fp
->fp_c_idx
,
389 fp
->fp_u_idx
, hw_prods
->packets_prod
,
392 start
= TX_BD(le16_to_cpu(*fp
->tx_cons_sb
) - 10);
393 end
= TX_BD(le16_to_cpu(*fp
->tx_cons_sb
) + 245);
394 for (j
= start
; j
< end
; j
++) {
395 struct sw_tx_bd
*sw_bd
= &fp
->tx_buf_ring
[j
];
397 BNX2X_ERR("packet[%x]=[%p,%x]\n", j
,
398 sw_bd
->skb
, sw_bd
->first_bd
);
401 start
= TX_BD(fp
->tx_bd_cons
- 10);
402 end
= TX_BD(fp
->tx_bd_cons
+ 254);
403 for (j
= start
; j
< end
; j
++) {
404 u32
*tx_bd
= (u32
*)&fp
->tx_desc_ring
[j
];
406 BNX2X_ERR("tx_bd[%x]=[%x:%x:%x:%x]\n",
407 j
, tx_bd
[0], tx_bd
[1], tx_bd
[2], tx_bd
[3]);
410 start
= RX_BD(le16_to_cpu(*fp
->rx_cons_sb
) - 10);
411 end
= RX_BD(le16_to_cpu(*fp
->rx_cons_sb
) + 503);
412 for (j
= start
; j
< end
; j
++) {
413 u32
*rx_bd
= (u32
*)&fp
->rx_desc_ring
[j
];
414 struct sw_rx_bd
*sw_bd
= &fp
->rx_buf_ring
[j
];
416 BNX2X_ERR("rx_bd[%x]=[%x:%x] sw_bd=[%p]\n",
417 j
, rx_bd
[0], rx_bd
[1], sw_bd
->skb
);
420 start
= RCQ_BD(fp
->rx_comp_cons
- 10);
421 end
= RCQ_BD(fp
->rx_comp_cons
+ 503);
422 for (j
= start
; j
< end
; j
++) {
423 u32
*cqe
= (u32
*)&fp
->rx_comp_ring
[j
];
425 BNX2X_ERR("cqe[%x]=[%x:%x:%x:%x]\n",
426 j
, cqe
[0], cqe
[1], cqe
[2], cqe
[3]);
430 BNX2X_ERR("def_c_idx(%u) def_u_idx(%u) def_t_idx(%u)"
431 " def_x_idx(%u) def_att_idx(%u) attn_state(%u)"
432 " spq_prod_idx(%u)\n",
433 bp
->def_c_idx
, bp
->def_u_idx
, bp
->def_t_idx
, bp
->def_x_idx
,
434 bp
->def_att_idx
, bp
->attn_state
, bp
->spq_prod_idx
);
438 BNX2X_ERR("end crash dump -----------------\n");
440 bp
->stats_state
= STATS_STATE_DISABLE
;
441 DP(BNX2X_MSG_STATS
, "stats_state - DISABLE\n");
444 static void bnx2x_enable_int(struct bnx2x
*bp
)
447 u32 addr
= port
? HC_REG_CONFIG_1
: HC_REG_CONFIG_0
;
448 u32 val
= REG_RD(bp
, addr
);
449 int msix
= (bp
->flags
& USING_MSIX_FLAG
) ? 1 : 0;
452 val
&= ~HC_CONFIG_0_REG_SINGLE_ISR_EN_0
;
453 val
|= (HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0
|
454 HC_CONFIG_0_REG_ATTN_BIT_EN_0
);
456 val
|= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0
|
457 HC_CONFIG_0_REG_INT_LINE_EN_0
|
458 HC_CONFIG_0_REG_ATTN_BIT_EN_0
);
459 val
&= ~HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0
;
462 DP(NETIF_MSG_INTR
, "write %x to HC %d (addr 0x%x) msi %d\n",
463 val
, port
, addr
, msix
);
465 REG_WR(bp
, addr
, val
);
468 static void bnx2x_disable_int(struct bnx2x
*bp
)
471 u32 addr
= port
? HC_REG_CONFIG_1
: HC_REG_CONFIG_0
;
472 u32 val
= REG_RD(bp
, addr
);
474 val
&= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0
|
475 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0
|
476 HC_CONFIG_0_REG_INT_LINE_EN_0
|
477 HC_CONFIG_0_REG_ATTN_BIT_EN_0
);
479 DP(NETIF_MSG_INTR
, "write %x to HC %d (addr 0x%x)\n",
482 REG_WR(bp
, addr
, val
);
483 if (REG_RD(bp
, addr
) != val
)
484 BNX2X_ERR("BUG! proper val not read from IGU!\n");
487 static void bnx2x_disable_int_sync(struct bnx2x
*bp
)
490 int msix
= (bp
->flags
& USING_MSIX_FLAG
) ? 1 : 0;
493 atomic_inc(&bp
->intr_sem
);
494 /* prevent the HW from sending interrupts*/
495 bnx2x_disable_int(bp
);
497 /* make sure all ISRs are done */
499 for_each_queue(bp
, i
)
500 synchronize_irq(bp
->msix_table
[i
].vector
);
502 /* one more for the Slow Path IRQ */
503 synchronize_irq(bp
->msix_table
[i
].vector
);
505 synchronize_irq(bp
->pdev
->irq
);
507 /* make sure sp_task is not running */
508 cancel_work_sync(&bp
->sp_task
);
515 * general service functions
518 static inline void bnx2x_ack_sb(struct bnx2x
*bp
, u8 id
,
519 u8 storm
, u16 index
, u8 op
, u8 update
)
521 u32 igu_addr
= (IGU_ADDR_INT_ACK
+ IGU_PORT_BASE
* bp
->port
) * 8;
522 struct igu_ack_register igu_ack
;
524 igu_ack
.status_block_index
= index
;
525 igu_ack
.sb_id_and_flags
=
526 ((id
<< IGU_ACK_REGISTER_STATUS_BLOCK_ID_SHIFT
) |
527 (storm
<< IGU_ACK_REGISTER_STORM_ID_SHIFT
) |
528 (update
<< IGU_ACK_REGISTER_UPDATE_INDEX_SHIFT
) |
529 (op
<< IGU_ACK_REGISTER_INTERRUPT_MODE_SHIFT
));
531 /* DP(NETIF_MSG_INTR, "write 0x%08x to IGU addr 0x%x\n",
532 (*(u32 *)&igu_ack), BAR_IGU_INTMEM + igu_addr); */
533 REG_WR(bp
, BAR_IGU_INTMEM
+ igu_addr
, (*(u32
*)&igu_ack
));
536 static inline u16
bnx2x_update_fpsb_idx(struct bnx2x_fastpath
*fp
)
538 struct host_status_block
*fpsb
= fp
->status_blk
;
541 barrier(); /* status block is written to by the chip */
542 if (fp
->fp_c_idx
!= fpsb
->c_status_block
.status_block_index
) {
543 fp
->fp_c_idx
= fpsb
->c_status_block
.status_block_index
;
546 if (fp
->fp_u_idx
!= fpsb
->u_status_block
.status_block_index
) {
547 fp
->fp_u_idx
= fpsb
->u_status_block
.status_block_index
;
553 static inline int bnx2x_has_work(struct bnx2x_fastpath
*fp
)
555 u16 rx_cons_sb
= le16_to_cpu(*fp
->rx_cons_sb
);
557 if ((rx_cons_sb
& MAX_RCQ_DESC_CNT
) == MAX_RCQ_DESC_CNT
)
560 if ((rx_cons_sb
!= fp
->rx_comp_cons
) ||
561 (le16_to_cpu(*fp
->tx_cons_sb
) != fp
->tx_pkt_cons
))
567 static u16
bnx2x_ack_int(struct bnx2x
*bp
)
569 u32 igu_addr
= (IGU_ADDR_SIMD_MASK
+ IGU_PORT_BASE
* bp
->port
) * 8;
570 u32 result
= REG_RD(bp
, BAR_IGU_INTMEM
+ igu_addr
);
572 /* DP(NETIF_MSG_INTR, "read 0x%08x from IGU addr 0x%x\n",
573 result, BAR_IGU_INTMEM + igu_addr); */
576 #warning IGU_DEBUG active
578 BNX2X_ERR("read %x from IGU\n", result
);
579 REG_WR(bp
, TM_REG_TIMER_SOFT_RST
, 0);
587 * fast path service functions
590 /* free skb in the packet ring at pos idx
591 * return idx of last bd freed
593 static u16
bnx2x_free_tx_pkt(struct bnx2x
*bp
, struct bnx2x_fastpath
*fp
,
596 struct sw_tx_bd
*tx_buf
= &fp
->tx_buf_ring
[idx
];
597 struct eth_tx_bd
*tx_bd
;
598 struct sk_buff
*skb
= tx_buf
->skb
;
599 u16 bd_idx
= tx_buf
->first_bd
;
602 DP(BNX2X_MSG_OFF
, "pkt_idx %d buff @(%p)->skb %p\n",
606 DP(BNX2X_MSG_OFF
, "free bd_idx %d\n", bd_idx
);
607 tx_bd
= &fp
->tx_desc_ring
[bd_idx
];
608 pci_unmap_single(bp
->pdev
, BD_UNMAP_ADDR(tx_bd
),
609 BD_UNMAP_LEN(tx_bd
), PCI_DMA_TODEVICE
);
611 nbd
= le16_to_cpu(tx_bd
->nbd
) - 1;
612 #ifdef BNX2X_STOP_ON_ERROR
613 if (nbd
> (MAX_SKB_FRAGS
+ 2)) {
614 BNX2X_ERR("bad nbd!\n");
619 /* Skip a parse bd and the TSO split header bd
620 since they have no mapping */
622 bd_idx
= TX_BD(NEXT_TX_IDX(bd_idx
));
624 if (tx_bd
->bd_flags
.as_bitfield
& (ETH_TX_BD_FLAGS_IP_CSUM
|
625 ETH_TX_BD_FLAGS_TCP_CSUM
|
626 ETH_TX_BD_FLAGS_SW_LSO
)) {
628 bd_idx
= TX_BD(NEXT_TX_IDX(bd_idx
));
629 tx_bd
= &fp
->tx_desc_ring
[bd_idx
];
630 /* is this a TSO split header bd? */
631 if (tx_bd
->bd_flags
.as_bitfield
& ETH_TX_BD_FLAGS_SW_LSO
) {
633 bd_idx
= TX_BD(NEXT_TX_IDX(bd_idx
));
640 DP(BNX2X_MSG_OFF
, "free frag bd_idx %d\n", bd_idx
);
641 tx_bd
= &fp
->tx_desc_ring
[bd_idx
];
642 pci_unmap_page(bp
->pdev
, BD_UNMAP_ADDR(tx_bd
),
643 BD_UNMAP_LEN(tx_bd
), PCI_DMA_TODEVICE
);
645 bd_idx
= TX_BD(NEXT_TX_IDX(bd_idx
));
651 tx_buf
->first_bd
= 0;
657 static inline u32
bnx2x_tx_avail(struct bnx2x_fastpath
*fp
)
663 /* Tell compiler that prod and cons can change */
665 prod
= fp
->tx_bd_prod
;
666 cons
= fp
->tx_bd_cons
;
668 used
= (NUM_TX_BD
- NUM_TX_RINGS
+ prod
- cons
+
669 (cons
/ TX_DESC_CNT
) - (prod
/ TX_DESC_CNT
));
672 /* used = prod - cons - prod/size + cons/size */
673 used
-= NUM_TX_BD
- NUM_TX_RINGS
;
676 BUG_TRAP(used
<= fp
->bp
->tx_ring_size
);
677 BUG_TRAP((fp
->bp
->tx_ring_size
- used
) <= MAX_TX_AVAIL
);
679 return (fp
->bp
->tx_ring_size
- used
);
682 static void bnx2x_tx_int(struct bnx2x_fastpath
*fp
, int work
)
684 struct bnx2x
*bp
= fp
->bp
;
685 u16 hw_cons
, sw_cons
, bd_cons
= fp
->tx_bd_cons
;
688 #ifdef BNX2X_STOP_ON_ERROR
689 if (unlikely(bp
->panic
))
693 hw_cons
= le16_to_cpu(*fp
->tx_cons_sb
);
694 sw_cons
= fp
->tx_pkt_cons
;
696 while (sw_cons
!= hw_cons
) {
699 pkt_cons
= TX_BD(sw_cons
);
701 /* prefetch(bp->tx_buf_ring[pkt_cons].skb); */
703 DP(NETIF_MSG_TX_DONE
, "hw_cons %u sw_cons %u pkt_cons %d\n",
704 hw_cons
, sw_cons
, pkt_cons
);
706 /* if (NEXT_TX_IDX(sw_cons) != hw_cons) {
708 prefetch(fp->tx_buf_ring[NEXT_TX_IDX(sw_cons)].skb);
711 bd_cons
= bnx2x_free_tx_pkt(bp
, fp
, pkt_cons
);
719 fp
->tx_pkt_cons
= sw_cons
;
720 fp
->tx_bd_cons
= bd_cons
;
722 /* Need to make the tx_cons update visible to start_xmit()
723 * before checking for netif_queue_stopped(). Without the
724 * memory barrier, there is a small possibility that start_xmit()
725 * will miss it and cause the queue to be stopped forever.
729 /* TBD need a thresh? */
730 if (unlikely(netif_queue_stopped(bp
->dev
))) {
732 netif_tx_lock(bp
->dev
);
734 if (netif_queue_stopped(bp
->dev
) &&
735 (bnx2x_tx_avail(fp
) >= MAX_SKB_FRAGS
+ 3))
736 netif_wake_queue(bp
->dev
);
738 netif_tx_unlock(bp
->dev
);
743 static void bnx2x_sp_event(struct bnx2x_fastpath
*fp
,
744 union eth_rx_cqe
*rr_cqe
)
746 struct bnx2x
*bp
= fp
->bp
;
747 int cid
= SW_CID(rr_cqe
->ramrod_cqe
.conn_and_cmd_data
);
748 int command
= CQE_CMD(rr_cqe
->ramrod_cqe
.conn_and_cmd_data
);
750 DP(NETIF_MSG_RX_STATUS
,
751 "fp %d cid %d got ramrod #%d state is %x type is %d\n",
752 fp
->index
, cid
, command
, bp
->state
, rr_cqe
->ramrod_cqe
.type
);
757 switch (command
| fp
->state
) {
758 case (RAMROD_CMD_ID_ETH_CLIENT_SETUP
|
759 BNX2X_FP_STATE_OPENING
):
760 DP(NETIF_MSG_IFUP
, "got MULTI[%d] setup ramrod\n",
762 fp
->state
= BNX2X_FP_STATE_OPEN
;
765 case (RAMROD_CMD_ID_ETH_HALT
| BNX2X_FP_STATE_HALTING
):
766 DP(NETIF_MSG_IFDOWN
, "got MULTI[%d] halt ramrod\n",
768 fp
->state
= BNX2X_FP_STATE_HALTED
;
772 BNX2X_ERR("unexpected MC reply(%d) state is %x\n",
775 mb(); /* force bnx2x_wait_ramrod to see the change */
778 switch (command
| bp
->state
) {
779 case (RAMROD_CMD_ID_ETH_PORT_SETUP
| BNX2X_STATE_OPENING_WAIT4_PORT
):
780 DP(NETIF_MSG_IFUP
, "got setup ramrod\n");
781 bp
->state
= BNX2X_STATE_OPEN
;
784 case (RAMROD_CMD_ID_ETH_HALT
| BNX2X_STATE_CLOSING_WAIT4_HALT
):
785 DP(NETIF_MSG_IFDOWN
, "got halt ramrod\n");
786 bp
->state
= BNX2X_STATE_CLOSING_WAIT4_DELETE
;
787 fp
->state
= BNX2X_FP_STATE_HALTED
;
790 case (RAMROD_CMD_ID_ETH_PORT_DEL
| BNX2X_STATE_CLOSING_WAIT4_DELETE
):
791 DP(NETIF_MSG_IFDOWN
, "got delete ramrod\n");
792 bp
->state
= BNX2X_STATE_CLOSING_WAIT4_UNLOAD
;
795 case (RAMROD_CMD_ID_ETH_CFC_DEL
| BNX2X_STATE_CLOSING_WAIT4_HALT
):
796 DP(NETIF_MSG_IFDOWN
, "got delete ramrod for MULTI[%d]\n", cid
);
797 bnx2x_fp(bp
, cid
, state
) = BNX2X_FP_STATE_DELETED
;
800 case (RAMROD_CMD_ID_ETH_SET_MAC
| BNX2X_STATE_OPEN
):
801 DP(NETIF_MSG_IFUP
, "got set mac ramrod\n");
805 BNX2X_ERR("unexpected ramrod (%d) state is %x\n",
809 mb(); /* force bnx2x_wait_ramrod to see the change */
812 static inline int bnx2x_alloc_rx_skb(struct bnx2x
*bp
,
813 struct bnx2x_fastpath
*fp
, u16 index
)
816 struct sw_rx_bd
*rx_buf
= &fp
->rx_buf_ring
[index
];
817 struct eth_rx_bd
*rx_bd
= &fp
->rx_desc_ring
[index
];
820 skb
= netdev_alloc_skb(bp
->dev
, bp
->rx_buf_size
);
821 if (unlikely(skb
== NULL
))
824 mapping
= pci_map_single(bp
->pdev
, skb
->data
, bp
->rx_buf_use_size
,
826 if (unlikely(dma_mapping_error(mapping
))) {
833 pci_unmap_addr_set(rx_buf
, mapping
, mapping
);
835 rx_bd
->addr_hi
= cpu_to_le32(U64_HI(mapping
));
836 rx_bd
->addr_lo
= cpu_to_le32(U64_LO(mapping
));
841 /* note that we are not allocating a new skb,
842 * we are just moving one from cons to prod
843 * we are not creating a new mapping,
844 * so there is no need to check for dma_mapping_error().
846 static void bnx2x_reuse_rx_skb(struct bnx2x_fastpath
*fp
,
847 struct sk_buff
*skb
, u16 cons
, u16 prod
)
849 struct bnx2x
*bp
= fp
->bp
;
850 struct sw_rx_bd
*cons_rx_buf
= &fp
->rx_buf_ring
[cons
];
851 struct sw_rx_bd
*prod_rx_buf
= &fp
->rx_buf_ring
[prod
];
852 struct eth_rx_bd
*cons_bd
= &fp
->rx_desc_ring
[cons
];
853 struct eth_rx_bd
*prod_bd
= &fp
->rx_desc_ring
[prod
];
855 pci_dma_sync_single_for_device(bp
->pdev
,
856 pci_unmap_addr(cons_rx_buf
, mapping
),
857 bp
->rx_offset
+ RX_COPY_THRESH
,
860 prod_rx_buf
->skb
= cons_rx_buf
->skb
;
861 pci_unmap_addr_set(prod_rx_buf
, mapping
,
862 pci_unmap_addr(cons_rx_buf
, mapping
));
866 static int bnx2x_rx_int(struct bnx2x_fastpath
*fp
, int budget
)
868 struct bnx2x
*bp
= fp
->bp
;
869 u16 bd_cons
, bd_prod
, comp_ring_cons
;
870 u16 hw_comp_cons
, sw_comp_cons
, sw_comp_prod
;
873 #ifdef BNX2X_STOP_ON_ERROR
874 if (unlikely(bp
->panic
))
878 hw_comp_cons
= le16_to_cpu(*fp
->rx_cons_sb
);
879 if ((hw_comp_cons
& MAX_RCQ_DESC_CNT
) == MAX_RCQ_DESC_CNT
)
882 bd_cons
= fp
->rx_bd_cons
;
883 bd_prod
= fp
->rx_bd_prod
;
884 sw_comp_cons
= fp
->rx_comp_cons
;
885 sw_comp_prod
= fp
->rx_comp_prod
;
887 /* Memory barrier necessary as speculative reads of the rx
888 * buffer can be ahead of the index in the status block
892 DP(NETIF_MSG_RX_STATUS
,
893 "queue[%d]: hw_comp_cons %u sw_comp_cons %u\n",
894 fp
->index
, hw_comp_cons
, sw_comp_cons
);
896 while (sw_comp_cons
!= hw_comp_cons
) {
897 unsigned int len
, pad
;
898 struct sw_rx_bd
*rx_buf
;
900 union eth_rx_cqe
*cqe
;
902 comp_ring_cons
= RCQ_BD(sw_comp_cons
);
903 bd_prod
= RX_BD(bd_prod
);
904 bd_cons
= RX_BD(bd_cons
);
906 cqe
= &fp
->rx_comp_ring
[comp_ring_cons
];
908 DP(NETIF_MSG_RX_STATUS
, "hw_comp_cons %u sw_comp_cons %u"
909 " comp_ring (%u) bd_ring (%u,%u)\n",
910 hw_comp_cons
, sw_comp_cons
,
911 comp_ring_cons
, bd_prod
, bd_cons
);
912 DP(NETIF_MSG_RX_STATUS
, "CQE type %x err %x status %x"
913 " queue %x vlan %x len %x\n",
914 cqe
->fast_path_cqe
.type
,
915 cqe
->fast_path_cqe
.error_type_flags
,
916 cqe
->fast_path_cqe
.status_flags
,
917 cqe
->fast_path_cqe
.rss_hash_result
,
918 cqe
->fast_path_cqe
.vlan_tag
, cqe
->fast_path_cqe
.pkt_len
);
920 /* is this a slowpath msg? */
921 if (unlikely(cqe
->fast_path_cqe
.type
)) {
922 bnx2x_sp_event(fp
, cqe
);
925 /* this is an rx packet */
927 rx_buf
= &fp
->rx_buf_ring
[bd_cons
];
930 len
= le16_to_cpu(cqe
->fast_path_cqe
.pkt_len
);
931 pad
= cqe
->fast_path_cqe
.placement_offset
;
933 pci_dma_sync_single_for_device(bp
->pdev
,
934 pci_unmap_addr(rx_buf
, mapping
),
935 pad
+ RX_COPY_THRESH
,
938 prefetch(((char *)(skb
)) + 128);
940 /* is this an error packet? */
941 if (unlikely(cqe
->fast_path_cqe
.error_type_flags
&
942 ETH_RX_ERROR_FALGS
)) {
943 /* do we sometimes forward error packets anyway? */
945 "ERROR flags(%u) Rx packet(%u)\n",
946 cqe
->fast_path_cqe
.error_type_flags
,
948 /* TBD make sure MC counts this as a drop */
952 /* Since we don't have a jumbo ring
953 * copy small packets if mtu > 1500
955 if ((bp
->dev
->mtu
> ETH_MAX_PACKET_SIZE
) &&
956 (len
<= RX_COPY_THRESH
)) {
957 struct sk_buff
*new_skb
;
959 new_skb
= netdev_alloc_skb(bp
->dev
,
961 if (new_skb
== NULL
) {
963 "ERROR packet dropped "
964 "because of alloc failure\n");
965 /* TBD count this as a drop? */
970 skb_copy_from_linear_data_offset(skb
, pad
,
971 new_skb
->data
+ pad
, len
);
972 skb_reserve(new_skb
, pad
);
973 skb_put(new_skb
, len
);
975 bnx2x_reuse_rx_skb(fp
, skb
, bd_cons
, bd_prod
);
979 } else if (bnx2x_alloc_rx_skb(bp
, fp
, bd_prod
) == 0) {
980 pci_unmap_single(bp
->pdev
,
981 pci_unmap_addr(rx_buf
, mapping
),
984 skb_reserve(skb
, pad
);
989 "ERROR packet dropped because "
990 "of alloc failure\n");
992 bnx2x_reuse_rx_skb(fp
, skb
, bd_cons
, bd_prod
);
996 skb
->protocol
= eth_type_trans(skb
, bp
->dev
);
998 skb
->ip_summed
= CHECKSUM_NONE
;
999 if (bp
->rx_csum
&& BNX2X_RX_SUM_OK(cqe
))
1000 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
1002 /* TBD do we pass bad csum packets in promisc */
1006 if ((le16_to_cpu(cqe
->fast_path_cqe
.pars_flags
.flags
)
1007 & PARSING_FLAGS_NUMBER_OF_NESTED_VLANS
)
1008 && (bp
->vlgrp
!= NULL
))
1009 vlan_hwaccel_receive_skb(skb
, bp
->vlgrp
,
1010 le16_to_cpu(cqe
->fast_path_cqe
.vlan_tag
));
1013 netif_receive_skb(skb
);
1015 bp
->dev
->last_rx
= jiffies
;
1020 bd_cons
= NEXT_RX_IDX(bd_cons
);
1021 bd_prod
= NEXT_RX_IDX(bd_prod
);
1023 sw_comp_prod
= NEXT_RCQ_IDX(sw_comp_prod
);
1024 sw_comp_cons
= NEXT_RCQ_IDX(sw_comp_cons
);
1027 if ((rx_pkt
== budget
))
1031 fp
->rx_bd_cons
= bd_cons
;
1032 fp
->rx_bd_prod
= bd_prod
;
1033 fp
->rx_comp_cons
= sw_comp_cons
;
1034 fp
->rx_comp_prod
= sw_comp_prod
;
1036 REG_WR(bp
, BAR_TSTRORM_INTMEM
+
1037 TSTORM_RCQ_PROD_OFFSET(bp
->port
, fp
->index
), sw_comp_prod
);
1039 mmiowb(); /* keep prod updates ordered */
1041 fp
->rx_pkt
+= rx_pkt
;
1047 static irqreturn_t
bnx2x_msix_fp_int(int irq
, void *fp_cookie
)
1049 struct bnx2x_fastpath
*fp
= fp_cookie
;
1050 struct bnx2x
*bp
= fp
->bp
;
1051 struct net_device
*dev
= bp
->dev
;
1052 int index
= fp
->index
;
1054 DP(NETIF_MSG_INTR
, "got an msix interrupt on [%d]\n", index
);
1055 bnx2x_ack_sb(bp
, index
, USTORM_ID
, 0, IGU_INT_DISABLE
, 0);
1057 #ifdef BNX2X_STOP_ON_ERROR
1058 if (unlikely(bp
->panic
))
1062 prefetch(fp
->rx_cons_sb
);
1063 prefetch(fp
->tx_cons_sb
);
1064 prefetch(&fp
->status_blk
->c_status_block
.status_block_index
);
1065 prefetch(&fp
->status_blk
->u_status_block
.status_block_index
);
1067 netif_rx_schedule(dev
, &bnx2x_fp(bp
, index
, napi
));
1071 static irqreturn_t
bnx2x_interrupt(int irq
, void *dev_instance
)
1073 struct net_device
*dev
= dev_instance
;
1074 struct bnx2x
*bp
= netdev_priv(dev
);
1075 u16 status
= bnx2x_ack_int(bp
);
1077 if (unlikely(status
== 0)) {
1078 DP(NETIF_MSG_INTR
, "not our interrupt!\n");
1082 DP(NETIF_MSG_INTR
, "got an interrupt status is %u\n", status
);
1084 #ifdef BNX2X_STOP_ON_ERROR
1085 if (unlikely(bp
->panic
))
1089 /* Return here if interrupt is shared and is disabled */
1090 if (unlikely(atomic_read(&bp
->intr_sem
) != 0)) {
1091 DP(NETIF_MSG_INTR
, "called but intr_sem not 0, returning\n");
1096 struct bnx2x_fastpath
*fp
= &bp
->fp
[0];
1098 prefetch(fp
->rx_cons_sb
);
1099 prefetch(fp
->tx_cons_sb
);
1100 prefetch(&fp
->status_blk
->c_status_block
.status_block_index
);
1101 prefetch(&fp
->status_blk
->u_status_block
.status_block_index
);
1103 netif_rx_schedule(dev
, &bnx2x_fp(bp
, 0, napi
));
1110 if (unlikely(status
& 0x1)) {
1112 schedule_work(&bp
->sp_task
);
1119 DP(NETIF_MSG_INTR
, "got an unknown interrupt! (status is %u)\n",
1125 /* end of fast path */
1130 * General service functions
1133 static void bnx2x_leds_set(struct bnx2x
*bp
, unsigned int speed
)
1135 int port
= bp
->port
;
1137 NIG_WR(NIG_REG_LED_MODE_P0
+ port
*4,
1138 ((bp
->hw_config
& SHARED_HW_CFG_LED_MODE_MASK
) >>
1139 SHARED_HW_CFG_LED_MODE_SHIFT
));
1140 NIG_WR(NIG_REG_LED_CONTROL_OVERRIDE_TRAFFIC_P0
+ port
*4, 0);
1142 /* Set blinking rate to ~15.9Hz */
1143 NIG_WR(NIG_REG_LED_CONTROL_BLINK_RATE_P0
+ port
*4,
1144 LED_BLINK_RATE_VAL
);
1145 NIG_WR(NIG_REG_LED_CONTROL_BLINK_RATE_ENA_P0
+ port
*4, 1);
1147 /* On Ax chip versions for speeds less than 10G
1148 LED scheme is different */
1149 if ((CHIP_REV(bp
) == CHIP_REV_Ax
) && (speed
< SPEED_10000
)) {
1150 NIG_WR(NIG_REG_LED_CONTROL_OVERRIDE_TRAFFIC_P0
+ port
*4, 1);
1151 NIG_WR(NIG_REG_LED_CONTROL_TRAFFIC_P0
+ port
*4, 0);
1152 NIG_WR(NIG_REG_LED_CONTROL_BLINK_TRAFFIC_P0
+ port
*4, 1);
1156 static void bnx2x_leds_unset(struct bnx2x
*bp
)
1158 int port
= bp
->port
;
1160 NIG_WR(NIG_REG_LED_10G_P0
+ port
*4, 0);
1161 NIG_WR(NIG_REG_LED_MODE_P0
+ port
*4, SHARED_HW_CFG_LED_MAC1
);
1164 static u32
bnx2x_bits_en(struct bnx2x
*bp
, u32 reg
, u32 bits
)
1166 u32 val
= REG_RD(bp
, reg
);
1169 REG_WR(bp
, reg
, val
);
1173 static u32
bnx2x_bits_dis(struct bnx2x
*bp
, u32 reg
, u32 bits
)
1175 u32 val
= REG_RD(bp
, reg
);
1178 REG_WR(bp
, reg
, val
);
1182 static int bnx2x_mdio22_write(struct bnx2x
*bp
, u32 reg
, u32 val
)
1186 int port
= bp
->port
;
1187 u32 emac_base
= port
? GRCBASE_EMAC1
: GRCBASE_EMAC0
;
1189 /* DP(NETIF_MSG_HW, "phy_addr 0x%x reg 0x%x val 0x%08x\n",
1190 bp->phy_addr, reg, val); */
1192 if (bp
->phy_flags
& PHY_INT_MODE_AUTO_POLLING_FLAG
) {
1194 tmp
= REG_RD(bp
, emac_base
+ EMAC_REG_EMAC_MDIO_MODE
);
1195 tmp
&= ~EMAC_MDIO_MODE_AUTO_POLL
;
1196 EMAC_WR(EMAC_REG_EMAC_MDIO_MODE
, tmp
);
1197 REG_RD(bp
, emac_base
+ EMAC_REG_EMAC_MDIO_MODE
);
1201 tmp
= ((bp
->phy_addr
<< 21) | (reg
<< 16) |
1202 (val
& EMAC_MDIO_COMM_DATA
) |
1203 EMAC_MDIO_COMM_COMMAND_WRITE_22
|
1204 EMAC_MDIO_COMM_START_BUSY
);
1205 EMAC_WR(EMAC_REG_EMAC_MDIO_COMM
, tmp
);
1207 for (i
= 0; i
< 50; i
++) {
1210 tmp
= REG_RD(bp
, emac_base
+ EMAC_REG_EMAC_MDIO_COMM
);
1211 if (!(tmp
& EMAC_MDIO_COMM_START_BUSY
)) {
1217 if (tmp
& EMAC_MDIO_COMM_START_BUSY
) {
1218 BNX2X_ERR("write phy register failed\n");
1225 if (bp
->phy_flags
& PHY_INT_MODE_AUTO_POLLING_FLAG
) {
1227 tmp
= REG_RD(bp
, emac_base
+ EMAC_REG_EMAC_MDIO_MODE
);
1228 tmp
|= EMAC_MDIO_MODE_AUTO_POLL
;
1229 EMAC_WR(EMAC_REG_EMAC_MDIO_MODE
, tmp
);
1235 static int bnx2x_mdio22_read(struct bnx2x
*bp
, u32 reg
, u32
*ret_val
)
1237 int port
= bp
->port
;
1238 u32 emac_base
= port
? GRCBASE_EMAC1
: GRCBASE_EMAC0
;
1242 if (bp
->phy_flags
& PHY_INT_MODE_AUTO_POLLING_FLAG
) {
1244 val
= REG_RD(bp
, emac_base
+ EMAC_REG_EMAC_MDIO_MODE
);
1245 val
&= ~EMAC_MDIO_MODE_AUTO_POLL
;
1246 EMAC_WR(EMAC_REG_EMAC_MDIO_MODE
, val
);
1247 REG_RD(bp
, emac_base
+ EMAC_REG_EMAC_MDIO_MODE
);
1251 val
= ((bp
->phy_addr
<< 21) | (reg
<< 16) |
1252 EMAC_MDIO_COMM_COMMAND_READ_22
|
1253 EMAC_MDIO_COMM_START_BUSY
);
1254 EMAC_WR(EMAC_REG_EMAC_MDIO_COMM
, val
);
1256 for (i
= 0; i
< 50; i
++) {
1259 val
= REG_RD(bp
, emac_base
+ EMAC_REG_EMAC_MDIO_COMM
);
1260 if (!(val
& EMAC_MDIO_COMM_START_BUSY
)) {
1261 val
&= EMAC_MDIO_COMM_DATA
;
1266 if (val
& EMAC_MDIO_COMM_START_BUSY
) {
1267 BNX2X_ERR("read phy register failed\n");
1276 if (bp
->phy_flags
& PHY_INT_MODE_AUTO_POLLING_FLAG
) {
1278 val
= REG_RD(bp
, emac_base
+ EMAC_REG_EMAC_MDIO_MODE
);
1279 val
|= EMAC_MDIO_MODE_AUTO_POLL
;
1280 EMAC_WR(EMAC_REG_EMAC_MDIO_MODE
, val
);
1283 /* DP(NETIF_MSG_HW, "phy_addr 0x%x reg 0x%x ret_val 0x%08x\n",
1284 bp->phy_addr, reg, *ret_val); */
1289 static int bnx2x_mdio45_write(struct bnx2x
*bp
, u32 reg
, u32 addr
, u32 val
)
1293 int port
= bp
->port
;
1294 u32 emac_base
= port
? GRCBASE_EMAC1
: GRCBASE_EMAC0
;
1296 if (bp
->phy_flags
& PHY_INT_MODE_AUTO_POLLING_FLAG
) {
1298 tmp
= REG_RD(bp
, emac_base
+ EMAC_REG_EMAC_MDIO_MODE
);
1299 tmp
&= ~EMAC_MDIO_MODE_AUTO_POLL
;
1300 EMAC_WR(EMAC_REG_EMAC_MDIO_MODE
, tmp
);
1301 REG_RD(bp
, emac_base
+ EMAC_REG_EMAC_MDIO_MODE
);
1305 /* set clause 45 mode */
1306 tmp
= REG_RD(bp
, emac_base
+ EMAC_REG_EMAC_MDIO_MODE
);
1307 tmp
|= EMAC_MDIO_MODE_CLAUSE_45
;
1308 EMAC_WR(EMAC_REG_EMAC_MDIO_MODE
, tmp
);
1311 tmp
= ((bp
->phy_addr
<< 21) | (reg
<< 16) | addr
|
1312 EMAC_MDIO_COMM_COMMAND_ADDRESS
|
1313 EMAC_MDIO_COMM_START_BUSY
);
1314 EMAC_WR(EMAC_REG_EMAC_MDIO_COMM
, tmp
);
1316 for (i
= 0; i
< 50; i
++) {
1319 tmp
= REG_RD(bp
, emac_base
+ EMAC_REG_EMAC_MDIO_COMM
);
1320 if (!(tmp
& EMAC_MDIO_COMM_START_BUSY
)) {
1326 if (tmp
& EMAC_MDIO_COMM_START_BUSY
) {
1327 BNX2X_ERR("write phy register failed\n");
1332 tmp
= ((bp
->phy_addr
<< 21) | (reg
<< 16) | val
|
1333 EMAC_MDIO_COMM_COMMAND_WRITE_45
|
1334 EMAC_MDIO_COMM_START_BUSY
);
1335 EMAC_WR(EMAC_REG_EMAC_MDIO_COMM
, tmp
);
1337 for (i
= 0; i
< 50; i
++) {
1340 tmp
= REG_RD(bp
, emac_base
+ EMAC_REG_EMAC_MDIO_COMM
);
1341 if (!(tmp
& EMAC_MDIO_COMM_START_BUSY
)) {
1347 if (tmp
& EMAC_MDIO_COMM_START_BUSY
) {
1348 BNX2X_ERR("write phy register failed\n");
1354 /* unset clause 45 mode */
1355 tmp
= REG_RD(bp
, emac_base
+ EMAC_REG_EMAC_MDIO_MODE
);
1356 tmp
&= ~EMAC_MDIO_MODE_CLAUSE_45
;
1357 EMAC_WR(EMAC_REG_EMAC_MDIO_MODE
, tmp
);
1359 if (bp
->phy_flags
& PHY_INT_MODE_AUTO_POLLING_FLAG
) {
1361 tmp
= REG_RD(bp
, emac_base
+ EMAC_REG_EMAC_MDIO_MODE
);
1362 tmp
|= EMAC_MDIO_MODE_AUTO_POLL
;
1363 EMAC_WR(EMAC_REG_EMAC_MDIO_MODE
, tmp
);
1369 static int bnx2x_mdio45_read(struct bnx2x
*bp
, u32 reg
, u32 addr
,
1372 int port
= bp
->port
;
1373 u32 emac_base
= port
? GRCBASE_EMAC1
: GRCBASE_EMAC0
;
1377 if (bp
->phy_flags
& PHY_INT_MODE_AUTO_POLLING_FLAG
) {
1379 val
= REG_RD(bp
, emac_base
+ EMAC_REG_EMAC_MDIO_MODE
);
1380 val
&= ~EMAC_MDIO_MODE_AUTO_POLL
;
1381 EMAC_WR(EMAC_REG_EMAC_MDIO_MODE
, val
);
1382 REG_RD(bp
, emac_base
+ EMAC_REG_EMAC_MDIO_MODE
);
1386 /* set clause 45 mode */
1387 val
= REG_RD(bp
, emac_base
+ EMAC_REG_EMAC_MDIO_MODE
);
1388 val
|= EMAC_MDIO_MODE_CLAUSE_45
;
1389 EMAC_WR(EMAC_REG_EMAC_MDIO_MODE
, val
);
1392 val
= ((bp
->phy_addr
<< 21) | (reg
<< 16) | addr
|
1393 EMAC_MDIO_COMM_COMMAND_ADDRESS
|
1394 EMAC_MDIO_COMM_START_BUSY
);
1395 EMAC_WR(EMAC_REG_EMAC_MDIO_COMM
, val
);
1397 for (i
= 0; i
< 50; i
++) {
1400 val
= REG_RD(bp
, emac_base
+ EMAC_REG_EMAC_MDIO_COMM
);
1401 if (!(val
& EMAC_MDIO_COMM_START_BUSY
)) {
1407 if (val
& EMAC_MDIO_COMM_START_BUSY
) {
1408 BNX2X_ERR("read phy register failed\n");
1414 val
= ((bp
->phy_addr
<< 21) | (reg
<< 16) |
1415 EMAC_MDIO_COMM_COMMAND_READ_45
|
1416 EMAC_MDIO_COMM_START_BUSY
);
1417 EMAC_WR(EMAC_REG_EMAC_MDIO_COMM
, val
);
1419 for (i
= 0; i
< 50; i
++) {
1422 val
= REG_RD(bp
, emac_base
+ EMAC_REG_EMAC_MDIO_COMM
);
1423 if (!(val
& EMAC_MDIO_COMM_START_BUSY
)) {
1424 val
&= EMAC_MDIO_COMM_DATA
;
1429 if (val
& EMAC_MDIO_COMM_START_BUSY
) {
1430 BNX2X_ERR("read phy register failed\n");
1439 /* unset clause 45 mode */
1440 val
= REG_RD(bp
, emac_base
+ EMAC_REG_EMAC_MDIO_MODE
);
1441 val
&= ~EMAC_MDIO_MODE_CLAUSE_45
;
1442 EMAC_WR(EMAC_REG_EMAC_MDIO_MODE
, val
);
1444 if (bp
->phy_flags
& PHY_INT_MODE_AUTO_POLLING_FLAG
) {
1446 val
= REG_RD(bp
, emac_base
+ EMAC_REG_EMAC_MDIO_MODE
);
1447 val
|= EMAC_MDIO_MODE_AUTO_POLL
;
1448 EMAC_WR(EMAC_REG_EMAC_MDIO_MODE
, val
);
1454 static int bnx2x_mdio45_vwrite(struct bnx2x
*bp
, u32 reg
, u32 addr
, u32 val
)
1460 for (i
= 0; i
< 10; i
++) {
1461 bnx2x_mdio45_write(bp
, reg
, addr
, val
);
1463 bnx2x_mdio45_read(bp
, reg
, addr
, &rd_val
);
1464 /* if the read value is not the same as the value we wrote,
1465 we should write it again */
1469 BNX2X_ERR("MDIO write in CL45 failed\n");
1477 static void bnx2x_flow_ctrl_resolve(struct bnx2x
*bp
, u32 gp_status
)
1479 u32 ld_pause
; /* local driver */
1480 u32 lp_pause
; /* link partner */
1485 /* reolve from gp_status in case of AN complete and not sgmii */
1486 if ((bp
->req_autoneg
& AUTONEG_FLOW_CTRL
) &&
1487 (gp_status
& MDIO_AN_CL73_OR_37_COMPLETE
) &&
1488 (!(bp
->phy_flags
& PHY_SGMII_FLAG
)) &&
1489 (XGXS_EXT_PHY_TYPE(bp
) == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT
)) {
1491 MDIO_SET_REG_BANK(bp
, MDIO_REG_BANK_COMBO_IEEE0
);
1492 bnx2x_mdio22_read(bp
, MDIO_COMBO_IEEE0_AUTO_NEG_ADV
,
1494 bnx2x_mdio22_read(bp
,
1495 MDIO_COMBO_IEEE0_AUTO_NEG_LINK_PARTNER_ABILITY1
,
1497 pause_result
= (ld_pause
&
1498 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK
)>>5;
1499 pause_result
|= (lp_pause
&
1500 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK
)>>7;
1501 DP(NETIF_MSG_LINK
, "pause_result 0x%x\n", pause_result
);
1503 switch (pause_result
) { /* ASYM P ASYM P */
1504 case 0xb: /* 1 0 1 1 */
1505 bp
->flow_ctrl
= FLOW_CTRL_TX
;
1508 case 0xe: /* 1 1 1 0 */
1509 bp
->flow_ctrl
= FLOW_CTRL_RX
;
1512 case 0x5: /* 0 1 0 1 */
1513 case 0x7: /* 0 1 1 1 */
1514 case 0xd: /* 1 1 0 1 */
1515 case 0xf: /* 1 1 1 1 */
1516 bp
->flow_ctrl
= FLOW_CTRL_BOTH
;
1523 } else { /* forced mode */
1524 switch (bp
->req_flow_ctrl
) {
1525 case FLOW_CTRL_AUTO
:
1526 if (bp
->dev
->mtu
<= 4500)
1527 bp
->flow_ctrl
= FLOW_CTRL_BOTH
;
1529 bp
->flow_ctrl
= FLOW_CTRL_TX
;
1534 case FLOW_CTRL_BOTH
:
1535 bp
->flow_ctrl
= bp
->req_flow_ctrl
;
1538 case FLOW_CTRL_NONE
:
1543 DP(NETIF_MSG_LINK
, "flow_ctrl 0x%x\n", bp
->flow_ctrl
);
1546 static void bnx2x_link_settings_status(struct bnx2x
*bp
, u32 gp_status
)
1548 bp
->link_status
= 0;
1550 if (gp_status
& MDIO_GP_STATUS_TOP_AN_STATUS1_LINK_STATUS
) {
1551 DP(NETIF_MSG_LINK
, "link up\n");
1554 bp
->link_status
|= LINK_STATUS_LINK_UP
;
1556 if (gp_status
& MDIO_GP_STATUS_TOP_AN_STATUS1_DUPLEX_STATUS
)
1557 bp
->duplex
= DUPLEX_FULL
;
1559 bp
->duplex
= DUPLEX_HALF
;
1561 bnx2x_flow_ctrl_resolve(bp
, gp_status
);
1563 switch (gp_status
& GP_STATUS_SPEED_MASK
) {
1565 bp
->line_speed
= SPEED_10
;
1566 if (bp
->duplex
== DUPLEX_FULL
)
1567 bp
->link_status
|= LINK_10TFD
;
1569 bp
->link_status
|= LINK_10THD
;
1572 case GP_STATUS_100M
:
1573 bp
->line_speed
= SPEED_100
;
1574 if (bp
->duplex
== DUPLEX_FULL
)
1575 bp
->link_status
|= LINK_100TXFD
;
1577 bp
->link_status
|= LINK_100TXHD
;
1581 case GP_STATUS_1G_KX
:
1582 bp
->line_speed
= SPEED_1000
;
1583 if (bp
->duplex
== DUPLEX_FULL
)
1584 bp
->link_status
|= LINK_1000TFD
;
1586 bp
->link_status
|= LINK_1000THD
;
1589 case GP_STATUS_2_5G
:
1590 bp
->line_speed
= SPEED_2500
;
1591 if (bp
->duplex
== DUPLEX_FULL
)
1592 bp
->link_status
|= LINK_2500TFD
;
1594 bp
->link_status
|= LINK_2500THD
;
1599 BNX2X_ERR("link speed unsupported gp_status 0x%x\n",
1603 case GP_STATUS_10G_KX4
:
1604 case GP_STATUS_10G_HIG
:
1605 case GP_STATUS_10G_CX4
:
1606 bp
->line_speed
= SPEED_10000
;
1607 bp
->link_status
|= LINK_10GTFD
;
1610 case GP_STATUS_12G_HIG
:
1611 bp
->line_speed
= SPEED_12000
;
1612 bp
->link_status
|= LINK_12GTFD
;
1615 case GP_STATUS_12_5G
:
1616 bp
->line_speed
= SPEED_12500
;
1617 bp
->link_status
|= LINK_12_5GTFD
;
1621 bp
->line_speed
= SPEED_13000
;
1622 bp
->link_status
|= LINK_13GTFD
;
1626 bp
->line_speed
= SPEED_15000
;
1627 bp
->link_status
|= LINK_15GTFD
;
1631 bp
->line_speed
= SPEED_16000
;
1632 bp
->link_status
|= LINK_16GTFD
;
1636 BNX2X_ERR("link speed unsupported gp_status 0x%x\n",
1641 bp
->link_status
|= LINK_STATUS_SERDES_LINK
;
1643 if (bp
->req_autoneg
& AUTONEG_SPEED
) {
1644 bp
->link_status
|= LINK_STATUS_AUTO_NEGOTIATE_ENABLED
;
1646 if (gp_status
& MDIO_AN_CL73_OR_37_COMPLETE
)
1648 LINK_STATUS_AUTO_NEGOTIATE_COMPLETE
;
1650 if (bp
->autoneg
& AUTONEG_PARALLEL
)
1652 LINK_STATUS_PARALLEL_DETECTION_USED
;
1655 if (bp
->flow_ctrl
& FLOW_CTRL_TX
)
1656 bp
->link_status
|= LINK_STATUS_TX_FLOW_CONTROL_ENABLED
;
1658 if (bp
->flow_ctrl
& FLOW_CTRL_RX
)
1659 bp
->link_status
|= LINK_STATUS_RX_FLOW_CONTROL_ENABLED
;
1661 } else { /* link_down */
1662 DP(NETIF_MSG_LINK
, "link down\n");
1667 bp
->duplex
= DUPLEX_FULL
;
1671 DP(NETIF_MSG_LINK
, "gp_status 0x%x link_up %d\n"
1672 DP_LEVEL
" line_speed %d duplex %d flow_ctrl 0x%x"
1673 " link_status 0x%x\n",
1674 gp_status
, bp
->link_up
, bp
->line_speed
, bp
->duplex
, bp
->flow_ctrl
,
1678 static void bnx2x_link_int_ack(struct bnx2x
*bp
, int is_10g
)
1680 int port
= bp
->port
;
1682 /* first reset all status
1683 * we asume only one line will be change at a time */
1684 bnx2x_bits_dis(bp
, NIG_REG_STATUS_INTERRUPT_PORT0
+ port
*4,
1685 (NIG_XGXS0_LINK_STATUS
|
1686 NIG_SERDES0_LINK_STATUS
|
1687 NIG_STATUS_INTERRUPT_XGXS0_LINK10G
));
1690 /* Disable the 10G link interrupt
1691 * by writing 1 to the status register
1693 DP(NETIF_MSG_LINK
, "10G XGXS link up\n");
1695 NIG_REG_STATUS_INTERRUPT_PORT0
+ port
*4,
1696 NIG_STATUS_INTERRUPT_XGXS0_LINK10G
);
1698 } else if (bp
->phy_flags
& PHY_XGXS_FLAG
) {
1699 /* Disable the link interrupt
1700 * by writing 1 to the relevant lane
1701 * in the status register
1703 DP(NETIF_MSG_LINK
, "1G XGXS link up\n");
1705 NIG_REG_STATUS_INTERRUPT_PORT0
+ port
*4,
1706 ((1 << bp
->ser_lane
) <<
1707 NIG_XGXS0_LINK_STATUS_SIZE
));
1709 } else { /* SerDes */
1710 DP(NETIF_MSG_LINK
, "SerDes link up\n");
1711 /* Disable the link interrupt
1712 * by writing 1 to the status register
1715 NIG_REG_STATUS_INTERRUPT_PORT0
+ port
*4,
1716 NIG_SERDES0_LINK_STATUS
);
1719 } else { /* link_down */
1723 static int bnx2x_ext_phy_is_link_up(struct bnx2x
*bp
)
1729 u32 rx_sd
, pcs_status
;
1731 if (bp
->phy_flags
& PHY_XGXS_FLAG
) {
1732 local_phy
= bp
->phy_addr
;
1733 ext_phy_addr
= ((bp
->ext_phy_config
&
1734 PORT_HW_CFG_XGXS_EXT_PHY_ADDR_MASK
) >>
1735 PORT_HW_CFG_XGXS_EXT_PHY_ADDR_SHIFT
);
1736 bp
->phy_addr
= (u8
)ext_phy_addr
;
1738 ext_phy_type
= XGXS_EXT_PHY_TYPE(bp
);
1739 switch (ext_phy_type
) {
1740 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT
:
1741 DP(NETIF_MSG_LINK
, "XGXS Direct\n");
1745 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8705
:
1746 DP(NETIF_MSG_LINK
, "XGXS 8705\n");
1747 bnx2x_mdio45_read(bp
, EXT_PHY_OPT_WIS_DEVAD
,
1748 EXT_PHY_OPT_LASI_STATUS
, &val
);
1749 DP(NETIF_MSG_LINK
, "8705 LASI status is %d\n", val
);
1751 bnx2x_mdio45_read(bp
, EXT_PHY_OPT_WIS_DEVAD
,
1752 EXT_PHY_OPT_LASI_STATUS
, &val
);
1753 DP(NETIF_MSG_LINK
, "8705 LASI status is %d\n", val
);
1755 bnx2x_mdio45_read(bp
, EXT_PHY_OPT_PMA_PMD_DEVAD
,
1756 EXT_PHY_OPT_PMD_RX_SD
, &rx_sd
);
1757 val
= (rx_sd
& 0x1);
1760 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8706
:
1761 DP(NETIF_MSG_LINK
, "XGXS 8706\n");
1762 bnx2x_mdio45_read(bp
, EXT_PHY_OPT_PMA_PMD_DEVAD
,
1763 EXT_PHY_OPT_LASI_STATUS
, &val
);
1764 DP(NETIF_MSG_LINK
, "8706 LASI status is %d\n", val
);
1766 bnx2x_mdio45_read(bp
, EXT_PHY_OPT_PMA_PMD_DEVAD
,
1767 EXT_PHY_OPT_LASI_STATUS
, &val
);
1768 DP(NETIF_MSG_LINK
, "8706 LASI status is %d\n", val
);
1770 bnx2x_mdio45_read(bp
, EXT_PHY_OPT_PMA_PMD_DEVAD
,
1771 EXT_PHY_OPT_PMD_RX_SD
, &rx_sd
);
1772 bnx2x_mdio45_read(bp
, EXT_PHY_OPT_PCS_DEVAD
,
1773 EXT_PHY_OPT_PCS_STATUS
, &pcs_status
);
1774 DP(NETIF_MSG_LINK
, "8706 rx_sd 0x%x"
1775 " pcs_status 0x%x\n", rx_sd
, pcs_status
);
1776 /* link is up if both bit 0 of pmd_rx and
1777 * bit 0 of pcs_status are set
1779 val
= (rx_sd
& pcs_status
);
1783 DP(NETIF_MSG_LINK
, "BAD XGXS ext_phy_config 0x%x\n",
1784 bp
->ext_phy_config
);
1788 bp
->phy_addr
= local_phy
;
1790 } else { /* SerDes */
1791 ext_phy_type
= SERDES_EXT_PHY_TYPE(bp
);
1792 switch (ext_phy_type
) {
1793 case PORT_HW_CFG_SERDES_EXT_PHY_TYPE_DIRECT
:
1794 DP(NETIF_MSG_LINK
, "SerDes Direct\n");
1798 case PORT_HW_CFG_SERDES_EXT_PHY_TYPE_BCM5482
:
1799 DP(NETIF_MSG_LINK
, "SerDes 5482\n");
1804 DP(NETIF_MSG_LINK
, "BAD SerDes ext_phy_config 0x%x\n",
1805 bp
->ext_phy_config
);
1814 static void bnx2x_bmac_enable(struct bnx2x
*bp
, int is_lb
)
1816 int port
= bp
->port
;
1817 u32 bmac_addr
= port
? NIG_REG_INGRESS_BMAC1_MEM
:
1818 NIG_REG_INGRESS_BMAC0_MEM
;
1822 DP(NETIF_MSG_LINK
, "enableing BigMAC\n");
1823 /* reset and unreset the BigMac */
1824 REG_WR(bp
, GRCBASE_MISC
+ MISC_REGISTERS_RESET_REG_2_CLEAR
,
1825 (MISC_REGISTERS_RESET_REG_2_RST_BMAC0
<< port
));
1827 REG_WR(bp
, GRCBASE_MISC
+ MISC_REGISTERS_RESET_REG_2_SET
,
1828 (MISC_REGISTERS_RESET_REG_2_RST_BMAC0
<< port
));
1830 /* enable access for bmac registers */
1831 NIG_WR(NIG_REG_BMAC0_REGS_OUT_EN
+ port
*4, 0x1);
1836 REG_WR_DMAE(bp
, bmac_addr
+ BIGMAC_REGISTER_BMAC_XGXS_CONTROL
,
1840 wb_write
[0] = ((bp
->dev
->dev_addr
[2] << 24) |
1841 (bp
->dev
->dev_addr
[3] << 16) |
1842 (bp
->dev
->dev_addr
[4] << 8) |
1843 bp
->dev
->dev_addr
[5]);
1844 wb_write
[1] = ((bp
->dev
->dev_addr
[0] << 8) |
1845 bp
->dev
->dev_addr
[1]);
1846 REG_WR_DMAE(bp
, bmac_addr
+ BIGMAC_REGISTER_TX_SOURCE_ADDR
,
1851 if (bp
->flow_ctrl
& FLOW_CTRL_TX
)
1855 REG_WR_DMAE(bp
, bmac_addr
+ BIGMAC_REGISTER_TX_CONTROL
, wb_write
, 2);
1858 wb_write
[0] = ETH_MAX_JUMBO_PACKET_SIZE
+ ETH_OVREHEAD
; /* -CRC */
1860 REG_WR_DMAE(bp
, bmac_addr
+ BIGMAC_REGISTER_TX_MAX_SIZE
, wb_write
, 2);
1866 DP(NETIF_MSG_LINK
, "enable bmac loopback\n");
1870 REG_WR_DMAE(bp
, bmac_addr
+ BIGMAC_REGISTER_BMAC_CONTROL
,
1873 /* rx control set to don't strip crc */
1875 if (bp
->flow_ctrl
& FLOW_CTRL_RX
)
1879 REG_WR_DMAE(bp
, bmac_addr
+ BIGMAC_REGISTER_RX_CONTROL
, wb_write
, 2);
1882 wb_write
[0] = ETH_MAX_JUMBO_PACKET_SIZE
+ ETH_OVREHEAD
;
1884 REG_WR_DMAE(bp
, bmac_addr
+ BIGMAC_REGISTER_RX_MAX_SIZE
, wb_write
, 2);
1886 /* set cnt max size */
1887 wb_write
[0] = ETH_MAX_JUMBO_PACKET_SIZE
+ ETH_OVREHEAD
; /* -VLAN */
1889 REG_WR_DMAE(bp
, bmac_addr
+ BIGMAC_REGISTER_CNT_MAX_SIZE
,
1892 /* configure safc */
1893 wb_write
[0] = 0x1000200;
1895 REG_WR_DMAE(bp
, bmac_addr
+ BIGMAC_REGISTER_RX_LLFC_MSG_FLDS
,
1898 /* fix for emulation */
1899 if (CHIP_REV(bp
) == CHIP_REV_EMUL
) {
1900 wb_write
[0] = 0xf000;
1903 bmac_addr
+ BIGMAC_REGISTER_TX_PAUSE_THRESHOLD
,
1907 /* reset old bmac stats */
1908 memset(&bp
->old_bmac
, 0, sizeof(struct bmac_stats
));
1910 NIG_WR(NIG_REG_XCM0_OUT_EN
+ port
*4, 0x0);
1913 NIG_WR(NIG_REG_XGXS_SERDES0_MODE_SEL
+ port
*4, 0x1);
1914 NIG_WR(NIG_REG_XGXS_LANE_SEL_P0
+ port
*4, 0x0);
1916 /* disable the NIG in/out to the emac */
1917 NIG_WR(NIG_REG_EMAC0_IN_EN
+ port
*4, 0x0);
1918 NIG_WR(NIG_REG_EMAC0_PAUSE_OUT_EN
+ port
*4, 0x0);
1919 NIG_WR(NIG_REG_EGRESS_EMAC0_OUT_EN
+ port
*4, 0x0);
1921 /* enable the NIG in/out to the bmac */
1922 NIG_WR(NIG_REG_EGRESS_EMAC0_PORT
+ port
*4, 0x0);
1924 NIG_WR(NIG_REG_BMAC0_IN_EN
+ port
*4, 0x1);
1926 if (bp
->flow_ctrl
& FLOW_CTRL_TX
)
1928 NIG_WR(NIG_REG_BMAC0_PAUSE_OUT_EN
+ port
*4, val
);
1929 NIG_WR(NIG_REG_BMAC0_OUT_EN
+ port
*4, 0x1);
1931 bp
->phy_flags
|= PHY_BMAC_FLAG
;
1933 bp
->stats_state
= STATS_STATE_ENABLE
;
1936 static void bnx2x_emac_enable(struct bnx2x
*bp
)
1938 int port
= bp
->port
;
1939 u32 emac_base
= port
? GRCBASE_EMAC1
: GRCBASE_EMAC0
;
1943 DP(NETIF_MSG_LINK
, "enableing EMAC\n");
1944 /* reset and unreset the emac core */
1945 REG_WR(bp
, GRCBASE_MISC
+ MISC_REGISTERS_RESET_REG_2_CLEAR
,
1946 (MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE
<< port
));
1948 REG_WR(bp
, GRCBASE_MISC
+ MISC_REGISTERS_RESET_REG_2_SET
,
1949 (MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE
<< port
));
1951 /* enable emac and not bmac */
1952 NIG_WR(NIG_REG_EGRESS_EMAC0_PORT
+ port
*4, 1);
1955 if (CHIP_REV(bp
) == CHIP_REV_EMUL
) {
1956 /* Use lane 1 (of lanes 0-3) */
1957 NIG_WR(NIG_REG_XGXS_LANE_SEL_P0
+ port
*4, 1);
1958 NIG_WR(NIG_REG_XGXS_SERDES0_MODE_SEL
+ port
*4, 1);
1961 else if (CHIP_REV(bp
) == CHIP_REV_FPGA
) {
1962 /* Use lane 1 (of lanes 0-3) */
1963 NIG_WR(NIG_REG_XGXS_LANE_SEL_P0
+ port
*4, 1);
1964 NIG_WR(NIG_REG_XGXS_SERDES0_MODE_SEL
+ port
*4, 0);
1968 if (bp
->phy_flags
& PHY_XGXS_FLAG
) {
1969 DP(NETIF_MSG_LINK
, "XGXS\n");
1970 /* select the master lanes (out of 0-3) */
1971 NIG_WR(NIG_REG_XGXS_LANE_SEL_P0
+ port
*4,
1974 NIG_WR(NIG_REG_XGXS_SERDES0_MODE_SEL
+ port
*4, 1);
1976 } else { /* SerDes */
1977 DP(NETIF_MSG_LINK
, "SerDes\n");
1979 NIG_WR(NIG_REG_XGXS_SERDES0_MODE_SEL
+ port
*4, 0);
1984 NIG_WR(NIG_REG_NIG_EMAC0_EN
+ port
*4, 1);
1986 /* init emac - use read-modify-write */
1987 /* self clear reset */
1988 val
= REG_RD(bp
, emac_base
+ EMAC_REG_EMAC_MODE
);
1989 EMAC_WR(EMAC_REG_EMAC_MODE
, (val
| EMAC_MODE_RESET
));
1992 while (val
& EMAC_MODE_RESET
) {
1993 val
= REG_RD(bp
, emac_base
+ EMAC_REG_EMAC_MODE
);
1994 DP(NETIF_MSG_LINK
, "EMAC reset reg is %u\n", val
);
1996 BNX2X_ERR("EMAC timeout!\n");
2003 EMAC_WR(EMAC_REG_EMAC_TX_MODE
, EMAC_TX_MODE_RESET
);
2006 while (val
& EMAC_TX_MODE_RESET
) {
2007 val
= REG_RD(bp
, emac_base
+ EMAC_REG_EMAC_TX_MODE
);
2008 DP(NETIF_MSG_LINK
, "EMAC reset reg is %u\n", val
);
2010 BNX2X_ERR("EMAC timeout!\n");
2016 if (CHIP_REV_IS_SLOW(bp
)) {
2017 /* config GMII mode */
2018 val
= REG_RD(bp
, emac_base
+ EMAC_REG_EMAC_MODE
);
2019 EMAC_WR(EMAC_REG_EMAC_MODE
, (val
| EMAC_MODE_PORT_GMII
));
2022 /* pause enable/disable */
2023 bnx2x_bits_dis(bp
, emac_base
+ EMAC_REG_EMAC_RX_MODE
,
2024 EMAC_RX_MODE_FLOW_EN
);
2025 if (bp
->flow_ctrl
& FLOW_CTRL_RX
)
2026 bnx2x_bits_en(bp
, emac_base
+ EMAC_REG_EMAC_RX_MODE
,
2027 EMAC_RX_MODE_FLOW_EN
);
2029 bnx2x_bits_dis(bp
, emac_base
+ EMAC_REG_EMAC_TX_MODE
,
2030 EMAC_TX_MODE_EXT_PAUSE_EN
);
2031 if (bp
->flow_ctrl
& FLOW_CTRL_TX
)
2032 bnx2x_bits_en(bp
, emac_base
+ EMAC_REG_EMAC_TX_MODE
,
2033 EMAC_TX_MODE_EXT_PAUSE_EN
);
2036 /* KEEP_VLAN_TAG, promiscous */
2037 val
= REG_RD(bp
, emac_base
+ EMAC_REG_EMAC_RX_MODE
);
2038 val
|= EMAC_RX_MODE_KEEP_VLAN_TAG
| EMAC_RX_MODE_PROMISCUOUS
;
2039 EMAC_WR(EMAC_REG_EMAC_RX_MODE
, val
);
2041 /* identify magic packets */
2042 val
= REG_RD(bp
, emac_base
+ EMAC_REG_EMAC_MODE
);
2043 EMAC_WR(EMAC_REG_EMAC_MODE
, (val
| EMAC_MODE_MPKT
));
2045 /* enable emac for jumbo packets */
2046 EMAC_WR(EMAC_REG_EMAC_RX_MTU_SIZE
,
2047 (EMAC_RX_MTU_SIZE_JUMBO_ENA
|
2048 (ETH_MAX_JUMBO_PACKET_SIZE
+ ETH_OVREHEAD
))); /* -VLAN */
2051 NIG_WR(NIG_REG_NIG_INGRESS_EMAC0_NO_CRC
+ port
*4, 0x1);
2053 val
= ((bp
->dev
->dev_addr
[0] << 8) |
2054 bp
->dev
->dev_addr
[1]);
2055 EMAC_WR(EMAC_REG_EMAC_MAC_MATCH
, val
);
2057 val
= ((bp
->dev
->dev_addr
[2] << 24) |
2058 (bp
->dev
->dev_addr
[3] << 16) |
2059 (bp
->dev
->dev_addr
[4] << 8) |
2060 bp
->dev
->dev_addr
[5]);
2061 EMAC_WR(EMAC_REG_EMAC_MAC_MATCH
+ 4, val
);
2063 /* disable the NIG in/out to the bmac */
2064 NIG_WR(NIG_REG_BMAC0_IN_EN
+ port
*4, 0x0);
2065 NIG_WR(NIG_REG_BMAC0_PAUSE_OUT_EN
+ port
*4, 0x0);
2066 NIG_WR(NIG_REG_BMAC0_OUT_EN
+ port
*4, 0x0);
2068 /* enable the NIG in/out to the emac */
2069 NIG_WR(NIG_REG_EMAC0_IN_EN
+ port
*4, 0x1);
2071 if (bp
->flow_ctrl
& FLOW_CTRL_TX
)
2073 NIG_WR(NIG_REG_EMAC0_PAUSE_OUT_EN
+ port
*4, val
);
2074 NIG_WR(NIG_REG_EGRESS_EMAC0_OUT_EN
+ port
*4, 0x1);
2076 if (CHIP_REV(bp
) == CHIP_REV_FPGA
) {
2077 /* take the BigMac out of reset */
2078 REG_WR(bp
, GRCBASE_MISC
+ MISC_REGISTERS_RESET_REG_2_SET
,
2079 (MISC_REGISTERS_RESET_REG_2_RST_BMAC0
<< port
));
2081 /* enable access for bmac registers */
2082 NIG_WR(NIG_REG_BMAC0_REGS_OUT_EN
+ port
*4, 0x1);
2085 bp
->phy_flags
|= PHY_EMAC_FLAG
;
2087 bp
->stats_state
= STATS_STATE_ENABLE
;
2090 static void bnx2x_emac_program(struct bnx2x
*bp
)
2093 int port
= bp
->port
;
2095 DP(NETIF_MSG_LINK
, "setting link speed & duplex\n");
2096 bnx2x_bits_dis(bp
, GRCBASE_EMAC0
+ port
*0x400 + EMAC_REG_EMAC_MODE
,
2097 (EMAC_MODE_25G_MODE
|
2098 EMAC_MODE_PORT_MII_10M
|
2099 EMAC_MODE_HALF_DUPLEX
));
2100 switch (bp
->line_speed
) {
2102 mode
|= EMAC_MODE_PORT_MII_10M
;
2106 mode
|= EMAC_MODE_PORT_MII
;
2110 mode
|= EMAC_MODE_PORT_GMII
;
2114 mode
|= (EMAC_MODE_25G_MODE
| EMAC_MODE_PORT_GMII
);
2118 /* 10G not valid for EMAC */
2119 BNX2X_ERR("Invalid line_speed 0x%x\n", bp
->line_speed
);
2123 if (bp
->duplex
== DUPLEX_HALF
)
2124 mode
|= EMAC_MODE_HALF_DUPLEX
;
2125 bnx2x_bits_en(bp
, GRCBASE_EMAC0
+ port
*0x400 + EMAC_REG_EMAC_MODE
,
2128 bnx2x_leds_set(bp
, bp
->line_speed
);
2131 static void bnx2x_set_sgmii_tx_driver(struct bnx2x
*bp
)
2137 MDIO_SET_REG_BANK(bp
, MDIO_REG_BANK_OVER_1G
);
2138 bnx2x_mdio22_read(bp
, MDIO_OVER_1G_LP_UP2
, &lp_up2
);
2140 MDIO_SET_REG_BANK(bp
, MDIO_REG_BANK_TX0
);
2141 bnx2x_mdio22_read(bp
, MDIO_TX0_TX_DRIVER
, &tx_driver
);
2143 /* bits [10:7] at lp_up2, positioned at [15:12] */
2144 lp_up2
= (((lp_up2
& MDIO_OVER_1G_LP_UP2_PREEMPHASIS_MASK
) >>
2145 MDIO_OVER_1G_LP_UP2_PREEMPHASIS_SHIFT
) <<
2146 MDIO_TX0_TX_DRIVER_PREEMPHASIS_SHIFT
);
2148 if ((lp_up2
!= 0) &&
2149 (lp_up2
!= (tx_driver
& MDIO_TX0_TX_DRIVER_PREEMPHASIS_MASK
))) {
2150 /* replace tx_driver bits [15:12] */
2151 tx_driver
&= ~MDIO_TX0_TX_DRIVER_PREEMPHASIS_MASK
;
2152 tx_driver
|= lp_up2
;
2153 bnx2x_mdio22_write(bp
, MDIO_TX0_TX_DRIVER
, tx_driver
);
2157 static void bnx2x_pbf_update(struct bnx2x
*bp
)
2159 int port
= bp
->port
;
2166 REG_WR(bp
, PBF_REG_DISABLE_NEW_TASK_PROC_P0
+ port
*4, 0x1);
2168 /* wait for init credit */
2169 init_crd
= REG_RD(bp
, PBF_REG_P0_INIT_CRD
+ port
*4);
2170 crd
= REG_RD(bp
, PBF_REG_P0_CREDIT
+ port
*8);
2171 DP(NETIF_MSG_LINK
, "init_crd 0x%x crd 0x%x\n", init_crd
, crd
);
2173 while ((init_crd
!= crd
) && count
) {
2176 crd
= REG_RD(bp
, PBF_REG_P0_CREDIT
+ port
*8);
2179 crd
= REG_RD(bp
, PBF_REG_P0_CREDIT
+ port
*8);
2180 if (init_crd
!= crd
)
2181 BNX2X_ERR("BUG! init_crd 0x%x != crd 0x%x\n", init_crd
, crd
);
2183 if (bp
->flow_ctrl
& FLOW_CTRL_RX
)
2185 REG_WR(bp
, PBF_REG_P0_PAUSE_ENABLE
+ port
*4, pause
);
2187 /* update threshold */
2188 REG_WR(bp
, PBF_REG_P0_ARB_THRSH
+ port
*4, 0);
2189 /* update init credit */
2190 init_crd
= 778; /* (800-18-4) */
2193 u32 thresh
= (ETH_MAX_JUMBO_PACKET_SIZE
+ ETH_OVREHEAD
)/16;
2195 /* update threshold */
2196 REG_WR(bp
, PBF_REG_P0_ARB_THRSH
+ port
*4, thresh
);
2197 /* update init credit */
2198 switch (bp
->line_speed
) {
2202 init_crd
= thresh
+ 55 - 22;
2206 init_crd
= thresh
+ 138 - 22;
2210 init_crd
= thresh
+ 553 - 22;
2214 BNX2X_ERR("Invalid line_speed 0x%x\n",
2219 REG_WR(bp
, PBF_REG_P0_INIT_CRD
+ port
*4, init_crd
);
2220 DP(NETIF_MSG_LINK
, "PBF updated to speed %d credit %d\n",
2221 bp
->line_speed
, init_crd
);
2223 /* probe the credit changes */
2224 REG_WR(bp
, PBF_REG_INIT_P0
+ port
*4, 0x1);
2226 REG_WR(bp
, PBF_REG_INIT_P0
+ port
*4, 0x0);
2229 REG_WR(bp
, PBF_REG_DISABLE_NEW_TASK_PROC_P0
+ port
*4, 0x0);
2232 static void bnx2x_update_mng(struct bnx2x
*bp
)
2235 SHMEM_WR(bp
, drv_fw_mb
[bp
->port
].link_status
,
2239 static void bnx2x_link_report(struct bnx2x
*bp
)
2242 netif_carrier_on(bp
->dev
);
2243 printk(KERN_INFO PFX
"%s NIC Link is Up, ", bp
->dev
->name
);
2245 printk("%d Mbps ", bp
->line_speed
);
2247 if (bp
->duplex
== DUPLEX_FULL
)
2248 printk("full duplex");
2250 printk("half duplex");
2252 if (bp
->flow_ctrl
) {
2253 if (bp
->flow_ctrl
& FLOW_CTRL_RX
) {
2254 printk(", receive ");
2255 if (bp
->flow_ctrl
& FLOW_CTRL_TX
)
2256 printk("& transmit ");
2258 printk(", transmit ");
2260 printk("flow control ON");
2264 } else { /* link_down */
2265 netif_carrier_off(bp
->dev
);
2266 printk(KERN_INFO PFX
"%s NIC Link is Down\n", bp
->dev
->name
);
2270 static void bnx2x_link_up(struct bnx2x
*bp
)
2272 int port
= bp
->port
;
2275 bnx2x_pbf_update(bp
);
2278 NIG_WR(NIG_REG_EGRESS_DRAIN0_MODE
+ port
*4, 0);
2280 /* update shared memory */
2281 bnx2x_update_mng(bp
);
2283 /* indicate link up */
2284 bnx2x_link_report(bp
);
2287 static void bnx2x_link_down(struct bnx2x
*bp
)
2289 int port
= bp
->port
;
2292 if (bp
->stats_state
!= STATS_STATE_DISABLE
) {
2293 bp
->stats_state
= STATS_STATE_STOP
;
2294 DP(BNX2X_MSG_STATS
, "stats_state - STOP\n");
2297 /* indicate link down */
2298 bp
->phy_flags
&= ~(PHY_BMAC_FLAG
| PHY_EMAC_FLAG
);
2301 REG_WR(bp
, GRCBASE_MISC
+ MISC_REGISTERS_RESET_REG_2_CLEAR
,
2302 (MISC_REGISTERS_RESET_REG_2_RST_BMAC0
<< port
));
2304 /* ignore drain flag interrupt */
2305 /* activate nig drain */
2306 NIG_WR(NIG_REG_EGRESS_DRAIN0_MODE
+ port
*4, 1);
2308 /* update shared memory */
2309 bnx2x_update_mng(bp
);
2311 /* indicate link down */
2312 bnx2x_link_report(bp
);
2315 static void bnx2x_init_mac_stats(struct bnx2x
*bp
);
2317 /* This function is called upon link interrupt */
2318 static void bnx2x_link_update(struct bnx2x
*bp
)
2321 int port
= bp
->port
;
2325 DP(NETIF_MSG_LINK
, "port %x, is xgxs %x, stat_mask 0x%x,"
2326 " int_mask 0x%x, saved_mask 0x%x, MI_INT %x, SERDES_LINK %x,"
2327 " 10G %x, XGXS_LINK %x\n", port
, (bp
->phy_flags
& PHY_XGXS_FLAG
),
2328 REG_RD(bp
, NIG_REG_STATUS_INTERRUPT_PORT0
+ port
*4),
2329 REG_RD(bp
, NIG_REG_MASK_INTERRUPT_PORT0
+ port
*4), bp
->nig_mask
,
2330 REG_RD(bp
, NIG_REG_EMAC0_STATUS_MISC_MI_INT
+ port
*0x18),
2331 REG_RD(bp
, NIG_REG_SERDES0_STATUS_LINK_STATUS
+ port
*0x3c),
2332 REG_RD(bp
, NIG_REG_XGXS0_STATUS_LINK10G
+ port
*0x68),
2333 REG_RD(bp
, NIG_REG_XGXS0_STATUS_LINK_STATUS
+ port
*0x68)
2337 MDIO_SET_REG_BANK(bp
, MDIO_REG_BANK_GP_STATUS
);
2338 /* avoid fast toggling */
2339 for (i
= 0 ; i
< 10 ; i
++) {
2341 bnx2x_mdio22_read(bp
, MDIO_GP_STATUS_TOP_AN_STATUS1
,
2345 bnx2x_link_settings_status(bp
, gp_status
);
2347 /* anything 10 and over uses the bmac */
2348 link_10g
= ((bp
->line_speed
>= SPEED_10000
) &&
2349 (bp
->line_speed
<= SPEED_16000
));
2351 bnx2x_link_int_ack(bp
, link_10g
);
2353 /* link is up only if both local phy and external phy are up */
2354 if (bp
->link_up
&& bnx2x_ext_phy_is_link_up(bp
)) {
2356 bnx2x_bmac_enable(bp
, 0);
2357 bnx2x_leds_set(bp
, SPEED_10000
);
2360 bnx2x_emac_enable(bp
);
2361 bnx2x_emac_program(bp
);
2364 if (gp_status
& MDIO_AN_CL73_OR_37_COMPLETE
) {
2365 if (!(bp
->phy_flags
& PHY_SGMII_FLAG
))
2366 bnx2x_set_sgmii_tx_driver(bp
);
2371 } else { /* link down */
2372 bnx2x_leds_unset(bp
);
2373 bnx2x_link_down(bp
);
2376 bnx2x_init_mac_stats(bp
);
2380 * Init service functions
2383 static void bnx2x_set_aer_mmd(struct bnx2x
*bp
)
2385 u16 offset
= (bp
->phy_flags
& PHY_XGXS_FLAG
) ?
2386 (bp
->phy_addr
+ bp
->ser_lane
) : 0;
2388 MDIO_SET_REG_BANK(bp
, MDIO_REG_BANK_AER_BLOCK
);
2389 bnx2x_mdio22_write(bp
, MDIO_AER_BLOCK_AER_REG
, 0x3800 + offset
);
2392 static void bnx2x_set_master_ln(struct bnx2x
*bp
)
2396 /* set the master_ln for AN */
2397 MDIO_SET_REG_BANK(bp
, MDIO_REG_BANK_XGXS_BLOCK2
);
2398 bnx2x_mdio22_read(bp
, MDIO_XGXS_BLOCK2_TEST_MODE_LANE
,
2400 bnx2x_mdio22_write(bp
, MDIO_XGXS_BLOCK2_TEST_MODE_LANE
,
2401 (new_master_ln
| bp
->ser_lane
));
2404 static void bnx2x_reset_unicore(struct bnx2x
*bp
)
2409 MDIO_SET_REG_BANK(bp
, MDIO_REG_BANK_COMBO_IEEE0
);
2410 bnx2x_mdio22_read(bp
, MDIO_COMBO_IEEE0_MII_CONTROL
, &mii_control
);
2411 /* reset the unicore */
2412 bnx2x_mdio22_write(bp
, MDIO_COMBO_IEEE0_MII_CONTROL
,
2413 (mii_control
| MDIO_COMBO_IEEO_MII_CONTROL_RESET
));
2415 /* wait for the reset to self clear */
2416 for (i
= 0; i
< MDIO_ACCESS_TIMEOUT
; i
++) {
2419 /* the reset erased the previous bank value */
2420 MDIO_SET_REG_BANK(bp
, MDIO_REG_BANK_COMBO_IEEE0
);
2421 bnx2x_mdio22_read(bp
, MDIO_COMBO_IEEE0_MII_CONTROL
,
2424 if (!(mii_control
& MDIO_COMBO_IEEO_MII_CONTROL_RESET
)) {
2430 BNX2X_ERR("BUG! unicore is still in reset!\n");
2433 static void bnx2x_set_swap_lanes(struct bnx2x
*bp
)
2435 /* Each two bits represents a lane number:
2436 No swap is 0123 => 0x1b no need to enable the swap */
2438 MDIO_SET_REG_BANK(bp
, MDIO_REG_BANK_XGXS_BLOCK2
);
2439 if (bp
->rx_lane_swap
!= 0x1b) {
2440 bnx2x_mdio22_write(bp
, MDIO_XGXS_BLOCK2_RX_LN_SWAP
,
2442 MDIO_XGXS_BLOCK2_RX_LN_SWAP_ENABLE
|
2443 MDIO_XGXS_BLOCK2_RX_LN_SWAP_FORCE_ENABLE
));
2445 bnx2x_mdio22_write(bp
, MDIO_XGXS_BLOCK2_RX_LN_SWAP
, 0);
2448 if (bp
->tx_lane_swap
!= 0x1b) {
2449 bnx2x_mdio22_write(bp
, MDIO_XGXS_BLOCK2_TX_LN_SWAP
,
2451 MDIO_XGXS_BLOCK2_TX_LN_SWAP_ENABLE
));
2453 bnx2x_mdio22_write(bp
, MDIO_XGXS_BLOCK2_TX_LN_SWAP
, 0);
2457 static void bnx2x_set_parallel_detection(struct bnx2x
*bp
)
2461 MDIO_SET_REG_BANK(bp
, MDIO_REG_BANK_SERDES_DIGITAL
);
2462 bnx2x_mdio22_read(bp
, MDIO_SERDES_DIGITAL_A_1000X_CONTROL2
,
2465 if (bp
->autoneg
& AUTONEG_PARALLEL
) {
2466 control2
|= MDIO_SERDES_DIGITAL_A_1000X_CONTROL2_PRL_DT_EN
;
2468 control2
&= ~MDIO_SERDES_DIGITAL_A_1000X_CONTROL2_PRL_DT_EN
;
2470 bnx2x_mdio22_write(bp
, MDIO_SERDES_DIGITAL_A_1000X_CONTROL2
,
2473 if (bp
->phy_flags
& PHY_XGXS_FLAG
) {
2474 DP(NETIF_MSG_LINK
, "XGXS\n");
2475 MDIO_SET_REG_BANK(bp
, MDIO_REG_BANK_10G_PARALLEL_DETECT
);
2477 bnx2x_mdio22_write(bp
,
2478 MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_LINK
,
2479 MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_LINK_CNT
);
2481 bnx2x_mdio22_read(bp
,
2482 MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_CONTROL
,
2485 if (bp
->autoneg
& AUTONEG_PARALLEL
) {
2487 MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_CONTROL_PARDET10G_EN
;
2490 ~MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_CONTROL_PARDET10G_EN
;
2492 bnx2x_mdio22_write(bp
,
2493 MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_CONTROL
,
2498 static void bnx2x_set_autoneg(struct bnx2x
*bp
)
2503 MDIO_SET_REG_BANK(bp
, MDIO_REG_BANK_COMBO_IEEE0
);
2504 bnx2x_mdio22_read(bp
, MDIO_COMBO_IEEE0_MII_CONTROL
, ®_val
);
2505 if ((bp
->req_autoneg
& AUTONEG_SPEED
) &&
2506 (bp
->autoneg
& AUTONEG_CL37
)) {
2507 /* CL37 Autoneg Enabled */
2508 reg_val
|= MDIO_COMBO_IEEO_MII_CONTROL_AN_EN
;
2510 /* CL37 Autoneg Disabled */
2511 reg_val
&= ~(MDIO_COMBO_IEEO_MII_CONTROL_AN_EN
|
2512 MDIO_COMBO_IEEO_MII_CONTROL_RESTART_AN
);
2514 bnx2x_mdio22_write(bp
, MDIO_COMBO_IEEE0_MII_CONTROL
, reg_val
);
2516 /* Enable/Disable Autodetection */
2517 MDIO_SET_REG_BANK(bp
, MDIO_REG_BANK_SERDES_DIGITAL
);
2518 bnx2x_mdio22_read(bp
, MDIO_SERDES_DIGITAL_A_1000X_CONTROL1
, ®_val
);
2519 reg_val
&= ~MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_SIGNAL_DETECT_EN
;
2521 if ((bp
->req_autoneg
& AUTONEG_SPEED
) &&
2522 (bp
->autoneg
& AUTONEG_SGMII_FIBER_AUTODET
)) {
2523 reg_val
|= MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_AUTODET
;
2525 reg_val
&= ~MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_AUTODET
;
2527 bnx2x_mdio22_write(bp
, MDIO_SERDES_DIGITAL_A_1000X_CONTROL1
, reg_val
);
2529 /* Enable TetonII and BAM autoneg */
2530 MDIO_SET_REG_BANK(bp
, MDIO_REG_BANK_BAM_NEXT_PAGE
);
2531 bnx2x_mdio22_read(bp
, MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL
,
2533 if ((bp
->req_autoneg
& AUTONEG_SPEED
) &&
2534 (bp
->autoneg
& AUTONEG_CL37
) && (bp
->autoneg
& AUTONEG_BAM
)) {
2535 /* Enable BAM aneg Mode and TetonII aneg Mode */
2536 reg_val
|= (MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL_BAM_MODE
|
2537 MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL_TETON_AN
);
2539 /* TetonII and BAM Autoneg Disabled */
2540 reg_val
&= ~(MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL_BAM_MODE
|
2541 MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL_TETON_AN
);
2543 bnx2x_mdio22_write(bp
, MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL
,
2546 /* Enable Clause 73 Aneg */
2547 if ((bp
->req_autoneg
& AUTONEG_SPEED
) &&
2548 (bp
->autoneg
& AUTONEG_CL73
)) {
2549 /* Enable BAM Station Manager */
2550 MDIO_SET_REG_BANK(bp
, MDIO_REG_BANK_CL73_USERB0
);
2551 bnx2x_mdio22_write(bp
, MDIO_CL73_USERB0_CL73_BAM_CTRL1
,
2552 (MDIO_CL73_USERB0_CL73_BAM_CTRL1_BAM_EN
|
2553 MDIO_CL73_USERB0_CL73_BAM_CTRL1_BAM_STATION_MNGR_EN
|
2554 MDIO_CL73_USERB0_CL73_BAM_CTRL1_BAM_NP_AFTER_BP_EN
));
2556 /* Merge CL73 and CL37 aneg resolution */
2557 bnx2x_mdio22_read(bp
, MDIO_CL73_USERB0_CL73_BAM_CTRL3
,
2559 bnx2x_mdio22_write(bp
, MDIO_CL73_USERB0_CL73_BAM_CTRL3
,
2561 MDIO_CL73_USERB0_CL73_BAM_CTRL3_USE_CL73_HCD_MR
));
2563 /* Set the CL73 AN speed */
2564 MDIO_SET_REG_BANK(bp
, MDIO_REG_BANK_CL73_IEEEB1
);
2565 bnx2x_mdio22_read(bp
, MDIO_CL73_IEEEB1_AN_ADV2
, ®_val
);
2566 /* In the SerDes we support only the 1G.
2567 In the XGXS we support the 10G KX4
2568 but we currently do not support the KR */
2569 if (bp
->phy_flags
& PHY_XGXS_FLAG
) {
2570 DP(NETIF_MSG_LINK
, "XGXS\n");
2572 reg_val
|= MDIO_CL73_IEEEB1_AN_ADV2_ADVR_10G_KX4
;
2574 DP(NETIF_MSG_LINK
, "SerDes\n");
2576 reg_val
|= MDIO_CL73_IEEEB1_AN_ADV2_ADVR_1000M_KX
;
2578 bnx2x_mdio22_write(bp
, MDIO_CL73_IEEEB1_AN_ADV2
, reg_val
);
2580 /* CL73 Autoneg Enabled */
2581 reg_val
= MDIO_CL73_IEEEB0_CL73_AN_CONTROL_AN_EN
;
2583 /* CL73 Autoneg Disabled */
2586 MDIO_SET_REG_BANK(bp
, MDIO_REG_BANK_CL73_IEEEB0
);
2587 bnx2x_mdio22_write(bp
, MDIO_CL73_IEEEB0_CL73_AN_CONTROL
, reg_val
);
2590 /* program SerDes, forced speed */
2591 static void bnx2x_program_serdes(struct bnx2x
*bp
)
2595 /* program duplex, disable autoneg */
2596 MDIO_SET_REG_BANK(bp
, MDIO_REG_BANK_COMBO_IEEE0
);
2597 bnx2x_mdio22_read(bp
, MDIO_COMBO_IEEE0_MII_CONTROL
, ®_val
);
2598 reg_val
&= ~(MDIO_COMBO_IEEO_MII_CONTROL_FULL_DUPLEX
|
2599 MDIO_COMBO_IEEO_MII_CONTROL_AN_EN
);
2600 if (bp
->req_duplex
== DUPLEX_FULL
)
2601 reg_val
|= MDIO_COMBO_IEEO_MII_CONTROL_FULL_DUPLEX
;
2602 bnx2x_mdio22_write(bp
, MDIO_COMBO_IEEE0_MII_CONTROL
, reg_val
);
2605 - needed only if the speed is greater than 1G (2.5G or 10G) */
2606 if (bp
->req_line_speed
> SPEED_1000
) {
2607 MDIO_SET_REG_BANK(bp
, MDIO_REG_BANK_SERDES_DIGITAL
);
2608 bnx2x_mdio22_read(bp
, MDIO_SERDES_DIGITAL_MISC1
, ®_val
);
2609 /* clearing the speed value before setting the right speed */
2610 reg_val
&= ~MDIO_SERDES_DIGITAL_MISC1_FORCE_SPEED_MASK
;
2611 reg_val
|= (MDIO_SERDES_DIGITAL_MISC1_REFCLK_SEL_156_25M
|
2612 MDIO_SERDES_DIGITAL_MISC1_FORCE_SPEED_SEL
);
2613 if (bp
->req_line_speed
== SPEED_10000
)
2615 MDIO_SERDES_DIGITAL_MISC1_FORCE_SPEED_10G_CX4
;
2616 bnx2x_mdio22_write(bp
, MDIO_SERDES_DIGITAL_MISC1
, reg_val
);
2620 static void bnx2x_set_brcm_cl37_advertisment(struct bnx2x
*bp
)
2624 /* configure the 48 bits for BAM AN */
2625 MDIO_SET_REG_BANK(bp
, MDIO_REG_BANK_OVER_1G
);
2627 /* set extended capabilities */
2628 if (bp
->advertising
& ADVERTISED_2500baseT_Full
)
2629 val
|= MDIO_OVER_1G_UP1_2_5G
;
2630 if (bp
->advertising
& ADVERTISED_10000baseT_Full
)
2631 val
|= MDIO_OVER_1G_UP1_10G
;
2632 bnx2x_mdio22_write(bp
, MDIO_OVER_1G_UP1
, val
);
2634 bnx2x_mdio22_write(bp
, MDIO_OVER_1G_UP3
, 0);
2637 static void bnx2x_set_ieee_aneg_advertisment(struct bnx2x
*bp
)
2641 /* for AN, we are always publishing full duplex */
2642 an_adv
= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_FULL_DUPLEX
;
2645 switch (bp
->pause_mode
) {
2646 case PAUSE_SYMMETRIC
:
2647 an_adv
|= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_SYMMETRIC
;
2649 case PAUSE_ASYMMETRIC
:
2650 an_adv
|= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC
;
2653 an_adv
|= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH
;
2656 an_adv
|= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE
;
2660 MDIO_SET_REG_BANK(bp
, MDIO_REG_BANK_COMBO_IEEE0
);
2661 bnx2x_mdio22_write(bp
, MDIO_COMBO_IEEE0_AUTO_NEG_ADV
, an_adv
);
2664 static void bnx2x_restart_autoneg(struct bnx2x
*bp
)
2666 if (bp
->autoneg
& AUTONEG_CL73
) {
2667 /* enable and restart clause 73 aneg */
2670 MDIO_SET_REG_BANK(bp
, MDIO_REG_BANK_CL73_IEEEB0
);
2671 bnx2x_mdio22_read(bp
, MDIO_CL73_IEEEB0_CL73_AN_CONTROL
,
2673 bnx2x_mdio22_write(bp
, MDIO_CL73_IEEEB0_CL73_AN_CONTROL
,
2675 MDIO_CL73_IEEEB0_CL73_AN_CONTROL_AN_EN
|
2676 MDIO_CL73_IEEEB0_CL73_AN_CONTROL_RESTART_AN
));
2679 /* Enable and restart BAM/CL37 aneg */
2682 MDIO_SET_REG_BANK(bp
, MDIO_REG_BANK_COMBO_IEEE0
);
2683 bnx2x_mdio22_read(bp
, MDIO_COMBO_IEEE0_MII_CONTROL
,
2685 bnx2x_mdio22_write(bp
, MDIO_COMBO_IEEE0_MII_CONTROL
,
2687 MDIO_COMBO_IEEO_MII_CONTROL_AN_EN
|
2688 MDIO_COMBO_IEEO_MII_CONTROL_RESTART_AN
));
2692 static void bnx2x_initialize_sgmii_process(struct bnx2x
*bp
)
2696 /* in SGMII mode, the unicore is always slave */
2697 MDIO_SET_REG_BANK(bp
, MDIO_REG_BANK_SERDES_DIGITAL
);
2698 bnx2x_mdio22_read(bp
, MDIO_SERDES_DIGITAL_A_1000X_CONTROL1
,
2700 control1
|= MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_INVERT_SIGNAL_DETECT
;
2701 /* set sgmii mode (and not fiber) */
2702 control1
&= ~(MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_FIBER_MODE
|
2703 MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_AUTODET
|
2704 MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_MSTR_MODE
);
2705 bnx2x_mdio22_write(bp
, MDIO_SERDES_DIGITAL_A_1000X_CONTROL1
,
2708 /* if forced speed */
2709 if (!(bp
->req_autoneg
& AUTONEG_SPEED
)) {
2710 /* set speed, disable autoneg */
2713 MDIO_SET_REG_BANK(bp
, MDIO_REG_BANK_COMBO_IEEE0
);
2714 bnx2x_mdio22_read(bp
, MDIO_COMBO_IEEE0_MII_CONTROL
,
2716 mii_control
&= ~(MDIO_COMBO_IEEO_MII_CONTROL_AN_EN
|
2717 MDIO_COMBO_IEEO_MII_CONTROL_MAN_SGMII_SP_MASK
|
2718 MDIO_COMBO_IEEO_MII_CONTROL_FULL_DUPLEX
);
2720 switch (bp
->req_line_speed
) {
2723 MDIO_COMBO_IEEO_MII_CONTROL_MAN_SGMII_SP_100
;
2727 MDIO_COMBO_IEEO_MII_CONTROL_MAN_SGMII_SP_1000
;
2730 /* there is nothing to set for 10M */
2733 /* invalid speed for SGMII */
2734 DP(NETIF_MSG_LINK
, "Invalid req_line_speed 0x%x\n",
2735 bp
->req_line_speed
);
2739 /* setting the full duplex */
2740 if (bp
->req_duplex
== DUPLEX_FULL
)
2742 MDIO_COMBO_IEEO_MII_CONTROL_FULL_DUPLEX
;
2743 bnx2x_mdio22_write(bp
, MDIO_COMBO_IEEE0_MII_CONTROL
,
2746 } else { /* AN mode */
2747 /* enable and restart AN */
2748 bnx2x_restart_autoneg(bp
);
2752 static void bnx2x_link_int_enable(struct bnx2x
*bp
)
2754 int port
= bp
->port
;
2756 /* setting the status to report on link up
2757 for either XGXS or SerDes */
2758 bnx2x_bits_dis(bp
, NIG_REG_STATUS_INTERRUPT_PORT0
+ port
*4,
2759 (NIG_XGXS0_LINK_STATUS
|
2760 NIG_STATUS_INTERRUPT_XGXS0_LINK10G
|
2761 NIG_SERDES0_LINK_STATUS
));
2763 if (bp
->phy_flags
& PHY_XGXS_FLAG
) {
2765 * in force mode (not AN) we can enable just the relevant
2767 * Even in AN we might enable only one according to the AN
2770 bnx2x_bits_en(bp
, NIG_REG_MASK_INTERRUPT_PORT0
+ port
*4,
2771 (NIG_MASK_XGXS0_LINK_STATUS
|
2772 NIG_MASK_XGXS0_LINK10G
));
2773 DP(NETIF_MSG_LINK
, "enable XGXS interrupt\n");
2775 } else { /* SerDes */
2776 bnx2x_bits_en(bp
, NIG_REG_MASK_INTERRUPT_PORT0
+ port
*4,
2777 NIG_MASK_SERDES0_LINK_STATUS
);
2778 DP(NETIF_MSG_LINK
, "enable SerDes interrupt\n");
2782 static void bnx2x_ext_phy_init(struct bnx2x
*bp
)
2784 int port
= bp
->port
;
2789 if (bp
->phy_flags
& PHY_XGXS_FLAG
) {
2790 local_phy
= bp
->phy_addr
;
2791 ext_phy_addr
= ((bp
->ext_phy_config
&
2792 PORT_HW_CFG_XGXS_EXT_PHY_ADDR_MASK
) >>
2793 PORT_HW_CFG_XGXS_EXT_PHY_ADDR_SHIFT
);
2795 ext_phy_type
= XGXS_EXT_PHY_TYPE(bp
);
2796 switch (ext_phy_type
) {
2797 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT
:
2798 DP(NETIF_MSG_LINK
, "XGXS Direct\n");
2801 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8705
:
2802 DP(NETIF_MSG_LINK
, "XGXS 8705\n");
2804 NIG_REG_MASK_INTERRUPT_PORT0
+ port
*4,
2806 DP(NETIF_MSG_LINK
, "enabled extenal phy int\n");
2808 bp
->phy_addr
= ext_phy_type
;
2809 bnx2x_mdio45_vwrite(bp
, EXT_PHY_OPT_PMA_PMD_DEVAD
,
2810 EXT_PHY_OPT_PMD_MISC_CNTL
,
2812 bnx2x_mdio45_vwrite(bp
, EXT_PHY_OPT_PMA_PMD_DEVAD
,
2813 EXT_PHY_OPT_PHY_IDENTIFIER
,
2815 bnx2x_mdio45_vwrite(bp
, EXT_PHY_OPT_PMA_PMD_DEVAD
,
2816 EXT_PHY_OPT_CMU_PLL_BYPASS
,
2818 bnx2x_mdio45_vwrite(bp
, EXT_PHY_OPT_WIS_DEVAD
,
2819 EXT_PHY_OPT_LASI_CNTL
, 0x1);
2822 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8706
:
2823 DP(NETIF_MSG_LINK
, "XGXS 8706\n");
2825 NIG_REG_MASK_INTERRUPT_PORT0
+ port
*4,
2827 DP(NETIF_MSG_LINK
, "enabled extenal phy int\n");
2829 bp
->phy_addr
= ext_phy_type
;
2830 bnx2x_mdio45_vwrite(bp
, EXT_PHY_OPT_PMA_PMD_DEVAD
,
2831 EXT_PHY_OPT_PMD_DIGITAL_CNT
,
2833 bnx2x_mdio45_vwrite(bp
, EXT_PHY_OPT_PMA_PMD_DEVAD
,
2834 EXT_PHY_OPT_LASI_CNTL
, 0x1);
2838 DP(NETIF_MSG_LINK
, "BAD XGXS ext_phy_config 0x%x\n",
2839 bp
->ext_phy_config
);
2842 bp
->phy_addr
= local_phy
;
2844 } else { /* SerDes */
2845 /* ext_phy_addr = ((bp->ext_phy_config &
2846 PORT_HW_CFG_SERDES_EXT_PHY_ADDR_MASK) >>
2847 PORT_HW_CFG_SERDES_EXT_PHY_ADDR_SHIFT);
2849 ext_phy_type
= SERDES_EXT_PHY_TYPE(bp
);
2850 switch (ext_phy_type
) {
2851 case PORT_HW_CFG_SERDES_EXT_PHY_TYPE_DIRECT
:
2852 DP(NETIF_MSG_LINK
, "SerDes Direct\n");
2855 case PORT_HW_CFG_SERDES_EXT_PHY_TYPE_BCM5482
:
2856 DP(NETIF_MSG_LINK
, "SerDes 5482\n");
2858 NIG_REG_MASK_INTERRUPT_PORT0
+ port
*4,
2860 DP(NETIF_MSG_LINK
, "enabled extenal phy int\n");
2864 DP(NETIF_MSG_LINK
, "BAD SerDes ext_phy_config 0x%x\n",
2865 bp
->ext_phy_config
);
2871 static void bnx2x_ext_phy_reset(struct bnx2x
*bp
)
2877 if (bp
->phy_flags
& PHY_XGXS_FLAG
) {
2878 ext_phy_type
= XGXS_EXT_PHY_TYPE(bp
);
2879 switch (ext_phy_type
) {
2880 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT
:
2881 DP(NETIF_MSG_LINK
, "XGXS Direct\n");
2884 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8705
:
2885 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8706
:
2886 DP(NETIF_MSG_LINK
, "XGXS 8705/6\n");
2887 local_phy
= bp
->phy_addr
;
2888 ext_phy_addr
= ((bp
->ext_phy_config
&
2889 PORT_HW_CFG_XGXS_EXT_PHY_ADDR_MASK
) >>
2890 PORT_HW_CFG_XGXS_EXT_PHY_ADDR_SHIFT
);
2891 bp
->phy_addr
= (u8
)ext_phy_addr
;
2892 bnx2x_mdio45_write(bp
, EXT_PHY_OPT_PMA_PMD_DEVAD
,
2893 EXT_PHY_OPT_CNTL
, 0xa040);
2894 bp
->phy_addr
= local_phy
;
2898 DP(NETIF_MSG_LINK
, "BAD XGXS ext_phy_config 0x%x\n",
2899 bp
->ext_phy_config
);
2903 } else { /* SerDes */
2904 ext_phy_type
= SERDES_EXT_PHY_TYPE(bp
);
2905 switch (ext_phy_type
) {
2906 case PORT_HW_CFG_SERDES_EXT_PHY_TYPE_DIRECT
:
2907 DP(NETIF_MSG_LINK
, "SerDes Direct\n");
2910 case PORT_HW_CFG_SERDES_EXT_PHY_TYPE_BCM5482
:
2911 DP(NETIF_MSG_LINK
, "SerDes 5482\n");
2915 DP(NETIF_MSG_LINK
, "BAD SerDes ext_phy_config 0x%x\n",
2916 bp
->ext_phy_config
);
2922 static void bnx2x_link_initialize(struct bnx2x
*bp
)
2924 int port
= bp
->port
;
2926 /* disable attentions */
2927 bnx2x_bits_dis(bp
, NIG_REG_MASK_INTERRUPT_PORT0
+ port
*4,
2928 (NIG_MASK_XGXS0_LINK_STATUS
|
2929 NIG_MASK_XGXS0_LINK10G
|
2930 NIG_MASK_SERDES0_LINK_STATUS
|
2933 bnx2x_ext_phy_reset(bp
);
2935 bnx2x_set_aer_mmd(bp
);
2937 if (bp
->phy_flags
& PHY_XGXS_FLAG
)
2938 bnx2x_set_master_ln(bp
);
2940 /* reset the SerDes and wait for reset bit return low */
2941 bnx2x_reset_unicore(bp
);
2943 bnx2x_set_aer_mmd(bp
);
2945 /* setting the masterLn_def again after the reset */
2946 if (bp
->phy_flags
& PHY_XGXS_FLAG
) {
2947 bnx2x_set_master_ln(bp
);
2948 bnx2x_set_swap_lanes(bp
);
2951 /* Set Parallel Detect */
2952 if (bp
->req_autoneg
& AUTONEG_SPEED
)
2953 bnx2x_set_parallel_detection(bp
);
2955 if (bp
->phy_flags
& PHY_XGXS_FLAG
) {
2956 if (bp
->req_line_speed
&&
2957 bp
->req_line_speed
< SPEED_1000
) {
2958 bp
->phy_flags
|= PHY_SGMII_FLAG
;
2960 bp
->phy_flags
&= ~PHY_SGMII_FLAG
;
2964 if (!(bp
->phy_flags
& PHY_SGMII_FLAG
)) {
2967 rx_eq
= ((bp
->serdes_config
&
2968 PORT_HW_CFG_SERDES_RX_DRV_EQUALIZER_MASK
) >>
2969 PORT_HW_CFG_SERDES_RX_DRV_EQUALIZER_SHIFT
);
2971 DP(NETIF_MSG_LINK
, "setting rx eq to %d\n", rx_eq
);
2972 for (bank
= MDIO_REG_BANK_RX0
; bank
<= MDIO_REG_BANK_RX_ALL
;
2973 bank
+= (MDIO_REG_BANK_RX1
- MDIO_REG_BANK_RX0
)) {
2974 MDIO_SET_REG_BANK(bp
, bank
);
2975 bnx2x_mdio22_write(bp
, MDIO_RX0_RX_EQ_BOOST
,
2977 MDIO_RX0_RX_EQ_BOOST_EQUALIZER_CTRL_MASK
) |
2978 MDIO_RX0_RX_EQ_BOOST_OFFSET_CTRL
));
2981 /* forced speed requested? */
2982 if (!(bp
->req_autoneg
& AUTONEG_SPEED
)) {
2983 DP(NETIF_MSG_LINK
, "not SGMII, no AN\n");
2985 /* disable autoneg */
2986 bnx2x_set_autoneg(bp
);
2988 /* program speed and duplex */
2989 bnx2x_program_serdes(bp
);
2991 } else { /* AN_mode */
2992 DP(NETIF_MSG_LINK
, "not SGMII, AN\n");
2995 bnx2x_set_brcm_cl37_advertisment(bp
);
2997 /* program duplex & pause advertisment (for aneg) */
2998 bnx2x_set_ieee_aneg_advertisment(bp
);
3000 /* enable autoneg */
3001 bnx2x_set_autoneg(bp
);
3003 /* enalbe and restart AN */
3004 bnx2x_restart_autoneg(bp
);
3007 } else { /* SGMII mode */
3008 DP(NETIF_MSG_LINK
, "SGMII\n");
3010 bnx2x_initialize_sgmii_process(bp
);
3013 /* enable the interrupt */
3014 bnx2x_link_int_enable(bp
);
3016 /* init ext phy and enable link state int */
3017 bnx2x_ext_phy_init(bp
);
3020 static void bnx2x_phy_deassert(struct bnx2x
*bp
)
3022 int port
= bp
->port
;
3025 if (bp
->phy_flags
& PHY_XGXS_FLAG
) {
3026 DP(NETIF_MSG_LINK
, "XGXS\n");
3027 val
= XGXS_RESET_BITS
;
3029 } else { /* SerDes */
3030 DP(NETIF_MSG_LINK
, "SerDes\n");
3031 val
= SERDES_RESET_BITS
;
3034 val
= val
<< (port
*16);
3036 /* reset and unreset the SerDes/XGXS */
3037 REG_WR(bp
, GRCBASE_MISC
+ MISC_REGISTERS_RESET_REG_3_CLEAR
, val
);
3039 REG_WR(bp
, GRCBASE_MISC
+ MISC_REGISTERS_RESET_REG_3_SET
, val
);
3042 static int bnx2x_phy_init(struct bnx2x
*bp
)
3044 DP(NETIF_MSG_LINK
, "started\n");
3045 if (CHIP_REV(bp
) == CHIP_REV_FPGA
) {
3046 bp
->phy_flags
|= PHY_EMAC_FLAG
;
3048 bp
->line_speed
= SPEED_10000
;
3049 bp
->duplex
= DUPLEX_FULL
;
3050 NIG_WR(NIG_REG_EGRESS_DRAIN0_MODE
+ bp
->port
*4, 0);
3051 bnx2x_emac_enable(bp
);
3052 bnx2x_link_report(bp
);
3055 } else if (CHIP_REV(bp
) == CHIP_REV_EMUL
) {
3056 bp
->phy_flags
|= PHY_BMAC_FLAG
;
3058 bp
->line_speed
= SPEED_10000
;
3059 bp
->duplex
= DUPLEX_FULL
;
3060 NIG_WR(NIG_REG_EGRESS_DRAIN0_MODE
+ bp
->port
*4, 0);
3061 bnx2x_bmac_enable(bp
, 0);
3062 bnx2x_link_report(bp
);
3066 bnx2x_phy_deassert(bp
);
3067 bnx2x_link_initialize(bp
);
3073 static void bnx2x_link_reset(struct bnx2x
*bp
)
3075 int port
= bp
->port
;
3077 /* disable attentions */
3078 bnx2x_bits_dis(bp
, NIG_REG_MASK_INTERRUPT_PORT0
+ port
*4,
3079 (NIG_MASK_XGXS0_LINK_STATUS
|
3080 NIG_MASK_XGXS0_LINK10G
|
3081 NIG_MASK_SERDES0_LINK_STATUS
|
3084 bnx2x_ext_phy_reset(bp
);
3086 /* reset the SerDes/XGXS */
3087 REG_WR(bp
, GRCBASE_MISC
+ MISC_REGISTERS_RESET_REG_3_CLEAR
,
3088 (0x1ff << (port
*16)));
3090 /* reset EMAC / BMAC and disable NIG interfaces */
3091 NIG_WR(NIG_REG_BMAC0_IN_EN
+ port
*4, 0);
3092 NIG_WR(NIG_REG_BMAC0_OUT_EN
+ port
*4, 0);
3094 NIG_WR(NIG_REG_NIG_EMAC0_EN
+ port
*4, 0);
3095 NIG_WR(NIG_REG_EMAC0_IN_EN
+ port
*4, 0);
3096 NIG_WR(NIG_REG_EGRESS_EMAC0_OUT_EN
+ port
*4, 0);
3098 NIG_WR(NIG_REG_EGRESS_DRAIN0_MODE
+ port
*4, 1);
3101 #ifdef BNX2X_XGXS_LB
3102 static void bnx2x_set_xgxs_loopback(struct bnx2x
*bp
, int is_10g
)
3104 int port
= bp
->port
;
3109 DP(NETIF_MSG_LINK
, "XGXS 10G loopback enable\n");
3111 /* change the uni_phy_addr in the nig */
3112 REG_RD(bp
, (NIG_REG_XGXS0_CTRL_MD_DEVAD
+ port
*0x18),
3114 NIG_WR(NIG_REG_XGXS0_CTRL_MD_DEVAD
+ port
*0x18, 0x5);
3116 /* change the aer mmd */
3117 MDIO_SET_REG_BANK(bp
, MDIO_REG_BANK_AER_BLOCK
);
3118 bnx2x_mdio22_write(bp
, MDIO_AER_BLOCK_AER_REG
, 0x2800);
3120 /* config combo IEEE0 control reg for loopback */
3121 MDIO_SET_REG_BANK(bp
, MDIO_REG_BANK_CL73_IEEEB0
);
3122 bnx2x_mdio22_write(bp
, MDIO_CL73_IEEEB0_CL73_AN_CONTROL
,
3125 /* set aer mmd back */
3126 bnx2x_set_aer_mmd(bp
);
3129 NIG_WR(NIG_REG_XGXS0_CTRL_MD_DEVAD
+ port
*0x18, md_devad
);
3134 DP(NETIF_MSG_LINK
, "XGXS 1G loopback enable\n");
3136 MDIO_SET_REG_BANK(bp
, MDIO_REG_BANK_COMBO_IEEE0
);
3137 bnx2x_mdio22_read(bp
, MDIO_COMBO_IEEE0_MII_CONTROL
,
3139 bnx2x_mdio22_write(bp
, MDIO_COMBO_IEEE0_MII_CONTROL
,
3141 MDIO_COMBO_IEEO_MII_CONTROL_LOOPBACK
));
3146 /* end of PHY/MAC */
3151 * General service functions
3154 /* the slow path queue is odd since completions arrive on the fastpath ring */
3155 static int bnx2x_sp_post(struct bnx2x
*bp
, int command
, int cid
,
3156 u32 data_hi
, u32 data_lo
, int common
)
3158 int port
= bp
->port
;
3161 "spe (%x:%x) command %x hw_cid %x data (%x:%x) left %x\n",
3162 (u32
)U64_HI(bp
->spq_mapping
), (u32
)(U64_LO(bp
->spq_mapping
) +
3163 (void *)bp
->spq_prod_bd
- (void *)bp
->spq
), command
,
3164 HW_CID(bp
, cid
), data_hi
, data_lo
, bp
->spq_left
);
3166 #ifdef BNX2X_STOP_ON_ERROR
3167 if (unlikely(bp
->panic
))
3171 spin_lock(&bp
->spq_lock
);
3173 if (!bp
->spq_left
) {
3174 BNX2X_ERR("BUG! SPQ ring full!\n");
3175 spin_unlock(&bp
->spq_lock
);
3179 /* CID needs port number to be encoded int it */
3180 bp
->spq_prod_bd
->hdr
.conn_and_cmd_data
=
3181 cpu_to_le32(((command
<< SPE_HDR_CMD_ID_SHIFT
) |
3183 bp
->spq_prod_bd
->hdr
.type
= cpu_to_le16(ETH_CONNECTION_TYPE
);
3185 bp
->spq_prod_bd
->hdr
.type
|=
3186 cpu_to_le16((1 << SPE_HDR_COMMON_RAMROD_SHIFT
));
3188 bp
->spq_prod_bd
->data
.mac_config_addr
.hi
= cpu_to_le32(data_hi
);
3189 bp
->spq_prod_bd
->data
.mac_config_addr
.lo
= cpu_to_le32(data_lo
);
3193 if (bp
->spq_prod_bd
== bp
->spq_last_bd
) {
3194 bp
->spq_prod_bd
= bp
->spq
;
3195 bp
->spq_prod_idx
= 0;
3196 DP(NETIF_MSG_TIMER
, "end of spq\n");
3203 REG_WR(bp
, BAR_XSTRORM_INTMEM
+ XSTORM_SPQ_PROD_OFFSET(port
),
3206 spin_unlock(&bp
->spq_lock
);
3210 /* acquire split MCP access lock register */
3211 static int bnx2x_lock_alr(struct bnx2x
*bp
)
3218 for (j
= 0; j
< i
*10; j
++) {
3220 REG_WR(bp
, GRCBASE_MCP
+ 0x9c, val
);
3221 val
= REG_RD(bp
, GRCBASE_MCP
+ 0x9c);
3222 if (val
& (1L << 31))
3228 if (!(val
& (1L << 31))) {
3229 BNX2X_ERR("Cannot acquire nvram interface\n");
3237 /* Release split MCP access lock register */
3238 static void bnx2x_unlock_alr(struct bnx2x
*bp
)
3242 REG_WR(bp
, GRCBASE_MCP
+ 0x9c, val
);
3245 static inline u16
bnx2x_update_dsb_idx(struct bnx2x
*bp
)
3247 struct host_def_status_block
*def_sb
= bp
->def_status_blk
;
3250 barrier(); /* status block is written to by the chip */
3252 if (bp
->def_att_idx
!= def_sb
->atten_status_block
.attn_bits_index
) {
3253 bp
->def_att_idx
= def_sb
->atten_status_block
.attn_bits_index
;
3256 if (bp
->def_c_idx
!= def_sb
->c_def_status_block
.status_block_index
) {
3257 bp
->def_c_idx
= def_sb
->c_def_status_block
.status_block_index
;
3260 if (bp
->def_u_idx
!= def_sb
->u_def_status_block
.status_block_index
) {
3261 bp
->def_u_idx
= def_sb
->u_def_status_block
.status_block_index
;
3264 if (bp
->def_x_idx
!= def_sb
->x_def_status_block
.status_block_index
) {
3265 bp
->def_x_idx
= def_sb
->x_def_status_block
.status_block_index
;
3268 if (bp
->def_t_idx
!= def_sb
->t_def_status_block
.status_block_index
) {
3269 bp
->def_t_idx
= def_sb
->t_def_status_block
.status_block_index
;
3276 * slow path service functions
3279 static void bnx2x_attn_int_asserted(struct bnx2x
*bp
, u32 asserted
)
3281 int port
= bp
->port
;
3282 u32 igu_addr
= (IGU_ADDR_ATTN_BITS_SET
+ IGU_PORT_BASE
* port
) * 8;
3283 u32 aeu_addr
= port
? MISC_REG_AEU_MASK_ATTN_FUNC_1
:
3284 MISC_REG_AEU_MASK_ATTN_FUNC_0
;
3285 u32 nig_mask_addr
= port
? NIG_REG_MASK_INTERRUPT_PORT1
:
3286 NIG_REG_MASK_INTERRUPT_PORT0
;
3288 if (~bp
->aeu_mask
& (asserted
& 0xff))
3289 BNX2X_ERR("IGU ERROR\n");
3290 if (bp
->attn_state
& asserted
)
3291 BNX2X_ERR("IGU ERROR\n");
3293 DP(NETIF_MSG_HW
, "aeu_mask %x newly asserted %x\n",
3294 bp
->aeu_mask
, asserted
);
3295 bp
->aeu_mask
&= ~(asserted
& 0xff);
3296 DP(NETIF_MSG_HW
, "after masking: aeu_mask %x\n", bp
->aeu_mask
);
3298 REG_WR(bp
, aeu_addr
, bp
->aeu_mask
);
3300 bp
->attn_state
|= asserted
;
3302 if (asserted
& ATTN_HARD_WIRED_MASK
) {
3303 if (asserted
& ATTN_NIG_FOR_FUNC
) {
3304 u32 nig_status_port
;
3305 u32 nig_int_addr
= port
?
3306 NIG_REG_STATUS_INTERRUPT_PORT1
:
3307 NIG_REG_STATUS_INTERRUPT_PORT0
;
3309 bp
->nig_mask
= REG_RD(bp
, nig_mask_addr
);
3310 REG_WR(bp
, nig_mask_addr
, 0);
3312 nig_status_port
= REG_RD(bp
, nig_int_addr
);
3313 bnx2x_link_update(bp
);
3315 /* handle unicore attn? */
3317 if (asserted
& ATTN_SW_TIMER_4_FUNC
)
3318 DP(NETIF_MSG_HW
, "ATTN_SW_TIMER_4_FUNC!\n");
3320 if (asserted
& GPIO_2_FUNC
)
3321 DP(NETIF_MSG_HW
, "GPIO_2_FUNC!\n");
3323 if (asserted
& GPIO_3_FUNC
)
3324 DP(NETIF_MSG_HW
, "GPIO_3_FUNC!\n");
3326 if (asserted
& GPIO_4_FUNC
)
3327 DP(NETIF_MSG_HW
, "GPIO_4_FUNC!\n");
3330 if (asserted
& ATTN_GENERAL_ATTN_1
) {
3331 DP(NETIF_MSG_HW
, "ATTN_GENERAL_ATTN_1!\n");
3332 REG_WR(bp
, MISC_REG_AEU_GENERAL_ATTN_1
, 0x0);
3334 if (asserted
& ATTN_GENERAL_ATTN_2
) {
3335 DP(NETIF_MSG_HW
, "ATTN_GENERAL_ATTN_2!\n");
3336 REG_WR(bp
, MISC_REG_AEU_GENERAL_ATTN_2
, 0x0);
3338 if (asserted
& ATTN_GENERAL_ATTN_3
) {
3339 DP(NETIF_MSG_HW
, "ATTN_GENERAL_ATTN_3!\n");
3340 REG_WR(bp
, MISC_REG_AEU_GENERAL_ATTN_3
, 0x0);
3343 if (asserted
& ATTN_GENERAL_ATTN_4
) {
3344 DP(NETIF_MSG_HW
, "ATTN_GENERAL_ATTN_4!\n");
3345 REG_WR(bp
, MISC_REG_AEU_GENERAL_ATTN_4
, 0x0);
3347 if (asserted
& ATTN_GENERAL_ATTN_5
) {
3348 DP(NETIF_MSG_HW
, "ATTN_GENERAL_ATTN_5!\n");
3349 REG_WR(bp
, MISC_REG_AEU_GENERAL_ATTN_5
, 0x0);
3351 if (asserted
& ATTN_GENERAL_ATTN_6
) {
3352 DP(NETIF_MSG_HW
, "ATTN_GENERAL_ATTN_6!\n");
3353 REG_WR(bp
, MISC_REG_AEU_GENERAL_ATTN_6
, 0x0);
3357 } /* if hardwired */
3359 DP(NETIF_MSG_HW
, "about to mask 0x%08x at IGU addr 0x%x\n",
3360 asserted
, BAR_IGU_INTMEM
+ igu_addr
);
3361 REG_WR(bp
, BAR_IGU_INTMEM
+ igu_addr
, asserted
);
3363 /* now set back the mask */
3364 if (asserted
& ATTN_NIG_FOR_FUNC
)
3365 REG_WR(bp
, nig_mask_addr
, bp
->nig_mask
);
3368 static void bnx2x_attn_int_deasserted(struct bnx2x
*bp
, u32 deasserted
)
3370 int port
= bp
->port
;
3372 struct attn_route attn
;
3373 struct attn_route group_mask
;
3377 /* need to take HW lock because MCP or other port might also
3378 try to handle this event */
3381 attn
.sig
[0] = REG_RD(bp
, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0
+ port
*4);
3382 attn
.sig
[1] = REG_RD(bp
, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0
+ port
*4);
3383 attn
.sig
[2] = REG_RD(bp
, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0
+ port
*4);
3384 attn
.sig
[3] = REG_RD(bp
, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0
+ port
*4);
3385 DP(NETIF_MSG_HW
, "attn %llx\n", (unsigned long long)attn
.sig
[0]);
3387 for (index
= 0; index
< MAX_DYNAMIC_ATTN_GRPS
; index
++) {
3388 if (deasserted
& (1 << index
)) {
3389 group_mask
= bp
->attn_group
[index
];
3391 DP(NETIF_MSG_HW
, "group[%d]: %llx\n", index
,
3392 (unsigned long long)group_mask
.sig
[0]);
3394 if (attn
.sig
[3] & group_mask
.sig
[3] &
3395 EVEREST_GEN_ATTN_IN_USE_MASK
) {
3397 if (attn
.sig
[3] & BNX2X_MC_ASSERT_BITS
) {
3399 BNX2X_ERR("MC assert!\n");
3402 } else if (attn
.sig
[3] & BNX2X_MCP_ASSERT
) {
3404 BNX2X_ERR("MCP assert!\n");
3406 MISC_REG_AEU_GENERAL_ATTN_11
, 0);
3407 bnx2x_mc_assert(bp
);
3410 BNX2X_ERR("UNKOWEN HW ASSERT!\n");
3414 if (attn
.sig
[1] & group_mask
.sig
[1] &
3415 BNX2X_DOORQ_ASSERT
) {
3417 val
= REG_RD(bp
, DORQ_REG_DORQ_INT_STS_CLR
);
3418 BNX2X_ERR("DB hw attention 0x%x\n", val
);
3419 /* DORQ discard attention */
3421 BNX2X_ERR("FATAL error from DORQ\n");
3424 if (attn
.sig
[2] & group_mask
.sig
[2] &
3425 AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT
) {
3427 val
= REG_RD(bp
, CFC_REG_CFC_INT_STS_CLR
);
3428 BNX2X_ERR("CFC hw attention 0x%x\n", val
);
3429 /* CFC error attention */
3431 BNX2X_ERR("FATAL error from CFC\n");
3434 if (attn
.sig
[2] & group_mask
.sig
[2] &
3435 AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT
) {
3437 val
= REG_RD(bp
, PXP_REG_PXP_INT_STS_CLR_0
);
3438 BNX2X_ERR("PXP hw attention 0x%x\n", val
);
3439 /* RQ_USDMDP_FIFO_OVERFLOW */
3441 BNX2X_ERR("FATAL error from PXP\n");
3444 if (attn
.sig
[3] & group_mask
.sig
[3] &
3445 EVEREST_LATCHED_ATTN_IN_USE_MASK
) {
3447 REG_WR(bp
, MISC_REG_AEU_CLR_LATCH_SIGNAL
,
3449 DP(NETIF_MSG_HW
, "got latched bits 0x%x\n",
3453 if ((attn
.sig
[0] & group_mask
.sig
[0] &
3454 HW_INTERRUT_ASSERT_SET_0
) ||
3455 (attn
.sig
[1] & group_mask
.sig
[1] &
3456 HW_INTERRUT_ASSERT_SET_1
) ||
3457 (attn
.sig
[2] & group_mask
.sig
[2] &
3458 HW_INTERRUT_ASSERT_SET_2
))
3459 BNX2X_ERR("FATAL HW block attention\n");
3461 if ((attn
.sig
[0] & group_mask
.sig
[0] &
3462 HW_PRTY_ASSERT_SET_0
) ||
3463 (attn
.sig
[1] & group_mask
.sig
[1] &
3464 HW_PRTY_ASSERT_SET_1
) ||
3465 (attn
.sig
[2] & group_mask
.sig
[2] &
3466 HW_PRTY_ASSERT_SET_2
))
3467 BNX2X_ERR("FATAL HW block parity atention\n");
3471 bnx2x_unlock_alr(bp
);
3473 reg_addr
= (IGU_ADDR_ATTN_BITS_CLR
+ IGU_PORT_BASE
* port
) * 8;
3476 /* DP(NETIF_MSG_INTR, "write 0x%08x to IGU addr 0x%x\n",
3477 val, BAR_IGU_INTMEM + reg_addr); */
3478 REG_WR(bp
, BAR_IGU_INTMEM
+ reg_addr
, val
);
3480 if (bp
->aeu_mask
& (deasserted
& 0xff))
3481 BNX2X_ERR("IGU BUG\n");
3482 if (~bp
->attn_state
& deasserted
)
3483 BNX2X_ERR("IGU BUG\n");
3485 reg_addr
= port
? MISC_REG_AEU_MASK_ATTN_FUNC_1
:
3486 MISC_REG_AEU_MASK_ATTN_FUNC_0
;
3488 DP(NETIF_MSG_HW
, "aeu_mask %x\n", bp
->aeu_mask
);
3489 bp
->aeu_mask
|= (deasserted
& 0xff);
3491 DP(NETIF_MSG_HW
, "new mask %x\n", bp
->aeu_mask
);
3492 REG_WR(bp
, reg_addr
, bp
->aeu_mask
);
3494 DP(NETIF_MSG_HW
, "attn_state %x\n", bp
->attn_state
);
3495 bp
->attn_state
&= ~deasserted
;
3496 DP(NETIF_MSG_HW
, "new state %x\n", bp
->attn_state
);
3499 static void bnx2x_attn_int(struct bnx2x
*bp
)
3501 /* read local copy of bits */
3502 u32 attn_bits
= bp
->def_status_blk
->atten_status_block
.attn_bits
;
3503 u32 attn_ack
= bp
->def_status_blk
->atten_status_block
.attn_bits_ack
;
3504 u32 attn_state
= bp
->attn_state
;
3506 /* look for changed bits */
3507 u32 asserted
= attn_bits
& ~attn_ack
& ~attn_state
;
3508 u32 deasserted
= ~attn_bits
& attn_ack
& attn_state
;
3511 "attn_bits %x attn_ack %x asserted %x deasserted %x\n",
3512 attn_bits
, attn_ack
, asserted
, deasserted
);
3514 if (~(attn_bits
^ attn_ack
) & (attn_bits
^ attn_state
))
3515 BNX2X_ERR("bad attention state\n");
3517 /* handle bits that were raised */
3519 bnx2x_attn_int_asserted(bp
, asserted
);
3522 bnx2x_attn_int_deasserted(bp
, deasserted
);
3525 static void bnx2x_sp_task(struct work_struct
*work
)
3527 struct bnx2x
*bp
= container_of(work
, struct bnx2x
, sp_task
);
3530 /* Return here if interrupt is disabled */
3531 if (unlikely(atomic_read(&bp
->intr_sem
) != 0)) {
3532 DP(NETIF_MSG_INTR
, "called but intr_sem not 0, returning\n");
3536 status
= bnx2x_update_dsb_idx(bp
);
3538 BNX2X_ERR("spurious slowpath interrupt!\n");
3540 DP(NETIF_MSG_INTR
, "got a slowpath interrupt (updated %x)\n", status
);
3547 /* CStorm events: query_stats, cfc delete ramrods */
3549 bp
->stat_pending
= 0;
3551 bnx2x_ack_sb(bp
, DEF_SB_ID
, ATTENTION_ID
, bp
->def_att_idx
,
3553 bnx2x_ack_sb(bp
, DEF_SB_ID
, USTORM_ID
, le16_to_cpu(bp
->def_u_idx
),
3555 bnx2x_ack_sb(bp
, DEF_SB_ID
, CSTORM_ID
, le16_to_cpu(bp
->def_c_idx
),
3557 bnx2x_ack_sb(bp
, DEF_SB_ID
, XSTORM_ID
, le16_to_cpu(bp
->def_x_idx
),
3559 bnx2x_ack_sb(bp
, DEF_SB_ID
, TSTORM_ID
, le16_to_cpu(bp
->def_t_idx
),
3563 static irqreturn_t
bnx2x_msix_sp_int(int irq
, void *dev_instance
)
3565 struct net_device
*dev
= dev_instance
;
3566 struct bnx2x
*bp
= netdev_priv(dev
);
3568 /* Return here if interrupt is disabled */
3569 if (unlikely(atomic_read(&bp
->intr_sem
) != 0)) {
3570 DP(NETIF_MSG_INTR
, "called but intr_sem not 0, returning\n");
3574 bnx2x_ack_sb(bp
, 16, XSTORM_ID
, 0, IGU_INT_DISABLE
, 0);
3576 #ifdef BNX2X_STOP_ON_ERROR
3577 if (unlikely(bp
->panic
))
3581 schedule_work(&bp
->sp_task
);
3586 /* end of slow path */
3590 /****************************************************************************
3592 ****************************************************************************/
3594 #define UPDATE_STAT(s, t) \
3596 estats->t += new->s - old->s; \
3600 /* sum[hi:lo] += add[hi:lo] */
3601 #define ADD_64(s_hi, a_hi, s_lo, a_lo) \
3604 s_hi += a_hi + (s_lo < a_lo) ? 1 : 0; \
3607 /* difference = minuend - subtrahend */
3608 #define DIFF_64(d_hi, m_hi, s_hi, d_lo, m_lo, s_lo) \
3610 if (m_lo < s_lo) { /* underflow */ \
3611 d_hi = m_hi - s_hi; \
3612 if (d_hi > 0) { /* we can 'loan' 1 */ \
3614 d_lo = m_lo + (UINT_MAX - s_lo) + 1; \
3615 } else { /* m_hi <= s_hi */ \
3619 } else { /* m_lo >= s_lo */ \
3620 if (m_hi < s_hi) { \
3623 } else { /* m_hi >= s_hi */ \
3624 d_hi = m_hi - s_hi; \
3625 d_lo = m_lo - s_lo; \
3630 /* minuend -= subtrahend */
3631 #define SUB_64(m_hi, s_hi, m_lo, s_lo) \
3633 DIFF_64(m_hi, m_hi, s_hi, m_lo, m_lo, s_lo); \
3636 #define UPDATE_STAT64(s_hi, t_hi, s_lo, t_lo) \
3638 DIFF_64(diff.hi, new->s_hi, old->s_hi, \
3639 diff.lo, new->s_lo, old->s_lo); \
3640 old->s_hi = new->s_hi; \
3641 old->s_lo = new->s_lo; \
3642 ADD_64(estats->t_hi, diff.hi, \
3643 estats->t_lo, diff.lo); \
3646 /* sum[hi:lo] += add */
3647 #define ADD_EXTEND_64(s_hi, s_lo, a) \
3650 s_hi += (s_lo < a) ? 1 : 0; \
3653 #define UPDATE_EXTEND_STAT(s, t_hi, t_lo) \
3655 ADD_EXTEND_64(estats->t_hi, estats->t_lo, new->s); \
3658 #define UPDATE_EXTEND_TSTAT(s, t_hi, t_lo) \
3660 diff = le32_to_cpu(tclient->s) - old_tclient->s; \
3661 old_tclient->s = le32_to_cpu(tclient->s); \
3662 ADD_EXTEND_64(estats->t_hi, estats->t_lo, diff); \
3666 * General service functions
3669 static inline long bnx2x_hilo(u32
*hiref
)
3671 u32 lo
= *(hiref
+ 1);
3672 #if (BITS_PER_LONG == 64)
3675 return HILO_U64(hi
, lo
);
3682 * Init service functions
3685 static void bnx2x_init_mac_stats(struct bnx2x
*bp
)
3687 struct dmae_command
*dmae
;
3688 int port
= bp
->port
;
3689 int loader_idx
= port
* 8;
3693 bp
->executer_idx
= 0;
3696 opcode
= (DMAE_CMD_SRC_PCI
| DMAE_CMD_DST_GRC
|
3697 DMAE_CMD_SRC_RESET
| DMAE_CMD_DST_RESET
|
3699 DMAE_CMD_ENDIANITY_B_DW_SWAP
|
3701 DMAE_CMD_ENDIANITY_DW_SWAP
|
3703 (port
? DMAE_CMD_PORT_1
: DMAE_CMD_PORT_0
));
3706 opcode
|= (DMAE_CMD_C_DST_GRC
| DMAE_CMD_C_ENABLE
);
3708 dmae
= bnx2x_sp(bp
, dmae
[bp
->executer_idx
++]);
3709 dmae
->opcode
= opcode
;
3710 dmae
->src_addr_lo
= U64_LO(bnx2x_sp_mapping(bp
, eth_stats
) +
3712 dmae
->src_addr_hi
= U64_HI(bnx2x_sp_mapping(bp
, eth_stats
) +
3714 dmae
->dst_addr_lo
= bp
->fw_mb
>> 2;
3715 dmae
->dst_addr_hi
= 0;
3716 dmae
->len
= (offsetof(struct bnx2x_eth_stats
, mac_stx_end
) -
3719 dmae
->comp_addr_lo
= dmae_reg_go_c
[loader_idx
] >> 2;
3720 dmae
->comp_addr_hi
= 0;
3723 dmae
->comp_addr_lo
= 0;
3724 dmae
->comp_addr_hi
= 0;
3730 /* no need to collect statistics in link down */
3734 opcode
= (DMAE_CMD_SRC_GRC
| DMAE_CMD_DST_PCI
|
3735 DMAE_CMD_C_DST_GRC
| DMAE_CMD_C_ENABLE
|
3736 DMAE_CMD_SRC_RESET
| DMAE_CMD_DST_RESET
|
3738 DMAE_CMD_ENDIANITY_B_DW_SWAP
|
3740 DMAE_CMD_ENDIANITY_DW_SWAP
|
3742 (port
? DMAE_CMD_PORT_1
: DMAE_CMD_PORT_0
));
3744 if (bp
->phy_flags
& PHY_BMAC_FLAG
) {
3746 mac_addr
= (port
? NIG_REG_INGRESS_BMAC1_MEM
:
3747 NIG_REG_INGRESS_BMAC0_MEM
);
3749 /* BIGMAC_REGISTER_TX_STAT_GTPKT ..
3750 BIGMAC_REGISTER_TX_STAT_GTBYT */
3751 dmae
= bnx2x_sp(bp
, dmae
[bp
->executer_idx
++]);
3752 dmae
->opcode
= opcode
;
3753 dmae
->src_addr_lo
= (mac_addr
+
3754 BIGMAC_REGISTER_TX_STAT_GTPKT
) >> 2;
3755 dmae
->src_addr_hi
= 0;
3756 dmae
->dst_addr_lo
= U64_LO(bnx2x_sp_mapping(bp
, mac_stats
));
3757 dmae
->dst_addr_hi
= U64_HI(bnx2x_sp_mapping(bp
, mac_stats
));
3758 dmae
->len
= (8 + BIGMAC_REGISTER_TX_STAT_GTBYT
-
3759 BIGMAC_REGISTER_TX_STAT_GTPKT
) >> 2;
3760 dmae
->comp_addr_lo
= dmae_reg_go_c
[loader_idx
] >> 2;
3761 dmae
->comp_addr_hi
= 0;
3764 /* BIGMAC_REGISTER_RX_STAT_GR64 ..
3765 BIGMAC_REGISTER_RX_STAT_GRIPJ */
3766 dmae
= bnx2x_sp(bp
, dmae
[bp
->executer_idx
++]);
3767 dmae
->opcode
= opcode
;
3768 dmae
->src_addr_lo
= (mac_addr
+
3769 BIGMAC_REGISTER_RX_STAT_GR64
) >> 2;
3770 dmae
->src_addr_hi
= 0;
3771 dmae
->dst_addr_lo
= U64_LO(bnx2x_sp_mapping(bp
, mac_stats
) +
3772 offsetof(struct bmac_stats
, rx_gr64
));
3773 dmae
->dst_addr_hi
= U64_HI(bnx2x_sp_mapping(bp
, mac_stats
) +
3774 offsetof(struct bmac_stats
, rx_gr64
));
3775 dmae
->len
= (8 + BIGMAC_REGISTER_RX_STAT_GRIPJ
-
3776 BIGMAC_REGISTER_RX_STAT_GR64
) >> 2;
3777 dmae
->comp_addr_lo
= dmae_reg_go_c
[loader_idx
] >> 2;
3778 dmae
->comp_addr_hi
= 0;
3781 } else if (bp
->phy_flags
& PHY_EMAC_FLAG
) {
3783 mac_addr
= (port
? GRCBASE_EMAC1
: GRCBASE_EMAC0
);
3785 /* EMAC_REG_EMAC_RX_STAT_AC (EMAC_REG_EMAC_RX_STAT_AC_COUNT)*/
3786 dmae
= bnx2x_sp(bp
, dmae
[bp
->executer_idx
++]);
3787 dmae
->opcode
= opcode
;
3788 dmae
->src_addr_lo
= (mac_addr
+
3789 EMAC_REG_EMAC_RX_STAT_AC
) >> 2;
3790 dmae
->src_addr_hi
= 0;
3791 dmae
->dst_addr_lo
= U64_LO(bnx2x_sp_mapping(bp
, mac_stats
));
3792 dmae
->dst_addr_hi
= U64_HI(bnx2x_sp_mapping(bp
, mac_stats
));
3793 dmae
->len
= EMAC_REG_EMAC_RX_STAT_AC_COUNT
;
3794 dmae
->comp_addr_lo
= dmae_reg_go_c
[loader_idx
] >> 2;
3795 dmae
->comp_addr_hi
= 0;
3798 /* EMAC_REG_EMAC_RX_STAT_AC_28 */
3799 dmae
= bnx2x_sp(bp
, dmae
[bp
->executer_idx
++]);
3800 dmae
->opcode
= opcode
;
3801 dmae
->src_addr_lo
= (mac_addr
+
3802 EMAC_REG_EMAC_RX_STAT_AC_28
) >> 2;
3803 dmae
->src_addr_hi
= 0;
3804 dmae
->dst_addr_lo
= U64_LO(bnx2x_sp_mapping(bp
, mac_stats
) +
3805 offsetof(struct emac_stats
,
3806 rx_falsecarriererrors
));
3807 dmae
->dst_addr_hi
= U64_HI(bnx2x_sp_mapping(bp
, mac_stats
) +
3808 offsetof(struct emac_stats
,
3809 rx_falsecarriererrors
));
3811 dmae
->comp_addr_lo
= dmae_reg_go_c
[loader_idx
] >> 2;
3812 dmae
->comp_addr_hi
= 0;
3815 /* EMAC_REG_EMAC_TX_STAT_AC (EMAC_REG_EMAC_TX_STAT_AC_COUNT)*/
3816 dmae
= bnx2x_sp(bp
, dmae
[bp
->executer_idx
++]);
3817 dmae
->opcode
= opcode
;
3818 dmae
->src_addr_lo
= (mac_addr
+
3819 EMAC_REG_EMAC_TX_STAT_AC
) >> 2;
3820 dmae
->src_addr_hi
= 0;
3821 dmae
->dst_addr_lo
= U64_LO(bnx2x_sp_mapping(bp
, mac_stats
) +
3822 offsetof(struct emac_stats
,
3824 dmae
->dst_addr_hi
= U64_HI(bnx2x_sp_mapping(bp
, mac_stats
) +
3825 offsetof(struct emac_stats
,
3827 dmae
->len
= EMAC_REG_EMAC_TX_STAT_AC_COUNT
;
3828 dmae
->comp_addr_lo
= dmae_reg_go_c
[loader_idx
] >> 2;
3829 dmae
->comp_addr_hi
= 0;
3834 dmae
= bnx2x_sp(bp
, dmae
[bp
->executer_idx
++]);
3835 dmae
->opcode
= (DMAE_CMD_SRC_GRC
| DMAE_CMD_DST_PCI
|
3836 DMAE_CMD_C_DST_PCI
| DMAE_CMD_C_ENABLE
|
3837 DMAE_CMD_SRC_RESET
| DMAE_CMD_DST_RESET
|
3839 DMAE_CMD_ENDIANITY_B_DW_SWAP
|
3841 DMAE_CMD_ENDIANITY_DW_SWAP
|
3843 (port
? DMAE_CMD_PORT_1
: DMAE_CMD_PORT_0
));
3844 dmae
->src_addr_lo
= (port
? NIG_REG_STAT1_BRB_DISCARD
:
3845 NIG_REG_STAT0_BRB_DISCARD
) >> 2;
3846 dmae
->src_addr_hi
= 0;
3847 dmae
->dst_addr_lo
= U64_LO(bnx2x_sp_mapping(bp
, nig
));
3848 dmae
->dst_addr_hi
= U64_HI(bnx2x_sp_mapping(bp
, nig
));
3849 dmae
->len
= (sizeof(struct nig_stats
) - 2*sizeof(u32
)) >> 2;
3850 dmae
->comp_addr_lo
= U64_LO(bnx2x_sp_mapping(bp
, nig
) +
3851 offsetof(struct nig_stats
, done
));
3852 dmae
->comp_addr_hi
= U64_HI(bnx2x_sp_mapping(bp
, nig
) +
3853 offsetof(struct nig_stats
, done
));
3854 dmae
->comp_val
= 0xffffffff;
3857 static void bnx2x_init_stats(struct bnx2x
*bp
)
3859 int port
= bp
->port
;
3861 bp
->stats_state
= STATS_STATE_DISABLE
;
3862 bp
->executer_idx
= 0;
3864 bp
->old_brb_discard
= REG_RD(bp
,
3865 NIG_REG_STAT0_BRB_DISCARD
+ port
*0x38);
3867 memset(&bp
->old_bmac
, 0, sizeof(struct bmac_stats
));
3868 memset(&bp
->old_tclient
, 0, sizeof(struct tstorm_per_client_stats
));
3869 memset(&bp
->dev
->stats
, 0, sizeof(struct net_device_stats
));
3871 REG_WR(bp
, BAR_XSTRORM_INTMEM
+ XSTORM_STATS_FLAGS_OFFSET(port
), 1);
3872 REG_WR(bp
, BAR_XSTRORM_INTMEM
+
3873 XSTORM_STATS_FLAGS_OFFSET(port
) + 4, 0);
3875 REG_WR(bp
, BAR_TSTRORM_INTMEM
+ TSTORM_STATS_FLAGS_OFFSET(port
), 1);
3876 REG_WR(bp
, BAR_TSTRORM_INTMEM
+
3877 TSTORM_STATS_FLAGS_OFFSET(port
) + 4, 0);
3879 REG_WR(bp
, BAR_CSTRORM_INTMEM
+ CSTORM_STATS_FLAGS_OFFSET(port
), 0);
3880 REG_WR(bp
, BAR_CSTRORM_INTMEM
+
3881 CSTORM_STATS_FLAGS_OFFSET(port
) + 4, 0);
3883 REG_WR(bp
, BAR_XSTRORM_INTMEM
+
3884 XSTORM_ETH_STATS_QUERY_ADDR_OFFSET(port
),
3885 U64_LO(bnx2x_sp_mapping(bp
, fw_stats
)));
3886 REG_WR(bp
, BAR_XSTRORM_INTMEM
+
3887 XSTORM_ETH_STATS_QUERY_ADDR_OFFSET(port
) + 4,
3888 U64_HI(bnx2x_sp_mapping(bp
, fw_stats
)));
3890 REG_WR(bp
, BAR_TSTRORM_INTMEM
+
3891 TSTORM_ETH_STATS_QUERY_ADDR_OFFSET(port
),
3892 U64_LO(bnx2x_sp_mapping(bp
, fw_stats
)));
3893 REG_WR(bp
, BAR_TSTRORM_INTMEM
+
3894 TSTORM_ETH_STATS_QUERY_ADDR_OFFSET(port
) + 4,
3895 U64_HI(bnx2x_sp_mapping(bp
, fw_stats
)));
3898 static void bnx2x_stop_stats(struct bnx2x
*bp
)
3901 if (bp
->stats_state
!= STATS_STATE_DISABLE
) {
3904 bp
->stats_state
= STATS_STATE_STOP
;
3905 DP(BNX2X_MSG_STATS
, "stats_state - STOP\n");
3907 while (bp
->stats_state
!= STATS_STATE_DISABLE
) {
3909 BNX2X_ERR("timeout wating for stats stop\n");
3916 DP(BNX2X_MSG_STATS
, "stats_state - DISABLE\n");
3920 * Statistics service functions
3923 static void bnx2x_update_bmac_stats(struct bnx2x
*bp
)
3927 struct bmac_stats
*new = bnx2x_sp(bp
, mac_stats
.bmac
);
3928 struct bmac_stats
*old
= &bp
->old_bmac
;
3929 struct bnx2x_eth_stats
*estats
= bnx2x_sp(bp
, eth_stats
);
3934 UPDATE_STAT64(tx_gtbyt
.hi
, total_bytes_transmitted_hi
,
3935 tx_gtbyt
.lo
, total_bytes_transmitted_lo
);
3937 UPDATE_STAT64(tx_gtmca
.hi
, total_multicast_packets_transmitted_hi
,
3938 tx_gtmca
.lo
, total_multicast_packets_transmitted_lo
);
3939 ADD_64(sum
.hi
, diff
.hi
, sum
.lo
, diff
.lo
);
3941 UPDATE_STAT64(tx_gtgca
.hi
, total_broadcast_packets_transmitted_hi
,
3942 tx_gtgca
.lo
, total_broadcast_packets_transmitted_lo
);
3943 ADD_64(sum
.hi
, diff
.hi
, sum
.lo
, diff
.lo
);
3945 UPDATE_STAT64(tx_gtpkt
.hi
, total_unicast_packets_transmitted_hi
,
3946 tx_gtpkt
.lo
, total_unicast_packets_transmitted_lo
);
3947 SUB_64(estats
->total_unicast_packets_transmitted_hi
, sum
.hi
,
3948 estats
->total_unicast_packets_transmitted_lo
, sum
.lo
);
3950 UPDATE_STAT(tx_gtxpf
.lo
, pause_xoff_frames_transmitted
);
3951 UPDATE_STAT(tx_gt64
.lo
, frames_transmitted_64_bytes
);
3952 UPDATE_STAT(tx_gt127
.lo
, frames_transmitted_65_127_bytes
);
3953 UPDATE_STAT(tx_gt255
.lo
, frames_transmitted_128_255_bytes
);
3954 UPDATE_STAT(tx_gt511
.lo
, frames_transmitted_256_511_bytes
);
3955 UPDATE_STAT(tx_gt1023
.lo
, frames_transmitted_512_1023_bytes
);
3956 UPDATE_STAT(tx_gt1518
.lo
, frames_transmitted_1024_1522_bytes
);
3957 UPDATE_STAT(tx_gt2047
.lo
, frames_transmitted_1523_9022_bytes
);
3958 UPDATE_STAT(tx_gt4095
.lo
, frames_transmitted_1523_9022_bytes
);
3959 UPDATE_STAT(tx_gt9216
.lo
, frames_transmitted_1523_9022_bytes
);
3960 UPDATE_STAT(tx_gt16383
.lo
, frames_transmitted_1523_9022_bytes
);
3962 UPDATE_STAT(rx_grfcs
.lo
, crc_receive_errors
);
3963 UPDATE_STAT(rx_grund
.lo
, runt_packets_received
);
3964 UPDATE_STAT(rx_grovr
.lo
, stat_Dot3statsFramesTooLong
);
3965 UPDATE_STAT(rx_grxpf
.lo
, pause_xoff_frames_received
);
3966 UPDATE_STAT(rx_grxcf
.lo
, control_frames_received
);
3967 /* UPDATE_STAT(rx_grxpf.lo, control_frames_received); */
3968 UPDATE_STAT(rx_grfrg
.lo
, error_runt_packets_received
);
3969 UPDATE_STAT(rx_grjbr
.lo
, error_jabber_packets_received
);
3971 UPDATE_STAT64(rx_grerb
.hi
, stat_IfHCInBadOctets_hi
,
3972 rx_grerb
.lo
, stat_IfHCInBadOctets_lo
);
3973 UPDATE_STAT64(tx_gtufl
.hi
, stat_IfHCOutBadOctets_hi
,
3974 tx_gtufl
.lo
, stat_IfHCOutBadOctets_lo
);
3975 UPDATE_STAT(tx_gterr
.lo
, stat_Dot3statsInternalMacTransmitErrors
);
3976 /* UPDATE_STAT(rx_grxpf.lo, stat_XoffStateEntered); */
3977 estats
->stat_XoffStateEntered
= estats
->pause_xoff_frames_received
;
3980 static void bnx2x_update_emac_stats(struct bnx2x
*bp
)
3982 struct emac_stats
*new = bnx2x_sp(bp
, mac_stats
.emac
);
3983 struct bnx2x_eth_stats
*estats
= bnx2x_sp(bp
, eth_stats
);
3985 UPDATE_EXTEND_STAT(tx_ifhcoutoctets
, total_bytes_transmitted_hi
,
3986 total_bytes_transmitted_lo
);
3987 UPDATE_EXTEND_STAT(tx_ifhcoutucastpkts
,
3988 total_unicast_packets_transmitted_hi
,
3989 total_unicast_packets_transmitted_lo
);
3990 UPDATE_EXTEND_STAT(tx_ifhcoutmulticastpkts
,
3991 total_multicast_packets_transmitted_hi
,
3992 total_multicast_packets_transmitted_lo
);
3993 UPDATE_EXTEND_STAT(tx_ifhcoutbroadcastpkts
,
3994 total_broadcast_packets_transmitted_hi
,
3995 total_broadcast_packets_transmitted_lo
);
3997 estats
->pause_xon_frames_transmitted
+= new->tx_outxonsent
;
3998 estats
->pause_xoff_frames_transmitted
+= new->tx_outxoffsent
;
3999 estats
->single_collision_transmit_frames
+=
4000 new->tx_dot3statssinglecollisionframes
;
4001 estats
->multiple_collision_transmit_frames
+=
4002 new->tx_dot3statsmultiplecollisionframes
;
4003 estats
->late_collision_frames
+= new->tx_dot3statslatecollisions
;
4004 estats
->excessive_collision_frames
+=
4005 new->tx_dot3statsexcessivecollisions
;
4006 estats
->frames_transmitted_64_bytes
+= new->tx_etherstatspkts64octets
;
4007 estats
->frames_transmitted_65_127_bytes
+=
4008 new->tx_etherstatspkts65octetsto127octets
;
4009 estats
->frames_transmitted_128_255_bytes
+=
4010 new->tx_etherstatspkts128octetsto255octets
;
4011 estats
->frames_transmitted_256_511_bytes
+=
4012 new->tx_etherstatspkts256octetsto511octets
;
4013 estats
->frames_transmitted_512_1023_bytes
+=
4014 new->tx_etherstatspkts512octetsto1023octets
;
4015 estats
->frames_transmitted_1024_1522_bytes
+=
4016 new->tx_etherstatspkts1024octetsto1522octet
;
4017 estats
->frames_transmitted_1523_9022_bytes
+=
4018 new->tx_etherstatspktsover1522octets
;
4020 estats
->crc_receive_errors
+= new->rx_dot3statsfcserrors
;
4021 estats
->alignment_errors
+= new->rx_dot3statsalignmenterrors
;
4022 estats
->false_carrier_detections
+= new->rx_falsecarriererrors
;
4023 estats
->runt_packets_received
+= new->rx_etherstatsundersizepkts
;
4024 estats
->stat_Dot3statsFramesTooLong
+= new->rx_dot3statsframestoolong
;
4025 estats
->pause_xon_frames_received
+= new->rx_xonpauseframesreceived
;
4026 estats
->pause_xoff_frames_received
+= new->rx_xoffpauseframesreceived
;
4027 estats
->control_frames_received
+= new->rx_maccontrolframesreceived
;
4028 estats
->error_runt_packets_received
+= new->rx_etherstatsfragments
;
4029 estats
->error_jabber_packets_received
+= new->rx_etherstatsjabbers
;
4031 UPDATE_EXTEND_STAT(rx_ifhcinbadoctets
, stat_IfHCInBadOctets_hi
,
4032 stat_IfHCInBadOctets_lo
);
4033 UPDATE_EXTEND_STAT(tx_ifhcoutbadoctets
, stat_IfHCOutBadOctets_hi
,
4034 stat_IfHCOutBadOctets_lo
);
4035 estats
->stat_Dot3statsInternalMacTransmitErrors
+=
4036 new->tx_dot3statsinternalmactransmiterrors
;
4037 estats
->stat_Dot3StatsCarrierSenseErrors
+=
4038 new->rx_dot3statscarriersenseerrors
;
4039 estats
->stat_Dot3StatsDeferredTransmissions
+=
4040 new->tx_dot3statsdeferredtransmissions
;
4041 estats
->stat_FlowControlDone
+= new->tx_flowcontroldone
;
4042 estats
->stat_XoffStateEntered
+= new->rx_xoffstateentered
;
4045 static int bnx2x_update_storm_stats(struct bnx2x
*bp
)
4047 struct eth_stats_query
*stats
= bnx2x_sp(bp
, fw_stats
);
4048 struct tstorm_common_stats
*tstats
= &stats
->tstorm_common
;
4049 struct tstorm_per_client_stats
*tclient
=
4050 &tstats
->client_statistics
[0];
4051 struct tstorm_per_client_stats
*old_tclient
= &bp
->old_tclient
;
4052 struct xstorm_common_stats
*xstats
= &stats
->xstorm_common
;
4053 struct nig_stats
*nstats
= bnx2x_sp(bp
, nig
);
4054 struct bnx2x_eth_stats
*estats
= bnx2x_sp(bp
, eth_stats
);
4057 /* are DMAE stats valid? */
4058 if (nstats
->done
!= 0xffffffff) {
4059 DP(BNX2X_MSG_STATS
, "stats not updated by dmae\n");
4063 /* are storm stats valid? */
4064 if (tstats
->done
.hi
!= 0xffffffff) {
4065 DP(BNX2X_MSG_STATS
, "stats not updated by tstorm\n");
4068 if (xstats
->done
.hi
!= 0xffffffff) {
4069 DP(BNX2X_MSG_STATS
, "stats not updated by xstorm\n");
4073 estats
->total_bytes_received_hi
=
4074 estats
->valid_bytes_received_hi
=
4075 le32_to_cpu(tclient
->total_rcv_bytes
.hi
);
4076 estats
->total_bytes_received_lo
=
4077 estats
->valid_bytes_received_lo
=
4078 le32_to_cpu(tclient
->total_rcv_bytes
.lo
);
4079 ADD_64(estats
->total_bytes_received_hi
,
4080 le32_to_cpu(tclient
->rcv_error_bytes
.hi
),
4081 estats
->total_bytes_received_lo
,
4082 le32_to_cpu(tclient
->rcv_error_bytes
.lo
));
4084 UPDATE_EXTEND_TSTAT(rcv_unicast_pkts
,
4085 total_unicast_packets_received_hi
,
4086 total_unicast_packets_received_lo
);
4087 UPDATE_EXTEND_TSTAT(rcv_multicast_pkts
,
4088 total_multicast_packets_received_hi
,
4089 total_multicast_packets_received_lo
);
4090 UPDATE_EXTEND_TSTAT(rcv_broadcast_pkts
,
4091 total_broadcast_packets_received_hi
,
4092 total_broadcast_packets_received_lo
);
4094 estats
->frames_received_64_bytes
= MAC_STX_NA
;
4095 estats
->frames_received_65_127_bytes
= MAC_STX_NA
;
4096 estats
->frames_received_128_255_bytes
= MAC_STX_NA
;
4097 estats
->frames_received_256_511_bytes
= MAC_STX_NA
;
4098 estats
->frames_received_512_1023_bytes
= MAC_STX_NA
;
4099 estats
->frames_received_1024_1522_bytes
= MAC_STX_NA
;
4100 estats
->frames_received_1523_9022_bytes
= MAC_STX_NA
;
4102 estats
->x_total_sent_bytes_hi
=
4103 le32_to_cpu(xstats
->total_sent_bytes
.hi
);
4104 estats
->x_total_sent_bytes_lo
=
4105 le32_to_cpu(xstats
->total_sent_bytes
.lo
);
4106 estats
->x_total_sent_pkts
= le32_to_cpu(xstats
->total_sent_pkts
);
4108 estats
->t_rcv_unicast_bytes_hi
=
4109 le32_to_cpu(tclient
->rcv_unicast_bytes
.hi
);
4110 estats
->t_rcv_unicast_bytes_lo
=
4111 le32_to_cpu(tclient
->rcv_unicast_bytes
.lo
);
4112 estats
->t_rcv_broadcast_bytes_hi
=
4113 le32_to_cpu(tclient
->rcv_broadcast_bytes
.hi
);
4114 estats
->t_rcv_broadcast_bytes_lo
=
4115 le32_to_cpu(tclient
->rcv_broadcast_bytes
.lo
);
4116 estats
->t_rcv_multicast_bytes_hi
=
4117 le32_to_cpu(tclient
->rcv_multicast_bytes
.hi
);
4118 estats
->t_rcv_multicast_bytes_lo
=
4119 le32_to_cpu(tclient
->rcv_multicast_bytes
.lo
);
4120 estats
->t_total_rcv_pkt
= le32_to_cpu(tclient
->total_rcv_pkts
);
4122 estats
->checksum_discard
= le32_to_cpu(tclient
->checksum_discard
);
4123 estats
->packets_too_big_discard
=
4124 le32_to_cpu(tclient
->packets_too_big_discard
);
4125 estats
->jabber_packets_received
= estats
->packets_too_big_discard
+
4126 estats
->stat_Dot3statsFramesTooLong
;
4127 estats
->no_buff_discard
= le32_to_cpu(tclient
->no_buff_discard
);
4128 estats
->ttl0_discard
= le32_to_cpu(tclient
->ttl0_discard
);
4129 estats
->mac_discard
= le32_to_cpu(tclient
->mac_discard
);
4130 estats
->mac_filter_discard
= le32_to_cpu(tstats
->mac_filter_discard
);
4131 estats
->xxoverflow_discard
= le32_to_cpu(tstats
->xxoverflow_discard
);
4132 estats
->brb_truncate_discard
=
4133 le32_to_cpu(tstats
->brb_truncate_discard
);
4135 estats
->brb_discard
+= nstats
->brb_discard
- bp
->old_brb_discard
;
4136 bp
->old_brb_discard
= nstats
->brb_discard
;
4138 estats
->brb_packet
= nstats
->brb_packet
;
4139 estats
->brb_truncate
= nstats
->brb_truncate
;
4140 estats
->flow_ctrl_discard
= nstats
->flow_ctrl_discard
;
4141 estats
->flow_ctrl_octets
= nstats
->flow_ctrl_octets
;
4142 estats
->flow_ctrl_packet
= nstats
->flow_ctrl_packet
;
4143 estats
->mng_discard
= nstats
->mng_discard
;
4144 estats
->mng_octet_inp
= nstats
->mng_octet_inp
;
4145 estats
->mng_octet_out
= nstats
->mng_octet_out
;
4146 estats
->mng_packet_inp
= nstats
->mng_packet_inp
;
4147 estats
->mng_packet_out
= nstats
->mng_packet_out
;
4148 estats
->pbf_octets
= nstats
->pbf_octets
;
4149 estats
->pbf_packet
= nstats
->pbf_packet
;
4150 estats
->safc_inp
= nstats
->safc_inp
;
4152 xstats
->done
.hi
= 0;
4153 tstats
->done
.hi
= 0;
4159 static void bnx2x_update_net_stats(struct bnx2x
*bp
)
4161 struct bnx2x_eth_stats
*estats
= bnx2x_sp(bp
, eth_stats
);
4162 struct net_device_stats
*nstats
= &bp
->dev
->stats
;
4164 nstats
->rx_packets
=
4165 bnx2x_hilo(&estats
->total_unicast_packets_received_hi
) +
4166 bnx2x_hilo(&estats
->total_multicast_packets_received_hi
) +
4167 bnx2x_hilo(&estats
->total_broadcast_packets_received_hi
);
4169 nstats
->tx_packets
=
4170 bnx2x_hilo(&estats
->total_unicast_packets_transmitted_hi
) +
4171 bnx2x_hilo(&estats
->total_multicast_packets_transmitted_hi
) +
4172 bnx2x_hilo(&estats
->total_broadcast_packets_transmitted_hi
);
4174 nstats
->rx_bytes
= bnx2x_hilo(&estats
->total_bytes_received_hi
);
4177 bnx2x_hilo(&estats
->total_bytes_transmitted_hi
);
4179 nstats
->rx_dropped
= estats
->checksum_discard
+
4180 estats
->mac_discard
;
4181 nstats
->tx_dropped
= 0;
4184 bnx2x_hilo(&estats
->total_multicast_packets_transmitted_hi
);
4186 nstats
->collisions
=
4187 estats
->single_collision_transmit_frames
+
4188 estats
->multiple_collision_transmit_frames
+
4189 estats
->late_collision_frames
+
4190 estats
->excessive_collision_frames
;
4192 nstats
->rx_length_errors
= estats
->runt_packets_received
+
4193 estats
->jabber_packets_received
;
4194 nstats
->rx_over_errors
= estats
->no_buff_discard
;
4195 nstats
->rx_crc_errors
= estats
->crc_receive_errors
;
4196 nstats
->rx_frame_errors
= estats
->alignment_errors
;
4197 nstats
->rx_fifo_errors
= estats
->brb_discard
+
4198 estats
->brb_truncate_discard
;
4199 nstats
->rx_missed_errors
= estats
->xxoverflow_discard
;
4201 nstats
->rx_errors
= nstats
->rx_length_errors
+
4202 nstats
->rx_over_errors
+
4203 nstats
->rx_crc_errors
+
4204 nstats
->rx_frame_errors
+
4205 nstats
->rx_fifo_errors
;
4207 nstats
->tx_aborted_errors
= estats
->late_collision_frames
+
4208 estats
->excessive_collision_frames
;
4209 nstats
->tx_carrier_errors
= estats
->false_carrier_detections
;
4210 nstats
->tx_fifo_errors
= 0;
4211 nstats
->tx_heartbeat_errors
= 0;
4212 nstats
->tx_window_errors
= 0;
4214 nstats
->tx_errors
= nstats
->tx_aborted_errors
+
4215 nstats
->tx_carrier_errors
;
4217 estats
->mac_stx_start
= ++estats
->mac_stx_end
;
4220 static void bnx2x_update_stats(struct bnx2x
*bp
)
4224 if (!bnx2x_update_storm_stats(bp
)) {
4226 if (bp
->phy_flags
& PHY_BMAC_FLAG
) {
4227 bnx2x_update_bmac_stats(bp
);
4229 } else if (bp
->phy_flags
& PHY_EMAC_FLAG
) {
4230 bnx2x_update_emac_stats(bp
);
4232 } else { /* unreached */
4233 BNX2X_ERR("no MAC active\n");
4237 bnx2x_update_net_stats(bp
);
4240 if (bp
->msglevel
& NETIF_MSG_TIMER
) {
4241 struct bnx2x_eth_stats
*estats
= bnx2x_sp(bp
, eth_stats
);
4242 struct net_device_stats
*nstats
= &bp
->dev
->stats
;
4244 printk(KERN_DEBUG
"%s:\n", bp
->dev
->name
);
4245 printk(KERN_DEBUG
" tx avail (%4x) tx hc idx (%x)"
4247 bnx2x_tx_avail(bp
->fp
),
4248 *bp
->fp
->tx_cons_sb
, nstats
->tx_packets
);
4249 printk(KERN_DEBUG
" rx usage (%4x) rx hc idx (%x)"
4251 (u16
)(*bp
->fp
->rx_cons_sb
- bp
->fp
->rx_comp_cons
),
4252 *bp
->fp
->rx_cons_sb
, nstats
->rx_packets
);
4253 printk(KERN_DEBUG
" %s (Xoff events %u) brb drops %u\n",
4254 netif_queue_stopped(bp
->dev
)? "Xoff" : "Xon",
4255 estats
->driver_xoff
, estats
->brb_discard
);
4256 printk(KERN_DEBUG
"tstats: checksum_discard %u "
4257 "packets_too_big_discard %u no_buff_discard %u "
4258 "mac_discard %u mac_filter_discard %u "
4259 "xxovrflow_discard %u brb_truncate_discard %u "
4260 "ttl0_discard %u\n",
4261 estats
->checksum_discard
,
4262 estats
->packets_too_big_discard
,
4263 estats
->no_buff_discard
, estats
->mac_discard
,
4264 estats
->mac_filter_discard
, estats
->xxoverflow_discard
,
4265 estats
->brb_truncate_discard
, estats
->ttl0_discard
);
4267 for_each_queue(bp
, i
) {
4268 printk(KERN_DEBUG
"[%d]: %lu\t%lu\t%lu\n", i
,
4269 bnx2x_fp(bp
, i
, tx_pkt
),
4270 bnx2x_fp(bp
, i
, rx_pkt
),
4271 bnx2x_fp(bp
, i
, rx_calls
));
4275 if (bp
->state
!= BNX2X_STATE_OPEN
) {
4276 DP(BNX2X_MSG_STATS
, "state is %x, returning\n", bp
->state
);
4280 #ifdef BNX2X_STOP_ON_ERROR
4281 if (unlikely(bp
->panic
))
4286 if (bp
->executer_idx
) {
4287 struct dmae_command
*dmae
= &bp
->dmae
;
4288 int port
= bp
->port
;
4289 int loader_idx
= port
* 8;
4291 memset(dmae
, 0, sizeof(struct dmae_command
));
4293 dmae
->opcode
= (DMAE_CMD_SRC_PCI
| DMAE_CMD_DST_GRC
|
4294 DMAE_CMD_C_DST_GRC
| DMAE_CMD_C_ENABLE
|
4295 DMAE_CMD_DST_RESET
|
4297 DMAE_CMD_ENDIANITY_B_DW_SWAP
|
4299 DMAE_CMD_ENDIANITY_DW_SWAP
|
4301 (port
? DMAE_CMD_PORT_1
: DMAE_CMD_PORT_0
));
4302 dmae
->src_addr_lo
= U64_LO(bnx2x_sp_mapping(bp
, dmae
[0]));
4303 dmae
->src_addr_hi
= U64_HI(bnx2x_sp_mapping(bp
, dmae
[0]));
4304 dmae
->dst_addr_lo
= (DMAE_REG_CMD_MEM
+
4305 sizeof(struct dmae_command
) *
4306 (loader_idx
+ 1)) >> 2;
4307 dmae
->dst_addr_hi
= 0;
4308 dmae
->len
= sizeof(struct dmae_command
) >> 2;
4309 dmae
->len
--; /* !!! for A0/1 only */
4310 dmae
->comp_addr_lo
= dmae_reg_go_c
[loader_idx
+ 1] >> 2;
4311 dmae
->comp_addr_hi
= 0;
4314 bnx2x_post_dmae(bp
, dmae
, loader_idx
);
4317 if (bp
->stats_state
!= STATS_STATE_ENABLE
) {
4318 bp
->stats_state
= STATS_STATE_DISABLE
;
4322 if (bnx2x_sp_post(bp
, RAMROD_CMD_ID_ETH_STAT_QUERY
, 0, 0, 0, 0) == 0) {
4323 /* stats ramrod has it's own slot on the spe */
4325 bp
->stat_pending
= 1;
4329 static void bnx2x_timer(unsigned long data
)
4331 struct bnx2x
*bp
= (struct bnx2x
*) data
;
4333 if (!netif_running(bp
->dev
))
4336 if (atomic_read(&bp
->intr_sem
) != 0)
4337 goto bnx2x_restart_timer
;
4340 struct bnx2x_fastpath
*fp
= &bp
->fp
[0];
4343 bnx2x_tx_int(fp
, 1000);
4344 rc
= bnx2x_rx_int(fp
, 1000);
4347 if (!nomcp
&& (bp
->bc_ver
>= 0x040003)) {
4348 int port
= bp
->port
;
4352 ++bp
->fw_drv_pulse_wr_seq
;
4353 bp
->fw_drv_pulse_wr_seq
&= DRV_PULSE_SEQ_MASK
;
4354 /* TBD - add SYSTEM_TIME */
4355 drv_pulse
= bp
->fw_drv_pulse_wr_seq
;
4356 SHMEM_WR(bp
, drv_fw_mb
[port
].drv_pulse_mb
, drv_pulse
);
4358 mcp_pulse
= (SHMEM_RD(bp
, drv_fw_mb
[port
].mcp_pulse_mb
) &
4359 MCP_PULSE_SEQ_MASK
);
4360 /* The delta between driver pulse and mcp response
4361 * should be 1 (before mcp response) or 0 (after mcp response)
4363 if ((drv_pulse
!= mcp_pulse
) &&
4364 (drv_pulse
!= ((mcp_pulse
+ 1) & MCP_PULSE_SEQ_MASK
))) {
4365 /* someone lost a heartbeat... */
4366 BNX2X_ERR("drv_pulse (0x%x) != mcp_pulse (0x%x)\n",
4367 drv_pulse
, mcp_pulse
);
4371 if (bp
->stats_state
== STATS_STATE_DISABLE
)
4372 goto bnx2x_restart_timer
;
4374 bnx2x_update_stats(bp
);
4376 bnx2x_restart_timer
:
4377 mod_timer(&bp
->timer
, jiffies
+ bp
->current_interval
);
4380 /* end of Statistics */
4385 * nic init service functions
4388 static void bnx2x_init_sb(struct bnx2x
*bp
, struct host_status_block
*sb
,
4389 dma_addr_t mapping
, int id
)
4391 int port
= bp
->port
;
4396 section
= ((u64
)mapping
) + offsetof(struct host_status_block
,
4398 sb
->u_status_block
.status_block_id
= id
;
4400 REG_WR(bp
, BAR_USTRORM_INTMEM
+
4401 USTORM_SB_HOST_SB_ADDR_OFFSET(port
, id
), U64_LO(section
));
4402 REG_WR(bp
, BAR_USTRORM_INTMEM
+
4403 ((USTORM_SB_HOST_SB_ADDR_OFFSET(port
, id
)) + 4),
4406 for (index
= 0; index
< HC_USTORM_SB_NUM_INDICES
; index
++)
4407 REG_WR16(bp
, BAR_USTRORM_INTMEM
+
4408 USTORM_SB_HC_DISABLE_OFFSET(port
, id
, index
), 0x1);
4411 section
= ((u64
)mapping
) + offsetof(struct host_status_block
,
4413 sb
->c_status_block
.status_block_id
= id
;
4415 REG_WR(bp
, BAR_CSTRORM_INTMEM
+
4416 CSTORM_SB_HOST_SB_ADDR_OFFSET(port
, id
), U64_LO(section
));
4417 REG_WR(bp
, BAR_CSTRORM_INTMEM
+
4418 ((CSTORM_SB_HOST_SB_ADDR_OFFSET(port
, id
)) + 4),
4421 for (index
= 0; index
< HC_CSTORM_SB_NUM_INDICES
; index
++)
4422 REG_WR16(bp
, BAR_CSTRORM_INTMEM
+
4423 CSTORM_SB_HC_DISABLE_OFFSET(port
, id
, index
), 0x1);
4425 bnx2x_ack_sb(bp
, id
, CSTORM_ID
, 0, IGU_INT_ENABLE
, 0);
4428 static void bnx2x_init_def_sb(struct bnx2x
*bp
,
4429 struct host_def_status_block
*def_sb
,
4430 dma_addr_t mapping
, int id
)
4432 int port
= bp
->port
;
4433 int index
, val
, reg_offset
;
4437 section
= ((u64
)mapping
) + offsetof(struct host_def_status_block
,
4438 atten_status_block
);
4439 def_sb
->atten_status_block
.status_block_id
= id
;
4441 reg_offset
= (port
? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0
:
4442 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0
);
4444 for (index
= 0; index
< 3; index
++) {
4445 bp
->attn_group
[index
].sig
[0] = REG_RD(bp
,
4446 reg_offset
+ 0x10*index
);
4447 bp
->attn_group
[index
].sig
[1] = REG_RD(bp
,
4448 reg_offset
+ 0x4 + 0x10*index
);
4449 bp
->attn_group
[index
].sig
[2] = REG_RD(bp
,
4450 reg_offset
+ 0x8 + 0x10*index
);
4451 bp
->attn_group
[index
].sig
[3] = REG_RD(bp
,
4452 reg_offset
+ 0xc + 0x10*index
);
4455 bp
->aeu_mask
= REG_RD(bp
, (port
? MISC_REG_AEU_MASK_ATTN_FUNC_1
:
4456 MISC_REG_AEU_MASK_ATTN_FUNC_0
));
4458 reg_offset
= (port
? HC_REG_ATTN_MSG1_ADDR_L
:
4459 HC_REG_ATTN_MSG0_ADDR_L
);
4461 REG_WR(bp
, reg_offset
, U64_LO(section
));
4462 REG_WR(bp
, reg_offset
+ 4, U64_HI(section
));
4464 reg_offset
= (port
? HC_REG_ATTN_NUM_P1
: HC_REG_ATTN_NUM_P0
);
4466 val
= REG_RD(bp
, reg_offset
);
4468 REG_WR(bp
, reg_offset
, val
);
4471 section
= ((u64
)mapping
) + offsetof(struct host_def_status_block
,
4472 u_def_status_block
);
4473 def_sb
->u_def_status_block
.status_block_id
= id
;
4475 REG_WR(bp
, BAR_USTRORM_INTMEM
+
4476 USTORM_DEF_SB_HOST_SB_ADDR_OFFSET(port
), U64_LO(section
));
4477 REG_WR(bp
, BAR_USTRORM_INTMEM
+
4478 ((USTORM_DEF_SB_HOST_SB_ADDR_OFFSET(port
)) + 4),
4480 REG_WR(bp
, BAR_USTRORM_INTMEM
+ USTORM_HC_BTR_OFFSET(port
),
4483 for (index
= 0; index
< HC_USTORM_DEF_SB_NUM_INDICES
; index
++)
4484 REG_WR16(bp
, BAR_USTRORM_INTMEM
+
4485 USTORM_DEF_SB_HC_DISABLE_OFFSET(port
, index
), 0x1);
4488 section
= ((u64
)mapping
) + offsetof(struct host_def_status_block
,
4489 c_def_status_block
);
4490 def_sb
->c_def_status_block
.status_block_id
= id
;
4492 REG_WR(bp
, BAR_CSTRORM_INTMEM
+
4493 CSTORM_DEF_SB_HOST_SB_ADDR_OFFSET(port
), U64_LO(section
));
4494 REG_WR(bp
, BAR_CSTRORM_INTMEM
+
4495 ((CSTORM_DEF_SB_HOST_SB_ADDR_OFFSET(port
)) + 4),
4497 REG_WR(bp
, BAR_CSTRORM_INTMEM
+ CSTORM_HC_BTR_OFFSET(port
),
4500 for (index
= 0; index
< HC_CSTORM_DEF_SB_NUM_INDICES
; index
++)
4501 REG_WR16(bp
, BAR_CSTRORM_INTMEM
+
4502 CSTORM_DEF_SB_HC_DISABLE_OFFSET(port
, index
), 0x1);
4505 section
= ((u64
)mapping
) + offsetof(struct host_def_status_block
,
4506 t_def_status_block
);
4507 def_sb
->t_def_status_block
.status_block_id
= id
;
4509 REG_WR(bp
, BAR_TSTRORM_INTMEM
+
4510 TSTORM_DEF_SB_HOST_SB_ADDR_OFFSET(port
), U64_LO(section
));
4511 REG_WR(bp
, BAR_TSTRORM_INTMEM
+
4512 ((TSTORM_DEF_SB_HOST_SB_ADDR_OFFSET(port
)) + 4),
4514 REG_WR(bp
, BAR_TSTRORM_INTMEM
+ TSTORM_HC_BTR_OFFSET(port
),
4517 for (index
= 0; index
< HC_TSTORM_DEF_SB_NUM_INDICES
; index
++)
4518 REG_WR16(bp
, BAR_TSTRORM_INTMEM
+
4519 TSTORM_DEF_SB_HC_DISABLE_OFFSET(port
, index
), 0x1);
4522 section
= ((u64
)mapping
) + offsetof(struct host_def_status_block
,
4523 x_def_status_block
);
4524 def_sb
->x_def_status_block
.status_block_id
= id
;
4526 REG_WR(bp
, BAR_XSTRORM_INTMEM
+
4527 XSTORM_DEF_SB_HOST_SB_ADDR_OFFSET(port
), U64_LO(section
));
4528 REG_WR(bp
, BAR_XSTRORM_INTMEM
+
4529 ((XSTORM_DEF_SB_HOST_SB_ADDR_OFFSET(port
)) + 4),
4531 REG_WR(bp
, BAR_XSTRORM_INTMEM
+ XSTORM_HC_BTR_OFFSET(port
),
4534 for (index
= 0; index
< HC_XSTORM_DEF_SB_NUM_INDICES
; index
++)
4535 REG_WR16(bp
, BAR_XSTRORM_INTMEM
+
4536 XSTORM_DEF_SB_HC_DISABLE_OFFSET(port
, index
), 0x1);
4538 bnx2x_ack_sb(bp
, id
, CSTORM_ID
, 0, IGU_INT_ENABLE
, 0);
4541 static void bnx2x_update_coalesce(struct bnx2x
*bp
)
4543 int port
= bp
->port
;
4546 for_each_queue(bp
, i
) {
4548 /* HC_INDEX_U_ETH_RX_CQ_CONS */
4549 REG_WR8(bp
, BAR_USTRORM_INTMEM
+
4550 USTORM_SB_HC_TIMEOUT_OFFSET(port
, i
,
4551 HC_INDEX_U_ETH_RX_CQ_CONS
),
4552 bp
->rx_ticks_int
/12);
4553 REG_WR16(bp
, BAR_USTRORM_INTMEM
+
4554 USTORM_SB_HC_DISABLE_OFFSET(port
, i
,
4555 HC_INDEX_U_ETH_RX_CQ_CONS
),
4556 bp
->rx_ticks_int
? 0 : 1);
4558 /* HC_INDEX_C_ETH_TX_CQ_CONS */
4559 REG_WR8(bp
, BAR_CSTRORM_INTMEM
+
4560 CSTORM_SB_HC_TIMEOUT_OFFSET(port
, i
,
4561 HC_INDEX_C_ETH_TX_CQ_CONS
),
4562 bp
->tx_ticks_int
/12);
4563 REG_WR16(bp
, BAR_CSTRORM_INTMEM
+
4564 CSTORM_SB_HC_DISABLE_OFFSET(port
, i
,
4565 HC_INDEX_C_ETH_TX_CQ_CONS
),
4566 bp
->tx_ticks_int
? 0 : 1);
4570 static void bnx2x_init_rx_rings(struct bnx2x
*bp
)
4574 int port
= bp
->port
;
4576 bp
->rx_buf_use_size
= bp
->dev
->mtu
;
4578 bp
->rx_buf_use_size
+= bp
->rx_offset
+ ETH_OVREHEAD
;
4579 bp
->rx_buf_size
= bp
->rx_buf_use_size
+ 64;
4581 for_each_queue(bp
, j
) {
4582 struct bnx2x_fastpath
*fp
= &bp
->fp
[j
];
4585 fp
->rx_cons_sb
= BNX2X_RX_SB_INDEX
;
4587 for (i
= 1; i
<= NUM_RX_RINGS
; i
++) {
4588 struct eth_rx_bd
*rx_bd
;
4590 rx_bd
= &fp
->rx_desc_ring
[RX_DESC_CNT
* i
- 2];
4592 cpu_to_le32(U64_HI(fp
->rx_desc_mapping
+
4593 BCM_PAGE_SIZE
*(i
% NUM_RX_RINGS
)));
4595 cpu_to_le32(U64_LO(fp
->rx_desc_mapping
+
4596 BCM_PAGE_SIZE
*(i
% NUM_RX_RINGS
)));
4600 for (i
= 1; i
<= NUM_RCQ_RINGS
; i
++) {
4601 struct eth_rx_cqe_next_page
*nextpg
;
4603 nextpg
= (struct eth_rx_cqe_next_page
*)
4604 &fp
->rx_comp_ring
[RCQ_DESC_CNT
* i
- 1];
4606 cpu_to_le32(U64_HI(fp
->rx_comp_mapping
+
4607 BCM_PAGE_SIZE
*(i
% NUM_RCQ_RINGS
)));
4609 cpu_to_le32(U64_LO(fp
->rx_comp_mapping
+
4610 BCM_PAGE_SIZE
*(i
% NUM_RCQ_RINGS
)));
4613 /* rx completion queue */
4614 fp
->rx_comp_cons
= ring_prod
= 0;
4616 for (i
= 0; i
< bp
->rx_ring_size
; i
++) {
4617 if (bnx2x_alloc_rx_skb(bp
, fp
, ring_prod
) < 0) {
4618 BNX2X_ERR("was only able to allocate "
4622 ring_prod
= NEXT_RX_IDX(ring_prod
);
4623 BUG_TRAP(ring_prod
> i
);
4626 fp
->rx_bd_prod
= fp
->rx_comp_prod
= ring_prod
;
4627 fp
->rx_pkt
= fp
->rx_calls
= 0;
4629 /* Warning! this will genrate an interrupt (to the TSTORM) */
4630 /* must only be done when chip is initialized */
4631 REG_WR(bp
, BAR_TSTRORM_INTMEM
+
4632 TSTORM_RCQ_PROD_OFFSET(port
, j
), ring_prod
);
4636 REG_WR(bp
, BAR_USTRORM_INTMEM
+
4637 USTORM_MEM_WORKAROUND_ADDRESS_OFFSET(port
),
4638 U64_LO(fp
->rx_comp_mapping
));
4639 REG_WR(bp
, BAR_USTRORM_INTMEM
+
4640 USTORM_MEM_WORKAROUND_ADDRESS_OFFSET(port
) + 4,
4641 U64_HI(fp
->rx_comp_mapping
));
4645 static void bnx2x_init_tx_ring(struct bnx2x
*bp
)
4649 for_each_queue(bp
, j
) {
4650 struct bnx2x_fastpath
*fp
= &bp
->fp
[j
];
4652 for (i
= 1; i
<= NUM_TX_RINGS
; i
++) {
4653 struct eth_tx_bd
*tx_bd
=
4654 &fp
->tx_desc_ring
[TX_DESC_CNT
* i
- 1];
4657 cpu_to_le32(U64_HI(fp
->tx_desc_mapping
+
4658 BCM_PAGE_SIZE
*(i
% NUM_TX_RINGS
)));
4660 cpu_to_le32(U64_LO(fp
->tx_desc_mapping
+
4661 BCM_PAGE_SIZE
*(i
% NUM_TX_RINGS
)));
4664 fp
->tx_pkt_prod
= 0;
4665 fp
->tx_pkt_cons
= 0;
4668 fp
->tx_cons_sb
= BNX2X_TX_SB_INDEX
;
4673 static void bnx2x_init_sp_ring(struct bnx2x
*bp
)
4675 int port
= bp
->port
;
4677 spin_lock_init(&bp
->spq_lock
);
4679 bp
->spq_left
= MAX_SPQ_PENDING
;
4680 bp
->spq_prod_idx
= 0;
4681 bp
->dsb_sp_prod_idx
= 0;
4682 bp
->dsb_sp_prod
= BNX2X_SP_DSB_INDEX
;
4683 bp
->spq_prod_bd
= bp
->spq
;
4684 bp
->spq_last_bd
= bp
->spq_prod_bd
+ MAX_SP_DESC_CNT
;
4686 REG_WR(bp
, BAR_XSTRORM_INTMEM
+ XSTORM_SPQ_PAGE_BASE_OFFSET(port
),
4687 U64_LO(bp
->spq_mapping
));
4688 REG_WR(bp
, BAR_XSTRORM_INTMEM
+ XSTORM_SPQ_PAGE_BASE_OFFSET(port
) + 4,
4689 U64_HI(bp
->spq_mapping
));
4691 REG_WR(bp
, XSEM_REG_FAST_MEMORY
+ XSTORM_SPQ_PROD_OFFSET(port
),
4695 static void bnx2x_init_context(struct bnx2x
*bp
)
4699 for_each_queue(bp
, i
) {
4700 struct eth_context
*context
= bnx2x_sp(bp
, context
[i
].eth
);
4701 struct bnx2x_fastpath
*fp
= &bp
->fp
[i
];
4703 context
->xstorm_st_context
.tx_bd_page_base_hi
=
4704 U64_HI(fp
->tx_desc_mapping
);
4705 context
->xstorm_st_context
.tx_bd_page_base_lo
=
4706 U64_LO(fp
->tx_desc_mapping
);
4707 context
->xstorm_st_context
.db_data_addr_hi
=
4708 U64_HI(fp
->tx_prods_mapping
);
4709 context
->xstorm_st_context
.db_data_addr_lo
=
4710 U64_LO(fp
->tx_prods_mapping
);
4712 context
->ustorm_st_context
.rx_bd_page_base_hi
=
4713 U64_HI(fp
->rx_desc_mapping
);
4714 context
->ustorm_st_context
.rx_bd_page_base_lo
=
4715 U64_LO(fp
->rx_desc_mapping
);
4716 context
->ustorm_st_context
.status_block_id
= i
;
4717 context
->ustorm_st_context
.sb_index_number
=
4718 HC_INDEX_U_ETH_RX_CQ_CONS
;
4719 context
->ustorm_st_context
.rcq_base_address_hi
=
4720 U64_HI(fp
->rx_comp_mapping
);
4721 context
->ustorm_st_context
.rcq_base_address_lo
=
4722 U64_LO(fp
->rx_comp_mapping
);
4723 context
->ustorm_st_context
.flags
=
4724 USTORM_ETH_ST_CONTEXT_ENABLE_MC_ALIGNMENT
;
4725 context
->ustorm_st_context
.mc_alignment_size
= 64;
4726 context
->ustorm_st_context
.num_rss
= bp
->num_queues
;
4728 context
->cstorm_st_context
.sb_index_number
=
4729 HC_INDEX_C_ETH_TX_CQ_CONS
;
4730 context
->cstorm_st_context
.status_block_id
= i
;
4732 context
->xstorm_ag_context
.cdu_reserved
=
4733 CDU_RSRVD_VALUE_TYPE_A(HW_CID(bp
, i
),
4734 CDU_REGION_NUMBER_XCM_AG
,
4735 ETH_CONNECTION_TYPE
);
4736 context
->ustorm_ag_context
.cdu_usage
=
4737 CDU_RSRVD_VALUE_TYPE_A(HW_CID(bp
, i
),
4738 CDU_REGION_NUMBER_UCM_AG
,
4739 ETH_CONNECTION_TYPE
);
4743 static void bnx2x_init_ind_table(struct bnx2x
*bp
)
4745 int port
= bp
->port
;
4751 for (i
= 0; i
< TSTORM_INDIRECTION_TABLE_SIZE
; i
++)
4752 REG_WR8(bp
, TSTORM_INDIRECTION_TABLE_OFFSET(port
) + i
,
4753 i
% bp
->num_queues
);
4755 REG_WR(bp
, PRS_REG_A_PRSU_20
, 0xf);
4758 static void bnx2x_set_storm_rx_mode(struct bnx2x
*bp
)
4760 int mode
= bp
->rx_mode
;
4761 int port
= bp
->port
;
4762 struct tstorm_eth_mac_filter_config tstorm_mac_filter
= {0};
4765 DP(NETIF_MSG_RX_STATUS
, "rx mode is %d\n", mode
);
4768 case BNX2X_RX_MODE_NONE
: /* no Rx */
4769 tstorm_mac_filter
.ucast_drop_all
= 1;
4770 tstorm_mac_filter
.mcast_drop_all
= 1;
4771 tstorm_mac_filter
.bcast_drop_all
= 1;
4773 case BNX2X_RX_MODE_NORMAL
:
4774 tstorm_mac_filter
.bcast_accept_all
= 1;
4776 case BNX2X_RX_MODE_ALLMULTI
:
4777 tstorm_mac_filter
.mcast_accept_all
= 1;
4778 tstorm_mac_filter
.bcast_accept_all
= 1;
4780 case BNX2X_RX_MODE_PROMISC
:
4781 tstorm_mac_filter
.ucast_accept_all
= 1;
4782 tstorm_mac_filter
.mcast_accept_all
= 1;
4783 tstorm_mac_filter
.bcast_accept_all
= 1;
4786 BNX2X_ERR("bad rx mode (%d)\n", mode
);
4789 for (i
= 0; i
< sizeof(struct tstorm_eth_mac_filter_config
)/4; i
++) {
4790 REG_WR(bp
, BAR_TSTRORM_INTMEM
+
4791 TSTORM_MAC_FILTER_CONFIG_OFFSET(port
) + i
* 4,
4792 ((u32
*)&tstorm_mac_filter
)[i
]);
4794 /* DP(NETIF_MSG_IFUP, "tstorm_mac_filter[%d]: 0x%08x\n", i,
4795 ((u32 *)&tstorm_mac_filter)[i]); */
4799 static void bnx2x_set_client_config(struct bnx2x
*bp
, int client_id
)
4802 int mode
= bp
->rx_mode
;
4804 int port
= bp
->port
;
4805 struct tstorm_eth_client_config tstorm_client
= {0};
4807 tstorm_client
.mtu
= bp
->dev
->mtu
;
4808 tstorm_client
.statistics_counter_id
= 0;
4809 tstorm_client
.config_flags
=
4810 TSTORM_ETH_CLIENT_CONFIG_STATSITICS_ENABLE
;
4812 if (mode
&& bp
->vlgrp
) {
4813 tstorm_client
.config_flags
|=
4814 TSTORM_ETH_CLIENT_CONFIG_VLAN_REMOVAL_ENABLE
;
4815 DP(NETIF_MSG_IFUP
, "vlan removal enabled\n");
4818 tstorm_client
.drop_flags
= (TSTORM_ETH_CLIENT_CONFIG_DROP_IP_CS_ERR
|
4819 TSTORM_ETH_CLIENT_CONFIG_DROP_TCP_CS_ERR
|
4820 TSTORM_ETH_CLIENT_CONFIG_DROP_UDP_CS_ERR
|
4821 TSTORM_ETH_CLIENT_CONFIG_DROP_MAC_ERR
);
4823 REG_WR(bp
, BAR_TSTRORM_INTMEM
+
4824 TSTORM_CLIENT_CONFIG_OFFSET(port
, client_id
),
4825 ((u32
*)&tstorm_client
)[0]);
4826 REG_WR(bp
, BAR_TSTRORM_INTMEM
+
4827 TSTORM_CLIENT_CONFIG_OFFSET(port
, client_id
) + 4,
4828 ((u32
*)&tstorm_client
)[1]);
4830 /* DP(NETIF_MSG_IFUP, "tstorm_client: 0x%08x 0x%08x\n",
4831 ((u32 *)&tstorm_client)[0], ((u32 *)&tstorm_client)[1]); */
4834 static void bnx2x_init_internal(struct bnx2x
*bp
)
4836 int port
= bp
->port
;
4837 struct tstorm_eth_function_common_config tstorm_config
= {0};
4838 struct stats_indication_flags stats_flags
= {0};
4842 tstorm_config
.config_flags
= MULTI_FLAGS
;
4843 tstorm_config
.rss_result_mask
= MULTI_MASK
;
4846 REG_WR(bp
, BAR_TSTRORM_INTMEM
+
4847 TSTORM_FUNCTION_COMMON_CONFIG_OFFSET(port
),
4848 (*(u32
*)&tstorm_config
));
4850 /* DP(NETIF_MSG_IFUP, "tstorm_config: 0x%08x\n",
4851 (*(u32 *)&tstorm_config)); */
4853 bp
->rx_mode
= BNX2X_RX_MODE_NONE
; /* no rx untill link is up */
4854 bnx2x_set_storm_rx_mode(bp
);
4856 for_each_queue(bp
, i
)
4857 bnx2x_set_client_config(bp
, i
);
4860 stats_flags
.collect_eth
= cpu_to_le32(1);
4862 REG_WR(bp
, BAR_XSTRORM_INTMEM
+ XSTORM_STATS_FLAGS_OFFSET(port
),
4863 ((u32
*)&stats_flags
)[0]);
4864 REG_WR(bp
, BAR_XSTRORM_INTMEM
+ XSTORM_STATS_FLAGS_OFFSET(port
) + 4,
4865 ((u32
*)&stats_flags
)[1]);
4867 REG_WR(bp
, BAR_TSTRORM_INTMEM
+ TSTORM_STATS_FLAGS_OFFSET(port
),
4868 ((u32
*)&stats_flags
)[0]);
4869 REG_WR(bp
, BAR_TSTRORM_INTMEM
+ TSTORM_STATS_FLAGS_OFFSET(port
) + 4,
4870 ((u32
*)&stats_flags
)[1]);
4872 REG_WR(bp
, BAR_CSTRORM_INTMEM
+ CSTORM_STATS_FLAGS_OFFSET(port
),
4873 ((u32
*)&stats_flags
)[0]);
4874 REG_WR(bp
, BAR_CSTRORM_INTMEM
+ CSTORM_STATS_FLAGS_OFFSET(port
) + 4,
4875 ((u32
*)&stats_flags
)[1]);
4877 /* DP(NETIF_MSG_IFUP, "stats_flags: 0x%08x 0x%08x\n",
4878 ((u32 *)&stats_flags)[0], ((u32 *)&stats_flags)[1]); */
4881 static void bnx2x_nic_init(struct bnx2x
*bp
)
4885 for_each_queue(bp
, i
) {
4886 struct bnx2x_fastpath
*fp
= &bp
->fp
[i
];
4888 fp
->state
= BNX2X_FP_STATE_CLOSED
;
4889 DP(NETIF_MSG_IFUP
, "bnx2x_init_sb(%p,%p,%d);\n",
4890 bp
, fp
->status_blk
, i
);
4892 bnx2x_init_sb(bp
, fp
->status_blk
, fp
->status_blk_mapping
, i
);
4895 bnx2x_init_def_sb(bp
, bp
->def_status_blk
,
4896 bp
->def_status_blk_mapping
, 0x10);
4897 bnx2x_update_coalesce(bp
);
4898 bnx2x_init_rx_rings(bp
);
4899 bnx2x_init_tx_ring(bp
);
4900 bnx2x_init_sp_ring(bp
);
4901 bnx2x_init_context(bp
);
4902 bnx2x_init_internal(bp
);
4903 bnx2x_init_stats(bp
);
4904 bnx2x_init_ind_table(bp
);
4905 bnx2x_enable_int(bp
);
4909 /* end of nic init */
4912 * gzip service functions
4915 static int bnx2x_gunzip_init(struct bnx2x
*bp
)
4917 bp
->gunzip_buf
= pci_alloc_consistent(bp
->pdev
, FW_BUF_SIZE
,
4918 &bp
->gunzip_mapping
);
4919 if (bp
->gunzip_buf
== NULL
)
4922 bp
->strm
= kmalloc(sizeof(*bp
->strm
), GFP_KERNEL
);
4923 if (bp
->strm
== NULL
)
4926 bp
->strm
->workspace
= kmalloc(zlib_inflate_workspacesize(),
4928 if (bp
->strm
->workspace
== NULL
)
4938 pci_free_consistent(bp
->pdev
, FW_BUF_SIZE
, bp
->gunzip_buf
,
4939 bp
->gunzip_mapping
);
4940 bp
->gunzip_buf
= NULL
;
4943 printk(KERN_ERR PFX
"%s: Cannot allocate firmware buffer for"
4944 " uncompression\n", bp
->dev
->name
);
4948 static void bnx2x_gunzip_end(struct bnx2x
*bp
)
4950 kfree(bp
->strm
->workspace
);
4955 if (bp
->gunzip_buf
) {
4956 pci_free_consistent(bp
->pdev
, FW_BUF_SIZE
, bp
->gunzip_buf
,
4957 bp
->gunzip_mapping
);
4958 bp
->gunzip_buf
= NULL
;
4962 static int bnx2x_gunzip(struct bnx2x
*bp
, u8
*zbuf
, int len
)
4966 /* check gzip header */
4967 if ((zbuf
[0] != 0x1f) || (zbuf
[1] != 0x8b) || (zbuf
[2] != Z_DEFLATED
))
4974 if (zbuf
[3] & FNAME
)
4975 while ((zbuf
[n
++] != 0) && (n
< len
));
4977 bp
->strm
->next_in
= zbuf
+ n
;
4978 bp
->strm
->avail_in
= len
- n
;
4979 bp
->strm
->next_out
= bp
->gunzip_buf
;
4980 bp
->strm
->avail_out
= FW_BUF_SIZE
;
4982 rc
= zlib_inflateInit2(bp
->strm
, -MAX_WBITS
);
4986 rc
= zlib_inflate(bp
->strm
, Z_FINISH
);
4987 if ((rc
!= Z_OK
) && (rc
!= Z_STREAM_END
))
4988 printk(KERN_ERR PFX
"%s: Firmware decompression error: %s\n",
4989 bp
->dev
->name
, bp
->strm
->msg
);
4991 bp
->gunzip_outlen
= (FW_BUF_SIZE
- bp
->strm
->avail_out
);
4992 if (bp
->gunzip_outlen
& 0x3)
4993 printk(KERN_ERR PFX
"%s: Firmware decompression error:"
4994 " gunzip_outlen (%d) not aligned\n",
4995 bp
->dev
->name
, bp
->gunzip_outlen
);
4996 bp
->gunzip_outlen
>>= 2;
4998 zlib_inflateEnd(bp
->strm
);
5000 if (rc
== Z_STREAM_END
)
5006 /* nic load/unload */
5009 * general service functions
5012 /* send a NIG loopback debug packet */
5013 static void bnx2x_lb_pckt(struct bnx2x
*bp
)
5019 /* Ethernet source and destination addresses */
5021 wb_write
[0] = 0x55555555;
5022 wb_write
[1] = 0x55555555;
5023 wb_write
[2] = 0x20; /* SOP */
5024 REG_WR_DMAE(bp
, NIG_REG_DEBUG_PACKET_LB
, wb_write
, 3);
5026 REG_WR_IND(bp
, NIG_REG_DEBUG_PACKET_LB
, 0x55555555);
5027 REG_WR_IND(bp
, NIG_REG_DEBUG_PACKET_LB
+ 4, 0x55555555);
5029 REG_WR_IND(bp
, NIG_REG_DEBUG_PACKET_LB
+ 8, 0x20);
5032 /* NON-IP protocol */
5034 wb_write
[0] = 0x09000000;
5035 wb_write
[1] = 0x55555555;
5036 wb_write
[2] = 0x10; /* EOP, eop_bvalid = 0 */
5037 REG_WR_DMAE(bp
, NIG_REG_DEBUG_PACKET_LB
, wb_write
, 3);
5039 REG_WR_IND(bp
, NIG_REG_DEBUG_PACKET_LB
, 0x09000000);
5040 REG_WR_IND(bp
, NIG_REG_DEBUG_PACKET_LB
+ 4, 0x55555555);
5041 /* EOP, eop_bvalid = 0 */
5042 REG_WR_IND(bp
, NIG_REG_DEBUG_PACKET_LB
+ 8, 0x10);
5046 /* some of the internal memories
5047 * are not directly readable from the driver
5048 * to test them we send debug packets
5050 static int bnx2x_int_mem_test(struct bnx2x
*bp
)
5056 switch (CHIP_REV(bp
)) {
5068 DP(NETIF_MSG_HW
, "start part1\n");
5070 /* Disable inputs of parser neighbor blocks */
5071 REG_WR(bp
, TSDM_REG_ENABLE_IN1
, 0x0);
5072 REG_WR(bp
, TCM_REG_PRS_IFEN
, 0x0);
5073 REG_WR(bp
, CFC_REG_DEBUG0
, 0x1);
5074 NIG_WR(NIG_REG_PRS_REQ_IN_EN
, 0x0);
5076 /* Write 0 to parser credits for CFC search request */
5077 REG_WR(bp
, PRS_REG_CFC_SEARCH_INITIAL_CREDIT
, 0x0);
5079 /* send Ethernet packet */
5082 /* TODO do i reset NIG statistic? */
5083 /* Wait until NIG register shows 1 packet of size 0x10 */
5084 count
= 1000 * factor
;
5086 #ifdef BNX2X_DMAE_RD
5087 bnx2x_read_dmae(bp
, NIG_REG_STAT2_BRB_OCTET
, 2);
5088 val
= *bnx2x_sp(bp
, wb_data
[0]);
5090 val
= REG_RD(bp
, NIG_REG_STAT2_BRB_OCTET
);
5091 REG_RD(bp
, NIG_REG_STAT2_BRB_OCTET
+ 4);
5100 BNX2X_ERR("NIG timeout val = 0x%x\n", val
);
5104 /* Wait until PRS register shows 1 packet */
5105 count
= 1000 * factor
;
5107 val
= REG_RD(bp
, PRS_REG_NUM_OF_PACKETS
);
5116 BNX2X_ERR("PRS timeout val = 0x%x\n", val
);
5120 /* Reset and init BRB, PRS */
5121 REG_WR(bp
, GRCBASE_MISC
+ MISC_REGISTERS_RESET_REG_1_CLEAR
, 0x3);
5123 REG_WR(bp
, GRCBASE_MISC
+ MISC_REGISTERS_RESET_REG_1_SET
, 0x3);
5125 bnx2x_init_block(bp
, BRB1_COMMON_START
, BRB1_COMMON_END
);
5126 bnx2x_init_block(bp
, PRS_COMMON_START
, PRS_COMMON_END
);
5128 DP(NETIF_MSG_HW
, "part2\n");
5130 /* Disable inputs of parser neighbor blocks */
5131 REG_WR(bp
, TSDM_REG_ENABLE_IN1
, 0x0);
5132 REG_WR(bp
, TCM_REG_PRS_IFEN
, 0x0);
5133 REG_WR(bp
, CFC_REG_DEBUG0
, 0x1);
5134 NIG_WR(NIG_REG_PRS_REQ_IN_EN
, 0x0);
5136 /* Write 0 to parser credits for CFC search request */
5137 REG_WR(bp
, PRS_REG_CFC_SEARCH_INITIAL_CREDIT
, 0x0);
5139 /* send 10 Ethernet packets */
5140 for (i
= 0; i
< 10; i
++)
5143 /* Wait until NIG register shows 10 + 1
5144 packets of size 11*0x10 = 0xb0 */
5145 count
= 1000 * factor
;
5147 #ifdef BNX2X_DMAE_RD
5148 bnx2x_read_dmae(bp
, NIG_REG_STAT2_BRB_OCTET
, 2);
5149 val
= *bnx2x_sp(bp
, wb_data
[0]);
5151 val
= REG_RD(bp
, NIG_REG_STAT2_BRB_OCTET
);
5152 REG_RD(bp
, NIG_REG_STAT2_BRB_OCTET
+ 4);
5161 BNX2X_ERR("NIG timeout val = 0x%x\n", val
);
5165 /* Wait until PRS register shows 2 packets */
5166 val
= REG_RD(bp
, PRS_REG_NUM_OF_PACKETS
);
5168 BNX2X_ERR("PRS timeout val = 0x%x\n", val
);
5170 /* Write 1 to parser credits for CFC search request */
5171 REG_WR(bp
, PRS_REG_CFC_SEARCH_INITIAL_CREDIT
, 0x1);
5173 /* Wait until PRS register shows 3 packets */
5174 msleep(10 * factor
);
5175 /* Wait until NIG register shows 1 packet of size 0x10 */
5176 val
= REG_RD(bp
, PRS_REG_NUM_OF_PACKETS
);
5178 BNX2X_ERR("PRS timeout val = 0x%x\n", val
);
5180 /* clear NIG EOP FIFO */
5181 for (i
= 0; i
< 11; i
++)
5182 REG_RD(bp
, NIG_REG_INGRESS_EOP_LB_FIFO
);
5183 val
= REG_RD(bp
, NIG_REG_INGRESS_EOP_LB_EMPTY
);
5185 BNX2X_ERR("clear of NIG failed\n");
5189 /* Reset and init BRB, PRS, NIG */
5190 REG_WR(bp
, GRCBASE_MISC
+ MISC_REGISTERS_RESET_REG_1_CLEAR
, 0x03);
5192 REG_WR(bp
, GRCBASE_MISC
+ MISC_REGISTERS_RESET_REG_1_SET
, 0x03);
5194 bnx2x_init_block(bp
, BRB1_COMMON_START
, BRB1_COMMON_END
);
5195 bnx2x_init_block(bp
, PRS_COMMON_START
, PRS_COMMON_END
);
5198 REG_WR(bp
, PRS_REG_NIC_MODE
, 1);
5201 /* Enable inputs of parser neighbor blocks */
5202 REG_WR(bp
, TSDM_REG_ENABLE_IN1
, 0x7fffffff);
5203 REG_WR(bp
, TCM_REG_PRS_IFEN
, 0x1);
5204 REG_WR(bp
, CFC_REG_DEBUG0
, 0x0);
5205 NIG_WR(NIG_REG_PRS_REQ_IN_EN
, 0x1);
5207 DP(NETIF_MSG_HW
, "done\n");
5212 static void enable_blocks_attention(struct bnx2x
*bp
)
5214 REG_WR(bp
, PXP_REG_PXP_INT_MASK_0
, 0);
5215 REG_WR(bp
, PXP_REG_PXP_INT_MASK_1
, 0);
5216 REG_WR(bp
, DORQ_REG_DORQ_INT_MASK
, 0);
5217 REG_WR(bp
, CFC_REG_CFC_INT_MASK
, 0);
5218 REG_WR(bp
, QM_REG_QM_INT_MASK
, 0);
5219 REG_WR(bp
, TM_REG_TM_INT_MASK
, 0);
5220 REG_WR(bp
, XSDM_REG_XSDM_INT_MASK_0
, 0);
5221 REG_WR(bp
, XSDM_REG_XSDM_INT_MASK_1
, 0);
5222 REG_WR(bp
, XCM_REG_XCM_INT_MASK
, 0);
5223 /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_0, 0); */
5224 /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_1, 0); */
5225 REG_WR(bp
, USDM_REG_USDM_INT_MASK_0
, 0);
5226 REG_WR(bp
, USDM_REG_USDM_INT_MASK_1
, 0);
5227 REG_WR(bp
, UCM_REG_UCM_INT_MASK
, 0);
5228 /* REG_WR(bp, USEM_REG_USEM_INT_MASK_0, 0); */
5229 /* REG_WR(bp, USEM_REG_USEM_INT_MASK_1, 0); */
5230 REG_WR(bp
, GRCBASE_UPB
+ PB_REG_PB_INT_MASK
, 0);
5231 REG_WR(bp
, CSDM_REG_CSDM_INT_MASK_0
, 0);
5232 REG_WR(bp
, CSDM_REG_CSDM_INT_MASK_1
, 0);
5233 REG_WR(bp
, CCM_REG_CCM_INT_MASK
, 0);
5234 /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_0, 0); */
5235 /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_1, 0); */
5236 REG_WR(bp
, PXP2_REG_PXP2_INT_MASK
, 0x480000);
5237 REG_WR(bp
, TSDM_REG_TSDM_INT_MASK_0
, 0);
5238 REG_WR(bp
, TSDM_REG_TSDM_INT_MASK_1
, 0);
5239 REG_WR(bp
, TCM_REG_TCM_INT_MASK
, 0);
5240 /* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_0, 0); */
5241 /* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_1, 0); */
5242 REG_WR(bp
, CDU_REG_CDU_INT_MASK
, 0);
5243 REG_WR(bp
, DMAE_REG_DMAE_INT_MASK
, 0);
5244 /* REG_WR(bp, MISC_REG_MISC_INT_MASK, 0); */
5245 REG_WR(bp
, PBF_REG_PBF_INT_MASK
, 0X18); /* bit 3,4 masked */
5248 static int bnx2x_function_init(struct bnx2x
*bp
, int mode
)
5250 int func
= bp
->port
;
5251 int port
= func
? PORT1
: PORT0
;
5257 DP(BNX2X_MSG_MCP
, "function is %d mode is %x\n", func
, mode
);
5258 if ((func
!= 0) && (func
!= 1)) {
5259 BNX2X_ERR("BAD function number (%d)\n", func
);
5263 bnx2x_gunzip_init(bp
);
5265 if (mode
& 0x1) { /* init common */
5266 DP(BNX2X_MSG_MCP
, "starting common init func %d mode %x\n",
5268 REG_WR(bp
, MISC_REG_RESET_REG_1
, 0xffffffff);
5269 REG_WR(bp
, MISC_REG_RESET_REG_2
, 0xfffc);
5270 bnx2x_init_block(bp
, MISC_COMMON_START
, MISC_COMMON_END
);
5272 REG_WR(bp
, MISC_REG_LCPLL_CTRL_REG_2
, 0x100);
5274 REG_WR(bp
, MISC_REG_LCPLL_CTRL_REG_2
, 0x0);
5276 bnx2x_init_block(bp
, PXP_COMMON_START
, PXP_COMMON_END
);
5277 bnx2x_init_block(bp
, PXP2_COMMON_START
, PXP2_COMMON_END
);
5281 if (CHIP_REV(bp
) == CHIP_REV_Ax
) {
5282 /* enable HW interrupt from PXP on USDM
5283 overflow bit 16 on INT_MASK_0 */
5284 REG_WR(bp
, PXP_REG_PXP_INT_MASK_0
, 0);
5288 REG_WR(bp
, PXP2_REG_RQ_QM_ENDIAN_M
, 1);
5289 REG_WR(bp
, PXP2_REG_RQ_TM_ENDIAN_M
, 1);
5290 REG_WR(bp
, PXP2_REG_RQ_SRC_ENDIAN_M
, 1);
5291 REG_WR(bp
, PXP2_REG_RQ_CDU_ENDIAN_M
, 1);
5292 REG_WR(bp
, PXP2_REG_RQ_DBG_ENDIAN_M
, 1);
5293 REG_WR(bp
, PXP2_REG_RQ_HC_ENDIAN_M
, 1);
5295 /* REG_WR(bp, PXP2_REG_RD_PBF_SWAP_MODE, 1); */
5296 REG_WR(bp
, PXP2_REG_RD_QM_SWAP_MODE
, 1);
5297 REG_WR(bp
, PXP2_REG_RD_TM_SWAP_MODE
, 1);
5298 REG_WR(bp
, PXP2_REG_RD_SRC_SWAP_MODE
, 1);
5299 REG_WR(bp
, PXP2_REG_RD_CDURD_SWAP_MODE
, 1);
5304 REG_WR(bp
, PRS_REG_NIC_MODE
, 1);
5307 REG_WR(bp
, PXP2_REG_RQ_CDU_P_SIZE
, 5);
5309 REG_WR(bp
, PXP2_REG_RQ_TM_P_SIZE
, 5);
5310 REG_WR(bp
, PXP2_REG_RQ_QM_P_SIZE
, 5);
5311 REG_WR(bp
, PXP2_REG_RQ_SRC_P_SIZE
, 5);
5314 bnx2x_init_block(bp
, DMAE_COMMON_START
, DMAE_COMMON_END
);
5316 /* let the HW do it's magic ... */
5319 (can be moved up if we want to use the DMAE) */
5320 val
= REG_RD(bp
, PXP2_REG_RQ_CFG_DONE
);
5322 BNX2X_ERR("PXP2 CFG failed\n");
5326 val
= REG_RD(bp
, PXP2_REG_RD_INIT_DONE
);
5328 BNX2X_ERR("PXP2 RD_INIT failed\n");
5332 REG_WR(bp
, PXP2_REG_RQ_DISABLE_INPUTS
, 0);
5333 REG_WR(bp
, PXP2_REG_RD_DISABLE_INPUTS
, 0);
5335 bnx2x_init_fill(bp
, TSEM_REG_PRAM
, 0, 8);
5337 bnx2x_init_block(bp
, TCM_COMMON_START
, TCM_COMMON_END
);
5338 bnx2x_init_block(bp
, UCM_COMMON_START
, UCM_COMMON_END
);
5339 bnx2x_init_block(bp
, CCM_COMMON_START
, CCM_COMMON_END
);
5340 bnx2x_init_block(bp
, XCM_COMMON_START
, XCM_COMMON_END
);
5342 #ifdef BNX2X_DMAE_RD
5343 bnx2x_read_dmae(bp
, XSEM_REG_PASSIVE_BUFFER
, 3);
5344 bnx2x_read_dmae(bp
, CSEM_REG_PASSIVE_BUFFER
, 3);
5345 bnx2x_read_dmae(bp
, TSEM_REG_PASSIVE_BUFFER
, 3);
5346 bnx2x_read_dmae(bp
, USEM_REG_PASSIVE_BUFFER
, 3);
5348 REG_RD(bp
, XSEM_REG_PASSIVE_BUFFER
);
5349 REG_RD(bp
, XSEM_REG_PASSIVE_BUFFER
+ 4);
5350 REG_RD(bp
, XSEM_REG_PASSIVE_BUFFER
+ 8);
5351 REG_RD(bp
, CSEM_REG_PASSIVE_BUFFER
);
5352 REG_RD(bp
, CSEM_REG_PASSIVE_BUFFER
+ 4);
5353 REG_RD(bp
, CSEM_REG_PASSIVE_BUFFER
+ 8);
5354 REG_RD(bp
, TSEM_REG_PASSIVE_BUFFER
);
5355 REG_RD(bp
, TSEM_REG_PASSIVE_BUFFER
+ 4);
5356 REG_RD(bp
, TSEM_REG_PASSIVE_BUFFER
+ 8);
5357 REG_RD(bp
, USEM_REG_PASSIVE_BUFFER
);
5358 REG_RD(bp
, USEM_REG_PASSIVE_BUFFER
+ 4);
5359 REG_RD(bp
, USEM_REG_PASSIVE_BUFFER
+ 8);
5361 bnx2x_init_block(bp
, QM_COMMON_START
, QM_COMMON_END
);
5362 /* softrest pulse */
5363 REG_WR(bp
, QM_REG_SOFT_RESET
, 1);
5364 REG_WR(bp
, QM_REG_SOFT_RESET
, 0);
5367 bnx2x_init_block(bp
, TIMERS_COMMON_START
, TIMERS_COMMON_END
);
5369 bnx2x_init_block(bp
, DQ_COMMON_START
, DQ_COMMON_END
);
5370 REG_WR(bp
, DORQ_REG_DPM_CID_OFST
, BCM_PAGE_BITS
);
5371 if (CHIP_REV(bp
) == CHIP_REV_Ax
) {
5372 /* enable hw interrupt from doorbell Q */
5373 REG_WR(bp
, DORQ_REG_DORQ_INT_MASK
, 0);
5376 bnx2x_init_block(bp
, BRB1_COMMON_START
, BRB1_COMMON_END
);
5378 if (CHIP_REV_IS_SLOW(bp
)) {
5379 /* fix for emulation and FPGA for no pause */
5380 REG_WR(bp
, BRB1_REG_PAUSE_HIGH_THRESHOLD_0
, 513);
5381 REG_WR(bp
, BRB1_REG_PAUSE_HIGH_THRESHOLD_1
, 513);
5382 REG_WR(bp
, BRB1_REG_PAUSE_LOW_THRESHOLD_0
, 0);
5383 REG_WR(bp
, BRB1_REG_PAUSE_LOW_THRESHOLD_1
, 0);
5386 bnx2x_init_block(bp
, PRS_COMMON_START
, PRS_COMMON_END
);
5388 bnx2x_init_block(bp
, TSDM_COMMON_START
, TSDM_COMMON_END
);
5389 bnx2x_init_block(bp
, CSDM_COMMON_START
, CSDM_COMMON_END
);
5390 bnx2x_init_block(bp
, USDM_COMMON_START
, USDM_COMMON_END
);
5391 bnx2x_init_block(bp
, XSDM_COMMON_START
, XSDM_COMMON_END
);
5393 bnx2x_init_fill(bp
, TSTORM_INTMEM_ADDR
, 0, STORM_INTMEM_SIZE
);
5394 bnx2x_init_fill(bp
, CSTORM_INTMEM_ADDR
, 0, STORM_INTMEM_SIZE
);
5395 bnx2x_init_fill(bp
, XSTORM_INTMEM_ADDR
, 0, STORM_INTMEM_SIZE
);
5396 bnx2x_init_fill(bp
, USTORM_INTMEM_ADDR
, 0, STORM_INTMEM_SIZE
);
5398 bnx2x_init_block(bp
, TSEM_COMMON_START
, TSEM_COMMON_END
);
5399 bnx2x_init_block(bp
, USEM_COMMON_START
, USEM_COMMON_END
);
5400 bnx2x_init_block(bp
, CSEM_COMMON_START
, CSEM_COMMON_END
);
5401 bnx2x_init_block(bp
, XSEM_COMMON_START
, XSEM_COMMON_END
);
5404 REG_WR(bp
, GRCBASE_MISC
+ MISC_REGISTERS_RESET_REG_1_CLEAR
,
5406 REG_WR(bp
, GRCBASE_MISC
+ MISC_REGISTERS_RESET_REG_1_SET
,
5409 bnx2x_init_block(bp
, UPB_COMMON_START
, UPB_COMMON_END
);
5410 bnx2x_init_block(bp
, XPB_COMMON_START
, XPB_COMMON_END
);
5411 bnx2x_init_block(bp
, PBF_COMMON_START
, PBF_COMMON_END
);
5413 REG_WR(bp
, SRC_REG_SOFT_RST
, 1);
5414 for (i
= SRC_REG_KEYRSS0_0
; i
<= SRC_REG_KEYRSS1_9
; i
+= 4) {
5415 REG_WR(bp
, i
, 0xc0cac01a);
5416 /* TODO: repleace with something meaningfull */
5418 /* SRCH COMMON comes here */
5419 REG_WR(bp
, SRC_REG_SOFT_RST
, 0);
5421 if (sizeof(union cdu_context
) != 1024) {
5422 /* we currently assume that a context is 1024 bytes */
5423 printk(KERN_ALERT PFX
"please adjust the size of"
5424 " cdu_context(%ld)\n",
5425 (long)sizeof(union cdu_context
));
5427 val
= (4 << 24) + (0 << 12) + 1024;
5428 REG_WR(bp
, CDU_REG_CDU_GLOBAL_PARAMS
, val
);
5429 bnx2x_init_block(bp
, CDU_COMMON_START
, CDU_COMMON_END
);
5431 bnx2x_init_block(bp
, CFC_COMMON_START
, CFC_COMMON_END
);
5432 REG_WR(bp
, CFC_REG_INIT_REG
, 0x7FF);
5434 bnx2x_init_block(bp
, HC_COMMON_START
, HC_COMMON_END
);
5435 bnx2x_init_block(bp
, MISC_AEU_COMMON_START
,
5436 MISC_AEU_COMMON_END
);
5437 /* RXPCS COMMON comes here */
5438 /* EMAC0 COMMON comes here */
5439 /* EMAC1 COMMON comes here */
5440 /* DBU COMMON comes here */
5441 /* DBG COMMON comes here */
5442 bnx2x_init_block(bp
, NIG_COMMON_START
, NIG_COMMON_END
);
5444 if (CHIP_REV_IS_SLOW(bp
))
5447 /* finish CFC init */
5448 val
= REG_RD(bp
, CFC_REG_LL_INIT_DONE
);
5450 BNX2X_ERR("CFC LL_INIT failed\n");
5454 val
= REG_RD(bp
, CFC_REG_AC_INIT_DONE
);
5456 BNX2X_ERR("CFC AC_INIT failed\n");
5460 val
= REG_RD(bp
, CFC_REG_CAM_INIT_DONE
);
5462 BNX2X_ERR("CFC CAM_INIT failed\n");
5466 REG_WR(bp
, CFC_REG_DEBUG0
, 0);
5468 /* read NIG statistic
5469 to see if this is our first up since powerup */
5470 #ifdef BNX2X_DMAE_RD
5471 bnx2x_read_dmae(bp
, NIG_REG_STAT2_BRB_OCTET
, 2);
5472 val
= *bnx2x_sp(bp
, wb_data
[0]);
5474 val
= REG_RD(bp
, NIG_REG_STAT2_BRB_OCTET
);
5475 REG_RD(bp
, NIG_REG_STAT2_BRB_OCTET
+ 4);
5477 /* do internal memory self test */
5478 if ((val
== 0) && bnx2x_int_mem_test(bp
)) {
5479 BNX2X_ERR("internal mem selftest failed\n");
5483 /* clear PXP2 attentions */
5484 REG_RD(bp
, PXP2_REG_PXP2_INT_STS_CLR
);
5486 enable_blocks_attention(bp
);
5487 /* enable_blocks_parity(bp); */
5489 } /* end of common init */
5493 /* the phys address is shifted right 12 bits and has an added
5494 1=valid bit added to the 53rd bit
5495 then since this is a wide register(TM)
5496 we split it into two 32 bit writes
5498 #define RQ_ONCHIP_AT_PORT_SIZE 384
5499 #define ONCHIP_ADDR1(x) ((u32)(((u64)x >> 12) & 0xFFFFFFFF))
5500 #define ONCHIP_ADDR2(x) ((u32)((1 << 20) | ((u64)x >> 44)))
5501 #define PXP_ONE_ILT(x) ((x << 10) | x)
5503 DP(BNX2X_MSG_MCP
, "starting per-function init port is %x\n", func
);
5505 REG_WR(bp
, NIG_REG_MASK_INTERRUPT_PORT0
+ func
*4, 0);
5507 /* Port PXP comes here */
5508 /* Port PXP2 comes here */
5513 i
= func
* RQ_ONCHIP_AT_PORT_SIZE
;
5515 wb_write
[0] = ONCHIP_ADDR1(bnx2x_sp_mapping(bp
, context
));
5516 wb_write
[1] = ONCHIP_ADDR2(bnx2x_sp_mapping(bp
, context
));
5517 REG_WR_DMAE(bp
, PXP2_REG_RQ_ONCHIP_AT
+ i
*8, wb_write
, 2);
5519 REG_WR_IND(bp
, PXP2_REG_RQ_ONCHIP_AT
+ i
*8,
5520 ONCHIP_ADDR1(bnx2x_sp_mapping(bp
, context
)));
5521 REG_WR_IND(bp
, PXP2_REG_RQ_ONCHIP_AT
+ i
*8 + 4,
5522 ONCHIP_ADDR2(bnx2x_sp_mapping(bp
, context
)));
5524 REG_WR(bp
, PXP2_REG_PSWRQ_CDU0_L2P
+ func
*4, PXP_ONE_ILT(i
));
5530 wb_write
[0] = ONCHIP_ADDR1(bp
->timers_mapping
);
5531 wb_write
[1] = ONCHIP_ADDR2(bp
->timers_mapping
);
5532 REG_WR_DMAE(bp
, PXP2_REG_RQ_ONCHIP_AT
+ i
*8, wb_write
, 2);
5533 REG_WR(bp
, PXP2_REG_PSWRQ_TM0_L2P
+ func
*4, PXP_ONE_ILT(i
));
5538 wb_write
[0] = ONCHIP_ADDR1(bp
->qm_mapping
);
5539 wb_write
[1] = ONCHIP_ADDR2(bp
->qm_mapping
);
5540 REG_WR_DMAE(bp
, PXP2_REG_RQ_ONCHIP_AT
+ i
*8, wb_write
, 2);
5541 REG_WR(bp
, PXP2_REG_PSWRQ_QM0_L2P
+ func
*4, PXP_ONE_ILT(i
));
5546 wb_write
[0] = ONCHIP_ADDR1(bp
->t1_mapping
);
5547 wb_write
[1] = ONCHIP_ADDR2(bp
->t1_mapping
);
5548 REG_WR_DMAE(bp
, PXP2_REG_RQ_ONCHIP_AT
+ i
*8, wb_write
, 2);
5549 REG_WR(bp
, PXP2_REG_PSWRQ_SRC0_L2P
+ func
*4, PXP_ONE_ILT(i
));
5552 /* Port TCM comes here */
5553 /* Port UCM comes here */
5554 /* Port CCM comes here */
5555 bnx2x_init_block(bp
, func
? XCM_PORT1_START
: XCM_PORT0_START
,
5556 func
? XCM_PORT1_END
: XCM_PORT0_END
);
5562 for (i
= 0; i
< 32; i
++) {
5563 REG_WR(bp
, QM_REG_BASEADDR
+ (func
*32 + i
)*4, 1024 * 4 * i
);
5565 REG_WR_DMAE(bp
, QM_REG_PTRTBL
+ (func
*32 + i
)*8, wb_write
, 2);
5567 REG_WR_IND(bp
, QM_REG_PTRTBL
+ (func
*32 + i
)*8, 0);
5568 REG_WR_IND(bp
, QM_REG_PTRTBL
+ (func
*32 + i
)*8 + 4, 0);
5571 REG_WR(bp
, QM_REG_CONNNUM_0
+ func
*4, 1024/16 - 1);
5573 /* Port QM comes here */
5576 REG_WR(bp
, TM_REG_LIN0_SCAN_TIME
+ func
*4, 1024/64*20);
5577 REG_WR(bp
, TM_REG_LIN0_MAX_ACTIVE_CID
+ func
*4, 31);
5579 bnx2x_init_block(bp
, func
? TIMERS_PORT1_START
: TIMERS_PORT0_START
,
5580 func
? TIMERS_PORT1_END
: TIMERS_PORT0_END
);
5582 /* Port DQ comes here */
5583 /* Port BRB1 comes here */
5584 bnx2x_init_block(bp
, func
? PRS_PORT1_START
: PRS_PORT0_START
,
5585 func
? PRS_PORT1_END
: PRS_PORT0_END
);
5586 /* Port TSDM comes here */
5587 /* Port CSDM comes here */
5588 /* Port USDM comes here */
5589 /* Port XSDM comes here */
5590 bnx2x_init_block(bp
, func
? TSEM_PORT1_START
: TSEM_PORT0_START
,
5591 func
? TSEM_PORT1_END
: TSEM_PORT0_END
);
5592 bnx2x_init_block(bp
, func
? USEM_PORT1_START
: USEM_PORT0_START
,
5593 func
? USEM_PORT1_END
: USEM_PORT0_END
);
5594 bnx2x_init_block(bp
, func
? CSEM_PORT1_START
: CSEM_PORT0_START
,
5595 func
? CSEM_PORT1_END
: CSEM_PORT0_END
);
5596 bnx2x_init_block(bp
, func
? XSEM_PORT1_START
: XSEM_PORT0_START
,
5597 func
? XSEM_PORT1_END
: XSEM_PORT0_END
);
5598 /* Port UPB comes here */
5599 /* Port XSDM comes here */
5600 bnx2x_init_block(bp
, func
? PBF_PORT1_START
: PBF_PORT0_START
,
5601 func
? PBF_PORT1_END
: PBF_PORT0_END
);
5603 /* configure PBF to work without PAUSE mtu 9000 */
5604 REG_WR(bp
, PBF_REG_P0_PAUSE_ENABLE
+ func
*4, 0);
5606 /* update threshold */
5607 REG_WR(bp
, PBF_REG_P0_ARB_THRSH
+ func
*4, (9040/16));
5608 /* update init credit */
5609 REG_WR(bp
, PBF_REG_P0_INIT_CRD
+ func
*4, (9040/16) + 553 - 22);
5612 REG_WR(bp
, PBF_REG_INIT_P0
+ func
*4, 1);
5614 REG_WR(bp
, PBF_REG_INIT_P0
+ func
*4, 0);
5617 /* tell the searcher where the T2 table is */
5618 REG_WR(bp
, SRC_REG_COUNTFREE0
+ func
*4, 16*1024/64);
5620 wb_write
[0] = U64_LO(bp
->t2_mapping
);
5621 wb_write
[1] = U64_HI(bp
->t2_mapping
);
5622 REG_WR_DMAE(bp
, SRC_REG_FIRSTFREE0
+ func
*4, wb_write
, 2);
5623 wb_write
[0] = U64_LO((u64
)bp
->t2_mapping
+ 16*1024 - 64);
5624 wb_write
[1] = U64_HI((u64
)bp
->t2_mapping
+ 16*1024 - 64);
5625 REG_WR_DMAE(bp
, SRC_REG_LASTFREE0
+ func
*4, wb_write
, 2);
5627 REG_WR(bp
, SRC_REG_NUMBER_HASH_BITS0
+ func
*4, 10);
5628 /* Port SRCH comes here */
5630 /* Port CDU comes here */
5631 /* Port CFC comes here */
5632 bnx2x_init_block(bp
, func
? HC_PORT1_START
: HC_PORT0_START
,
5633 func
? HC_PORT1_END
: HC_PORT0_END
);
5634 bnx2x_init_block(bp
, func
? MISC_AEU_PORT1_START
:
5635 MISC_AEU_PORT0_START
,
5636 func
? MISC_AEU_PORT1_END
: MISC_AEU_PORT0_END
);
5637 /* Port PXPCS comes here */
5638 /* Port EMAC0 comes here */
5639 /* Port EMAC1 comes here */
5640 /* Port DBU comes here */
5641 /* Port DBG comes here */
5642 bnx2x_init_block(bp
, func
? NIG_PORT1_START
: NIG_PORT0_START
,
5643 func
? NIG_PORT1_END
: NIG_PORT0_END
);
5644 REG_WR(bp
, NIG_REG_XGXS_SERDES0_MODE_SEL
+ func
*4, 1);
5645 /* Port MCP comes here */
5646 /* Port DMAE comes here */
5648 bnx2x_link_reset(bp
);
5650 /* Reset pciex errors for debug */
5651 REG_WR(bp
, 0x2114, 0xffffffff);
5652 REG_WR(bp
, 0x2120, 0xffffffff);
5653 REG_WR(bp
, 0x2814, 0xffffffff);
5655 /* !!! move to init_values.h */
5656 REG_WR(bp
, XSDM_REG_INIT_CREDIT_PXP_CTRL
, 0x1);
5657 REG_WR(bp
, USDM_REG_INIT_CREDIT_PXP_CTRL
, 0x1);
5658 REG_WR(bp
, CSDM_REG_INIT_CREDIT_PXP_CTRL
, 0x1);
5659 REG_WR(bp
, TSDM_REG_INIT_CREDIT_PXP_CTRL
, 0x1);
5661 REG_WR(bp
, DBG_REG_PCI_REQ_CREDIT
, 0x1);
5662 REG_WR(bp
, TM_REG_PCIARB_CRDCNT_VAL
, 0x1);
5663 REG_WR(bp
, CDU_REG_CDU_DEBUG
, 0x264);
5664 REG_WR(bp
, CDU_REG_CDU_DEBUG
, 0x0);
5666 bnx2x_gunzip_end(bp
);
5671 bp
->fw_drv_pulse_wr_seq
=
5672 (SHMEM_RD(bp
, drv_fw_mb
[port
].drv_pulse_mb
) &
5673 DRV_PULSE_SEQ_MASK
);
5674 bp
->fw_mb
= SHMEM_RD(bp
, drv_fw_mb
[port
].fw_mb_param
);
5675 DP(BNX2X_MSG_MCP
, "drv_pulse 0x%x fw_mb 0x%x\n",
5676 bp
->fw_drv_pulse_wr_seq
, bp
->fw_mb
);
5685 /* send the MCP a request, block untill there is a reply */
5686 static u32
bnx2x_fw_command(struct bnx2x
*bp
, u32 command
)
5689 u32 seq
= ++bp
->fw_seq
;
5690 int port
= bp
->port
;
5692 SHMEM_WR(bp
, drv_fw_mb
[port
].drv_mb_header
, command
|seq
);
5693 DP(BNX2X_MSG_MCP
, "wrote command (%x) to FW MB\n", command
|seq
);
5695 /* let the FW do it's magic ... */
5696 msleep(100); /* TBD */
5698 if (CHIP_REV_IS_SLOW(bp
))
5701 rc
= SHMEM_RD(bp
, drv_fw_mb
[port
].fw_mb_header
);
5703 DP(BNX2X_MSG_MCP
, "read (%x) seq is (%x) from FW MB\n", rc
, seq
);
5705 /* is this a reply to our command? */
5706 if (seq
== (rc
& FW_MSG_SEQ_NUMBER_MASK
)) {
5707 rc
&= FW_MSG_CODE_MASK
;
5710 BNX2X_ERR("FW failed to respond!\n");
5717 static void bnx2x_free_mem(struct bnx2x
*bp
)
5720 #define BNX2X_PCI_FREE(x, y, size) \
5723 pci_free_consistent(bp->pdev, size, x, y); \
5729 #define BNX2X_FREE(x) \
5740 for_each_queue(bp
, i
) {
5743 BNX2X_PCI_FREE(bnx2x_fp(bp
, i
, status_blk
),
5744 bnx2x_fp(bp
, i
, status_blk_mapping
),
5745 sizeof(struct host_status_block
) +
5746 sizeof(struct eth_tx_db_data
));
5748 /* fast path rings: tx_buf tx_desc rx_buf rx_desc rx_comp */
5749 BNX2X_FREE(bnx2x_fp(bp
, i
, tx_buf_ring
));
5750 BNX2X_PCI_FREE(bnx2x_fp(bp
, i
, tx_desc_ring
),
5751 bnx2x_fp(bp
, i
, tx_desc_mapping
),
5752 sizeof(struct eth_tx_bd
) * NUM_TX_BD
);
5754 BNX2X_FREE(bnx2x_fp(bp
, i
, rx_buf_ring
));
5755 BNX2X_PCI_FREE(bnx2x_fp(bp
, i
, rx_desc_ring
),
5756 bnx2x_fp(bp
, i
, rx_desc_mapping
),
5757 sizeof(struct eth_rx_bd
) * NUM_RX_BD
);
5759 BNX2X_PCI_FREE(bnx2x_fp(bp
, i
, rx_comp_ring
),
5760 bnx2x_fp(bp
, i
, rx_comp_mapping
),
5761 sizeof(struct eth_fast_path_rx_cqe
) *
5767 /* end of fastpath */
5769 BNX2X_PCI_FREE(bp
->def_status_blk
, bp
->def_status_blk_mapping
,
5770 (sizeof(struct host_def_status_block
)));
5772 BNX2X_PCI_FREE(bp
->slowpath
, bp
->slowpath_mapping
,
5773 (sizeof(struct bnx2x_slowpath
)));
5776 BNX2X_PCI_FREE(bp
->t1
, bp
->t1_mapping
, 64*1024);
5777 BNX2X_PCI_FREE(bp
->t2
, bp
->t2_mapping
, 16*1024);
5778 BNX2X_PCI_FREE(bp
->timers
, bp
->timers_mapping
, 8*1024);
5779 BNX2X_PCI_FREE(bp
->qm
, bp
->qm_mapping
, 128*1024);
5781 BNX2X_PCI_FREE(bp
->spq
, bp
->spq_mapping
, PAGE_SIZE
);
5783 #undef BNX2X_PCI_FREE
5787 static int bnx2x_alloc_mem(struct bnx2x
*bp
)
5790 #define BNX2X_PCI_ALLOC(x, y, size) \
5792 x = pci_alloc_consistent(bp->pdev, size, y); \
5794 goto alloc_mem_err; \
5795 memset(x, 0, size); \
5798 #define BNX2X_ALLOC(x, size) \
5800 x = vmalloc(size); \
5802 goto alloc_mem_err; \
5803 memset(x, 0, size); \
5809 BNX2X_ALLOC(bp
->fp
, sizeof(struct bnx2x_fastpath
) * bp
->num_queues
);
5811 for_each_queue(bp
, i
) {
5812 bnx2x_fp(bp
, i
, bp
) = bp
;
5815 BNX2X_PCI_ALLOC(bnx2x_fp(bp
, i
, status_blk
),
5816 &bnx2x_fp(bp
, i
, status_blk_mapping
),
5817 sizeof(struct host_status_block
) +
5818 sizeof(struct eth_tx_db_data
));
5820 bnx2x_fp(bp
, i
, hw_tx_prods
) =
5821 (void *)(bnx2x_fp(bp
, i
, status_blk
) + 1);
5823 bnx2x_fp(bp
, i
, tx_prods_mapping
) =
5824 bnx2x_fp(bp
, i
, status_blk_mapping
) +
5825 sizeof(struct host_status_block
);
5827 /* fast path rings: tx_buf tx_desc rx_buf rx_desc rx_comp */
5828 BNX2X_ALLOC(bnx2x_fp(bp
, i
, tx_buf_ring
),
5829 sizeof(struct sw_tx_bd
) * NUM_TX_BD
);
5830 BNX2X_PCI_ALLOC(bnx2x_fp(bp
, i
, tx_desc_ring
),
5831 &bnx2x_fp(bp
, i
, tx_desc_mapping
),
5832 sizeof(struct eth_tx_bd
) * NUM_TX_BD
);
5834 BNX2X_ALLOC(bnx2x_fp(bp
, i
, rx_buf_ring
),
5835 sizeof(struct sw_rx_bd
) * NUM_RX_BD
);
5836 BNX2X_PCI_ALLOC(bnx2x_fp(bp
, i
, rx_desc_ring
),
5837 &bnx2x_fp(bp
, i
, rx_desc_mapping
),
5838 sizeof(struct eth_rx_bd
) * NUM_RX_BD
);
5840 BNX2X_PCI_ALLOC(bnx2x_fp(bp
, i
, rx_comp_ring
),
5841 &bnx2x_fp(bp
, i
, rx_comp_mapping
),
5842 sizeof(struct eth_fast_path_rx_cqe
) *
5846 /* end of fastpath */
5848 BNX2X_PCI_ALLOC(bp
->def_status_blk
, &bp
->def_status_blk_mapping
,
5849 sizeof(struct host_def_status_block
));
5851 BNX2X_PCI_ALLOC(bp
->slowpath
, &bp
->slowpath_mapping
,
5852 sizeof(struct bnx2x_slowpath
));
5855 BNX2X_PCI_ALLOC(bp
->t1
, &bp
->t1_mapping
, 64*1024);
5858 for (i
= 0; i
< 64*1024; i
+= 64) {
5859 *(u64
*)((char *)bp
->t1
+ i
+ 56) = 0x0UL
;
5860 *(u64
*)((char *)bp
->t1
+ i
+ 3) = 0x0UL
;
5863 /* allocate searcher T2 table
5864 we allocate 1/4 of alloc num for T2
5865 (which is not entered into the ILT) */
5866 BNX2X_PCI_ALLOC(bp
->t2
, &bp
->t2_mapping
, 16*1024);
5869 for (i
= 0; i
< 16*1024; i
+= 64)
5870 * (u64
*)((char *)bp
->t2
+ i
+ 56) = bp
->t2_mapping
+ i
+ 64;
5872 /* now sixup the last line in the block to point to the next block */
5873 *(u64
*)((char *)bp
->t2
+ 1024*16-8) = bp
->t2_mapping
;
5875 /* Timer block array (MAX_CONN*8) phys uncached for now 1024 conns */
5876 BNX2X_PCI_ALLOC(bp
->timers
, &bp
->timers_mapping
, 8*1024);
5878 /* QM queues (128*MAX_CONN) */
5879 BNX2X_PCI_ALLOC(bp
->qm
, &bp
->qm_mapping
, 128*1024);
5882 /* Slow path ring */
5883 BNX2X_PCI_ALLOC(bp
->spq
, &bp
->spq_mapping
, BCM_PAGE_SIZE
);
5891 #undef BNX2X_PCI_ALLOC
5895 static void bnx2x_free_tx_skbs(struct bnx2x
*bp
)
5899 for_each_queue(bp
, i
) {
5900 struct bnx2x_fastpath
*fp
= &bp
->fp
[i
];
5902 u16 bd_cons
= fp
->tx_bd_cons
;
5903 u16 sw_prod
= fp
->tx_pkt_prod
;
5904 u16 sw_cons
= fp
->tx_pkt_cons
;
5906 BUG_TRAP(fp
->tx_buf_ring
!= NULL
);
5908 while (sw_cons
!= sw_prod
) {
5909 bd_cons
= bnx2x_free_tx_pkt(bp
, fp
, TX_BD(sw_cons
));
5915 static void bnx2x_free_rx_skbs(struct bnx2x
*bp
)
5919 for_each_queue(bp
, j
) {
5920 struct bnx2x_fastpath
*fp
= &bp
->fp
[j
];
5922 BUG_TRAP(fp
->rx_buf_ring
!= NULL
);
5924 for (i
= 0; i
< NUM_RX_BD
; i
++) {
5925 struct sw_rx_bd
*rx_buf
= &fp
->rx_buf_ring
[i
];
5926 struct sk_buff
*skb
= rx_buf
->skb
;
5931 pci_unmap_single(bp
->pdev
,
5932 pci_unmap_addr(rx_buf
, mapping
),
5933 bp
->rx_buf_use_size
,
5934 PCI_DMA_FROMDEVICE
);
5942 static void bnx2x_free_skbs(struct bnx2x
*bp
)
5944 bnx2x_free_tx_skbs(bp
);
5945 bnx2x_free_rx_skbs(bp
);
5948 static void bnx2x_free_msix_irqs(struct bnx2x
*bp
)
5952 free_irq(bp
->msix_table
[0].vector
, bp
->dev
);
5953 DP(NETIF_MSG_IFDOWN
, "rleased sp irq (%d)\n",
5954 bp
->msix_table
[0].vector
);
5956 for_each_queue(bp
, i
) {
5957 DP(NETIF_MSG_IFDOWN
, "about to rlease fp #%d->%d irq "
5958 "state(%x)\n", i
, bp
->msix_table
[i
+ 1].vector
,
5959 bnx2x_fp(bp
, i
, state
));
5961 if (bnx2x_fp(bp
, i
, state
) != BNX2X_FP_STATE_CLOSED
) {
5963 free_irq(bp
->msix_table
[i
+ 1].vector
, &bp
->fp
[i
]);
5964 bnx2x_fp(bp
, i
, state
) = BNX2X_FP_STATE_CLOSED
;
5967 DP(NETIF_MSG_IFDOWN
, "irq not freed\n");
5973 static void bnx2x_free_irq(struct bnx2x
*bp
)
5976 if (bp
->flags
& USING_MSIX_FLAG
) {
5978 bnx2x_free_msix_irqs(bp
);
5979 pci_disable_msix(bp
->pdev
);
5981 bp
->flags
&= ~USING_MSIX_FLAG
;
5984 free_irq(bp
->pdev
->irq
, bp
->dev
);
5987 static int bnx2x_enable_msix(struct bnx2x
*bp
)
5992 bp
->msix_table
[0].entry
= 0;
5993 for_each_queue(bp
, i
)
5994 bp
->msix_table
[i
+ 1].entry
= i
+ 1;
5996 if (pci_enable_msix(bp
->pdev
, &bp
->msix_table
[0],
5997 bp
->num_queues
+ 1)){
5998 BNX2X_ERR("failed to enable msix\n");
6003 bp
->flags
|= USING_MSIX_FLAG
;
6010 static int bnx2x_req_msix_irqs(struct bnx2x
*bp
)
6016 DP(NETIF_MSG_IFUP
, "about to request sp irq\n");
6018 rc
= request_irq(bp
->msix_table
[0].vector
, bnx2x_msix_sp_int
, 0,
6019 bp
->dev
->name
, bp
->dev
);
6022 BNX2X_ERR("request sp irq failed\n");
6026 for_each_queue(bp
, i
) {
6027 rc
= request_irq(bp
->msix_table
[i
+ 1].vector
,
6028 bnx2x_msix_fp_int
, 0,
6029 bp
->dev
->name
, &bp
->fp
[i
]);
6032 BNX2X_ERR("request fp #%d irq failed\n", i
);
6033 bnx2x_free_msix_irqs(bp
);
6037 bnx2x_fp(bp
, i
, state
) = BNX2X_FP_STATE_IRQ
;
6045 static int bnx2x_req_irq(struct bnx2x
*bp
)
6048 int rc
= request_irq(bp
->pdev
->irq
, bnx2x_interrupt
,
6049 IRQF_SHARED
, bp
->dev
->name
, bp
->dev
);
6051 bnx2x_fp(bp
, 0, state
) = BNX2X_FP_STATE_IRQ
;
6058 * Init service functions
6061 static void bnx2x_set_mac_addr(struct bnx2x
*bp
)
6063 struct mac_configuration_cmd
*config
= bnx2x_sp(bp
, mac_config
);
6066 * unicasts 0-31:port0 32-63:port1
6067 * multicast 64-127:port0 128-191:port1
6069 config
->hdr
.length_6b
= 2;
6070 config
->hdr
.offset
= bp
->port
? 31 : 0;
6071 config
->hdr
.reserved0
= 0;
6072 config
->hdr
.reserved1
= 0;
6075 config
->config_table
[0].cam_entry
.msb_mac_addr
=
6076 swab16(*(u16
*)&bp
->dev
->dev_addr
[0]);
6077 config
->config_table
[0].cam_entry
.middle_mac_addr
=
6078 swab16(*(u16
*)&bp
->dev
->dev_addr
[2]);
6079 config
->config_table
[0].cam_entry
.lsb_mac_addr
=
6080 swab16(*(u16
*)&bp
->dev
->dev_addr
[4]);
6081 config
->config_table
[0].cam_entry
.flags
= cpu_to_le16(bp
->port
);
6082 config
->config_table
[0].target_table_entry
.flags
= 0;
6083 config
->config_table
[0].target_table_entry
.client_id
= 0;
6084 config
->config_table
[0].target_table_entry
.vlan_id
= 0;
6086 DP(NETIF_MSG_IFUP
, "setting MAC (%04x:%04x:%04x)\n",
6087 config
->config_table
[0].cam_entry
.msb_mac_addr
,
6088 config
->config_table
[0].cam_entry
.middle_mac_addr
,
6089 config
->config_table
[0].cam_entry
.lsb_mac_addr
);
6092 config
->config_table
[1].cam_entry
.msb_mac_addr
= 0xffff;
6093 config
->config_table
[1].cam_entry
.middle_mac_addr
= 0xffff;
6094 config
->config_table
[1].cam_entry
.lsb_mac_addr
= 0xffff;
6095 config
->config_table
[1].cam_entry
.flags
= cpu_to_le16(bp
->port
);
6096 config
->config_table
[1].target_table_entry
.flags
=
6097 TSTORM_CAM_TARGET_TABLE_ENTRY_BROADCAST
;
6098 config
->config_table
[1].target_table_entry
.client_id
= 0;
6099 config
->config_table
[1].target_table_entry
.vlan_id
= 0;
6101 bnx2x_sp_post(bp
, RAMROD_CMD_ID_ETH_SET_MAC
, 0,
6102 U64_HI(bnx2x_sp_mapping(bp
, mac_config
)),
6103 U64_LO(bnx2x_sp_mapping(bp
, mac_config
)), 0);
6106 static int bnx2x_wait_ramrod(struct bnx2x
*bp
, int state
, int idx
,
6107 int *state_p
, int poll
)
6109 /* can take a while if any port is running */
6112 /* DP("waiting for state to become %d on IDX [%d]\n",
6120 bnx2x_rx_int(bp
->fp
, 10);
6121 /* If index is different from 0
6122 * The reply for some commands will
6123 * be on the none default queue
6126 bnx2x_rx_int(&bp
->fp
[idx
], 10);
6129 mb(); /* state is changed by bnx2x_sp_event()*/
6131 if (*state_p
!= state
)
6141 BNX2X_ERR("timeout waiting for ramrod %d on %d\n", state
, idx
);
6146 static int bnx2x_setup_leading(struct bnx2x
*bp
)
6149 /* reset IGU staae */
6150 bnx2x_ack_sb(bp
, DEF_SB_ID
, CSTORM_ID
, 0, IGU_INT_ENABLE
, 0);
6153 bnx2x_sp_post(bp
, RAMROD_CMD_ID_ETH_PORT_SETUP
, 0, 0, 0, 0);
6155 return bnx2x_wait_ramrod(bp
, BNX2X_STATE_OPEN
, 0, &(bp
->state
), 0);
6159 static int bnx2x_setup_multi(struct bnx2x
*bp
, int index
)
6162 /* reset IGU state */
6163 bnx2x_ack_sb(bp
, index
, CSTORM_ID
, 0, IGU_INT_ENABLE
, 0);
6165 bp
->fp
[index
].state
= BNX2X_FP_STATE_OPENING
;
6166 bnx2x_sp_post(bp
, RAMROD_CMD_ID_ETH_CLIENT_SETUP
, index
, 0, index
, 0);
6168 /* Wait for completion */
6169 return bnx2x_wait_ramrod(bp
, BNX2X_FP_STATE_OPEN
, index
,
6170 &(bp
->fp
[index
].state
), 1);
6175 static int bnx2x_poll(struct napi_struct
*napi
, int budget
);
6176 static void bnx2x_set_rx_mode(struct net_device
*dev
);
6178 static int bnx2x_nic_load(struct bnx2x
*bp
, int req_irq
)
6183 bp
->state
= BNX2X_STATE_OPENING_WAIT4_LOAD
;
6185 /* Send LOAD_REQUEST command to MCP.
6186 Returns the type of LOAD command: if it is the
6187 first port to be initialized common blocks should be
6188 initialized, otherwise - not.
6191 rc
= bnx2x_fw_command(bp
, DRV_MSG_CODE_LOAD_REQ
);
6192 if (rc
== FW_MSG_CODE_DRV_LOAD_REFUSED
) {
6193 return -EBUSY
; /* other port in diagnostic mode */
6196 rc
= FW_MSG_CODE_DRV_LOAD_COMMON
;
6199 DP(NETIF_MSG_IFUP
, "set number of queues to %d\n", bp
->num_queues
);
6201 /* if we can't use msix we only need one fp,
6202 * so try to enable msix with the requested number of fp's
6203 * and fallback to inta with one fp
6210 if (use_multi
> 1 && use_multi
<= 16)
6211 /* user requested number */
6212 bp
->num_queues
= use_multi
;
6213 else if (use_multi
== 1)
6214 bp
->num_queues
= num_online_cpus();
6218 if (bnx2x_enable_msix(bp
)) {
6219 /* faild to enable msix */
6222 BNX2X_ERR("Muti requested but failed"
6223 " to enable MSI-X\n");
6228 if (bnx2x_alloc_mem(bp
))
6232 if (bp
->flags
& USING_MSIX_FLAG
) {
6233 if (bnx2x_req_msix_irqs(bp
)) {
6234 pci_disable_msix(bp
->pdev
);
6239 if (bnx2x_req_irq(bp
)) {
6240 BNX2X_ERR("IRQ request failed, aborting\n");
6246 for_each_queue(bp
, i
)
6247 netif_napi_add(bp
->dev
, &bnx2x_fp(bp
, i
, napi
),
6252 if (bnx2x_function_init(bp
, (rc
== FW_MSG_CODE_DRV_LOAD_COMMON
))) {
6253 BNX2X_ERR("HW init failed, aborting\n");
6258 atomic_set(&bp
->intr_sem
, 0);
6260 /* Reenable SP tasklet */
6261 /*if (bp->sp_task_en) { */
6262 /* tasklet_enable(&bp->sp_task);*/
6264 /* bp->sp_task_en = 1; */
6267 /* Setup NIC internals and enable interrupts */
6270 /* Send LOAD_DONE command to MCP */
6272 rc
= bnx2x_fw_command(bp
, DRV_MSG_CODE_LOAD_DONE
);
6273 DP(NETIF_MSG_IFUP
, "rc = 0x%x\n", rc
);
6275 BNX2X_ERR("MCP response failure, unloading\n");
6280 bp
->state
= BNX2X_STATE_OPENING_WAIT4_PORT
;
6282 /* Enable Rx interrupt handling before sending the ramrod
6283 as it's completed on Rx FP queue */
6284 for_each_queue(bp
, i
)
6285 napi_enable(&bnx2x_fp(bp
, i
, napi
));
6287 if (bnx2x_setup_leading(bp
))
6290 for_each_nondefault_queue(bp
, i
)
6291 if (bnx2x_setup_multi(bp
, i
))
6294 bnx2x_set_mac_addr(bp
);
6298 /* Start fast path */
6299 if (req_irq
) { /* IRQ is only requested from bnx2x_open */
6300 netif_start_queue(bp
->dev
);
6301 if (bp
->flags
& USING_MSIX_FLAG
)
6302 printk(KERN_INFO PFX
"%s: using MSI-X\n",
6305 /* Otherwise Tx queue should be only reenabled */
6306 } else if (netif_running(bp
->dev
)) {
6307 netif_wake_queue(bp
->dev
);
6308 bnx2x_set_rx_mode(bp
->dev
);
6311 /* start the timer */
6312 mod_timer(&bp
->timer
, jiffies
+ bp
->current_interval
);
6317 for_each_queue(bp
, i
)
6318 napi_disable(&bnx2x_fp(bp
, i
, napi
));
6321 bnx2x_disable_int_sync(bp
);
6323 bnx2x_free_skbs(bp
);
6329 /* TBD we really need to reset the chip
6330 if we want to recover from this */
6334 static void bnx2x_netif_stop(struct bnx2x
*bp
)
6338 bp
->rx_mode
= BNX2X_RX_MODE_NONE
;
6339 bnx2x_set_storm_rx_mode(bp
);
6341 bnx2x_disable_int_sync(bp
);
6342 bnx2x_link_reset(bp
);
6344 for_each_queue(bp
, i
)
6345 napi_disable(&bnx2x_fp(bp
, i
, napi
));
6347 if (netif_running(bp
->dev
)) {
6348 netif_tx_disable(bp
->dev
);
6349 bp
->dev
->trans_start
= jiffies
; /* prevent tx timeout */
6353 static void bnx2x_reset_chip(struct bnx2x
*bp
, u32 reset_code
)
6355 int port
= bp
->port
;
6361 DP(NETIF_MSG_IFDOWN
, "reset called with code %x\n", reset_code
);
6363 /* Do not rcv packets to BRB */
6364 REG_WR(bp
, NIG_REG_LLH0_BRB1_DRV_MASK
+ port
*4, 0x0);
6365 /* Do not direct rcv packets that are not for MCP to the BRB */
6366 REG_WR(bp
, (port
? NIG_REG_LLH1_BRB1_NOT_MCP
:
6367 NIG_REG_LLH0_BRB1_NOT_MCP
), 0x0);
6369 /* Configure IGU and AEU */
6370 REG_WR(bp
, HC_REG_CONFIG_0
+ port
*4, 0x1000);
6371 REG_WR(bp
, MISC_REG_AEU_MASK_ATTN_FUNC_0
+ port
*4, 0);
6373 /* TODO: Close Doorbell port? */
6380 base
= port
* RQ_ONCHIP_AT_PORT_SIZE
;
6381 for (i
= base
; i
< base
+ RQ_ONCHIP_AT_PORT_SIZE
; i
++) {
6383 REG_WR_DMAE(bp
, PXP2_REG_RQ_ONCHIP_AT
+ i
*8, wb_write
, 2);
6385 REG_WR_IND(bp
, PXP2_REG_RQ_ONCHIP_AT
, 0);
6386 REG_WR_IND(bp
, PXP2_REG_RQ_ONCHIP_AT
+ 4, 0);
6390 if (reset_code
== FW_MSG_CODE_DRV_UNLOAD_COMMON
) {
6392 REG_WR(bp
, GRCBASE_MISC
+ MISC_REGISTERS_RESET_REG_1_CLEAR
,
6394 REG_WR(bp
, GRCBASE_MISC
+ MISC_REGISTERS_RESET_REG_2_CLEAR
,
6399 static int bnx2x_stop_multi(struct bnx2x
*bp
, int index
)
6404 /* halt the connnection */
6405 bp
->fp
[index
].state
= BNX2X_FP_STATE_HALTING
;
6406 bnx2x_sp_post(bp
, RAMROD_CMD_ID_ETH_HALT
, index
, 0, 0, 0);
6409 rc
= bnx2x_wait_ramrod(bp
, BNX2X_FP_STATE_HALTED
, index
,
6410 &(bp
->fp
[index
].state
), 1);
6411 if (rc
) /* timout */
6414 /* delete cfc entry */
6415 bnx2x_sp_post(bp
, RAMROD_CMD_ID_ETH_CFC_DEL
, index
, 0, 0, 1);
6417 return bnx2x_wait_ramrod(bp
, BNX2X_FP_STATE_DELETED
, index
,
6418 &(bp
->fp
[index
].state
), 1);
6423 static void bnx2x_stop_leading(struct bnx2x
*bp
)
6426 /* if the other port is hadling traffic,
6427 this can take a lot of time */
6432 /* Send HALT ramrod */
6433 bp
->fp
[0].state
= BNX2X_FP_STATE_HALTING
;
6434 bnx2x_sp_post(bp
, RAMROD_CMD_ID_ETH_HALT
, 0, 0, 0, 0);
6436 if (bnx2x_wait_ramrod(bp
, BNX2X_FP_STATE_HALTED
, 0,
6437 &(bp
->fp
[0].state
), 1))
6440 bp
->dsb_sp_prod_idx
= *bp
->dsb_sp_prod
;
6442 /* Send CFC_DELETE ramrod */
6443 bnx2x_sp_post(bp
, RAMROD_CMD_ID_ETH_PORT_DEL
, 0, 0, 0, 1);
6446 Wait for completion.
6447 we are going to reset the chip anyway
6448 so there is not much to do if this times out
6450 while (bp
->dsb_sp_prod_idx
== *bp
->dsb_sp_prod
&& timeout
) {
6457 static int bnx2x_nic_unload(struct bnx2x
*bp
, int fre_irq
)
6463 bp
->state
= BNX2X_STATE_CLOSING_WAIT4_HALT
;
6465 /* Calling flush_scheduled_work() may deadlock because
6466 * linkwatch_event() may be on the workqueue and it will try to get
6467 * the rtnl_lock which we are holding.
6470 while (bp
->in_reset_task
)
6473 /* Delete the timer: do it before disabling interrupts, as it
6474 may be stil STAT_QUERY ramrod pending after stopping the timer */
6475 del_timer_sync(&bp
->timer
);
6477 /* Wait until stat ramrod returns and all SP tasks complete */
6478 while (bp
->stat_pending
&& (bp
->spq_left
!= MAX_SPQ_PENDING
))
6481 /* Stop fast path, disable MAC, disable interrupts, disable napi */
6482 bnx2x_netif_stop(bp
);
6484 if (bp
->flags
& NO_WOL_FLAG
)
6485 reset_code
= DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP
;
6487 u32 emac_base
= bp
->port
? GRCBASE_EMAC0
: GRCBASE_EMAC1
;
6488 u8
*mac_addr
= bp
->dev
->dev_addr
;
6489 u32 val
= (EMAC_MODE_MPKT
| EMAC_MODE_MPKT_RCVD
|
6490 EMAC_MODE_ACPI_RCVD
);
6492 EMAC_WR(EMAC_REG_EMAC_MODE
, val
);
6494 val
= (mac_addr
[0] << 8) | mac_addr
[1];
6495 EMAC_WR(EMAC_REG_EMAC_MAC_MATCH
, val
);
6497 val
= (mac_addr
[2] << 24) | (mac_addr
[3] << 16) |
6498 (mac_addr
[4] << 8) | mac_addr
[5];
6499 EMAC_WR(EMAC_REG_EMAC_MAC_MATCH
+ 4, val
);
6501 reset_code
= DRV_MSG_CODE_UNLOAD_REQ_WOL_EN
;
6503 reset_code
= DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS
;
6505 for_each_nondefault_queue(bp
, i
)
6506 if (bnx2x_stop_multi(bp
, i
))
6510 bnx2x_stop_leading(bp
);
6514 rc
= bnx2x_fw_command(bp
, reset_code
);
6516 rc
= FW_MSG_CODE_DRV_UNLOAD_COMMON
;
6522 /* Reset the chip */
6523 bnx2x_reset_chip(bp
, rc
);
6525 /* Report UNLOAD_DONE to MCP */
6527 bnx2x_fw_command(bp
, DRV_MSG_CODE_UNLOAD_DONE
);
6529 /* Free SKBs and driver internals */
6530 bnx2x_free_skbs(bp
);
6533 bp
->state
= BNX2X_STATE_CLOSED
;
6536 netif_carrier_off(bp
->dev
);
6541 /* end of nic load/unload */
6546 * Init service functions
6549 static void bnx2x_link_settings_supported(struct bnx2x
*bp
, u32 switch_cfg
)
6551 int port
= bp
->port
;
6556 switch (switch_cfg
) {
6558 BNX2X_DEV_INFO("switch_cfg 0x%x (1G)\n", switch_cfg
);
6560 ext_phy_type
= SERDES_EXT_PHY_TYPE(bp
);
6561 switch (ext_phy_type
) {
6562 case PORT_HW_CFG_SERDES_EXT_PHY_TYPE_DIRECT
:
6563 BNX2X_DEV_INFO("ext_phy_type 0x%x (Direct)\n",
6566 bp
->supported
|= (SUPPORTED_10baseT_Half
|
6567 SUPPORTED_10baseT_Full
|
6568 SUPPORTED_100baseT_Half
|
6569 SUPPORTED_100baseT_Full
|
6570 SUPPORTED_1000baseT_Full
|
6571 SUPPORTED_2500baseT_Full
|
6572 SUPPORTED_TP
| SUPPORTED_FIBRE
|
6575 SUPPORTED_Asym_Pause
);
6578 case PORT_HW_CFG_SERDES_EXT_PHY_TYPE_BCM5482
:
6579 BNX2X_DEV_INFO("ext_phy_type 0x%x (5482)\n",
6582 bp
->phy_flags
|= PHY_SGMII_FLAG
;
6584 bp
->supported
|= (/* SUPPORTED_10baseT_Half |
6585 SUPPORTED_10baseT_Full |
6586 SUPPORTED_100baseT_Half |
6587 SUPPORTED_100baseT_Full |*/
6588 SUPPORTED_1000baseT_Full
|
6589 SUPPORTED_TP
| SUPPORTED_FIBRE
|
6592 SUPPORTED_Asym_Pause
);
6596 BNX2X_ERR("NVRAM config error. "
6597 "BAD SerDes ext_phy_config 0x%x\n",
6598 bp
->ext_phy_config
);
6602 bp
->phy_addr
= REG_RD(bp
, NIG_REG_SERDES0_CTRL_PHY_ADDR
+
6604 BNX2X_DEV_INFO("phy_addr 0x%x\n", bp
->phy_addr
);
6607 case SWITCH_CFG_10G
:
6608 BNX2X_DEV_INFO("switch_cfg 0x%x (10G)\n", switch_cfg
);
6610 bp
->phy_flags
|= PHY_XGXS_FLAG
;
6612 ext_phy_type
= XGXS_EXT_PHY_TYPE(bp
);
6613 switch (ext_phy_type
) {
6614 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT
:
6615 BNX2X_DEV_INFO("ext_phy_type 0x%x (Direct)\n",
6618 bp
->supported
|= (SUPPORTED_10baseT_Half
|
6619 SUPPORTED_10baseT_Full
|
6620 SUPPORTED_100baseT_Half
|
6621 SUPPORTED_100baseT_Full
|
6622 SUPPORTED_1000baseT_Full
|
6623 SUPPORTED_2500baseT_Full
|
6624 SUPPORTED_10000baseT_Full
|
6625 SUPPORTED_TP
| SUPPORTED_FIBRE
|
6628 SUPPORTED_Asym_Pause
);
6631 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8705
:
6632 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8706
:
6633 BNX2X_DEV_INFO("ext_phy_type 0x%x (8705/6)\n",
6636 bp
->supported
|= (SUPPORTED_10000baseT_Full
|
6639 SUPPORTED_Asym_Pause
);
6643 BNX2X_ERR("NVRAM config error. "
6644 "BAD XGXS ext_phy_config 0x%x\n",
6645 bp
->ext_phy_config
);
6649 bp
->phy_addr
= REG_RD(bp
, NIG_REG_XGXS0_CTRL_PHY_ADDR
+
6651 BNX2X_DEV_INFO("phy_addr 0x%x\n", bp
->phy_addr
);
6653 bp
->ser_lane
= ((bp
->lane_config
&
6654 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_MASK
) >>
6655 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_SHIFT
);
6656 bp
->rx_lane_swap
= ((bp
->lane_config
&
6657 PORT_HW_CFG_LANE_SWAP_CFG_RX_MASK
) >>
6658 PORT_HW_CFG_LANE_SWAP_CFG_RX_SHIFT
);
6659 bp
->tx_lane_swap
= ((bp
->lane_config
&
6660 PORT_HW_CFG_LANE_SWAP_CFG_TX_MASK
) >>
6661 PORT_HW_CFG_LANE_SWAP_CFG_TX_SHIFT
);
6662 BNX2X_DEV_INFO("rx_lane_swap 0x%x tx_lane_swap 0x%x\n",
6663 bp
->rx_lane_swap
, bp
->tx_lane_swap
);
6667 BNX2X_ERR("BAD switch_cfg link_config 0x%x\n",
6672 /* mask what we support according to speed_cap_mask */
6673 if (!(bp
->speed_cap_mask
&
6674 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF
))
6675 bp
->supported
&= ~SUPPORTED_10baseT_Half
;
6677 if (!(bp
->speed_cap_mask
&
6678 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL
))
6679 bp
->supported
&= ~SUPPORTED_10baseT_Full
;
6681 if (!(bp
->speed_cap_mask
&
6682 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF
))
6683 bp
->supported
&= ~SUPPORTED_100baseT_Half
;
6685 if (!(bp
->speed_cap_mask
&
6686 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL
))
6687 bp
->supported
&= ~SUPPORTED_100baseT_Full
;
6689 if (!(bp
->speed_cap_mask
& PORT_HW_CFG_SPEED_CAPABILITY_D0_1G
))
6690 bp
->supported
&= ~(SUPPORTED_1000baseT_Half
|
6691 SUPPORTED_1000baseT_Full
);
6693 if (!(bp
->speed_cap_mask
& PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G
))
6694 bp
->supported
&= ~SUPPORTED_2500baseT_Full
;
6696 if (!(bp
->speed_cap_mask
& PORT_HW_CFG_SPEED_CAPABILITY_D0_10G
))
6697 bp
->supported
&= ~SUPPORTED_10000baseT_Full
;
6699 BNX2X_DEV_INFO("supported 0x%x\n", bp
->supported
);
6702 static void bnx2x_link_settings_requested(struct bnx2x
*bp
)
6704 bp
->req_autoneg
= 0;
6705 bp
->req_duplex
= DUPLEX_FULL
;
6707 switch (bp
->link_config
& PORT_FEATURE_LINK_SPEED_MASK
) {
6708 case PORT_FEATURE_LINK_SPEED_AUTO
:
6709 if (bp
->supported
& SUPPORTED_Autoneg
) {
6710 bp
->req_autoneg
|= AUTONEG_SPEED
;
6711 bp
->req_line_speed
= 0;
6712 bp
->advertising
= bp
->supported
;
6716 ext_phy_type
= XGXS_EXT_PHY_TYPE(bp
);
6717 if ((ext_phy_type
==
6718 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8705
) ||
6720 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8706
)) {
6721 /* force 10G, no AN */
6722 bp
->req_line_speed
= SPEED_10000
;
6724 (ADVERTISED_10000baseT_Full
|
6728 BNX2X_ERR("NVRAM config error. "
6729 "Invalid link_config 0x%x"
6730 " Autoneg not supported\n",
6736 case PORT_FEATURE_LINK_SPEED_10M_FULL
:
6737 if (bp
->speed_cap_mask
&
6738 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL
) {
6739 bp
->req_line_speed
= SPEED_10
;
6740 bp
->advertising
= (ADVERTISED_10baseT_Full
|
6743 BNX2X_ERR("NVRAM config error. "
6744 "Invalid link_config 0x%x"
6745 " speed_cap_mask 0x%x\n",
6746 bp
->link_config
, bp
->speed_cap_mask
);
6751 case PORT_FEATURE_LINK_SPEED_10M_HALF
:
6752 if (bp
->speed_cap_mask
&
6753 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF
) {
6754 bp
->req_line_speed
= SPEED_10
;
6755 bp
->req_duplex
= DUPLEX_HALF
;
6756 bp
->advertising
= (ADVERTISED_10baseT_Half
|
6759 BNX2X_ERR("NVRAM config error. "
6760 "Invalid link_config 0x%x"
6761 " speed_cap_mask 0x%x\n",
6762 bp
->link_config
, bp
->speed_cap_mask
);
6767 case PORT_FEATURE_LINK_SPEED_100M_FULL
:
6768 if (bp
->speed_cap_mask
&
6769 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL
) {
6770 bp
->req_line_speed
= SPEED_100
;
6771 bp
->advertising
= (ADVERTISED_100baseT_Full
|
6774 BNX2X_ERR("NVRAM config error. "
6775 "Invalid link_config 0x%x"
6776 " speed_cap_mask 0x%x\n",
6777 bp
->link_config
, bp
->speed_cap_mask
);
6782 case PORT_FEATURE_LINK_SPEED_100M_HALF
:
6783 if (bp
->speed_cap_mask
&
6784 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF
) {
6785 bp
->req_line_speed
= SPEED_100
;
6786 bp
->req_duplex
= DUPLEX_HALF
;
6787 bp
->advertising
= (ADVERTISED_100baseT_Half
|
6790 BNX2X_ERR("NVRAM config error. "
6791 "Invalid link_config 0x%x"
6792 " speed_cap_mask 0x%x\n",
6793 bp
->link_config
, bp
->speed_cap_mask
);
6798 case PORT_FEATURE_LINK_SPEED_1G
:
6799 if (bp
->speed_cap_mask
&
6800 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G
) {
6801 bp
->req_line_speed
= SPEED_1000
;
6802 bp
->advertising
= (ADVERTISED_1000baseT_Full
|
6805 BNX2X_ERR("NVRAM config error. "
6806 "Invalid link_config 0x%x"
6807 " speed_cap_mask 0x%x\n",
6808 bp
->link_config
, bp
->speed_cap_mask
);
6813 case PORT_FEATURE_LINK_SPEED_2_5G
:
6814 if (bp
->speed_cap_mask
&
6815 PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G
) {
6816 bp
->req_line_speed
= SPEED_2500
;
6817 bp
->advertising
= (ADVERTISED_2500baseT_Full
|
6820 BNX2X_ERR("NVRAM config error. "
6821 "Invalid link_config 0x%x"
6822 " speed_cap_mask 0x%x\n",
6823 bp
->link_config
, bp
->speed_cap_mask
);
6828 case PORT_FEATURE_LINK_SPEED_10G_CX4
:
6829 case PORT_FEATURE_LINK_SPEED_10G_KX4
:
6830 case PORT_FEATURE_LINK_SPEED_10G_KR
:
6831 if (!(bp
->phy_flags
& PHY_XGXS_FLAG
)) {
6832 BNX2X_ERR("NVRAM config error. "
6833 "Invalid link_config 0x%x"
6834 " phy_flags 0x%x\n",
6835 bp
->link_config
, bp
->phy_flags
);
6838 if (bp
->speed_cap_mask
&
6839 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G
) {
6840 bp
->req_line_speed
= SPEED_10000
;
6841 bp
->advertising
= (ADVERTISED_10000baseT_Full
|
6844 BNX2X_ERR("NVRAM config error. "
6845 "Invalid link_config 0x%x"
6846 " speed_cap_mask 0x%x\n",
6847 bp
->link_config
, bp
->speed_cap_mask
);
6853 BNX2X_ERR("NVRAM config error. "
6854 "BAD link speed link_config 0x%x\n",
6856 bp
->req_autoneg
|= AUTONEG_SPEED
;
6857 bp
->req_line_speed
= 0;
6858 bp
->advertising
= bp
->supported
;
6861 BNX2X_DEV_INFO("req_line_speed %d req_duplex %d\n",
6862 bp
->req_line_speed
, bp
->req_duplex
);
6864 bp
->req_flow_ctrl
= (bp
->link_config
&
6865 PORT_FEATURE_FLOW_CONTROL_MASK
);
6866 /* Please refer to Table 28B-3 of the 802.3ab-1999 spec */
6867 switch (bp
->req_flow_ctrl
) {
6868 case FLOW_CTRL_AUTO
:
6869 bp
->req_autoneg
|= AUTONEG_FLOW_CTRL
;
6870 if (bp
->dev
->mtu
<= 4500) {
6871 bp
->pause_mode
= PAUSE_BOTH
;
6872 bp
->advertising
|= (ADVERTISED_Pause
|
6873 ADVERTISED_Asym_Pause
);
6875 bp
->pause_mode
= PAUSE_ASYMMETRIC
;
6876 bp
->advertising
|= ADVERTISED_Asym_Pause
;
6881 bp
->pause_mode
= PAUSE_ASYMMETRIC
;
6882 bp
->advertising
|= ADVERTISED_Asym_Pause
;
6886 case FLOW_CTRL_BOTH
:
6887 bp
->pause_mode
= PAUSE_BOTH
;
6888 bp
->advertising
|= (ADVERTISED_Pause
|
6889 ADVERTISED_Asym_Pause
);
6892 case FLOW_CTRL_NONE
:
6894 bp
->pause_mode
= PAUSE_NONE
;
6895 bp
->advertising
&= ~(ADVERTISED_Pause
|
6896 ADVERTISED_Asym_Pause
);
6899 BNX2X_DEV_INFO("req_autoneg 0x%x req_flow_ctrl 0x%x\n"
6900 KERN_INFO
" pause_mode %d advertising 0x%x\n",
6901 bp
->req_autoneg
, bp
->req_flow_ctrl
,
6902 bp
->pause_mode
, bp
->advertising
);
6905 static void bnx2x_get_hwinfo(struct bnx2x
*bp
)
6907 u32 val
, val2
, val3
, val4
, id
;
6908 int port
= bp
->port
;
6911 bp
->shmem_base
= REG_RD(bp
, MISC_REG_SHARED_MEM_ADDR
);
6912 BNX2X_DEV_INFO("shmem offset is %x\n", bp
->shmem_base
);
6914 /* Get the chip revision id and number. */
6915 /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
6916 val
= REG_RD(bp
, MISC_REG_CHIP_NUM
);
6917 id
= ((val
& 0xffff) << 16);
6918 val
= REG_RD(bp
, MISC_REG_CHIP_REV
);
6919 id
|= ((val
& 0xf) << 12);
6920 val
= REG_RD(bp
, MISC_REG_CHIP_METAL
);
6921 id
|= ((val
& 0xff) << 4);
6922 REG_RD(bp
, MISC_REG_BOND_ID
);
6925 BNX2X_DEV_INFO("chip ID is %x\n", id
);
6927 if (!bp
->shmem_base
|| (bp
->shmem_base
!= 0xAF900)) {
6928 BNX2X_DEV_INFO("MCP not active\n");
6933 val
= SHMEM_RD(bp
, validity_map
[port
]);
6934 if ((val
& (SHR_MEM_VALIDITY_DEV_INFO
| SHR_MEM_VALIDITY_MB
))
6935 != (SHR_MEM_VALIDITY_DEV_INFO
| SHR_MEM_VALIDITY_MB
))
6936 BNX2X_ERR("MCP validity signature bad\n");
6938 bp
->fw_seq
= (SHMEM_RD(bp
, drv_fw_mb
[port
].drv_mb_header
) &
6939 DRV_MSG_SEQ_NUMBER_MASK
);
6941 bp
->hw_config
= SHMEM_RD(bp
, dev_info
.shared_hw_config
.config
);
6944 SHMEM_RD(bp
, dev_info
.port_hw_config
[bp
->port
].serdes_config
);
6946 SHMEM_RD(bp
, dev_info
.port_hw_config
[port
].lane_config
);
6947 bp
->ext_phy_config
=
6949 dev_info
.port_hw_config
[port
].external_phy_config
);
6950 bp
->speed_cap_mask
=
6952 dev_info
.port_hw_config
[port
].speed_capability_mask
);
6955 SHMEM_RD(bp
, dev_info
.port_feature_config
[port
].link_config
);
6957 BNX2X_DEV_INFO("hw_config (%08x) serdes_config (%08x)\n"
6958 KERN_INFO
" lane_config (%08x) ext_phy_config (%08x)\n"
6959 KERN_INFO
" speed_cap_mask (%08x) link_config (%08x)"
6961 bp
->hw_config
, bp
->serdes_config
, bp
->lane_config
,
6962 bp
->ext_phy_config
, bp
->speed_cap_mask
,
6963 bp
->link_config
, bp
->fw_seq
);
6965 switch_cfg
= (bp
->link_config
& PORT_FEATURE_CONNECTED_SWITCH_MASK
);
6966 bnx2x_link_settings_supported(bp
, switch_cfg
);
6968 bp
->autoneg
= (bp
->hw_config
& SHARED_HW_CFG_AN_ENABLE_MASK
);
6969 /* for now disable cl73 */
6970 bp
->autoneg
&= ~SHARED_HW_CFG_AN_ENABLE_CL73
;
6971 BNX2X_DEV_INFO("autoneg 0x%x\n", bp
->autoneg
);
6973 bnx2x_link_settings_requested(bp
);
6975 val2
= SHMEM_RD(bp
, dev_info
.port_hw_config
[port
].mac_upper
);
6976 val
= SHMEM_RD(bp
, dev_info
.port_hw_config
[port
].mac_lower
);
6977 bp
->dev
->dev_addr
[0] = (u8
)(val2
>> 8 & 0xff);
6978 bp
->dev
->dev_addr
[1] = (u8
)(val2
& 0xff);
6979 bp
->dev
->dev_addr
[2] = (u8
)(val
>> 24 & 0xff);
6980 bp
->dev
->dev_addr
[3] = (u8
)(val
>> 16 & 0xff);
6981 bp
->dev
->dev_addr
[4] = (u8
)(val
>> 8 & 0xff);
6982 bp
->dev
->dev_addr
[5] = (u8
)(val
& 0xff);
6984 memcpy(bp
->dev
->perm_addr
, bp
->dev
->dev_addr
, 6);
6987 val
= SHMEM_RD(bp
, dev_info
.shared_hw_config
.part_num
);
6988 val2
= SHMEM_RD(bp
, dev_info
.shared_hw_config
.part_num
[4]);
6989 val3
= SHMEM_RD(bp
, dev_info
.shared_hw_config
.part_num
[8]);
6990 val4
= SHMEM_RD(bp
, dev_info
.shared_hw_config
.part_num
[12]);
6992 printk(KERN_INFO PFX
"part number %X-%X-%X-%X\n",
6993 val
, val2
, val3
, val4
);
6997 bp
->bc_ver
= val
= ((SHMEM_RD(bp
, dev_info
.bc_rev
)) >> 8);
6998 BNX2X_DEV_INFO("bc_ver %X\n", val
);
6999 if (val
< BNX2X_BC_VER
) {
7000 /* for now only warn
7001 * later we might need to enforce this */
7002 BNX2X_ERR("This driver needs bc_ver %X but found %X,"
7003 " please upgrade BC\n", BNX2X_BC_VER
, val
);
7009 val
= REG_RD(bp
, MCP_REG_MCPR_NVM_CFG4
);
7010 bp
->flash_size
= (NVRAM_1MB_SIZE
<< (val
& MCPR_NVM_CFG4_FLASH_SIZE
));
7011 BNX2X_DEV_INFO("flash_size 0x%x (%d)\n",
7012 bp
->flash_size
, bp
->flash_size
);
7016 set_mac
: /* only supposed to happen on emulation/FPGA */
7017 BNX2X_ERR("warning constant MAC workaround active\n");
7018 bp
->dev
->dev_addr
[0] = 0;
7019 bp
->dev
->dev_addr
[1] = 0x50;
7020 bp
->dev
->dev_addr
[2] = 0xc2;
7021 bp
->dev
->dev_addr
[3] = 0x2c;
7022 bp
->dev
->dev_addr
[4] = 0x71;
7023 bp
->dev
->dev_addr
[5] = port
? 0x0d : 0x0e;
7025 memcpy(bp
->dev
->perm_addr
, bp
->dev
->dev_addr
, 6);
7030 * ethtool service functions
7033 /* All ethtool functions called with rtnl_lock */
7035 static int bnx2x_get_settings(struct net_device
*dev
, struct ethtool_cmd
*cmd
)
7037 struct bnx2x
*bp
= netdev_priv(dev
);
7039 cmd
->supported
= bp
->supported
;
7040 cmd
->advertising
= bp
->advertising
;
7042 if (netif_carrier_ok(dev
)) {
7043 cmd
->speed
= bp
->line_speed
;
7044 cmd
->duplex
= bp
->duplex
;
7046 cmd
->speed
= bp
->req_line_speed
;
7047 cmd
->duplex
= bp
->req_duplex
;
7050 if (bp
->phy_flags
& PHY_XGXS_FLAG
) {
7051 cmd
->port
= PORT_FIBRE
;
7053 cmd
->port
= PORT_TP
;
7056 cmd
->phy_address
= bp
->phy_addr
;
7057 cmd
->transceiver
= XCVR_INTERNAL
;
7059 if (bp
->req_autoneg
& AUTONEG_SPEED
) {
7060 cmd
->autoneg
= AUTONEG_ENABLE
;
7062 cmd
->autoneg
= AUTONEG_DISABLE
;
7068 DP(NETIF_MSG_LINK
, "ethtool_cmd: cmd %d\n"
7069 DP_LEVEL
" supported 0x%x advertising 0x%x speed %d\n"
7070 DP_LEVEL
" duplex %d port %d phy_address %d transceiver %d\n"
7071 DP_LEVEL
" autoneg %d maxtxpkt %d maxrxpkt %d\n",
7072 cmd
->cmd
, cmd
->supported
, cmd
->advertising
, cmd
->speed
,
7073 cmd
->duplex
, cmd
->port
, cmd
->phy_address
, cmd
->transceiver
,
7074 cmd
->autoneg
, cmd
->maxtxpkt
, cmd
->maxrxpkt
);
7079 static int bnx2x_set_settings(struct net_device
*dev
, struct ethtool_cmd
*cmd
)
7081 struct bnx2x
*bp
= netdev_priv(dev
);
7084 DP(NETIF_MSG_LINK
, "ethtool_cmd: cmd %d\n"
7085 DP_LEVEL
" supported 0x%x advertising 0x%x speed %d\n"
7086 DP_LEVEL
" duplex %d port %d phy_address %d transceiver %d\n"
7087 DP_LEVEL
" autoneg %d maxtxpkt %d maxrxpkt %d\n",
7088 cmd
->cmd
, cmd
->supported
, cmd
->advertising
, cmd
->speed
,
7089 cmd
->duplex
, cmd
->port
, cmd
->phy_address
, cmd
->transceiver
,
7090 cmd
->autoneg
, cmd
->maxtxpkt
, cmd
->maxrxpkt
);
7092 switch (cmd
->port
) {
7094 if (!(bp
->supported
& SUPPORTED_TP
))
7097 if (bp
->phy_flags
& PHY_XGXS_FLAG
) {
7098 bnx2x_link_reset(bp
);
7099 bnx2x_link_settings_supported(bp
, SWITCH_CFG_1G
);
7100 bnx2x_phy_deassert(bp
);
7105 if (!(bp
->supported
& SUPPORTED_FIBRE
))
7108 if (!(bp
->phy_flags
& PHY_XGXS_FLAG
)) {
7109 bnx2x_link_reset(bp
);
7110 bnx2x_link_settings_supported(bp
, SWITCH_CFG_10G
);
7111 bnx2x_phy_deassert(bp
);
7119 if (cmd
->autoneg
== AUTONEG_ENABLE
) {
7120 if (!(bp
->supported
& SUPPORTED_Autoneg
))
7123 /* advertise the requested speed and duplex if supported */
7124 cmd
->advertising
&= bp
->supported
;
7126 bp
->req_autoneg
|= AUTONEG_SPEED
;
7127 bp
->req_line_speed
= 0;
7128 bp
->req_duplex
= DUPLEX_FULL
;
7129 bp
->advertising
|= (ADVERTISED_Autoneg
| cmd
->advertising
);
7131 } else { /* forced speed */
7132 /* advertise the requested speed and duplex if supported */
7133 switch (cmd
->speed
) {
7135 if (cmd
->duplex
== DUPLEX_FULL
) {
7136 if (!(bp
->supported
& SUPPORTED_10baseT_Full
))
7139 advertising
= (ADVERTISED_10baseT_Full
|
7142 if (!(bp
->supported
& SUPPORTED_10baseT_Half
))
7145 advertising
= (ADVERTISED_10baseT_Half
|
7151 if (cmd
->duplex
== DUPLEX_FULL
) {
7152 if (!(bp
->supported
&
7153 SUPPORTED_100baseT_Full
))
7156 advertising
= (ADVERTISED_100baseT_Full
|
7159 if (!(bp
->supported
&
7160 SUPPORTED_100baseT_Half
))
7163 advertising
= (ADVERTISED_100baseT_Half
|
7169 if (cmd
->duplex
!= DUPLEX_FULL
)
7172 if (!(bp
->supported
& SUPPORTED_1000baseT_Full
))
7175 advertising
= (ADVERTISED_1000baseT_Full
|
7180 if (cmd
->duplex
!= DUPLEX_FULL
)
7183 if (!(bp
->supported
& SUPPORTED_2500baseT_Full
))
7186 advertising
= (ADVERTISED_2500baseT_Full
|
7191 if (cmd
->duplex
!= DUPLEX_FULL
)
7194 if (!(bp
->supported
& SUPPORTED_10000baseT_Full
))
7197 advertising
= (ADVERTISED_10000baseT_Full
|
7205 bp
->req_autoneg
&= ~AUTONEG_SPEED
;
7206 bp
->req_line_speed
= cmd
->speed
;
7207 bp
->req_duplex
= cmd
->duplex
;
7208 bp
->advertising
= advertising
;
7211 DP(NETIF_MSG_LINK
, "req_autoneg 0x%x req_line_speed %d\n"
7212 DP_LEVEL
" req_duplex %d advertising 0x%x\n",
7213 bp
->req_autoneg
, bp
->req_line_speed
, bp
->req_duplex
,
7216 bnx2x_stop_stats(bp
);
7217 bnx2x_link_initialize(bp
);
7222 static void bnx2x_get_drvinfo(struct net_device
*dev
,
7223 struct ethtool_drvinfo
*info
)
7225 struct bnx2x
*bp
= netdev_priv(dev
);
7227 strcpy(info
->driver
, DRV_MODULE_NAME
);
7228 strcpy(info
->version
, DRV_MODULE_VERSION
);
7229 snprintf(info
->fw_version
, 32, "%d.%d.%d:%d (BC VER %x)",
7230 BCM_5710_FW_MAJOR_VERSION
, BCM_5710_FW_MINOR_VERSION
,
7231 BCM_5710_FW_REVISION_VERSION
, BCM_5710_FW_COMPILE_FLAGS
,
7233 strcpy(info
->bus_info
, pci_name(bp
->pdev
));
7234 info
->n_stats
= BNX2X_NUM_STATS
;
7235 info
->testinfo_len
= BNX2X_NUM_TESTS
;
7236 info
->eedump_len
= bp
->flash_size
;
7237 info
->regdump_len
= 0;
7240 static void bnx2x_get_wol(struct net_device
*dev
, struct ethtool_wolinfo
*wol
)
7242 struct bnx2x
*bp
= netdev_priv(dev
);
7244 if (bp
->flags
& NO_WOL_FLAG
) {
7248 wol
->supported
= WAKE_MAGIC
;
7250 wol
->wolopts
= WAKE_MAGIC
;
7254 memset(&wol
->sopass
, 0, sizeof(wol
->sopass
));
7257 static int bnx2x_set_wol(struct net_device
*dev
, struct ethtool_wolinfo
*wol
)
7259 struct bnx2x
*bp
= netdev_priv(dev
);
7261 if (wol
->wolopts
& ~WAKE_MAGIC
)
7264 if (wol
->wolopts
& WAKE_MAGIC
) {
7265 if (bp
->flags
& NO_WOL_FLAG
)
7275 static u32
bnx2x_get_msglevel(struct net_device
*dev
)
7277 struct bnx2x
*bp
= netdev_priv(dev
);
7279 return bp
->msglevel
;
7282 static void bnx2x_set_msglevel(struct net_device
*dev
, u32 level
)
7284 struct bnx2x
*bp
= netdev_priv(dev
);
7286 if (capable(CAP_NET_ADMIN
))
7287 bp
->msglevel
= level
;
7290 static int bnx2x_nway_reset(struct net_device
*dev
)
7292 struct bnx2x
*bp
= netdev_priv(dev
);
7294 if (bp
->state
!= BNX2X_STATE_OPEN
) {
7295 DP(NETIF_MSG_PROBE
, "state is %x, returning\n", bp
->state
);
7299 bnx2x_stop_stats(bp
);
7300 bnx2x_link_initialize(bp
);
7305 static int bnx2x_get_eeprom_len(struct net_device
*dev
)
7307 struct bnx2x
*bp
= netdev_priv(dev
);
7309 return bp
->flash_size
;
7312 static int bnx2x_acquire_nvram_lock(struct bnx2x
*bp
)
7314 int port
= bp
->port
;
7318 /* adjust timeout for emulation/FPGA */
7319 count
= NVRAM_TIMEOUT_COUNT
;
7320 if (CHIP_REV_IS_SLOW(bp
))
7323 /* request access to nvram interface */
7324 REG_WR(bp
, MCP_REG_MCPR_NVM_SW_ARB
,
7325 (MCPR_NVM_SW_ARB_ARB_REQ_SET1
<< port
));
7327 for (i
= 0; i
< count
*10; i
++) {
7328 val
= REG_RD(bp
, MCP_REG_MCPR_NVM_SW_ARB
);
7329 if (val
& (MCPR_NVM_SW_ARB_ARB_ARB1
<< port
))
7335 if (!(val
& (MCPR_NVM_SW_ARB_ARB_ARB1
<< port
))) {
7336 DP(NETIF_MSG_NVM
, "cannot get access to nvram interface\n");
7343 static int bnx2x_release_nvram_lock(struct bnx2x
*bp
)
7345 int port
= bp
->port
;
7349 /* adjust timeout for emulation/FPGA */
7350 count
= NVRAM_TIMEOUT_COUNT
;
7351 if (CHIP_REV_IS_SLOW(bp
))
7354 /* relinquish nvram interface */
7355 REG_WR(bp
, MCP_REG_MCPR_NVM_SW_ARB
,
7356 (MCPR_NVM_SW_ARB_ARB_REQ_CLR1
<< port
));
7358 for (i
= 0; i
< count
*10; i
++) {
7359 val
= REG_RD(bp
, MCP_REG_MCPR_NVM_SW_ARB
);
7360 if (!(val
& (MCPR_NVM_SW_ARB_ARB_ARB1
<< port
)))
7366 if (val
& (MCPR_NVM_SW_ARB_ARB_ARB1
<< port
)) {
7367 DP(NETIF_MSG_NVM
, "cannot free access to nvram interface\n");
7374 static void bnx2x_enable_nvram_access(struct bnx2x
*bp
)
7378 val
= REG_RD(bp
, MCP_REG_MCPR_NVM_ACCESS_ENABLE
);
7380 /* enable both bits, even on read */
7381 REG_WR(bp
, MCP_REG_MCPR_NVM_ACCESS_ENABLE
,
7382 (val
| MCPR_NVM_ACCESS_ENABLE_EN
|
7383 MCPR_NVM_ACCESS_ENABLE_WR_EN
));
7386 static void bnx2x_disable_nvram_access(struct bnx2x
*bp
)
7390 val
= REG_RD(bp
, MCP_REG_MCPR_NVM_ACCESS_ENABLE
);
7392 /* disable both bits, even after read */
7393 REG_WR(bp
, MCP_REG_MCPR_NVM_ACCESS_ENABLE
,
7394 (val
& ~(MCPR_NVM_ACCESS_ENABLE_EN
|
7395 MCPR_NVM_ACCESS_ENABLE_WR_EN
)));
7398 static int bnx2x_nvram_read_dword(struct bnx2x
*bp
, u32 offset
, u32
*ret_val
,
7405 /* build the command word */
7406 cmd_flags
|= MCPR_NVM_COMMAND_DOIT
;
7408 /* need to clear DONE bit separately */
7409 REG_WR(bp
, MCP_REG_MCPR_NVM_COMMAND
, MCPR_NVM_COMMAND_DONE
);
7411 /* address of the NVRAM to read from */
7412 REG_WR(bp
, MCP_REG_MCPR_NVM_ADDR
,
7413 (offset
& MCPR_NVM_ADDR_NVM_ADDR_VALUE
));
7415 /* issue a read command */
7416 REG_WR(bp
, MCP_REG_MCPR_NVM_COMMAND
, cmd_flags
);
7418 /* adjust timeout for emulation/FPGA */
7419 count
= NVRAM_TIMEOUT_COUNT
;
7420 if (CHIP_REV_IS_SLOW(bp
))
7423 /* wait for completion */
7426 for (i
= 0; i
< count
; i
++) {
7428 val
= REG_RD(bp
, MCP_REG_MCPR_NVM_COMMAND
);
7430 if (val
& MCPR_NVM_COMMAND_DONE
) {
7431 val
= REG_RD(bp
, MCP_REG_MCPR_NVM_READ
);
7432 DP(NETIF_MSG_NVM
, "val 0x%08x\n", val
);
7433 /* we read nvram data in cpu order
7434 * but ethtool sees it as an array of bytes
7435 * converting to big-endian will do the work */
7436 val
= cpu_to_be32(val
);
7446 static int bnx2x_nvram_read(struct bnx2x
*bp
, u32 offset
, u8
*ret_buf
,
7453 if ((offset
& 0x03) || (buf_size
& 0x03) || (buf_size
== 0)) {
7455 "Invalid paramter: offset 0x%x buf_size 0x%x\n",
7460 if (offset
+ buf_size
> bp
->flash_size
) {
7461 DP(NETIF_MSG_NVM
, "Invalid paramter: offset (0x%x) +"
7462 " buf_size (0x%x) > flash_size (0x%x)\n",
7463 offset
, buf_size
, bp
->flash_size
);
7467 /* request access to nvram interface */
7468 rc
= bnx2x_acquire_nvram_lock(bp
);
7472 /* enable access to nvram interface */
7473 bnx2x_enable_nvram_access(bp
);
7475 /* read the first word(s) */
7476 cmd_flags
= MCPR_NVM_COMMAND_FIRST
;
7477 while ((buf_size
> sizeof(u32
)) && (rc
== 0)) {
7478 rc
= bnx2x_nvram_read_dword(bp
, offset
, &val
, cmd_flags
);
7479 memcpy(ret_buf
, &val
, 4);
7481 /* advance to the next dword */
7482 offset
+= sizeof(u32
);
7483 ret_buf
+= sizeof(u32
);
7484 buf_size
-= sizeof(u32
);
7489 cmd_flags
|= MCPR_NVM_COMMAND_LAST
;
7490 rc
= bnx2x_nvram_read_dword(bp
, offset
, &val
, cmd_flags
);
7491 memcpy(ret_buf
, &val
, 4);
7494 /* disable access to nvram interface */
7495 bnx2x_disable_nvram_access(bp
);
7496 bnx2x_release_nvram_lock(bp
);
7501 static int bnx2x_get_eeprom(struct net_device
*dev
,
7502 struct ethtool_eeprom
*eeprom
, u8
*eebuf
)
7504 struct bnx2x
*bp
= netdev_priv(dev
);
7507 DP(NETIF_MSG_NVM
, "ethtool_eeprom: cmd %d\n"
7508 DP_LEVEL
" magic 0x%x offset 0x%x (%d) len 0x%x (%d)\n",
7509 eeprom
->cmd
, eeprom
->magic
, eeprom
->offset
, eeprom
->offset
,
7510 eeprom
->len
, eeprom
->len
);
7512 /* parameters already validated in ethtool_get_eeprom */
7514 rc
= bnx2x_nvram_read(bp
, eeprom
->offset
, eebuf
, eeprom
->len
);
7519 static int bnx2x_nvram_write_dword(struct bnx2x
*bp
, u32 offset
, u32 val
,
7525 /* build the command word */
7526 cmd_flags
|= MCPR_NVM_COMMAND_DOIT
| MCPR_NVM_COMMAND_WR
;
7528 /* need to clear DONE bit separately */
7529 REG_WR(bp
, MCP_REG_MCPR_NVM_COMMAND
, MCPR_NVM_COMMAND_DONE
);
7531 /* write the data */
7532 REG_WR(bp
, MCP_REG_MCPR_NVM_WRITE
, val
);
7534 /* address of the NVRAM to write to */
7535 REG_WR(bp
, MCP_REG_MCPR_NVM_ADDR
,
7536 (offset
& MCPR_NVM_ADDR_NVM_ADDR_VALUE
));
7538 /* issue the write command */
7539 REG_WR(bp
, MCP_REG_MCPR_NVM_COMMAND
, cmd_flags
);
7541 /* adjust timeout for emulation/FPGA */
7542 count
= NVRAM_TIMEOUT_COUNT
;
7543 if (CHIP_REV_IS_SLOW(bp
))
7546 /* wait for completion */
7548 for (i
= 0; i
< count
; i
++) {
7550 val
= REG_RD(bp
, MCP_REG_MCPR_NVM_COMMAND
);
7551 if (val
& MCPR_NVM_COMMAND_DONE
) {
7560 #define BYTE_OFFSET(offset) (8 * (offset & 0x03))
7562 static int bnx2x_nvram_write1(struct bnx2x
*bp
, u32 offset
, u8
*data_buf
,
7570 if (offset
+ buf_size
> bp
->flash_size
) {
7571 DP(NETIF_MSG_NVM
, "Invalid paramter: offset (0x%x) +"
7572 " buf_size (0x%x) > flash_size (0x%x)\n",
7573 offset
, buf_size
, bp
->flash_size
);
7577 /* request access to nvram interface */
7578 rc
= bnx2x_acquire_nvram_lock(bp
);
7582 /* enable access to nvram interface */
7583 bnx2x_enable_nvram_access(bp
);
7585 cmd_flags
= (MCPR_NVM_COMMAND_FIRST
| MCPR_NVM_COMMAND_LAST
);
7586 align_offset
= (offset
& ~0x03);
7587 rc
= bnx2x_nvram_read_dword(bp
, align_offset
, &val
, cmd_flags
);
7590 val
&= ~(0xff << BYTE_OFFSET(offset
));
7591 val
|= (*data_buf
<< BYTE_OFFSET(offset
));
7593 /* nvram data is returned as an array of bytes
7594 * convert it back to cpu order */
7595 val
= be32_to_cpu(val
);
7597 DP(NETIF_MSG_NVM
, "val 0x%08x\n", val
);
7599 rc
= bnx2x_nvram_write_dword(bp
, align_offset
, val
,
7603 /* disable access to nvram interface */
7604 bnx2x_disable_nvram_access(bp
);
7605 bnx2x_release_nvram_lock(bp
);
7610 static int bnx2x_nvram_write(struct bnx2x
*bp
, u32 offset
, u8
*data_buf
,
7618 if (buf_size
== 1) { /* ethtool */
7619 return bnx2x_nvram_write1(bp
, offset
, data_buf
, buf_size
);
7622 if ((offset
& 0x03) || (buf_size
& 0x03) || (buf_size
== 0)) {
7624 "Invalid paramter: offset 0x%x buf_size 0x%x\n",
7629 if (offset
+ buf_size
> bp
->flash_size
) {
7630 DP(NETIF_MSG_NVM
, "Invalid paramter: offset (0x%x) +"
7631 " buf_size (0x%x) > flash_size (0x%x)\n",
7632 offset
, buf_size
, bp
->flash_size
);
7636 /* request access to nvram interface */
7637 rc
= bnx2x_acquire_nvram_lock(bp
);
7641 /* enable access to nvram interface */
7642 bnx2x_enable_nvram_access(bp
);
7645 cmd_flags
= MCPR_NVM_COMMAND_FIRST
;
7646 while ((written_so_far
< buf_size
) && (rc
== 0)) {
7647 if (written_so_far
== (buf_size
- sizeof(u32
)))
7648 cmd_flags
|= MCPR_NVM_COMMAND_LAST
;
7649 else if (((offset
+ 4) % NVRAM_PAGE_SIZE
) == 0)
7650 cmd_flags
|= MCPR_NVM_COMMAND_LAST
;
7651 else if ((offset
% NVRAM_PAGE_SIZE
) == 0)
7652 cmd_flags
|= MCPR_NVM_COMMAND_FIRST
;
7654 memcpy(&val
, data_buf
, 4);
7655 DP(NETIF_MSG_NVM
, "val 0x%08x\n", val
);
7657 rc
= bnx2x_nvram_write_dword(bp
, offset
, val
, cmd_flags
);
7659 /* advance to the next dword */
7660 offset
+= sizeof(u32
);
7661 data_buf
+= sizeof(u32
);
7662 written_so_far
+= sizeof(u32
);
7666 /* disable access to nvram interface */
7667 bnx2x_disable_nvram_access(bp
);
7668 bnx2x_release_nvram_lock(bp
);
7673 static int bnx2x_set_eeprom(struct net_device
*dev
,
7674 struct ethtool_eeprom
*eeprom
, u8
*eebuf
)
7676 struct bnx2x
*bp
= netdev_priv(dev
);
7679 DP(NETIF_MSG_NVM
, "ethtool_eeprom: cmd %d\n"
7680 DP_LEVEL
" magic 0x%x offset 0x%x (%d) len 0x%x (%d)\n",
7681 eeprom
->cmd
, eeprom
->magic
, eeprom
->offset
, eeprom
->offset
,
7682 eeprom
->len
, eeprom
->len
);
7684 /* parameters already validated in ethtool_set_eeprom */
7686 rc
= bnx2x_nvram_write(bp
, eeprom
->offset
, eebuf
, eeprom
->len
);
7691 static int bnx2x_get_coalesce(struct net_device
*dev
,
7692 struct ethtool_coalesce
*coal
)
7694 struct bnx2x
*bp
= netdev_priv(dev
);
7696 memset(coal
, 0, sizeof(struct ethtool_coalesce
));
7698 coal
->rx_coalesce_usecs
= bp
->rx_ticks
;
7699 coal
->tx_coalesce_usecs
= bp
->tx_ticks
;
7700 coal
->stats_block_coalesce_usecs
= bp
->stats_ticks
;
7705 static int bnx2x_set_coalesce(struct net_device
*dev
,
7706 struct ethtool_coalesce
*coal
)
7708 struct bnx2x
*bp
= netdev_priv(dev
);
7710 bp
->rx_ticks
= (u16
) coal
->rx_coalesce_usecs
;
7711 if (bp
->rx_ticks
> 3000)
7712 bp
->rx_ticks
= 3000;
7714 bp
->tx_ticks
= (u16
) coal
->tx_coalesce_usecs
;
7715 if (bp
->tx_ticks
> 0x3000)
7716 bp
->tx_ticks
= 0x3000;
7718 bp
->stats_ticks
= coal
->stats_block_coalesce_usecs
;
7719 if (bp
->stats_ticks
> 0xffff00)
7720 bp
->stats_ticks
= 0xffff00;
7721 bp
->stats_ticks
&= 0xffff00;
7723 if (netif_running(bp
->dev
))
7724 bnx2x_update_coalesce(bp
);
7729 static void bnx2x_get_ringparam(struct net_device
*dev
,
7730 struct ethtool_ringparam
*ering
)
7732 struct bnx2x
*bp
= netdev_priv(dev
);
7734 ering
->rx_max_pending
= MAX_RX_AVAIL
;
7735 ering
->rx_mini_max_pending
= 0;
7736 ering
->rx_jumbo_max_pending
= 0;
7738 ering
->rx_pending
= bp
->rx_ring_size
;
7739 ering
->rx_mini_pending
= 0;
7740 ering
->rx_jumbo_pending
= 0;
7742 ering
->tx_max_pending
= MAX_TX_AVAIL
;
7743 ering
->tx_pending
= bp
->tx_ring_size
;
7746 static int bnx2x_set_ringparam(struct net_device
*dev
,
7747 struct ethtool_ringparam
*ering
)
7749 struct bnx2x
*bp
= netdev_priv(dev
);
7751 if ((ering
->rx_pending
> MAX_RX_AVAIL
) ||
7752 (ering
->tx_pending
> MAX_TX_AVAIL
) ||
7753 (ering
->tx_pending
<= MAX_SKB_FRAGS
+ 4))
7756 bp
->rx_ring_size
= ering
->rx_pending
;
7757 bp
->tx_ring_size
= ering
->tx_pending
;
7759 if (netif_running(bp
->dev
)) {
7760 bnx2x_nic_unload(bp
, 0);
7761 bnx2x_nic_load(bp
, 0);
7767 static void bnx2x_get_pauseparam(struct net_device
*dev
,
7768 struct ethtool_pauseparam
*epause
)
7770 struct bnx2x
*bp
= netdev_priv(dev
);
7773 ((bp
->req_autoneg
& AUTONEG_FLOW_CTRL
) == AUTONEG_FLOW_CTRL
);
7774 epause
->rx_pause
= ((bp
->flow_ctrl
& FLOW_CTRL_RX
) == FLOW_CTRL_RX
);
7775 epause
->tx_pause
= ((bp
->flow_ctrl
& FLOW_CTRL_TX
) == FLOW_CTRL_TX
);
7777 DP(NETIF_MSG_LINK
, "ethtool_pauseparam: cmd %d\n"
7778 DP_LEVEL
" autoneg %d rx_pause %d tx_pause %d\n",
7779 epause
->cmd
, epause
->autoneg
, epause
->rx_pause
, epause
->tx_pause
);
7782 static int bnx2x_set_pauseparam(struct net_device
*dev
,
7783 struct ethtool_pauseparam
*epause
)
7785 struct bnx2x
*bp
= netdev_priv(dev
);
7787 DP(NETIF_MSG_LINK
, "ethtool_pauseparam: cmd %d\n"
7788 DP_LEVEL
" autoneg %d rx_pause %d tx_pause %d\n",
7789 epause
->cmd
, epause
->autoneg
, epause
->rx_pause
, epause
->tx_pause
);
7791 bp
->req_flow_ctrl
= FLOW_CTRL_AUTO
;
7792 if (epause
->autoneg
) {
7793 bp
->req_autoneg
|= AUTONEG_FLOW_CTRL
;
7794 if (bp
->dev
->mtu
<= 4500) {
7795 bp
->pause_mode
= PAUSE_BOTH
;
7796 bp
->advertising
|= (ADVERTISED_Pause
|
7797 ADVERTISED_Asym_Pause
);
7799 bp
->pause_mode
= PAUSE_ASYMMETRIC
;
7800 bp
->advertising
|= ADVERTISED_Asym_Pause
;
7804 bp
->req_autoneg
&= ~AUTONEG_FLOW_CTRL
;
7806 if (epause
->rx_pause
)
7807 bp
->req_flow_ctrl
|= FLOW_CTRL_RX
;
7808 if (epause
->tx_pause
)
7809 bp
->req_flow_ctrl
|= FLOW_CTRL_TX
;
7811 switch (bp
->req_flow_ctrl
) {
7812 case FLOW_CTRL_AUTO
:
7813 bp
->req_flow_ctrl
= FLOW_CTRL_NONE
;
7814 bp
->pause_mode
= PAUSE_NONE
;
7815 bp
->advertising
&= ~(ADVERTISED_Pause
|
7816 ADVERTISED_Asym_Pause
);
7820 bp
->pause_mode
= PAUSE_ASYMMETRIC
;
7821 bp
->advertising
|= ADVERTISED_Asym_Pause
;
7825 case FLOW_CTRL_BOTH
:
7826 bp
->pause_mode
= PAUSE_BOTH
;
7827 bp
->advertising
|= (ADVERTISED_Pause
|
7828 ADVERTISED_Asym_Pause
);
7833 DP(NETIF_MSG_LINK
, "req_autoneg 0x%x req_flow_ctrl 0x%x\n"
7834 DP_LEVEL
" pause_mode %d advertising 0x%x\n",
7835 bp
->req_autoneg
, bp
->req_flow_ctrl
, bp
->pause_mode
,
7838 bnx2x_stop_stats(bp
);
7839 bnx2x_link_initialize(bp
);
7844 static u32
bnx2x_get_rx_csum(struct net_device
*dev
)
7846 struct bnx2x
*bp
= netdev_priv(dev
);
7851 static int bnx2x_set_rx_csum(struct net_device
*dev
, u32 data
)
7853 struct bnx2x
*bp
= netdev_priv(dev
);
7859 static int bnx2x_set_tso(struct net_device
*dev
, u32 data
)
7862 dev
->features
|= (NETIF_F_TSO
| NETIF_F_TSO_ECN
);
7864 dev
->features
&= ~(NETIF_F_TSO
| NETIF_F_TSO_ECN
);
7869 char string
[ETH_GSTRING_LEN
];
7870 } bnx2x_tests_str_arr
[BNX2X_NUM_TESTS
] = {
7871 { "MC Errors (online)" }
7874 static int bnx2x_self_test_count(struct net_device
*dev
)
7876 return BNX2X_NUM_TESTS
;
7879 static void bnx2x_self_test(struct net_device
*dev
,
7880 struct ethtool_test
*etest
, u64
*buf
)
7882 struct bnx2x
*bp
= netdev_priv(dev
);
7885 memset(buf
, 0, sizeof(u64
) * BNX2X_NUM_TESTS
);
7887 if (bp
->state
!= BNX2X_STATE_OPEN
) {
7888 DP(NETIF_MSG_PROBE
, "state is %x, returning\n", bp
->state
);
7892 stats_state
= bp
->stats_state
;
7893 bnx2x_stop_stats(bp
);
7895 if (bnx2x_mc_assert(bp
) != 0) {
7897 etest
->flags
|= ETH_TEST_FL_FAILED
;
7900 #ifdef BNX2X_EXTRA_DEBUG
7901 bnx2x_panic_dump(bp
);
7903 bp
->stats_state
= stats_state
;
7907 char string
[ETH_GSTRING_LEN
];
7908 } bnx2x_stats_str_arr
[BNX2X_NUM_STATS
] = {
7909 { "rx_bytes"}, /* 0 */
7910 { "rx_error_bytes"}, /* 1 */
7911 { "tx_bytes"}, /* 2 */
7912 { "tx_error_bytes"}, /* 3 */
7913 { "rx_ucast_packets"}, /* 4 */
7914 { "rx_mcast_packets"}, /* 5 */
7915 { "rx_bcast_packets"}, /* 6 */
7916 { "tx_ucast_packets"}, /* 7 */
7917 { "tx_mcast_packets"}, /* 8 */
7918 { "tx_bcast_packets"}, /* 9 */
7919 { "tx_mac_errors"}, /* 10 */
7920 { "tx_carrier_errors"}, /* 11 */
7921 { "rx_crc_errors"}, /* 12 */
7922 { "rx_align_errors"}, /* 13 */
7923 { "tx_single_collisions"}, /* 14 */
7924 { "tx_multi_collisions"}, /* 15 */
7925 { "tx_deferred"}, /* 16 */
7926 { "tx_excess_collisions"}, /* 17 */
7927 { "tx_late_collisions"}, /* 18 */
7928 { "tx_total_collisions"}, /* 19 */
7929 { "rx_fragments"}, /* 20 */
7930 { "rx_jabbers"}, /* 21 */
7931 { "rx_undersize_packets"}, /* 22 */
7932 { "rx_oversize_packets"}, /* 23 */
7933 { "rx_xon_frames"}, /* 24 */
7934 { "rx_xoff_frames"}, /* 25 */
7935 { "tx_xon_frames"}, /* 26 */
7936 { "tx_xoff_frames"}, /* 27 */
7937 { "rx_mac_ctrl_frames"}, /* 28 */
7938 { "rx_filtered_packets"}, /* 29 */
7939 { "rx_discards"}, /* 30 */
7942 #define STATS_OFFSET32(offset_name) \
7943 (offsetof(struct bnx2x_eth_stats, offset_name) / 4)
7945 static unsigned long bnx2x_stats_offset_arr
[BNX2X_NUM_STATS
] = {
7946 STATS_OFFSET32(total_bytes_received_hi
), /* 0 */
7947 STATS_OFFSET32(stat_IfHCInBadOctets_hi
), /* 1 */
7948 STATS_OFFSET32(total_bytes_transmitted_hi
), /* 2 */
7949 STATS_OFFSET32(stat_IfHCOutBadOctets_hi
), /* 3 */
7950 STATS_OFFSET32(total_unicast_packets_received_hi
), /* 4 */
7951 STATS_OFFSET32(total_multicast_packets_received_hi
), /* 5 */
7952 STATS_OFFSET32(total_broadcast_packets_received_hi
), /* 6 */
7953 STATS_OFFSET32(total_unicast_packets_transmitted_hi
), /* 7 */
7954 STATS_OFFSET32(total_multicast_packets_transmitted_hi
), /* 8 */
7955 STATS_OFFSET32(total_broadcast_packets_transmitted_hi
), /* 9 */
7956 STATS_OFFSET32(stat_Dot3statsInternalMacTransmitErrors
), /* 10 */
7957 STATS_OFFSET32(stat_Dot3StatsCarrierSenseErrors
), /* 11 */
7958 STATS_OFFSET32(crc_receive_errors
), /* 12 */
7959 STATS_OFFSET32(alignment_errors
), /* 13 */
7960 STATS_OFFSET32(single_collision_transmit_frames
), /* 14 */
7961 STATS_OFFSET32(multiple_collision_transmit_frames
), /* 15 */
7962 STATS_OFFSET32(stat_Dot3StatsDeferredTransmissions
), /* 16 */
7963 STATS_OFFSET32(excessive_collision_frames
), /* 17 */
7964 STATS_OFFSET32(late_collision_frames
), /* 18 */
7965 STATS_OFFSET32(number_of_bugs_found_in_stats_spec
), /* 19 */
7966 STATS_OFFSET32(runt_packets_received
), /* 20 */
7967 STATS_OFFSET32(jabber_packets_received
), /* 21 */
7968 STATS_OFFSET32(error_runt_packets_received
), /* 22 */
7969 STATS_OFFSET32(error_jabber_packets_received
), /* 23 */
7970 STATS_OFFSET32(pause_xon_frames_received
), /* 24 */
7971 STATS_OFFSET32(pause_xoff_frames_received
), /* 25 */
7972 STATS_OFFSET32(pause_xon_frames_transmitted
), /* 26 */
7973 STATS_OFFSET32(pause_xoff_frames_transmitted
), /* 27 */
7974 STATS_OFFSET32(control_frames_received
), /* 28 */
7975 STATS_OFFSET32(mac_filter_discard
), /* 29 */
7976 STATS_OFFSET32(no_buff_discard
), /* 30 */
7979 static u8 bnx2x_stats_len_arr
[BNX2X_NUM_STATS
] = {
7980 8, 0, 8, 0, 8, 8, 8, 8, 8, 8,
7981 4, 0, 4, 4, 4, 4, 4, 4, 4, 4,
7982 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
7986 static void bnx2x_get_strings(struct net_device
*dev
, u32 stringset
, u8
*buf
)
7988 switch (stringset
) {
7990 memcpy(buf
, bnx2x_stats_str_arr
, sizeof(bnx2x_stats_str_arr
));
7994 memcpy(buf
, bnx2x_tests_str_arr
, sizeof(bnx2x_tests_str_arr
));
7999 static int bnx2x_get_stats_count(struct net_device
*dev
)
8001 return BNX2X_NUM_STATS
;
8004 static void bnx2x_get_ethtool_stats(struct net_device
*dev
,
8005 struct ethtool_stats
*stats
, u64
*buf
)
8007 struct bnx2x
*bp
= netdev_priv(dev
);
8008 u32
*hw_stats
= (u32
*)bnx2x_sp_check(bp
, eth_stats
);
8011 for (i
= 0; i
< BNX2X_NUM_STATS
; i
++) {
8012 if (bnx2x_stats_len_arr
[i
] == 0) {
8013 /* skip this counter */
8021 if (bnx2x_stats_len_arr
[i
] == 4) {
8022 /* 4-byte counter */
8023 buf
[i
] = (u64
) *(hw_stats
+ bnx2x_stats_offset_arr
[i
]);
8026 /* 8-byte counter */
8027 buf
[i
] = HILO_U64(*(hw_stats
+ bnx2x_stats_offset_arr
[i
]),
8028 *(hw_stats
+ bnx2x_stats_offset_arr
[i
] + 1));
8032 static int bnx2x_phys_id(struct net_device
*dev
, u32 data
)
8034 struct bnx2x
*bp
= netdev_priv(dev
);
8040 for (i
= 0; i
< (data
* 2); i
++) {
8042 bnx2x_leds_set(bp
, SPEED_1000
);
8044 bnx2x_leds_unset(bp
);
8046 msleep_interruptible(500);
8047 if (signal_pending(current
))
8052 bnx2x_leds_set(bp
, bp
->line_speed
);
8057 static struct ethtool_ops bnx2x_ethtool_ops
= {
8058 .get_settings
= bnx2x_get_settings
,
8059 .set_settings
= bnx2x_set_settings
,
8060 .get_drvinfo
= bnx2x_get_drvinfo
,
8061 .get_wol
= bnx2x_get_wol
,
8062 .set_wol
= bnx2x_set_wol
,
8063 .get_msglevel
= bnx2x_get_msglevel
,
8064 .set_msglevel
= bnx2x_set_msglevel
,
8065 .nway_reset
= bnx2x_nway_reset
,
8066 .get_link
= ethtool_op_get_link
,
8067 .get_eeprom_len
= bnx2x_get_eeprom_len
,
8068 .get_eeprom
= bnx2x_get_eeprom
,
8069 .set_eeprom
= bnx2x_set_eeprom
,
8070 .get_coalesce
= bnx2x_get_coalesce
,
8071 .set_coalesce
= bnx2x_set_coalesce
,
8072 .get_ringparam
= bnx2x_get_ringparam
,
8073 .set_ringparam
= bnx2x_set_ringparam
,
8074 .get_pauseparam
= bnx2x_get_pauseparam
,
8075 .set_pauseparam
= bnx2x_set_pauseparam
,
8076 .get_rx_csum
= bnx2x_get_rx_csum
,
8077 .set_rx_csum
= bnx2x_set_rx_csum
,
8078 .get_tx_csum
= ethtool_op_get_tx_csum
,
8079 .set_tx_csum
= ethtool_op_set_tx_csum
,
8080 .get_sg
= ethtool_op_get_sg
,
8081 .set_sg
= ethtool_op_set_sg
,
8082 .get_tso
= ethtool_op_get_tso
,
8083 .set_tso
= bnx2x_set_tso
,
8084 .self_test_count
= bnx2x_self_test_count
,
8085 .self_test
= bnx2x_self_test
,
8086 .get_strings
= bnx2x_get_strings
,
8087 .phys_id
= bnx2x_phys_id
,
8088 .get_stats_count
= bnx2x_get_stats_count
,
8089 .get_ethtool_stats
= bnx2x_get_ethtool_stats
8092 /* end of ethtool_ops */
8094 /****************************************************************************
8095 * General service functions
8096 ****************************************************************************/
8098 static int bnx2x_set_power_state(struct bnx2x
*bp
, pci_power_t state
)
8102 pci_read_config_word(bp
->pdev
, bp
->pm_cap
+ PCI_PM_CTRL
, &pmcsr
);
8106 pci_write_config_word(bp
->pdev
,
8107 bp
->pm_cap
+ PCI_PM_CTRL
,
8108 ((pmcsr
& ~PCI_PM_CTRL_STATE_MASK
) |
8109 PCI_PM_CTRL_PME_STATUS
));
8111 if (pmcsr
& PCI_PM_CTRL_STATE_MASK
)
8112 /* delay required during transition out of D3hot */
8117 pmcsr
&= ~PCI_PM_CTRL_STATE_MASK
;
8121 pmcsr
|= PCI_PM_CTRL_PME_ENABLE
;
8123 pci_write_config_word(bp
->pdev
, bp
->pm_cap
+ PCI_PM_CTRL
,
8126 /* No more memory access after this point until
8127 * device is brought back to D0.
8138 * net_device service functions
8141 /* Called with rtnl_lock from vlan functions and also netif_tx_lock
8142 * from set_multicast.
8144 static void bnx2x_set_rx_mode(struct net_device
*dev
)
8146 struct bnx2x
*bp
= netdev_priv(dev
);
8147 u32 rx_mode
= BNX2X_RX_MODE_NORMAL
;
8149 DP(NETIF_MSG_IFUP
, "called dev->flags = %x\n", dev
->flags
);
8151 if (dev
->flags
& IFF_PROMISC
)
8152 rx_mode
= BNX2X_RX_MODE_PROMISC
;
8154 else if ((dev
->flags
& IFF_ALLMULTI
) ||
8155 (dev
->mc_count
> BNX2X_MAX_MULTICAST
))
8156 rx_mode
= BNX2X_RX_MODE_ALLMULTI
;
8158 else { /* some multicasts */
8160 struct dev_mc_list
*mclist
;
8161 struct mac_configuration_cmd
*config
=
8162 bnx2x_sp(bp
, mcast_config
);
8164 for (i
= 0, mclist
= dev
->mc_list
;
8165 mclist
&& (i
< dev
->mc_count
);
8166 i
++, mclist
= mclist
->next
) {
8168 config
->config_table
[i
].cam_entry
.msb_mac_addr
=
8169 swab16(*(u16
*)&mclist
->dmi_addr
[0]);
8170 config
->config_table
[i
].cam_entry
.middle_mac_addr
=
8171 swab16(*(u16
*)&mclist
->dmi_addr
[2]);
8172 config
->config_table
[i
].cam_entry
.lsb_mac_addr
=
8173 swab16(*(u16
*)&mclist
->dmi_addr
[4]);
8174 config
->config_table
[i
].cam_entry
.flags
=
8175 cpu_to_le16(bp
->port
);
8176 config
->config_table
[i
].target_table_entry
.flags
= 0;
8177 config
->config_table
[i
].target_table_entry
.
8179 config
->config_table
[i
].target_table_entry
.
8183 "setting MCAST[%d] (%04x:%04x:%04x)\n",
8184 i
, config
->config_table
[i
].cam_entry
.msb_mac_addr
,
8185 config
->config_table
[i
].cam_entry
.middle_mac_addr
,
8186 config
->config_table
[i
].cam_entry
.lsb_mac_addr
);
8188 old
= config
->hdr
.length_6b
;
8190 for (; i
< old
; i
++) {
8191 if (CAM_IS_INVALID(config
->config_table
[i
])) {
8192 i
--; /* already invalidated */
8196 CAM_INVALIDATE(config
->config_table
[i
]);
8200 if (CHIP_REV_IS_SLOW(bp
))
8201 offset
= BNX2X_MAX_EMUL_MULTI
*(1 + bp
->port
);
8203 offset
= BNX2X_MAX_MULTICAST
*(1 + bp
->port
);
8205 config
->hdr
.length_6b
= i
;
8206 config
->hdr
.offset
= offset
;
8207 config
->hdr
.reserved0
= 0;
8208 config
->hdr
.reserved1
= 0;
8210 bnx2x_sp_post(bp
, RAMROD_CMD_ID_ETH_SET_MAC
, 0,
8211 U64_HI(bnx2x_sp_mapping(bp
, mcast_config
)),
8212 U64_LO(bnx2x_sp_mapping(bp
, mcast_config
)), 0);
8215 bp
->rx_mode
= rx_mode
;
8216 bnx2x_set_storm_rx_mode(bp
);
8219 static int bnx2x_poll(struct napi_struct
*napi
, int budget
)
8221 struct bnx2x_fastpath
*fp
= container_of(napi
, struct bnx2x_fastpath
,
8223 struct bnx2x
*bp
= fp
->bp
;
8226 #ifdef BNX2X_STOP_ON_ERROR
8227 if (unlikely(bp
->panic
))
8231 prefetch(fp
->tx_buf_ring
[TX_BD(fp
->tx_pkt_cons
)].skb
);
8232 prefetch(fp
->rx_buf_ring
[RX_BD(fp
->rx_bd_cons
)].skb
);
8233 prefetch((char *)(fp
->rx_buf_ring
[RX_BD(fp
->rx_bd_cons
)].skb
) + 256);
8235 bnx2x_update_fpsb_idx(fp
);
8237 if (le16_to_cpu(*fp
->tx_cons_sb
) != fp
->tx_pkt_cons
)
8238 bnx2x_tx_int(fp
, budget
);
8241 if (le16_to_cpu(*fp
->rx_cons_sb
) != fp
->rx_comp_cons
)
8242 work_done
= bnx2x_rx_int(fp
, budget
);
8245 rmb(); /* bnx2x_has_work() reads the status block */
8247 /* must not complete if we consumed full budget */
8248 if ((work_done
< budget
) && !bnx2x_has_work(fp
)) {
8250 #ifdef BNX2X_STOP_ON_ERROR
8253 netif_rx_complete(bp
->dev
, napi
);
8255 bnx2x_ack_sb(bp
, fp
->index
, USTORM_ID
,
8256 le16_to_cpu(fp
->fp_u_idx
), IGU_INT_NOP
, 1);
8257 bnx2x_ack_sb(bp
, fp
->index
, CSTORM_ID
,
8258 le16_to_cpu(fp
->fp_c_idx
), IGU_INT_ENABLE
, 1);
8264 /* Called with netif_tx_lock.
8265 * bnx2x_tx_int() runs without netif_tx_lock unless it needs to call
8266 * netif_wake_queue().
8268 static int bnx2x_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
8270 struct bnx2x
*bp
= netdev_priv(dev
);
8271 struct bnx2x_fastpath
*fp
;
8272 struct sw_tx_bd
*tx_buf
;
8273 struct eth_tx_bd
*tx_bd
;
8274 struct eth_tx_parse_bd
*pbd
= NULL
;
8275 u16 pkt_prod
, bd_prod
;
8276 int nbd
, fp_index
= 0;
8279 #ifdef BNX2X_STOP_ON_ERROR
8280 if (unlikely(bp
->panic
))
8281 return NETDEV_TX_BUSY
;
8284 fp_index
= smp_processor_id() % (bp
->num_queues
);
8286 fp
= &bp
->fp
[fp_index
];
8287 if (unlikely(bnx2x_tx_avail(bp
->fp
) <
8288 (skb_shinfo(skb
)->nr_frags
+ 3))) {
8289 bp
->slowpath
->eth_stats
.driver_xoff
++,
8290 netif_stop_queue(dev
);
8291 BNX2X_ERR("BUG! Tx ring full when queue awake!\n");
8292 return NETDEV_TX_BUSY
;
8296 This is a bit ugly. First we use one BD which we mark as start,
8297 then for TSO or xsum we have a parsing info BD,
8298 and only then we have the rest of the TSO bds.
8299 (don't forget to mark the last one as last,
8300 and to unmap only AFTER you write to the BD ...)
8301 I would like to thank DovH for this mess.
8304 pkt_prod
= fp
->tx_pkt_prod
++;
8305 bd_prod
= fp
->tx_bd_prod
;
8306 bd_prod
= TX_BD(bd_prod
);
8308 /* get a tx_buff and first bd */
8309 tx_buf
= &fp
->tx_buf_ring
[TX_BD(pkt_prod
)];
8310 tx_bd
= &fp
->tx_desc_ring
[bd_prod
];
8312 tx_bd
->bd_flags
.as_bitfield
= ETH_TX_BD_FLAGS_START_BD
;
8313 tx_bd
->general_data
= (UNICAST_ADDRESS
<<
8314 ETH_TX_BD_ETH_ADDR_TYPE_SHIFT
);
8315 tx_bd
->general_data
|= 1; /* header nbd */
8317 /* remeber the first bd of the packet */
8318 tx_buf
->first_bd
= bd_prod
;
8320 DP(NETIF_MSG_TX_QUEUED
,
8321 "sending pkt %u @%p next_idx %u bd %u @%p\n",
8322 pkt_prod
, tx_buf
, fp
->tx_pkt_prod
, bd_prod
, tx_bd
);
8324 if (skb
->ip_summed
== CHECKSUM_PARTIAL
) {
8325 struct iphdr
*iph
= ip_hdr(skb
);
8328 tx_bd
->bd_flags
.as_bitfield
|= ETH_TX_BD_FLAGS_IP_CSUM
;
8330 /* turn on parsing and get a bd */
8331 bd_prod
= TX_BD(NEXT_TX_IDX(bd_prod
));
8332 pbd
= (void *)&fp
->tx_desc_ring
[bd_prod
];
8333 len
= ((u8
*)iph
- (u8
*)skb
->data
) / 2;
8335 /* for now NS flag is not used in Linux */
8336 pbd
->global_data
= (len
|
8337 ((skb
->protocol
== ETH_P_8021Q
) <<
8338 ETH_TX_PARSE_BD_LLC_SNAP_EN_SHIFT
));
8339 pbd
->ip_hlen
= ip_hdrlen(skb
) / 2;
8340 pbd
->total_hlen
= cpu_to_le16(len
+ pbd
->ip_hlen
);
8341 if (iph
->protocol
== IPPROTO_TCP
) {
8342 struct tcphdr
*th
= tcp_hdr(skb
);
8344 tx_bd
->bd_flags
.as_bitfield
|=
8345 ETH_TX_BD_FLAGS_TCP_CSUM
;
8346 pbd
->tcp_flags
= htonl(tcp_flag_word(skb
)) & 0xFFFF;
8347 pbd
->total_hlen
+= cpu_to_le16(tcp_hdrlen(skb
) / 2);
8348 pbd
->tcp_pseudo_csum
= swab16(th
->check
);
8350 } else if (iph
->protocol
== IPPROTO_UDP
) {
8351 struct udphdr
*uh
= udp_hdr(skb
);
8353 tx_bd
->bd_flags
.as_bitfield
|=
8354 ETH_TX_BD_FLAGS_TCP_CSUM
;
8355 pbd
->total_hlen
+= cpu_to_le16(4);
8356 pbd
->global_data
|= ETH_TX_PARSE_BD_CS_ANY_FLG
;
8357 pbd
->cs_offset
= 5; /* 10 >> 1 */
8358 pbd
->tcp_pseudo_csum
= 0;
8359 /* HW bug: we need to subtract 10 bytes before the
8360 * UDP header from the csum
8362 uh
->check
= (u16
) ~csum_fold(csum_sub(uh
->check
,
8363 csum_partial(((u8
*)(uh
)-10), 10, 0)));
8367 if ((bp
->vlgrp
!= NULL
) && vlan_tx_tag_present(skb
)) {
8368 tx_bd
->vlan
= cpu_to_le16(vlan_tx_tag_get(skb
));
8369 tx_bd
->bd_flags
.as_bitfield
|= ETH_TX_BD_FLAGS_VLAN_TAG
;
8371 tx_bd
->vlan
= cpu_to_le16(pkt_prod
);
8374 mapping
= pci_map_single(bp
->pdev
, skb
->data
,
8375 skb
->len
, PCI_DMA_TODEVICE
);
8377 tx_bd
->addr_hi
= cpu_to_le32(U64_HI(mapping
));
8378 tx_bd
->addr_lo
= cpu_to_le32(U64_LO(mapping
));
8379 nbd
= skb_shinfo(skb
)->nr_frags
+ ((pbd
== NULL
)? 1 : 2);
8380 tx_bd
->nbd
= cpu_to_le16(nbd
);
8381 tx_bd
->nbytes
= cpu_to_le16(skb_headlen(skb
));
8383 DP(NETIF_MSG_TX_QUEUED
, "first bd @%p addr (%x:%x) nbd %d"
8384 " nbytes %d flags %x vlan %u\n",
8385 tx_bd
, tx_bd
->addr_hi
, tx_bd
->addr_lo
, tx_bd
->nbd
,
8386 tx_bd
->nbytes
, tx_bd
->bd_flags
.as_bitfield
, tx_bd
->vlan
);
8388 if (skb_shinfo(skb
)->gso_size
&&
8389 (skb
->len
> (bp
->dev
->mtu
+ ETH_HLEN
))) {
8390 int hlen
= 2 * le32_to_cpu(pbd
->total_hlen
);
8392 DP(NETIF_MSG_TX_QUEUED
,
8393 "TSO packet len %d hlen %d total len %d tso size %d\n",
8394 skb
->len
, hlen
, skb_headlen(skb
),
8395 skb_shinfo(skb
)->gso_size
);
8397 tx_bd
->bd_flags
.as_bitfield
|= ETH_TX_BD_FLAGS_SW_LSO
;
8399 if (tx_bd
->nbytes
> cpu_to_le16(hlen
)) {
8400 /* we split the first bd into headers and data bds
8401 * to ease the pain of our fellow micocode engineers
8402 * we use one mapping for both bds
8403 * So far this has only been observed to happen
8404 * in Other Operating Systems(TM)
8407 /* first fix first bd */
8409 tx_bd
->nbd
= cpu_to_le16(nbd
);
8410 tx_bd
->nbytes
= cpu_to_le16(hlen
);
8412 /* we only print this as an error
8413 * because we don't think this will ever happen.
8415 BNX2X_ERR("TSO split header size is %d (%x:%x)"
8416 " nbd %d\n", tx_bd
->nbytes
, tx_bd
->addr_hi
,
8417 tx_bd
->addr_lo
, tx_bd
->nbd
);
8419 /* now get a new data bd
8420 * (after the pbd) and fill it */
8421 bd_prod
= TX_BD(NEXT_TX_IDX(bd_prod
));
8422 tx_bd
= &fp
->tx_desc_ring
[bd_prod
];
8424 tx_bd
->addr_hi
= cpu_to_le32(U64_HI(mapping
));
8425 tx_bd
->addr_lo
= cpu_to_le32(U64_LO(mapping
) + hlen
);
8426 tx_bd
->nbytes
= cpu_to_le16(skb_headlen(skb
) - hlen
);
8427 tx_bd
->vlan
= cpu_to_le16(pkt_prod
);
8428 /* this marks the bd
8429 * as one that has no individual mapping
8430 * the FW ignors this flag in a bd not maked start
8432 tx_bd
->bd_flags
.as_bitfield
= ETH_TX_BD_FLAGS_SW_LSO
;
8433 DP(NETIF_MSG_TX_QUEUED
,
8434 "TSO split data size is %d (%x:%x)\n",
8435 tx_bd
->nbytes
, tx_bd
->addr_hi
, tx_bd
->addr_lo
);
8439 /* supposed to be unreached
8440 * (and therefore not handled properly...)
8442 BNX2X_ERR("LSO with no PBD\n");
8446 pbd
->lso_mss
= cpu_to_le16(skb_shinfo(skb
)->gso_size
);
8447 pbd
->tcp_send_seq
= swab32(tcp_hdr(skb
)->seq
);
8448 pbd
->ip_id
= swab16(ip_hdr(skb
)->id
);
8449 pbd
->tcp_pseudo_csum
=
8450 swab16(~csum_tcpudp_magic(ip_hdr(skb
)->saddr
,
8452 0, IPPROTO_TCP
, 0));
8453 pbd
->global_data
|= ETH_TX_PARSE_BD_PSEUDO_CS_WITHOUT_LEN
;
8459 for (i
= 0; i
< skb_shinfo(skb
)->nr_frags
; i
++) {
8460 skb_frag_t
*frag
= &skb_shinfo(skb
)->frags
[i
];
8462 bd_prod
= TX_BD(NEXT_TX_IDX(bd_prod
));
8463 tx_bd
= &fp
->tx_desc_ring
[bd_prod
];
8465 mapping
= pci_map_page(bp
->pdev
, frag
->page
,
8467 frag
->size
, PCI_DMA_TODEVICE
);
8469 tx_bd
->addr_hi
= cpu_to_le32(U64_HI(mapping
));
8470 tx_bd
->addr_lo
= cpu_to_le32(U64_LO(mapping
));
8471 tx_bd
->nbytes
= cpu_to_le16(frag
->size
);
8472 tx_bd
->vlan
= cpu_to_le16(pkt_prod
);
8473 tx_bd
->bd_flags
.as_bitfield
= 0;
8474 DP(NETIF_MSG_TX_QUEUED
, "frag %d bd @%p"
8475 " addr (%x:%x) nbytes %d flags %x\n",
8476 i
, tx_bd
, tx_bd
->addr_hi
, tx_bd
->addr_lo
,
8477 tx_bd
->nbytes
, tx_bd
->bd_flags
.as_bitfield
);
8481 /* now at last mark the bd as the last bd */
8482 tx_bd
->bd_flags
.as_bitfield
|= ETH_TX_BD_FLAGS_END_BD
;
8484 DP(NETIF_MSG_TX_QUEUED
, "last bd @%p flags %x\n",
8485 tx_bd
, tx_bd
->bd_flags
.as_bitfield
);
8489 bd_prod
= TX_BD(NEXT_TX_IDX(bd_prod
));
8491 /* now send a tx doorbell, counting the next bd
8492 * if the packet contains or ends with it
8494 if (TX_BD_POFF(bd_prod
) < nbd
)
8498 DP(NETIF_MSG_TX_QUEUED
,
8499 "PBD @%p ip_data %x ip_hlen %u ip_id %u lso_mss %u"
8500 " tcp_flags %x xsum %x seq %u hlen %u\n",
8501 pbd
, pbd
->global_data
, pbd
->ip_hlen
, pbd
->ip_id
,
8502 pbd
->lso_mss
, pbd
->tcp_flags
, pbd
->tcp_pseudo_csum
,
8503 pbd
->tcp_send_seq
, pbd
->total_hlen
);
8505 DP(NETIF_MSG_TX_QUEUED
, "doorbell: nbd %u bd %d\n", nbd
, bd_prod
);
8507 fp
->hw_tx_prods
->bds_prod
+= cpu_to_le16(nbd
);
8508 mb(); /* FW restriction: must not reorder writing nbd and packets */
8509 fp
->hw_tx_prods
->packets_prod
+= cpu_to_le32(1);
8510 DOORBELL(bp
, fp_index
, 0);
8514 fp
->tx_bd_prod
= bd_prod
;
8515 dev
->trans_start
= jiffies
;
8517 if (unlikely(bnx2x_tx_avail(fp
) < MAX_SKB_FRAGS
+ 3)) {
8518 netif_stop_queue(dev
);
8519 bp
->slowpath
->eth_stats
.driver_xoff
++;
8520 if (bnx2x_tx_avail(fp
) >= MAX_SKB_FRAGS
+ 3)
8521 netif_wake_queue(dev
);
8525 return NETDEV_TX_OK
;
8528 static struct net_device_stats
*bnx2x_get_stats(struct net_device
*dev
)
8533 /* Called with rtnl_lock */
8534 static int bnx2x_open(struct net_device
*dev
)
8536 struct bnx2x
*bp
= netdev_priv(dev
);
8538 bnx2x_set_power_state(bp
, PCI_D0
);
8540 return bnx2x_nic_load(bp
, 1);
8543 /* Called with rtnl_lock */
8544 static int bnx2x_close(struct net_device
*dev
)
8547 struct bnx2x
*bp
= netdev_priv(dev
);
8549 /* Unload the driver, release IRQs */
8550 rc
= bnx2x_nic_unload(bp
, 1);
8552 BNX2X_ERR("bnx2x_nic_unload failed: %d\n", rc
);
8555 bnx2x_set_power_state(bp
, PCI_D3hot
);
8560 /* Called with rtnl_lock */
8561 static int bnx2x_change_mac_addr(struct net_device
*dev
, void *p
)
8563 struct sockaddr
*addr
= p
;
8564 struct bnx2x
*bp
= netdev_priv(dev
);
8566 if (!is_valid_ether_addr(addr
->sa_data
))
8569 memcpy(dev
->dev_addr
, addr
->sa_data
, dev
->addr_len
);
8570 if (netif_running(dev
))
8571 bnx2x_set_mac_addr(bp
);
8576 /* Called with rtnl_lock */
8577 static int bnx2x_ioctl(struct net_device
*dev
, struct ifreq
*ifr
, int cmd
)
8579 struct mii_ioctl_data
*data
= if_mii(ifr
);
8580 struct bnx2x
*bp
= netdev_priv(dev
);
8585 data
->phy_id
= bp
->phy_addr
;
8591 spin_lock_bh(&bp
->phy_lock
);
8592 if (bp
->state
== BNX2X_STATE_OPEN
) {
8593 err
= bnx2x_mdio22_read(bp
, data
->reg_num
& 0x1f,
8596 data
->val_out
= mii_regval
;
8600 spin_unlock_bh(&bp
->phy_lock
);
8605 if (!capable(CAP_NET_ADMIN
))
8608 spin_lock_bh(&bp
->phy_lock
);
8609 if (bp
->state
== BNX2X_STATE_OPEN
) {
8610 err
= bnx2x_mdio22_write(bp
, data
->reg_num
& 0x1f,
8615 spin_unlock_bh(&bp
->phy_lock
);
8626 /* Called with rtnl_lock */
8627 static int bnx2x_change_mtu(struct net_device
*dev
, int new_mtu
)
8629 struct bnx2x
*bp
= netdev_priv(dev
);
8631 if ((new_mtu
> ETH_MAX_JUMBO_PACKET_SIZE
) ||
8632 ((new_mtu
+ ETH_HLEN
) < ETH_MIN_PACKET_SIZE
))
8635 /* This does not race with packet allocation
8636 * because the actuall alloc size is
8637 * only updated as part of load
8641 if (netif_running(dev
)) {
8642 bnx2x_nic_unload(bp
, 0);
8643 bnx2x_nic_load(bp
, 0);
8648 static void bnx2x_tx_timeout(struct net_device
*dev
)
8650 struct bnx2x
*bp
= netdev_priv(dev
);
8652 #ifdef BNX2X_STOP_ON_ERROR
8656 /* This allows the netif to be shutdown gracefully before resetting */
8657 schedule_work(&bp
->reset_task
);
8661 /* Called with rtnl_lock */
8662 static void bnx2x_vlan_rx_register(struct net_device
*dev
,
8663 struct vlan_group
*vlgrp
)
8665 struct bnx2x
*bp
= netdev_priv(dev
);
8668 if (netif_running(dev
))
8669 bnx2x_set_rx_mode(dev
);
8673 #if defined(HAVE_POLL_CONTROLLER) || defined(CONFIG_NET_POLL_CONTROLLER)
8674 static void poll_bnx2x(struct net_device
*dev
)
8676 struct bnx2x
*bp
= netdev_priv(dev
);
8678 disable_irq(bp
->pdev
->irq
);
8679 bnx2x_interrupt(bp
->pdev
->irq
, dev
);
8680 enable_irq(bp
->pdev
->irq
);
8684 static void bnx2x_reset_task(struct work_struct
*work
)
8686 struct bnx2x
*bp
= container_of(work
, struct bnx2x
, reset_task
);
8688 #ifdef BNX2X_STOP_ON_ERROR
8689 BNX2X_ERR("reset task called but STOP_ON_ERROR defined"
8690 " so reset not done to allow debug dump,\n"
8691 KERN_ERR
" you will need to reboot when done\n");
8695 if (!netif_running(bp
->dev
))
8698 bp
->in_reset_task
= 1;
8700 bnx2x_netif_stop(bp
);
8702 bnx2x_nic_unload(bp
, 0);
8703 bnx2x_nic_load(bp
, 0);
8705 bp
->in_reset_task
= 0;
8708 static int __devinit
bnx2x_init_board(struct pci_dev
*pdev
,
8709 struct net_device
*dev
)
8714 SET_NETDEV_DEV(dev
, &pdev
->dev
);
8715 bp
= netdev_priv(dev
);
8718 bp
->port
= PCI_FUNC(pdev
->devfn
);
8720 rc
= pci_enable_device(pdev
);
8722 printk(KERN_ERR PFX
"Cannot enable PCI device, aborting\n");
8726 if (!(pci_resource_flags(pdev
, 0) & IORESOURCE_MEM
)) {
8727 printk(KERN_ERR PFX
"Cannot find PCI device base address,"
8730 goto err_out_disable
;
8733 if (!(pci_resource_flags(pdev
, 2) & IORESOURCE_MEM
)) {
8734 printk(KERN_ERR PFX
"Cannot find second PCI device"
8735 " base address, aborting\n");
8737 goto err_out_disable
;
8740 rc
= pci_request_regions(pdev
, DRV_MODULE_NAME
);
8742 printk(KERN_ERR PFX
"Cannot obtain PCI resources,"
8744 goto err_out_disable
;
8747 pci_set_master(pdev
);
8749 bp
->pm_cap
= pci_find_capability(pdev
, PCI_CAP_ID_PM
);
8750 if (bp
->pm_cap
== 0) {
8751 printk(KERN_ERR PFX
"Cannot find power management"
8752 " capability, aborting\n");
8754 goto err_out_release
;
8757 bp
->pcie_cap
= pci_find_capability(pdev
, PCI_CAP_ID_EXP
);
8758 if (bp
->pcie_cap
== 0) {
8759 printk(KERN_ERR PFX
"Cannot find PCI Express capability,"
8762 goto err_out_release
;
8765 if (pci_set_dma_mask(pdev
, DMA_64BIT_MASK
) == 0) {
8766 bp
->flags
|= USING_DAC_FLAG
;
8767 if (pci_set_consistent_dma_mask(pdev
, DMA_64BIT_MASK
) != 0) {
8768 printk(KERN_ERR PFX
"pci_set_consistent_dma_mask"
8769 " failed, aborting\n");
8771 goto err_out_release
;
8774 } else if (pci_set_dma_mask(pdev
, DMA_32BIT_MASK
) != 0) {
8775 printk(KERN_ERR PFX
"System does not support DMA,"
8778 goto err_out_release
;
8784 spin_lock_init(&bp
->phy_lock
);
8786 bp
->in_reset_task
= 0;
8788 INIT_WORK(&bp
->reset_task
, bnx2x_reset_task
);
8789 INIT_WORK(&bp
->sp_task
, bnx2x_sp_task
);
8791 dev
->base_addr
= pci_resource_start(pdev
, 0);
8793 dev
->irq
= pdev
->irq
;
8795 bp
->regview
= ioremap_nocache(dev
->base_addr
,
8796 pci_resource_len(pdev
, 0));
8798 printk(KERN_ERR PFX
"Cannot map register space, aborting\n");
8800 goto err_out_release
;
8803 bp
->doorbells
= ioremap_nocache(pci_resource_start(pdev
, 2),
8804 pci_resource_len(pdev
, 2));
8805 if (!bp
->doorbells
) {
8806 printk(KERN_ERR PFX
"Cannot map doorbell space, aborting\n");
8811 bnx2x_set_power_state(bp
, PCI_D0
);
8813 bnx2x_get_hwinfo(bp
);
8815 if (CHIP_REV(bp
) == CHIP_REV_FPGA
) {
8816 printk(KERN_ERR PFX
"FPGA detacted. MCP disabled,"
8817 " will only init first device\n");
8823 printk(KERN_ERR PFX
"MCP disabled, will only"
8824 " init first device\n");
8828 if (onefunc
&& bp
->port
) {
8829 printk(KERN_ERR PFX
"Second device disabled, exiting\n");
8834 bp
->tx_ring_size
= MAX_TX_AVAIL
;
8835 bp
->rx_ring_size
= MAX_RX_AVAIL
;
8841 bp
->tx_quick_cons_trip_int
= 0xff;
8842 bp
->tx_quick_cons_trip
= 0xff;
8843 bp
->tx_ticks_int
= 50;
8846 bp
->rx_quick_cons_trip_int
= 0xff;
8847 bp
->rx_quick_cons_trip
= 0xff;
8848 bp
->rx_ticks_int
= 25;
8851 bp
->stats_ticks
= 1000000 & 0xffff00;
8853 bp
->timer_interval
= HZ
;
8854 bp
->current_interval
= (poll
? poll
: HZ
);
8856 init_timer(&bp
->timer
);
8857 bp
->timer
.expires
= jiffies
+ bp
->current_interval
;
8858 bp
->timer
.data
= (unsigned long) bp
;
8859 bp
->timer
.function
= bnx2x_timer
;
8865 iounmap(bp
->regview
);
8869 if (bp
->doorbells
) {
8870 iounmap(bp
->doorbells
);
8871 bp
->doorbells
= NULL
;
8875 pci_release_regions(pdev
);
8878 pci_disable_device(pdev
);
8879 pci_set_drvdata(pdev
, NULL
);
8885 static int __devinit
bnx2x_init_one(struct pci_dev
*pdev
,
8886 const struct pci_device_id
*ent
)
8888 static int version_printed
;
8889 struct net_device
*dev
= NULL
;
8892 int port
= PCI_FUNC(pdev
->devfn
);
8894 if (version_printed
++ == 0)
8895 printk(KERN_INFO
"%s", version
);
8897 /* dev zeroed in init_etherdev */
8898 dev
= alloc_etherdev(sizeof(*bp
));
8902 netif_carrier_off(dev
);
8904 bp
= netdev_priv(dev
);
8905 bp
->msglevel
= debug
;
8907 if (port
&& onefunc
) {
8908 printk(KERN_ERR PFX
"second function disabled. exiting\n");
8912 rc
= bnx2x_init_board(pdev
, dev
);
8918 dev
->hard_start_xmit
= bnx2x_start_xmit
;
8919 dev
->watchdog_timeo
= TX_TIMEOUT
;
8921 dev
->get_stats
= bnx2x_get_stats
;
8922 dev
->ethtool_ops
= &bnx2x_ethtool_ops
;
8923 dev
->open
= bnx2x_open
;
8924 dev
->stop
= bnx2x_close
;
8925 dev
->set_multicast_list
= bnx2x_set_rx_mode
;
8926 dev
->set_mac_address
= bnx2x_change_mac_addr
;
8927 dev
->do_ioctl
= bnx2x_ioctl
;
8928 dev
->change_mtu
= bnx2x_change_mtu
;
8929 dev
->tx_timeout
= bnx2x_tx_timeout
;
8931 dev
->vlan_rx_register
= bnx2x_vlan_rx_register
;
8933 #if defined(HAVE_POLL_CONTROLLER) || defined(CONFIG_NET_POLL_CONTROLLER)
8934 dev
->poll_controller
= poll_bnx2x
;
8936 dev
->features
|= NETIF_F_SG
;
8937 if (bp
->flags
& USING_DAC_FLAG
)
8938 dev
->features
|= NETIF_F_HIGHDMA
;
8939 dev
->features
|= NETIF_F_IP_CSUM
;
8941 dev
->features
|= NETIF_F_HW_VLAN_TX
| NETIF_F_HW_VLAN_RX
;
8943 dev
->features
|= NETIF_F_TSO
| NETIF_F_TSO_ECN
;
8945 rc
= register_netdev(dev
);
8947 printk(KERN_ERR PFX
"Cannot register net device\n");
8949 iounmap(bp
->regview
);
8951 iounmap(bp
->doorbells
);
8952 pci_release_regions(pdev
);
8953 pci_disable_device(pdev
);
8954 pci_set_drvdata(pdev
, NULL
);
8959 pci_set_drvdata(pdev
, dev
);
8961 bp
->name
= board_info
[ent
->driver_data
].name
;
8962 printk(KERN_INFO
"%s: %s (%c%d) PCI%s %s %dMHz "
8963 "found at mem %lx, IRQ %d, ",
8964 dev
->name
, bp
->name
,
8965 ((CHIP_ID(bp
) & 0xf000) >> 12) + 'A',
8966 ((CHIP_ID(bp
) & 0x0ff0) >> 4),
8967 ((bp
->flags
& PCIX_FLAG
) ? "-X" : ""),
8968 ((bp
->flags
& PCI_32BIT_FLAG
) ? "32-bit" : "64-bit"),
8973 printk("node addr ");
8974 for (i
= 0; i
< 6; i
++)
8975 printk("%2.2x", dev
->dev_addr
[i
]);
8981 static void __devexit
bnx2x_remove_one(struct pci_dev
*pdev
)
8983 struct net_device
*dev
= pci_get_drvdata(pdev
);
8984 struct bnx2x
*bp
= netdev_priv(dev
);
8986 flush_scheduled_work();
8987 /*tasklet_kill(&bp->sp_task);*/
8988 unregister_netdev(dev
);
8991 iounmap(bp
->regview
);
8994 iounmap(bp
->doorbells
);
8997 pci_release_regions(pdev
);
8998 pci_disable_device(pdev
);
8999 pci_set_drvdata(pdev
, NULL
);
9002 static int bnx2x_suspend(struct pci_dev
*pdev
, pm_message_t state
)
9004 struct net_device
*dev
= pci_get_drvdata(pdev
);
9005 struct bnx2x
*bp
= netdev_priv(dev
);
9008 if (!netif_running(dev
))
9011 rc
= bnx2x_nic_unload(bp
, 0);
9015 netif_device_detach(dev
);
9016 pci_save_state(pdev
);
9018 bnx2x_set_power_state(bp
, pci_choose_state(pdev
, state
));
9022 static int bnx2x_resume(struct pci_dev
*pdev
)
9024 struct net_device
*dev
= pci_get_drvdata(pdev
);
9025 struct bnx2x
*bp
= netdev_priv(dev
);
9028 if (!netif_running(dev
))
9031 pci_restore_state(pdev
);
9033 bnx2x_set_power_state(bp
, PCI_D0
);
9034 netif_device_attach(dev
);
9036 rc
= bnx2x_nic_load(bp
, 0);
9043 static struct pci_driver bnx2x_pci_driver
= {
9044 .name
= DRV_MODULE_NAME
,
9045 .id_table
= bnx2x_pci_tbl
,
9046 .probe
= bnx2x_init_one
,
9047 .remove
= __devexit_p(bnx2x_remove_one
),
9048 .suspend
= bnx2x_suspend
,
9049 .resume
= bnx2x_resume
,
9052 static int __init
bnx2x_init(void)
9054 return pci_register_driver(&bnx2x_pci_driver
);
9057 static void __exit
bnx2x_cleanup(void)
9059 pci_unregister_driver(&bnx2x_pci_driver
);
9062 module_init(bnx2x_init
);
9063 module_exit(bnx2x_cleanup
);