2 * tg3.c: Broadcom Tigon3 ethernet driver.
4 * Copyright (C) 2001, 2002, 2003, 2004 David S. Miller (davem@redhat.com)
5 * Copyright (C) 2001, 2002, 2003 Jeff Garzik (jgarzik@pobox.com)
6 * Copyright (C) 2004 Sun Microsystems Inc.
9 * Copyright (C) 2000-2003 Broadcom Corporation.
12 #include <linux/config.h>
14 #include <linux/module.h>
15 #include <linux/moduleparam.h>
16 #include <linux/kernel.h>
17 #include <linux/types.h>
18 #include <linux/compiler.h>
19 #include <linux/slab.h>
20 #include <linux/delay.h>
21 #include <linux/init.h>
22 #include <linux/ioport.h>
23 #include <linux/pci.h>
24 #include <linux/netdevice.h>
25 #include <linux/etherdevice.h>
26 #include <linux/skbuff.h>
27 #include <linux/ethtool.h>
28 #include <linux/mii.h>
29 #include <linux/if_vlan.h>
31 #include <linux/tcp.h>
32 #include <linux/workqueue.h>
34 #include <net/checksum.h>
36 #include <asm/system.h>
38 #include <asm/byteorder.h>
39 #include <asm/uaccess.h>
42 #include <asm/idprom.h>
43 #include <asm/oplib.h>
47 #if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
48 #define TG3_VLAN_TAG_USED 1
50 #define TG3_VLAN_TAG_USED 0
54 #define TG3_TSO_SUPPORT 1
56 #define TG3_TSO_SUPPORT 0
61 #define DRV_MODULE_NAME "tg3"
62 #define PFX DRV_MODULE_NAME ": "
63 #define DRV_MODULE_VERSION "3.15"
64 #define DRV_MODULE_RELDATE "January 6, 2005"
66 #define TG3_DEF_MAC_MODE 0
67 #define TG3_DEF_RX_MODE 0
68 #define TG3_DEF_TX_MODE 0
69 #define TG3_DEF_MSG_ENABLE \
79 /* length of time before we decide the hardware is borked,
80 * and dev->tx_timeout() should be called to fix the problem
82 #define TG3_TX_TIMEOUT (5 * HZ)
84 /* hardware minimum and maximum for a single frame's data payload */
85 #define TG3_MIN_MTU 60
86 #define TG3_MAX_MTU(tp) \
87 ((GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5705 && \
88 GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5750) ? 9000 : 1500)
90 /* These numbers seem to be hard coded in the NIC firmware somehow.
91 * You can't change the ring sizes, but you can change where you place
92 * them in the NIC onboard memory.
94 #define TG3_RX_RING_SIZE 512
95 #define TG3_DEF_RX_RING_PENDING 200
96 #define TG3_RX_JUMBO_RING_SIZE 256
97 #define TG3_DEF_RX_JUMBO_RING_PENDING 100
99 /* Do not place this n-ring entries value into the tp struct itself,
100 * we really want to expose these constants to GCC so that modulo et
101 * al. operations are done with shifts and masks instead of with
102 * hw multiply/modulo instructions. Another solution would be to
103 * replace things like '% foo' with '& (foo - 1)'.
105 #define TG3_RX_RCB_RING_SIZE(tp) \
106 ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 || \
107 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750) ? \
110 #define TG3_TX_RING_SIZE 512
111 #define TG3_DEF_TX_RING_PENDING (TG3_TX_RING_SIZE - 1)
113 #define TG3_RX_RING_BYTES (sizeof(struct tg3_rx_buffer_desc) * \
115 #define TG3_RX_JUMBO_RING_BYTES (sizeof(struct tg3_rx_buffer_desc) * \
116 TG3_RX_JUMBO_RING_SIZE)
117 #define TG3_RX_RCB_RING_BYTES(tp) (sizeof(struct tg3_rx_buffer_desc) * \
118 TG3_RX_RCB_RING_SIZE(tp))
119 #define TG3_TX_RING_BYTES (sizeof(struct tg3_tx_buffer_desc) * \
121 #define TX_RING_GAP(TP) \
122 (TG3_TX_RING_SIZE - (TP)->tx_pending)
123 #define TX_BUFFS_AVAIL(TP) \
124 (((TP)->tx_cons <= (TP)->tx_prod) ? \
125 (TP)->tx_cons + (TP)->tx_pending - (TP)->tx_prod : \
126 (TP)->tx_cons - (TP)->tx_prod - TX_RING_GAP(TP))
127 #define NEXT_TX(N) (((N) + 1) & (TG3_TX_RING_SIZE - 1))
129 #define RX_PKT_BUF_SZ (1536 + tp->rx_offset + 64)
130 #define RX_JUMBO_PKT_BUF_SZ (9046 + tp->rx_offset + 64)
132 /* minimum number of free TX descriptors required to wake up TX process */
133 #define TG3_TX_WAKEUP_THRESH (TG3_TX_RING_SIZE / 4)
135 /* number of ETHTOOL_GSTATS u64's */
136 #define TG3_NUM_STATS (sizeof(struct tg3_ethtool_stats)/sizeof(u64))
138 static char version[] __devinitdata =
139 DRV_MODULE_NAME ".c:v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
141 MODULE_AUTHOR("David S. Miller (davem@redhat.com) and Jeff Garzik (jgarzik@pobox.com)");
142 MODULE_DESCRIPTION("Broadcom Tigon3 ethernet driver");
143 MODULE_LICENSE("GPL");
144 MODULE_VERSION(DRV_MODULE_VERSION);
146 static int tg3_debug = -1; /* -1 == use TG3_DEF_MSG_ENABLE as value */
147 module_param(tg3_debug, int, 0);
148 MODULE_PARM_DESC(tg3_debug, "Tigon3 bitmapped debugging message enable value");
150 static struct pci_device_id tg3_pci_tbl[] = {
151 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5700,
152 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
153 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5701,
154 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
155 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702,
156 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
157 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5703,
158 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
159 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5704,
160 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
161 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702FE,
162 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
163 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705,
164 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
165 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705_2,
166 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
167 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705M,
168 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
169 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705M_2,
170 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
171 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702X,
172 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
173 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5703X,
174 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
175 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5704S,
176 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
177 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702A3,
178 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
179 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5703A3,
180 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
181 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5782,
182 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
183 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5788,
184 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
185 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5789,
186 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
187 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5901,
188 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
189 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5901_2,
190 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
191 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5704S_2,
192 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
193 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705F,
194 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
195 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5720,
196 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
197 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5721,
198 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
199 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5750,
200 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
201 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5751,
202 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
203 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5750M,
204 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
205 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5751M,
206 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
207 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5751F,
208 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
209 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753,
210 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
211 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753M,
212 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
213 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753F,
214 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
215 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5781,
216 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
217 { PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_9DXX,
218 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
219 { PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_9MXX,
220 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
221 { PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1000,
222 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
223 { PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1001,
224 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
225 { PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1003,
226 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
227 { PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC9100,
228 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
229 { PCI_VENDOR_ID_APPLE, PCI_DEVICE_ID_APPLE_TIGON3,
230 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
234 MODULE_DEVICE_TABLE(pci, tg3_pci_tbl);
237 const char string[ETH_GSTRING_LEN];
238 } ethtool_stats_keys[TG3_NUM_STATS] = {
241 { "rx_ucast_packets" },
242 { "rx_mcast_packets" },
243 { "rx_bcast_packets" },
245 { "rx_align_errors" },
246 { "rx_xon_pause_rcvd" },
247 { "rx_xoff_pause_rcvd" },
248 { "rx_mac_ctrl_rcvd" },
249 { "rx_xoff_entered" },
250 { "rx_frame_too_long_errors" },
252 { "rx_undersize_packets" },
253 { "rx_in_length_errors" },
254 { "rx_out_length_errors" },
255 { "rx_64_or_less_octet_packets" },
256 { "rx_65_to_127_octet_packets" },
257 { "rx_128_to_255_octet_packets" },
258 { "rx_256_to_511_octet_packets" },
259 { "rx_512_to_1023_octet_packets" },
260 { "rx_1024_to_1522_octet_packets" },
261 { "rx_1523_to_2047_octet_packets" },
262 { "rx_2048_to_4095_octet_packets" },
263 { "rx_4096_to_8191_octet_packets" },
264 { "rx_8192_to_9022_octet_packets" },
271 { "tx_flow_control" },
273 { "tx_single_collisions" },
274 { "tx_mult_collisions" },
276 { "tx_excessive_collisions" },
277 { "tx_late_collisions" },
278 { "tx_collide_2times" },
279 { "tx_collide_3times" },
280 { "tx_collide_4times" },
281 { "tx_collide_5times" },
282 { "tx_collide_6times" },
283 { "tx_collide_7times" },
284 { "tx_collide_8times" },
285 { "tx_collide_9times" },
286 { "tx_collide_10times" },
287 { "tx_collide_11times" },
288 { "tx_collide_12times" },
289 { "tx_collide_13times" },
290 { "tx_collide_14times" },
291 { "tx_collide_15times" },
292 { "tx_ucast_packets" },
293 { "tx_mcast_packets" },
294 { "tx_bcast_packets" },
295 { "tx_carrier_sense_errors" },
299 { "dma_writeq_full" },
300 { "dma_write_prioq_full" },
304 { "rx_threshold_hit" },
306 { "dma_readq_full" },
307 { "dma_read_prioq_full" },
308 { "tx_comp_queue_full" },
310 { "ring_set_send_prod_index" },
311 { "ring_status_update" },
313 { "nic_avoided_irqs" },
314 { "nic_tx_threshold_hit" }
317 static void tg3_write_indirect_reg32(struct tg3 *tp, u32 off, u32 val)
319 if ((tp->tg3_flags & TG3_FLAG_PCIX_TARGET_HWBUG) != 0) {
322 spin_lock_irqsave(&tp->indirect_lock, flags);
323 pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off);
324 pci_write_config_dword(tp->pdev, TG3PCI_REG_DATA, val);
325 spin_unlock_irqrestore(&tp->indirect_lock, flags);
327 writel(val, tp->regs + off);
328 if ((tp->tg3_flags & TG3_FLAG_5701_REG_WRITE_BUG) != 0)
329 readl(tp->regs + off);
333 static void _tw32_flush(struct tg3 *tp, u32 off, u32 val)
335 if ((tp->tg3_flags & TG3_FLAG_PCIX_TARGET_HWBUG) != 0) {
338 spin_lock_irqsave(&tp->indirect_lock, flags);
339 pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off);
340 pci_write_config_dword(tp->pdev, TG3PCI_REG_DATA, val);
341 spin_unlock_irqrestore(&tp->indirect_lock, flags);
343 void __iomem *dest = tp->regs + off;
345 readl(dest); /* always flush PCI write */
349 static inline void _tw32_rx_mbox(struct tg3 *tp, u32 off, u32 val)
351 void __iomem *mbox = tp->regs + off;
353 if (tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER)
357 static inline void _tw32_tx_mbox(struct tg3 *tp, u32 off, u32 val)
359 void __iomem *mbox = tp->regs + off;
361 if (tp->tg3_flags & TG3_FLAG_TXD_MBOX_HWBUG)
363 if (tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER)
367 #define tw32_mailbox(reg, val) writel(((val) & 0xffffffff), tp->regs + (reg))
368 #define tw32_rx_mbox(reg, val) _tw32_rx_mbox(tp, reg, val)
369 #define tw32_tx_mbox(reg, val) _tw32_tx_mbox(tp, reg, val)
371 #define tw32(reg,val) tg3_write_indirect_reg32(tp,(reg),(val))
372 #define tw32_f(reg,val) _tw32_flush(tp,(reg),(val))
373 #define tw16(reg,val) writew(((val) & 0xffff), tp->regs + (reg))
374 #define tw8(reg,val) writeb(((val) & 0xff), tp->regs + (reg))
375 #define tr32(reg) readl(tp->regs + (reg))
376 #define tr16(reg) readw(tp->regs + (reg))
377 #define tr8(reg) readb(tp->regs + (reg))
379 static void tg3_write_mem(struct tg3 *tp, u32 off, u32 val)
383 spin_lock_irqsave(&tp->indirect_lock, flags);
384 pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, off);
385 pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val);
387 /* Always leave this as zero. */
388 pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0);
389 spin_unlock_irqrestore(&tp->indirect_lock, flags);
392 static void tg3_read_mem(struct tg3 *tp, u32 off, u32 *val)
396 spin_lock_irqsave(&tp->indirect_lock, flags);
397 pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, off);
398 pci_read_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val);
400 /* Always leave this as zero. */
401 pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0);
402 spin_unlock_irqrestore(&tp->indirect_lock, flags);
405 static void tg3_disable_ints(struct tg3 *tp)
407 tw32(TG3PCI_MISC_HOST_CTRL,
408 (tp->misc_host_ctrl | MISC_HOST_CTRL_MASK_PCI_INT));
409 tw32_mailbox(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001);
410 tr32(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW);
413 static inline void tg3_cond_int(struct tg3 *tp)
415 if (tp->hw_status->status & SD_STATUS_UPDATED)
416 tw32(GRC_LOCAL_CTRL, tp->grc_local_ctrl | GRC_LCLCTRL_SETINT);
419 static void tg3_enable_ints(struct tg3 *tp)
421 tw32(TG3PCI_MISC_HOST_CTRL,
422 (tp->misc_host_ctrl & ~MISC_HOST_CTRL_MASK_PCI_INT));
423 tw32_mailbox(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000000);
424 tr32(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW);
430 * similar to tg3_enable_ints, but it can return without flushing the
431 * PIO write which reenables interrupts
433 static void tg3_restart_ints(struct tg3 *tp)
435 tw32(TG3PCI_MISC_HOST_CTRL,
436 (tp->misc_host_ctrl & ~MISC_HOST_CTRL_MASK_PCI_INT));
437 tw32_mailbox(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000000);
443 static inline void tg3_netif_stop(struct tg3 *tp)
445 netif_poll_disable(tp->dev);
446 netif_tx_disable(tp->dev);
449 static inline void tg3_netif_start(struct tg3 *tp)
451 netif_wake_queue(tp->dev);
452 /* NOTE: unconditional netif_wake_queue is only appropriate
453 * so long as all callers are assured to have free tx slots
454 * (such as after tg3_init_hw)
456 netif_poll_enable(tp->dev);
460 static void tg3_switch_clocks(struct tg3 *tp)
462 u32 clock_ctrl = tr32(TG3PCI_CLOCK_CTRL);
465 orig_clock_ctrl = clock_ctrl;
466 clock_ctrl &= (CLOCK_CTRL_FORCE_CLKRUN |
467 CLOCK_CTRL_CLKRUN_OENABLE |
469 tp->pci_clock_ctrl = clock_ctrl;
471 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 ||
472 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750) {
473 if (orig_clock_ctrl & CLOCK_CTRL_625_CORE) {
474 tw32_f(TG3PCI_CLOCK_CTRL,
475 clock_ctrl | CLOCK_CTRL_625_CORE);
478 } else if ((orig_clock_ctrl & CLOCK_CTRL_44MHZ_CORE) != 0) {
479 tw32_f(TG3PCI_CLOCK_CTRL,
481 (CLOCK_CTRL_44MHZ_CORE | CLOCK_CTRL_ALTCLK));
483 tw32_f(TG3PCI_CLOCK_CTRL,
484 clock_ctrl | (CLOCK_CTRL_ALTCLK));
487 tw32_f(TG3PCI_CLOCK_CTRL, clock_ctrl);
491 #define PHY_BUSY_LOOPS 5000
493 static int tg3_readphy(struct tg3 *tp, int reg, u32 *val)
499 if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) {
501 (tp->mi_mode & ~MAC_MI_MODE_AUTO_POLL));
507 frame_val = ((PHY_ADDR << MI_COM_PHY_ADDR_SHIFT) &
508 MI_COM_PHY_ADDR_MASK);
509 frame_val |= ((reg << MI_COM_REG_ADDR_SHIFT) &
510 MI_COM_REG_ADDR_MASK);
511 frame_val |= (MI_COM_CMD_READ | MI_COM_START);
513 tw32_f(MAC_MI_COM, frame_val);
515 loops = PHY_BUSY_LOOPS;
518 frame_val = tr32(MAC_MI_COM);
520 if ((frame_val & MI_COM_BUSY) == 0) {
522 frame_val = tr32(MAC_MI_COM);
530 *val = frame_val & MI_COM_DATA_MASK;
534 if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) {
535 tw32_f(MAC_MI_MODE, tp->mi_mode);
542 static int tg3_writephy(struct tg3 *tp, int reg, u32 val)
548 if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) {
550 (tp->mi_mode & ~MAC_MI_MODE_AUTO_POLL));
554 frame_val = ((PHY_ADDR << MI_COM_PHY_ADDR_SHIFT) &
555 MI_COM_PHY_ADDR_MASK);
556 frame_val |= ((reg << MI_COM_REG_ADDR_SHIFT) &
557 MI_COM_REG_ADDR_MASK);
558 frame_val |= (val & MI_COM_DATA_MASK);
559 frame_val |= (MI_COM_CMD_WRITE | MI_COM_START);
561 tw32_f(MAC_MI_COM, frame_val);
563 loops = PHY_BUSY_LOOPS;
566 frame_val = tr32(MAC_MI_COM);
567 if ((frame_val & MI_COM_BUSY) == 0) {
569 frame_val = tr32(MAC_MI_COM);
579 if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) {
580 tw32_f(MAC_MI_MODE, tp->mi_mode);
587 static void tg3_phy_set_wirespeed(struct tg3 *tp)
591 if (tp->tg3_flags2 & TG3_FLG2_NO_ETH_WIRE_SPEED)
594 tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x7007);
595 tg3_readphy(tp, MII_TG3_AUX_CTRL, &val);
596 tg3_writephy(tp, MII_TG3_AUX_CTRL, (val | (1 << 15) | (1 << 4)));
599 static int tg3_bmcr_reset(struct tg3 *tp)
604 /* OK, reset it, and poll the BMCR_RESET bit until it
605 * clears or we time out.
607 phy_control = BMCR_RESET;
608 err = tg3_writephy(tp, MII_BMCR, phy_control);
614 err = tg3_readphy(tp, MII_BMCR, &phy_control);
618 if ((phy_control & BMCR_RESET) == 0) {
630 static int tg3_wait_macro_done(struct tg3 *tp)
637 tg3_readphy(tp, 0x16, &tmp32);
638 if ((tmp32 & 0x1000) == 0)
647 static int tg3_phy_write_and_check_testpat(struct tg3 *tp, int *resetp)
649 static const u32 test_pat[4][6] = {
650 { 0x00005555, 0x00000005, 0x00002aaa, 0x0000000a, 0x00003456, 0x00000003 },
651 { 0x00002aaa, 0x0000000a, 0x00003333, 0x00000003, 0x0000789a, 0x00000005 },
652 { 0x00005a5a, 0x00000005, 0x00002a6a, 0x0000000a, 0x00001bcd, 0x00000003 },
653 { 0x00002a5a, 0x0000000a, 0x000033c3, 0x00000003, 0x00002ef1, 0x00000005 }
657 for (chan = 0; chan < 4; chan++) {
660 tg3_writephy(tp, MII_TG3_DSP_ADDRESS,
661 (chan * 0x2000) | 0x0200);
662 tg3_writephy(tp, 0x16, 0x0002);
664 for (i = 0; i < 6; i++)
665 tg3_writephy(tp, MII_TG3_DSP_RW_PORT,
668 tg3_writephy(tp, 0x16, 0x0202);
669 if (tg3_wait_macro_done(tp)) {
674 tg3_writephy(tp, MII_TG3_DSP_ADDRESS,
675 (chan * 0x2000) | 0x0200);
676 tg3_writephy(tp, 0x16, 0x0082);
677 if (tg3_wait_macro_done(tp)) {
682 tg3_writephy(tp, 0x16, 0x0802);
683 if (tg3_wait_macro_done(tp)) {
688 for (i = 0; i < 6; i += 2) {
691 tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &low);
692 tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &high);
693 if (tg3_wait_macro_done(tp)) {
699 if (low != test_pat[chan][i] ||
700 high != test_pat[chan][i+1]) {
701 tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000b);
702 tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x4001);
703 tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x4005);
713 static int tg3_phy_reset_chanpat(struct tg3 *tp)
717 for (chan = 0; chan < 4; chan++) {
720 tg3_writephy(tp, MII_TG3_DSP_ADDRESS,
721 (chan * 0x2000) | 0x0200);
722 tg3_writephy(tp, 0x16, 0x0002);
723 for (i = 0; i < 6; i++)
724 tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x000);
725 tg3_writephy(tp, 0x16, 0x0202);
726 if (tg3_wait_macro_done(tp))
733 static int tg3_phy_reset_5703_4_5(struct tg3 *tp)
735 u32 reg32, phy9_orig;
736 int retries, do_phy_reset, err;
742 err = tg3_bmcr_reset(tp);
748 /* Disable transmitter and interrupt. */
749 tg3_readphy(tp, MII_TG3_EXT_CTRL, ®32);
751 tg3_writephy(tp, MII_TG3_EXT_CTRL, reg32);
753 /* Set full-duplex, 1000 mbps. */
754 tg3_writephy(tp, MII_BMCR,
755 BMCR_FULLDPLX | TG3_BMCR_SPEED1000);
757 /* Set to master mode. */
758 tg3_readphy(tp, MII_TG3_CTRL, &phy9_orig);
759 tg3_writephy(tp, MII_TG3_CTRL,
760 (MII_TG3_CTRL_AS_MASTER |
761 MII_TG3_CTRL_ENABLE_AS_MASTER));
763 /* Enable SM_DSP_CLOCK and 6dB. */
764 tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0c00);
766 /* Block the PHY control access. */
767 tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8005);
768 tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0800);
770 err = tg3_phy_write_and_check_testpat(tp, &do_phy_reset);
775 err = tg3_phy_reset_chanpat(tp);
779 tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8005);
780 tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0000);
782 tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8200);
783 tg3_writephy(tp, 0x16, 0x0000);
785 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 ||
786 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) {
787 /* Set Extended packet length bit for jumbo frames */
788 tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x4400);
791 tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0400);
794 tg3_writephy(tp, MII_TG3_CTRL, phy9_orig);
796 tg3_readphy(tp, MII_TG3_EXT_CTRL, ®32);
798 tg3_writephy(tp, MII_TG3_EXT_CTRL, reg32);
803 /* This will reset the tigon3 PHY if there is no valid
804 * link unless the FORCE argument is non-zero.
806 static int tg3_phy_reset(struct tg3 *tp)
811 err = tg3_readphy(tp, MII_BMSR, &phy_status);
812 err |= tg3_readphy(tp, MII_BMSR, &phy_status);
816 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 ||
817 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 ||
818 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) {
819 err = tg3_phy_reset_5703_4_5(tp);
825 err = tg3_bmcr_reset(tp);
830 if (tp->tg3_flags2 & TG3_FLG2_PHY_ADC_BUG) {
831 tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0c00);
832 tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x201f);
833 tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x2aaa);
834 tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000a);
835 tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0323);
836 tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0400);
838 if (tp->tg3_flags2 & TG3_FLG2_PHY_5704_A0_BUG) {
839 tg3_writephy(tp, 0x1c, 0x8d68);
840 tg3_writephy(tp, 0x1c, 0x8d68);
842 if (tp->tg3_flags2 & TG3_FLG2_PHY_BER_BUG) {
843 tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0c00);
844 tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000a);
845 tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x310b);
846 tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x201f);
847 tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x9506);
848 tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x401f);
849 tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x14e2);
850 tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0400);
852 /* Set Extended packet length bit (bit 14) on all chips that */
853 /* support jumbo frames */
854 if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5401) {
855 /* Cannot do read-modify-write on 5401 */
856 tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x4c20);
857 } else if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5705 &&
858 GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5750) {
861 /* Set bit 14 with read-modify-write to preserve other bits */
862 tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0007);
863 tg3_readphy(tp, MII_TG3_AUX_CTRL, &phy_reg);
864 tg3_writephy(tp, MII_TG3_AUX_CTRL, phy_reg | 0x4000);
866 tg3_phy_set_wirespeed(tp);
870 static void tg3_frob_aux_power(struct tg3 *tp)
872 struct tg3 *tp_peer = tp;
874 if ((tp->tg3_flags & TG3_FLAG_EEPROM_WRITE_PROT) != 0)
877 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) {
878 tp_peer = pci_get_drvdata(tp->pdev_peer);
884 if ((tp->tg3_flags & TG3_FLAG_WOL_ENABLE) != 0 ||
885 (tp_peer->tg3_flags & TG3_FLAG_WOL_ENABLE) != 0) {
886 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
887 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) {
888 tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
889 (GRC_LCLCTRL_GPIO_OE0 |
890 GRC_LCLCTRL_GPIO_OE1 |
891 GRC_LCLCTRL_GPIO_OE2 |
892 GRC_LCLCTRL_GPIO_OUTPUT0 |
893 GRC_LCLCTRL_GPIO_OUTPUT1));
900 (tp_peer->tg3_flags & TG3_FLAG_INIT_COMPLETE) != 0)
903 /* On 5753 and variants, GPIO2 cannot be used. */
904 no_gpio2 = (tp->nic_sram_data_cfg &
905 NIC_SRAM_DATA_CFG_NO_GPIO2) != 0;
907 grc_local_ctrl = GRC_LCLCTRL_GPIO_OE0 |
908 GRC_LCLCTRL_GPIO_OE1 |
909 GRC_LCLCTRL_GPIO_OE2 |
910 GRC_LCLCTRL_GPIO_OUTPUT1 |
911 GRC_LCLCTRL_GPIO_OUTPUT2;
913 grc_local_ctrl &= ~(GRC_LCLCTRL_GPIO_OE2 |
914 GRC_LCLCTRL_GPIO_OUTPUT2);
916 tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
920 grc_local_ctrl = GRC_LCLCTRL_GPIO_OE0 |
921 GRC_LCLCTRL_GPIO_OE1 |
922 GRC_LCLCTRL_GPIO_OE2 |
923 GRC_LCLCTRL_GPIO_OUTPUT0 |
924 GRC_LCLCTRL_GPIO_OUTPUT1 |
925 GRC_LCLCTRL_GPIO_OUTPUT2;
927 grc_local_ctrl &= ~(GRC_LCLCTRL_GPIO_OE2 |
928 GRC_LCLCTRL_GPIO_OUTPUT2);
930 tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
934 grc_local_ctrl = GRC_LCLCTRL_GPIO_OE0 |
935 GRC_LCLCTRL_GPIO_OE1 |
936 GRC_LCLCTRL_GPIO_OE2 |
937 GRC_LCLCTRL_GPIO_OUTPUT0 |
938 GRC_LCLCTRL_GPIO_OUTPUT1;
940 tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
946 if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 &&
947 GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) {
949 (tp_peer->tg3_flags & TG3_FLAG_INIT_COMPLETE) != 0)
952 tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
953 (GRC_LCLCTRL_GPIO_OE1 |
954 GRC_LCLCTRL_GPIO_OUTPUT1));
957 tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
958 (GRC_LCLCTRL_GPIO_OE1));
961 tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
962 (GRC_LCLCTRL_GPIO_OE1 |
963 GRC_LCLCTRL_GPIO_OUTPUT1));
969 static int tg3_setup_phy(struct tg3 *, int);
971 #define RESET_KIND_SHUTDOWN 0
972 #define RESET_KIND_INIT 1
973 #define RESET_KIND_SUSPEND 2
975 static void tg3_write_sig_post_reset(struct tg3 *, int);
977 static int tg3_set_power_state(struct tg3 *tp, int state)
980 u16 power_control, power_caps;
983 /* Make sure register accesses (indirect or otherwise)
984 * will function correctly.
986 pci_write_config_dword(tp->pdev,
987 TG3PCI_MISC_HOST_CTRL,
990 pci_read_config_word(tp->pdev,
993 power_control |= PCI_PM_CTRL_PME_STATUS;
994 power_control &= ~(PCI_PM_CTRL_STATE_MASK);
998 pci_write_config_word(tp->pdev,
1001 tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl);
1019 printk(KERN_WARNING PFX "%s: Invalid power state (%d) "
1021 tp->dev->name, state);
1025 power_control |= PCI_PM_CTRL_PME_ENABLE;
1027 misc_host_ctrl = tr32(TG3PCI_MISC_HOST_CTRL);
1028 tw32(TG3PCI_MISC_HOST_CTRL,
1029 misc_host_ctrl | MISC_HOST_CTRL_MASK_PCI_INT);
1031 if (tp->link_config.phy_is_low_power == 0) {
1032 tp->link_config.phy_is_low_power = 1;
1033 tp->link_config.orig_speed = tp->link_config.speed;
1034 tp->link_config.orig_duplex = tp->link_config.duplex;
1035 tp->link_config.orig_autoneg = tp->link_config.autoneg;
1038 if (!(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)) {
1039 tp->link_config.speed = SPEED_10;
1040 tp->link_config.duplex = DUPLEX_HALF;
1041 tp->link_config.autoneg = AUTONEG_ENABLE;
1042 tg3_setup_phy(tp, 0);
1045 pci_read_config_word(tp->pdev, pm + PCI_PM_PMC, &power_caps);
1047 if (tp->tg3_flags & TG3_FLAG_WOL_ENABLE) {
1050 if (!(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)) {
1051 tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x5a);
1054 mac_mode = MAC_MODE_PORT_MODE_MII;
1056 if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 ||
1057 !(tp->tg3_flags & TG3_FLAG_WOL_SPEED_100MB))
1058 mac_mode |= MAC_MODE_LINK_POLARITY;
1060 mac_mode = MAC_MODE_PORT_MODE_TBI;
1063 if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5750)
1064 tw32(MAC_LED_CTRL, tp->led_ctrl);
1066 if (((power_caps & PCI_PM_CAP_PME_D3cold) &&
1067 (tp->tg3_flags & TG3_FLAG_WOL_ENABLE)))
1068 mac_mode |= MAC_MODE_MAGIC_PKT_ENABLE;
1070 tw32_f(MAC_MODE, mac_mode);
1073 tw32_f(MAC_RX_MODE, RX_MODE_ENABLE);
1077 if (!(tp->tg3_flags & TG3_FLAG_WOL_SPEED_100MB) &&
1078 (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
1079 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701)) {
1082 base_val = tp->pci_clock_ctrl;
1083 base_val |= (CLOCK_CTRL_RXCLK_DISABLE |
1084 CLOCK_CTRL_TXCLK_DISABLE);
1086 tw32_f(TG3PCI_CLOCK_CTRL, base_val |
1088 CLOCK_CTRL_PWRDOWN_PLL133);
1090 } else if (!((GET_ASIC_REV(tp->pci_chip_rev_id) == 5750) &&
1091 (tp->tg3_flags & TG3_FLAG_ENABLE_ASF))) {
1092 u32 newbits1, newbits2;
1094 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
1095 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) {
1096 newbits1 = (CLOCK_CTRL_RXCLK_DISABLE |
1097 CLOCK_CTRL_TXCLK_DISABLE |
1099 newbits2 = newbits1 | CLOCK_CTRL_44MHZ_CORE;
1100 } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 ||
1101 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750) {
1102 newbits1 = CLOCK_CTRL_625_CORE;
1103 newbits2 = newbits1 | CLOCK_CTRL_ALTCLK;
1105 newbits1 = CLOCK_CTRL_ALTCLK;
1106 newbits2 = newbits1 | CLOCK_CTRL_44MHZ_CORE;
1109 tw32_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl | newbits1);
1112 tw32_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl | newbits2);
1115 if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5705 &&
1116 GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5750) {
1119 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
1120 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) {
1121 newbits3 = (CLOCK_CTRL_RXCLK_DISABLE |
1122 CLOCK_CTRL_TXCLK_DISABLE |
1123 CLOCK_CTRL_44MHZ_CORE);
1125 newbits3 = CLOCK_CTRL_44MHZ_CORE;
1128 tw32_f(TG3PCI_CLOCK_CTRL,
1129 tp->pci_clock_ctrl | newbits3);
1134 tg3_frob_aux_power(tp);
1136 /* Finally, set the new power state. */
1137 pci_write_config_word(tp->pdev, pm + PCI_PM_CTRL, power_control);
1139 tg3_write_sig_post_reset(tp, RESET_KIND_SHUTDOWN);
1144 static void tg3_link_report(struct tg3 *tp)
1146 if (!netif_carrier_ok(tp->dev)) {
1147 printk(KERN_INFO PFX "%s: Link is down.\n", tp->dev->name);
1149 printk(KERN_INFO PFX "%s: Link is up at %d Mbps, %s duplex.\n",
1151 (tp->link_config.active_speed == SPEED_1000 ?
1153 (tp->link_config.active_speed == SPEED_100 ?
1155 (tp->link_config.active_duplex == DUPLEX_FULL ?
1158 printk(KERN_INFO PFX "%s: Flow control is %s for TX and "
1161 (tp->tg3_flags & TG3_FLAG_TX_PAUSE) ? "on" : "off",
1162 (tp->tg3_flags & TG3_FLAG_RX_PAUSE) ? "on" : "off");
1166 static void tg3_setup_flow_control(struct tg3 *tp, u32 local_adv, u32 remote_adv)
1168 u32 new_tg3_flags = 0;
1169 u32 old_rx_mode = tp->rx_mode;
1170 u32 old_tx_mode = tp->tx_mode;
1172 if (tp->tg3_flags & TG3_FLAG_PAUSE_AUTONEG) {
1173 if (local_adv & ADVERTISE_PAUSE_CAP) {
1174 if (local_adv & ADVERTISE_PAUSE_ASYM) {
1175 if (remote_adv & LPA_PAUSE_CAP)
1177 (TG3_FLAG_RX_PAUSE |
1179 else if (remote_adv & LPA_PAUSE_ASYM)
1181 (TG3_FLAG_RX_PAUSE);
1183 if (remote_adv & LPA_PAUSE_CAP)
1185 (TG3_FLAG_RX_PAUSE |
1188 } else if (local_adv & ADVERTISE_PAUSE_ASYM) {
1189 if ((remote_adv & LPA_PAUSE_CAP) &&
1190 (remote_adv & LPA_PAUSE_ASYM))
1191 new_tg3_flags |= TG3_FLAG_TX_PAUSE;
1194 tp->tg3_flags &= ~(TG3_FLAG_RX_PAUSE | TG3_FLAG_TX_PAUSE);
1195 tp->tg3_flags |= new_tg3_flags;
1197 new_tg3_flags = tp->tg3_flags;
1200 if (new_tg3_flags & TG3_FLAG_RX_PAUSE)
1201 tp->rx_mode |= RX_MODE_FLOW_CTRL_ENABLE;
1203 tp->rx_mode &= ~RX_MODE_FLOW_CTRL_ENABLE;
1205 if (old_rx_mode != tp->rx_mode) {
1206 tw32_f(MAC_RX_MODE, tp->rx_mode);
1209 if (new_tg3_flags & TG3_FLAG_TX_PAUSE)
1210 tp->tx_mode |= TX_MODE_FLOW_CTRL_ENABLE;
1212 tp->tx_mode &= ~TX_MODE_FLOW_CTRL_ENABLE;
1214 if (old_tx_mode != tp->tx_mode) {
1215 tw32_f(MAC_TX_MODE, tp->tx_mode);
1219 static void tg3_aux_stat_to_speed_duplex(struct tg3 *tp, u32 val, u16 *speed, u8 *duplex)
1221 switch (val & MII_TG3_AUX_STAT_SPDMASK) {
1222 case MII_TG3_AUX_STAT_10HALF:
1224 *duplex = DUPLEX_HALF;
1227 case MII_TG3_AUX_STAT_10FULL:
1229 *duplex = DUPLEX_FULL;
1232 case MII_TG3_AUX_STAT_100HALF:
1234 *duplex = DUPLEX_HALF;
1237 case MII_TG3_AUX_STAT_100FULL:
1239 *duplex = DUPLEX_FULL;
1242 case MII_TG3_AUX_STAT_1000HALF:
1243 *speed = SPEED_1000;
1244 *duplex = DUPLEX_HALF;
1247 case MII_TG3_AUX_STAT_1000FULL:
1248 *speed = SPEED_1000;
1249 *duplex = DUPLEX_FULL;
1253 *speed = SPEED_INVALID;
1254 *duplex = DUPLEX_INVALID;
1259 static int tg3_phy_copper_begin(struct tg3 *tp)
1264 if (tp->link_config.phy_is_low_power) {
1265 /* Entering low power mode. Disable gigabit and
1266 * 100baseT advertisements.
1268 tg3_writephy(tp, MII_TG3_CTRL, 0);
1270 new_adv = (ADVERTISE_10HALF | ADVERTISE_10FULL |
1271 ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP);
1272 if (tp->tg3_flags & TG3_FLAG_WOL_SPEED_100MB)
1273 new_adv |= (ADVERTISE_100HALF | ADVERTISE_100FULL);
1275 tg3_writephy(tp, MII_ADVERTISE, new_adv);
1276 } else if (tp->link_config.speed == SPEED_INVALID) {
1277 tp->link_config.advertising =
1278 (ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full |
1279 ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full |
1280 ADVERTISED_1000baseT_Half | ADVERTISED_1000baseT_Full |
1281 ADVERTISED_Autoneg | ADVERTISED_MII);
1283 if (tp->tg3_flags & TG3_FLAG_10_100_ONLY)
1284 tp->link_config.advertising &=
1285 ~(ADVERTISED_1000baseT_Half |
1286 ADVERTISED_1000baseT_Full);
1288 new_adv = (ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP);
1289 if (tp->link_config.advertising & ADVERTISED_10baseT_Half)
1290 new_adv |= ADVERTISE_10HALF;
1291 if (tp->link_config.advertising & ADVERTISED_10baseT_Full)
1292 new_adv |= ADVERTISE_10FULL;
1293 if (tp->link_config.advertising & ADVERTISED_100baseT_Half)
1294 new_adv |= ADVERTISE_100HALF;
1295 if (tp->link_config.advertising & ADVERTISED_100baseT_Full)
1296 new_adv |= ADVERTISE_100FULL;
1297 tg3_writephy(tp, MII_ADVERTISE, new_adv);
1299 if (tp->link_config.advertising &
1300 (ADVERTISED_1000baseT_Half | ADVERTISED_1000baseT_Full)) {
1302 if (tp->link_config.advertising & ADVERTISED_1000baseT_Half)
1303 new_adv |= MII_TG3_CTRL_ADV_1000_HALF;
1304 if (tp->link_config.advertising & ADVERTISED_1000baseT_Full)
1305 new_adv |= MII_TG3_CTRL_ADV_1000_FULL;
1306 if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY) &&
1307 (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 ||
1308 tp->pci_chip_rev_id == CHIPREV_ID_5701_B0))
1309 new_adv |= (MII_TG3_CTRL_AS_MASTER |
1310 MII_TG3_CTRL_ENABLE_AS_MASTER);
1311 tg3_writephy(tp, MII_TG3_CTRL, new_adv);
1313 tg3_writephy(tp, MII_TG3_CTRL, 0);
1316 /* Asking for a specific link mode. */
1317 if (tp->link_config.speed == SPEED_1000) {
1318 new_adv = ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP;
1319 tg3_writephy(tp, MII_ADVERTISE, new_adv);
1321 if (tp->link_config.duplex == DUPLEX_FULL)
1322 new_adv = MII_TG3_CTRL_ADV_1000_FULL;
1324 new_adv = MII_TG3_CTRL_ADV_1000_HALF;
1325 if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 ||
1326 tp->pci_chip_rev_id == CHIPREV_ID_5701_B0)
1327 new_adv |= (MII_TG3_CTRL_AS_MASTER |
1328 MII_TG3_CTRL_ENABLE_AS_MASTER);
1329 tg3_writephy(tp, MII_TG3_CTRL, new_adv);
1331 tg3_writephy(tp, MII_TG3_CTRL, 0);
1333 new_adv = ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP;
1334 if (tp->link_config.speed == SPEED_100) {
1335 if (tp->link_config.duplex == DUPLEX_FULL)
1336 new_adv |= ADVERTISE_100FULL;
1338 new_adv |= ADVERTISE_100HALF;
1340 if (tp->link_config.duplex == DUPLEX_FULL)
1341 new_adv |= ADVERTISE_10FULL;
1343 new_adv |= ADVERTISE_10HALF;
1345 tg3_writephy(tp, MII_ADVERTISE, new_adv);
1349 if (tp->link_config.autoneg == AUTONEG_DISABLE &&
1350 tp->link_config.speed != SPEED_INVALID) {
1351 u32 bmcr, orig_bmcr;
1353 tp->link_config.active_speed = tp->link_config.speed;
1354 tp->link_config.active_duplex = tp->link_config.duplex;
1357 switch (tp->link_config.speed) {
1363 bmcr |= BMCR_SPEED100;
1367 bmcr |= TG3_BMCR_SPEED1000;
1371 if (tp->link_config.duplex == DUPLEX_FULL)
1372 bmcr |= BMCR_FULLDPLX;
1374 tg3_readphy(tp, MII_BMCR, &orig_bmcr);
1375 if (bmcr != orig_bmcr) {
1376 tg3_writephy(tp, MII_BMCR, BMCR_LOOPBACK);
1377 for (i = 0; i < 1500; i++) {
1381 tg3_readphy(tp, MII_BMSR, &tmp);
1382 tg3_readphy(tp, MII_BMSR, &tmp);
1383 if (!(tmp & BMSR_LSTATUS)) {
1388 tg3_writephy(tp, MII_BMCR, bmcr);
1392 tg3_writephy(tp, MII_BMCR,
1393 BMCR_ANENABLE | BMCR_ANRESTART);
1399 static int tg3_init_5401phy_dsp(struct tg3 *tp)
1403 /* Turn off tap power management. */
1404 /* Set Extended packet length bit */
1405 err = tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x4c20);
1407 err |= tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x0012);
1408 err |= tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x1804);
1410 err |= tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x0013);
1411 err |= tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x1204);
1413 err |= tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8006);
1414 err |= tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0132);
1416 err |= tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8006);
1417 err |= tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0232);
1419 err |= tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x201f);
1420 err |= tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0a20);
1427 static int tg3_copper_is_advertising_all(struct tg3 *tp)
1429 u32 adv_reg, all_mask;
1431 tg3_readphy(tp, MII_ADVERTISE, &adv_reg);
1432 all_mask = (ADVERTISE_10HALF | ADVERTISE_10FULL |
1433 ADVERTISE_100HALF | ADVERTISE_100FULL);
1434 if ((adv_reg & all_mask) != all_mask)
1436 if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY)) {
1439 tg3_readphy(tp, MII_TG3_CTRL, &tg3_ctrl);
1440 all_mask = (MII_TG3_CTRL_ADV_1000_HALF |
1441 MII_TG3_CTRL_ADV_1000_FULL);
1442 if ((tg3_ctrl & all_mask) != all_mask)
1448 static int tg3_setup_copper_phy(struct tg3 *tp, int force_reset)
1450 int current_link_up;
1459 (MAC_STATUS_SYNC_CHANGED |
1460 MAC_STATUS_CFG_CHANGED |
1461 MAC_STATUS_MI_COMPLETION |
1462 MAC_STATUS_LNKSTATE_CHANGED));
1465 tp->mi_mode = MAC_MI_MODE_BASE;
1466 tw32_f(MAC_MI_MODE, tp->mi_mode);
1469 tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x02);
1471 /* Some third-party PHYs need to be reset on link going
1474 if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 ||
1475 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 ||
1476 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) &&
1477 netif_carrier_ok(tp->dev)) {
1478 tg3_readphy(tp, MII_BMSR, &bmsr);
1479 tg3_readphy(tp, MII_BMSR, &bmsr);
1480 if (!(bmsr & BMSR_LSTATUS))
1486 if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5401) {
1487 tg3_readphy(tp, MII_BMSR, &bmsr);
1488 tg3_readphy(tp, MII_BMSR, &bmsr);
1490 if (!(tp->tg3_flags & TG3_FLAG_INIT_COMPLETE))
1493 if (!(bmsr & BMSR_LSTATUS)) {
1494 err = tg3_init_5401phy_dsp(tp);
1498 tg3_readphy(tp, MII_BMSR, &bmsr);
1499 for (i = 0; i < 1000; i++) {
1501 tg3_readphy(tp, MII_BMSR, &bmsr);
1502 if (bmsr & BMSR_LSTATUS) {
1508 if ((tp->phy_id & PHY_ID_REV_MASK) == PHY_REV_BCM5401_B0 &&
1509 !(bmsr & BMSR_LSTATUS) &&
1510 tp->link_config.active_speed == SPEED_1000) {
1511 err = tg3_phy_reset(tp);
1513 err = tg3_init_5401phy_dsp(tp);
1518 } else if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 ||
1519 tp->pci_chip_rev_id == CHIPREV_ID_5701_B0) {
1520 /* 5701 {A0,B0} CRC bug workaround */
1521 tg3_writephy(tp, 0x15, 0x0a75);
1522 tg3_writephy(tp, 0x1c, 0x8c68);
1523 tg3_writephy(tp, 0x1c, 0x8d68);
1524 tg3_writephy(tp, 0x1c, 0x8c68);
1527 /* Clear pending interrupts... */
1528 tg3_readphy(tp, MII_TG3_ISTAT, &dummy);
1529 tg3_readphy(tp, MII_TG3_ISTAT, &dummy);
1531 if (tp->tg3_flags & TG3_FLAG_USE_MI_INTERRUPT)
1532 tg3_writephy(tp, MII_TG3_IMASK, ~MII_TG3_INT_LINKCHG);
1534 tg3_writephy(tp, MII_TG3_IMASK, ~0);
1536 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
1537 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) {
1538 if (tp->led_ctrl == LED_CTRL_MODE_PHY_1)
1539 tg3_writephy(tp, MII_TG3_EXT_CTRL,
1540 MII_TG3_EXT_CTRL_LNK3_LED_MODE);
1542 tg3_writephy(tp, MII_TG3_EXT_CTRL, 0);
1545 current_link_up = 0;
1546 current_speed = SPEED_INVALID;
1547 current_duplex = DUPLEX_INVALID;
1549 if (tp->tg3_flags2 & TG3_FLG2_CAPACITIVE_COUPLING) {
1552 tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x4007);
1553 tg3_readphy(tp, MII_TG3_AUX_CTRL, &val);
1554 if (!(val & (1 << 10))) {
1556 tg3_writephy(tp, MII_TG3_AUX_CTRL, val);
1562 for (i = 0; i < 100; i++) {
1563 tg3_readphy(tp, MII_BMSR, &bmsr);
1564 tg3_readphy(tp, MII_BMSR, &bmsr);
1565 if (bmsr & BMSR_LSTATUS)
1570 if (bmsr & BMSR_LSTATUS) {
1573 tg3_readphy(tp, MII_TG3_AUX_STAT, &aux_stat);
1574 for (i = 0; i < 2000; i++) {
1576 tg3_readphy(tp, MII_TG3_AUX_STAT, &aux_stat);
1581 tg3_aux_stat_to_speed_duplex(tp, aux_stat,
1586 for (i = 0; i < 200; i++) {
1587 tg3_readphy(tp, MII_BMCR, &bmcr);
1588 tg3_readphy(tp, MII_BMCR, &bmcr);
1589 if (bmcr && bmcr != 0x7fff)
1594 if (tp->link_config.autoneg == AUTONEG_ENABLE) {
1595 if (bmcr & BMCR_ANENABLE) {
1596 current_link_up = 1;
1598 /* Force autoneg restart if we are exiting
1601 if (!tg3_copper_is_advertising_all(tp))
1602 current_link_up = 0;
1604 current_link_up = 0;
1607 if (!(bmcr & BMCR_ANENABLE) &&
1608 tp->link_config.speed == current_speed &&
1609 tp->link_config.duplex == current_duplex) {
1610 current_link_up = 1;
1612 current_link_up = 0;
1616 tp->link_config.active_speed = current_speed;
1617 tp->link_config.active_duplex = current_duplex;
1620 if (current_link_up == 1 &&
1621 (tp->link_config.active_duplex == DUPLEX_FULL) &&
1622 (tp->link_config.autoneg == AUTONEG_ENABLE)) {
1623 u32 local_adv, remote_adv;
1625 tg3_readphy(tp, MII_ADVERTISE, &local_adv);
1626 local_adv &= (ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM);
1628 tg3_readphy(tp, MII_LPA, &remote_adv);
1629 remote_adv &= (LPA_PAUSE_CAP | LPA_PAUSE_ASYM);
1631 /* If we are not advertising full pause capability,
1632 * something is wrong. Bring the link down and reconfigure.
1634 if (local_adv != ADVERTISE_PAUSE_CAP) {
1635 current_link_up = 0;
1637 tg3_setup_flow_control(tp, local_adv, remote_adv);
1641 if (current_link_up == 0) {
1644 tg3_phy_copper_begin(tp);
1646 tg3_readphy(tp, MII_BMSR, &tmp);
1647 tg3_readphy(tp, MII_BMSR, &tmp);
1648 if (tmp & BMSR_LSTATUS)
1649 current_link_up = 1;
1652 tp->mac_mode &= ~MAC_MODE_PORT_MODE_MASK;
1653 if (current_link_up == 1) {
1654 if (tp->link_config.active_speed == SPEED_100 ||
1655 tp->link_config.active_speed == SPEED_10)
1656 tp->mac_mode |= MAC_MODE_PORT_MODE_MII;
1658 tp->mac_mode |= MAC_MODE_PORT_MODE_GMII;
1660 tp->mac_mode |= MAC_MODE_PORT_MODE_GMII;
1662 tp->mac_mode &= ~MAC_MODE_HALF_DUPLEX;
1663 if (tp->link_config.active_duplex == DUPLEX_HALF)
1664 tp->mac_mode |= MAC_MODE_HALF_DUPLEX;
1666 tp->mac_mode &= ~MAC_MODE_LINK_POLARITY;
1667 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) {
1668 if ((tp->led_ctrl == LED_CTRL_MODE_PHY_2) ||
1669 (current_link_up == 1 &&
1670 tp->link_config.active_speed == SPEED_10))
1671 tp->mac_mode |= MAC_MODE_LINK_POLARITY;
1673 if (current_link_up == 1)
1674 tp->mac_mode |= MAC_MODE_LINK_POLARITY;
1677 /* ??? Without this setting Netgear GA302T PHY does not
1678 * ??? send/receive packets...
1680 if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5411 &&
1681 tp->pci_chip_rev_id == CHIPREV_ID_5700_ALTIMA) {
1682 tp->mi_mode |= MAC_MI_MODE_AUTO_POLL;
1683 tw32_f(MAC_MI_MODE, tp->mi_mode);
1687 tw32_f(MAC_MODE, tp->mac_mode);
1690 if (tp->tg3_flags & TG3_FLAG_USE_LINKCHG_REG) {
1691 /* Polled via timer. */
1692 tw32_f(MAC_EVENT, 0);
1694 tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED);
1698 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 &&
1699 current_link_up == 1 &&
1700 tp->link_config.active_speed == SPEED_1000 &&
1701 ((tp->tg3_flags & TG3_FLAG_PCIX_MODE) ||
1702 (tp->tg3_flags & TG3_FLAG_PCI_HIGH_SPEED))) {
1705 (MAC_STATUS_SYNC_CHANGED |
1706 MAC_STATUS_CFG_CHANGED));
1709 NIC_SRAM_FIRMWARE_MBOX,
1710 NIC_SRAM_FIRMWARE_MBOX_MAGIC2);
1713 if (current_link_up != netif_carrier_ok(tp->dev)) {
1714 if (current_link_up)
1715 netif_carrier_on(tp->dev);
1717 netif_carrier_off(tp->dev);
1718 tg3_link_report(tp);
1724 struct tg3_fiber_aneginfo {
1726 #define ANEG_STATE_UNKNOWN 0
1727 #define ANEG_STATE_AN_ENABLE 1
1728 #define ANEG_STATE_RESTART_INIT 2
1729 #define ANEG_STATE_RESTART 3
1730 #define ANEG_STATE_DISABLE_LINK_OK 4
1731 #define ANEG_STATE_ABILITY_DETECT_INIT 5
1732 #define ANEG_STATE_ABILITY_DETECT 6
1733 #define ANEG_STATE_ACK_DETECT_INIT 7
1734 #define ANEG_STATE_ACK_DETECT 8
1735 #define ANEG_STATE_COMPLETE_ACK_INIT 9
1736 #define ANEG_STATE_COMPLETE_ACK 10
1737 #define ANEG_STATE_IDLE_DETECT_INIT 11
1738 #define ANEG_STATE_IDLE_DETECT 12
1739 #define ANEG_STATE_LINK_OK 13
1740 #define ANEG_STATE_NEXT_PAGE_WAIT_INIT 14
1741 #define ANEG_STATE_NEXT_PAGE_WAIT 15
1744 #define MR_AN_ENABLE 0x00000001
1745 #define MR_RESTART_AN 0x00000002
1746 #define MR_AN_COMPLETE 0x00000004
1747 #define MR_PAGE_RX 0x00000008
1748 #define MR_NP_LOADED 0x00000010
1749 #define MR_TOGGLE_TX 0x00000020
1750 #define MR_LP_ADV_FULL_DUPLEX 0x00000040
1751 #define MR_LP_ADV_HALF_DUPLEX 0x00000080
1752 #define MR_LP_ADV_SYM_PAUSE 0x00000100
1753 #define MR_LP_ADV_ASYM_PAUSE 0x00000200
1754 #define MR_LP_ADV_REMOTE_FAULT1 0x00000400
1755 #define MR_LP_ADV_REMOTE_FAULT2 0x00000800
1756 #define MR_LP_ADV_NEXT_PAGE 0x00001000
1757 #define MR_TOGGLE_RX 0x00002000
1758 #define MR_NP_RX 0x00004000
1760 #define MR_LINK_OK 0x80000000
1762 unsigned long link_time, cur_time;
1764 u32 ability_match_cfg;
1765 int ability_match_count;
1767 char ability_match, idle_match, ack_match;
1769 u32 txconfig, rxconfig;
1770 #define ANEG_CFG_NP 0x00000080
1771 #define ANEG_CFG_ACK 0x00000040
1772 #define ANEG_CFG_RF2 0x00000020
1773 #define ANEG_CFG_RF1 0x00000010
1774 #define ANEG_CFG_PS2 0x00000001
1775 #define ANEG_CFG_PS1 0x00008000
1776 #define ANEG_CFG_HD 0x00004000
1777 #define ANEG_CFG_FD 0x00002000
1778 #define ANEG_CFG_INVAL 0x00001f06
1783 #define ANEG_TIMER_ENAB 2
1784 #define ANEG_FAILED -1
1786 #define ANEG_STATE_SETTLE_TIME 10000
1788 static int tg3_fiber_aneg_smachine(struct tg3 *tp,
1789 struct tg3_fiber_aneginfo *ap)
1791 unsigned long delta;
1795 if (ap->state == ANEG_STATE_UNKNOWN) {
1799 ap->ability_match_cfg = 0;
1800 ap->ability_match_count = 0;
1801 ap->ability_match = 0;
1807 if (tr32(MAC_STATUS) & MAC_STATUS_RCVD_CFG) {
1808 rx_cfg_reg = tr32(MAC_RX_AUTO_NEG);
1810 if (rx_cfg_reg != ap->ability_match_cfg) {
1811 ap->ability_match_cfg = rx_cfg_reg;
1812 ap->ability_match = 0;
1813 ap->ability_match_count = 0;
1815 if (++ap->ability_match_count > 1) {
1816 ap->ability_match = 1;
1817 ap->ability_match_cfg = rx_cfg_reg;
1820 if (rx_cfg_reg & ANEG_CFG_ACK)
1828 ap->ability_match_cfg = 0;
1829 ap->ability_match_count = 0;
1830 ap->ability_match = 0;
1836 ap->rxconfig = rx_cfg_reg;
1840 case ANEG_STATE_UNKNOWN:
1841 if (ap->flags & (MR_AN_ENABLE | MR_RESTART_AN))
1842 ap->state = ANEG_STATE_AN_ENABLE;
1845 case ANEG_STATE_AN_ENABLE:
1846 ap->flags &= ~(MR_AN_COMPLETE | MR_PAGE_RX);
1847 if (ap->flags & MR_AN_ENABLE) {
1850 ap->ability_match_cfg = 0;
1851 ap->ability_match_count = 0;
1852 ap->ability_match = 0;
1856 ap->state = ANEG_STATE_RESTART_INIT;
1858 ap->state = ANEG_STATE_DISABLE_LINK_OK;
1862 case ANEG_STATE_RESTART_INIT:
1863 ap->link_time = ap->cur_time;
1864 ap->flags &= ~(MR_NP_LOADED);
1866 tw32(MAC_TX_AUTO_NEG, 0);
1867 tp->mac_mode |= MAC_MODE_SEND_CONFIGS;
1868 tw32_f(MAC_MODE, tp->mac_mode);
1871 ret = ANEG_TIMER_ENAB;
1872 ap->state = ANEG_STATE_RESTART;
1875 case ANEG_STATE_RESTART:
1876 delta = ap->cur_time - ap->link_time;
1877 if (delta > ANEG_STATE_SETTLE_TIME) {
1878 ap->state = ANEG_STATE_ABILITY_DETECT_INIT;
1880 ret = ANEG_TIMER_ENAB;
1884 case ANEG_STATE_DISABLE_LINK_OK:
1888 case ANEG_STATE_ABILITY_DETECT_INIT:
1889 ap->flags &= ~(MR_TOGGLE_TX);
1890 ap->txconfig = (ANEG_CFG_FD | ANEG_CFG_PS1);
1891 tw32(MAC_TX_AUTO_NEG, ap->txconfig);
1892 tp->mac_mode |= MAC_MODE_SEND_CONFIGS;
1893 tw32_f(MAC_MODE, tp->mac_mode);
1896 ap->state = ANEG_STATE_ABILITY_DETECT;
1899 case ANEG_STATE_ABILITY_DETECT:
1900 if (ap->ability_match != 0 && ap->rxconfig != 0) {
1901 ap->state = ANEG_STATE_ACK_DETECT_INIT;
1905 case ANEG_STATE_ACK_DETECT_INIT:
1906 ap->txconfig |= ANEG_CFG_ACK;
1907 tw32(MAC_TX_AUTO_NEG, ap->txconfig);
1908 tp->mac_mode |= MAC_MODE_SEND_CONFIGS;
1909 tw32_f(MAC_MODE, tp->mac_mode);
1912 ap->state = ANEG_STATE_ACK_DETECT;
1915 case ANEG_STATE_ACK_DETECT:
1916 if (ap->ack_match != 0) {
1917 if ((ap->rxconfig & ~ANEG_CFG_ACK) ==
1918 (ap->ability_match_cfg & ~ANEG_CFG_ACK)) {
1919 ap->state = ANEG_STATE_COMPLETE_ACK_INIT;
1921 ap->state = ANEG_STATE_AN_ENABLE;
1923 } else if (ap->ability_match != 0 &&
1924 ap->rxconfig == 0) {
1925 ap->state = ANEG_STATE_AN_ENABLE;
1929 case ANEG_STATE_COMPLETE_ACK_INIT:
1930 if (ap->rxconfig & ANEG_CFG_INVAL) {
1934 ap->flags &= ~(MR_LP_ADV_FULL_DUPLEX |
1935 MR_LP_ADV_HALF_DUPLEX |
1936 MR_LP_ADV_SYM_PAUSE |
1937 MR_LP_ADV_ASYM_PAUSE |
1938 MR_LP_ADV_REMOTE_FAULT1 |
1939 MR_LP_ADV_REMOTE_FAULT2 |
1940 MR_LP_ADV_NEXT_PAGE |
1943 if (ap->rxconfig & ANEG_CFG_FD)
1944 ap->flags |= MR_LP_ADV_FULL_DUPLEX;
1945 if (ap->rxconfig & ANEG_CFG_HD)
1946 ap->flags |= MR_LP_ADV_HALF_DUPLEX;
1947 if (ap->rxconfig & ANEG_CFG_PS1)
1948 ap->flags |= MR_LP_ADV_SYM_PAUSE;
1949 if (ap->rxconfig & ANEG_CFG_PS2)
1950 ap->flags |= MR_LP_ADV_ASYM_PAUSE;
1951 if (ap->rxconfig & ANEG_CFG_RF1)
1952 ap->flags |= MR_LP_ADV_REMOTE_FAULT1;
1953 if (ap->rxconfig & ANEG_CFG_RF2)
1954 ap->flags |= MR_LP_ADV_REMOTE_FAULT2;
1955 if (ap->rxconfig & ANEG_CFG_NP)
1956 ap->flags |= MR_LP_ADV_NEXT_PAGE;
1958 ap->link_time = ap->cur_time;
1960 ap->flags ^= (MR_TOGGLE_TX);
1961 if (ap->rxconfig & 0x0008)
1962 ap->flags |= MR_TOGGLE_RX;
1963 if (ap->rxconfig & ANEG_CFG_NP)
1964 ap->flags |= MR_NP_RX;
1965 ap->flags |= MR_PAGE_RX;
1967 ap->state = ANEG_STATE_COMPLETE_ACK;
1968 ret = ANEG_TIMER_ENAB;
1971 case ANEG_STATE_COMPLETE_ACK:
1972 if (ap->ability_match != 0 &&
1973 ap->rxconfig == 0) {
1974 ap->state = ANEG_STATE_AN_ENABLE;
1977 delta = ap->cur_time - ap->link_time;
1978 if (delta > ANEG_STATE_SETTLE_TIME) {
1979 if (!(ap->flags & (MR_LP_ADV_NEXT_PAGE))) {
1980 ap->state = ANEG_STATE_IDLE_DETECT_INIT;
1982 if ((ap->txconfig & ANEG_CFG_NP) == 0 &&
1983 !(ap->flags & MR_NP_RX)) {
1984 ap->state = ANEG_STATE_IDLE_DETECT_INIT;
1992 case ANEG_STATE_IDLE_DETECT_INIT:
1993 ap->link_time = ap->cur_time;
1994 tp->mac_mode &= ~MAC_MODE_SEND_CONFIGS;
1995 tw32_f(MAC_MODE, tp->mac_mode);
1998 ap->state = ANEG_STATE_IDLE_DETECT;
1999 ret = ANEG_TIMER_ENAB;
2002 case ANEG_STATE_IDLE_DETECT:
2003 if (ap->ability_match != 0 &&
2004 ap->rxconfig == 0) {
2005 ap->state = ANEG_STATE_AN_ENABLE;
2008 delta = ap->cur_time - ap->link_time;
2009 if (delta > ANEG_STATE_SETTLE_TIME) {
2010 /* XXX another gem from the Broadcom driver :( */
2011 ap->state = ANEG_STATE_LINK_OK;
2015 case ANEG_STATE_LINK_OK:
2016 ap->flags |= (MR_AN_COMPLETE | MR_LINK_OK);
2020 case ANEG_STATE_NEXT_PAGE_WAIT_INIT:
2021 /* ??? unimplemented */
2024 case ANEG_STATE_NEXT_PAGE_WAIT:
2025 /* ??? unimplemented */
2036 static int fiber_autoneg(struct tg3 *tp, u32 *flags)
2039 struct tg3_fiber_aneginfo aninfo;
2040 int status = ANEG_FAILED;
2044 tw32_f(MAC_TX_AUTO_NEG, 0);
2046 tmp = tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK;
2047 tw32_f(MAC_MODE, tmp | MAC_MODE_PORT_MODE_GMII);
2050 tw32_f(MAC_MODE, tp->mac_mode | MAC_MODE_SEND_CONFIGS);
2053 memset(&aninfo, 0, sizeof(aninfo));
2054 aninfo.flags |= MR_AN_ENABLE;
2055 aninfo.state = ANEG_STATE_UNKNOWN;
2056 aninfo.cur_time = 0;
2058 while (++tick < 195000) {
2059 status = tg3_fiber_aneg_smachine(tp, &aninfo);
2060 if (status == ANEG_DONE || status == ANEG_FAILED)
2066 tp->mac_mode &= ~MAC_MODE_SEND_CONFIGS;
2067 tw32_f(MAC_MODE, tp->mac_mode);
2070 *flags = aninfo.flags;
2072 if (status == ANEG_DONE &&
2073 (aninfo.flags & (MR_AN_COMPLETE | MR_LINK_OK |
2074 MR_LP_ADV_FULL_DUPLEX)))
2080 static void tg3_init_bcm8002(struct tg3 *tp)
2082 u32 mac_status = tr32(MAC_STATUS);
2085 /* Reset when initting first time or we have a link. */
2086 if ((tp->tg3_flags & TG3_FLAG_INIT_COMPLETE) &&
2087 !(mac_status & MAC_STATUS_PCS_SYNCED))
2090 /* Set PLL lock range. */
2091 tg3_writephy(tp, 0x16, 0x8007);
2094 tg3_writephy(tp, MII_BMCR, BMCR_RESET);
2096 /* Wait for reset to complete. */
2097 /* XXX schedule_timeout() ... */
2098 for (i = 0; i < 500; i++)
2101 /* Config mode; select PMA/Ch 1 regs. */
2102 tg3_writephy(tp, 0x10, 0x8411);
2104 /* Enable auto-lock and comdet, select txclk for tx. */
2105 tg3_writephy(tp, 0x11, 0x0a10);
2107 tg3_writephy(tp, 0x18, 0x00a0);
2108 tg3_writephy(tp, 0x16, 0x41ff);
2110 /* Assert and deassert POR. */
2111 tg3_writephy(tp, 0x13, 0x0400);
2113 tg3_writephy(tp, 0x13, 0x0000);
2115 tg3_writephy(tp, 0x11, 0x0a50);
2117 tg3_writephy(tp, 0x11, 0x0a10);
2119 /* Wait for signal to stabilize */
2120 /* XXX schedule_timeout() ... */
2121 for (i = 0; i < 15000; i++)
2124 /* Deselect the channel register so we can read the PHYID
2127 tg3_writephy(tp, 0x10, 0x8011);
2130 static int tg3_setup_fiber_hw_autoneg(struct tg3 *tp, u32 mac_status)
2132 u32 sg_dig_ctrl, sg_dig_status;
2133 u32 serdes_cfg, expected_sg_dig_ctrl;
2134 int workaround, port_a;
2135 int current_link_up;
2138 expected_sg_dig_ctrl = 0;
2141 current_link_up = 0;
2143 if (tp->pci_chip_rev_id != CHIPREV_ID_5704_A0 &&
2144 tp->pci_chip_rev_id != CHIPREV_ID_5704_A1) {
2146 if (tr32(TG3PCI_DUAL_MAC_CTRL) & DUAL_MAC_CTRL_ID)
2149 serdes_cfg = tr32(MAC_SERDES_CFG) &
2150 ((1 << 23) | (1 << 22) | (1 << 21) | (1 << 20));
2153 sg_dig_ctrl = tr32(SG_DIG_CTRL);
2155 if (tp->link_config.autoneg != AUTONEG_ENABLE) {
2156 if (sg_dig_ctrl & (1 << 31)) {
2158 u32 val = serdes_cfg;
2164 tw32_f(MAC_SERDES_CFG, val);
2166 tw32_f(SG_DIG_CTRL, 0x01388400);
2168 if (mac_status & MAC_STATUS_PCS_SYNCED) {
2169 tg3_setup_flow_control(tp, 0, 0);
2170 current_link_up = 1;
2175 /* Want auto-negotiation. */
2176 expected_sg_dig_ctrl = 0x81388400;
2178 /* Pause capability */
2179 expected_sg_dig_ctrl |= (1 << 11);
2181 /* Asymettric pause */
2182 expected_sg_dig_ctrl |= (1 << 12);
2184 if (sg_dig_ctrl != expected_sg_dig_ctrl) {
2186 tw32_f(MAC_SERDES_CFG, serdes_cfg | 0xc011880);
2187 tw32_f(SG_DIG_CTRL, expected_sg_dig_ctrl | (1 << 30));
2189 tw32_f(SG_DIG_CTRL, expected_sg_dig_ctrl);
2191 tp->tg3_flags2 |= TG3_FLG2_PHY_JUST_INITTED;
2192 } else if (mac_status & (MAC_STATUS_PCS_SYNCED |
2193 MAC_STATUS_SIGNAL_DET)) {
2196 /* Giver time to negotiate (~200ms) */
2197 for (i = 0; i < 40000; i++) {
2198 sg_dig_status = tr32(SG_DIG_STATUS);
2199 if (sg_dig_status & (0x3))
2203 mac_status = tr32(MAC_STATUS);
2205 if ((sg_dig_status & (1 << 1)) &&
2206 (mac_status & MAC_STATUS_PCS_SYNCED)) {
2207 u32 local_adv, remote_adv;
2209 local_adv = ADVERTISE_PAUSE_CAP;
2211 if (sg_dig_status & (1 << 19))
2212 remote_adv |= LPA_PAUSE_CAP;
2213 if (sg_dig_status & (1 << 20))
2214 remote_adv |= LPA_PAUSE_ASYM;
2216 tg3_setup_flow_control(tp, local_adv, remote_adv);
2217 current_link_up = 1;
2218 tp->tg3_flags2 &= ~TG3_FLG2_PHY_JUST_INITTED;
2219 } else if (!(sg_dig_status & (1 << 1))) {
2220 if (tp->tg3_flags2 & TG3_FLG2_PHY_JUST_INITTED)
2221 tp->tg3_flags2 &= ~TG3_FLG2_PHY_JUST_INITTED;
2224 u32 val = serdes_cfg;
2231 tw32_f(MAC_SERDES_CFG, val);
2234 tw32_f(SG_DIG_CTRL, 0x01388400);
2237 mac_status = tr32(MAC_STATUS);
2238 if (mac_status & MAC_STATUS_PCS_SYNCED) {
2239 tg3_setup_flow_control(tp, 0, 0);
2240 current_link_up = 1;
2247 return current_link_up;
2250 static int tg3_setup_fiber_by_hand(struct tg3 *tp, u32 mac_status)
2252 int current_link_up = 0;
2254 if (!(mac_status & MAC_STATUS_PCS_SYNCED)) {
2255 tp->tg3_flags &= ~TG3_FLAG_GOT_SERDES_FLOWCTL;
2259 if (tp->link_config.autoneg == AUTONEG_ENABLE) {
2263 if (fiber_autoneg(tp, &flags)) {
2264 u32 local_adv, remote_adv;
2266 local_adv = ADVERTISE_PAUSE_CAP;
2268 if (flags & MR_LP_ADV_SYM_PAUSE)
2269 remote_adv |= LPA_PAUSE_CAP;
2270 if (flags & MR_LP_ADV_ASYM_PAUSE)
2271 remote_adv |= LPA_PAUSE_ASYM;
2273 tg3_setup_flow_control(tp, local_adv, remote_adv);
2275 tp->tg3_flags |= TG3_FLAG_GOT_SERDES_FLOWCTL;
2276 current_link_up = 1;
2278 for (i = 0; i < 30; i++) {
2281 (MAC_STATUS_SYNC_CHANGED |
2282 MAC_STATUS_CFG_CHANGED));
2284 if ((tr32(MAC_STATUS) &
2285 (MAC_STATUS_SYNC_CHANGED |
2286 MAC_STATUS_CFG_CHANGED)) == 0)
2290 mac_status = tr32(MAC_STATUS);
2291 if (current_link_up == 0 &&
2292 (mac_status & MAC_STATUS_PCS_SYNCED) &&
2293 !(mac_status & MAC_STATUS_RCVD_CFG))
2294 current_link_up = 1;
2296 /* Forcing 1000FD link up. */
2297 current_link_up = 1;
2298 tp->tg3_flags |= TG3_FLAG_GOT_SERDES_FLOWCTL;
2300 tw32_f(MAC_MODE, (tp->mac_mode | MAC_MODE_SEND_CONFIGS));
2305 return current_link_up;
2308 static int tg3_setup_fiber_phy(struct tg3 *tp, int force_reset)
2311 u16 orig_active_speed;
2312 u8 orig_active_duplex;
2314 int current_link_up;
2318 (tp->tg3_flags & (TG3_FLAG_RX_PAUSE |
2319 TG3_FLAG_TX_PAUSE));
2320 orig_active_speed = tp->link_config.active_speed;
2321 orig_active_duplex = tp->link_config.active_duplex;
2323 if (!(tp->tg3_flags2 & TG3_FLG2_HW_AUTONEG) &&
2324 netif_carrier_ok(tp->dev) &&
2325 (tp->tg3_flags & TG3_FLAG_INIT_COMPLETE)) {
2326 mac_status = tr32(MAC_STATUS);
2327 mac_status &= (MAC_STATUS_PCS_SYNCED |
2328 MAC_STATUS_SIGNAL_DET |
2329 MAC_STATUS_CFG_CHANGED |
2330 MAC_STATUS_RCVD_CFG);
2331 if (mac_status == (MAC_STATUS_PCS_SYNCED |
2332 MAC_STATUS_SIGNAL_DET)) {
2333 tw32_f(MAC_STATUS, (MAC_STATUS_SYNC_CHANGED |
2334 MAC_STATUS_CFG_CHANGED));
2339 tw32_f(MAC_TX_AUTO_NEG, 0);
2341 tp->mac_mode &= ~(MAC_MODE_PORT_MODE_MASK | MAC_MODE_HALF_DUPLEX);
2342 tp->mac_mode |= MAC_MODE_PORT_MODE_TBI;
2343 tw32_f(MAC_MODE, tp->mac_mode);
2346 if (tp->phy_id == PHY_ID_BCM8002)
2347 tg3_init_bcm8002(tp);
2349 /* Enable link change event even when serdes polling. */
2350 tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED);
2353 current_link_up = 0;
2354 mac_status = tr32(MAC_STATUS);
2356 if (tp->tg3_flags2 & TG3_FLG2_HW_AUTONEG)
2357 current_link_up = tg3_setup_fiber_hw_autoneg(tp, mac_status);
2359 current_link_up = tg3_setup_fiber_by_hand(tp, mac_status);
2361 tp->mac_mode &= ~MAC_MODE_LINK_POLARITY;
2362 tw32_f(MAC_MODE, tp->mac_mode);
2365 tp->hw_status->status =
2366 (SD_STATUS_UPDATED |
2367 (tp->hw_status->status & ~SD_STATUS_LINK_CHG));
2369 for (i = 0; i < 100; i++) {
2370 tw32_f(MAC_STATUS, (MAC_STATUS_SYNC_CHANGED |
2371 MAC_STATUS_CFG_CHANGED));
2373 if ((tr32(MAC_STATUS) & (MAC_STATUS_SYNC_CHANGED |
2374 MAC_STATUS_CFG_CHANGED)) == 0)
2378 mac_status = tr32(MAC_STATUS);
2379 if ((mac_status & MAC_STATUS_PCS_SYNCED) == 0) {
2380 current_link_up = 0;
2381 if (tp->link_config.autoneg == AUTONEG_ENABLE) {
2382 tw32_f(MAC_MODE, (tp->mac_mode |
2383 MAC_MODE_SEND_CONFIGS));
2385 tw32_f(MAC_MODE, tp->mac_mode);
2389 if (current_link_up == 1) {
2390 tp->link_config.active_speed = SPEED_1000;
2391 tp->link_config.active_duplex = DUPLEX_FULL;
2392 tw32(MAC_LED_CTRL, (tp->led_ctrl |
2393 LED_CTRL_LNKLED_OVERRIDE |
2394 LED_CTRL_1000MBPS_ON));
2396 tp->link_config.active_speed = SPEED_INVALID;
2397 tp->link_config.active_duplex = DUPLEX_INVALID;
2398 tw32(MAC_LED_CTRL, (tp->led_ctrl |
2399 LED_CTRL_LNKLED_OVERRIDE |
2400 LED_CTRL_TRAFFIC_OVERRIDE));
2403 if (current_link_up != netif_carrier_ok(tp->dev)) {
2404 if (current_link_up)
2405 netif_carrier_on(tp->dev);
2407 netif_carrier_off(tp->dev);
2408 tg3_link_report(tp);
2411 tp->tg3_flags & (TG3_FLAG_RX_PAUSE |
2413 if (orig_pause_cfg != now_pause_cfg ||
2414 orig_active_speed != tp->link_config.active_speed ||
2415 orig_active_duplex != tp->link_config.active_duplex)
2416 tg3_link_report(tp);
2422 static int tg3_setup_phy(struct tg3 *tp, int force_reset)
2426 if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) {
2427 err = tg3_setup_fiber_phy(tp, force_reset);
2429 err = tg3_setup_copper_phy(tp, force_reset);
2432 if (tp->link_config.active_speed == SPEED_1000 &&
2433 tp->link_config.active_duplex == DUPLEX_HALF)
2434 tw32(MAC_TX_LENGTHS,
2435 ((2 << TX_LENGTHS_IPG_CRS_SHIFT) |
2436 (6 << TX_LENGTHS_IPG_SHIFT) |
2437 (0xff << TX_LENGTHS_SLOT_TIME_SHIFT)));
2439 tw32(MAC_TX_LENGTHS,
2440 ((2 << TX_LENGTHS_IPG_CRS_SHIFT) |
2441 (6 << TX_LENGTHS_IPG_SHIFT) |
2442 (32 << TX_LENGTHS_SLOT_TIME_SHIFT)));
2444 if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5705 &&
2445 GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5750) {
2446 if (netif_carrier_ok(tp->dev)) {
2447 tw32(HOSTCC_STAT_COAL_TICKS,
2448 DEFAULT_STAT_COAL_TICKS);
2450 tw32(HOSTCC_STAT_COAL_TICKS, 0);
2457 /* Tigon3 never reports partial packet sends. So we do not
2458 * need special logic to handle SKBs that have not had all
2459 * of their frags sent yet, like SunGEM does.
2461 static void tg3_tx(struct tg3 *tp)
2463 u32 hw_idx = tp->hw_status->idx[0].tx_consumer;
2464 u32 sw_idx = tp->tx_cons;
2466 while (sw_idx != hw_idx) {
2467 struct tx_ring_info *ri = &tp->tx_buffers[sw_idx];
2468 struct sk_buff *skb = ri->skb;
2471 if (unlikely(skb == NULL))
2474 pci_unmap_single(tp->pdev,
2475 pci_unmap_addr(ri, mapping),
2481 sw_idx = NEXT_TX(sw_idx);
2483 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
2484 if (unlikely(sw_idx == hw_idx))
2487 ri = &tp->tx_buffers[sw_idx];
2488 if (unlikely(ri->skb != NULL))
2491 pci_unmap_page(tp->pdev,
2492 pci_unmap_addr(ri, mapping),
2493 skb_shinfo(skb)->frags[i].size,
2496 sw_idx = NEXT_TX(sw_idx);
2499 dev_kfree_skb_irq(skb);
2502 tp->tx_cons = sw_idx;
2504 if (netif_queue_stopped(tp->dev) &&
2505 (TX_BUFFS_AVAIL(tp) > TG3_TX_WAKEUP_THRESH))
2506 netif_wake_queue(tp->dev);
2509 /* Returns size of skb allocated or < 0 on error.
2511 * We only need to fill in the address because the other members
2512 * of the RX descriptor are invariant, see tg3_init_rings.
2514 * Note the purposeful assymetry of cpu vs. chip accesses. For
2515 * posting buffers we only dirty the first cache line of the RX
2516 * descriptor (containing the address). Whereas for the RX status
2517 * buffers the cpu only reads the last cacheline of the RX descriptor
2518 * (to fetch the error flags, vlan tag, checksum, and opaque cookie).
2520 static int tg3_alloc_rx_skb(struct tg3 *tp, u32 opaque_key,
2521 int src_idx, u32 dest_idx_unmasked)
2523 struct tg3_rx_buffer_desc *desc;
2524 struct ring_info *map, *src_map;
2525 struct sk_buff *skb;
2527 int skb_size, dest_idx;
2530 switch (opaque_key) {
2531 case RXD_OPAQUE_RING_STD:
2532 dest_idx = dest_idx_unmasked % TG3_RX_RING_SIZE;
2533 desc = &tp->rx_std[dest_idx];
2534 map = &tp->rx_std_buffers[dest_idx];
2536 src_map = &tp->rx_std_buffers[src_idx];
2537 skb_size = RX_PKT_BUF_SZ;
2540 case RXD_OPAQUE_RING_JUMBO:
2541 dest_idx = dest_idx_unmasked % TG3_RX_JUMBO_RING_SIZE;
2542 desc = &tp->rx_jumbo[dest_idx];
2543 map = &tp->rx_jumbo_buffers[dest_idx];
2545 src_map = &tp->rx_jumbo_buffers[src_idx];
2546 skb_size = RX_JUMBO_PKT_BUF_SZ;
2553 /* Do not overwrite any of the map or rp information
2554 * until we are sure we can commit to a new buffer.
2556 * Callers depend upon this behavior and assume that
2557 * we leave everything unchanged if we fail.
2559 skb = dev_alloc_skb(skb_size);
2564 skb_reserve(skb, tp->rx_offset);
2566 mapping = pci_map_single(tp->pdev, skb->data,
2567 skb_size - tp->rx_offset,
2568 PCI_DMA_FROMDEVICE);
2571 pci_unmap_addr_set(map, mapping, mapping);
2573 if (src_map != NULL)
2574 src_map->skb = NULL;
2576 desc->addr_hi = ((u64)mapping >> 32);
2577 desc->addr_lo = ((u64)mapping & 0xffffffff);
2582 /* We only need to move over in the address because the other
2583 * members of the RX descriptor are invariant. See notes above
2584 * tg3_alloc_rx_skb for full details.
2586 static void tg3_recycle_rx(struct tg3 *tp, u32 opaque_key,
2587 int src_idx, u32 dest_idx_unmasked)
2589 struct tg3_rx_buffer_desc *src_desc, *dest_desc;
2590 struct ring_info *src_map, *dest_map;
2593 switch (opaque_key) {
2594 case RXD_OPAQUE_RING_STD:
2595 dest_idx = dest_idx_unmasked % TG3_RX_RING_SIZE;
2596 dest_desc = &tp->rx_std[dest_idx];
2597 dest_map = &tp->rx_std_buffers[dest_idx];
2598 src_desc = &tp->rx_std[src_idx];
2599 src_map = &tp->rx_std_buffers[src_idx];
2602 case RXD_OPAQUE_RING_JUMBO:
2603 dest_idx = dest_idx_unmasked % TG3_RX_JUMBO_RING_SIZE;
2604 dest_desc = &tp->rx_jumbo[dest_idx];
2605 dest_map = &tp->rx_jumbo_buffers[dest_idx];
2606 src_desc = &tp->rx_jumbo[src_idx];
2607 src_map = &tp->rx_jumbo_buffers[src_idx];
2614 dest_map->skb = src_map->skb;
2615 pci_unmap_addr_set(dest_map, mapping,
2616 pci_unmap_addr(src_map, mapping));
2617 dest_desc->addr_hi = src_desc->addr_hi;
2618 dest_desc->addr_lo = src_desc->addr_lo;
2620 src_map->skb = NULL;
2623 #if TG3_VLAN_TAG_USED
2624 static int tg3_vlan_rx(struct tg3 *tp, struct sk_buff *skb, u16 vlan_tag)
2626 return vlan_hwaccel_receive_skb(skb, tp->vlgrp, vlan_tag);
2630 /* The RX ring scheme is composed of multiple rings which post fresh
2631 * buffers to the chip, and one special ring the chip uses to report
2632 * status back to the host.
2634 * The special ring reports the status of received packets to the
2635 * host. The chip does not write into the original descriptor the
2636 * RX buffer was obtained from. The chip simply takes the original
2637 * descriptor as provided by the host, updates the status and length
2638 * field, then writes this into the next status ring entry.
2640 * Each ring the host uses to post buffers to the chip is described
2641 * by a TG3_BDINFO entry in the chips SRAM area. When a packet arrives,
2642 * it is first placed into the on-chip ram. When the packet's length
2643 * is known, it walks down the TG3_BDINFO entries to select the ring.
2644 * Each TG3_BDINFO specifies a MAXLEN field and the first TG3_BDINFO
2645 * which is within the range of the new packet's length is chosen.
2647 * The "separate ring for rx status" scheme may sound queer, but it makes
2648 * sense from a cache coherency perspective. If only the host writes
2649 * to the buffer post rings, and only the chip writes to the rx status
2650 * rings, then cache lines never move beyond shared-modified state.
2651 * If both the host and chip were to write into the same ring, cache line
2652 * eviction could occur since both entities want it in an exclusive state.
2654 static int tg3_rx(struct tg3 *tp, int budget)
2657 u32 rx_rcb_ptr = tp->rx_rcb_ptr;
2661 hw_idx = tp->hw_status->idx[0].rx_producer;
2663 * We need to order the read of hw_idx and the read of
2664 * the opaque cookie.
2667 sw_idx = rx_rcb_ptr % TG3_RX_RCB_RING_SIZE(tp);
2670 while (sw_idx != hw_idx && budget > 0) {
2671 struct tg3_rx_buffer_desc *desc = &tp->rx_rcb[sw_idx];
2673 struct sk_buff *skb;
2674 dma_addr_t dma_addr;
2675 u32 opaque_key, desc_idx, *post_ptr;
2677 desc_idx = desc->opaque & RXD_OPAQUE_INDEX_MASK;
2678 opaque_key = desc->opaque & RXD_OPAQUE_RING_MASK;
2679 if (opaque_key == RXD_OPAQUE_RING_STD) {
2680 dma_addr = pci_unmap_addr(&tp->rx_std_buffers[desc_idx],
2682 skb = tp->rx_std_buffers[desc_idx].skb;
2683 post_ptr = &tp->rx_std_ptr;
2684 } else if (opaque_key == RXD_OPAQUE_RING_JUMBO) {
2685 dma_addr = pci_unmap_addr(&tp->rx_jumbo_buffers[desc_idx],
2687 skb = tp->rx_jumbo_buffers[desc_idx].skb;
2688 post_ptr = &tp->rx_jumbo_ptr;
2691 goto next_pkt_nopost;
2694 work_mask |= opaque_key;
2696 if ((desc->err_vlan & RXD_ERR_MASK) != 0 &&
2697 (desc->err_vlan != RXD_ERR_ODD_NIBBLE_RCVD_MII)) {
2699 tg3_recycle_rx(tp, opaque_key,
2700 desc_idx, *post_ptr);
2702 /* Other statistics kept track of by card. */
2703 tp->net_stats.rx_dropped++;
2707 len = ((desc->idx_len & RXD_LEN_MASK) >> RXD_LEN_SHIFT) - 4; /* omit crc */
2709 if (len > RX_COPY_THRESHOLD) {
2712 skb_size = tg3_alloc_rx_skb(tp, opaque_key,
2713 desc_idx, *post_ptr);
2717 pci_unmap_single(tp->pdev, dma_addr,
2718 skb_size - tp->rx_offset,
2719 PCI_DMA_FROMDEVICE);
2723 struct sk_buff *copy_skb;
2725 tg3_recycle_rx(tp, opaque_key,
2726 desc_idx, *post_ptr);
2728 copy_skb = dev_alloc_skb(len + 2);
2729 if (copy_skb == NULL)
2730 goto drop_it_no_recycle;
2732 copy_skb->dev = tp->dev;
2733 skb_reserve(copy_skb, 2);
2734 skb_put(copy_skb, len);
2735 pci_dma_sync_single_for_cpu(tp->pdev, dma_addr, len, PCI_DMA_FROMDEVICE);
2736 memcpy(copy_skb->data, skb->data, len);
2737 pci_dma_sync_single_for_device(tp->pdev, dma_addr, len, PCI_DMA_FROMDEVICE);
2739 /* We'll reuse the original ring buffer. */
2743 if ((tp->tg3_flags & TG3_FLAG_RX_CHECKSUMS) &&
2744 (desc->type_flags & RXD_FLAG_TCPUDP_CSUM) &&
2745 (((desc->ip_tcp_csum & RXD_TCPCSUM_MASK)
2746 >> RXD_TCPCSUM_SHIFT) == 0xffff))
2747 skb->ip_summed = CHECKSUM_UNNECESSARY;
2749 skb->ip_summed = CHECKSUM_NONE;
2751 skb->protocol = eth_type_trans(skb, tp->dev);
2752 #if TG3_VLAN_TAG_USED
2753 if (tp->vlgrp != NULL &&
2754 desc->type_flags & RXD_FLAG_VLAN) {
2755 tg3_vlan_rx(tp, skb,
2756 desc->err_vlan & RXD_VLAN_MASK);
2759 netif_receive_skb(skb);
2761 tp->dev->last_rx = jiffies;
2769 sw_idx = rx_rcb_ptr % TG3_RX_RCB_RING_SIZE(tp);
2772 /* ACK the status ring. */
2773 tp->rx_rcb_ptr = rx_rcb_ptr;
2774 tw32_rx_mbox(MAILBOX_RCVRET_CON_IDX_0 + TG3_64BIT_REG_LOW,
2775 (rx_rcb_ptr % TG3_RX_RCB_RING_SIZE(tp)));
2777 /* Refill RX ring(s). */
2778 if (work_mask & RXD_OPAQUE_RING_STD) {
2779 sw_idx = tp->rx_std_ptr % TG3_RX_RING_SIZE;
2780 tw32_rx_mbox(MAILBOX_RCV_STD_PROD_IDX + TG3_64BIT_REG_LOW,
2783 if (work_mask & RXD_OPAQUE_RING_JUMBO) {
2784 sw_idx = tp->rx_jumbo_ptr % TG3_RX_JUMBO_RING_SIZE;
2785 tw32_rx_mbox(MAILBOX_RCV_JUMBO_PROD_IDX + TG3_64BIT_REG_LOW,
2793 static int tg3_poll(struct net_device *netdev, int *budget)
2795 struct tg3 *tp = netdev_priv(netdev);
2796 struct tg3_hw_status *sblk = tp->hw_status;
2797 unsigned long flags;
2800 spin_lock_irqsave(&tp->lock, flags);
2802 /* handle link change and other phy events */
2803 if (!(tp->tg3_flags &
2804 (TG3_FLAG_USE_LINKCHG_REG |
2805 TG3_FLAG_POLL_SERDES))) {
2806 if (sblk->status & SD_STATUS_LINK_CHG) {
2807 sblk->status = SD_STATUS_UPDATED |
2808 (sblk->status & ~SD_STATUS_LINK_CHG);
2809 tg3_setup_phy(tp, 0);
2813 /* run TX completion thread */
2814 if (sblk->idx[0].tx_consumer != tp->tx_cons) {
2815 spin_lock(&tp->tx_lock);
2817 spin_unlock(&tp->tx_lock);
2820 spin_unlock_irqrestore(&tp->lock, flags);
2822 /* run RX thread, within the bounds set by NAPI.
2823 * All RX "locking" is done by ensuring outside
2824 * code synchronizes with dev->poll()
2827 if (sblk->idx[0].rx_producer != tp->rx_rcb_ptr) {
2828 int orig_budget = *budget;
2831 if (orig_budget > netdev->quota)
2832 orig_budget = netdev->quota;
2834 work_done = tg3_rx(tp, orig_budget);
2836 *budget -= work_done;
2837 netdev->quota -= work_done;
2839 if (work_done >= orig_budget)
2843 /* if no more work, tell net stack and NIC we're done */
2845 spin_lock_irqsave(&tp->lock, flags);
2846 __netif_rx_complete(netdev);
2847 tg3_restart_ints(tp);
2848 spin_unlock_irqrestore(&tp->lock, flags);
2851 return (done ? 0 : 1);
2854 static inline unsigned int tg3_has_work(struct net_device *dev, struct tg3 *tp)
2856 struct tg3_hw_status *sblk = tp->hw_status;
2857 unsigned int work_exists = 0;
2859 /* check for phy events */
2860 if (!(tp->tg3_flags &
2861 (TG3_FLAG_USE_LINKCHG_REG |
2862 TG3_FLAG_POLL_SERDES))) {
2863 if (sblk->status & SD_STATUS_LINK_CHG)
2866 /* check for RX/TX work to do */
2867 if (sblk->idx[0].tx_consumer != tp->tx_cons ||
2868 sblk->idx[0].rx_producer != tp->rx_rcb_ptr)
2874 static irqreturn_t tg3_interrupt(int irq, void *dev_id, struct pt_regs *regs)
2876 struct net_device *dev = dev_id;
2877 struct tg3 *tp = netdev_priv(dev);
2878 struct tg3_hw_status *sblk = tp->hw_status;
2879 unsigned long flags;
2880 unsigned int handled = 1;
2882 spin_lock_irqsave(&tp->lock, flags);
2884 if (sblk->status & SD_STATUS_UPDATED) {
2886 * writing any value to intr-mbox-0 clears PCI INTA# and
2887 * chip-internal interrupt pending events.
2888 * writing non-zero to intr-mbox-0 additional tells the
2889 * NIC to stop sending us irqs, engaging "in-intr-handler"
2892 tw32_mailbox(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW,
2895 * Flush PCI write. This also guarantees that our
2896 * status block has been flushed to host memory.
2898 tr32(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW);
2899 sblk->status &= ~SD_STATUS_UPDATED;
2901 if (likely(tg3_has_work(dev, tp)))
2902 netif_rx_schedule(dev); /* schedule NAPI poll */
2904 /* no work, shared interrupt perhaps? re-enable
2905 * interrupts, and flush that PCI write
2907 tw32_mailbox(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW,
2909 tr32(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW);
2911 } else { /* shared interrupt */
2915 spin_unlock_irqrestore(&tp->lock, flags);
2917 return IRQ_RETVAL(handled);
2920 static int tg3_init_hw(struct tg3 *);
2921 static int tg3_halt(struct tg3 *);
2923 #ifdef CONFIG_NET_POLL_CONTROLLER
2924 static void tg3_poll_controller(struct net_device *dev)
2926 tg3_interrupt(dev->irq, dev, NULL);
2930 static void tg3_reset_task(void *_data)
2932 struct tg3 *tp = _data;
2933 unsigned int restart_timer;
2937 spin_lock_irq(&tp->lock);
2938 spin_lock(&tp->tx_lock);
2940 restart_timer = tp->tg3_flags2 & TG3_FLG2_RESTART_TIMER;
2941 tp->tg3_flags2 &= ~TG3_FLG2_RESTART_TIMER;
2946 tg3_netif_start(tp);
2948 spin_unlock(&tp->tx_lock);
2949 spin_unlock_irq(&tp->lock);
2952 mod_timer(&tp->timer, jiffies + 1);
2955 static void tg3_tx_timeout(struct net_device *dev)
2957 struct tg3 *tp = netdev_priv(dev);
2959 printk(KERN_ERR PFX "%s: transmit timed out, resetting\n",
2962 schedule_work(&tp->reset_task);
2965 static void tg3_set_txd(struct tg3 *, int, dma_addr_t, int, u32, u32);
2967 static int tigon3_4gb_hwbug_workaround(struct tg3 *tp, struct sk_buff *skb,
2968 u32 guilty_entry, int guilty_len,
2969 u32 last_plus_one, u32 *start, u32 mss)
2971 struct sk_buff *new_skb = skb_copy(skb, GFP_ATOMIC);
2972 dma_addr_t new_addr;
2981 /* New SKB is guaranteed to be linear. */
2983 new_addr = pci_map_single(tp->pdev, new_skb->data, new_skb->len,
2985 tg3_set_txd(tp, entry, new_addr, new_skb->len,
2986 (skb->ip_summed == CHECKSUM_HW) ?
2987 TXD_FLAG_TCPUDP_CSUM : 0, 1 | (mss << 1));
2988 *start = NEXT_TX(entry);
2990 /* Now clean up the sw ring entries. */
2992 while (entry != last_plus_one) {
2996 len = skb_headlen(skb);
2998 len = skb_shinfo(skb)->frags[i-1].size;
2999 pci_unmap_single(tp->pdev,
3000 pci_unmap_addr(&tp->tx_buffers[entry], mapping),
3001 len, PCI_DMA_TODEVICE);
3003 tp->tx_buffers[entry].skb = new_skb;
3004 pci_unmap_addr_set(&tp->tx_buffers[entry], mapping, new_addr);
3006 tp->tx_buffers[entry].skb = NULL;
3008 entry = NEXT_TX(entry);
3016 static void tg3_set_txd(struct tg3 *tp, int entry,
3017 dma_addr_t mapping, int len, u32 flags,
3020 struct tg3_tx_buffer_desc *txd = &tp->tx_ring[entry];
3021 int is_end = (mss_and_is_end & 0x1);
3022 u32 mss = (mss_and_is_end >> 1);
3026 flags |= TXD_FLAG_END;
3027 if (flags & TXD_FLAG_VLAN) {
3028 vlan_tag = flags >> 16;
3031 vlan_tag |= (mss << TXD_MSS_SHIFT);
3033 txd->addr_hi = ((u64) mapping >> 32);
3034 txd->addr_lo = ((u64) mapping & 0xffffffff);
3035 txd->len_flags = (len << TXD_LEN_SHIFT) | flags;
3036 txd->vlan_tag = vlan_tag << TXD_VLAN_TAG_SHIFT;
3039 static inline int tg3_4g_overflow_test(dma_addr_t mapping, int len)
3041 u32 base = (u32) mapping & 0xffffffff;
3043 return ((base > 0xffffdcc0) &&
3044 (base + len + 8 < base));
3047 static int tg3_start_xmit(struct sk_buff *skb, struct net_device *dev)
3049 struct tg3 *tp = netdev_priv(dev);
3052 u32 len, entry, base_flags, mss;
3053 int would_hit_hwbug;
3054 unsigned long flags;
3056 len = skb_headlen(skb);
3058 /* No BH disabling for tx_lock here. We are running in BH disabled
3059 * context and TX reclaim runs via tp->poll inside of a software
3060 * interrupt. Rejoice!
3062 * Actually, things are not so simple. If we are to take a hw
3063 * IRQ here, we can deadlock, consider:
3072 * spin on tp->tx_lock
3074 * So we really do need to disable interrupts when taking
3077 local_irq_save(flags);
3078 if (!spin_trylock(&tp->tx_lock)) {
3079 local_irq_restore(flags);
3080 return NETDEV_TX_LOCKED;
3083 /* This is a hard error, log it. */
3084 if (unlikely(TX_BUFFS_AVAIL(tp) <= (skb_shinfo(skb)->nr_frags + 1))) {
3085 netif_stop_queue(dev);
3086 spin_unlock_irqrestore(&tp->tx_lock, flags);
3087 printk(KERN_ERR PFX "%s: BUG! Tx Ring full when queue awake!\n",
3089 return NETDEV_TX_BUSY;
3092 entry = tp->tx_prod;
3094 if (skb->ip_summed == CHECKSUM_HW)
3095 base_flags |= TXD_FLAG_TCPUDP_CSUM;
3096 #if TG3_TSO_SUPPORT != 0
3098 if (skb->len > (tp->dev->mtu + ETH_HLEN) &&
3099 (mss = skb_shinfo(skb)->tso_size) != 0) {
3100 int tcp_opt_len, ip_tcp_len;
3102 tcp_opt_len = ((skb->h.th->doff - 5) * 4);
3103 ip_tcp_len = (skb->nh.iph->ihl * 4) + sizeof(struct tcphdr);
3105 base_flags |= (TXD_FLAG_CPU_PRE_DMA |
3106 TXD_FLAG_CPU_POST_DMA);
3108 skb->nh.iph->check = 0;
3109 skb->nh.iph->tot_len = ntohs(mss + ip_tcp_len + tcp_opt_len);
3110 skb->h.th->check = ~csum_tcpudp_magic(skb->nh.iph->saddr,
3114 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) {
3115 if (tcp_opt_len || skb->nh.iph->ihl > 5) {
3118 tsflags = ((skb->nh.iph->ihl - 5) +
3119 (tcp_opt_len >> 2));
3120 mss |= (tsflags << 11);
3123 if (tcp_opt_len || skb->nh.iph->ihl > 5) {
3126 tsflags = ((skb->nh.iph->ihl - 5) +
3127 (tcp_opt_len >> 2));
3128 base_flags |= tsflags << 12;
3135 #if TG3_VLAN_TAG_USED
3136 if (tp->vlgrp != NULL && vlan_tx_tag_present(skb))
3137 base_flags |= (TXD_FLAG_VLAN |
3138 (vlan_tx_tag_get(skb) << 16));
3141 /* Queue skb data, a.k.a. the main skb fragment. */
3142 mapping = pci_map_single(tp->pdev, skb->data, len, PCI_DMA_TODEVICE);
3144 tp->tx_buffers[entry].skb = skb;
3145 pci_unmap_addr_set(&tp->tx_buffers[entry], mapping, mapping);
3147 would_hit_hwbug = 0;
3149 if (tg3_4g_overflow_test(mapping, len))
3150 would_hit_hwbug = entry + 1;
3152 tg3_set_txd(tp, entry, mapping, len, base_flags,
3153 (skb_shinfo(skb)->nr_frags == 0) | (mss << 1));
3155 entry = NEXT_TX(entry);
3157 /* Now loop through additional data fragments, and queue them. */
3158 if (skb_shinfo(skb)->nr_frags > 0) {
3159 unsigned int i, last;
3161 last = skb_shinfo(skb)->nr_frags - 1;
3162 for (i = 0; i <= last; i++) {
3163 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
3166 mapping = pci_map_page(tp->pdev,
3169 len, PCI_DMA_TODEVICE);
3171 tp->tx_buffers[entry].skb = NULL;
3172 pci_unmap_addr_set(&tp->tx_buffers[entry], mapping, mapping);
3174 if (tg3_4g_overflow_test(mapping, len)) {
3175 /* Only one should match. */
3176 if (would_hit_hwbug)
3178 would_hit_hwbug = entry + 1;
3181 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750)
3182 tg3_set_txd(tp, entry, mapping, len,
3183 base_flags, (i == last)|(mss << 1));
3185 tg3_set_txd(tp, entry, mapping, len,
3186 base_flags, (i == last));
3188 entry = NEXT_TX(entry);
3192 if (would_hit_hwbug) {
3193 u32 last_plus_one = entry;
3195 unsigned int len = 0;
3197 would_hit_hwbug -= 1;
3198 entry = entry - 1 - skb_shinfo(skb)->nr_frags;
3199 entry &= (TG3_TX_RING_SIZE - 1);
3202 while (entry != last_plus_one) {
3204 len = skb_headlen(skb);
3206 len = skb_shinfo(skb)->frags[i-1].size;
3208 if (entry == would_hit_hwbug)
3212 entry = NEXT_TX(entry);
3216 /* If the workaround fails due to memory/mapping
3217 * failure, silently drop this packet.
3219 if (tigon3_4gb_hwbug_workaround(tp, skb,
3228 /* Packets are ready, update Tx producer idx local and on card. */
3229 tw32_tx_mbox((MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW), entry);
3231 tp->tx_prod = entry;
3232 if (TX_BUFFS_AVAIL(tp) <= (MAX_SKB_FRAGS + 1))
3233 netif_stop_queue(dev);
3237 spin_unlock_irqrestore(&tp->tx_lock, flags);
3239 dev->trans_start = jiffies;
3241 return NETDEV_TX_OK;
3244 static inline void tg3_set_mtu(struct net_device *dev, struct tg3 *tp,
3249 if (new_mtu > ETH_DATA_LEN)
3250 tp->tg3_flags |= TG3_FLAG_JUMBO_ENABLE;
3252 tp->tg3_flags &= ~TG3_FLAG_JUMBO_ENABLE;
3255 static int tg3_change_mtu(struct net_device *dev, int new_mtu)
3257 struct tg3 *tp = netdev_priv(dev);
3259 if (new_mtu < TG3_MIN_MTU || new_mtu > TG3_MAX_MTU(tp))
3262 if (!netif_running(dev)) {
3263 /* We'll just catch it later when the
3266 tg3_set_mtu(dev, tp, new_mtu);
3271 spin_lock_irq(&tp->lock);
3272 spin_lock(&tp->tx_lock);
3276 tg3_set_mtu(dev, tp, new_mtu);
3280 tg3_netif_start(tp);
3282 spin_unlock(&tp->tx_lock);
3283 spin_unlock_irq(&tp->lock);
3288 /* Free up pending packets in all rx/tx rings.
3290 * The chip has been shut down and the driver detached from
3291 * the networking, so no interrupts or new tx packets will
3292 * end up in the driver. tp->{tx,}lock is not held and we are not
3293 * in an interrupt context and thus may sleep.
3295 static void tg3_free_rings(struct tg3 *tp)
3297 struct ring_info *rxp;
3300 for (i = 0; i < TG3_RX_RING_SIZE; i++) {
3301 rxp = &tp->rx_std_buffers[i];
3303 if (rxp->skb == NULL)
3305 pci_unmap_single(tp->pdev,
3306 pci_unmap_addr(rxp, mapping),
3307 RX_PKT_BUF_SZ - tp->rx_offset,
3308 PCI_DMA_FROMDEVICE);
3309 dev_kfree_skb_any(rxp->skb);
3313 for (i = 0; i < TG3_RX_JUMBO_RING_SIZE; i++) {
3314 rxp = &tp->rx_jumbo_buffers[i];
3316 if (rxp->skb == NULL)
3318 pci_unmap_single(tp->pdev,
3319 pci_unmap_addr(rxp, mapping),
3320 RX_JUMBO_PKT_BUF_SZ - tp->rx_offset,
3321 PCI_DMA_FROMDEVICE);
3322 dev_kfree_skb_any(rxp->skb);
3326 for (i = 0; i < TG3_TX_RING_SIZE; ) {
3327 struct tx_ring_info *txp;
3328 struct sk_buff *skb;
3331 txp = &tp->tx_buffers[i];
3339 pci_unmap_single(tp->pdev,
3340 pci_unmap_addr(txp, mapping),
3347 for (j = 0; j < skb_shinfo(skb)->nr_frags; j++) {
3348 txp = &tp->tx_buffers[i & (TG3_TX_RING_SIZE - 1)];
3349 pci_unmap_page(tp->pdev,
3350 pci_unmap_addr(txp, mapping),
3351 skb_shinfo(skb)->frags[j].size,
3356 dev_kfree_skb_any(skb);
3360 /* Initialize tx/rx rings for packet processing.
3362 * The chip has been shut down and the driver detached from
3363 * the networking, so no interrupts or new tx packets will
3364 * end up in the driver. tp->{tx,}lock are held and thus
3367 static void tg3_init_rings(struct tg3 *tp)
3371 /* Free up all the SKBs. */
3374 /* Zero out all descriptors. */
3375 memset(tp->rx_std, 0, TG3_RX_RING_BYTES);
3376 memset(tp->rx_jumbo, 0, TG3_RX_JUMBO_RING_BYTES);
3377 memset(tp->rx_rcb, 0, TG3_RX_RCB_RING_BYTES(tp));
3378 memset(tp->tx_ring, 0, TG3_TX_RING_BYTES);
3380 /* Initialize invariants of the rings, we only set this
3381 * stuff once. This works because the card does not
3382 * write into the rx buffer posting rings.
3384 for (i = 0; i < TG3_RX_RING_SIZE; i++) {
3385 struct tg3_rx_buffer_desc *rxd;
3387 rxd = &tp->rx_std[i];
3388 rxd->idx_len = (RX_PKT_BUF_SZ - tp->rx_offset - 64)
3390 rxd->type_flags = (RXD_FLAG_END << RXD_FLAGS_SHIFT);
3391 rxd->opaque = (RXD_OPAQUE_RING_STD |
3392 (i << RXD_OPAQUE_INDEX_SHIFT));
3395 if (tp->tg3_flags & TG3_FLAG_JUMBO_ENABLE) {
3396 for (i = 0; i < TG3_RX_JUMBO_RING_SIZE; i++) {
3397 struct tg3_rx_buffer_desc *rxd;
3399 rxd = &tp->rx_jumbo[i];
3400 rxd->idx_len = (RX_JUMBO_PKT_BUF_SZ - tp->rx_offset - 64)
3402 rxd->type_flags = (RXD_FLAG_END << RXD_FLAGS_SHIFT) |
3404 rxd->opaque = (RXD_OPAQUE_RING_JUMBO |
3405 (i << RXD_OPAQUE_INDEX_SHIFT));
3409 /* Now allocate fresh SKBs for each rx ring. */
3410 for (i = 0; i < tp->rx_pending; i++) {
3411 if (tg3_alloc_rx_skb(tp, RXD_OPAQUE_RING_STD,
3416 if (tp->tg3_flags & TG3_FLAG_JUMBO_ENABLE) {
3417 for (i = 0; i < tp->rx_jumbo_pending; i++) {
3418 if (tg3_alloc_rx_skb(tp, RXD_OPAQUE_RING_JUMBO,
3426 * Must not be invoked with interrupt sources disabled and
3427 * the hardware shutdown down.
3429 static void tg3_free_consistent(struct tg3 *tp)
3431 if (tp->rx_std_buffers) {
3432 kfree(tp->rx_std_buffers);
3433 tp->rx_std_buffers = NULL;
3436 pci_free_consistent(tp->pdev, TG3_RX_RING_BYTES,
3437 tp->rx_std, tp->rx_std_mapping);
3441 pci_free_consistent(tp->pdev, TG3_RX_JUMBO_RING_BYTES,
3442 tp->rx_jumbo, tp->rx_jumbo_mapping);
3443 tp->rx_jumbo = NULL;
3446 pci_free_consistent(tp->pdev, TG3_RX_RCB_RING_BYTES(tp),
3447 tp->rx_rcb, tp->rx_rcb_mapping);
3451 pci_free_consistent(tp->pdev, TG3_TX_RING_BYTES,
3452 tp->tx_ring, tp->tx_desc_mapping);
3455 if (tp->hw_status) {
3456 pci_free_consistent(tp->pdev, TG3_HW_STATUS_SIZE,
3457 tp->hw_status, tp->status_mapping);
3458 tp->hw_status = NULL;
3461 pci_free_consistent(tp->pdev, sizeof(struct tg3_hw_stats),
3462 tp->hw_stats, tp->stats_mapping);
3463 tp->hw_stats = NULL;
3468 * Must not be invoked with interrupt sources disabled and
3469 * the hardware shutdown down. Can sleep.
3471 static int tg3_alloc_consistent(struct tg3 *tp)
3473 tp->rx_std_buffers = kmalloc((sizeof(struct ring_info) *
3475 TG3_RX_JUMBO_RING_SIZE)) +
3476 (sizeof(struct tx_ring_info) *
3479 if (!tp->rx_std_buffers)
3482 memset(tp->rx_std_buffers, 0,
3483 (sizeof(struct ring_info) *
3485 TG3_RX_JUMBO_RING_SIZE)) +
3486 (sizeof(struct tx_ring_info) *
3489 tp->rx_jumbo_buffers = &tp->rx_std_buffers[TG3_RX_RING_SIZE];
3490 tp->tx_buffers = (struct tx_ring_info *)
3491 &tp->rx_jumbo_buffers[TG3_RX_JUMBO_RING_SIZE];
3493 tp->rx_std = pci_alloc_consistent(tp->pdev, TG3_RX_RING_BYTES,
3494 &tp->rx_std_mapping);
3498 tp->rx_jumbo = pci_alloc_consistent(tp->pdev, TG3_RX_JUMBO_RING_BYTES,
3499 &tp->rx_jumbo_mapping);
3504 tp->rx_rcb = pci_alloc_consistent(tp->pdev, TG3_RX_RCB_RING_BYTES(tp),
3505 &tp->rx_rcb_mapping);
3509 tp->tx_ring = pci_alloc_consistent(tp->pdev, TG3_TX_RING_BYTES,
3510 &tp->tx_desc_mapping);
3514 tp->hw_status = pci_alloc_consistent(tp->pdev,
3516 &tp->status_mapping);
3520 tp->hw_stats = pci_alloc_consistent(tp->pdev,
3521 sizeof(struct tg3_hw_stats),
3522 &tp->stats_mapping);
3526 memset(tp->hw_status, 0, TG3_HW_STATUS_SIZE);
3527 memset(tp->hw_stats, 0, sizeof(struct tg3_hw_stats));
3532 tg3_free_consistent(tp);
3536 #define MAX_WAIT_CNT 1000
3538 /* To stop a block, clear the enable bit and poll till it
3539 * clears. tp->lock is held.
3541 static int tg3_stop_block(struct tg3 *tp, unsigned long ofs, u32 enable_bit)
3546 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 ||
3547 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750) {
3554 /* We can't enable/disable these bits of the
3555 * 5705/5750, just say success.
3568 for (i = 0; i < MAX_WAIT_CNT; i++) {
3571 if ((val & enable_bit) == 0)
3575 if (i == MAX_WAIT_CNT) {
3576 printk(KERN_ERR PFX "tg3_stop_block timed out, "
3577 "ofs=%lx enable_bit=%x\n",
3585 /* tp->lock is held. */
3586 static int tg3_abort_hw(struct tg3 *tp)
3590 tg3_disable_ints(tp);
3592 tp->rx_mode &= ~RX_MODE_ENABLE;
3593 tw32_f(MAC_RX_MODE, tp->rx_mode);
3596 err = tg3_stop_block(tp, RCVBDI_MODE, RCVBDI_MODE_ENABLE);
3597 err |= tg3_stop_block(tp, RCVLPC_MODE, RCVLPC_MODE_ENABLE);
3598 err |= tg3_stop_block(tp, RCVLSC_MODE, RCVLSC_MODE_ENABLE);
3599 err |= tg3_stop_block(tp, RCVDBDI_MODE, RCVDBDI_MODE_ENABLE);
3600 err |= tg3_stop_block(tp, RCVDCC_MODE, RCVDCC_MODE_ENABLE);
3601 err |= tg3_stop_block(tp, RCVCC_MODE, RCVCC_MODE_ENABLE);
3603 err |= tg3_stop_block(tp, SNDBDS_MODE, SNDBDS_MODE_ENABLE);
3604 err |= tg3_stop_block(tp, SNDBDI_MODE, SNDBDI_MODE_ENABLE);
3605 err |= tg3_stop_block(tp, SNDDATAI_MODE, SNDDATAI_MODE_ENABLE);
3606 err |= tg3_stop_block(tp, RDMAC_MODE, RDMAC_MODE_ENABLE);
3607 err |= tg3_stop_block(tp, SNDDATAC_MODE, SNDDATAC_MODE_ENABLE);
3608 err |= tg3_stop_block(tp, DMAC_MODE, DMAC_MODE_ENABLE);
3609 err |= tg3_stop_block(tp, SNDBDC_MODE, SNDBDC_MODE_ENABLE);
3613 tp->mac_mode &= ~MAC_MODE_TDE_ENABLE;
3614 tw32_f(MAC_MODE, tp->mac_mode);
3617 tp->tx_mode &= ~TX_MODE_ENABLE;
3618 tw32_f(MAC_TX_MODE, tp->tx_mode);
3620 for (i = 0; i < MAX_WAIT_CNT; i++) {
3622 if (!(tr32(MAC_TX_MODE) & TX_MODE_ENABLE))
3625 if (i >= MAX_WAIT_CNT) {
3626 printk(KERN_ERR PFX "tg3_abort_hw timed out for %s, "
3627 "TX_MODE_ENABLE will not clear MAC_TX_MODE=%08x\n",
3628 tp->dev->name, tr32(MAC_TX_MODE));
3632 err = tg3_stop_block(tp, HOSTCC_MODE, HOSTCC_MODE_ENABLE);
3633 err |= tg3_stop_block(tp, WDMAC_MODE, WDMAC_MODE_ENABLE);
3634 err |= tg3_stop_block(tp, MBFREE_MODE, MBFREE_MODE_ENABLE);
3636 tw32(FTQ_RESET, 0xffffffff);
3637 tw32(FTQ_RESET, 0x00000000);
3639 err |= tg3_stop_block(tp, BUFMGR_MODE, BUFMGR_MODE_ENABLE);
3640 err |= tg3_stop_block(tp, MEMARB_MODE, MEMARB_MODE_ENABLE);
3645 memset(tp->hw_status, 0, TG3_HW_STATUS_SIZE);
3647 memset(tp->hw_stats, 0, sizeof(struct tg3_hw_stats));
3653 /* tp->lock is held. */
3654 static int tg3_nvram_lock(struct tg3 *tp)
3656 if (tp->tg3_flags & TG3_FLAG_NVRAM) {
3659 tw32(NVRAM_SWARB, SWARB_REQ_SET1);
3660 for (i = 0; i < 8000; i++) {
3661 if (tr32(NVRAM_SWARB) & SWARB_GNT1)
3671 /* tp->lock is held. */
3672 static void tg3_nvram_unlock(struct tg3 *tp)
3674 if (tp->tg3_flags & TG3_FLAG_NVRAM)
3675 tw32_f(NVRAM_SWARB, SWARB_REQ_CLR1);
3678 /* tp->lock is held. */
3679 static void tg3_write_sig_pre_reset(struct tg3 *tp, int kind)
3681 tg3_write_mem(tp, NIC_SRAM_FIRMWARE_MBOX,
3682 NIC_SRAM_FIRMWARE_MBOX_MAGIC1);
3684 if (tp->tg3_flags2 & TG3_FLG2_ASF_NEW_HANDSHAKE) {
3686 case RESET_KIND_INIT:
3687 tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
3691 case RESET_KIND_SHUTDOWN:
3692 tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
3696 case RESET_KIND_SUSPEND:
3697 tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
3707 /* tp->lock is held. */
3708 static void tg3_write_sig_post_reset(struct tg3 *tp, int kind)
3710 if (tp->tg3_flags2 & TG3_FLG2_ASF_NEW_HANDSHAKE) {
3712 case RESET_KIND_INIT:
3713 tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
3714 DRV_STATE_START_DONE);
3717 case RESET_KIND_SHUTDOWN:
3718 tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
3719 DRV_STATE_UNLOAD_DONE);
3728 /* tp->lock is held. */
3729 static void tg3_write_sig_legacy(struct tg3 *tp, int kind)
3731 if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) {
3733 case RESET_KIND_INIT:
3734 tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
3738 case RESET_KIND_SHUTDOWN:
3739 tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
3743 case RESET_KIND_SUSPEND:
3744 tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
3754 static void tg3_stop_fw(struct tg3 *);
3756 /* tp->lock is held. */
3757 static int tg3_chip_reset(struct tg3 *tp)
3763 if (!(tp->tg3_flags2 & TG3_FLG2_SUN_570X))
3767 * We must avoid the readl() that normally takes place.
3768 * It locks machines, causes machine checks, and other
3769 * fun things. So, temporarily disable the 5701
3770 * hardware workaround, while we do the reset.
3772 flags_save = tp->tg3_flags;
3773 tp->tg3_flags &= ~TG3_FLAG_5701_REG_WRITE_BUG;
3776 val = GRC_MISC_CFG_CORECLK_RESET;
3778 if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) {
3779 if (tr32(0x7e2c) == 0x60) {
3782 if (tp->pci_chip_rev_id != CHIPREV_ID_5750_A0) {
3783 tw32(GRC_MISC_CFG, (1 << 29));
3788 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 ||
3789 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750)
3790 val |= GRC_MISC_CFG_KEEP_GPHY_POWER;
3791 tw32(GRC_MISC_CFG, val);
3793 /* restore 5701 hardware bug workaround flag */
3794 tp->tg3_flags = flags_save;
3796 /* Unfortunately, we have to delay before the PCI read back.
3797 * Some 575X chips even will not respond to a PCI cfg access
3798 * when the reset command is given to the chip.
3800 * How do these hardware designers expect things to work
3801 * properly if the PCI write is posted for a long period
3802 * of time? It is always necessary to have some method by
3803 * which a register read back can occur to push the write
3804 * out which does the reset.
3806 * For most tg3 variants the trick below was working.
3811 /* Flush PCI posted writes. The normal MMIO registers
3812 * are inaccessible at this time so this is the only
3813 * way to make this reliably (actually, this is no longer
3814 * the case, see above). I tried to use indirect
3815 * register read/write but this upset some 5701 variants.
3817 pci_read_config_dword(tp->pdev, PCI_COMMAND, &val);
3821 if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) {
3822 if (tp->pci_chip_rev_id == CHIPREV_ID_5750_A0) {
3826 /* Wait for link training to complete. */
3827 for (i = 0; i < 5000; i++)
3830 pci_read_config_dword(tp->pdev, 0xc4, &cfg_val);
3831 pci_write_config_dword(tp->pdev, 0xc4,
3832 cfg_val | (1 << 15));
3834 /* Set PCIE max payload size and clear error status. */
3835 pci_write_config_dword(tp->pdev, 0xd8, 0xf5000);
3838 /* Re-enable indirect register accesses. */
3839 pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL,
3840 tp->misc_host_ctrl);
3842 /* Set MAX PCI retry to zero. */
3843 val = (PCISTATE_ROM_ENABLE | PCISTATE_ROM_RETRY_ENABLE);
3844 if (tp->pci_chip_rev_id == CHIPREV_ID_5704_A0 &&
3845 (tp->tg3_flags & TG3_FLAG_PCIX_MODE))
3846 val |= PCISTATE_RETRY_SAME_DMA;
3847 pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE, val);
3849 pci_restore_state(tp->pdev);
3851 /* Make sure PCI-X relaxed ordering bit is clear. */
3852 pci_read_config_dword(tp->pdev, TG3PCI_X_CAPS, &val);
3853 val &= ~PCIX_CAPS_RELAXED_ORDERING;
3854 pci_write_config_dword(tp->pdev, TG3PCI_X_CAPS, val);
3856 tw32(MEMARB_MODE, MEMARB_MODE_ENABLE);
3858 if (tp->pci_chip_rev_id == CHIPREV_ID_5750_A3) {
3860 tw32(0x5000, 0x400);
3863 tw32(GRC_MODE, tp->grc_mode);
3865 if (tp->pci_chip_rev_id == CHIPREV_ID_5705_A0) {
3866 u32 val = tr32(0xc4);
3868 tw32(0xc4, val | (1 << 15));
3871 if ((tp->nic_sram_data_cfg & NIC_SRAM_DATA_CFG_MINI_PCI) != 0 &&
3872 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) {
3873 tp->pci_clock_ctrl |= CLOCK_CTRL_CLKRUN_OENABLE;
3874 if (tp->pci_chip_rev_id == CHIPREV_ID_5705_A0)
3875 tp->pci_clock_ctrl |= CLOCK_CTRL_FORCE_CLKRUN;
3876 tw32(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl);
3879 if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) {
3880 tp->mac_mode = MAC_MODE_PORT_MODE_TBI;
3881 tw32_f(MAC_MODE, tp->mac_mode);
3883 tw32_f(MAC_MODE, 0);
3886 /* Wait for firmware initialization to complete. */
3887 for (i = 0; i < 100000; i++) {
3888 tg3_read_mem(tp, NIC_SRAM_FIRMWARE_MBOX, &val);
3889 if (val == ~NIC_SRAM_FIRMWARE_MBOX_MAGIC1)
3894 !(tp->tg3_flags2 & TG3_FLG2_SUN_570X)) {
3895 printk(KERN_ERR PFX "tg3_reset_hw timed out for %s, "
3896 "firmware will not restart magic=%08x\n",
3897 tp->dev->name, val);
3901 if ((tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) &&
3902 tp->pci_chip_rev_id != CHIPREV_ID_5750_A0) {
3903 u32 val = tr32(0x7c00);
3905 tw32(0x7c00, val | (1 << 25));
3908 /* Reprobe ASF enable state. */
3909 tp->tg3_flags &= ~TG3_FLAG_ENABLE_ASF;
3910 tp->tg3_flags2 &= ~TG3_FLG2_ASF_NEW_HANDSHAKE;
3911 tg3_read_mem(tp, NIC_SRAM_DATA_SIG, &val);
3912 if (val == NIC_SRAM_DATA_SIG_MAGIC) {
3915 tg3_read_mem(tp, NIC_SRAM_DATA_CFG, &nic_cfg);
3916 if (nic_cfg & NIC_SRAM_DATA_CFG_ASF_ENABLE) {
3917 tp->tg3_flags |= TG3_FLAG_ENABLE_ASF;
3918 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750)
3919 tp->tg3_flags2 |= TG3_FLG2_ASF_NEW_HANDSHAKE;
3926 /* tp->lock is held. */
3927 static void tg3_stop_fw(struct tg3 *tp)
3929 if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) {
3933 tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX, FWCMD_NICDRV_PAUSE_FW);
3934 val = tr32(GRC_RX_CPU_EVENT);
3936 tw32(GRC_RX_CPU_EVENT, val);
3938 /* Wait for RX cpu to ACK the event. */
3939 for (i = 0; i < 100; i++) {
3940 if (!(tr32(GRC_RX_CPU_EVENT) & (1 << 14)))
3947 /* tp->lock is held. */
3948 static int tg3_halt(struct tg3 *tp)
3954 tg3_write_sig_pre_reset(tp, RESET_KIND_SHUTDOWN);
3957 err = tg3_chip_reset(tp);
3959 tg3_write_sig_legacy(tp, RESET_KIND_SHUTDOWN);
3960 tg3_write_sig_post_reset(tp, RESET_KIND_SHUTDOWN);
3968 #define TG3_FW_RELEASE_MAJOR 0x0
3969 #define TG3_FW_RELASE_MINOR 0x0
3970 #define TG3_FW_RELEASE_FIX 0x0
3971 #define TG3_FW_START_ADDR 0x08000000
3972 #define TG3_FW_TEXT_ADDR 0x08000000
3973 #define TG3_FW_TEXT_LEN 0x9c0
3974 #define TG3_FW_RODATA_ADDR 0x080009c0
3975 #define TG3_FW_RODATA_LEN 0x60
3976 #define TG3_FW_DATA_ADDR 0x08000a40
3977 #define TG3_FW_DATA_LEN 0x20
3978 #define TG3_FW_SBSS_ADDR 0x08000a60
3979 #define TG3_FW_SBSS_LEN 0xc
3980 #define TG3_FW_BSS_ADDR 0x08000a70
3981 #define TG3_FW_BSS_LEN 0x10
3983 static u32 tg3FwText[(TG3_FW_TEXT_LEN / sizeof(u32)) + 1] = {
3984 0x00000000, 0x10000003, 0x00000000, 0x0000000d, 0x0000000d, 0x3c1d0800,
3985 0x37bd3ffc, 0x03a0f021, 0x3c100800, 0x26100000, 0x0e000018, 0x00000000,
3986 0x0000000d, 0x3c1d0800, 0x37bd3ffc, 0x03a0f021, 0x3c100800, 0x26100034,
3987 0x0e00021c, 0x00000000, 0x0000000d, 0x00000000, 0x00000000, 0x00000000,
3988 0x27bdffe0, 0x3c1cc000, 0xafbf0018, 0xaf80680c, 0x0e00004c, 0x241b2105,
3989 0x97850000, 0x97870002, 0x9782002c, 0x9783002e, 0x3c040800, 0x248409c0,
3990 0xafa00014, 0x00021400, 0x00621825, 0x00052c00, 0xafa30010, 0x8f860010,
3991 0x00e52825, 0x0e000060, 0x24070102, 0x3c02ac00, 0x34420100, 0x3c03ac01,
3992 0x34630100, 0xaf820490, 0x3c02ffff, 0xaf820494, 0xaf830498, 0xaf82049c,
3993 0x24020001, 0xaf825ce0, 0x0e00003f, 0xaf825d00, 0x0e000140, 0x00000000,
3994 0x8fbf0018, 0x03e00008, 0x27bd0020, 0x2402ffff, 0xaf825404, 0x8f835400,
3995 0x34630400, 0xaf835400, 0xaf825404, 0x3c020800, 0x24420034, 0xaf82541c,
3996 0x03e00008, 0xaf805400, 0x00000000, 0x00000000, 0x3c020800, 0x34423000,
3997 0x3c030800, 0x34633000, 0x3c040800, 0x348437ff, 0x3c010800, 0xac220a64,
3998 0x24020040, 0x3c010800, 0xac220a68, 0x3c010800, 0xac200a60, 0xac600000,
3999 0x24630004, 0x0083102b, 0x5040fffd, 0xac600000, 0x03e00008, 0x00000000,
4000 0x00804821, 0x8faa0010, 0x3c020800, 0x8c420a60, 0x3c040800, 0x8c840a68,
4001 0x8fab0014, 0x24430001, 0x0044102b, 0x3c010800, 0xac230a60, 0x14400003,
4002 0x00004021, 0x3c010800, 0xac200a60, 0x3c020800, 0x8c420a60, 0x3c030800,
4003 0x8c630a64, 0x91240000, 0x00021140, 0x00431021, 0x00481021, 0x25080001,
4004 0xa0440000, 0x29020008, 0x1440fff4, 0x25290001, 0x3c020800, 0x8c420a60,
4005 0x3c030800, 0x8c630a64, 0x8f84680c, 0x00021140, 0x00431021, 0xac440008,
4006 0xac45000c, 0xac460010, 0xac470014, 0xac4a0018, 0x03e00008, 0xac4b001c,
4007 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4008 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4010 0x02000008, 0x00000000, 0x0a0001e3, 0x3c0a0001, 0x0a0001e3, 0x3c0a0002,
4011 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000,
4012 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000,
4013 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000,
4014 0x0a0001e3, 0x3c0a0007, 0x0a0001e3, 0x3c0a0008, 0x0a0001e3, 0x3c0a0009,
4015 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x3c0a000b,
4016 0x0a0001e3, 0x3c0a000c, 0x0a0001e3, 0x3c0a000d, 0x0a0001e3, 0x00000000,
4017 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x3c0a000e, 0x0a0001e3, 0x00000000,
4018 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000,
4019 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000,
4020 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x3c0a0013, 0x0a0001e3, 0x3c0a0014,
4021 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4022 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4023 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4024 0x27bdffe0, 0x00001821, 0x00001021, 0xafbf0018, 0xafb10014, 0xafb00010,
4025 0x3c010800, 0x00220821, 0xac200a70, 0x3c010800, 0x00220821, 0xac200a74,
4026 0x3c010800, 0x00220821, 0xac200a78, 0x24630001, 0x1860fff5, 0x2442000c,
4027 0x24110001, 0x8f906810, 0x32020004, 0x14400005, 0x24040001, 0x3c020800,
4028 0x8c420a78, 0x18400003, 0x00002021, 0x0e000182, 0x00000000, 0x32020001,
4029 0x10400003, 0x00000000, 0x0e000169, 0x00000000, 0x0a000153, 0xaf915028,
4030 0x8fbf0018, 0x8fb10014, 0x8fb00010, 0x03e00008, 0x27bd0020, 0x3c050800,
4031 0x8ca50a70, 0x3c060800, 0x8cc60a80, 0x3c070800, 0x8ce70a78, 0x27bdffe0,
4032 0x3c040800, 0x248409d0, 0xafbf0018, 0xafa00010, 0x0e000060, 0xafa00014,
4033 0x0e00017b, 0x00002021, 0x8fbf0018, 0x03e00008, 0x27bd0020, 0x24020001,
4034 0x8f836810, 0x00821004, 0x00021027, 0x00621824, 0x03e00008, 0xaf836810,
4035 0x27bdffd8, 0xafbf0024, 0x1080002e, 0xafb00020, 0x8f825cec, 0xafa20018,
4036 0x8f825cec, 0x3c100800, 0x26100a78, 0xafa2001c, 0x34028000, 0xaf825cec,
4037 0x8e020000, 0x18400016, 0x00000000, 0x3c020800, 0x94420a74, 0x8fa3001c,
4038 0x000221c0, 0xac830004, 0x8fa2001c, 0x3c010800, 0x0e000201, 0xac220a74,
4039 0x10400005, 0x00000000, 0x8e020000, 0x24420001, 0x0a0001df, 0xae020000,
4040 0x3c020800, 0x8c420a70, 0x00021c02, 0x000321c0, 0x0a0001c5, 0xafa2001c,
4041 0x0e000201, 0x00000000, 0x1040001f, 0x00000000, 0x8e020000, 0x8fa3001c,
4042 0x24420001, 0x3c010800, 0xac230a70, 0x3c010800, 0xac230a74, 0x0a0001df,
4043 0xae020000, 0x3c100800, 0x26100a78, 0x8e020000, 0x18400028, 0x00000000,
4044 0x0e000201, 0x00000000, 0x14400024, 0x00000000, 0x8e020000, 0x3c030800,
4045 0x8c630a70, 0x2442ffff, 0xafa3001c, 0x18400006, 0xae020000, 0x00031402,
4046 0x000221c0, 0x8c820004, 0x3c010800, 0xac220a70, 0x97a2001e, 0x2442ff00,
4047 0x2c420300, 0x1440000b, 0x24024000, 0x3c040800, 0x248409dc, 0xafa00010,
4048 0xafa00014, 0x8fa6001c, 0x24050008, 0x0e000060, 0x00003821, 0x0a0001df,
4049 0x00000000, 0xaf825cf8, 0x3c020800, 0x8c420a40, 0x8fa3001c, 0x24420001,
4050 0xaf835cf8, 0x3c010800, 0xac220a40, 0x8fbf0024, 0x8fb00020, 0x03e00008,
4051 0x27bd0028, 0x27bdffe0, 0x3c040800, 0x248409e8, 0x00002821, 0x00003021,
4052 0x00003821, 0xafbf0018, 0xafa00010, 0x0e000060, 0xafa00014, 0x8fbf0018,
4053 0x03e00008, 0x27bd0020, 0x8f82680c, 0x8f85680c, 0x00021827, 0x0003182b,
4054 0x00031823, 0x00431024, 0x00441021, 0x00a2282b, 0x10a00006, 0x00000000,
4055 0x00401821, 0x8f82680c, 0x0043102b, 0x1440fffd, 0x00000000, 0x03e00008,
4056 0x00000000, 0x3c040800, 0x8c840000, 0x3c030800, 0x8c630a40, 0x0064102b,
4057 0x54400002, 0x00831023, 0x00641023, 0x2c420008, 0x03e00008, 0x38420001,
4058 0x27bdffe0, 0x00802821, 0x3c040800, 0x24840a00, 0x00003021, 0x00003821,
4059 0xafbf0018, 0xafa00010, 0x0e000060, 0xafa00014, 0x0a000216, 0x00000000,
4060 0x8fbf0018, 0x03e00008, 0x27bd0020, 0x00000000, 0x27bdffe0, 0x3c1cc000,
4061 0xafbf0018, 0x0e00004c, 0xaf80680c, 0x3c040800, 0x24840a10, 0x03802821,
4062 0x00003021, 0x00003821, 0xafa00010, 0x0e000060, 0xafa00014, 0x2402ffff,
4063 0xaf825404, 0x3c0200aa, 0x0e000234, 0xaf825434, 0x8fbf0018, 0x03e00008,
4064 0x27bd0020, 0x00000000, 0x00000000, 0x00000000, 0x27bdffe8, 0xafb00010,
4065 0x24100001, 0xafbf0014, 0x3c01c003, 0xac200000, 0x8f826810, 0x30422000,
4066 0x10400003, 0x00000000, 0x0e000246, 0x00000000, 0x0a00023a, 0xaf905428,
4067 0x8fbf0014, 0x8fb00010, 0x03e00008, 0x27bd0018, 0x27bdfff8, 0x8f845d0c,
4068 0x3c0200ff, 0x3c030800, 0x8c630a50, 0x3442fff8, 0x00821024, 0x1043001e,
4069 0x3c0500ff, 0x34a5fff8, 0x3c06c003, 0x3c074000, 0x00851824, 0x8c620010,
4070 0x3c010800, 0xac230a50, 0x30420008, 0x10400005, 0x00871025, 0x8cc20000,
4071 0x24420001, 0xacc20000, 0x00871025, 0xaf825d0c, 0x8fa20000, 0x24420001,
4072 0xafa20000, 0x8fa20000, 0x8fa20000, 0x24420001, 0xafa20000, 0x8fa20000,
4073 0x8f845d0c, 0x3c030800, 0x8c630a50, 0x00851024, 0x1443ffe8, 0x00851824,
4074 0x27bd0008, 0x03e00008, 0x00000000, 0x00000000, 0x00000000
4077 static u32 tg3FwRodata[(TG3_FW_RODATA_LEN / sizeof(u32)) + 1] = {
4078 0x35373031, 0x726c7341, 0x00000000, 0x00000000, 0x53774576, 0x656e7430,
4079 0x00000000, 0x726c7045, 0x76656e74, 0x31000000, 0x556e6b6e, 0x45766e74,
4080 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x66617461, 0x6c457272,
4081 0x00000000, 0x00000000, 0x4d61696e, 0x43707542, 0x00000000, 0x00000000,
4085 #if 0 /* All zeros, don't eat up space with it. */
4086 u32 tg3FwData[(TG3_FW_DATA_LEN / sizeof(u32)) + 1] = {
4087 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
4088 0x00000000, 0x00000000, 0x00000000, 0x00000000
4092 #define RX_CPU_SCRATCH_BASE 0x30000
4093 #define RX_CPU_SCRATCH_SIZE 0x04000
4094 #define TX_CPU_SCRATCH_BASE 0x34000
4095 #define TX_CPU_SCRATCH_SIZE 0x04000
4097 /* tp->lock is held. */
4098 static int tg3_halt_cpu(struct tg3 *tp, u32 offset)
4102 if (offset == TX_CPU_BASE &&
4103 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705)
4106 if (offset == RX_CPU_BASE) {
4107 for (i = 0; i < 10000; i++) {
4108 tw32(offset + CPU_STATE, 0xffffffff);
4109 tw32(offset + CPU_MODE, CPU_MODE_HALT);
4110 if (tr32(offset + CPU_MODE) & CPU_MODE_HALT)
4114 tw32(offset + CPU_STATE, 0xffffffff);
4115 tw32_f(offset + CPU_MODE, CPU_MODE_HALT);
4118 for (i = 0; i < 10000; i++) {
4119 tw32(offset + CPU_STATE, 0xffffffff);
4120 tw32(offset + CPU_MODE, CPU_MODE_HALT);
4121 if (tr32(offset + CPU_MODE) & CPU_MODE_HALT)
4127 printk(KERN_ERR PFX "tg3_reset_cpu timed out for %s, "
4130 (offset == RX_CPU_BASE ? "RX" : "TX"));
4137 unsigned int text_base;
4138 unsigned int text_len;
4140 unsigned int rodata_base;
4141 unsigned int rodata_len;
4143 unsigned int data_base;
4144 unsigned int data_len;
4148 /* tp->lock is held. */
4149 static int tg3_load_firmware_cpu(struct tg3 *tp, u32 cpu_base, u32 cpu_scratch_base,
4150 int cpu_scratch_size, struct fw_info *info)
4153 u32 orig_tg3_flags = tp->tg3_flags;
4154 void (*write_op)(struct tg3 *, u32, u32);
4156 if (cpu_base == TX_CPU_BASE &&
4157 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) {
4158 printk(KERN_ERR PFX "tg3_load_firmware_cpu: Trying to load "
4159 "TX cpu firmware on %s which is 5705.\n",
4164 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705)
4165 write_op = tg3_write_mem;
4167 write_op = tg3_write_indirect_reg32;
4169 /* Force use of PCI config space for indirect register
4172 tp->tg3_flags |= TG3_FLAG_PCIX_TARGET_HWBUG;
4174 err = tg3_halt_cpu(tp, cpu_base);
4178 for (i = 0; i < cpu_scratch_size; i += sizeof(u32))
4179 write_op(tp, cpu_scratch_base + i, 0);
4180 tw32(cpu_base + CPU_STATE, 0xffffffff);
4181 tw32(cpu_base + CPU_MODE, tr32(cpu_base+CPU_MODE)|CPU_MODE_HALT);
4182 for (i = 0; i < (info->text_len / sizeof(u32)); i++)
4183 write_op(tp, (cpu_scratch_base +
4184 (info->text_base & 0xffff) +
4187 info->text_data[i] : 0));
4188 for (i = 0; i < (info->rodata_len / sizeof(u32)); i++)
4189 write_op(tp, (cpu_scratch_base +
4190 (info->rodata_base & 0xffff) +
4192 (info->rodata_data ?
4193 info->rodata_data[i] : 0));
4194 for (i = 0; i < (info->data_len / sizeof(u32)); i++)
4195 write_op(tp, (cpu_scratch_base +
4196 (info->data_base & 0xffff) +
4199 info->data_data[i] : 0));
4204 tp->tg3_flags = orig_tg3_flags;
4208 /* tp->lock is held. */
4209 static int tg3_load_5701_a0_firmware_fix(struct tg3 *tp)
4211 struct fw_info info;
4214 info.text_base = TG3_FW_TEXT_ADDR;
4215 info.text_len = TG3_FW_TEXT_LEN;
4216 info.text_data = &tg3FwText[0];
4217 info.rodata_base = TG3_FW_RODATA_ADDR;
4218 info.rodata_len = TG3_FW_RODATA_LEN;
4219 info.rodata_data = &tg3FwRodata[0];
4220 info.data_base = TG3_FW_DATA_ADDR;
4221 info.data_len = TG3_FW_DATA_LEN;
4222 info.data_data = NULL;
4224 err = tg3_load_firmware_cpu(tp, RX_CPU_BASE,
4225 RX_CPU_SCRATCH_BASE, RX_CPU_SCRATCH_SIZE,
4230 err = tg3_load_firmware_cpu(tp, TX_CPU_BASE,
4231 TX_CPU_SCRATCH_BASE, TX_CPU_SCRATCH_SIZE,
4236 /* Now startup only the RX cpu. */
4237 tw32(RX_CPU_BASE + CPU_STATE, 0xffffffff);
4238 tw32_f(RX_CPU_BASE + CPU_PC, TG3_FW_TEXT_ADDR);
4240 for (i = 0; i < 5; i++) {
4241 if (tr32(RX_CPU_BASE + CPU_PC) == TG3_FW_TEXT_ADDR)
4243 tw32(RX_CPU_BASE + CPU_STATE, 0xffffffff);
4244 tw32(RX_CPU_BASE + CPU_MODE, CPU_MODE_HALT);
4245 tw32_f(RX_CPU_BASE + CPU_PC, TG3_FW_TEXT_ADDR);
4249 printk(KERN_ERR PFX "tg3_load_firmware fails for %s "
4250 "to set RX CPU PC, is %08x should be %08x\n",
4251 tp->dev->name, tr32(RX_CPU_BASE + CPU_PC),
4255 tw32(RX_CPU_BASE + CPU_STATE, 0xffffffff);
4256 tw32_f(RX_CPU_BASE + CPU_MODE, 0x00000000);
4261 #if TG3_TSO_SUPPORT != 0
4263 #define TG3_TSO_FW_RELEASE_MAJOR 0x1
4264 #define TG3_TSO_FW_RELASE_MINOR 0x6
4265 #define TG3_TSO_FW_RELEASE_FIX 0x0
4266 #define TG3_TSO_FW_START_ADDR 0x08000000
4267 #define TG3_TSO_FW_TEXT_ADDR 0x08000000
4268 #define TG3_TSO_FW_TEXT_LEN 0x1aa0
4269 #define TG3_TSO_FW_RODATA_ADDR 0x08001aa0
4270 #define TG3_TSO_FW_RODATA_LEN 0x60
4271 #define TG3_TSO_FW_DATA_ADDR 0x08001b20
4272 #define TG3_TSO_FW_DATA_LEN 0x30
4273 #define TG3_TSO_FW_SBSS_ADDR 0x08001b50
4274 #define TG3_TSO_FW_SBSS_LEN 0x2c
4275 #define TG3_TSO_FW_BSS_ADDR 0x08001b80
4276 #define TG3_TSO_FW_BSS_LEN 0x894
4278 static u32 tg3TsoFwText[(TG3_TSO_FW_TEXT_LEN / 4) + 1] = {
4279 0x0e000003, 0x00000000, 0x08001b24, 0x00000000, 0x10000003, 0x00000000,
4280 0x0000000d, 0x0000000d, 0x3c1d0800, 0x37bd4000, 0x03a0f021, 0x3c100800,
4281 0x26100000, 0x0e000010, 0x00000000, 0x0000000d, 0x27bdffe0, 0x3c04fefe,
4282 0xafbf0018, 0x0e0005d8, 0x34840002, 0x0e000668, 0x00000000, 0x3c030800,
4283 0x90631b68, 0x24020002, 0x3c040800, 0x24841aac, 0x14620003, 0x24050001,
4284 0x3c040800, 0x24841aa0, 0x24060006, 0x00003821, 0xafa00010, 0x0e00067c,
4285 0xafa00014, 0x8f625c50, 0x34420001, 0xaf625c50, 0x8f625c90, 0x34420001,
4286 0xaf625c90, 0x2402ffff, 0x0e000034, 0xaf625404, 0x8fbf0018, 0x03e00008,
4287 0x27bd0020, 0x00000000, 0x00000000, 0x00000000, 0x27bdffe0, 0xafbf001c,
4288 0xafb20018, 0xafb10014, 0x0e00005b, 0xafb00010, 0x24120002, 0x24110001,
4289 0x8f706820, 0x32020100, 0x10400003, 0x00000000, 0x0e0000bb, 0x00000000,
4290 0x8f706820, 0x32022000, 0x10400004, 0x32020001, 0x0e0001f0, 0x24040001,
4291 0x32020001, 0x10400003, 0x00000000, 0x0e0000a3, 0x00000000, 0x3c020800,
4292 0x90421b98, 0x14520003, 0x00000000, 0x0e0004c0, 0x00000000, 0x0a00003c,
4293 0xaf715028, 0x8fbf001c, 0x8fb20018, 0x8fb10014, 0x8fb00010, 0x03e00008,
4294 0x27bd0020, 0x27bdffe0, 0x3c040800, 0x24841ac0, 0x00002821, 0x00003021,
4295 0x00003821, 0xafbf0018, 0xafa00010, 0x0e00067c, 0xafa00014, 0x3c040800,
4296 0x248423d8, 0xa4800000, 0x3c010800, 0xa0201b98, 0x3c010800, 0xac201b9c,
4297 0x3c010800, 0xac201ba0, 0x3c010800, 0xac201ba4, 0x3c010800, 0xac201bac,
4298 0x3c010800, 0xac201bb8, 0x3c010800, 0xac201bbc, 0x8f624434, 0x3c010800,
4299 0xac221b88, 0x8f624438, 0x3c010800, 0xac221b8c, 0x8f624410, 0xac80f7a8,
4300 0x3c010800, 0xac201b84, 0x3c010800, 0xac2023e0, 0x3c010800, 0xac2023c8,
4301 0x3c010800, 0xac2023cc, 0x3c010800, 0xac202400, 0x3c010800, 0xac221b90,
4302 0x8f620068, 0x24030007, 0x00021702, 0x10430005, 0x00000000, 0x8f620068,
4303 0x00021702, 0x14400004, 0x24020001, 0x3c010800, 0x0a000097, 0xac20240c,
4304 0xac820034, 0x3c040800, 0x24841acc, 0x3c050800, 0x8ca5240c, 0x00003021,
4305 0x00003821, 0xafa00010, 0x0e00067c, 0xafa00014, 0x8fbf0018, 0x03e00008,
4306 0x27bd0020, 0x27bdffe0, 0x3c040800, 0x24841ad8, 0x00002821, 0x00003021,
4307 0x00003821, 0xafbf0018, 0xafa00010, 0x0e00067c, 0xafa00014, 0x0e00005b,
4308 0x00000000, 0x0e0000b4, 0x00002021, 0x8fbf0018, 0x03e00008, 0x27bd0020,
4309 0x24020001, 0x8f636820, 0x00821004, 0x00021027, 0x00621824, 0x03e00008,
4310 0xaf636820, 0x27bdffd0, 0xafbf002c, 0xafb60028, 0xafb50024, 0xafb40020,
4311 0xafb3001c, 0xafb20018, 0xafb10014, 0xafb00010, 0x8f675c5c, 0x3c030800,
4312 0x24631bbc, 0x8c620000, 0x14470005, 0x3c0200ff, 0x3c020800, 0x90421b98,
4313 0x14400119, 0x3c0200ff, 0x3442fff8, 0x00e28824, 0xac670000, 0x00111902,
4314 0x306300ff, 0x30e20003, 0x000211c0, 0x00622825, 0x00a04021, 0x00071602,
4315 0x3c030800, 0x90631b98, 0x3044000f, 0x14600036, 0x00804821, 0x24020001,
4316 0x3c010800, 0xa0221b98, 0x00051100, 0x00821025, 0x3c010800, 0xac201b9c,
4317 0x3c010800, 0xac201ba0, 0x3c010800, 0xac201ba4, 0x3c010800, 0xac201bac,
4318 0x3c010800, 0xac201bb8, 0x3c010800, 0xac201bb0, 0x3c010800, 0xac201bb4,
4319 0x3c010800, 0xa42223d8, 0x9622000c, 0x30437fff, 0x3c010800, 0xa4222410,
4320 0x30428000, 0x3c010800, 0xa4231bc6, 0x10400005, 0x24020001, 0x3c010800,
4321 0xac2223f4, 0x0a000102, 0x2406003e, 0x24060036, 0x3c010800, 0xac2023f4,
4322 0x9622000a, 0x3c030800, 0x94631bc6, 0x3c010800, 0xac2023f0, 0x3c010800,
4323 0xac2023f8, 0x00021302, 0x00021080, 0x00c21021, 0x00621821, 0x3c010800,
4324 0xa42223d0, 0x3c010800, 0x0a000115, 0xa4231b96, 0x9622000c, 0x3c010800,
4325 0xa42223ec, 0x3c040800, 0x24841b9c, 0x8c820000, 0x00021100, 0x3c010800,
4326 0x00220821, 0xac311bc8, 0x8c820000, 0x00021100, 0x3c010800, 0x00220821,
4327 0xac271bcc, 0x8c820000, 0x25030001, 0x306601ff, 0x00021100, 0x3c010800,
4328 0x00220821, 0xac261bd0, 0x8c820000, 0x00021100, 0x3c010800, 0x00220821,
4329 0xac291bd4, 0x96230008, 0x3c020800, 0x8c421bac, 0x00432821, 0x3c010800,
4330 0xac251bac, 0x9622000a, 0x30420004, 0x14400018, 0x00061100, 0x8f630c14,
4331 0x3063000f, 0x2c620002, 0x1440000b, 0x3c02c000, 0x8f630c14, 0x3c020800,
4332 0x8c421b40, 0x3063000f, 0x24420001, 0x3c010800, 0xac221b40, 0x2c620002,
4333 0x1040fff7, 0x3c02c000, 0x00e21825, 0xaf635c5c, 0x8f625c50, 0x30420002,
4334 0x10400014, 0x00000000, 0x0a000147, 0x00000000, 0x3c030800, 0x8c631b80,
4335 0x3c040800, 0x94841b94, 0x01221025, 0x3c010800, 0xa42223da, 0x24020001,
4336 0x3c010800, 0xac221bb8, 0x24630001, 0x0085202a, 0x3c010800, 0x10800003,
4337 0xac231b80, 0x3c010800, 0xa4251b94, 0x3c060800, 0x24c61b9c, 0x8cc20000,
4338 0x24420001, 0xacc20000, 0x28420080, 0x14400005, 0x00000000, 0x0e000656,
4339 0x24040002, 0x0a0001e6, 0x00000000, 0x3c020800, 0x8c421bb8, 0x10400078,
4340 0x24020001, 0x3c050800, 0x90a51b98, 0x14a20072, 0x00000000, 0x3c150800,
4341 0x96b51b96, 0x3c040800, 0x8c841bac, 0x32a3ffff, 0x0083102a, 0x1440006c,
4342 0x00000000, 0x14830003, 0x00000000, 0x3c010800, 0xac2523f0, 0x1060005c,
4343 0x00009021, 0x24d60004, 0x0060a021, 0x24d30014, 0x8ec20000, 0x00028100,
4344 0x3c110800, 0x02308821, 0x0e000625, 0x8e311bc8, 0x00402821, 0x10a00054,
4345 0x00000000, 0x9628000a, 0x31020040, 0x10400005, 0x2407180c, 0x8e22000c,
4346 0x2407188c, 0x00021400, 0xaca20018, 0x3c030800, 0x00701821, 0x8c631bd0,
4347 0x3c020800, 0x00501021, 0x8c421bd4, 0x00031d00, 0x00021400, 0x00621825,
4348 0xaca30014, 0x8ec30004, 0x96220008, 0x00432023, 0x3242ffff, 0x3083ffff,
4349 0x00431021, 0x0282102a, 0x14400002, 0x02b23023, 0x00803021, 0x8e620000,
4350 0x30c4ffff, 0x00441021, 0xae620000, 0x8e220000, 0xaca20000, 0x8e220004,
4351 0x8e63fff4, 0x00431021, 0xaca20004, 0xa4a6000e, 0x8e62fff4, 0x00441021,
4352 0xae62fff4, 0x96230008, 0x0043102a, 0x14400005, 0x02469021, 0x8e62fff0,
4353 0xae60fff4, 0x24420001, 0xae62fff0, 0xaca00008, 0x3242ffff, 0x14540008,
4354 0x24020305, 0x31020080, 0x54400001, 0x34e70010, 0x24020905, 0xa4a2000c,
4355 0x0a0001cb, 0x34e70020, 0xa4a2000c, 0x3c020800, 0x8c4223f0, 0x10400003,
4356 0x3c024b65, 0x0a0001d3, 0x34427654, 0x3c02b49a, 0x344289ab, 0xaca2001c,
4357 0x30e2ffff, 0xaca20010, 0x0e0005a2, 0x00a02021, 0x3242ffff, 0x0054102b,
4358 0x1440ffa9, 0x00000000, 0x24020002, 0x3c010800, 0x0a0001e6, 0xa0221b98,
4359 0x8ec2083c, 0x24420001, 0x0a0001e6, 0xaec2083c, 0x0e0004c0, 0x00000000,
4360 0x8fbf002c, 0x8fb60028, 0x8fb50024, 0x8fb40020, 0x8fb3001c, 0x8fb20018,
4361 0x8fb10014, 0x8fb00010, 0x03e00008, 0x27bd0030, 0x27bdffd0, 0xafbf0028,
4362 0xafb30024, 0xafb20020, 0xafb1001c, 0xafb00018, 0x8f725c9c, 0x3c0200ff,
4363 0x3442fff8, 0x3c070800, 0x24e71bb4, 0x02428824, 0x9623000e, 0x8ce20000,
4364 0x00431021, 0xace20000, 0x8e220010, 0x30420020, 0x14400011, 0x00809821,
4365 0x0e00063b, 0x02202021, 0x3c02c000, 0x02421825, 0xaf635c9c, 0x8f625c90,
4366 0x30420002, 0x1040011e, 0x00000000, 0xaf635c9c, 0x8f625c90, 0x30420002,
4367 0x10400119, 0x00000000, 0x0a00020d, 0x00000000, 0x8e240008, 0x8e230014,
4368 0x00041402, 0x000231c0, 0x00031502, 0x304201ff, 0x2442ffff, 0x3042007f,
4369 0x00031942, 0x30637800, 0x00021100, 0x24424000, 0x00624821, 0x9522000a,
4370 0x3084ffff, 0x30420008, 0x104000b0, 0x000429c0, 0x3c020800, 0x8c422400,
4371 0x14400024, 0x24c50008, 0x94c20014, 0x3c010800, 0xa42223d0, 0x8cc40010,
4372 0x00041402, 0x3c010800, 0xa42223d2, 0x3c010800, 0xa42423d4, 0x94c2000e,
4373 0x3083ffff, 0x00431023, 0x3c010800, 0xac222408, 0x94c2001a, 0x3c010800,
4374 0xac262400, 0x3c010800, 0xac322404, 0x3c010800, 0xac2223fc, 0x3c02c000,
4375 0x02421825, 0xaf635c9c, 0x8f625c90, 0x30420002, 0x104000e5, 0x00000000,
4376 0xaf635c9c, 0x8f625c90, 0x30420002, 0x104000e0, 0x00000000, 0x0a000246,
4377 0x00000000, 0x94c2000e, 0x3c030800, 0x946323d4, 0x00434023, 0x3103ffff,
4378 0x2c620008, 0x1040001c, 0x00000000, 0x94c20014, 0x24420028, 0x00a22821,
4379 0x00031042, 0x1840000b, 0x00002021, 0x24e60848, 0x00403821, 0x94a30000,
4380 0x8cc20000, 0x24840001, 0x00431021, 0xacc20000, 0x0087102a, 0x1440fff9,
4381 0x24a50002, 0x31020001, 0x1040001f, 0x3c024000, 0x3c040800, 0x248423fc,
4382 0xa0a00001, 0x94a30000, 0x8c820000, 0x00431021, 0x0a000285, 0xac820000,
4383 0x8f626800, 0x3c030010, 0x00431024, 0x10400009, 0x00000000, 0x94c2001a,
4384 0x3c030800, 0x8c6323fc, 0x00431021, 0x3c010800, 0xac2223fc, 0x0a000286,
4385 0x3c024000, 0x94c2001a, 0x94c4001c, 0x3c030800, 0x8c6323fc, 0x00441023,
4386 0x00621821, 0x3c010800, 0xac2323fc, 0x3c024000, 0x02421825, 0xaf635c9c,
4387 0x8f625c90, 0x30420002, 0x1440fffc, 0x00000000, 0x9522000a, 0x30420010,
4388 0x1040009b, 0x00000000, 0x3c030800, 0x946323d4, 0x3c070800, 0x24e72400,
4389 0x8ce40000, 0x8f626800, 0x24630030, 0x00832821, 0x3c030010, 0x00431024,
4390 0x1440000a, 0x00000000, 0x94a20004, 0x3c040800, 0x8c842408, 0x3c030800,
4391 0x8c6323fc, 0x00441023, 0x00621821, 0x3c010800, 0xac2323fc, 0x3c040800,
4392 0x8c8423fc, 0x00041c02, 0x3082ffff, 0x00622021, 0x00041402, 0x00822021,
4393 0x00041027, 0xa4a20006, 0x3c030800, 0x8c632404, 0x3c0200ff, 0x3442fff8,
4394 0x00628824, 0x96220008, 0x24050001, 0x24034000, 0x000231c0, 0x00801021,
4395 0xa4c2001a, 0xa4c0001c, 0xace00000, 0x3c010800, 0xac251b60, 0xaf635cb8,
4396 0x8f625cb0, 0x30420002, 0x10400003, 0x00000000, 0x3c010800, 0xac201b60,
4397 0x8e220008, 0xaf625cb8, 0x8f625cb0, 0x30420002, 0x10400003, 0x00000000,
4398 0x3c010800, 0xac201b60, 0x3c020800, 0x8c421b60, 0x1040ffec, 0x00000000,
4399 0x3c040800, 0x0e00063b, 0x8c842404, 0x0a00032a, 0x00000000, 0x3c030800,
4400 0x90631b98, 0x24020002, 0x14620003, 0x3c034b65, 0x0a0002e1, 0x00008021,
4401 0x8e22001c, 0x34637654, 0x10430002, 0x24100002, 0x24100001, 0x00c02021,
4402 0x0e000350, 0x02003021, 0x24020003, 0x3c010800, 0xa0221b98, 0x24020002,
4403 0x1202000a, 0x24020001, 0x3c030800, 0x8c6323f0, 0x10620006, 0x00000000,
4404 0x3c020800, 0x944223d8, 0x00021400, 0x0a00031f, 0xae220014, 0x3c040800,
4405 0x248423da, 0x94820000, 0x00021400, 0xae220014, 0x3c020800, 0x8c421bbc,
4406 0x3c03c000, 0x3c010800, 0xa0201b98, 0x00431025, 0xaf625c5c, 0x8f625c50,
4407 0x30420002, 0x10400009, 0x00000000, 0x2484f7e2, 0x8c820000, 0x00431025,
4408 0xaf625c5c, 0x8f625c50, 0x30420002, 0x1440fffa, 0x00000000, 0x3c020800,
4409 0x24421b84, 0x8c430000, 0x24630001, 0xac430000, 0x8f630c14, 0x3063000f,
4410 0x2c620002, 0x1440000c, 0x3c024000, 0x8f630c14, 0x3c020800, 0x8c421b40,
4411 0x3063000f, 0x24420001, 0x3c010800, 0xac221b40, 0x2c620002, 0x1040fff7,
4412 0x00000000, 0x3c024000, 0x02421825, 0xaf635c9c, 0x8f625c90, 0x30420002,
4413 0x1440fffc, 0x00000000, 0x12600003, 0x00000000, 0x0e0004c0, 0x00000000,
4414 0x8fbf0028, 0x8fb30024, 0x8fb20020, 0x8fb1001c, 0x8fb00018, 0x03e00008,
4415 0x27bd0030, 0x8f634450, 0x3c040800, 0x24841b88, 0x8c820000, 0x00031c02,
4416 0x0043102b, 0x14400007, 0x3c038000, 0x8c840004, 0x8f624450, 0x00021c02,
4417 0x0083102b, 0x1040fffc, 0x3c038000, 0xaf634444, 0x8f624444, 0x00431024,
4418 0x1440fffd, 0x00000000, 0x8f624448, 0x03e00008, 0x3042ffff, 0x3c024000,
4419 0x00822025, 0xaf645c38, 0x8f625c30, 0x30420002, 0x1440fffc, 0x00000000,
4420 0x03e00008, 0x00000000, 0x27bdffe0, 0x00805821, 0x14c00011, 0x256e0008,
4421 0x3c020800, 0x8c4223f4, 0x10400007, 0x24020016, 0x3c010800, 0xa42223d2,
4422 0x2402002a, 0x3c010800, 0x0a000364, 0xa42223d4, 0x8d670010, 0x00071402,
4423 0x3c010800, 0xa42223d2, 0x3c010800, 0xa42723d4, 0x3c040800, 0x948423d4,
4424 0x3c030800, 0x946323d2, 0x95cf0006, 0x3c020800, 0x944223d0, 0x00832023,
4425 0x01e2c023, 0x3065ffff, 0x24a20028, 0x01c24821, 0x3082ffff, 0x14c0001a,
4426 0x01226021, 0x9582000c, 0x3042003f, 0x3c010800, 0xa42223d6, 0x95820004,
4427 0x95830006, 0x3c010800, 0xac2023e4, 0x3c010800, 0xac2023e8, 0x00021400,
4428 0x00431025, 0x3c010800, 0xac221bc0, 0x95220004, 0x3c010800, 0xa4221bc4,
4429 0x95230002, 0x01e51023, 0x0043102a, 0x10400010, 0x24020001, 0x3c010800,
4430 0x0a000398, 0xac2223f8, 0x3c030800, 0x8c6323e8, 0x3c020800, 0x94421bc4,
4431 0x00431021, 0xa5220004, 0x3c020800, 0x94421bc0, 0xa5820004, 0x3c020800,
4432 0x8c421bc0, 0xa5820006, 0x3c020800, 0x8c4223f0, 0x3c0d0800, 0x8dad23e4,
4433 0x3c0a0800, 0x144000e5, 0x8d4a23e8, 0x3c020800, 0x94421bc4, 0x004a1821,
4434 0x3063ffff, 0x0062182b, 0x24020002, 0x10c2000d, 0x01435023, 0x3c020800,
4435 0x944223d6, 0x30420009, 0x10400008, 0x00000000, 0x9582000c, 0x3042fff6,
4436 0xa582000c, 0x3c020800, 0x944223d6, 0x30420009, 0x01a26823, 0x3c020800,
4437 0x8c4223f8, 0x1040004a, 0x01203821, 0x3c020800, 0x944223d2, 0x00004021,
4438 0xa520000a, 0x01e21023, 0xa5220002, 0x3082ffff, 0x00021042, 0x18400008,
4439 0x00003021, 0x00401821, 0x94e20000, 0x25080001, 0x00c23021, 0x0103102a,
4440 0x1440fffb, 0x24e70002, 0x00061c02, 0x30c2ffff, 0x00623021, 0x00061402,
4441 0x00c23021, 0x00c02821, 0x00061027, 0xa522000a, 0x00003021, 0x2527000c,
4442 0x00004021, 0x94e20000, 0x25080001, 0x00c23021, 0x2d020004, 0x1440fffb,
4443 0x24e70002, 0x95220002, 0x00004021, 0x91230009, 0x00442023, 0x01803821,
4444 0x3082ffff, 0xa4e00010, 0x00621821, 0x00021042, 0x18400010, 0x00c33021,
4445 0x00404821, 0x94e20000, 0x24e70002, 0x00c23021, 0x30e2007f, 0x14400006,
4446 0x25080001, 0x8d630000, 0x3c02007f, 0x3442ff80, 0x00625824, 0x25670008,
4447 0x0109102a, 0x1440fff3, 0x00000000, 0x30820001, 0x10400005, 0x00061c02,
4448 0xa0e00001, 0x94e20000, 0x00c23021, 0x00061c02, 0x30c2ffff, 0x00623021,
4449 0x00061402, 0x00c23021, 0x0a00047d, 0x30c6ffff, 0x24020002, 0x14c20081,
4450 0x00000000, 0x3c020800, 0x8c42240c, 0x14400007, 0x00000000, 0x3c020800,
4451 0x944223d2, 0x95230002, 0x01e21023, 0x10620077, 0x00000000, 0x3c020800,
4452 0x944223d2, 0x01e21023, 0xa5220002, 0x3c020800, 0x8c42240c, 0x1040001a,
4453 0x31e3ffff, 0x8dc70010, 0x3c020800, 0x94421b96, 0x00e04021, 0x00072c02,
4454 0x00aa2021, 0x00431023, 0x00823823, 0x00072402, 0x30e2ffff, 0x00823821,
4455 0x00071027, 0xa522000a, 0x3102ffff, 0x3c040800, 0x948423d4, 0x00453023,
4456 0x00e02821, 0x00641823, 0x006d1821, 0x00c33021, 0x00061c02, 0x30c2ffff,
4457 0x0a00047d, 0x00623021, 0x01203821, 0x00004021, 0x3082ffff, 0x00021042,
4458 0x18400008, 0x00003021, 0x00401821, 0x94e20000, 0x25080001, 0x00c23021,
4459 0x0103102a, 0x1440fffb, 0x24e70002, 0x00061c02, 0x30c2ffff, 0x00623021,
4460 0x00061402, 0x00c23021, 0x00c02821, 0x00061027, 0xa522000a, 0x00003021,
4461 0x2527000c, 0x00004021, 0x94e20000, 0x25080001, 0x00c23021, 0x2d020004,
4462 0x1440fffb, 0x24e70002, 0x95220002, 0x00004021, 0x91230009, 0x00442023,
4463 0x01803821, 0x3082ffff, 0xa4e00010, 0x3c040800, 0x948423d4, 0x00621821,
4464 0x00c33021, 0x00061c02, 0x30c2ffff, 0x00623021, 0x00061c02, 0x3c020800,
4465 0x944223d0, 0x00c34821, 0x00441023, 0x00021fc2, 0x00431021, 0x00021043,
4466 0x18400010, 0x00003021, 0x00402021, 0x94e20000, 0x24e70002, 0x00c23021,
4467 0x30e2007f, 0x14400006, 0x25080001, 0x8d630000, 0x3c02007f, 0x3442ff80,
4468 0x00625824, 0x25670008, 0x0104102a, 0x1440fff3, 0x00000000, 0x3c020800,
4469 0x944223ec, 0x00c23021, 0x3122ffff, 0x00c23021, 0x00061c02, 0x30c2ffff,
4470 0x00623021, 0x00061402, 0x00c23021, 0x00c04021, 0x00061027, 0xa5820010,
4471 0xadc00014, 0x0a00049d, 0xadc00000, 0x8dc70010, 0x00e04021, 0x11400007,
4472 0x00072c02, 0x00aa3021, 0x00061402, 0x30c3ffff, 0x00433021, 0x00061402,
4473 0x00c22821, 0x00051027, 0xa522000a, 0x3c030800, 0x946323d4, 0x3102ffff,
4474 0x01e21021, 0x00433023, 0x00cd3021, 0x00061c02, 0x30c2ffff, 0x00623021,
4475 0x00061402, 0x00c23021, 0x00c04021, 0x00061027, 0xa5820010, 0x3102ffff,
4476 0x00051c00, 0x00431025, 0xadc20010, 0x3c020800, 0x8c4223f4, 0x10400005,
4477 0x2de205eb, 0x14400002, 0x25e2fff2, 0x34028870, 0xa5c20034, 0x3c030800,
4478 0x246323e8, 0x8c620000, 0x24420001, 0xac620000, 0x3c040800, 0x8c8423e4,
4479 0x3c020800, 0x8c421bc0, 0x3303ffff, 0x00832021, 0x00431821, 0x0062102b,
4480 0x3c010800, 0xac2423e4, 0x10400003, 0x2482ffff, 0x3c010800, 0xac2223e4,
4481 0x3c010800, 0xac231bc0, 0x03e00008, 0x27bd0020, 0x27bdffb8, 0x3c050800,
4482 0x24a51b96, 0xafbf0044, 0xafbe0040, 0xafb7003c, 0xafb60038, 0xafb50034,
4483 0xafb40030, 0xafb3002c, 0xafb20028, 0xafb10024, 0xafb00020, 0x94a90000,
4484 0x3c020800, 0x944223d0, 0x3c030800, 0x8c631bb0, 0x3c040800, 0x8c841bac,
4485 0x01221023, 0x0064182a, 0xa7a9001e, 0x106000be, 0xa7a20016, 0x24be0022,
4486 0x97b6001e, 0x24b3001a, 0x24b70016, 0x8fc20000, 0x14400008, 0x00000000,
4487 0x8fc2fff8, 0x97a30016, 0x8fc4fff4, 0x00431021, 0x0082202a, 0x148000b0,
4488 0x00000000, 0x97d50818, 0x32a2ffff, 0x104000a3, 0x00009021, 0x0040a021,
4489 0x00008821, 0x0e000625, 0x00000000, 0x00403021, 0x14c00007, 0x00000000,
4490 0x3c020800, 0x8c4223dc, 0x24420001, 0x3c010800, 0x0a000596, 0xac2223dc,
4491 0x3c100800, 0x02118021, 0x8e101bc8, 0x9608000a, 0x31020040, 0x10400005,
4492 0x2407180c, 0x8e02000c, 0x2407188c, 0x00021400, 0xacc20018, 0x31020080,
4493 0x54400001, 0x34e70010, 0x3c020800, 0x00511021, 0x8c421bd0, 0x3c030800,
4494 0x00711821, 0x8c631bd4, 0x00021500, 0x00031c00, 0x00431025, 0xacc20014,
4495 0x96040008, 0x3242ffff, 0x00821021, 0x0282102a, 0x14400002, 0x02b22823,
4496 0x00802821, 0x8e020000, 0x02459021, 0xacc20000, 0x8e020004, 0x00c02021,
4497 0x26310010, 0xac820004, 0x30e2ffff, 0xac800008, 0xa485000e, 0xac820010,
4498 0x24020305, 0x0e0005a2, 0xa482000c, 0x3242ffff, 0x0054102b, 0x1440ffc5,
4499 0x3242ffff, 0x0a00058e, 0x00000000, 0x8e620000, 0x8e63fffc, 0x0043102a,
4500 0x10400067, 0x00000000, 0x8e62fff0, 0x00028900, 0x3c100800, 0x02118021,
4501 0x0e000625, 0x8e101bc8, 0x00403021, 0x14c00005, 0x00000000, 0x8e62082c,
4502 0x24420001, 0x0a000596, 0xae62082c, 0x9608000a, 0x31020040, 0x10400005,
4503 0x2407180c, 0x8e02000c, 0x2407188c, 0x00021400, 0xacc20018, 0x3c020800,
4504 0x00511021, 0x8c421bd0, 0x3c030800, 0x00711821, 0x8c631bd4, 0x00021500,
4505 0x00031c00, 0x00431025, 0xacc20014, 0x8e63fff4, 0x96020008, 0x00432023,
4506 0x3242ffff, 0x3083ffff, 0x00431021, 0x02c2102a, 0x10400003, 0x00802821,
4507 0x97a9001e, 0x01322823, 0x8e620000, 0x30a4ffff, 0x00441021, 0xae620000,
4508 0xa4c5000e, 0x8e020000, 0xacc20000, 0x8e020004, 0x8e63fff4, 0x00431021,
4509 0xacc20004, 0x8e63fff4, 0x96020008, 0x00641821, 0x0062102a, 0x14400006,
4510 0x02459021, 0x8e62fff0, 0xae60fff4, 0x24420001, 0x0a000571, 0xae62fff0,
4511 0xae63fff4, 0xacc00008, 0x3242ffff, 0x10560003, 0x31020004, 0x10400006,
4512 0x24020305, 0x31020080, 0x54400001, 0x34e70010, 0x34e70020, 0x24020905,
4513 0xa4c2000c, 0x8ee30000, 0x8ee20004, 0x14620007, 0x3c02b49a, 0x8ee20860,
4514 0x54400001, 0x34e70400, 0x3c024b65, 0x0a000588, 0x34427654, 0x344289ab,
4515 0xacc2001c, 0x30e2ffff, 0xacc20010, 0x0e0005a2, 0x00c02021, 0x3242ffff,
4516 0x0056102b, 0x1440ff9b, 0x00000000, 0x8e620000, 0x8e63fffc, 0x0043102a,
4517 0x1440ff48, 0x00000000, 0x8fbf0044, 0x8fbe0040, 0x8fb7003c, 0x8fb60038,
4518 0x8fb50034, 0x8fb40030, 0x8fb3002c, 0x8fb20028, 0x8fb10024, 0x8fb00020,
4519 0x03e00008, 0x27bd0048, 0x27bdffe8, 0xafbf0014, 0xafb00010, 0x8f624450,
4520 0x8f634410, 0x0a0005b1, 0x00808021, 0x8f626820, 0x30422000, 0x10400003,
4521 0x00000000, 0x0e0001f0, 0x00002021, 0x8f624450, 0x8f634410, 0x3042ffff,
4522 0x0043102b, 0x1440fff5, 0x00000000, 0x8f630c14, 0x3063000f, 0x2c620002,
4523 0x1440000b, 0x00000000, 0x8f630c14, 0x3c020800, 0x8c421b40, 0x3063000f,
4524 0x24420001, 0x3c010800, 0xac221b40, 0x2c620002, 0x1040fff7, 0x00000000,
4525 0xaf705c18, 0x8f625c10, 0x30420002, 0x10400009, 0x00000000, 0x8f626820,
4526 0x30422000, 0x1040fff8, 0x00000000, 0x0e0001f0, 0x00002021, 0x0a0005c4,
4527 0x00000000, 0x8fbf0014, 0x8fb00010, 0x03e00008, 0x27bd0018, 0x00000000,
4528 0x00000000, 0x00000000, 0x27bdffe8, 0x3c1bc000, 0xafbf0014, 0xafb00010,
4529 0xaf60680c, 0x8f626804, 0x34420082, 0xaf626804, 0x8f634000, 0x24020b50,
4530 0x3c010800, 0xac221b54, 0x24020b78, 0x3c010800, 0xac221b64, 0x34630002,
4531 0xaf634000, 0x0e000605, 0x00808021, 0x3c010800, 0xa0221b68, 0x304200ff,
4532 0x24030002, 0x14430005, 0x00000000, 0x3c020800, 0x8c421b54, 0x0a0005f8,
4533 0xac5000c0, 0x3c020800, 0x8c421b54, 0xac5000bc, 0x8f624434, 0x8f634438,
4534 0x8f644410, 0x3c010800, 0xac221b5c, 0x3c010800, 0xac231b6c, 0x3c010800,
4535 0xac241b58, 0x8fbf0014, 0x8fb00010, 0x03e00008, 0x27bd0018, 0x3c040800,
4536 0x8c870000, 0x3c03aa55, 0x3463aa55, 0x3c06c003, 0xac830000, 0x8cc20000,
4537 0x14430007, 0x24050002, 0x3c0355aa, 0x346355aa, 0xac830000, 0x8cc20000,
4538 0x50430001, 0x24050001, 0x3c020800, 0xac470000, 0x03e00008, 0x00a01021,
4539 0x27bdfff8, 0x18800009, 0x00002821, 0x8f63680c, 0x8f62680c, 0x1043fffe,
4540 0x00000000, 0x24a50001, 0x00a4102a, 0x1440fff9, 0x00000000, 0x03e00008,
4541 0x27bd0008, 0x8f634450, 0x3c020800, 0x8c421b5c, 0x00031c02, 0x0043102b,
4542 0x14400008, 0x3c038000, 0x3c040800, 0x8c841b6c, 0x8f624450, 0x00021c02,
4543 0x0083102b, 0x1040fffc, 0x3c038000, 0xaf634444, 0x8f624444, 0x00431024,
4544 0x1440fffd, 0x00000000, 0x8f624448, 0x03e00008, 0x3042ffff, 0x3082ffff,
4545 0x2442e000, 0x2c422001, 0x14400003, 0x3c024000, 0x0a000648, 0x2402ffff,
4546 0x00822025, 0xaf645c38, 0x8f625c30, 0x30420002, 0x1440fffc, 0x00001021,
4547 0x03e00008, 0x00000000, 0x8f624450, 0x3c030800, 0x8c631b58, 0x0a000651,
4548 0x3042ffff, 0x8f624450, 0x3042ffff, 0x0043102b, 0x1440fffc, 0x00000000,
4549 0x03e00008, 0x00000000, 0x27bdffe0, 0x00802821, 0x3c040800, 0x24841af0,
4550 0x00003021, 0x00003821, 0xafbf0018, 0xafa00010, 0x0e00067c, 0xafa00014,
4551 0x0a000660, 0x00000000, 0x8fbf0018, 0x03e00008, 0x27bd0020, 0x00000000,
4552 0x00000000, 0x00000000, 0x3c020800, 0x34423000, 0x3c030800, 0x34633000,
4553 0x3c040800, 0x348437ff, 0x3c010800, 0xac221b74, 0x24020040, 0x3c010800,
4554 0xac221b78, 0x3c010800, 0xac201b70, 0xac600000, 0x24630004, 0x0083102b,
4555 0x5040fffd, 0xac600000, 0x03e00008, 0x00000000, 0x00804821, 0x8faa0010,
4556 0x3c020800, 0x8c421b70, 0x3c040800, 0x8c841b78, 0x8fab0014, 0x24430001,
4557 0x0044102b, 0x3c010800, 0xac231b70, 0x14400003, 0x00004021, 0x3c010800,
4558 0xac201b70, 0x3c020800, 0x8c421b70, 0x3c030800, 0x8c631b74, 0x91240000,
4559 0x00021140, 0x00431021, 0x00481021, 0x25080001, 0xa0440000, 0x29020008,
4560 0x1440fff4, 0x25290001, 0x3c020800, 0x8c421b70, 0x3c030800, 0x8c631b74,
4561 0x8f64680c, 0x00021140, 0x00431021, 0xac440008, 0xac45000c, 0xac460010,
4562 0xac470014, 0xac4a0018, 0x03e00008, 0xac4b001c, 0x00000000, 0x00000000,
4565 static u32 tg3TsoFwRodata[] = {
4566 0x4d61696e, 0x43707542, 0x00000000, 0x4d61696e, 0x43707541, 0x00000000,
4567 0x00000000, 0x00000000, 0x73746b6f, 0x66666c64, 0x496e0000, 0x73746b6f,
4568 0x66662a2a, 0x00000000, 0x53774576, 0x656e7430, 0x00000000, 0x00000000,
4569 0x00000000, 0x00000000, 0x66617461, 0x6c457272, 0x00000000, 0x00000000,
4573 static u32 tg3TsoFwData[] = {
4574 0x00000000, 0x73746b6f, 0x66666c64, 0x5f76312e, 0x362e3000, 0x00000000,
4575 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
4579 /* 5705 needs a special version of the TSO firmware. */
4580 #define TG3_TSO5_FW_RELEASE_MAJOR 0x1
4581 #define TG3_TSO5_FW_RELASE_MINOR 0x2
4582 #define TG3_TSO5_FW_RELEASE_FIX 0x0
4583 #define TG3_TSO5_FW_START_ADDR 0x00010000
4584 #define TG3_TSO5_FW_TEXT_ADDR 0x00010000
4585 #define TG3_TSO5_FW_TEXT_LEN 0xe90
4586 #define TG3_TSO5_FW_RODATA_ADDR 0x00010e90
4587 #define TG3_TSO5_FW_RODATA_LEN 0x50
4588 #define TG3_TSO5_FW_DATA_ADDR 0x00010f00
4589 #define TG3_TSO5_FW_DATA_LEN 0x20
4590 #define TG3_TSO5_FW_SBSS_ADDR 0x00010f20
4591 #define TG3_TSO5_FW_SBSS_LEN 0x28
4592 #define TG3_TSO5_FW_BSS_ADDR 0x00010f50
4593 #define TG3_TSO5_FW_BSS_LEN 0x88
4595 static u32 tg3Tso5FwText[(TG3_TSO5_FW_TEXT_LEN / 4) + 1] = {
4596 0x0c004003, 0x00000000, 0x00010f04, 0x00000000, 0x10000003, 0x00000000,
4597 0x0000000d, 0x0000000d, 0x3c1d0001, 0x37bde000, 0x03a0f021, 0x3c100001,
4598 0x26100000, 0x0c004010, 0x00000000, 0x0000000d, 0x27bdffe0, 0x3c04fefe,
4599 0xafbf0018, 0x0c0042e8, 0x34840002, 0x0c004364, 0x00000000, 0x3c030001,
4600 0x90630f34, 0x24020002, 0x3c040001, 0x24840e9c, 0x14620003, 0x24050001,
4601 0x3c040001, 0x24840e90, 0x24060002, 0x00003821, 0xafa00010, 0x0c004378,
4602 0xafa00014, 0x0c00402c, 0x00000000, 0x8fbf0018, 0x03e00008, 0x27bd0020,
4603 0x00000000, 0x00000000, 0x27bdffe0, 0xafbf001c, 0xafb20018, 0xafb10014,
4604 0x0c0042d4, 0xafb00010, 0x3c128000, 0x24110001, 0x8f706810, 0x32020400,
4605 0x10400007, 0x00000000, 0x8f641008, 0x00921024, 0x14400003, 0x00000000,
4606 0x0c004064, 0x00000000, 0x3c020001, 0x90420f56, 0x10510003, 0x32020200,
4607 0x1040fff1, 0x00000000, 0x0c0041b4, 0x00000000, 0x08004034, 0x00000000,
4608 0x8fbf001c, 0x8fb20018, 0x8fb10014, 0x8fb00010, 0x03e00008, 0x27bd0020,
4609 0x27bdffe0, 0x3c040001, 0x24840eb0, 0x00002821, 0x00003021, 0x00003821,
4610 0xafbf0018, 0xafa00010, 0x0c004378, 0xafa00014, 0x0000d021, 0x24020130,
4611 0xaf625000, 0x3c010001, 0xa4200f50, 0x3c010001, 0xa0200f57, 0x8fbf0018,
4612 0x03e00008, 0x27bd0020, 0x00000000, 0x00000000, 0x3c030001, 0x24630f60,
4613 0x90620000, 0x27bdfff0, 0x14400003, 0x0080c021, 0x08004073, 0x00004821,
4614 0x3c022000, 0x03021024, 0x10400003, 0x24090002, 0x08004073, 0xa0600000,
4615 0x24090001, 0x00181040, 0x30431f80, 0x346f8008, 0x1520004b, 0x25eb0028,
4616 0x3c040001, 0x00832021, 0x8c848010, 0x3c050001, 0x24a50f7a, 0x00041402,
4617 0xa0a20000, 0x3c010001, 0xa0240f7b, 0x3c020001, 0x00431021, 0x94428014,
4618 0x3c010001, 0xa0220f7c, 0x3c0c0001, 0x01836021, 0x8d8c8018, 0x304200ff,
4619 0x24420008, 0x000220c3, 0x24020001, 0x3c010001, 0xa0220f60, 0x0124102b,
4620 0x1040000c, 0x00003821, 0x24a6000e, 0x01602821, 0x8ca20000, 0x8ca30004,
4621 0x24a50008, 0x24e70001, 0xacc20000, 0xacc30004, 0x00e4102b, 0x1440fff8,
4622 0x24c60008, 0x00003821, 0x3c080001, 0x25080f7b, 0x91060000, 0x3c020001,
4623 0x90420f7c, 0x2503000d, 0x00c32821, 0x00461023, 0x00021fc2, 0x00431021,
4624 0x00021043, 0x1840000c, 0x00002021, 0x91020001, 0x00461023, 0x00021fc2,
4625 0x00431021, 0x00021843, 0x94a20000, 0x24e70001, 0x00822021, 0x00e3102a,
4626 0x1440fffb, 0x24a50002, 0x00041c02, 0x3082ffff, 0x00622021, 0x00041402,
4627 0x00822021, 0x3c02ffff, 0x01821024, 0x3083ffff, 0x00431025, 0x3c010001,
4628 0x080040fa, 0xac220f80, 0x3c050001, 0x24a50f7c, 0x90a20000, 0x3c0c0001,
4629 0x01836021, 0x8d8c8018, 0x000220c2, 0x1080000e, 0x00003821, 0x01603021,
4630 0x24a5000c, 0x8ca20000, 0x8ca30004, 0x24a50008, 0x24e70001, 0xacc20000,
4631 0xacc30004, 0x00e4102b, 0x1440fff8, 0x24c60008, 0x3c050001, 0x24a50f7c,
4632 0x90a20000, 0x30430007, 0x24020004, 0x10620011, 0x28620005, 0x10400005,
4633 0x24020002, 0x10620008, 0x000710c0, 0x080040fa, 0x00000000, 0x24020006,
4634 0x1062000e, 0x000710c0, 0x080040fa, 0x00000000, 0x00a21821, 0x9463000c,
4635 0x004b1021, 0x080040fa, 0xa4430000, 0x000710c0, 0x00a21821, 0x8c63000c,
4636 0x004b1021, 0x080040fa, 0xac430000, 0x00a21821, 0x8c63000c, 0x004b2021,
4637 0x00a21021, 0xac830000, 0x94420010, 0xa4820004, 0x95e70006, 0x3c020001,
4638 0x90420f7c, 0x3c030001, 0x90630f7a, 0x00e2c823, 0x3c020001, 0x90420f7b,
4639 0x24630028, 0x01e34021, 0x24420028, 0x15200012, 0x01e23021, 0x94c2000c,
4640 0x3c010001, 0xa4220f78, 0x94c20004, 0x94c30006, 0x3c010001, 0xa4200f76,
4641 0x3c010001, 0xa4200f72, 0x00021400, 0x00431025, 0x3c010001, 0xac220f6c,
4642 0x95020004, 0x3c010001, 0x08004124, 0xa4220f70, 0x3c020001, 0x94420f70,
4643 0x3c030001, 0x94630f72, 0x00431021, 0xa5020004, 0x3c020001, 0x94420f6c,
4644 0xa4c20004, 0x3c020001, 0x8c420f6c, 0xa4c20006, 0x3c040001, 0x94840f72,
4645 0x3c020001, 0x94420f70, 0x3c0a0001, 0x954a0f76, 0x00441821, 0x3063ffff,
4646 0x0062182a, 0x24020002, 0x1122000b, 0x00832023, 0x3c030001, 0x94630f78,
4647 0x30620009, 0x10400006, 0x3062fff6, 0xa4c2000c, 0x3c020001, 0x94420f78,
4648 0x30420009, 0x01425023, 0x24020001, 0x1122001b, 0x29220002, 0x50400005,
4649 0x24020002, 0x11200007, 0x31a2ffff, 0x08004197, 0x00000000, 0x1122001d,
4650 0x24020016, 0x08004197, 0x31a2ffff, 0x3c0e0001, 0x95ce0f80, 0x10800005,
4651 0x01806821, 0x01c42021, 0x00041c02, 0x3082ffff, 0x00627021, 0x000e1027,
4652 0xa502000a, 0x3c030001, 0x90630f7b, 0x31a2ffff, 0x00e21021, 0x0800418d,
4653 0x00432023, 0x3c020001, 0x94420f80, 0x00442021, 0x00041c02, 0x3082ffff,
4654 0x00622021, 0x00807021, 0x00041027, 0x08004185, 0xa502000a, 0x3c050001,
4655 0x24a50f7a, 0x90a30000, 0x14620002, 0x24e2fff2, 0xa5e20034, 0x90a20000,
4656 0x00e21023, 0xa5020002, 0x3c030001, 0x94630f80, 0x3c020001, 0x94420f5a,
4657 0x30e5ffff, 0x00641821, 0x00451023, 0x00622023, 0x00041c02, 0x3082ffff,
4658 0x00622021, 0x00041027, 0xa502000a, 0x3c030001, 0x90630f7c, 0x24620001,
4659 0x14a20005, 0x00807021, 0x01631021, 0x90420000, 0x08004185, 0x00026200,
4660 0x24620002, 0x14a20003, 0x306200fe, 0x004b1021, 0x944c0000, 0x3c020001,
4661 0x94420f82, 0x3183ffff, 0x3c040001, 0x90840f7b, 0x00431021, 0x00e21021,
4662 0x00442023, 0x008a2021, 0x00041c02, 0x3082ffff, 0x00622021, 0x00041402,
4663 0x00822021, 0x00806821, 0x00041027, 0xa4c20010, 0x31a2ffff, 0x000e1c00,
4664 0x00431025, 0x3c040001, 0x24840f72, 0xade20010, 0x94820000, 0x3c050001,
4665 0x94a50f76, 0x3c030001, 0x8c630f6c, 0x24420001, 0x00b92821, 0xa4820000,
4666 0x3322ffff, 0x00622021, 0x0083182b, 0x3c010001, 0xa4250f76, 0x10600003,
4667 0x24a2ffff, 0x3c010001, 0xa4220f76, 0x3c024000, 0x03021025, 0x3c010001,
4668 0xac240f6c, 0xaf621008, 0x03e00008, 0x27bd0010, 0x3c030001, 0x90630f56,
4669 0x27bdffe8, 0x24020001, 0xafbf0014, 0x10620026, 0xafb00010, 0x8f620cf4,
4670 0x2442ffff, 0x3042007f, 0x00021100, 0x8c434000, 0x3c010001, 0xac230f64,
4671 0x8c434008, 0x24444000, 0x8c5c4004, 0x30620040, 0x14400002, 0x24020088,
4672 0x24020008, 0x3c010001, 0xa4220f68, 0x30620004, 0x10400005, 0x24020001,
4673 0x3c010001, 0xa0220f57, 0x080041d5, 0x00031402, 0x3c010001, 0xa0200f57,
4674 0x00031402, 0x3c010001, 0xa4220f54, 0x9483000c, 0x24020001, 0x3c010001,
4675 0xa4200f50, 0x3c010001, 0xa0220f56, 0x3c010001, 0xa4230f62, 0x24020001,
4676 0x1342001e, 0x00000000, 0x13400005, 0x24020003, 0x13420067, 0x00000000,
4677 0x080042cf, 0x00000000, 0x3c020001, 0x94420f62, 0x241a0001, 0x3c010001,
4678 0xa4200f5e, 0x3c010001, 0xa4200f52, 0x304407ff, 0x00021bc2, 0x00031823,
4679 0x3063003e, 0x34630036, 0x00021242, 0x3042003c, 0x00621821, 0x3c010001,
4680 0xa4240f58, 0x00832021, 0x24630030, 0x3c010001, 0xa4240f5a, 0x3c010001,
4681 0xa4230f5c, 0x3c060001, 0x24c60f52, 0x94c50000, 0x94c30002, 0x3c040001,
4682 0x94840f5a, 0x00651021, 0x0044102a, 0x10400013, 0x3c108000, 0x00a31021,
4683 0xa4c20000, 0x3c02a000, 0xaf620cf4, 0x3c010001, 0xa0200f56, 0x8f641008,
4684 0x00901024, 0x14400003, 0x00000000, 0x0c004064, 0x00000000, 0x8f620cf4,
4685 0x00501024, 0x104000b7, 0x00000000, 0x0800420f, 0x00000000, 0x3c030001,
4686 0x94630f50, 0x00851023, 0xa4c40000, 0x00621821, 0x3042ffff, 0x3c010001,
4687 0xa4230f50, 0xaf620ce8, 0x3c020001, 0x94420f68, 0x34420024, 0xaf620cec,
4688 0x94c30002, 0x3c020001, 0x94420f50, 0x14620012, 0x3c028000, 0x3c108000,
4689 0x3c02a000, 0xaf620cf4, 0x3c010001, 0xa0200f56, 0x8f641008, 0x00901024,
4690 0x14400003, 0x00000000, 0x0c004064, 0x00000000, 0x8f620cf4, 0x00501024,
4691 0x1440fff7, 0x00000000, 0x080042cf, 0x241a0003, 0xaf620cf4, 0x3c108000,
4692 0x8f641008, 0x00901024, 0x14400003, 0x00000000, 0x0c004064, 0x00000000,
4693 0x8f620cf4, 0x00501024, 0x1440fff7, 0x00000000, 0x080042cf, 0x241a0003,
4694 0x3c070001, 0x24e70f50, 0x94e20000, 0x03821021, 0xaf620ce0, 0x3c020001,
4695 0x8c420f64, 0xaf620ce4, 0x3c050001, 0x94a50f54, 0x94e30000, 0x3c040001,
4696 0x94840f58, 0x3c020001, 0x94420f5e, 0x00a32823, 0x00822023, 0x30a6ffff,
4697 0x3083ffff, 0x00c3102b, 0x14400043, 0x00000000, 0x3c020001, 0x94420f5c,
4698 0x00021400, 0x00621025, 0xaf620ce8, 0x94e20000, 0x3c030001, 0x94630f54,
4699 0x00441021, 0xa4e20000, 0x3042ffff, 0x14430021, 0x3c020008, 0x3c020001,
4700 0x90420f57, 0x10400006, 0x3c03000c, 0x3c020001, 0x94420f68, 0x34630624,
4701 0x0800427c, 0x0000d021, 0x3c020001, 0x94420f68, 0x3c030008, 0x34630624,
4702 0x00431025, 0xaf620cec, 0x3c108000, 0x3c02a000, 0xaf620cf4, 0x3c010001,
4703 0xa0200f56, 0x8f641008, 0x00901024, 0x14400003, 0x00000000, 0x0c004064,
4704 0x00000000, 0x8f620cf4, 0x00501024, 0x10400015, 0x00000000, 0x08004283,
4705 0x00000000, 0x3c030001, 0x94630f68, 0x34420624, 0x3c108000, 0x00621825,
4706 0x3c028000, 0xaf630cec, 0xaf620cf4, 0x8f641008, 0x00901024, 0x14400003,
4707 0x00000000, 0x0c004064, 0x00000000, 0x8f620cf4, 0x00501024, 0x1440fff7,
4708 0x00000000, 0x3c010001, 0x080042cf, 0xa4200f5e, 0x3c020001, 0x94420f5c,
4709 0x00021400, 0x00c21025, 0xaf620ce8, 0x3c020001, 0x90420f57, 0x10400009,
4710 0x3c03000c, 0x3c020001, 0x94420f68, 0x34630624, 0x0000d021, 0x00431025,
4711 0xaf620cec, 0x080042c1, 0x3c108000, 0x3c020001, 0x94420f68, 0x3c030008,
4712 0x34630604, 0x00431025, 0xaf620cec, 0x3c020001, 0x94420f5e, 0x00451021,
4713 0x3c010001, 0xa4220f5e, 0x3c108000, 0x3c02a000, 0xaf620cf4, 0x3c010001,
4714 0xa0200f56, 0x8f641008, 0x00901024, 0x14400003, 0x00000000, 0x0c004064,
4715 0x00000000, 0x8f620cf4, 0x00501024, 0x1440fff7, 0x00000000, 0x8fbf0014,
4716 0x8fb00010, 0x03e00008, 0x27bd0018, 0x00000000, 0x27bdffe0, 0x3c040001,
4717 0x24840ec0, 0x00002821, 0x00003021, 0x00003821, 0xafbf0018, 0xafa00010,
4718 0x0c004378, 0xafa00014, 0x0000d021, 0x24020130, 0xaf625000, 0x3c010001,
4719 0xa4200f50, 0x3c010001, 0xa0200f57, 0x8fbf0018, 0x03e00008, 0x27bd0020,
4720 0x27bdffe8, 0x3c1bc000, 0xafbf0014, 0xafb00010, 0xaf60680c, 0x8f626804,
4721 0x34420082, 0xaf626804, 0x8f634000, 0x24020b50, 0x3c010001, 0xac220f20,
4722 0x24020b78, 0x3c010001, 0xac220f30, 0x34630002, 0xaf634000, 0x0c004315,
4723 0x00808021, 0x3c010001, 0xa0220f34, 0x304200ff, 0x24030002, 0x14430005,
4724 0x00000000, 0x3c020001, 0x8c420f20, 0x08004308, 0xac5000c0, 0x3c020001,
4725 0x8c420f20, 0xac5000bc, 0x8f624434, 0x8f634438, 0x8f644410, 0x3c010001,
4726 0xac220f28, 0x3c010001, 0xac230f38, 0x3c010001, 0xac240f24, 0x8fbf0014,
4727 0x8fb00010, 0x03e00008, 0x27bd0018, 0x03e00008, 0x24020001, 0x27bdfff8,
4728 0x18800009, 0x00002821, 0x8f63680c, 0x8f62680c, 0x1043fffe, 0x00000000,
4729 0x24a50001, 0x00a4102a, 0x1440fff9, 0x00000000, 0x03e00008, 0x27bd0008,
4730 0x8f634450, 0x3c020001, 0x8c420f28, 0x00031c02, 0x0043102b, 0x14400008,
4731 0x3c038000, 0x3c040001, 0x8c840f38, 0x8f624450, 0x00021c02, 0x0083102b,
4732 0x1040fffc, 0x3c038000, 0xaf634444, 0x8f624444, 0x00431024, 0x1440fffd,
4733 0x00000000, 0x8f624448, 0x03e00008, 0x3042ffff, 0x3082ffff, 0x2442e000,
4734 0x2c422001, 0x14400003, 0x3c024000, 0x08004347, 0x2402ffff, 0x00822025,
4735 0xaf645c38, 0x8f625c30, 0x30420002, 0x1440fffc, 0x00001021, 0x03e00008,
4736 0x00000000, 0x8f624450, 0x3c030001, 0x8c630f24, 0x08004350, 0x3042ffff,
4737 0x8f624450, 0x3042ffff, 0x0043102b, 0x1440fffc, 0x00000000, 0x03e00008,
4738 0x00000000, 0x27bdffe0, 0x00802821, 0x3c040001, 0x24840ed0, 0x00003021,
4739 0x00003821, 0xafbf0018, 0xafa00010, 0x0c004378, 0xafa00014, 0x0800435f,
4740 0x00000000, 0x8fbf0018, 0x03e00008, 0x27bd0020, 0x3c020001, 0x3442d600,
4741 0x3c030001, 0x3463d600, 0x3c040001, 0x3484ddff, 0x3c010001, 0xac220f40,
4742 0x24020040, 0x3c010001, 0xac220f44, 0x3c010001, 0xac200f3c, 0xac600000,
4743 0x24630004, 0x0083102b, 0x5040fffd, 0xac600000, 0x03e00008, 0x00000000,
4744 0x00804821, 0x8faa0010, 0x3c020001, 0x8c420f3c, 0x3c040001, 0x8c840f44,
4745 0x8fab0014, 0x24430001, 0x0044102b, 0x3c010001, 0xac230f3c, 0x14400003,
4746 0x00004021, 0x3c010001, 0xac200f3c, 0x3c020001, 0x8c420f3c, 0x3c030001,
4747 0x8c630f40, 0x91240000, 0x00021140, 0x00431021, 0x00481021, 0x25080001,
4748 0xa0440000, 0x29020008, 0x1440fff4, 0x25290001, 0x3c020001, 0x8c420f3c,
4749 0x3c030001, 0x8c630f40, 0x8f64680c, 0x00021140, 0x00431021, 0xac440008,
4750 0xac45000c, 0xac460010, 0xac470014, 0xac4a0018, 0x03e00008, 0xac4b001c,
4751 0x00000000, 0x00000000, 0x00000000,
4754 static u32 tg3Tso5FwRodata[(TG3_TSO5_FW_RODATA_LEN / 4) + 1] = {
4755 0x4d61696e, 0x43707542, 0x00000000, 0x4d61696e, 0x43707541, 0x00000000,
4756 0x00000000, 0x00000000, 0x73746b6f, 0x66666c64, 0x00000000, 0x00000000,
4757 0x73746b6f, 0x66666c64, 0x00000000, 0x00000000, 0x66617461, 0x6c457272,
4758 0x00000000, 0x00000000, 0x00000000,
4761 static u32 tg3Tso5FwData[(TG3_TSO5_FW_DATA_LEN / 4) + 1] = {
4762 0x00000000, 0x73746b6f, 0x66666c64, 0x5f76312e, 0x322e3000, 0x00000000,
4763 0x00000000, 0x00000000, 0x00000000,
4766 /* tp->lock is held. */
4767 static int tg3_load_tso_firmware(struct tg3 *tp)
4769 struct fw_info info;
4770 unsigned long cpu_base, cpu_scratch_base, cpu_scratch_size;
4773 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750)
4776 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) {
4777 info.text_base = TG3_TSO5_FW_TEXT_ADDR;
4778 info.text_len = TG3_TSO5_FW_TEXT_LEN;
4779 info.text_data = &tg3Tso5FwText[0];
4780 info.rodata_base = TG3_TSO5_FW_RODATA_ADDR;
4781 info.rodata_len = TG3_TSO5_FW_RODATA_LEN;
4782 info.rodata_data = &tg3Tso5FwRodata[0];
4783 info.data_base = TG3_TSO5_FW_DATA_ADDR;
4784 info.data_len = TG3_TSO5_FW_DATA_LEN;
4785 info.data_data = &tg3Tso5FwData[0];
4786 cpu_base = RX_CPU_BASE;
4787 cpu_scratch_base = NIC_SRAM_MBUF_POOL_BASE5705;
4788 cpu_scratch_size = (info.text_len +
4791 TG3_TSO5_FW_SBSS_LEN +
4792 TG3_TSO5_FW_BSS_LEN);
4794 info.text_base = TG3_TSO_FW_TEXT_ADDR;
4795 info.text_len = TG3_TSO_FW_TEXT_LEN;
4796 info.text_data = &tg3TsoFwText[0];
4797 info.rodata_base = TG3_TSO_FW_RODATA_ADDR;
4798 info.rodata_len = TG3_TSO_FW_RODATA_LEN;
4799 info.rodata_data = &tg3TsoFwRodata[0];
4800 info.data_base = TG3_TSO_FW_DATA_ADDR;
4801 info.data_len = TG3_TSO_FW_DATA_LEN;
4802 info.data_data = &tg3TsoFwData[0];
4803 cpu_base = TX_CPU_BASE;
4804 cpu_scratch_base = TX_CPU_SCRATCH_BASE;
4805 cpu_scratch_size = TX_CPU_SCRATCH_SIZE;
4808 err = tg3_load_firmware_cpu(tp, cpu_base,
4809 cpu_scratch_base, cpu_scratch_size,
4814 /* Now startup the cpu. */
4815 tw32(cpu_base + CPU_STATE, 0xffffffff);
4816 tw32_f(cpu_base + CPU_PC, info.text_base);
4818 for (i = 0; i < 5; i++) {
4819 if (tr32(cpu_base + CPU_PC) == info.text_base)
4821 tw32(cpu_base + CPU_STATE, 0xffffffff);
4822 tw32(cpu_base + CPU_MODE, CPU_MODE_HALT);
4823 tw32_f(cpu_base + CPU_PC, info.text_base);
4827 printk(KERN_ERR PFX "tg3_load_tso_firmware fails for %s "
4828 "to set CPU PC, is %08x should be %08x\n",
4829 tp->dev->name, tr32(cpu_base + CPU_PC),
4833 tw32(cpu_base + CPU_STATE, 0xffffffff);
4834 tw32_f(cpu_base + CPU_MODE, 0x00000000);
4838 #endif /* TG3_TSO_SUPPORT != 0 */
4840 /* tp->lock is held. */
4841 static void __tg3_set_mac_addr(struct tg3 *tp)
4843 u32 addr_high, addr_low;
4846 addr_high = ((tp->dev->dev_addr[0] << 8) |
4847 tp->dev->dev_addr[1]);
4848 addr_low = ((tp->dev->dev_addr[2] << 24) |
4849 (tp->dev->dev_addr[3] << 16) |
4850 (tp->dev->dev_addr[4] << 8) |
4851 (tp->dev->dev_addr[5] << 0));
4852 for (i = 0; i < 4; i++) {
4853 tw32(MAC_ADDR_0_HIGH + (i * 8), addr_high);
4854 tw32(MAC_ADDR_0_LOW + (i * 8), addr_low);
4857 if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 &&
4858 GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701 &&
4859 GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5705) {
4860 for (i = 0; i < 12; i++) {
4861 tw32(MAC_EXTADDR_0_HIGH + (i * 8), addr_high);
4862 tw32(MAC_EXTADDR_0_LOW + (i * 8), addr_low);
4866 addr_high = (tp->dev->dev_addr[0] +
4867 tp->dev->dev_addr[1] +
4868 tp->dev->dev_addr[2] +
4869 tp->dev->dev_addr[3] +
4870 tp->dev->dev_addr[4] +
4871 tp->dev->dev_addr[5]) &
4872 TX_BACKOFF_SEED_MASK;
4873 tw32(MAC_TX_BACKOFF_SEED, addr_high);
4876 static int tg3_set_mac_addr(struct net_device *dev, void *p)
4878 struct tg3 *tp = netdev_priv(dev);
4879 struct sockaddr *addr = p;
4881 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
4883 spin_lock_irq(&tp->lock);
4884 __tg3_set_mac_addr(tp);
4885 spin_unlock_irq(&tp->lock);
4890 /* tp->lock is held. */
4891 static void tg3_set_bdinfo(struct tg3 *tp, u32 bdinfo_addr,
4892 dma_addr_t mapping, u32 maxlen_flags,
4896 (bdinfo_addr + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH),
4897 ((u64) mapping >> 32));
4899 (bdinfo_addr + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW),
4900 ((u64) mapping & 0xffffffff));
4902 (bdinfo_addr + TG3_BDINFO_MAXLEN_FLAGS),
4905 if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5705)
4907 (bdinfo_addr + TG3_BDINFO_NIC_ADDR),
4911 static void __tg3_set_rx_mode(struct net_device *);
4913 /* tp->lock is held. */
4914 static int tg3_reset_hw(struct tg3 *tp)
4916 u32 val, rdmac_mode;
4919 tg3_disable_ints(tp);
4923 tg3_write_sig_pre_reset(tp, RESET_KIND_INIT);
4925 if (tp->tg3_flags & TG3_FLAG_INIT_COMPLETE) {
4926 err = tg3_abort_hw(tp);
4931 err = tg3_chip_reset(tp);
4935 tg3_write_sig_legacy(tp, RESET_KIND_INIT);
4937 /* This works around an issue with Athlon chipsets on
4938 * B3 tigon3 silicon. This bit has no effect on any
4939 * other revision. But do not set this on PCI Express
4942 if (!(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS))
4943 tp->pci_clock_ctrl |= CLOCK_CTRL_DELAY_PCI_GRANT;
4944 tw32_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl);
4946 if (tp->pci_chip_rev_id == CHIPREV_ID_5704_A0 &&
4947 (tp->tg3_flags & TG3_FLAG_PCIX_MODE)) {
4948 val = tr32(TG3PCI_PCISTATE);
4949 val |= PCISTATE_RETRY_SAME_DMA;
4950 tw32(TG3PCI_PCISTATE, val);
4953 if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5704_BX) {
4954 /* Enable some hw fixes. */
4955 val = tr32(TG3PCI_MSI_DATA);
4956 val |= (1 << 26) | (1 << 28) | (1 << 29);
4957 tw32(TG3PCI_MSI_DATA, val);
4960 /* Descriptor ring init may make accesses to the
4961 * NIC SRAM area to setup the TX descriptors, so we
4962 * can only do this after the hardware has been
4963 * successfully reset.
4967 /* This value is determined during the probe time DMA
4968 * engine test, tg3_test_dma.
4970 tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl);
4972 tp->grc_mode &= ~(GRC_MODE_HOST_SENDBDS |
4973 GRC_MODE_4X_NIC_SEND_RINGS |
4974 GRC_MODE_NO_TX_PHDR_CSUM |
4975 GRC_MODE_NO_RX_PHDR_CSUM);
4976 tp->grc_mode |= GRC_MODE_HOST_SENDBDS;
4977 if (tp->tg3_flags & TG3_FLAG_NO_TX_PSEUDO_CSUM)
4978 tp->grc_mode |= GRC_MODE_NO_TX_PHDR_CSUM;
4979 if (tp->tg3_flags & TG3_FLAG_NO_RX_PSEUDO_CSUM)
4980 tp->grc_mode |= GRC_MODE_NO_RX_PHDR_CSUM;
4984 (GRC_MODE_IRQ_ON_MAC_ATTN | GRC_MODE_HOST_STACKUP));
4986 /* Setup the timer prescalar register. Clock is always 66Mhz. */
4987 val = tr32(GRC_MISC_CFG);
4989 val |= (65 << GRC_MISC_CFG_PRESCALAR_SHIFT);
4990 tw32(GRC_MISC_CFG, val);
4992 /* Initialize MBUF/DESC pool. */
4993 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750) {
4995 } else if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5705) {
4996 tw32(BUFMGR_MB_POOL_ADDR, NIC_SRAM_MBUF_POOL_BASE);
4997 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704)
4998 tw32(BUFMGR_MB_POOL_SIZE, NIC_SRAM_MBUF_POOL_SIZE64);
5000 tw32(BUFMGR_MB_POOL_SIZE, NIC_SRAM_MBUF_POOL_SIZE96);
5001 tw32(BUFMGR_DMA_DESC_POOL_ADDR, NIC_SRAM_DMA_DESC_POOL_BASE);
5002 tw32(BUFMGR_DMA_DESC_POOL_SIZE, NIC_SRAM_DMA_DESC_POOL_SIZE);
5004 #if TG3_TSO_SUPPORT != 0
5005 else if (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) {
5008 fw_len = (TG3_TSO5_FW_TEXT_LEN +
5009 TG3_TSO5_FW_RODATA_LEN +
5010 TG3_TSO5_FW_DATA_LEN +
5011 TG3_TSO5_FW_SBSS_LEN +
5012 TG3_TSO5_FW_BSS_LEN);
5013 fw_len = (fw_len + (0x80 - 1)) & ~(0x80 - 1);
5014 tw32(BUFMGR_MB_POOL_ADDR,
5015 NIC_SRAM_MBUF_POOL_BASE5705 + fw_len);
5016 tw32(BUFMGR_MB_POOL_SIZE,
5017 NIC_SRAM_MBUF_POOL_SIZE5705 - fw_len - 0xa00);
5021 if (!(tp->tg3_flags & TG3_FLAG_JUMBO_ENABLE)) {
5022 tw32(BUFMGR_MB_RDMA_LOW_WATER,
5023 tp->bufmgr_config.mbuf_read_dma_low_water);
5024 tw32(BUFMGR_MB_MACRX_LOW_WATER,
5025 tp->bufmgr_config.mbuf_mac_rx_low_water);
5026 tw32(BUFMGR_MB_HIGH_WATER,
5027 tp->bufmgr_config.mbuf_high_water);
5029 tw32(BUFMGR_MB_RDMA_LOW_WATER,
5030 tp->bufmgr_config.mbuf_read_dma_low_water_jumbo);
5031 tw32(BUFMGR_MB_MACRX_LOW_WATER,
5032 tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo);
5033 tw32(BUFMGR_MB_HIGH_WATER,
5034 tp->bufmgr_config.mbuf_high_water_jumbo);
5036 tw32(BUFMGR_DMA_LOW_WATER,
5037 tp->bufmgr_config.dma_low_water);
5038 tw32(BUFMGR_DMA_HIGH_WATER,
5039 tp->bufmgr_config.dma_high_water);
5041 tw32(BUFMGR_MODE, BUFMGR_MODE_ENABLE | BUFMGR_MODE_ATTN_ENABLE);
5042 for (i = 0; i < 2000; i++) {
5043 if (tr32(BUFMGR_MODE) & BUFMGR_MODE_ENABLE)
5048 printk(KERN_ERR PFX "tg3_reset_hw cannot enable BUFMGR for %s.\n",
5053 /* Setup replenish threshold. */
5054 tw32(RCVBDI_STD_THRESH, tp->rx_pending / 8);
5056 /* Initialize TG3_BDINFO's at:
5057 * RCVDBDI_STD_BD: standard eth size rx ring
5058 * RCVDBDI_JUMBO_BD: jumbo frame rx ring
5059 * RCVDBDI_MINI_BD: small frame rx ring (??? does not work)
5062 * TG3_BDINFO_HOST_ADDR: high/low parts of DMA address of ring
5063 * TG3_BDINFO_MAXLEN_FLAGS: (rx max buffer size << 16) |
5064 * ring attribute flags
5065 * TG3_BDINFO_NIC_ADDR: location of descriptors in nic SRAM
5067 * Standard receive ring @ NIC_SRAM_RX_BUFFER_DESC, 512 entries.
5068 * Jumbo receive ring @ NIC_SRAM_RX_JUMBO_BUFFER_DESC, 256 entries.
5070 * The size of each ring is fixed in the firmware, but the location is
5073 tw32(RCVDBDI_STD_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH,
5074 ((u64) tp->rx_std_mapping >> 32));
5075 tw32(RCVDBDI_STD_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW,
5076 ((u64) tp->rx_std_mapping & 0xffffffff));
5077 tw32(RCVDBDI_STD_BD + TG3_BDINFO_NIC_ADDR,
5078 NIC_SRAM_RX_BUFFER_DESC);
5080 /* Don't even try to program the JUMBO/MINI buffer descriptor
5083 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 ||
5084 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750) {
5085 tw32(RCVDBDI_STD_BD + TG3_BDINFO_MAXLEN_FLAGS,
5086 RX_STD_MAX_SIZE_5705 << BDINFO_FLAGS_MAXLEN_SHIFT);
5088 tw32(RCVDBDI_STD_BD + TG3_BDINFO_MAXLEN_FLAGS,
5089 RX_STD_MAX_SIZE << BDINFO_FLAGS_MAXLEN_SHIFT);
5091 tw32(RCVDBDI_MINI_BD + TG3_BDINFO_MAXLEN_FLAGS,
5092 BDINFO_FLAGS_DISABLED);
5094 /* Setup replenish threshold. */
5095 tw32(RCVBDI_JUMBO_THRESH, tp->rx_jumbo_pending / 8);
5097 if (tp->tg3_flags & TG3_FLAG_JUMBO_ENABLE) {
5098 tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH,
5099 ((u64) tp->rx_jumbo_mapping >> 32));
5100 tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW,
5101 ((u64) tp->rx_jumbo_mapping & 0xffffffff));
5102 tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_MAXLEN_FLAGS,
5103 RX_JUMBO_MAX_SIZE << BDINFO_FLAGS_MAXLEN_SHIFT);
5104 tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_NIC_ADDR,
5105 NIC_SRAM_RX_JUMBO_BUFFER_DESC);
5107 tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_MAXLEN_FLAGS,
5108 BDINFO_FLAGS_DISABLED);
5113 /* There is only one send ring on 5705/5750, no need to explicitly
5114 * disable the others.
5116 if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5705 &&
5117 GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5750) {
5118 /* Clear out send RCB ring in SRAM. */
5119 for (i = NIC_SRAM_SEND_RCB; i < NIC_SRAM_RCV_RET_RCB; i += TG3_BDINFO_SIZE)
5120 tg3_write_mem(tp, i + TG3_BDINFO_MAXLEN_FLAGS,
5121 BDINFO_FLAGS_DISABLED);
5126 tw32_mailbox(MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW, 0);
5127 tw32_tx_mbox(MAILBOX_SNDNIC_PROD_IDX_0 + TG3_64BIT_REG_LOW, 0);
5129 tg3_set_bdinfo(tp, NIC_SRAM_SEND_RCB,
5130 tp->tx_desc_mapping,
5131 (TG3_TX_RING_SIZE <<
5132 BDINFO_FLAGS_MAXLEN_SHIFT),
5133 NIC_SRAM_TX_BUFFER_DESC);
5135 /* There is only one receive return ring on 5705/5750, no need
5136 * to explicitly disable the others.
5138 if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5705 &&
5139 GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5750) {
5140 for (i = NIC_SRAM_RCV_RET_RCB; i < NIC_SRAM_STATS_BLK;
5141 i += TG3_BDINFO_SIZE) {
5142 tg3_write_mem(tp, i + TG3_BDINFO_MAXLEN_FLAGS,
5143 BDINFO_FLAGS_DISABLED);
5148 tw32_rx_mbox(MAILBOX_RCVRET_CON_IDX_0 + TG3_64BIT_REG_LOW, 0);
5150 tg3_set_bdinfo(tp, NIC_SRAM_RCV_RET_RCB,
5152 (TG3_RX_RCB_RING_SIZE(tp) <<
5153 BDINFO_FLAGS_MAXLEN_SHIFT),
5156 tp->rx_std_ptr = tp->rx_pending;
5157 tw32_rx_mbox(MAILBOX_RCV_STD_PROD_IDX + TG3_64BIT_REG_LOW,
5160 tp->rx_jumbo_ptr = (tp->tg3_flags & TG3_FLAG_JUMBO_ENABLE) ?
5161 tp->rx_jumbo_pending : 0;
5162 tw32_rx_mbox(MAILBOX_RCV_JUMBO_PROD_IDX + TG3_64BIT_REG_LOW,
5165 /* Initialize MAC address and backoff seed. */
5166 __tg3_set_mac_addr(tp);
5168 /* MTU + ethernet header + FCS + optional VLAN tag */
5169 tw32(MAC_RX_MTU_SIZE, tp->dev->mtu + ETH_HLEN + 8);
5171 /* The slot time is changed by tg3_setup_phy if we
5172 * run at gigabit with half duplex.
5174 tw32(MAC_TX_LENGTHS,
5175 (2 << TX_LENGTHS_IPG_CRS_SHIFT) |
5176 (6 << TX_LENGTHS_IPG_SHIFT) |
5177 (32 << TX_LENGTHS_SLOT_TIME_SHIFT));
5179 /* Receive rules. */
5180 tw32(MAC_RCV_RULE_CFG, RCV_RULE_CFG_DEFAULT_CLASS);
5181 tw32(RCVLPC_CONFIG, 0x0181);
5183 /* Calculate RDMAC_MODE setting early, we need it to determine
5184 * the RCVLPC_STATE_ENABLE mask.
5186 rdmac_mode = (RDMAC_MODE_ENABLE | RDMAC_MODE_TGTABORT_ENAB |
5187 RDMAC_MODE_MSTABORT_ENAB | RDMAC_MODE_PARITYERR_ENAB |
5188 RDMAC_MODE_ADDROFLOW_ENAB | RDMAC_MODE_FIFOOFLOW_ENAB |
5189 RDMAC_MODE_FIFOURUN_ENAB | RDMAC_MODE_FIFOOREAD_ENAB |
5190 RDMAC_MODE_LNGREAD_ENAB);
5191 if (tp->tg3_flags & TG3_FLAG_SPLIT_MODE)
5192 rdmac_mode |= RDMAC_MODE_SPLIT_ENABLE;
5193 if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 &&
5194 tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) ||
5195 (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750)) {
5196 if (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE &&
5197 (tp->pci_chip_rev_id == CHIPREV_ID_5705_A1 ||
5198 tp->pci_chip_rev_id == CHIPREV_ID_5705_A2)) {
5199 rdmac_mode |= RDMAC_MODE_FIFO_SIZE_128;
5200 } else if (!(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH) &&
5201 !(tp->tg3_flags2 & TG3_FLG2_IS_5788)) {
5202 rdmac_mode |= RDMAC_MODE_FIFO_LONG_BURST;
5206 #if TG3_TSO_SUPPORT != 0
5207 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750)
5208 rdmac_mode |= (1 << 27);
5211 /* Receive/send statistics. */
5212 if ((rdmac_mode & RDMAC_MODE_FIFO_SIZE_128) &&
5213 (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE)) {
5214 val = tr32(RCVLPC_STATS_ENABLE);
5215 val &= ~RCVLPC_STATSENAB_LNGBRST_RFIX;
5216 tw32(RCVLPC_STATS_ENABLE, val);
5218 tw32(RCVLPC_STATS_ENABLE, 0xffffff);
5220 tw32(RCVLPC_STATSCTRL, RCVLPC_STATSCTRL_ENABLE);
5221 tw32(SNDDATAI_STATSENAB, 0xffffff);
5222 tw32(SNDDATAI_STATSCTRL,
5223 (SNDDATAI_SCTRL_ENABLE |
5224 SNDDATAI_SCTRL_FASTUPD));
5226 /* Setup host coalescing engine. */
5227 tw32(HOSTCC_MODE, 0);
5228 for (i = 0; i < 2000; i++) {
5229 if (!(tr32(HOSTCC_MODE) & HOSTCC_MODE_ENABLE))
5234 tw32(HOSTCC_RXCOL_TICKS, 0);
5235 tw32(HOSTCC_TXCOL_TICKS, LOW_TXCOL_TICKS);
5236 tw32(HOSTCC_RXMAX_FRAMES, 1);
5237 tw32(HOSTCC_TXMAX_FRAMES, LOW_RXMAX_FRAMES);
5238 if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5705 &&
5239 GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5750) {
5240 tw32(HOSTCC_RXCOAL_TICK_INT, 0);
5241 tw32(HOSTCC_TXCOAL_TICK_INT, 0);
5243 tw32(HOSTCC_RXCOAL_MAXF_INT, 1);
5244 tw32(HOSTCC_TXCOAL_MAXF_INT, 0);
5246 /* set status block DMA address */
5247 tw32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH,
5248 ((u64) tp->status_mapping >> 32));
5249 tw32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW,
5250 ((u64) tp->status_mapping & 0xffffffff));
5252 if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5705 &&
5253 GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5750) {
5254 /* Status/statistics block address. See tg3_timer,
5255 * the tg3_periodic_fetch_stats call there, and
5256 * tg3_get_stats to see how this works for 5705/5750 chips.
5258 tw32(HOSTCC_STAT_COAL_TICKS,
5259 DEFAULT_STAT_COAL_TICKS);
5260 tw32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH,
5261 ((u64) tp->stats_mapping >> 32));
5262 tw32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW,
5263 ((u64) tp->stats_mapping & 0xffffffff));
5264 tw32(HOSTCC_STATS_BLK_NIC_ADDR, NIC_SRAM_STATS_BLK);
5265 tw32(HOSTCC_STATUS_BLK_NIC_ADDR, NIC_SRAM_STATUS_BLK);
5268 tw32(HOSTCC_MODE, HOSTCC_MODE_ENABLE | tp->coalesce_mode);
5270 tw32(RCVCC_MODE, RCVCC_MODE_ENABLE | RCVCC_MODE_ATTN_ENABLE);
5271 tw32(RCVLPC_MODE, RCVLPC_MODE_ENABLE);
5272 if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5705 &&
5273 GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5750)
5274 tw32(RCVLSC_MODE, RCVLSC_MODE_ENABLE | RCVLSC_MODE_ATTN_ENABLE);
5276 /* Clear statistics/status block in chip, and status block in ram. */
5277 for (i = NIC_SRAM_STATS_BLK;
5278 i < NIC_SRAM_STATUS_BLK + TG3_HW_STATUS_SIZE;
5280 tg3_write_mem(tp, i, 0);
5283 memset(tp->hw_status, 0, TG3_HW_STATUS_SIZE);
5285 tp->mac_mode = MAC_MODE_TXSTAT_ENABLE | MAC_MODE_RXSTAT_ENABLE |
5286 MAC_MODE_TDE_ENABLE | MAC_MODE_RDE_ENABLE | MAC_MODE_FHDE_ENABLE;
5287 tw32_f(MAC_MODE, tp->mac_mode | MAC_MODE_RXSTAT_CLEAR | MAC_MODE_TXSTAT_CLEAR);
5290 tp->grc_local_ctrl = GRC_LCLCTRL_INT_ON_ATTN | GRC_LCLCTRL_AUTO_SEEPROM;
5291 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700)
5292 tp->grc_local_ctrl |= (GRC_LCLCTRL_GPIO_OE1 |
5293 GRC_LCLCTRL_GPIO_OUTPUT1);
5294 tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl);
5297 tw32_mailbox(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0);
5298 tr32(MAILBOX_INTERRUPT_0);
5300 if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5705 &&
5301 GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5750) {
5302 tw32_f(DMAC_MODE, DMAC_MODE_ENABLE);
5306 val = (WDMAC_MODE_ENABLE | WDMAC_MODE_TGTABORT_ENAB |
5307 WDMAC_MODE_MSTABORT_ENAB | WDMAC_MODE_PARITYERR_ENAB |
5308 WDMAC_MODE_ADDROFLOW_ENAB | WDMAC_MODE_FIFOOFLOW_ENAB |
5309 WDMAC_MODE_FIFOURUN_ENAB | WDMAC_MODE_FIFOOREAD_ENAB |
5310 WDMAC_MODE_LNGREAD_ENAB);
5312 if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 &&
5313 tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) ||
5314 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750) {
5315 if ((tp->tg3_flags & TG3_FLG2_TSO_CAPABLE) &&
5316 (tp->pci_chip_rev_id == CHIPREV_ID_5705_A1 ||
5317 tp->pci_chip_rev_id == CHIPREV_ID_5705_A2)) {
5319 } else if (!(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH) &&
5320 !(tp->tg3_flags2 & TG3_FLG2_IS_5788) &&
5321 !(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS)) {
5322 val |= WDMAC_MODE_RX_ACCEL;
5326 tw32_f(WDMAC_MODE, val);
5329 if ((tp->tg3_flags & TG3_FLAG_PCIX_MODE) != 0) {
5330 val = tr32(TG3PCI_X_CAPS);
5331 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703) {
5332 val &= ~PCIX_CAPS_BURST_MASK;
5333 val |= (PCIX_CAPS_MAX_BURST_CPIOB << PCIX_CAPS_BURST_SHIFT);
5334 } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) {
5335 val &= ~(PCIX_CAPS_SPLIT_MASK | PCIX_CAPS_BURST_MASK);
5336 val |= (PCIX_CAPS_MAX_BURST_CPIOB << PCIX_CAPS_BURST_SHIFT);
5337 if (tp->tg3_flags & TG3_FLAG_SPLIT_MODE)
5338 val |= (tp->split_mode_max_reqs <<
5339 PCIX_CAPS_SPLIT_SHIFT);
5341 tw32(TG3PCI_X_CAPS, val);
5344 tw32_f(RDMAC_MODE, rdmac_mode);
5347 tw32(RCVDCC_MODE, RCVDCC_MODE_ENABLE | RCVDCC_MODE_ATTN_ENABLE);
5348 if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5705 &&
5349 GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5750)
5350 tw32(MBFREE_MODE, MBFREE_MODE_ENABLE);
5351 tw32(SNDDATAC_MODE, SNDDATAC_MODE_ENABLE);
5352 tw32(SNDBDC_MODE, SNDBDC_MODE_ENABLE | SNDBDC_MODE_ATTN_ENABLE);
5353 tw32(RCVBDI_MODE, RCVBDI_MODE_ENABLE | RCVBDI_MODE_RCB_ATTN_ENAB);
5354 tw32(RCVDBDI_MODE, RCVDBDI_MODE_ENABLE | RCVDBDI_MODE_INV_RING_SZ);
5355 tw32(SNDDATAI_MODE, SNDDATAI_MODE_ENABLE);
5356 #if TG3_TSO_SUPPORT != 0
5357 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750)
5358 tw32(SNDDATAI_MODE, SNDDATAI_MODE_ENABLE | 0x8);
5360 tw32(SNDBDI_MODE, SNDBDI_MODE_ENABLE | SNDBDI_MODE_ATTN_ENABLE);
5361 tw32(SNDBDS_MODE, SNDBDS_MODE_ENABLE | SNDBDS_MODE_ATTN_ENABLE);
5363 if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0) {
5364 err = tg3_load_5701_a0_firmware_fix(tp);
5369 #if TG3_TSO_SUPPORT != 0
5370 if (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) {
5371 err = tg3_load_tso_firmware(tp);
5377 tp->tx_mode = TX_MODE_ENABLE;
5378 tw32_f(MAC_TX_MODE, tp->tx_mode);
5381 tp->rx_mode = RX_MODE_ENABLE;
5382 tw32_f(MAC_RX_MODE, tp->rx_mode);
5385 if (tp->link_config.phy_is_low_power) {
5386 tp->link_config.phy_is_low_power = 0;
5387 tp->link_config.speed = tp->link_config.orig_speed;
5388 tp->link_config.duplex = tp->link_config.orig_duplex;
5389 tp->link_config.autoneg = tp->link_config.orig_autoneg;
5392 tp->mi_mode = MAC_MI_MODE_BASE;
5393 tw32_f(MAC_MI_MODE, tp->mi_mode);
5396 tw32(MAC_LED_CTRL, tp->led_ctrl);
5398 tw32(MAC_MI_STAT, MAC_MI_STAT_LNKSTAT_ATTN_ENAB);
5399 if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) {
5400 tw32_f(MAC_RX_MODE, RX_MODE_RESET);
5403 tw32_f(MAC_RX_MODE, tp->rx_mode);
5406 if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) {
5407 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) {
5408 /* Set drive transmission level to 1.2V */
5409 val = tr32(MAC_SERDES_CFG);
5412 tw32(MAC_SERDES_CFG, val);
5414 if (tp->pci_chip_rev_id == CHIPREV_ID_5703_A1)
5415 tw32(MAC_SERDES_CFG, 0x616000);
5418 /* Prevent chip from dropping frames when flow control
5421 tw32_f(MAC_LOW_WMARK_MAX_RX_FRAME, 2);
5423 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 &&
5424 (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)) {
5425 /* Use hardware link auto-negotiation */
5426 tp->tg3_flags2 |= TG3_FLG2_HW_AUTONEG;
5429 err = tg3_setup_phy(tp, 1);
5433 if (!(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)) {
5436 /* Clear CRC stats. */
5437 tg3_readphy(tp, 0x1e, &tmp);
5438 tg3_writephy(tp, 0x1e, tmp | 0x8000);
5439 tg3_readphy(tp, 0x14, &tmp);
5442 __tg3_set_rx_mode(tp->dev);
5444 /* Initialize receive rules. */
5445 tw32(MAC_RCV_RULE_0, 0xc2000000 & RCV_RULE_DISABLE_MASK);
5446 tw32(MAC_RCV_VALUE_0, 0xffffffff & RCV_RULE_DISABLE_MASK);
5447 tw32(MAC_RCV_RULE_1, 0x86000004 & RCV_RULE_DISABLE_MASK);
5448 tw32(MAC_RCV_VALUE_1, 0xffffffff & RCV_RULE_DISABLE_MASK);
5450 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 ||
5451 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750)
5455 if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF)
5459 tw32(MAC_RCV_RULE_15, 0); tw32(MAC_RCV_VALUE_15, 0);
5461 tw32(MAC_RCV_RULE_14, 0); tw32(MAC_RCV_VALUE_14, 0);
5463 tw32(MAC_RCV_RULE_13, 0); tw32(MAC_RCV_VALUE_13, 0);
5465 tw32(MAC_RCV_RULE_12, 0); tw32(MAC_RCV_VALUE_12, 0);
5467 tw32(MAC_RCV_RULE_11, 0); tw32(MAC_RCV_VALUE_11, 0);
5469 tw32(MAC_RCV_RULE_10, 0); tw32(MAC_RCV_VALUE_10, 0);
5471 tw32(MAC_RCV_RULE_9, 0); tw32(MAC_RCV_VALUE_9, 0);
5473 tw32(MAC_RCV_RULE_8, 0); tw32(MAC_RCV_VALUE_8, 0);
5475 tw32(MAC_RCV_RULE_7, 0); tw32(MAC_RCV_VALUE_7, 0);
5477 tw32(MAC_RCV_RULE_6, 0); tw32(MAC_RCV_VALUE_6, 0);
5479 tw32(MAC_RCV_RULE_5, 0); tw32(MAC_RCV_VALUE_5, 0);
5481 tw32(MAC_RCV_RULE_4, 0); tw32(MAC_RCV_VALUE_4, 0);
5483 /* tw32(MAC_RCV_RULE_3, 0); tw32(MAC_RCV_VALUE_3, 0); */
5485 /* tw32(MAC_RCV_RULE_2, 0); tw32(MAC_RCV_VALUE_2, 0); */
5493 tg3_write_sig_post_reset(tp, RESET_KIND_INIT);
5495 if (tp->tg3_flags & TG3_FLAG_INIT_COMPLETE)
5496 tg3_enable_ints(tp);
5501 /* Called at device open time to get the chip ready for
5502 * packet processing. Invoked with tp->lock held.
5504 static int tg3_init_hw(struct tg3 *tp)
5508 /* Force the chip into D0. */
5509 err = tg3_set_power_state(tp, 0);
5513 tg3_switch_clocks(tp);
5515 tw32(TG3PCI_MEM_WIN_BASE_ADDR, 0);
5517 err = tg3_reset_hw(tp);
5523 #define TG3_STAT_ADD32(PSTAT, REG) \
5524 do { u32 __val = tr32(REG); \
5525 (PSTAT)->low += __val; \
5526 if ((PSTAT)->low < __val) \
5527 (PSTAT)->high += 1; \
5530 static void tg3_periodic_fetch_stats(struct tg3 *tp)
5532 struct tg3_hw_stats *sp = tp->hw_stats;
5534 if (!netif_carrier_ok(tp->dev))
5537 TG3_STAT_ADD32(&sp->tx_octets, MAC_TX_STATS_OCTETS);
5538 TG3_STAT_ADD32(&sp->tx_collisions, MAC_TX_STATS_COLLISIONS);
5539 TG3_STAT_ADD32(&sp->tx_xon_sent, MAC_TX_STATS_XON_SENT);
5540 TG3_STAT_ADD32(&sp->tx_xoff_sent, MAC_TX_STATS_XOFF_SENT);
5541 TG3_STAT_ADD32(&sp->tx_mac_errors, MAC_TX_STATS_MAC_ERRORS);
5542 TG3_STAT_ADD32(&sp->tx_single_collisions, MAC_TX_STATS_SINGLE_COLLISIONS);
5543 TG3_STAT_ADD32(&sp->tx_mult_collisions, MAC_TX_STATS_MULT_COLLISIONS);
5544 TG3_STAT_ADD32(&sp->tx_deferred, MAC_TX_STATS_DEFERRED);
5545 TG3_STAT_ADD32(&sp->tx_excessive_collisions, MAC_TX_STATS_EXCESSIVE_COL);
5546 TG3_STAT_ADD32(&sp->tx_late_collisions, MAC_TX_STATS_LATE_COL);
5547 TG3_STAT_ADD32(&sp->tx_ucast_packets, MAC_TX_STATS_UCAST);
5548 TG3_STAT_ADD32(&sp->tx_mcast_packets, MAC_TX_STATS_MCAST);
5549 TG3_STAT_ADD32(&sp->tx_bcast_packets, MAC_TX_STATS_BCAST);
5551 TG3_STAT_ADD32(&sp->rx_octets, MAC_RX_STATS_OCTETS);
5552 TG3_STAT_ADD32(&sp->rx_fragments, MAC_RX_STATS_FRAGMENTS);
5553 TG3_STAT_ADD32(&sp->rx_ucast_packets, MAC_RX_STATS_UCAST);
5554 TG3_STAT_ADD32(&sp->rx_mcast_packets, MAC_RX_STATS_MCAST);
5555 TG3_STAT_ADD32(&sp->rx_bcast_packets, MAC_RX_STATS_BCAST);
5556 TG3_STAT_ADD32(&sp->rx_fcs_errors, MAC_RX_STATS_FCS_ERRORS);
5557 TG3_STAT_ADD32(&sp->rx_align_errors, MAC_RX_STATS_ALIGN_ERRORS);
5558 TG3_STAT_ADD32(&sp->rx_xon_pause_rcvd, MAC_RX_STATS_XON_PAUSE_RECVD);
5559 TG3_STAT_ADD32(&sp->rx_xoff_pause_rcvd, MAC_RX_STATS_XOFF_PAUSE_RECVD);
5560 TG3_STAT_ADD32(&sp->rx_mac_ctrl_rcvd, MAC_RX_STATS_MAC_CTRL_RECVD);
5561 TG3_STAT_ADD32(&sp->rx_xoff_entered, MAC_RX_STATS_XOFF_ENTERED);
5562 TG3_STAT_ADD32(&sp->rx_frame_too_long_errors, MAC_RX_STATS_FRAME_TOO_LONG);
5563 TG3_STAT_ADD32(&sp->rx_jabbers, MAC_RX_STATS_JABBERS);
5564 TG3_STAT_ADD32(&sp->rx_undersize_packets, MAC_RX_STATS_UNDERSIZE);
5567 static void tg3_timer(unsigned long __opaque)
5569 struct tg3 *tp = (struct tg3 *) __opaque;
5570 unsigned long flags;
5572 spin_lock_irqsave(&tp->lock, flags);
5573 spin_lock(&tp->tx_lock);
5575 /* All of this garbage is because when using non-tagged
5576 * IRQ status the mailbox/status_block protocol the chip
5577 * uses with the cpu is race prone.
5579 if (tp->hw_status->status & SD_STATUS_UPDATED) {
5580 tw32(GRC_LOCAL_CTRL,
5581 tp->grc_local_ctrl | GRC_LCLCTRL_SETINT);
5583 tw32(HOSTCC_MODE, tp->coalesce_mode |
5584 (HOSTCC_MODE_ENABLE | HOSTCC_MODE_NOW));
5587 if (!(tr32(WDMAC_MODE) & WDMAC_MODE_ENABLE)) {
5588 tp->tg3_flags2 |= TG3_FLG2_RESTART_TIMER;
5589 spin_unlock(&tp->tx_lock);
5590 spin_unlock_irqrestore(&tp->lock, flags);
5591 schedule_work(&tp->reset_task);
5595 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 ||
5596 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750)
5597 tg3_periodic_fetch_stats(tp);
5599 /* This part only runs once per second. */
5600 if (!--tp->timer_counter) {
5601 if (tp->tg3_flags & TG3_FLAG_USE_LINKCHG_REG) {
5605 mac_stat = tr32(MAC_STATUS);
5608 if (tp->tg3_flags & TG3_FLAG_USE_MI_INTERRUPT) {
5609 if (mac_stat & MAC_STATUS_MI_INTERRUPT)
5611 } else if (mac_stat & MAC_STATUS_LNKSTATE_CHANGED)
5615 tg3_setup_phy(tp, 0);
5616 } else if (tp->tg3_flags & TG3_FLAG_POLL_SERDES) {
5617 u32 mac_stat = tr32(MAC_STATUS);
5620 if (netif_carrier_ok(tp->dev) &&
5621 (mac_stat & MAC_STATUS_LNKSTATE_CHANGED)) {
5624 if (! netif_carrier_ok(tp->dev) &&
5625 (mac_stat & (MAC_STATUS_PCS_SYNCED |
5626 MAC_STATUS_SIGNAL_DET))) {
5632 ~MAC_MODE_PORT_MODE_MASK));
5634 tw32_f(MAC_MODE, tp->mac_mode);
5636 tg3_setup_phy(tp, 0);
5640 tp->timer_counter = tp->timer_multiplier;
5643 /* Heartbeat is only sent once every 120 seconds. */
5644 if (!--tp->asf_counter) {
5645 if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) {
5648 tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX, FWCMD_NICDRV_ALIVE);
5649 tg3_write_mem(tp, NIC_SRAM_FW_CMD_LEN_MBOX, 4);
5650 tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX, 3);
5651 val = tr32(GRC_RX_CPU_EVENT);
5653 tw32(GRC_RX_CPU_EVENT, val);
5655 tp->asf_counter = tp->asf_multiplier;
5658 spin_unlock(&tp->tx_lock);
5659 spin_unlock_irqrestore(&tp->lock, flags);
5661 tp->timer.expires = jiffies + tp->timer_offset;
5662 add_timer(&tp->timer);
5665 static int tg3_open(struct net_device *dev)
5667 struct tg3 *tp = netdev_priv(dev);
5670 spin_lock_irq(&tp->lock);
5671 spin_lock(&tp->tx_lock);
5673 tg3_disable_ints(tp);
5674 tp->tg3_flags &= ~TG3_FLAG_INIT_COMPLETE;
5676 spin_unlock(&tp->tx_lock);
5677 spin_unlock_irq(&tp->lock);
5679 /* The placement of this call is tied
5680 * to the setup and use of Host TX descriptors.
5682 err = tg3_alloc_consistent(tp);
5686 err = request_irq(dev->irq, tg3_interrupt,
5687 SA_SHIRQ, dev->name, dev);
5690 tg3_free_consistent(tp);
5694 spin_lock_irq(&tp->lock);
5695 spin_lock(&tp->tx_lock);
5697 err = tg3_init_hw(tp);
5702 tp->timer_offset = HZ / 10;
5703 tp->timer_counter = tp->timer_multiplier = 10;
5704 tp->asf_counter = tp->asf_multiplier = (10 * 120);
5706 init_timer(&tp->timer);
5707 tp->timer.expires = jiffies + tp->timer_offset;
5708 tp->timer.data = (unsigned long) tp;
5709 tp->timer.function = tg3_timer;
5710 add_timer(&tp->timer);
5712 tp->tg3_flags |= TG3_FLAG_INIT_COMPLETE;
5715 spin_unlock(&tp->tx_lock);
5716 spin_unlock_irq(&tp->lock);
5719 free_irq(dev->irq, dev);
5720 tg3_free_consistent(tp);
5724 spin_lock_irq(&tp->lock);
5725 spin_lock(&tp->tx_lock);
5727 tg3_enable_ints(tp);
5729 spin_unlock(&tp->tx_lock);
5730 spin_unlock_irq(&tp->lock);
5732 netif_start_queue(dev);
5738 /*static*/ void tg3_dump_state(struct tg3 *tp)
5740 u32 val32, val32_2, val32_3, val32_4, val32_5;
5744 pci_read_config_word(tp->pdev, PCI_STATUS, &val16);
5745 pci_read_config_dword(tp->pdev, TG3PCI_PCISTATE, &val32);
5746 printk("DEBUG: PCI status [%04x] TG3PCI state[%08x]\n",
5750 printk("DEBUG: MAC_MODE[%08x] MAC_STATUS[%08x]\n",
5751 tr32(MAC_MODE), tr32(MAC_STATUS));
5752 printk(" MAC_EVENT[%08x] MAC_LED_CTRL[%08x]\n",
5753 tr32(MAC_EVENT), tr32(MAC_LED_CTRL));
5754 printk("DEBUG: MAC_TX_MODE[%08x] MAC_TX_STATUS[%08x]\n",
5755 tr32(MAC_TX_MODE), tr32(MAC_TX_STATUS));
5756 printk(" MAC_RX_MODE[%08x] MAC_RX_STATUS[%08x]\n",
5757 tr32(MAC_RX_MODE), tr32(MAC_RX_STATUS));
5759 /* Send data initiator control block */
5760 printk("DEBUG: SNDDATAI_MODE[%08x] SNDDATAI_STATUS[%08x]\n",
5761 tr32(SNDDATAI_MODE), tr32(SNDDATAI_STATUS));
5762 printk(" SNDDATAI_STATSCTRL[%08x]\n",
5763 tr32(SNDDATAI_STATSCTRL));
5765 /* Send data completion control block */
5766 printk("DEBUG: SNDDATAC_MODE[%08x]\n", tr32(SNDDATAC_MODE));
5768 /* Send BD ring selector block */
5769 printk("DEBUG: SNDBDS_MODE[%08x] SNDBDS_STATUS[%08x]\n",
5770 tr32(SNDBDS_MODE), tr32(SNDBDS_STATUS));
5772 /* Send BD initiator control block */
5773 printk("DEBUG: SNDBDI_MODE[%08x] SNDBDI_STATUS[%08x]\n",
5774 tr32(SNDBDI_MODE), tr32(SNDBDI_STATUS));
5776 /* Send BD completion control block */
5777 printk("DEBUG: SNDBDC_MODE[%08x]\n", tr32(SNDBDC_MODE));
5779 /* Receive list placement control block */
5780 printk("DEBUG: RCVLPC_MODE[%08x] RCVLPC_STATUS[%08x]\n",
5781 tr32(RCVLPC_MODE), tr32(RCVLPC_STATUS));
5782 printk(" RCVLPC_STATSCTRL[%08x]\n",
5783 tr32(RCVLPC_STATSCTRL));
5785 /* Receive data and receive BD initiator control block */
5786 printk("DEBUG: RCVDBDI_MODE[%08x] RCVDBDI_STATUS[%08x]\n",
5787 tr32(RCVDBDI_MODE), tr32(RCVDBDI_STATUS));
5789 /* Receive data completion control block */
5790 printk("DEBUG: RCVDCC_MODE[%08x]\n",
5793 /* Receive BD initiator control block */
5794 printk("DEBUG: RCVBDI_MODE[%08x] RCVBDI_STATUS[%08x]\n",
5795 tr32(RCVBDI_MODE), tr32(RCVBDI_STATUS));
5797 /* Receive BD completion control block */
5798 printk("DEBUG: RCVCC_MODE[%08x] RCVCC_STATUS[%08x]\n",
5799 tr32(RCVCC_MODE), tr32(RCVCC_STATUS));
5801 /* Receive list selector control block */
5802 printk("DEBUG: RCVLSC_MODE[%08x] RCVLSC_STATUS[%08x]\n",
5803 tr32(RCVLSC_MODE), tr32(RCVLSC_STATUS));
5805 /* Mbuf cluster free block */
5806 printk("DEBUG: MBFREE_MODE[%08x] MBFREE_STATUS[%08x]\n",
5807 tr32(MBFREE_MODE), tr32(MBFREE_STATUS));
5809 /* Host coalescing control block */
5810 printk("DEBUG: HOSTCC_MODE[%08x] HOSTCC_STATUS[%08x]\n",
5811 tr32(HOSTCC_MODE), tr32(HOSTCC_STATUS));
5812 printk("DEBUG: HOSTCC_STATS_BLK_HOST_ADDR[%08x%08x]\n",
5813 tr32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH),
5814 tr32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW));
5815 printk("DEBUG: HOSTCC_STATUS_BLK_HOST_ADDR[%08x%08x]\n",
5816 tr32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH),
5817 tr32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW));
5818 printk("DEBUG: HOSTCC_STATS_BLK_NIC_ADDR[%08x]\n",
5819 tr32(HOSTCC_STATS_BLK_NIC_ADDR));
5820 printk("DEBUG: HOSTCC_STATUS_BLK_NIC_ADDR[%08x]\n",
5821 tr32(HOSTCC_STATUS_BLK_NIC_ADDR));
5823 /* Memory arbiter control block */
5824 printk("DEBUG: MEMARB_MODE[%08x] MEMARB_STATUS[%08x]\n",
5825 tr32(MEMARB_MODE), tr32(MEMARB_STATUS));
5827 /* Buffer manager control block */
5828 printk("DEBUG: BUFMGR_MODE[%08x] BUFMGR_STATUS[%08x]\n",
5829 tr32(BUFMGR_MODE), tr32(BUFMGR_STATUS));
5830 printk("DEBUG: BUFMGR_MB_POOL_ADDR[%08x] BUFMGR_MB_POOL_SIZE[%08x]\n",
5831 tr32(BUFMGR_MB_POOL_ADDR), tr32(BUFMGR_MB_POOL_SIZE));
5832 printk("DEBUG: BUFMGR_DMA_DESC_POOL_ADDR[%08x] "
5833 "BUFMGR_DMA_DESC_POOL_SIZE[%08x]\n",
5834 tr32(BUFMGR_DMA_DESC_POOL_ADDR),
5835 tr32(BUFMGR_DMA_DESC_POOL_SIZE));
5837 /* Read DMA control block */
5838 printk("DEBUG: RDMAC_MODE[%08x] RDMAC_STATUS[%08x]\n",
5839 tr32(RDMAC_MODE), tr32(RDMAC_STATUS));
5841 /* Write DMA control block */
5842 printk("DEBUG: WDMAC_MODE[%08x] WDMAC_STATUS[%08x]\n",
5843 tr32(WDMAC_MODE), tr32(WDMAC_STATUS));
5845 /* DMA completion block */
5846 printk("DEBUG: DMAC_MODE[%08x]\n",
5850 printk("DEBUG: GRC_MODE[%08x] GRC_MISC_CFG[%08x]\n",
5851 tr32(GRC_MODE), tr32(GRC_MISC_CFG));
5852 printk("DEBUG: GRC_LOCAL_CTRL[%08x]\n",
5853 tr32(GRC_LOCAL_CTRL));
5856 printk("DEBUG: RCVDBDI_JUMBO_BD[%08x%08x:%08x:%08x]\n",
5857 tr32(RCVDBDI_JUMBO_BD + 0x0),
5858 tr32(RCVDBDI_JUMBO_BD + 0x4),
5859 tr32(RCVDBDI_JUMBO_BD + 0x8),
5860 tr32(RCVDBDI_JUMBO_BD + 0xc));
5861 printk("DEBUG: RCVDBDI_STD_BD[%08x%08x:%08x:%08x]\n",
5862 tr32(RCVDBDI_STD_BD + 0x0),
5863 tr32(RCVDBDI_STD_BD + 0x4),
5864 tr32(RCVDBDI_STD_BD + 0x8),
5865 tr32(RCVDBDI_STD_BD + 0xc));
5866 printk("DEBUG: RCVDBDI_MINI_BD[%08x%08x:%08x:%08x]\n",
5867 tr32(RCVDBDI_MINI_BD + 0x0),
5868 tr32(RCVDBDI_MINI_BD + 0x4),
5869 tr32(RCVDBDI_MINI_BD + 0x8),
5870 tr32(RCVDBDI_MINI_BD + 0xc));
5872 tg3_read_mem(tp, NIC_SRAM_SEND_RCB + 0x0, &val32);
5873 tg3_read_mem(tp, NIC_SRAM_SEND_RCB + 0x4, &val32_2);
5874 tg3_read_mem(tp, NIC_SRAM_SEND_RCB + 0x8, &val32_3);
5875 tg3_read_mem(tp, NIC_SRAM_SEND_RCB + 0xc, &val32_4);
5876 printk("DEBUG: SRAM_SEND_RCB_0[%08x%08x:%08x:%08x]\n",
5877 val32, val32_2, val32_3, val32_4);
5879 tg3_read_mem(tp, NIC_SRAM_RCV_RET_RCB + 0x0, &val32);
5880 tg3_read_mem(tp, NIC_SRAM_RCV_RET_RCB + 0x4, &val32_2);
5881 tg3_read_mem(tp, NIC_SRAM_RCV_RET_RCB + 0x8, &val32_3);
5882 tg3_read_mem(tp, NIC_SRAM_RCV_RET_RCB + 0xc, &val32_4);
5883 printk("DEBUG: SRAM_RCV_RET_RCB_0[%08x%08x:%08x:%08x]\n",
5884 val32, val32_2, val32_3, val32_4);
5886 tg3_read_mem(tp, NIC_SRAM_STATUS_BLK + 0x0, &val32);
5887 tg3_read_mem(tp, NIC_SRAM_STATUS_BLK + 0x4, &val32_2);
5888 tg3_read_mem(tp, NIC_SRAM_STATUS_BLK + 0x8, &val32_3);
5889 tg3_read_mem(tp, NIC_SRAM_STATUS_BLK + 0xc, &val32_4);
5890 tg3_read_mem(tp, NIC_SRAM_STATUS_BLK + 0x10, &val32_5);
5891 printk("DEBUG: SRAM_STATUS_BLK[%08x:%08x:%08x:%08x:%08x]\n",
5892 val32, val32_2, val32_3, val32_4, val32_5);
5894 /* SW status block */
5895 printk("DEBUG: Host status block [%08x:%08x:(%04x:%04x:%04x):(%04x:%04x)]\n",
5896 tp->hw_status->status,
5897 tp->hw_status->status_tag,
5898 tp->hw_status->rx_jumbo_consumer,
5899 tp->hw_status->rx_consumer,
5900 tp->hw_status->rx_mini_consumer,
5901 tp->hw_status->idx[0].rx_producer,
5902 tp->hw_status->idx[0].tx_consumer);
5904 /* SW statistics block */
5905 printk("DEBUG: Host statistics block [%08x:%08x:%08x:%08x]\n",
5906 ((u32 *)tp->hw_stats)[0],
5907 ((u32 *)tp->hw_stats)[1],
5908 ((u32 *)tp->hw_stats)[2],
5909 ((u32 *)tp->hw_stats)[3]);
5912 printk("DEBUG: SNDHOST_PROD[%08x%08x] SNDNIC_PROD[%08x%08x]\n",
5913 tr32(MAILBOX_SNDHOST_PROD_IDX_0 + 0x0),
5914 tr32(MAILBOX_SNDHOST_PROD_IDX_0 + 0x4),
5915 tr32(MAILBOX_SNDNIC_PROD_IDX_0 + 0x0),
5916 tr32(MAILBOX_SNDNIC_PROD_IDX_0 + 0x4));
5918 /* NIC side send descriptors. */
5919 for (i = 0; i < 6; i++) {
5922 txd = tp->regs + NIC_SRAM_WIN_BASE + NIC_SRAM_TX_BUFFER_DESC
5923 + (i * sizeof(struct tg3_tx_buffer_desc));
5924 printk("DEBUG: NIC TXD(%d)[%08x:%08x:%08x:%08x]\n",
5926 readl(txd + 0x0), readl(txd + 0x4),
5927 readl(txd + 0x8), readl(txd + 0xc));
5930 /* NIC side RX descriptors. */
5931 for (i = 0; i < 6; i++) {
5934 rxd = tp->regs + NIC_SRAM_WIN_BASE + NIC_SRAM_RX_BUFFER_DESC
5935 + (i * sizeof(struct tg3_rx_buffer_desc));
5936 printk("DEBUG: NIC RXD_STD(%d)[0][%08x:%08x:%08x:%08x]\n",
5938 readl(rxd + 0x0), readl(rxd + 0x4),
5939 readl(rxd + 0x8), readl(rxd + 0xc));
5940 rxd += (4 * sizeof(u32));
5941 printk("DEBUG: NIC RXD_STD(%d)[1][%08x:%08x:%08x:%08x]\n",
5943 readl(rxd + 0x0), readl(rxd + 0x4),
5944 readl(rxd + 0x8), readl(rxd + 0xc));
5947 for (i = 0; i < 6; i++) {
5950 rxd = tp->regs + NIC_SRAM_WIN_BASE + NIC_SRAM_RX_JUMBO_BUFFER_DESC
5951 + (i * sizeof(struct tg3_rx_buffer_desc));
5952 printk("DEBUG: NIC RXD_JUMBO(%d)[0][%08x:%08x:%08x:%08x]\n",
5954 readl(rxd + 0x0), readl(rxd + 0x4),
5955 readl(rxd + 0x8), readl(rxd + 0xc));
5956 rxd += (4 * sizeof(u32));
5957 printk("DEBUG: NIC RXD_JUMBO(%d)[1][%08x:%08x:%08x:%08x]\n",
5959 readl(rxd + 0x0), readl(rxd + 0x4),
5960 readl(rxd + 0x8), readl(rxd + 0xc));
5965 static struct net_device_stats *tg3_get_stats(struct net_device *);
5966 static struct tg3_ethtool_stats *tg3_get_estats(struct tg3 *);
5968 static int tg3_close(struct net_device *dev)
5970 struct tg3 *tp = netdev_priv(dev);
5972 netif_stop_queue(dev);
5974 del_timer_sync(&tp->timer);
5976 spin_lock_irq(&tp->lock);
5977 spin_lock(&tp->tx_lock);
5982 tg3_disable_ints(tp);
5987 ~(TG3_FLAG_INIT_COMPLETE |
5988 TG3_FLAG_GOT_SERDES_FLOWCTL);
5989 netif_carrier_off(tp->dev);
5991 spin_unlock(&tp->tx_lock);
5992 spin_unlock_irq(&tp->lock);
5994 free_irq(dev->irq, dev);
5996 memcpy(&tp->net_stats_prev, tg3_get_stats(tp->dev),
5997 sizeof(tp->net_stats_prev));
5998 memcpy(&tp->estats_prev, tg3_get_estats(tp),
5999 sizeof(tp->estats_prev));
6001 tg3_free_consistent(tp);
6006 static inline unsigned long get_stat64(tg3_stat64_t *val)
6010 #if (BITS_PER_LONG == 32)
6013 ret = ((u64)val->high << 32) | ((u64)val->low);
6018 static unsigned long calc_crc_errors(struct tg3 *tp)
6020 struct tg3_hw_stats *hw_stats = tp->hw_stats;
6022 if (!(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) &&
6023 (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
6024 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701)) {
6025 unsigned long flags;
6028 spin_lock_irqsave(&tp->lock, flags);
6029 tg3_readphy(tp, 0x1e, &val);
6030 tg3_writephy(tp, 0x1e, val | 0x8000);
6031 tg3_readphy(tp, 0x14, &val);
6032 spin_unlock_irqrestore(&tp->lock, flags);
6034 tp->phy_crc_errors += val;
6036 return tp->phy_crc_errors;
6039 return get_stat64(&hw_stats->rx_fcs_errors);
6042 #define ESTAT_ADD(member) \
6043 estats->member = old_estats->member + \
6044 get_stat64(&hw_stats->member)
6046 static struct tg3_ethtool_stats *tg3_get_estats(struct tg3 *tp)
6048 struct tg3_ethtool_stats *estats = &tp->estats;
6049 struct tg3_ethtool_stats *old_estats = &tp->estats_prev;
6050 struct tg3_hw_stats *hw_stats = tp->hw_stats;
6055 ESTAT_ADD(rx_octets);
6056 ESTAT_ADD(rx_fragments);
6057 ESTAT_ADD(rx_ucast_packets);
6058 ESTAT_ADD(rx_mcast_packets);
6059 ESTAT_ADD(rx_bcast_packets);
6060 ESTAT_ADD(rx_fcs_errors);
6061 ESTAT_ADD(rx_align_errors);
6062 ESTAT_ADD(rx_xon_pause_rcvd);
6063 ESTAT_ADD(rx_xoff_pause_rcvd);
6064 ESTAT_ADD(rx_mac_ctrl_rcvd);
6065 ESTAT_ADD(rx_xoff_entered);
6066 ESTAT_ADD(rx_frame_too_long_errors);
6067 ESTAT_ADD(rx_jabbers);
6068 ESTAT_ADD(rx_undersize_packets);
6069 ESTAT_ADD(rx_in_length_errors);
6070 ESTAT_ADD(rx_out_length_errors);
6071 ESTAT_ADD(rx_64_or_less_octet_packets);
6072 ESTAT_ADD(rx_65_to_127_octet_packets);
6073 ESTAT_ADD(rx_128_to_255_octet_packets);
6074 ESTAT_ADD(rx_256_to_511_octet_packets);
6075 ESTAT_ADD(rx_512_to_1023_octet_packets);
6076 ESTAT_ADD(rx_1024_to_1522_octet_packets);
6077 ESTAT_ADD(rx_1523_to_2047_octet_packets);
6078 ESTAT_ADD(rx_2048_to_4095_octet_packets);
6079 ESTAT_ADD(rx_4096_to_8191_octet_packets);
6080 ESTAT_ADD(rx_8192_to_9022_octet_packets);
6082 ESTAT_ADD(tx_octets);
6083 ESTAT_ADD(tx_collisions);
6084 ESTAT_ADD(tx_xon_sent);
6085 ESTAT_ADD(tx_xoff_sent);
6086 ESTAT_ADD(tx_flow_control);
6087 ESTAT_ADD(tx_mac_errors);
6088 ESTAT_ADD(tx_single_collisions);
6089 ESTAT_ADD(tx_mult_collisions);
6090 ESTAT_ADD(tx_deferred);
6091 ESTAT_ADD(tx_excessive_collisions);
6092 ESTAT_ADD(tx_late_collisions);
6093 ESTAT_ADD(tx_collide_2times);
6094 ESTAT_ADD(tx_collide_3times);
6095 ESTAT_ADD(tx_collide_4times);
6096 ESTAT_ADD(tx_collide_5times);
6097 ESTAT_ADD(tx_collide_6times);
6098 ESTAT_ADD(tx_collide_7times);
6099 ESTAT_ADD(tx_collide_8times);
6100 ESTAT_ADD(tx_collide_9times);
6101 ESTAT_ADD(tx_collide_10times);
6102 ESTAT_ADD(tx_collide_11times);
6103 ESTAT_ADD(tx_collide_12times);
6104 ESTAT_ADD(tx_collide_13times);
6105 ESTAT_ADD(tx_collide_14times);
6106 ESTAT_ADD(tx_collide_15times);
6107 ESTAT_ADD(tx_ucast_packets);
6108 ESTAT_ADD(tx_mcast_packets);
6109 ESTAT_ADD(tx_bcast_packets);
6110 ESTAT_ADD(tx_carrier_sense_errors);
6111 ESTAT_ADD(tx_discards);
6112 ESTAT_ADD(tx_errors);
6114 ESTAT_ADD(dma_writeq_full);
6115 ESTAT_ADD(dma_write_prioq_full);
6116 ESTAT_ADD(rxbds_empty);
6117 ESTAT_ADD(rx_discards);
6118 ESTAT_ADD(rx_errors);
6119 ESTAT_ADD(rx_threshold_hit);
6121 ESTAT_ADD(dma_readq_full);
6122 ESTAT_ADD(dma_read_prioq_full);
6123 ESTAT_ADD(tx_comp_queue_full);
6125 ESTAT_ADD(ring_set_send_prod_index);
6126 ESTAT_ADD(ring_status_update);
6127 ESTAT_ADD(nic_irqs);
6128 ESTAT_ADD(nic_avoided_irqs);
6129 ESTAT_ADD(nic_tx_threshold_hit);
6134 static struct net_device_stats *tg3_get_stats(struct net_device *dev)
6136 struct tg3 *tp = netdev_priv(dev);
6137 struct net_device_stats *stats = &tp->net_stats;
6138 struct net_device_stats *old_stats = &tp->net_stats_prev;
6139 struct tg3_hw_stats *hw_stats = tp->hw_stats;
6144 stats->rx_packets = old_stats->rx_packets +
6145 get_stat64(&hw_stats->rx_ucast_packets) +
6146 get_stat64(&hw_stats->rx_mcast_packets) +
6147 get_stat64(&hw_stats->rx_bcast_packets);
6149 stats->tx_packets = old_stats->tx_packets +
6150 get_stat64(&hw_stats->tx_ucast_packets) +
6151 get_stat64(&hw_stats->tx_mcast_packets) +
6152 get_stat64(&hw_stats->tx_bcast_packets);
6154 stats->rx_bytes = old_stats->rx_bytes +
6155 get_stat64(&hw_stats->rx_octets);
6156 stats->tx_bytes = old_stats->tx_bytes +
6157 get_stat64(&hw_stats->tx_octets);
6159 stats->rx_errors = old_stats->rx_errors +
6160 get_stat64(&hw_stats->rx_errors) +
6161 get_stat64(&hw_stats->rx_discards);
6162 stats->tx_errors = old_stats->tx_errors +
6163 get_stat64(&hw_stats->tx_errors) +
6164 get_stat64(&hw_stats->tx_mac_errors) +
6165 get_stat64(&hw_stats->tx_carrier_sense_errors) +
6166 get_stat64(&hw_stats->tx_discards);
6168 stats->multicast = old_stats->multicast +
6169 get_stat64(&hw_stats->rx_mcast_packets);
6170 stats->collisions = old_stats->collisions +
6171 get_stat64(&hw_stats->tx_collisions);
6173 stats->rx_length_errors = old_stats->rx_length_errors +
6174 get_stat64(&hw_stats->rx_frame_too_long_errors) +
6175 get_stat64(&hw_stats->rx_undersize_packets);
6177 stats->rx_over_errors = old_stats->rx_over_errors +
6178 get_stat64(&hw_stats->rxbds_empty);
6179 stats->rx_frame_errors = old_stats->rx_frame_errors +
6180 get_stat64(&hw_stats->rx_align_errors);
6181 stats->tx_aborted_errors = old_stats->tx_aborted_errors +
6182 get_stat64(&hw_stats->tx_discards);
6183 stats->tx_carrier_errors = old_stats->tx_carrier_errors +
6184 get_stat64(&hw_stats->tx_carrier_sense_errors);
6186 stats->rx_crc_errors = old_stats->rx_crc_errors +
6187 calc_crc_errors(tp);
6192 static inline u32 calc_crc(unsigned char *buf, int len)
6200 for (j = 0; j < len; j++) {
6203 for (k = 0; k < 8; k++) {
6217 static void tg3_set_multi(struct tg3 *tp, unsigned int accept_all)
6219 /* accept or reject all multicast frames */
6220 tw32(MAC_HASH_REG_0, accept_all ? 0xffffffff : 0);
6221 tw32(MAC_HASH_REG_1, accept_all ? 0xffffffff : 0);
6222 tw32(MAC_HASH_REG_2, accept_all ? 0xffffffff : 0);
6223 tw32(MAC_HASH_REG_3, accept_all ? 0xffffffff : 0);
6226 static void __tg3_set_rx_mode(struct net_device *dev)
6228 struct tg3 *tp = netdev_priv(dev);
6231 rx_mode = tp->rx_mode & ~(RX_MODE_PROMISC |
6232 RX_MODE_KEEP_VLAN_TAG);
6234 /* When ASF is in use, we always keep the RX_MODE_KEEP_VLAN_TAG
6237 #if TG3_VLAN_TAG_USED
6239 !(tp->tg3_flags & TG3_FLAG_ENABLE_ASF))
6240 rx_mode |= RX_MODE_KEEP_VLAN_TAG;
6242 /* By definition, VLAN is disabled always in this
6245 if (!(tp->tg3_flags & TG3_FLAG_ENABLE_ASF))
6246 rx_mode |= RX_MODE_KEEP_VLAN_TAG;
6249 if (dev->flags & IFF_PROMISC) {
6250 /* Promiscuous mode. */
6251 rx_mode |= RX_MODE_PROMISC;
6252 } else if (dev->flags & IFF_ALLMULTI) {
6253 /* Accept all multicast. */
6254 tg3_set_multi (tp, 1);
6255 } else if (dev->mc_count < 1) {
6256 /* Reject all multicast. */
6257 tg3_set_multi (tp, 0);
6259 /* Accept one or more multicast(s). */
6260 struct dev_mc_list *mclist;
6262 u32 mc_filter[4] = { 0, };
6267 for (i = 0, mclist = dev->mc_list; mclist && i < dev->mc_count;
6268 i++, mclist = mclist->next) {
6270 crc = calc_crc (mclist->dmi_addr, ETH_ALEN);
6272 regidx = (bit & 0x60) >> 5;
6274 mc_filter[regidx] |= (1 << bit);
6277 tw32(MAC_HASH_REG_0, mc_filter[0]);
6278 tw32(MAC_HASH_REG_1, mc_filter[1]);
6279 tw32(MAC_HASH_REG_2, mc_filter[2]);
6280 tw32(MAC_HASH_REG_3, mc_filter[3]);
6283 if (rx_mode != tp->rx_mode) {
6284 tp->rx_mode = rx_mode;
6285 tw32_f(MAC_RX_MODE, rx_mode);
6290 static void tg3_set_rx_mode(struct net_device *dev)
6292 struct tg3 *tp = netdev_priv(dev);
6294 spin_lock_irq(&tp->lock);
6295 spin_lock(&tp->tx_lock);
6296 __tg3_set_rx_mode(dev);
6297 spin_unlock(&tp->tx_lock);
6298 spin_unlock_irq(&tp->lock);
6301 #define TG3_REGDUMP_LEN (32 * 1024)
6303 static int tg3_get_regs_len(struct net_device *dev)
6305 return TG3_REGDUMP_LEN;
6308 static void tg3_get_regs(struct net_device *dev,
6309 struct ethtool_regs *regs, void *_p)
6312 struct tg3 *tp = netdev_priv(dev);
6318 memset(p, 0, TG3_REGDUMP_LEN);
6320 spin_lock_irq(&tp->lock);
6321 spin_lock(&tp->tx_lock);
6323 #define __GET_REG32(reg) (*(p)++ = tr32(reg))
6324 #define GET_REG32_LOOP(base,len) \
6325 do { p = (u32 *)(orig_p + (base)); \
6326 for (i = 0; i < len; i += 4) \
6327 __GET_REG32((base) + i); \
6329 #define GET_REG32_1(reg) \
6330 do { p = (u32 *)(orig_p + (reg)); \
6331 __GET_REG32((reg)); \
6334 GET_REG32_LOOP(TG3PCI_VENDOR, 0xb0);
6335 GET_REG32_LOOP(MAILBOX_INTERRUPT_0, 0x200);
6336 GET_REG32_LOOP(MAC_MODE, 0x4f0);
6337 GET_REG32_LOOP(SNDDATAI_MODE, 0xe0);
6338 GET_REG32_1(SNDDATAC_MODE);
6339 GET_REG32_LOOP(SNDBDS_MODE, 0x80);
6340 GET_REG32_LOOP(SNDBDI_MODE, 0x48);
6341 GET_REG32_1(SNDBDC_MODE);
6342 GET_REG32_LOOP(RCVLPC_MODE, 0x20);
6343 GET_REG32_LOOP(RCVLPC_SELLST_BASE, 0x15c);
6344 GET_REG32_LOOP(RCVDBDI_MODE, 0x0c);
6345 GET_REG32_LOOP(RCVDBDI_JUMBO_BD, 0x3c);
6346 GET_REG32_LOOP(RCVDBDI_BD_PROD_IDX_0, 0x44);
6347 GET_REG32_1(RCVDCC_MODE);
6348 GET_REG32_LOOP(RCVBDI_MODE, 0x20);
6349 GET_REG32_LOOP(RCVCC_MODE, 0x14);
6350 GET_REG32_LOOP(RCVLSC_MODE, 0x08);
6351 GET_REG32_1(MBFREE_MODE);
6352 GET_REG32_LOOP(HOSTCC_MODE, 0x100);
6353 GET_REG32_LOOP(MEMARB_MODE, 0x10);
6354 GET_REG32_LOOP(BUFMGR_MODE, 0x58);
6355 GET_REG32_LOOP(RDMAC_MODE, 0x08);
6356 GET_REG32_LOOP(WDMAC_MODE, 0x08);
6357 GET_REG32_LOOP(RX_CPU_BASE, 0x280);
6358 GET_REG32_LOOP(TX_CPU_BASE, 0x280);
6359 GET_REG32_LOOP(GRCMBOX_INTERRUPT_0, 0x110);
6360 GET_REG32_LOOP(FTQ_RESET, 0x120);
6361 GET_REG32_LOOP(MSGINT_MODE, 0x0c);
6362 GET_REG32_1(DMAC_MODE);
6363 GET_REG32_LOOP(GRC_MODE, 0x4c);
6364 if (tp->tg3_flags & TG3_FLAG_NVRAM)
6365 GET_REG32_LOOP(NVRAM_CMD, 0x24);
6368 #undef GET_REG32_LOOP
6371 spin_unlock(&tp->tx_lock);
6372 spin_unlock_irq(&tp->lock);
6375 static int tg3_get_eeprom_len(struct net_device *dev)
6377 return EEPROM_CHIP_SIZE;
6380 static int tg3_nvram_read_using_eeprom(struct tg3 *tp,
6381 u32 offset, u32 *val);
6382 static int tg3_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, u8 *data)
6384 struct tg3 *tp = netdev_priv(dev);
6387 u32 i, offset, len, val, b_offset, b_count;
6389 offset = eeprom->offset;
6393 ret = tg3_nvram_read_using_eeprom(tp, 0, &eeprom->magic);
6396 eeprom->magic = swab32(eeprom->magic);
6399 /* adjustments to start on required 4 byte boundary */
6400 b_offset = offset & 3;
6401 b_count = 4 - b_offset;
6402 if (b_count > len) {
6403 /* i.e. offset=1 len=2 */
6406 ret = tg3_nvram_read_using_eeprom(tp, offset-b_offset, &val);
6409 memcpy(data, ((char*)&val) + b_offset, b_count);
6412 eeprom->len += b_count;
6415 /* read bytes upto the last 4 byte boundary */
6416 pd = &data[eeprom->len];
6417 for (i = 0; i < (len - (len & 3)); i += 4) {
6418 ret = tg3_nvram_read_using_eeprom(tp, offset + i,
6428 /* read last bytes not ending on 4 byte boundary */
6429 pd = &data[eeprom->len];
6431 b_offset = offset + len - b_count;
6432 ret = tg3_nvram_read_using_eeprom(tp, b_offset, &val);
6435 memcpy(pd, ((char*)&val), b_count);
6436 eeprom->len += b_count;
6441 static int tg3_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
6443 struct tg3 *tp = netdev_priv(dev);
6445 if (!(tp->tg3_flags & TG3_FLAG_INIT_COMPLETE) ||
6446 tp->link_config.phy_is_low_power)
6449 cmd->supported = (SUPPORTED_Autoneg);
6451 if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY))
6452 cmd->supported |= (SUPPORTED_1000baseT_Half |
6453 SUPPORTED_1000baseT_Full);
6455 if (!(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES))
6456 cmd->supported |= (SUPPORTED_100baseT_Half |
6457 SUPPORTED_100baseT_Full |
6458 SUPPORTED_10baseT_Half |
6459 SUPPORTED_10baseT_Full |
6462 cmd->supported |= SUPPORTED_FIBRE;
6464 cmd->advertising = tp->link_config.advertising;
6465 cmd->speed = tp->link_config.active_speed;
6466 cmd->duplex = tp->link_config.active_duplex;
6468 cmd->phy_address = PHY_ADDR;
6469 cmd->transceiver = 0;
6470 cmd->autoneg = tp->link_config.autoneg;
6476 static int tg3_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
6478 struct tg3 *tp = netdev_priv(dev);
6480 if (!(tp->tg3_flags & TG3_FLAG_INIT_COMPLETE) ||
6481 tp->link_config.phy_is_low_power)
6484 if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) {
6485 /* These are the only valid advertisement bits allowed. */
6486 if (cmd->autoneg == AUTONEG_ENABLE &&
6487 (cmd->advertising & ~(ADVERTISED_1000baseT_Half |
6488 ADVERTISED_1000baseT_Full |
6489 ADVERTISED_Autoneg |
6494 spin_lock_irq(&tp->lock);
6495 spin_lock(&tp->tx_lock);
6497 tp->link_config.autoneg = cmd->autoneg;
6498 if (cmd->autoneg == AUTONEG_ENABLE) {
6499 tp->link_config.advertising = cmd->advertising;
6500 tp->link_config.speed = SPEED_INVALID;
6501 tp->link_config.duplex = DUPLEX_INVALID;
6503 tp->link_config.advertising = 0;
6504 tp->link_config.speed = cmd->speed;
6505 tp->link_config.duplex = cmd->duplex;
6508 tg3_setup_phy(tp, 1);
6509 spin_unlock(&tp->tx_lock);
6510 spin_unlock_irq(&tp->lock);
6515 static void tg3_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
6517 struct tg3 *tp = netdev_priv(dev);
6519 strcpy(info->driver, DRV_MODULE_NAME);
6520 strcpy(info->version, DRV_MODULE_VERSION);
6521 strcpy(info->bus_info, pci_name(tp->pdev));
6524 static void tg3_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
6526 struct tg3 *tp = netdev_priv(dev);
6528 wol->supported = WAKE_MAGIC;
6530 if (tp->tg3_flags & TG3_FLAG_WOL_ENABLE)
6531 wol->wolopts = WAKE_MAGIC;
6532 memset(&wol->sopass, 0, sizeof(wol->sopass));
6535 static int tg3_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
6537 struct tg3 *tp = netdev_priv(dev);
6539 if (wol->wolopts & ~WAKE_MAGIC)
6541 if ((wol->wolopts & WAKE_MAGIC) &&
6542 tp->tg3_flags2 & TG3_FLG2_PHY_SERDES &&
6543 !(tp->tg3_flags & TG3_FLAG_SERDES_WOL_CAP))
6546 spin_lock_irq(&tp->lock);
6547 if (wol->wolopts & WAKE_MAGIC)
6548 tp->tg3_flags |= TG3_FLAG_WOL_ENABLE;
6550 tp->tg3_flags &= ~TG3_FLAG_WOL_ENABLE;
6551 spin_unlock_irq(&tp->lock);
6556 static u32 tg3_get_msglevel(struct net_device *dev)
6558 struct tg3 *tp = netdev_priv(dev);
6559 return tp->msg_enable;
6562 static void tg3_set_msglevel(struct net_device *dev, u32 value)
6564 struct tg3 *tp = netdev_priv(dev);
6565 tp->msg_enable = value;
6568 #if TG3_TSO_SUPPORT != 0
6569 static int tg3_set_tso(struct net_device *dev, u32 value)
6571 struct tg3 *tp = netdev_priv(dev);
6573 if (!(tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE)) {
6578 return ethtool_op_set_tso(dev, value);
6582 static int tg3_nway_reset(struct net_device *dev)
6584 struct tg3 *tp = netdev_priv(dev);
6588 spin_lock_irq(&tp->lock);
6589 tg3_readphy(tp, MII_BMCR, &bmcr);
6590 tg3_readphy(tp, MII_BMCR, &bmcr);
6592 if (bmcr & BMCR_ANENABLE) {
6593 tg3_writephy(tp, MII_BMCR, bmcr | BMCR_ANRESTART);
6596 spin_unlock_irq(&tp->lock);
6601 static void tg3_get_ringparam(struct net_device *dev, struct ethtool_ringparam *ering)
6603 struct tg3 *tp = netdev_priv(dev);
6605 ering->rx_max_pending = TG3_RX_RING_SIZE - 1;
6606 ering->rx_mini_max_pending = 0;
6607 ering->rx_jumbo_max_pending = TG3_RX_JUMBO_RING_SIZE - 1;
6609 ering->rx_pending = tp->rx_pending;
6610 ering->rx_mini_pending = 0;
6611 ering->rx_jumbo_pending = tp->rx_jumbo_pending;
6612 ering->tx_pending = tp->tx_pending;
6615 static int tg3_set_ringparam(struct net_device *dev, struct ethtool_ringparam *ering)
6617 struct tg3 *tp = netdev_priv(dev);
6619 if ((ering->rx_pending > TG3_RX_RING_SIZE - 1) ||
6620 (ering->rx_jumbo_pending > TG3_RX_JUMBO_RING_SIZE - 1) ||
6621 (ering->tx_pending > TG3_TX_RING_SIZE - 1))
6625 spin_lock_irq(&tp->lock);
6626 spin_lock(&tp->tx_lock);
6628 tp->rx_pending = ering->rx_pending;
6630 if ((tp->tg3_flags2 & TG3_FLG2_MAX_RXPEND_64) &&
6631 tp->rx_pending > 63)
6632 tp->rx_pending = 63;
6633 tp->rx_jumbo_pending = ering->rx_jumbo_pending;
6634 tp->tx_pending = ering->tx_pending;
6638 tg3_netif_start(tp);
6639 spin_unlock(&tp->tx_lock);
6640 spin_unlock_irq(&tp->lock);
6645 static void tg3_get_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause)
6647 struct tg3 *tp = netdev_priv(dev);
6649 epause->autoneg = (tp->tg3_flags & TG3_FLAG_PAUSE_AUTONEG) != 0;
6650 epause->rx_pause = (tp->tg3_flags & TG3_FLAG_RX_PAUSE) != 0;
6651 epause->tx_pause = (tp->tg3_flags & TG3_FLAG_TX_PAUSE) != 0;
6654 static int tg3_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause)
6656 struct tg3 *tp = netdev_priv(dev);
6659 spin_lock_irq(&tp->lock);
6660 spin_lock(&tp->tx_lock);
6661 if (epause->autoneg)
6662 tp->tg3_flags |= TG3_FLAG_PAUSE_AUTONEG;
6664 tp->tg3_flags &= ~TG3_FLAG_PAUSE_AUTONEG;
6665 if (epause->rx_pause)
6666 tp->tg3_flags |= TG3_FLAG_RX_PAUSE;
6668 tp->tg3_flags &= ~TG3_FLAG_RX_PAUSE;
6669 if (epause->tx_pause)
6670 tp->tg3_flags |= TG3_FLAG_TX_PAUSE;
6672 tp->tg3_flags &= ~TG3_FLAG_TX_PAUSE;
6675 tg3_netif_start(tp);
6676 spin_unlock(&tp->tx_lock);
6677 spin_unlock_irq(&tp->lock);
6682 static u32 tg3_get_rx_csum(struct net_device *dev)
6684 struct tg3 *tp = netdev_priv(dev);
6685 return (tp->tg3_flags & TG3_FLAG_RX_CHECKSUMS) != 0;
6688 static int tg3_set_rx_csum(struct net_device *dev, u32 data)
6690 struct tg3 *tp = netdev_priv(dev);
6692 if (tp->tg3_flags & TG3_FLAG_BROKEN_CHECKSUMS) {
6698 spin_lock_irq(&tp->lock);
6700 tp->tg3_flags |= TG3_FLAG_RX_CHECKSUMS;
6702 tp->tg3_flags &= ~TG3_FLAG_RX_CHECKSUMS;
6703 spin_unlock_irq(&tp->lock);
6708 static int tg3_set_tx_csum(struct net_device *dev, u32 data)
6710 struct tg3 *tp = netdev_priv(dev);
6712 if (tp->tg3_flags & TG3_FLAG_BROKEN_CHECKSUMS) {
6719 dev->features |= NETIF_F_IP_CSUM;
6721 dev->features &= ~NETIF_F_IP_CSUM;
6726 static int tg3_get_stats_count (struct net_device *dev)
6728 return TG3_NUM_STATS;
6731 static void tg3_get_strings (struct net_device *dev, u32 stringset, u8 *buf)
6733 switch (stringset) {
6735 memcpy(buf, ðtool_stats_keys, sizeof(ethtool_stats_keys));
6738 WARN_ON(1); /* we need a WARN() */
6743 static void tg3_get_ethtool_stats (struct net_device *dev,
6744 struct ethtool_stats *estats, u64 *tmp_stats)
6746 struct tg3 *tp = netdev_priv(dev);
6747 memcpy(tmp_stats, tg3_get_estats(tp), sizeof(tp->estats));
6750 static int tg3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
6752 struct mii_ioctl_data *data = if_mii(ifr);
6753 struct tg3 *tp = netdev_priv(dev);
6758 data->phy_id = PHY_ADDR;
6764 if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)
6765 break; /* We have no PHY */
6767 spin_lock_irq(&tp->lock);
6768 err = tg3_readphy(tp, data->reg_num & 0x1f, &mii_regval);
6769 spin_unlock_irq(&tp->lock);
6771 data->val_out = mii_regval;
6777 if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)
6778 break; /* We have no PHY */
6780 if (!capable(CAP_NET_ADMIN))
6783 spin_lock_irq(&tp->lock);
6784 err = tg3_writephy(tp, data->reg_num & 0x1f, data->val_in);
6785 spin_unlock_irq(&tp->lock);
6796 #if TG3_VLAN_TAG_USED
6797 static void tg3_vlan_rx_register(struct net_device *dev, struct vlan_group *grp)
6799 struct tg3 *tp = netdev_priv(dev);
6801 spin_lock_irq(&tp->lock);
6802 spin_lock(&tp->tx_lock);
6806 /* Update RX_MODE_KEEP_VLAN_TAG bit in RX_MODE register. */
6807 __tg3_set_rx_mode(dev);
6809 spin_unlock(&tp->tx_lock);
6810 spin_unlock_irq(&tp->lock);
6813 static void tg3_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
6815 struct tg3 *tp = netdev_priv(dev);
6817 spin_lock_irq(&tp->lock);
6818 spin_lock(&tp->tx_lock);
6820 tp->vlgrp->vlan_devices[vid] = NULL;
6821 spin_unlock(&tp->tx_lock);
6822 spin_unlock_irq(&tp->lock);
6826 static struct ethtool_ops tg3_ethtool_ops = {
6827 .get_settings = tg3_get_settings,
6828 .set_settings = tg3_set_settings,
6829 .get_drvinfo = tg3_get_drvinfo,
6830 .get_regs_len = tg3_get_regs_len,
6831 .get_regs = tg3_get_regs,
6832 .get_wol = tg3_get_wol,
6833 .set_wol = tg3_set_wol,
6834 .get_msglevel = tg3_get_msglevel,
6835 .set_msglevel = tg3_set_msglevel,
6836 .nway_reset = tg3_nway_reset,
6837 .get_link = ethtool_op_get_link,
6838 .get_eeprom_len = tg3_get_eeprom_len,
6839 .get_eeprom = tg3_get_eeprom,
6840 .get_ringparam = tg3_get_ringparam,
6841 .set_ringparam = tg3_set_ringparam,
6842 .get_pauseparam = tg3_get_pauseparam,
6843 .set_pauseparam = tg3_set_pauseparam,
6844 .get_rx_csum = tg3_get_rx_csum,
6845 .set_rx_csum = tg3_set_rx_csum,
6846 .get_tx_csum = ethtool_op_get_tx_csum,
6847 .set_tx_csum = tg3_set_tx_csum,
6848 .get_sg = ethtool_op_get_sg,
6849 .set_sg = ethtool_op_set_sg,
6850 #if TG3_TSO_SUPPORT != 0
6851 .get_tso = ethtool_op_get_tso,
6852 .set_tso = tg3_set_tso,
6854 .get_strings = tg3_get_strings,
6855 .get_stats_count = tg3_get_stats_count,
6856 .get_ethtool_stats = tg3_get_ethtool_stats,
6859 /* Chips other than 5700/5701 use the NVRAM for fetching info. */
6860 static void __devinit tg3_nvram_init(struct tg3 *tp)
6864 if (tp->tg3_flags2 & TG3_FLG2_SUN_570X)
6867 tw32_f(GRC_EEPROM_ADDR,
6868 (EEPROM_ADDR_FSM_RESET |
6869 (EEPROM_DEFAULT_CLOCK_PERIOD <<
6870 EEPROM_ADDR_CLKPERD_SHIFT)));
6872 /* XXX schedule_timeout() ... */
6873 for (j = 0; j < 100; j++)
6876 /* Enable seeprom accesses. */
6877 tw32_f(GRC_LOCAL_CTRL,
6878 tr32(GRC_LOCAL_CTRL) | GRC_LCLCTRL_AUTO_SEEPROM);
6881 if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 &&
6882 GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) {
6885 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750) {
6886 u32 nvaccess = tr32(NVRAM_ACCESS);
6888 tw32_f(NVRAM_ACCESS, nvaccess | ACCESS_ENABLE);
6891 nvcfg1 = tr32(NVRAM_CFG1);
6893 tp->tg3_flags |= TG3_FLAG_NVRAM;
6894 if (nvcfg1 & NVRAM_CFG1_FLASHIF_ENAB) {
6895 if (nvcfg1 & NVRAM_CFG1_BUFFERED_MODE)
6896 tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
6898 nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS;
6899 tw32(NVRAM_CFG1, nvcfg1);
6902 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750) {
6903 u32 nvaccess = tr32(NVRAM_ACCESS);
6905 tw32_f(NVRAM_ACCESS, nvaccess & ~ACCESS_ENABLE);
6908 tp->tg3_flags &= ~(TG3_FLAG_NVRAM | TG3_FLAG_NVRAM_BUFFERED);
6912 static int tg3_nvram_read_using_eeprom(struct tg3 *tp,
6913 u32 offset, u32 *val)
6918 if (offset > EEPROM_ADDR_ADDR_MASK ||
6922 tmp = tr32(GRC_EEPROM_ADDR) & ~(EEPROM_ADDR_ADDR_MASK |
6923 EEPROM_ADDR_DEVID_MASK |
6925 tw32(GRC_EEPROM_ADDR,
6927 (0 << EEPROM_ADDR_DEVID_SHIFT) |
6928 ((offset << EEPROM_ADDR_ADDR_SHIFT) &
6929 EEPROM_ADDR_ADDR_MASK) |
6930 EEPROM_ADDR_READ | EEPROM_ADDR_START);
6932 for (i = 0; i < 10000; i++) {
6933 tmp = tr32(GRC_EEPROM_ADDR);
6935 if (tmp & EEPROM_ADDR_COMPLETE)
6939 if (!(tmp & EEPROM_ADDR_COMPLETE))
6942 *val = tr32(GRC_EEPROM_DATA);
6946 static int __devinit tg3_nvram_read(struct tg3 *tp,
6947 u32 offset, u32 *val)
6951 if (tp->tg3_flags2 & TG3_FLG2_SUN_570X) {
6952 printk(KERN_ERR PFX "Attempt to do nvram_read on Sun 570X\n");
6956 if (!(tp->tg3_flags & TG3_FLAG_NVRAM))
6957 return tg3_nvram_read_using_eeprom(tp, offset, val);
6959 if (tp->tg3_flags & TG3_FLAG_NVRAM_BUFFERED)
6960 offset = ((offset / NVRAM_BUFFERED_PAGE_SIZE) <<
6961 NVRAM_BUFFERED_PAGE_POS) +
6962 (offset % NVRAM_BUFFERED_PAGE_SIZE);
6964 if (offset > NVRAM_ADDR_MSK)
6969 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750) {
6970 u32 nvaccess = tr32(NVRAM_ACCESS);
6972 tw32_f(NVRAM_ACCESS, nvaccess | ACCESS_ENABLE);
6975 tw32(NVRAM_ADDR, offset);
6977 NVRAM_CMD_RD | NVRAM_CMD_GO |
6978 NVRAM_CMD_FIRST | NVRAM_CMD_LAST | NVRAM_CMD_DONE);
6980 /* Wait for done bit to clear. */
6981 for (i = 0; i < 1000; i++) {
6983 if (tr32(NVRAM_CMD) & NVRAM_CMD_DONE) {
6985 *val = swab32(tr32(NVRAM_RDDATA));
6990 tg3_nvram_unlock(tp);
6992 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750) {
6993 u32 nvaccess = tr32(NVRAM_ACCESS);
6995 tw32_f(NVRAM_ACCESS, nvaccess & ~ACCESS_ENABLE);
7004 struct subsys_tbl_ent {
7005 u16 subsys_vendor, subsys_devid;
7009 static struct subsys_tbl_ent subsys_id_to_phy_id[] = {
7010 /* Broadcom boards. */
7011 { PCI_VENDOR_ID_BROADCOM, 0x1644, PHY_ID_BCM5401 }, /* BCM95700A6 */
7012 { PCI_VENDOR_ID_BROADCOM, 0x0001, PHY_ID_BCM5701 }, /* BCM95701A5 */
7013 { PCI_VENDOR_ID_BROADCOM, 0x0002, PHY_ID_BCM8002 }, /* BCM95700T6 */
7014 { PCI_VENDOR_ID_BROADCOM, 0x0003, 0 }, /* BCM95700A9 */
7015 { PCI_VENDOR_ID_BROADCOM, 0x0005, PHY_ID_BCM5701 }, /* BCM95701T1 */
7016 { PCI_VENDOR_ID_BROADCOM, 0x0006, PHY_ID_BCM5701 }, /* BCM95701T8 */
7017 { PCI_VENDOR_ID_BROADCOM, 0x0007, 0 }, /* BCM95701A7 */
7018 { PCI_VENDOR_ID_BROADCOM, 0x0008, PHY_ID_BCM5701 }, /* BCM95701A10 */
7019 { PCI_VENDOR_ID_BROADCOM, 0x8008, PHY_ID_BCM5701 }, /* BCM95701A12 */
7020 { PCI_VENDOR_ID_BROADCOM, 0x0009, PHY_ID_BCM5703 }, /* BCM95703Ax1 */
7021 { PCI_VENDOR_ID_BROADCOM, 0x8009, PHY_ID_BCM5703 }, /* BCM95703Ax2 */
7024 { PCI_VENDOR_ID_3COM, 0x1000, PHY_ID_BCM5401 }, /* 3C996T */
7025 { PCI_VENDOR_ID_3COM, 0x1006, PHY_ID_BCM5701 }, /* 3C996BT */
7026 { PCI_VENDOR_ID_3COM, 0x1004, 0 }, /* 3C996SX */
7027 { PCI_VENDOR_ID_3COM, 0x1007, PHY_ID_BCM5701 }, /* 3C1000T */
7028 { PCI_VENDOR_ID_3COM, 0x1008, PHY_ID_BCM5701 }, /* 3C940BR01 */
7031 { PCI_VENDOR_ID_DELL, 0x00d1, PHY_ID_BCM5401 }, /* VIPER */
7032 { PCI_VENDOR_ID_DELL, 0x0106, PHY_ID_BCM5401 }, /* JAGUAR */
7033 { PCI_VENDOR_ID_DELL, 0x0109, PHY_ID_BCM5411 }, /* MERLOT */
7034 { PCI_VENDOR_ID_DELL, 0x010a, PHY_ID_BCM5411 }, /* SLIM_MERLOT */
7036 /* Compaq boards. */
7037 { PCI_VENDOR_ID_COMPAQ, 0x007c, PHY_ID_BCM5701 }, /* BANSHEE */
7038 { PCI_VENDOR_ID_COMPAQ, 0x009a, PHY_ID_BCM5701 }, /* BANSHEE_2 */
7039 { PCI_VENDOR_ID_COMPAQ, 0x007d, 0 }, /* CHANGELING */
7040 { PCI_VENDOR_ID_COMPAQ, 0x0085, PHY_ID_BCM5701 }, /* NC7780 */
7041 { PCI_VENDOR_ID_COMPAQ, 0x0099, PHY_ID_BCM5701 }, /* NC7780_2 */
7044 { PCI_VENDOR_ID_IBM, 0x0281, 0 } /* IBM??? */
7047 static inline struct subsys_tbl_ent *lookup_by_subsys(struct tg3 *tp)
7051 for (i = 0; i < ARRAY_SIZE(subsys_id_to_phy_id); i++) {
7052 if ((subsys_id_to_phy_id[i].subsys_vendor ==
7053 tp->pdev->subsystem_vendor) &&
7054 (subsys_id_to_phy_id[i].subsys_devid ==
7055 tp->pdev->subsystem_device))
7056 return &subsys_id_to_phy_id[i];
7061 static int __devinit tg3_phy_probe(struct tg3 *tp)
7063 u32 eeprom_phy_id, hw_phy_id_1, hw_phy_id_2;
7064 u32 hw_phy_id, hw_phy_id_masked;
7066 int eeprom_signature_found, eeprom_phy_serdes, err;
7068 tp->phy_id = PHY_ID_INVALID;
7069 eeprom_phy_id = PHY_ID_INVALID;
7070 eeprom_phy_serdes = 0;
7071 eeprom_signature_found = 0;
7072 tg3_read_mem(tp, NIC_SRAM_DATA_SIG, &val);
7073 if (val == NIC_SRAM_DATA_SIG_MAGIC) {
7074 u32 nic_cfg, led_cfg;
7075 u32 nic_phy_id, cfg2;
7077 tg3_read_mem(tp, NIC_SRAM_DATA_CFG, &nic_cfg);
7078 tp->nic_sram_data_cfg = nic_cfg;
7080 eeprom_signature_found = 1;
7082 if ((nic_cfg & NIC_SRAM_DATA_CFG_PHY_TYPE_MASK) ==
7083 NIC_SRAM_DATA_CFG_PHY_TYPE_FIBER)
7084 eeprom_phy_serdes = 1;
7086 tg3_read_mem(tp, NIC_SRAM_DATA_PHY_ID, &nic_phy_id);
7087 if (nic_phy_id != 0) {
7088 u32 id1 = nic_phy_id & NIC_SRAM_DATA_PHY_ID1_MASK;
7089 u32 id2 = nic_phy_id & NIC_SRAM_DATA_PHY_ID2_MASK;
7091 eeprom_phy_id = (id1 >> 16) << 10;
7092 eeprom_phy_id |= (id2 & 0xfc00) << 16;
7093 eeprom_phy_id |= (id2 & 0x03ff) << 0;
7097 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750) {
7098 tg3_read_mem(tp, NIC_SRAM_DATA_CFG_2, &led_cfg);
7099 led_cfg &= (NIC_SRAM_DATA_CFG_LED_MODE_MASK |
7100 SHASTA_EXT_LED_MODE_MASK);
7102 led_cfg = nic_cfg & NIC_SRAM_DATA_CFG_LED_MODE_MASK;
7106 case NIC_SRAM_DATA_CFG_LED_MODE_PHY_1:
7107 tp->led_ctrl = LED_CTRL_MODE_PHY_1;
7110 case NIC_SRAM_DATA_CFG_LED_MODE_PHY_2:
7111 tp->led_ctrl = LED_CTRL_MODE_PHY_2;
7114 case NIC_SRAM_DATA_CFG_LED_MODE_MAC:
7115 tp->led_ctrl = LED_CTRL_MODE_MAC;
7118 case SHASTA_EXT_LED_SHARED:
7119 tp->led_ctrl = LED_CTRL_MODE_SHARED;
7120 if (tp->pci_chip_rev_id != CHIPREV_ID_5750_A0 &&
7121 tp->pci_chip_rev_id != CHIPREV_ID_5750_A1)
7122 tp->led_ctrl |= (LED_CTRL_MODE_PHY_1 |
7123 LED_CTRL_MODE_PHY_2);
7126 case SHASTA_EXT_LED_MAC:
7127 tp->led_ctrl = LED_CTRL_MODE_SHASTA_MAC;
7130 case SHASTA_EXT_LED_COMBO:
7131 tp->led_ctrl = LED_CTRL_MODE_COMBO;
7132 if (tp->pci_chip_rev_id != CHIPREV_ID_5750_A0)
7133 tp->led_ctrl |= (LED_CTRL_MODE_PHY_1 |
7134 LED_CTRL_MODE_PHY_2);
7139 if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
7140 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) &&
7141 tp->pdev->subsystem_vendor == PCI_VENDOR_ID_DELL)
7142 tp->led_ctrl = LED_CTRL_MODE_PHY_2;
7144 if (((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703) ||
7145 (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) ||
7146 (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705)) &&
7147 (nic_cfg & NIC_SRAM_DATA_CFG_EEPROM_WP))
7148 tp->tg3_flags |= TG3_FLAG_EEPROM_WRITE_PROT;
7150 if (nic_cfg & NIC_SRAM_DATA_CFG_ASF_ENABLE) {
7151 tp->tg3_flags |= TG3_FLAG_ENABLE_ASF;
7152 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750)
7153 tp->tg3_flags2 |= TG3_FLG2_ASF_NEW_HANDSHAKE;
7155 if (nic_cfg & NIC_SRAM_DATA_CFG_FIBER_WOL)
7156 tp->tg3_flags |= TG3_FLAG_SERDES_WOL_CAP;
7158 tg3_read_mem(tp, NIC_SRAM_DATA_PHY_ID, &cfg2);
7159 if (cfg2 & (1 << 17))
7160 tp->tg3_flags2 |= TG3_FLG2_CAPACITIVE_COUPLING;
7163 /* Reading the PHY ID register can conflict with ASF
7164 * firwmare access to the PHY hardware.
7167 if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) {
7168 hw_phy_id = hw_phy_id_masked = PHY_ID_INVALID;
7170 /* Now read the physical PHY_ID from the chip and verify
7171 * that it is sane. If it doesn't look good, we fall back
7172 * to either the hard-coded table based PHY_ID and failing
7173 * that the value found in the eeprom area.
7175 err |= tg3_readphy(tp, MII_PHYSID1, &hw_phy_id_1);
7176 err |= tg3_readphy(tp, MII_PHYSID2, &hw_phy_id_2);
7178 hw_phy_id = (hw_phy_id_1 & 0xffff) << 10;
7179 hw_phy_id |= (hw_phy_id_2 & 0xfc00) << 16;
7180 hw_phy_id |= (hw_phy_id_2 & 0x03ff) << 0;
7182 hw_phy_id_masked = hw_phy_id & PHY_ID_MASK;
7185 if (!err && KNOWN_PHY_ID(hw_phy_id_masked)) {
7186 tp->phy_id = hw_phy_id;
7187 if (hw_phy_id_masked == PHY_ID_BCM8002)
7188 tp->tg3_flags2 |= TG3_FLG2_PHY_SERDES;
7190 if (eeprom_signature_found) {
7191 tp->phy_id = eeprom_phy_id;
7192 if (eeprom_phy_serdes)
7193 tp->tg3_flags2 |= TG3_FLG2_PHY_SERDES;
7195 struct subsys_tbl_ent *p;
7197 /* No eeprom signature? Try the hardcoded
7198 * subsys device table.
7200 p = lookup_by_subsys(tp);
7204 tp->phy_id = p->phy_id;
7206 tp->phy_id == PHY_ID_BCM8002)
7207 tp->tg3_flags2 |= TG3_FLG2_PHY_SERDES;
7211 if (!(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) &&
7212 !(tp->tg3_flags & TG3_FLAG_ENABLE_ASF)) {
7213 u32 bmsr, adv_reg, tg3_ctrl;
7215 tg3_readphy(tp, MII_BMSR, &bmsr);
7216 tg3_readphy(tp, MII_BMSR, &bmsr);
7218 if (bmsr & BMSR_LSTATUS)
7219 goto skip_phy_reset;
7221 err = tg3_phy_reset(tp);
7225 adv_reg = (ADVERTISE_10HALF | ADVERTISE_10FULL |
7226 ADVERTISE_100HALF | ADVERTISE_100FULL |
7227 ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP);
7229 if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY)) {
7230 tg3_ctrl = (MII_TG3_CTRL_ADV_1000_HALF |
7231 MII_TG3_CTRL_ADV_1000_FULL);
7232 if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 ||
7233 tp->pci_chip_rev_id == CHIPREV_ID_5701_B0)
7234 tg3_ctrl |= (MII_TG3_CTRL_AS_MASTER |
7235 MII_TG3_CTRL_ENABLE_AS_MASTER);
7238 if (!tg3_copper_is_advertising_all(tp)) {
7239 tg3_writephy(tp, MII_ADVERTISE, adv_reg);
7241 if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY))
7242 tg3_writephy(tp, MII_TG3_CTRL, tg3_ctrl);
7244 tg3_writephy(tp, MII_BMCR,
7245 BMCR_ANENABLE | BMCR_ANRESTART);
7247 tg3_phy_set_wirespeed(tp);
7249 tg3_writephy(tp, MII_ADVERTISE, adv_reg);
7250 if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY))
7251 tg3_writephy(tp, MII_TG3_CTRL, tg3_ctrl);
7255 if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5401) {
7256 err = tg3_init_5401phy_dsp(tp);
7261 if (!err && ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5401)) {
7262 err = tg3_init_5401phy_dsp(tp);
7265 if (!eeprom_signature_found)
7266 tp->led_ctrl = LED_CTRL_MODE_PHY_1;
7268 if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)
7269 tp->link_config.advertising =
7270 (ADVERTISED_1000baseT_Half |
7271 ADVERTISED_1000baseT_Full |
7272 ADVERTISED_Autoneg |
7274 if (tp->tg3_flags & TG3_FLAG_10_100_ONLY)
7275 tp->link_config.advertising &=
7276 ~(ADVERTISED_1000baseT_Half |
7277 ADVERTISED_1000baseT_Full);
7282 static void __devinit tg3_read_partno(struct tg3 *tp)
7284 unsigned char vpd_data[256];
7287 if (tp->tg3_flags2 & TG3_FLG2_SUN_570X) {
7288 /* Sun decided not to put the necessary bits in the
7289 * NVRAM of their onboard tg3 parts :(
7291 strcpy(tp->board_part_number, "Sun 570X");
7295 for (i = 0; i < 256; i += 4) {
7298 if (tg3_nvram_read(tp, 0x100 + i, &tmp))
7301 vpd_data[i + 0] = ((tmp >> 0) & 0xff);
7302 vpd_data[i + 1] = ((tmp >> 8) & 0xff);
7303 vpd_data[i + 2] = ((tmp >> 16) & 0xff);
7304 vpd_data[i + 3] = ((tmp >> 24) & 0xff);
7307 /* Now parse and find the part number. */
7308 for (i = 0; i < 256; ) {
7309 unsigned char val = vpd_data[i];
7312 if (val == 0x82 || val == 0x91) {
7315 (vpd_data[i + 2] << 8)));
7322 block_end = (i + 3 +
7324 (vpd_data[i + 2] << 8)));
7326 while (i < block_end) {
7327 if (vpd_data[i + 0] == 'P' &&
7328 vpd_data[i + 1] == 'N') {
7329 int partno_len = vpd_data[i + 2];
7331 if (partno_len > 24)
7334 memcpy(tp->board_part_number,
7343 /* Part number not found. */
7348 strcpy(tp->board_part_number, "none");
7351 #ifdef CONFIG_SPARC64
7352 static int __devinit tg3_is_sun_570X(struct tg3 *tp)
7354 struct pci_dev *pdev = tp->pdev;
7355 struct pcidev_cookie *pcp = pdev->sysdata;
7358 int node = pcp->prom_node;
7362 err = prom_getproperty(node, "subsystem-vendor-id",
7363 (char *) &venid, sizeof(venid));
7364 if (err == 0 || err == -1)
7366 if (venid == PCI_VENDOR_ID_SUN)
7373 static int __devinit tg3_get_invariants(struct tg3 *tp)
7376 u32 cacheline_sz_reg;
7377 u32 pci_state_reg, grc_misc_cfg;
7382 #ifdef CONFIG_SPARC64
7383 if (tg3_is_sun_570X(tp))
7384 tp->tg3_flags2 |= TG3_FLG2_SUN_570X;
7387 /* If we have an AMD 762 or Intel ICH/ICH0/ICH2 chipset, write
7388 * reordering to the mailbox registers done by the host
7389 * controller can cause major troubles. We read back from
7390 * every mailbox register write to force the writes to be
7391 * posted to the chip in order.
7393 if (pci_find_device(PCI_VENDOR_ID_INTEL,
7394 PCI_DEVICE_ID_INTEL_82801AA_8, NULL) ||
7395 pci_find_device(PCI_VENDOR_ID_INTEL,
7396 PCI_DEVICE_ID_INTEL_82801AB_8, NULL) ||
7397 pci_find_device(PCI_VENDOR_ID_INTEL,
7398 PCI_DEVICE_ID_INTEL_82801BA_11, NULL) ||
7399 pci_find_device(PCI_VENDOR_ID_INTEL,
7400 PCI_DEVICE_ID_INTEL_82801BA_6, NULL) ||
7401 pci_find_device(PCI_VENDOR_ID_AMD,
7402 PCI_DEVICE_ID_AMD_FE_GATE_700C, NULL))
7403 tp->tg3_flags |= TG3_FLAG_MBOX_WRITE_REORDER;
7405 /* Force memory write invalidate off. If we leave it on,
7406 * then on 5700_BX chips we have to enable a workaround.
7407 * The workaround is to set the TG3PCI_DMA_RW_CTRL boundary
7408 * to match the cacheline size. The Broadcom driver have this
7409 * workaround but turns MWI off all the times so never uses
7410 * it. This seems to suggest that the workaround is insufficient.
7412 pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd);
7413 pci_cmd &= ~PCI_COMMAND_INVALIDATE;
7414 pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd);
7416 /* It is absolutely critical that TG3PCI_MISC_HOST_CTRL
7417 * has the register indirect write enable bit set before
7418 * we try to access any of the MMIO registers. It is also
7419 * critical that the PCI-X hw workaround situation is decided
7420 * before that as well.
7422 pci_read_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL,
7425 tp->pci_chip_rev_id = (misc_ctrl_reg >>
7426 MISC_HOST_CTRL_CHIPREV_SHIFT);
7428 /* Initialize misc host control in PCI block. */
7429 tp->misc_host_ctrl |= (misc_ctrl_reg &
7430 MISC_HOST_CTRL_CHIPREV);
7431 pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL,
7432 tp->misc_host_ctrl);
7434 pci_read_config_dword(tp->pdev, TG3PCI_CACHELINESZ,
7437 tp->pci_cacheline_sz = (cacheline_sz_reg >> 0) & 0xff;
7438 tp->pci_lat_timer = (cacheline_sz_reg >> 8) & 0xff;
7439 tp->pci_hdr_type = (cacheline_sz_reg >> 16) & 0xff;
7440 tp->pci_bist = (cacheline_sz_reg >> 24) & 0xff;
7442 if (pci_find_capability(tp->pdev, PCI_CAP_ID_EXP) != 0)
7443 tp->tg3_flags2 |= TG3_FLG2_PCI_EXPRESS;
7445 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 &&
7446 tp->pci_lat_timer < 64) {
7447 tp->pci_lat_timer = 64;
7449 cacheline_sz_reg = ((tp->pci_cacheline_sz & 0xff) << 0);
7450 cacheline_sz_reg |= ((tp->pci_lat_timer & 0xff) << 8);
7451 cacheline_sz_reg |= ((tp->pci_hdr_type & 0xff) << 16);
7452 cacheline_sz_reg |= ((tp->pci_bist & 0xff) << 24);
7454 pci_write_config_dword(tp->pdev, TG3PCI_CACHELINESZ,
7458 pci_read_config_dword(tp->pdev, TG3PCI_PCISTATE,
7461 if ((pci_state_reg & PCISTATE_CONV_PCI_MODE) == 0) {
7462 tp->tg3_flags |= TG3_FLAG_PCIX_MODE;
7464 /* If this is a 5700 BX chipset, and we are in PCI-X
7465 * mode, enable register write workaround.
7467 * The workaround is to use indirect register accesses
7468 * for all chip writes not to mailbox registers.
7470 if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5700_BX) {
7474 tp->tg3_flags |= TG3_FLAG_PCIX_TARGET_HWBUG;
7476 /* The chip can have it's power management PCI config
7477 * space registers clobbered due to this bug.
7478 * So explicitly force the chip into D0 here.
7480 pci_read_config_dword(tp->pdev, TG3PCI_PM_CTRL_STAT,
7482 pm_reg &= ~PCI_PM_CTRL_STATE_MASK;
7483 pm_reg |= PCI_PM_CTRL_PME_ENABLE | 0 /* D0 */;
7484 pci_write_config_dword(tp->pdev, TG3PCI_PM_CTRL_STAT,
7487 /* Also, force SERR#/PERR# in PCI command. */
7488 pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd);
7489 pci_cmd |= PCI_COMMAND_PARITY | PCI_COMMAND_SERR;
7490 pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd);
7494 /* Back to back register writes can cause problems on this chip,
7495 * the workaround is to read back all reg writes except those to
7496 * mailbox regs. See tg3_write_indirect_reg32().
7498 * PCI Express 5750_A0 rev chips need this workaround too.
7500 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701 ||
7501 ((tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) &&
7502 tp->pci_chip_rev_id == CHIPREV_ID_5750_A0))
7503 tp->tg3_flags |= TG3_FLAG_5701_REG_WRITE_BUG;
7505 if ((pci_state_reg & PCISTATE_BUS_SPEED_HIGH) != 0)
7506 tp->tg3_flags |= TG3_FLAG_PCI_HIGH_SPEED;
7507 if ((pci_state_reg & PCISTATE_BUS_32BIT) != 0)
7508 tp->tg3_flags |= TG3_FLAG_PCI_32BIT;
7510 /* Chip-specific fixup from Broadcom driver */
7511 if ((tp->pci_chip_rev_id == CHIPREV_ID_5704_A0) &&
7512 (!(pci_state_reg & PCISTATE_RETRY_SAME_DMA))) {
7513 pci_state_reg |= PCISTATE_RETRY_SAME_DMA;
7514 pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE, pci_state_reg);
7517 /* Force the chip into D0. */
7518 err = tg3_set_power_state(tp, 0);
7520 printk(KERN_ERR PFX "(%s) transition to D0 failed\n",
7521 pci_name(tp->pdev));
7525 /* 5700 B0 chips do not support checksumming correctly due
7528 if (tp->pci_chip_rev_id == CHIPREV_ID_5700_B0)
7529 tp->tg3_flags |= TG3_FLAG_BROKEN_CHECKSUMS;
7531 /* Pseudo-header checksum is done by hardware logic and not
7532 * the offload processers, so make the chip do the pseudo-
7533 * header checksums on receive. For transmit it is more
7534 * convenient to do the pseudo-header checksum in software
7535 * as Linux does that on transmit for us in all cases.
7537 tp->tg3_flags |= TG3_FLAG_NO_TX_PSEUDO_CSUM;
7538 tp->tg3_flags &= ~TG3_FLAG_NO_RX_PSEUDO_CSUM;
7540 /* Derive initial jumbo mode from MTU assigned in
7541 * ether_setup() via the alloc_etherdev() call
7543 if (tp->dev->mtu > ETH_DATA_LEN)
7544 tp->tg3_flags |= TG3_FLAG_JUMBO_ENABLE;
7546 /* Determine WakeOnLan speed to use. */
7547 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
7548 tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 ||
7549 tp->pci_chip_rev_id == CHIPREV_ID_5701_B0 ||
7550 tp->pci_chip_rev_id == CHIPREV_ID_5701_B2) {
7551 tp->tg3_flags &= ~(TG3_FLAG_WOL_SPEED_100MB);
7553 tp->tg3_flags |= TG3_FLAG_WOL_SPEED_100MB;
7556 /* A few boards don't want Ethernet@WireSpeed phy feature */
7557 if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) ||
7558 ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) &&
7559 (tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) &&
7560 (tp->pci_chip_rev_id != CHIPREV_ID_5705_A1)))
7561 tp->tg3_flags2 |= TG3_FLG2_NO_ETH_WIRE_SPEED;
7563 if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5703_AX ||
7564 GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5704_AX)
7565 tp->tg3_flags2 |= TG3_FLG2_PHY_ADC_BUG;
7566 if (tp->pci_chip_rev_id == CHIPREV_ID_5704_A0)
7567 tp->tg3_flags2 |= TG3_FLG2_PHY_5704_A0_BUG;
7569 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 ||
7570 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750)
7571 tp->tg3_flags2 |= TG3_FLG2_PHY_BER_BUG;
7573 /* Only 5701 and later support tagged irq status mode.
7574 * Also, 5788 chips cannot use tagged irq status.
7576 * However, since we are using NAPI avoid tagged irq status
7577 * because the interrupt condition is more difficult to
7578 * fully clear in that mode.
7580 tp->coalesce_mode = 0;
7582 if (GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5700_AX &&
7583 GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5700_BX)
7584 tp->coalesce_mode |= HOSTCC_MODE_32BYTE;
7586 /* Initialize MAC MI mode, polling disabled. */
7587 tw32_f(MAC_MI_MODE, tp->mi_mode);
7590 /* Initialize data/descriptor byte/word swapping. */
7591 val = tr32(GRC_MODE);
7592 val &= GRC_MODE_HOST_STACKUP;
7593 tw32(GRC_MODE, val | tp->grc_mode);
7595 tg3_switch_clocks(tp);
7597 /* Clear this out for sanity. */
7598 tw32(TG3PCI_MEM_WIN_BASE_ADDR, 0);
7600 pci_read_config_dword(tp->pdev, TG3PCI_PCISTATE,
7602 if ((pci_state_reg & PCISTATE_CONV_PCI_MODE) == 0 &&
7603 (tp->tg3_flags & TG3_FLAG_PCIX_TARGET_HWBUG) == 0) {
7604 u32 chiprevid = GET_CHIP_REV_ID(tp->misc_host_ctrl);
7606 if (chiprevid == CHIPREV_ID_5701_A0 ||
7607 chiprevid == CHIPREV_ID_5701_B0 ||
7608 chiprevid == CHIPREV_ID_5701_B2 ||
7609 chiprevid == CHIPREV_ID_5701_B5) {
7610 void __iomem *sram_base;
7612 /* Write some dummy words into the SRAM status block
7613 * area, see if it reads back correctly. If the return
7614 * value is bad, force enable the PCIX workaround.
7616 sram_base = tp->regs + NIC_SRAM_WIN_BASE + NIC_SRAM_STATS_BLK;
7618 writel(0x00000000, sram_base);
7619 writel(0x00000000, sram_base + 4);
7620 writel(0xffffffff, sram_base + 4);
7621 if (readl(sram_base) != 0x00000000)
7622 tp->tg3_flags |= TG3_FLAG_PCIX_TARGET_HWBUG;
7629 grc_misc_cfg = tr32(GRC_MISC_CFG);
7630 grc_misc_cfg &= GRC_MISC_CFG_BOARD_ID_MASK;
7632 /* Broadcom's driver says that CIOBE multisplit has a bug */
7634 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 &&
7635 grc_misc_cfg == GRC_MISC_CFG_BOARD_ID_5704CIOBE) {
7636 tp->tg3_flags |= TG3_FLAG_SPLIT_MODE;
7637 tp->split_mode_max_reqs = SPLIT_MODE_5704_MAX_REQ;
7640 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 &&
7641 (grc_misc_cfg == GRC_MISC_CFG_BOARD_ID_5788 ||
7642 grc_misc_cfg == GRC_MISC_CFG_BOARD_ID_5788M))
7643 tp->tg3_flags2 |= TG3_FLG2_IS_5788;
7645 /* these are limited to 10/100 only */
7646 if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 &&
7647 (grc_misc_cfg == 0x8000 || grc_misc_cfg == 0x4000)) ||
7648 (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 &&
7649 tp->pdev->vendor == PCI_VENDOR_ID_BROADCOM &&
7650 (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5901 ||
7651 tp->pdev->device == PCI_DEVICE_ID_TIGON3_5901_2 ||
7652 tp->pdev->device == PCI_DEVICE_ID_TIGON3_5705F)) ||
7653 (tp->pdev->vendor == PCI_VENDOR_ID_BROADCOM &&
7654 (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5751F ||
7655 tp->pdev->device == PCI_DEVICE_ID_TIGON3_5753F)))
7656 tp->tg3_flags |= TG3_FLAG_10_100_ONLY;
7658 err = tg3_phy_probe(tp);
7660 printk(KERN_ERR PFX "(%s) phy probe failed, err %d\n",
7661 pci_name(tp->pdev), err);
7662 /* ... but do not return immediately ... */
7665 tg3_read_partno(tp);
7667 if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) {
7668 tp->tg3_flags &= ~TG3_FLAG_USE_MI_INTERRUPT;
7670 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700)
7671 tp->tg3_flags |= TG3_FLAG_USE_MI_INTERRUPT;
7673 tp->tg3_flags &= ~TG3_FLAG_USE_MI_INTERRUPT;
7676 /* 5700 {AX,BX} chips have a broken status block link
7677 * change bit implementation, so we must use the
7678 * status register in those cases.
7680 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700)
7681 tp->tg3_flags |= TG3_FLAG_USE_LINKCHG_REG;
7683 tp->tg3_flags &= ~TG3_FLAG_USE_LINKCHG_REG;
7685 /* The led_ctrl is set during tg3_phy_probe, here we might
7686 * have to force the link status polling mechanism based
7687 * upon subsystem IDs.
7689 if (tp->pdev->subsystem_vendor == PCI_VENDOR_ID_DELL &&
7690 !(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)) {
7691 tp->tg3_flags |= (TG3_FLAG_USE_MI_INTERRUPT |
7692 TG3_FLAG_USE_LINKCHG_REG);
7695 /* For all SERDES we poll the MAC status register. */
7696 if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)
7697 tp->tg3_flags |= TG3_FLAG_POLL_SERDES;
7699 tp->tg3_flags &= ~TG3_FLAG_POLL_SERDES;
7701 /* 5700 BX chips need to have their TX producer index mailboxes
7702 * written twice to workaround a bug.
7704 if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5700_BX)
7705 tp->tg3_flags |= TG3_FLAG_TXD_MBOX_HWBUG;
7707 tp->tg3_flags &= ~TG3_FLAG_TXD_MBOX_HWBUG;
7709 /* It seems all chips can get confused if TX buffers
7710 * straddle the 4GB address boundary in some cases.
7712 tp->dev->hard_start_xmit = tg3_start_xmit;
7715 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701 &&
7716 (tp->tg3_flags & TG3_FLAG_PCIX_MODE) != 0)
7719 /* By default, disable wake-on-lan. User can change this
7720 * using ETHTOOL_SWOL.
7722 tp->tg3_flags &= ~TG3_FLAG_WOL_ENABLE;
7727 #ifdef CONFIG_SPARC64
7728 static int __devinit tg3_get_macaddr_sparc(struct tg3 *tp)
7730 struct net_device *dev = tp->dev;
7731 struct pci_dev *pdev = tp->pdev;
7732 struct pcidev_cookie *pcp = pdev->sysdata;
7735 int node = pcp->prom_node;
7737 if (prom_getproplen(node, "local-mac-address") == 6) {
7738 prom_getproperty(node, "local-mac-address",
7746 static int __devinit tg3_get_default_macaddr_sparc(struct tg3 *tp)
7748 struct net_device *dev = tp->dev;
7750 memcpy(dev->dev_addr, idprom->id_ethaddr, 6);
7755 static int __devinit tg3_get_device_address(struct tg3 *tp)
7757 struct net_device *dev = tp->dev;
7758 u32 hi, lo, mac_offset;
7760 #ifdef CONFIG_SPARC64
7761 if (!tg3_get_macaddr_sparc(tp))
7766 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 &&
7767 !(tp->tg3_flags & TG3_FLG2_SUN_570X)) {
7768 if (tr32(TG3PCI_DUAL_MAC_CTRL) & DUAL_MAC_CTRL_ID)
7770 if (tg3_nvram_lock(tp))
7771 tw32_f(NVRAM_CMD, NVRAM_CMD_RESET);
7773 tg3_nvram_unlock(tp);
7776 /* First try to get it from MAC address mailbox. */
7777 tg3_read_mem(tp, NIC_SRAM_MAC_ADDR_HIGH_MBOX, &hi);
7778 if ((hi >> 16) == 0x484b) {
7779 dev->dev_addr[0] = (hi >> 8) & 0xff;
7780 dev->dev_addr[1] = (hi >> 0) & 0xff;
7782 tg3_read_mem(tp, NIC_SRAM_MAC_ADDR_LOW_MBOX, &lo);
7783 dev->dev_addr[2] = (lo >> 24) & 0xff;
7784 dev->dev_addr[3] = (lo >> 16) & 0xff;
7785 dev->dev_addr[4] = (lo >> 8) & 0xff;
7786 dev->dev_addr[5] = (lo >> 0) & 0xff;
7788 /* Next, try NVRAM. */
7789 else if (!(tp->tg3_flags & TG3_FLG2_SUN_570X) &&
7790 !tg3_nvram_read(tp, mac_offset + 0, &hi) &&
7791 !tg3_nvram_read(tp, mac_offset + 4, &lo)) {
7792 dev->dev_addr[0] = ((hi >> 16) & 0xff);
7793 dev->dev_addr[1] = ((hi >> 24) & 0xff);
7794 dev->dev_addr[2] = ((lo >> 0) & 0xff);
7795 dev->dev_addr[3] = ((lo >> 8) & 0xff);
7796 dev->dev_addr[4] = ((lo >> 16) & 0xff);
7797 dev->dev_addr[5] = ((lo >> 24) & 0xff);
7799 /* Finally just fetch it out of the MAC control regs. */
7801 hi = tr32(MAC_ADDR_0_HIGH);
7802 lo = tr32(MAC_ADDR_0_LOW);
7804 dev->dev_addr[5] = lo & 0xff;
7805 dev->dev_addr[4] = (lo >> 8) & 0xff;
7806 dev->dev_addr[3] = (lo >> 16) & 0xff;
7807 dev->dev_addr[2] = (lo >> 24) & 0xff;
7808 dev->dev_addr[1] = hi & 0xff;
7809 dev->dev_addr[0] = (hi >> 8) & 0xff;
7812 if (!is_valid_ether_addr(&dev->dev_addr[0])) {
7813 #ifdef CONFIG_SPARC64
7814 if (!tg3_get_default_macaddr_sparc(tp))
7822 static int __devinit tg3_do_test_dma(struct tg3 *tp, u32 *buf, dma_addr_t buf_dma, int size, int to_device)
7824 struct tg3_internal_buffer_desc test_desc;
7828 sram_dma_descs = NIC_SRAM_DMA_DESC_POOL_BASE;
7830 tw32(FTQ_RCVBD_COMP_FIFO_ENQDEQ, 0);
7831 tw32(FTQ_RCVDATA_COMP_FIFO_ENQDEQ, 0);
7832 tw32(RDMAC_STATUS, 0);
7833 tw32(WDMAC_STATUS, 0);
7835 tw32(BUFMGR_MODE, 0);
7838 test_desc.addr_hi = ((u64) buf_dma) >> 32;
7839 test_desc.addr_lo = buf_dma & 0xffffffff;
7840 test_desc.nic_mbuf = 0x00002100;
7841 test_desc.len = size;
7844 * HP ZX1 was seeing test failures for 5701 cards running at 33Mhz
7845 * the *second* time the tg3 driver was getting loaded after an
7848 * Broadcom tells me:
7849 * ...the DMA engine is connected to the GRC block and a DMA
7850 * reset may affect the GRC block in some unpredictable way...
7851 * The behavior of resets to individual blocks has not been tested.
7853 * Broadcom noted the GRC reset will also reset all sub-components.
7856 test_desc.cqid_sqid = (13 << 8) | 2;
7858 tw32_f(RDMAC_MODE, RDMAC_MODE_ENABLE);
7861 test_desc.cqid_sqid = (16 << 8) | 7;
7863 tw32_f(WDMAC_MODE, WDMAC_MODE_ENABLE);
7866 test_desc.flags = 0x00000005;
7868 for (i = 0; i < (sizeof(test_desc) / sizeof(u32)); i++) {
7871 val = *(((u32 *)&test_desc) + i);
7872 pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR,
7873 sram_dma_descs + (i * sizeof(u32)));
7874 pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val);
7876 pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0);
7879 tw32(FTQ_DMA_HIGH_READ_FIFO_ENQDEQ, sram_dma_descs);
7881 tw32(FTQ_DMA_HIGH_WRITE_FIFO_ENQDEQ, sram_dma_descs);
7885 for (i = 0; i < 40; i++) {
7889 val = tr32(FTQ_RCVBD_COMP_FIFO_ENQDEQ);
7891 val = tr32(FTQ_RCVDATA_COMP_FIFO_ENQDEQ);
7892 if ((val & 0xffff) == sram_dma_descs) {
7903 #define TEST_BUFFER_SIZE 0x400
7905 static int __devinit tg3_test_dma(struct tg3 *tp)
7911 buf = pci_alloc_consistent(tp->pdev, TEST_BUFFER_SIZE, &buf_dma);
7917 tp->dma_rwctrl = ((0x7 << DMA_RWCTRL_PCI_WRITE_CMD_SHIFT) |
7918 (0x6 << DMA_RWCTRL_PCI_READ_CMD_SHIFT));
7924 pci_read_config_byte(tp->pdev, PCI_CACHE_LINE_SIZE, &byte);
7927 cacheline_size = 1024;
7929 cacheline_size = (int) byte * 4;
7931 switch (cacheline_size) {
7936 if ((tp->tg3_flags & TG3_FLAG_PCIX_MODE) &&
7937 !(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS)) {
7939 DMA_RWCTRL_WRITE_BNDRY_384_PCIX;
7941 } else if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) {
7943 ~(DMA_RWCTRL_PCI_WRITE_CMD);
7945 DMA_RWCTRL_WRITE_BNDRY_128_PCIE;
7950 if (!(tp->tg3_flags & TG3_FLAG_PCIX_MODE) &&
7951 !(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS))
7953 DMA_RWCTRL_WRITE_BNDRY_256;
7954 else if (!(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS))
7956 DMA_RWCTRL_WRITE_BNDRY_256_PCIX;
7961 if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) {
7962 /* DMA read watermark not used on PCIE */
7963 tp->dma_rwctrl |= 0x00180000;
7964 } else if (!(tp->tg3_flags & TG3_FLAG_PCIX_MODE)) {
7965 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 ||
7966 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750)
7967 tp->dma_rwctrl |= 0x003f0000;
7969 tp->dma_rwctrl |= 0x003f000f;
7971 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 ||
7972 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) {
7973 u32 ccval = (tr32(TG3PCI_CLOCK_CTRL) & 0x1f);
7975 if (ccval == 0x6 || ccval == 0x7)
7976 tp->dma_rwctrl |= DMA_RWCTRL_ONE_DMA;
7978 /* Set bit 23 to renable PCIX hw bug fix */
7979 tp->dma_rwctrl |= 0x009f0000;
7981 tp->dma_rwctrl |= 0x001b000f;
7985 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 ||
7986 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704)
7987 tp->dma_rwctrl &= 0xfffffff0;
7989 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
7990 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) {
7991 /* Remove this if it causes problems for some boards. */
7992 tp->dma_rwctrl |= DMA_RWCTRL_USE_MEM_READ_MULT;
7994 /* On 5700/5701 chips, we need to set this bit.
7995 * Otherwise the chip will issue cacheline transactions
7996 * to streamable DMA memory with not all the byte
7997 * enables turned on. This is an error on several
7998 * RISC PCI controllers, in particular sparc64.
8000 * On 5703/5704 chips, this bit has been reassigned
8001 * a different meaning. In particular, it is used
8002 * on those chips to enable a PCI-X workaround.
8004 tp->dma_rwctrl |= DMA_RWCTRL_ASSERT_ALL_BE;
8007 tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl);
8010 /* Unneeded, already done by tg3_get_invariants. */
8011 tg3_switch_clocks(tp);
8015 if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 &&
8016 GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701)
8022 for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++)
8025 /* Send the buffer to the chip. */
8026 ret = tg3_do_test_dma(tp, buf, buf_dma, TEST_BUFFER_SIZE, 1);
8028 printk(KERN_ERR "tg3_test_dma() Write the buffer failed %d\n", ret);
8033 /* validate data reached card RAM correctly. */
8034 for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++) {
8036 tg3_read_mem(tp, 0x2100 + (i*4), &val);
8037 if (le32_to_cpu(val) != p[i]) {
8038 printk(KERN_ERR " tg3_test_dma() Card buffer corrupted on write! (%d != %d)\n", val, i);
8039 /* ret = -ENODEV here? */
8044 /* Now read it back. */
8045 ret = tg3_do_test_dma(tp, buf, buf_dma, TEST_BUFFER_SIZE, 0);
8047 printk(KERN_ERR "tg3_test_dma() Read the buffer failed %d\n", ret);
8053 for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++) {
8057 if ((tp->dma_rwctrl & DMA_RWCTRL_WRITE_BNDRY_MASK) ==
8058 DMA_RWCTRL_WRITE_BNDRY_DISAB) {
8059 tp->dma_rwctrl |= DMA_RWCTRL_WRITE_BNDRY_16;
8060 tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl);
8063 printk(KERN_ERR "tg3_test_dma() buffer corrupted on read back! (%d != %d)\n", p[i], i);
8069 if (i == (TEST_BUFFER_SIZE / sizeof(u32))) {
8077 pci_free_consistent(tp->pdev, TEST_BUFFER_SIZE, buf, buf_dma);
8082 static void __devinit tg3_init_link_config(struct tg3 *tp)
8084 tp->link_config.advertising =
8085 (ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full |
8086 ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full |
8087 ADVERTISED_1000baseT_Half | ADVERTISED_1000baseT_Full |
8088 ADVERTISED_Autoneg | ADVERTISED_MII);
8089 tp->link_config.speed = SPEED_INVALID;
8090 tp->link_config.duplex = DUPLEX_INVALID;
8091 tp->link_config.autoneg = AUTONEG_ENABLE;
8092 netif_carrier_off(tp->dev);
8093 tp->link_config.active_speed = SPEED_INVALID;
8094 tp->link_config.active_duplex = DUPLEX_INVALID;
8095 tp->link_config.phy_is_low_power = 0;
8096 tp->link_config.orig_speed = SPEED_INVALID;
8097 tp->link_config.orig_duplex = DUPLEX_INVALID;
8098 tp->link_config.orig_autoneg = AUTONEG_INVALID;
8101 static void __devinit tg3_init_bufmgr_config(struct tg3 *tp)
8103 tp->bufmgr_config.mbuf_read_dma_low_water =
8104 DEFAULT_MB_RDMA_LOW_WATER;
8105 tp->bufmgr_config.mbuf_mac_rx_low_water =
8106 DEFAULT_MB_MACRX_LOW_WATER;
8107 tp->bufmgr_config.mbuf_high_water =
8108 DEFAULT_MB_HIGH_WATER;
8110 tp->bufmgr_config.mbuf_read_dma_low_water_jumbo =
8111 DEFAULT_MB_RDMA_LOW_WATER_JUMBO;
8112 tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo =
8113 DEFAULT_MB_MACRX_LOW_WATER_JUMBO;
8114 tp->bufmgr_config.mbuf_high_water_jumbo =
8115 DEFAULT_MB_HIGH_WATER_JUMBO;
8117 tp->bufmgr_config.dma_low_water = DEFAULT_DMA_LOW_WATER;
8118 tp->bufmgr_config.dma_high_water = DEFAULT_DMA_HIGH_WATER;
8121 static char * __devinit tg3_phy_string(struct tg3 *tp)
8123 switch (tp->phy_id & PHY_ID_MASK) {
8124 case PHY_ID_BCM5400: return "5400";
8125 case PHY_ID_BCM5401: return "5401";
8126 case PHY_ID_BCM5411: return "5411";
8127 case PHY_ID_BCM5701: return "5701";
8128 case PHY_ID_BCM5703: return "5703";
8129 case PHY_ID_BCM5704: return "5704";
8130 case PHY_ID_BCM5705: return "5705";
8131 case PHY_ID_BCM5750: return "5750";
8132 case PHY_ID_BCM8002: return "8002/serdes";
8133 case 0: return "serdes";
8134 default: return "unknown";
8138 static struct pci_dev * __devinit tg3_find_5704_peer(struct tg3 *tp)
8140 struct pci_dev *peer;
8141 unsigned int func, devnr = tp->pdev->devfn & ~7;
8143 for (func = 0; func < 8; func++) {
8144 peer = pci_get_slot(tp->pdev->bus, devnr | func);
8145 if (peer && peer != tp->pdev)
8149 if (!peer || peer == tp->pdev)
8153 * We don't need to keep the refcount elevated; there's no way
8154 * to remove one half of this device without removing the other
8161 static int __devinit tg3_init_one(struct pci_dev *pdev,
8162 const struct pci_device_id *ent)
8164 static int tg3_version_printed = 0;
8165 unsigned long tg3reg_base, tg3reg_len;
8166 struct net_device *dev;
8168 int i, err, pci_using_dac, pm_cap;
8170 if (tg3_version_printed++ == 0)
8171 printk(KERN_INFO "%s", version);
8173 err = pci_enable_device(pdev);
8175 printk(KERN_ERR PFX "Cannot enable PCI device, "
8180 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
8181 printk(KERN_ERR PFX "Cannot find proper PCI device "
8182 "base address, aborting.\n");
8184 goto err_out_disable_pdev;
8187 err = pci_request_regions(pdev, DRV_MODULE_NAME);
8189 printk(KERN_ERR PFX "Cannot obtain PCI resources, "
8191 goto err_out_disable_pdev;
8194 pci_set_master(pdev);
8196 /* Find power-management capability. */
8197 pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
8199 printk(KERN_ERR PFX "Cannot find PowerManagement capability, "
8202 goto err_out_free_res;
8205 /* Configure DMA attributes. */
8206 err = pci_set_dma_mask(pdev, 0xffffffffffffffffULL);
8209 err = pci_set_consistent_dma_mask(pdev, 0xffffffffffffffffULL);
8211 printk(KERN_ERR PFX "Unable to obtain 64 bit DMA "
8212 "for consistent allocations\n");
8213 goto err_out_free_res;
8216 err = pci_set_dma_mask(pdev, 0xffffffffULL);
8218 printk(KERN_ERR PFX "No usable DMA configuration, "
8220 goto err_out_free_res;
8225 tg3reg_base = pci_resource_start(pdev, 0);
8226 tg3reg_len = pci_resource_len(pdev, 0);
8228 dev = alloc_etherdev(sizeof(*tp));
8230 printk(KERN_ERR PFX "Etherdev alloc failed, aborting.\n");
8232 goto err_out_free_res;
8235 SET_MODULE_OWNER(dev);
8236 SET_NETDEV_DEV(dev, &pdev->dev);
8239 dev->features |= NETIF_F_HIGHDMA;
8240 dev->features |= NETIF_F_LLTX;
8241 #if TG3_VLAN_TAG_USED
8242 dev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
8243 dev->vlan_rx_register = tg3_vlan_rx_register;
8244 dev->vlan_rx_kill_vid = tg3_vlan_rx_kill_vid;
8247 tp = netdev_priv(dev);
8250 tp->pm_cap = pm_cap;
8251 tp->mac_mode = TG3_DEF_MAC_MODE;
8252 tp->rx_mode = TG3_DEF_RX_MODE;
8253 tp->tx_mode = TG3_DEF_TX_MODE;
8254 tp->mi_mode = MAC_MI_MODE_BASE;
8256 tp->msg_enable = tg3_debug;
8258 tp->msg_enable = TG3_DEF_MSG_ENABLE;
8260 /* The word/byte swap controls here control register access byte
8261 * swapping. DMA data byte swapping is controlled in the GRC_MODE
8264 tp->misc_host_ctrl =
8265 MISC_HOST_CTRL_MASK_PCI_INT |
8266 MISC_HOST_CTRL_WORD_SWAP |
8267 MISC_HOST_CTRL_INDIR_ACCESS |
8268 MISC_HOST_CTRL_PCISTATE_RW;
8270 /* The NONFRM (non-frame) byte/word swap controls take effect
8271 * on descriptor entries, anything which isn't packet data.
8273 * The StrongARM chips on the board (one for tx, one for rx)
8274 * are running in big-endian mode.
8276 tp->grc_mode = (GRC_MODE_WSWAP_DATA | GRC_MODE_BSWAP_DATA |
8277 GRC_MODE_WSWAP_NONFRM_DATA);
8279 tp->grc_mode |= GRC_MODE_BSWAP_NONFRM_DATA;
8281 spin_lock_init(&tp->lock);
8282 spin_lock_init(&tp->tx_lock);
8283 spin_lock_init(&tp->indirect_lock);
8284 INIT_WORK(&tp->reset_task, tg3_reset_task, tp);
8286 tp->regs = ioremap_nocache(tg3reg_base, tg3reg_len);
8287 if (tp->regs == 0UL) {
8288 printk(KERN_ERR PFX "Cannot map device registers, "
8291 goto err_out_free_dev;
8294 tg3_init_link_config(tp);
8296 tg3_init_bufmgr_config(tp);
8298 tp->rx_pending = TG3_DEF_RX_RING_PENDING;
8299 tp->rx_jumbo_pending = TG3_DEF_RX_JUMBO_RING_PENDING;
8300 tp->tx_pending = TG3_DEF_TX_RING_PENDING;
8302 dev->open = tg3_open;
8303 dev->stop = tg3_close;
8304 dev->get_stats = tg3_get_stats;
8305 dev->set_multicast_list = tg3_set_rx_mode;
8306 dev->set_mac_address = tg3_set_mac_addr;
8307 dev->do_ioctl = tg3_ioctl;
8308 dev->tx_timeout = tg3_tx_timeout;
8309 dev->poll = tg3_poll;
8310 dev->ethtool_ops = &tg3_ethtool_ops;
8312 dev->watchdog_timeo = TG3_TX_TIMEOUT;
8313 dev->change_mtu = tg3_change_mtu;
8314 dev->irq = pdev->irq;
8315 #ifdef CONFIG_NET_POLL_CONTROLLER
8316 dev->poll_controller = tg3_poll_controller;
8319 err = tg3_get_invariants(tp);
8321 printk(KERN_ERR PFX "Problem fetching invariants of chip, "
8323 goto err_out_iounmap;
8326 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 ||
8327 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750) {
8328 tp->bufmgr_config.mbuf_read_dma_low_water =
8329 DEFAULT_MB_RDMA_LOW_WATER_5705;
8330 tp->bufmgr_config.mbuf_mac_rx_low_water =
8331 DEFAULT_MB_MACRX_LOW_WATER_5705;
8332 tp->bufmgr_config.mbuf_high_water =
8333 DEFAULT_MB_HIGH_WATER_5705;
8336 #if TG3_TSO_SUPPORT != 0
8337 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
8338 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701 ||
8339 tp->pci_chip_rev_id == CHIPREV_ID_5705_A0 ||
8340 ((tp->tg3_flags & TG3_FLAG_ENABLE_ASF) != 0 &&
8341 GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5750)) {
8342 tp->tg3_flags2 &= ~TG3_FLG2_TSO_CAPABLE;
8344 tp->tg3_flags2 |= TG3_FLG2_TSO_CAPABLE;
8347 /* TSO is off by default, user can enable using ethtool. */
8349 if (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE)
8350 dev->features |= NETIF_F_TSO;
8355 if (tp->pci_chip_rev_id == CHIPREV_ID_5705_A1 &&
8356 !(tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) &&
8357 !(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH)) {
8358 tp->tg3_flags2 |= TG3_FLG2_MAX_RXPEND_64;
8359 tp->rx_pending = 63;
8362 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704)
8363 tp->pdev_peer = tg3_find_5704_peer(tp);
8365 err = tg3_get_device_address(tp);
8367 printk(KERN_ERR PFX "Could not obtain valid ethernet address, "
8369 goto err_out_iounmap;
8373 * Reset chip in case UNDI or EFI driver did not shutdown
8374 * DMA self test will enable WDMAC and we'll see (spurious)
8375 * pending DMA on the PCI bus at that point.
8377 if ((tr32(HOSTCC_MODE) & HOSTCC_MODE_ENABLE) ||
8378 (tr32(WDMAC_MODE) & WDMAC_MODE_ENABLE)) {
8379 pci_save_state(tp->pdev);
8380 tw32(MEMARB_MODE, MEMARB_MODE_ENABLE);
8384 err = tg3_test_dma(tp);
8386 printk(KERN_ERR PFX "DMA engine test failed, aborting.\n");
8387 goto err_out_iounmap;
8390 /* Tigon3 can do ipv4 only... and some chips have buggy
8393 if ((tp->tg3_flags & TG3_FLAG_BROKEN_CHECKSUMS) == 0) {
8394 dev->features |= NETIF_F_SG | NETIF_F_IP_CSUM;
8395 tp->tg3_flags |= TG3_FLAG_RX_CHECKSUMS;
8397 tp->tg3_flags &= ~TG3_FLAG_RX_CHECKSUMS;
8399 if (tp->tg3_flags2 & TG3_FLG2_IS_5788)
8400 dev->features &= ~NETIF_F_HIGHDMA;
8402 /* flow control autonegotiation is default behavior */
8403 tp->tg3_flags |= TG3_FLAG_PAUSE_AUTONEG;
8405 err = register_netdev(dev);
8407 printk(KERN_ERR PFX "Cannot register net device, "
8409 goto err_out_iounmap;
8412 pci_set_drvdata(pdev, dev);
8414 /* Now that we have fully setup the chip, save away a snapshot
8415 * of the PCI config space. We need to restore this after
8416 * GRC_MISC_CFG core clock resets and some resume events.
8418 pci_save_state(tp->pdev);
8420 printk(KERN_INFO "%s: Tigon3 [partno(%s) rev %04x PHY(%s)] (PCI%s:%s:%s) %sBaseT Ethernet ",
8422 tp->board_part_number,
8423 tp->pci_chip_rev_id,
8425 ((tp->tg3_flags & TG3_FLAG_PCIX_MODE) ? "X" : ""),
8426 ((tp->tg3_flags & TG3_FLAG_PCI_HIGH_SPEED) ?
8427 ((tp->tg3_flags & TG3_FLAG_PCIX_MODE) ? "133MHz" : "66MHz") :
8428 ((tp->tg3_flags & TG3_FLAG_PCIX_MODE) ? "100MHz" : "33MHz")),
8429 ((tp->tg3_flags & TG3_FLAG_PCI_32BIT) ? "32-bit" : "64-bit"),
8430 (tp->tg3_flags & TG3_FLAG_10_100_ONLY) ? "10/100" : "10/100/1000");
8432 for (i = 0; i < 6; i++)
8433 printk("%2.2x%c", dev->dev_addr[i],
8434 i == 5 ? '\n' : ':');
8436 printk(KERN_INFO "%s: RXcsums[%d] LinkChgREG[%d] "
8437 "MIirq[%d] ASF[%d] Split[%d] WireSpeed[%d] "
8440 (tp->tg3_flags & TG3_FLAG_RX_CHECKSUMS) != 0,
8441 (tp->tg3_flags & TG3_FLAG_USE_LINKCHG_REG) != 0,
8442 (tp->tg3_flags & TG3_FLAG_USE_MI_INTERRUPT) != 0,
8443 (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) != 0,
8444 (tp->tg3_flags & TG3_FLAG_SPLIT_MODE) != 0,
8445 (tp->tg3_flags2 & TG3_FLG2_NO_ETH_WIRE_SPEED) == 0,
8446 (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) != 0);
8457 pci_release_regions(pdev);
8459 err_out_disable_pdev:
8460 pci_disable_device(pdev);
8461 pci_set_drvdata(pdev, NULL);
8465 static void __devexit tg3_remove_one(struct pci_dev *pdev)
8467 struct net_device *dev = pci_get_drvdata(pdev);
8470 struct tg3 *tp = netdev_priv(dev);
8472 unregister_netdev(dev);
8475 pci_release_regions(pdev);
8476 pci_disable_device(pdev);
8477 pci_set_drvdata(pdev, NULL);
8481 static int tg3_suspend(struct pci_dev *pdev, u32 state)
8483 struct net_device *dev = pci_get_drvdata(pdev);
8484 struct tg3 *tp = netdev_priv(dev);
8487 if (!netif_running(dev))
8492 del_timer_sync(&tp->timer);
8494 spin_lock_irq(&tp->lock);
8495 spin_lock(&tp->tx_lock);
8496 tg3_disable_ints(tp);
8497 spin_unlock(&tp->tx_lock);
8498 spin_unlock_irq(&tp->lock);
8500 netif_device_detach(dev);
8502 spin_lock_irq(&tp->lock);
8503 spin_lock(&tp->tx_lock);
8505 spin_unlock(&tp->tx_lock);
8506 spin_unlock_irq(&tp->lock);
8508 err = tg3_set_power_state(tp, state);
8510 spin_lock_irq(&tp->lock);
8511 spin_lock(&tp->tx_lock);
8515 tp->timer.expires = jiffies + tp->timer_offset;
8516 add_timer(&tp->timer);
8518 netif_device_attach(dev);
8519 tg3_netif_start(tp);
8521 spin_unlock(&tp->tx_lock);
8522 spin_unlock_irq(&tp->lock);
8528 static int tg3_resume(struct pci_dev *pdev)
8530 struct net_device *dev = pci_get_drvdata(pdev);
8531 struct tg3 *tp = netdev_priv(dev);
8534 if (!netif_running(dev))
8537 pci_restore_state(tp->pdev);
8539 err = tg3_set_power_state(tp, 0);
8543 netif_device_attach(dev);
8545 spin_lock_irq(&tp->lock);
8546 spin_lock(&tp->tx_lock);
8550 tp->timer.expires = jiffies + tp->timer_offset;
8551 add_timer(&tp->timer);
8553 tg3_enable_ints(tp);
8555 tg3_netif_start(tp);
8557 spin_unlock(&tp->tx_lock);
8558 spin_unlock_irq(&tp->lock);
8563 static struct pci_driver tg3_driver = {
8564 .name = DRV_MODULE_NAME,
8565 .id_table = tg3_pci_tbl,
8566 .probe = tg3_init_one,
8567 .remove = __devexit_p(tg3_remove_one),
8568 .suspend = tg3_suspend,
8569 .resume = tg3_resume
8572 static int __init tg3_init(void)
8574 return pci_module_init(&tg3_driver);
8577 static void __exit tg3_cleanup(void)
8579 pci_unregister_driver(&tg3_driver);
8582 module_init(tg3_init);
8583 module_exit(tg3_cleanup);