1 /* bnx2.c: QLogic bnx2 network driver.
3 * Copyright (c) 2004-2014 Broadcom Corporation
4 * Copyright (c) 2014-2015 QLogic Corporation
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation.
10 * Written by: Michael Chan (mchan@broadcom.com)
13 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
15 #include <linux/module.h>
16 #include <linux/moduleparam.h>
18 #include <linux/stringify.h>
19 #include <linux/kernel.h>
20 #include <linux/timer.h>
21 #include <linux/errno.h>
22 #include <linux/ioport.h>
23 #include <linux/slab.h>
24 #include <linux/vmalloc.h>
25 #include <linux/interrupt.h>
26 #include <linux/pci.h>
27 #include <linux/netdevice.h>
28 #include <linux/etherdevice.h>
29 #include <linux/skbuff.h>
30 #include <linux/dma-mapping.h>
31 #include <linux/bitops.h>
34 #include <linux/delay.h>
35 #include <asm/byteorder.h>
37 #include <linux/time.h>
38 #include <linux/ethtool.h>
39 #include <linux/mii.h>
41 #include <linux/if_vlan.h>
44 #include <net/checksum.h>
45 #include <linux/workqueue.h>
46 #include <linux/crc32.h>
47 #include <linux/prefetch.h>
48 #include <linux/cache.h>
49 #include <linux/firmware.h>
50 #include <linux/log2.h>
51 #include <linux/aer.h>
52 #include <linux/crash_dump.h>
54 #if IS_ENABLED(CONFIG_CNIC)
61 #define DRV_MODULE_NAME "bnx2"
62 #define DRV_MODULE_VERSION "2.2.6"
63 #define DRV_MODULE_RELDATE "January 29, 2014"
64 #define FW_MIPS_FILE_06 "bnx2/bnx2-mips-06-6.2.3.fw"
65 #define FW_RV2P_FILE_06 "bnx2/bnx2-rv2p-06-6.0.15.fw"
66 #define FW_MIPS_FILE_09 "bnx2/bnx2-mips-09-6.2.1b.fw"
67 #define FW_RV2P_FILE_09_Ax "bnx2/bnx2-rv2p-09ax-6.0.17.fw"
68 #define FW_RV2P_FILE_09 "bnx2/bnx2-rv2p-09-6.0.17.fw"
70 #define RUN_AT(x) (jiffies + (x))
72 /* Time in jiffies before concluding the transmitter is hung. */
73 #define TX_TIMEOUT (5*HZ)
75 static char version
[] =
76 "QLogic " DRV_MODULE_NAME
" Gigabit Ethernet Driver v" DRV_MODULE_VERSION
" (" DRV_MODULE_RELDATE
")\n";
78 MODULE_AUTHOR("Michael Chan <mchan@broadcom.com>");
79 MODULE_DESCRIPTION("QLogic BCM5706/5708/5709/5716 Driver");
80 MODULE_LICENSE("GPL");
81 MODULE_VERSION(DRV_MODULE_VERSION
);
82 MODULE_FIRMWARE(FW_MIPS_FILE_06
);
83 MODULE_FIRMWARE(FW_RV2P_FILE_06
);
84 MODULE_FIRMWARE(FW_MIPS_FILE_09
);
85 MODULE_FIRMWARE(FW_RV2P_FILE_09
);
86 MODULE_FIRMWARE(FW_RV2P_FILE_09_Ax
);
88 static int disable_msi
= 0;
90 module_param(disable_msi
, int, S_IRUGO
);
91 MODULE_PARM_DESC(disable_msi
, "Disable Message Signaled Interrupt (MSI)");
107 /* indexed by board_t, above */
111 { "Broadcom NetXtreme II BCM5706 1000Base-T" },
112 { "HP NC370T Multifunction Gigabit Server Adapter" },
113 { "HP NC370i Multifunction Gigabit Server Adapter" },
114 { "Broadcom NetXtreme II BCM5706 1000Base-SX" },
115 { "HP NC370F Multifunction Gigabit Server Adapter" },
116 { "Broadcom NetXtreme II BCM5708 1000Base-T" },
117 { "Broadcom NetXtreme II BCM5708 1000Base-SX" },
118 { "Broadcom NetXtreme II BCM5709 1000Base-T" },
119 { "Broadcom NetXtreme II BCM5709 1000Base-SX" },
120 { "Broadcom NetXtreme II BCM5716 1000Base-T" },
121 { "Broadcom NetXtreme II BCM5716 1000Base-SX" },
124 static const struct pci_device_id bnx2_pci_tbl
[] = {
125 { PCI_VENDOR_ID_BROADCOM
, PCI_DEVICE_ID_NX2_5706
,
126 PCI_VENDOR_ID_HP
, 0x3101, 0, 0, NC370T
},
127 { PCI_VENDOR_ID_BROADCOM
, PCI_DEVICE_ID_NX2_5706
,
128 PCI_VENDOR_ID_HP
, 0x3106, 0, 0, NC370I
},
129 { PCI_VENDOR_ID_BROADCOM
, PCI_DEVICE_ID_NX2_5706
,
130 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, BCM5706
},
131 { PCI_VENDOR_ID_BROADCOM
, PCI_DEVICE_ID_NX2_5708
,
132 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, BCM5708
},
133 { PCI_VENDOR_ID_BROADCOM
, PCI_DEVICE_ID_NX2_5706S
,
134 PCI_VENDOR_ID_HP
, 0x3102, 0, 0, NC370F
},
135 { PCI_VENDOR_ID_BROADCOM
, PCI_DEVICE_ID_NX2_5706S
,
136 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, BCM5706S
},
137 { PCI_VENDOR_ID_BROADCOM
, PCI_DEVICE_ID_NX2_5708S
,
138 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, BCM5708S
},
139 { PCI_VENDOR_ID_BROADCOM
, PCI_DEVICE_ID_NX2_5709
,
140 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, BCM5709
},
141 { PCI_VENDOR_ID_BROADCOM
, PCI_DEVICE_ID_NX2_5709S
,
142 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, BCM5709S
},
143 { PCI_VENDOR_ID_BROADCOM
, 0x163b,
144 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, BCM5716
},
145 { PCI_VENDOR_ID_BROADCOM
, 0x163c,
146 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, BCM5716S
},
150 static const struct flash_spec flash_table
[] =
152 #define BUFFERED_FLAGS (BNX2_NV_BUFFERED | BNX2_NV_TRANSLATE)
153 #define NONBUFFERED_FLAGS (BNX2_NV_WREN)
155 {0x00000000, 0x40830380, 0x009f0081, 0xa184a053, 0xaf000400,
156 BUFFERED_FLAGS
, SEEPROM_PAGE_BITS
, SEEPROM_PAGE_SIZE
,
157 SEEPROM_BYTE_ADDR_MASK
, SEEPROM_TOTAL_SIZE
,
159 /* Expansion entry 0001 */
160 {0x08000002, 0x4b808201, 0x00050081, 0x03840253, 0xaf020406,
161 NONBUFFERED_FLAGS
, SAIFUN_FLASH_PAGE_BITS
, SAIFUN_FLASH_PAGE_SIZE
,
162 SAIFUN_FLASH_BYTE_ADDR_MASK
, 0,
164 /* Saifun SA25F010 (non-buffered flash) */
165 /* strap, cfg1, & write1 need updates */
166 {0x04000001, 0x47808201, 0x00050081, 0x03840253, 0xaf020406,
167 NONBUFFERED_FLAGS
, SAIFUN_FLASH_PAGE_BITS
, SAIFUN_FLASH_PAGE_SIZE
,
168 SAIFUN_FLASH_BYTE_ADDR_MASK
, SAIFUN_FLASH_BASE_TOTAL_SIZE
*2,
169 "Non-buffered flash (128kB)"},
170 /* Saifun SA25F020 (non-buffered flash) */
171 /* strap, cfg1, & write1 need updates */
172 {0x0c000003, 0x4f808201, 0x00050081, 0x03840253, 0xaf020406,
173 NONBUFFERED_FLAGS
, SAIFUN_FLASH_PAGE_BITS
, SAIFUN_FLASH_PAGE_SIZE
,
174 SAIFUN_FLASH_BYTE_ADDR_MASK
, SAIFUN_FLASH_BASE_TOTAL_SIZE
*4,
175 "Non-buffered flash (256kB)"},
176 /* Expansion entry 0100 */
177 {0x11000000, 0x53808201, 0x00050081, 0x03840253, 0xaf020406,
178 NONBUFFERED_FLAGS
, SAIFUN_FLASH_PAGE_BITS
, SAIFUN_FLASH_PAGE_SIZE
,
179 SAIFUN_FLASH_BYTE_ADDR_MASK
, 0,
181 /* Entry 0101: ST M45PE10 (non-buffered flash, TetonII B0) */
182 {0x19000002, 0x5b808201, 0x000500db, 0x03840253, 0xaf020406,
183 NONBUFFERED_FLAGS
, ST_MICRO_FLASH_PAGE_BITS
, ST_MICRO_FLASH_PAGE_SIZE
,
184 ST_MICRO_FLASH_BYTE_ADDR_MASK
, ST_MICRO_FLASH_BASE_TOTAL_SIZE
*2,
185 "Entry 0101: ST M45PE10 (128kB non-bufferred)"},
186 /* Entry 0110: ST M45PE20 (non-buffered flash)*/
187 {0x15000001, 0x57808201, 0x000500db, 0x03840253, 0xaf020406,
188 NONBUFFERED_FLAGS
, ST_MICRO_FLASH_PAGE_BITS
, ST_MICRO_FLASH_PAGE_SIZE
,
189 ST_MICRO_FLASH_BYTE_ADDR_MASK
, ST_MICRO_FLASH_BASE_TOTAL_SIZE
*4,
190 "Entry 0110: ST M45PE20 (256kB non-bufferred)"},
191 /* Saifun SA25F005 (non-buffered flash) */
192 /* strap, cfg1, & write1 need updates */
193 {0x1d000003, 0x5f808201, 0x00050081, 0x03840253, 0xaf020406,
194 NONBUFFERED_FLAGS
, SAIFUN_FLASH_PAGE_BITS
, SAIFUN_FLASH_PAGE_SIZE
,
195 SAIFUN_FLASH_BYTE_ADDR_MASK
, SAIFUN_FLASH_BASE_TOTAL_SIZE
,
196 "Non-buffered flash (64kB)"},
198 {0x22000000, 0x62808380, 0x009f0081, 0xa184a053, 0xaf000400,
199 BUFFERED_FLAGS
, SEEPROM_PAGE_BITS
, SEEPROM_PAGE_SIZE
,
200 SEEPROM_BYTE_ADDR_MASK
, SEEPROM_TOTAL_SIZE
,
202 /* Expansion entry 1001 */
203 {0x2a000002, 0x6b808201, 0x00050081, 0x03840253, 0xaf020406,
204 NONBUFFERED_FLAGS
, SAIFUN_FLASH_PAGE_BITS
, SAIFUN_FLASH_PAGE_SIZE
,
205 SAIFUN_FLASH_BYTE_ADDR_MASK
, 0,
207 /* Expansion entry 1010 */
208 {0x26000001, 0x67808201, 0x00050081, 0x03840253, 0xaf020406,
209 NONBUFFERED_FLAGS
, SAIFUN_FLASH_PAGE_BITS
, SAIFUN_FLASH_PAGE_SIZE
,
210 SAIFUN_FLASH_BYTE_ADDR_MASK
, 0,
212 /* ATMEL AT45DB011B (buffered flash) */
213 {0x2e000003, 0x6e808273, 0x00570081, 0x68848353, 0xaf000400,
214 BUFFERED_FLAGS
, BUFFERED_FLASH_PAGE_BITS
, BUFFERED_FLASH_PAGE_SIZE
,
215 BUFFERED_FLASH_BYTE_ADDR_MASK
, BUFFERED_FLASH_TOTAL_SIZE
,
216 "Buffered flash (128kB)"},
217 /* Expansion entry 1100 */
218 {0x33000000, 0x73808201, 0x00050081, 0x03840253, 0xaf020406,
219 NONBUFFERED_FLAGS
, SAIFUN_FLASH_PAGE_BITS
, SAIFUN_FLASH_PAGE_SIZE
,
220 SAIFUN_FLASH_BYTE_ADDR_MASK
, 0,
222 /* Expansion entry 1101 */
223 {0x3b000002, 0x7b808201, 0x00050081, 0x03840253, 0xaf020406,
224 NONBUFFERED_FLAGS
, SAIFUN_FLASH_PAGE_BITS
, SAIFUN_FLASH_PAGE_SIZE
,
225 SAIFUN_FLASH_BYTE_ADDR_MASK
, 0,
227 /* Ateml Expansion entry 1110 */
228 {0x37000001, 0x76808273, 0x00570081, 0x68848353, 0xaf000400,
229 BUFFERED_FLAGS
, BUFFERED_FLASH_PAGE_BITS
, BUFFERED_FLASH_PAGE_SIZE
,
230 BUFFERED_FLASH_BYTE_ADDR_MASK
, 0,
231 "Entry 1110 (Atmel)"},
232 /* ATMEL AT45DB021B (buffered flash) */
233 {0x3f000003, 0x7e808273, 0x00570081, 0x68848353, 0xaf000400,
234 BUFFERED_FLAGS
, BUFFERED_FLASH_PAGE_BITS
, BUFFERED_FLASH_PAGE_SIZE
,
235 BUFFERED_FLASH_BYTE_ADDR_MASK
, BUFFERED_FLASH_TOTAL_SIZE
*2,
236 "Buffered flash (256kB)"},
239 static const struct flash_spec flash_5709
= {
240 .flags
= BNX2_NV_BUFFERED
,
241 .page_bits
= BCM5709_FLASH_PAGE_BITS
,
242 .page_size
= BCM5709_FLASH_PAGE_SIZE
,
243 .addr_mask
= BCM5709_FLASH_BYTE_ADDR_MASK
,
244 .total_size
= BUFFERED_FLASH_TOTAL_SIZE
*2,
245 .name
= "5709 Buffered flash (256kB)",
248 MODULE_DEVICE_TABLE(pci
, bnx2_pci_tbl
);
250 static void bnx2_init_napi(struct bnx2
*bp
);
251 static void bnx2_del_napi(struct bnx2
*bp
);
253 static inline u32
bnx2_tx_avail(struct bnx2
*bp
, struct bnx2_tx_ring_info
*txr
)
257 /* Tell compiler to fetch tx_prod and tx_cons from memory. */
260 /* The ring uses 256 indices for 255 entries, one of them
261 * needs to be skipped.
263 diff
= txr
->tx_prod
- txr
->tx_cons
;
264 if (unlikely(diff
>= BNX2_TX_DESC_CNT
)) {
266 if (diff
== BNX2_TX_DESC_CNT
)
267 diff
= BNX2_MAX_TX_DESC_CNT
;
269 return bp
->tx_ring_size
- diff
;
273 bnx2_reg_rd_ind(struct bnx2
*bp
, u32 offset
)
278 spin_lock_irqsave(&bp
->indirect_lock
, flags
);
279 BNX2_WR(bp
, BNX2_PCICFG_REG_WINDOW_ADDRESS
, offset
);
280 val
= BNX2_RD(bp
, BNX2_PCICFG_REG_WINDOW
);
281 spin_unlock_irqrestore(&bp
->indirect_lock
, flags
);
286 bnx2_reg_wr_ind(struct bnx2
*bp
, u32 offset
, u32 val
)
290 spin_lock_irqsave(&bp
->indirect_lock
, flags
);
291 BNX2_WR(bp
, BNX2_PCICFG_REG_WINDOW_ADDRESS
, offset
);
292 BNX2_WR(bp
, BNX2_PCICFG_REG_WINDOW
, val
);
293 spin_unlock_irqrestore(&bp
->indirect_lock
, flags
);
297 bnx2_shmem_wr(struct bnx2
*bp
, u32 offset
, u32 val
)
299 bnx2_reg_wr_ind(bp
, bp
->shmem_base
+ offset
, val
);
303 bnx2_shmem_rd(struct bnx2
*bp
, u32 offset
)
305 return bnx2_reg_rd_ind(bp
, bp
->shmem_base
+ offset
);
309 bnx2_ctx_wr(struct bnx2
*bp
, u32 cid_addr
, u32 offset
, u32 val
)
314 spin_lock_irqsave(&bp
->indirect_lock
, flags
);
315 if (BNX2_CHIP(bp
) == BNX2_CHIP_5709
) {
318 BNX2_WR(bp
, BNX2_CTX_CTX_DATA
, val
);
319 BNX2_WR(bp
, BNX2_CTX_CTX_CTRL
,
320 offset
| BNX2_CTX_CTX_CTRL_WRITE_REQ
);
321 for (i
= 0; i
< 5; i
++) {
322 val
= BNX2_RD(bp
, BNX2_CTX_CTX_CTRL
);
323 if ((val
& BNX2_CTX_CTX_CTRL_WRITE_REQ
) == 0)
328 BNX2_WR(bp
, BNX2_CTX_DATA_ADR
, offset
);
329 BNX2_WR(bp
, BNX2_CTX_DATA
, val
);
331 spin_unlock_irqrestore(&bp
->indirect_lock
, flags
);
336 bnx2_drv_ctl(struct net_device
*dev
, struct drv_ctl_info
*info
)
338 struct bnx2
*bp
= netdev_priv(dev
);
339 struct drv_ctl_io
*io
= &info
->data
.io
;
342 case DRV_CTL_IO_WR_CMD
:
343 bnx2_reg_wr_ind(bp
, io
->offset
, io
->data
);
345 case DRV_CTL_IO_RD_CMD
:
346 io
->data
= bnx2_reg_rd_ind(bp
, io
->offset
);
348 case DRV_CTL_CTX_WR_CMD
:
349 bnx2_ctx_wr(bp
, io
->cid_addr
, io
->offset
, io
->data
);
357 static void bnx2_setup_cnic_irq_info(struct bnx2
*bp
)
359 struct cnic_eth_dev
*cp
= &bp
->cnic_eth_dev
;
360 struct bnx2_napi
*bnapi
= &bp
->bnx2_napi
[0];
363 if (bp
->flags
& BNX2_FLAG_USING_MSIX
) {
364 cp
->drv_state
|= CNIC_DRV_STATE_USING_MSIX
;
365 bnapi
->cnic_present
= 0;
366 sb_id
= bp
->irq_nvecs
;
367 cp
->irq_arr
[0].irq_flags
|= CNIC_IRQ_FL_MSIX
;
369 cp
->drv_state
&= ~CNIC_DRV_STATE_USING_MSIX
;
370 bnapi
->cnic_tag
= bnapi
->last_status_idx
;
371 bnapi
->cnic_present
= 1;
373 cp
->irq_arr
[0].irq_flags
&= ~CNIC_IRQ_FL_MSIX
;
376 cp
->irq_arr
[0].vector
= bp
->irq_tbl
[sb_id
].vector
;
377 cp
->irq_arr
[0].status_blk
= (void *)
378 ((unsigned long) bnapi
->status_blk
.msi
+
379 (BNX2_SBLK_MSIX_ALIGN_SIZE
* sb_id
));
380 cp
->irq_arr
[0].status_blk_num
= sb_id
;
384 static int bnx2_register_cnic(struct net_device
*dev
, struct cnic_ops
*ops
,
387 struct bnx2
*bp
= netdev_priv(dev
);
388 struct cnic_eth_dev
*cp
= &bp
->cnic_eth_dev
;
393 if (cp
->drv_state
& CNIC_DRV_STATE_REGD
)
396 if (!bnx2_reg_rd_ind(bp
, BNX2_FW_MAX_ISCSI_CONN
))
399 bp
->cnic_data
= data
;
400 rcu_assign_pointer(bp
->cnic_ops
, ops
);
403 cp
->drv_state
= CNIC_DRV_STATE_REGD
;
405 bnx2_setup_cnic_irq_info(bp
);
410 static int bnx2_unregister_cnic(struct net_device
*dev
)
412 struct bnx2
*bp
= netdev_priv(dev
);
413 struct bnx2_napi
*bnapi
= &bp
->bnx2_napi
[0];
414 struct cnic_eth_dev
*cp
= &bp
->cnic_eth_dev
;
416 mutex_lock(&bp
->cnic_lock
);
418 bnapi
->cnic_present
= 0;
419 RCU_INIT_POINTER(bp
->cnic_ops
, NULL
);
420 mutex_unlock(&bp
->cnic_lock
);
425 static struct cnic_eth_dev
*bnx2_cnic_probe(struct net_device
*dev
)
427 struct bnx2
*bp
= netdev_priv(dev
);
428 struct cnic_eth_dev
*cp
= &bp
->cnic_eth_dev
;
430 if (!cp
->max_iscsi_conn
)
433 cp
->drv_owner
= THIS_MODULE
;
434 cp
->chip_id
= bp
->chip_id
;
436 cp
->io_base
= bp
->regview
;
437 cp
->drv_ctl
= bnx2_drv_ctl
;
438 cp
->drv_register_cnic
= bnx2_register_cnic
;
439 cp
->drv_unregister_cnic
= bnx2_unregister_cnic
;
445 bnx2_cnic_stop(struct bnx2
*bp
)
447 struct cnic_ops
*c_ops
;
448 struct cnic_ctl_info info
;
450 mutex_lock(&bp
->cnic_lock
);
451 c_ops
= rcu_dereference_protected(bp
->cnic_ops
,
452 lockdep_is_held(&bp
->cnic_lock
));
454 info
.cmd
= CNIC_CTL_STOP_CMD
;
455 c_ops
->cnic_ctl(bp
->cnic_data
, &info
);
457 mutex_unlock(&bp
->cnic_lock
);
461 bnx2_cnic_start(struct bnx2
*bp
)
463 struct cnic_ops
*c_ops
;
464 struct cnic_ctl_info info
;
466 mutex_lock(&bp
->cnic_lock
);
467 c_ops
= rcu_dereference_protected(bp
->cnic_ops
,
468 lockdep_is_held(&bp
->cnic_lock
));
470 if (!(bp
->flags
& BNX2_FLAG_USING_MSIX
)) {
471 struct bnx2_napi
*bnapi
= &bp
->bnx2_napi
[0];
473 bnapi
->cnic_tag
= bnapi
->last_status_idx
;
475 info
.cmd
= CNIC_CTL_START_CMD
;
476 c_ops
->cnic_ctl(bp
->cnic_data
, &info
);
478 mutex_unlock(&bp
->cnic_lock
);
484 bnx2_cnic_stop(struct bnx2
*bp
)
489 bnx2_cnic_start(struct bnx2
*bp
)
496 bnx2_read_phy(struct bnx2
*bp
, u32 reg
, u32
*val
)
501 if (bp
->phy_flags
& BNX2_PHY_FLAG_INT_MODE_AUTO_POLLING
) {
502 val1
= BNX2_RD(bp
, BNX2_EMAC_MDIO_MODE
);
503 val1
&= ~BNX2_EMAC_MDIO_MODE_AUTO_POLL
;
505 BNX2_WR(bp
, BNX2_EMAC_MDIO_MODE
, val1
);
506 BNX2_RD(bp
, BNX2_EMAC_MDIO_MODE
);
511 val1
= (bp
->phy_addr
<< 21) | (reg
<< 16) |
512 BNX2_EMAC_MDIO_COMM_COMMAND_READ
| BNX2_EMAC_MDIO_COMM_DISEXT
|
513 BNX2_EMAC_MDIO_COMM_START_BUSY
;
514 BNX2_WR(bp
, BNX2_EMAC_MDIO_COMM
, val1
);
516 for (i
= 0; i
< 50; i
++) {
519 val1
= BNX2_RD(bp
, BNX2_EMAC_MDIO_COMM
);
520 if (!(val1
& BNX2_EMAC_MDIO_COMM_START_BUSY
)) {
523 val1
= BNX2_RD(bp
, BNX2_EMAC_MDIO_COMM
);
524 val1
&= BNX2_EMAC_MDIO_COMM_DATA
;
530 if (val1
& BNX2_EMAC_MDIO_COMM_START_BUSY
) {
539 if (bp
->phy_flags
& BNX2_PHY_FLAG_INT_MODE_AUTO_POLLING
) {
540 val1
= BNX2_RD(bp
, BNX2_EMAC_MDIO_MODE
);
541 val1
|= BNX2_EMAC_MDIO_MODE_AUTO_POLL
;
543 BNX2_WR(bp
, BNX2_EMAC_MDIO_MODE
, val1
);
544 BNX2_RD(bp
, BNX2_EMAC_MDIO_MODE
);
553 bnx2_write_phy(struct bnx2
*bp
, u32 reg
, u32 val
)
558 if (bp
->phy_flags
& BNX2_PHY_FLAG_INT_MODE_AUTO_POLLING
) {
559 val1
= BNX2_RD(bp
, BNX2_EMAC_MDIO_MODE
);
560 val1
&= ~BNX2_EMAC_MDIO_MODE_AUTO_POLL
;
562 BNX2_WR(bp
, BNX2_EMAC_MDIO_MODE
, val1
);
563 BNX2_RD(bp
, BNX2_EMAC_MDIO_MODE
);
568 val1
= (bp
->phy_addr
<< 21) | (reg
<< 16) | val
|
569 BNX2_EMAC_MDIO_COMM_COMMAND_WRITE
|
570 BNX2_EMAC_MDIO_COMM_START_BUSY
| BNX2_EMAC_MDIO_COMM_DISEXT
;
571 BNX2_WR(bp
, BNX2_EMAC_MDIO_COMM
, val1
);
573 for (i
= 0; i
< 50; i
++) {
576 val1
= BNX2_RD(bp
, BNX2_EMAC_MDIO_COMM
);
577 if (!(val1
& BNX2_EMAC_MDIO_COMM_START_BUSY
)) {
583 if (val1
& BNX2_EMAC_MDIO_COMM_START_BUSY
)
588 if (bp
->phy_flags
& BNX2_PHY_FLAG_INT_MODE_AUTO_POLLING
) {
589 val1
= BNX2_RD(bp
, BNX2_EMAC_MDIO_MODE
);
590 val1
|= BNX2_EMAC_MDIO_MODE_AUTO_POLL
;
592 BNX2_WR(bp
, BNX2_EMAC_MDIO_MODE
, val1
);
593 BNX2_RD(bp
, BNX2_EMAC_MDIO_MODE
);
602 bnx2_disable_int(struct bnx2
*bp
)
605 struct bnx2_napi
*bnapi
;
607 for (i
= 0; i
< bp
->irq_nvecs
; i
++) {
608 bnapi
= &bp
->bnx2_napi
[i
];
609 BNX2_WR(bp
, BNX2_PCICFG_INT_ACK_CMD
, bnapi
->int_num
|
610 BNX2_PCICFG_INT_ACK_CMD_MASK_INT
);
612 BNX2_RD(bp
, BNX2_PCICFG_INT_ACK_CMD
);
616 bnx2_enable_int(struct bnx2
*bp
)
619 struct bnx2_napi
*bnapi
;
621 for (i
= 0; i
< bp
->irq_nvecs
; i
++) {
622 bnapi
= &bp
->bnx2_napi
[i
];
624 BNX2_WR(bp
, BNX2_PCICFG_INT_ACK_CMD
, bnapi
->int_num
|
625 BNX2_PCICFG_INT_ACK_CMD_INDEX_VALID
|
626 BNX2_PCICFG_INT_ACK_CMD_MASK_INT
|
627 bnapi
->last_status_idx
);
629 BNX2_WR(bp
, BNX2_PCICFG_INT_ACK_CMD
, bnapi
->int_num
|
630 BNX2_PCICFG_INT_ACK_CMD_INDEX_VALID
|
631 bnapi
->last_status_idx
);
633 BNX2_WR(bp
, BNX2_HC_COMMAND
, bp
->hc_cmd
| BNX2_HC_COMMAND_COAL_NOW
);
637 bnx2_disable_int_sync(struct bnx2
*bp
)
641 atomic_inc(&bp
->intr_sem
);
642 if (!netif_running(bp
->dev
))
645 bnx2_disable_int(bp
);
646 for (i
= 0; i
< bp
->irq_nvecs
; i
++)
647 synchronize_irq(bp
->irq_tbl
[i
].vector
);
651 bnx2_napi_disable(struct bnx2
*bp
)
655 for (i
= 0; i
< bp
->irq_nvecs
; i
++)
656 napi_disable(&bp
->bnx2_napi
[i
].napi
);
660 bnx2_napi_enable(struct bnx2
*bp
)
664 for (i
= 0; i
< bp
->irq_nvecs
; i
++)
665 napi_enable(&bp
->bnx2_napi
[i
].napi
);
669 bnx2_netif_stop(struct bnx2
*bp
, bool stop_cnic
)
673 if (netif_running(bp
->dev
)) {
674 bnx2_napi_disable(bp
);
675 netif_tx_disable(bp
->dev
);
677 bnx2_disable_int_sync(bp
);
678 netif_carrier_off(bp
->dev
); /* prevent tx timeout */
682 bnx2_netif_start(struct bnx2
*bp
, bool start_cnic
)
684 if (atomic_dec_and_test(&bp
->intr_sem
)) {
685 if (netif_running(bp
->dev
)) {
686 netif_tx_wake_all_queues(bp
->dev
);
687 spin_lock_bh(&bp
->phy_lock
);
689 netif_carrier_on(bp
->dev
);
690 spin_unlock_bh(&bp
->phy_lock
);
691 bnx2_napi_enable(bp
);
700 bnx2_free_tx_mem(struct bnx2
*bp
)
704 for (i
= 0; i
< bp
->num_tx_rings
; i
++) {
705 struct bnx2_napi
*bnapi
= &bp
->bnx2_napi
[i
];
706 struct bnx2_tx_ring_info
*txr
= &bnapi
->tx_ring
;
708 if (txr
->tx_desc_ring
) {
709 dma_free_coherent(&bp
->pdev
->dev
, TXBD_RING_SIZE
,
711 txr
->tx_desc_mapping
);
712 txr
->tx_desc_ring
= NULL
;
714 kfree(txr
->tx_buf_ring
);
715 txr
->tx_buf_ring
= NULL
;
720 bnx2_free_rx_mem(struct bnx2
*bp
)
724 for (i
= 0; i
< bp
->num_rx_rings
; i
++) {
725 struct bnx2_napi
*bnapi
= &bp
->bnx2_napi
[i
];
726 struct bnx2_rx_ring_info
*rxr
= &bnapi
->rx_ring
;
729 for (j
= 0; j
< bp
->rx_max_ring
; j
++) {
730 if (rxr
->rx_desc_ring
[j
])
731 dma_free_coherent(&bp
->pdev
->dev
, RXBD_RING_SIZE
,
732 rxr
->rx_desc_ring
[j
],
733 rxr
->rx_desc_mapping
[j
]);
734 rxr
->rx_desc_ring
[j
] = NULL
;
736 vfree(rxr
->rx_buf_ring
);
737 rxr
->rx_buf_ring
= NULL
;
739 for (j
= 0; j
< bp
->rx_max_pg_ring
; j
++) {
740 if (rxr
->rx_pg_desc_ring
[j
])
741 dma_free_coherent(&bp
->pdev
->dev
, RXBD_RING_SIZE
,
742 rxr
->rx_pg_desc_ring
[j
],
743 rxr
->rx_pg_desc_mapping
[j
]);
744 rxr
->rx_pg_desc_ring
[j
] = NULL
;
746 vfree(rxr
->rx_pg_ring
);
747 rxr
->rx_pg_ring
= NULL
;
752 bnx2_alloc_tx_mem(struct bnx2
*bp
)
756 for (i
= 0; i
< bp
->num_tx_rings
; i
++) {
757 struct bnx2_napi
*bnapi
= &bp
->bnx2_napi
[i
];
758 struct bnx2_tx_ring_info
*txr
= &bnapi
->tx_ring
;
760 txr
->tx_buf_ring
= kzalloc(SW_TXBD_RING_SIZE
, GFP_KERNEL
);
761 if (txr
->tx_buf_ring
== NULL
)
765 dma_alloc_coherent(&bp
->pdev
->dev
, TXBD_RING_SIZE
,
766 &txr
->tx_desc_mapping
, GFP_KERNEL
);
767 if (txr
->tx_desc_ring
== NULL
)
774 bnx2_alloc_rx_mem(struct bnx2
*bp
)
778 for (i
= 0; i
< bp
->num_rx_rings
; i
++) {
779 struct bnx2_napi
*bnapi
= &bp
->bnx2_napi
[i
];
780 struct bnx2_rx_ring_info
*rxr
= &bnapi
->rx_ring
;
784 vzalloc(SW_RXBD_RING_SIZE
* bp
->rx_max_ring
);
785 if (rxr
->rx_buf_ring
== NULL
)
788 for (j
= 0; j
< bp
->rx_max_ring
; j
++) {
789 rxr
->rx_desc_ring
[j
] =
790 dma_alloc_coherent(&bp
->pdev
->dev
,
792 &rxr
->rx_desc_mapping
[j
],
794 if (rxr
->rx_desc_ring
[j
] == NULL
)
799 if (bp
->rx_pg_ring_size
) {
800 rxr
->rx_pg_ring
= vzalloc(SW_RXPG_RING_SIZE
*
802 if (rxr
->rx_pg_ring
== NULL
)
807 for (j
= 0; j
< bp
->rx_max_pg_ring
; j
++) {
808 rxr
->rx_pg_desc_ring
[j
] =
809 dma_alloc_coherent(&bp
->pdev
->dev
,
811 &rxr
->rx_pg_desc_mapping
[j
],
813 if (rxr
->rx_pg_desc_ring
[j
] == NULL
)
822 bnx2_free_stats_blk(struct net_device
*dev
)
824 struct bnx2
*bp
= netdev_priv(dev
);
826 if (bp
->status_blk
) {
827 dma_free_coherent(&bp
->pdev
->dev
, bp
->status_stats_size
,
829 bp
->status_blk_mapping
);
830 bp
->status_blk
= NULL
;
831 bp
->stats_blk
= NULL
;
836 bnx2_alloc_stats_blk(struct net_device
*dev
)
840 struct bnx2
*bp
= netdev_priv(dev
);
842 /* Combine status and statistics blocks into one allocation. */
843 status_blk_size
= L1_CACHE_ALIGN(sizeof(struct status_block
));
844 if (bp
->flags
& BNX2_FLAG_MSIX_CAP
)
845 status_blk_size
= L1_CACHE_ALIGN(BNX2_MAX_MSIX_HW_VEC
*
846 BNX2_SBLK_MSIX_ALIGN_SIZE
);
847 bp
->status_stats_size
= status_blk_size
+
848 sizeof(struct statistics_block
);
849 status_blk
= dma_zalloc_coherent(&bp
->pdev
->dev
, bp
->status_stats_size
,
850 &bp
->status_blk_mapping
, GFP_KERNEL
);
851 if (status_blk
== NULL
)
854 bp
->status_blk
= status_blk
;
855 bp
->stats_blk
= status_blk
+ status_blk_size
;
856 bp
->stats_blk_mapping
= bp
->status_blk_mapping
+ status_blk_size
;
862 bnx2_free_mem(struct bnx2
*bp
)
865 struct bnx2_napi
*bnapi
= &bp
->bnx2_napi
[0];
867 bnx2_free_tx_mem(bp
);
868 bnx2_free_rx_mem(bp
);
870 for (i
= 0; i
< bp
->ctx_pages
; i
++) {
871 if (bp
->ctx_blk
[i
]) {
872 dma_free_coherent(&bp
->pdev
->dev
, BNX2_PAGE_SIZE
,
874 bp
->ctx_blk_mapping
[i
]);
875 bp
->ctx_blk
[i
] = NULL
;
879 if (bnapi
->status_blk
.msi
)
880 bnapi
->status_blk
.msi
= NULL
;
884 bnx2_alloc_mem(struct bnx2
*bp
)
887 struct bnx2_napi
*bnapi
;
889 bnapi
= &bp
->bnx2_napi
[0];
890 bnapi
->status_blk
.msi
= bp
->status_blk
;
891 bnapi
->hw_tx_cons_ptr
=
892 &bnapi
->status_blk
.msi
->status_tx_quick_consumer_index0
;
893 bnapi
->hw_rx_cons_ptr
=
894 &bnapi
->status_blk
.msi
->status_rx_quick_consumer_index0
;
895 if (bp
->flags
& BNX2_FLAG_MSIX_CAP
) {
896 for (i
= 1; i
< bp
->irq_nvecs
; i
++) {
897 struct status_block_msix
*sblk
;
899 bnapi
= &bp
->bnx2_napi
[i
];
901 sblk
= (bp
->status_blk
+ BNX2_SBLK_MSIX_ALIGN_SIZE
* i
);
902 bnapi
->status_blk
.msix
= sblk
;
903 bnapi
->hw_tx_cons_ptr
=
904 &sblk
->status_tx_quick_consumer_index
;
905 bnapi
->hw_rx_cons_ptr
=
906 &sblk
->status_rx_quick_consumer_index
;
907 bnapi
->int_num
= i
<< 24;
911 if (BNX2_CHIP(bp
) == BNX2_CHIP_5709
) {
912 bp
->ctx_pages
= 0x2000 / BNX2_PAGE_SIZE
;
913 if (bp
->ctx_pages
== 0)
915 for (i
= 0; i
< bp
->ctx_pages
; i
++) {
916 bp
->ctx_blk
[i
] = dma_alloc_coherent(&bp
->pdev
->dev
,
918 &bp
->ctx_blk_mapping
[i
],
920 if (bp
->ctx_blk
[i
] == NULL
)
925 err
= bnx2_alloc_rx_mem(bp
);
929 err
= bnx2_alloc_tx_mem(bp
);
941 bnx2_report_fw_link(struct bnx2
*bp
)
943 u32 fw_link_status
= 0;
945 if (bp
->phy_flags
& BNX2_PHY_FLAG_REMOTE_PHY_CAP
)
951 switch (bp
->line_speed
) {
953 if (bp
->duplex
== DUPLEX_HALF
)
954 fw_link_status
= BNX2_LINK_STATUS_10HALF
;
956 fw_link_status
= BNX2_LINK_STATUS_10FULL
;
959 if (bp
->duplex
== DUPLEX_HALF
)
960 fw_link_status
= BNX2_LINK_STATUS_100HALF
;
962 fw_link_status
= BNX2_LINK_STATUS_100FULL
;
965 if (bp
->duplex
== DUPLEX_HALF
)
966 fw_link_status
= BNX2_LINK_STATUS_1000HALF
;
968 fw_link_status
= BNX2_LINK_STATUS_1000FULL
;
971 if (bp
->duplex
== DUPLEX_HALF
)
972 fw_link_status
= BNX2_LINK_STATUS_2500HALF
;
974 fw_link_status
= BNX2_LINK_STATUS_2500FULL
;
978 fw_link_status
|= BNX2_LINK_STATUS_LINK_UP
;
981 fw_link_status
|= BNX2_LINK_STATUS_AN_ENABLED
;
983 bnx2_read_phy(bp
, bp
->mii_bmsr
, &bmsr
);
984 bnx2_read_phy(bp
, bp
->mii_bmsr
, &bmsr
);
986 if (!(bmsr
& BMSR_ANEGCOMPLETE
) ||
987 bp
->phy_flags
& BNX2_PHY_FLAG_PARALLEL_DETECT
)
988 fw_link_status
|= BNX2_LINK_STATUS_PARALLEL_DET
;
990 fw_link_status
|= BNX2_LINK_STATUS_AN_COMPLETE
;
994 fw_link_status
= BNX2_LINK_STATUS_LINK_DOWN
;
996 bnx2_shmem_wr(bp
, BNX2_LINK_STATUS
, fw_link_status
);
1000 bnx2_xceiver_str(struct bnx2
*bp
)
1002 return (bp
->phy_port
== PORT_FIBRE
) ? "SerDes" :
1003 ((bp
->phy_flags
& BNX2_PHY_FLAG_SERDES
) ? "Remote Copper" :
1008 bnx2_report_link(struct bnx2
*bp
)
1011 netif_carrier_on(bp
->dev
);
1012 netdev_info(bp
->dev
, "NIC %s Link is Up, %d Mbps %s duplex",
1013 bnx2_xceiver_str(bp
),
1015 bp
->duplex
== DUPLEX_FULL
? "full" : "half");
1017 if (bp
->flow_ctrl
) {
1018 if (bp
->flow_ctrl
& FLOW_CTRL_RX
) {
1019 pr_cont(", receive ");
1020 if (bp
->flow_ctrl
& FLOW_CTRL_TX
)
1021 pr_cont("& transmit ");
1024 pr_cont(", transmit ");
1026 pr_cont("flow control ON");
1030 netif_carrier_off(bp
->dev
);
1031 netdev_err(bp
->dev
, "NIC %s Link is Down\n",
1032 bnx2_xceiver_str(bp
));
1035 bnx2_report_fw_link(bp
);
1039 bnx2_resolve_flow_ctrl(struct bnx2
*bp
)
1041 u32 local_adv
, remote_adv
;
1044 if ((bp
->autoneg
& (AUTONEG_SPEED
| AUTONEG_FLOW_CTRL
)) !=
1045 (AUTONEG_SPEED
| AUTONEG_FLOW_CTRL
)) {
1047 if (bp
->duplex
== DUPLEX_FULL
) {
1048 bp
->flow_ctrl
= bp
->req_flow_ctrl
;
1053 if (bp
->duplex
!= DUPLEX_FULL
) {
1057 if ((bp
->phy_flags
& BNX2_PHY_FLAG_SERDES
) &&
1058 (BNX2_CHIP(bp
) == BNX2_CHIP_5708
)) {
1061 bnx2_read_phy(bp
, BCM5708S_1000X_STAT1
, &val
);
1062 if (val
& BCM5708S_1000X_STAT1_TX_PAUSE
)
1063 bp
->flow_ctrl
|= FLOW_CTRL_TX
;
1064 if (val
& BCM5708S_1000X_STAT1_RX_PAUSE
)
1065 bp
->flow_ctrl
|= FLOW_CTRL_RX
;
1069 bnx2_read_phy(bp
, bp
->mii_adv
, &local_adv
);
1070 bnx2_read_phy(bp
, bp
->mii_lpa
, &remote_adv
);
1072 if (bp
->phy_flags
& BNX2_PHY_FLAG_SERDES
) {
1073 u32 new_local_adv
= 0;
1074 u32 new_remote_adv
= 0;
1076 if (local_adv
& ADVERTISE_1000XPAUSE
)
1077 new_local_adv
|= ADVERTISE_PAUSE_CAP
;
1078 if (local_adv
& ADVERTISE_1000XPSE_ASYM
)
1079 new_local_adv
|= ADVERTISE_PAUSE_ASYM
;
1080 if (remote_adv
& ADVERTISE_1000XPAUSE
)
1081 new_remote_adv
|= ADVERTISE_PAUSE_CAP
;
1082 if (remote_adv
& ADVERTISE_1000XPSE_ASYM
)
1083 new_remote_adv
|= ADVERTISE_PAUSE_ASYM
;
1085 local_adv
= new_local_adv
;
1086 remote_adv
= new_remote_adv
;
1089 /* See Table 28B-3 of 802.3ab-1999 spec. */
1090 if (local_adv
& ADVERTISE_PAUSE_CAP
) {
1091 if(local_adv
& ADVERTISE_PAUSE_ASYM
) {
1092 if (remote_adv
& ADVERTISE_PAUSE_CAP
) {
1093 bp
->flow_ctrl
= FLOW_CTRL_TX
| FLOW_CTRL_RX
;
1095 else if (remote_adv
& ADVERTISE_PAUSE_ASYM
) {
1096 bp
->flow_ctrl
= FLOW_CTRL_RX
;
1100 if (remote_adv
& ADVERTISE_PAUSE_CAP
) {
1101 bp
->flow_ctrl
= FLOW_CTRL_TX
| FLOW_CTRL_RX
;
1105 else if (local_adv
& ADVERTISE_PAUSE_ASYM
) {
1106 if ((remote_adv
& ADVERTISE_PAUSE_CAP
) &&
1107 (remote_adv
& ADVERTISE_PAUSE_ASYM
)) {
1109 bp
->flow_ctrl
= FLOW_CTRL_TX
;
1115 bnx2_5709s_linkup(struct bnx2
*bp
)
1121 bnx2_write_phy(bp
, MII_BNX2_BLK_ADDR
, MII_BNX2_BLK_ADDR_GP_STATUS
);
1122 bnx2_read_phy(bp
, MII_BNX2_GP_TOP_AN_STATUS1
, &val
);
1123 bnx2_write_phy(bp
, MII_BNX2_BLK_ADDR
, MII_BNX2_BLK_ADDR_COMBO_IEEEB0
);
1125 if ((bp
->autoneg
& AUTONEG_SPEED
) == 0) {
1126 bp
->line_speed
= bp
->req_line_speed
;
1127 bp
->duplex
= bp
->req_duplex
;
1130 speed
= val
& MII_BNX2_GP_TOP_AN_SPEED_MSK
;
1132 case MII_BNX2_GP_TOP_AN_SPEED_10
:
1133 bp
->line_speed
= SPEED_10
;
1135 case MII_BNX2_GP_TOP_AN_SPEED_100
:
1136 bp
->line_speed
= SPEED_100
;
1138 case MII_BNX2_GP_TOP_AN_SPEED_1G
:
1139 case MII_BNX2_GP_TOP_AN_SPEED_1GKV
:
1140 bp
->line_speed
= SPEED_1000
;
1142 case MII_BNX2_GP_TOP_AN_SPEED_2_5G
:
1143 bp
->line_speed
= SPEED_2500
;
1146 if (val
& MII_BNX2_GP_TOP_AN_FD
)
1147 bp
->duplex
= DUPLEX_FULL
;
1149 bp
->duplex
= DUPLEX_HALF
;
1154 bnx2_5708s_linkup(struct bnx2
*bp
)
1159 bnx2_read_phy(bp
, BCM5708S_1000X_STAT1
, &val
);
1160 switch (val
& BCM5708S_1000X_STAT1_SPEED_MASK
) {
1161 case BCM5708S_1000X_STAT1_SPEED_10
:
1162 bp
->line_speed
= SPEED_10
;
1164 case BCM5708S_1000X_STAT1_SPEED_100
:
1165 bp
->line_speed
= SPEED_100
;
1167 case BCM5708S_1000X_STAT1_SPEED_1G
:
1168 bp
->line_speed
= SPEED_1000
;
1170 case BCM5708S_1000X_STAT1_SPEED_2G5
:
1171 bp
->line_speed
= SPEED_2500
;
1174 if (val
& BCM5708S_1000X_STAT1_FD
)
1175 bp
->duplex
= DUPLEX_FULL
;
1177 bp
->duplex
= DUPLEX_HALF
;
1183 bnx2_5706s_linkup(struct bnx2
*bp
)
1185 u32 bmcr
, local_adv
, remote_adv
, common
;
1188 bp
->line_speed
= SPEED_1000
;
1190 bnx2_read_phy(bp
, bp
->mii_bmcr
, &bmcr
);
1191 if (bmcr
& BMCR_FULLDPLX
) {
1192 bp
->duplex
= DUPLEX_FULL
;
1195 bp
->duplex
= DUPLEX_HALF
;
1198 if (!(bmcr
& BMCR_ANENABLE
)) {
1202 bnx2_read_phy(bp
, bp
->mii_adv
, &local_adv
);
1203 bnx2_read_phy(bp
, bp
->mii_lpa
, &remote_adv
);
1205 common
= local_adv
& remote_adv
;
1206 if (common
& (ADVERTISE_1000XHALF
| ADVERTISE_1000XFULL
)) {
1208 if (common
& ADVERTISE_1000XFULL
) {
1209 bp
->duplex
= DUPLEX_FULL
;
1212 bp
->duplex
= DUPLEX_HALF
;
1220 bnx2_copper_linkup(struct bnx2
*bp
)
1224 bp
->phy_flags
&= ~BNX2_PHY_FLAG_MDIX
;
1226 bnx2_read_phy(bp
, bp
->mii_bmcr
, &bmcr
);
1227 if (bmcr
& BMCR_ANENABLE
) {
1228 u32 local_adv
, remote_adv
, common
;
1230 bnx2_read_phy(bp
, MII_CTRL1000
, &local_adv
);
1231 bnx2_read_phy(bp
, MII_STAT1000
, &remote_adv
);
1233 common
= local_adv
& (remote_adv
>> 2);
1234 if (common
& ADVERTISE_1000FULL
) {
1235 bp
->line_speed
= SPEED_1000
;
1236 bp
->duplex
= DUPLEX_FULL
;
1238 else if (common
& ADVERTISE_1000HALF
) {
1239 bp
->line_speed
= SPEED_1000
;
1240 bp
->duplex
= DUPLEX_HALF
;
1243 bnx2_read_phy(bp
, bp
->mii_adv
, &local_adv
);
1244 bnx2_read_phy(bp
, bp
->mii_lpa
, &remote_adv
);
1246 common
= local_adv
& remote_adv
;
1247 if (common
& ADVERTISE_100FULL
) {
1248 bp
->line_speed
= SPEED_100
;
1249 bp
->duplex
= DUPLEX_FULL
;
1251 else if (common
& ADVERTISE_100HALF
) {
1252 bp
->line_speed
= SPEED_100
;
1253 bp
->duplex
= DUPLEX_HALF
;
1255 else if (common
& ADVERTISE_10FULL
) {
1256 bp
->line_speed
= SPEED_10
;
1257 bp
->duplex
= DUPLEX_FULL
;
1259 else if (common
& ADVERTISE_10HALF
) {
1260 bp
->line_speed
= SPEED_10
;
1261 bp
->duplex
= DUPLEX_HALF
;
1270 if (bmcr
& BMCR_SPEED100
) {
1271 bp
->line_speed
= SPEED_100
;
1274 bp
->line_speed
= SPEED_10
;
1276 if (bmcr
& BMCR_FULLDPLX
) {
1277 bp
->duplex
= DUPLEX_FULL
;
1280 bp
->duplex
= DUPLEX_HALF
;
1287 bnx2_read_phy(bp
, MII_BNX2_EXT_STATUS
, &ext_status
);
1288 if (ext_status
& EXT_STATUS_MDIX
)
1289 bp
->phy_flags
|= BNX2_PHY_FLAG_MDIX
;
1296 bnx2_init_rx_context(struct bnx2
*bp
, u32 cid
)
1298 u32 val
, rx_cid_addr
= GET_CID_ADDR(cid
);
1300 val
= BNX2_L2CTX_CTX_TYPE_CTX_BD_CHN_TYPE_VALUE
;
1301 val
|= BNX2_L2CTX_CTX_TYPE_SIZE_L2
;
1304 if (bp
->flow_ctrl
& FLOW_CTRL_TX
)
1305 val
|= BNX2_L2CTX_FLOW_CTRL_ENABLE
;
1307 bnx2_ctx_wr(bp
, rx_cid_addr
, BNX2_L2CTX_CTX_TYPE
, val
);
1311 bnx2_init_all_rx_contexts(struct bnx2
*bp
)
1316 for (i
= 0, cid
= RX_CID
; i
< bp
->num_rx_rings
; i
++, cid
++) {
1319 bnx2_init_rx_context(bp
, cid
);
1324 bnx2_set_mac_link(struct bnx2
*bp
)
1328 BNX2_WR(bp
, BNX2_EMAC_TX_LENGTHS
, 0x2620);
1329 if (bp
->link_up
&& (bp
->line_speed
== SPEED_1000
) &&
1330 (bp
->duplex
== DUPLEX_HALF
)) {
1331 BNX2_WR(bp
, BNX2_EMAC_TX_LENGTHS
, 0x26ff);
1334 /* Configure the EMAC mode register. */
1335 val
= BNX2_RD(bp
, BNX2_EMAC_MODE
);
1337 val
&= ~(BNX2_EMAC_MODE_PORT
| BNX2_EMAC_MODE_HALF_DUPLEX
|
1338 BNX2_EMAC_MODE_MAC_LOOP
| BNX2_EMAC_MODE_FORCE_LINK
|
1339 BNX2_EMAC_MODE_25G_MODE
);
1342 switch (bp
->line_speed
) {
1344 if (BNX2_CHIP(bp
) != BNX2_CHIP_5706
) {
1345 val
|= BNX2_EMAC_MODE_PORT_MII_10M
;
1350 val
|= BNX2_EMAC_MODE_PORT_MII
;
1353 val
|= BNX2_EMAC_MODE_25G_MODE
;
1356 val
|= BNX2_EMAC_MODE_PORT_GMII
;
1361 val
|= BNX2_EMAC_MODE_PORT_GMII
;
1364 /* Set the MAC to operate in the appropriate duplex mode. */
1365 if (bp
->duplex
== DUPLEX_HALF
)
1366 val
|= BNX2_EMAC_MODE_HALF_DUPLEX
;
1367 BNX2_WR(bp
, BNX2_EMAC_MODE
, val
);
1369 /* Enable/disable rx PAUSE. */
1370 bp
->rx_mode
&= ~BNX2_EMAC_RX_MODE_FLOW_EN
;
1372 if (bp
->flow_ctrl
& FLOW_CTRL_RX
)
1373 bp
->rx_mode
|= BNX2_EMAC_RX_MODE_FLOW_EN
;
1374 BNX2_WR(bp
, BNX2_EMAC_RX_MODE
, bp
->rx_mode
);
1376 /* Enable/disable tx PAUSE. */
1377 val
= BNX2_RD(bp
, BNX2_EMAC_TX_MODE
);
1378 val
&= ~BNX2_EMAC_TX_MODE_FLOW_EN
;
1380 if (bp
->flow_ctrl
& FLOW_CTRL_TX
)
1381 val
|= BNX2_EMAC_TX_MODE_FLOW_EN
;
1382 BNX2_WR(bp
, BNX2_EMAC_TX_MODE
, val
);
1384 /* Acknowledge the interrupt. */
1385 BNX2_WR(bp
, BNX2_EMAC_STATUS
, BNX2_EMAC_STATUS_LINK_CHANGE
);
1387 bnx2_init_all_rx_contexts(bp
);
1391 bnx2_enable_bmsr1(struct bnx2
*bp
)
1393 if ((bp
->phy_flags
& BNX2_PHY_FLAG_SERDES
) &&
1394 (BNX2_CHIP(bp
) == BNX2_CHIP_5709
))
1395 bnx2_write_phy(bp
, MII_BNX2_BLK_ADDR
,
1396 MII_BNX2_BLK_ADDR_GP_STATUS
);
1400 bnx2_disable_bmsr1(struct bnx2
*bp
)
1402 if ((bp
->phy_flags
& BNX2_PHY_FLAG_SERDES
) &&
1403 (BNX2_CHIP(bp
) == BNX2_CHIP_5709
))
1404 bnx2_write_phy(bp
, MII_BNX2_BLK_ADDR
,
1405 MII_BNX2_BLK_ADDR_COMBO_IEEEB0
);
1409 bnx2_test_and_enable_2g5(struct bnx2
*bp
)
1414 if (!(bp
->phy_flags
& BNX2_PHY_FLAG_2_5G_CAPABLE
))
1417 if (bp
->autoneg
& AUTONEG_SPEED
)
1418 bp
->advertising
|= ADVERTISED_2500baseX_Full
;
1420 if (BNX2_CHIP(bp
) == BNX2_CHIP_5709
)
1421 bnx2_write_phy(bp
, MII_BNX2_BLK_ADDR
, MII_BNX2_BLK_ADDR_OVER1G
);
1423 bnx2_read_phy(bp
, bp
->mii_up1
, &up1
);
1424 if (!(up1
& BCM5708S_UP1_2G5
)) {
1425 up1
|= BCM5708S_UP1_2G5
;
1426 bnx2_write_phy(bp
, bp
->mii_up1
, up1
);
1430 if (BNX2_CHIP(bp
) == BNX2_CHIP_5709
)
1431 bnx2_write_phy(bp
, MII_BNX2_BLK_ADDR
,
1432 MII_BNX2_BLK_ADDR_COMBO_IEEEB0
);
1438 bnx2_test_and_disable_2g5(struct bnx2
*bp
)
1443 if (!(bp
->phy_flags
& BNX2_PHY_FLAG_2_5G_CAPABLE
))
1446 if (BNX2_CHIP(bp
) == BNX2_CHIP_5709
)
1447 bnx2_write_phy(bp
, MII_BNX2_BLK_ADDR
, MII_BNX2_BLK_ADDR_OVER1G
);
1449 bnx2_read_phy(bp
, bp
->mii_up1
, &up1
);
1450 if (up1
& BCM5708S_UP1_2G5
) {
1451 up1
&= ~BCM5708S_UP1_2G5
;
1452 bnx2_write_phy(bp
, bp
->mii_up1
, up1
);
1456 if (BNX2_CHIP(bp
) == BNX2_CHIP_5709
)
1457 bnx2_write_phy(bp
, MII_BNX2_BLK_ADDR
,
1458 MII_BNX2_BLK_ADDR_COMBO_IEEEB0
);
1464 bnx2_enable_forced_2g5(struct bnx2
*bp
)
1466 u32
uninitialized_var(bmcr
);
1469 if (!(bp
->phy_flags
& BNX2_PHY_FLAG_2_5G_CAPABLE
))
1472 if (BNX2_CHIP(bp
) == BNX2_CHIP_5709
) {
1475 bnx2_write_phy(bp
, MII_BNX2_BLK_ADDR
,
1476 MII_BNX2_BLK_ADDR_SERDES_DIG
);
1477 if (!bnx2_read_phy(bp
, MII_BNX2_SERDES_DIG_MISC1
, &val
)) {
1478 val
&= ~MII_BNX2_SD_MISC1_FORCE_MSK
;
1479 val
|= MII_BNX2_SD_MISC1_FORCE
|
1480 MII_BNX2_SD_MISC1_FORCE_2_5G
;
1481 bnx2_write_phy(bp
, MII_BNX2_SERDES_DIG_MISC1
, val
);
1484 bnx2_write_phy(bp
, MII_BNX2_BLK_ADDR
,
1485 MII_BNX2_BLK_ADDR_COMBO_IEEEB0
);
1486 err
= bnx2_read_phy(bp
, bp
->mii_bmcr
, &bmcr
);
1488 } else if (BNX2_CHIP(bp
) == BNX2_CHIP_5708
) {
1489 err
= bnx2_read_phy(bp
, bp
->mii_bmcr
, &bmcr
);
1491 bmcr
|= BCM5708S_BMCR_FORCE_2500
;
1499 if (bp
->autoneg
& AUTONEG_SPEED
) {
1500 bmcr
&= ~BMCR_ANENABLE
;
1501 if (bp
->req_duplex
== DUPLEX_FULL
)
1502 bmcr
|= BMCR_FULLDPLX
;
1504 bnx2_write_phy(bp
, bp
->mii_bmcr
, bmcr
);
1508 bnx2_disable_forced_2g5(struct bnx2
*bp
)
1510 u32
uninitialized_var(bmcr
);
1513 if (!(bp
->phy_flags
& BNX2_PHY_FLAG_2_5G_CAPABLE
))
1516 if (BNX2_CHIP(bp
) == BNX2_CHIP_5709
) {
1519 bnx2_write_phy(bp
, MII_BNX2_BLK_ADDR
,
1520 MII_BNX2_BLK_ADDR_SERDES_DIG
);
1521 if (!bnx2_read_phy(bp
, MII_BNX2_SERDES_DIG_MISC1
, &val
)) {
1522 val
&= ~MII_BNX2_SD_MISC1_FORCE
;
1523 bnx2_write_phy(bp
, MII_BNX2_SERDES_DIG_MISC1
, val
);
1526 bnx2_write_phy(bp
, MII_BNX2_BLK_ADDR
,
1527 MII_BNX2_BLK_ADDR_COMBO_IEEEB0
);
1528 err
= bnx2_read_phy(bp
, bp
->mii_bmcr
, &bmcr
);
1530 } else if (BNX2_CHIP(bp
) == BNX2_CHIP_5708
) {
1531 err
= bnx2_read_phy(bp
, bp
->mii_bmcr
, &bmcr
);
1533 bmcr
&= ~BCM5708S_BMCR_FORCE_2500
;
1541 if (bp
->autoneg
& AUTONEG_SPEED
)
1542 bmcr
|= BMCR_SPEED1000
| BMCR_ANENABLE
| BMCR_ANRESTART
;
1543 bnx2_write_phy(bp
, bp
->mii_bmcr
, bmcr
);
1547 bnx2_5706s_force_link_dn(struct bnx2
*bp
, int start
)
1551 bnx2_write_phy(bp
, MII_BNX2_DSP_ADDRESS
, MII_EXPAND_SERDES_CTL
);
1552 bnx2_read_phy(bp
, MII_BNX2_DSP_RW_PORT
, &val
);
1554 bnx2_write_phy(bp
, MII_BNX2_DSP_RW_PORT
, val
& 0xff0f);
1556 bnx2_write_phy(bp
, MII_BNX2_DSP_RW_PORT
, val
| 0xc0);
1560 bnx2_set_link(struct bnx2
*bp
)
1565 if (bp
->loopback
== MAC_LOOPBACK
|| bp
->loopback
== PHY_LOOPBACK
) {
1570 if (bp
->phy_flags
& BNX2_PHY_FLAG_REMOTE_PHY_CAP
)
1573 link_up
= bp
->link_up
;
1575 bnx2_enable_bmsr1(bp
);
1576 bnx2_read_phy(bp
, bp
->mii_bmsr1
, &bmsr
);
1577 bnx2_read_phy(bp
, bp
->mii_bmsr1
, &bmsr
);
1578 bnx2_disable_bmsr1(bp
);
1580 if ((bp
->phy_flags
& BNX2_PHY_FLAG_SERDES
) &&
1581 (BNX2_CHIP(bp
) == BNX2_CHIP_5706
)) {
1584 if (bp
->phy_flags
& BNX2_PHY_FLAG_FORCED_DOWN
) {
1585 bnx2_5706s_force_link_dn(bp
, 0);
1586 bp
->phy_flags
&= ~BNX2_PHY_FLAG_FORCED_DOWN
;
1588 val
= BNX2_RD(bp
, BNX2_EMAC_STATUS
);
1590 bnx2_write_phy(bp
, MII_BNX2_MISC_SHADOW
, MISC_SHDW_AN_DBG
);
1591 bnx2_read_phy(bp
, MII_BNX2_MISC_SHADOW
, &an_dbg
);
1592 bnx2_read_phy(bp
, MII_BNX2_MISC_SHADOW
, &an_dbg
);
1594 if ((val
& BNX2_EMAC_STATUS_LINK
) &&
1595 !(an_dbg
& MISC_SHDW_AN_DBG_NOSYNC
))
1596 bmsr
|= BMSR_LSTATUS
;
1598 bmsr
&= ~BMSR_LSTATUS
;
1601 if (bmsr
& BMSR_LSTATUS
) {
1604 if (bp
->phy_flags
& BNX2_PHY_FLAG_SERDES
) {
1605 if (BNX2_CHIP(bp
) == BNX2_CHIP_5706
)
1606 bnx2_5706s_linkup(bp
);
1607 else if (BNX2_CHIP(bp
) == BNX2_CHIP_5708
)
1608 bnx2_5708s_linkup(bp
);
1609 else if (BNX2_CHIP(bp
) == BNX2_CHIP_5709
)
1610 bnx2_5709s_linkup(bp
);
1613 bnx2_copper_linkup(bp
);
1615 bnx2_resolve_flow_ctrl(bp
);
1618 if ((bp
->phy_flags
& BNX2_PHY_FLAG_SERDES
) &&
1619 (bp
->autoneg
& AUTONEG_SPEED
))
1620 bnx2_disable_forced_2g5(bp
);
1622 if (bp
->phy_flags
& BNX2_PHY_FLAG_PARALLEL_DETECT
) {
1625 bnx2_read_phy(bp
, bp
->mii_bmcr
, &bmcr
);
1626 bmcr
|= BMCR_ANENABLE
;
1627 bnx2_write_phy(bp
, bp
->mii_bmcr
, bmcr
);
1629 bp
->phy_flags
&= ~BNX2_PHY_FLAG_PARALLEL_DETECT
;
1634 if (bp
->link_up
!= link_up
) {
1635 bnx2_report_link(bp
);
1638 bnx2_set_mac_link(bp
);
1644 bnx2_reset_phy(struct bnx2
*bp
)
1649 bnx2_write_phy(bp
, bp
->mii_bmcr
, BMCR_RESET
);
1651 #define PHY_RESET_MAX_WAIT 100
1652 for (i
= 0; i
< PHY_RESET_MAX_WAIT
; i
++) {
1655 bnx2_read_phy(bp
, bp
->mii_bmcr
, ®
);
1656 if (!(reg
& BMCR_RESET
)) {
1661 if (i
== PHY_RESET_MAX_WAIT
) {
1668 bnx2_phy_get_pause_adv(struct bnx2
*bp
)
1672 if ((bp
->req_flow_ctrl
& (FLOW_CTRL_RX
| FLOW_CTRL_TX
)) ==
1673 (FLOW_CTRL_RX
| FLOW_CTRL_TX
)) {
1675 if (bp
->phy_flags
& BNX2_PHY_FLAG_SERDES
) {
1676 adv
= ADVERTISE_1000XPAUSE
;
1679 adv
= ADVERTISE_PAUSE_CAP
;
1682 else if (bp
->req_flow_ctrl
& FLOW_CTRL_TX
) {
1683 if (bp
->phy_flags
& BNX2_PHY_FLAG_SERDES
) {
1684 adv
= ADVERTISE_1000XPSE_ASYM
;
1687 adv
= ADVERTISE_PAUSE_ASYM
;
1690 else if (bp
->req_flow_ctrl
& FLOW_CTRL_RX
) {
1691 if (bp
->phy_flags
& BNX2_PHY_FLAG_SERDES
) {
1692 adv
= ADVERTISE_1000XPAUSE
| ADVERTISE_1000XPSE_ASYM
;
1695 adv
= ADVERTISE_PAUSE_CAP
| ADVERTISE_PAUSE_ASYM
;
1701 static int bnx2_fw_sync(struct bnx2
*, u32
, int, int);
1704 bnx2_setup_remote_phy(struct bnx2
*bp
, u8 port
)
1705 __releases(&bp
->phy_lock
)
1706 __acquires(&bp
->phy_lock
)
1708 u32 speed_arg
= 0, pause_adv
;
1710 pause_adv
= bnx2_phy_get_pause_adv(bp
);
1712 if (bp
->autoneg
& AUTONEG_SPEED
) {
1713 speed_arg
|= BNX2_NETLINK_SET_LINK_ENABLE_AUTONEG
;
1714 if (bp
->advertising
& ADVERTISED_10baseT_Half
)
1715 speed_arg
|= BNX2_NETLINK_SET_LINK_SPEED_10HALF
;
1716 if (bp
->advertising
& ADVERTISED_10baseT_Full
)
1717 speed_arg
|= BNX2_NETLINK_SET_LINK_SPEED_10FULL
;
1718 if (bp
->advertising
& ADVERTISED_100baseT_Half
)
1719 speed_arg
|= BNX2_NETLINK_SET_LINK_SPEED_100HALF
;
1720 if (bp
->advertising
& ADVERTISED_100baseT_Full
)
1721 speed_arg
|= BNX2_NETLINK_SET_LINK_SPEED_100FULL
;
1722 if (bp
->advertising
& ADVERTISED_1000baseT_Full
)
1723 speed_arg
|= BNX2_NETLINK_SET_LINK_SPEED_1GFULL
;
1724 if (bp
->advertising
& ADVERTISED_2500baseX_Full
)
1725 speed_arg
|= BNX2_NETLINK_SET_LINK_SPEED_2G5FULL
;
1727 if (bp
->req_line_speed
== SPEED_2500
)
1728 speed_arg
= BNX2_NETLINK_SET_LINK_SPEED_2G5FULL
;
1729 else if (bp
->req_line_speed
== SPEED_1000
)
1730 speed_arg
= BNX2_NETLINK_SET_LINK_SPEED_1GFULL
;
1731 else if (bp
->req_line_speed
== SPEED_100
) {
1732 if (bp
->req_duplex
== DUPLEX_FULL
)
1733 speed_arg
= BNX2_NETLINK_SET_LINK_SPEED_100FULL
;
1735 speed_arg
= BNX2_NETLINK_SET_LINK_SPEED_100HALF
;
1736 } else if (bp
->req_line_speed
== SPEED_10
) {
1737 if (bp
->req_duplex
== DUPLEX_FULL
)
1738 speed_arg
= BNX2_NETLINK_SET_LINK_SPEED_10FULL
;
1740 speed_arg
= BNX2_NETLINK_SET_LINK_SPEED_10HALF
;
1744 if (pause_adv
& (ADVERTISE_1000XPAUSE
| ADVERTISE_PAUSE_CAP
))
1745 speed_arg
|= BNX2_NETLINK_SET_LINK_FC_SYM_PAUSE
;
1746 if (pause_adv
& (ADVERTISE_1000XPSE_ASYM
| ADVERTISE_PAUSE_ASYM
))
1747 speed_arg
|= BNX2_NETLINK_SET_LINK_FC_ASYM_PAUSE
;
1749 if (port
== PORT_TP
)
1750 speed_arg
|= BNX2_NETLINK_SET_LINK_PHY_APP_REMOTE
|
1751 BNX2_NETLINK_SET_LINK_ETH_AT_WIRESPEED
;
1753 bnx2_shmem_wr(bp
, BNX2_DRV_MB_ARG0
, speed_arg
);
1755 spin_unlock_bh(&bp
->phy_lock
);
1756 bnx2_fw_sync(bp
, BNX2_DRV_MSG_CODE_CMD_SET_LINK
, 1, 0);
1757 spin_lock_bh(&bp
->phy_lock
);
1763 bnx2_setup_serdes_phy(struct bnx2
*bp
, u8 port
)
1764 __releases(&bp
->phy_lock
)
1765 __acquires(&bp
->phy_lock
)
1770 if (bp
->phy_flags
& BNX2_PHY_FLAG_REMOTE_PHY_CAP
)
1771 return bnx2_setup_remote_phy(bp
, port
);
1773 if (!(bp
->autoneg
& AUTONEG_SPEED
)) {
1775 int force_link_down
= 0;
1777 if (bp
->req_line_speed
== SPEED_2500
) {
1778 if (!bnx2_test_and_enable_2g5(bp
))
1779 force_link_down
= 1;
1780 } else if (bp
->req_line_speed
== SPEED_1000
) {
1781 if (bnx2_test_and_disable_2g5(bp
))
1782 force_link_down
= 1;
1784 bnx2_read_phy(bp
, bp
->mii_adv
, &adv
);
1785 adv
&= ~(ADVERTISE_1000XFULL
| ADVERTISE_1000XHALF
);
1787 bnx2_read_phy(bp
, bp
->mii_bmcr
, &bmcr
);
1788 new_bmcr
= bmcr
& ~BMCR_ANENABLE
;
1789 new_bmcr
|= BMCR_SPEED1000
;
1791 if (BNX2_CHIP(bp
) == BNX2_CHIP_5709
) {
1792 if (bp
->req_line_speed
== SPEED_2500
)
1793 bnx2_enable_forced_2g5(bp
);
1794 else if (bp
->req_line_speed
== SPEED_1000
) {
1795 bnx2_disable_forced_2g5(bp
);
1796 new_bmcr
&= ~0x2000;
1799 } else if (BNX2_CHIP(bp
) == BNX2_CHIP_5708
) {
1800 if (bp
->req_line_speed
== SPEED_2500
)
1801 new_bmcr
|= BCM5708S_BMCR_FORCE_2500
;
1803 new_bmcr
= bmcr
& ~BCM5708S_BMCR_FORCE_2500
;
1806 if (bp
->req_duplex
== DUPLEX_FULL
) {
1807 adv
|= ADVERTISE_1000XFULL
;
1808 new_bmcr
|= BMCR_FULLDPLX
;
1811 adv
|= ADVERTISE_1000XHALF
;
1812 new_bmcr
&= ~BMCR_FULLDPLX
;
1814 if ((new_bmcr
!= bmcr
) || (force_link_down
)) {
1815 /* Force a link down visible on the other side */
1817 bnx2_write_phy(bp
, bp
->mii_adv
, adv
&
1818 ~(ADVERTISE_1000XFULL
|
1819 ADVERTISE_1000XHALF
));
1820 bnx2_write_phy(bp
, bp
->mii_bmcr
, bmcr
|
1821 BMCR_ANRESTART
| BMCR_ANENABLE
);
1824 netif_carrier_off(bp
->dev
);
1825 bnx2_write_phy(bp
, bp
->mii_bmcr
, new_bmcr
);
1826 bnx2_report_link(bp
);
1828 bnx2_write_phy(bp
, bp
->mii_adv
, adv
);
1829 bnx2_write_phy(bp
, bp
->mii_bmcr
, new_bmcr
);
1831 bnx2_resolve_flow_ctrl(bp
);
1832 bnx2_set_mac_link(bp
);
1837 bnx2_test_and_enable_2g5(bp
);
1839 if (bp
->advertising
& ADVERTISED_1000baseT_Full
)
1840 new_adv
|= ADVERTISE_1000XFULL
;
1842 new_adv
|= bnx2_phy_get_pause_adv(bp
);
1844 bnx2_read_phy(bp
, bp
->mii_adv
, &adv
);
1845 bnx2_read_phy(bp
, bp
->mii_bmcr
, &bmcr
);
1847 bp
->serdes_an_pending
= 0;
1848 if ((adv
!= new_adv
) || ((bmcr
& BMCR_ANENABLE
) == 0)) {
1849 /* Force a link down visible on the other side */
1851 bnx2_write_phy(bp
, bp
->mii_bmcr
, BMCR_LOOPBACK
);
1852 spin_unlock_bh(&bp
->phy_lock
);
1854 spin_lock_bh(&bp
->phy_lock
);
1857 bnx2_write_phy(bp
, bp
->mii_adv
, new_adv
);
1858 bnx2_write_phy(bp
, bp
->mii_bmcr
, bmcr
| BMCR_ANRESTART
|
1860 /* Speed up link-up time when the link partner
1861 * does not autonegotiate which is very common
1862 * in blade servers. Some blade servers use
1863 * IPMI for kerboard input and it's important
1864 * to minimize link disruptions. Autoneg. involves
1865 * exchanging base pages plus 3 next pages and
1866 * normally completes in about 120 msec.
1868 bp
->current_interval
= BNX2_SERDES_AN_TIMEOUT
;
1869 bp
->serdes_an_pending
= 1;
1870 mod_timer(&bp
->timer
, jiffies
+ bp
->current_interval
);
1872 bnx2_resolve_flow_ctrl(bp
);
1873 bnx2_set_mac_link(bp
);
1879 #define ETHTOOL_ALL_FIBRE_SPEED \
1880 (bp->phy_flags & BNX2_PHY_FLAG_2_5G_CAPABLE) ? \
1881 (ADVERTISED_2500baseX_Full | ADVERTISED_1000baseT_Full) :\
1882 (ADVERTISED_1000baseT_Full)
1884 #define ETHTOOL_ALL_COPPER_SPEED \
1885 (ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full | \
1886 ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full | \
1887 ADVERTISED_1000baseT_Full)
1889 #define PHY_ALL_10_100_SPEED (ADVERTISE_10HALF | ADVERTISE_10FULL | \
1890 ADVERTISE_100HALF | ADVERTISE_100FULL | ADVERTISE_CSMA)
1892 #define PHY_ALL_1000_SPEED (ADVERTISE_1000HALF | ADVERTISE_1000FULL)
1895 bnx2_set_default_remote_link(struct bnx2
*bp
)
1899 if (bp
->phy_port
== PORT_TP
)
1900 link
= bnx2_shmem_rd(bp
, BNX2_RPHY_COPPER_LINK
);
1902 link
= bnx2_shmem_rd(bp
, BNX2_RPHY_SERDES_LINK
);
1904 if (link
& BNX2_NETLINK_SET_LINK_ENABLE_AUTONEG
) {
1905 bp
->req_line_speed
= 0;
1906 bp
->autoneg
|= AUTONEG_SPEED
;
1907 bp
->advertising
= ADVERTISED_Autoneg
;
1908 if (link
& BNX2_NETLINK_SET_LINK_SPEED_10HALF
)
1909 bp
->advertising
|= ADVERTISED_10baseT_Half
;
1910 if (link
& BNX2_NETLINK_SET_LINK_SPEED_10FULL
)
1911 bp
->advertising
|= ADVERTISED_10baseT_Full
;
1912 if (link
& BNX2_NETLINK_SET_LINK_SPEED_100HALF
)
1913 bp
->advertising
|= ADVERTISED_100baseT_Half
;
1914 if (link
& BNX2_NETLINK_SET_LINK_SPEED_100FULL
)
1915 bp
->advertising
|= ADVERTISED_100baseT_Full
;
1916 if (link
& BNX2_NETLINK_SET_LINK_SPEED_1GFULL
)
1917 bp
->advertising
|= ADVERTISED_1000baseT_Full
;
1918 if (link
& BNX2_NETLINK_SET_LINK_SPEED_2G5FULL
)
1919 bp
->advertising
|= ADVERTISED_2500baseX_Full
;
1922 bp
->advertising
= 0;
1923 bp
->req_duplex
= DUPLEX_FULL
;
1924 if (link
& BNX2_NETLINK_SET_LINK_SPEED_10
) {
1925 bp
->req_line_speed
= SPEED_10
;
1926 if (link
& BNX2_NETLINK_SET_LINK_SPEED_10HALF
)
1927 bp
->req_duplex
= DUPLEX_HALF
;
1929 if (link
& BNX2_NETLINK_SET_LINK_SPEED_100
) {
1930 bp
->req_line_speed
= SPEED_100
;
1931 if (link
& BNX2_NETLINK_SET_LINK_SPEED_100HALF
)
1932 bp
->req_duplex
= DUPLEX_HALF
;
1934 if (link
& BNX2_NETLINK_SET_LINK_SPEED_1GFULL
)
1935 bp
->req_line_speed
= SPEED_1000
;
1936 if (link
& BNX2_NETLINK_SET_LINK_SPEED_2G5FULL
)
1937 bp
->req_line_speed
= SPEED_2500
;
1942 bnx2_set_default_link(struct bnx2
*bp
)
1944 if (bp
->phy_flags
& BNX2_PHY_FLAG_REMOTE_PHY_CAP
) {
1945 bnx2_set_default_remote_link(bp
);
1949 bp
->autoneg
= AUTONEG_SPEED
| AUTONEG_FLOW_CTRL
;
1950 bp
->req_line_speed
= 0;
1951 if (bp
->phy_flags
& BNX2_PHY_FLAG_SERDES
) {
1954 bp
->advertising
= ETHTOOL_ALL_FIBRE_SPEED
| ADVERTISED_Autoneg
;
1956 reg
= bnx2_shmem_rd(bp
, BNX2_PORT_HW_CFG_CONFIG
);
1957 reg
&= BNX2_PORT_HW_CFG_CFG_DFLT_LINK_MASK
;
1958 if (reg
== BNX2_PORT_HW_CFG_CFG_DFLT_LINK_1G
) {
1960 bp
->req_line_speed
= bp
->line_speed
= SPEED_1000
;
1961 bp
->req_duplex
= DUPLEX_FULL
;
1964 bp
->advertising
= ETHTOOL_ALL_COPPER_SPEED
| ADVERTISED_Autoneg
;
1968 bnx2_send_heart_beat(struct bnx2
*bp
)
1973 spin_lock(&bp
->indirect_lock
);
1974 msg
= (u32
) (++bp
->fw_drv_pulse_wr_seq
& BNX2_DRV_PULSE_SEQ_MASK
);
1975 addr
= bp
->shmem_base
+ BNX2_DRV_PULSE_MB
;
1976 BNX2_WR(bp
, BNX2_PCICFG_REG_WINDOW_ADDRESS
, addr
);
1977 BNX2_WR(bp
, BNX2_PCICFG_REG_WINDOW
, msg
);
1978 spin_unlock(&bp
->indirect_lock
);
1982 bnx2_remote_phy_event(struct bnx2
*bp
)
1985 u8 link_up
= bp
->link_up
;
1988 msg
= bnx2_shmem_rd(bp
, BNX2_LINK_STATUS
);
1990 if (msg
& BNX2_LINK_STATUS_HEART_BEAT_EXPIRED
)
1991 bnx2_send_heart_beat(bp
);
1993 msg
&= ~BNX2_LINK_STATUS_HEART_BEAT_EXPIRED
;
1995 if ((msg
& BNX2_LINK_STATUS_LINK_UP
) == BNX2_LINK_STATUS_LINK_DOWN
)
2001 speed
= msg
& BNX2_LINK_STATUS_SPEED_MASK
;
2002 bp
->duplex
= DUPLEX_FULL
;
2004 case BNX2_LINK_STATUS_10HALF
:
2005 bp
->duplex
= DUPLEX_HALF
;
2007 case BNX2_LINK_STATUS_10FULL
:
2008 bp
->line_speed
= SPEED_10
;
2010 case BNX2_LINK_STATUS_100HALF
:
2011 bp
->duplex
= DUPLEX_HALF
;
2013 case BNX2_LINK_STATUS_100BASE_T4
:
2014 case BNX2_LINK_STATUS_100FULL
:
2015 bp
->line_speed
= SPEED_100
;
2017 case BNX2_LINK_STATUS_1000HALF
:
2018 bp
->duplex
= DUPLEX_HALF
;
2020 case BNX2_LINK_STATUS_1000FULL
:
2021 bp
->line_speed
= SPEED_1000
;
2023 case BNX2_LINK_STATUS_2500HALF
:
2024 bp
->duplex
= DUPLEX_HALF
;
2026 case BNX2_LINK_STATUS_2500FULL
:
2027 bp
->line_speed
= SPEED_2500
;
2035 if ((bp
->autoneg
& (AUTONEG_SPEED
| AUTONEG_FLOW_CTRL
)) !=
2036 (AUTONEG_SPEED
| AUTONEG_FLOW_CTRL
)) {
2037 if (bp
->duplex
== DUPLEX_FULL
)
2038 bp
->flow_ctrl
= bp
->req_flow_ctrl
;
2040 if (msg
& BNX2_LINK_STATUS_TX_FC_ENABLED
)
2041 bp
->flow_ctrl
|= FLOW_CTRL_TX
;
2042 if (msg
& BNX2_LINK_STATUS_RX_FC_ENABLED
)
2043 bp
->flow_ctrl
|= FLOW_CTRL_RX
;
2046 old_port
= bp
->phy_port
;
2047 if (msg
& BNX2_LINK_STATUS_SERDES_LINK
)
2048 bp
->phy_port
= PORT_FIBRE
;
2050 bp
->phy_port
= PORT_TP
;
2052 if (old_port
!= bp
->phy_port
)
2053 bnx2_set_default_link(bp
);
2056 if (bp
->link_up
!= link_up
)
2057 bnx2_report_link(bp
);
2059 bnx2_set_mac_link(bp
);
2063 bnx2_set_remote_link(struct bnx2
*bp
)
2067 evt_code
= bnx2_shmem_rd(bp
, BNX2_FW_EVT_CODE_MB
);
2069 case BNX2_FW_EVT_CODE_LINK_EVENT
:
2070 bnx2_remote_phy_event(bp
);
2072 case BNX2_FW_EVT_CODE_SW_TIMER_EXPIRATION_EVENT
:
2074 bnx2_send_heart_beat(bp
);
2081 bnx2_setup_copper_phy(struct bnx2
*bp
)
2082 __releases(&bp
->phy_lock
)
2083 __acquires(&bp
->phy_lock
)
2085 u32 bmcr
, adv_reg
, new_adv
= 0;
2088 bnx2_read_phy(bp
, bp
->mii_bmcr
, &bmcr
);
2090 bnx2_read_phy(bp
, bp
->mii_adv
, &adv_reg
);
2091 adv_reg
&= (PHY_ALL_10_100_SPEED
| ADVERTISE_PAUSE_CAP
|
2092 ADVERTISE_PAUSE_ASYM
);
2094 new_adv
= ADVERTISE_CSMA
| ethtool_adv_to_mii_adv_t(bp
->advertising
);
2096 if (bp
->autoneg
& AUTONEG_SPEED
) {
2098 u32 new_adv1000
= 0;
2100 new_adv
|= bnx2_phy_get_pause_adv(bp
);
2102 bnx2_read_phy(bp
, MII_CTRL1000
, &adv1000_reg
);
2103 adv1000_reg
&= PHY_ALL_1000_SPEED
;
2105 new_adv1000
|= ethtool_adv_to_mii_ctrl1000_t(bp
->advertising
);
2106 if ((adv1000_reg
!= new_adv1000
) ||
2107 (adv_reg
!= new_adv
) ||
2108 ((bmcr
& BMCR_ANENABLE
) == 0)) {
2110 bnx2_write_phy(bp
, bp
->mii_adv
, new_adv
);
2111 bnx2_write_phy(bp
, MII_CTRL1000
, new_adv1000
);
2112 bnx2_write_phy(bp
, bp
->mii_bmcr
, BMCR_ANRESTART
|
2115 else if (bp
->link_up
) {
2116 /* Flow ctrl may have changed from auto to forced */
2117 /* or vice-versa. */
2119 bnx2_resolve_flow_ctrl(bp
);
2120 bnx2_set_mac_link(bp
);
2125 /* advertise nothing when forcing speed */
2126 if (adv_reg
!= new_adv
)
2127 bnx2_write_phy(bp
, bp
->mii_adv
, new_adv
);
2130 if (bp
->req_line_speed
== SPEED_100
) {
2131 new_bmcr
|= BMCR_SPEED100
;
2133 if (bp
->req_duplex
== DUPLEX_FULL
) {
2134 new_bmcr
|= BMCR_FULLDPLX
;
2136 if (new_bmcr
!= bmcr
) {
2139 bnx2_read_phy(bp
, bp
->mii_bmsr
, &bmsr
);
2140 bnx2_read_phy(bp
, bp
->mii_bmsr
, &bmsr
);
2142 if (bmsr
& BMSR_LSTATUS
) {
2143 /* Force link down */
2144 bnx2_write_phy(bp
, bp
->mii_bmcr
, BMCR_LOOPBACK
);
2145 spin_unlock_bh(&bp
->phy_lock
);
2147 spin_lock_bh(&bp
->phy_lock
);
2149 bnx2_read_phy(bp
, bp
->mii_bmsr
, &bmsr
);
2150 bnx2_read_phy(bp
, bp
->mii_bmsr
, &bmsr
);
2153 bnx2_write_phy(bp
, bp
->mii_bmcr
, new_bmcr
);
2155 /* Normally, the new speed is setup after the link has
2156 * gone down and up again. In some cases, link will not go
2157 * down so we need to set up the new speed here.
2159 if (bmsr
& BMSR_LSTATUS
) {
2160 bp
->line_speed
= bp
->req_line_speed
;
2161 bp
->duplex
= bp
->req_duplex
;
2162 bnx2_resolve_flow_ctrl(bp
);
2163 bnx2_set_mac_link(bp
);
2166 bnx2_resolve_flow_ctrl(bp
);
2167 bnx2_set_mac_link(bp
);
2173 bnx2_setup_phy(struct bnx2
*bp
, u8 port
)
2174 __releases(&bp
->phy_lock
)
2175 __acquires(&bp
->phy_lock
)
2177 if (bp
->loopback
== MAC_LOOPBACK
)
2180 if (bp
->phy_flags
& BNX2_PHY_FLAG_SERDES
) {
2181 return bnx2_setup_serdes_phy(bp
, port
);
2184 return bnx2_setup_copper_phy(bp
);
2189 bnx2_init_5709s_phy(struct bnx2
*bp
, int reset_phy
)
2193 bp
->mii_bmcr
= MII_BMCR
+ 0x10;
2194 bp
->mii_bmsr
= MII_BMSR
+ 0x10;
2195 bp
->mii_bmsr1
= MII_BNX2_GP_TOP_AN_STATUS1
;
2196 bp
->mii_adv
= MII_ADVERTISE
+ 0x10;
2197 bp
->mii_lpa
= MII_LPA
+ 0x10;
2198 bp
->mii_up1
= MII_BNX2_OVER1G_UP1
;
2200 bnx2_write_phy(bp
, MII_BNX2_BLK_ADDR
, MII_BNX2_BLK_ADDR_AER
);
2201 bnx2_write_phy(bp
, MII_BNX2_AER_AER
, MII_BNX2_AER_AER_AN_MMD
);
2203 bnx2_write_phy(bp
, MII_BNX2_BLK_ADDR
, MII_BNX2_BLK_ADDR_COMBO_IEEEB0
);
2207 bnx2_write_phy(bp
, MII_BNX2_BLK_ADDR
, MII_BNX2_BLK_ADDR_SERDES_DIG
);
2209 bnx2_read_phy(bp
, MII_BNX2_SERDES_DIG_1000XCTL1
, &val
);
2210 val
&= ~MII_BNX2_SD_1000XCTL1_AUTODET
;
2211 val
|= MII_BNX2_SD_1000XCTL1_FIBER
;
2212 bnx2_write_phy(bp
, MII_BNX2_SERDES_DIG_1000XCTL1
, val
);
2214 bnx2_write_phy(bp
, MII_BNX2_BLK_ADDR
, MII_BNX2_BLK_ADDR_OVER1G
);
2215 bnx2_read_phy(bp
, MII_BNX2_OVER1G_UP1
, &val
);
2216 if (bp
->phy_flags
& BNX2_PHY_FLAG_2_5G_CAPABLE
)
2217 val
|= BCM5708S_UP1_2G5
;
2219 val
&= ~BCM5708S_UP1_2G5
;
2220 bnx2_write_phy(bp
, MII_BNX2_OVER1G_UP1
, val
);
2222 bnx2_write_phy(bp
, MII_BNX2_BLK_ADDR
, MII_BNX2_BLK_ADDR_BAM_NXTPG
);
2223 bnx2_read_phy(bp
, MII_BNX2_BAM_NXTPG_CTL
, &val
);
2224 val
|= MII_BNX2_NXTPG_CTL_T2
| MII_BNX2_NXTPG_CTL_BAM
;
2225 bnx2_write_phy(bp
, MII_BNX2_BAM_NXTPG_CTL
, val
);
2227 bnx2_write_phy(bp
, MII_BNX2_BLK_ADDR
, MII_BNX2_BLK_ADDR_CL73_USERB0
);
2229 val
= MII_BNX2_CL73_BAM_EN
| MII_BNX2_CL73_BAM_STA_MGR_EN
|
2230 MII_BNX2_CL73_BAM_NP_AFT_BP_EN
;
2231 bnx2_write_phy(bp
, MII_BNX2_CL73_BAM_CTL1
, val
);
2233 bnx2_write_phy(bp
, MII_BNX2_BLK_ADDR
, MII_BNX2_BLK_ADDR_COMBO_IEEEB0
);
2239 bnx2_init_5708s_phy(struct bnx2
*bp
, int reset_phy
)
2246 bp
->mii_up1
= BCM5708S_UP1
;
2248 bnx2_write_phy(bp
, BCM5708S_BLK_ADDR
, BCM5708S_BLK_ADDR_DIG3
);
2249 bnx2_write_phy(bp
, BCM5708S_DIG_3_0
, BCM5708S_DIG_3_0_USE_IEEE
);
2250 bnx2_write_phy(bp
, BCM5708S_BLK_ADDR
, BCM5708S_BLK_ADDR_DIG
);
2252 bnx2_read_phy(bp
, BCM5708S_1000X_CTL1
, &val
);
2253 val
|= BCM5708S_1000X_CTL1_FIBER_MODE
| BCM5708S_1000X_CTL1_AUTODET_EN
;
2254 bnx2_write_phy(bp
, BCM5708S_1000X_CTL1
, val
);
2256 bnx2_read_phy(bp
, BCM5708S_1000X_CTL2
, &val
);
2257 val
|= BCM5708S_1000X_CTL2_PLLEL_DET_EN
;
2258 bnx2_write_phy(bp
, BCM5708S_1000X_CTL2
, val
);
2260 if (bp
->phy_flags
& BNX2_PHY_FLAG_2_5G_CAPABLE
) {
2261 bnx2_read_phy(bp
, BCM5708S_UP1
, &val
);
2262 val
|= BCM5708S_UP1_2G5
;
2263 bnx2_write_phy(bp
, BCM5708S_UP1
, val
);
2266 if ((BNX2_CHIP_ID(bp
) == BNX2_CHIP_ID_5708_A0
) ||
2267 (BNX2_CHIP_ID(bp
) == BNX2_CHIP_ID_5708_B0
) ||
2268 (BNX2_CHIP_ID(bp
) == BNX2_CHIP_ID_5708_B1
)) {
2269 /* increase tx signal amplitude */
2270 bnx2_write_phy(bp
, BCM5708S_BLK_ADDR
,
2271 BCM5708S_BLK_ADDR_TX_MISC
);
2272 bnx2_read_phy(bp
, BCM5708S_TX_ACTL1
, &val
);
2273 val
&= ~BCM5708S_TX_ACTL1_DRIVER_VCM
;
2274 bnx2_write_phy(bp
, BCM5708S_TX_ACTL1
, val
);
2275 bnx2_write_phy(bp
, BCM5708S_BLK_ADDR
, BCM5708S_BLK_ADDR_DIG
);
2278 val
= bnx2_shmem_rd(bp
, BNX2_PORT_HW_CFG_CONFIG
) &
2279 BNX2_PORT_HW_CFG_CFG_TXCTL3_MASK
;
2284 is_backplane
= bnx2_shmem_rd(bp
, BNX2_SHARED_HW_CFG_CONFIG
);
2285 if (is_backplane
& BNX2_SHARED_HW_CFG_PHY_BACKPLANE
) {
2286 bnx2_write_phy(bp
, BCM5708S_BLK_ADDR
,
2287 BCM5708S_BLK_ADDR_TX_MISC
);
2288 bnx2_write_phy(bp
, BCM5708S_TX_ACTL3
, val
);
2289 bnx2_write_phy(bp
, BCM5708S_BLK_ADDR
,
2290 BCM5708S_BLK_ADDR_DIG
);
2297 bnx2_init_5706s_phy(struct bnx2
*bp
, int reset_phy
)
2302 bp
->phy_flags
&= ~BNX2_PHY_FLAG_PARALLEL_DETECT
;
2304 if (BNX2_CHIP(bp
) == BNX2_CHIP_5706
)
2305 BNX2_WR(bp
, BNX2_MISC_GP_HW_CTL0
, 0x300);
2307 if (bp
->dev
->mtu
> 1500) {
2310 /* Set extended packet length bit */
2311 bnx2_write_phy(bp
, 0x18, 0x7);
2312 bnx2_read_phy(bp
, 0x18, &val
);
2313 bnx2_write_phy(bp
, 0x18, (val
& 0xfff8) | 0x4000);
2315 bnx2_write_phy(bp
, 0x1c, 0x6c00);
2316 bnx2_read_phy(bp
, 0x1c, &val
);
2317 bnx2_write_phy(bp
, 0x1c, (val
& 0x3ff) | 0xec02);
2322 bnx2_write_phy(bp
, 0x18, 0x7);
2323 bnx2_read_phy(bp
, 0x18, &val
);
2324 bnx2_write_phy(bp
, 0x18, val
& ~0x4007);
2326 bnx2_write_phy(bp
, 0x1c, 0x6c00);
2327 bnx2_read_phy(bp
, 0x1c, &val
);
2328 bnx2_write_phy(bp
, 0x1c, (val
& 0x3fd) | 0xec00);
2335 bnx2_init_copper_phy(struct bnx2
*bp
, int reset_phy
)
2342 if (bp
->phy_flags
& BNX2_PHY_FLAG_CRC_FIX
) {
2343 bnx2_write_phy(bp
, 0x18, 0x0c00);
2344 bnx2_write_phy(bp
, 0x17, 0x000a);
2345 bnx2_write_phy(bp
, 0x15, 0x310b);
2346 bnx2_write_phy(bp
, 0x17, 0x201f);
2347 bnx2_write_phy(bp
, 0x15, 0x9506);
2348 bnx2_write_phy(bp
, 0x17, 0x401f);
2349 bnx2_write_phy(bp
, 0x15, 0x14e2);
2350 bnx2_write_phy(bp
, 0x18, 0x0400);
2353 if (bp
->phy_flags
& BNX2_PHY_FLAG_DIS_EARLY_DAC
) {
2354 bnx2_write_phy(bp
, MII_BNX2_DSP_ADDRESS
,
2355 MII_BNX2_DSP_EXPAND_REG
| 0x8);
2356 bnx2_read_phy(bp
, MII_BNX2_DSP_RW_PORT
, &val
);
2358 bnx2_write_phy(bp
, MII_BNX2_DSP_RW_PORT
, val
);
2361 if (bp
->dev
->mtu
> 1500) {
2362 /* Set extended packet length bit */
2363 bnx2_write_phy(bp
, 0x18, 0x7);
2364 bnx2_read_phy(bp
, 0x18, &val
);
2365 bnx2_write_phy(bp
, 0x18, val
| 0x4000);
2367 bnx2_read_phy(bp
, 0x10, &val
);
2368 bnx2_write_phy(bp
, 0x10, val
| 0x1);
2371 bnx2_write_phy(bp
, 0x18, 0x7);
2372 bnx2_read_phy(bp
, 0x18, &val
);
2373 bnx2_write_phy(bp
, 0x18, val
& ~0x4007);
2375 bnx2_read_phy(bp
, 0x10, &val
);
2376 bnx2_write_phy(bp
, 0x10, val
& ~0x1);
2379 /* ethernet@wirespeed */
2380 bnx2_write_phy(bp
, MII_BNX2_AUX_CTL
, AUX_CTL_MISC_CTL
);
2381 bnx2_read_phy(bp
, MII_BNX2_AUX_CTL
, &val
);
2382 val
|= AUX_CTL_MISC_CTL_WR
| AUX_CTL_MISC_CTL_WIRESPEED
;
2385 if (BNX2_CHIP(bp
) == BNX2_CHIP_5709
)
2386 val
|= AUX_CTL_MISC_CTL_AUTOMDIX
;
2388 bnx2_write_phy(bp
, MII_BNX2_AUX_CTL
, val
);
2394 bnx2_init_phy(struct bnx2
*bp
, int reset_phy
)
2395 __releases(&bp
->phy_lock
)
2396 __acquires(&bp
->phy_lock
)
2401 bp
->phy_flags
&= ~BNX2_PHY_FLAG_INT_MODE_MASK
;
2402 bp
->phy_flags
|= BNX2_PHY_FLAG_INT_MODE_LINK_READY
;
2404 bp
->mii_bmcr
= MII_BMCR
;
2405 bp
->mii_bmsr
= MII_BMSR
;
2406 bp
->mii_bmsr1
= MII_BMSR
;
2407 bp
->mii_adv
= MII_ADVERTISE
;
2408 bp
->mii_lpa
= MII_LPA
;
2410 BNX2_WR(bp
, BNX2_EMAC_ATTENTION_ENA
, BNX2_EMAC_ATTENTION_ENA_LINK
);
2412 if (bp
->phy_flags
& BNX2_PHY_FLAG_REMOTE_PHY_CAP
)
2415 bnx2_read_phy(bp
, MII_PHYSID1
, &val
);
2416 bp
->phy_id
= val
<< 16;
2417 bnx2_read_phy(bp
, MII_PHYSID2
, &val
);
2418 bp
->phy_id
|= val
& 0xffff;
2420 if (bp
->phy_flags
& BNX2_PHY_FLAG_SERDES
) {
2421 if (BNX2_CHIP(bp
) == BNX2_CHIP_5706
)
2422 rc
= bnx2_init_5706s_phy(bp
, reset_phy
);
2423 else if (BNX2_CHIP(bp
) == BNX2_CHIP_5708
)
2424 rc
= bnx2_init_5708s_phy(bp
, reset_phy
);
2425 else if (BNX2_CHIP(bp
) == BNX2_CHIP_5709
)
2426 rc
= bnx2_init_5709s_phy(bp
, reset_phy
);
2429 rc
= bnx2_init_copper_phy(bp
, reset_phy
);
2434 rc
= bnx2_setup_phy(bp
, bp
->phy_port
);
2440 bnx2_set_mac_loopback(struct bnx2
*bp
)
2444 mac_mode
= BNX2_RD(bp
, BNX2_EMAC_MODE
);
2445 mac_mode
&= ~BNX2_EMAC_MODE_PORT
;
2446 mac_mode
|= BNX2_EMAC_MODE_MAC_LOOP
| BNX2_EMAC_MODE_FORCE_LINK
;
2447 BNX2_WR(bp
, BNX2_EMAC_MODE
, mac_mode
);
2452 static int bnx2_test_link(struct bnx2
*);
2455 bnx2_set_phy_loopback(struct bnx2
*bp
)
2460 spin_lock_bh(&bp
->phy_lock
);
2461 rc
= bnx2_write_phy(bp
, bp
->mii_bmcr
, BMCR_LOOPBACK
| BMCR_FULLDPLX
|
2463 spin_unlock_bh(&bp
->phy_lock
);
2467 for (i
= 0; i
< 10; i
++) {
2468 if (bnx2_test_link(bp
) == 0)
2473 mac_mode
= BNX2_RD(bp
, BNX2_EMAC_MODE
);
2474 mac_mode
&= ~(BNX2_EMAC_MODE_PORT
| BNX2_EMAC_MODE_HALF_DUPLEX
|
2475 BNX2_EMAC_MODE_MAC_LOOP
| BNX2_EMAC_MODE_FORCE_LINK
|
2476 BNX2_EMAC_MODE_25G_MODE
);
2478 mac_mode
|= BNX2_EMAC_MODE_PORT_GMII
;
2479 BNX2_WR(bp
, BNX2_EMAC_MODE
, mac_mode
);
2485 bnx2_dump_mcp_state(struct bnx2
*bp
)
2487 struct net_device
*dev
= bp
->dev
;
2490 netdev_err(dev
, "<--- start MCP states dump --->\n");
2491 if (BNX2_CHIP(bp
) == BNX2_CHIP_5709
) {
2492 mcp_p0
= BNX2_MCP_STATE_P0
;
2493 mcp_p1
= BNX2_MCP_STATE_P1
;
2495 mcp_p0
= BNX2_MCP_STATE_P0_5708
;
2496 mcp_p1
= BNX2_MCP_STATE_P1_5708
;
2498 netdev_err(dev
, "DEBUG: MCP_STATE_P0[%08x] MCP_STATE_P1[%08x]\n",
2499 bnx2_reg_rd_ind(bp
, mcp_p0
), bnx2_reg_rd_ind(bp
, mcp_p1
));
2500 netdev_err(dev
, "DEBUG: MCP mode[%08x] state[%08x] evt_mask[%08x]\n",
2501 bnx2_reg_rd_ind(bp
, BNX2_MCP_CPU_MODE
),
2502 bnx2_reg_rd_ind(bp
, BNX2_MCP_CPU_STATE
),
2503 bnx2_reg_rd_ind(bp
, BNX2_MCP_CPU_EVENT_MASK
));
2504 netdev_err(dev
, "DEBUG: pc[%08x] pc[%08x] instr[%08x]\n",
2505 bnx2_reg_rd_ind(bp
, BNX2_MCP_CPU_PROGRAM_COUNTER
),
2506 bnx2_reg_rd_ind(bp
, BNX2_MCP_CPU_PROGRAM_COUNTER
),
2507 bnx2_reg_rd_ind(bp
, BNX2_MCP_CPU_INSTRUCTION
));
2508 netdev_err(dev
, "DEBUG: shmem states:\n");
2509 netdev_err(dev
, "DEBUG: drv_mb[%08x] fw_mb[%08x] link_status[%08x]",
2510 bnx2_shmem_rd(bp
, BNX2_DRV_MB
),
2511 bnx2_shmem_rd(bp
, BNX2_FW_MB
),
2512 bnx2_shmem_rd(bp
, BNX2_LINK_STATUS
));
2513 pr_cont(" drv_pulse_mb[%08x]\n", bnx2_shmem_rd(bp
, BNX2_DRV_PULSE_MB
));
2514 netdev_err(dev
, "DEBUG: dev_info_signature[%08x] reset_type[%08x]",
2515 bnx2_shmem_rd(bp
, BNX2_DEV_INFO_SIGNATURE
),
2516 bnx2_shmem_rd(bp
, BNX2_BC_STATE_RESET_TYPE
));
2517 pr_cont(" condition[%08x]\n",
2518 bnx2_shmem_rd(bp
, BNX2_BC_STATE_CONDITION
));
2519 DP_SHMEM_LINE(bp
, BNX2_BC_RESET_TYPE
);
2520 DP_SHMEM_LINE(bp
, 0x3cc);
2521 DP_SHMEM_LINE(bp
, 0x3dc);
2522 DP_SHMEM_LINE(bp
, 0x3ec);
2523 netdev_err(dev
, "DEBUG: 0x3fc[%08x]\n", bnx2_shmem_rd(bp
, 0x3fc));
2524 netdev_err(dev
, "<--- end MCP states dump --->\n");
2528 bnx2_fw_sync(struct bnx2
*bp
, u32 msg_data
, int ack
, int silent
)
2534 msg_data
|= bp
->fw_wr_seq
;
2535 bp
->fw_last_msg
= msg_data
;
2537 bnx2_shmem_wr(bp
, BNX2_DRV_MB
, msg_data
);
2542 /* wait for an acknowledgement. */
2543 for (i
= 0; i
< (BNX2_FW_ACK_TIME_OUT_MS
/ 10); i
++) {
2546 val
= bnx2_shmem_rd(bp
, BNX2_FW_MB
);
2548 if ((val
& BNX2_FW_MSG_ACK
) == (msg_data
& BNX2_DRV_MSG_SEQ
))
2551 if ((msg_data
& BNX2_DRV_MSG_DATA
) == BNX2_DRV_MSG_DATA_WAIT0
)
2554 /* If we timed out, inform the firmware that this is the case. */
2555 if ((val
& BNX2_FW_MSG_ACK
) != (msg_data
& BNX2_DRV_MSG_SEQ
)) {
2556 msg_data
&= ~BNX2_DRV_MSG_CODE
;
2557 msg_data
|= BNX2_DRV_MSG_CODE_FW_TIMEOUT
;
2559 bnx2_shmem_wr(bp
, BNX2_DRV_MB
, msg_data
);
2561 pr_err("fw sync timeout, reset code = %x\n", msg_data
);
2562 bnx2_dump_mcp_state(bp
);
2568 if ((val
& BNX2_FW_MSG_STATUS_MASK
) != BNX2_FW_MSG_STATUS_OK
)
2575 bnx2_init_5709_context(struct bnx2
*bp
)
2580 val
= BNX2_CTX_COMMAND_ENABLED
| BNX2_CTX_COMMAND_MEM_INIT
| (1 << 12);
2581 val
|= (BNX2_PAGE_BITS
- 8) << 16;
2582 BNX2_WR(bp
, BNX2_CTX_COMMAND
, val
);
2583 for (i
= 0; i
< 10; i
++) {
2584 val
= BNX2_RD(bp
, BNX2_CTX_COMMAND
);
2585 if (!(val
& BNX2_CTX_COMMAND_MEM_INIT
))
2589 if (val
& BNX2_CTX_COMMAND_MEM_INIT
)
2592 for (i
= 0; i
< bp
->ctx_pages
; i
++) {
2596 memset(bp
->ctx_blk
[i
], 0, BNX2_PAGE_SIZE
);
2600 BNX2_WR(bp
, BNX2_CTX_HOST_PAGE_TBL_DATA0
,
2601 (bp
->ctx_blk_mapping
[i
] & 0xffffffff) |
2602 BNX2_CTX_HOST_PAGE_TBL_DATA0_VALID
);
2603 BNX2_WR(bp
, BNX2_CTX_HOST_PAGE_TBL_DATA1
,
2604 (u64
) bp
->ctx_blk_mapping
[i
] >> 32);
2605 BNX2_WR(bp
, BNX2_CTX_HOST_PAGE_TBL_CTRL
, i
|
2606 BNX2_CTX_HOST_PAGE_TBL_CTRL_WRITE_REQ
);
2607 for (j
= 0; j
< 10; j
++) {
2609 val
= BNX2_RD(bp
, BNX2_CTX_HOST_PAGE_TBL_CTRL
);
2610 if (!(val
& BNX2_CTX_HOST_PAGE_TBL_CTRL_WRITE_REQ
))
2614 if (val
& BNX2_CTX_HOST_PAGE_TBL_CTRL_WRITE_REQ
) {
2623 bnx2_init_context(struct bnx2
*bp
)
2629 u32 vcid_addr
, pcid_addr
, offset
;
2634 if (BNX2_CHIP_ID(bp
) == BNX2_CHIP_ID_5706_A0
) {
2637 vcid_addr
= GET_PCID_ADDR(vcid
);
2639 new_vcid
= 0x60 + (vcid
& 0xf0) + (vcid
& 0x7);
2644 pcid_addr
= GET_PCID_ADDR(new_vcid
);
2647 vcid_addr
= GET_CID_ADDR(vcid
);
2648 pcid_addr
= vcid_addr
;
2651 for (i
= 0; i
< (CTX_SIZE
/ PHY_CTX_SIZE
); i
++) {
2652 vcid_addr
+= (i
<< PHY_CTX_SHIFT
);
2653 pcid_addr
+= (i
<< PHY_CTX_SHIFT
);
2655 BNX2_WR(bp
, BNX2_CTX_VIRT_ADDR
, vcid_addr
);
2656 BNX2_WR(bp
, BNX2_CTX_PAGE_TBL
, pcid_addr
);
2658 /* Zero out the context. */
2659 for (offset
= 0; offset
< PHY_CTX_SIZE
; offset
+= 4)
2660 bnx2_ctx_wr(bp
, vcid_addr
, offset
, 0);
2666 bnx2_alloc_bad_rbuf(struct bnx2
*bp
)
2672 good_mbuf
= kmalloc(512 * sizeof(u16
), GFP_KERNEL
);
2673 if (good_mbuf
== NULL
)
2676 BNX2_WR(bp
, BNX2_MISC_ENABLE_SET_BITS
,
2677 BNX2_MISC_ENABLE_SET_BITS_RX_MBUF_ENABLE
);
2681 /* Allocate a bunch of mbufs and save the good ones in an array. */
2682 val
= bnx2_reg_rd_ind(bp
, BNX2_RBUF_STATUS1
);
2683 while (val
& BNX2_RBUF_STATUS1_FREE_COUNT
) {
2684 bnx2_reg_wr_ind(bp
, BNX2_RBUF_COMMAND
,
2685 BNX2_RBUF_COMMAND_ALLOC_REQ
);
2687 val
= bnx2_reg_rd_ind(bp
, BNX2_RBUF_FW_BUF_ALLOC
);
2689 val
&= BNX2_RBUF_FW_BUF_ALLOC_VALUE
;
2691 /* The addresses with Bit 9 set are bad memory blocks. */
2692 if (!(val
& (1 << 9))) {
2693 good_mbuf
[good_mbuf_cnt
] = (u16
) val
;
2697 val
= bnx2_reg_rd_ind(bp
, BNX2_RBUF_STATUS1
);
2700 /* Free the good ones back to the mbuf pool thus discarding
2701 * all the bad ones. */
2702 while (good_mbuf_cnt
) {
2705 val
= good_mbuf
[good_mbuf_cnt
];
2706 val
= (val
<< 9) | val
| 1;
2708 bnx2_reg_wr_ind(bp
, BNX2_RBUF_FW_BUF_FREE
, val
);
2715 bnx2_set_mac_addr(struct bnx2
*bp
, u8
*mac_addr
, u32 pos
)
2719 val
= (mac_addr
[0] << 8) | mac_addr
[1];
2721 BNX2_WR(bp
, BNX2_EMAC_MAC_MATCH0
+ (pos
* 8), val
);
2723 val
= (mac_addr
[2] << 24) | (mac_addr
[3] << 16) |
2724 (mac_addr
[4] << 8) | mac_addr
[5];
2726 BNX2_WR(bp
, BNX2_EMAC_MAC_MATCH1
+ (pos
* 8), val
);
2730 bnx2_alloc_rx_page(struct bnx2
*bp
, struct bnx2_rx_ring_info
*rxr
, u16 index
, gfp_t gfp
)
2733 struct bnx2_sw_pg
*rx_pg
= &rxr
->rx_pg_ring
[index
];
2734 struct bnx2_rx_bd
*rxbd
=
2735 &rxr
->rx_pg_desc_ring
[BNX2_RX_RING(index
)][BNX2_RX_IDX(index
)];
2736 struct page
*page
= alloc_page(gfp
);
2740 mapping
= dma_map_page(&bp
->pdev
->dev
, page
, 0, PAGE_SIZE
,
2741 PCI_DMA_FROMDEVICE
);
2742 if (dma_mapping_error(&bp
->pdev
->dev
, mapping
)) {
2748 dma_unmap_addr_set(rx_pg
, mapping
, mapping
);
2749 rxbd
->rx_bd_haddr_hi
= (u64
) mapping
>> 32;
2750 rxbd
->rx_bd_haddr_lo
= (u64
) mapping
& 0xffffffff;
2755 bnx2_free_rx_page(struct bnx2
*bp
, struct bnx2_rx_ring_info
*rxr
, u16 index
)
2757 struct bnx2_sw_pg
*rx_pg
= &rxr
->rx_pg_ring
[index
];
2758 struct page
*page
= rx_pg
->page
;
2763 dma_unmap_page(&bp
->pdev
->dev
, dma_unmap_addr(rx_pg
, mapping
),
2764 PAGE_SIZE
, PCI_DMA_FROMDEVICE
);
2771 bnx2_alloc_rx_data(struct bnx2
*bp
, struct bnx2_rx_ring_info
*rxr
, u16 index
, gfp_t gfp
)
2774 struct bnx2_sw_bd
*rx_buf
= &rxr
->rx_buf_ring
[index
];
2776 struct bnx2_rx_bd
*rxbd
=
2777 &rxr
->rx_desc_ring
[BNX2_RX_RING(index
)][BNX2_RX_IDX(index
)];
2779 data
= kmalloc(bp
->rx_buf_size
, gfp
);
2783 mapping
= dma_map_single(&bp
->pdev
->dev
,
2785 bp
->rx_buf_use_size
,
2786 PCI_DMA_FROMDEVICE
);
2787 if (dma_mapping_error(&bp
->pdev
->dev
, mapping
)) {
2792 rx_buf
->data
= data
;
2793 dma_unmap_addr_set(rx_buf
, mapping
, mapping
);
2795 rxbd
->rx_bd_haddr_hi
= (u64
) mapping
>> 32;
2796 rxbd
->rx_bd_haddr_lo
= (u64
) mapping
& 0xffffffff;
2798 rxr
->rx_prod_bseq
+= bp
->rx_buf_use_size
;
2804 bnx2_phy_event_is_set(struct bnx2
*bp
, struct bnx2_napi
*bnapi
, u32 event
)
2806 struct status_block
*sblk
= bnapi
->status_blk
.msi
;
2807 u32 new_link_state
, old_link_state
;
2810 new_link_state
= sblk
->status_attn_bits
& event
;
2811 old_link_state
= sblk
->status_attn_bits_ack
& event
;
2812 if (new_link_state
!= old_link_state
) {
2814 BNX2_WR(bp
, BNX2_PCICFG_STATUS_BIT_SET_CMD
, event
);
2816 BNX2_WR(bp
, BNX2_PCICFG_STATUS_BIT_CLEAR_CMD
, event
);
2824 bnx2_phy_int(struct bnx2
*bp
, struct bnx2_napi
*bnapi
)
2826 spin_lock(&bp
->phy_lock
);
2828 if (bnx2_phy_event_is_set(bp
, bnapi
, STATUS_ATTN_BITS_LINK_STATE
))
2830 if (bnx2_phy_event_is_set(bp
, bnapi
, STATUS_ATTN_BITS_TIMER_ABORT
))
2831 bnx2_set_remote_link(bp
);
2833 spin_unlock(&bp
->phy_lock
);
2838 bnx2_get_hw_tx_cons(struct bnx2_napi
*bnapi
)
2842 /* Tell compiler that status block fields can change. */
2844 cons
= *bnapi
->hw_tx_cons_ptr
;
2846 if (unlikely((cons
& BNX2_MAX_TX_DESC_CNT
) == BNX2_MAX_TX_DESC_CNT
))
2852 bnx2_tx_int(struct bnx2
*bp
, struct bnx2_napi
*bnapi
, int budget
)
2854 struct bnx2_tx_ring_info
*txr
= &bnapi
->tx_ring
;
2855 u16 hw_cons
, sw_cons
, sw_ring_cons
;
2856 int tx_pkt
= 0, index
;
2857 unsigned int tx_bytes
= 0;
2858 struct netdev_queue
*txq
;
2860 index
= (bnapi
- bp
->bnx2_napi
);
2861 txq
= netdev_get_tx_queue(bp
->dev
, index
);
2863 hw_cons
= bnx2_get_hw_tx_cons(bnapi
);
2864 sw_cons
= txr
->tx_cons
;
2866 while (sw_cons
!= hw_cons
) {
2867 struct bnx2_sw_tx_bd
*tx_buf
;
2868 struct sk_buff
*skb
;
2871 sw_ring_cons
= BNX2_TX_RING_IDX(sw_cons
);
2873 tx_buf
= &txr
->tx_buf_ring
[sw_ring_cons
];
2876 /* prefetch skb_end_pointer() to speedup skb_shinfo(skb) */
2877 prefetch(&skb
->end
);
2879 /* partial BD completions possible with TSO packets */
2880 if (tx_buf
->is_gso
) {
2881 u16 last_idx
, last_ring_idx
;
2883 last_idx
= sw_cons
+ tx_buf
->nr_frags
+ 1;
2884 last_ring_idx
= sw_ring_cons
+ tx_buf
->nr_frags
+ 1;
2885 if (unlikely(last_ring_idx
>= BNX2_MAX_TX_DESC_CNT
)) {
2888 if (((s16
) ((s16
) last_idx
- (s16
) hw_cons
)) > 0) {
2893 dma_unmap_single(&bp
->pdev
->dev
, dma_unmap_addr(tx_buf
, mapping
),
2894 skb_headlen(skb
), PCI_DMA_TODEVICE
);
2897 last
= tx_buf
->nr_frags
;
2899 for (i
= 0; i
< last
; i
++) {
2900 struct bnx2_sw_tx_bd
*tx_buf
;
2902 sw_cons
= BNX2_NEXT_TX_BD(sw_cons
);
2904 tx_buf
= &txr
->tx_buf_ring
[BNX2_TX_RING_IDX(sw_cons
)];
2905 dma_unmap_page(&bp
->pdev
->dev
,
2906 dma_unmap_addr(tx_buf
, mapping
),
2907 skb_frag_size(&skb_shinfo(skb
)->frags
[i
]),
2911 sw_cons
= BNX2_NEXT_TX_BD(sw_cons
);
2913 tx_bytes
+= skb
->len
;
2914 dev_kfree_skb_any(skb
);
2916 if (tx_pkt
== budget
)
2919 if (hw_cons
== sw_cons
)
2920 hw_cons
= bnx2_get_hw_tx_cons(bnapi
);
2923 netdev_tx_completed_queue(txq
, tx_pkt
, tx_bytes
);
2924 txr
->hw_tx_cons
= hw_cons
;
2925 txr
->tx_cons
= sw_cons
;
2927 /* Need to make the tx_cons update visible to bnx2_start_xmit()
2928 * before checking for netif_tx_queue_stopped(). Without the
2929 * memory barrier, there is a small possibility that bnx2_start_xmit()
2930 * will miss it and cause the queue to be stopped forever.
2934 if (unlikely(netif_tx_queue_stopped(txq
)) &&
2935 (bnx2_tx_avail(bp
, txr
) > bp
->tx_wake_thresh
)) {
2936 __netif_tx_lock(txq
, smp_processor_id());
2937 if ((netif_tx_queue_stopped(txq
)) &&
2938 (bnx2_tx_avail(bp
, txr
) > bp
->tx_wake_thresh
))
2939 netif_tx_wake_queue(txq
);
2940 __netif_tx_unlock(txq
);
2947 bnx2_reuse_rx_skb_pages(struct bnx2
*bp
, struct bnx2_rx_ring_info
*rxr
,
2948 struct sk_buff
*skb
, int count
)
2950 struct bnx2_sw_pg
*cons_rx_pg
, *prod_rx_pg
;
2951 struct bnx2_rx_bd
*cons_bd
, *prod_bd
;
2954 u16 cons
= rxr
->rx_pg_cons
;
2956 cons_rx_pg
= &rxr
->rx_pg_ring
[cons
];
2958 /* The caller was unable to allocate a new page to replace the
2959 * last one in the frags array, so we need to recycle that page
2960 * and then free the skb.
2964 struct skb_shared_info
*shinfo
;
2966 shinfo
= skb_shinfo(skb
);
2968 page
= skb_frag_page(&shinfo
->frags
[shinfo
->nr_frags
]);
2969 __skb_frag_set_page(&shinfo
->frags
[shinfo
->nr_frags
], NULL
);
2971 cons_rx_pg
->page
= page
;
2975 hw_prod
= rxr
->rx_pg_prod
;
2977 for (i
= 0; i
< count
; i
++) {
2978 prod
= BNX2_RX_PG_RING_IDX(hw_prod
);
2980 prod_rx_pg
= &rxr
->rx_pg_ring
[prod
];
2981 cons_rx_pg
= &rxr
->rx_pg_ring
[cons
];
2982 cons_bd
= &rxr
->rx_pg_desc_ring
[BNX2_RX_RING(cons
)]
2983 [BNX2_RX_IDX(cons
)];
2984 prod_bd
= &rxr
->rx_pg_desc_ring
[BNX2_RX_RING(prod
)]
2985 [BNX2_RX_IDX(prod
)];
2988 prod_rx_pg
->page
= cons_rx_pg
->page
;
2989 cons_rx_pg
->page
= NULL
;
2990 dma_unmap_addr_set(prod_rx_pg
, mapping
,
2991 dma_unmap_addr(cons_rx_pg
, mapping
));
2993 prod_bd
->rx_bd_haddr_hi
= cons_bd
->rx_bd_haddr_hi
;
2994 prod_bd
->rx_bd_haddr_lo
= cons_bd
->rx_bd_haddr_lo
;
2997 cons
= BNX2_RX_PG_RING_IDX(BNX2_NEXT_RX_BD(cons
));
2998 hw_prod
= BNX2_NEXT_RX_BD(hw_prod
);
3000 rxr
->rx_pg_prod
= hw_prod
;
3001 rxr
->rx_pg_cons
= cons
;
3005 bnx2_reuse_rx_data(struct bnx2
*bp
, struct bnx2_rx_ring_info
*rxr
,
3006 u8
*data
, u16 cons
, u16 prod
)
3008 struct bnx2_sw_bd
*cons_rx_buf
, *prod_rx_buf
;
3009 struct bnx2_rx_bd
*cons_bd
, *prod_bd
;
3011 cons_rx_buf
= &rxr
->rx_buf_ring
[cons
];
3012 prod_rx_buf
= &rxr
->rx_buf_ring
[prod
];
3014 dma_sync_single_for_device(&bp
->pdev
->dev
,
3015 dma_unmap_addr(cons_rx_buf
, mapping
),
3016 BNX2_RX_OFFSET
+ BNX2_RX_COPY_THRESH
, PCI_DMA_FROMDEVICE
);
3018 rxr
->rx_prod_bseq
+= bp
->rx_buf_use_size
;
3020 prod_rx_buf
->data
= data
;
3025 dma_unmap_addr_set(prod_rx_buf
, mapping
,
3026 dma_unmap_addr(cons_rx_buf
, mapping
));
3028 cons_bd
= &rxr
->rx_desc_ring
[BNX2_RX_RING(cons
)][BNX2_RX_IDX(cons
)];
3029 prod_bd
= &rxr
->rx_desc_ring
[BNX2_RX_RING(prod
)][BNX2_RX_IDX(prod
)];
3030 prod_bd
->rx_bd_haddr_hi
= cons_bd
->rx_bd_haddr_hi
;
3031 prod_bd
->rx_bd_haddr_lo
= cons_bd
->rx_bd_haddr_lo
;
3034 static struct sk_buff
*
3035 bnx2_rx_skb(struct bnx2
*bp
, struct bnx2_rx_ring_info
*rxr
, u8
*data
,
3036 unsigned int len
, unsigned int hdr_len
, dma_addr_t dma_addr
,
3040 u16 prod
= ring_idx
& 0xffff;
3041 struct sk_buff
*skb
;
3043 err
= bnx2_alloc_rx_data(bp
, rxr
, prod
, GFP_ATOMIC
);
3044 if (unlikely(err
)) {
3045 bnx2_reuse_rx_data(bp
, rxr
, data
, (u16
) (ring_idx
>> 16), prod
);
3048 unsigned int raw_len
= len
+ 4;
3049 int pages
= PAGE_ALIGN(raw_len
- hdr_len
) >> PAGE_SHIFT
;
3051 bnx2_reuse_rx_skb_pages(bp
, rxr
, NULL
, pages
);
3056 dma_unmap_single(&bp
->pdev
->dev
, dma_addr
, bp
->rx_buf_use_size
,
3057 PCI_DMA_FROMDEVICE
);
3058 skb
= build_skb(data
, 0);
3063 skb_reserve(skb
, ((u8
*)get_l2_fhdr(data
) - data
) + BNX2_RX_OFFSET
);
3068 unsigned int i
, frag_len
, frag_size
, pages
;
3069 struct bnx2_sw_pg
*rx_pg
;
3070 u16 pg_cons
= rxr
->rx_pg_cons
;
3071 u16 pg_prod
= rxr
->rx_pg_prod
;
3073 frag_size
= len
+ 4 - hdr_len
;
3074 pages
= PAGE_ALIGN(frag_size
) >> PAGE_SHIFT
;
3075 skb_put(skb
, hdr_len
);
3077 for (i
= 0; i
< pages
; i
++) {
3078 dma_addr_t mapping_old
;
3080 frag_len
= min(frag_size
, (unsigned int) PAGE_SIZE
);
3081 if (unlikely(frag_len
<= 4)) {
3082 unsigned int tail
= 4 - frag_len
;
3084 rxr
->rx_pg_cons
= pg_cons
;
3085 rxr
->rx_pg_prod
= pg_prod
;
3086 bnx2_reuse_rx_skb_pages(bp
, rxr
, NULL
,
3093 &skb_shinfo(skb
)->frags
[i
- 1];
3094 skb_frag_size_sub(frag
, tail
);
3095 skb
->data_len
-= tail
;
3099 rx_pg
= &rxr
->rx_pg_ring
[pg_cons
];
3101 /* Don't unmap yet. If we're unable to allocate a new
3102 * page, we need to recycle the page and the DMA addr.
3104 mapping_old
= dma_unmap_addr(rx_pg
, mapping
);
3108 skb_fill_page_desc(skb
, i
, rx_pg
->page
, 0, frag_len
);
3111 err
= bnx2_alloc_rx_page(bp
, rxr
,
3112 BNX2_RX_PG_RING_IDX(pg_prod
),
3114 if (unlikely(err
)) {
3115 rxr
->rx_pg_cons
= pg_cons
;
3116 rxr
->rx_pg_prod
= pg_prod
;
3117 bnx2_reuse_rx_skb_pages(bp
, rxr
, skb
,
3122 dma_unmap_page(&bp
->pdev
->dev
, mapping_old
,
3123 PAGE_SIZE
, PCI_DMA_FROMDEVICE
);
3125 frag_size
-= frag_len
;
3126 skb
->data_len
+= frag_len
;
3127 skb
->truesize
+= PAGE_SIZE
;
3128 skb
->len
+= frag_len
;
3130 pg_prod
= BNX2_NEXT_RX_BD(pg_prod
);
3131 pg_cons
= BNX2_RX_PG_RING_IDX(BNX2_NEXT_RX_BD(pg_cons
));
3133 rxr
->rx_pg_prod
= pg_prod
;
3134 rxr
->rx_pg_cons
= pg_cons
;
3140 bnx2_get_hw_rx_cons(struct bnx2_napi
*bnapi
)
3144 /* Tell compiler that status block fields can change. */
3146 cons
= *bnapi
->hw_rx_cons_ptr
;
3148 if (unlikely((cons
& BNX2_MAX_RX_DESC_CNT
) == BNX2_MAX_RX_DESC_CNT
))
3154 bnx2_rx_int(struct bnx2
*bp
, struct bnx2_napi
*bnapi
, int budget
)
3156 struct bnx2_rx_ring_info
*rxr
= &bnapi
->rx_ring
;
3157 u16 hw_cons
, sw_cons
, sw_ring_cons
, sw_prod
, sw_ring_prod
;
3158 struct l2_fhdr
*rx_hdr
;
3159 int rx_pkt
= 0, pg_ring_used
= 0;
3164 hw_cons
= bnx2_get_hw_rx_cons(bnapi
);
3165 sw_cons
= rxr
->rx_cons
;
3166 sw_prod
= rxr
->rx_prod
;
3168 /* Memory barrier necessary as speculative reads of the rx
3169 * buffer can be ahead of the index in the status block
3172 while (sw_cons
!= hw_cons
) {
3173 unsigned int len
, hdr_len
;
3175 struct bnx2_sw_bd
*rx_buf
, *next_rx_buf
;
3176 struct sk_buff
*skb
;
3177 dma_addr_t dma_addr
;
3181 sw_ring_cons
= BNX2_RX_RING_IDX(sw_cons
);
3182 sw_ring_prod
= BNX2_RX_RING_IDX(sw_prod
);
3184 rx_buf
= &rxr
->rx_buf_ring
[sw_ring_cons
];
3185 data
= rx_buf
->data
;
3186 rx_buf
->data
= NULL
;
3188 rx_hdr
= get_l2_fhdr(data
);
3191 dma_addr
= dma_unmap_addr(rx_buf
, mapping
);
3193 dma_sync_single_for_cpu(&bp
->pdev
->dev
, dma_addr
,
3194 BNX2_RX_OFFSET
+ BNX2_RX_COPY_THRESH
,
3195 PCI_DMA_FROMDEVICE
);
3197 next_ring_idx
= BNX2_RX_RING_IDX(BNX2_NEXT_RX_BD(sw_cons
));
3198 next_rx_buf
= &rxr
->rx_buf_ring
[next_ring_idx
];
3199 prefetch(get_l2_fhdr(next_rx_buf
->data
));
3201 len
= rx_hdr
->l2_fhdr_pkt_len
;
3202 status
= rx_hdr
->l2_fhdr_status
;
3205 if (status
& L2_FHDR_STATUS_SPLIT
) {
3206 hdr_len
= rx_hdr
->l2_fhdr_ip_xsum
;
3208 } else if (len
> bp
->rx_jumbo_thresh
) {
3209 hdr_len
= bp
->rx_jumbo_thresh
;
3213 if (unlikely(status
& (L2_FHDR_ERRORS_BAD_CRC
|
3214 L2_FHDR_ERRORS_PHY_DECODE
|
3215 L2_FHDR_ERRORS_ALIGNMENT
|
3216 L2_FHDR_ERRORS_TOO_SHORT
|
3217 L2_FHDR_ERRORS_GIANT_FRAME
))) {
3219 bnx2_reuse_rx_data(bp
, rxr
, data
, sw_ring_cons
,
3224 pages
= PAGE_ALIGN(len
- hdr_len
) >> PAGE_SHIFT
;
3226 bnx2_reuse_rx_skb_pages(bp
, rxr
, NULL
, pages
);
3233 if (len
<= bp
->rx_copy_thresh
) {
3234 skb
= netdev_alloc_skb(bp
->dev
, len
+ 6);
3236 bnx2_reuse_rx_data(bp
, rxr
, data
, sw_ring_cons
,
3243 (u8
*)rx_hdr
+ BNX2_RX_OFFSET
- 6,
3245 skb_reserve(skb
, 6);
3248 bnx2_reuse_rx_data(bp
, rxr
, data
,
3249 sw_ring_cons
, sw_ring_prod
);
3252 skb
= bnx2_rx_skb(bp
, rxr
, data
, len
, hdr_len
, dma_addr
,
3253 (sw_ring_cons
<< 16) | sw_ring_prod
);
3257 if ((status
& L2_FHDR_STATUS_L2_VLAN_TAG
) &&
3258 !(bp
->rx_mode
& BNX2_EMAC_RX_MODE_KEEP_VLAN_TAG
))
3259 __vlan_hwaccel_put_tag(skb
, htons(ETH_P_8021Q
), rx_hdr
->l2_fhdr_vlan_tag
);
3261 skb
->protocol
= eth_type_trans(skb
, bp
->dev
);
3263 if (len
> (bp
->dev
->mtu
+ ETH_HLEN
) &&
3264 skb
->protocol
!= htons(0x8100) &&
3265 skb
->protocol
!= htons(ETH_P_8021AD
)) {
3272 skb_checksum_none_assert(skb
);
3273 if ((bp
->dev
->features
& NETIF_F_RXCSUM
) &&
3274 (status
& (L2_FHDR_STATUS_TCP_SEGMENT
|
3275 L2_FHDR_STATUS_UDP_DATAGRAM
))) {
3277 if (likely((status
& (L2_FHDR_ERRORS_TCP_XSUM
|
3278 L2_FHDR_ERRORS_UDP_XSUM
)) == 0))
3279 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
3281 if ((bp
->dev
->features
& NETIF_F_RXHASH
) &&
3282 ((status
& L2_FHDR_STATUS_USE_RXHASH
) ==
3283 L2_FHDR_STATUS_USE_RXHASH
))
3284 skb_set_hash(skb
, rx_hdr
->l2_fhdr_hash
,
3287 skb_record_rx_queue(skb
, bnapi
- &bp
->bnx2_napi
[0]);
3288 napi_gro_receive(&bnapi
->napi
, skb
);
3292 sw_cons
= BNX2_NEXT_RX_BD(sw_cons
);
3293 sw_prod
= BNX2_NEXT_RX_BD(sw_prod
);
3295 if ((rx_pkt
== budget
))
3298 /* Refresh hw_cons to see if there is new work */
3299 if (sw_cons
== hw_cons
) {
3300 hw_cons
= bnx2_get_hw_rx_cons(bnapi
);
3304 rxr
->rx_cons
= sw_cons
;
3305 rxr
->rx_prod
= sw_prod
;
3308 BNX2_WR16(bp
, rxr
->rx_pg_bidx_addr
, rxr
->rx_pg_prod
);
3310 BNX2_WR16(bp
, rxr
->rx_bidx_addr
, sw_prod
);
3312 BNX2_WR(bp
, rxr
->rx_bseq_addr
, rxr
->rx_prod_bseq
);
3320 /* MSI ISR - The only difference between this and the INTx ISR
3321 * is that the MSI interrupt is always serviced.
3324 bnx2_msi(int irq
, void *dev_instance
)
3326 struct bnx2_napi
*bnapi
= dev_instance
;
3327 struct bnx2
*bp
= bnapi
->bp
;
3329 prefetch(bnapi
->status_blk
.msi
);
3330 BNX2_WR(bp
, BNX2_PCICFG_INT_ACK_CMD
,
3331 BNX2_PCICFG_INT_ACK_CMD_USE_INT_HC_PARAM
|
3332 BNX2_PCICFG_INT_ACK_CMD_MASK_INT
);
3334 /* Return here if interrupt is disabled. */
3335 if (unlikely(atomic_read(&bp
->intr_sem
) != 0))
3338 napi_schedule(&bnapi
->napi
);
3344 bnx2_msi_1shot(int irq
, void *dev_instance
)
3346 struct bnx2_napi
*bnapi
= dev_instance
;
3347 struct bnx2
*bp
= bnapi
->bp
;
3349 prefetch(bnapi
->status_blk
.msi
);
3351 /* Return here if interrupt is disabled. */
3352 if (unlikely(atomic_read(&bp
->intr_sem
) != 0))
3355 napi_schedule(&bnapi
->napi
);
3361 bnx2_interrupt(int irq
, void *dev_instance
)
3363 struct bnx2_napi
*bnapi
= dev_instance
;
3364 struct bnx2
*bp
= bnapi
->bp
;
3365 struct status_block
*sblk
= bnapi
->status_blk
.msi
;
3367 /* When using INTx, it is possible for the interrupt to arrive
3368 * at the CPU before the status block posted prior to the
3369 * interrupt. Reading a register will flush the status block.
3370 * When using MSI, the MSI message will always complete after
3371 * the status block write.
3373 if ((sblk
->status_idx
== bnapi
->last_status_idx
) &&
3374 (BNX2_RD(bp
, BNX2_PCICFG_MISC_STATUS
) &
3375 BNX2_PCICFG_MISC_STATUS_INTA_VALUE
))
3378 BNX2_WR(bp
, BNX2_PCICFG_INT_ACK_CMD
,
3379 BNX2_PCICFG_INT_ACK_CMD_USE_INT_HC_PARAM
|
3380 BNX2_PCICFG_INT_ACK_CMD_MASK_INT
);
3382 /* Read back to deassert IRQ immediately to avoid too many
3383 * spurious interrupts.
3385 BNX2_RD(bp
, BNX2_PCICFG_INT_ACK_CMD
);
3387 /* Return here if interrupt is shared and is disabled. */
3388 if (unlikely(atomic_read(&bp
->intr_sem
) != 0))
3391 if (napi_schedule_prep(&bnapi
->napi
)) {
3392 bnapi
->last_status_idx
= sblk
->status_idx
;
3393 __napi_schedule(&bnapi
->napi
);
3400 bnx2_has_fast_work(struct bnx2_napi
*bnapi
)
3402 struct bnx2_tx_ring_info
*txr
= &bnapi
->tx_ring
;
3403 struct bnx2_rx_ring_info
*rxr
= &bnapi
->rx_ring
;
3405 if ((bnx2_get_hw_rx_cons(bnapi
) != rxr
->rx_cons
) ||
3406 (bnx2_get_hw_tx_cons(bnapi
) != txr
->hw_tx_cons
))
3411 #define STATUS_ATTN_EVENTS (STATUS_ATTN_BITS_LINK_STATE | \
3412 STATUS_ATTN_BITS_TIMER_ABORT)
3415 bnx2_has_work(struct bnx2_napi
*bnapi
)
3417 struct status_block
*sblk
= bnapi
->status_blk
.msi
;
3419 if (bnx2_has_fast_work(bnapi
))
3423 if (bnapi
->cnic_present
&& (bnapi
->cnic_tag
!= sblk
->status_idx
))
3427 if ((sblk
->status_attn_bits
& STATUS_ATTN_EVENTS
) !=
3428 (sblk
->status_attn_bits_ack
& STATUS_ATTN_EVENTS
))
3435 bnx2_chk_missed_msi(struct bnx2
*bp
)
3437 struct bnx2_napi
*bnapi
= &bp
->bnx2_napi
[0];
3440 if (bnx2_has_work(bnapi
)) {
3441 msi_ctrl
= BNX2_RD(bp
, BNX2_PCICFG_MSI_CONTROL
);
3442 if (!(msi_ctrl
& BNX2_PCICFG_MSI_CONTROL_ENABLE
))
3445 if (bnapi
->last_status_idx
== bp
->idle_chk_status_idx
) {
3446 BNX2_WR(bp
, BNX2_PCICFG_MSI_CONTROL
, msi_ctrl
&
3447 ~BNX2_PCICFG_MSI_CONTROL_ENABLE
);
3448 BNX2_WR(bp
, BNX2_PCICFG_MSI_CONTROL
, msi_ctrl
);
3449 bnx2_msi(bp
->irq_tbl
[0].vector
, bnapi
);
3453 bp
->idle_chk_status_idx
= bnapi
->last_status_idx
;
3457 static void bnx2_poll_cnic(struct bnx2
*bp
, struct bnx2_napi
*bnapi
)
3459 struct cnic_ops
*c_ops
;
3461 if (!bnapi
->cnic_present
)
3465 c_ops
= rcu_dereference(bp
->cnic_ops
);
3467 bnapi
->cnic_tag
= c_ops
->cnic_handler(bp
->cnic_data
,
3468 bnapi
->status_blk
.msi
);
3473 static void bnx2_poll_link(struct bnx2
*bp
, struct bnx2_napi
*bnapi
)
3475 struct status_block
*sblk
= bnapi
->status_blk
.msi
;
3476 u32 status_attn_bits
= sblk
->status_attn_bits
;
3477 u32 status_attn_bits_ack
= sblk
->status_attn_bits_ack
;
3479 if ((status_attn_bits
& STATUS_ATTN_EVENTS
) !=
3480 (status_attn_bits_ack
& STATUS_ATTN_EVENTS
)) {
3482 bnx2_phy_int(bp
, bnapi
);
3484 /* This is needed to take care of transient status
3485 * during link changes.
3487 BNX2_WR(bp
, BNX2_HC_COMMAND
,
3488 bp
->hc_cmd
| BNX2_HC_COMMAND_COAL_NOW_WO_INT
);
3489 BNX2_RD(bp
, BNX2_HC_COMMAND
);
3493 static int bnx2_poll_work(struct bnx2
*bp
, struct bnx2_napi
*bnapi
,
3494 int work_done
, int budget
)
3496 struct bnx2_tx_ring_info
*txr
= &bnapi
->tx_ring
;
3497 struct bnx2_rx_ring_info
*rxr
= &bnapi
->rx_ring
;
3499 if (bnx2_get_hw_tx_cons(bnapi
) != txr
->hw_tx_cons
)
3500 bnx2_tx_int(bp
, bnapi
, 0);
3502 if (bnx2_get_hw_rx_cons(bnapi
) != rxr
->rx_cons
)
3503 work_done
+= bnx2_rx_int(bp
, bnapi
, budget
- work_done
);
3508 static int bnx2_poll_msix(struct napi_struct
*napi
, int budget
)
3510 struct bnx2_napi
*bnapi
= container_of(napi
, struct bnx2_napi
, napi
);
3511 struct bnx2
*bp
= bnapi
->bp
;
3513 struct status_block_msix
*sblk
= bnapi
->status_blk
.msix
;
3516 work_done
= bnx2_poll_work(bp
, bnapi
, work_done
, budget
);
3517 if (unlikely(work_done
>= budget
))
3520 bnapi
->last_status_idx
= sblk
->status_idx
;
3521 /* status idx must be read before checking for more work. */
3523 if (likely(!bnx2_has_fast_work(bnapi
))) {
3525 napi_complete(napi
);
3526 BNX2_WR(bp
, BNX2_PCICFG_INT_ACK_CMD
, bnapi
->int_num
|
3527 BNX2_PCICFG_INT_ACK_CMD_INDEX_VALID
|
3528 bnapi
->last_status_idx
);
3535 static int bnx2_poll(struct napi_struct
*napi
, int budget
)
3537 struct bnx2_napi
*bnapi
= container_of(napi
, struct bnx2_napi
, napi
);
3538 struct bnx2
*bp
= bnapi
->bp
;
3540 struct status_block
*sblk
= bnapi
->status_blk
.msi
;
3543 bnx2_poll_link(bp
, bnapi
);
3545 work_done
= bnx2_poll_work(bp
, bnapi
, work_done
, budget
);
3548 bnx2_poll_cnic(bp
, bnapi
);
3551 /* bnapi->last_status_idx is used below to tell the hw how
3552 * much work has been processed, so we must read it before
3553 * checking for more work.
3555 bnapi
->last_status_idx
= sblk
->status_idx
;
3557 if (unlikely(work_done
>= budget
))
3561 if (likely(!bnx2_has_work(bnapi
))) {
3562 napi_complete(napi
);
3563 if (likely(bp
->flags
& BNX2_FLAG_USING_MSI_OR_MSIX
)) {
3564 BNX2_WR(bp
, BNX2_PCICFG_INT_ACK_CMD
,
3565 BNX2_PCICFG_INT_ACK_CMD_INDEX_VALID
|
3566 bnapi
->last_status_idx
);
3569 BNX2_WR(bp
, BNX2_PCICFG_INT_ACK_CMD
,
3570 BNX2_PCICFG_INT_ACK_CMD_INDEX_VALID
|
3571 BNX2_PCICFG_INT_ACK_CMD_MASK_INT
|
3572 bnapi
->last_status_idx
);
3574 BNX2_WR(bp
, BNX2_PCICFG_INT_ACK_CMD
,
3575 BNX2_PCICFG_INT_ACK_CMD_INDEX_VALID
|
3576 bnapi
->last_status_idx
);
3584 /* Called with rtnl_lock from vlan functions and also netif_tx_lock
3585 * from set_multicast.
3588 bnx2_set_rx_mode(struct net_device
*dev
)
3590 struct bnx2
*bp
= netdev_priv(dev
);
3591 u32 rx_mode
, sort_mode
;
3592 struct netdev_hw_addr
*ha
;
3595 if (!netif_running(dev
))
3598 spin_lock_bh(&bp
->phy_lock
);
3600 rx_mode
= bp
->rx_mode
& ~(BNX2_EMAC_RX_MODE_PROMISCUOUS
|
3601 BNX2_EMAC_RX_MODE_KEEP_VLAN_TAG
);
3602 sort_mode
= 1 | BNX2_RPM_SORT_USER0_BC_EN
;
3603 if (!(dev
->features
& NETIF_F_HW_VLAN_CTAG_RX
) &&
3604 (bp
->flags
& BNX2_FLAG_CAN_KEEP_VLAN
))
3605 rx_mode
|= BNX2_EMAC_RX_MODE_KEEP_VLAN_TAG
;
3606 if (dev
->flags
& IFF_PROMISC
) {
3607 /* Promiscuous mode. */
3608 rx_mode
|= BNX2_EMAC_RX_MODE_PROMISCUOUS
;
3609 sort_mode
|= BNX2_RPM_SORT_USER0_PROM_EN
|
3610 BNX2_RPM_SORT_USER0_PROM_VLAN
;
3612 else if (dev
->flags
& IFF_ALLMULTI
) {
3613 for (i
= 0; i
< NUM_MC_HASH_REGISTERS
; i
++) {
3614 BNX2_WR(bp
, BNX2_EMAC_MULTICAST_HASH0
+ (i
* 4),
3617 sort_mode
|= BNX2_RPM_SORT_USER0_MC_EN
;
3620 /* Accept one or more multicast(s). */
3621 u32 mc_filter
[NUM_MC_HASH_REGISTERS
];
3626 memset(mc_filter
, 0, 4 * NUM_MC_HASH_REGISTERS
);
3628 netdev_for_each_mc_addr(ha
, dev
) {
3629 crc
= ether_crc_le(ETH_ALEN
, ha
->addr
);
3631 regidx
= (bit
& 0xe0) >> 5;
3633 mc_filter
[regidx
] |= (1 << bit
);
3636 for (i
= 0; i
< NUM_MC_HASH_REGISTERS
; i
++) {
3637 BNX2_WR(bp
, BNX2_EMAC_MULTICAST_HASH0
+ (i
* 4),
3641 sort_mode
|= BNX2_RPM_SORT_USER0_MC_HSH_EN
;
3644 if (netdev_uc_count(dev
) > BNX2_MAX_UNICAST_ADDRESSES
) {
3645 rx_mode
|= BNX2_EMAC_RX_MODE_PROMISCUOUS
;
3646 sort_mode
|= BNX2_RPM_SORT_USER0_PROM_EN
|
3647 BNX2_RPM_SORT_USER0_PROM_VLAN
;
3648 } else if (!(dev
->flags
& IFF_PROMISC
)) {
3649 /* Add all entries into to the match filter list */
3651 netdev_for_each_uc_addr(ha
, dev
) {
3652 bnx2_set_mac_addr(bp
, ha
->addr
,
3653 i
+ BNX2_START_UNICAST_ADDRESS_INDEX
);
3655 (i
+ BNX2_START_UNICAST_ADDRESS_INDEX
));
3661 if (rx_mode
!= bp
->rx_mode
) {
3662 bp
->rx_mode
= rx_mode
;
3663 BNX2_WR(bp
, BNX2_EMAC_RX_MODE
, rx_mode
);
3666 BNX2_WR(bp
, BNX2_RPM_SORT_USER0
, 0x0);
3667 BNX2_WR(bp
, BNX2_RPM_SORT_USER0
, sort_mode
);
3668 BNX2_WR(bp
, BNX2_RPM_SORT_USER0
, sort_mode
| BNX2_RPM_SORT_USER0_ENA
);
3670 spin_unlock_bh(&bp
->phy_lock
);
3674 check_fw_section(const struct firmware
*fw
,
3675 const struct bnx2_fw_file_section
*section
,
3676 u32 alignment
, bool non_empty
)
3678 u32 offset
= be32_to_cpu(section
->offset
);
3679 u32 len
= be32_to_cpu(section
->len
);
3681 if ((offset
== 0 && len
!= 0) || offset
>= fw
->size
|| offset
& 3)
3683 if ((non_empty
&& len
== 0) || len
> fw
->size
- offset
||
3684 len
& (alignment
- 1))
3690 check_mips_fw_entry(const struct firmware
*fw
,
3691 const struct bnx2_mips_fw_file_entry
*entry
)
3693 if (check_fw_section(fw
, &entry
->text
, 4, true) ||
3694 check_fw_section(fw
, &entry
->data
, 4, false) ||
3695 check_fw_section(fw
, &entry
->rodata
, 4, false))
3700 static void bnx2_release_firmware(struct bnx2
*bp
)
3702 if (bp
->rv2p_firmware
) {
3703 release_firmware(bp
->mips_firmware
);
3704 release_firmware(bp
->rv2p_firmware
);
3705 bp
->rv2p_firmware
= NULL
;
3709 static int bnx2_request_uncached_firmware(struct bnx2
*bp
)
3711 const char *mips_fw_file
, *rv2p_fw_file
;
3712 const struct bnx2_mips_fw_file
*mips_fw
;
3713 const struct bnx2_rv2p_fw_file
*rv2p_fw
;
3716 if (BNX2_CHIP(bp
) == BNX2_CHIP_5709
) {
3717 mips_fw_file
= FW_MIPS_FILE_09
;
3718 if ((BNX2_CHIP_ID(bp
) == BNX2_CHIP_ID_5709_A0
) ||
3719 (BNX2_CHIP_ID(bp
) == BNX2_CHIP_ID_5709_A1
))
3720 rv2p_fw_file
= FW_RV2P_FILE_09_Ax
;
3722 rv2p_fw_file
= FW_RV2P_FILE_09
;
3724 mips_fw_file
= FW_MIPS_FILE_06
;
3725 rv2p_fw_file
= FW_RV2P_FILE_06
;
3728 rc
= request_firmware(&bp
->mips_firmware
, mips_fw_file
, &bp
->pdev
->dev
);
3730 pr_err("Can't load firmware file \"%s\"\n", mips_fw_file
);
3734 rc
= request_firmware(&bp
->rv2p_firmware
, rv2p_fw_file
, &bp
->pdev
->dev
);
3736 pr_err("Can't load firmware file \"%s\"\n", rv2p_fw_file
);
3737 goto err_release_mips_firmware
;
3739 mips_fw
= (const struct bnx2_mips_fw_file
*) bp
->mips_firmware
->data
;
3740 rv2p_fw
= (const struct bnx2_rv2p_fw_file
*) bp
->rv2p_firmware
->data
;
3741 if (bp
->mips_firmware
->size
< sizeof(*mips_fw
) ||
3742 check_mips_fw_entry(bp
->mips_firmware
, &mips_fw
->com
) ||
3743 check_mips_fw_entry(bp
->mips_firmware
, &mips_fw
->cp
) ||
3744 check_mips_fw_entry(bp
->mips_firmware
, &mips_fw
->rxp
) ||
3745 check_mips_fw_entry(bp
->mips_firmware
, &mips_fw
->tpat
) ||
3746 check_mips_fw_entry(bp
->mips_firmware
, &mips_fw
->txp
)) {
3747 pr_err("Firmware file \"%s\" is invalid\n", mips_fw_file
);
3749 goto err_release_firmware
;
3751 if (bp
->rv2p_firmware
->size
< sizeof(*rv2p_fw
) ||
3752 check_fw_section(bp
->rv2p_firmware
, &rv2p_fw
->proc1
.rv2p
, 8, true) ||
3753 check_fw_section(bp
->rv2p_firmware
, &rv2p_fw
->proc2
.rv2p
, 8, true)) {
3754 pr_err("Firmware file \"%s\" is invalid\n", rv2p_fw_file
);
3756 goto err_release_firmware
;
3761 err_release_firmware
:
3762 release_firmware(bp
->rv2p_firmware
);
3763 bp
->rv2p_firmware
= NULL
;
3764 err_release_mips_firmware
:
3765 release_firmware(bp
->mips_firmware
);
3769 static int bnx2_request_firmware(struct bnx2
*bp
)
3771 return bp
->rv2p_firmware
? 0 : bnx2_request_uncached_firmware(bp
);
3775 rv2p_fw_fixup(u32 rv2p_proc
, int idx
, u32 loc
, u32 rv2p_code
)
3778 case RV2P_P1_FIXUP_PAGE_SIZE_IDX
:
3779 rv2p_code
&= ~RV2P_BD_PAGE_SIZE_MSK
;
3780 rv2p_code
|= RV2P_BD_PAGE_SIZE
;
3787 load_rv2p_fw(struct bnx2
*bp
, u32 rv2p_proc
,
3788 const struct bnx2_rv2p_fw_file_entry
*fw_entry
)
3790 u32 rv2p_code_len
, file_offset
;
3795 rv2p_code_len
= be32_to_cpu(fw_entry
->rv2p
.len
);
3796 file_offset
= be32_to_cpu(fw_entry
->rv2p
.offset
);
3798 rv2p_code
= (__be32
*)(bp
->rv2p_firmware
->data
+ file_offset
);
3800 if (rv2p_proc
== RV2P_PROC1
) {
3801 cmd
= BNX2_RV2P_PROC1_ADDR_CMD_RDWR
;
3802 addr
= BNX2_RV2P_PROC1_ADDR_CMD
;
3804 cmd
= BNX2_RV2P_PROC2_ADDR_CMD_RDWR
;
3805 addr
= BNX2_RV2P_PROC2_ADDR_CMD
;
3808 for (i
= 0; i
< rv2p_code_len
; i
+= 8) {
3809 BNX2_WR(bp
, BNX2_RV2P_INSTR_HIGH
, be32_to_cpu(*rv2p_code
));
3811 BNX2_WR(bp
, BNX2_RV2P_INSTR_LOW
, be32_to_cpu(*rv2p_code
));
3814 val
= (i
/ 8) | cmd
;
3815 BNX2_WR(bp
, addr
, val
);
3818 rv2p_code
= (__be32
*)(bp
->rv2p_firmware
->data
+ file_offset
);
3819 for (i
= 0; i
< 8; i
++) {
3822 loc
= be32_to_cpu(fw_entry
->fixup
[i
]);
3823 if (loc
&& ((loc
* 4) < rv2p_code_len
)) {
3824 code
= be32_to_cpu(*(rv2p_code
+ loc
- 1));
3825 BNX2_WR(bp
, BNX2_RV2P_INSTR_HIGH
, code
);
3826 code
= be32_to_cpu(*(rv2p_code
+ loc
));
3827 code
= rv2p_fw_fixup(rv2p_proc
, i
, loc
, code
);
3828 BNX2_WR(bp
, BNX2_RV2P_INSTR_LOW
, code
);
3830 val
= (loc
/ 2) | cmd
;
3831 BNX2_WR(bp
, addr
, val
);
3835 /* Reset the processor, un-stall is done later. */
3836 if (rv2p_proc
== RV2P_PROC1
) {
3837 BNX2_WR(bp
, BNX2_RV2P_COMMAND
, BNX2_RV2P_COMMAND_PROC1_RESET
);
3840 BNX2_WR(bp
, BNX2_RV2P_COMMAND
, BNX2_RV2P_COMMAND_PROC2_RESET
);
3847 load_cpu_fw(struct bnx2
*bp
, const struct cpu_reg
*cpu_reg
,
3848 const struct bnx2_mips_fw_file_entry
*fw_entry
)
3850 u32 addr
, len
, file_offset
;
3856 val
= bnx2_reg_rd_ind(bp
, cpu_reg
->mode
);
3857 val
|= cpu_reg
->mode_value_halt
;
3858 bnx2_reg_wr_ind(bp
, cpu_reg
->mode
, val
);
3859 bnx2_reg_wr_ind(bp
, cpu_reg
->state
, cpu_reg
->state_value_clear
);
3861 /* Load the Text area. */
3862 addr
= be32_to_cpu(fw_entry
->text
.addr
);
3863 len
= be32_to_cpu(fw_entry
->text
.len
);
3864 file_offset
= be32_to_cpu(fw_entry
->text
.offset
);
3865 data
= (__be32
*)(bp
->mips_firmware
->data
+ file_offset
);
3867 offset
= cpu_reg
->spad_base
+ (addr
- cpu_reg
->mips_view_base
);
3871 for (j
= 0; j
< (len
/ 4); j
++, offset
+= 4)
3872 bnx2_reg_wr_ind(bp
, offset
, be32_to_cpu(data
[j
]));
3875 /* Load the Data area. */
3876 addr
= be32_to_cpu(fw_entry
->data
.addr
);
3877 len
= be32_to_cpu(fw_entry
->data
.len
);
3878 file_offset
= be32_to_cpu(fw_entry
->data
.offset
);
3879 data
= (__be32
*)(bp
->mips_firmware
->data
+ file_offset
);
3881 offset
= cpu_reg
->spad_base
+ (addr
- cpu_reg
->mips_view_base
);
3885 for (j
= 0; j
< (len
/ 4); j
++, offset
+= 4)
3886 bnx2_reg_wr_ind(bp
, offset
, be32_to_cpu(data
[j
]));
3889 /* Load the Read-Only area. */
3890 addr
= be32_to_cpu(fw_entry
->rodata
.addr
);
3891 len
= be32_to_cpu(fw_entry
->rodata
.len
);
3892 file_offset
= be32_to_cpu(fw_entry
->rodata
.offset
);
3893 data
= (__be32
*)(bp
->mips_firmware
->data
+ file_offset
);
3895 offset
= cpu_reg
->spad_base
+ (addr
- cpu_reg
->mips_view_base
);
3899 for (j
= 0; j
< (len
/ 4); j
++, offset
+= 4)
3900 bnx2_reg_wr_ind(bp
, offset
, be32_to_cpu(data
[j
]));
3903 /* Clear the pre-fetch instruction. */
3904 bnx2_reg_wr_ind(bp
, cpu_reg
->inst
, 0);
3906 val
= be32_to_cpu(fw_entry
->start_addr
);
3907 bnx2_reg_wr_ind(bp
, cpu_reg
->pc
, val
);
3909 /* Start the CPU. */
3910 val
= bnx2_reg_rd_ind(bp
, cpu_reg
->mode
);
3911 val
&= ~cpu_reg
->mode_value_halt
;
3912 bnx2_reg_wr_ind(bp
, cpu_reg
->state
, cpu_reg
->state_value_clear
);
3913 bnx2_reg_wr_ind(bp
, cpu_reg
->mode
, val
);
3919 bnx2_init_cpus(struct bnx2
*bp
)
3921 const struct bnx2_mips_fw_file
*mips_fw
=
3922 (const struct bnx2_mips_fw_file
*) bp
->mips_firmware
->data
;
3923 const struct bnx2_rv2p_fw_file
*rv2p_fw
=
3924 (const struct bnx2_rv2p_fw_file
*) bp
->rv2p_firmware
->data
;
3927 /* Initialize the RV2P processor. */
3928 load_rv2p_fw(bp
, RV2P_PROC1
, &rv2p_fw
->proc1
);
3929 load_rv2p_fw(bp
, RV2P_PROC2
, &rv2p_fw
->proc2
);
3931 /* Initialize the RX Processor. */
3932 rc
= load_cpu_fw(bp
, &cpu_reg_rxp
, &mips_fw
->rxp
);
3936 /* Initialize the TX Processor. */
3937 rc
= load_cpu_fw(bp
, &cpu_reg_txp
, &mips_fw
->txp
);
3941 /* Initialize the TX Patch-up Processor. */
3942 rc
= load_cpu_fw(bp
, &cpu_reg_tpat
, &mips_fw
->tpat
);
3946 /* Initialize the Completion Processor. */
3947 rc
= load_cpu_fw(bp
, &cpu_reg_com
, &mips_fw
->com
);
3951 /* Initialize the Command Processor. */
3952 rc
= load_cpu_fw(bp
, &cpu_reg_cp
, &mips_fw
->cp
);
3959 bnx2_setup_wol(struct bnx2
*bp
)
3968 autoneg
= bp
->autoneg
;
3969 advertising
= bp
->advertising
;
3971 if (bp
->phy_port
== PORT_TP
) {
3972 bp
->autoneg
= AUTONEG_SPEED
;
3973 bp
->advertising
= ADVERTISED_10baseT_Half
|
3974 ADVERTISED_10baseT_Full
|
3975 ADVERTISED_100baseT_Half
|
3976 ADVERTISED_100baseT_Full
|
3980 spin_lock_bh(&bp
->phy_lock
);
3981 bnx2_setup_phy(bp
, bp
->phy_port
);
3982 spin_unlock_bh(&bp
->phy_lock
);
3984 bp
->autoneg
= autoneg
;
3985 bp
->advertising
= advertising
;
3987 bnx2_set_mac_addr(bp
, bp
->dev
->dev_addr
, 0);
3989 val
= BNX2_RD(bp
, BNX2_EMAC_MODE
);
3991 /* Enable port mode. */
3992 val
&= ~BNX2_EMAC_MODE_PORT
;
3993 val
|= BNX2_EMAC_MODE_MPKT_RCVD
|
3994 BNX2_EMAC_MODE_ACPI_RCVD
|
3995 BNX2_EMAC_MODE_MPKT
;
3996 if (bp
->phy_port
== PORT_TP
) {
3997 val
|= BNX2_EMAC_MODE_PORT_MII
;
3999 val
|= BNX2_EMAC_MODE_PORT_GMII
;
4000 if (bp
->line_speed
== SPEED_2500
)
4001 val
|= BNX2_EMAC_MODE_25G_MODE
;
4004 BNX2_WR(bp
, BNX2_EMAC_MODE
, val
);
4006 /* receive all multicast */
4007 for (i
= 0; i
< NUM_MC_HASH_REGISTERS
; i
++) {
4008 BNX2_WR(bp
, BNX2_EMAC_MULTICAST_HASH0
+ (i
* 4),
4011 BNX2_WR(bp
, BNX2_EMAC_RX_MODE
, BNX2_EMAC_RX_MODE_SORT_MODE
);
4013 val
= 1 | BNX2_RPM_SORT_USER0_BC_EN
| BNX2_RPM_SORT_USER0_MC_EN
;
4014 BNX2_WR(bp
, BNX2_RPM_SORT_USER0
, 0x0);
4015 BNX2_WR(bp
, BNX2_RPM_SORT_USER0
, val
);
4016 BNX2_WR(bp
, BNX2_RPM_SORT_USER0
, val
| BNX2_RPM_SORT_USER0_ENA
);
4018 /* Need to enable EMAC and RPM for WOL. */
4019 BNX2_WR(bp
, BNX2_MISC_ENABLE_SET_BITS
,
4020 BNX2_MISC_ENABLE_SET_BITS_RX_PARSER_MAC_ENABLE
|
4021 BNX2_MISC_ENABLE_SET_BITS_TX_HEADER_Q_ENABLE
|
4022 BNX2_MISC_ENABLE_SET_BITS_EMAC_ENABLE
);
4024 val
= BNX2_RD(bp
, BNX2_RPM_CONFIG
);
4025 val
&= ~BNX2_RPM_CONFIG_ACPI_ENA
;
4026 BNX2_WR(bp
, BNX2_RPM_CONFIG
, val
);
4028 wol_msg
= BNX2_DRV_MSG_CODE_SUSPEND_WOL
;
4030 wol_msg
= BNX2_DRV_MSG_CODE_SUSPEND_NO_WOL
;
4033 if (!(bp
->flags
& BNX2_FLAG_NO_WOL
)) {
4036 wol_msg
|= BNX2_DRV_MSG_DATA_WAIT3
;
4037 if (bp
->fw_last_msg
|| BNX2_CHIP(bp
) != BNX2_CHIP_5709
) {
4038 bnx2_fw_sync(bp
, wol_msg
, 1, 0);
4041 /* Tell firmware not to power down the PHY yet, otherwise
4042 * the chip will take a long time to respond to MMIO reads.
4044 val
= bnx2_shmem_rd(bp
, BNX2_PORT_FEATURE
);
4045 bnx2_shmem_wr(bp
, BNX2_PORT_FEATURE
,
4046 val
| BNX2_PORT_FEATURE_ASF_ENABLED
);
4047 bnx2_fw_sync(bp
, wol_msg
, 1, 0);
4048 bnx2_shmem_wr(bp
, BNX2_PORT_FEATURE
, val
);
4054 bnx2_set_power_state(struct bnx2
*bp
, pci_power_t state
)
4060 pci_enable_wake(bp
->pdev
, PCI_D0
, false);
4061 pci_set_power_state(bp
->pdev
, PCI_D0
);
4063 val
= BNX2_RD(bp
, BNX2_EMAC_MODE
);
4064 val
|= BNX2_EMAC_MODE_MPKT_RCVD
| BNX2_EMAC_MODE_ACPI_RCVD
;
4065 val
&= ~BNX2_EMAC_MODE_MPKT
;
4066 BNX2_WR(bp
, BNX2_EMAC_MODE
, val
);
4068 val
= BNX2_RD(bp
, BNX2_RPM_CONFIG
);
4069 val
&= ~BNX2_RPM_CONFIG_ACPI_ENA
;
4070 BNX2_WR(bp
, BNX2_RPM_CONFIG
, val
);
4075 pci_wake_from_d3(bp
->pdev
, bp
->wol
);
4076 if ((BNX2_CHIP_ID(bp
) == BNX2_CHIP_ID_5706_A0
) ||
4077 (BNX2_CHIP_ID(bp
) == BNX2_CHIP_ID_5706_A1
)) {
4080 pci_set_power_state(bp
->pdev
, PCI_D3hot
);
4084 if (!bp
->fw_last_msg
&& BNX2_CHIP(bp
) == BNX2_CHIP_5709
) {
4087 /* Tell firmware not to power down the PHY yet,
4088 * otherwise the other port may not respond to
4091 val
= bnx2_shmem_rd(bp
, BNX2_BC_STATE_CONDITION
);
4092 val
&= ~BNX2_CONDITION_PM_STATE_MASK
;
4093 val
|= BNX2_CONDITION_PM_STATE_UNPREP
;
4094 bnx2_shmem_wr(bp
, BNX2_BC_STATE_CONDITION
, val
);
4096 pci_set_power_state(bp
->pdev
, PCI_D3hot
);
4098 /* No more memory access after this point until
4099 * device is brought back to D0.
4110 bnx2_acquire_nvram_lock(struct bnx2
*bp
)
4115 /* Request access to the flash interface. */
4116 BNX2_WR(bp
, BNX2_NVM_SW_ARB
, BNX2_NVM_SW_ARB_ARB_REQ_SET2
);
4117 for (j
= 0; j
< NVRAM_TIMEOUT_COUNT
; j
++) {
4118 val
= BNX2_RD(bp
, BNX2_NVM_SW_ARB
);
4119 if (val
& BNX2_NVM_SW_ARB_ARB_ARB2
)
4125 if (j
>= NVRAM_TIMEOUT_COUNT
)
4132 bnx2_release_nvram_lock(struct bnx2
*bp
)
4137 /* Relinquish nvram interface. */
4138 BNX2_WR(bp
, BNX2_NVM_SW_ARB
, BNX2_NVM_SW_ARB_ARB_REQ_CLR2
);
4140 for (j
= 0; j
< NVRAM_TIMEOUT_COUNT
; j
++) {
4141 val
= BNX2_RD(bp
, BNX2_NVM_SW_ARB
);
4142 if (!(val
& BNX2_NVM_SW_ARB_ARB_ARB2
))
4148 if (j
>= NVRAM_TIMEOUT_COUNT
)
4156 bnx2_enable_nvram_write(struct bnx2
*bp
)
4160 val
= BNX2_RD(bp
, BNX2_MISC_CFG
);
4161 BNX2_WR(bp
, BNX2_MISC_CFG
, val
| BNX2_MISC_CFG_NVM_WR_EN_PCI
);
4163 if (bp
->flash_info
->flags
& BNX2_NV_WREN
) {
4166 BNX2_WR(bp
, BNX2_NVM_COMMAND
, BNX2_NVM_COMMAND_DONE
);
4167 BNX2_WR(bp
, BNX2_NVM_COMMAND
,
4168 BNX2_NVM_COMMAND_WREN
| BNX2_NVM_COMMAND_DOIT
);
4170 for (j
= 0; j
< NVRAM_TIMEOUT_COUNT
; j
++) {
4173 val
= BNX2_RD(bp
, BNX2_NVM_COMMAND
);
4174 if (val
& BNX2_NVM_COMMAND_DONE
)
4178 if (j
>= NVRAM_TIMEOUT_COUNT
)
4185 bnx2_disable_nvram_write(struct bnx2
*bp
)
4189 val
= BNX2_RD(bp
, BNX2_MISC_CFG
);
4190 BNX2_WR(bp
, BNX2_MISC_CFG
, val
& ~BNX2_MISC_CFG_NVM_WR_EN
);
4195 bnx2_enable_nvram_access(struct bnx2
*bp
)
4199 val
= BNX2_RD(bp
, BNX2_NVM_ACCESS_ENABLE
);
4200 /* Enable both bits, even on read. */
4201 BNX2_WR(bp
, BNX2_NVM_ACCESS_ENABLE
,
4202 val
| BNX2_NVM_ACCESS_ENABLE_EN
| BNX2_NVM_ACCESS_ENABLE_WR_EN
);
4206 bnx2_disable_nvram_access(struct bnx2
*bp
)
4210 val
= BNX2_RD(bp
, BNX2_NVM_ACCESS_ENABLE
);
4211 /* Disable both bits, even after read. */
4212 BNX2_WR(bp
, BNX2_NVM_ACCESS_ENABLE
,
4213 val
& ~(BNX2_NVM_ACCESS_ENABLE_EN
|
4214 BNX2_NVM_ACCESS_ENABLE_WR_EN
));
4218 bnx2_nvram_erase_page(struct bnx2
*bp
, u32 offset
)
4223 if (bp
->flash_info
->flags
& BNX2_NV_BUFFERED
)
4224 /* Buffered flash, no erase needed */
4227 /* Build an erase command */
4228 cmd
= BNX2_NVM_COMMAND_ERASE
| BNX2_NVM_COMMAND_WR
|
4229 BNX2_NVM_COMMAND_DOIT
;
4231 /* Need to clear DONE bit separately. */
4232 BNX2_WR(bp
, BNX2_NVM_COMMAND
, BNX2_NVM_COMMAND_DONE
);
4234 /* Address of the NVRAM to read from. */
4235 BNX2_WR(bp
, BNX2_NVM_ADDR
, offset
& BNX2_NVM_ADDR_NVM_ADDR_VALUE
);
4237 /* Issue an erase command. */
4238 BNX2_WR(bp
, BNX2_NVM_COMMAND
, cmd
);
4240 /* Wait for completion. */
4241 for (j
= 0; j
< NVRAM_TIMEOUT_COUNT
; j
++) {
4246 val
= BNX2_RD(bp
, BNX2_NVM_COMMAND
);
4247 if (val
& BNX2_NVM_COMMAND_DONE
)
4251 if (j
>= NVRAM_TIMEOUT_COUNT
)
4258 bnx2_nvram_read_dword(struct bnx2
*bp
, u32 offset
, u8
*ret_val
, u32 cmd_flags
)
4263 /* Build the command word. */
4264 cmd
= BNX2_NVM_COMMAND_DOIT
| cmd_flags
;
4266 /* Calculate an offset of a buffered flash, not needed for 5709. */
4267 if (bp
->flash_info
->flags
& BNX2_NV_TRANSLATE
) {
4268 offset
= ((offset
/ bp
->flash_info
->page_size
) <<
4269 bp
->flash_info
->page_bits
) +
4270 (offset
% bp
->flash_info
->page_size
);
4273 /* Need to clear DONE bit separately. */
4274 BNX2_WR(bp
, BNX2_NVM_COMMAND
, BNX2_NVM_COMMAND_DONE
);
4276 /* Address of the NVRAM to read from. */
4277 BNX2_WR(bp
, BNX2_NVM_ADDR
, offset
& BNX2_NVM_ADDR_NVM_ADDR_VALUE
);
4279 /* Issue a read command. */
4280 BNX2_WR(bp
, BNX2_NVM_COMMAND
, cmd
);
4282 /* Wait for completion. */
4283 for (j
= 0; j
< NVRAM_TIMEOUT_COUNT
; j
++) {
4288 val
= BNX2_RD(bp
, BNX2_NVM_COMMAND
);
4289 if (val
& BNX2_NVM_COMMAND_DONE
) {
4290 __be32 v
= cpu_to_be32(BNX2_RD(bp
, BNX2_NVM_READ
));
4291 memcpy(ret_val
, &v
, 4);
4295 if (j
>= NVRAM_TIMEOUT_COUNT
)
4303 bnx2_nvram_write_dword(struct bnx2
*bp
, u32 offset
, u8
*val
, u32 cmd_flags
)
4309 /* Build the command word. */
4310 cmd
= BNX2_NVM_COMMAND_DOIT
| BNX2_NVM_COMMAND_WR
| cmd_flags
;
4312 /* Calculate an offset of a buffered flash, not needed for 5709. */
4313 if (bp
->flash_info
->flags
& BNX2_NV_TRANSLATE
) {
4314 offset
= ((offset
/ bp
->flash_info
->page_size
) <<
4315 bp
->flash_info
->page_bits
) +
4316 (offset
% bp
->flash_info
->page_size
);
4319 /* Need to clear DONE bit separately. */
4320 BNX2_WR(bp
, BNX2_NVM_COMMAND
, BNX2_NVM_COMMAND_DONE
);
4322 memcpy(&val32
, val
, 4);
4324 /* Write the data. */
4325 BNX2_WR(bp
, BNX2_NVM_WRITE
, be32_to_cpu(val32
));
4327 /* Address of the NVRAM to write to. */
4328 BNX2_WR(bp
, BNX2_NVM_ADDR
, offset
& BNX2_NVM_ADDR_NVM_ADDR_VALUE
);
4330 /* Issue the write command. */
4331 BNX2_WR(bp
, BNX2_NVM_COMMAND
, cmd
);
4333 /* Wait for completion. */
4334 for (j
= 0; j
< NVRAM_TIMEOUT_COUNT
; j
++) {
4337 if (BNX2_RD(bp
, BNX2_NVM_COMMAND
) & BNX2_NVM_COMMAND_DONE
)
4340 if (j
>= NVRAM_TIMEOUT_COUNT
)
4347 bnx2_init_nvram(struct bnx2
*bp
)
4350 int j
, entry_count
, rc
= 0;
4351 const struct flash_spec
*flash
;
4353 if (BNX2_CHIP(bp
) == BNX2_CHIP_5709
) {
4354 bp
->flash_info
= &flash_5709
;
4355 goto get_flash_size
;
4358 /* Determine the selected interface. */
4359 val
= BNX2_RD(bp
, BNX2_NVM_CFG1
);
4361 entry_count
= ARRAY_SIZE(flash_table
);
4363 if (val
& 0x40000000) {
4365 /* Flash interface has been reconfigured */
4366 for (j
= 0, flash
= &flash_table
[0]; j
< entry_count
;
4368 if ((val
& FLASH_BACKUP_STRAP_MASK
) ==
4369 (flash
->config1
& FLASH_BACKUP_STRAP_MASK
)) {
4370 bp
->flash_info
= flash
;
4377 /* Not yet been reconfigured */
4379 if (val
& (1 << 23))
4380 mask
= FLASH_BACKUP_STRAP_MASK
;
4382 mask
= FLASH_STRAP_MASK
;
4384 for (j
= 0, flash
= &flash_table
[0]; j
< entry_count
;
4387 if ((val
& mask
) == (flash
->strapping
& mask
)) {
4388 bp
->flash_info
= flash
;
4390 /* Request access to the flash interface. */
4391 if ((rc
= bnx2_acquire_nvram_lock(bp
)) != 0)
4394 /* Enable access to flash interface */
4395 bnx2_enable_nvram_access(bp
);
4397 /* Reconfigure the flash interface */
4398 BNX2_WR(bp
, BNX2_NVM_CFG1
, flash
->config1
);
4399 BNX2_WR(bp
, BNX2_NVM_CFG2
, flash
->config2
);
4400 BNX2_WR(bp
, BNX2_NVM_CFG3
, flash
->config3
);
4401 BNX2_WR(bp
, BNX2_NVM_WRITE1
, flash
->write1
);
4403 /* Disable access to flash interface */
4404 bnx2_disable_nvram_access(bp
);
4405 bnx2_release_nvram_lock(bp
);
4410 } /* if (val & 0x40000000) */
4412 if (j
== entry_count
) {
4413 bp
->flash_info
= NULL
;
4414 pr_alert("Unknown flash/EEPROM type\n");
4419 val
= bnx2_shmem_rd(bp
, BNX2_SHARED_HW_CFG_CONFIG2
);
4420 val
&= BNX2_SHARED_HW_CFG2_NVM_SIZE_MASK
;
4422 bp
->flash_size
= val
;
4424 bp
->flash_size
= bp
->flash_info
->total_size
;
4430 bnx2_nvram_read(struct bnx2
*bp
, u32 offset
, u8
*ret_buf
,
4434 u32 cmd_flags
, offset32
, len32
, extra
;
4439 /* Request access to the flash interface. */
4440 if ((rc
= bnx2_acquire_nvram_lock(bp
)) != 0)
4443 /* Enable access to flash interface */
4444 bnx2_enable_nvram_access(bp
);
4457 pre_len
= 4 - (offset
& 3);
4459 if (pre_len
>= len32
) {
4461 cmd_flags
= BNX2_NVM_COMMAND_FIRST
|
4462 BNX2_NVM_COMMAND_LAST
;
4465 cmd_flags
= BNX2_NVM_COMMAND_FIRST
;
4468 rc
= bnx2_nvram_read_dword(bp
, offset32
, buf
, cmd_flags
);
4473 memcpy(ret_buf
, buf
+ (offset
& 3), pre_len
);
4480 extra
= 4 - (len32
& 3);
4481 len32
= (len32
+ 4) & ~3;
4488 cmd_flags
= BNX2_NVM_COMMAND_LAST
;
4490 cmd_flags
= BNX2_NVM_COMMAND_FIRST
|
4491 BNX2_NVM_COMMAND_LAST
;
4493 rc
= bnx2_nvram_read_dword(bp
, offset32
, buf
, cmd_flags
);
4495 memcpy(ret_buf
, buf
, 4 - extra
);
4497 else if (len32
> 0) {
4500 /* Read the first word. */
4504 cmd_flags
= BNX2_NVM_COMMAND_FIRST
;
4506 rc
= bnx2_nvram_read_dword(bp
, offset32
, ret_buf
, cmd_flags
);
4508 /* Advance to the next dword. */
4513 while (len32
> 4 && rc
== 0) {
4514 rc
= bnx2_nvram_read_dword(bp
, offset32
, ret_buf
, 0);
4516 /* Advance to the next dword. */
4525 cmd_flags
= BNX2_NVM_COMMAND_LAST
;
4526 rc
= bnx2_nvram_read_dword(bp
, offset32
, buf
, cmd_flags
);
4528 memcpy(ret_buf
, buf
, 4 - extra
);
4531 /* Disable access to flash interface */
4532 bnx2_disable_nvram_access(bp
);
4534 bnx2_release_nvram_lock(bp
);
4540 bnx2_nvram_write(struct bnx2
*bp
, u32 offset
, u8
*data_buf
,
4543 u32 written
, offset32
, len32
;
4544 u8
*buf
, start
[4], end
[4], *align_buf
= NULL
, *flash_buffer
= NULL
;
4546 int align_start
, align_end
;
4551 align_start
= align_end
= 0;
4553 if ((align_start
= (offset32
& 3))) {
4555 len32
+= align_start
;
4558 if ((rc
= bnx2_nvram_read(bp
, offset32
, start
, 4)))
4563 align_end
= 4 - (len32
& 3);
4565 if ((rc
= bnx2_nvram_read(bp
, offset32
+ len32
- 4, end
, 4)))
4569 if (align_start
|| align_end
) {
4570 align_buf
= kmalloc(len32
, GFP_KERNEL
);
4571 if (align_buf
== NULL
)
4574 memcpy(align_buf
, start
, 4);
4577 memcpy(align_buf
+ len32
- 4, end
, 4);
4579 memcpy(align_buf
+ align_start
, data_buf
, buf_size
);
4583 if (!(bp
->flash_info
->flags
& BNX2_NV_BUFFERED
)) {
4584 flash_buffer
= kmalloc(264, GFP_KERNEL
);
4585 if (flash_buffer
== NULL
) {
4587 goto nvram_write_end
;
4592 while ((written
< len32
) && (rc
== 0)) {
4593 u32 page_start
, page_end
, data_start
, data_end
;
4594 u32 addr
, cmd_flags
;
4597 /* Find the page_start addr */
4598 page_start
= offset32
+ written
;
4599 page_start
-= (page_start
% bp
->flash_info
->page_size
);
4600 /* Find the page_end addr */
4601 page_end
= page_start
+ bp
->flash_info
->page_size
;
4602 /* Find the data_start addr */
4603 data_start
= (written
== 0) ? offset32
: page_start
;
4604 /* Find the data_end addr */
4605 data_end
= (page_end
> offset32
+ len32
) ?
4606 (offset32
+ len32
) : page_end
;
4608 /* Request access to the flash interface. */
4609 if ((rc
= bnx2_acquire_nvram_lock(bp
)) != 0)
4610 goto nvram_write_end
;
4612 /* Enable access to flash interface */
4613 bnx2_enable_nvram_access(bp
);
4615 cmd_flags
= BNX2_NVM_COMMAND_FIRST
;
4616 if (!(bp
->flash_info
->flags
& BNX2_NV_BUFFERED
)) {
4619 /* Read the whole page into the buffer
4620 * (non-buffer flash only) */
4621 for (j
= 0; j
< bp
->flash_info
->page_size
; j
+= 4) {
4622 if (j
== (bp
->flash_info
->page_size
- 4)) {
4623 cmd_flags
|= BNX2_NVM_COMMAND_LAST
;
4625 rc
= bnx2_nvram_read_dword(bp
,
4631 goto nvram_write_end
;
4637 /* Enable writes to flash interface (unlock write-protect) */
4638 if ((rc
= bnx2_enable_nvram_write(bp
)) != 0)
4639 goto nvram_write_end
;
4641 /* Loop to write back the buffer data from page_start to
4644 if (!(bp
->flash_info
->flags
& BNX2_NV_BUFFERED
)) {
4645 /* Erase the page */
4646 if ((rc
= bnx2_nvram_erase_page(bp
, page_start
)) != 0)
4647 goto nvram_write_end
;
4649 /* Re-enable the write again for the actual write */
4650 bnx2_enable_nvram_write(bp
);
4652 for (addr
= page_start
; addr
< data_start
;
4653 addr
+= 4, i
+= 4) {
4655 rc
= bnx2_nvram_write_dword(bp
, addr
,
4656 &flash_buffer
[i
], cmd_flags
);
4659 goto nvram_write_end
;
4665 /* Loop to write the new data from data_start to data_end */
4666 for (addr
= data_start
; addr
< data_end
; addr
+= 4, i
+= 4) {
4667 if ((addr
== page_end
- 4) ||
4668 ((bp
->flash_info
->flags
& BNX2_NV_BUFFERED
) &&
4669 (addr
== data_end
- 4))) {
4671 cmd_flags
|= BNX2_NVM_COMMAND_LAST
;
4673 rc
= bnx2_nvram_write_dword(bp
, addr
, buf
,
4677 goto nvram_write_end
;
4683 /* Loop to write back the buffer data from data_end
4685 if (!(bp
->flash_info
->flags
& BNX2_NV_BUFFERED
)) {
4686 for (addr
= data_end
; addr
< page_end
;
4687 addr
+= 4, i
+= 4) {
4689 if (addr
== page_end
-4) {
4690 cmd_flags
= BNX2_NVM_COMMAND_LAST
;
4692 rc
= bnx2_nvram_write_dword(bp
, addr
,
4693 &flash_buffer
[i
], cmd_flags
);
4696 goto nvram_write_end
;
4702 /* Disable writes to flash interface (lock write-protect) */
4703 bnx2_disable_nvram_write(bp
);
4705 /* Disable access to flash interface */
4706 bnx2_disable_nvram_access(bp
);
4707 bnx2_release_nvram_lock(bp
);
4709 /* Increment written */
4710 written
+= data_end
- data_start
;
4714 kfree(flash_buffer
);
4720 bnx2_init_fw_cap(struct bnx2
*bp
)
4724 bp
->phy_flags
&= ~BNX2_PHY_FLAG_REMOTE_PHY_CAP
;
4725 bp
->flags
&= ~BNX2_FLAG_CAN_KEEP_VLAN
;
4727 if (!(bp
->flags
& BNX2_FLAG_ASF_ENABLE
))
4728 bp
->flags
|= BNX2_FLAG_CAN_KEEP_VLAN
;
4730 val
= bnx2_shmem_rd(bp
, BNX2_FW_CAP_MB
);
4731 if ((val
& BNX2_FW_CAP_SIGNATURE_MASK
) != BNX2_FW_CAP_SIGNATURE
)
4734 if ((val
& BNX2_FW_CAP_CAN_KEEP_VLAN
) == BNX2_FW_CAP_CAN_KEEP_VLAN
) {
4735 bp
->flags
|= BNX2_FLAG_CAN_KEEP_VLAN
;
4736 sig
|= BNX2_DRV_ACK_CAP_SIGNATURE
| BNX2_FW_CAP_CAN_KEEP_VLAN
;
4739 if ((bp
->phy_flags
& BNX2_PHY_FLAG_SERDES
) &&
4740 (val
& BNX2_FW_CAP_REMOTE_PHY_CAPABLE
)) {
4743 bp
->phy_flags
|= BNX2_PHY_FLAG_REMOTE_PHY_CAP
;
4745 link
= bnx2_shmem_rd(bp
, BNX2_LINK_STATUS
);
4746 if (link
& BNX2_LINK_STATUS_SERDES_LINK
)
4747 bp
->phy_port
= PORT_FIBRE
;
4749 bp
->phy_port
= PORT_TP
;
4751 sig
|= BNX2_DRV_ACK_CAP_SIGNATURE
|
4752 BNX2_FW_CAP_REMOTE_PHY_CAPABLE
;
4755 if (netif_running(bp
->dev
) && sig
)
4756 bnx2_shmem_wr(bp
, BNX2_DRV_ACK_CAP_MB
, sig
);
4760 bnx2_setup_msix_tbl(struct bnx2
*bp
)
4762 BNX2_WR(bp
, BNX2_PCI_GRC_WINDOW_ADDR
, BNX2_PCI_GRC_WINDOW_ADDR_SEP_WIN
);
4764 BNX2_WR(bp
, BNX2_PCI_GRC_WINDOW2_ADDR
, BNX2_MSIX_TABLE_ADDR
);
4765 BNX2_WR(bp
, BNX2_PCI_GRC_WINDOW3_ADDR
, BNX2_MSIX_PBA_ADDR
);
4769 bnx2_wait_dma_complete(struct bnx2
*bp
)
4775 * Wait for the current PCI transaction to complete before
4778 if ((BNX2_CHIP(bp
) == BNX2_CHIP_5706
) ||
4779 (BNX2_CHIP(bp
) == BNX2_CHIP_5708
)) {
4780 BNX2_WR(bp
, BNX2_MISC_ENABLE_CLR_BITS
,
4781 BNX2_MISC_ENABLE_CLR_BITS_TX_DMA_ENABLE
|
4782 BNX2_MISC_ENABLE_CLR_BITS_DMA_ENGINE_ENABLE
|
4783 BNX2_MISC_ENABLE_CLR_BITS_RX_DMA_ENABLE
|
4784 BNX2_MISC_ENABLE_CLR_BITS_HOST_COALESCE_ENABLE
);
4785 val
= BNX2_RD(bp
, BNX2_MISC_ENABLE_CLR_BITS
);
4788 val
= BNX2_RD(bp
, BNX2_MISC_NEW_CORE_CTL
);
4789 val
&= ~BNX2_MISC_NEW_CORE_CTL_DMA_ENABLE
;
4790 BNX2_WR(bp
, BNX2_MISC_NEW_CORE_CTL
, val
);
4791 val
= BNX2_RD(bp
, BNX2_MISC_NEW_CORE_CTL
);
4793 for (i
= 0; i
< 100; i
++) {
4795 val
= BNX2_RD(bp
, BNX2_PCICFG_DEVICE_CONTROL
);
4796 if (!(val
& BNX2_PCICFG_DEVICE_STATUS_NO_PEND
))
4806 bnx2_reset_chip(struct bnx2
*bp
, u32 reset_code
)
4812 /* Wait for the current PCI transaction to complete before
4813 * issuing a reset. */
4814 bnx2_wait_dma_complete(bp
);
4816 /* Wait for the firmware to tell us it is ok to issue a reset. */
4817 bnx2_fw_sync(bp
, BNX2_DRV_MSG_DATA_WAIT0
| reset_code
, 1, 1);
4819 /* Deposit a driver reset signature so the firmware knows that
4820 * this is a soft reset. */
4821 bnx2_shmem_wr(bp
, BNX2_DRV_RESET_SIGNATURE
,
4822 BNX2_DRV_RESET_SIGNATURE_MAGIC
);
4824 /* Do a dummy read to force the chip to complete all current transaction
4825 * before we issue a reset. */
4826 val
= BNX2_RD(bp
, BNX2_MISC_ID
);
4828 if (BNX2_CHIP(bp
) == BNX2_CHIP_5709
) {
4829 BNX2_WR(bp
, BNX2_MISC_COMMAND
, BNX2_MISC_COMMAND_SW_RESET
);
4830 BNX2_RD(bp
, BNX2_MISC_COMMAND
);
4833 val
= BNX2_PCICFG_MISC_CONFIG_REG_WINDOW_ENA
|
4834 BNX2_PCICFG_MISC_CONFIG_TARGET_MB_WORD_SWAP
;
4836 BNX2_WR(bp
, BNX2_PCICFG_MISC_CONFIG
, val
);
4839 val
= BNX2_PCICFG_MISC_CONFIG_CORE_RST_REQ
|
4840 BNX2_PCICFG_MISC_CONFIG_REG_WINDOW_ENA
|
4841 BNX2_PCICFG_MISC_CONFIG_TARGET_MB_WORD_SWAP
;
4844 BNX2_WR(bp
, BNX2_PCICFG_MISC_CONFIG
, val
);
4846 /* Reading back any register after chip reset will hang the
4847 * bus on 5706 A0 and A1. The msleep below provides plenty
4848 * of margin for write posting.
4850 if ((BNX2_CHIP_ID(bp
) == BNX2_CHIP_ID_5706_A0
) ||
4851 (BNX2_CHIP_ID(bp
) == BNX2_CHIP_ID_5706_A1
))
4854 /* Reset takes approximate 30 usec */
4855 for (i
= 0; i
< 10; i
++) {
4856 val
= BNX2_RD(bp
, BNX2_PCICFG_MISC_CONFIG
);
4857 if ((val
& (BNX2_PCICFG_MISC_CONFIG_CORE_RST_REQ
|
4858 BNX2_PCICFG_MISC_CONFIG_CORE_RST_BSY
)) == 0)
4863 if (val
& (BNX2_PCICFG_MISC_CONFIG_CORE_RST_REQ
|
4864 BNX2_PCICFG_MISC_CONFIG_CORE_RST_BSY
)) {
4865 pr_err("Chip reset did not complete\n");
4870 /* Make sure byte swapping is properly configured. */
4871 val
= BNX2_RD(bp
, BNX2_PCI_SWAP_DIAG0
);
4872 if (val
!= 0x01020304) {
4873 pr_err("Chip not in correct endian mode\n");
4877 /* Wait for the firmware to finish its initialization. */
4878 rc
= bnx2_fw_sync(bp
, BNX2_DRV_MSG_DATA_WAIT1
| reset_code
, 1, 0);
4882 spin_lock_bh(&bp
->phy_lock
);
4883 old_port
= bp
->phy_port
;
4884 bnx2_init_fw_cap(bp
);
4885 if ((bp
->phy_flags
& BNX2_PHY_FLAG_REMOTE_PHY_CAP
) &&
4886 old_port
!= bp
->phy_port
)
4887 bnx2_set_default_remote_link(bp
);
4888 spin_unlock_bh(&bp
->phy_lock
);
4890 if (BNX2_CHIP_ID(bp
) == BNX2_CHIP_ID_5706_A0
) {
4891 /* Adjust the voltage regular to two steps lower. The default
4892 * of this register is 0x0000000e. */
4893 BNX2_WR(bp
, BNX2_MISC_VREG_CONTROL
, 0x000000fa);
4895 /* Remove bad rbuf memory from the free pool. */
4896 rc
= bnx2_alloc_bad_rbuf(bp
);
4899 if (bp
->flags
& BNX2_FLAG_USING_MSIX
) {
4900 bnx2_setup_msix_tbl(bp
);
4901 /* Prevent MSIX table reads and write from timing out */
4902 BNX2_WR(bp
, BNX2_MISC_ECO_HW_CTL
,
4903 BNX2_MISC_ECO_HW_CTL_LARGE_GRC_TMOUT_EN
);
4910 bnx2_init_chip(struct bnx2
*bp
)
4915 /* Make sure the interrupt is not active. */
4916 BNX2_WR(bp
, BNX2_PCICFG_INT_ACK_CMD
, BNX2_PCICFG_INT_ACK_CMD_MASK_INT
);
4918 val
= BNX2_DMA_CONFIG_DATA_BYTE_SWAP
|
4919 BNX2_DMA_CONFIG_DATA_WORD_SWAP
|
4921 BNX2_DMA_CONFIG_CNTL_BYTE_SWAP
|
4923 BNX2_DMA_CONFIG_CNTL_WORD_SWAP
|
4924 DMA_READ_CHANS
<< 12 |
4925 DMA_WRITE_CHANS
<< 16;
4927 val
|= (0x2 << 20) | (1 << 11);
4929 if ((bp
->flags
& BNX2_FLAG_PCIX
) && (bp
->bus_speed_mhz
== 133))
4932 if ((BNX2_CHIP(bp
) == BNX2_CHIP_5706
) &&
4933 (BNX2_CHIP_ID(bp
) != BNX2_CHIP_ID_5706_A0
) &&
4934 !(bp
->flags
& BNX2_FLAG_PCIX
))
4935 val
|= BNX2_DMA_CONFIG_CNTL_PING_PONG_DMA
;
4937 BNX2_WR(bp
, BNX2_DMA_CONFIG
, val
);
4939 if (BNX2_CHIP_ID(bp
) == BNX2_CHIP_ID_5706_A0
) {
4940 val
= BNX2_RD(bp
, BNX2_TDMA_CONFIG
);
4941 val
|= BNX2_TDMA_CONFIG_ONE_DMA
;
4942 BNX2_WR(bp
, BNX2_TDMA_CONFIG
, val
);
4945 if (bp
->flags
& BNX2_FLAG_PCIX
) {
4948 pci_read_config_word(bp
->pdev
, bp
->pcix_cap
+ PCI_X_CMD
,
4950 pci_write_config_word(bp
->pdev
, bp
->pcix_cap
+ PCI_X_CMD
,
4951 val16
& ~PCI_X_CMD_ERO
);
4954 BNX2_WR(bp
, BNX2_MISC_ENABLE_SET_BITS
,
4955 BNX2_MISC_ENABLE_SET_BITS_HOST_COALESCE_ENABLE
|
4956 BNX2_MISC_ENABLE_STATUS_BITS_RX_V2P_ENABLE
|
4957 BNX2_MISC_ENABLE_STATUS_BITS_CONTEXT_ENABLE
);
4959 /* Initialize context mapping and zero out the quick contexts. The
4960 * context block must have already been enabled. */
4961 if (BNX2_CHIP(bp
) == BNX2_CHIP_5709
) {
4962 rc
= bnx2_init_5709_context(bp
);
4966 bnx2_init_context(bp
);
4968 if ((rc
= bnx2_init_cpus(bp
)) != 0)
4971 bnx2_init_nvram(bp
);
4973 bnx2_set_mac_addr(bp
, bp
->dev
->dev_addr
, 0);
4975 val
= BNX2_RD(bp
, BNX2_MQ_CONFIG
);
4976 val
&= ~BNX2_MQ_CONFIG_KNL_BYP_BLK_SIZE
;
4977 val
|= BNX2_MQ_CONFIG_KNL_BYP_BLK_SIZE_256
;
4978 if (BNX2_CHIP(bp
) == BNX2_CHIP_5709
) {
4979 val
|= BNX2_MQ_CONFIG_BIN_MQ_MODE
;
4980 if (BNX2_CHIP_REV(bp
) == BNX2_CHIP_REV_Ax
)
4981 val
|= BNX2_MQ_CONFIG_HALT_DIS
;
4984 BNX2_WR(bp
, BNX2_MQ_CONFIG
, val
);
4986 val
= 0x10000 + (MAX_CID_CNT
* MB_KERNEL_CTX_SIZE
);
4987 BNX2_WR(bp
, BNX2_MQ_KNL_BYP_WIND_START
, val
);
4988 BNX2_WR(bp
, BNX2_MQ_KNL_WIND_END
, val
);
4990 val
= (BNX2_PAGE_BITS
- 8) << 24;
4991 BNX2_WR(bp
, BNX2_RV2P_CONFIG
, val
);
4993 /* Configure page size. */
4994 val
= BNX2_RD(bp
, BNX2_TBDR_CONFIG
);
4995 val
&= ~BNX2_TBDR_CONFIG_PAGE_SIZE
;
4996 val
|= (BNX2_PAGE_BITS
- 8) << 24 | 0x40;
4997 BNX2_WR(bp
, BNX2_TBDR_CONFIG
, val
);
4999 val
= bp
->mac_addr
[0] +
5000 (bp
->mac_addr
[1] << 8) +
5001 (bp
->mac_addr
[2] << 16) +
5003 (bp
->mac_addr
[4] << 8) +
5004 (bp
->mac_addr
[5] << 16);
5005 BNX2_WR(bp
, BNX2_EMAC_BACKOFF_SEED
, val
);
5007 /* Program the MTU. Also include 4 bytes for CRC32. */
5009 val
= mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
5010 if (val
> (MAX_ETHERNET_PACKET_SIZE
+ 4))
5011 val
|= BNX2_EMAC_RX_MTU_SIZE_JUMBO_ENA
;
5012 BNX2_WR(bp
, BNX2_EMAC_RX_MTU_SIZE
, val
);
5017 bnx2_reg_wr_ind(bp
, BNX2_RBUF_CONFIG
, BNX2_RBUF_CONFIG_VAL(mtu
));
5018 bnx2_reg_wr_ind(bp
, BNX2_RBUF_CONFIG2
, BNX2_RBUF_CONFIG2_VAL(mtu
));
5019 bnx2_reg_wr_ind(bp
, BNX2_RBUF_CONFIG3
, BNX2_RBUF_CONFIG3_VAL(mtu
));
5021 memset(bp
->bnx2_napi
[0].status_blk
.msi
, 0, bp
->status_stats_size
);
5022 for (i
= 0; i
< BNX2_MAX_MSIX_VEC
; i
++)
5023 bp
->bnx2_napi
[i
].last_status_idx
= 0;
5025 bp
->idle_chk_status_idx
= 0xffff;
5027 /* Set up how to generate a link change interrupt. */
5028 BNX2_WR(bp
, BNX2_EMAC_ATTENTION_ENA
, BNX2_EMAC_ATTENTION_ENA_LINK
);
5030 BNX2_WR(bp
, BNX2_HC_STATUS_ADDR_L
,
5031 (u64
) bp
->status_blk_mapping
& 0xffffffff);
5032 BNX2_WR(bp
, BNX2_HC_STATUS_ADDR_H
, (u64
) bp
->status_blk_mapping
>> 32);
5034 BNX2_WR(bp
, BNX2_HC_STATISTICS_ADDR_L
,
5035 (u64
) bp
->stats_blk_mapping
& 0xffffffff);
5036 BNX2_WR(bp
, BNX2_HC_STATISTICS_ADDR_H
,
5037 (u64
) bp
->stats_blk_mapping
>> 32);
5039 BNX2_WR(bp
, BNX2_HC_TX_QUICK_CONS_TRIP
,
5040 (bp
->tx_quick_cons_trip_int
<< 16) | bp
->tx_quick_cons_trip
);
5042 BNX2_WR(bp
, BNX2_HC_RX_QUICK_CONS_TRIP
,
5043 (bp
->rx_quick_cons_trip_int
<< 16) | bp
->rx_quick_cons_trip
);
5045 BNX2_WR(bp
, BNX2_HC_COMP_PROD_TRIP
,
5046 (bp
->comp_prod_trip_int
<< 16) | bp
->comp_prod_trip
);
5048 BNX2_WR(bp
, BNX2_HC_TX_TICKS
, (bp
->tx_ticks_int
<< 16) | bp
->tx_ticks
);
5050 BNX2_WR(bp
, BNX2_HC_RX_TICKS
, (bp
->rx_ticks_int
<< 16) | bp
->rx_ticks
);
5052 BNX2_WR(bp
, BNX2_HC_COM_TICKS
,
5053 (bp
->com_ticks_int
<< 16) | bp
->com_ticks
);
5055 BNX2_WR(bp
, BNX2_HC_CMD_TICKS
,
5056 (bp
->cmd_ticks_int
<< 16) | bp
->cmd_ticks
);
5058 if (bp
->flags
& BNX2_FLAG_BROKEN_STATS
)
5059 BNX2_WR(bp
, BNX2_HC_STATS_TICKS
, 0);
5061 BNX2_WR(bp
, BNX2_HC_STATS_TICKS
, bp
->stats_ticks
);
5062 BNX2_WR(bp
, BNX2_HC_STAT_COLLECT_TICKS
, 0xbb8); /* 3ms */
5064 if (BNX2_CHIP_ID(bp
) == BNX2_CHIP_ID_5706_A1
)
5065 val
= BNX2_HC_CONFIG_COLLECT_STATS
;
5067 val
= BNX2_HC_CONFIG_RX_TMR_MODE
| BNX2_HC_CONFIG_TX_TMR_MODE
|
5068 BNX2_HC_CONFIG_COLLECT_STATS
;
5071 if (bp
->flags
& BNX2_FLAG_USING_MSIX
) {
5072 BNX2_WR(bp
, BNX2_HC_MSIX_BIT_VECTOR
,
5073 BNX2_HC_MSIX_BIT_VECTOR_VAL
);
5075 val
|= BNX2_HC_CONFIG_SB_ADDR_INC_128B
;
5078 if (bp
->flags
& BNX2_FLAG_ONE_SHOT_MSI
)
5079 val
|= BNX2_HC_CONFIG_ONE_SHOT
| BNX2_HC_CONFIG_USE_INT_PARAM
;
5081 BNX2_WR(bp
, BNX2_HC_CONFIG
, val
);
5083 if (bp
->rx_ticks
< 25)
5084 bnx2_reg_wr_ind(bp
, BNX2_FW_RX_LOW_LATENCY
, 1);
5086 bnx2_reg_wr_ind(bp
, BNX2_FW_RX_LOW_LATENCY
, 0);
5088 for (i
= 1; i
< bp
->irq_nvecs
; i
++) {
5089 u32 base
= ((i
- 1) * BNX2_HC_SB_CONFIG_SIZE
) +
5090 BNX2_HC_SB_CONFIG_1
;
5093 BNX2_HC_SB_CONFIG_1_TX_TMR_MODE
|
5094 BNX2_HC_SB_CONFIG_1_RX_TMR_MODE
|
5095 BNX2_HC_SB_CONFIG_1_ONE_SHOT
);
5097 BNX2_WR(bp
, base
+ BNX2_HC_TX_QUICK_CONS_TRIP_OFF
,
5098 (bp
->tx_quick_cons_trip_int
<< 16) |
5099 bp
->tx_quick_cons_trip
);
5101 BNX2_WR(bp
, base
+ BNX2_HC_TX_TICKS_OFF
,
5102 (bp
->tx_ticks_int
<< 16) | bp
->tx_ticks
);
5104 BNX2_WR(bp
, base
+ BNX2_HC_RX_QUICK_CONS_TRIP_OFF
,
5105 (bp
->rx_quick_cons_trip_int
<< 16) |
5106 bp
->rx_quick_cons_trip
);
5108 BNX2_WR(bp
, base
+ BNX2_HC_RX_TICKS_OFF
,
5109 (bp
->rx_ticks_int
<< 16) | bp
->rx_ticks
);
5112 /* Clear internal stats counters. */
5113 BNX2_WR(bp
, BNX2_HC_COMMAND
, BNX2_HC_COMMAND_CLR_STAT_NOW
);
5115 BNX2_WR(bp
, BNX2_HC_ATTN_BITS_ENABLE
, STATUS_ATTN_EVENTS
);
5117 /* Initialize the receive filter. */
5118 bnx2_set_rx_mode(bp
->dev
);
5120 if (BNX2_CHIP(bp
) == BNX2_CHIP_5709
) {
5121 val
= BNX2_RD(bp
, BNX2_MISC_NEW_CORE_CTL
);
5122 val
|= BNX2_MISC_NEW_CORE_CTL_DMA_ENABLE
;
5123 BNX2_WR(bp
, BNX2_MISC_NEW_CORE_CTL
, val
);
5125 rc
= bnx2_fw_sync(bp
, BNX2_DRV_MSG_DATA_WAIT2
| BNX2_DRV_MSG_CODE_RESET
,
5128 BNX2_WR(bp
, BNX2_MISC_ENABLE_SET_BITS
, BNX2_MISC_ENABLE_DEFAULT
);
5129 BNX2_RD(bp
, BNX2_MISC_ENABLE_SET_BITS
);
5133 bp
->hc_cmd
= BNX2_RD(bp
, BNX2_HC_COMMAND
);
5139 bnx2_clear_ring_states(struct bnx2
*bp
)
5141 struct bnx2_napi
*bnapi
;
5142 struct bnx2_tx_ring_info
*txr
;
5143 struct bnx2_rx_ring_info
*rxr
;
5146 for (i
= 0; i
< BNX2_MAX_MSIX_VEC
; i
++) {
5147 bnapi
= &bp
->bnx2_napi
[i
];
5148 txr
= &bnapi
->tx_ring
;
5149 rxr
= &bnapi
->rx_ring
;
5152 txr
->hw_tx_cons
= 0;
5153 rxr
->rx_prod_bseq
= 0;
5156 rxr
->rx_pg_prod
= 0;
5157 rxr
->rx_pg_cons
= 0;
5162 bnx2_init_tx_context(struct bnx2
*bp
, u32 cid
, struct bnx2_tx_ring_info
*txr
)
5164 u32 val
, offset0
, offset1
, offset2
, offset3
;
5165 u32 cid_addr
= GET_CID_ADDR(cid
);
5167 if (BNX2_CHIP(bp
) == BNX2_CHIP_5709
) {
5168 offset0
= BNX2_L2CTX_TYPE_XI
;
5169 offset1
= BNX2_L2CTX_CMD_TYPE_XI
;
5170 offset2
= BNX2_L2CTX_TBDR_BHADDR_HI_XI
;
5171 offset3
= BNX2_L2CTX_TBDR_BHADDR_LO_XI
;
5173 offset0
= BNX2_L2CTX_TYPE
;
5174 offset1
= BNX2_L2CTX_CMD_TYPE
;
5175 offset2
= BNX2_L2CTX_TBDR_BHADDR_HI
;
5176 offset3
= BNX2_L2CTX_TBDR_BHADDR_LO
;
5178 val
= BNX2_L2CTX_TYPE_TYPE_L2
| BNX2_L2CTX_TYPE_SIZE_L2
;
5179 bnx2_ctx_wr(bp
, cid_addr
, offset0
, val
);
5181 val
= BNX2_L2CTX_CMD_TYPE_TYPE_L2
| (8 << 16);
5182 bnx2_ctx_wr(bp
, cid_addr
, offset1
, val
);
5184 val
= (u64
) txr
->tx_desc_mapping
>> 32;
5185 bnx2_ctx_wr(bp
, cid_addr
, offset2
, val
);
5187 val
= (u64
) txr
->tx_desc_mapping
& 0xffffffff;
5188 bnx2_ctx_wr(bp
, cid_addr
, offset3
, val
);
5192 bnx2_init_tx_ring(struct bnx2
*bp
, int ring_num
)
5194 struct bnx2_tx_bd
*txbd
;
5196 struct bnx2_napi
*bnapi
;
5197 struct bnx2_tx_ring_info
*txr
;
5199 bnapi
= &bp
->bnx2_napi
[ring_num
];
5200 txr
= &bnapi
->tx_ring
;
5205 cid
= TX_TSS_CID
+ ring_num
- 1;
5207 bp
->tx_wake_thresh
= bp
->tx_ring_size
/ 2;
5209 txbd
= &txr
->tx_desc_ring
[BNX2_MAX_TX_DESC_CNT
];
5211 txbd
->tx_bd_haddr_hi
= (u64
) txr
->tx_desc_mapping
>> 32;
5212 txbd
->tx_bd_haddr_lo
= (u64
) txr
->tx_desc_mapping
& 0xffffffff;
5215 txr
->tx_prod_bseq
= 0;
5217 txr
->tx_bidx_addr
= MB_GET_CID_ADDR(cid
) + BNX2_L2CTX_TX_HOST_BIDX
;
5218 txr
->tx_bseq_addr
= MB_GET_CID_ADDR(cid
) + BNX2_L2CTX_TX_HOST_BSEQ
;
5220 bnx2_init_tx_context(bp
, cid
, txr
);
5224 bnx2_init_rxbd_rings(struct bnx2_rx_bd
*rx_ring
[], dma_addr_t dma
[],
5225 u32 buf_size
, int num_rings
)
5228 struct bnx2_rx_bd
*rxbd
;
5230 for (i
= 0; i
< num_rings
; i
++) {
5233 rxbd
= &rx_ring
[i
][0];
5234 for (j
= 0; j
< BNX2_MAX_RX_DESC_CNT
; j
++, rxbd
++) {
5235 rxbd
->rx_bd_len
= buf_size
;
5236 rxbd
->rx_bd_flags
= RX_BD_FLAGS_START
| RX_BD_FLAGS_END
;
5238 if (i
== (num_rings
- 1))
5242 rxbd
->rx_bd_haddr_hi
= (u64
) dma
[j
] >> 32;
5243 rxbd
->rx_bd_haddr_lo
= (u64
) dma
[j
] & 0xffffffff;
5248 bnx2_init_rx_ring(struct bnx2
*bp
, int ring_num
)
5251 u16 prod
, ring_prod
;
5252 u32 cid
, rx_cid_addr
, val
;
5253 struct bnx2_napi
*bnapi
= &bp
->bnx2_napi
[ring_num
];
5254 struct bnx2_rx_ring_info
*rxr
= &bnapi
->rx_ring
;
5259 cid
= RX_RSS_CID
+ ring_num
- 1;
5261 rx_cid_addr
= GET_CID_ADDR(cid
);
5263 bnx2_init_rxbd_rings(rxr
->rx_desc_ring
, rxr
->rx_desc_mapping
,
5264 bp
->rx_buf_use_size
, bp
->rx_max_ring
);
5266 bnx2_init_rx_context(bp
, cid
);
5268 if (BNX2_CHIP(bp
) == BNX2_CHIP_5709
) {
5269 val
= BNX2_RD(bp
, BNX2_MQ_MAP_L2_5
);
5270 BNX2_WR(bp
, BNX2_MQ_MAP_L2_5
, val
| BNX2_MQ_MAP_L2_5_ARM
);
5273 bnx2_ctx_wr(bp
, rx_cid_addr
, BNX2_L2CTX_PG_BUF_SIZE
, 0);
5274 if (bp
->rx_pg_ring_size
) {
5275 bnx2_init_rxbd_rings(rxr
->rx_pg_desc_ring
,
5276 rxr
->rx_pg_desc_mapping
,
5277 PAGE_SIZE
, bp
->rx_max_pg_ring
);
5278 val
= (bp
->rx_buf_use_size
<< 16) | PAGE_SIZE
;
5279 bnx2_ctx_wr(bp
, rx_cid_addr
, BNX2_L2CTX_PG_BUF_SIZE
, val
);
5280 bnx2_ctx_wr(bp
, rx_cid_addr
, BNX2_L2CTX_RBDC_KEY
,
5281 BNX2_L2CTX_RBDC_JUMBO_KEY
- ring_num
);
5283 val
= (u64
) rxr
->rx_pg_desc_mapping
[0] >> 32;
5284 bnx2_ctx_wr(bp
, rx_cid_addr
, BNX2_L2CTX_NX_PG_BDHADDR_HI
, val
);
5286 val
= (u64
) rxr
->rx_pg_desc_mapping
[0] & 0xffffffff;
5287 bnx2_ctx_wr(bp
, rx_cid_addr
, BNX2_L2CTX_NX_PG_BDHADDR_LO
, val
);
5289 if (BNX2_CHIP(bp
) == BNX2_CHIP_5709
)
5290 BNX2_WR(bp
, BNX2_MQ_MAP_L2_3
, BNX2_MQ_MAP_L2_3_DEFAULT
);
5293 val
= (u64
) rxr
->rx_desc_mapping
[0] >> 32;
5294 bnx2_ctx_wr(bp
, rx_cid_addr
, BNX2_L2CTX_NX_BDHADDR_HI
, val
);
5296 val
= (u64
) rxr
->rx_desc_mapping
[0] & 0xffffffff;
5297 bnx2_ctx_wr(bp
, rx_cid_addr
, BNX2_L2CTX_NX_BDHADDR_LO
, val
);
5299 ring_prod
= prod
= rxr
->rx_pg_prod
;
5300 for (i
= 0; i
< bp
->rx_pg_ring_size
; i
++) {
5301 if (bnx2_alloc_rx_page(bp
, rxr
, ring_prod
, GFP_KERNEL
) < 0) {
5302 netdev_warn(bp
->dev
, "init'ed rx page ring %d with %d/%d pages only\n",
5303 ring_num
, i
, bp
->rx_pg_ring_size
);
5306 prod
= BNX2_NEXT_RX_BD(prod
);
5307 ring_prod
= BNX2_RX_PG_RING_IDX(prod
);
5309 rxr
->rx_pg_prod
= prod
;
5311 ring_prod
= prod
= rxr
->rx_prod
;
5312 for (i
= 0; i
< bp
->rx_ring_size
; i
++) {
5313 if (bnx2_alloc_rx_data(bp
, rxr
, ring_prod
, GFP_KERNEL
) < 0) {
5314 netdev_warn(bp
->dev
, "init'ed rx ring %d with %d/%d skbs only\n",
5315 ring_num
, i
, bp
->rx_ring_size
);
5318 prod
= BNX2_NEXT_RX_BD(prod
);
5319 ring_prod
= BNX2_RX_RING_IDX(prod
);
5321 rxr
->rx_prod
= prod
;
5323 rxr
->rx_bidx_addr
= MB_GET_CID_ADDR(cid
) + BNX2_L2CTX_HOST_BDIDX
;
5324 rxr
->rx_bseq_addr
= MB_GET_CID_ADDR(cid
) + BNX2_L2CTX_HOST_BSEQ
;
5325 rxr
->rx_pg_bidx_addr
= MB_GET_CID_ADDR(cid
) + BNX2_L2CTX_HOST_PG_BDIDX
;
5327 BNX2_WR16(bp
, rxr
->rx_pg_bidx_addr
, rxr
->rx_pg_prod
);
5328 BNX2_WR16(bp
, rxr
->rx_bidx_addr
, prod
);
5330 BNX2_WR(bp
, rxr
->rx_bseq_addr
, rxr
->rx_prod_bseq
);
5334 bnx2_init_all_rings(struct bnx2
*bp
)
5339 bnx2_clear_ring_states(bp
);
5341 BNX2_WR(bp
, BNX2_TSCH_TSS_CFG
, 0);
5342 for (i
= 0; i
< bp
->num_tx_rings
; i
++)
5343 bnx2_init_tx_ring(bp
, i
);
5345 if (bp
->num_tx_rings
> 1)
5346 BNX2_WR(bp
, BNX2_TSCH_TSS_CFG
, ((bp
->num_tx_rings
- 1) << 24) |
5349 BNX2_WR(bp
, BNX2_RLUP_RSS_CONFIG
, 0);
5350 bnx2_reg_wr_ind(bp
, BNX2_RXP_SCRATCH_RSS_TBL_SZ
, 0);
5352 for (i
= 0; i
< bp
->num_rx_rings
; i
++)
5353 bnx2_init_rx_ring(bp
, i
);
5355 if (bp
->num_rx_rings
> 1) {
5358 for (i
= 0; i
< BNX2_RXP_SCRATCH_RSS_TBL_MAX_ENTRIES
; i
++) {
5359 int shift
= (i
% 8) << 2;
5361 tbl_32
|= (i
% (bp
->num_rx_rings
- 1)) << shift
;
5363 BNX2_WR(bp
, BNX2_RLUP_RSS_DATA
, tbl_32
);
5364 BNX2_WR(bp
, BNX2_RLUP_RSS_COMMAND
, (i
>> 3) |
5365 BNX2_RLUP_RSS_COMMAND_RSS_WRITE_MASK
|
5366 BNX2_RLUP_RSS_COMMAND_WRITE
|
5367 BNX2_RLUP_RSS_COMMAND_HASH_MASK
);
5372 val
= BNX2_RLUP_RSS_CONFIG_IPV4_RSS_TYPE_ALL_XI
|
5373 BNX2_RLUP_RSS_CONFIG_IPV6_RSS_TYPE_ALL_XI
;
5375 BNX2_WR(bp
, BNX2_RLUP_RSS_CONFIG
, val
);
5380 static u32
bnx2_find_max_ring(u32 ring_size
, u32 max_size
)
5382 u32 max
, num_rings
= 1;
5384 while (ring_size
> BNX2_MAX_RX_DESC_CNT
) {
5385 ring_size
-= BNX2_MAX_RX_DESC_CNT
;
5388 /* round to next power of 2 */
5390 while ((max
& num_rings
) == 0)
5393 if (num_rings
!= max
)
5400 bnx2_set_rx_ring_size(struct bnx2
*bp
, u32 size
)
5402 u32 rx_size
, rx_space
, jumbo_size
;
5404 /* 8 for CRC and VLAN */
5405 rx_size
= bp
->dev
->mtu
+ ETH_HLEN
+ BNX2_RX_OFFSET
+ 8;
5407 rx_space
= SKB_DATA_ALIGN(rx_size
+ BNX2_RX_ALIGN
) + NET_SKB_PAD
+
5408 SKB_DATA_ALIGN(sizeof(struct skb_shared_info
));
5410 bp
->rx_copy_thresh
= BNX2_RX_COPY_THRESH
;
5411 bp
->rx_pg_ring_size
= 0;
5412 bp
->rx_max_pg_ring
= 0;
5413 bp
->rx_max_pg_ring_idx
= 0;
5414 if ((rx_space
> PAGE_SIZE
) && !(bp
->flags
& BNX2_FLAG_JUMBO_BROKEN
)) {
5415 int pages
= PAGE_ALIGN(bp
->dev
->mtu
- 40) >> PAGE_SHIFT
;
5417 jumbo_size
= size
* pages
;
5418 if (jumbo_size
> BNX2_MAX_TOTAL_RX_PG_DESC_CNT
)
5419 jumbo_size
= BNX2_MAX_TOTAL_RX_PG_DESC_CNT
;
5421 bp
->rx_pg_ring_size
= jumbo_size
;
5422 bp
->rx_max_pg_ring
= bnx2_find_max_ring(jumbo_size
,
5423 BNX2_MAX_RX_PG_RINGS
);
5424 bp
->rx_max_pg_ring_idx
=
5425 (bp
->rx_max_pg_ring
* BNX2_RX_DESC_CNT
) - 1;
5426 rx_size
= BNX2_RX_COPY_THRESH
+ BNX2_RX_OFFSET
;
5427 bp
->rx_copy_thresh
= 0;
5430 bp
->rx_buf_use_size
= rx_size
;
5431 /* hw alignment + build_skb() overhead*/
5432 bp
->rx_buf_size
= SKB_DATA_ALIGN(bp
->rx_buf_use_size
+ BNX2_RX_ALIGN
) +
5433 NET_SKB_PAD
+ SKB_DATA_ALIGN(sizeof(struct skb_shared_info
));
5434 bp
->rx_jumbo_thresh
= rx_size
- BNX2_RX_OFFSET
;
5435 bp
->rx_ring_size
= size
;
5436 bp
->rx_max_ring
= bnx2_find_max_ring(size
, BNX2_MAX_RX_RINGS
);
5437 bp
->rx_max_ring_idx
= (bp
->rx_max_ring
* BNX2_RX_DESC_CNT
) - 1;
5441 bnx2_free_tx_skbs(struct bnx2
*bp
)
5445 for (i
= 0; i
< bp
->num_tx_rings
; i
++) {
5446 struct bnx2_napi
*bnapi
= &bp
->bnx2_napi
[i
];
5447 struct bnx2_tx_ring_info
*txr
= &bnapi
->tx_ring
;
5450 if (txr
->tx_buf_ring
== NULL
)
5453 for (j
= 0; j
< BNX2_TX_DESC_CNT
; ) {
5454 struct bnx2_sw_tx_bd
*tx_buf
= &txr
->tx_buf_ring
[j
];
5455 struct sk_buff
*skb
= tx_buf
->skb
;
5459 j
= BNX2_NEXT_TX_BD(j
);
5463 dma_unmap_single(&bp
->pdev
->dev
,
5464 dma_unmap_addr(tx_buf
, mapping
),
5470 last
= tx_buf
->nr_frags
;
5471 j
= BNX2_NEXT_TX_BD(j
);
5472 for (k
= 0; k
< last
; k
++, j
= BNX2_NEXT_TX_BD(j
)) {
5473 tx_buf
= &txr
->tx_buf_ring
[BNX2_TX_RING_IDX(j
)];
5474 dma_unmap_page(&bp
->pdev
->dev
,
5475 dma_unmap_addr(tx_buf
, mapping
),
5476 skb_frag_size(&skb_shinfo(skb
)->frags
[k
]),
5481 netdev_tx_reset_queue(netdev_get_tx_queue(bp
->dev
, i
));
5486 bnx2_free_rx_skbs(struct bnx2
*bp
)
5490 for (i
= 0; i
< bp
->num_rx_rings
; i
++) {
5491 struct bnx2_napi
*bnapi
= &bp
->bnx2_napi
[i
];
5492 struct bnx2_rx_ring_info
*rxr
= &bnapi
->rx_ring
;
5495 if (rxr
->rx_buf_ring
== NULL
)
5498 for (j
= 0; j
< bp
->rx_max_ring_idx
; j
++) {
5499 struct bnx2_sw_bd
*rx_buf
= &rxr
->rx_buf_ring
[j
];
5500 u8
*data
= rx_buf
->data
;
5505 dma_unmap_single(&bp
->pdev
->dev
,
5506 dma_unmap_addr(rx_buf
, mapping
),
5507 bp
->rx_buf_use_size
,
5508 PCI_DMA_FROMDEVICE
);
5510 rx_buf
->data
= NULL
;
5514 for (j
= 0; j
< bp
->rx_max_pg_ring_idx
; j
++)
5515 bnx2_free_rx_page(bp
, rxr
, j
);
5520 bnx2_free_skbs(struct bnx2
*bp
)
5522 bnx2_free_tx_skbs(bp
);
5523 bnx2_free_rx_skbs(bp
);
5527 bnx2_reset_nic(struct bnx2
*bp
, u32 reset_code
)
5531 rc
= bnx2_reset_chip(bp
, reset_code
);
5536 if ((rc
= bnx2_init_chip(bp
)) != 0)
5539 bnx2_init_all_rings(bp
);
5544 bnx2_init_nic(struct bnx2
*bp
, int reset_phy
)
5548 if ((rc
= bnx2_reset_nic(bp
, BNX2_DRV_MSG_CODE_RESET
)) != 0)
5551 spin_lock_bh(&bp
->phy_lock
);
5552 bnx2_init_phy(bp
, reset_phy
);
5554 if (bp
->phy_flags
& BNX2_PHY_FLAG_REMOTE_PHY_CAP
)
5555 bnx2_remote_phy_event(bp
);
5556 spin_unlock_bh(&bp
->phy_lock
);
5561 bnx2_shutdown_chip(struct bnx2
*bp
)
5565 if (bp
->flags
& BNX2_FLAG_NO_WOL
)
5566 reset_code
= BNX2_DRV_MSG_CODE_UNLOAD_LNK_DN
;
5568 reset_code
= BNX2_DRV_MSG_CODE_SUSPEND_WOL
;
5570 reset_code
= BNX2_DRV_MSG_CODE_SUSPEND_NO_WOL
;
5572 return bnx2_reset_chip(bp
, reset_code
);
5576 bnx2_test_registers(struct bnx2
*bp
)
5580 static const struct {
5583 #define BNX2_FL_NOT_5709 1
5587 { 0x006c, 0, 0x00000000, 0x0000003f },
5588 { 0x0090, 0, 0xffffffff, 0x00000000 },
5589 { 0x0094, 0, 0x00000000, 0x00000000 },
5591 { 0x0404, BNX2_FL_NOT_5709
, 0x00003f00, 0x00000000 },
5592 { 0x0418, BNX2_FL_NOT_5709
, 0x00000000, 0xffffffff },
5593 { 0x041c, BNX2_FL_NOT_5709
, 0x00000000, 0xffffffff },
5594 { 0x0420, BNX2_FL_NOT_5709
, 0x00000000, 0x80ffffff },
5595 { 0x0424, BNX2_FL_NOT_5709
, 0x00000000, 0x00000000 },
5596 { 0x0428, BNX2_FL_NOT_5709
, 0x00000000, 0x00000001 },
5597 { 0x0450, BNX2_FL_NOT_5709
, 0x00000000, 0x0000ffff },
5598 { 0x0454, BNX2_FL_NOT_5709
, 0x00000000, 0xffffffff },
5599 { 0x0458, BNX2_FL_NOT_5709
, 0x00000000, 0xffffffff },
5601 { 0x0808, BNX2_FL_NOT_5709
, 0x00000000, 0xffffffff },
5602 { 0x0854, BNX2_FL_NOT_5709
, 0x00000000, 0xffffffff },
5603 { 0x0868, BNX2_FL_NOT_5709
, 0x00000000, 0x77777777 },
5604 { 0x086c, BNX2_FL_NOT_5709
, 0x00000000, 0x77777777 },
5605 { 0x0870, BNX2_FL_NOT_5709
, 0x00000000, 0x77777777 },
5606 { 0x0874, BNX2_FL_NOT_5709
, 0x00000000, 0x77777777 },
5608 { 0x0c00, BNX2_FL_NOT_5709
, 0x00000000, 0x00000001 },
5609 { 0x0c04, BNX2_FL_NOT_5709
, 0x00000000, 0x03ff0001 },
5610 { 0x0c08, BNX2_FL_NOT_5709
, 0x0f0ff073, 0x00000000 },
5612 { 0x1000, 0, 0x00000000, 0x00000001 },
5613 { 0x1004, BNX2_FL_NOT_5709
, 0x00000000, 0x000f0001 },
5615 { 0x1408, 0, 0x01c00800, 0x00000000 },
5616 { 0x149c, 0, 0x8000ffff, 0x00000000 },
5617 { 0x14a8, 0, 0x00000000, 0x000001ff },
5618 { 0x14ac, 0, 0x0fffffff, 0x10000000 },
5619 { 0x14b0, 0, 0x00000002, 0x00000001 },
5620 { 0x14b8, 0, 0x00000000, 0x00000000 },
5621 { 0x14c0, 0, 0x00000000, 0x00000009 },
5622 { 0x14c4, 0, 0x00003fff, 0x00000000 },
5623 { 0x14cc, 0, 0x00000000, 0x00000001 },
5624 { 0x14d0, 0, 0xffffffff, 0x00000000 },
5626 { 0x1800, 0, 0x00000000, 0x00000001 },
5627 { 0x1804, 0, 0x00000000, 0x00000003 },
5629 { 0x2800, 0, 0x00000000, 0x00000001 },
5630 { 0x2804, 0, 0x00000000, 0x00003f01 },
5631 { 0x2808, 0, 0x0f3f3f03, 0x00000000 },
5632 { 0x2810, 0, 0xffff0000, 0x00000000 },
5633 { 0x2814, 0, 0xffff0000, 0x00000000 },
5634 { 0x2818, 0, 0xffff0000, 0x00000000 },
5635 { 0x281c, 0, 0xffff0000, 0x00000000 },
5636 { 0x2834, 0, 0xffffffff, 0x00000000 },
5637 { 0x2840, 0, 0x00000000, 0xffffffff },
5638 { 0x2844, 0, 0x00000000, 0xffffffff },
5639 { 0x2848, 0, 0xffffffff, 0x00000000 },
5640 { 0x284c, 0, 0xf800f800, 0x07ff07ff },
5642 { 0x2c00, 0, 0x00000000, 0x00000011 },
5643 { 0x2c04, 0, 0x00000000, 0x00030007 },
5645 { 0x3c00, 0, 0x00000000, 0x00000001 },
5646 { 0x3c04, 0, 0x00000000, 0x00070000 },
5647 { 0x3c08, 0, 0x00007f71, 0x07f00000 },
5648 { 0x3c0c, 0, 0x1f3ffffc, 0x00000000 },
5649 { 0x3c10, 0, 0xffffffff, 0x00000000 },
5650 { 0x3c14, 0, 0x00000000, 0xffffffff },
5651 { 0x3c18, 0, 0x00000000, 0xffffffff },
5652 { 0x3c1c, 0, 0xfffff000, 0x00000000 },
5653 { 0x3c20, 0, 0xffffff00, 0x00000000 },
5655 { 0x5004, 0, 0x00000000, 0x0000007f },
5656 { 0x5008, 0, 0x0f0007ff, 0x00000000 },
5658 { 0x5c00, 0, 0x00000000, 0x00000001 },
5659 { 0x5c04, 0, 0x00000000, 0x0003000f },
5660 { 0x5c08, 0, 0x00000003, 0x00000000 },
5661 { 0x5c0c, 0, 0x0000fff8, 0x00000000 },
5662 { 0x5c10, 0, 0x00000000, 0xffffffff },
5663 { 0x5c80, 0, 0x00000000, 0x0f7113f1 },
5664 { 0x5c84, 0, 0x00000000, 0x0000f333 },
5665 { 0x5c88, 0, 0x00000000, 0x00077373 },
5666 { 0x5c8c, 0, 0x00000000, 0x0007f737 },
5668 { 0x6808, 0, 0x0000ff7f, 0x00000000 },
5669 { 0x680c, 0, 0xffffffff, 0x00000000 },
5670 { 0x6810, 0, 0xffffffff, 0x00000000 },
5671 { 0x6814, 0, 0xffffffff, 0x00000000 },
5672 { 0x6818, 0, 0xffffffff, 0x00000000 },
5673 { 0x681c, 0, 0xffffffff, 0x00000000 },
5674 { 0x6820, 0, 0x00ff00ff, 0x00000000 },
5675 { 0x6824, 0, 0x00ff00ff, 0x00000000 },
5676 { 0x6828, 0, 0x00ff00ff, 0x00000000 },
5677 { 0x682c, 0, 0x03ff03ff, 0x00000000 },
5678 { 0x6830, 0, 0x03ff03ff, 0x00000000 },
5679 { 0x6834, 0, 0x03ff03ff, 0x00000000 },
5680 { 0x6838, 0, 0x03ff03ff, 0x00000000 },
5681 { 0x683c, 0, 0x0000ffff, 0x00000000 },
5682 { 0x6840, 0, 0x00000ff0, 0x00000000 },
5683 { 0x6844, 0, 0x00ffff00, 0x00000000 },
5684 { 0x684c, 0, 0xffffffff, 0x00000000 },
5685 { 0x6850, 0, 0x7f7f7f7f, 0x00000000 },
5686 { 0x6854, 0, 0x7f7f7f7f, 0x00000000 },
5687 { 0x6858, 0, 0x7f7f7f7f, 0x00000000 },
5688 { 0x685c, 0, 0x7f7f7f7f, 0x00000000 },
5689 { 0x6908, 0, 0x00000000, 0x0001ff0f },
5690 { 0x690c, 0, 0x00000000, 0x0ffe00f0 },
5692 { 0xffff, 0, 0x00000000, 0x00000000 },
5697 if (BNX2_CHIP(bp
) == BNX2_CHIP_5709
)
5700 for (i
= 0; reg_tbl
[i
].offset
!= 0xffff; i
++) {
5701 u32 offset
, rw_mask
, ro_mask
, save_val
, val
;
5702 u16 flags
= reg_tbl
[i
].flags
;
5704 if (is_5709
&& (flags
& BNX2_FL_NOT_5709
))
5707 offset
= (u32
) reg_tbl
[i
].offset
;
5708 rw_mask
= reg_tbl
[i
].rw_mask
;
5709 ro_mask
= reg_tbl
[i
].ro_mask
;
5711 save_val
= readl(bp
->regview
+ offset
);
5713 writel(0, bp
->regview
+ offset
);
5715 val
= readl(bp
->regview
+ offset
);
5716 if ((val
& rw_mask
) != 0) {
5720 if ((val
& ro_mask
) != (save_val
& ro_mask
)) {
5724 writel(0xffffffff, bp
->regview
+ offset
);
5726 val
= readl(bp
->regview
+ offset
);
5727 if ((val
& rw_mask
) != rw_mask
) {
5731 if ((val
& ro_mask
) != (save_val
& ro_mask
)) {
5735 writel(save_val
, bp
->regview
+ offset
);
5739 writel(save_val
, bp
->regview
+ offset
);
5747 bnx2_do_mem_test(struct bnx2
*bp
, u32 start
, u32 size
)
5749 static const u32 test_pattern
[] = { 0x00000000, 0xffffffff, 0x55555555,
5750 0xaaaaaaaa , 0xaa55aa55, 0x55aa55aa };
5753 for (i
= 0; i
< sizeof(test_pattern
) / 4; i
++) {
5756 for (offset
= 0; offset
< size
; offset
+= 4) {
5758 bnx2_reg_wr_ind(bp
, start
+ offset
, test_pattern
[i
]);
5760 if (bnx2_reg_rd_ind(bp
, start
+ offset
) !=
5770 bnx2_test_memory(struct bnx2
*bp
)
5774 static struct mem_entry
{
5777 } mem_tbl_5706
[] = {
5778 { 0x60000, 0x4000 },
5779 { 0xa0000, 0x3000 },
5780 { 0xe0000, 0x4000 },
5781 { 0x120000, 0x4000 },
5782 { 0x1a0000, 0x4000 },
5783 { 0x160000, 0x4000 },
5787 { 0x60000, 0x4000 },
5788 { 0xa0000, 0x3000 },
5789 { 0xe0000, 0x4000 },
5790 { 0x120000, 0x4000 },
5791 { 0x1a0000, 0x4000 },
5794 struct mem_entry
*mem_tbl
;
5796 if (BNX2_CHIP(bp
) == BNX2_CHIP_5709
)
5797 mem_tbl
= mem_tbl_5709
;
5799 mem_tbl
= mem_tbl_5706
;
5801 for (i
= 0; mem_tbl
[i
].offset
!= 0xffffffff; i
++) {
5802 if ((ret
= bnx2_do_mem_test(bp
, mem_tbl
[i
].offset
,
5803 mem_tbl
[i
].len
)) != 0) {
5811 #define BNX2_MAC_LOOPBACK 0
5812 #define BNX2_PHY_LOOPBACK 1
5815 bnx2_run_loopback(struct bnx2
*bp
, int loopback_mode
)
5817 unsigned int pkt_size
, num_pkts
, i
;
5818 struct sk_buff
*skb
;
5820 unsigned char *packet
;
5821 u16 rx_start_idx
, rx_idx
;
5823 struct bnx2_tx_bd
*txbd
;
5824 struct bnx2_sw_bd
*rx_buf
;
5825 struct l2_fhdr
*rx_hdr
;
5827 struct bnx2_napi
*bnapi
= &bp
->bnx2_napi
[0], *tx_napi
;
5828 struct bnx2_tx_ring_info
*txr
= &bnapi
->tx_ring
;
5829 struct bnx2_rx_ring_info
*rxr
= &bnapi
->rx_ring
;
5833 txr
= &tx_napi
->tx_ring
;
5834 rxr
= &bnapi
->rx_ring
;
5835 if (loopback_mode
== BNX2_MAC_LOOPBACK
) {
5836 bp
->loopback
= MAC_LOOPBACK
;
5837 bnx2_set_mac_loopback(bp
);
5839 else if (loopback_mode
== BNX2_PHY_LOOPBACK
) {
5840 if (bp
->phy_flags
& BNX2_PHY_FLAG_REMOTE_PHY_CAP
)
5843 bp
->loopback
= PHY_LOOPBACK
;
5844 bnx2_set_phy_loopback(bp
);
5849 pkt_size
= min(bp
->dev
->mtu
+ ETH_HLEN
, bp
->rx_jumbo_thresh
- 4);
5850 skb
= netdev_alloc_skb(bp
->dev
, pkt_size
);
5853 packet
= skb_put(skb
, pkt_size
);
5854 memcpy(packet
, bp
->dev
->dev_addr
, ETH_ALEN
);
5855 memset(packet
+ ETH_ALEN
, 0x0, 8);
5856 for (i
= 14; i
< pkt_size
; i
++)
5857 packet
[i
] = (unsigned char) (i
& 0xff);
5859 map
= dma_map_single(&bp
->pdev
->dev
, skb
->data
, pkt_size
,
5861 if (dma_mapping_error(&bp
->pdev
->dev
, map
)) {
5866 BNX2_WR(bp
, BNX2_HC_COMMAND
,
5867 bp
->hc_cmd
| BNX2_HC_COMMAND_COAL_NOW_WO_INT
);
5869 BNX2_RD(bp
, BNX2_HC_COMMAND
);
5872 rx_start_idx
= bnx2_get_hw_rx_cons(bnapi
);
5876 txbd
= &txr
->tx_desc_ring
[BNX2_TX_RING_IDX(txr
->tx_prod
)];
5878 txbd
->tx_bd_haddr_hi
= (u64
) map
>> 32;
5879 txbd
->tx_bd_haddr_lo
= (u64
) map
& 0xffffffff;
5880 txbd
->tx_bd_mss_nbytes
= pkt_size
;
5881 txbd
->tx_bd_vlan_tag_flags
= TX_BD_FLAGS_START
| TX_BD_FLAGS_END
;
5884 txr
->tx_prod
= BNX2_NEXT_TX_BD(txr
->tx_prod
);
5885 txr
->tx_prod_bseq
+= pkt_size
;
5887 BNX2_WR16(bp
, txr
->tx_bidx_addr
, txr
->tx_prod
);
5888 BNX2_WR(bp
, txr
->tx_bseq_addr
, txr
->tx_prod_bseq
);
5892 BNX2_WR(bp
, BNX2_HC_COMMAND
,
5893 bp
->hc_cmd
| BNX2_HC_COMMAND_COAL_NOW_WO_INT
);
5895 BNX2_RD(bp
, BNX2_HC_COMMAND
);
5899 dma_unmap_single(&bp
->pdev
->dev
, map
, pkt_size
, PCI_DMA_TODEVICE
);
5902 if (bnx2_get_hw_tx_cons(tx_napi
) != txr
->tx_prod
)
5903 goto loopback_test_done
;
5905 rx_idx
= bnx2_get_hw_rx_cons(bnapi
);
5906 if (rx_idx
!= rx_start_idx
+ num_pkts
) {
5907 goto loopback_test_done
;
5910 rx_buf
= &rxr
->rx_buf_ring
[rx_start_idx
];
5911 data
= rx_buf
->data
;
5913 rx_hdr
= get_l2_fhdr(data
);
5914 data
= (u8
*)rx_hdr
+ BNX2_RX_OFFSET
;
5916 dma_sync_single_for_cpu(&bp
->pdev
->dev
,
5917 dma_unmap_addr(rx_buf
, mapping
),
5918 bp
->rx_buf_use_size
, PCI_DMA_FROMDEVICE
);
5920 if (rx_hdr
->l2_fhdr_status
&
5921 (L2_FHDR_ERRORS_BAD_CRC
|
5922 L2_FHDR_ERRORS_PHY_DECODE
|
5923 L2_FHDR_ERRORS_ALIGNMENT
|
5924 L2_FHDR_ERRORS_TOO_SHORT
|
5925 L2_FHDR_ERRORS_GIANT_FRAME
)) {
5927 goto loopback_test_done
;
5930 if ((rx_hdr
->l2_fhdr_pkt_len
- 4) != pkt_size
) {
5931 goto loopback_test_done
;
5934 for (i
= 14; i
< pkt_size
; i
++) {
5935 if (*(data
+ i
) != (unsigned char) (i
& 0xff)) {
5936 goto loopback_test_done
;
5947 #define BNX2_MAC_LOOPBACK_FAILED 1
5948 #define BNX2_PHY_LOOPBACK_FAILED 2
5949 #define BNX2_LOOPBACK_FAILED (BNX2_MAC_LOOPBACK_FAILED | \
5950 BNX2_PHY_LOOPBACK_FAILED)
5953 bnx2_test_loopback(struct bnx2
*bp
)
5957 if (!netif_running(bp
->dev
))
5958 return BNX2_LOOPBACK_FAILED
;
5960 bnx2_reset_nic(bp
, BNX2_DRV_MSG_CODE_RESET
);
5961 spin_lock_bh(&bp
->phy_lock
);
5962 bnx2_init_phy(bp
, 1);
5963 spin_unlock_bh(&bp
->phy_lock
);
5964 if (bnx2_run_loopback(bp
, BNX2_MAC_LOOPBACK
))
5965 rc
|= BNX2_MAC_LOOPBACK_FAILED
;
5966 if (bnx2_run_loopback(bp
, BNX2_PHY_LOOPBACK
))
5967 rc
|= BNX2_PHY_LOOPBACK_FAILED
;
5971 #define NVRAM_SIZE 0x200
5972 #define CRC32_RESIDUAL 0xdebb20e3
5975 bnx2_test_nvram(struct bnx2
*bp
)
5977 __be32 buf
[NVRAM_SIZE
/ 4];
5978 u8
*data
= (u8
*) buf
;
5982 if ((rc
= bnx2_nvram_read(bp
, 0, data
, 4)) != 0)
5983 goto test_nvram_done
;
5985 magic
= be32_to_cpu(buf
[0]);
5986 if (magic
!= 0x669955aa) {
5988 goto test_nvram_done
;
5991 if ((rc
= bnx2_nvram_read(bp
, 0x100, data
, NVRAM_SIZE
)) != 0)
5992 goto test_nvram_done
;
5994 csum
= ether_crc_le(0x100, data
);
5995 if (csum
!= CRC32_RESIDUAL
) {
5997 goto test_nvram_done
;
6000 csum
= ether_crc_le(0x100, data
+ 0x100);
6001 if (csum
!= CRC32_RESIDUAL
) {
6010 bnx2_test_link(struct bnx2
*bp
)
6014 if (!netif_running(bp
->dev
))
6017 if (bp
->phy_flags
& BNX2_PHY_FLAG_REMOTE_PHY_CAP
) {
6022 spin_lock_bh(&bp
->phy_lock
);
6023 bnx2_enable_bmsr1(bp
);
6024 bnx2_read_phy(bp
, bp
->mii_bmsr1
, &bmsr
);
6025 bnx2_read_phy(bp
, bp
->mii_bmsr1
, &bmsr
);
6026 bnx2_disable_bmsr1(bp
);
6027 spin_unlock_bh(&bp
->phy_lock
);
6029 if (bmsr
& BMSR_LSTATUS
) {
6036 bnx2_test_intr(struct bnx2
*bp
)
6041 if (!netif_running(bp
->dev
))
6044 status_idx
= BNX2_RD(bp
, BNX2_PCICFG_INT_ACK_CMD
) & 0xffff;
6046 /* This register is not touched during run-time. */
6047 BNX2_WR(bp
, BNX2_HC_COMMAND
, bp
->hc_cmd
| BNX2_HC_COMMAND_COAL_NOW
);
6048 BNX2_RD(bp
, BNX2_HC_COMMAND
);
6050 for (i
= 0; i
< 10; i
++) {
6051 if ((BNX2_RD(bp
, BNX2_PCICFG_INT_ACK_CMD
) & 0xffff) !=
6057 msleep_interruptible(10);
6065 /* Determining link for parallel detection. */
6067 bnx2_5706_serdes_has_link(struct bnx2
*bp
)
6069 u32 mode_ctl
, an_dbg
, exp
;
6071 if (bp
->phy_flags
& BNX2_PHY_FLAG_NO_PARALLEL
)
6074 bnx2_write_phy(bp
, MII_BNX2_MISC_SHADOW
, MISC_SHDW_MODE_CTL
);
6075 bnx2_read_phy(bp
, MII_BNX2_MISC_SHADOW
, &mode_ctl
);
6077 if (!(mode_ctl
& MISC_SHDW_MODE_CTL_SIG_DET
))
6080 bnx2_write_phy(bp
, MII_BNX2_MISC_SHADOW
, MISC_SHDW_AN_DBG
);
6081 bnx2_read_phy(bp
, MII_BNX2_MISC_SHADOW
, &an_dbg
);
6082 bnx2_read_phy(bp
, MII_BNX2_MISC_SHADOW
, &an_dbg
);
6084 if (an_dbg
& (MISC_SHDW_AN_DBG_NOSYNC
| MISC_SHDW_AN_DBG_RUDI_INVALID
))
6087 bnx2_write_phy(bp
, MII_BNX2_DSP_ADDRESS
, MII_EXPAND_REG1
);
6088 bnx2_read_phy(bp
, MII_BNX2_DSP_RW_PORT
, &exp
);
6089 bnx2_read_phy(bp
, MII_BNX2_DSP_RW_PORT
, &exp
);
6091 if (exp
& MII_EXPAND_REG1_RUDI_C
) /* receiving CONFIG */
6098 bnx2_5706_serdes_timer(struct bnx2
*bp
)
6102 spin_lock(&bp
->phy_lock
);
6103 if (bp
->serdes_an_pending
) {
6104 bp
->serdes_an_pending
--;
6106 } else if ((bp
->link_up
== 0) && (bp
->autoneg
& AUTONEG_SPEED
)) {
6109 bp
->current_interval
= BNX2_TIMER_INTERVAL
;
6111 bnx2_read_phy(bp
, bp
->mii_bmcr
, &bmcr
);
6113 if (bmcr
& BMCR_ANENABLE
) {
6114 if (bnx2_5706_serdes_has_link(bp
)) {
6115 bmcr
&= ~BMCR_ANENABLE
;
6116 bmcr
|= BMCR_SPEED1000
| BMCR_FULLDPLX
;
6117 bnx2_write_phy(bp
, bp
->mii_bmcr
, bmcr
);
6118 bp
->phy_flags
|= BNX2_PHY_FLAG_PARALLEL_DETECT
;
6122 else if ((bp
->link_up
) && (bp
->autoneg
& AUTONEG_SPEED
) &&
6123 (bp
->phy_flags
& BNX2_PHY_FLAG_PARALLEL_DETECT
)) {
6126 bnx2_write_phy(bp
, 0x17, 0x0f01);
6127 bnx2_read_phy(bp
, 0x15, &phy2
);
6131 bnx2_read_phy(bp
, bp
->mii_bmcr
, &bmcr
);
6132 bmcr
|= BMCR_ANENABLE
;
6133 bnx2_write_phy(bp
, bp
->mii_bmcr
, bmcr
);
6135 bp
->phy_flags
&= ~BNX2_PHY_FLAG_PARALLEL_DETECT
;
6138 bp
->current_interval
= BNX2_TIMER_INTERVAL
;
6143 bnx2_write_phy(bp
, MII_BNX2_MISC_SHADOW
, MISC_SHDW_AN_DBG
);
6144 bnx2_read_phy(bp
, MII_BNX2_MISC_SHADOW
, &val
);
6145 bnx2_read_phy(bp
, MII_BNX2_MISC_SHADOW
, &val
);
6147 if (bp
->link_up
&& (val
& MISC_SHDW_AN_DBG_NOSYNC
)) {
6148 if (!(bp
->phy_flags
& BNX2_PHY_FLAG_FORCED_DOWN
)) {
6149 bnx2_5706s_force_link_dn(bp
, 1);
6150 bp
->phy_flags
|= BNX2_PHY_FLAG_FORCED_DOWN
;
6153 } else if (!bp
->link_up
&& !(val
& MISC_SHDW_AN_DBG_NOSYNC
))
6156 spin_unlock(&bp
->phy_lock
);
6160 bnx2_5708_serdes_timer(struct bnx2
*bp
)
6162 if (bp
->phy_flags
& BNX2_PHY_FLAG_REMOTE_PHY_CAP
)
6165 if ((bp
->phy_flags
& BNX2_PHY_FLAG_2_5G_CAPABLE
) == 0) {
6166 bp
->serdes_an_pending
= 0;
6170 spin_lock(&bp
->phy_lock
);
6171 if (bp
->serdes_an_pending
)
6172 bp
->serdes_an_pending
--;
6173 else if ((bp
->link_up
== 0) && (bp
->autoneg
& AUTONEG_SPEED
)) {
6176 bnx2_read_phy(bp
, bp
->mii_bmcr
, &bmcr
);
6177 if (bmcr
& BMCR_ANENABLE
) {
6178 bnx2_enable_forced_2g5(bp
);
6179 bp
->current_interval
= BNX2_SERDES_FORCED_TIMEOUT
;
6181 bnx2_disable_forced_2g5(bp
);
6182 bp
->serdes_an_pending
= 2;
6183 bp
->current_interval
= BNX2_TIMER_INTERVAL
;
6187 bp
->current_interval
= BNX2_TIMER_INTERVAL
;
6189 spin_unlock(&bp
->phy_lock
);
6193 bnx2_timer(unsigned long data
)
6195 struct bnx2
*bp
= (struct bnx2
*) data
;
6197 if (!netif_running(bp
->dev
))
6200 if (atomic_read(&bp
->intr_sem
) != 0)
6201 goto bnx2_restart_timer
;
6203 if ((bp
->flags
& (BNX2_FLAG_USING_MSI
| BNX2_FLAG_ONE_SHOT_MSI
)) ==
6204 BNX2_FLAG_USING_MSI
)
6205 bnx2_chk_missed_msi(bp
);
6207 bnx2_send_heart_beat(bp
);
6209 bp
->stats_blk
->stat_FwRxDrop
=
6210 bnx2_reg_rd_ind(bp
, BNX2_FW_RX_DROP_COUNT
);
6212 /* workaround occasional corrupted counters */
6213 if ((bp
->flags
& BNX2_FLAG_BROKEN_STATS
) && bp
->stats_ticks
)
6214 BNX2_WR(bp
, BNX2_HC_COMMAND
, bp
->hc_cmd
|
6215 BNX2_HC_COMMAND_STATS_NOW
);
6217 if (bp
->phy_flags
& BNX2_PHY_FLAG_SERDES
) {
6218 if (BNX2_CHIP(bp
) == BNX2_CHIP_5706
)
6219 bnx2_5706_serdes_timer(bp
);
6221 bnx2_5708_serdes_timer(bp
);
6225 mod_timer(&bp
->timer
, jiffies
+ bp
->current_interval
);
6229 bnx2_request_irq(struct bnx2
*bp
)
6231 unsigned long flags
;
6232 struct bnx2_irq
*irq
;
6235 if (bp
->flags
& BNX2_FLAG_USING_MSI_OR_MSIX
)
6238 flags
= IRQF_SHARED
;
6240 for (i
= 0; i
< bp
->irq_nvecs
; i
++) {
6241 irq
= &bp
->irq_tbl
[i
];
6242 rc
= request_irq(irq
->vector
, irq
->handler
, flags
, irq
->name
,
6252 __bnx2_free_irq(struct bnx2
*bp
)
6254 struct bnx2_irq
*irq
;
6257 for (i
= 0; i
< bp
->irq_nvecs
; i
++) {
6258 irq
= &bp
->irq_tbl
[i
];
6260 free_irq(irq
->vector
, &bp
->bnx2_napi
[i
]);
6266 bnx2_free_irq(struct bnx2
*bp
)
6269 __bnx2_free_irq(bp
);
6270 if (bp
->flags
& BNX2_FLAG_USING_MSI
)
6271 pci_disable_msi(bp
->pdev
);
6272 else if (bp
->flags
& BNX2_FLAG_USING_MSIX
)
6273 pci_disable_msix(bp
->pdev
);
6275 bp
->flags
&= ~(BNX2_FLAG_USING_MSI_OR_MSIX
| BNX2_FLAG_ONE_SHOT_MSI
);
6279 bnx2_enable_msix(struct bnx2
*bp
, int msix_vecs
)
6282 struct msix_entry msix_ent
[BNX2_MAX_MSIX_VEC
];
6283 struct net_device
*dev
= bp
->dev
;
6284 const int len
= sizeof(bp
->irq_tbl
[0].name
);
6286 bnx2_setup_msix_tbl(bp
);
6287 BNX2_WR(bp
, BNX2_PCI_MSIX_CONTROL
, BNX2_MAX_MSIX_HW_VEC
- 1);
6288 BNX2_WR(bp
, BNX2_PCI_MSIX_TBL_OFF_BIR
, BNX2_PCI_GRC_WINDOW2_BASE
);
6289 BNX2_WR(bp
, BNX2_PCI_MSIX_PBA_OFF_BIT
, BNX2_PCI_GRC_WINDOW3_BASE
);
6291 /* Need to flush the previous three writes to ensure MSI-X
6292 * is setup properly */
6293 BNX2_RD(bp
, BNX2_PCI_MSIX_CONTROL
);
6295 for (i
= 0; i
< BNX2_MAX_MSIX_VEC
; i
++) {
6296 msix_ent
[i
].entry
= i
;
6297 msix_ent
[i
].vector
= 0;
6300 total_vecs
= msix_vecs
;
6304 total_vecs
= pci_enable_msix_range(bp
->pdev
, msix_ent
,
6305 BNX2_MIN_MSIX_VEC
, total_vecs
);
6309 msix_vecs
= total_vecs
;
6313 bp
->irq_nvecs
= msix_vecs
;
6314 bp
->flags
|= BNX2_FLAG_USING_MSIX
| BNX2_FLAG_ONE_SHOT_MSI
;
6315 for (i
= 0; i
< total_vecs
; i
++) {
6316 bp
->irq_tbl
[i
].vector
= msix_ent
[i
].vector
;
6317 snprintf(bp
->irq_tbl
[i
].name
, len
, "%s-%d", dev
->name
, i
);
6318 bp
->irq_tbl
[i
].handler
= bnx2_msi_1shot
;
6323 bnx2_setup_int_mode(struct bnx2
*bp
, int dis_msi
)
6325 int cpus
= netif_get_num_default_rss_queues();
6328 if (!bp
->num_req_rx_rings
)
6329 msix_vecs
= max(cpus
+ 1, bp
->num_req_tx_rings
);
6330 else if (!bp
->num_req_tx_rings
)
6331 msix_vecs
= max(cpus
, bp
->num_req_rx_rings
);
6333 msix_vecs
= max(bp
->num_req_rx_rings
, bp
->num_req_tx_rings
);
6335 msix_vecs
= min(msix_vecs
, RX_MAX_RINGS
);
6337 bp
->irq_tbl
[0].handler
= bnx2_interrupt
;
6338 strcpy(bp
->irq_tbl
[0].name
, bp
->dev
->name
);
6340 bp
->irq_tbl
[0].vector
= bp
->pdev
->irq
;
6342 if ((bp
->flags
& BNX2_FLAG_MSIX_CAP
) && !dis_msi
)
6343 bnx2_enable_msix(bp
, msix_vecs
);
6345 if ((bp
->flags
& BNX2_FLAG_MSI_CAP
) && !dis_msi
&&
6346 !(bp
->flags
& BNX2_FLAG_USING_MSIX
)) {
6347 if (pci_enable_msi(bp
->pdev
) == 0) {
6348 bp
->flags
|= BNX2_FLAG_USING_MSI
;
6349 if (BNX2_CHIP(bp
) == BNX2_CHIP_5709
) {
6350 bp
->flags
|= BNX2_FLAG_ONE_SHOT_MSI
;
6351 bp
->irq_tbl
[0].handler
= bnx2_msi_1shot
;
6353 bp
->irq_tbl
[0].handler
= bnx2_msi
;
6355 bp
->irq_tbl
[0].vector
= bp
->pdev
->irq
;
6359 if (!bp
->num_req_tx_rings
)
6360 bp
->num_tx_rings
= rounddown_pow_of_two(bp
->irq_nvecs
);
6362 bp
->num_tx_rings
= min(bp
->irq_nvecs
, bp
->num_req_tx_rings
);
6364 if (!bp
->num_req_rx_rings
)
6365 bp
->num_rx_rings
= bp
->irq_nvecs
;
6367 bp
->num_rx_rings
= min(bp
->irq_nvecs
, bp
->num_req_rx_rings
);
6369 netif_set_real_num_tx_queues(bp
->dev
, bp
->num_tx_rings
);
6371 return netif_set_real_num_rx_queues(bp
->dev
, bp
->num_rx_rings
);
6374 /* Called with rtnl_lock */
6376 bnx2_open(struct net_device
*dev
)
6378 struct bnx2
*bp
= netdev_priv(dev
);
6381 rc
= bnx2_request_firmware(bp
);
6385 netif_carrier_off(dev
);
6387 bnx2_disable_int(bp
);
6389 rc
= bnx2_setup_int_mode(bp
, disable_msi
);
6393 bnx2_napi_enable(bp
);
6394 rc
= bnx2_alloc_mem(bp
);
6398 rc
= bnx2_request_irq(bp
);
6402 rc
= bnx2_init_nic(bp
, 1);
6406 mod_timer(&bp
->timer
, jiffies
+ bp
->current_interval
);
6408 atomic_set(&bp
->intr_sem
, 0);
6410 memset(bp
->temp_stats_blk
, 0, sizeof(struct statistics_block
));
6412 bnx2_enable_int(bp
);
6414 if (bp
->flags
& BNX2_FLAG_USING_MSI
) {
6415 /* Test MSI to make sure it is working
6416 * If MSI test fails, go back to INTx mode
6418 if (bnx2_test_intr(bp
) != 0) {
6419 netdev_warn(bp
->dev
, "No interrupt was generated using MSI, switching to INTx mode. Please report this failure to the PCI maintainer and include system chipset information.\n");
6421 bnx2_disable_int(bp
);
6424 bnx2_setup_int_mode(bp
, 1);
6426 rc
= bnx2_init_nic(bp
, 0);
6429 rc
= bnx2_request_irq(bp
);
6432 del_timer_sync(&bp
->timer
);
6435 bnx2_enable_int(bp
);
6438 if (bp
->flags
& BNX2_FLAG_USING_MSI
)
6439 netdev_info(dev
, "using MSI\n");
6440 else if (bp
->flags
& BNX2_FLAG_USING_MSIX
)
6441 netdev_info(dev
, "using MSIX\n");
6443 netif_tx_start_all_queues(dev
);
6448 bnx2_napi_disable(bp
);
6453 bnx2_release_firmware(bp
);
6458 bnx2_reset_task(struct work_struct
*work
)
6460 struct bnx2
*bp
= container_of(work
, struct bnx2
, reset_task
);
6465 if (!netif_running(bp
->dev
)) {
6470 bnx2_netif_stop(bp
, true);
6472 pci_read_config_word(bp
->pdev
, PCI_COMMAND
, &pcicmd
);
6473 if (!(pcicmd
& PCI_COMMAND_MEMORY
)) {
6474 /* in case PCI block has reset */
6475 pci_restore_state(bp
->pdev
);
6476 pci_save_state(bp
->pdev
);
6478 rc
= bnx2_init_nic(bp
, 1);
6480 netdev_err(bp
->dev
, "failed to reset NIC, closing\n");
6481 bnx2_napi_enable(bp
);
6487 atomic_set(&bp
->intr_sem
, 1);
6488 bnx2_netif_start(bp
, true);
6492 #define BNX2_FTQ_ENTRY(ftq) { __stringify(ftq##FTQ_CTL), BNX2_##ftq##FTQ_CTL }
6495 bnx2_dump_ftq(struct bnx2
*bp
)
6498 u32 reg
, bdidx
, cid
, valid
;
6499 struct net_device
*dev
= bp
->dev
;
6500 static const struct ftq_reg
{
6504 BNX2_FTQ_ENTRY(RV2P_P
),
6505 BNX2_FTQ_ENTRY(RV2P_T
),
6506 BNX2_FTQ_ENTRY(RV2P_M
),
6507 BNX2_FTQ_ENTRY(TBDR_
),
6508 BNX2_FTQ_ENTRY(TDMA_
),
6509 BNX2_FTQ_ENTRY(TXP_
),
6510 BNX2_FTQ_ENTRY(TXP_
),
6511 BNX2_FTQ_ENTRY(TPAT_
),
6512 BNX2_FTQ_ENTRY(RXP_C
),
6513 BNX2_FTQ_ENTRY(RXP_
),
6514 BNX2_FTQ_ENTRY(COM_COMXQ_
),
6515 BNX2_FTQ_ENTRY(COM_COMTQ_
),
6516 BNX2_FTQ_ENTRY(COM_COMQ_
),
6517 BNX2_FTQ_ENTRY(CP_CPQ_
),
6520 netdev_err(dev
, "<--- start FTQ dump --->\n");
6521 for (i
= 0; i
< ARRAY_SIZE(ftq_arr
); i
++)
6522 netdev_err(dev
, "%s %08x\n", ftq_arr
[i
].name
,
6523 bnx2_reg_rd_ind(bp
, ftq_arr
[i
].off
));
6525 netdev_err(dev
, "CPU states:\n");
6526 for (reg
= BNX2_TXP_CPU_MODE
; reg
<= BNX2_CP_CPU_MODE
; reg
+= 0x40000)
6527 netdev_err(dev
, "%06x mode %x state %x evt_mask %x pc %x pc %x instr %x\n",
6528 reg
, bnx2_reg_rd_ind(bp
, reg
),
6529 bnx2_reg_rd_ind(bp
, reg
+ 4),
6530 bnx2_reg_rd_ind(bp
, reg
+ 8),
6531 bnx2_reg_rd_ind(bp
, reg
+ 0x1c),
6532 bnx2_reg_rd_ind(bp
, reg
+ 0x1c),
6533 bnx2_reg_rd_ind(bp
, reg
+ 0x20));
6535 netdev_err(dev
, "<--- end FTQ dump --->\n");
6536 netdev_err(dev
, "<--- start TBDC dump --->\n");
6537 netdev_err(dev
, "TBDC free cnt: %ld\n",
6538 BNX2_RD(bp
, BNX2_TBDC_STATUS
) & BNX2_TBDC_STATUS_FREE_CNT
);
6539 netdev_err(dev
, "LINE CID BIDX CMD VALIDS\n");
6540 for (i
= 0; i
< 0x20; i
++) {
6543 BNX2_WR(bp
, BNX2_TBDC_BD_ADDR
, i
);
6544 BNX2_WR(bp
, BNX2_TBDC_CAM_OPCODE
,
6545 BNX2_TBDC_CAM_OPCODE_OPCODE_CAM_READ
);
6546 BNX2_WR(bp
, BNX2_TBDC_COMMAND
, BNX2_TBDC_COMMAND_CMD_REG_ARB
);
6547 while ((BNX2_RD(bp
, BNX2_TBDC_COMMAND
) &
6548 BNX2_TBDC_COMMAND_CMD_REG_ARB
) && j
< 100)
6551 cid
= BNX2_RD(bp
, BNX2_TBDC_CID
);
6552 bdidx
= BNX2_RD(bp
, BNX2_TBDC_BIDX
);
6553 valid
= BNX2_RD(bp
, BNX2_TBDC_CAM_OPCODE
);
6554 netdev_err(dev
, "%02x %06x %04lx %02x [%x]\n",
6555 i
, cid
, bdidx
& BNX2_TBDC_BDIDX_BDIDX
,
6556 bdidx
>> 24, (valid
>> 8) & 0x0ff);
6558 netdev_err(dev
, "<--- end TBDC dump --->\n");
6562 bnx2_dump_state(struct bnx2
*bp
)
6564 struct net_device
*dev
= bp
->dev
;
6567 pci_read_config_dword(bp
->pdev
, PCI_COMMAND
, &val1
);
6568 netdev_err(dev
, "DEBUG: intr_sem[%x] PCI_CMD[%08x]\n",
6569 atomic_read(&bp
->intr_sem
), val1
);
6570 pci_read_config_dword(bp
->pdev
, bp
->pm_cap
+ PCI_PM_CTRL
, &val1
);
6571 pci_read_config_dword(bp
->pdev
, BNX2_PCICFG_MISC_CONFIG
, &val2
);
6572 netdev_err(dev
, "DEBUG: PCI_PM[%08x] PCI_MISC_CFG[%08x]\n", val1
, val2
);
6573 netdev_err(dev
, "DEBUG: EMAC_TX_STATUS[%08x] EMAC_RX_STATUS[%08x]\n",
6574 BNX2_RD(bp
, BNX2_EMAC_TX_STATUS
),
6575 BNX2_RD(bp
, BNX2_EMAC_RX_STATUS
));
6576 netdev_err(dev
, "DEBUG: RPM_MGMT_PKT_CTRL[%08x]\n",
6577 BNX2_RD(bp
, BNX2_RPM_MGMT_PKT_CTRL
));
6578 netdev_err(dev
, "DEBUG: HC_STATS_INTERRUPT_STATUS[%08x]\n",
6579 BNX2_RD(bp
, BNX2_HC_STATS_INTERRUPT_STATUS
));
6580 if (bp
->flags
& BNX2_FLAG_USING_MSIX
)
6581 netdev_err(dev
, "DEBUG: PBA[%08x]\n",
6582 BNX2_RD(bp
, BNX2_PCI_GRC_WINDOW3_BASE
));
6586 bnx2_tx_timeout(struct net_device
*dev
)
6588 struct bnx2
*bp
= netdev_priv(dev
);
6591 bnx2_dump_state(bp
);
6592 bnx2_dump_mcp_state(bp
);
6594 /* This allows the netif to be shutdown gracefully before resetting */
6595 schedule_work(&bp
->reset_task
);
6598 /* Called with netif_tx_lock.
6599 * bnx2_tx_int() runs without netif_tx_lock unless it needs to call
6600 * netif_wake_queue().
6603 bnx2_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
6605 struct bnx2
*bp
= netdev_priv(dev
);
6607 struct bnx2_tx_bd
*txbd
;
6608 struct bnx2_sw_tx_bd
*tx_buf
;
6609 u32 len
, vlan_tag_flags
, last_frag
, mss
;
6610 u16 prod
, ring_prod
;
6612 struct bnx2_napi
*bnapi
;
6613 struct bnx2_tx_ring_info
*txr
;
6614 struct netdev_queue
*txq
;
6616 /* Determine which tx ring we will be placed on */
6617 i
= skb_get_queue_mapping(skb
);
6618 bnapi
= &bp
->bnx2_napi
[i
];
6619 txr
= &bnapi
->tx_ring
;
6620 txq
= netdev_get_tx_queue(dev
, i
);
6622 if (unlikely(bnx2_tx_avail(bp
, txr
) <
6623 (skb_shinfo(skb
)->nr_frags
+ 1))) {
6624 netif_tx_stop_queue(txq
);
6625 netdev_err(dev
, "BUG! Tx ring full when queue awake!\n");
6627 return NETDEV_TX_BUSY
;
6629 len
= skb_headlen(skb
);
6630 prod
= txr
->tx_prod
;
6631 ring_prod
= BNX2_TX_RING_IDX(prod
);
6634 if (skb
->ip_summed
== CHECKSUM_PARTIAL
) {
6635 vlan_tag_flags
|= TX_BD_FLAGS_TCP_UDP_CKSUM
;
6638 if (skb_vlan_tag_present(skb
)) {
6640 (TX_BD_FLAGS_VLAN_TAG
| (skb_vlan_tag_get(skb
) << 16));
6643 if ((mss
= skb_shinfo(skb
)->gso_size
)) {
6647 vlan_tag_flags
|= TX_BD_FLAGS_SW_LSO
;
6649 tcp_opt_len
= tcp_optlen(skb
);
6651 if (skb_shinfo(skb
)->gso_type
& SKB_GSO_TCPV6
) {
6652 u32 tcp_off
= skb_transport_offset(skb
) -
6653 sizeof(struct ipv6hdr
) - ETH_HLEN
;
6655 vlan_tag_flags
|= ((tcp_opt_len
>> 2) << 8) |
6656 TX_BD_FLAGS_SW_FLAGS
;
6657 if (likely(tcp_off
== 0))
6658 vlan_tag_flags
&= ~TX_BD_FLAGS_TCP6_OFF0_MSK
;
6661 vlan_tag_flags
|= ((tcp_off
& 0x3) <<
6662 TX_BD_FLAGS_TCP6_OFF0_SHL
) |
6663 ((tcp_off
& 0x10) <<
6664 TX_BD_FLAGS_TCP6_OFF4_SHL
);
6665 mss
|= (tcp_off
& 0xc) << TX_BD_TCP6_OFF2_SHL
;
6669 if (tcp_opt_len
|| (iph
->ihl
> 5)) {
6670 vlan_tag_flags
|= ((iph
->ihl
- 5) +
6671 (tcp_opt_len
>> 2)) << 8;
6677 mapping
= dma_map_single(&bp
->pdev
->dev
, skb
->data
, len
, PCI_DMA_TODEVICE
);
6678 if (dma_mapping_error(&bp
->pdev
->dev
, mapping
)) {
6679 dev_kfree_skb_any(skb
);
6680 return NETDEV_TX_OK
;
6683 tx_buf
= &txr
->tx_buf_ring
[ring_prod
];
6685 dma_unmap_addr_set(tx_buf
, mapping
, mapping
);
6687 txbd
= &txr
->tx_desc_ring
[ring_prod
];
6689 txbd
->tx_bd_haddr_hi
= (u64
) mapping
>> 32;
6690 txbd
->tx_bd_haddr_lo
= (u64
) mapping
& 0xffffffff;
6691 txbd
->tx_bd_mss_nbytes
= len
| (mss
<< 16);
6692 txbd
->tx_bd_vlan_tag_flags
= vlan_tag_flags
| TX_BD_FLAGS_START
;
6694 last_frag
= skb_shinfo(skb
)->nr_frags
;
6695 tx_buf
->nr_frags
= last_frag
;
6696 tx_buf
->is_gso
= skb_is_gso(skb
);
6698 for (i
= 0; i
< last_frag
; i
++) {
6699 const skb_frag_t
*frag
= &skb_shinfo(skb
)->frags
[i
];
6701 prod
= BNX2_NEXT_TX_BD(prod
);
6702 ring_prod
= BNX2_TX_RING_IDX(prod
);
6703 txbd
= &txr
->tx_desc_ring
[ring_prod
];
6705 len
= skb_frag_size(frag
);
6706 mapping
= skb_frag_dma_map(&bp
->pdev
->dev
, frag
, 0, len
,
6708 if (dma_mapping_error(&bp
->pdev
->dev
, mapping
))
6710 dma_unmap_addr_set(&txr
->tx_buf_ring
[ring_prod
], mapping
,
6713 txbd
->tx_bd_haddr_hi
= (u64
) mapping
>> 32;
6714 txbd
->tx_bd_haddr_lo
= (u64
) mapping
& 0xffffffff;
6715 txbd
->tx_bd_mss_nbytes
= len
| (mss
<< 16);
6716 txbd
->tx_bd_vlan_tag_flags
= vlan_tag_flags
;
6719 txbd
->tx_bd_vlan_tag_flags
|= TX_BD_FLAGS_END
;
6721 /* Sync BD data before updating TX mailbox */
6724 netdev_tx_sent_queue(txq
, skb
->len
);
6726 prod
= BNX2_NEXT_TX_BD(prod
);
6727 txr
->tx_prod_bseq
+= skb
->len
;
6729 BNX2_WR16(bp
, txr
->tx_bidx_addr
, prod
);
6730 BNX2_WR(bp
, txr
->tx_bseq_addr
, txr
->tx_prod_bseq
);
6734 txr
->tx_prod
= prod
;
6736 if (unlikely(bnx2_tx_avail(bp
, txr
) <= MAX_SKB_FRAGS
)) {
6737 netif_tx_stop_queue(txq
);
6739 /* netif_tx_stop_queue() must be done before checking
6740 * tx index in bnx2_tx_avail() below, because in
6741 * bnx2_tx_int(), we update tx index before checking for
6742 * netif_tx_queue_stopped().
6745 if (bnx2_tx_avail(bp
, txr
) > bp
->tx_wake_thresh
)
6746 netif_tx_wake_queue(txq
);
6749 return NETDEV_TX_OK
;
6751 /* save value of frag that failed */
6754 /* start back at beginning and unmap skb */
6755 prod
= txr
->tx_prod
;
6756 ring_prod
= BNX2_TX_RING_IDX(prod
);
6757 tx_buf
= &txr
->tx_buf_ring
[ring_prod
];
6759 dma_unmap_single(&bp
->pdev
->dev
, dma_unmap_addr(tx_buf
, mapping
),
6760 skb_headlen(skb
), PCI_DMA_TODEVICE
);
6762 /* unmap remaining mapped pages */
6763 for (i
= 0; i
< last_frag
; i
++) {
6764 prod
= BNX2_NEXT_TX_BD(prod
);
6765 ring_prod
= BNX2_TX_RING_IDX(prod
);
6766 tx_buf
= &txr
->tx_buf_ring
[ring_prod
];
6767 dma_unmap_page(&bp
->pdev
->dev
, dma_unmap_addr(tx_buf
, mapping
),
6768 skb_frag_size(&skb_shinfo(skb
)->frags
[i
]),
6772 dev_kfree_skb_any(skb
);
6773 return NETDEV_TX_OK
;
6776 /* Called with rtnl_lock */
6778 bnx2_close(struct net_device
*dev
)
6780 struct bnx2
*bp
= netdev_priv(dev
);
6782 bnx2_disable_int_sync(bp
);
6783 bnx2_napi_disable(bp
);
6784 netif_tx_disable(dev
);
6785 del_timer_sync(&bp
->timer
);
6786 bnx2_shutdown_chip(bp
);
6792 netif_carrier_off(bp
->dev
);
6797 bnx2_save_stats(struct bnx2
*bp
)
6799 u32
*hw_stats
= (u32
*) bp
->stats_blk
;
6800 u32
*temp_stats
= (u32
*) bp
->temp_stats_blk
;
6803 /* The 1st 10 counters are 64-bit counters */
6804 for (i
= 0; i
< 20; i
+= 2) {
6808 hi
= temp_stats
[i
] + hw_stats
[i
];
6809 lo
= (u64
) temp_stats
[i
+ 1] + (u64
) hw_stats
[i
+ 1];
6810 if (lo
> 0xffffffff)
6813 temp_stats
[i
+ 1] = lo
& 0xffffffff;
6816 for ( ; i
< sizeof(struct statistics_block
) / 4; i
++)
6817 temp_stats
[i
] += hw_stats
[i
];
6820 #define GET_64BIT_NET_STATS64(ctr) \
6821 (((u64) (ctr##_hi) << 32) + (u64) (ctr##_lo))
6823 #define GET_64BIT_NET_STATS(ctr) \
6824 GET_64BIT_NET_STATS64(bp->stats_blk->ctr) + \
6825 GET_64BIT_NET_STATS64(bp->temp_stats_blk->ctr)
6827 #define GET_32BIT_NET_STATS(ctr) \
6828 (unsigned long) (bp->stats_blk->ctr + \
6829 bp->temp_stats_blk->ctr)
6831 static struct rtnl_link_stats64
*
6832 bnx2_get_stats64(struct net_device
*dev
, struct rtnl_link_stats64
*net_stats
)
6834 struct bnx2
*bp
= netdev_priv(dev
);
6836 if (bp
->stats_blk
== NULL
)
6839 net_stats
->rx_packets
=
6840 GET_64BIT_NET_STATS(stat_IfHCInUcastPkts
) +
6841 GET_64BIT_NET_STATS(stat_IfHCInMulticastPkts
) +
6842 GET_64BIT_NET_STATS(stat_IfHCInBroadcastPkts
);
6844 net_stats
->tx_packets
=
6845 GET_64BIT_NET_STATS(stat_IfHCOutUcastPkts
) +
6846 GET_64BIT_NET_STATS(stat_IfHCOutMulticastPkts
) +
6847 GET_64BIT_NET_STATS(stat_IfHCOutBroadcastPkts
);
6849 net_stats
->rx_bytes
=
6850 GET_64BIT_NET_STATS(stat_IfHCInOctets
);
6852 net_stats
->tx_bytes
=
6853 GET_64BIT_NET_STATS(stat_IfHCOutOctets
);
6855 net_stats
->multicast
=
6856 GET_64BIT_NET_STATS(stat_IfHCInMulticastPkts
);
6858 net_stats
->collisions
=
6859 GET_32BIT_NET_STATS(stat_EtherStatsCollisions
);
6861 net_stats
->rx_length_errors
=
6862 GET_32BIT_NET_STATS(stat_EtherStatsUndersizePkts
) +
6863 GET_32BIT_NET_STATS(stat_EtherStatsOverrsizePkts
);
6865 net_stats
->rx_over_errors
=
6866 GET_32BIT_NET_STATS(stat_IfInFTQDiscards
) +
6867 GET_32BIT_NET_STATS(stat_IfInMBUFDiscards
);
6869 net_stats
->rx_frame_errors
=
6870 GET_32BIT_NET_STATS(stat_Dot3StatsAlignmentErrors
);
6872 net_stats
->rx_crc_errors
=
6873 GET_32BIT_NET_STATS(stat_Dot3StatsFCSErrors
);
6875 net_stats
->rx_errors
= net_stats
->rx_length_errors
+
6876 net_stats
->rx_over_errors
+ net_stats
->rx_frame_errors
+
6877 net_stats
->rx_crc_errors
;
6879 net_stats
->tx_aborted_errors
=
6880 GET_32BIT_NET_STATS(stat_Dot3StatsExcessiveCollisions
) +
6881 GET_32BIT_NET_STATS(stat_Dot3StatsLateCollisions
);
6883 if ((BNX2_CHIP(bp
) == BNX2_CHIP_5706
) ||
6884 (BNX2_CHIP_ID(bp
) == BNX2_CHIP_ID_5708_A0
))
6885 net_stats
->tx_carrier_errors
= 0;
6887 net_stats
->tx_carrier_errors
=
6888 GET_32BIT_NET_STATS(stat_Dot3StatsCarrierSenseErrors
);
6891 net_stats
->tx_errors
=
6892 GET_32BIT_NET_STATS(stat_emac_tx_stat_dot3statsinternalmactransmiterrors
) +
6893 net_stats
->tx_aborted_errors
+
6894 net_stats
->tx_carrier_errors
;
6896 net_stats
->rx_missed_errors
=
6897 GET_32BIT_NET_STATS(stat_IfInFTQDiscards
) +
6898 GET_32BIT_NET_STATS(stat_IfInMBUFDiscards
) +
6899 GET_32BIT_NET_STATS(stat_FwRxDrop
);
6904 /* All ethtool functions called with rtnl_lock */
6907 bnx2_get_settings(struct net_device
*dev
, struct ethtool_cmd
*cmd
)
6909 struct bnx2
*bp
= netdev_priv(dev
);
6910 int support_serdes
= 0, support_copper
= 0;
6912 cmd
->supported
= SUPPORTED_Autoneg
;
6913 if (bp
->phy_flags
& BNX2_PHY_FLAG_REMOTE_PHY_CAP
) {
6916 } else if (bp
->phy_port
== PORT_FIBRE
)
6921 if (support_serdes
) {
6922 cmd
->supported
|= SUPPORTED_1000baseT_Full
|
6924 if (bp
->phy_flags
& BNX2_PHY_FLAG_2_5G_CAPABLE
)
6925 cmd
->supported
|= SUPPORTED_2500baseX_Full
;
6928 if (support_copper
) {
6929 cmd
->supported
|= SUPPORTED_10baseT_Half
|
6930 SUPPORTED_10baseT_Full
|
6931 SUPPORTED_100baseT_Half
|
6932 SUPPORTED_100baseT_Full
|
6933 SUPPORTED_1000baseT_Full
|
6938 spin_lock_bh(&bp
->phy_lock
);
6939 cmd
->port
= bp
->phy_port
;
6940 cmd
->advertising
= bp
->advertising
;
6942 if (bp
->autoneg
& AUTONEG_SPEED
) {
6943 cmd
->autoneg
= AUTONEG_ENABLE
;
6945 cmd
->autoneg
= AUTONEG_DISABLE
;
6948 if (netif_carrier_ok(dev
)) {
6949 ethtool_cmd_speed_set(cmd
, bp
->line_speed
);
6950 cmd
->duplex
= bp
->duplex
;
6951 if (!(bp
->phy_flags
& BNX2_PHY_FLAG_SERDES
)) {
6952 if (bp
->phy_flags
& BNX2_PHY_FLAG_MDIX
)
6953 cmd
->eth_tp_mdix
= ETH_TP_MDI_X
;
6955 cmd
->eth_tp_mdix
= ETH_TP_MDI
;
6959 ethtool_cmd_speed_set(cmd
, SPEED_UNKNOWN
);
6960 cmd
->duplex
= DUPLEX_UNKNOWN
;
6962 spin_unlock_bh(&bp
->phy_lock
);
6964 cmd
->transceiver
= XCVR_INTERNAL
;
6965 cmd
->phy_address
= bp
->phy_addr
;
6971 bnx2_set_settings(struct net_device
*dev
, struct ethtool_cmd
*cmd
)
6973 struct bnx2
*bp
= netdev_priv(dev
);
6974 u8 autoneg
= bp
->autoneg
;
6975 u8 req_duplex
= bp
->req_duplex
;
6976 u16 req_line_speed
= bp
->req_line_speed
;
6977 u32 advertising
= bp
->advertising
;
6980 spin_lock_bh(&bp
->phy_lock
);
6982 if (cmd
->port
!= PORT_TP
&& cmd
->port
!= PORT_FIBRE
)
6983 goto err_out_unlock
;
6985 if (cmd
->port
!= bp
->phy_port
&&
6986 !(bp
->phy_flags
& BNX2_PHY_FLAG_REMOTE_PHY_CAP
))
6987 goto err_out_unlock
;
6989 /* If device is down, we can store the settings only if the user
6990 * is setting the currently active port.
6992 if (!netif_running(dev
) && cmd
->port
!= bp
->phy_port
)
6993 goto err_out_unlock
;
6995 if (cmd
->autoneg
== AUTONEG_ENABLE
) {
6996 autoneg
|= AUTONEG_SPEED
;
6998 advertising
= cmd
->advertising
;
6999 if (cmd
->port
== PORT_TP
) {
7000 advertising
&= ETHTOOL_ALL_COPPER_SPEED
;
7002 advertising
= ETHTOOL_ALL_COPPER_SPEED
;
7004 advertising
&= ETHTOOL_ALL_FIBRE_SPEED
;
7006 advertising
= ETHTOOL_ALL_FIBRE_SPEED
;
7008 advertising
|= ADVERTISED_Autoneg
;
7011 u32 speed
= ethtool_cmd_speed(cmd
);
7012 if (cmd
->port
== PORT_FIBRE
) {
7013 if ((speed
!= SPEED_1000
&&
7014 speed
!= SPEED_2500
) ||
7015 (cmd
->duplex
!= DUPLEX_FULL
))
7016 goto err_out_unlock
;
7018 if (speed
== SPEED_2500
&&
7019 !(bp
->phy_flags
& BNX2_PHY_FLAG_2_5G_CAPABLE
))
7020 goto err_out_unlock
;
7021 } else if (speed
== SPEED_1000
|| speed
== SPEED_2500
)
7022 goto err_out_unlock
;
7024 autoneg
&= ~AUTONEG_SPEED
;
7025 req_line_speed
= speed
;
7026 req_duplex
= cmd
->duplex
;
7030 bp
->autoneg
= autoneg
;
7031 bp
->advertising
= advertising
;
7032 bp
->req_line_speed
= req_line_speed
;
7033 bp
->req_duplex
= req_duplex
;
7036 /* If device is down, the new settings will be picked up when it is
7039 if (netif_running(dev
))
7040 err
= bnx2_setup_phy(bp
, cmd
->port
);
7043 spin_unlock_bh(&bp
->phy_lock
);
7049 bnx2_get_drvinfo(struct net_device
*dev
, struct ethtool_drvinfo
*info
)
7051 struct bnx2
*bp
= netdev_priv(dev
);
7053 strlcpy(info
->driver
, DRV_MODULE_NAME
, sizeof(info
->driver
));
7054 strlcpy(info
->version
, DRV_MODULE_VERSION
, sizeof(info
->version
));
7055 strlcpy(info
->bus_info
, pci_name(bp
->pdev
), sizeof(info
->bus_info
));
7056 strlcpy(info
->fw_version
, bp
->fw_version
, sizeof(info
->fw_version
));
7059 #define BNX2_REGDUMP_LEN (32 * 1024)
7062 bnx2_get_regs_len(struct net_device
*dev
)
7064 return BNX2_REGDUMP_LEN
;
7068 bnx2_get_regs(struct net_device
*dev
, struct ethtool_regs
*regs
, void *_p
)
7070 u32
*p
= _p
, i
, offset
;
7072 struct bnx2
*bp
= netdev_priv(dev
);
7073 static const u32 reg_boundaries
[] = {
7074 0x0000, 0x0098, 0x0400, 0x045c,
7075 0x0800, 0x0880, 0x0c00, 0x0c10,
7076 0x0c30, 0x0d08, 0x1000, 0x101c,
7077 0x1040, 0x1048, 0x1080, 0x10a4,
7078 0x1400, 0x1490, 0x1498, 0x14f0,
7079 0x1500, 0x155c, 0x1580, 0x15dc,
7080 0x1600, 0x1658, 0x1680, 0x16d8,
7081 0x1800, 0x1820, 0x1840, 0x1854,
7082 0x1880, 0x1894, 0x1900, 0x1984,
7083 0x1c00, 0x1c0c, 0x1c40, 0x1c54,
7084 0x1c80, 0x1c94, 0x1d00, 0x1d84,
7085 0x2000, 0x2030, 0x23c0, 0x2400,
7086 0x2800, 0x2820, 0x2830, 0x2850,
7087 0x2b40, 0x2c10, 0x2fc0, 0x3058,
7088 0x3c00, 0x3c94, 0x4000, 0x4010,
7089 0x4080, 0x4090, 0x43c0, 0x4458,
7090 0x4c00, 0x4c18, 0x4c40, 0x4c54,
7091 0x4fc0, 0x5010, 0x53c0, 0x5444,
7092 0x5c00, 0x5c18, 0x5c80, 0x5c90,
7093 0x5fc0, 0x6000, 0x6400, 0x6428,
7094 0x6800, 0x6848, 0x684c, 0x6860,
7095 0x6888, 0x6910, 0x8000
7100 memset(p
, 0, BNX2_REGDUMP_LEN
);
7102 if (!netif_running(bp
->dev
))
7106 offset
= reg_boundaries
[0];
7108 while (offset
< BNX2_REGDUMP_LEN
) {
7109 *p
++ = BNX2_RD(bp
, offset
);
7111 if (offset
== reg_boundaries
[i
+ 1]) {
7112 offset
= reg_boundaries
[i
+ 2];
7113 p
= (u32
*) (orig_p
+ offset
);
7120 bnx2_get_wol(struct net_device
*dev
, struct ethtool_wolinfo
*wol
)
7122 struct bnx2
*bp
= netdev_priv(dev
);
7124 if (bp
->flags
& BNX2_FLAG_NO_WOL
) {
7129 wol
->supported
= WAKE_MAGIC
;
7131 wol
->wolopts
= WAKE_MAGIC
;
7135 memset(&wol
->sopass
, 0, sizeof(wol
->sopass
));
7139 bnx2_set_wol(struct net_device
*dev
, struct ethtool_wolinfo
*wol
)
7141 struct bnx2
*bp
= netdev_priv(dev
);
7143 if (wol
->wolopts
& ~WAKE_MAGIC
)
7146 if (wol
->wolopts
& WAKE_MAGIC
) {
7147 if (bp
->flags
& BNX2_FLAG_NO_WOL
)
7156 device_set_wakeup_enable(&bp
->pdev
->dev
, bp
->wol
);
7162 bnx2_nway_reset(struct net_device
*dev
)
7164 struct bnx2
*bp
= netdev_priv(dev
);
7167 if (!netif_running(dev
))
7170 if (!(bp
->autoneg
& AUTONEG_SPEED
)) {
7174 spin_lock_bh(&bp
->phy_lock
);
7176 if (bp
->phy_flags
& BNX2_PHY_FLAG_REMOTE_PHY_CAP
) {
7179 rc
= bnx2_setup_remote_phy(bp
, bp
->phy_port
);
7180 spin_unlock_bh(&bp
->phy_lock
);
7184 /* Force a link down visible on the other side */
7185 if (bp
->phy_flags
& BNX2_PHY_FLAG_SERDES
) {
7186 bnx2_write_phy(bp
, bp
->mii_bmcr
, BMCR_LOOPBACK
);
7187 spin_unlock_bh(&bp
->phy_lock
);
7191 spin_lock_bh(&bp
->phy_lock
);
7193 bp
->current_interval
= BNX2_SERDES_AN_TIMEOUT
;
7194 bp
->serdes_an_pending
= 1;
7195 mod_timer(&bp
->timer
, jiffies
+ bp
->current_interval
);
7198 bnx2_read_phy(bp
, bp
->mii_bmcr
, &bmcr
);
7199 bmcr
&= ~BMCR_LOOPBACK
;
7200 bnx2_write_phy(bp
, bp
->mii_bmcr
, bmcr
| BMCR_ANRESTART
| BMCR_ANENABLE
);
7202 spin_unlock_bh(&bp
->phy_lock
);
7208 bnx2_get_link(struct net_device
*dev
)
7210 struct bnx2
*bp
= netdev_priv(dev
);
7216 bnx2_get_eeprom_len(struct net_device
*dev
)
7218 struct bnx2
*bp
= netdev_priv(dev
);
7220 if (bp
->flash_info
== NULL
)
7223 return (int) bp
->flash_size
;
7227 bnx2_get_eeprom(struct net_device
*dev
, struct ethtool_eeprom
*eeprom
,
7230 struct bnx2
*bp
= netdev_priv(dev
);
7233 /* parameters already validated in ethtool_get_eeprom */
7235 rc
= bnx2_nvram_read(bp
, eeprom
->offset
, eebuf
, eeprom
->len
);
7241 bnx2_set_eeprom(struct net_device
*dev
, struct ethtool_eeprom
*eeprom
,
7244 struct bnx2
*bp
= netdev_priv(dev
);
7247 /* parameters already validated in ethtool_set_eeprom */
7249 rc
= bnx2_nvram_write(bp
, eeprom
->offset
, eebuf
, eeprom
->len
);
7255 bnx2_get_coalesce(struct net_device
*dev
, struct ethtool_coalesce
*coal
)
7257 struct bnx2
*bp
= netdev_priv(dev
);
7259 memset(coal
, 0, sizeof(struct ethtool_coalesce
));
7261 coal
->rx_coalesce_usecs
= bp
->rx_ticks
;
7262 coal
->rx_max_coalesced_frames
= bp
->rx_quick_cons_trip
;
7263 coal
->rx_coalesce_usecs_irq
= bp
->rx_ticks_int
;
7264 coal
->rx_max_coalesced_frames_irq
= bp
->rx_quick_cons_trip_int
;
7266 coal
->tx_coalesce_usecs
= bp
->tx_ticks
;
7267 coal
->tx_max_coalesced_frames
= bp
->tx_quick_cons_trip
;
7268 coal
->tx_coalesce_usecs_irq
= bp
->tx_ticks_int
;
7269 coal
->tx_max_coalesced_frames_irq
= bp
->tx_quick_cons_trip_int
;
7271 coal
->stats_block_coalesce_usecs
= bp
->stats_ticks
;
7277 bnx2_set_coalesce(struct net_device
*dev
, struct ethtool_coalesce
*coal
)
7279 struct bnx2
*bp
= netdev_priv(dev
);
7281 bp
->rx_ticks
= (u16
) coal
->rx_coalesce_usecs
;
7282 if (bp
->rx_ticks
> 0x3ff) bp
->rx_ticks
= 0x3ff;
7284 bp
->rx_quick_cons_trip
= (u16
) coal
->rx_max_coalesced_frames
;
7285 if (bp
->rx_quick_cons_trip
> 0xff) bp
->rx_quick_cons_trip
= 0xff;
7287 bp
->rx_ticks_int
= (u16
) coal
->rx_coalesce_usecs_irq
;
7288 if (bp
->rx_ticks_int
> 0x3ff) bp
->rx_ticks_int
= 0x3ff;
7290 bp
->rx_quick_cons_trip_int
= (u16
) coal
->rx_max_coalesced_frames_irq
;
7291 if (bp
->rx_quick_cons_trip_int
> 0xff)
7292 bp
->rx_quick_cons_trip_int
= 0xff;
7294 bp
->tx_ticks
= (u16
) coal
->tx_coalesce_usecs
;
7295 if (bp
->tx_ticks
> 0x3ff) bp
->tx_ticks
= 0x3ff;
7297 bp
->tx_quick_cons_trip
= (u16
) coal
->tx_max_coalesced_frames
;
7298 if (bp
->tx_quick_cons_trip
> 0xff) bp
->tx_quick_cons_trip
= 0xff;
7300 bp
->tx_ticks_int
= (u16
) coal
->tx_coalesce_usecs_irq
;
7301 if (bp
->tx_ticks_int
> 0x3ff) bp
->tx_ticks_int
= 0x3ff;
7303 bp
->tx_quick_cons_trip_int
= (u16
) coal
->tx_max_coalesced_frames_irq
;
7304 if (bp
->tx_quick_cons_trip_int
> 0xff) bp
->tx_quick_cons_trip_int
=
7307 bp
->stats_ticks
= coal
->stats_block_coalesce_usecs
;
7308 if (bp
->flags
& BNX2_FLAG_BROKEN_STATS
) {
7309 if (bp
->stats_ticks
!= 0 && bp
->stats_ticks
!= USEC_PER_SEC
)
7310 bp
->stats_ticks
= USEC_PER_SEC
;
7312 if (bp
->stats_ticks
> BNX2_HC_STATS_TICKS_HC_STAT_TICKS
)
7313 bp
->stats_ticks
= BNX2_HC_STATS_TICKS_HC_STAT_TICKS
;
7314 bp
->stats_ticks
&= BNX2_HC_STATS_TICKS_HC_STAT_TICKS
;
7316 if (netif_running(bp
->dev
)) {
7317 bnx2_netif_stop(bp
, true);
7318 bnx2_init_nic(bp
, 0);
7319 bnx2_netif_start(bp
, true);
7326 bnx2_get_ringparam(struct net_device
*dev
, struct ethtool_ringparam
*ering
)
7328 struct bnx2
*bp
= netdev_priv(dev
);
7330 ering
->rx_max_pending
= BNX2_MAX_TOTAL_RX_DESC_CNT
;
7331 ering
->rx_jumbo_max_pending
= BNX2_MAX_TOTAL_RX_PG_DESC_CNT
;
7333 ering
->rx_pending
= bp
->rx_ring_size
;
7334 ering
->rx_jumbo_pending
= bp
->rx_pg_ring_size
;
7336 ering
->tx_max_pending
= BNX2_MAX_TX_DESC_CNT
;
7337 ering
->tx_pending
= bp
->tx_ring_size
;
7341 bnx2_change_ring_size(struct bnx2
*bp
, u32 rx
, u32 tx
, bool reset_irq
)
7343 if (netif_running(bp
->dev
)) {
7344 /* Reset will erase chipset stats; save them */
7345 bnx2_save_stats(bp
);
7347 bnx2_netif_stop(bp
, true);
7348 bnx2_reset_chip(bp
, BNX2_DRV_MSG_CODE_RESET
);
7353 __bnx2_free_irq(bp
);
7359 bnx2_set_rx_ring_size(bp
, rx
);
7360 bp
->tx_ring_size
= tx
;
7362 if (netif_running(bp
->dev
)) {
7366 rc
= bnx2_setup_int_mode(bp
, disable_msi
);
7371 rc
= bnx2_alloc_mem(bp
);
7374 rc
= bnx2_request_irq(bp
);
7377 rc
= bnx2_init_nic(bp
, 0);
7380 bnx2_napi_enable(bp
);
7385 mutex_lock(&bp
->cnic_lock
);
7386 /* Let cnic know about the new status block. */
7387 if (bp
->cnic_eth_dev
.drv_state
& CNIC_DRV_STATE_REGD
)
7388 bnx2_setup_cnic_irq_info(bp
);
7389 mutex_unlock(&bp
->cnic_lock
);
7391 bnx2_netif_start(bp
, true);
7397 bnx2_set_ringparam(struct net_device
*dev
, struct ethtool_ringparam
*ering
)
7399 struct bnx2
*bp
= netdev_priv(dev
);
7402 if ((ering
->rx_pending
> BNX2_MAX_TOTAL_RX_DESC_CNT
) ||
7403 (ering
->tx_pending
> BNX2_MAX_TX_DESC_CNT
) ||
7404 (ering
->tx_pending
<= MAX_SKB_FRAGS
)) {
7408 rc
= bnx2_change_ring_size(bp
, ering
->rx_pending
, ering
->tx_pending
,
7414 bnx2_get_pauseparam(struct net_device
*dev
, struct ethtool_pauseparam
*epause
)
7416 struct bnx2
*bp
= netdev_priv(dev
);
7418 epause
->autoneg
= ((bp
->autoneg
& AUTONEG_FLOW_CTRL
) != 0);
7419 epause
->rx_pause
= ((bp
->flow_ctrl
& FLOW_CTRL_RX
) != 0);
7420 epause
->tx_pause
= ((bp
->flow_ctrl
& FLOW_CTRL_TX
) != 0);
7424 bnx2_set_pauseparam(struct net_device
*dev
, struct ethtool_pauseparam
*epause
)
7426 struct bnx2
*bp
= netdev_priv(dev
);
7428 bp
->req_flow_ctrl
= 0;
7429 if (epause
->rx_pause
)
7430 bp
->req_flow_ctrl
|= FLOW_CTRL_RX
;
7431 if (epause
->tx_pause
)
7432 bp
->req_flow_ctrl
|= FLOW_CTRL_TX
;
7434 if (epause
->autoneg
) {
7435 bp
->autoneg
|= AUTONEG_FLOW_CTRL
;
7438 bp
->autoneg
&= ~AUTONEG_FLOW_CTRL
;
7441 if (netif_running(dev
)) {
7442 spin_lock_bh(&bp
->phy_lock
);
7443 bnx2_setup_phy(bp
, bp
->phy_port
);
7444 spin_unlock_bh(&bp
->phy_lock
);
7451 char string
[ETH_GSTRING_LEN
];
7452 } bnx2_stats_str_arr
[] = {
7454 { "rx_error_bytes" },
7456 { "tx_error_bytes" },
7457 { "rx_ucast_packets" },
7458 { "rx_mcast_packets" },
7459 { "rx_bcast_packets" },
7460 { "tx_ucast_packets" },
7461 { "tx_mcast_packets" },
7462 { "tx_bcast_packets" },
7463 { "tx_mac_errors" },
7464 { "tx_carrier_errors" },
7465 { "rx_crc_errors" },
7466 { "rx_align_errors" },
7467 { "tx_single_collisions" },
7468 { "tx_multi_collisions" },
7470 { "tx_excess_collisions" },
7471 { "tx_late_collisions" },
7472 { "tx_total_collisions" },
7475 { "rx_undersize_packets" },
7476 { "rx_oversize_packets" },
7477 { "rx_64_byte_packets" },
7478 { "rx_65_to_127_byte_packets" },
7479 { "rx_128_to_255_byte_packets" },
7480 { "rx_256_to_511_byte_packets" },
7481 { "rx_512_to_1023_byte_packets" },
7482 { "rx_1024_to_1522_byte_packets" },
7483 { "rx_1523_to_9022_byte_packets" },
7484 { "tx_64_byte_packets" },
7485 { "tx_65_to_127_byte_packets" },
7486 { "tx_128_to_255_byte_packets" },
7487 { "tx_256_to_511_byte_packets" },
7488 { "tx_512_to_1023_byte_packets" },
7489 { "tx_1024_to_1522_byte_packets" },
7490 { "tx_1523_to_9022_byte_packets" },
7491 { "rx_xon_frames" },
7492 { "rx_xoff_frames" },
7493 { "tx_xon_frames" },
7494 { "tx_xoff_frames" },
7495 { "rx_mac_ctrl_frames" },
7496 { "rx_filtered_packets" },
7497 { "rx_ftq_discards" },
7499 { "rx_fw_discards" },
7502 #define BNX2_NUM_STATS ARRAY_SIZE(bnx2_stats_str_arr)
7504 #define STATS_OFFSET32(offset_name) (offsetof(struct statistics_block, offset_name) / 4)
7506 static const unsigned long bnx2_stats_offset_arr
[BNX2_NUM_STATS
] = {
7507 STATS_OFFSET32(stat_IfHCInOctets_hi
),
7508 STATS_OFFSET32(stat_IfHCInBadOctets_hi
),
7509 STATS_OFFSET32(stat_IfHCOutOctets_hi
),
7510 STATS_OFFSET32(stat_IfHCOutBadOctets_hi
),
7511 STATS_OFFSET32(stat_IfHCInUcastPkts_hi
),
7512 STATS_OFFSET32(stat_IfHCInMulticastPkts_hi
),
7513 STATS_OFFSET32(stat_IfHCInBroadcastPkts_hi
),
7514 STATS_OFFSET32(stat_IfHCOutUcastPkts_hi
),
7515 STATS_OFFSET32(stat_IfHCOutMulticastPkts_hi
),
7516 STATS_OFFSET32(stat_IfHCOutBroadcastPkts_hi
),
7517 STATS_OFFSET32(stat_emac_tx_stat_dot3statsinternalmactransmiterrors
),
7518 STATS_OFFSET32(stat_Dot3StatsCarrierSenseErrors
),
7519 STATS_OFFSET32(stat_Dot3StatsFCSErrors
),
7520 STATS_OFFSET32(stat_Dot3StatsAlignmentErrors
),
7521 STATS_OFFSET32(stat_Dot3StatsSingleCollisionFrames
),
7522 STATS_OFFSET32(stat_Dot3StatsMultipleCollisionFrames
),
7523 STATS_OFFSET32(stat_Dot3StatsDeferredTransmissions
),
7524 STATS_OFFSET32(stat_Dot3StatsExcessiveCollisions
),
7525 STATS_OFFSET32(stat_Dot3StatsLateCollisions
),
7526 STATS_OFFSET32(stat_EtherStatsCollisions
),
7527 STATS_OFFSET32(stat_EtherStatsFragments
),
7528 STATS_OFFSET32(stat_EtherStatsJabbers
),
7529 STATS_OFFSET32(stat_EtherStatsUndersizePkts
),
7530 STATS_OFFSET32(stat_EtherStatsOverrsizePkts
),
7531 STATS_OFFSET32(stat_EtherStatsPktsRx64Octets
),
7532 STATS_OFFSET32(stat_EtherStatsPktsRx65Octetsto127Octets
),
7533 STATS_OFFSET32(stat_EtherStatsPktsRx128Octetsto255Octets
),
7534 STATS_OFFSET32(stat_EtherStatsPktsRx256Octetsto511Octets
),
7535 STATS_OFFSET32(stat_EtherStatsPktsRx512Octetsto1023Octets
),
7536 STATS_OFFSET32(stat_EtherStatsPktsRx1024Octetsto1522Octets
),
7537 STATS_OFFSET32(stat_EtherStatsPktsRx1523Octetsto9022Octets
),
7538 STATS_OFFSET32(stat_EtherStatsPktsTx64Octets
),
7539 STATS_OFFSET32(stat_EtherStatsPktsTx65Octetsto127Octets
),
7540 STATS_OFFSET32(stat_EtherStatsPktsTx128Octetsto255Octets
),
7541 STATS_OFFSET32(stat_EtherStatsPktsTx256Octetsto511Octets
),
7542 STATS_OFFSET32(stat_EtherStatsPktsTx512Octetsto1023Octets
),
7543 STATS_OFFSET32(stat_EtherStatsPktsTx1024Octetsto1522Octets
),
7544 STATS_OFFSET32(stat_EtherStatsPktsTx1523Octetsto9022Octets
),
7545 STATS_OFFSET32(stat_XonPauseFramesReceived
),
7546 STATS_OFFSET32(stat_XoffPauseFramesReceived
),
7547 STATS_OFFSET32(stat_OutXonSent
),
7548 STATS_OFFSET32(stat_OutXoffSent
),
7549 STATS_OFFSET32(stat_MacControlFramesReceived
),
7550 STATS_OFFSET32(stat_IfInFramesL2FilterDiscards
),
7551 STATS_OFFSET32(stat_IfInFTQDiscards
),
7552 STATS_OFFSET32(stat_IfInMBUFDiscards
),
7553 STATS_OFFSET32(stat_FwRxDrop
),
7556 /* stat_IfHCInBadOctets and stat_Dot3StatsCarrierSenseErrors are
7557 * skipped because of errata.
7559 static u8 bnx2_5706_stats_len_arr
[BNX2_NUM_STATS
] = {
7560 8,0,8,8,8,8,8,8,8,8,
7561 4,0,4,4,4,4,4,4,4,4,
7562 4,4,4,4,4,4,4,4,4,4,
7563 4,4,4,4,4,4,4,4,4,4,
7567 static u8 bnx2_5708_stats_len_arr
[BNX2_NUM_STATS
] = {
7568 8,0,8,8,8,8,8,8,8,8,
7569 4,4,4,4,4,4,4,4,4,4,
7570 4,4,4,4,4,4,4,4,4,4,
7571 4,4,4,4,4,4,4,4,4,4,
7575 #define BNX2_NUM_TESTS 6
7578 char string
[ETH_GSTRING_LEN
];
7579 } bnx2_tests_str_arr
[BNX2_NUM_TESTS
] = {
7580 { "register_test (offline)" },
7581 { "memory_test (offline)" },
7582 { "loopback_test (offline)" },
7583 { "nvram_test (online)" },
7584 { "interrupt_test (online)" },
7585 { "link_test (online)" },
7589 bnx2_get_sset_count(struct net_device
*dev
, int sset
)
7593 return BNX2_NUM_TESTS
;
7595 return BNX2_NUM_STATS
;
7602 bnx2_self_test(struct net_device
*dev
, struct ethtool_test
*etest
, u64
*buf
)
7604 struct bnx2
*bp
= netdev_priv(dev
);
7606 memset(buf
, 0, sizeof(u64
) * BNX2_NUM_TESTS
);
7607 if (etest
->flags
& ETH_TEST_FL_OFFLINE
) {
7610 bnx2_netif_stop(bp
, true);
7611 bnx2_reset_chip(bp
, BNX2_DRV_MSG_CODE_DIAG
);
7614 if (bnx2_test_registers(bp
) != 0) {
7616 etest
->flags
|= ETH_TEST_FL_FAILED
;
7618 if (bnx2_test_memory(bp
) != 0) {
7620 etest
->flags
|= ETH_TEST_FL_FAILED
;
7622 if ((buf
[2] = bnx2_test_loopback(bp
)) != 0)
7623 etest
->flags
|= ETH_TEST_FL_FAILED
;
7625 if (!netif_running(bp
->dev
))
7626 bnx2_shutdown_chip(bp
);
7628 bnx2_init_nic(bp
, 1);
7629 bnx2_netif_start(bp
, true);
7632 /* wait for link up */
7633 for (i
= 0; i
< 7; i
++) {
7636 msleep_interruptible(1000);
7640 if (bnx2_test_nvram(bp
) != 0) {
7642 etest
->flags
|= ETH_TEST_FL_FAILED
;
7644 if (bnx2_test_intr(bp
) != 0) {
7646 etest
->flags
|= ETH_TEST_FL_FAILED
;
7649 if (bnx2_test_link(bp
) != 0) {
7651 etest
->flags
|= ETH_TEST_FL_FAILED
;
7657 bnx2_get_strings(struct net_device
*dev
, u32 stringset
, u8
*buf
)
7659 switch (stringset
) {
7661 memcpy(buf
, bnx2_stats_str_arr
,
7662 sizeof(bnx2_stats_str_arr
));
7665 memcpy(buf
, bnx2_tests_str_arr
,
7666 sizeof(bnx2_tests_str_arr
));
7672 bnx2_get_ethtool_stats(struct net_device
*dev
,
7673 struct ethtool_stats
*stats
, u64
*buf
)
7675 struct bnx2
*bp
= netdev_priv(dev
);
7677 u32
*hw_stats
= (u32
*) bp
->stats_blk
;
7678 u32
*temp_stats
= (u32
*) bp
->temp_stats_blk
;
7679 u8
*stats_len_arr
= NULL
;
7681 if (hw_stats
== NULL
) {
7682 memset(buf
, 0, sizeof(u64
) * BNX2_NUM_STATS
);
7686 if ((BNX2_CHIP_ID(bp
) == BNX2_CHIP_ID_5706_A0
) ||
7687 (BNX2_CHIP_ID(bp
) == BNX2_CHIP_ID_5706_A1
) ||
7688 (BNX2_CHIP_ID(bp
) == BNX2_CHIP_ID_5706_A2
) ||
7689 (BNX2_CHIP_ID(bp
) == BNX2_CHIP_ID_5708_A0
))
7690 stats_len_arr
= bnx2_5706_stats_len_arr
;
7692 stats_len_arr
= bnx2_5708_stats_len_arr
;
7694 for (i
= 0; i
< BNX2_NUM_STATS
; i
++) {
7695 unsigned long offset
;
7697 if (stats_len_arr
[i
] == 0) {
7698 /* skip this counter */
7703 offset
= bnx2_stats_offset_arr
[i
];
7704 if (stats_len_arr
[i
] == 4) {
7705 /* 4-byte counter */
7706 buf
[i
] = (u64
) *(hw_stats
+ offset
) +
7707 *(temp_stats
+ offset
);
7710 /* 8-byte counter */
7711 buf
[i
] = (((u64
) *(hw_stats
+ offset
)) << 32) +
7712 *(hw_stats
+ offset
+ 1) +
7713 (((u64
) *(temp_stats
+ offset
)) << 32) +
7714 *(temp_stats
+ offset
+ 1);
7719 bnx2_set_phys_id(struct net_device
*dev
, enum ethtool_phys_id_state state
)
7721 struct bnx2
*bp
= netdev_priv(dev
);
7724 case ETHTOOL_ID_ACTIVE
:
7725 bp
->leds_save
= BNX2_RD(bp
, BNX2_MISC_CFG
);
7726 BNX2_WR(bp
, BNX2_MISC_CFG
, BNX2_MISC_CFG_LEDMODE_MAC
);
7727 return 1; /* cycle on/off once per second */
7730 BNX2_WR(bp
, BNX2_EMAC_LED
, BNX2_EMAC_LED_OVERRIDE
|
7731 BNX2_EMAC_LED_1000MB_OVERRIDE
|
7732 BNX2_EMAC_LED_100MB_OVERRIDE
|
7733 BNX2_EMAC_LED_10MB_OVERRIDE
|
7734 BNX2_EMAC_LED_TRAFFIC_OVERRIDE
|
7735 BNX2_EMAC_LED_TRAFFIC
);
7738 case ETHTOOL_ID_OFF
:
7739 BNX2_WR(bp
, BNX2_EMAC_LED
, BNX2_EMAC_LED_OVERRIDE
);
7742 case ETHTOOL_ID_INACTIVE
:
7743 BNX2_WR(bp
, BNX2_EMAC_LED
, 0);
7744 BNX2_WR(bp
, BNX2_MISC_CFG
, bp
->leds_save
);
7752 bnx2_set_features(struct net_device
*dev
, netdev_features_t features
)
7754 struct bnx2
*bp
= netdev_priv(dev
);
7756 /* TSO with VLAN tag won't work with current firmware */
7757 if (features
& NETIF_F_HW_VLAN_CTAG_TX
)
7758 dev
->vlan_features
|= (dev
->hw_features
& NETIF_F_ALL_TSO
);
7760 dev
->vlan_features
&= ~NETIF_F_ALL_TSO
;
7762 if ((!!(features
& NETIF_F_HW_VLAN_CTAG_RX
) !=
7763 !!(bp
->rx_mode
& BNX2_EMAC_RX_MODE_KEEP_VLAN_TAG
)) &&
7764 netif_running(dev
)) {
7765 bnx2_netif_stop(bp
, false);
7766 dev
->features
= features
;
7767 bnx2_set_rx_mode(dev
);
7768 bnx2_fw_sync(bp
, BNX2_DRV_MSG_CODE_KEEP_VLAN_UPDATE
, 0, 1);
7769 bnx2_netif_start(bp
, false);
7776 static void bnx2_get_channels(struct net_device
*dev
,
7777 struct ethtool_channels
*channels
)
7779 struct bnx2
*bp
= netdev_priv(dev
);
7780 u32 max_rx_rings
= 1;
7781 u32 max_tx_rings
= 1;
7783 if ((bp
->flags
& BNX2_FLAG_MSIX_CAP
) && !disable_msi
) {
7784 max_rx_rings
= RX_MAX_RINGS
;
7785 max_tx_rings
= TX_MAX_RINGS
;
7788 channels
->max_rx
= max_rx_rings
;
7789 channels
->max_tx
= max_tx_rings
;
7790 channels
->max_other
= 0;
7791 channels
->max_combined
= 0;
7792 channels
->rx_count
= bp
->num_rx_rings
;
7793 channels
->tx_count
= bp
->num_tx_rings
;
7794 channels
->other_count
= 0;
7795 channels
->combined_count
= 0;
7798 static int bnx2_set_channels(struct net_device
*dev
,
7799 struct ethtool_channels
*channels
)
7801 struct bnx2
*bp
= netdev_priv(dev
);
7802 u32 max_rx_rings
= 1;
7803 u32 max_tx_rings
= 1;
7806 if ((bp
->flags
& BNX2_FLAG_MSIX_CAP
) && !disable_msi
) {
7807 max_rx_rings
= RX_MAX_RINGS
;
7808 max_tx_rings
= TX_MAX_RINGS
;
7810 if (channels
->rx_count
> max_rx_rings
||
7811 channels
->tx_count
> max_tx_rings
)
7814 bp
->num_req_rx_rings
= channels
->rx_count
;
7815 bp
->num_req_tx_rings
= channels
->tx_count
;
7817 if (netif_running(dev
))
7818 rc
= bnx2_change_ring_size(bp
, bp
->rx_ring_size
,
7819 bp
->tx_ring_size
, true);
7824 static const struct ethtool_ops bnx2_ethtool_ops
= {
7825 .get_settings
= bnx2_get_settings
,
7826 .set_settings
= bnx2_set_settings
,
7827 .get_drvinfo
= bnx2_get_drvinfo
,
7828 .get_regs_len
= bnx2_get_regs_len
,
7829 .get_regs
= bnx2_get_regs
,
7830 .get_wol
= bnx2_get_wol
,
7831 .set_wol
= bnx2_set_wol
,
7832 .nway_reset
= bnx2_nway_reset
,
7833 .get_link
= bnx2_get_link
,
7834 .get_eeprom_len
= bnx2_get_eeprom_len
,
7835 .get_eeprom
= bnx2_get_eeprom
,
7836 .set_eeprom
= bnx2_set_eeprom
,
7837 .get_coalesce
= bnx2_get_coalesce
,
7838 .set_coalesce
= bnx2_set_coalesce
,
7839 .get_ringparam
= bnx2_get_ringparam
,
7840 .set_ringparam
= bnx2_set_ringparam
,
7841 .get_pauseparam
= bnx2_get_pauseparam
,
7842 .set_pauseparam
= bnx2_set_pauseparam
,
7843 .self_test
= bnx2_self_test
,
7844 .get_strings
= bnx2_get_strings
,
7845 .set_phys_id
= bnx2_set_phys_id
,
7846 .get_ethtool_stats
= bnx2_get_ethtool_stats
,
7847 .get_sset_count
= bnx2_get_sset_count
,
7848 .get_channels
= bnx2_get_channels
,
7849 .set_channels
= bnx2_set_channels
,
7852 /* Called with rtnl_lock */
7854 bnx2_ioctl(struct net_device
*dev
, struct ifreq
*ifr
, int cmd
)
7856 struct mii_ioctl_data
*data
= if_mii(ifr
);
7857 struct bnx2
*bp
= netdev_priv(dev
);
7862 data
->phy_id
= bp
->phy_addr
;
7868 if (bp
->phy_flags
& BNX2_PHY_FLAG_REMOTE_PHY_CAP
)
7871 if (!netif_running(dev
))
7874 spin_lock_bh(&bp
->phy_lock
);
7875 err
= bnx2_read_phy(bp
, data
->reg_num
& 0x1f, &mii_regval
);
7876 spin_unlock_bh(&bp
->phy_lock
);
7878 data
->val_out
= mii_regval
;
7884 if (bp
->phy_flags
& BNX2_PHY_FLAG_REMOTE_PHY_CAP
)
7887 if (!netif_running(dev
))
7890 spin_lock_bh(&bp
->phy_lock
);
7891 err
= bnx2_write_phy(bp
, data
->reg_num
& 0x1f, data
->val_in
);
7892 spin_unlock_bh(&bp
->phy_lock
);
7903 /* Called with rtnl_lock */
7905 bnx2_change_mac_addr(struct net_device
*dev
, void *p
)
7907 struct sockaddr
*addr
= p
;
7908 struct bnx2
*bp
= netdev_priv(dev
);
7910 if (!is_valid_ether_addr(addr
->sa_data
))
7911 return -EADDRNOTAVAIL
;
7913 memcpy(dev
->dev_addr
, addr
->sa_data
, dev
->addr_len
);
7914 if (netif_running(dev
))
7915 bnx2_set_mac_addr(bp
, bp
->dev
->dev_addr
, 0);
7920 /* Called with rtnl_lock */
7922 bnx2_change_mtu(struct net_device
*dev
, int new_mtu
)
7924 struct bnx2
*bp
= netdev_priv(dev
);
7926 if (((new_mtu
+ ETH_HLEN
) > MAX_ETHERNET_JUMBO_PACKET_SIZE
) ||
7927 ((new_mtu
+ ETH_HLEN
) < MIN_ETHERNET_PACKET_SIZE
))
7931 return bnx2_change_ring_size(bp
, bp
->rx_ring_size
, bp
->tx_ring_size
,
7935 #ifdef CONFIG_NET_POLL_CONTROLLER
7937 poll_bnx2(struct net_device
*dev
)
7939 struct bnx2
*bp
= netdev_priv(dev
);
7942 for (i
= 0; i
< bp
->irq_nvecs
; i
++) {
7943 struct bnx2_irq
*irq
= &bp
->irq_tbl
[i
];
7945 disable_irq(irq
->vector
);
7946 irq
->handler(irq
->vector
, &bp
->bnx2_napi
[i
]);
7947 enable_irq(irq
->vector
);
7953 bnx2_get_5709_media(struct bnx2
*bp
)
7955 u32 val
= BNX2_RD(bp
, BNX2_MISC_DUAL_MEDIA_CTRL
);
7956 u32 bond_id
= val
& BNX2_MISC_DUAL_MEDIA_CTRL_BOND_ID
;
7959 if (bond_id
== BNX2_MISC_DUAL_MEDIA_CTRL_BOND_ID_C
)
7961 else if (bond_id
== BNX2_MISC_DUAL_MEDIA_CTRL_BOND_ID_S
) {
7962 bp
->phy_flags
|= BNX2_PHY_FLAG_SERDES
;
7966 if (val
& BNX2_MISC_DUAL_MEDIA_CTRL_STRAP_OVERRIDE
)
7967 strap
= (val
& BNX2_MISC_DUAL_MEDIA_CTRL_PHY_CTRL
) >> 21;
7969 strap
= (val
& BNX2_MISC_DUAL_MEDIA_CTRL_PHY_CTRL_STRAP
) >> 8;
7971 if (bp
->func
== 0) {
7976 bp
->phy_flags
|= BNX2_PHY_FLAG_SERDES
;
7984 bp
->phy_flags
|= BNX2_PHY_FLAG_SERDES
;
7991 bnx2_get_pci_speed(struct bnx2
*bp
)
7995 reg
= BNX2_RD(bp
, BNX2_PCICFG_MISC_STATUS
);
7996 if (reg
& BNX2_PCICFG_MISC_STATUS_PCIX_DET
) {
7999 bp
->flags
|= BNX2_FLAG_PCIX
;
8001 clkreg
= BNX2_RD(bp
, BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS
);
8003 clkreg
&= BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET
;
8005 case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_133MHZ
:
8006 bp
->bus_speed_mhz
= 133;
8009 case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_95MHZ
:
8010 bp
->bus_speed_mhz
= 100;
8013 case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_66MHZ
:
8014 case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_80MHZ
:
8015 bp
->bus_speed_mhz
= 66;
8018 case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_48MHZ
:
8019 case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_55MHZ
:
8020 bp
->bus_speed_mhz
= 50;
8023 case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_LOW
:
8024 case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_32MHZ
:
8025 case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_38MHZ
:
8026 bp
->bus_speed_mhz
= 33;
8031 if (reg
& BNX2_PCICFG_MISC_STATUS_M66EN
)
8032 bp
->bus_speed_mhz
= 66;
8034 bp
->bus_speed_mhz
= 33;
8037 if (reg
& BNX2_PCICFG_MISC_STATUS_32BIT_DET
)
8038 bp
->flags
|= BNX2_FLAG_PCI_32BIT
;
8043 bnx2_read_vpd_fw_ver(struct bnx2
*bp
)
8047 unsigned int block_end
, rosize
, len
;
8049 #define BNX2_VPD_NVRAM_OFFSET 0x300
8050 #define BNX2_VPD_LEN 128
8051 #define BNX2_MAX_VER_SLEN 30
8053 data
= kmalloc(256, GFP_KERNEL
);
8057 rc
= bnx2_nvram_read(bp
, BNX2_VPD_NVRAM_OFFSET
, data
+ BNX2_VPD_LEN
,
8062 for (i
= 0; i
< BNX2_VPD_LEN
; i
+= 4) {
8063 data
[i
] = data
[i
+ BNX2_VPD_LEN
+ 3];
8064 data
[i
+ 1] = data
[i
+ BNX2_VPD_LEN
+ 2];
8065 data
[i
+ 2] = data
[i
+ BNX2_VPD_LEN
+ 1];
8066 data
[i
+ 3] = data
[i
+ BNX2_VPD_LEN
];
8069 i
= pci_vpd_find_tag(data
, 0, BNX2_VPD_LEN
, PCI_VPD_LRDT_RO_DATA
);
8073 rosize
= pci_vpd_lrdt_size(&data
[i
]);
8074 i
+= PCI_VPD_LRDT_TAG_SIZE
;
8075 block_end
= i
+ rosize
;
8077 if (block_end
> BNX2_VPD_LEN
)
8080 j
= pci_vpd_find_info_keyword(data
, i
, rosize
,
8081 PCI_VPD_RO_KEYWORD_MFR_ID
);
8085 len
= pci_vpd_info_field_size(&data
[j
]);
8087 j
+= PCI_VPD_INFO_FLD_HDR_SIZE
;
8088 if (j
+ len
> block_end
|| len
!= 4 ||
8089 memcmp(&data
[j
], "1028", 4))
8092 j
= pci_vpd_find_info_keyword(data
, i
, rosize
,
8093 PCI_VPD_RO_KEYWORD_VENDOR0
);
8097 len
= pci_vpd_info_field_size(&data
[j
]);
8099 j
+= PCI_VPD_INFO_FLD_HDR_SIZE
;
8100 if (j
+ len
> block_end
|| len
> BNX2_MAX_VER_SLEN
)
8103 memcpy(bp
->fw_version
, &data
[j
], len
);
8104 bp
->fw_version
[len
] = ' ';
8111 bnx2_init_board(struct pci_dev
*pdev
, struct net_device
*dev
)
8116 u64 dma_mask
, persist_dma_mask
;
8119 SET_NETDEV_DEV(dev
, &pdev
->dev
);
8120 bp
= netdev_priv(dev
);
8125 bp
->temp_stats_blk
=
8126 kzalloc(sizeof(struct statistics_block
), GFP_KERNEL
);
8128 if (bp
->temp_stats_blk
== NULL
) {
8133 /* enable device (incl. PCI PM wakeup), and bus-mastering */
8134 rc
= pci_enable_device(pdev
);
8136 dev_err(&pdev
->dev
, "Cannot enable PCI device, aborting\n");
8140 if (!(pci_resource_flags(pdev
, 0) & IORESOURCE_MEM
)) {
8142 "Cannot find PCI device base address, aborting\n");
8144 goto err_out_disable
;
8147 rc
= pci_request_regions(pdev
, DRV_MODULE_NAME
);
8149 dev_err(&pdev
->dev
, "Cannot obtain PCI resources, aborting\n");
8150 goto err_out_disable
;
8153 pci_set_master(pdev
);
8155 bp
->pm_cap
= pdev
->pm_cap
;
8156 if (bp
->pm_cap
== 0) {
8158 "Cannot find power management capability, aborting\n");
8160 goto err_out_release
;
8166 spin_lock_init(&bp
->phy_lock
);
8167 spin_lock_init(&bp
->indirect_lock
);
8169 mutex_init(&bp
->cnic_lock
);
8171 INIT_WORK(&bp
->reset_task
, bnx2_reset_task
);
8173 bp
->regview
= pci_iomap(pdev
, 0, MB_GET_CID_ADDR(TX_TSS_CID
+
8174 TX_MAX_TSS_RINGS
+ 1));
8176 dev_err(&pdev
->dev
, "Cannot map register space, aborting\n");
8178 goto err_out_release
;
8181 /* Configure byte swap and enable write to the reg_window registers.
8182 * Rely on CPU to do target byte swapping on big endian systems
8183 * The chip's target access swapping will not swap all accesses
8185 BNX2_WR(bp
, BNX2_PCICFG_MISC_CONFIG
,
8186 BNX2_PCICFG_MISC_CONFIG_REG_WINDOW_ENA
|
8187 BNX2_PCICFG_MISC_CONFIG_TARGET_MB_WORD_SWAP
);
8189 bp
->chip_id
= BNX2_RD(bp
, BNX2_MISC_ID
);
8191 if (BNX2_CHIP(bp
) == BNX2_CHIP_5709
) {
8192 if (!pci_is_pcie(pdev
)) {
8193 dev_err(&pdev
->dev
, "Not PCIE, aborting\n");
8197 bp
->flags
|= BNX2_FLAG_PCIE
;
8198 if (BNX2_CHIP_REV(bp
) == BNX2_CHIP_REV_Ax
)
8199 bp
->flags
|= BNX2_FLAG_JUMBO_BROKEN
;
8201 /* AER (Advanced Error Reporting) hooks */
8202 err
= pci_enable_pcie_error_reporting(pdev
);
8204 bp
->flags
|= BNX2_FLAG_AER_ENABLED
;
8207 bp
->pcix_cap
= pci_find_capability(pdev
, PCI_CAP_ID_PCIX
);
8208 if (bp
->pcix_cap
== 0) {
8210 "Cannot find PCIX capability, aborting\n");
8214 bp
->flags
|= BNX2_FLAG_BROKEN_STATS
;
8217 if (BNX2_CHIP(bp
) == BNX2_CHIP_5709
&&
8218 BNX2_CHIP_REV(bp
) != BNX2_CHIP_REV_Ax
) {
8220 bp
->flags
|= BNX2_FLAG_MSIX_CAP
;
8223 if (BNX2_CHIP_ID(bp
) != BNX2_CHIP_ID_5706_A0
&&
8224 BNX2_CHIP_ID(bp
) != BNX2_CHIP_ID_5706_A1
) {
8226 bp
->flags
|= BNX2_FLAG_MSI_CAP
;
8229 /* 5708 cannot support DMA addresses > 40-bit. */
8230 if (BNX2_CHIP(bp
) == BNX2_CHIP_5708
)
8231 persist_dma_mask
= dma_mask
= DMA_BIT_MASK(40);
8233 persist_dma_mask
= dma_mask
= DMA_BIT_MASK(64);
8235 /* Configure DMA attributes. */
8236 if (pci_set_dma_mask(pdev
, dma_mask
) == 0) {
8237 dev
->features
|= NETIF_F_HIGHDMA
;
8238 rc
= pci_set_consistent_dma_mask(pdev
, persist_dma_mask
);
8241 "pci_set_consistent_dma_mask failed, aborting\n");
8244 } else if ((rc
= pci_set_dma_mask(pdev
, DMA_BIT_MASK(32))) != 0) {
8245 dev_err(&pdev
->dev
, "System does not support DMA, aborting\n");
8249 if (!(bp
->flags
& BNX2_FLAG_PCIE
))
8250 bnx2_get_pci_speed(bp
);
8252 /* 5706A0 may falsely detect SERR and PERR. */
8253 if (BNX2_CHIP_ID(bp
) == BNX2_CHIP_ID_5706_A0
) {
8254 reg
= BNX2_RD(bp
, PCI_COMMAND
);
8255 reg
&= ~(PCI_COMMAND_SERR
| PCI_COMMAND_PARITY
);
8256 BNX2_WR(bp
, PCI_COMMAND
, reg
);
8257 } else if ((BNX2_CHIP_ID(bp
) == BNX2_CHIP_ID_5706_A1
) &&
8258 !(bp
->flags
& BNX2_FLAG_PCIX
)) {
8261 "5706 A1 can only be used in a PCIX bus, aborting\n");
8265 bnx2_init_nvram(bp
);
8267 reg
= bnx2_reg_rd_ind(bp
, BNX2_SHM_HDR_SIGNATURE
);
8269 if (bnx2_reg_rd_ind(bp
, BNX2_MCP_TOE_ID
) & BNX2_MCP_TOE_ID_FUNCTION_ID
)
8272 if ((reg
& BNX2_SHM_HDR_SIGNATURE_SIG_MASK
) ==
8273 BNX2_SHM_HDR_SIGNATURE_SIG
) {
8274 u32 off
= bp
->func
<< 2;
8276 bp
->shmem_base
= bnx2_reg_rd_ind(bp
, BNX2_SHM_HDR_ADDR_0
+ off
);
8278 bp
->shmem_base
= HOST_VIEW_SHMEM_BASE
;
8280 /* Get the permanent MAC address. First we need to make sure the
8281 * firmware is actually running.
8283 reg
= bnx2_shmem_rd(bp
, BNX2_DEV_INFO_SIGNATURE
);
8285 if ((reg
& BNX2_DEV_INFO_SIGNATURE_MAGIC_MASK
) !=
8286 BNX2_DEV_INFO_SIGNATURE_MAGIC
) {
8287 dev_err(&pdev
->dev
, "Firmware not running, aborting\n");
8292 bnx2_read_vpd_fw_ver(bp
);
8294 j
= strlen(bp
->fw_version
);
8295 reg
= bnx2_shmem_rd(bp
, BNX2_DEV_INFO_BC_REV
);
8296 for (i
= 0; i
< 3 && j
< 24; i
++) {
8300 bp
->fw_version
[j
++] = 'b';
8301 bp
->fw_version
[j
++] = 'c';
8302 bp
->fw_version
[j
++] = ' ';
8304 num
= (u8
) (reg
>> (24 - (i
* 8)));
8305 for (k
= 100, skip0
= 1; k
>= 1; num
%= k
, k
/= 10) {
8306 if (num
>= k
|| !skip0
|| k
== 1) {
8307 bp
->fw_version
[j
++] = (num
/ k
) + '0';
8312 bp
->fw_version
[j
++] = '.';
8314 reg
= bnx2_shmem_rd(bp
, BNX2_PORT_FEATURE
);
8315 if (reg
& BNX2_PORT_FEATURE_WOL_ENABLED
)
8318 if (reg
& BNX2_PORT_FEATURE_ASF_ENABLED
) {
8319 bp
->flags
|= BNX2_FLAG_ASF_ENABLE
;
8321 for (i
= 0; i
< 30; i
++) {
8322 reg
= bnx2_shmem_rd(bp
, BNX2_BC_STATE_CONDITION
);
8323 if (reg
& BNX2_CONDITION_MFW_RUN_MASK
)
8328 reg
= bnx2_shmem_rd(bp
, BNX2_BC_STATE_CONDITION
);
8329 reg
&= BNX2_CONDITION_MFW_RUN_MASK
;
8330 if (reg
!= BNX2_CONDITION_MFW_RUN_UNKNOWN
&&
8331 reg
!= BNX2_CONDITION_MFW_RUN_NONE
) {
8332 u32 addr
= bnx2_shmem_rd(bp
, BNX2_MFW_VER_PTR
);
8335 bp
->fw_version
[j
++] = ' ';
8336 for (i
= 0; i
< 3 && j
< 28; i
++) {
8337 reg
= bnx2_reg_rd_ind(bp
, addr
+ i
* 4);
8338 reg
= be32_to_cpu(reg
);
8339 memcpy(&bp
->fw_version
[j
], ®
, 4);
8344 reg
= bnx2_shmem_rd(bp
, BNX2_PORT_HW_CFG_MAC_UPPER
);
8345 bp
->mac_addr
[0] = (u8
) (reg
>> 8);
8346 bp
->mac_addr
[1] = (u8
) reg
;
8348 reg
= bnx2_shmem_rd(bp
, BNX2_PORT_HW_CFG_MAC_LOWER
);
8349 bp
->mac_addr
[2] = (u8
) (reg
>> 24);
8350 bp
->mac_addr
[3] = (u8
) (reg
>> 16);
8351 bp
->mac_addr
[4] = (u8
) (reg
>> 8);
8352 bp
->mac_addr
[5] = (u8
) reg
;
8354 bp
->tx_ring_size
= BNX2_MAX_TX_DESC_CNT
;
8355 bnx2_set_rx_ring_size(bp
, 255);
8357 bp
->tx_quick_cons_trip_int
= 2;
8358 bp
->tx_quick_cons_trip
= 20;
8359 bp
->tx_ticks_int
= 18;
8362 bp
->rx_quick_cons_trip_int
= 2;
8363 bp
->rx_quick_cons_trip
= 12;
8364 bp
->rx_ticks_int
= 18;
8367 bp
->stats_ticks
= USEC_PER_SEC
& BNX2_HC_STATS_TICKS_HC_STAT_TICKS
;
8369 bp
->current_interval
= BNX2_TIMER_INTERVAL
;
8373 /* allocate stats_blk */
8374 rc
= bnx2_alloc_stats_blk(dev
);
8378 /* Disable WOL support if we are running on a SERDES chip. */
8379 if (BNX2_CHIP(bp
) == BNX2_CHIP_5709
)
8380 bnx2_get_5709_media(bp
);
8381 else if (BNX2_CHIP_BOND(bp
) & BNX2_CHIP_BOND_SERDES_BIT
)
8382 bp
->phy_flags
|= BNX2_PHY_FLAG_SERDES
;
8384 bp
->phy_port
= PORT_TP
;
8385 if (bp
->phy_flags
& BNX2_PHY_FLAG_SERDES
) {
8386 bp
->phy_port
= PORT_FIBRE
;
8387 reg
= bnx2_shmem_rd(bp
, BNX2_SHARED_HW_CFG_CONFIG
);
8388 if (!(reg
& BNX2_SHARED_HW_CFG_GIG_LINK_ON_VAUX
)) {
8389 bp
->flags
|= BNX2_FLAG_NO_WOL
;
8392 if (BNX2_CHIP(bp
) == BNX2_CHIP_5706
) {
8393 /* Don't do parallel detect on this board because of
8394 * some board problems. The link will not go down
8395 * if we do parallel detect.
8397 if (pdev
->subsystem_vendor
== PCI_VENDOR_ID_HP
&&
8398 pdev
->subsystem_device
== 0x310c)
8399 bp
->phy_flags
|= BNX2_PHY_FLAG_NO_PARALLEL
;
8402 if (reg
& BNX2_SHARED_HW_CFG_PHY_2_5G
)
8403 bp
->phy_flags
|= BNX2_PHY_FLAG_2_5G_CAPABLE
;
8405 } else if (BNX2_CHIP(bp
) == BNX2_CHIP_5706
||
8406 BNX2_CHIP(bp
) == BNX2_CHIP_5708
)
8407 bp
->phy_flags
|= BNX2_PHY_FLAG_CRC_FIX
;
8408 else if (BNX2_CHIP(bp
) == BNX2_CHIP_5709
&&
8409 (BNX2_CHIP_REV(bp
) == BNX2_CHIP_REV_Ax
||
8410 BNX2_CHIP_REV(bp
) == BNX2_CHIP_REV_Bx
))
8411 bp
->phy_flags
|= BNX2_PHY_FLAG_DIS_EARLY_DAC
;
8413 bnx2_init_fw_cap(bp
);
8415 if ((BNX2_CHIP_ID(bp
) == BNX2_CHIP_ID_5708_A0
) ||
8416 (BNX2_CHIP_ID(bp
) == BNX2_CHIP_ID_5708_B0
) ||
8417 (BNX2_CHIP_ID(bp
) == BNX2_CHIP_ID_5708_B1
) ||
8418 !(BNX2_RD(bp
, BNX2_PCI_CONFIG_3
) & BNX2_PCI_CONFIG_3_VAUX_PRESET
)) {
8419 bp
->flags
|= BNX2_FLAG_NO_WOL
;
8423 if (bp
->flags
& BNX2_FLAG_NO_WOL
)
8424 device_set_wakeup_capable(&bp
->pdev
->dev
, false);
8426 device_set_wakeup_enable(&bp
->pdev
->dev
, bp
->wol
);
8428 if (BNX2_CHIP_ID(bp
) == BNX2_CHIP_ID_5706_A0
) {
8429 bp
->tx_quick_cons_trip_int
=
8430 bp
->tx_quick_cons_trip
;
8431 bp
->tx_ticks_int
= bp
->tx_ticks
;
8432 bp
->rx_quick_cons_trip_int
=
8433 bp
->rx_quick_cons_trip
;
8434 bp
->rx_ticks_int
= bp
->rx_ticks
;
8435 bp
->comp_prod_trip_int
= bp
->comp_prod_trip
;
8436 bp
->com_ticks_int
= bp
->com_ticks
;
8437 bp
->cmd_ticks_int
= bp
->cmd_ticks
;
8440 /* Disable MSI on 5706 if AMD 8132 bridge is found.
8442 * MSI is defined to be 32-bit write. The 5706 does 64-bit MSI writes
8443 * with byte enables disabled on the unused 32-bit word. This is legal
8444 * but causes problems on the AMD 8132 which will eventually stop
8445 * responding after a while.
8447 * AMD believes this incompatibility is unique to the 5706, and
8448 * prefers to locally disable MSI rather than globally disabling it.
8450 if (BNX2_CHIP(bp
) == BNX2_CHIP_5706
&& disable_msi
== 0) {
8451 struct pci_dev
*amd_8132
= NULL
;
8453 while ((amd_8132
= pci_get_device(PCI_VENDOR_ID_AMD
,
8454 PCI_DEVICE_ID_AMD_8132_BRIDGE
,
8457 if (amd_8132
->revision
>= 0x10 &&
8458 amd_8132
->revision
<= 0x13) {
8460 pci_dev_put(amd_8132
);
8466 bnx2_set_default_link(bp
);
8467 bp
->req_flow_ctrl
= FLOW_CTRL_RX
| FLOW_CTRL_TX
;
8469 init_timer(&bp
->timer
);
8470 bp
->timer
.expires
= RUN_AT(BNX2_TIMER_INTERVAL
);
8471 bp
->timer
.data
= (unsigned long) bp
;
8472 bp
->timer
.function
= bnx2_timer
;
8475 if (bnx2_shmem_rd(bp
, BNX2_ISCSI_INITIATOR
) & BNX2_ISCSI_INITIATOR_EN
)
8476 bp
->cnic_eth_dev
.max_iscsi_conn
=
8477 (bnx2_shmem_rd(bp
, BNX2_ISCSI_MAX_CONN
) &
8478 BNX2_ISCSI_MAX_CONN_MASK
) >> BNX2_ISCSI_MAX_CONN_SHIFT
;
8479 bp
->cnic_probe
= bnx2_cnic_probe
;
8481 pci_save_state(pdev
);
8486 if (bp
->flags
& BNX2_FLAG_AER_ENABLED
) {
8487 pci_disable_pcie_error_reporting(pdev
);
8488 bp
->flags
&= ~BNX2_FLAG_AER_ENABLED
;
8491 pci_iounmap(pdev
, bp
->regview
);
8495 pci_release_regions(pdev
);
8498 pci_disable_device(pdev
);
8501 kfree(bp
->temp_stats_blk
);
8507 bnx2_bus_string(struct bnx2
*bp
, char *str
)
8511 if (bp
->flags
& BNX2_FLAG_PCIE
) {
8512 s
+= sprintf(s
, "PCI Express");
8514 s
+= sprintf(s
, "PCI");
8515 if (bp
->flags
& BNX2_FLAG_PCIX
)
8516 s
+= sprintf(s
, "-X");
8517 if (bp
->flags
& BNX2_FLAG_PCI_32BIT
)
8518 s
+= sprintf(s
, " 32-bit");
8520 s
+= sprintf(s
, " 64-bit");
8521 s
+= sprintf(s
, " %dMHz", bp
->bus_speed_mhz
);
8527 bnx2_del_napi(struct bnx2
*bp
)
8531 for (i
= 0; i
< bp
->irq_nvecs
; i
++)
8532 netif_napi_del(&bp
->bnx2_napi
[i
].napi
);
8536 bnx2_init_napi(struct bnx2
*bp
)
8540 for (i
= 0; i
< bp
->irq_nvecs
; i
++) {
8541 struct bnx2_napi
*bnapi
= &bp
->bnx2_napi
[i
];
8542 int (*poll
)(struct napi_struct
*, int);
8547 poll
= bnx2_poll_msix
;
8549 netif_napi_add(bp
->dev
, &bp
->bnx2_napi
[i
].napi
, poll
, 64);
8554 static const struct net_device_ops bnx2_netdev_ops
= {
8555 .ndo_open
= bnx2_open
,
8556 .ndo_start_xmit
= bnx2_start_xmit
,
8557 .ndo_stop
= bnx2_close
,
8558 .ndo_get_stats64
= bnx2_get_stats64
,
8559 .ndo_set_rx_mode
= bnx2_set_rx_mode
,
8560 .ndo_do_ioctl
= bnx2_ioctl
,
8561 .ndo_validate_addr
= eth_validate_addr
,
8562 .ndo_set_mac_address
= bnx2_change_mac_addr
,
8563 .ndo_change_mtu
= bnx2_change_mtu
,
8564 .ndo_set_features
= bnx2_set_features
,
8565 .ndo_tx_timeout
= bnx2_tx_timeout
,
8566 #ifdef CONFIG_NET_POLL_CONTROLLER
8567 .ndo_poll_controller
= poll_bnx2
,
8572 bnx2_init_one(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
8574 static int version_printed
= 0;
8575 struct net_device
*dev
;
8580 if (version_printed
++ == 0)
8581 pr_info("%s", version
);
8583 /* dev zeroed in init_etherdev */
8584 dev
= alloc_etherdev_mq(sizeof(*bp
), TX_MAX_RINGS
);
8588 rc
= bnx2_init_board(pdev
, dev
);
8592 dev
->netdev_ops
= &bnx2_netdev_ops
;
8593 dev
->watchdog_timeo
= TX_TIMEOUT
;
8594 dev
->ethtool_ops
= &bnx2_ethtool_ops
;
8596 bp
= netdev_priv(dev
);
8598 pci_set_drvdata(pdev
, dev
);
8601 * In-flight DMA from 1st kernel could continue going in kdump kernel.
8602 * New io-page table has been created before bnx2 does reset at open stage.
8603 * We have to wait for the in-flight DMA to complete to avoid it look up
8604 * into the newly created io-page table.
8606 if (is_kdump_kernel())
8607 bnx2_wait_dma_complete(bp
);
8609 memcpy(dev
->dev_addr
, bp
->mac_addr
, ETH_ALEN
);
8611 dev
->hw_features
= NETIF_F_IP_CSUM
| NETIF_F_SG
|
8612 NETIF_F_TSO
| NETIF_F_TSO_ECN
|
8613 NETIF_F_RXHASH
| NETIF_F_RXCSUM
;
8615 if (BNX2_CHIP(bp
) == BNX2_CHIP_5709
)
8616 dev
->hw_features
|= NETIF_F_IPV6_CSUM
| NETIF_F_TSO6
;
8618 dev
->vlan_features
= dev
->hw_features
;
8619 dev
->hw_features
|= NETIF_F_HW_VLAN_CTAG_TX
| NETIF_F_HW_VLAN_CTAG_RX
;
8620 dev
->features
|= dev
->hw_features
;
8621 dev
->priv_flags
|= IFF_UNICAST_FLT
;
8623 if (!(bp
->flags
& BNX2_FLAG_CAN_KEEP_VLAN
))
8624 dev
->hw_features
&= ~NETIF_F_HW_VLAN_CTAG_RX
;
8626 if ((rc
= register_netdev(dev
))) {
8627 dev_err(&pdev
->dev
, "Cannot register net device\n");
8631 netdev_info(dev
, "%s (%c%d) %s found at mem %lx, IRQ %d, "
8632 "node addr %pM\n", board_info
[ent
->driver_data
].name
,
8633 ((BNX2_CHIP_ID(bp
) & 0xf000) >> 12) + 'A',
8634 ((BNX2_CHIP_ID(bp
) & 0x0ff0) >> 4),
8635 bnx2_bus_string(bp
, str
), (long)pci_resource_start(pdev
, 0),
8636 pdev
->irq
, dev
->dev_addr
);
8641 pci_iounmap(pdev
, bp
->regview
);
8642 pci_release_regions(pdev
);
8643 pci_disable_device(pdev
);
8645 bnx2_free_stats_blk(dev
);
8651 bnx2_remove_one(struct pci_dev
*pdev
)
8653 struct net_device
*dev
= pci_get_drvdata(pdev
);
8654 struct bnx2
*bp
= netdev_priv(dev
);
8656 unregister_netdev(dev
);
8658 del_timer_sync(&bp
->timer
);
8659 cancel_work_sync(&bp
->reset_task
);
8661 pci_iounmap(bp
->pdev
, bp
->regview
);
8663 bnx2_free_stats_blk(dev
);
8664 kfree(bp
->temp_stats_blk
);
8666 if (bp
->flags
& BNX2_FLAG_AER_ENABLED
) {
8667 pci_disable_pcie_error_reporting(pdev
);
8668 bp
->flags
&= ~BNX2_FLAG_AER_ENABLED
;
8671 bnx2_release_firmware(bp
);
8675 pci_release_regions(pdev
);
8676 pci_disable_device(pdev
);
8679 #ifdef CONFIG_PM_SLEEP
8681 bnx2_suspend(struct device
*device
)
8683 struct pci_dev
*pdev
= to_pci_dev(device
);
8684 struct net_device
*dev
= pci_get_drvdata(pdev
);
8685 struct bnx2
*bp
= netdev_priv(dev
);
8687 if (netif_running(dev
)) {
8688 cancel_work_sync(&bp
->reset_task
);
8689 bnx2_netif_stop(bp
, true);
8690 netif_device_detach(dev
);
8691 del_timer_sync(&bp
->timer
);
8692 bnx2_shutdown_chip(bp
);
8693 __bnx2_free_irq(bp
);
8701 bnx2_resume(struct device
*device
)
8703 struct pci_dev
*pdev
= to_pci_dev(device
);
8704 struct net_device
*dev
= pci_get_drvdata(pdev
);
8705 struct bnx2
*bp
= netdev_priv(dev
);
8707 if (!netif_running(dev
))
8710 bnx2_set_power_state(bp
, PCI_D0
);
8711 netif_device_attach(dev
);
8712 bnx2_request_irq(bp
);
8713 bnx2_init_nic(bp
, 1);
8714 bnx2_netif_start(bp
, true);
8718 static SIMPLE_DEV_PM_OPS(bnx2_pm_ops
, bnx2_suspend
, bnx2_resume
);
8719 #define BNX2_PM_OPS (&bnx2_pm_ops)
8723 #define BNX2_PM_OPS NULL
8725 #endif /* CONFIG_PM_SLEEP */
8727 * bnx2_io_error_detected - called when PCI error is detected
8728 * @pdev: Pointer to PCI device
8729 * @state: The current pci connection state
8731 * This function is called after a PCI bus error affecting
8732 * this device has been detected.
8734 static pci_ers_result_t
bnx2_io_error_detected(struct pci_dev
*pdev
,
8735 pci_channel_state_t state
)
8737 struct net_device
*dev
= pci_get_drvdata(pdev
);
8738 struct bnx2
*bp
= netdev_priv(dev
);
8741 netif_device_detach(dev
);
8743 if (state
== pci_channel_io_perm_failure
) {
8745 return PCI_ERS_RESULT_DISCONNECT
;
8748 if (netif_running(dev
)) {
8749 bnx2_netif_stop(bp
, true);
8750 del_timer_sync(&bp
->timer
);
8751 bnx2_reset_nic(bp
, BNX2_DRV_MSG_CODE_RESET
);
8754 pci_disable_device(pdev
);
8757 /* Request a slot slot reset. */
8758 return PCI_ERS_RESULT_NEED_RESET
;
8762 * bnx2_io_slot_reset - called after the pci bus has been reset.
8763 * @pdev: Pointer to PCI device
8765 * Restart the card from scratch, as if from a cold-boot.
8767 static pci_ers_result_t
bnx2_io_slot_reset(struct pci_dev
*pdev
)
8769 struct net_device
*dev
= pci_get_drvdata(pdev
);
8770 struct bnx2
*bp
= netdev_priv(dev
);
8771 pci_ers_result_t result
= PCI_ERS_RESULT_DISCONNECT
;
8775 if (pci_enable_device(pdev
)) {
8777 "Cannot re-enable PCI device after reset\n");
8779 pci_set_master(pdev
);
8780 pci_restore_state(pdev
);
8781 pci_save_state(pdev
);
8783 if (netif_running(dev
))
8784 err
= bnx2_init_nic(bp
, 1);
8787 result
= PCI_ERS_RESULT_RECOVERED
;
8790 if (result
!= PCI_ERS_RESULT_RECOVERED
&& netif_running(dev
)) {
8791 bnx2_napi_enable(bp
);
8796 if (!(bp
->flags
& BNX2_FLAG_AER_ENABLED
))
8799 err
= pci_cleanup_aer_uncorrect_error_status(pdev
);
8802 "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n",
8803 err
); /* non-fatal, continue */
8810 * bnx2_io_resume - called when traffic can start flowing again.
8811 * @pdev: Pointer to PCI device
8813 * This callback is called when the error recovery driver tells us that
8814 * its OK to resume normal operation.
8816 static void bnx2_io_resume(struct pci_dev
*pdev
)
8818 struct net_device
*dev
= pci_get_drvdata(pdev
);
8819 struct bnx2
*bp
= netdev_priv(dev
);
8822 if (netif_running(dev
))
8823 bnx2_netif_start(bp
, true);
8825 netif_device_attach(dev
);
8829 static void bnx2_shutdown(struct pci_dev
*pdev
)
8831 struct net_device
*dev
= pci_get_drvdata(pdev
);
8837 bp
= netdev_priv(dev
);
8842 if (netif_running(dev
))
8845 if (system_state
== SYSTEM_POWER_OFF
)
8846 bnx2_set_power_state(bp
, PCI_D3hot
);
8851 static const struct pci_error_handlers bnx2_err_handler
= {
8852 .error_detected
= bnx2_io_error_detected
,
8853 .slot_reset
= bnx2_io_slot_reset
,
8854 .resume
= bnx2_io_resume
,
8857 static struct pci_driver bnx2_pci_driver
= {
8858 .name
= DRV_MODULE_NAME
,
8859 .id_table
= bnx2_pci_tbl
,
8860 .probe
= bnx2_init_one
,
8861 .remove
= bnx2_remove_one
,
8862 .driver
.pm
= BNX2_PM_OPS
,
8863 .err_handler
= &bnx2_err_handler
,
8864 .shutdown
= bnx2_shutdown
,
8867 module_pci_driver(bnx2_pci_driver
);