1 /* bnx2.c: Broadcom NX2 network driver.
3 * Copyright (c) 2004, 2005, 2006 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: Michael Chan (mchan@broadcom.com)
11 * Etherboot port by Ryan Jackson (rjackson@lnxi.com), based on driver
12 * version 1.4.40 from linux 2.6.17
16 #include "etherboot.h"
20 #include <gpxe/ethernet.h>
27 /* Dummy defines for error handling */
35 /* The bnx2 seems to be picky about the alignment of the receive buffers
36 * and possibly the status block.
39 struct tx_bd tx_desc_ring
[TX_DESC_CNT
];
40 struct rx_bd rx_desc_ring
[RX_DESC_CNT
];
41 unsigned char rx_buf
[RX_BUF_CNT
][RX_BUF_SIZE
];
42 struct status_block status_blk
;
43 struct statistics_block stats_blk
;
46 static struct bnx2 bnx2
;
48 static struct flash_spec flash_table
[] =
51 {0x00000000, 0x40830380, 0x009f0081, 0xa184a053, 0xaf000400,
52 1, SEEPROM_PAGE_BITS
, SEEPROM_PAGE_SIZE
,
53 SEEPROM_BYTE_ADDR_MASK
, SEEPROM_TOTAL_SIZE
,
55 /* Expansion entry 0001 */
56 {0x08000002, 0x4b808201, 0x00050081, 0x03840253, 0xaf020406,
57 0, SAIFUN_FLASH_PAGE_BITS
, SAIFUN_FLASH_PAGE_SIZE
,
58 SAIFUN_FLASH_BYTE_ADDR_MASK
, 0,
60 /* Saifun SA25F010 (non-buffered flash) */
61 /* strap, cfg1, & write1 need updates */
62 {0x04000001, 0x47808201, 0x00050081, 0x03840253, 0xaf020406,
63 0, SAIFUN_FLASH_PAGE_BITS
, SAIFUN_FLASH_PAGE_SIZE
,
64 SAIFUN_FLASH_BYTE_ADDR_MASK
, SAIFUN_FLASH_BASE_TOTAL_SIZE
*2,
65 "Non-buffered flash (128kB)"},
66 /* Saifun SA25F020 (non-buffered flash) */
67 /* strap, cfg1, & write1 need updates */
68 {0x0c000003, 0x4f808201, 0x00050081, 0x03840253, 0xaf020406,
69 0, SAIFUN_FLASH_PAGE_BITS
, SAIFUN_FLASH_PAGE_SIZE
,
70 SAIFUN_FLASH_BYTE_ADDR_MASK
, SAIFUN_FLASH_BASE_TOTAL_SIZE
*4,
71 "Non-buffered flash (256kB)"},
72 /* Expansion entry 0100 */
73 {0x11000000, 0x53808201, 0x00050081, 0x03840253, 0xaf020406,
74 0, SAIFUN_FLASH_PAGE_BITS
, SAIFUN_FLASH_PAGE_SIZE
,
75 SAIFUN_FLASH_BYTE_ADDR_MASK
, 0,
77 /* Entry 0101: ST M45PE10 (non-buffered flash, TetonII B0) */
78 {0x19000002, 0x5b808201, 0x000500db, 0x03840253, 0xaf020406,
79 0, ST_MICRO_FLASH_PAGE_BITS
, ST_MICRO_FLASH_PAGE_SIZE
,
80 ST_MICRO_FLASH_BYTE_ADDR_MASK
, ST_MICRO_FLASH_BASE_TOTAL_SIZE
*2,
81 "Entry 0101: ST M45PE10 (128kB non-bufferred)"},
82 /* Entry 0110: ST M45PE20 (non-buffered flash)*/
83 {0x15000001, 0x57808201, 0x000500db, 0x03840253, 0xaf020406,
84 0, ST_MICRO_FLASH_PAGE_BITS
, ST_MICRO_FLASH_PAGE_SIZE
,
85 ST_MICRO_FLASH_BYTE_ADDR_MASK
, ST_MICRO_FLASH_BASE_TOTAL_SIZE
*4,
86 "Entry 0110: ST M45PE20 (256kB non-bufferred)"},
87 /* Saifun SA25F005 (non-buffered flash) */
88 /* strap, cfg1, & write1 need updates */
89 {0x1d000003, 0x5f808201, 0x00050081, 0x03840253, 0xaf020406,
90 0, SAIFUN_FLASH_PAGE_BITS
, SAIFUN_FLASH_PAGE_SIZE
,
91 SAIFUN_FLASH_BYTE_ADDR_MASK
, SAIFUN_FLASH_BASE_TOTAL_SIZE
,
92 "Non-buffered flash (64kB)"},
94 {0x22000000, 0x62808380, 0x009f0081, 0xa184a053, 0xaf000400,
95 1, SEEPROM_PAGE_BITS
, SEEPROM_PAGE_SIZE
,
96 SEEPROM_BYTE_ADDR_MASK
, SEEPROM_TOTAL_SIZE
,
98 /* Expansion entry 1001 */
99 {0x2a000002, 0x6b808201, 0x00050081, 0x03840253, 0xaf020406,
100 0, SAIFUN_FLASH_PAGE_BITS
, SAIFUN_FLASH_PAGE_SIZE
,
101 SAIFUN_FLASH_BYTE_ADDR_MASK
, 0,
103 /* Expansion entry 1010 */
104 {0x26000001, 0x67808201, 0x00050081, 0x03840253, 0xaf020406,
105 0, SAIFUN_FLASH_PAGE_BITS
, SAIFUN_FLASH_PAGE_SIZE
,
106 SAIFUN_FLASH_BYTE_ADDR_MASK
, 0,
108 /* ATMEL AT45DB011B (buffered flash) */
109 {0x2e000003, 0x6e808273, 0x00570081, 0x68848353, 0xaf000400,
110 1, BUFFERED_FLASH_PAGE_BITS
, BUFFERED_FLASH_PAGE_SIZE
,
111 BUFFERED_FLASH_BYTE_ADDR_MASK
, BUFFERED_FLASH_TOTAL_SIZE
,
112 "Buffered flash (128kB)"},
113 /* Expansion entry 1100 */
114 {0x33000000, 0x73808201, 0x00050081, 0x03840253, 0xaf020406,
115 0, SAIFUN_FLASH_PAGE_BITS
, SAIFUN_FLASH_PAGE_SIZE
,
116 SAIFUN_FLASH_BYTE_ADDR_MASK
, 0,
118 /* Expansion entry 1101 */
119 {0x3b000002, 0x7b808201, 0x00050081, 0x03840253, 0xaf020406,
120 0, SAIFUN_FLASH_PAGE_BITS
, SAIFUN_FLASH_PAGE_SIZE
,
121 SAIFUN_FLASH_BYTE_ADDR_MASK
, 0,
123 /* Ateml Expansion entry 1110 */
124 {0x37000001, 0x76808273, 0x00570081, 0x68848353, 0xaf000400,
125 1, BUFFERED_FLASH_PAGE_BITS
, BUFFERED_FLASH_PAGE_SIZE
,
126 BUFFERED_FLASH_BYTE_ADDR_MASK
, 0,
127 "Entry 1110 (Atmel)"},
128 /* ATMEL AT45DB021B (buffered flash) */
129 {0x3f000003, 0x7e808273, 0x00570081, 0x68848353, 0xaf000400,
130 1, BUFFERED_FLASH_PAGE_BITS
, BUFFERED_FLASH_PAGE_SIZE
,
131 BUFFERED_FLASH_BYTE_ADDR_MASK
, BUFFERED_FLASH_TOTAL_SIZE
*2,
132 "Buffered flash (256kB)"},
136 bnx2_reg_rd_ind(struct bnx2
*bp
, u32 offset
)
138 REG_WR(bp
, BNX2_PCICFG_REG_WINDOW_ADDRESS
, offset
);
139 return (REG_RD(bp
, BNX2_PCICFG_REG_WINDOW
));
143 bnx2_reg_wr_ind(struct bnx2
*bp
, u32 offset
, u32 val
)
145 REG_WR(bp
, BNX2_PCICFG_REG_WINDOW_ADDRESS
, offset
);
146 REG_WR(bp
, BNX2_PCICFG_REG_WINDOW
, val
);
150 bnx2_ctx_wr(struct bnx2
*bp
, u32 cid_addr
, u32 offset
, u32 val
)
153 REG_WR(bp
, BNX2_CTX_DATA_ADR
, offset
);
154 REG_WR(bp
, BNX2_CTX_DATA
, val
);
158 bnx2_read_phy(struct bnx2
*bp
, u32 reg
, u32
*val
)
163 if (bp
->phy_flags
& PHY_INT_MODE_AUTO_POLLING_FLAG
) {
164 val1
= REG_RD(bp
, BNX2_EMAC_MDIO_MODE
);
165 val1
&= ~BNX2_EMAC_MDIO_MODE_AUTO_POLL
;
167 REG_WR(bp
, BNX2_EMAC_MDIO_MODE
, val1
);
168 REG_RD(bp
, BNX2_EMAC_MDIO_MODE
);
173 val1
= (bp
->phy_addr
<< 21) | (reg
<< 16) |
174 BNX2_EMAC_MDIO_COMM_COMMAND_READ
| BNX2_EMAC_MDIO_COMM_DISEXT
|
175 BNX2_EMAC_MDIO_COMM_START_BUSY
;
176 REG_WR(bp
, BNX2_EMAC_MDIO_COMM
, val1
);
178 for (i
= 0; i
< 50; i
++) {
181 val1
= REG_RD(bp
, BNX2_EMAC_MDIO_COMM
);
182 if (!(val1
& BNX2_EMAC_MDIO_COMM_START_BUSY
)) {
185 val1
= REG_RD(bp
, BNX2_EMAC_MDIO_COMM
);
186 val1
&= BNX2_EMAC_MDIO_COMM_DATA
;
192 if (val1
& BNX2_EMAC_MDIO_COMM_START_BUSY
) {
201 if (bp
->phy_flags
& PHY_INT_MODE_AUTO_POLLING_FLAG
) {
202 val1
= REG_RD(bp
, BNX2_EMAC_MDIO_MODE
);
203 val1
|= BNX2_EMAC_MDIO_MODE_AUTO_POLL
;
205 REG_WR(bp
, BNX2_EMAC_MDIO_MODE
, val1
);
206 REG_RD(bp
, BNX2_EMAC_MDIO_MODE
);
215 bnx2_write_phy(struct bnx2
*bp
, u32 reg
, u32 val
)
220 if (bp
->phy_flags
& PHY_INT_MODE_AUTO_POLLING_FLAG
) {
221 val1
= REG_RD(bp
, BNX2_EMAC_MDIO_MODE
);
222 val1
&= ~BNX2_EMAC_MDIO_MODE_AUTO_POLL
;
224 REG_WR(bp
, BNX2_EMAC_MDIO_MODE
, val1
);
225 REG_RD(bp
, BNX2_EMAC_MDIO_MODE
);
230 val1
= (bp
->phy_addr
<< 21) | (reg
<< 16) | val
|
231 BNX2_EMAC_MDIO_COMM_COMMAND_WRITE
|
232 BNX2_EMAC_MDIO_COMM_START_BUSY
| BNX2_EMAC_MDIO_COMM_DISEXT
;
233 REG_WR(bp
, BNX2_EMAC_MDIO_COMM
, val1
);
235 for (i
= 0; i
< 50; i
++) {
238 val1
= REG_RD(bp
, BNX2_EMAC_MDIO_COMM
);
239 if (!(val1
& BNX2_EMAC_MDIO_COMM_START_BUSY
)) {
245 if (val1
& BNX2_EMAC_MDIO_COMM_START_BUSY
)
250 if (bp
->phy_flags
& PHY_INT_MODE_AUTO_POLLING_FLAG
) {
251 val1
= REG_RD(bp
, BNX2_EMAC_MDIO_MODE
);
252 val1
|= BNX2_EMAC_MDIO_MODE_AUTO_POLL
;
254 REG_WR(bp
, BNX2_EMAC_MDIO_MODE
, val1
);
255 REG_RD(bp
, BNX2_EMAC_MDIO_MODE
);
264 bnx2_disable_int(struct bnx2
*bp
)
266 REG_WR(bp
, BNX2_PCICFG_INT_ACK_CMD
,
267 BNX2_PCICFG_INT_ACK_CMD_MASK_INT
);
268 REG_RD(bp
, BNX2_PCICFG_INT_ACK_CMD
);
273 bnx2_alloc_mem(struct bnx2
*bp
)
275 bp
->tx_desc_ring
= bnx2_bss
.tx_desc_ring
;
276 bp
->tx_desc_mapping
= virt_to_bus(bp
->tx_desc_ring
);
278 bp
->rx_desc_ring
= bnx2_bss
.rx_desc_ring
;
279 memset(bp
->rx_desc_ring
, 0, sizeof(struct rx_bd
) * RX_DESC_CNT
);
280 bp
->rx_desc_mapping
= virt_to_bus(bp
->rx_desc_ring
);
282 memset(&bnx2_bss
.status_blk
, 0, sizeof(struct status_block
));
283 bp
->status_blk
= &bnx2_bss
.status_blk
;
284 bp
->status_blk_mapping
= virt_to_bus(&bnx2_bss
.status_blk
);
286 bp
->stats_blk
= &bnx2_bss
.stats_blk
;
287 memset(&bnx2_bss
.stats_blk
, 0, sizeof(struct statistics_block
));
288 bp
->stats_blk_mapping
= virt_to_bus(&bnx2_bss
.stats_blk
);
294 bnx2_report_fw_link(struct bnx2
*bp
)
296 u32 fw_link_status
= 0;
301 switch (bp
->line_speed
) {
303 if (bp
->duplex
== DUPLEX_HALF
)
304 fw_link_status
= BNX2_LINK_STATUS_10HALF
;
306 fw_link_status
= BNX2_LINK_STATUS_10FULL
;
309 if (bp
->duplex
== DUPLEX_HALF
)
310 fw_link_status
= BNX2_LINK_STATUS_100HALF
;
312 fw_link_status
= BNX2_LINK_STATUS_100FULL
;
315 if (bp
->duplex
== DUPLEX_HALF
)
316 fw_link_status
= BNX2_LINK_STATUS_1000HALF
;
318 fw_link_status
= BNX2_LINK_STATUS_1000FULL
;
321 if (bp
->duplex
== DUPLEX_HALF
)
322 fw_link_status
= BNX2_LINK_STATUS_2500HALF
;
324 fw_link_status
= BNX2_LINK_STATUS_2500FULL
;
328 fw_link_status
|= BNX2_LINK_STATUS_LINK_UP
;
331 fw_link_status
|= BNX2_LINK_STATUS_AN_ENABLED
;
333 bnx2_read_phy(bp
, MII_BMSR
, &bmsr
);
334 bnx2_read_phy(bp
, MII_BMSR
, &bmsr
);
336 if (!(bmsr
& BMSR_ANEGCOMPLETE
) ||
337 bp
->phy_flags
& PHY_PARALLEL_DETECT_FLAG
)
338 fw_link_status
|= BNX2_LINK_STATUS_PARALLEL_DET
;
340 fw_link_status
|= BNX2_LINK_STATUS_AN_COMPLETE
;
344 fw_link_status
= BNX2_LINK_STATUS_LINK_DOWN
;
346 REG_WR_IND(bp
, bp
->shmem_base
+ BNX2_LINK_STATUS
, fw_link_status
);
350 bnx2_report_link(struct bnx2
*bp
)
353 printf("NIC Link is Up, ");
355 printf("%d Mbps ", bp
->line_speed
);
357 if (bp
->duplex
== DUPLEX_FULL
)
358 printf("full duplex");
360 printf("half duplex");
363 if (bp
->flow_ctrl
& FLOW_CTRL_RX
) {
364 printf(", receive ");
365 if (bp
->flow_ctrl
& FLOW_CTRL_TX
)
366 printf("& transmit ");
369 printf(", transmit ");
371 printf("flow control ON");
376 printf("NIC Link is Down\n");
379 bnx2_report_fw_link(bp
);
383 bnx2_resolve_flow_ctrl(struct bnx2
*bp
)
385 u32 local_adv
, remote_adv
;
388 if ((bp
->autoneg
& (AUTONEG_SPEED
| AUTONEG_FLOW_CTRL
)) !=
389 (AUTONEG_SPEED
| AUTONEG_FLOW_CTRL
)) {
391 if (bp
->duplex
== DUPLEX_FULL
) {
392 bp
->flow_ctrl
= bp
->req_flow_ctrl
;
397 if (bp
->duplex
!= DUPLEX_FULL
) {
401 if ((bp
->phy_flags
& PHY_SERDES_FLAG
) &&
402 (CHIP_NUM(bp
) == CHIP_NUM_5708
)) {
405 bnx2_read_phy(bp
, BCM5708S_1000X_STAT1
, &val
);
406 if (val
& BCM5708S_1000X_STAT1_TX_PAUSE
)
407 bp
->flow_ctrl
|= FLOW_CTRL_TX
;
408 if (val
& BCM5708S_1000X_STAT1_RX_PAUSE
)
409 bp
->flow_ctrl
|= FLOW_CTRL_RX
;
413 bnx2_read_phy(bp
, MII_ADVERTISE
, &local_adv
);
414 bnx2_read_phy(bp
, MII_LPA
, &remote_adv
);
416 if (bp
->phy_flags
& PHY_SERDES_FLAG
) {
417 u32 new_local_adv
= 0;
418 u32 new_remote_adv
= 0;
420 if (local_adv
& ADVERTISE_1000XPAUSE
)
421 new_local_adv
|= ADVERTISE_PAUSE_CAP
;
422 if (local_adv
& ADVERTISE_1000XPSE_ASYM
)
423 new_local_adv
|= ADVERTISE_PAUSE_ASYM
;
424 if (remote_adv
& ADVERTISE_1000XPAUSE
)
425 new_remote_adv
|= ADVERTISE_PAUSE_CAP
;
426 if (remote_adv
& ADVERTISE_1000XPSE_ASYM
)
427 new_remote_adv
|= ADVERTISE_PAUSE_ASYM
;
429 local_adv
= new_local_adv
;
430 remote_adv
= new_remote_adv
;
433 /* See Table 28B-3 of 802.3ab-1999 spec. */
434 if (local_adv
& ADVERTISE_PAUSE_CAP
) {
435 if(local_adv
& ADVERTISE_PAUSE_ASYM
) {
436 if (remote_adv
& ADVERTISE_PAUSE_CAP
) {
437 bp
->flow_ctrl
= FLOW_CTRL_TX
| FLOW_CTRL_RX
;
439 else if (remote_adv
& ADVERTISE_PAUSE_ASYM
) {
440 bp
->flow_ctrl
= FLOW_CTRL_RX
;
444 if (remote_adv
& ADVERTISE_PAUSE_CAP
) {
445 bp
->flow_ctrl
= FLOW_CTRL_TX
| FLOW_CTRL_RX
;
449 else if (local_adv
& ADVERTISE_PAUSE_ASYM
) {
450 if ((remote_adv
& ADVERTISE_PAUSE_CAP
) &&
451 (remote_adv
& ADVERTISE_PAUSE_ASYM
)) {
453 bp
->flow_ctrl
= FLOW_CTRL_TX
;
459 bnx2_5708s_linkup(struct bnx2
*bp
)
464 bnx2_read_phy(bp
, BCM5708S_1000X_STAT1
, &val
);
465 switch (val
& BCM5708S_1000X_STAT1_SPEED_MASK
) {
466 case BCM5708S_1000X_STAT1_SPEED_10
:
467 bp
->line_speed
= SPEED_10
;
469 case BCM5708S_1000X_STAT1_SPEED_100
:
470 bp
->line_speed
= SPEED_100
;
472 case BCM5708S_1000X_STAT1_SPEED_1G
:
473 bp
->line_speed
= SPEED_1000
;
475 case BCM5708S_1000X_STAT1_SPEED_2G5
:
476 bp
->line_speed
= SPEED_2500
;
479 if (val
& BCM5708S_1000X_STAT1_FD
)
480 bp
->duplex
= DUPLEX_FULL
;
482 bp
->duplex
= DUPLEX_HALF
;
488 bnx2_5706s_linkup(struct bnx2
*bp
)
490 u32 bmcr
, local_adv
, remote_adv
, common
;
493 bp
->line_speed
= SPEED_1000
;
495 bnx2_read_phy(bp
, MII_BMCR
, &bmcr
);
496 if (bmcr
& BMCR_FULLDPLX
) {
497 bp
->duplex
= DUPLEX_FULL
;
500 bp
->duplex
= DUPLEX_HALF
;
503 if (!(bmcr
& BMCR_ANENABLE
)) {
507 bnx2_read_phy(bp
, MII_ADVERTISE
, &local_adv
);
508 bnx2_read_phy(bp
, MII_LPA
, &remote_adv
);
510 common
= local_adv
& remote_adv
;
511 if (common
& (ADVERTISE_1000XHALF
| ADVERTISE_1000XFULL
)) {
513 if (common
& ADVERTISE_1000XFULL
) {
514 bp
->duplex
= DUPLEX_FULL
;
517 bp
->duplex
= DUPLEX_HALF
;
525 bnx2_copper_linkup(struct bnx2
*bp
)
529 bnx2_read_phy(bp
, MII_BMCR
, &bmcr
);
530 if (bmcr
& BMCR_ANENABLE
) {
531 u32 local_adv
, remote_adv
, common
;
533 bnx2_read_phy(bp
, MII_CTRL1000
, &local_adv
);
534 bnx2_read_phy(bp
, MII_STAT1000
, &remote_adv
);
536 common
= local_adv
& (remote_adv
>> 2);
537 if (common
& ADVERTISE_1000FULL
) {
538 bp
->line_speed
= SPEED_1000
;
539 bp
->duplex
= DUPLEX_FULL
;
541 else if (common
& ADVERTISE_1000HALF
) {
542 bp
->line_speed
= SPEED_1000
;
543 bp
->duplex
= DUPLEX_HALF
;
546 bnx2_read_phy(bp
, MII_ADVERTISE
, &local_adv
);
547 bnx2_read_phy(bp
, MII_LPA
, &remote_adv
);
549 common
= local_adv
& remote_adv
;
550 if (common
& ADVERTISE_100FULL
) {
551 bp
->line_speed
= SPEED_100
;
552 bp
->duplex
= DUPLEX_FULL
;
554 else if (common
& ADVERTISE_100HALF
) {
555 bp
->line_speed
= SPEED_100
;
556 bp
->duplex
= DUPLEX_HALF
;
558 else if (common
& ADVERTISE_10FULL
) {
559 bp
->line_speed
= SPEED_10
;
560 bp
->duplex
= DUPLEX_FULL
;
562 else if (common
& ADVERTISE_10HALF
) {
563 bp
->line_speed
= SPEED_10
;
564 bp
->duplex
= DUPLEX_HALF
;
573 if (bmcr
& BMCR_SPEED100
) {
574 bp
->line_speed
= SPEED_100
;
577 bp
->line_speed
= SPEED_10
;
579 if (bmcr
& BMCR_FULLDPLX
) {
580 bp
->duplex
= DUPLEX_FULL
;
583 bp
->duplex
= DUPLEX_HALF
;
591 bnx2_set_mac_link(struct bnx2
*bp
)
595 REG_WR(bp
, BNX2_EMAC_TX_LENGTHS
, 0x2620);
596 if (bp
->link_up
&& (bp
->line_speed
== SPEED_1000
) &&
597 (bp
->duplex
== DUPLEX_HALF
)) {
598 REG_WR(bp
, BNX2_EMAC_TX_LENGTHS
, 0x26ff);
601 /* Configure the EMAC mode register. */
602 val
= REG_RD(bp
, BNX2_EMAC_MODE
);
604 val
&= ~(BNX2_EMAC_MODE_PORT
| BNX2_EMAC_MODE_HALF_DUPLEX
|
605 BNX2_EMAC_MODE_MAC_LOOP
| BNX2_EMAC_MODE_FORCE_LINK
|
609 switch (bp
->line_speed
) {
611 if (CHIP_NUM(bp
) == CHIP_NUM_5708
) {
612 val
|= BNX2_EMAC_MODE_PORT_MII_10
;
617 val
|= BNX2_EMAC_MODE_PORT_MII
;
620 val
|= BNX2_EMAC_MODE_25G
;
623 val
|= BNX2_EMAC_MODE_PORT_GMII
;
628 val
|= BNX2_EMAC_MODE_PORT_GMII
;
631 /* Set the MAC to operate in the appropriate duplex mode. */
632 if (bp
->duplex
== DUPLEX_HALF
)
633 val
|= BNX2_EMAC_MODE_HALF_DUPLEX
;
634 REG_WR(bp
, BNX2_EMAC_MODE
, val
);
636 /* Enable/disable rx PAUSE. */
637 bp
->rx_mode
&= ~BNX2_EMAC_RX_MODE_FLOW_EN
;
639 if (bp
->flow_ctrl
& FLOW_CTRL_RX
)
640 bp
->rx_mode
|= BNX2_EMAC_RX_MODE_FLOW_EN
;
641 REG_WR(bp
, BNX2_EMAC_RX_MODE
, bp
->rx_mode
);
643 /* Enable/disable tx PAUSE. */
644 val
= REG_RD(bp
, BNX2_EMAC_TX_MODE
);
645 val
&= ~BNX2_EMAC_TX_MODE_FLOW_EN
;
647 if (bp
->flow_ctrl
& FLOW_CTRL_TX
)
648 val
|= BNX2_EMAC_TX_MODE_FLOW_EN
;
649 REG_WR(bp
, BNX2_EMAC_TX_MODE
, val
);
651 /* Acknowledge the interrupt. */
652 REG_WR(bp
, BNX2_EMAC_STATUS
, BNX2_EMAC_STATUS_LINK_CHANGE
);
658 bnx2_set_link(struct bnx2
*bp
)
663 if (bp
->loopback
== MAC_LOOPBACK
) {
668 link_up
= bp
->link_up
;
670 bnx2_read_phy(bp
, MII_BMSR
, &bmsr
);
671 bnx2_read_phy(bp
, MII_BMSR
, &bmsr
);
673 if ((bp
->phy_flags
& PHY_SERDES_FLAG
) &&
674 (CHIP_NUM(bp
) == CHIP_NUM_5706
)) {
677 val
= REG_RD(bp
, BNX2_EMAC_STATUS
);
678 if (val
& BNX2_EMAC_STATUS_LINK
)
679 bmsr
|= BMSR_LSTATUS
;
681 bmsr
&= ~BMSR_LSTATUS
;
684 if (bmsr
& BMSR_LSTATUS
) {
687 if (bp
->phy_flags
& PHY_SERDES_FLAG
) {
688 if (CHIP_NUM(bp
) == CHIP_NUM_5706
)
689 bnx2_5706s_linkup(bp
);
690 else if (CHIP_NUM(bp
) == CHIP_NUM_5708
)
691 bnx2_5708s_linkup(bp
);
694 bnx2_copper_linkup(bp
);
696 bnx2_resolve_flow_ctrl(bp
);
699 if ((bp
->phy_flags
& PHY_SERDES_FLAG
) &&
700 (bp
->autoneg
& AUTONEG_SPEED
)) {
704 bnx2_read_phy(bp
, MII_BMCR
, &bmcr
);
705 if (!(bmcr
& BMCR_ANENABLE
)) {
706 bnx2_write_phy(bp
, MII_BMCR
, bmcr
|
710 bp
->phy_flags
&= ~PHY_PARALLEL_DETECT_FLAG
;
714 if (bp
->link_up
!= link_up
) {
715 bnx2_report_link(bp
);
718 bnx2_set_mac_link(bp
);
724 bnx2_reset_phy(struct bnx2
*bp
)
729 bnx2_write_phy(bp
, MII_BMCR
, BMCR_RESET
);
731 #define PHY_RESET_MAX_WAIT 100
732 for (i
= 0; i
< PHY_RESET_MAX_WAIT
; i
++) {
735 bnx2_read_phy(bp
, MII_BMCR
, ®
);
736 if (!(reg
& BMCR_RESET
)) {
741 if (i
== PHY_RESET_MAX_WAIT
) {
748 bnx2_phy_get_pause_adv(struct bnx2
*bp
)
752 if ((bp
->req_flow_ctrl
& (FLOW_CTRL_RX
| FLOW_CTRL_TX
)) ==
753 (FLOW_CTRL_RX
| FLOW_CTRL_TX
)) {
755 if (bp
->phy_flags
& PHY_SERDES_FLAG
) {
756 adv
= ADVERTISE_1000XPAUSE
;
759 adv
= ADVERTISE_PAUSE_CAP
;
762 else if (bp
->req_flow_ctrl
& FLOW_CTRL_TX
) {
763 if (bp
->phy_flags
& PHY_SERDES_FLAG
) {
764 adv
= ADVERTISE_1000XPSE_ASYM
;
767 adv
= ADVERTISE_PAUSE_ASYM
;
770 else if (bp
->req_flow_ctrl
& FLOW_CTRL_RX
) {
771 if (bp
->phy_flags
& PHY_SERDES_FLAG
) {
772 adv
= ADVERTISE_1000XPAUSE
| ADVERTISE_1000XPSE_ASYM
;
775 adv
= ADVERTISE_PAUSE_CAP
| ADVERTISE_PAUSE_ASYM
;
782 bnx2_setup_serdes_phy(struct bnx2
*bp
)
787 if (!(bp
->autoneg
& AUTONEG_SPEED
)) {
789 int force_link_down
= 0;
791 if (CHIP_NUM(bp
) == CHIP_NUM_5708
) {
792 bnx2_read_phy(bp
, BCM5708S_UP1
, &up1
);
793 if (up1
& BCM5708S_UP1_2G5
) {
794 up1
&= ~BCM5708S_UP1_2G5
;
795 bnx2_write_phy(bp
, BCM5708S_UP1
, up1
);
800 bnx2_read_phy(bp
, MII_ADVERTISE
, &adv
);
801 adv
&= ~(ADVERTISE_1000XFULL
| ADVERTISE_1000XHALF
);
803 bnx2_read_phy(bp
, MII_BMCR
, &bmcr
);
804 new_bmcr
= bmcr
& ~BMCR_ANENABLE
;
805 new_bmcr
|= BMCR_SPEED1000
;
806 if (bp
->req_duplex
== DUPLEX_FULL
) {
807 adv
|= ADVERTISE_1000XFULL
;
808 new_bmcr
|= BMCR_FULLDPLX
;
811 adv
|= ADVERTISE_1000XHALF
;
812 new_bmcr
&= ~BMCR_FULLDPLX
;
814 if ((new_bmcr
!= bmcr
) || (force_link_down
)) {
815 /* Force a link down visible on the other side */
817 bnx2_write_phy(bp
, MII_ADVERTISE
, adv
&
818 ~(ADVERTISE_1000XFULL
|
819 ADVERTISE_1000XHALF
));
820 bnx2_write_phy(bp
, MII_BMCR
, bmcr
|
821 BMCR_ANRESTART
| BMCR_ANENABLE
);
824 bnx2_write_phy(bp
, MII_BMCR
, new_bmcr
);
826 bnx2_write_phy(bp
, MII_ADVERTISE
, adv
);
827 bnx2_write_phy(bp
, MII_BMCR
, new_bmcr
);
832 if (bp
->phy_flags
& PHY_2_5G_CAPABLE_FLAG
) {
833 bnx2_read_phy(bp
, BCM5708S_UP1
, &up1
);
834 up1
|= BCM5708S_UP1_2G5
;
835 bnx2_write_phy(bp
, BCM5708S_UP1
, up1
);
838 if (bp
->advertising
& ADVERTISED_1000baseT_Full
)
839 new_adv
|= ADVERTISE_1000XFULL
;
841 new_adv
|= bnx2_phy_get_pause_adv(bp
);
843 bnx2_read_phy(bp
, MII_ADVERTISE
, &adv
);
844 bnx2_read_phy(bp
, MII_BMCR
, &bmcr
);
846 bp
->serdes_an_pending
= 0;
847 if ((adv
!= new_adv
) || ((bmcr
& BMCR_ANENABLE
) == 0)) {
848 /* Force a link down visible on the other side */
852 bnx2_write_phy(bp
, MII_BMCR
, BMCR_LOOPBACK
);
853 for (i
= 0; i
< 110; i
++) {
858 bnx2_write_phy(bp
, MII_ADVERTISE
, new_adv
);
859 bnx2_write_phy(bp
, MII_BMCR
, bmcr
| BMCR_ANRESTART
|
862 if (CHIP_NUM(bp
) == CHIP_NUM_5706
) {
863 /* Speed up link-up time when the link partner
864 * does not autonegotiate which is very common
865 * in blade servers. Some blade servers use
866 * IPMI for kerboard input and it's important
867 * to minimize link disruptions. Autoneg. involves
868 * exchanging base pages plus 3 next pages and
869 * normally completes in about 120 msec.
871 bp
->current_interval
= SERDES_AN_TIMEOUT
;
872 bp
->serdes_an_pending
= 1;
873 mod_timer(&bp
->timer
, jiffies
+ bp
->current_interval
);
881 #define ETHTOOL_ALL_FIBRE_SPEED \
882 (ADVERTISED_1000baseT_Full)
884 #define ETHTOOL_ALL_COPPER_SPEED \
885 (ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full | \
886 ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full | \
887 ADVERTISED_1000baseT_Full)
889 #define PHY_ALL_10_100_SPEED (ADVERTISE_10HALF | ADVERTISE_10FULL | \
890 ADVERTISE_100HALF | ADVERTISE_100FULL | ADVERTISE_CSMA)
892 #define PHY_ALL_1000_SPEED (ADVERTISE_1000HALF | ADVERTISE_1000FULL)
895 bnx2_setup_copper_phy(struct bnx2
*bp
)
900 bnx2_read_phy(bp
, MII_BMCR
, &bmcr
);
902 if (bp
->autoneg
& AUTONEG_SPEED
) {
903 u32 adv_reg
, adv1000_reg
;
905 u32 new_adv1000_reg
= 0;
907 bnx2_read_phy(bp
, MII_ADVERTISE
, &adv_reg
);
908 adv_reg
&= (PHY_ALL_10_100_SPEED
| ADVERTISE_PAUSE_CAP
|
909 ADVERTISE_PAUSE_ASYM
);
911 bnx2_read_phy(bp
, MII_CTRL1000
, &adv1000_reg
);
912 adv1000_reg
&= PHY_ALL_1000_SPEED
;
914 if (bp
->advertising
& ADVERTISED_10baseT_Half
)
915 new_adv_reg
|= ADVERTISE_10HALF
;
916 if (bp
->advertising
& ADVERTISED_10baseT_Full
)
917 new_adv_reg
|= ADVERTISE_10FULL
;
918 if (bp
->advertising
& ADVERTISED_100baseT_Half
)
919 new_adv_reg
|= ADVERTISE_100HALF
;
920 if (bp
->advertising
& ADVERTISED_100baseT_Full
)
921 new_adv_reg
|= ADVERTISE_100FULL
;
922 if (bp
->advertising
& ADVERTISED_1000baseT_Full
)
923 new_adv1000_reg
|= ADVERTISE_1000FULL
;
925 new_adv_reg
|= ADVERTISE_CSMA
;
927 new_adv_reg
|= bnx2_phy_get_pause_adv(bp
);
929 if ((adv1000_reg
!= new_adv1000_reg
) ||
930 (adv_reg
!= new_adv_reg
) ||
931 ((bmcr
& BMCR_ANENABLE
) == 0)) {
933 bnx2_write_phy(bp
, MII_ADVERTISE
, new_adv_reg
);
934 bnx2_write_phy(bp
, MII_CTRL1000
, new_adv1000_reg
);
935 bnx2_write_phy(bp
, MII_BMCR
, BMCR_ANRESTART
|
938 else if (bp
->link_up
) {
939 /* Flow ctrl may have changed from auto to forced */
942 bnx2_resolve_flow_ctrl(bp
);
943 bnx2_set_mac_link(bp
);
949 if (bp
->req_line_speed
== SPEED_100
) {
950 new_bmcr
|= BMCR_SPEED100
;
952 if (bp
->req_duplex
== DUPLEX_FULL
) {
953 new_bmcr
|= BMCR_FULLDPLX
;
955 if (new_bmcr
!= bmcr
) {
959 bnx2_read_phy(bp
, MII_BMSR
, &bmsr
);
960 bnx2_read_phy(bp
, MII_BMSR
, &bmsr
);
962 if (bmsr
& BMSR_LSTATUS
) {
963 /* Force link down */
964 bnx2_write_phy(bp
, MII_BMCR
, BMCR_LOOPBACK
);
967 bnx2_read_phy(bp
, MII_BMSR
, &bmsr
);
968 bnx2_read_phy(bp
, MII_BMSR
, &bmsr
);
970 } while ((bmsr
& BMSR_LSTATUS
) && (i
< 620));
973 bnx2_write_phy(bp
, MII_BMCR
, new_bmcr
);
975 /* Normally, the new speed is setup after the link has
976 * gone down and up again. In some cases, link will not go
977 * down so we need to set up the new speed here.
979 if (bmsr
& BMSR_LSTATUS
) {
980 bp
->line_speed
= bp
->req_line_speed
;
981 bp
->duplex
= bp
->req_duplex
;
982 bnx2_resolve_flow_ctrl(bp
);
983 bnx2_set_mac_link(bp
);
990 bnx2_setup_phy(struct bnx2
*bp
)
992 if (bp
->loopback
== MAC_LOOPBACK
)
995 if (bp
->phy_flags
& PHY_SERDES_FLAG
) {
996 return (bnx2_setup_serdes_phy(bp
));
999 return (bnx2_setup_copper_phy(bp
));
1004 bnx2_init_5708s_phy(struct bnx2
*bp
)
1008 bnx2_write_phy(bp
, BCM5708S_BLK_ADDR
, BCM5708S_BLK_ADDR_DIG3
);
1009 bnx2_write_phy(bp
, BCM5708S_DIG_3_0
, BCM5708S_DIG_3_0_USE_IEEE
);
1010 bnx2_write_phy(bp
, BCM5708S_BLK_ADDR
, BCM5708S_BLK_ADDR_DIG
);
1012 bnx2_read_phy(bp
, BCM5708S_1000X_CTL1
, &val
);
1013 val
|= BCM5708S_1000X_CTL1_FIBER_MODE
| BCM5708S_1000X_CTL1_AUTODET_EN
;
1014 bnx2_write_phy(bp
, BCM5708S_1000X_CTL1
, val
);
1016 bnx2_read_phy(bp
, BCM5708S_1000X_CTL2
, &val
);
1017 val
|= BCM5708S_1000X_CTL2_PLLEL_DET_EN
;
1018 bnx2_write_phy(bp
, BCM5708S_1000X_CTL2
, val
);
1020 if (bp
->phy_flags
& PHY_2_5G_CAPABLE_FLAG
) {
1021 bnx2_read_phy(bp
, BCM5708S_UP1
, &val
);
1022 val
|= BCM5708S_UP1_2G5
;
1023 bnx2_write_phy(bp
, BCM5708S_UP1
, val
);
1026 if ((CHIP_ID(bp
) == CHIP_ID_5708_A0
) ||
1027 (CHIP_ID(bp
) == CHIP_ID_5708_B0
) ||
1028 (CHIP_ID(bp
) == CHIP_ID_5708_B1
)) {
1029 /* increase tx signal amplitude */
1030 bnx2_write_phy(bp
, BCM5708S_BLK_ADDR
,
1031 BCM5708S_BLK_ADDR_TX_MISC
);
1032 bnx2_read_phy(bp
, BCM5708S_TX_ACTL1
, &val
);
1033 val
&= ~BCM5708S_TX_ACTL1_DRIVER_VCM
;
1034 bnx2_write_phy(bp
, BCM5708S_TX_ACTL1
, val
);
1035 bnx2_write_phy(bp
, BCM5708S_BLK_ADDR
, BCM5708S_BLK_ADDR_DIG
);
1038 val
= REG_RD_IND(bp
, bp
->shmem_base
+ BNX2_PORT_HW_CFG_CONFIG
) &
1039 BNX2_PORT_HW_CFG_CFG_TXCTL3_MASK
;
1044 is_backplane
= REG_RD_IND(bp
, bp
->shmem_base
+
1045 BNX2_SHARED_HW_CFG_CONFIG
);
1046 if (is_backplane
& BNX2_SHARED_HW_CFG_PHY_BACKPLANE
) {
1047 bnx2_write_phy(bp
, BCM5708S_BLK_ADDR
,
1048 BCM5708S_BLK_ADDR_TX_MISC
);
1049 bnx2_write_phy(bp
, BCM5708S_TX_ACTL3
, val
);
1050 bnx2_write_phy(bp
, BCM5708S_BLK_ADDR
,
1051 BCM5708S_BLK_ADDR_DIG
);
1058 bnx2_init_5706s_phy(struct bnx2
*bp
)
1062 bp
->phy_flags
&= ~PHY_PARALLEL_DETECT_FLAG
;
1064 if (CHIP_NUM(bp
) == CHIP_NUM_5706
) {
1065 REG_WR(bp
, BNX2_MISC_UNUSED0
, 0x300);
1069 bnx2_write_phy(bp
, 0x18, 0x7);
1070 bnx2_read_phy(bp
, 0x18, &val
);
1071 bnx2_write_phy(bp
, 0x18, val
& ~0x4007);
1073 bnx2_write_phy(bp
, 0x1c, 0x6c00);
1074 bnx2_read_phy(bp
, 0x1c, &val
);
1075 bnx2_write_phy(bp
, 0x1c, (val
& 0x3fd) | 0xec00);
1081 bnx2_init_copper_phy(struct bnx2
*bp
)
1085 bp
->phy_flags
|= PHY_CRC_FIX_FLAG
;
1087 if (bp
->phy_flags
& PHY_CRC_FIX_FLAG
) {
1088 bnx2_write_phy(bp
, 0x18, 0x0c00);
1089 bnx2_write_phy(bp
, 0x17, 0x000a);
1090 bnx2_write_phy(bp
, 0x15, 0x310b);
1091 bnx2_write_phy(bp
, 0x17, 0x201f);
1092 bnx2_write_phy(bp
, 0x15, 0x9506);
1093 bnx2_write_phy(bp
, 0x17, 0x401f);
1094 bnx2_write_phy(bp
, 0x15, 0x14e2);
1095 bnx2_write_phy(bp
, 0x18, 0x0400);
1098 bnx2_write_phy(bp
, 0x18, 0x7);
1099 bnx2_read_phy(bp
, 0x18, &val
);
1100 bnx2_write_phy(bp
, 0x18, val
& ~0x4007);
1102 bnx2_read_phy(bp
, 0x10, &val
);
1103 bnx2_write_phy(bp
, 0x10, val
& ~0x1);
1105 /* ethernet@wirespeed */
1106 bnx2_write_phy(bp
, 0x18, 0x7007);
1107 bnx2_read_phy(bp
, 0x18, &val
);
1108 bnx2_write_phy(bp
, 0x18, val
| (1 << 15) | (1 << 4));
1113 bnx2_init_phy(struct bnx2
*bp
)
1118 bp
->phy_flags
&= ~PHY_INT_MODE_MASK_FLAG
;
1119 bp
->phy_flags
|= PHY_INT_MODE_LINK_READY_FLAG
;
1121 REG_WR(bp
, BNX2_EMAC_ATTENTION_ENA
, BNX2_EMAC_ATTENTION_ENA_LINK
);
1125 bnx2_read_phy(bp
, MII_PHYSID1
, &val
);
1126 bp
->phy_id
= val
<< 16;
1127 bnx2_read_phy(bp
, MII_PHYSID2
, &val
);
1128 bp
->phy_id
|= val
& 0xffff;
1130 if (bp
->phy_flags
& PHY_SERDES_FLAG
) {
1131 if (CHIP_NUM(bp
) == CHIP_NUM_5706
)
1132 rc
= bnx2_init_5706s_phy(bp
);
1133 else if (CHIP_NUM(bp
) == CHIP_NUM_5708
)
1134 rc
= bnx2_init_5708s_phy(bp
);
1137 rc
= bnx2_init_copper_phy(bp
);
1146 bnx2_fw_sync(struct bnx2
*bp
, u32 msg_data
, int silent
)
1152 msg_data
|= bp
->fw_wr_seq
;
1154 REG_WR_IND(bp
, bp
->shmem_base
+ BNX2_DRV_MB
, msg_data
);
1156 /* wait for an acknowledgement. */
1157 for (i
= 0; i
< (FW_ACK_TIME_OUT_MS
/ 50); i
++) {
1160 val
= REG_RD_IND(bp
, bp
->shmem_base
+ BNX2_FW_MB
);
1162 if ((val
& BNX2_FW_MSG_ACK
) == (msg_data
& BNX2_DRV_MSG_SEQ
))
1165 if ((msg_data
& BNX2_DRV_MSG_DATA
) == BNX2_DRV_MSG_DATA_WAIT0
)
1168 /* If we timed out, inform the firmware that this is the case. */
1169 if ((val
& BNX2_FW_MSG_ACK
) != (msg_data
& BNX2_DRV_MSG_SEQ
)) {
1171 printf("fw sync timeout, reset code = %x\n", (unsigned int) msg_data
);
1173 msg_data
&= ~BNX2_DRV_MSG_CODE
;
1174 msg_data
|= BNX2_DRV_MSG_CODE_FW_TIMEOUT
;
1176 REG_WR_IND(bp
, bp
->shmem_base
+ BNX2_DRV_MB
, msg_data
);
1181 if ((val
& BNX2_FW_MSG_STATUS_MASK
) != BNX2_FW_MSG_STATUS_OK
)
1188 bnx2_init_context(struct bnx2
*bp
)
1194 u32 vcid_addr
, pcid_addr
, offset
;
1198 if (CHIP_ID(bp
) == CHIP_ID_5706_A0
) {
1201 vcid_addr
= GET_PCID_ADDR(vcid
);
1203 new_vcid
= 0x60 + (vcid
& 0xf0) + (vcid
& 0x7);
1208 pcid_addr
= GET_PCID_ADDR(new_vcid
);
1211 vcid_addr
= GET_CID_ADDR(vcid
);
1212 pcid_addr
= vcid_addr
;
1215 REG_WR(bp
, BNX2_CTX_VIRT_ADDR
, 0x00);
1216 REG_WR(bp
, BNX2_CTX_PAGE_TBL
, pcid_addr
);
1218 /* Zero out the context. */
1219 for (offset
= 0; offset
< PHY_CTX_SIZE
; offset
+= 4) {
1220 CTX_WR(bp
, 0x00, offset
, 0);
1223 REG_WR(bp
, BNX2_CTX_VIRT_ADDR
, vcid_addr
);
1224 REG_WR(bp
, BNX2_CTX_PAGE_TBL
, pcid_addr
);
1229 bnx2_alloc_bad_rbuf(struct bnx2
*bp
)
1235 REG_WR(bp
, BNX2_MISC_ENABLE_SET_BITS
,
1236 BNX2_MISC_ENABLE_SET_BITS_RX_MBUF_ENABLE
);
1240 /* Allocate a bunch of mbufs and save the good ones in an array. */
1241 val
= REG_RD_IND(bp
, BNX2_RBUF_STATUS1
);
1242 while (val
& BNX2_RBUF_STATUS1_FREE_COUNT
) {
1243 REG_WR_IND(bp
, BNX2_RBUF_COMMAND
, BNX2_RBUF_COMMAND_ALLOC_REQ
);
1245 val
= REG_RD_IND(bp
, BNX2_RBUF_FW_BUF_ALLOC
);
1247 val
&= BNX2_RBUF_FW_BUF_ALLOC_VALUE
;
1249 /* The addresses with Bit 9 set are bad memory blocks. */
1250 if (!(val
& (1 << 9))) {
1251 good_mbuf
[good_mbuf_cnt
] = (u16
) val
;
1255 val
= REG_RD_IND(bp
, BNX2_RBUF_STATUS1
);
1258 /* Free the good ones back to the mbuf pool thus discarding
1259 * all the bad ones. */
1260 while (good_mbuf_cnt
) {
1263 val
= good_mbuf
[good_mbuf_cnt
];
1264 val
= (val
<< 9) | val
| 1;
1266 REG_WR_IND(bp
, BNX2_RBUF_FW_BUF_FREE
, val
);
1272 bnx2_set_mac_addr(struct bnx2
*bp
)
1275 u8
*mac_addr
= bp
->nic
->node_addr
;
1277 val
= (mac_addr
[0] << 8) | mac_addr
[1];
1279 REG_WR(bp
, BNX2_EMAC_MAC_MATCH0
, val
);
1281 val
= (mac_addr
[2] << 24) | (mac_addr
[3] << 16) |
1282 (mac_addr
[4] << 8) | mac_addr
[5];
1284 REG_WR(bp
, BNX2_EMAC_MAC_MATCH1
, val
);
1288 bnx2_set_rx_mode(struct nic
*nic __unused
)
1290 struct bnx2
*bp
= &bnx2
;
1291 u32 rx_mode
, sort_mode
;
1294 rx_mode
= bp
->rx_mode
& ~(BNX2_EMAC_RX_MODE_PROMISCUOUS
|
1295 BNX2_EMAC_RX_MODE_KEEP_VLAN_TAG
);
1296 sort_mode
= 1 | BNX2_RPM_SORT_USER0_BC_EN
;
1298 if (!(bp
->flags
& ASF_ENABLE_FLAG
)) {
1299 rx_mode
|= BNX2_EMAC_RX_MODE_KEEP_VLAN_TAG
;
1302 /* Accept all multicasts */
1303 for (i
= 0; i
< NUM_MC_HASH_REGISTERS
; i
++) {
1304 REG_WR(bp
, BNX2_EMAC_MULTICAST_HASH0
+ (i
* 4),
1307 sort_mode
|= BNX2_RPM_SORT_USER0_MC_EN
;
1309 if (rx_mode
!= bp
->rx_mode
) {
1310 bp
->rx_mode
= rx_mode
;
1311 REG_WR(bp
, BNX2_EMAC_RX_MODE
, rx_mode
);
1314 REG_WR(bp
, BNX2_RPM_SORT_USER0
, 0x0);
1315 REG_WR(bp
, BNX2_RPM_SORT_USER0
, sort_mode
);
1316 REG_WR(bp
, BNX2_RPM_SORT_USER0
, sort_mode
| BNX2_RPM_SORT_USER0_ENA
);
1320 load_rv2p_fw(struct bnx2
*bp
, u32
*rv2p_code
, u32 rv2p_code_len
, u32 rv2p_proc
)
1326 for (i
= 0; i
< rv2p_code_len
; i
+= 8) {
1327 REG_WR(bp
, BNX2_RV2P_INSTR_HIGH
, *rv2p_code
);
1329 REG_WR(bp
, BNX2_RV2P_INSTR_LOW
, *rv2p_code
);
1332 if (rv2p_proc
== RV2P_PROC1
) {
1333 val
= (i
/ 8) | BNX2_RV2P_PROC1_ADDR_CMD_RDWR
;
1334 REG_WR(bp
, BNX2_RV2P_PROC1_ADDR_CMD
, val
);
1337 val
= (i
/ 8) | BNX2_RV2P_PROC2_ADDR_CMD_RDWR
;
1338 REG_WR(bp
, BNX2_RV2P_PROC2_ADDR_CMD
, val
);
1342 /* Reset the processor, un-stall is done later. */
1343 if (rv2p_proc
== RV2P_PROC1
) {
1344 REG_WR(bp
, BNX2_RV2P_COMMAND
, BNX2_RV2P_COMMAND_PROC1_RESET
);
1347 REG_WR(bp
, BNX2_RV2P_COMMAND
, BNX2_RV2P_COMMAND_PROC2_RESET
);
1352 load_cpu_fw(struct bnx2
*bp
, struct cpu_reg
*cpu_reg
, struct fw_info
*fw
)
1358 val
= REG_RD_IND(bp
, cpu_reg
->mode
);
1359 val
|= cpu_reg
->mode_value_halt
;
1360 REG_WR_IND(bp
, cpu_reg
->mode
, val
);
1361 REG_WR_IND(bp
, cpu_reg
->state
, cpu_reg
->state_value_clear
);
1363 /* Load the Text area. */
1364 offset
= cpu_reg
->spad_base
+ (fw
->text_addr
- cpu_reg
->mips_view_base
);
1368 for (j
= 0; j
< (fw
->text_len
/ 4); j
++, offset
+= 4) {
1369 REG_WR_IND(bp
, offset
, fw
->text
[j
]);
1373 /* Load the Data area. */
1374 offset
= cpu_reg
->spad_base
+ (fw
->data_addr
- cpu_reg
->mips_view_base
);
1378 for (j
= 0; j
< (fw
->data_len
/ 4); j
++, offset
+= 4) {
1379 REG_WR_IND(bp
, offset
, fw
->data
[j
]);
1383 /* Load the SBSS area. */
1384 offset
= cpu_reg
->spad_base
+ (fw
->sbss_addr
- cpu_reg
->mips_view_base
);
1388 for (j
= 0; j
< (fw
->sbss_len
/ 4); j
++, offset
+= 4) {
1389 REG_WR_IND(bp
, offset
, fw
->sbss
[j
]);
1393 /* Load the BSS area. */
1394 offset
= cpu_reg
->spad_base
+ (fw
->bss_addr
- cpu_reg
->mips_view_base
);
1398 for (j
= 0; j
< (fw
->bss_len
/4); j
++, offset
+= 4) {
1399 REG_WR_IND(bp
, offset
, fw
->bss
[j
]);
1403 /* Load the Read-Only area. */
1404 offset
= cpu_reg
->spad_base
+
1405 (fw
->rodata_addr
- cpu_reg
->mips_view_base
);
1409 for (j
= 0; j
< (fw
->rodata_len
/ 4); j
++, offset
+= 4) {
1410 REG_WR_IND(bp
, offset
, fw
->rodata
[j
]);
1414 /* Clear the pre-fetch instruction. */
1415 REG_WR_IND(bp
, cpu_reg
->inst
, 0);
1416 REG_WR_IND(bp
, cpu_reg
->pc
, fw
->start_addr
);
1418 /* Start the CPU. */
1419 val
= REG_RD_IND(bp
, cpu_reg
->mode
);
1420 val
&= ~cpu_reg
->mode_value_halt
;
1421 REG_WR_IND(bp
, cpu_reg
->state
, cpu_reg
->state_value_clear
);
1422 REG_WR_IND(bp
, cpu_reg
->mode
, val
);
1426 bnx2_init_cpus(struct bnx2
*bp
)
1428 struct cpu_reg cpu_reg
;
1431 /* Unfortunately, it looks like we need to load the firmware
1432 * before the card will work properly. That means this driver
1433 * will be huge by Etherboot standards (approx. 50K compressed).
1436 /* Initialize the RV2P processor. */
1437 load_rv2p_fw(bp
, bnx2_rv2p_proc1
, sizeof(bnx2_rv2p_proc1
), RV2P_PROC1
);
1438 load_rv2p_fw(bp
, bnx2_rv2p_proc2
, sizeof(bnx2_rv2p_proc2
), RV2P_PROC2
);
1440 /* Initialize the RX Processor. */
1441 cpu_reg
.mode
= BNX2_RXP_CPU_MODE
;
1442 cpu_reg
.mode_value_halt
= BNX2_RXP_CPU_MODE_SOFT_HALT
;
1443 cpu_reg
.mode_value_sstep
= BNX2_RXP_CPU_MODE_STEP_ENA
;
1444 cpu_reg
.state
= BNX2_RXP_CPU_STATE
;
1445 cpu_reg
.state_value_clear
= 0xffffff;
1446 cpu_reg
.gpr0
= BNX2_RXP_CPU_REG_FILE
;
1447 cpu_reg
.evmask
= BNX2_RXP_CPU_EVENT_MASK
;
1448 cpu_reg
.pc
= BNX2_RXP_CPU_PROGRAM_COUNTER
;
1449 cpu_reg
.inst
= BNX2_RXP_CPU_INSTRUCTION
;
1450 cpu_reg
.bp
= BNX2_RXP_CPU_HW_BREAKPOINT
;
1451 cpu_reg
.spad_base
= BNX2_RXP_SCRATCH
;
1452 cpu_reg
.mips_view_base
= 0x8000000;
1454 fw
.ver_major
= bnx2_RXP_b06FwReleaseMajor
;
1455 fw
.ver_minor
= bnx2_RXP_b06FwReleaseMinor
;
1456 fw
.ver_fix
= bnx2_RXP_b06FwReleaseFix
;
1457 fw
.start_addr
= bnx2_RXP_b06FwStartAddr
;
1459 fw
.text_addr
= bnx2_RXP_b06FwTextAddr
;
1460 fw
.text_len
= bnx2_RXP_b06FwTextLen
;
1462 fw
.text
= bnx2_RXP_b06FwText
;
1464 fw
.data_addr
= bnx2_RXP_b06FwDataAddr
;
1465 fw
.data_len
= bnx2_RXP_b06FwDataLen
;
1467 fw
.data
= bnx2_RXP_b06FwData
;
1469 fw
.sbss_addr
= bnx2_RXP_b06FwSbssAddr
;
1470 fw
.sbss_len
= bnx2_RXP_b06FwSbssLen
;
1472 fw
.sbss
= bnx2_RXP_b06FwSbss
;
1474 fw
.bss_addr
= bnx2_RXP_b06FwBssAddr
;
1475 fw
.bss_len
= bnx2_RXP_b06FwBssLen
;
1477 fw
.bss
= bnx2_RXP_b06FwBss
;
1479 fw
.rodata_addr
= bnx2_RXP_b06FwRodataAddr
;
1480 fw
.rodata_len
= bnx2_RXP_b06FwRodataLen
;
1481 fw
.rodata_index
= 0;
1482 fw
.rodata
= bnx2_RXP_b06FwRodata
;
1484 load_cpu_fw(bp
, &cpu_reg
, &fw
);
1486 /* Initialize the TX Processor. */
1487 cpu_reg
.mode
= BNX2_TXP_CPU_MODE
;
1488 cpu_reg
.mode_value_halt
= BNX2_TXP_CPU_MODE_SOFT_HALT
;
1489 cpu_reg
.mode_value_sstep
= BNX2_TXP_CPU_MODE_STEP_ENA
;
1490 cpu_reg
.state
= BNX2_TXP_CPU_STATE
;
1491 cpu_reg
.state_value_clear
= 0xffffff;
1492 cpu_reg
.gpr0
= BNX2_TXP_CPU_REG_FILE
;
1493 cpu_reg
.evmask
= BNX2_TXP_CPU_EVENT_MASK
;
1494 cpu_reg
.pc
= BNX2_TXP_CPU_PROGRAM_COUNTER
;
1495 cpu_reg
.inst
= BNX2_TXP_CPU_INSTRUCTION
;
1496 cpu_reg
.bp
= BNX2_TXP_CPU_HW_BREAKPOINT
;
1497 cpu_reg
.spad_base
= BNX2_TXP_SCRATCH
;
1498 cpu_reg
.mips_view_base
= 0x8000000;
1500 fw
.ver_major
= bnx2_TXP_b06FwReleaseMajor
;
1501 fw
.ver_minor
= bnx2_TXP_b06FwReleaseMinor
;
1502 fw
.ver_fix
= bnx2_TXP_b06FwReleaseFix
;
1503 fw
.start_addr
= bnx2_TXP_b06FwStartAddr
;
1505 fw
.text_addr
= bnx2_TXP_b06FwTextAddr
;
1506 fw
.text_len
= bnx2_TXP_b06FwTextLen
;
1508 fw
.text
= bnx2_TXP_b06FwText
;
1510 fw
.data_addr
= bnx2_TXP_b06FwDataAddr
;
1511 fw
.data_len
= bnx2_TXP_b06FwDataLen
;
1513 fw
.data
= bnx2_TXP_b06FwData
;
1515 fw
.sbss_addr
= bnx2_TXP_b06FwSbssAddr
;
1516 fw
.sbss_len
= bnx2_TXP_b06FwSbssLen
;
1518 fw
.sbss
= bnx2_TXP_b06FwSbss
;
1520 fw
.bss_addr
= bnx2_TXP_b06FwBssAddr
;
1521 fw
.bss_len
= bnx2_TXP_b06FwBssLen
;
1523 fw
.bss
= bnx2_TXP_b06FwBss
;
1525 fw
.rodata_addr
= bnx2_TXP_b06FwRodataAddr
;
1526 fw
.rodata_len
= bnx2_TXP_b06FwRodataLen
;
1527 fw
.rodata_index
= 0;
1528 fw
.rodata
= bnx2_TXP_b06FwRodata
;
1530 load_cpu_fw(bp
, &cpu_reg
, &fw
);
1532 /* Initialize the TX Patch-up Processor. */
1533 cpu_reg
.mode
= BNX2_TPAT_CPU_MODE
;
1534 cpu_reg
.mode_value_halt
= BNX2_TPAT_CPU_MODE_SOFT_HALT
;
1535 cpu_reg
.mode_value_sstep
= BNX2_TPAT_CPU_MODE_STEP_ENA
;
1536 cpu_reg
.state
= BNX2_TPAT_CPU_STATE
;
1537 cpu_reg
.state_value_clear
= 0xffffff;
1538 cpu_reg
.gpr0
= BNX2_TPAT_CPU_REG_FILE
;
1539 cpu_reg
.evmask
= BNX2_TPAT_CPU_EVENT_MASK
;
1540 cpu_reg
.pc
= BNX2_TPAT_CPU_PROGRAM_COUNTER
;
1541 cpu_reg
.inst
= BNX2_TPAT_CPU_INSTRUCTION
;
1542 cpu_reg
.bp
= BNX2_TPAT_CPU_HW_BREAKPOINT
;
1543 cpu_reg
.spad_base
= BNX2_TPAT_SCRATCH
;
1544 cpu_reg
.mips_view_base
= 0x8000000;
1546 fw
.ver_major
= bnx2_TPAT_b06FwReleaseMajor
;
1547 fw
.ver_minor
= bnx2_TPAT_b06FwReleaseMinor
;
1548 fw
.ver_fix
= bnx2_TPAT_b06FwReleaseFix
;
1549 fw
.start_addr
= bnx2_TPAT_b06FwStartAddr
;
1551 fw
.text_addr
= bnx2_TPAT_b06FwTextAddr
;
1552 fw
.text_len
= bnx2_TPAT_b06FwTextLen
;
1554 fw
.text
= bnx2_TPAT_b06FwText
;
1556 fw
.data_addr
= bnx2_TPAT_b06FwDataAddr
;
1557 fw
.data_len
= bnx2_TPAT_b06FwDataLen
;
1559 fw
.data
= bnx2_TPAT_b06FwData
;
1561 fw
.sbss_addr
= bnx2_TPAT_b06FwSbssAddr
;
1562 fw
.sbss_len
= bnx2_TPAT_b06FwSbssLen
;
1564 fw
.sbss
= bnx2_TPAT_b06FwSbss
;
1566 fw
.bss_addr
= bnx2_TPAT_b06FwBssAddr
;
1567 fw
.bss_len
= bnx2_TPAT_b06FwBssLen
;
1569 fw
.bss
= bnx2_TPAT_b06FwBss
;
1571 fw
.rodata_addr
= bnx2_TPAT_b06FwRodataAddr
;
1572 fw
.rodata_len
= bnx2_TPAT_b06FwRodataLen
;
1573 fw
.rodata_index
= 0;
1574 fw
.rodata
= bnx2_TPAT_b06FwRodata
;
1576 load_cpu_fw(bp
, &cpu_reg
, &fw
);
1578 /* Initialize the Completion Processor. */
1579 cpu_reg
.mode
= BNX2_COM_CPU_MODE
;
1580 cpu_reg
.mode_value_halt
= BNX2_COM_CPU_MODE_SOFT_HALT
;
1581 cpu_reg
.mode_value_sstep
= BNX2_COM_CPU_MODE_STEP_ENA
;
1582 cpu_reg
.state
= BNX2_COM_CPU_STATE
;
1583 cpu_reg
.state_value_clear
= 0xffffff;
1584 cpu_reg
.gpr0
= BNX2_COM_CPU_REG_FILE
;
1585 cpu_reg
.evmask
= BNX2_COM_CPU_EVENT_MASK
;
1586 cpu_reg
.pc
= BNX2_COM_CPU_PROGRAM_COUNTER
;
1587 cpu_reg
.inst
= BNX2_COM_CPU_INSTRUCTION
;
1588 cpu_reg
.bp
= BNX2_COM_CPU_HW_BREAKPOINT
;
1589 cpu_reg
.spad_base
= BNX2_COM_SCRATCH
;
1590 cpu_reg
.mips_view_base
= 0x8000000;
1592 fw
.ver_major
= bnx2_COM_b06FwReleaseMajor
;
1593 fw
.ver_minor
= bnx2_COM_b06FwReleaseMinor
;
1594 fw
.ver_fix
= bnx2_COM_b06FwReleaseFix
;
1595 fw
.start_addr
= bnx2_COM_b06FwStartAddr
;
1597 fw
.text_addr
= bnx2_COM_b06FwTextAddr
;
1598 fw
.text_len
= bnx2_COM_b06FwTextLen
;
1600 fw
.text
= bnx2_COM_b06FwText
;
1602 fw
.data_addr
= bnx2_COM_b06FwDataAddr
;
1603 fw
.data_len
= bnx2_COM_b06FwDataLen
;
1605 fw
.data
= bnx2_COM_b06FwData
;
1607 fw
.sbss_addr
= bnx2_COM_b06FwSbssAddr
;
1608 fw
.sbss_len
= bnx2_COM_b06FwSbssLen
;
1610 fw
.sbss
= bnx2_COM_b06FwSbss
;
1612 fw
.bss_addr
= bnx2_COM_b06FwBssAddr
;
1613 fw
.bss_len
= bnx2_COM_b06FwBssLen
;
1615 fw
.bss
= bnx2_COM_b06FwBss
;
1617 fw
.rodata_addr
= bnx2_COM_b06FwRodataAddr
;
1618 fw
.rodata_len
= bnx2_COM_b06FwRodataLen
;
1619 fw
.rodata_index
= 0;
1620 fw
.rodata
= bnx2_COM_b06FwRodata
;
1622 load_cpu_fw(bp
, &cpu_reg
, &fw
);
1627 bnx2_set_power_state_0(struct bnx2
*bp
)
1632 pci_read_config_word(bp
->pdev
, bp
->pm_cap
+ PCI_PM_CTRL
, &pmcsr
);
1634 pci_write_config_word(bp
->pdev
, bp
->pm_cap
+ PCI_PM_CTRL
,
1635 (pmcsr
& ~PCI_PM_CTRL_STATE_MASK
) |
1636 PCI_PM_CTRL_PME_STATUS
);
1638 if (pmcsr
& PCI_PM_CTRL_STATE_MASK
)
1639 /* delay required during transition out of D3hot */
1642 val
= REG_RD(bp
, BNX2_EMAC_MODE
);
1643 val
|= BNX2_EMAC_MODE_MPKT_RCVD
| BNX2_EMAC_MODE_ACPI_RCVD
;
1644 val
&= ~BNX2_EMAC_MODE_MPKT
;
1645 REG_WR(bp
, BNX2_EMAC_MODE
, val
);
1647 val
= REG_RD(bp
, BNX2_RPM_CONFIG
);
1648 val
&= ~BNX2_RPM_CONFIG_ACPI_ENA
;
1649 REG_WR(bp
, BNX2_RPM_CONFIG
, val
);
1655 bnx2_enable_nvram_access(struct bnx2
*bp
)
1659 val
= REG_RD(bp
, BNX2_NVM_ACCESS_ENABLE
);
1660 /* Enable both bits, even on read. */
1661 REG_WR(bp
, BNX2_NVM_ACCESS_ENABLE
,
1662 val
| BNX2_NVM_ACCESS_ENABLE_EN
| BNX2_NVM_ACCESS_ENABLE_WR_EN
);
1666 bnx2_disable_nvram_access(struct bnx2
*bp
)
1670 val
= REG_RD(bp
, BNX2_NVM_ACCESS_ENABLE
);
1671 /* Disable both bits, even after read. */
1672 REG_WR(bp
, BNX2_NVM_ACCESS_ENABLE
,
1673 val
& ~(BNX2_NVM_ACCESS_ENABLE_EN
|
1674 BNX2_NVM_ACCESS_ENABLE_WR_EN
));
1678 bnx2_init_nvram(struct bnx2
*bp
)
1681 int j
, entry_count
, rc
;
1682 struct flash_spec
*flash
;
1684 /* Determine the selected interface. */
1685 val
= REG_RD(bp
, BNX2_NVM_CFG1
);
1687 entry_count
= sizeof(flash_table
) / sizeof(struct flash_spec
);
1690 if (val
& 0x40000000) {
1691 /* Flash interface has been reconfigured */
1692 for (j
= 0, flash
= &flash_table
[0]; j
< entry_count
;
1694 if ((val
& FLASH_BACKUP_STRAP_MASK
) ==
1695 (flash
->config1
& FLASH_BACKUP_STRAP_MASK
)) {
1696 bp
->flash_info
= flash
;
1703 /* Not yet been reconfigured */
1705 if (val
& (1 << 23))
1706 mask
= FLASH_BACKUP_STRAP_MASK
;
1708 mask
= FLASH_STRAP_MASK
;
1710 for (j
= 0, flash
= &flash_table
[0]; j
< entry_count
;
1713 if ((val
& mask
) == (flash
->strapping
& mask
)) {
1714 bp
->flash_info
= flash
;
1716 /* Enable access to flash interface */
1717 bnx2_enable_nvram_access(bp
);
1719 /* Reconfigure the flash interface */
1720 REG_WR(bp
, BNX2_NVM_CFG1
, flash
->config1
);
1721 REG_WR(bp
, BNX2_NVM_CFG2
, flash
->config2
);
1722 REG_WR(bp
, BNX2_NVM_CFG3
, flash
->config3
);
1723 REG_WR(bp
, BNX2_NVM_WRITE1
, flash
->write1
);
1725 /* Disable access to flash interface */
1726 bnx2_disable_nvram_access(bp
);
1731 } /* if (val & 0x40000000) */
1733 if (j
== entry_count
) {
1734 bp
->flash_info
= NULL
;
1735 printf("Unknown flash/EEPROM type.\n");
1739 val
= REG_RD_IND(bp
, bp
->shmem_base
+ BNX2_SHARED_HW_CFG_CONFIG2
);
1740 val
&= BNX2_SHARED_HW_CFG2_NVM_SIZE_MASK
;
1742 bp
->flash_size
= val
;
1745 bp
->flash_size
= bp
->flash_info
->total_size
;
1752 bnx2_reset_chip(struct bnx2
*bp
, u32 reset_code
)
1757 /* Wait for the current PCI transaction to complete before
1758 * issuing a reset. */
1759 REG_WR(bp
, BNX2_MISC_ENABLE_CLR_BITS
,
1760 BNX2_MISC_ENABLE_CLR_BITS_TX_DMA_ENABLE
|
1761 BNX2_MISC_ENABLE_CLR_BITS_DMA_ENGINE_ENABLE
|
1762 BNX2_MISC_ENABLE_CLR_BITS_RX_DMA_ENABLE
|
1763 BNX2_MISC_ENABLE_CLR_BITS_HOST_COALESCE_ENABLE
);
1764 val
= REG_RD(bp
, BNX2_MISC_ENABLE_CLR_BITS
);
1768 /* Wait for the firmware to tell us it is ok to issue a reset. */
1769 bnx2_fw_sync(bp
, BNX2_DRV_MSG_DATA_WAIT0
| reset_code
, 1);
1771 /* Deposit a driver reset signature so the firmware knows that
1772 * this is a soft reset. */
1773 REG_WR_IND(bp
, bp
->shmem_base
+ BNX2_DRV_RESET_SIGNATURE
,
1774 BNX2_DRV_RESET_SIGNATURE_MAGIC
);
1776 /* Do a dummy read to force the chip to complete all current transaction
1777 * before we issue a reset. */
1778 val
= REG_RD(bp
, BNX2_MISC_ID
);
1780 val
= BNX2_PCICFG_MISC_CONFIG_CORE_RST_REQ
|
1781 BNX2_PCICFG_MISC_CONFIG_REG_WINDOW_ENA
|
1782 BNX2_PCICFG_MISC_CONFIG_TARGET_MB_WORD_SWAP
;
1785 REG_WR(bp
, BNX2_PCICFG_MISC_CONFIG
, val
);
1787 if ((CHIP_ID(bp
) == CHIP_ID_5706_A0
) ||
1788 (CHIP_ID(bp
) == CHIP_ID_5706_A1
))
1791 /* Reset takes approximate 30 usec */
1792 for (i
= 0; i
< 10; i
++) {
1793 val
= REG_RD(bp
, BNX2_PCICFG_MISC_CONFIG
);
1794 if ((val
& (BNX2_PCICFG_MISC_CONFIG_CORE_RST_REQ
|
1795 BNX2_PCICFG_MISC_CONFIG_CORE_RST_BSY
)) == 0) {
1801 if (val
& (BNX2_PCICFG_MISC_CONFIG_CORE_RST_REQ
|
1802 BNX2_PCICFG_MISC_CONFIG_CORE_RST_BSY
)) {
1803 printf("Chip reset did not complete\n");
1807 /* Make sure byte swapping is properly configured. */
1808 val
= REG_RD(bp
, BNX2_PCI_SWAP_DIAG0
);
1809 if (val
!= 0x01020304) {
1810 printf("Chip not in correct endian mode\n");
1814 /* Wait for the firmware to finish its initialization. */
1815 rc
= bnx2_fw_sync(bp
, BNX2_DRV_MSG_DATA_WAIT1
| reset_code
, 0);
1820 if (CHIP_ID(bp
) == CHIP_ID_5706_A0
) {
1821 /* Adjust the voltage regular to two steps lower. The default
1822 * of this register is 0x0000000e. */
1823 REG_WR(bp
, BNX2_MISC_VREG_CONTROL
, 0x000000fa);
1825 /* Remove bad rbuf memory from the free pool. */
1826 rc
= bnx2_alloc_bad_rbuf(bp
);
1833 bnx2_disable(struct nic
*nic __unused
)
1835 struct bnx2
* bp
= &bnx2
;
1838 bnx2_reset_chip(bp
, BNX2_DRV_MSG_CODE_UNLOAD
);
1839 iounmap(bp
->regview
);
1844 bnx2_init_chip(struct bnx2
*bp
)
1849 /* Make sure the interrupt is not active. */
1850 REG_WR(bp
, BNX2_PCICFG_INT_ACK_CMD
, BNX2_PCICFG_INT_ACK_CMD_MASK_INT
);
1852 val
= BNX2_DMA_CONFIG_DATA_BYTE_SWAP
|
1853 BNX2_DMA_CONFIG_DATA_WORD_SWAP
|
1854 #if __BYTE_ORDER == __BIG_ENDIAN
1855 BNX2_DMA_CONFIG_CNTL_BYTE_SWAP
|
1857 BNX2_DMA_CONFIG_CNTL_WORD_SWAP
|
1858 DMA_READ_CHANS
<< 12 |
1859 DMA_WRITE_CHANS
<< 16;
1861 val
|= (0x2 << 20) | (1 << 11);
1863 if ((bp
->flags
& PCIX_FLAG
) && (bp
->bus_speed_mhz
== 133))
1866 if ((CHIP_NUM(bp
) == CHIP_NUM_5706
) &&
1867 (CHIP_ID(bp
) != CHIP_ID_5706_A0
) && !(bp
->flags
& PCIX_FLAG
))
1868 val
|= BNX2_DMA_CONFIG_CNTL_PING_PONG_DMA
;
1870 REG_WR(bp
, BNX2_DMA_CONFIG
, val
);
1872 if (CHIP_ID(bp
) == CHIP_ID_5706_A0
) {
1873 val
= REG_RD(bp
, BNX2_TDMA_CONFIG
);
1874 val
|= BNX2_TDMA_CONFIG_ONE_DMA
;
1875 REG_WR(bp
, BNX2_TDMA_CONFIG
, val
);
1878 if (bp
->flags
& PCIX_FLAG
) {
1881 pci_read_config_word(bp
->pdev
, bp
->pcix_cap
+ PCI_X_CMD
,
1883 pci_write_config_word(bp
->pdev
, bp
->pcix_cap
+ PCI_X_CMD
,
1884 val16
& ~PCI_X_CMD_ERO
);
1887 REG_WR(bp
, BNX2_MISC_ENABLE_SET_BITS
,
1888 BNX2_MISC_ENABLE_SET_BITS_HOST_COALESCE_ENABLE
|
1889 BNX2_MISC_ENABLE_STATUS_BITS_RX_V2P_ENABLE
|
1890 BNX2_MISC_ENABLE_STATUS_BITS_CONTEXT_ENABLE
);
1892 /* Initialize context mapping and zero out the quick contexts. The
1893 * context block must have already been enabled. */
1894 bnx2_init_context(bp
);
1896 bnx2_init_nvram(bp
);
1899 bnx2_set_mac_addr(bp
);
1901 val
= REG_RD(bp
, BNX2_MQ_CONFIG
);
1902 val
&= ~BNX2_MQ_CONFIG_KNL_BYP_BLK_SIZE
;
1903 val
|= BNX2_MQ_CONFIG_KNL_BYP_BLK_SIZE_256
;
1904 REG_WR(bp
, BNX2_MQ_CONFIG
, val
);
1906 val
= 0x10000 + (MAX_CID_CNT
* MB_KERNEL_CTX_SIZE
);
1907 REG_WR(bp
, BNX2_MQ_KNL_BYP_WIND_START
, val
);
1908 REG_WR(bp
, BNX2_MQ_KNL_WIND_END
, val
);
1910 val
= (BCM_PAGE_BITS
- 8) << 24;
1911 REG_WR(bp
, BNX2_RV2P_CONFIG
, val
);
1913 /* Configure page size. */
1914 val
= REG_RD(bp
, BNX2_TBDR_CONFIG
);
1915 val
&= ~BNX2_TBDR_CONFIG_PAGE_SIZE
;
1916 val
|= (BCM_PAGE_BITS
- 8) << 24 | 0x40;
1917 REG_WR(bp
, BNX2_TBDR_CONFIG
, val
);
1919 val
= bp
->mac_addr
[0] +
1920 (bp
->mac_addr
[1] << 8) +
1921 (bp
->mac_addr
[2] << 16) +
1923 (bp
->mac_addr
[4] << 8) +
1924 (bp
->mac_addr
[5] << 16);
1925 REG_WR(bp
, BNX2_EMAC_BACKOFF_SEED
, val
);
1927 /* Program the MTU. Also include 4 bytes for CRC32. */
1928 val
= ETH_MAX_MTU
+ ETH_HLEN
+ 4;
1929 if (val
> (MAX_ETHERNET_PACKET_SIZE
+ 4))
1930 val
|= BNX2_EMAC_RX_MTU_SIZE_JUMBO_ENA
;
1931 REG_WR(bp
, BNX2_EMAC_RX_MTU_SIZE
, val
);
1933 bp
->last_status_idx
= 0;
1934 bp
->rx_mode
= BNX2_EMAC_RX_MODE_SORT_MODE
;
1936 /* Set up how to generate a link change interrupt. */
1937 REG_WR(bp
, BNX2_EMAC_ATTENTION_ENA
, BNX2_EMAC_ATTENTION_ENA_LINK
);
1939 REG_WR(bp
, BNX2_HC_STATUS_ADDR_L
,
1940 (u64
) bp
->status_blk_mapping
& 0xffffffff);
1941 REG_WR(bp
, BNX2_HC_STATUS_ADDR_H
, (u64
) bp
->status_blk_mapping
>> 32);
1943 REG_WR(bp
, BNX2_HC_STATISTICS_ADDR_L
,
1944 (u64
) bp
->stats_blk_mapping
& 0xffffffff);
1945 REG_WR(bp
, BNX2_HC_STATISTICS_ADDR_H
,
1946 (u64
) bp
->stats_blk_mapping
>> 32);
1948 REG_WR(bp
, BNX2_HC_TX_QUICK_CONS_TRIP
,
1949 (bp
->tx_quick_cons_trip_int
<< 16) | bp
->tx_quick_cons_trip
);
1951 REG_WR(bp
, BNX2_HC_RX_QUICK_CONS_TRIP
,
1952 (bp
->rx_quick_cons_trip_int
<< 16) | bp
->rx_quick_cons_trip
);
1954 REG_WR(bp
, BNX2_HC_COMP_PROD_TRIP
,
1955 (bp
->comp_prod_trip_int
<< 16) | bp
->comp_prod_trip
);
1957 REG_WR(bp
, BNX2_HC_TX_TICKS
, (bp
->tx_ticks_int
<< 16) | bp
->tx_ticks
);
1959 REG_WR(bp
, BNX2_HC_RX_TICKS
, (bp
->rx_ticks_int
<< 16) | bp
->rx_ticks
);
1961 REG_WR(bp
, BNX2_HC_COM_TICKS
,
1962 (bp
->com_ticks_int
<< 16) | bp
->com_ticks
);
1964 REG_WR(bp
, BNX2_HC_CMD_TICKS
,
1965 (bp
->cmd_ticks_int
<< 16) | bp
->cmd_ticks
);
1967 REG_WR(bp
, BNX2_HC_STATS_TICKS
, bp
->stats_ticks
& 0xffff00);
1968 REG_WR(bp
, BNX2_HC_STAT_COLLECT_TICKS
, 0xbb8); /* 3ms */
1970 if (CHIP_ID(bp
) == CHIP_ID_5706_A1
)
1971 REG_WR(bp
, BNX2_HC_CONFIG
, BNX2_HC_CONFIG_COLLECT_STATS
);
1973 REG_WR(bp
, BNX2_HC_CONFIG
, BNX2_HC_CONFIG_RX_TMR_MODE
|
1974 BNX2_HC_CONFIG_TX_TMR_MODE
|
1975 BNX2_HC_CONFIG_COLLECT_STATS
);
1978 /* Clear internal stats counters. */
1979 REG_WR(bp
, BNX2_HC_COMMAND
, BNX2_HC_COMMAND_CLR_STAT_NOW
);
1981 REG_WR(bp
, BNX2_HC_ATTN_BITS_ENABLE
, STATUS_ATTN_BITS_LINK_STATE
);
1983 if (REG_RD_IND(bp
, bp
->shmem_base
+ BNX2_PORT_FEATURE
) &
1984 BNX2_PORT_FEATURE_ASF_ENABLED
)
1985 bp
->flags
|= ASF_ENABLE_FLAG
;
1987 /* Initialize the receive filter. */
1988 bnx2_set_rx_mode(bp
->nic
);
1990 rc
= bnx2_fw_sync(bp
, BNX2_DRV_MSG_DATA_WAIT2
| BNX2_DRV_MSG_CODE_RESET
,
1993 REG_WR(bp
, BNX2_MISC_ENABLE_SET_BITS
, 0x5ffffff);
1994 REG_RD(bp
, BNX2_MISC_ENABLE_SET_BITS
);
1998 bp
->hc_cmd
= REG_RD(bp
, BNX2_HC_COMMAND
);
2004 bnx2_init_tx_ring(struct bnx2
*bp
)
2009 txbd
= &bp
->tx_desc_ring
[MAX_TX_DESC_CNT
];
2011 /* Etherboot lives below 4GB, so hi is always 0 */
2012 txbd
->tx_bd_haddr_hi
= 0;
2013 txbd
->tx_bd_haddr_lo
= bp
->tx_desc_mapping
;
2018 bp
->tx_prod_bseq
= 0;
2020 val
= BNX2_L2CTX_TYPE_TYPE_L2
;
2021 val
|= BNX2_L2CTX_TYPE_SIZE_L2
;
2022 CTX_WR(bp
, GET_CID_ADDR(TX_CID
), BNX2_L2CTX_TYPE
, val
);
2024 val
= BNX2_L2CTX_CMD_TYPE_TYPE_L2
;
2026 CTX_WR(bp
, GET_CID_ADDR(TX_CID
), BNX2_L2CTX_CMD_TYPE
, val
);
2028 /* Etherboot lives below 4GB, so hi is always 0 */
2029 CTX_WR(bp
, GET_CID_ADDR(TX_CID
), BNX2_L2CTX_TBDR_BHADDR_HI
, 0);
2031 val
= (u64
) bp
->tx_desc_mapping
& 0xffffffff;
2032 CTX_WR(bp
, GET_CID_ADDR(TX_CID
), BNX2_L2CTX_TBDR_BHADDR_LO
, val
);
2036 bnx2_init_rx_ring(struct bnx2
*bp
)
2040 u16 prod
, ring_prod
;
2043 bp
->rx_buf_use_size
= RX_BUF_USE_SIZE
;
2044 bp
->rx_buf_size
= RX_BUF_SIZE
;
2046 ring_prod
= prod
= bp
->rx_prod
= 0;
2049 bp
->rx_prod_bseq
= 0;
2051 memset(bnx2_bss
.rx_buf
, 0, sizeof(bnx2_bss
.rx_buf
));
2053 rxbd
= &bp
->rx_desc_ring
[0];
2054 for (i
= 0; i
< MAX_RX_DESC_CNT
; i
++, rxbd
++) {
2055 rxbd
->rx_bd_len
= bp
->rx_buf_use_size
;
2056 rxbd
->rx_bd_flags
= RX_BD_FLAGS_START
| RX_BD_FLAGS_END
;
2058 rxbd
->rx_bd_haddr_hi
= 0;
2059 rxbd
->rx_bd_haddr_lo
= (u64
) bp
->rx_desc_mapping
& 0xffffffff;
2061 val
= BNX2_L2CTX_CTX_TYPE_CTX_BD_CHN_TYPE_VALUE
;
2062 val
|= BNX2_L2CTX_CTX_TYPE_SIZE_L2
;
2064 CTX_WR(bp
, GET_CID_ADDR(RX_CID
), BNX2_L2CTX_CTX_TYPE
, val
);
2066 /* Etherboot doesn't use memory above 4GB, so this is always 0 */
2067 CTX_WR(bp
, GET_CID_ADDR(RX_CID
), BNX2_L2CTX_NX_BDHADDR_HI
, 0);
2069 val
= bp
->rx_desc_mapping
& 0xffffffff;
2070 CTX_WR(bp
, GET_CID_ADDR(RX_CID
), BNX2_L2CTX_NX_BDHADDR_LO
, val
);
2072 for (i
= 0; (int) i
< bp
->rx_ring_size
; i
++) {
2073 rxbd
= &bp
->rx_desc_ring
[RX_RING_IDX(ring_prod
)];
2074 rxbd
->rx_bd_haddr_hi
= 0;
2075 rxbd
->rx_bd_haddr_lo
= virt_to_bus(&bnx2_bss
.rx_buf
[ring_prod
][0]);
2076 bp
->rx_prod_bseq
+= bp
->rx_buf_use_size
;
2077 prod
= NEXT_RX_BD(prod
);
2078 ring_prod
= RX_RING_IDX(prod
);
2082 REG_WR16(bp
, MB_RX_CID_ADDR
+ BNX2_L2CTX_HOST_BDIDX
, bp
->rx_prod
);
2084 REG_WR(bp
, MB_RX_CID_ADDR
+ BNX2_L2CTX_HOST_BSEQ
, bp
->rx_prod_bseq
);
2088 bnx2_reset_nic(struct bnx2
*bp
, u32 reset_code
)
2092 rc
= bnx2_reset_chip(bp
, reset_code
);
2098 bnx2_init_tx_ring(bp
);
2099 bnx2_init_rx_ring(bp
);
2104 bnx2_init_nic(struct bnx2
*bp
)
2108 if ((rc
= bnx2_reset_nic(bp
, BNX2_DRV_MSG_CODE_RESET
)) != 0)
2117 bnx2_init_board(struct pci_device
*pdev
, struct nic
*nic
)
2119 unsigned long bnx2reg_base
, bnx2reg_len
;
2120 struct bnx2
*bp
= &bnx2
;
2127 /* enable device (incl. PCI PM wakeup), and bus-mastering */
2128 adjust_pci_device(pdev
);
2130 nic
->ioaddr
= pdev
->ioaddr
& ~3;
2134 bp
->pm_cap
= pci_find_capability(pdev
, PCI_CAP_ID_PM
);
2135 if (bp
->pm_cap
== 0) {
2136 printf("Cannot find power management capability, aborting.\n");
2138 goto err_out_disable
;
2141 bp
->pcix_cap
= pci_find_capability(pdev
, PCI_CAP_ID_PCIX
);
2142 if (bp
->pcix_cap
== 0) {
2143 printf("Cannot find PCIX capability, aborting.\n");
2145 goto err_out_disable
;
2151 bnx2reg_base
= pci_bar_start(pdev
, PCI_BASE_ADDRESS_0
);
2152 bnx2reg_len
= MB_GET_CID_ADDR(17);
2154 bp
->regview
= ioremap(bnx2reg_base
, bnx2reg_len
);
2157 printf("Cannot map register space, aborting.\n");
2159 goto err_out_disable
;
2162 /* Configure byte swap and enable write to the reg_window registers.
2163 * Rely on CPU to do target byte swapping on big endian systems
2164 * The chip's target access swapping will not swap all accesses
2166 pci_write_config_dword(bp
->pdev
, BNX2_PCICFG_MISC_CONFIG
,
2167 BNX2_PCICFG_MISC_CONFIG_REG_WINDOW_ENA
|
2168 BNX2_PCICFG_MISC_CONFIG_TARGET_MB_WORD_SWAP
);
2170 bnx2_set_power_state_0(bp
);
2172 bp
->chip_id
= REG_RD(bp
, BNX2_MISC_ID
);
2174 /* Get bus information. */
2175 reg
= REG_RD(bp
, BNX2_PCICFG_MISC_STATUS
);
2176 if (reg
& BNX2_PCICFG_MISC_STATUS_PCIX_DET
) {
2179 bp
->flags
|= PCIX_FLAG
;
2181 clkreg
= REG_RD(bp
, BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS
);
2183 clkreg
&= BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET
;
2185 case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_133MHZ
:
2186 bp
->bus_speed_mhz
= 133;
2189 case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_95MHZ
:
2190 bp
->bus_speed_mhz
= 100;
2193 case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_66MHZ
:
2194 case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_80MHZ
:
2195 bp
->bus_speed_mhz
= 66;
2198 case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_48MHZ
:
2199 case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_55MHZ
:
2200 bp
->bus_speed_mhz
= 50;
2203 case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_LOW
:
2204 case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_32MHZ
:
2205 case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_38MHZ
:
2206 bp
->bus_speed_mhz
= 33;
2211 if (reg
& BNX2_PCICFG_MISC_STATUS_M66EN
)
2212 bp
->bus_speed_mhz
= 66;
2214 bp
->bus_speed_mhz
= 33;
2217 if (reg
& BNX2_PCICFG_MISC_STATUS_32BIT_DET
)
2218 bp
->flags
|= PCI_32BIT_FLAG
;
2220 /* 5706A0 may falsely detect SERR and PERR. */
2221 if (CHIP_ID(bp
) == CHIP_ID_5706_A0
) {
2222 reg
= REG_RD(bp
, PCI_COMMAND
);
2223 reg
&= ~(PCI_COMMAND_SERR
| PCI_COMMAND_PARITY
);
2224 REG_WR(bp
, PCI_COMMAND
, reg
);
2226 else if ((CHIP_ID(bp
) == CHIP_ID_5706_A1
) &&
2227 !(bp
->flags
& PCIX_FLAG
)) {
2229 printf("5706 A1 can only be used in a PCIX bus, aborting.\n");
2230 goto err_out_disable
;
2233 bnx2_init_nvram(bp
);
2235 reg
= REG_RD_IND(bp
, BNX2_SHM_HDR_SIGNATURE
);
2237 if ((reg
& BNX2_SHM_HDR_SIGNATURE_SIG_MASK
) ==
2238 BNX2_SHM_HDR_SIGNATURE_SIG
)
2239 bp
->shmem_base
= REG_RD_IND(bp
, BNX2_SHM_HDR_ADDR_0
);
2241 bp
->shmem_base
= HOST_VIEW_SHMEM_BASE
;
2243 /* Get the permanent MAC address. First we need to make sure the
2244 * firmware is actually running.
2246 reg
= REG_RD_IND(bp
, bp
->shmem_base
+ BNX2_DEV_INFO_SIGNATURE
);
2248 if ((reg
& BNX2_DEV_INFO_SIGNATURE_MAGIC_MASK
) !=
2249 BNX2_DEV_INFO_SIGNATURE_MAGIC
) {
2250 printf("Firmware not running, aborting.\n");
2252 goto err_out_disable
;
2255 bp
->fw_ver
= REG_RD_IND(bp
, bp
->shmem_base
+ BNX2_DEV_INFO_BC_REV
);
2257 reg
= REG_RD_IND(bp
, bp
->shmem_base
+ BNX2_PORT_HW_CFG_MAC_UPPER
);
2258 bp
->mac_addr
[0] = (u8
) (reg
>> 8);
2259 bp
->mac_addr
[1] = (u8
) reg
;
2261 reg
= REG_RD_IND(bp
, bp
->shmem_base
+ BNX2_PORT_HW_CFG_MAC_LOWER
);
2262 bp
->mac_addr
[2] = (u8
) (reg
>> 24);
2263 bp
->mac_addr
[3] = (u8
) (reg
>> 16);
2264 bp
->mac_addr
[4] = (u8
) (reg
>> 8);
2265 bp
->mac_addr
[5] = (u8
) reg
;
2267 bp
->tx_ring_size
= MAX_TX_DESC_CNT
;
2268 bp
->rx_ring_size
= RX_BUF_CNT
;
2269 bp
->rx_max_ring_idx
= MAX_RX_DESC_CNT
;
2271 bp
->rx_offset
= RX_OFFSET
;
2273 bp
->tx_quick_cons_trip_int
= 20;
2274 bp
->tx_quick_cons_trip
= 20;
2275 bp
->tx_ticks_int
= 80;
2278 bp
->rx_quick_cons_trip_int
= 6;
2279 bp
->rx_quick_cons_trip
= 6;
2280 bp
->rx_ticks_int
= 18;
2283 bp
->stats_ticks
= 1000000 & 0xffff00;
2287 /* No need for WOL support in Etherboot */
2288 bp
->flags
|= NO_WOL_FLAG
;
2290 /* Disable WOL support if we are running on a SERDES chip. */
2291 if (CHIP_BOND_ID(bp
) & CHIP_BOND_ID_SERDES_BIT
) {
2292 bp
->phy_flags
|= PHY_SERDES_FLAG
;
2293 if (CHIP_NUM(bp
) == CHIP_NUM_5708
) {
2295 reg
= REG_RD_IND(bp
, bp
->shmem_base
+
2296 BNX2_SHARED_HW_CFG_CONFIG
);
2297 if (reg
& BNX2_SHARED_HW_CFG_PHY_2_5G
)
2298 bp
->phy_flags
|= PHY_2_5G_CAPABLE_FLAG
;
2302 if (CHIP_ID(bp
) == CHIP_ID_5706_A0
) {
2303 bp
->tx_quick_cons_trip_int
=
2304 bp
->tx_quick_cons_trip
;
2305 bp
->tx_ticks_int
= bp
->tx_ticks
;
2306 bp
->rx_quick_cons_trip_int
=
2307 bp
->rx_quick_cons_trip
;
2308 bp
->rx_ticks_int
= bp
->rx_ticks
;
2309 bp
->comp_prod_trip_int
= bp
->comp_prod_trip
;
2310 bp
->com_ticks_int
= bp
->com_ticks
;
2311 bp
->cmd_ticks_int
= bp
->cmd_ticks
;
2314 bp
->autoneg
= AUTONEG_SPEED
| AUTONEG_FLOW_CTRL
;
2315 bp
->req_line_speed
= 0;
2316 if (bp
->phy_flags
& PHY_SERDES_FLAG
) {
2317 bp
->advertising
= ETHTOOL_ALL_FIBRE_SPEED
| ADVERTISED_Autoneg
;
2319 reg
= REG_RD_IND(bp
, bp
->shmem_base
+ BNX2_PORT_HW_CFG_CONFIG
);
2320 reg
&= BNX2_PORT_HW_CFG_CFG_DFLT_LINK_MASK
;
2321 if (reg
== BNX2_PORT_HW_CFG_CFG_DFLT_LINK_1G
) {
2323 bp
->req_line_speed
= bp
->line_speed
= SPEED_1000
;
2324 bp
->req_duplex
= DUPLEX_FULL
;
2328 bp
->advertising
= ETHTOOL_ALL_COPPER_SPEED
| ADVERTISED_Autoneg
;
2331 bp
->req_flow_ctrl
= FLOW_CTRL_RX
| FLOW_CTRL_TX
;
2333 /* Disable driver heartbeat checking */
2334 REG_WR_IND(bp
, bp
->shmem_base
+ BNX2_DRV_PULSE_MB
,
2335 BNX2_DRV_MSG_DATA_PULSE_CODE_ALWAYS_ALIVE
);
2336 REG_RD_IND(bp
, bp
->shmem_base
+ BNX2_DRV_PULSE_MB
);
2347 bnx2_transmit(struct nic
*nic
, const char *dst_addr
,
2348 unsigned int type
, unsigned int size
, const char *packet
)
2350 /* Sometimes the nic will be behind by a frame. Using two transmit
2351 * buffers prevents us from timing out in that case.
2353 static struct eth_frame
{
2354 uint8_t dst_addr
[ETH_ALEN
];
2355 uint8_t src_addr
[ETH_ALEN
];
2357 uint8_t data
[ETH_FRAME_LEN
- ETH_HLEN
];
2359 static int frame_idx
= 0;
2361 /* send the packet to destination */
2363 struct bnx2
*bp
= &bnx2
;
2364 u16 prod
, ring_prod
;
2369 ring_prod
= TX_RING_IDX(prod
);
2370 hw_cons
= bp
->status_blk
->status_tx_quick_consumer_index0
;
2371 if ((hw_cons
& MAX_TX_DESC_CNT
) == MAX_TX_DESC_CNT
) {
2375 while((hw_cons
!= prod
) && (hw_cons
!= (PREV_TX_BD(prod
)))) {
2376 mdelay(10); /* give the nic a chance */
2377 //poll_interruptions();
2378 if (++i
> 500) { /* timeout 5s for transmit */
2379 printf("transmit timed out\n");
2380 bnx2_disable(bp
->nic
);
2381 bnx2_init_board(bp
->pdev
, bp
->nic
);
2389 /* Copy the packet to the our local buffer */
2390 memcpy(&frame
[frame_idx
].dst_addr
, dst_addr
, ETH_ALEN
);
2391 memcpy(&frame
[frame_idx
].src_addr
, nic
->node_addr
, ETH_ALEN
);
2392 frame
[frame_idx
].type
= htons(type
);
2393 memset(&frame
[frame_idx
].data
, 0, sizeof(frame
[frame_idx
].data
));
2394 memcpy(&frame
[frame_idx
].data
, packet
, size
);
2396 /* Setup the ring buffer entry to transmit */
2397 txbd
= &bp
->tx_desc_ring
[ring_prod
];
2398 txbd
->tx_bd_haddr_hi
= 0; /* Etherboot runs under 4GB */
2399 txbd
->tx_bd_haddr_lo
= virt_to_bus(&frame
[frame_idx
]);
2400 txbd
->tx_bd_mss_nbytes
= (size
+ ETH_HLEN
);
2401 txbd
->tx_bd_vlan_tag_flags
= TX_BD_FLAGS_START
| TX_BD_FLAGS_END
;
2403 /* Advance to the next entry */
2404 prod
= NEXT_TX_BD(prod
);
2407 bp
->tx_prod_bseq
+= (size
+ ETH_HLEN
);
2409 REG_WR16(bp
, MB_TX_CID_ADDR
+ BNX2_L2CTX_TX_HOST_BIDX
, prod
);
2410 REG_WR(bp
, MB_TX_CID_ADDR
+ BNX2_L2CTX_TX_HOST_BSEQ
, bp
->tx_prod_bseq
);
2418 bnx2_poll_link(struct bnx2
*bp
)
2420 u32 new_link_state
, old_link_state
, emac_status
;
2422 new_link_state
= bp
->status_blk
->status_attn_bits
&
2423 STATUS_ATTN_BITS_LINK_STATE
;
2425 old_link_state
= bp
->status_blk
->status_attn_bits_ack
&
2426 STATUS_ATTN_BITS_LINK_STATE
;
2428 if (!new_link_state
&& !old_link_state
) {
2429 /* For some reason the card doesn't always update the link
2430 * status bits properly. Kick the stupid thing and try again.
2434 bnx2_read_phy(bp
, MII_BMSR
, &bmsr
);
2435 bnx2_read_phy(bp
, MII_BMSR
, &bmsr
);
2437 if ((bp
->phy_flags
& PHY_SERDES_FLAG
) &&
2438 (CHIP_NUM(bp
) == CHIP_NUM_5706
)) {
2439 REG_RD(bp
, BNX2_EMAC_STATUS
);
2442 new_link_state
= bp
->status_blk
->status_attn_bits
&
2443 STATUS_ATTN_BITS_LINK_STATE
;
2445 old_link_state
= bp
->status_blk
->status_attn_bits_ack
&
2446 STATUS_ATTN_BITS_LINK_STATE
;
2448 /* Okay, for some reason the above doesn't work with some
2449 * switches (like HP ProCurve). If the above doesn't work,
2450 * check the MAC directly to see if we have a link. Perhaps we
2451 * should always check the MAC instead probing the MII.
2453 if (!new_link_state
&& !old_link_state
) {
2454 emac_status
= REG_RD(bp
, BNX2_EMAC_STATUS
);
2455 if (emac_status
& BNX2_EMAC_STATUS_LINK_CHANGE
) {
2456 /* Acknowledge the link change */
2457 REG_WR(bp
, BNX2_EMAC_STATUS
, BNX2_EMAC_STATUS_LINK_CHANGE
);
2458 } else if (emac_status
& BNX2_EMAC_STATUS_LINK
) {
2459 new_link_state
= !old_link_state
;
2465 if (new_link_state
!= old_link_state
) {
2466 if (new_link_state
) {
2467 REG_WR(bp
, BNX2_PCICFG_STATUS_BIT_SET_CMD
,
2468 STATUS_ATTN_BITS_LINK_STATE
);
2471 REG_WR(bp
, BNX2_PCICFG_STATUS_BIT_CLEAR_CMD
,
2472 STATUS_ATTN_BITS_LINK_STATE
);
2477 /* This is needed to take care of transient status
2478 * during link changes.
2481 REG_WR(bp
, BNX2_HC_COMMAND
,
2482 bp
->hc_cmd
| BNX2_HC_COMMAND_COAL_NOW_WO_INT
);
2483 REG_RD(bp
, BNX2_HC_COMMAND
);
2491 bnx2_poll(struct nic
* nic
, int retrieve
)
2493 struct bnx2
*bp
= &bnx2
;
2494 struct rx_bd
*cons_bd
, *prod_bd
;
2495 u16 hw_cons
, sw_cons
, sw_ring_cons
, sw_prod
, sw_ring_prod
;
2496 struct l2_fhdr
*rx_hdr
;
2499 unsigned char *data
;
2503 if ((bp
->status_blk
->status_idx
== bp
->last_status_idx
) &&
2504 (REG_RD(bp
, BNX2_PCICFG_MISC_STATUS
) &
2505 BNX2_PCICFG_MISC_STATUS_INTA_VALUE
)) {
2507 bp
->last_status_idx
= bp
->status_blk
->status_idx
;
2508 REG_WR(bp
, BNX2_PCICFG_INT_ACK_CMD
,
2509 BNX2_PCICFG_INT_ACK_CMD_INDEX_VALID
|
2510 BNX2_PCICFG_INT_ACK_CMD_MASK_INT
|
2511 bp
->last_status_idx
);
2516 if ((bp
->status_blk
->status_rx_quick_consumer_index0
!= bp
->rx_cons
) && !retrieve
)
2519 if (bp
->status_blk
->status_rx_quick_consumer_index0
!= bp
->rx_cons
) {
2521 hw_cons
= bp
->hw_rx_cons
= bp
->status_blk
->status_rx_quick_consumer_index0
;
2522 if ((hw_cons
& MAX_RX_DESC_CNT
) == MAX_RX_DESC_CNT
) {
2525 sw_cons
= bp
->rx_cons
;
2526 sw_prod
= bp
->rx_prod
;
2529 if (sw_cons
!= hw_cons
) {
2531 sw_ring_cons
= RX_RING_IDX(sw_cons
);
2532 sw_ring_prod
= RX_RING_IDX(sw_prod
);
2534 data
= bus_to_virt(bp
->rx_desc_ring
[sw_ring_cons
].rx_bd_haddr_lo
);
2536 rx_hdr
= (struct l2_fhdr
*)data
;
2537 len
= rx_hdr
->l2_fhdr_pkt_len
- 4;
2538 if ((len
> (ETH_MAX_MTU
+ ETH_HLEN
)) ||
2539 ((status
= rx_hdr
->l2_fhdr_status
) &
2540 (L2_FHDR_ERRORS_BAD_CRC
|
2541 L2_FHDR_ERRORS_PHY_DECODE
|
2542 L2_FHDR_ERRORS_ALIGNMENT
|
2543 L2_FHDR_ERRORS_TOO_SHORT
|
2544 L2_FHDR_ERRORS_GIANT_FRAME
))) {
2549 nic
->packetlen
= len
;
2550 memcpy(nic
->packet
, data
+ bp
->rx_offset
, len
);
2554 /* Reuse the buffer */
2555 bp
->rx_prod_bseq
+= bp
->rx_buf_use_size
;
2556 if (sw_cons
!= sw_prod
) {
2557 cons_bd
= &bp
->rx_desc_ring
[sw_ring_cons
];
2558 prod_bd
= &bp
->rx_desc_ring
[sw_ring_prod
];
2559 prod_bd
->rx_bd_haddr_hi
= 0; /* Etherboot runs under 4GB */
2560 prod_bd
->rx_bd_haddr_lo
= cons_bd
->rx_bd_haddr_lo
;
2563 sw_cons
= NEXT_RX_BD(sw_cons
);
2564 sw_prod
= NEXT_RX_BD(sw_prod
);
2568 bp
->rx_cons
= sw_cons
;
2569 bp
->rx_prod
= sw_prod
;
2571 REG_WR16(bp
, MB_RX_CID_ADDR
+ BNX2_L2CTX_HOST_BDIDX
, bp
->rx_prod
);
2573 REG_WR(bp
, MB_RX_CID_ADDR
+ BNX2_L2CTX_HOST_BSEQ
, bp
->rx_prod_bseq
);
2582 bp
->last_status_idx
= bp
->status_blk
->status_idx
;
2585 REG_WR(bp
, BNX2_PCICFG_INT_ACK_CMD
,
2586 BNX2_PCICFG_INT_ACK_CMD_INDEX_VALID
|
2587 BNX2_PCICFG_INT_ACK_CMD_MASK_INT
|
2588 bp
->last_status_idx
);
2590 REG_WR(bp
, BNX2_HC_COMMAND
, bp
->hc_cmd
| BNX2_HC_COMMAND_COAL_NOW_WO_INT
);
2597 bnx2_irq(struct nic
*nic __unused
, irq_action_t action __unused
)
2600 case DISABLE
: break;
2606 static struct nic_operations bnx2_operations
= {
2607 .connect
= dummy_connect
,
2609 .transmit
= bnx2_transmit
,
2614 bnx2_probe(struct nic
*nic
, struct pci_device
*pdev
)
2616 struct bnx2
*bp
= &bnx2
;
2622 memset(bp
, 0, sizeof(*bp
));
2624 rc
= bnx2_init_board(pdev
, nic
);
2630 nic->disable = bnx2_disable;
2631 nic->transmit = bnx2_transmit;
2632 nic->poll = bnx2_poll;
2633 nic->irq = bnx2_irq;
2636 nic
->nic_op
= &bnx2_operations
;
2638 memcpy(nic
->node_addr
, bp
->mac_addr
, ETH_ALEN
);
2639 printf("Ethernet addr: %s\n", eth_ntoa( nic
->node_addr
) );
2640 printf("Broadcom NetXtreme II (%c%d) PCI%s %s %dMHz\n",
2641 (int) ((CHIP_ID(bp
) & 0xf000) >> 12) + 'A',
2642 (int) ((CHIP_ID(bp
) & 0x0ff0) >> 4),
2643 ((bp
->flags
& PCIX_FLAG
) ? "-X" : ""),
2644 ((bp
->flags
& PCI_32BIT_FLAG
) ? "32-bit" : "64-bit"),
2647 bnx2_set_power_state_0(bp
);
2648 bnx2_disable_int(bp
);
2652 rc
= bnx2_init_nic(bp
);
2658 for(i
= 0; !bp
->link_up
&& (i
< VALID_LINK_TIMEOUT
*100); i
++) {
2664 printf("Valid link not established\n");
2665 goto err_out_disable
;
2676 static struct pci_device_id bnx2_nics
[] = {
2677 PCI_ROM(0x14e4, 0x164a, "bnx2-5706", "Broadcom NetXtreme II BCM5706"),
2678 PCI_ROM(0x14e4, 0x164c, "bnx2-5708", "Broadcom NetXtreme II BCM5708"),
2679 PCI_ROM(0x14e4, 0x16aa, "bnx2-5706S", "Broadcom NetXtreme II BCM5706S"),
2680 PCI_ROM(0x14e4, 0x16ac, "bnx2-5708S", "Broadcom NetXtreme II BCM5708S"),
2683 PCI_DRIVER ( bnx2_driver
, bnx2_nics
, PCI_NO_CLASS
);
2685 DRIVER ( "BNX2", nic_driver
, pci_driver
, bnx2_driver
, bnx2_probe
, bnx2_disable
);
2688 static struct pci_driver bnx2_driver __pci_driver = {
2691 .probe = bnx2_probe,
2693 .id_count = sizeof(bnx2_nics)/sizeof(bnx2_nics[0]),