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.
7 * Copyright (C) 2005-2007 Broadcom Corporation.
10 * Derived from proprietary unpublished source code,
11 * Copyright (C) 2000-2003 Broadcom Corporation.
13 * Permission is hereby granted for the distribution of this firmware
14 * data in hexadecimal or equivalent format, provided this copyright
15 * notice is accompanying it.
19 #include <linux/module.h>
20 #include <linux/moduleparam.h>
21 #include <linux/kernel.h>
22 #include <linux/types.h>
23 #include <linux/compiler.h>
24 #include <linux/slab.h>
25 #include <linux/delay.h>
27 #include <linux/init.h>
28 #include <linux/ioport.h>
29 #include <linux/pci.h>
30 #include <linux/netdevice.h>
31 #include <linux/etherdevice.h>
32 #include <linux/skbuff.h>
33 #include <linux/ethtool.h>
34 #include <linux/mii.h>
35 #include <linux/phy.h>
36 #include <linux/brcmphy.h>
37 #include <linux/if_vlan.h>
39 #include <linux/tcp.h>
40 #include <linux/workqueue.h>
41 #include <linux/prefetch.h>
42 #include <linux/dma-mapping.h>
43 #include <linux/firmware.h>
45 #include <net/checksum.h>
48 #include <asm/system.h>
50 #include <asm/byteorder.h>
51 #include <asm/uaccess.h>
54 #include <asm/idprom.h>
61 #if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
62 #define TG3_VLAN_TAG_USED 1
64 #define TG3_VLAN_TAG_USED 0
69 #define DRV_MODULE_NAME "tg3"
70 #define PFX DRV_MODULE_NAME ": "
71 #define DRV_MODULE_VERSION "3.97"
72 #define DRV_MODULE_RELDATE "December 10, 2008"
74 #define TG3_DEF_MAC_MODE 0
75 #define TG3_DEF_RX_MODE 0
76 #define TG3_DEF_TX_MODE 0
77 #define TG3_DEF_MSG_ENABLE \
87 /* length of time before we decide the hardware is borked,
88 * and dev->tx_timeout() should be called to fix the problem
90 #define TG3_TX_TIMEOUT (5 * HZ)
92 /* hardware minimum and maximum for a single frame's data payload */
93 #define TG3_MIN_MTU 60
94 #define TG3_MAX_MTU(tp) \
95 ((tp->tg3_flags2 & TG3_FLG2_JUMBO_CAPABLE) ? 9000 : 1500)
97 /* These numbers seem to be hard coded in the NIC firmware somehow.
98 * You can't change the ring sizes, but you can change where you place
99 * them in the NIC onboard memory.
101 #define TG3_RX_RING_SIZE 512
102 #define TG3_DEF_RX_RING_PENDING 200
103 #define TG3_RX_JUMBO_RING_SIZE 256
104 #define TG3_DEF_RX_JUMBO_RING_PENDING 100
106 /* Do not place this n-ring entries value into the tp struct itself,
107 * we really want to expose these constants to GCC so that modulo et
108 * al. operations are done with shifts and masks instead of with
109 * hw multiply/modulo instructions. Another solution would be to
110 * replace things like '% foo' with '& (foo - 1)'.
112 #define TG3_RX_RCB_RING_SIZE(tp) \
113 ((tp->tg3_flags2 & TG3_FLG2_5705_PLUS) ? 512 : 1024)
115 #define TG3_TX_RING_SIZE 512
116 #define TG3_DEF_TX_RING_PENDING (TG3_TX_RING_SIZE - 1)
118 #define TG3_RX_RING_BYTES (sizeof(struct tg3_rx_buffer_desc) * \
120 #define TG3_RX_JUMBO_RING_BYTES (sizeof(struct tg3_rx_buffer_desc) * \
121 TG3_RX_JUMBO_RING_SIZE)
122 #define TG3_RX_RCB_RING_BYTES(tp) (sizeof(struct tg3_rx_buffer_desc) * \
123 TG3_RX_RCB_RING_SIZE(tp))
124 #define TG3_TX_RING_BYTES (sizeof(struct tg3_tx_buffer_desc) * \
126 #define NEXT_TX(N) (((N) + 1) & (TG3_TX_RING_SIZE - 1))
128 #define RX_PKT_BUF_SZ (1536 + tp->rx_offset + 64)
129 #define RX_JUMBO_PKT_BUF_SZ (9046 + tp->rx_offset + 64)
131 /* minimum number of free TX descriptors required to wake up TX process */
132 #define TG3_TX_WAKEUP_THRESH(tp) ((tp)->tx_pending / 4)
134 #define TG3_RAW_IP_ALIGN 2
136 /* number of ETHTOOL_GSTATS u64's */
137 #define TG3_NUM_STATS (sizeof(struct tg3_ethtool_stats)/sizeof(u64))
139 #define TG3_NUM_TEST 6
141 #define FIRMWARE_TG3 "tigon/tg3.bin"
142 #define FIRMWARE_TG3TSO "tigon/tg3_tso.bin"
143 #define FIRMWARE_TG3TSO5 "tigon/tg3_tso5.bin"
145 static char version
[] __devinitdata
=
146 DRV_MODULE_NAME
".c:v" DRV_MODULE_VERSION
" (" DRV_MODULE_RELDATE
")\n";
148 MODULE_AUTHOR("David S. Miller (davem@redhat.com) and Jeff Garzik (jgarzik@pobox.com)");
149 MODULE_DESCRIPTION("Broadcom Tigon3 ethernet driver");
150 MODULE_LICENSE("GPL");
151 MODULE_VERSION(DRV_MODULE_VERSION
);
152 MODULE_FIRMWARE(FIRMWARE_TG3
);
153 MODULE_FIRMWARE(FIRMWARE_TG3TSO
);
154 MODULE_FIRMWARE(FIRMWARE_TG3TSO5
);
157 static int tg3_debug
= -1; /* -1 == use TG3_DEF_MSG_ENABLE as value */
158 module_param(tg3_debug
, int, 0);
159 MODULE_PARM_DESC(tg3_debug
, "Tigon3 bitmapped debugging message enable value");
161 static struct pci_device_id tg3_pci_tbl
[] = {
162 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, PCI_DEVICE_ID_TIGON3_5700
)},
163 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, PCI_DEVICE_ID_TIGON3_5701
)},
164 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, PCI_DEVICE_ID_TIGON3_5702
)},
165 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, PCI_DEVICE_ID_TIGON3_5703
)},
166 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, PCI_DEVICE_ID_TIGON3_5704
)},
167 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, PCI_DEVICE_ID_TIGON3_5702FE
)},
168 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, PCI_DEVICE_ID_TIGON3_5705
)},
169 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, PCI_DEVICE_ID_TIGON3_5705_2
)},
170 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, PCI_DEVICE_ID_TIGON3_5705M
)},
171 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, PCI_DEVICE_ID_TIGON3_5705M_2
)},
172 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, PCI_DEVICE_ID_TIGON3_5702X
)},
173 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, PCI_DEVICE_ID_TIGON3_5703X
)},
174 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, PCI_DEVICE_ID_TIGON3_5704S
)},
175 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, PCI_DEVICE_ID_TIGON3_5702A3
)},
176 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, PCI_DEVICE_ID_TIGON3_5703A3
)},
177 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, PCI_DEVICE_ID_TIGON3_5782
)},
178 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, PCI_DEVICE_ID_TIGON3_5788
)},
179 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, PCI_DEVICE_ID_TIGON3_5789
)},
180 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, PCI_DEVICE_ID_TIGON3_5901
)},
181 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, PCI_DEVICE_ID_TIGON3_5901_2
)},
182 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, PCI_DEVICE_ID_TIGON3_5704S_2
)},
183 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, PCI_DEVICE_ID_TIGON3_5705F
)},
184 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, PCI_DEVICE_ID_TIGON3_5720
)},
185 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, PCI_DEVICE_ID_TIGON3_5721
)},
186 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, PCI_DEVICE_ID_TIGON3_5722
)},
187 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, PCI_DEVICE_ID_TIGON3_5750
)},
188 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, PCI_DEVICE_ID_TIGON3_5751
)},
189 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, PCI_DEVICE_ID_TIGON3_5750M
)},
190 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, PCI_DEVICE_ID_TIGON3_5751M
)},
191 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, PCI_DEVICE_ID_TIGON3_5751F
)},
192 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, PCI_DEVICE_ID_TIGON3_5752
)},
193 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, PCI_DEVICE_ID_TIGON3_5752M
)},
194 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, PCI_DEVICE_ID_TIGON3_5753
)},
195 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, PCI_DEVICE_ID_TIGON3_5753M
)},
196 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, PCI_DEVICE_ID_TIGON3_5753F
)},
197 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, PCI_DEVICE_ID_TIGON3_5754
)},
198 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, PCI_DEVICE_ID_TIGON3_5754M
)},
199 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, PCI_DEVICE_ID_TIGON3_5755
)},
200 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, PCI_DEVICE_ID_TIGON3_5755M
)},
201 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, PCI_DEVICE_ID_TIGON3_5756
)},
202 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, PCI_DEVICE_ID_TIGON3_5786
)},
203 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, PCI_DEVICE_ID_TIGON3_5787
)},
204 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, PCI_DEVICE_ID_TIGON3_5787M
)},
205 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, PCI_DEVICE_ID_TIGON3_5787F
)},
206 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, PCI_DEVICE_ID_TIGON3_5714
)},
207 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, PCI_DEVICE_ID_TIGON3_5714S
)},
208 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, PCI_DEVICE_ID_TIGON3_5715
)},
209 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, PCI_DEVICE_ID_TIGON3_5715S
)},
210 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, PCI_DEVICE_ID_TIGON3_5780
)},
211 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, PCI_DEVICE_ID_TIGON3_5780S
)},
212 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, PCI_DEVICE_ID_TIGON3_5781
)},
213 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, PCI_DEVICE_ID_TIGON3_5906
)},
214 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, PCI_DEVICE_ID_TIGON3_5906M
)},
215 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, PCI_DEVICE_ID_TIGON3_5784
)},
216 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, PCI_DEVICE_ID_TIGON3_5764
)},
217 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, PCI_DEVICE_ID_TIGON3_5723
)},
218 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, PCI_DEVICE_ID_TIGON3_5761
)},
219 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, PCI_DEVICE_ID_TIGON3_5761E
)},
220 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, TG3PCI_DEVICE_TIGON3_5761S
)},
221 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, TG3PCI_DEVICE_TIGON3_5761SE
)},
222 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, PCI_DEVICE_ID_TIGON3_5785
)},
223 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, TG3PCI_DEVICE_TIGON3_57780
)},
224 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, TG3PCI_DEVICE_TIGON3_57760
)},
225 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, TG3PCI_DEVICE_TIGON3_57790
)},
226 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, TG3PCI_DEVICE_TIGON3_57720
)},
227 {PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT
, PCI_DEVICE_ID_SYSKONNECT_9DXX
)},
228 {PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT
, PCI_DEVICE_ID_SYSKONNECT_9MXX
)},
229 {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA
, PCI_DEVICE_ID_ALTIMA_AC1000
)},
230 {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA
, PCI_DEVICE_ID_ALTIMA_AC1001
)},
231 {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA
, PCI_DEVICE_ID_ALTIMA_AC1003
)},
232 {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA
, PCI_DEVICE_ID_ALTIMA_AC9100
)},
233 {PCI_DEVICE(PCI_VENDOR_ID_APPLE
, PCI_DEVICE_ID_APPLE_TIGON3
)},
237 MODULE_DEVICE_TABLE(pci
, tg3_pci_tbl
);
239 static const struct {
240 const char string
[ETH_GSTRING_LEN
];
241 } ethtool_stats_keys
[TG3_NUM_STATS
] = {
244 { "rx_ucast_packets" },
245 { "rx_mcast_packets" },
246 { "rx_bcast_packets" },
248 { "rx_align_errors" },
249 { "rx_xon_pause_rcvd" },
250 { "rx_xoff_pause_rcvd" },
251 { "rx_mac_ctrl_rcvd" },
252 { "rx_xoff_entered" },
253 { "rx_frame_too_long_errors" },
255 { "rx_undersize_packets" },
256 { "rx_in_length_errors" },
257 { "rx_out_length_errors" },
258 { "rx_64_or_less_octet_packets" },
259 { "rx_65_to_127_octet_packets" },
260 { "rx_128_to_255_octet_packets" },
261 { "rx_256_to_511_octet_packets" },
262 { "rx_512_to_1023_octet_packets" },
263 { "rx_1024_to_1522_octet_packets" },
264 { "rx_1523_to_2047_octet_packets" },
265 { "rx_2048_to_4095_octet_packets" },
266 { "rx_4096_to_8191_octet_packets" },
267 { "rx_8192_to_9022_octet_packets" },
274 { "tx_flow_control" },
276 { "tx_single_collisions" },
277 { "tx_mult_collisions" },
279 { "tx_excessive_collisions" },
280 { "tx_late_collisions" },
281 { "tx_collide_2times" },
282 { "tx_collide_3times" },
283 { "tx_collide_4times" },
284 { "tx_collide_5times" },
285 { "tx_collide_6times" },
286 { "tx_collide_7times" },
287 { "tx_collide_8times" },
288 { "tx_collide_9times" },
289 { "tx_collide_10times" },
290 { "tx_collide_11times" },
291 { "tx_collide_12times" },
292 { "tx_collide_13times" },
293 { "tx_collide_14times" },
294 { "tx_collide_15times" },
295 { "tx_ucast_packets" },
296 { "tx_mcast_packets" },
297 { "tx_bcast_packets" },
298 { "tx_carrier_sense_errors" },
302 { "dma_writeq_full" },
303 { "dma_write_prioq_full" },
307 { "rx_threshold_hit" },
309 { "dma_readq_full" },
310 { "dma_read_prioq_full" },
311 { "tx_comp_queue_full" },
313 { "ring_set_send_prod_index" },
314 { "ring_status_update" },
316 { "nic_avoided_irqs" },
317 { "nic_tx_threshold_hit" }
320 static const struct {
321 const char string
[ETH_GSTRING_LEN
];
322 } ethtool_test_keys
[TG3_NUM_TEST
] = {
323 { "nvram test (online) " },
324 { "link test (online) " },
325 { "register test (offline)" },
326 { "memory test (offline)" },
327 { "loopback test (offline)" },
328 { "interrupt test (offline)" },
331 static void tg3_write32(struct tg3
*tp
, u32 off
, u32 val
)
333 writel(val
, tp
->regs
+ off
);
336 static u32
tg3_read32(struct tg3
*tp
, u32 off
)
338 return (readl(tp
->regs
+ off
));
341 static void tg3_ape_write32(struct tg3
*tp
, u32 off
, u32 val
)
343 writel(val
, tp
->aperegs
+ off
);
346 static u32
tg3_ape_read32(struct tg3
*tp
, u32 off
)
348 return (readl(tp
->aperegs
+ off
));
351 static void tg3_write_indirect_reg32(struct tg3
*tp
, u32 off
, u32 val
)
355 spin_lock_irqsave(&tp
->indirect_lock
, flags
);
356 pci_write_config_dword(tp
->pdev
, TG3PCI_REG_BASE_ADDR
, off
);
357 pci_write_config_dword(tp
->pdev
, TG3PCI_REG_DATA
, val
);
358 spin_unlock_irqrestore(&tp
->indirect_lock
, flags
);
361 static void tg3_write_flush_reg32(struct tg3
*tp
, u32 off
, u32 val
)
363 writel(val
, tp
->regs
+ off
);
364 readl(tp
->regs
+ off
);
367 static u32
tg3_read_indirect_reg32(struct tg3
*tp
, u32 off
)
372 spin_lock_irqsave(&tp
->indirect_lock
, flags
);
373 pci_write_config_dword(tp
->pdev
, TG3PCI_REG_BASE_ADDR
, off
);
374 pci_read_config_dword(tp
->pdev
, TG3PCI_REG_DATA
, &val
);
375 spin_unlock_irqrestore(&tp
->indirect_lock
, flags
);
379 static void tg3_write_indirect_mbox(struct tg3
*tp
, u32 off
, u32 val
)
383 if (off
== (MAILBOX_RCVRET_CON_IDX_0
+ TG3_64BIT_REG_LOW
)) {
384 pci_write_config_dword(tp
->pdev
, TG3PCI_RCV_RET_RING_CON_IDX
+
385 TG3_64BIT_REG_LOW
, val
);
388 if (off
== (MAILBOX_RCV_STD_PROD_IDX
+ TG3_64BIT_REG_LOW
)) {
389 pci_write_config_dword(tp
->pdev
, TG3PCI_STD_RING_PROD_IDX
+
390 TG3_64BIT_REG_LOW
, val
);
394 spin_lock_irqsave(&tp
->indirect_lock
, flags
);
395 pci_write_config_dword(tp
->pdev
, TG3PCI_REG_BASE_ADDR
, off
+ 0x5600);
396 pci_write_config_dword(tp
->pdev
, TG3PCI_REG_DATA
, val
);
397 spin_unlock_irqrestore(&tp
->indirect_lock
, flags
);
399 /* In indirect mode when disabling interrupts, we also need
400 * to clear the interrupt bit in the GRC local ctrl register.
402 if ((off
== (MAILBOX_INTERRUPT_0
+ TG3_64BIT_REG_LOW
)) &&
404 pci_write_config_dword(tp
->pdev
, TG3PCI_MISC_LOCAL_CTRL
,
405 tp
->grc_local_ctrl
|GRC_LCLCTRL_CLEARINT
);
409 static u32
tg3_read_indirect_mbox(struct tg3
*tp
, u32 off
)
414 spin_lock_irqsave(&tp
->indirect_lock
, flags
);
415 pci_write_config_dword(tp
->pdev
, TG3PCI_REG_BASE_ADDR
, off
+ 0x5600);
416 pci_read_config_dword(tp
->pdev
, TG3PCI_REG_DATA
, &val
);
417 spin_unlock_irqrestore(&tp
->indirect_lock
, flags
);
421 /* usec_wait specifies the wait time in usec when writing to certain registers
422 * where it is unsafe to read back the register without some delay.
423 * GRC_LOCAL_CTRL is one example if the GPIOs are toggled to switch power.
424 * TG3PCI_CLOCK_CTRL is another example if the clock frequencies are changed.
426 static void _tw32_flush(struct tg3
*tp
, u32 off
, u32 val
, u32 usec_wait
)
428 if ((tp
->tg3_flags
& TG3_FLAG_PCIX_TARGET_HWBUG
) ||
429 (tp
->tg3_flags2
& TG3_FLG2_ICH_WORKAROUND
))
430 /* Non-posted methods */
431 tp
->write32(tp
, off
, val
);
434 tg3_write32(tp
, off
, val
);
439 /* Wait again after the read for the posted method to guarantee that
440 * the wait time is met.
446 static inline void tw32_mailbox_flush(struct tg3
*tp
, u32 off
, u32 val
)
448 tp
->write32_mbox(tp
, off
, val
);
449 if (!(tp
->tg3_flags
& TG3_FLAG_MBOX_WRITE_REORDER
) &&
450 !(tp
->tg3_flags2
& TG3_FLG2_ICH_WORKAROUND
))
451 tp
->read32_mbox(tp
, off
);
454 static void tg3_write32_tx_mbox(struct tg3
*tp
, u32 off
, u32 val
)
456 void __iomem
*mbox
= tp
->regs
+ off
;
458 if (tp
->tg3_flags
& TG3_FLAG_TXD_MBOX_HWBUG
)
460 if (tp
->tg3_flags
& TG3_FLAG_MBOX_WRITE_REORDER
)
464 static u32
tg3_read32_mbox_5906(struct tg3
*tp
, u32 off
)
466 return (readl(tp
->regs
+ off
+ GRCMBOX_BASE
));
469 static void tg3_write32_mbox_5906(struct tg3
*tp
, u32 off
, u32 val
)
471 writel(val
, tp
->regs
+ off
+ GRCMBOX_BASE
);
474 #define tw32_mailbox(reg, val) tp->write32_mbox(tp, reg, val)
475 #define tw32_mailbox_f(reg, val) tw32_mailbox_flush(tp, (reg), (val))
476 #define tw32_rx_mbox(reg, val) tp->write32_rx_mbox(tp, reg, val)
477 #define tw32_tx_mbox(reg, val) tp->write32_tx_mbox(tp, reg, val)
478 #define tr32_mailbox(reg) tp->read32_mbox(tp, reg)
480 #define tw32(reg,val) tp->write32(tp, reg, val)
481 #define tw32_f(reg,val) _tw32_flush(tp,(reg),(val), 0)
482 #define tw32_wait_f(reg,val,us) _tw32_flush(tp,(reg),(val), (us))
483 #define tr32(reg) tp->read32(tp, reg)
485 static void tg3_write_mem(struct tg3
*tp
, u32 off
, u32 val
)
489 if ((GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5906
) &&
490 (off
>= NIC_SRAM_STATS_BLK
) && (off
< NIC_SRAM_TX_BUFFER_DESC
))
493 spin_lock_irqsave(&tp
->indirect_lock
, flags
);
494 if (tp
->tg3_flags
& TG3_FLAG_SRAM_USE_CONFIG
) {
495 pci_write_config_dword(tp
->pdev
, TG3PCI_MEM_WIN_BASE_ADDR
, off
);
496 pci_write_config_dword(tp
->pdev
, TG3PCI_MEM_WIN_DATA
, val
);
498 /* Always leave this as zero. */
499 pci_write_config_dword(tp
->pdev
, TG3PCI_MEM_WIN_BASE_ADDR
, 0);
501 tw32_f(TG3PCI_MEM_WIN_BASE_ADDR
, off
);
502 tw32_f(TG3PCI_MEM_WIN_DATA
, val
);
504 /* Always leave this as zero. */
505 tw32_f(TG3PCI_MEM_WIN_BASE_ADDR
, 0);
507 spin_unlock_irqrestore(&tp
->indirect_lock
, flags
);
510 static void tg3_read_mem(struct tg3
*tp
, u32 off
, u32
*val
)
514 if ((GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5906
) &&
515 (off
>= NIC_SRAM_STATS_BLK
) && (off
< NIC_SRAM_TX_BUFFER_DESC
)) {
520 spin_lock_irqsave(&tp
->indirect_lock
, flags
);
521 if (tp
->tg3_flags
& TG3_FLAG_SRAM_USE_CONFIG
) {
522 pci_write_config_dword(tp
->pdev
, TG3PCI_MEM_WIN_BASE_ADDR
, off
);
523 pci_read_config_dword(tp
->pdev
, TG3PCI_MEM_WIN_DATA
, val
);
525 /* Always leave this as zero. */
526 pci_write_config_dword(tp
->pdev
, TG3PCI_MEM_WIN_BASE_ADDR
, 0);
528 tw32_f(TG3PCI_MEM_WIN_BASE_ADDR
, off
);
529 *val
= tr32(TG3PCI_MEM_WIN_DATA
);
531 /* Always leave this as zero. */
532 tw32_f(TG3PCI_MEM_WIN_BASE_ADDR
, 0);
534 spin_unlock_irqrestore(&tp
->indirect_lock
, flags
);
537 static void tg3_ape_lock_init(struct tg3
*tp
)
541 /* Make sure the driver hasn't any stale locks. */
542 for (i
= 0; i
< 8; i
++)
543 tg3_ape_write32(tp
, TG3_APE_LOCK_GRANT
+ 4 * i
,
544 APE_LOCK_GRANT_DRIVER
);
547 static int tg3_ape_lock(struct tg3
*tp
, int locknum
)
553 if (!(tp
->tg3_flags3
& TG3_FLG3_ENABLE_APE
))
557 case TG3_APE_LOCK_GRC
:
558 case TG3_APE_LOCK_MEM
:
566 tg3_ape_write32(tp
, TG3_APE_LOCK_REQ
+ off
, APE_LOCK_REQ_DRIVER
);
568 /* Wait for up to 1 millisecond to acquire lock. */
569 for (i
= 0; i
< 100; i
++) {
570 status
= tg3_ape_read32(tp
, TG3_APE_LOCK_GRANT
+ off
);
571 if (status
== APE_LOCK_GRANT_DRIVER
)
576 if (status
!= APE_LOCK_GRANT_DRIVER
) {
577 /* Revoke the lock request. */
578 tg3_ape_write32(tp
, TG3_APE_LOCK_GRANT
+ off
,
579 APE_LOCK_GRANT_DRIVER
);
587 static void tg3_ape_unlock(struct tg3
*tp
, int locknum
)
591 if (!(tp
->tg3_flags3
& TG3_FLG3_ENABLE_APE
))
595 case TG3_APE_LOCK_GRC
:
596 case TG3_APE_LOCK_MEM
:
603 tg3_ape_write32(tp
, TG3_APE_LOCK_GRANT
+ off
, APE_LOCK_GRANT_DRIVER
);
606 static void tg3_disable_ints(struct tg3
*tp
)
608 tw32(TG3PCI_MISC_HOST_CTRL
,
609 (tp
->misc_host_ctrl
| MISC_HOST_CTRL_MASK_PCI_INT
));
610 tw32_mailbox_f(MAILBOX_INTERRUPT_0
+ TG3_64BIT_REG_LOW
, 0x00000001);
613 static inline void tg3_cond_int(struct tg3
*tp
)
615 if (!(tp
->tg3_flags
& TG3_FLAG_TAGGED_STATUS
) &&
616 (tp
->hw_status
->status
& SD_STATUS_UPDATED
))
617 tw32(GRC_LOCAL_CTRL
, tp
->grc_local_ctrl
| GRC_LCLCTRL_SETINT
);
619 tw32(HOSTCC_MODE
, tp
->coalesce_mode
|
620 (HOSTCC_MODE_ENABLE
| HOSTCC_MODE_NOW
));
623 static void tg3_enable_ints(struct tg3
*tp
)
628 tw32(TG3PCI_MISC_HOST_CTRL
,
629 (tp
->misc_host_ctrl
& ~MISC_HOST_CTRL_MASK_PCI_INT
));
630 tw32_mailbox_f(MAILBOX_INTERRUPT_0
+ TG3_64BIT_REG_LOW
,
631 (tp
->last_tag
<< 24));
632 if (tp
->tg3_flags2
& TG3_FLG2_1SHOT_MSI
)
633 tw32_mailbox_f(MAILBOX_INTERRUPT_0
+ TG3_64BIT_REG_LOW
,
634 (tp
->last_tag
<< 24));
638 static inline unsigned int tg3_has_work(struct tg3
*tp
)
640 struct tg3_hw_status
*sblk
= tp
->hw_status
;
641 unsigned int work_exists
= 0;
643 /* check for phy events */
644 if (!(tp
->tg3_flags
&
645 (TG3_FLAG_USE_LINKCHG_REG
|
646 TG3_FLAG_POLL_SERDES
))) {
647 if (sblk
->status
& SD_STATUS_LINK_CHG
)
650 /* check for RX/TX work to do */
651 if (sblk
->idx
[0].tx_consumer
!= tp
->tx_cons
||
652 sblk
->idx
[0].rx_producer
!= tp
->rx_rcb_ptr
)
659 * similar to tg3_enable_ints, but it accurately determines whether there
660 * is new work pending and can return without flushing the PIO write
661 * which reenables interrupts
663 static void tg3_restart_ints(struct tg3
*tp
)
665 tw32_mailbox(MAILBOX_INTERRUPT_0
+ TG3_64BIT_REG_LOW
,
669 /* When doing tagged status, this work check is unnecessary.
670 * The last_tag we write above tells the chip which piece of
671 * work we've completed.
673 if (!(tp
->tg3_flags
& TG3_FLAG_TAGGED_STATUS
) &&
675 tw32(HOSTCC_MODE
, tp
->coalesce_mode
|
676 (HOSTCC_MODE_ENABLE
| HOSTCC_MODE_NOW
));
679 static inline void tg3_netif_stop(struct tg3
*tp
)
681 tp
->dev
->trans_start
= jiffies
; /* prevent tx timeout */
682 napi_disable(&tp
->napi
);
683 netif_tx_disable(tp
->dev
);
686 static inline void tg3_netif_start(struct tg3
*tp
)
688 netif_wake_queue(tp
->dev
);
689 /* NOTE: unconditional netif_wake_queue is only appropriate
690 * so long as all callers are assured to have free tx slots
691 * (such as after tg3_init_hw)
693 napi_enable(&tp
->napi
);
694 tp
->hw_status
->status
|= SD_STATUS_UPDATED
;
698 static void tg3_switch_clocks(struct tg3
*tp
)
700 u32 clock_ctrl
= tr32(TG3PCI_CLOCK_CTRL
);
703 if ((tp
->tg3_flags
& TG3_FLAG_CPMU_PRESENT
) ||
704 (tp
->tg3_flags2
& TG3_FLG2_5780_CLASS
))
707 orig_clock_ctrl
= clock_ctrl
;
708 clock_ctrl
&= (CLOCK_CTRL_FORCE_CLKRUN
|
709 CLOCK_CTRL_CLKRUN_OENABLE
|
711 tp
->pci_clock_ctrl
= clock_ctrl
;
713 if (tp
->tg3_flags2
& TG3_FLG2_5705_PLUS
) {
714 if (orig_clock_ctrl
& CLOCK_CTRL_625_CORE
) {
715 tw32_wait_f(TG3PCI_CLOCK_CTRL
,
716 clock_ctrl
| CLOCK_CTRL_625_CORE
, 40);
718 } else if ((orig_clock_ctrl
& CLOCK_CTRL_44MHZ_CORE
) != 0) {
719 tw32_wait_f(TG3PCI_CLOCK_CTRL
,
721 (CLOCK_CTRL_44MHZ_CORE
| CLOCK_CTRL_ALTCLK
),
723 tw32_wait_f(TG3PCI_CLOCK_CTRL
,
724 clock_ctrl
| (CLOCK_CTRL_ALTCLK
),
727 tw32_wait_f(TG3PCI_CLOCK_CTRL
, clock_ctrl
, 40);
730 #define PHY_BUSY_LOOPS 5000
732 static int tg3_readphy(struct tg3
*tp
, int reg
, u32
*val
)
738 if ((tp
->mi_mode
& MAC_MI_MODE_AUTO_POLL
) != 0) {
740 (tp
->mi_mode
& ~MAC_MI_MODE_AUTO_POLL
));
746 frame_val
= ((PHY_ADDR
<< MI_COM_PHY_ADDR_SHIFT
) &
747 MI_COM_PHY_ADDR_MASK
);
748 frame_val
|= ((reg
<< MI_COM_REG_ADDR_SHIFT
) &
749 MI_COM_REG_ADDR_MASK
);
750 frame_val
|= (MI_COM_CMD_READ
| MI_COM_START
);
752 tw32_f(MAC_MI_COM
, frame_val
);
754 loops
= PHY_BUSY_LOOPS
;
757 frame_val
= tr32(MAC_MI_COM
);
759 if ((frame_val
& MI_COM_BUSY
) == 0) {
761 frame_val
= tr32(MAC_MI_COM
);
769 *val
= frame_val
& MI_COM_DATA_MASK
;
773 if ((tp
->mi_mode
& MAC_MI_MODE_AUTO_POLL
) != 0) {
774 tw32_f(MAC_MI_MODE
, tp
->mi_mode
);
781 static int tg3_writephy(struct tg3
*tp
, int reg
, u32 val
)
787 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5906
&&
788 (reg
== MII_TG3_CTRL
|| reg
== MII_TG3_AUX_CTRL
))
791 if ((tp
->mi_mode
& MAC_MI_MODE_AUTO_POLL
) != 0) {
793 (tp
->mi_mode
& ~MAC_MI_MODE_AUTO_POLL
));
797 frame_val
= ((PHY_ADDR
<< MI_COM_PHY_ADDR_SHIFT
) &
798 MI_COM_PHY_ADDR_MASK
);
799 frame_val
|= ((reg
<< MI_COM_REG_ADDR_SHIFT
) &
800 MI_COM_REG_ADDR_MASK
);
801 frame_val
|= (val
& MI_COM_DATA_MASK
);
802 frame_val
|= (MI_COM_CMD_WRITE
| MI_COM_START
);
804 tw32_f(MAC_MI_COM
, frame_val
);
806 loops
= PHY_BUSY_LOOPS
;
809 frame_val
= tr32(MAC_MI_COM
);
810 if ((frame_val
& MI_COM_BUSY
) == 0) {
812 frame_val
= tr32(MAC_MI_COM
);
822 if ((tp
->mi_mode
& MAC_MI_MODE_AUTO_POLL
) != 0) {
823 tw32_f(MAC_MI_MODE
, tp
->mi_mode
);
830 static int tg3_bmcr_reset(struct tg3
*tp
)
835 /* OK, reset it, and poll the BMCR_RESET bit until it
836 * clears or we time out.
838 phy_control
= BMCR_RESET
;
839 err
= tg3_writephy(tp
, MII_BMCR
, phy_control
);
845 err
= tg3_readphy(tp
, MII_BMCR
, &phy_control
);
849 if ((phy_control
& BMCR_RESET
) == 0) {
861 static int tg3_mdio_read(struct mii_bus
*bp
, int mii_id
, int reg
)
863 struct tg3
*tp
= (struct tg3
*)bp
->priv
;
866 if (tp
->tg3_flags3
& TG3_FLG3_MDIOBUS_PAUSED
)
869 if (tg3_readphy(tp
, reg
, &val
))
875 static int tg3_mdio_write(struct mii_bus
*bp
, int mii_id
, int reg
, u16 val
)
877 struct tg3
*tp
= (struct tg3
*)bp
->priv
;
879 if (tp
->tg3_flags3
& TG3_FLG3_MDIOBUS_PAUSED
)
882 if (tg3_writephy(tp
, reg
, val
))
888 static int tg3_mdio_reset(struct mii_bus
*bp
)
893 static void tg3_mdio_config_5785(struct tg3
*tp
)
896 struct phy_device
*phydev
;
898 phydev
= tp
->mdio_bus
->phy_map
[PHY_ADDR
];
899 switch (phydev
->drv
->phy_id
& phydev
->drv
->phy_id_mask
) {
900 case TG3_PHY_ID_BCM50610
:
901 val
= MAC_PHYCFG2_50610_LED_MODES
;
903 case TG3_PHY_ID_BCMAC131
:
904 val
= MAC_PHYCFG2_AC131_LED_MODES
;
906 case TG3_PHY_ID_RTL8211C
:
907 val
= MAC_PHYCFG2_RTL8211C_LED_MODES
;
909 case TG3_PHY_ID_RTL8201E
:
910 val
= MAC_PHYCFG2_RTL8201E_LED_MODES
;
916 if (phydev
->interface
!= PHY_INTERFACE_MODE_RGMII
) {
917 tw32(MAC_PHYCFG2
, val
);
919 val
= tr32(MAC_PHYCFG1
);
920 val
&= ~MAC_PHYCFG1_RGMII_INT
;
921 tw32(MAC_PHYCFG1
, val
);
926 if (!(tp
->tg3_flags3
& TG3_FLG3_RGMII_STD_IBND_DISABLE
))
927 val
|= MAC_PHYCFG2_EMODE_MASK_MASK
|
928 MAC_PHYCFG2_FMODE_MASK_MASK
|
929 MAC_PHYCFG2_GMODE_MASK_MASK
|
930 MAC_PHYCFG2_ACT_MASK_MASK
|
931 MAC_PHYCFG2_QUAL_MASK_MASK
|
932 MAC_PHYCFG2_INBAND_ENABLE
;
934 tw32(MAC_PHYCFG2
, val
);
936 val
= tr32(MAC_PHYCFG1
) & ~(MAC_PHYCFG1_RGMII_EXT_RX_DEC
|
937 MAC_PHYCFG1_RGMII_SND_STAT_EN
);
938 if (tp
->tg3_flags3
& TG3_FLG3_RGMII_STD_IBND_DISABLE
) {
939 if (tp
->tg3_flags3
& TG3_FLG3_RGMII_EXT_IBND_RX_EN
)
940 val
|= MAC_PHYCFG1_RGMII_EXT_RX_DEC
;
941 if (tp
->tg3_flags3
& TG3_FLG3_RGMII_EXT_IBND_TX_EN
)
942 val
|= MAC_PHYCFG1_RGMII_SND_STAT_EN
;
944 tw32(MAC_PHYCFG1
, val
| MAC_PHYCFG1_RGMII_INT
| MAC_PHYCFG1_TXC_DRV
);
946 val
= tr32(MAC_EXT_RGMII_MODE
);
947 val
&= ~(MAC_RGMII_MODE_RX_INT_B
|
948 MAC_RGMII_MODE_RX_QUALITY
|
949 MAC_RGMII_MODE_RX_ACTIVITY
|
950 MAC_RGMII_MODE_RX_ENG_DET
|
951 MAC_RGMII_MODE_TX_ENABLE
|
952 MAC_RGMII_MODE_TX_LOWPWR
|
953 MAC_RGMII_MODE_TX_RESET
);
954 if (!(tp
->tg3_flags3
& TG3_FLG3_RGMII_STD_IBND_DISABLE
)) {
955 if (tp
->tg3_flags3
& TG3_FLG3_RGMII_EXT_IBND_RX_EN
)
956 val
|= MAC_RGMII_MODE_RX_INT_B
|
957 MAC_RGMII_MODE_RX_QUALITY
|
958 MAC_RGMII_MODE_RX_ACTIVITY
|
959 MAC_RGMII_MODE_RX_ENG_DET
;
960 if (tp
->tg3_flags3
& TG3_FLG3_RGMII_EXT_IBND_TX_EN
)
961 val
|= MAC_RGMII_MODE_TX_ENABLE
|
962 MAC_RGMII_MODE_TX_LOWPWR
|
963 MAC_RGMII_MODE_TX_RESET
;
965 tw32(MAC_EXT_RGMII_MODE
, val
);
968 static void tg3_mdio_start(struct tg3
*tp
)
970 if (tp
->tg3_flags3
& TG3_FLG3_MDIOBUS_INITED
) {
971 mutex_lock(&tp
->mdio_bus
->mdio_lock
);
972 tp
->tg3_flags3
&= ~TG3_FLG3_MDIOBUS_PAUSED
;
973 mutex_unlock(&tp
->mdio_bus
->mdio_lock
);
976 tp
->mi_mode
&= ~MAC_MI_MODE_AUTO_POLL
;
977 tw32_f(MAC_MI_MODE
, tp
->mi_mode
);
980 if ((tp
->tg3_flags3
& TG3_FLG3_MDIOBUS_INITED
) &&
981 GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5785
)
982 tg3_mdio_config_5785(tp
);
985 static void tg3_mdio_stop(struct tg3
*tp
)
987 if (tp
->tg3_flags3
& TG3_FLG3_MDIOBUS_INITED
) {
988 mutex_lock(&tp
->mdio_bus
->mdio_lock
);
989 tp
->tg3_flags3
|= TG3_FLG3_MDIOBUS_PAUSED
;
990 mutex_unlock(&tp
->mdio_bus
->mdio_lock
);
994 static int tg3_mdio_init(struct tg3
*tp
)
998 struct phy_device
*phydev
;
1002 if (!(tp
->tg3_flags3
& TG3_FLG3_USE_PHYLIB
) ||
1003 (tp
->tg3_flags3
& TG3_FLG3_MDIOBUS_INITED
))
1006 tp
->mdio_bus
= mdiobus_alloc();
1007 if (tp
->mdio_bus
== NULL
)
1010 tp
->mdio_bus
->name
= "tg3 mdio bus";
1011 snprintf(tp
->mdio_bus
->id
, MII_BUS_ID_SIZE
, "%x",
1012 (tp
->pdev
->bus
->number
<< 8) | tp
->pdev
->devfn
);
1013 tp
->mdio_bus
->priv
= tp
;
1014 tp
->mdio_bus
->parent
= &tp
->pdev
->dev
;
1015 tp
->mdio_bus
->read
= &tg3_mdio_read
;
1016 tp
->mdio_bus
->write
= &tg3_mdio_write
;
1017 tp
->mdio_bus
->reset
= &tg3_mdio_reset
;
1018 tp
->mdio_bus
->phy_mask
= ~(1 << PHY_ADDR
);
1019 tp
->mdio_bus
->irq
= &tp
->mdio_irq
[0];
1021 for (i
= 0; i
< PHY_MAX_ADDR
; i
++)
1022 tp
->mdio_bus
->irq
[i
] = PHY_POLL
;
1024 /* The bus registration will look for all the PHYs on the mdio bus.
1025 * Unfortunately, it does not ensure the PHY is powered up before
1026 * accessing the PHY ID registers. A chip reset is the
1027 * quickest way to bring the device back to an operational state..
1029 if (tg3_readphy(tp
, MII_BMCR
, ®
) || (reg
& BMCR_PDOWN
))
1032 i
= mdiobus_register(tp
->mdio_bus
);
1034 printk(KERN_WARNING
"%s: mdiobus_reg failed (0x%x)\n",
1036 mdiobus_free(tp
->mdio_bus
);
1040 phydev
= tp
->mdio_bus
->phy_map
[PHY_ADDR
];
1042 if (!phydev
|| !phydev
->drv
) {
1043 printk(KERN_WARNING
"%s: No PHY devices\n", tp
->dev
->name
);
1044 mdiobus_unregister(tp
->mdio_bus
);
1045 mdiobus_free(tp
->mdio_bus
);
1049 switch (phydev
->drv
->phy_id
& phydev
->drv
->phy_id_mask
) {
1050 case TG3_PHY_ID_BCM57780
:
1051 phydev
->interface
= PHY_INTERFACE_MODE_GMII
;
1053 case TG3_PHY_ID_BCM50610
:
1054 if (tp
->tg3_flags3
& TG3_FLG3_RGMII_STD_IBND_DISABLE
)
1055 phydev
->dev_flags
|= PHY_BRCM_STD_IBND_DISABLE
;
1056 if (tp
->tg3_flags3
& TG3_FLG3_RGMII_EXT_IBND_RX_EN
)
1057 phydev
->dev_flags
|= PHY_BRCM_EXT_IBND_RX_ENABLE
;
1058 if (tp
->tg3_flags3
& TG3_FLG3_RGMII_EXT_IBND_TX_EN
)
1059 phydev
->dev_flags
|= PHY_BRCM_EXT_IBND_TX_ENABLE
;
1061 case TG3_PHY_ID_RTL8211C
:
1062 phydev
->interface
= PHY_INTERFACE_MODE_RGMII
;
1064 case TG3_PHY_ID_RTL8201E
:
1065 case TG3_PHY_ID_BCMAC131
:
1066 phydev
->interface
= PHY_INTERFACE_MODE_MII
;
1070 tp
->tg3_flags3
|= TG3_FLG3_MDIOBUS_INITED
;
1072 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5785
)
1073 tg3_mdio_config_5785(tp
);
1078 static void tg3_mdio_fini(struct tg3
*tp
)
1080 if (tp
->tg3_flags3
& TG3_FLG3_MDIOBUS_INITED
) {
1081 tp
->tg3_flags3
&= ~TG3_FLG3_MDIOBUS_INITED
;
1082 mdiobus_unregister(tp
->mdio_bus
);
1083 mdiobus_free(tp
->mdio_bus
);
1084 tp
->tg3_flags3
&= ~TG3_FLG3_MDIOBUS_PAUSED
;
1088 /* tp->lock is held. */
1089 static inline void tg3_generate_fw_event(struct tg3
*tp
)
1093 val
= tr32(GRC_RX_CPU_EVENT
);
1094 val
|= GRC_RX_CPU_DRIVER_EVENT
;
1095 tw32_f(GRC_RX_CPU_EVENT
, val
);
1097 tp
->last_event_jiffies
= jiffies
;
1100 #define TG3_FW_EVENT_TIMEOUT_USEC 2500
1102 /* tp->lock is held. */
1103 static void tg3_wait_for_event_ack(struct tg3
*tp
)
1106 unsigned int delay_cnt
;
1109 /* If enough time has passed, no wait is necessary. */
1110 time_remain
= (long)(tp
->last_event_jiffies
+ 1 +
1111 usecs_to_jiffies(TG3_FW_EVENT_TIMEOUT_USEC
)) -
1113 if (time_remain
< 0)
1116 /* Check if we can shorten the wait time. */
1117 delay_cnt
= jiffies_to_usecs(time_remain
);
1118 if (delay_cnt
> TG3_FW_EVENT_TIMEOUT_USEC
)
1119 delay_cnt
= TG3_FW_EVENT_TIMEOUT_USEC
;
1120 delay_cnt
= (delay_cnt
>> 3) + 1;
1122 for (i
= 0; i
< delay_cnt
; i
++) {
1123 if (!(tr32(GRC_RX_CPU_EVENT
) & GRC_RX_CPU_DRIVER_EVENT
))
1129 /* tp->lock is held. */
1130 static void tg3_ump_link_report(struct tg3
*tp
)
1135 if (!(tp
->tg3_flags2
& TG3_FLG2_5780_CLASS
) ||
1136 !(tp
->tg3_flags
& TG3_FLAG_ENABLE_ASF
))
1139 tg3_wait_for_event_ack(tp
);
1141 tg3_write_mem(tp
, NIC_SRAM_FW_CMD_MBOX
, FWCMD_NICDRV_LINK_UPDATE
);
1143 tg3_write_mem(tp
, NIC_SRAM_FW_CMD_LEN_MBOX
, 14);
1146 if (!tg3_readphy(tp
, MII_BMCR
, ®
))
1148 if (!tg3_readphy(tp
, MII_BMSR
, ®
))
1149 val
|= (reg
& 0xffff);
1150 tg3_write_mem(tp
, NIC_SRAM_FW_CMD_DATA_MBOX
, val
);
1153 if (!tg3_readphy(tp
, MII_ADVERTISE
, ®
))
1155 if (!tg3_readphy(tp
, MII_LPA
, ®
))
1156 val
|= (reg
& 0xffff);
1157 tg3_write_mem(tp
, NIC_SRAM_FW_CMD_DATA_MBOX
+ 4, val
);
1160 if (!(tp
->tg3_flags2
& TG3_FLG2_MII_SERDES
)) {
1161 if (!tg3_readphy(tp
, MII_CTRL1000
, ®
))
1163 if (!tg3_readphy(tp
, MII_STAT1000
, ®
))
1164 val
|= (reg
& 0xffff);
1166 tg3_write_mem(tp
, NIC_SRAM_FW_CMD_DATA_MBOX
+ 8, val
);
1168 if (!tg3_readphy(tp
, MII_PHYADDR
, ®
))
1172 tg3_write_mem(tp
, NIC_SRAM_FW_CMD_DATA_MBOX
+ 12, val
);
1174 tg3_generate_fw_event(tp
);
1177 static void tg3_link_report(struct tg3
*tp
)
1179 if (!netif_carrier_ok(tp
->dev
)) {
1180 if (netif_msg_link(tp
))
1181 printk(KERN_INFO PFX
"%s: Link is down.\n",
1183 tg3_ump_link_report(tp
);
1184 } else if (netif_msg_link(tp
)) {
1185 printk(KERN_INFO PFX
"%s: Link is up at %d Mbps, %s duplex.\n",
1187 (tp
->link_config
.active_speed
== SPEED_1000
?
1189 (tp
->link_config
.active_speed
== SPEED_100
?
1191 (tp
->link_config
.active_duplex
== DUPLEX_FULL
?
1194 printk(KERN_INFO PFX
1195 "%s: Flow control is %s for TX and %s for RX.\n",
1197 (tp
->link_config
.active_flowctrl
& FLOW_CTRL_TX
) ?
1199 (tp
->link_config
.active_flowctrl
& FLOW_CTRL_RX
) ?
1201 tg3_ump_link_report(tp
);
1205 static u16
tg3_advert_flowctrl_1000T(u8 flow_ctrl
)
1209 if ((flow_ctrl
& FLOW_CTRL_TX
) && (flow_ctrl
& FLOW_CTRL_RX
))
1210 miireg
= ADVERTISE_PAUSE_CAP
;
1211 else if (flow_ctrl
& FLOW_CTRL_TX
)
1212 miireg
= ADVERTISE_PAUSE_ASYM
;
1213 else if (flow_ctrl
& FLOW_CTRL_RX
)
1214 miireg
= ADVERTISE_PAUSE_CAP
| ADVERTISE_PAUSE_ASYM
;
1221 static u16
tg3_advert_flowctrl_1000X(u8 flow_ctrl
)
1225 if ((flow_ctrl
& FLOW_CTRL_TX
) && (flow_ctrl
& FLOW_CTRL_RX
))
1226 miireg
= ADVERTISE_1000XPAUSE
;
1227 else if (flow_ctrl
& FLOW_CTRL_TX
)
1228 miireg
= ADVERTISE_1000XPSE_ASYM
;
1229 else if (flow_ctrl
& FLOW_CTRL_RX
)
1230 miireg
= ADVERTISE_1000XPAUSE
| ADVERTISE_1000XPSE_ASYM
;
1237 static u8
tg3_resolve_flowctrl_1000X(u16 lcladv
, u16 rmtadv
)
1241 if (lcladv
& ADVERTISE_1000XPAUSE
) {
1242 if (lcladv
& ADVERTISE_1000XPSE_ASYM
) {
1243 if (rmtadv
& LPA_1000XPAUSE
)
1244 cap
= FLOW_CTRL_TX
| FLOW_CTRL_RX
;
1245 else if (rmtadv
& LPA_1000XPAUSE_ASYM
)
1248 if (rmtadv
& LPA_1000XPAUSE
)
1249 cap
= FLOW_CTRL_TX
| FLOW_CTRL_RX
;
1251 } else if (lcladv
& ADVERTISE_1000XPSE_ASYM
) {
1252 if ((rmtadv
& LPA_1000XPAUSE
) && (rmtadv
& LPA_1000XPAUSE_ASYM
))
1259 static void tg3_setup_flow_control(struct tg3
*tp
, u32 lcladv
, u32 rmtadv
)
1263 u32 old_rx_mode
= tp
->rx_mode
;
1264 u32 old_tx_mode
= tp
->tx_mode
;
1266 if (tp
->tg3_flags3
& TG3_FLG3_USE_PHYLIB
)
1267 autoneg
= tp
->mdio_bus
->phy_map
[PHY_ADDR
]->autoneg
;
1269 autoneg
= tp
->link_config
.autoneg
;
1271 if (autoneg
== AUTONEG_ENABLE
&&
1272 (tp
->tg3_flags
& TG3_FLAG_PAUSE_AUTONEG
)) {
1273 if (tp
->tg3_flags2
& TG3_FLG2_ANY_SERDES
)
1274 flowctrl
= tg3_resolve_flowctrl_1000X(lcladv
, rmtadv
);
1276 flowctrl
= mii_resolve_flowctrl_fdx(lcladv
, rmtadv
);
1278 flowctrl
= tp
->link_config
.flowctrl
;
1280 tp
->link_config
.active_flowctrl
= flowctrl
;
1282 if (flowctrl
& FLOW_CTRL_RX
)
1283 tp
->rx_mode
|= RX_MODE_FLOW_CTRL_ENABLE
;
1285 tp
->rx_mode
&= ~RX_MODE_FLOW_CTRL_ENABLE
;
1287 if (old_rx_mode
!= tp
->rx_mode
)
1288 tw32_f(MAC_RX_MODE
, tp
->rx_mode
);
1290 if (flowctrl
& FLOW_CTRL_TX
)
1291 tp
->tx_mode
|= TX_MODE_FLOW_CTRL_ENABLE
;
1293 tp
->tx_mode
&= ~TX_MODE_FLOW_CTRL_ENABLE
;
1295 if (old_tx_mode
!= tp
->tx_mode
)
1296 tw32_f(MAC_TX_MODE
, tp
->tx_mode
);
1299 static void tg3_adjust_link(struct net_device
*dev
)
1301 u8 oldflowctrl
, linkmesg
= 0;
1302 u32 mac_mode
, lcl_adv
, rmt_adv
;
1303 struct tg3
*tp
= netdev_priv(dev
);
1304 struct phy_device
*phydev
= tp
->mdio_bus
->phy_map
[PHY_ADDR
];
1306 spin_lock(&tp
->lock
);
1308 mac_mode
= tp
->mac_mode
& ~(MAC_MODE_PORT_MODE_MASK
|
1309 MAC_MODE_HALF_DUPLEX
);
1311 oldflowctrl
= tp
->link_config
.active_flowctrl
;
1317 if (phydev
->speed
== SPEED_100
|| phydev
->speed
== SPEED_10
)
1318 mac_mode
|= MAC_MODE_PORT_MODE_MII
;
1320 mac_mode
|= MAC_MODE_PORT_MODE_GMII
;
1322 if (phydev
->duplex
== DUPLEX_HALF
)
1323 mac_mode
|= MAC_MODE_HALF_DUPLEX
;
1325 lcl_adv
= tg3_advert_flowctrl_1000T(
1326 tp
->link_config
.flowctrl
);
1329 rmt_adv
= LPA_PAUSE_CAP
;
1330 if (phydev
->asym_pause
)
1331 rmt_adv
|= LPA_PAUSE_ASYM
;
1334 tg3_setup_flow_control(tp
, lcl_adv
, rmt_adv
);
1336 mac_mode
|= MAC_MODE_PORT_MODE_GMII
;
1338 if (mac_mode
!= tp
->mac_mode
) {
1339 tp
->mac_mode
= mac_mode
;
1340 tw32_f(MAC_MODE
, tp
->mac_mode
);
1344 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5785
) {
1345 if (phydev
->speed
== SPEED_10
)
1347 MAC_MI_STAT_10MBPS_MODE
|
1348 MAC_MI_STAT_LNKSTAT_ATTN_ENAB
);
1350 tw32(MAC_MI_STAT
, MAC_MI_STAT_LNKSTAT_ATTN_ENAB
);
1353 if (phydev
->speed
== SPEED_1000
&& phydev
->duplex
== DUPLEX_HALF
)
1354 tw32(MAC_TX_LENGTHS
,
1355 ((2 << TX_LENGTHS_IPG_CRS_SHIFT
) |
1356 (6 << TX_LENGTHS_IPG_SHIFT
) |
1357 (0xff << TX_LENGTHS_SLOT_TIME_SHIFT
)));
1359 tw32(MAC_TX_LENGTHS
,
1360 ((2 << TX_LENGTHS_IPG_CRS_SHIFT
) |
1361 (6 << TX_LENGTHS_IPG_SHIFT
) |
1362 (32 << TX_LENGTHS_SLOT_TIME_SHIFT
)));
1364 if ((phydev
->link
&& tp
->link_config
.active_speed
== SPEED_INVALID
) ||
1365 (!phydev
->link
&& tp
->link_config
.active_speed
!= SPEED_INVALID
) ||
1366 phydev
->speed
!= tp
->link_config
.active_speed
||
1367 phydev
->duplex
!= tp
->link_config
.active_duplex
||
1368 oldflowctrl
!= tp
->link_config
.active_flowctrl
)
1371 tp
->link_config
.active_speed
= phydev
->speed
;
1372 tp
->link_config
.active_duplex
= phydev
->duplex
;
1374 spin_unlock(&tp
->lock
);
1377 tg3_link_report(tp
);
1380 static int tg3_phy_init(struct tg3
*tp
)
1382 struct phy_device
*phydev
;
1384 if (tp
->tg3_flags3
& TG3_FLG3_PHY_CONNECTED
)
1387 /* Bring the PHY back to a known state. */
1390 phydev
= tp
->mdio_bus
->phy_map
[PHY_ADDR
];
1392 /* Attach the MAC to the PHY. */
1393 phydev
= phy_connect(tp
->dev
, dev_name(&phydev
->dev
), tg3_adjust_link
,
1394 phydev
->dev_flags
, phydev
->interface
);
1395 if (IS_ERR(phydev
)) {
1396 printk(KERN_ERR
"%s: Could not attach to PHY\n", tp
->dev
->name
);
1397 return PTR_ERR(phydev
);
1400 /* Mask with MAC supported features. */
1401 switch (phydev
->interface
) {
1402 case PHY_INTERFACE_MODE_GMII
:
1403 case PHY_INTERFACE_MODE_RGMII
:
1404 if (!(tp
->tg3_flags
& TG3_FLAG_10_100_ONLY
)) {
1405 phydev
->supported
&= (PHY_GBIT_FEATURES
|
1407 SUPPORTED_Asym_Pause
);
1411 case PHY_INTERFACE_MODE_MII
:
1412 phydev
->supported
&= (PHY_BASIC_FEATURES
|
1414 SUPPORTED_Asym_Pause
);
1417 phy_disconnect(tp
->mdio_bus
->phy_map
[PHY_ADDR
]);
1421 tp
->tg3_flags3
|= TG3_FLG3_PHY_CONNECTED
;
1423 phydev
->advertising
= phydev
->supported
;
1428 static void tg3_phy_start(struct tg3
*tp
)
1430 struct phy_device
*phydev
;
1432 if (!(tp
->tg3_flags3
& TG3_FLG3_PHY_CONNECTED
))
1435 phydev
= tp
->mdio_bus
->phy_map
[PHY_ADDR
];
1437 if (tp
->link_config
.phy_is_low_power
) {
1438 tp
->link_config
.phy_is_low_power
= 0;
1439 phydev
->speed
= tp
->link_config
.orig_speed
;
1440 phydev
->duplex
= tp
->link_config
.orig_duplex
;
1441 phydev
->autoneg
= tp
->link_config
.orig_autoneg
;
1442 phydev
->advertising
= tp
->link_config
.orig_advertising
;
1447 phy_start_aneg(phydev
);
1450 static void tg3_phy_stop(struct tg3
*tp
)
1452 if (!(tp
->tg3_flags3
& TG3_FLG3_PHY_CONNECTED
))
1455 phy_stop(tp
->mdio_bus
->phy_map
[PHY_ADDR
]);
1458 static void tg3_phy_fini(struct tg3
*tp
)
1460 if (tp
->tg3_flags3
& TG3_FLG3_PHY_CONNECTED
) {
1461 phy_disconnect(tp
->mdio_bus
->phy_map
[PHY_ADDR
]);
1462 tp
->tg3_flags3
&= ~TG3_FLG3_PHY_CONNECTED
;
1466 static void tg3_phydsp_write(struct tg3
*tp
, u32 reg
, u32 val
)
1468 tg3_writephy(tp
, MII_TG3_DSP_ADDRESS
, reg
);
1469 tg3_writephy(tp
, MII_TG3_DSP_RW_PORT
, val
);
1472 static void tg3_phy_toggle_apd(struct tg3
*tp
, bool enable
)
1476 if (!(tp
->tg3_flags2
& TG3_FLG2_5705_PLUS
))
1479 reg
= MII_TG3_MISC_SHDW_WREN
|
1480 MII_TG3_MISC_SHDW_SCR5_SEL
|
1481 MII_TG3_MISC_SHDW_SCR5_LPED
|
1482 MII_TG3_MISC_SHDW_SCR5_DLPTLM
|
1483 MII_TG3_MISC_SHDW_SCR5_SDTL
|
1484 MII_TG3_MISC_SHDW_SCR5_C125OE
;
1485 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) != ASIC_REV_5784
|| !enable
)
1486 reg
|= MII_TG3_MISC_SHDW_SCR5_DLLAPD
;
1488 tg3_writephy(tp
, MII_TG3_MISC_SHDW
, reg
);
1491 reg
= MII_TG3_MISC_SHDW_WREN
|
1492 MII_TG3_MISC_SHDW_APD_SEL
|
1493 MII_TG3_MISC_SHDW_APD_WKTM_84MS
;
1495 reg
|= MII_TG3_MISC_SHDW_APD_ENABLE
;
1497 tg3_writephy(tp
, MII_TG3_MISC_SHDW
, reg
);
1500 static void tg3_phy_toggle_automdix(struct tg3
*tp
, int enable
)
1504 if (!(tp
->tg3_flags2
& TG3_FLG2_5705_PLUS
) ||
1505 (tp
->tg3_flags2
& TG3_FLG2_ANY_SERDES
))
1508 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5906
) {
1511 if (!tg3_readphy(tp
, MII_TG3_EPHY_TEST
, &ephy
)) {
1512 tg3_writephy(tp
, MII_TG3_EPHY_TEST
,
1513 ephy
| MII_TG3_EPHY_SHADOW_EN
);
1514 if (!tg3_readphy(tp
, MII_TG3_EPHYTST_MISCCTRL
, &phy
)) {
1516 phy
|= MII_TG3_EPHYTST_MISCCTRL_MDIX
;
1518 phy
&= ~MII_TG3_EPHYTST_MISCCTRL_MDIX
;
1519 tg3_writephy(tp
, MII_TG3_EPHYTST_MISCCTRL
, phy
);
1521 tg3_writephy(tp
, MII_TG3_EPHY_TEST
, ephy
);
1524 phy
= MII_TG3_AUXCTL_MISC_RDSEL_MISC
|
1525 MII_TG3_AUXCTL_SHDWSEL_MISC
;
1526 if (!tg3_writephy(tp
, MII_TG3_AUX_CTRL
, phy
) &&
1527 !tg3_readphy(tp
, MII_TG3_AUX_CTRL
, &phy
)) {
1529 phy
|= MII_TG3_AUXCTL_MISC_FORCE_AMDIX
;
1531 phy
&= ~MII_TG3_AUXCTL_MISC_FORCE_AMDIX
;
1532 phy
|= MII_TG3_AUXCTL_MISC_WREN
;
1533 tg3_writephy(tp
, MII_TG3_AUX_CTRL
, phy
);
1538 static void tg3_phy_set_wirespeed(struct tg3
*tp
)
1542 if (tp
->tg3_flags2
& TG3_FLG2_NO_ETH_WIRE_SPEED
)
1545 if (!tg3_writephy(tp
, MII_TG3_AUX_CTRL
, 0x7007) &&
1546 !tg3_readphy(tp
, MII_TG3_AUX_CTRL
, &val
))
1547 tg3_writephy(tp
, MII_TG3_AUX_CTRL
,
1548 (val
| (1 << 15) | (1 << 4)));
1551 static void tg3_phy_apply_otp(struct tg3
*tp
)
1560 /* Enable SM_DSP clock and tx 6dB coding. */
1561 phy
= MII_TG3_AUXCTL_SHDWSEL_AUXCTL
|
1562 MII_TG3_AUXCTL_ACTL_SMDSP_ENA
|
1563 MII_TG3_AUXCTL_ACTL_TX_6DB
;
1564 tg3_writephy(tp
, MII_TG3_AUX_CTRL
, phy
);
1566 phy
= ((otp
& TG3_OTP_AGCTGT_MASK
) >> TG3_OTP_AGCTGT_SHIFT
);
1567 phy
|= MII_TG3_DSP_TAP1_AGCTGT_DFLT
;
1568 tg3_phydsp_write(tp
, MII_TG3_DSP_TAP1
, phy
);
1570 phy
= ((otp
& TG3_OTP_HPFFLTR_MASK
) >> TG3_OTP_HPFFLTR_SHIFT
) |
1571 ((otp
& TG3_OTP_HPFOVER_MASK
) >> TG3_OTP_HPFOVER_SHIFT
);
1572 tg3_phydsp_write(tp
, MII_TG3_DSP_AADJ1CH0
, phy
);
1574 phy
= ((otp
& TG3_OTP_LPFDIS_MASK
) >> TG3_OTP_LPFDIS_SHIFT
);
1575 phy
|= MII_TG3_DSP_AADJ1CH3_ADCCKADJ
;
1576 tg3_phydsp_write(tp
, MII_TG3_DSP_AADJ1CH3
, phy
);
1578 phy
= ((otp
& TG3_OTP_VDAC_MASK
) >> TG3_OTP_VDAC_SHIFT
);
1579 tg3_phydsp_write(tp
, MII_TG3_DSP_EXP75
, phy
);
1581 phy
= ((otp
& TG3_OTP_10BTAMP_MASK
) >> TG3_OTP_10BTAMP_SHIFT
);
1582 tg3_phydsp_write(tp
, MII_TG3_DSP_EXP96
, phy
);
1584 phy
= ((otp
& TG3_OTP_ROFF_MASK
) >> TG3_OTP_ROFF_SHIFT
) |
1585 ((otp
& TG3_OTP_RCOFF_MASK
) >> TG3_OTP_RCOFF_SHIFT
);
1586 tg3_phydsp_write(tp
, MII_TG3_DSP_EXP97
, phy
);
1588 /* Turn off SM_DSP clock. */
1589 phy
= MII_TG3_AUXCTL_SHDWSEL_AUXCTL
|
1590 MII_TG3_AUXCTL_ACTL_TX_6DB
;
1591 tg3_writephy(tp
, MII_TG3_AUX_CTRL
, phy
);
1594 static int tg3_wait_macro_done(struct tg3
*tp
)
1601 if (!tg3_readphy(tp
, 0x16, &tmp32
)) {
1602 if ((tmp32
& 0x1000) == 0)
1612 static int tg3_phy_write_and_check_testpat(struct tg3
*tp
, int *resetp
)
1614 static const u32 test_pat
[4][6] = {
1615 { 0x00005555, 0x00000005, 0x00002aaa, 0x0000000a, 0x00003456, 0x00000003 },
1616 { 0x00002aaa, 0x0000000a, 0x00003333, 0x00000003, 0x0000789a, 0x00000005 },
1617 { 0x00005a5a, 0x00000005, 0x00002a6a, 0x0000000a, 0x00001bcd, 0x00000003 },
1618 { 0x00002a5a, 0x0000000a, 0x000033c3, 0x00000003, 0x00002ef1, 0x00000005 }
1622 for (chan
= 0; chan
< 4; chan
++) {
1625 tg3_writephy(tp
, MII_TG3_DSP_ADDRESS
,
1626 (chan
* 0x2000) | 0x0200);
1627 tg3_writephy(tp
, 0x16, 0x0002);
1629 for (i
= 0; i
< 6; i
++)
1630 tg3_writephy(tp
, MII_TG3_DSP_RW_PORT
,
1633 tg3_writephy(tp
, 0x16, 0x0202);
1634 if (tg3_wait_macro_done(tp
)) {
1639 tg3_writephy(tp
, MII_TG3_DSP_ADDRESS
,
1640 (chan
* 0x2000) | 0x0200);
1641 tg3_writephy(tp
, 0x16, 0x0082);
1642 if (tg3_wait_macro_done(tp
)) {
1647 tg3_writephy(tp
, 0x16, 0x0802);
1648 if (tg3_wait_macro_done(tp
)) {
1653 for (i
= 0; i
< 6; i
+= 2) {
1656 if (tg3_readphy(tp
, MII_TG3_DSP_RW_PORT
, &low
) ||
1657 tg3_readphy(tp
, MII_TG3_DSP_RW_PORT
, &high
) ||
1658 tg3_wait_macro_done(tp
)) {
1664 if (low
!= test_pat
[chan
][i
] ||
1665 high
!= test_pat
[chan
][i
+1]) {
1666 tg3_writephy(tp
, MII_TG3_DSP_ADDRESS
, 0x000b);
1667 tg3_writephy(tp
, MII_TG3_DSP_RW_PORT
, 0x4001);
1668 tg3_writephy(tp
, MII_TG3_DSP_RW_PORT
, 0x4005);
1678 static int tg3_phy_reset_chanpat(struct tg3
*tp
)
1682 for (chan
= 0; chan
< 4; chan
++) {
1685 tg3_writephy(tp
, MII_TG3_DSP_ADDRESS
,
1686 (chan
* 0x2000) | 0x0200);
1687 tg3_writephy(tp
, 0x16, 0x0002);
1688 for (i
= 0; i
< 6; i
++)
1689 tg3_writephy(tp
, MII_TG3_DSP_RW_PORT
, 0x000);
1690 tg3_writephy(tp
, 0x16, 0x0202);
1691 if (tg3_wait_macro_done(tp
))
1698 static int tg3_phy_reset_5703_4_5(struct tg3
*tp
)
1700 u32 reg32
, phy9_orig
;
1701 int retries
, do_phy_reset
, err
;
1707 err
= tg3_bmcr_reset(tp
);
1713 /* Disable transmitter and interrupt. */
1714 if (tg3_readphy(tp
, MII_TG3_EXT_CTRL
, ®32
))
1718 tg3_writephy(tp
, MII_TG3_EXT_CTRL
, reg32
);
1720 /* Set full-duplex, 1000 mbps. */
1721 tg3_writephy(tp
, MII_BMCR
,
1722 BMCR_FULLDPLX
| TG3_BMCR_SPEED1000
);
1724 /* Set to master mode. */
1725 if (tg3_readphy(tp
, MII_TG3_CTRL
, &phy9_orig
))
1728 tg3_writephy(tp
, MII_TG3_CTRL
,
1729 (MII_TG3_CTRL_AS_MASTER
|
1730 MII_TG3_CTRL_ENABLE_AS_MASTER
));
1732 /* Enable SM_DSP_CLOCK and 6dB. */
1733 tg3_writephy(tp
, MII_TG3_AUX_CTRL
, 0x0c00);
1735 /* Block the PHY control access. */
1736 tg3_writephy(tp
, MII_TG3_DSP_ADDRESS
, 0x8005);
1737 tg3_writephy(tp
, MII_TG3_DSP_RW_PORT
, 0x0800);
1739 err
= tg3_phy_write_and_check_testpat(tp
, &do_phy_reset
);
1742 } while (--retries
);
1744 err
= tg3_phy_reset_chanpat(tp
);
1748 tg3_writephy(tp
, MII_TG3_DSP_ADDRESS
, 0x8005);
1749 tg3_writephy(tp
, MII_TG3_DSP_RW_PORT
, 0x0000);
1751 tg3_writephy(tp
, MII_TG3_DSP_ADDRESS
, 0x8200);
1752 tg3_writephy(tp
, 0x16, 0x0000);
1754 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5703
||
1755 GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5704
) {
1756 /* Set Extended packet length bit for jumbo frames */
1757 tg3_writephy(tp
, MII_TG3_AUX_CTRL
, 0x4400);
1760 tg3_writephy(tp
, MII_TG3_AUX_CTRL
, 0x0400);
1763 tg3_writephy(tp
, MII_TG3_CTRL
, phy9_orig
);
1765 if (!tg3_readphy(tp
, MII_TG3_EXT_CTRL
, ®32
)) {
1767 tg3_writephy(tp
, MII_TG3_EXT_CTRL
, reg32
);
1774 /* This will reset the tigon3 PHY if there is no valid
1775 * link unless the FORCE argument is non-zero.
1777 static int tg3_phy_reset(struct tg3
*tp
)
1783 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5906
) {
1786 val
= tr32(GRC_MISC_CFG
);
1787 tw32_f(GRC_MISC_CFG
, val
& ~GRC_MISC_CFG_EPHY_IDDQ
);
1790 err
= tg3_readphy(tp
, MII_BMSR
, &phy_status
);
1791 err
|= tg3_readphy(tp
, MII_BMSR
, &phy_status
);
1795 if (netif_running(tp
->dev
) && netif_carrier_ok(tp
->dev
)) {
1796 netif_carrier_off(tp
->dev
);
1797 tg3_link_report(tp
);
1800 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5703
||
1801 GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5704
||
1802 GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5705
) {
1803 err
= tg3_phy_reset_5703_4_5(tp
);
1810 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5784
&&
1811 GET_CHIP_REV(tp
->pci_chip_rev_id
) != CHIPREV_5784_AX
) {
1812 cpmuctrl
= tr32(TG3_CPMU_CTRL
);
1813 if (cpmuctrl
& CPMU_CTRL_GPHY_10MB_RXONLY
)
1815 cpmuctrl
& ~CPMU_CTRL_GPHY_10MB_RXONLY
);
1818 err
= tg3_bmcr_reset(tp
);
1822 if (cpmuctrl
& CPMU_CTRL_GPHY_10MB_RXONLY
) {
1825 phy
= MII_TG3_DSP_EXP8_AEDW
| MII_TG3_DSP_EXP8_REJ2MHz
;
1826 tg3_phydsp_write(tp
, MII_TG3_DSP_EXP8
, phy
);
1828 tw32(TG3_CPMU_CTRL
, cpmuctrl
);
1831 if (GET_CHIP_REV(tp
->pci_chip_rev_id
) == CHIPREV_5784_AX
||
1832 GET_CHIP_REV(tp
->pci_chip_rev_id
) == CHIPREV_5761_AX
) {
1835 val
= tr32(TG3_CPMU_LSPD_1000MB_CLK
);
1836 if ((val
& CPMU_LSPD_1000MB_MACCLK_MASK
) ==
1837 CPMU_LSPD_1000MB_MACCLK_12_5
) {
1838 val
&= ~CPMU_LSPD_1000MB_MACCLK_MASK
;
1840 tw32_f(TG3_CPMU_LSPD_1000MB_CLK
, val
);
1844 tg3_phy_apply_otp(tp
);
1846 if (tp
->tg3_flags3
& TG3_FLG3_PHY_ENABLE_APD
)
1847 tg3_phy_toggle_apd(tp
, true);
1849 tg3_phy_toggle_apd(tp
, false);
1852 if (tp
->tg3_flags2
& TG3_FLG2_PHY_ADC_BUG
) {
1853 tg3_writephy(tp
, MII_TG3_AUX_CTRL
, 0x0c00);
1854 tg3_writephy(tp
, MII_TG3_DSP_ADDRESS
, 0x201f);
1855 tg3_writephy(tp
, MII_TG3_DSP_RW_PORT
, 0x2aaa);
1856 tg3_writephy(tp
, MII_TG3_DSP_ADDRESS
, 0x000a);
1857 tg3_writephy(tp
, MII_TG3_DSP_RW_PORT
, 0x0323);
1858 tg3_writephy(tp
, MII_TG3_AUX_CTRL
, 0x0400);
1860 if (tp
->tg3_flags2
& TG3_FLG2_PHY_5704_A0_BUG
) {
1861 tg3_writephy(tp
, 0x1c, 0x8d68);
1862 tg3_writephy(tp
, 0x1c, 0x8d68);
1864 if (tp
->tg3_flags2
& TG3_FLG2_PHY_BER_BUG
) {
1865 tg3_writephy(tp
, MII_TG3_AUX_CTRL
, 0x0c00);
1866 tg3_writephy(tp
, MII_TG3_DSP_ADDRESS
, 0x000a);
1867 tg3_writephy(tp
, MII_TG3_DSP_RW_PORT
, 0x310b);
1868 tg3_writephy(tp
, MII_TG3_DSP_ADDRESS
, 0x201f);
1869 tg3_writephy(tp
, MII_TG3_DSP_RW_PORT
, 0x9506);
1870 tg3_writephy(tp
, MII_TG3_DSP_ADDRESS
, 0x401f);
1871 tg3_writephy(tp
, MII_TG3_DSP_RW_PORT
, 0x14e2);
1872 tg3_writephy(tp
, MII_TG3_AUX_CTRL
, 0x0400);
1874 else if (tp
->tg3_flags2
& TG3_FLG2_PHY_JITTER_BUG
) {
1875 tg3_writephy(tp
, MII_TG3_AUX_CTRL
, 0x0c00);
1876 tg3_writephy(tp
, MII_TG3_DSP_ADDRESS
, 0x000a);
1877 if (tp
->tg3_flags2
& TG3_FLG2_PHY_ADJUST_TRIM
) {
1878 tg3_writephy(tp
, MII_TG3_DSP_RW_PORT
, 0x110b);
1879 tg3_writephy(tp
, MII_TG3_TEST1
,
1880 MII_TG3_TEST1_TRIM_EN
| 0x4);
1882 tg3_writephy(tp
, MII_TG3_DSP_RW_PORT
, 0x010b);
1883 tg3_writephy(tp
, MII_TG3_AUX_CTRL
, 0x0400);
1885 /* Set Extended packet length bit (bit 14) on all chips that */
1886 /* support jumbo frames */
1887 if ((tp
->phy_id
& PHY_ID_MASK
) == PHY_ID_BCM5401
) {
1888 /* Cannot do read-modify-write on 5401 */
1889 tg3_writephy(tp
, MII_TG3_AUX_CTRL
, 0x4c20);
1890 } else if (tp
->tg3_flags2
& TG3_FLG2_JUMBO_CAPABLE
) {
1893 /* Set bit 14 with read-modify-write to preserve other bits */
1894 if (!tg3_writephy(tp
, MII_TG3_AUX_CTRL
, 0x0007) &&
1895 !tg3_readphy(tp
, MII_TG3_AUX_CTRL
, &phy_reg
))
1896 tg3_writephy(tp
, MII_TG3_AUX_CTRL
, phy_reg
| 0x4000);
1899 /* Set phy register 0x10 bit 0 to high fifo elasticity to support
1900 * jumbo frames transmission.
1902 if (tp
->tg3_flags2
& TG3_FLG2_JUMBO_CAPABLE
) {
1905 if (!tg3_readphy(tp
, MII_TG3_EXT_CTRL
, &phy_reg
))
1906 tg3_writephy(tp
, MII_TG3_EXT_CTRL
,
1907 phy_reg
| MII_TG3_EXT_CTRL_FIFO_ELASTIC
);
1910 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5906
) {
1911 /* adjust output voltage */
1912 tg3_writephy(tp
, MII_TG3_EPHY_PTEST
, 0x12);
1915 tg3_phy_toggle_automdix(tp
, 1);
1916 tg3_phy_set_wirespeed(tp
);
1920 static void tg3_frob_aux_power(struct tg3
*tp
)
1922 struct tg3
*tp_peer
= tp
;
1924 if ((tp
->tg3_flags2
& TG3_FLG2_IS_NIC
) == 0)
1927 if ((GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5704
) ||
1928 (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5714
)) {
1929 struct net_device
*dev_peer
;
1931 dev_peer
= pci_get_drvdata(tp
->pdev_peer
);
1932 /* remove_one() may have been run on the peer. */
1936 tp_peer
= netdev_priv(dev_peer
);
1939 if ((tp
->tg3_flags
& TG3_FLAG_WOL_ENABLE
) != 0 ||
1940 (tp
->tg3_flags
& TG3_FLAG_ENABLE_ASF
) != 0 ||
1941 (tp_peer
->tg3_flags
& TG3_FLAG_WOL_ENABLE
) != 0 ||
1942 (tp_peer
->tg3_flags
& TG3_FLAG_ENABLE_ASF
) != 0) {
1943 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5700
||
1944 GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5701
) {
1945 tw32_wait_f(GRC_LOCAL_CTRL
, tp
->grc_local_ctrl
|
1946 (GRC_LCLCTRL_GPIO_OE0
|
1947 GRC_LCLCTRL_GPIO_OE1
|
1948 GRC_LCLCTRL_GPIO_OE2
|
1949 GRC_LCLCTRL_GPIO_OUTPUT0
|
1950 GRC_LCLCTRL_GPIO_OUTPUT1
),
1952 } else if (tp
->pdev
->device
== PCI_DEVICE_ID_TIGON3_5761
) {
1953 /* The 5761 non-e device swaps GPIO 0 and GPIO 2. */
1954 u32 grc_local_ctrl
= GRC_LCLCTRL_GPIO_OE0
|
1955 GRC_LCLCTRL_GPIO_OE1
|
1956 GRC_LCLCTRL_GPIO_OE2
|
1957 GRC_LCLCTRL_GPIO_OUTPUT0
|
1958 GRC_LCLCTRL_GPIO_OUTPUT1
|
1960 tw32_wait_f(GRC_LOCAL_CTRL
, grc_local_ctrl
, 100);
1962 grc_local_ctrl
|= GRC_LCLCTRL_GPIO_OUTPUT2
;
1963 tw32_wait_f(GRC_LOCAL_CTRL
, grc_local_ctrl
, 100);
1965 grc_local_ctrl
&= ~GRC_LCLCTRL_GPIO_OUTPUT0
;
1966 tw32_wait_f(GRC_LOCAL_CTRL
, grc_local_ctrl
, 100);
1969 u32 grc_local_ctrl
= 0;
1971 if (tp_peer
!= tp
&&
1972 (tp_peer
->tg3_flags
& TG3_FLAG_INIT_COMPLETE
) != 0)
1975 /* Workaround to prevent overdrawing Amps. */
1976 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) ==
1978 grc_local_ctrl
|= GRC_LCLCTRL_GPIO_OE3
;
1979 tw32_wait_f(GRC_LOCAL_CTRL
, tp
->grc_local_ctrl
|
1980 grc_local_ctrl
, 100);
1983 /* On 5753 and variants, GPIO2 cannot be used. */
1984 no_gpio2
= tp
->nic_sram_data_cfg
&
1985 NIC_SRAM_DATA_CFG_NO_GPIO2
;
1987 grc_local_ctrl
|= GRC_LCLCTRL_GPIO_OE0
|
1988 GRC_LCLCTRL_GPIO_OE1
|
1989 GRC_LCLCTRL_GPIO_OE2
|
1990 GRC_LCLCTRL_GPIO_OUTPUT1
|
1991 GRC_LCLCTRL_GPIO_OUTPUT2
;
1993 grc_local_ctrl
&= ~(GRC_LCLCTRL_GPIO_OE2
|
1994 GRC_LCLCTRL_GPIO_OUTPUT2
);
1996 tw32_wait_f(GRC_LOCAL_CTRL
, tp
->grc_local_ctrl
|
1997 grc_local_ctrl
, 100);
1999 grc_local_ctrl
|= GRC_LCLCTRL_GPIO_OUTPUT0
;
2001 tw32_wait_f(GRC_LOCAL_CTRL
, tp
->grc_local_ctrl
|
2002 grc_local_ctrl
, 100);
2005 grc_local_ctrl
&= ~GRC_LCLCTRL_GPIO_OUTPUT2
;
2006 tw32_wait_f(GRC_LOCAL_CTRL
, tp
->grc_local_ctrl
|
2007 grc_local_ctrl
, 100);
2011 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) != ASIC_REV_5700
&&
2012 GET_ASIC_REV(tp
->pci_chip_rev_id
) != ASIC_REV_5701
) {
2013 if (tp_peer
!= tp
&&
2014 (tp_peer
->tg3_flags
& TG3_FLAG_INIT_COMPLETE
) != 0)
2017 tw32_wait_f(GRC_LOCAL_CTRL
, tp
->grc_local_ctrl
|
2018 (GRC_LCLCTRL_GPIO_OE1
|
2019 GRC_LCLCTRL_GPIO_OUTPUT1
), 100);
2021 tw32_wait_f(GRC_LOCAL_CTRL
, tp
->grc_local_ctrl
|
2022 GRC_LCLCTRL_GPIO_OE1
, 100);
2024 tw32_wait_f(GRC_LOCAL_CTRL
, tp
->grc_local_ctrl
|
2025 (GRC_LCLCTRL_GPIO_OE1
|
2026 GRC_LCLCTRL_GPIO_OUTPUT1
), 100);
2031 static int tg3_5700_link_polarity(struct tg3
*tp
, u32 speed
)
2033 if (tp
->led_ctrl
== LED_CTRL_MODE_PHY_2
)
2035 else if ((tp
->phy_id
& PHY_ID_MASK
) == PHY_ID_BCM5411
) {
2036 if (speed
!= SPEED_10
)
2038 } else if (speed
== SPEED_10
)
2044 static int tg3_setup_phy(struct tg3
*, int);
2046 #define RESET_KIND_SHUTDOWN 0
2047 #define RESET_KIND_INIT 1
2048 #define RESET_KIND_SUSPEND 2
2050 static void tg3_write_sig_post_reset(struct tg3
*, int);
2051 static int tg3_halt_cpu(struct tg3
*, u32
);
2052 static int tg3_nvram_lock(struct tg3
*);
2053 static void tg3_nvram_unlock(struct tg3
*);
2055 static void tg3_power_down_phy(struct tg3
*tp
, bool do_low_power
)
2059 if (tp
->tg3_flags2
& TG3_FLG2_PHY_SERDES
) {
2060 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5704
) {
2061 u32 sg_dig_ctrl
= tr32(SG_DIG_CTRL
);
2062 u32 serdes_cfg
= tr32(MAC_SERDES_CFG
);
2065 SG_DIG_USING_HW_AUTONEG
| SG_DIG_SOFT_RESET
;
2066 tw32(SG_DIG_CTRL
, sg_dig_ctrl
);
2067 tw32(MAC_SERDES_CFG
, serdes_cfg
| (1 << 15));
2072 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5906
) {
2074 val
= tr32(GRC_MISC_CFG
);
2075 tw32_f(GRC_MISC_CFG
, val
| GRC_MISC_CFG_EPHY_IDDQ
);
2078 } else if (do_low_power
) {
2079 tg3_writephy(tp
, MII_TG3_EXT_CTRL
,
2080 MII_TG3_EXT_CTRL_FORCE_LED_OFF
);
2082 tg3_writephy(tp
, MII_TG3_AUX_CTRL
,
2083 MII_TG3_AUXCTL_SHDWSEL_PWRCTL
|
2084 MII_TG3_AUXCTL_PCTL_100TX_LPWR
|
2085 MII_TG3_AUXCTL_PCTL_SPR_ISOLATE
|
2086 MII_TG3_AUXCTL_PCTL_VREG_11V
);
2089 /* The PHY should not be powered down on some chips because
2092 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5700
||
2093 GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5704
||
2094 (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5780
&&
2095 (tp
->tg3_flags2
& TG3_FLG2_MII_SERDES
)))
2098 if (GET_CHIP_REV(tp
->pci_chip_rev_id
) == CHIPREV_5784_AX
||
2099 GET_CHIP_REV(tp
->pci_chip_rev_id
) == CHIPREV_5761_AX
) {
2100 val
= tr32(TG3_CPMU_LSPD_1000MB_CLK
);
2101 val
&= ~CPMU_LSPD_1000MB_MACCLK_MASK
;
2102 val
|= CPMU_LSPD_1000MB_MACCLK_12_5
;
2103 tw32_f(TG3_CPMU_LSPD_1000MB_CLK
, val
);
2106 tg3_writephy(tp
, MII_BMCR
, BMCR_PDOWN
);
2109 /* tp->lock is held. */
2110 static void __tg3_set_mac_addr(struct tg3
*tp
, int skip_mac_1
)
2112 u32 addr_high
, addr_low
;
2115 addr_high
= ((tp
->dev
->dev_addr
[0] << 8) |
2116 tp
->dev
->dev_addr
[1]);
2117 addr_low
= ((tp
->dev
->dev_addr
[2] << 24) |
2118 (tp
->dev
->dev_addr
[3] << 16) |
2119 (tp
->dev
->dev_addr
[4] << 8) |
2120 (tp
->dev
->dev_addr
[5] << 0));
2121 for (i
= 0; i
< 4; i
++) {
2122 if (i
== 1 && skip_mac_1
)
2124 tw32(MAC_ADDR_0_HIGH
+ (i
* 8), addr_high
);
2125 tw32(MAC_ADDR_0_LOW
+ (i
* 8), addr_low
);
2128 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5703
||
2129 GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5704
) {
2130 for (i
= 0; i
< 12; i
++) {
2131 tw32(MAC_EXTADDR_0_HIGH
+ (i
* 8), addr_high
);
2132 tw32(MAC_EXTADDR_0_LOW
+ (i
* 8), addr_low
);
2136 addr_high
= (tp
->dev
->dev_addr
[0] +
2137 tp
->dev
->dev_addr
[1] +
2138 tp
->dev
->dev_addr
[2] +
2139 tp
->dev
->dev_addr
[3] +
2140 tp
->dev
->dev_addr
[4] +
2141 tp
->dev
->dev_addr
[5]) &
2142 TX_BACKOFF_SEED_MASK
;
2143 tw32(MAC_TX_BACKOFF_SEED
, addr_high
);
2146 static int tg3_set_power_state(struct tg3
*tp
, pci_power_t state
)
2149 bool device_should_wake
, do_low_power
;
2151 /* Make sure register accesses (indirect or otherwise)
2152 * will function correctly.
2154 pci_write_config_dword(tp
->pdev
,
2155 TG3PCI_MISC_HOST_CTRL
,
2156 tp
->misc_host_ctrl
);
2160 pci_enable_wake(tp
->pdev
, state
, false);
2161 pci_set_power_state(tp
->pdev
, PCI_D0
);
2163 /* Switch out of Vaux if it is a NIC */
2164 if (tp
->tg3_flags2
& TG3_FLG2_IS_NIC
)
2165 tw32_wait_f(GRC_LOCAL_CTRL
, tp
->grc_local_ctrl
, 100);
2175 printk(KERN_ERR PFX
"%s: Invalid power state (D%d) requested\n",
2176 tp
->dev
->name
, state
);
2180 /* Restore the CLKREQ setting. */
2181 if (tp
->tg3_flags3
& TG3_FLG3_CLKREQ_BUG
) {
2184 pci_read_config_word(tp
->pdev
,
2185 tp
->pcie_cap
+ PCI_EXP_LNKCTL
,
2187 lnkctl
|= PCI_EXP_LNKCTL_CLKREQ_EN
;
2188 pci_write_config_word(tp
->pdev
,
2189 tp
->pcie_cap
+ PCI_EXP_LNKCTL
,
2193 misc_host_ctrl
= tr32(TG3PCI_MISC_HOST_CTRL
);
2194 tw32(TG3PCI_MISC_HOST_CTRL
,
2195 misc_host_ctrl
| MISC_HOST_CTRL_MASK_PCI_INT
);
2197 device_should_wake
= pci_pme_capable(tp
->pdev
, state
) &&
2198 device_may_wakeup(&tp
->pdev
->dev
) &&
2199 (tp
->tg3_flags
& TG3_FLAG_WOL_ENABLE
);
2201 if (tp
->tg3_flags3
& TG3_FLG3_USE_PHYLIB
) {
2202 do_low_power
= false;
2203 if ((tp
->tg3_flags3
& TG3_FLG3_PHY_CONNECTED
) &&
2204 !tp
->link_config
.phy_is_low_power
) {
2205 struct phy_device
*phydev
;
2206 u32 phyid
, advertising
;
2208 phydev
= tp
->mdio_bus
->phy_map
[PHY_ADDR
];
2210 tp
->link_config
.phy_is_low_power
= 1;
2212 tp
->link_config
.orig_speed
= phydev
->speed
;
2213 tp
->link_config
.orig_duplex
= phydev
->duplex
;
2214 tp
->link_config
.orig_autoneg
= phydev
->autoneg
;
2215 tp
->link_config
.orig_advertising
= phydev
->advertising
;
2217 advertising
= ADVERTISED_TP
|
2219 ADVERTISED_Autoneg
|
2220 ADVERTISED_10baseT_Half
;
2222 if ((tp
->tg3_flags
& TG3_FLAG_ENABLE_ASF
) ||
2223 device_should_wake
) {
2224 if (tp
->tg3_flags
& TG3_FLAG_WOL_SPEED_100MB
)
2226 ADVERTISED_100baseT_Half
|
2227 ADVERTISED_100baseT_Full
|
2228 ADVERTISED_10baseT_Full
;
2230 advertising
|= ADVERTISED_10baseT_Full
;
2233 phydev
->advertising
= advertising
;
2235 phy_start_aneg(phydev
);
2237 phyid
= phydev
->drv
->phy_id
& phydev
->drv
->phy_id_mask
;
2238 if (phyid
!= TG3_PHY_ID_BCMAC131
) {
2239 phyid
&= TG3_PHY_OUI_MASK
;
2240 if (phyid
== TG3_PHY_OUI_1
&&
2241 phyid
== TG3_PHY_OUI_2
&&
2242 phyid
== TG3_PHY_OUI_3
)
2243 do_low_power
= true;
2247 do_low_power
= true;
2249 if (tp
->link_config
.phy_is_low_power
== 0) {
2250 tp
->link_config
.phy_is_low_power
= 1;
2251 tp
->link_config
.orig_speed
= tp
->link_config
.speed
;
2252 tp
->link_config
.orig_duplex
= tp
->link_config
.duplex
;
2253 tp
->link_config
.orig_autoneg
= tp
->link_config
.autoneg
;
2256 if (!(tp
->tg3_flags2
& TG3_FLG2_ANY_SERDES
)) {
2257 tp
->link_config
.speed
= SPEED_10
;
2258 tp
->link_config
.duplex
= DUPLEX_HALF
;
2259 tp
->link_config
.autoneg
= AUTONEG_ENABLE
;
2260 tg3_setup_phy(tp
, 0);
2264 __tg3_set_mac_addr(tp
, 0);
2266 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5906
) {
2269 val
= tr32(GRC_VCPU_EXT_CTRL
);
2270 tw32(GRC_VCPU_EXT_CTRL
, val
| GRC_VCPU_EXT_CTRL_DISABLE_WOL
);
2271 } else if (!(tp
->tg3_flags
& TG3_FLAG_ENABLE_ASF
)) {
2275 for (i
= 0; i
< 200; i
++) {
2276 tg3_read_mem(tp
, NIC_SRAM_FW_ASF_STATUS_MBOX
, &val
);
2277 if (val
== ~NIC_SRAM_FIRMWARE_MBOX_MAGIC1
)
2282 if (tp
->tg3_flags
& TG3_FLAG_WOL_CAP
)
2283 tg3_write_mem(tp
, NIC_SRAM_WOL_MBOX
, WOL_SIGNATURE
|
2284 WOL_DRV_STATE_SHUTDOWN
|
2288 if (device_should_wake
) {
2291 if (!(tp
->tg3_flags2
& TG3_FLG2_PHY_SERDES
)) {
2293 tg3_writephy(tp
, MII_TG3_AUX_CTRL
, 0x5a);
2297 if (tp
->tg3_flags2
& TG3_FLG2_MII_SERDES
)
2298 mac_mode
= MAC_MODE_PORT_MODE_GMII
;
2300 mac_mode
= MAC_MODE_PORT_MODE_MII
;
2302 mac_mode
|= tp
->mac_mode
& MAC_MODE_LINK_POLARITY
;
2303 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) ==
2305 u32 speed
= (tp
->tg3_flags
&
2306 TG3_FLAG_WOL_SPEED_100MB
) ?
2307 SPEED_100
: SPEED_10
;
2308 if (tg3_5700_link_polarity(tp
, speed
))
2309 mac_mode
|= MAC_MODE_LINK_POLARITY
;
2311 mac_mode
&= ~MAC_MODE_LINK_POLARITY
;
2314 mac_mode
= MAC_MODE_PORT_MODE_TBI
;
2317 if (!(tp
->tg3_flags2
& TG3_FLG2_5750_PLUS
))
2318 tw32(MAC_LED_CTRL
, tp
->led_ctrl
);
2320 mac_mode
|= MAC_MODE_MAGIC_PKT_ENABLE
;
2321 if (((tp
->tg3_flags2
& TG3_FLG2_5705_PLUS
) &&
2322 !(tp
->tg3_flags2
& TG3_FLG2_5780_CLASS
)) &&
2323 ((tp
->tg3_flags
& TG3_FLAG_ENABLE_ASF
) ||
2324 (tp
->tg3_flags3
& TG3_FLG3_ENABLE_APE
)))
2325 mac_mode
|= MAC_MODE_KEEP_FRAME_IN_WOL
;
2327 if (tp
->tg3_flags3
& TG3_FLG3_ENABLE_APE
) {
2328 mac_mode
|= tp
->mac_mode
&
2329 (MAC_MODE_APE_TX_EN
| MAC_MODE_APE_RX_EN
);
2330 if (mac_mode
& MAC_MODE_APE_TX_EN
)
2331 mac_mode
|= MAC_MODE_TDE_ENABLE
;
2334 tw32_f(MAC_MODE
, mac_mode
);
2337 tw32_f(MAC_RX_MODE
, RX_MODE_ENABLE
);
2341 if (!(tp
->tg3_flags
& TG3_FLAG_WOL_SPEED_100MB
) &&
2342 (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5700
||
2343 GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5701
)) {
2346 base_val
= tp
->pci_clock_ctrl
;
2347 base_val
|= (CLOCK_CTRL_RXCLK_DISABLE
|
2348 CLOCK_CTRL_TXCLK_DISABLE
);
2350 tw32_wait_f(TG3PCI_CLOCK_CTRL
, base_val
| CLOCK_CTRL_ALTCLK
|
2351 CLOCK_CTRL_PWRDOWN_PLL133
, 40);
2352 } else if ((tp
->tg3_flags2
& TG3_FLG2_5780_CLASS
) ||
2353 (tp
->tg3_flags
& TG3_FLAG_CPMU_PRESENT
) ||
2354 (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5906
)) {
2356 } else if (!((tp
->tg3_flags2
& TG3_FLG2_5750_PLUS
) &&
2357 (tp
->tg3_flags
& TG3_FLAG_ENABLE_ASF
))) {
2358 u32 newbits1
, newbits2
;
2360 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5700
||
2361 GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5701
) {
2362 newbits1
= (CLOCK_CTRL_RXCLK_DISABLE
|
2363 CLOCK_CTRL_TXCLK_DISABLE
|
2365 newbits2
= newbits1
| CLOCK_CTRL_44MHZ_CORE
;
2366 } else if (tp
->tg3_flags2
& TG3_FLG2_5705_PLUS
) {
2367 newbits1
= CLOCK_CTRL_625_CORE
;
2368 newbits2
= newbits1
| CLOCK_CTRL_ALTCLK
;
2370 newbits1
= CLOCK_CTRL_ALTCLK
;
2371 newbits2
= newbits1
| CLOCK_CTRL_44MHZ_CORE
;
2374 tw32_wait_f(TG3PCI_CLOCK_CTRL
, tp
->pci_clock_ctrl
| newbits1
,
2377 tw32_wait_f(TG3PCI_CLOCK_CTRL
, tp
->pci_clock_ctrl
| newbits2
,
2380 if (!(tp
->tg3_flags2
& TG3_FLG2_5705_PLUS
)) {
2383 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5700
||
2384 GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5701
) {
2385 newbits3
= (CLOCK_CTRL_RXCLK_DISABLE
|
2386 CLOCK_CTRL_TXCLK_DISABLE
|
2387 CLOCK_CTRL_44MHZ_CORE
);
2389 newbits3
= CLOCK_CTRL_44MHZ_CORE
;
2392 tw32_wait_f(TG3PCI_CLOCK_CTRL
,
2393 tp
->pci_clock_ctrl
| newbits3
, 40);
2397 if (!(device_should_wake
) &&
2398 !(tp
->tg3_flags
& TG3_FLAG_ENABLE_ASF
))
2399 tg3_power_down_phy(tp
, do_low_power
);
2401 tg3_frob_aux_power(tp
);
2403 /* Workaround for unstable PLL clock */
2404 if ((GET_CHIP_REV(tp
->pci_chip_rev_id
) == CHIPREV_5750_AX
) ||
2405 (GET_CHIP_REV(tp
->pci_chip_rev_id
) == CHIPREV_5750_BX
)) {
2406 u32 val
= tr32(0x7d00);
2408 val
&= ~((1 << 16) | (1 << 4) | (1 << 2) | (1 << 1) | 1);
2410 if (!(tp
->tg3_flags
& TG3_FLAG_ENABLE_ASF
)) {
2413 err
= tg3_nvram_lock(tp
);
2414 tg3_halt_cpu(tp
, RX_CPU_BASE
);
2416 tg3_nvram_unlock(tp
);
2420 tg3_write_sig_post_reset(tp
, RESET_KIND_SHUTDOWN
);
2422 if (device_should_wake
)
2423 pci_enable_wake(tp
->pdev
, state
, true);
2425 /* Finally, set the new power state. */
2426 pci_set_power_state(tp
->pdev
, state
);
2431 static void tg3_aux_stat_to_speed_duplex(struct tg3
*tp
, u32 val
, u16
*speed
, u8
*duplex
)
2433 switch (val
& MII_TG3_AUX_STAT_SPDMASK
) {
2434 case MII_TG3_AUX_STAT_10HALF
:
2436 *duplex
= DUPLEX_HALF
;
2439 case MII_TG3_AUX_STAT_10FULL
:
2441 *duplex
= DUPLEX_FULL
;
2444 case MII_TG3_AUX_STAT_100HALF
:
2446 *duplex
= DUPLEX_HALF
;
2449 case MII_TG3_AUX_STAT_100FULL
:
2451 *duplex
= DUPLEX_FULL
;
2454 case MII_TG3_AUX_STAT_1000HALF
:
2455 *speed
= SPEED_1000
;
2456 *duplex
= DUPLEX_HALF
;
2459 case MII_TG3_AUX_STAT_1000FULL
:
2460 *speed
= SPEED_1000
;
2461 *duplex
= DUPLEX_FULL
;
2465 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5906
) {
2466 *speed
= (val
& MII_TG3_AUX_STAT_100
) ? SPEED_100
:
2468 *duplex
= (val
& MII_TG3_AUX_STAT_FULL
) ? DUPLEX_FULL
:
2472 *speed
= SPEED_INVALID
;
2473 *duplex
= DUPLEX_INVALID
;
2478 static void tg3_phy_copper_begin(struct tg3
*tp
)
2483 if (tp
->link_config
.phy_is_low_power
) {
2484 /* Entering low power mode. Disable gigabit and
2485 * 100baseT advertisements.
2487 tg3_writephy(tp
, MII_TG3_CTRL
, 0);
2489 new_adv
= (ADVERTISE_10HALF
| ADVERTISE_10FULL
|
2490 ADVERTISE_CSMA
| ADVERTISE_PAUSE_CAP
);
2491 if (tp
->tg3_flags
& TG3_FLAG_WOL_SPEED_100MB
)
2492 new_adv
|= (ADVERTISE_100HALF
| ADVERTISE_100FULL
);
2494 tg3_writephy(tp
, MII_ADVERTISE
, new_adv
);
2495 } else if (tp
->link_config
.speed
== SPEED_INVALID
) {
2496 if (tp
->tg3_flags
& TG3_FLAG_10_100_ONLY
)
2497 tp
->link_config
.advertising
&=
2498 ~(ADVERTISED_1000baseT_Half
|
2499 ADVERTISED_1000baseT_Full
);
2501 new_adv
= ADVERTISE_CSMA
;
2502 if (tp
->link_config
.advertising
& ADVERTISED_10baseT_Half
)
2503 new_adv
|= ADVERTISE_10HALF
;
2504 if (tp
->link_config
.advertising
& ADVERTISED_10baseT_Full
)
2505 new_adv
|= ADVERTISE_10FULL
;
2506 if (tp
->link_config
.advertising
& ADVERTISED_100baseT_Half
)
2507 new_adv
|= ADVERTISE_100HALF
;
2508 if (tp
->link_config
.advertising
& ADVERTISED_100baseT_Full
)
2509 new_adv
|= ADVERTISE_100FULL
;
2511 new_adv
|= tg3_advert_flowctrl_1000T(tp
->link_config
.flowctrl
);
2513 tg3_writephy(tp
, MII_ADVERTISE
, new_adv
);
2515 if (tp
->link_config
.advertising
&
2516 (ADVERTISED_1000baseT_Half
| ADVERTISED_1000baseT_Full
)) {
2518 if (tp
->link_config
.advertising
& ADVERTISED_1000baseT_Half
)
2519 new_adv
|= MII_TG3_CTRL_ADV_1000_HALF
;
2520 if (tp
->link_config
.advertising
& ADVERTISED_1000baseT_Full
)
2521 new_adv
|= MII_TG3_CTRL_ADV_1000_FULL
;
2522 if (!(tp
->tg3_flags
& TG3_FLAG_10_100_ONLY
) &&
2523 (tp
->pci_chip_rev_id
== CHIPREV_ID_5701_A0
||
2524 tp
->pci_chip_rev_id
== CHIPREV_ID_5701_B0
))
2525 new_adv
|= (MII_TG3_CTRL_AS_MASTER
|
2526 MII_TG3_CTRL_ENABLE_AS_MASTER
);
2527 tg3_writephy(tp
, MII_TG3_CTRL
, new_adv
);
2529 tg3_writephy(tp
, MII_TG3_CTRL
, 0);
2532 new_adv
= tg3_advert_flowctrl_1000T(tp
->link_config
.flowctrl
);
2533 new_adv
|= ADVERTISE_CSMA
;
2535 /* Asking for a specific link mode. */
2536 if (tp
->link_config
.speed
== SPEED_1000
) {
2537 tg3_writephy(tp
, MII_ADVERTISE
, new_adv
);
2539 if (tp
->link_config
.duplex
== DUPLEX_FULL
)
2540 new_adv
= MII_TG3_CTRL_ADV_1000_FULL
;
2542 new_adv
= MII_TG3_CTRL_ADV_1000_HALF
;
2543 if (tp
->pci_chip_rev_id
== CHIPREV_ID_5701_A0
||
2544 tp
->pci_chip_rev_id
== CHIPREV_ID_5701_B0
)
2545 new_adv
|= (MII_TG3_CTRL_AS_MASTER
|
2546 MII_TG3_CTRL_ENABLE_AS_MASTER
);
2548 if (tp
->link_config
.speed
== SPEED_100
) {
2549 if (tp
->link_config
.duplex
== DUPLEX_FULL
)
2550 new_adv
|= ADVERTISE_100FULL
;
2552 new_adv
|= ADVERTISE_100HALF
;
2554 if (tp
->link_config
.duplex
== DUPLEX_FULL
)
2555 new_adv
|= ADVERTISE_10FULL
;
2557 new_adv
|= ADVERTISE_10HALF
;
2559 tg3_writephy(tp
, MII_ADVERTISE
, new_adv
);
2564 tg3_writephy(tp
, MII_TG3_CTRL
, new_adv
);
2567 if (tp
->link_config
.autoneg
== AUTONEG_DISABLE
&&
2568 tp
->link_config
.speed
!= SPEED_INVALID
) {
2569 u32 bmcr
, orig_bmcr
;
2571 tp
->link_config
.active_speed
= tp
->link_config
.speed
;
2572 tp
->link_config
.active_duplex
= tp
->link_config
.duplex
;
2575 switch (tp
->link_config
.speed
) {
2581 bmcr
|= BMCR_SPEED100
;
2585 bmcr
|= TG3_BMCR_SPEED1000
;
2589 if (tp
->link_config
.duplex
== DUPLEX_FULL
)
2590 bmcr
|= BMCR_FULLDPLX
;
2592 if (!tg3_readphy(tp
, MII_BMCR
, &orig_bmcr
) &&
2593 (bmcr
!= orig_bmcr
)) {
2594 tg3_writephy(tp
, MII_BMCR
, BMCR_LOOPBACK
);
2595 for (i
= 0; i
< 1500; i
++) {
2599 if (tg3_readphy(tp
, MII_BMSR
, &tmp
) ||
2600 tg3_readphy(tp
, MII_BMSR
, &tmp
))
2602 if (!(tmp
& BMSR_LSTATUS
)) {
2607 tg3_writephy(tp
, MII_BMCR
, bmcr
);
2611 tg3_writephy(tp
, MII_BMCR
,
2612 BMCR_ANENABLE
| BMCR_ANRESTART
);
2616 static int tg3_init_5401phy_dsp(struct tg3
*tp
)
2620 /* Turn off tap power management. */
2621 /* Set Extended packet length bit */
2622 err
= tg3_writephy(tp
, MII_TG3_AUX_CTRL
, 0x4c20);
2624 err
|= tg3_writephy(tp
, MII_TG3_DSP_ADDRESS
, 0x0012);
2625 err
|= tg3_writephy(tp
, MII_TG3_DSP_RW_PORT
, 0x1804);
2627 err
|= tg3_writephy(tp
, MII_TG3_DSP_ADDRESS
, 0x0013);
2628 err
|= tg3_writephy(tp
, MII_TG3_DSP_RW_PORT
, 0x1204);
2630 err
|= tg3_writephy(tp
, MII_TG3_DSP_ADDRESS
, 0x8006);
2631 err
|= tg3_writephy(tp
, MII_TG3_DSP_RW_PORT
, 0x0132);
2633 err
|= tg3_writephy(tp
, MII_TG3_DSP_ADDRESS
, 0x8006);
2634 err
|= tg3_writephy(tp
, MII_TG3_DSP_RW_PORT
, 0x0232);
2636 err
|= tg3_writephy(tp
, MII_TG3_DSP_ADDRESS
, 0x201f);
2637 err
|= tg3_writephy(tp
, MII_TG3_DSP_RW_PORT
, 0x0a20);
2644 static int tg3_copper_is_advertising_all(struct tg3
*tp
, u32 mask
)
2646 u32 adv_reg
, all_mask
= 0;
2648 if (mask
& ADVERTISED_10baseT_Half
)
2649 all_mask
|= ADVERTISE_10HALF
;
2650 if (mask
& ADVERTISED_10baseT_Full
)
2651 all_mask
|= ADVERTISE_10FULL
;
2652 if (mask
& ADVERTISED_100baseT_Half
)
2653 all_mask
|= ADVERTISE_100HALF
;
2654 if (mask
& ADVERTISED_100baseT_Full
)
2655 all_mask
|= ADVERTISE_100FULL
;
2657 if (tg3_readphy(tp
, MII_ADVERTISE
, &adv_reg
))
2660 if ((adv_reg
& all_mask
) != all_mask
)
2662 if (!(tp
->tg3_flags
& TG3_FLAG_10_100_ONLY
)) {
2666 if (mask
& ADVERTISED_1000baseT_Half
)
2667 all_mask
|= ADVERTISE_1000HALF
;
2668 if (mask
& ADVERTISED_1000baseT_Full
)
2669 all_mask
|= ADVERTISE_1000FULL
;
2671 if (tg3_readphy(tp
, MII_TG3_CTRL
, &tg3_ctrl
))
2674 if ((tg3_ctrl
& all_mask
) != all_mask
)
2680 static int tg3_adv_1000T_flowctrl_ok(struct tg3
*tp
, u32
*lcladv
, u32
*rmtadv
)
2684 if (tg3_readphy(tp
, MII_ADVERTISE
, lcladv
))
2687 curadv
= *lcladv
& (ADVERTISE_PAUSE_CAP
| ADVERTISE_PAUSE_ASYM
);
2688 reqadv
= tg3_advert_flowctrl_1000T(tp
->link_config
.flowctrl
);
2690 if (tp
->link_config
.active_duplex
== DUPLEX_FULL
) {
2691 if (curadv
!= reqadv
)
2694 if (tp
->tg3_flags
& TG3_FLAG_PAUSE_AUTONEG
)
2695 tg3_readphy(tp
, MII_LPA
, rmtadv
);
2697 /* Reprogram the advertisement register, even if it
2698 * does not affect the current link. If the link
2699 * gets renegotiated in the future, we can save an
2700 * additional renegotiation cycle by advertising
2701 * it correctly in the first place.
2703 if (curadv
!= reqadv
) {
2704 *lcladv
&= ~(ADVERTISE_PAUSE_CAP
|
2705 ADVERTISE_PAUSE_ASYM
);
2706 tg3_writephy(tp
, MII_ADVERTISE
, *lcladv
| reqadv
);
2713 static int tg3_setup_copper_phy(struct tg3
*tp
, int force_reset
)
2715 int current_link_up
;
2717 u32 lcl_adv
, rmt_adv
;
2725 (MAC_STATUS_SYNC_CHANGED
|
2726 MAC_STATUS_CFG_CHANGED
|
2727 MAC_STATUS_MI_COMPLETION
|
2728 MAC_STATUS_LNKSTATE_CHANGED
));
2731 if ((tp
->mi_mode
& MAC_MI_MODE_AUTO_POLL
) != 0) {
2733 (tp
->mi_mode
& ~MAC_MI_MODE_AUTO_POLL
));
2737 tg3_writephy(tp
, MII_TG3_AUX_CTRL
, 0x02);
2739 /* Some third-party PHYs need to be reset on link going
2742 if ((GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5703
||
2743 GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5704
||
2744 GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5705
) &&
2745 netif_carrier_ok(tp
->dev
)) {
2746 tg3_readphy(tp
, MII_BMSR
, &bmsr
);
2747 if (!tg3_readphy(tp
, MII_BMSR
, &bmsr
) &&
2748 !(bmsr
& BMSR_LSTATUS
))
2754 if ((tp
->phy_id
& PHY_ID_MASK
) == PHY_ID_BCM5401
) {
2755 tg3_readphy(tp
, MII_BMSR
, &bmsr
);
2756 if (tg3_readphy(tp
, MII_BMSR
, &bmsr
) ||
2757 !(tp
->tg3_flags
& TG3_FLAG_INIT_COMPLETE
))
2760 if (!(bmsr
& BMSR_LSTATUS
)) {
2761 err
= tg3_init_5401phy_dsp(tp
);
2765 tg3_readphy(tp
, MII_BMSR
, &bmsr
);
2766 for (i
= 0; i
< 1000; i
++) {
2768 if (!tg3_readphy(tp
, MII_BMSR
, &bmsr
) &&
2769 (bmsr
& BMSR_LSTATUS
)) {
2775 if ((tp
->phy_id
& PHY_ID_REV_MASK
) == PHY_REV_BCM5401_B0
&&
2776 !(bmsr
& BMSR_LSTATUS
) &&
2777 tp
->link_config
.active_speed
== SPEED_1000
) {
2778 err
= tg3_phy_reset(tp
);
2780 err
= tg3_init_5401phy_dsp(tp
);
2785 } else if (tp
->pci_chip_rev_id
== CHIPREV_ID_5701_A0
||
2786 tp
->pci_chip_rev_id
== CHIPREV_ID_5701_B0
) {
2787 /* 5701 {A0,B0} CRC bug workaround */
2788 tg3_writephy(tp
, 0x15, 0x0a75);
2789 tg3_writephy(tp
, 0x1c, 0x8c68);
2790 tg3_writephy(tp
, 0x1c, 0x8d68);
2791 tg3_writephy(tp
, 0x1c, 0x8c68);
2794 /* Clear pending interrupts... */
2795 tg3_readphy(tp
, MII_TG3_ISTAT
, &dummy
);
2796 tg3_readphy(tp
, MII_TG3_ISTAT
, &dummy
);
2798 if (tp
->tg3_flags
& TG3_FLAG_USE_MI_INTERRUPT
)
2799 tg3_writephy(tp
, MII_TG3_IMASK
, ~MII_TG3_INT_LINKCHG
);
2800 else if (GET_ASIC_REV(tp
->pci_chip_rev_id
) != ASIC_REV_5906
)
2801 tg3_writephy(tp
, MII_TG3_IMASK
, ~0);
2803 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5700
||
2804 GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5701
) {
2805 if (tp
->led_ctrl
== LED_CTRL_MODE_PHY_1
)
2806 tg3_writephy(tp
, MII_TG3_EXT_CTRL
,
2807 MII_TG3_EXT_CTRL_LNK3_LED_MODE
);
2809 tg3_writephy(tp
, MII_TG3_EXT_CTRL
, 0);
2812 current_link_up
= 0;
2813 current_speed
= SPEED_INVALID
;
2814 current_duplex
= DUPLEX_INVALID
;
2816 if (tp
->tg3_flags2
& TG3_FLG2_CAPACITIVE_COUPLING
) {
2819 tg3_writephy(tp
, MII_TG3_AUX_CTRL
, 0x4007);
2820 tg3_readphy(tp
, MII_TG3_AUX_CTRL
, &val
);
2821 if (!(val
& (1 << 10))) {
2823 tg3_writephy(tp
, MII_TG3_AUX_CTRL
, val
);
2829 for (i
= 0; i
< 100; i
++) {
2830 tg3_readphy(tp
, MII_BMSR
, &bmsr
);
2831 if (!tg3_readphy(tp
, MII_BMSR
, &bmsr
) &&
2832 (bmsr
& BMSR_LSTATUS
))
2837 if (bmsr
& BMSR_LSTATUS
) {
2840 tg3_readphy(tp
, MII_TG3_AUX_STAT
, &aux_stat
);
2841 for (i
= 0; i
< 2000; i
++) {
2843 if (!tg3_readphy(tp
, MII_TG3_AUX_STAT
, &aux_stat
) &&
2848 tg3_aux_stat_to_speed_duplex(tp
, aux_stat
,
2853 for (i
= 0; i
< 200; i
++) {
2854 tg3_readphy(tp
, MII_BMCR
, &bmcr
);
2855 if (tg3_readphy(tp
, MII_BMCR
, &bmcr
))
2857 if (bmcr
&& bmcr
!= 0x7fff)
2865 tp
->link_config
.active_speed
= current_speed
;
2866 tp
->link_config
.active_duplex
= current_duplex
;
2868 if (tp
->link_config
.autoneg
== AUTONEG_ENABLE
) {
2869 if ((bmcr
& BMCR_ANENABLE
) &&
2870 tg3_copper_is_advertising_all(tp
,
2871 tp
->link_config
.advertising
)) {
2872 if (tg3_adv_1000T_flowctrl_ok(tp
, &lcl_adv
,
2874 current_link_up
= 1;
2877 if (!(bmcr
& BMCR_ANENABLE
) &&
2878 tp
->link_config
.speed
== current_speed
&&
2879 tp
->link_config
.duplex
== current_duplex
&&
2880 tp
->link_config
.flowctrl
==
2881 tp
->link_config
.active_flowctrl
) {
2882 current_link_up
= 1;
2886 if (current_link_up
== 1 &&
2887 tp
->link_config
.active_duplex
== DUPLEX_FULL
)
2888 tg3_setup_flow_control(tp
, lcl_adv
, rmt_adv
);
2892 if (current_link_up
== 0 || tp
->link_config
.phy_is_low_power
) {
2895 tg3_phy_copper_begin(tp
);
2897 tg3_readphy(tp
, MII_BMSR
, &tmp
);
2898 if (!tg3_readphy(tp
, MII_BMSR
, &tmp
) &&
2899 (tmp
& BMSR_LSTATUS
))
2900 current_link_up
= 1;
2903 tp
->mac_mode
&= ~MAC_MODE_PORT_MODE_MASK
;
2904 if (current_link_up
== 1) {
2905 if (tp
->link_config
.active_speed
== SPEED_100
||
2906 tp
->link_config
.active_speed
== SPEED_10
)
2907 tp
->mac_mode
|= MAC_MODE_PORT_MODE_MII
;
2909 tp
->mac_mode
|= MAC_MODE_PORT_MODE_GMII
;
2911 tp
->mac_mode
|= MAC_MODE_PORT_MODE_GMII
;
2913 tp
->mac_mode
&= ~MAC_MODE_HALF_DUPLEX
;
2914 if (tp
->link_config
.active_duplex
== DUPLEX_HALF
)
2915 tp
->mac_mode
|= MAC_MODE_HALF_DUPLEX
;
2917 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5700
) {
2918 if (current_link_up
== 1 &&
2919 tg3_5700_link_polarity(tp
, tp
->link_config
.active_speed
))
2920 tp
->mac_mode
|= MAC_MODE_LINK_POLARITY
;
2922 tp
->mac_mode
&= ~MAC_MODE_LINK_POLARITY
;
2925 /* ??? Without this setting Netgear GA302T PHY does not
2926 * ??? send/receive packets...
2928 if ((tp
->phy_id
& PHY_ID_MASK
) == PHY_ID_BCM5411
&&
2929 tp
->pci_chip_rev_id
== CHIPREV_ID_5700_ALTIMA
) {
2930 tp
->mi_mode
|= MAC_MI_MODE_AUTO_POLL
;
2931 tw32_f(MAC_MI_MODE
, tp
->mi_mode
);
2935 tw32_f(MAC_MODE
, tp
->mac_mode
);
2938 if (tp
->tg3_flags
& TG3_FLAG_USE_LINKCHG_REG
) {
2939 /* Polled via timer. */
2940 tw32_f(MAC_EVENT
, 0);
2942 tw32_f(MAC_EVENT
, MAC_EVENT_LNKSTATE_CHANGED
);
2946 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5700
&&
2947 current_link_up
== 1 &&
2948 tp
->link_config
.active_speed
== SPEED_1000
&&
2949 ((tp
->tg3_flags
& TG3_FLAG_PCIX_MODE
) ||
2950 (tp
->tg3_flags
& TG3_FLAG_PCI_HIGH_SPEED
))) {
2953 (MAC_STATUS_SYNC_CHANGED
|
2954 MAC_STATUS_CFG_CHANGED
));
2957 NIC_SRAM_FIRMWARE_MBOX
,
2958 NIC_SRAM_FIRMWARE_MBOX_MAGIC2
);
2961 /* Prevent send BD corruption. */
2962 if (tp
->tg3_flags3
& TG3_FLG3_CLKREQ_BUG
) {
2963 u16 oldlnkctl
, newlnkctl
;
2965 pci_read_config_word(tp
->pdev
,
2966 tp
->pcie_cap
+ PCI_EXP_LNKCTL
,
2968 if (tp
->link_config
.active_speed
== SPEED_100
||
2969 tp
->link_config
.active_speed
== SPEED_10
)
2970 newlnkctl
= oldlnkctl
& ~PCI_EXP_LNKCTL_CLKREQ_EN
;
2972 newlnkctl
= oldlnkctl
| PCI_EXP_LNKCTL_CLKREQ_EN
;
2973 if (newlnkctl
!= oldlnkctl
)
2974 pci_write_config_word(tp
->pdev
,
2975 tp
->pcie_cap
+ PCI_EXP_LNKCTL
,
2979 if (current_link_up
!= netif_carrier_ok(tp
->dev
)) {
2980 if (current_link_up
)
2981 netif_carrier_on(tp
->dev
);
2983 netif_carrier_off(tp
->dev
);
2984 tg3_link_report(tp
);
2990 struct tg3_fiber_aneginfo
{
2992 #define ANEG_STATE_UNKNOWN 0
2993 #define ANEG_STATE_AN_ENABLE 1
2994 #define ANEG_STATE_RESTART_INIT 2
2995 #define ANEG_STATE_RESTART 3
2996 #define ANEG_STATE_DISABLE_LINK_OK 4
2997 #define ANEG_STATE_ABILITY_DETECT_INIT 5
2998 #define ANEG_STATE_ABILITY_DETECT 6
2999 #define ANEG_STATE_ACK_DETECT_INIT 7
3000 #define ANEG_STATE_ACK_DETECT 8
3001 #define ANEG_STATE_COMPLETE_ACK_INIT 9
3002 #define ANEG_STATE_COMPLETE_ACK 10
3003 #define ANEG_STATE_IDLE_DETECT_INIT 11
3004 #define ANEG_STATE_IDLE_DETECT 12
3005 #define ANEG_STATE_LINK_OK 13
3006 #define ANEG_STATE_NEXT_PAGE_WAIT_INIT 14
3007 #define ANEG_STATE_NEXT_PAGE_WAIT 15
3010 #define MR_AN_ENABLE 0x00000001
3011 #define MR_RESTART_AN 0x00000002
3012 #define MR_AN_COMPLETE 0x00000004
3013 #define MR_PAGE_RX 0x00000008
3014 #define MR_NP_LOADED 0x00000010
3015 #define MR_TOGGLE_TX 0x00000020
3016 #define MR_LP_ADV_FULL_DUPLEX 0x00000040
3017 #define MR_LP_ADV_HALF_DUPLEX 0x00000080
3018 #define MR_LP_ADV_SYM_PAUSE 0x00000100
3019 #define MR_LP_ADV_ASYM_PAUSE 0x00000200
3020 #define MR_LP_ADV_REMOTE_FAULT1 0x00000400
3021 #define MR_LP_ADV_REMOTE_FAULT2 0x00000800
3022 #define MR_LP_ADV_NEXT_PAGE 0x00001000
3023 #define MR_TOGGLE_RX 0x00002000
3024 #define MR_NP_RX 0x00004000
3026 #define MR_LINK_OK 0x80000000
3028 unsigned long link_time
, cur_time
;
3030 u32 ability_match_cfg
;
3031 int ability_match_count
;
3033 char ability_match
, idle_match
, ack_match
;
3035 u32 txconfig
, rxconfig
;
3036 #define ANEG_CFG_NP 0x00000080
3037 #define ANEG_CFG_ACK 0x00000040
3038 #define ANEG_CFG_RF2 0x00000020
3039 #define ANEG_CFG_RF1 0x00000010
3040 #define ANEG_CFG_PS2 0x00000001
3041 #define ANEG_CFG_PS1 0x00008000
3042 #define ANEG_CFG_HD 0x00004000
3043 #define ANEG_CFG_FD 0x00002000
3044 #define ANEG_CFG_INVAL 0x00001f06
3049 #define ANEG_TIMER_ENAB 2
3050 #define ANEG_FAILED -1
3052 #define ANEG_STATE_SETTLE_TIME 10000
3054 static int tg3_fiber_aneg_smachine(struct tg3
*tp
,
3055 struct tg3_fiber_aneginfo
*ap
)
3058 unsigned long delta
;
3062 if (ap
->state
== ANEG_STATE_UNKNOWN
) {
3066 ap
->ability_match_cfg
= 0;
3067 ap
->ability_match_count
= 0;
3068 ap
->ability_match
= 0;
3074 if (tr32(MAC_STATUS
) & MAC_STATUS_RCVD_CFG
) {
3075 rx_cfg_reg
= tr32(MAC_RX_AUTO_NEG
);
3077 if (rx_cfg_reg
!= ap
->ability_match_cfg
) {
3078 ap
->ability_match_cfg
= rx_cfg_reg
;
3079 ap
->ability_match
= 0;
3080 ap
->ability_match_count
= 0;
3082 if (++ap
->ability_match_count
> 1) {
3083 ap
->ability_match
= 1;
3084 ap
->ability_match_cfg
= rx_cfg_reg
;
3087 if (rx_cfg_reg
& ANEG_CFG_ACK
)
3095 ap
->ability_match_cfg
= 0;
3096 ap
->ability_match_count
= 0;
3097 ap
->ability_match
= 0;
3103 ap
->rxconfig
= rx_cfg_reg
;
3107 case ANEG_STATE_UNKNOWN
:
3108 if (ap
->flags
& (MR_AN_ENABLE
| MR_RESTART_AN
))
3109 ap
->state
= ANEG_STATE_AN_ENABLE
;
3112 case ANEG_STATE_AN_ENABLE
:
3113 ap
->flags
&= ~(MR_AN_COMPLETE
| MR_PAGE_RX
);
3114 if (ap
->flags
& MR_AN_ENABLE
) {
3117 ap
->ability_match_cfg
= 0;
3118 ap
->ability_match_count
= 0;
3119 ap
->ability_match
= 0;
3123 ap
->state
= ANEG_STATE_RESTART_INIT
;
3125 ap
->state
= ANEG_STATE_DISABLE_LINK_OK
;
3129 case ANEG_STATE_RESTART_INIT
:
3130 ap
->link_time
= ap
->cur_time
;
3131 ap
->flags
&= ~(MR_NP_LOADED
);
3133 tw32(MAC_TX_AUTO_NEG
, 0);
3134 tp
->mac_mode
|= MAC_MODE_SEND_CONFIGS
;
3135 tw32_f(MAC_MODE
, tp
->mac_mode
);
3138 ret
= ANEG_TIMER_ENAB
;
3139 ap
->state
= ANEG_STATE_RESTART
;
3142 case ANEG_STATE_RESTART
:
3143 delta
= ap
->cur_time
- ap
->link_time
;
3144 if (delta
> ANEG_STATE_SETTLE_TIME
) {
3145 ap
->state
= ANEG_STATE_ABILITY_DETECT_INIT
;
3147 ret
= ANEG_TIMER_ENAB
;
3151 case ANEG_STATE_DISABLE_LINK_OK
:
3155 case ANEG_STATE_ABILITY_DETECT_INIT
:
3156 ap
->flags
&= ~(MR_TOGGLE_TX
);
3157 ap
->txconfig
= ANEG_CFG_FD
;
3158 flowctrl
= tg3_advert_flowctrl_1000X(tp
->link_config
.flowctrl
);
3159 if (flowctrl
& ADVERTISE_1000XPAUSE
)
3160 ap
->txconfig
|= ANEG_CFG_PS1
;
3161 if (flowctrl
& ADVERTISE_1000XPSE_ASYM
)
3162 ap
->txconfig
|= ANEG_CFG_PS2
;
3163 tw32(MAC_TX_AUTO_NEG
, ap
->txconfig
);
3164 tp
->mac_mode
|= MAC_MODE_SEND_CONFIGS
;
3165 tw32_f(MAC_MODE
, tp
->mac_mode
);
3168 ap
->state
= ANEG_STATE_ABILITY_DETECT
;
3171 case ANEG_STATE_ABILITY_DETECT
:
3172 if (ap
->ability_match
!= 0 && ap
->rxconfig
!= 0) {
3173 ap
->state
= ANEG_STATE_ACK_DETECT_INIT
;
3177 case ANEG_STATE_ACK_DETECT_INIT
:
3178 ap
->txconfig
|= ANEG_CFG_ACK
;
3179 tw32(MAC_TX_AUTO_NEG
, ap
->txconfig
);
3180 tp
->mac_mode
|= MAC_MODE_SEND_CONFIGS
;
3181 tw32_f(MAC_MODE
, tp
->mac_mode
);
3184 ap
->state
= ANEG_STATE_ACK_DETECT
;
3187 case ANEG_STATE_ACK_DETECT
:
3188 if (ap
->ack_match
!= 0) {
3189 if ((ap
->rxconfig
& ~ANEG_CFG_ACK
) ==
3190 (ap
->ability_match_cfg
& ~ANEG_CFG_ACK
)) {
3191 ap
->state
= ANEG_STATE_COMPLETE_ACK_INIT
;
3193 ap
->state
= ANEG_STATE_AN_ENABLE
;
3195 } else if (ap
->ability_match
!= 0 &&
3196 ap
->rxconfig
== 0) {
3197 ap
->state
= ANEG_STATE_AN_ENABLE
;
3201 case ANEG_STATE_COMPLETE_ACK_INIT
:
3202 if (ap
->rxconfig
& ANEG_CFG_INVAL
) {
3206 ap
->flags
&= ~(MR_LP_ADV_FULL_DUPLEX
|
3207 MR_LP_ADV_HALF_DUPLEX
|
3208 MR_LP_ADV_SYM_PAUSE
|
3209 MR_LP_ADV_ASYM_PAUSE
|
3210 MR_LP_ADV_REMOTE_FAULT1
|
3211 MR_LP_ADV_REMOTE_FAULT2
|
3212 MR_LP_ADV_NEXT_PAGE
|
3215 if (ap
->rxconfig
& ANEG_CFG_FD
)
3216 ap
->flags
|= MR_LP_ADV_FULL_DUPLEX
;
3217 if (ap
->rxconfig
& ANEG_CFG_HD
)
3218 ap
->flags
|= MR_LP_ADV_HALF_DUPLEX
;
3219 if (ap
->rxconfig
& ANEG_CFG_PS1
)
3220 ap
->flags
|= MR_LP_ADV_SYM_PAUSE
;
3221 if (ap
->rxconfig
& ANEG_CFG_PS2
)
3222 ap
->flags
|= MR_LP_ADV_ASYM_PAUSE
;
3223 if (ap
->rxconfig
& ANEG_CFG_RF1
)
3224 ap
->flags
|= MR_LP_ADV_REMOTE_FAULT1
;
3225 if (ap
->rxconfig
& ANEG_CFG_RF2
)
3226 ap
->flags
|= MR_LP_ADV_REMOTE_FAULT2
;
3227 if (ap
->rxconfig
& ANEG_CFG_NP
)
3228 ap
->flags
|= MR_LP_ADV_NEXT_PAGE
;
3230 ap
->link_time
= ap
->cur_time
;
3232 ap
->flags
^= (MR_TOGGLE_TX
);
3233 if (ap
->rxconfig
& 0x0008)
3234 ap
->flags
|= MR_TOGGLE_RX
;
3235 if (ap
->rxconfig
& ANEG_CFG_NP
)
3236 ap
->flags
|= MR_NP_RX
;
3237 ap
->flags
|= MR_PAGE_RX
;
3239 ap
->state
= ANEG_STATE_COMPLETE_ACK
;
3240 ret
= ANEG_TIMER_ENAB
;
3243 case ANEG_STATE_COMPLETE_ACK
:
3244 if (ap
->ability_match
!= 0 &&
3245 ap
->rxconfig
== 0) {
3246 ap
->state
= ANEG_STATE_AN_ENABLE
;
3249 delta
= ap
->cur_time
- ap
->link_time
;
3250 if (delta
> ANEG_STATE_SETTLE_TIME
) {
3251 if (!(ap
->flags
& (MR_LP_ADV_NEXT_PAGE
))) {
3252 ap
->state
= ANEG_STATE_IDLE_DETECT_INIT
;
3254 if ((ap
->txconfig
& ANEG_CFG_NP
) == 0 &&
3255 !(ap
->flags
& MR_NP_RX
)) {
3256 ap
->state
= ANEG_STATE_IDLE_DETECT_INIT
;
3264 case ANEG_STATE_IDLE_DETECT_INIT
:
3265 ap
->link_time
= ap
->cur_time
;
3266 tp
->mac_mode
&= ~MAC_MODE_SEND_CONFIGS
;
3267 tw32_f(MAC_MODE
, tp
->mac_mode
);
3270 ap
->state
= ANEG_STATE_IDLE_DETECT
;
3271 ret
= ANEG_TIMER_ENAB
;
3274 case ANEG_STATE_IDLE_DETECT
:
3275 if (ap
->ability_match
!= 0 &&
3276 ap
->rxconfig
== 0) {
3277 ap
->state
= ANEG_STATE_AN_ENABLE
;
3280 delta
= ap
->cur_time
- ap
->link_time
;
3281 if (delta
> ANEG_STATE_SETTLE_TIME
) {
3282 /* XXX another gem from the Broadcom driver :( */
3283 ap
->state
= ANEG_STATE_LINK_OK
;
3287 case ANEG_STATE_LINK_OK
:
3288 ap
->flags
|= (MR_AN_COMPLETE
| MR_LINK_OK
);
3292 case ANEG_STATE_NEXT_PAGE_WAIT_INIT
:
3293 /* ??? unimplemented */
3296 case ANEG_STATE_NEXT_PAGE_WAIT
:
3297 /* ??? unimplemented */
3308 static int fiber_autoneg(struct tg3
*tp
, u32
*txflags
, u32
*rxflags
)
3311 struct tg3_fiber_aneginfo aninfo
;
3312 int status
= ANEG_FAILED
;
3316 tw32_f(MAC_TX_AUTO_NEG
, 0);
3318 tmp
= tp
->mac_mode
& ~MAC_MODE_PORT_MODE_MASK
;
3319 tw32_f(MAC_MODE
, tmp
| MAC_MODE_PORT_MODE_GMII
);
3322 tw32_f(MAC_MODE
, tp
->mac_mode
| MAC_MODE_SEND_CONFIGS
);
3325 memset(&aninfo
, 0, sizeof(aninfo
));
3326 aninfo
.flags
|= MR_AN_ENABLE
;
3327 aninfo
.state
= ANEG_STATE_UNKNOWN
;
3328 aninfo
.cur_time
= 0;
3330 while (++tick
< 195000) {
3331 status
= tg3_fiber_aneg_smachine(tp
, &aninfo
);
3332 if (status
== ANEG_DONE
|| status
== ANEG_FAILED
)
3338 tp
->mac_mode
&= ~MAC_MODE_SEND_CONFIGS
;
3339 tw32_f(MAC_MODE
, tp
->mac_mode
);
3342 *txflags
= aninfo
.txconfig
;
3343 *rxflags
= aninfo
.flags
;
3345 if (status
== ANEG_DONE
&&
3346 (aninfo
.flags
& (MR_AN_COMPLETE
| MR_LINK_OK
|
3347 MR_LP_ADV_FULL_DUPLEX
)))
3353 static void tg3_init_bcm8002(struct tg3
*tp
)
3355 u32 mac_status
= tr32(MAC_STATUS
);
3358 /* Reset when initting first time or we have a link. */
3359 if ((tp
->tg3_flags
& TG3_FLAG_INIT_COMPLETE
) &&
3360 !(mac_status
& MAC_STATUS_PCS_SYNCED
))
3363 /* Set PLL lock range. */
3364 tg3_writephy(tp
, 0x16, 0x8007);
3367 tg3_writephy(tp
, MII_BMCR
, BMCR_RESET
);
3369 /* Wait for reset to complete. */
3370 /* XXX schedule_timeout() ... */
3371 for (i
= 0; i
< 500; i
++)
3374 /* Config mode; select PMA/Ch 1 regs. */
3375 tg3_writephy(tp
, 0x10, 0x8411);
3377 /* Enable auto-lock and comdet, select txclk for tx. */
3378 tg3_writephy(tp
, 0x11, 0x0a10);
3380 tg3_writephy(tp
, 0x18, 0x00a0);
3381 tg3_writephy(tp
, 0x16, 0x41ff);
3383 /* Assert and deassert POR. */
3384 tg3_writephy(tp
, 0x13, 0x0400);
3386 tg3_writephy(tp
, 0x13, 0x0000);
3388 tg3_writephy(tp
, 0x11, 0x0a50);
3390 tg3_writephy(tp
, 0x11, 0x0a10);
3392 /* Wait for signal to stabilize */
3393 /* XXX schedule_timeout() ... */
3394 for (i
= 0; i
< 15000; i
++)
3397 /* Deselect the channel register so we can read the PHYID
3400 tg3_writephy(tp
, 0x10, 0x8011);
3403 static int tg3_setup_fiber_hw_autoneg(struct tg3
*tp
, u32 mac_status
)
3406 u32 sg_dig_ctrl
, sg_dig_status
;
3407 u32 serdes_cfg
, expected_sg_dig_ctrl
;
3408 int workaround
, port_a
;
3409 int current_link_up
;
3412 expected_sg_dig_ctrl
= 0;
3415 current_link_up
= 0;
3417 if (tp
->pci_chip_rev_id
!= CHIPREV_ID_5704_A0
&&
3418 tp
->pci_chip_rev_id
!= CHIPREV_ID_5704_A1
) {
3420 if (tr32(TG3PCI_DUAL_MAC_CTRL
) & DUAL_MAC_CTRL_ID
)
3423 /* preserve bits 0-11,13,14 for signal pre-emphasis */
3424 /* preserve bits 20-23 for voltage regulator */
3425 serdes_cfg
= tr32(MAC_SERDES_CFG
) & 0x00f06fff;
3428 sg_dig_ctrl
= tr32(SG_DIG_CTRL
);
3430 if (tp
->link_config
.autoneg
!= AUTONEG_ENABLE
) {
3431 if (sg_dig_ctrl
& SG_DIG_USING_HW_AUTONEG
) {
3433 u32 val
= serdes_cfg
;
3439 tw32_f(MAC_SERDES_CFG
, val
);
3442 tw32_f(SG_DIG_CTRL
, SG_DIG_COMMON_SETUP
);
3444 if (mac_status
& MAC_STATUS_PCS_SYNCED
) {
3445 tg3_setup_flow_control(tp
, 0, 0);
3446 current_link_up
= 1;
3451 /* Want auto-negotiation. */
3452 expected_sg_dig_ctrl
= SG_DIG_USING_HW_AUTONEG
| SG_DIG_COMMON_SETUP
;
3454 flowctrl
= tg3_advert_flowctrl_1000X(tp
->link_config
.flowctrl
);
3455 if (flowctrl
& ADVERTISE_1000XPAUSE
)
3456 expected_sg_dig_ctrl
|= SG_DIG_PAUSE_CAP
;
3457 if (flowctrl
& ADVERTISE_1000XPSE_ASYM
)
3458 expected_sg_dig_ctrl
|= SG_DIG_ASYM_PAUSE
;
3460 if (sg_dig_ctrl
!= expected_sg_dig_ctrl
) {
3461 if ((tp
->tg3_flags2
& TG3_FLG2_PARALLEL_DETECT
) &&
3462 tp
->serdes_counter
&&
3463 ((mac_status
& (MAC_STATUS_PCS_SYNCED
|
3464 MAC_STATUS_RCVD_CFG
)) ==
3465 MAC_STATUS_PCS_SYNCED
)) {
3466 tp
->serdes_counter
--;
3467 current_link_up
= 1;
3472 tw32_f(MAC_SERDES_CFG
, serdes_cfg
| 0xc011000);
3473 tw32_f(SG_DIG_CTRL
, expected_sg_dig_ctrl
| SG_DIG_SOFT_RESET
);
3475 tw32_f(SG_DIG_CTRL
, expected_sg_dig_ctrl
);
3477 tp
->serdes_counter
= SERDES_AN_TIMEOUT_5704S
;
3478 tp
->tg3_flags2
&= ~TG3_FLG2_PARALLEL_DETECT
;
3479 } else if (mac_status
& (MAC_STATUS_PCS_SYNCED
|
3480 MAC_STATUS_SIGNAL_DET
)) {
3481 sg_dig_status
= tr32(SG_DIG_STATUS
);
3482 mac_status
= tr32(MAC_STATUS
);
3484 if ((sg_dig_status
& SG_DIG_AUTONEG_COMPLETE
) &&
3485 (mac_status
& MAC_STATUS_PCS_SYNCED
)) {
3486 u32 local_adv
= 0, remote_adv
= 0;
3488 if (sg_dig_ctrl
& SG_DIG_PAUSE_CAP
)
3489 local_adv
|= ADVERTISE_1000XPAUSE
;
3490 if (sg_dig_ctrl
& SG_DIG_ASYM_PAUSE
)
3491 local_adv
|= ADVERTISE_1000XPSE_ASYM
;
3493 if (sg_dig_status
& SG_DIG_PARTNER_PAUSE_CAPABLE
)
3494 remote_adv
|= LPA_1000XPAUSE
;
3495 if (sg_dig_status
& SG_DIG_PARTNER_ASYM_PAUSE
)
3496 remote_adv
|= LPA_1000XPAUSE_ASYM
;
3498 tg3_setup_flow_control(tp
, local_adv
, remote_adv
);
3499 current_link_up
= 1;
3500 tp
->serdes_counter
= 0;
3501 tp
->tg3_flags2
&= ~TG3_FLG2_PARALLEL_DETECT
;
3502 } else if (!(sg_dig_status
& SG_DIG_AUTONEG_COMPLETE
)) {
3503 if (tp
->serdes_counter
)
3504 tp
->serdes_counter
--;
3507 u32 val
= serdes_cfg
;
3514 tw32_f(MAC_SERDES_CFG
, val
);
3517 tw32_f(SG_DIG_CTRL
, SG_DIG_COMMON_SETUP
);
3520 /* Link parallel detection - link is up */
3521 /* only if we have PCS_SYNC and not */
3522 /* receiving config code words */
3523 mac_status
= tr32(MAC_STATUS
);
3524 if ((mac_status
& MAC_STATUS_PCS_SYNCED
) &&
3525 !(mac_status
& MAC_STATUS_RCVD_CFG
)) {
3526 tg3_setup_flow_control(tp
, 0, 0);
3527 current_link_up
= 1;
3529 TG3_FLG2_PARALLEL_DETECT
;
3530 tp
->serdes_counter
=
3531 SERDES_PARALLEL_DET_TIMEOUT
;
3533 goto restart_autoneg
;
3537 tp
->serdes_counter
= SERDES_AN_TIMEOUT_5704S
;
3538 tp
->tg3_flags2
&= ~TG3_FLG2_PARALLEL_DETECT
;
3542 return current_link_up
;
3545 static int tg3_setup_fiber_by_hand(struct tg3
*tp
, u32 mac_status
)
3547 int current_link_up
= 0;
3549 if (!(mac_status
& MAC_STATUS_PCS_SYNCED
))
3552 if (tp
->link_config
.autoneg
== AUTONEG_ENABLE
) {
3553 u32 txflags
, rxflags
;
3556 if (fiber_autoneg(tp
, &txflags
, &rxflags
)) {
3557 u32 local_adv
= 0, remote_adv
= 0;
3559 if (txflags
& ANEG_CFG_PS1
)
3560 local_adv
|= ADVERTISE_1000XPAUSE
;
3561 if (txflags
& ANEG_CFG_PS2
)
3562 local_adv
|= ADVERTISE_1000XPSE_ASYM
;
3564 if (rxflags
& MR_LP_ADV_SYM_PAUSE
)
3565 remote_adv
|= LPA_1000XPAUSE
;
3566 if (rxflags
& MR_LP_ADV_ASYM_PAUSE
)
3567 remote_adv
|= LPA_1000XPAUSE_ASYM
;
3569 tg3_setup_flow_control(tp
, local_adv
, remote_adv
);
3571 current_link_up
= 1;
3573 for (i
= 0; i
< 30; i
++) {
3576 (MAC_STATUS_SYNC_CHANGED
|
3577 MAC_STATUS_CFG_CHANGED
));
3579 if ((tr32(MAC_STATUS
) &
3580 (MAC_STATUS_SYNC_CHANGED
|
3581 MAC_STATUS_CFG_CHANGED
)) == 0)
3585 mac_status
= tr32(MAC_STATUS
);
3586 if (current_link_up
== 0 &&
3587 (mac_status
& MAC_STATUS_PCS_SYNCED
) &&
3588 !(mac_status
& MAC_STATUS_RCVD_CFG
))
3589 current_link_up
= 1;
3591 tg3_setup_flow_control(tp
, 0, 0);
3593 /* Forcing 1000FD link up. */
3594 current_link_up
= 1;
3596 tw32_f(MAC_MODE
, (tp
->mac_mode
| MAC_MODE_SEND_CONFIGS
));
3599 tw32_f(MAC_MODE
, tp
->mac_mode
);
3604 return current_link_up
;
3607 static int tg3_setup_fiber_phy(struct tg3
*tp
, int force_reset
)
3610 u16 orig_active_speed
;
3611 u8 orig_active_duplex
;
3613 int current_link_up
;
3616 orig_pause_cfg
= tp
->link_config
.active_flowctrl
;
3617 orig_active_speed
= tp
->link_config
.active_speed
;
3618 orig_active_duplex
= tp
->link_config
.active_duplex
;
3620 if (!(tp
->tg3_flags2
& TG3_FLG2_HW_AUTONEG
) &&
3621 netif_carrier_ok(tp
->dev
) &&
3622 (tp
->tg3_flags
& TG3_FLAG_INIT_COMPLETE
)) {
3623 mac_status
= tr32(MAC_STATUS
);
3624 mac_status
&= (MAC_STATUS_PCS_SYNCED
|
3625 MAC_STATUS_SIGNAL_DET
|
3626 MAC_STATUS_CFG_CHANGED
|
3627 MAC_STATUS_RCVD_CFG
);
3628 if (mac_status
== (MAC_STATUS_PCS_SYNCED
|
3629 MAC_STATUS_SIGNAL_DET
)) {
3630 tw32_f(MAC_STATUS
, (MAC_STATUS_SYNC_CHANGED
|
3631 MAC_STATUS_CFG_CHANGED
));
3636 tw32_f(MAC_TX_AUTO_NEG
, 0);
3638 tp
->mac_mode
&= ~(MAC_MODE_PORT_MODE_MASK
| MAC_MODE_HALF_DUPLEX
);
3639 tp
->mac_mode
|= MAC_MODE_PORT_MODE_TBI
;
3640 tw32_f(MAC_MODE
, tp
->mac_mode
);
3643 if (tp
->phy_id
== PHY_ID_BCM8002
)
3644 tg3_init_bcm8002(tp
);
3646 /* Enable link change event even when serdes polling. */
3647 tw32_f(MAC_EVENT
, MAC_EVENT_LNKSTATE_CHANGED
);
3650 current_link_up
= 0;
3651 mac_status
= tr32(MAC_STATUS
);
3653 if (tp
->tg3_flags2
& TG3_FLG2_HW_AUTONEG
)
3654 current_link_up
= tg3_setup_fiber_hw_autoneg(tp
, mac_status
);
3656 current_link_up
= tg3_setup_fiber_by_hand(tp
, mac_status
);
3658 tp
->hw_status
->status
=
3659 (SD_STATUS_UPDATED
|
3660 (tp
->hw_status
->status
& ~SD_STATUS_LINK_CHG
));
3662 for (i
= 0; i
< 100; i
++) {
3663 tw32_f(MAC_STATUS
, (MAC_STATUS_SYNC_CHANGED
|
3664 MAC_STATUS_CFG_CHANGED
));
3666 if ((tr32(MAC_STATUS
) & (MAC_STATUS_SYNC_CHANGED
|
3667 MAC_STATUS_CFG_CHANGED
|
3668 MAC_STATUS_LNKSTATE_CHANGED
)) == 0)
3672 mac_status
= tr32(MAC_STATUS
);
3673 if ((mac_status
& MAC_STATUS_PCS_SYNCED
) == 0) {
3674 current_link_up
= 0;
3675 if (tp
->link_config
.autoneg
== AUTONEG_ENABLE
&&
3676 tp
->serdes_counter
== 0) {
3677 tw32_f(MAC_MODE
, (tp
->mac_mode
|
3678 MAC_MODE_SEND_CONFIGS
));
3680 tw32_f(MAC_MODE
, tp
->mac_mode
);
3684 if (current_link_up
== 1) {
3685 tp
->link_config
.active_speed
= SPEED_1000
;
3686 tp
->link_config
.active_duplex
= DUPLEX_FULL
;
3687 tw32(MAC_LED_CTRL
, (tp
->led_ctrl
|
3688 LED_CTRL_LNKLED_OVERRIDE
|
3689 LED_CTRL_1000MBPS_ON
));
3691 tp
->link_config
.active_speed
= SPEED_INVALID
;
3692 tp
->link_config
.active_duplex
= DUPLEX_INVALID
;
3693 tw32(MAC_LED_CTRL
, (tp
->led_ctrl
|
3694 LED_CTRL_LNKLED_OVERRIDE
|
3695 LED_CTRL_TRAFFIC_OVERRIDE
));
3698 if (current_link_up
!= netif_carrier_ok(tp
->dev
)) {
3699 if (current_link_up
)
3700 netif_carrier_on(tp
->dev
);
3702 netif_carrier_off(tp
->dev
);
3703 tg3_link_report(tp
);
3705 u32 now_pause_cfg
= tp
->link_config
.active_flowctrl
;
3706 if (orig_pause_cfg
!= now_pause_cfg
||
3707 orig_active_speed
!= tp
->link_config
.active_speed
||
3708 orig_active_duplex
!= tp
->link_config
.active_duplex
)
3709 tg3_link_report(tp
);
3715 static int tg3_setup_fiber_mii_phy(struct tg3
*tp
, int force_reset
)
3717 int current_link_up
, err
= 0;
3721 u32 local_adv
, remote_adv
;
3723 tp
->mac_mode
|= MAC_MODE_PORT_MODE_GMII
;
3724 tw32_f(MAC_MODE
, tp
->mac_mode
);
3730 (MAC_STATUS_SYNC_CHANGED
|
3731 MAC_STATUS_CFG_CHANGED
|
3732 MAC_STATUS_MI_COMPLETION
|
3733 MAC_STATUS_LNKSTATE_CHANGED
));
3739 current_link_up
= 0;
3740 current_speed
= SPEED_INVALID
;
3741 current_duplex
= DUPLEX_INVALID
;
3743 err
|= tg3_readphy(tp
, MII_BMSR
, &bmsr
);
3744 err
|= tg3_readphy(tp
, MII_BMSR
, &bmsr
);
3745 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5714
) {
3746 if (tr32(MAC_TX_STATUS
) & TX_STATUS_LINK_UP
)
3747 bmsr
|= BMSR_LSTATUS
;
3749 bmsr
&= ~BMSR_LSTATUS
;
3752 err
|= tg3_readphy(tp
, MII_BMCR
, &bmcr
);
3754 if ((tp
->link_config
.autoneg
== AUTONEG_ENABLE
) && !force_reset
&&
3755 (tp
->tg3_flags2
& TG3_FLG2_PARALLEL_DETECT
)) {
3756 /* do nothing, just check for link up at the end */
3757 } else if (tp
->link_config
.autoneg
== AUTONEG_ENABLE
) {
3760 err
|= tg3_readphy(tp
, MII_ADVERTISE
, &adv
);
3761 new_adv
= adv
& ~(ADVERTISE_1000XFULL
| ADVERTISE_1000XHALF
|
3762 ADVERTISE_1000XPAUSE
|
3763 ADVERTISE_1000XPSE_ASYM
|
3766 new_adv
|= tg3_advert_flowctrl_1000X(tp
->link_config
.flowctrl
);
3768 if (tp
->link_config
.advertising
& ADVERTISED_1000baseT_Half
)
3769 new_adv
|= ADVERTISE_1000XHALF
;
3770 if (tp
->link_config
.advertising
& ADVERTISED_1000baseT_Full
)
3771 new_adv
|= ADVERTISE_1000XFULL
;
3773 if ((new_adv
!= adv
) || !(bmcr
& BMCR_ANENABLE
)) {
3774 tg3_writephy(tp
, MII_ADVERTISE
, new_adv
);
3775 bmcr
|= BMCR_ANENABLE
| BMCR_ANRESTART
;
3776 tg3_writephy(tp
, MII_BMCR
, bmcr
);
3778 tw32_f(MAC_EVENT
, MAC_EVENT_LNKSTATE_CHANGED
);
3779 tp
->serdes_counter
= SERDES_AN_TIMEOUT_5714S
;
3780 tp
->tg3_flags2
&= ~TG3_FLG2_PARALLEL_DETECT
;
3787 bmcr
&= ~BMCR_SPEED1000
;
3788 new_bmcr
= bmcr
& ~(BMCR_ANENABLE
| BMCR_FULLDPLX
);
3790 if (tp
->link_config
.duplex
== DUPLEX_FULL
)
3791 new_bmcr
|= BMCR_FULLDPLX
;
3793 if (new_bmcr
!= bmcr
) {
3794 /* BMCR_SPEED1000 is a reserved bit that needs
3795 * to be set on write.
3797 new_bmcr
|= BMCR_SPEED1000
;
3799 /* Force a linkdown */
3800 if (netif_carrier_ok(tp
->dev
)) {
3803 err
|= tg3_readphy(tp
, MII_ADVERTISE
, &adv
);
3804 adv
&= ~(ADVERTISE_1000XFULL
|
3805 ADVERTISE_1000XHALF
|
3807 tg3_writephy(tp
, MII_ADVERTISE
, adv
);
3808 tg3_writephy(tp
, MII_BMCR
, bmcr
|
3812 netif_carrier_off(tp
->dev
);
3814 tg3_writephy(tp
, MII_BMCR
, new_bmcr
);
3816 err
|= tg3_readphy(tp
, MII_BMSR
, &bmsr
);
3817 err
|= tg3_readphy(tp
, MII_BMSR
, &bmsr
);
3818 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) ==
3820 if (tr32(MAC_TX_STATUS
) & TX_STATUS_LINK_UP
)
3821 bmsr
|= BMSR_LSTATUS
;
3823 bmsr
&= ~BMSR_LSTATUS
;
3825 tp
->tg3_flags2
&= ~TG3_FLG2_PARALLEL_DETECT
;
3829 if (bmsr
& BMSR_LSTATUS
) {
3830 current_speed
= SPEED_1000
;
3831 current_link_up
= 1;
3832 if (bmcr
& BMCR_FULLDPLX
)
3833 current_duplex
= DUPLEX_FULL
;
3835 current_duplex
= DUPLEX_HALF
;
3840 if (bmcr
& BMCR_ANENABLE
) {
3843 err
|= tg3_readphy(tp
, MII_ADVERTISE
, &local_adv
);
3844 err
|= tg3_readphy(tp
, MII_LPA
, &remote_adv
);
3845 common
= local_adv
& remote_adv
;
3846 if (common
& (ADVERTISE_1000XHALF
|
3847 ADVERTISE_1000XFULL
)) {
3848 if (common
& ADVERTISE_1000XFULL
)
3849 current_duplex
= DUPLEX_FULL
;
3851 current_duplex
= DUPLEX_HALF
;
3854 current_link_up
= 0;
3858 if (current_link_up
== 1 && current_duplex
== DUPLEX_FULL
)
3859 tg3_setup_flow_control(tp
, local_adv
, remote_adv
);
3861 tp
->mac_mode
&= ~MAC_MODE_HALF_DUPLEX
;
3862 if (tp
->link_config
.active_duplex
== DUPLEX_HALF
)
3863 tp
->mac_mode
|= MAC_MODE_HALF_DUPLEX
;
3865 tw32_f(MAC_MODE
, tp
->mac_mode
);
3868 tw32_f(MAC_EVENT
, MAC_EVENT_LNKSTATE_CHANGED
);
3870 tp
->link_config
.active_speed
= current_speed
;
3871 tp
->link_config
.active_duplex
= current_duplex
;
3873 if (current_link_up
!= netif_carrier_ok(tp
->dev
)) {
3874 if (current_link_up
)
3875 netif_carrier_on(tp
->dev
);
3877 netif_carrier_off(tp
->dev
);
3878 tp
->tg3_flags2
&= ~TG3_FLG2_PARALLEL_DETECT
;
3880 tg3_link_report(tp
);
3885 static void tg3_serdes_parallel_detect(struct tg3
*tp
)
3887 if (tp
->serdes_counter
) {
3888 /* Give autoneg time to complete. */
3889 tp
->serdes_counter
--;
3892 if (!netif_carrier_ok(tp
->dev
) &&
3893 (tp
->link_config
.autoneg
== AUTONEG_ENABLE
)) {
3896 tg3_readphy(tp
, MII_BMCR
, &bmcr
);
3897 if (bmcr
& BMCR_ANENABLE
) {
3900 /* Select shadow register 0x1f */
3901 tg3_writephy(tp
, 0x1c, 0x7c00);
3902 tg3_readphy(tp
, 0x1c, &phy1
);
3904 /* Select expansion interrupt status register */
3905 tg3_writephy(tp
, 0x17, 0x0f01);
3906 tg3_readphy(tp
, 0x15, &phy2
);
3907 tg3_readphy(tp
, 0x15, &phy2
);
3909 if ((phy1
& 0x10) && !(phy2
& 0x20)) {
3910 /* We have signal detect and not receiving
3911 * config code words, link is up by parallel
3915 bmcr
&= ~BMCR_ANENABLE
;
3916 bmcr
|= BMCR_SPEED1000
| BMCR_FULLDPLX
;
3917 tg3_writephy(tp
, MII_BMCR
, bmcr
);
3918 tp
->tg3_flags2
|= TG3_FLG2_PARALLEL_DETECT
;
3922 else if (netif_carrier_ok(tp
->dev
) &&
3923 (tp
->link_config
.autoneg
== AUTONEG_ENABLE
) &&
3924 (tp
->tg3_flags2
& TG3_FLG2_PARALLEL_DETECT
)) {
3927 /* Select expansion interrupt status register */
3928 tg3_writephy(tp
, 0x17, 0x0f01);
3929 tg3_readphy(tp
, 0x15, &phy2
);
3933 /* Config code words received, turn on autoneg. */
3934 tg3_readphy(tp
, MII_BMCR
, &bmcr
);
3935 tg3_writephy(tp
, MII_BMCR
, bmcr
| BMCR_ANENABLE
);
3937 tp
->tg3_flags2
&= ~TG3_FLG2_PARALLEL_DETECT
;
3943 static int tg3_setup_phy(struct tg3
*tp
, int force_reset
)
3947 if (tp
->tg3_flags2
& TG3_FLG2_PHY_SERDES
) {
3948 err
= tg3_setup_fiber_phy(tp
, force_reset
);
3949 } else if (tp
->tg3_flags2
& TG3_FLG2_MII_SERDES
) {
3950 err
= tg3_setup_fiber_mii_phy(tp
, force_reset
);
3952 err
= tg3_setup_copper_phy(tp
, force_reset
);
3955 if (GET_CHIP_REV(tp
->pci_chip_rev_id
) == CHIPREV_5784_AX
) {
3958 val
= tr32(TG3_CPMU_CLCK_STAT
) & CPMU_CLCK_STAT_MAC_CLCK_MASK
;
3959 if (val
== CPMU_CLCK_STAT_MAC_CLCK_62_5
)
3961 else if (val
== CPMU_CLCK_STAT_MAC_CLCK_6_25
)
3966 val
= tr32(GRC_MISC_CFG
) & ~GRC_MISC_CFG_PRESCALAR_MASK
;
3967 val
|= (scale
<< GRC_MISC_CFG_PRESCALAR_SHIFT
);
3968 tw32(GRC_MISC_CFG
, val
);
3971 if (tp
->link_config
.active_speed
== SPEED_1000
&&
3972 tp
->link_config
.active_duplex
== DUPLEX_HALF
)
3973 tw32(MAC_TX_LENGTHS
,
3974 ((2 << TX_LENGTHS_IPG_CRS_SHIFT
) |
3975 (6 << TX_LENGTHS_IPG_SHIFT
) |
3976 (0xff << TX_LENGTHS_SLOT_TIME_SHIFT
)));
3978 tw32(MAC_TX_LENGTHS
,
3979 ((2 << TX_LENGTHS_IPG_CRS_SHIFT
) |
3980 (6 << TX_LENGTHS_IPG_SHIFT
) |
3981 (32 << TX_LENGTHS_SLOT_TIME_SHIFT
)));
3983 if (!(tp
->tg3_flags2
& TG3_FLG2_5705_PLUS
)) {
3984 if (netif_carrier_ok(tp
->dev
)) {
3985 tw32(HOSTCC_STAT_COAL_TICKS
,
3986 tp
->coal
.stats_block_coalesce_usecs
);
3988 tw32(HOSTCC_STAT_COAL_TICKS
, 0);
3992 if (tp
->tg3_flags
& TG3_FLAG_ASPM_WORKAROUND
) {
3993 u32 val
= tr32(PCIE_PWR_MGMT_THRESH
);
3994 if (!netif_carrier_ok(tp
->dev
))
3995 val
= (val
& ~PCIE_PWR_MGMT_L1_THRESH_MSK
) |
3998 val
|= PCIE_PWR_MGMT_L1_THRESH_MSK
;
3999 tw32(PCIE_PWR_MGMT_THRESH
, val
);
4005 /* This is called whenever we suspect that the system chipset is re-
4006 * ordering the sequence of MMIO to the tx send mailbox. The symptom
4007 * is bogus tx completions. We try to recover by setting the
4008 * TG3_FLAG_MBOX_WRITE_REORDER flag and resetting the chip later
4011 static void tg3_tx_recover(struct tg3
*tp
)
4013 BUG_ON((tp
->tg3_flags
& TG3_FLAG_MBOX_WRITE_REORDER
) ||
4014 tp
->write32_tx_mbox
== tg3_write_indirect_mbox
);
4016 printk(KERN_WARNING PFX
"%s: The system may be re-ordering memory-"
4017 "mapped I/O cycles to the network device, attempting to "
4018 "recover. Please report the problem to the driver maintainer "
4019 "and include system chipset information.\n", tp
->dev
->name
);
4021 spin_lock(&tp
->lock
);
4022 tp
->tg3_flags
|= TG3_FLAG_TX_RECOVERY_PENDING
;
4023 spin_unlock(&tp
->lock
);
4026 static inline u32
tg3_tx_avail(struct tg3
*tp
)
4029 return (tp
->tx_pending
-
4030 ((tp
->tx_prod
- tp
->tx_cons
) & (TG3_TX_RING_SIZE
- 1)));
4033 /* Tigon3 never reports partial packet sends. So we do not
4034 * need special logic to handle SKBs that have not had all
4035 * of their frags sent yet, like SunGEM does.
4037 static void tg3_tx(struct tg3
*tp
)
4039 u32 hw_idx
= tp
->hw_status
->idx
[0].tx_consumer
;
4040 u32 sw_idx
= tp
->tx_cons
;
4042 while (sw_idx
!= hw_idx
) {
4043 struct tx_ring_info
*ri
= &tp
->tx_buffers
[sw_idx
];
4044 struct sk_buff
*skb
= ri
->skb
;
4047 if (unlikely(skb
== NULL
)) {
4052 skb_dma_unmap(&tp
->pdev
->dev
, skb
, DMA_TO_DEVICE
);
4056 sw_idx
= NEXT_TX(sw_idx
);
4058 for (i
= 0; i
< skb_shinfo(skb
)->nr_frags
; i
++) {
4059 ri
= &tp
->tx_buffers
[sw_idx
];
4060 if (unlikely(ri
->skb
!= NULL
|| sw_idx
== hw_idx
))
4062 sw_idx
= NEXT_TX(sw_idx
);
4067 if (unlikely(tx_bug
)) {
4073 tp
->tx_cons
= sw_idx
;
4075 /* Need to make the tx_cons update visible to tg3_start_xmit()
4076 * before checking for netif_queue_stopped(). Without the
4077 * memory barrier, there is a small possibility that tg3_start_xmit()
4078 * will miss it and cause the queue to be stopped forever.
4082 if (unlikely(netif_queue_stopped(tp
->dev
) &&
4083 (tg3_tx_avail(tp
) > TG3_TX_WAKEUP_THRESH(tp
)))) {
4084 netif_tx_lock(tp
->dev
);
4085 if (netif_queue_stopped(tp
->dev
) &&
4086 (tg3_tx_avail(tp
) > TG3_TX_WAKEUP_THRESH(tp
)))
4087 netif_wake_queue(tp
->dev
);
4088 netif_tx_unlock(tp
->dev
);
4092 /* Returns size of skb allocated or < 0 on error.
4094 * We only need to fill in the address because the other members
4095 * of the RX descriptor are invariant, see tg3_init_rings.
4097 * Note the purposeful assymetry of cpu vs. chip accesses. For
4098 * posting buffers we only dirty the first cache line of the RX
4099 * descriptor (containing the address). Whereas for the RX status
4100 * buffers the cpu only reads the last cacheline of the RX descriptor
4101 * (to fetch the error flags, vlan tag, checksum, and opaque cookie).
4103 static int tg3_alloc_rx_skb(struct tg3
*tp
, u32 opaque_key
,
4104 int src_idx
, u32 dest_idx_unmasked
)
4106 struct tg3_rx_buffer_desc
*desc
;
4107 struct ring_info
*map
, *src_map
;
4108 struct sk_buff
*skb
;
4110 int skb_size
, dest_idx
;
4113 switch (opaque_key
) {
4114 case RXD_OPAQUE_RING_STD
:
4115 dest_idx
= dest_idx_unmasked
% TG3_RX_RING_SIZE
;
4116 desc
= &tp
->rx_std
[dest_idx
];
4117 map
= &tp
->rx_std_buffers
[dest_idx
];
4119 src_map
= &tp
->rx_std_buffers
[src_idx
];
4120 skb_size
= tp
->rx_pkt_buf_sz
;
4123 case RXD_OPAQUE_RING_JUMBO
:
4124 dest_idx
= dest_idx_unmasked
% TG3_RX_JUMBO_RING_SIZE
;
4125 desc
= &tp
->rx_jumbo
[dest_idx
];
4126 map
= &tp
->rx_jumbo_buffers
[dest_idx
];
4128 src_map
= &tp
->rx_jumbo_buffers
[src_idx
];
4129 skb_size
= RX_JUMBO_PKT_BUF_SZ
;
4136 /* Do not overwrite any of the map or rp information
4137 * until we are sure we can commit to a new buffer.
4139 * Callers depend upon this behavior and assume that
4140 * we leave everything unchanged if we fail.
4142 skb
= netdev_alloc_skb(tp
->dev
, skb_size
);
4146 skb_reserve(skb
, tp
->rx_offset
);
4148 mapping
= pci_map_single(tp
->pdev
, skb
->data
,
4149 skb_size
- tp
->rx_offset
,
4150 PCI_DMA_FROMDEVICE
);
4153 pci_unmap_addr_set(map
, mapping
, mapping
);
4155 if (src_map
!= NULL
)
4156 src_map
->skb
= NULL
;
4158 desc
->addr_hi
= ((u64
)mapping
>> 32);
4159 desc
->addr_lo
= ((u64
)mapping
& 0xffffffff);
4164 /* We only need to move over in the address because the other
4165 * members of the RX descriptor are invariant. See notes above
4166 * tg3_alloc_rx_skb for full details.
4168 static void tg3_recycle_rx(struct tg3
*tp
, u32 opaque_key
,
4169 int src_idx
, u32 dest_idx_unmasked
)
4171 struct tg3_rx_buffer_desc
*src_desc
, *dest_desc
;
4172 struct ring_info
*src_map
, *dest_map
;
4175 switch (opaque_key
) {
4176 case RXD_OPAQUE_RING_STD
:
4177 dest_idx
= dest_idx_unmasked
% TG3_RX_RING_SIZE
;
4178 dest_desc
= &tp
->rx_std
[dest_idx
];
4179 dest_map
= &tp
->rx_std_buffers
[dest_idx
];
4180 src_desc
= &tp
->rx_std
[src_idx
];
4181 src_map
= &tp
->rx_std_buffers
[src_idx
];
4184 case RXD_OPAQUE_RING_JUMBO
:
4185 dest_idx
= dest_idx_unmasked
% TG3_RX_JUMBO_RING_SIZE
;
4186 dest_desc
= &tp
->rx_jumbo
[dest_idx
];
4187 dest_map
= &tp
->rx_jumbo_buffers
[dest_idx
];
4188 src_desc
= &tp
->rx_jumbo
[src_idx
];
4189 src_map
= &tp
->rx_jumbo_buffers
[src_idx
];
4196 dest_map
->skb
= src_map
->skb
;
4197 pci_unmap_addr_set(dest_map
, mapping
,
4198 pci_unmap_addr(src_map
, mapping
));
4199 dest_desc
->addr_hi
= src_desc
->addr_hi
;
4200 dest_desc
->addr_lo
= src_desc
->addr_lo
;
4202 src_map
->skb
= NULL
;
4205 #if TG3_VLAN_TAG_USED
4206 static int tg3_vlan_rx(struct tg3
*tp
, struct sk_buff
*skb
, u16 vlan_tag
)
4208 return vlan_hwaccel_receive_skb(skb
, tp
->vlgrp
, vlan_tag
);
4212 /* The RX ring scheme is composed of multiple rings which post fresh
4213 * buffers to the chip, and one special ring the chip uses to report
4214 * status back to the host.
4216 * The special ring reports the status of received packets to the
4217 * host. The chip does not write into the original descriptor the
4218 * RX buffer was obtained from. The chip simply takes the original
4219 * descriptor as provided by the host, updates the status and length
4220 * field, then writes this into the next status ring entry.
4222 * Each ring the host uses to post buffers to the chip is described
4223 * by a TG3_BDINFO entry in the chips SRAM area. When a packet arrives,
4224 * it is first placed into the on-chip ram. When the packet's length
4225 * is known, it walks down the TG3_BDINFO entries to select the ring.
4226 * Each TG3_BDINFO specifies a MAXLEN field and the first TG3_BDINFO
4227 * which is within the range of the new packet's length is chosen.
4229 * The "separate ring for rx status" scheme may sound queer, but it makes
4230 * sense from a cache coherency perspective. If only the host writes
4231 * to the buffer post rings, and only the chip writes to the rx status
4232 * rings, then cache lines never move beyond shared-modified state.
4233 * If both the host and chip were to write into the same ring, cache line
4234 * eviction could occur since both entities want it in an exclusive state.
4236 static int tg3_rx(struct tg3
*tp
, int budget
)
4238 u32 work_mask
, rx_std_posted
= 0;
4239 u32 sw_idx
= tp
->rx_rcb_ptr
;
4243 hw_idx
= tp
->hw_status
->idx
[0].rx_producer
;
4245 * We need to order the read of hw_idx and the read of
4246 * the opaque cookie.
4251 while (sw_idx
!= hw_idx
&& budget
> 0) {
4252 struct tg3_rx_buffer_desc
*desc
= &tp
->rx_rcb
[sw_idx
];
4254 struct sk_buff
*skb
;
4255 dma_addr_t dma_addr
;
4256 u32 opaque_key
, desc_idx
, *post_ptr
;
4258 desc_idx
= desc
->opaque
& RXD_OPAQUE_INDEX_MASK
;
4259 opaque_key
= desc
->opaque
& RXD_OPAQUE_RING_MASK
;
4260 if (opaque_key
== RXD_OPAQUE_RING_STD
) {
4261 dma_addr
= pci_unmap_addr(&tp
->rx_std_buffers
[desc_idx
],
4263 skb
= tp
->rx_std_buffers
[desc_idx
].skb
;
4264 post_ptr
= &tp
->rx_std_ptr
;
4266 } else if (opaque_key
== RXD_OPAQUE_RING_JUMBO
) {
4267 dma_addr
= pci_unmap_addr(&tp
->rx_jumbo_buffers
[desc_idx
],
4269 skb
= tp
->rx_jumbo_buffers
[desc_idx
].skb
;
4270 post_ptr
= &tp
->rx_jumbo_ptr
;
4273 goto next_pkt_nopost
;
4276 work_mask
|= opaque_key
;
4278 if ((desc
->err_vlan
& RXD_ERR_MASK
) != 0 &&
4279 (desc
->err_vlan
!= RXD_ERR_ODD_NIBBLE_RCVD_MII
)) {
4281 tg3_recycle_rx(tp
, opaque_key
,
4282 desc_idx
, *post_ptr
);
4284 /* Other statistics kept track of by card. */
4285 tp
->net_stats
.rx_dropped
++;
4289 len
= ((desc
->idx_len
& RXD_LEN_MASK
) >> RXD_LEN_SHIFT
) -
4292 if (len
> RX_COPY_THRESHOLD
4293 && tp
->rx_offset
== NET_IP_ALIGN
4294 /* rx_offset will likely not equal NET_IP_ALIGN
4295 * if this is a 5701 card running in PCI-X mode
4296 * [see tg3_get_invariants()]
4301 skb_size
= tg3_alloc_rx_skb(tp
, opaque_key
,
4302 desc_idx
, *post_ptr
);
4306 pci_unmap_single(tp
->pdev
, dma_addr
,
4307 skb_size
- tp
->rx_offset
,
4308 PCI_DMA_FROMDEVICE
);
4312 struct sk_buff
*copy_skb
;
4314 tg3_recycle_rx(tp
, opaque_key
,
4315 desc_idx
, *post_ptr
);
4317 copy_skb
= netdev_alloc_skb(tp
->dev
,
4318 len
+ TG3_RAW_IP_ALIGN
);
4319 if (copy_skb
== NULL
)
4320 goto drop_it_no_recycle
;
4322 skb_reserve(copy_skb
, TG3_RAW_IP_ALIGN
);
4323 skb_put(copy_skb
, len
);
4324 pci_dma_sync_single_for_cpu(tp
->pdev
, dma_addr
, len
, PCI_DMA_FROMDEVICE
);
4325 skb_copy_from_linear_data(skb
, copy_skb
->data
, len
);
4326 pci_dma_sync_single_for_device(tp
->pdev
, dma_addr
, len
, PCI_DMA_FROMDEVICE
);
4328 /* We'll reuse the original ring buffer. */
4332 if ((tp
->tg3_flags
& TG3_FLAG_RX_CHECKSUMS
) &&
4333 (desc
->type_flags
& RXD_FLAG_TCPUDP_CSUM
) &&
4334 (((desc
->ip_tcp_csum
& RXD_TCPCSUM_MASK
)
4335 >> RXD_TCPCSUM_SHIFT
) == 0xffff))
4336 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
4338 skb
->ip_summed
= CHECKSUM_NONE
;
4340 skb
->protocol
= eth_type_trans(skb
, tp
->dev
);
4341 #if TG3_VLAN_TAG_USED
4342 if (tp
->vlgrp
!= NULL
&&
4343 desc
->type_flags
& RXD_FLAG_VLAN
) {
4344 tg3_vlan_rx(tp
, skb
,
4345 desc
->err_vlan
& RXD_VLAN_MASK
);
4348 netif_receive_skb(skb
);
4356 if (unlikely(rx_std_posted
>= tp
->rx_std_max_post
)) {
4357 u32 idx
= *post_ptr
% TG3_RX_RING_SIZE
;
4359 tw32_rx_mbox(MAILBOX_RCV_STD_PROD_IDX
+
4360 TG3_64BIT_REG_LOW
, idx
);
4361 work_mask
&= ~RXD_OPAQUE_RING_STD
;
4366 sw_idx
&= (TG3_RX_RCB_RING_SIZE(tp
) - 1);
4368 /* Refresh hw_idx to see if there is new work */
4369 if (sw_idx
== hw_idx
) {
4370 hw_idx
= tp
->hw_status
->idx
[0].rx_producer
;
4375 /* ACK the status ring. */
4376 tp
->rx_rcb_ptr
= sw_idx
;
4377 tw32_rx_mbox(MAILBOX_RCVRET_CON_IDX_0
+ TG3_64BIT_REG_LOW
, sw_idx
);
4379 /* Refill RX ring(s). */
4380 if (work_mask
& RXD_OPAQUE_RING_STD
) {
4381 sw_idx
= tp
->rx_std_ptr
% TG3_RX_RING_SIZE
;
4382 tw32_rx_mbox(MAILBOX_RCV_STD_PROD_IDX
+ TG3_64BIT_REG_LOW
,
4385 if (work_mask
& RXD_OPAQUE_RING_JUMBO
) {
4386 sw_idx
= tp
->rx_jumbo_ptr
% TG3_RX_JUMBO_RING_SIZE
;
4387 tw32_rx_mbox(MAILBOX_RCV_JUMBO_PROD_IDX
+ TG3_64BIT_REG_LOW
,
4395 static int tg3_poll_work(struct tg3
*tp
, int work_done
, int budget
)
4397 struct tg3_hw_status
*sblk
= tp
->hw_status
;
4399 /* handle link change and other phy events */
4400 if (!(tp
->tg3_flags
&
4401 (TG3_FLAG_USE_LINKCHG_REG
|
4402 TG3_FLAG_POLL_SERDES
))) {
4403 if (sblk
->status
& SD_STATUS_LINK_CHG
) {
4404 sblk
->status
= SD_STATUS_UPDATED
|
4405 (sblk
->status
& ~SD_STATUS_LINK_CHG
);
4406 spin_lock(&tp
->lock
);
4407 if (tp
->tg3_flags3
& TG3_FLG3_USE_PHYLIB
) {
4409 (MAC_STATUS_SYNC_CHANGED
|
4410 MAC_STATUS_CFG_CHANGED
|
4411 MAC_STATUS_MI_COMPLETION
|
4412 MAC_STATUS_LNKSTATE_CHANGED
));
4415 tg3_setup_phy(tp
, 0);
4416 spin_unlock(&tp
->lock
);
4420 /* run TX completion thread */
4421 if (sblk
->idx
[0].tx_consumer
!= tp
->tx_cons
) {
4423 if (unlikely(tp
->tg3_flags
& TG3_FLAG_TX_RECOVERY_PENDING
))
4427 /* run RX thread, within the bounds set by NAPI.
4428 * All RX "locking" is done by ensuring outside
4429 * code synchronizes with tg3->napi.poll()
4431 if (sblk
->idx
[0].rx_producer
!= tp
->rx_rcb_ptr
)
4432 work_done
+= tg3_rx(tp
, budget
- work_done
);
4437 static int tg3_poll(struct napi_struct
*napi
, int budget
)
4439 struct tg3
*tp
= container_of(napi
, struct tg3
, napi
);
4441 struct tg3_hw_status
*sblk
= tp
->hw_status
;
4444 work_done
= tg3_poll_work(tp
, work_done
, budget
);
4446 if (unlikely(tp
->tg3_flags
& TG3_FLAG_TX_RECOVERY_PENDING
))
4449 if (unlikely(work_done
>= budget
))
4452 if (tp
->tg3_flags
& TG3_FLAG_TAGGED_STATUS
) {
4453 /* tp->last_tag is used in tg3_restart_ints() below
4454 * to tell the hw how much work has been processed,
4455 * so we must read it before checking for more work.
4457 tp
->last_tag
= sblk
->status_tag
;
4460 sblk
->status
&= ~SD_STATUS_UPDATED
;
4462 if (likely(!tg3_has_work(tp
))) {
4463 netif_rx_complete(napi
);
4464 tg3_restart_ints(tp
);
4472 /* work_done is guaranteed to be less than budget. */
4473 netif_rx_complete(napi
);
4474 schedule_work(&tp
->reset_task
);
4478 static void tg3_irq_quiesce(struct tg3
*tp
)
4480 BUG_ON(tp
->irq_sync
);
4485 synchronize_irq(tp
->pdev
->irq
);
4488 static inline int tg3_irq_sync(struct tg3
*tp
)
4490 return tp
->irq_sync
;
4493 /* Fully shutdown all tg3 driver activity elsewhere in the system.
4494 * If irq_sync is non-zero, then the IRQ handler must be synchronized
4495 * with as well. Most of the time, this is not necessary except when
4496 * shutting down the device.
4498 static inline void tg3_full_lock(struct tg3
*tp
, int irq_sync
)
4500 spin_lock_bh(&tp
->lock
);
4502 tg3_irq_quiesce(tp
);
4505 static inline void tg3_full_unlock(struct tg3
*tp
)
4507 spin_unlock_bh(&tp
->lock
);
4510 /* One-shot MSI handler - Chip automatically disables interrupt
4511 * after sending MSI so driver doesn't have to do it.
4513 static irqreturn_t
tg3_msi_1shot(int irq
, void *dev_id
)
4515 struct net_device
*dev
= dev_id
;
4516 struct tg3
*tp
= netdev_priv(dev
);
4518 prefetch(tp
->hw_status
);
4519 prefetch(&tp
->rx_rcb
[tp
->rx_rcb_ptr
]);
4521 if (likely(!tg3_irq_sync(tp
)))
4522 netif_rx_schedule(&tp
->napi
);
4527 /* MSI ISR - No need to check for interrupt sharing and no need to
4528 * flush status block and interrupt mailbox. PCI ordering rules
4529 * guarantee that MSI will arrive after the status block.
4531 static irqreturn_t
tg3_msi(int irq
, void *dev_id
)
4533 struct net_device
*dev
= dev_id
;
4534 struct tg3
*tp
= netdev_priv(dev
);
4536 prefetch(tp
->hw_status
);
4537 prefetch(&tp
->rx_rcb
[tp
->rx_rcb_ptr
]);
4539 * Writing any value to intr-mbox-0 clears PCI INTA# and
4540 * chip-internal interrupt pending events.
4541 * Writing non-zero to intr-mbox-0 additional tells the
4542 * NIC to stop sending us irqs, engaging "in-intr-handler"
4545 tw32_mailbox(MAILBOX_INTERRUPT_0
+ TG3_64BIT_REG_LOW
, 0x00000001);
4546 if (likely(!tg3_irq_sync(tp
)))
4547 netif_rx_schedule(&tp
->napi
);
4549 return IRQ_RETVAL(1);
4552 static irqreturn_t
tg3_interrupt(int irq
, void *dev_id
)
4554 struct net_device
*dev
= dev_id
;
4555 struct tg3
*tp
= netdev_priv(dev
);
4556 struct tg3_hw_status
*sblk
= tp
->hw_status
;
4557 unsigned int handled
= 1;
4559 /* In INTx mode, it is possible for the interrupt to arrive at
4560 * the CPU before the status block posted prior to the interrupt.
4561 * Reading the PCI State register will confirm whether the
4562 * interrupt is ours and will flush the status block.
4564 if (unlikely(!(sblk
->status
& SD_STATUS_UPDATED
))) {
4565 if ((tp
->tg3_flags
& TG3_FLAG_CHIP_RESETTING
) ||
4566 (tr32(TG3PCI_PCISTATE
) & PCISTATE_INT_NOT_ACTIVE
)) {
4573 * Writing any value to intr-mbox-0 clears PCI INTA# and
4574 * chip-internal interrupt pending events.
4575 * Writing non-zero to intr-mbox-0 additional tells the
4576 * NIC to stop sending us irqs, engaging "in-intr-handler"
4579 * Flush the mailbox to de-assert the IRQ immediately to prevent
4580 * spurious interrupts. The flush impacts performance but
4581 * excessive spurious interrupts can be worse in some cases.
4583 tw32_mailbox_f(MAILBOX_INTERRUPT_0
+ TG3_64BIT_REG_LOW
, 0x00000001);
4584 if (tg3_irq_sync(tp
))
4586 sblk
->status
&= ~SD_STATUS_UPDATED
;
4587 if (likely(tg3_has_work(tp
))) {
4588 prefetch(&tp
->rx_rcb
[tp
->rx_rcb_ptr
]);
4589 netif_rx_schedule(&tp
->napi
);
4591 /* No work, shared interrupt perhaps? re-enable
4592 * interrupts, and flush that PCI write
4594 tw32_mailbox_f(MAILBOX_INTERRUPT_0
+ TG3_64BIT_REG_LOW
,
4598 return IRQ_RETVAL(handled
);
4601 static irqreturn_t
tg3_interrupt_tagged(int irq
, void *dev_id
)
4603 struct net_device
*dev
= dev_id
;
4604 struct tg3
*tp
= netdev_priv(dev
);
4605 struct tg3_hw_status
*sblk
= tp
->hw_status
;
4606 unsigned int handled
= 1;
4608 /* In INTx mode, it is possible for the interrupt to arrive at
4609 * the CPU before the status block posted prior to the interrupt.
4610 * Reading the PCI State register will confirm whether the
4611 * interrupt is ours and will flush the status block.
4613 if (unlikely(sblk
->status_tag
== tp
->last_tag
)) {
4614 if ((tp
->tg3_flags
& TG3_FLAG_CHIP_RESETTING
) ||
4615 (tr32(TG3PCI_PCISTATE
) & PCISTATE_INT_NOT_ACTIVE
)) {
4622 * writing any value to intr-mbox-0 clears PCI INTA# and
4623 * chip-internal interrupt pending events.
4624 * writing non-zero to intr-mbox-0 additional tells the
4625 * NIC to stop sending us irqs, engaging "in-intr-handler"
4628 * Flush the mailbox to de-assert the IRQ immediately to prevent
4629 * spurious interrupts. The flush impacts performance but
4630 * excessive spurious interrupts can be worse in some cases.
4632 tw32_mailbox_f(MAILBOX_INTERRUPT_0
+ TG3_64BIT_REG_LOW
, 0x00000001);
4633 if (tg3_irq_sync(tp
))
4635 if (netif_rx_schedule_prep(&tp
->napi
)) {
4636 prefetch(&tp
->rx_rcb
[tp
->rx_rcb_ptr
]);
4637 /* Update last_tag to mark that this status has been
4638 * seen. Because interrupt may be shared, we may be
4639 * racing with tg3_poll(), so only update last_tag
4640 * if tg3_poll() is not scheduled.
4642 tp
->last_tag
= sblk
->status_tag
;
4643 __netif_rx_schedule(&tp
->napi
);
4646 return IRQ_RETVAL(handled
);
4649 /* ISR for interrupt test */
4650 static irqreturn_t
tg3_test_isr(int irq
, void *dev_id
)
4652 struct net_device
*dev
= dev_id
;
4653 struct tg3
*tp
= netdev_priv(dev
);
4654 struct tg3_hw_status
*sblk
= tp
->hw_status
;
4656 if ((sblk
->status
& SD_STATUS_UPDATED
) ||
4657 !(tr32(TG3PCI_PCISTATE
) & PCISTATE_INT_NOT_ACTIVE
)) {
4658 tg3_disable_ints(tp
);
4659 return IRQ_RETVAL(1);
4661 return IRQ_RETVAL(0);
4664 static int tg3_init_hw(struct tg3
*, int);
4665 static int tg3_halt(struct tg3
*, int, int);
4667 /* Restart hardware after configuration changes, self-test, etc.
4668 * Invoked with tp->lock held.
4670 static int tg3_restart_hw(struct tg3
*tp
, int reset_phy
)
4671 __releases(tp
->lock
)
4672 __acquires(tp
->lock
)
4676 err
= tg3_init_hw(tp
, reset_phy
);
4678 printk(KERN_ERR PFX
"%s: Failed to re-initialize device, "
4679 "aborting.\n", tp
->dev
->name
);
4680 tg3_halt(tp
, RESET_KIND_SHUTDOWN
, 1);
4681 tg3_full_unlock(tp
);
4682 del_timer_sync(&tp
->timer
);
4684 napi_enable(&tp
->napi
);
4686 tg3_full_lock(tp
, 0);
4691 #ifdef CONFIG_NET_POLL_CONTROLLER
4692 static void tg3_poll_controller(struct net_device
*dev
)
4694 struct tg3
*tp
= netdev_priv(dev
);
4696 tg3_interrupt(tp
->pdev
->irq
, dev
);
4700 static void tg3_reset_task(struct work_struct
*work
)
4702 struct tg3
*tp
= container_of(work
, struct tg3
, reset_task
);
4704 unsigned int restart_timer
;
4706 tg3_full_lock(tp
, 0);
4708 if (!netif_running(tp
->dev
)) {
4709 tg3_full_unlock(tp
);
4713 tg3_full_unlock(tp
);
4719 tg3_full_lock(tp
, 1);
4721 restart_timer
= tp
->tg3_flags2
& TG3_FLG2_RESTART_TIMER
;
4722 tp
->tg3_flags2
&= ~TG3_FLG2_RESTART_TIMER
;
4724 if (tp
->tg3_flags
& TG3_FLAG_TX_RECOVERY_PENDING
) {
4725 tp
->write32_tx_mbox
= tg3_write32_tx_mbox
;
4726 tp
->write32_rx_mbox
= tg3_write_flush_reg32
;
4727 tp
->tg3_flags
|= TG3_FLAG_MBOX_WRITE_REORDER
;
4728 tp
->tg3_flags
&= ~TG3_FLAG_TX_RECOVERY_PENDING
;
4731 tg3_halt(tp
, RESET_KIND_SHUTDOWN
, 0);
4732 err
= tg3_init_hw(tp
, 1);
4736 tg3_netif_start(tp
);
4739 mod_timer(&tp
->timer
, jiffies
+ 1);
4742 tg3_full_unlock(tp
);
4748 static void tg3_dump_short_state(struct tg3
*tp
)
4750 printk(KERN_ERR PFX
"DEBUG: MAC_TX_STATUS[%08x] MAC_RX_STATUS[%08x]\n",
4751 tr32(MAC_TX_STATUS
), tr32(MAC_RX_STATUS
));
4752 printk(KERN_ERR PFX
"DEBUG: RDMAC_STATUS[%08x] WDMAC_STATUS[%08x]\n",
4753 tr32(RDMAC_STATUS
), tr32(WDMAC_STATUS
));
4756 static void tg3_tx_timeout(struct net_device
*dev
)
4758 struct tg3
*tp
= netdev_priv(dev
);
4760 if (netif_msg_tx_err(tp
)) {
4761 printk(KERN_ERR PFX
"%s: transmit timed out, resetting\n",
4763 tg3_dump_short_state(tp
);
4766 schedule_work(&tp
->reset_task
);
4769 /* Test for DMA buffers crossing any 4GB boundaries: 4G, 8G, etc */
4770 static inline int tg3_4g_overflow_test(dma_addr_t mapping
, int len
)
4772 u32 base
= (u32
) mapping
& 0xffffffff;
4774 return ((base
> 0xffffdcc0) &&
4775 (base
+ len
+ 8 < base
));
4778 /* Test for DMA addresses > 40-bit */
4779 static inline int tg3_40bit_overflow_test(struct tg3
*tp
, dma_addr_t mapping
,
4782 #if defined(CONFIG_HIGHMEM) && (BITS_PER_LONG == 64)
4783 if (tp
->tg3_flags
& TG3_FLAG_40BIT_DMA_BUG
)
4784 return (((u64
) mapping
+ len
) > DMA_40BIT_MASK
);
4791 static void tg3_set_txd(struct tg3
*, int, dma_addr_t
, int, u32
, u32
);
4793 /* Workaround 4GB and 40-bit hardware DMA bugs. */
4794 static int tigon3_dma_hwbug_workaround(struct tg3
*tp
, struct sk_buff
*skb
,
4795 u32 last_plus_one
, u32
*start
,
4796 u32 base_flags
, u32 mss
)
4798 struct sk_buff
*new_skb
;
4799 dma_addr_t new_addr
= 0;
4803 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) != ASIC_REV_5701
)
4804 new_skb
= skb_copy(skb
, GFP_ATOMIC
);
4806 int more_headroom
= 4 - ((unsigned long)skb
->data
& 3);
4808 new_skb
= skb_copy_expand(skb
,
4809 skb_headroom(skb
) + more_headroom
,
4810 skb_tailroom(skb
), GFP_ATOMIC
);
4816 /* New SKB is guaranteed to be linear. */
4818 ret
= skb_dma_map(&tp
->pdev
->dev
, new_skb
, DMA_TO_DEVICE
);
4819 new_addr
= skb_shinfo(new_skb
)->dma_maps
[0];
4821 /* Make sure new skb does not cross any 4G boundaries.
4822 * Drop the packet if it does.
4824 if (ret
|| tg3_4g_overflow_test(new_addr
, new_skb
->len
)) {
4826 skb_dma_unmap(&tp
->pdev
->dev
, new_skb
,
4829 dev_kfree_skb(new_skb
);
4832 tg3_set_txd(tp
, entry
, new_addr
, new_skb
->len
,
4833 base_flags
, 1 | (mss
<< 1));
4834 *start
= NEXT_TX(entry
);
4838 /* Now clean up the sw ring entries. */
4840 while (entry
!= last_plus_one
) {
4842 tp
->tx_buffers
[entry
].skb
= new_skb
;
4844 tp
->tx_buffers
[entry
].skb
= NULL
;
4846 entry
= NEXT_TX(entry
);
4850 skb_dma_unmap(&tp
->pdev
->dev
, skb
, DMA_TO_DEVICE
);
4856 static void tg3_set_txd(struct tg3
*tp
, int entry
,
4857 dma_addr_t mapping
, int len
, u32 flags
,
4860 struct tg3_tx_buffer_desc
*txd
= &tp
->tx_ring
[entry
];
4861 int is_end
= (mss_and_is_end
& 0x1);
4862 u32 mss
= (mss_and_is_end
>> 1);
4866 flags
|= TXD_FLAG_END
;
4867 if (flags
& TXD_FLAG_VLAN
) {
4868 vlan_tag
= flags
>> 16;
4871 vlan_tag
|= (mss
<< TXD_MSS_SHIFT
);
4873 txd
->addr_hi
= ((u64
) mapping
>> 32);
4874 txd
->addr_lo
= ((u64
) mapping
& 0xffffffff);
4875 txd
->len_flags
= (len
<< TXD_LEN_SHIFT
) | flags
;
4876 txd
->vlan_tag
= vlan_tag
<< TXD_VLAN_TAG_SHIFT
;
4879 /* hard_start_xmit for devices that don't have any bugs and
4880 * support TG3_FLG2_HW_TSO_2 only.
4882 static int tg3_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
4884 struct tg3
*tp
= netdev_priv(dev
);
4885 u32 len
, entry
, base_flags
, mss
;
4886 struct skb_shared_info
*sp
;
4889 len
= skb_headlen(skb
);
4891 /* We are running in BH disabled context with netif_tx_lock
4892 * and TX reclaim runs via tp->napi.poll inside of a software
4893 * interrupt. Furthermore, IRQ processing runs lockless so we have
4894 * no IRQ context deadlocks to worry about either. Rejoice!
4896 if (unlikely(tg3_tx_avail(tp
) <= (skb_shinfo(skb
)->nr_frags
+ 1))) {
4897 if (!netif_queue_stopped(dev
)) {
4898 netif_stop_queue(dev
);
4900 /* This is a hard error, log it. */
4901 printk(KERN_ERR PFX
"%s: BUG! Tx Ring full when "
4902 "queue awake!\n", dev
->name
);
4904 return NETDEV_TX_BUSY
;
4907 entry
= tp
->tx_prod
;
4910 if ((mss
= skb_shinfo(skb
)->gso_size
) != 0) {
4911 int tcp_opt_len
, ip_tcp_len
;
4913 if (skb_header_cloned(skb
) &&
4914 pskb_expand_head(skb
, 0, 0, GFP_ATOMIC
)) {
4919 if (skb_shinfo(skb
)->gso_type
& SKB_GSO_TCPV6
)
4920 mss
|= (skb_headlen(skb
) - ETH_HLEN
) << 9;
4922 struct iphdr
*iph
= ip_hdr(skb
);
4924 tcp_opt_len
= tcp_optlen(skb
);
4925 ip_tcp_len
= ip_hdrlen(skb
) + sizeof(struct tcphdr
);
4928 iph
->tot_len
= htons(mss
+ ip_tcp_len
+ tcp_opt_len
);
4929 mss
|= (ip_tcp_len
+ tcp_opt_len
) << 9;
4932 base_flags
|= (TXD_FLAG_CPU_PRE_DMA
|
4933 TXD_FLAG_CPU_POST_DMA
);
4935 tcp_hdr(skb
)->check
= 0;
4938 else if (skb
->ip_summed
== CHECKSUM_PARTIAL
)
4939 base_flags
|= TXD_FLAG_TCPUDP_CSUM
;
4940 #if TG3_VLAN_TAG_USED
4941 if (tp
->vlgrp
!= NULL
&& vlan_tx_tag_present(skb
))
4942 base_flags
|= (TXD_FLAG_VLAN
|
4943 (vlan_tx_tag_get(skb
) << 16));
4946 if (skb_dma_map(&tp
->pdev
->dev
, skb
, DMA_TO_DEVICE
)) {
4951 sp
= skb_shinfo(skb
);
4953 mapping
= sp
->dma_maps
[0];
4955 tp
->tx_buffers
[entry
].skb
= skb
;
4957 tg3_set_txd(tp
, entry
, mapping
, len
, base_flags
,
4958 (skb_shinfo(skb
)->nr_frags
== 0) | (mss
<< 1));
4960 entry
= NEXT_TX(entry
);
4962 /* Now loop through additional data fragments, and queue them. */
4963 if (skb_shinfo(skb
)->nr_frags
> 0) {
4964 unsigned int i
, last
;
4966 last
= skb_shinfo(skb
)->nr_frags
- 1;
4967 for (i
= 0; i
<= last
; i
++) {
4968 skb_frag_t
*frag
= &skb_shinfo(skb
)->frags
[i
];
4971 mapping
= sp
->dma_maps
[i
+ 1];
4972 tp
->tx_buffers
[entry
].skb
= NULL
;
4974 tg3_set_txd(tp
, entry
, mapping
, len
,
4975 base_flags
, (i
== last
) | (mss
<< 1));
4977 entry
= NEXT_TX(entry
);
4981 /* Packets are ready, update Tx producer idx local and on card. */
4982 tw32_tx_mbox((MAILBOX_SNDHOST_PROD_IDX_0
+ TG3_64BIT_REG_LOW
), entry
);
4984 tp
->tx_prod
= entry
;
4985 if (unlikely(tg3_tx_avail(tp
) <= (MAX_SKB_FRAGS
+ 1))) {
4986 netif_stop_queue(dev
);
4987 if (tg3_tx_avail(tp
) > TG3_TX_WAKEUP_THRESH(tp
))
4988 netif_wake_queue(tp
->dev
);
4994 dev
->trans_start
= jiffies
;
4996 return NETDEV_TX_OK
;
4999 static int tg3_start_xmit_dma_bug(struct sk_buff
*, struct net_device
*);
5001 /* Use GSO to workaround a rare TSO bug that may be triggered when the
5002 * TSO header is greater than 80 bytes.
5004 static int tg3_tso_bug(struct tg3
*tp
, struct sk_buff
*skb
)
5006 struct sk_buff
*segs
, *nskb
;
5008 /* Estimate the number of fragments in the worst case */
5009 if (unlikely(tg3_tx_avail(tp
) <= (skb_shinfo(skb
)->gso_segs
* 3))) {
5010 netif_stop_queue(tp
->dev
);
5011 if (tg3_tx_avail(tp
) <= (skb_shinfo(skb
)->gso_segs
* 3))
5012 return NETDEV_TX_BUSY
;
5014 netif_wake_queue(tp
->dev
);
5017 segs
= skb_gso_segment(skb
, tp
->dev
->features
& ~NETIF_F_TSO
);
5019 goto tg3_tso_bug_end
;
5025 tg3_start_xmit_dma_bug(nskb
, tp
->dev
);
5031 return NETDEV_TX_OK
;
5034 /* hard_start_xmit for devices that have the 4G bug and/or 40-bit bug and
5035 * support TG3_FLG2_HW_TSO_1 or firmware TSO only.
5037 static int tg3_start_xmit_dma_bug(struct sk_buff
*skb
, struct net_device
*dev
)
5039 struct tg3
*tp
= netdev_priv(dev
);
5040 u32 len
, entry
, base_flags
, mss
;
5041 struct skb_shared_info
*sp
;
5042 int would_hit_hwbug
;
5045 len
= skb_headlen(skb
);
5047 /* We are running in BH disabled context with netif_tx_lock
5048 * and TX reclaim runs via tp->napi.poll inside of a software
5049 * interrupt. Furthermore, IRQ processing runs lockless so we have
5050 * no IRQ context deadlocks to worry about either. Rejoice!
5052 if (unlikely(tg3_tx_avail(tp
) <= (skb_shinfo(skb
)->nr_frags
+ 1))) {
5053 if (!netif_queue_stopped(dev
)) {
5054 netif_stop_queue(dev
);
5056 /* This is a hard error, log it. */
5057 printk(KERN_ERR PFX
"%s: BUG! Tx Ring full when "
5058 "queue awake!\n", dev
->name
);
5060 return NETDEV_TX_BUSY
;
5063 entry
= tp
->tx_prod
;
5065 if (skb
->ip_summed
== CHECKSUM_PARTIAL
)
5066 base_flags
|= TXD_FLAG_TCPUDP_CSUM
;
5068 if ((mss
= skb_shinfo(skb
)->gso_size
) != 0) {
5070 int tcp_opt_len
, ip_tcp_len
, hdr_len
;
5072 if (skb_header_cloned(skb
) &&
5073 pskb_expand_head(skb
, 0, 0, GFP_ATOMIC
)) {
5078 tcp_opt_len
= tcp_optlen(skb
);
5079 ip_tcp_len
= ip_hdrlen(skb
) + sizeof(struct tcphdr
);
5081 hdr_len
= ip_tcp_len
+ tcp_opt_len
;
5082 if (unlikely((ETH_HLEN
+ hdr_len
) > 80) &&
5083 (tp
->tg3_flags2
& TG3_FLG2_TSO_BUG
))
5084 return (tg3_tso_bug(tp
, skb
));
5086 base_flags
|= (TXD_FLAG_CPU_PRE_DMA
|
5087 TXD_FLAG_CPU_POST_DMA
);
5091 iph
->tot_len
= htons(mss
+ hdr_len
);
5092 if (tp
->tg3_flags2
& TG3_FLG2_HW_TSO
) {
5093 tcp_hdr(skb
)->check
= 0;
5094 base_flags
&= ~TXD_FLAG_TCPUDP_CSUM
;
5096 tcp_hdr(skb
)->check
= ~csum_tcpudp_magic(iph
->saddr
,
5101 if ((tp
->tg3_flags2
& TG3_FLG2_HW_TSO
) ||
5102 (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5705
)) {
5103 if (tcp_opt_len
|| iph
->ihl
> 5) {
5106 tsflags
= (iph
->ihl
- 5) + (tcp_opt_len
>> 2);
5107 mss
|= (tsflags
<< 11);
5110 if (tcp_opt_len
|| iph
->ihl
> 5) {
5113 tsflags
= (iph
->ihl
- 5) + (tcp_opt_len
>> 2);
5114 base_flags
|= tsflags
<< 12;
5118 #if TG3_VLAN_TAG_USED
5119 if (tp
->vlgrp
!= NULL
&& vlan_tx_tag_present(skb
))
5120 base_flags
|= (TXD_FLAG_VLAN
|
5121 (vlan_tx_tag_get(skb
) << 16));
5124 if (skb_dma_map(&tp
->pdev
->dev
, skb
, DMA_TO_DEVICE
)) {
5129 sp
= skb_shinfo(skb
);
5131 mapping
= sp
->dma_maps
[0];
5133 tp
->tx_buffers
[entry
].skb
= skb
;
5135 would_hit_hwbug
= 0;
5137 if (tp
->tg3_flags3
& TG3_FLG3_5701_DMA_BUG
)
5138 would_hit_hwbug
= 1;
5139 else if (tg3_4g_overflow_test(mapping
, len
))
5140 would_hit_hwbug
= 1;
5142 tg3_set_txd(tp
, entry
, mapping
, len
, base_flags
,
5143 (skb_shinfo(skb
)->nr_frags
== 0) | (mss
<< 1));
5145 entry
= NEXT_TX(entry
);
5147 /* Now loop through additional data fragments, and queue them. */
5148 if (skb_shinfo(skb
)->nr_frags
> 0) {
5149 unsigned int i
, last
;
5151 last
= skb_shinfo(skb
)->nr_frags
- 1;
5152 for (i
= 0; i
<= last
; i
++) {
5153 skb_frag_t
*frag
= &skb_shinfo(skb
)->frags
[i
];
5156 mapping
= sp
->dma_maps
[i
+ 1];
5158 tp
->tx_buffers
[entry
].skb
= NULL
;
5160 if (tg3_4g_overflow_test(mapping
, len
))
5161 would_hit_hwbug
= 1;
5163 if (tg3_40bit_overflow_test(tp
, mapping
, len
))
5164 would_hit_hwbug
= 1;
5166 if (tp
->tg3_flags2
& TG3_FLG2_HW_TSO
)
5167 tg3_set_txd(tp
, entry
, mapping
, len
,
5168 base_flags
, (i
== last
)|(mss
<< 1));
5170 tg3_set_txd(tp
, entry
, mapping
, len
,
5171 base_flags
, (i
== last
));
5173 entry
= NEXT_TX(entry
);
5177 if (would_hit_hwbug
) {
5178 u32 last_plus_one
= entry
;
5181 start
= entry
- 1 - skb_shinfo(skb
)->nr_frags
;
5182 start
&= (TG3_TX_RING_SIZE
- 1);
5184 /* If the workaround fails due to memory/mapping
5185 * failure, silently drop this packet.
5187 if (tigon3_dma_hwbug_workaround(tp
, skb
, last_plus_one
,
5188 &start
, base_flags
, mss
))
5194 /* Packets are ready, update Tx producer idx local and on card. */
5195 tw32_tx_mbox((MAILBOX_SNDHOST_PROD_IDX_0
+ TG3_64BIT_REG_LOW
), entry
);
5197 tp
->tx_prod
= entry
;
5198 if (unlikely(tg3_tx_avail(tp
) <= (MAX_SKB_FRAGS
+ 1))) {
5199 netif_stop_queue(dev
);
5200 if (tg3_tx_avail(tp
) > TG3_TX_WAKEUP_THRESH(tp
))
5201 netif_wake_queue(tp
->dev
);
5207 dev
->trans_start
= jiffies
;
5209 return NETDEV_TX_OK
;
5212 static inline void tg3_set_mtu(struct net_device
*dev
, struct tg3
*tp
,
5217 if (new_mtu
> ETH_DATA_LEN
) {
5218 if (tp
->tg3_flags2
& TG3_FLG2_5780_CLASS
) {
5219 tp
->tg3_flags2
&= ~TG3_FLG2_TSO_CAPABLE
;
5220 ethtool_op_set_tso(dev
, 0);
5223 tp
->tg3_flags
|= TG3_FLAG_JUMBO_RING_ENABLE
;
5225 if (tp
->tg3_flags2
& TG3_FLG2_5780_CLASS
)
5226 tp
->tg3_flags2
|= TG3_FLG2_TSO_CAPABLE
;
5227 tp
->tg3_flags
&= ~TG3_FLAG_JUMBO_RING_ENABLE
;
5231 static int tg3_change_mtu(struct net_device
*dev
, int new_mtu
)
5233 struct tg3
*tp
= netdev_priv(dev
);
5236 if (new_mtu
< TG3_MIN_MTU
|| new_mtu
> TG3_MAX_MTU(tp
))
5239 if (!netif_running(dev
)) {
5240 /* We'll just catch it later when the
5243 tg3_set_mtu(dev
, tp
, new_mtu
);
5251 tg3_full_lock(tp
, 1);
5253 tg3_halt(tp
, RESET_KIND_SHUTDOWN
, 1);
5255 tg3_set_mtu(dev
, tp
, new_mtu
);
5257 err
= tg3_restart_hw(tp
, 0);
5260 tg3_netif_start(tp
);
5262 tg3_full_unlock(tp
);
5270 /* Free up pending packets in all rx/tx rings.
5272 * The chip has been shut down and the driver detached from
5273 * the networking, so no interrupts or new tx packets will
5274 * end up in the driver. tp->{tx,}lock is not held and we are not
5275 * in an interrupt context and thus may sleep.
5277 static void tg3_free_rings(struct tg3
*tp
)
5279 struct ring_info
*rxp
;
5282 for (i
= 0; i
< TG3_RX_RING_SIZE
; i
++) {
5283 rxp
= &tp
->rx_std_buffers
[i
];
5285 if (rxp
->skb
== NULL
)
5287 pci_unmap_single(tp
->pdev
,
5288 pci_unmap_addr(rxp
, mapping
),
5289 tp
->rx_pkt_buf_sz
- tp
->rx_offset
,
5290 PCI_DMA_FROMDEVICE
);
5291 dev_kfree_skb_any(rxp
->skb
);
5295 for (i
= 0; i
< TG3_RX_JUMBO_RING_SIZE
; i
++) {
5296 rxp
= &tp
->rx_jumbo_buffers
[i
];
5298 if (rxp
->skb
== NULL
)
5300 pci_unmap_single(tp
->pdev
,
5301 pci_unmap_addr(rxp
, mapping
),
5302 RX_JUMBO_PKT_BUF_SZ
- tp
->rx_offset
,
5303 PCI_DMA_FROMDEVICE
);
5304 dev_kfree_skb_any(rxp
->skb
);
5308 for (i
= 0; i
< TG3_TX_RING_SIZE
; ) {
5309 struct tx_ring_info
*txp
;
5310 struct sk_buff
*skb
;
5312 txp
= &tp
->tx_buffers
[i
];
5320 skb_dma_unmap(&tp
->pdev
->dev
, skb
, DMA_TO_DEVICE
);
5324 i
+= skb_shinfo(skb
)->nr_frags
+ 1;
5326 dev_kfree_skb_any(skb
);
5330 /* Initialize tx/rx rings for packet processing.
5332 * The chip has been shut down and the driver detached from
5333 * the networking, so no interrupts or new tx packets will
5334 * end up in the driver. tp->{tx,}lock are held and thus
5337 static int tg3_init_rings(struct tg3
*tp
)
5341 /* Free up all the SKBs. */
5344 /* Zero out all descriptors. */
5345 memset(tp
->rx_std
, 0, TG3_RX_RING_BYTES
);
5346 memset(tp
->rx_jumbo
, 0, TG3_RX_JUMBO_RING_BYTES
);
5347 memset(tp
->rx_rcb
, 0, TG3_RX_RCB_RING_BYTES(tp
));
5348 memset(tp
->tx_ring
, 0, TG3_TX_RING_BYTES
);
5350 tp
->rx_pkt_buf_sz
= RX_PKT_BUF_SZ
;
5351 if ((tp
->tg3_flags2
& TG3_FLG2_5780_CLASS
) &&
5352 (tp
->dev
->mtu
> ETH_DATA_LEN
))
5353 tp
->rx_pkt_buf_sz
= RX_JUMBO_PKT_BUF_SZ
;
5355 /* Initialize invariants of the rings, we only set this
5356 * stuff once. This works because the card does not
5357 * write into the rx buffer posting rings.
5359 for (i
= 0; i
< TG3_RX_RING_SIZE
; i
++) {
5360 struct tg3_rx_buffer_desc
*rxd
;
5362 rxd
= &tp
->rx_std
[i
];
5363 rxd
->idx_len
= (tp
->rx_pkt_buf_sz
- tp
->rx_offset
- 64)
5365 rxd
->type_flags
= (RXD_FLAG_END
<< RXD_FLAGS_SHIFT
);
5366 rxd
->opaque
= (RXD_OPAQUE_RING_STD
|
5367 (i
<< RXD_OPAQUE_INDEX_SHIFT
));
5370 if (tp
->tg3_flags
& TG3_FLAG_JUMBO_RING_ENABLE
) {
5371 for (i
= 0; i
< TG3_RX_JUMBO_RING_SIZE
; i
++) {
5372 struct tg3_rx_buffer_desc
*rxd
;
5374 rxd
= &tp
->rx_jumbo
[i
];
5375 rxd
->idx_len
= (RX_JUMBO_PKT_BUF_SZ
- tp
->rx_offset
- 64)
5377 rxd
->type_flags
= (RXD_FLAG_END
<< RXD_FLAGS_SHIFT
) |
5379 rxd
->opaque
= (RXD_OPAQUE_RING_JUMBO
|
5380 (i
<< RXD_OPAQUE_INDEX_SHIFT
));
5384 /* Now allocate fresh SKBs for each rx ring. */
5385 for (i
= 0; i
< tp
->rx_pending
; i
++) {
5386 if (tg3_alloc_rx_skb(tp
, RXD_OPAQUE_RING_STD
, -1, i
) < 0) {
5387 printk(KERN_WARNING PFX
5388 "%s: Using a smaller RX standard ring, "
5389 "only %d out of %d buffers were allocated "
5391 tp
->dev
->name
, i
, tp
->rx_pending
);
5399 if (tp
->tg3_flags
& TG3_FLAG_JUMBO_RING_ENABLE
) {
5400 for (i
= 0; i
< tp
->rx_jumbo_pending
; i
++) {
5401 if (tg3_alloc_rx_skb(tp
, RXD_OPAQUE_RING_JUMBO
,
5403 printk(KERN_WARNING PFX
5404 "%s: Using a smaller RX jumbo ring, "
5405 "only %d out of %d buffers were "
5406 "allocated successfully.\n",
5407 tp
->dev
->name
, i
, tp
->rx_jumbo_pending
);
5412 tp
->rx_jumbo_pending
= i
;
5421 * Must not be invoked with interrupt sources disabled and
5422 * the hardware shutdown down.
5424 static void tg3_free_consistent(struct tg3
*tp
)
5426 kfree(tp
->rx_std_buffers
);
5427 tp
->rx_std_buffers
= NULL
;
5429 pci_free_consistent(tp
->pdev
, TG3_RX_RING_BYTES
,
5430 tp
->rx_std
, tp
->rx_std_mapping
);
5434 pci_free_consistent(tp
->pdev
, TG3_RX_JUMBO_RING_BYTES
,
5435 tp
->rx_jumbo
, tp
->rx_jumbo_mapping
);
5436 tp
->rx_jumbo
= NULL
;
5439 pci_free_consistent(tp
->pdev
, TG3_RX_RCB_RING_BYTES(tp
),
5440 tp
->rx_rcb
, tp
->rx_rcb_mapping
);
5444 pci_free_consistent(tp
->pdev
, TG3_TX_RING_BYTES
,
5445 tp
->tx_ring
, tp
->tx_desc_mapping
);
5448 if (tp
->hw_status
) {
5449 pci_free_consistent(tp
->pdev
, TG3_HW_STATUS_SIZE
,
5450 tp
->hw_status
, tp
->status_mapping
);
5451 tp
->hw_status
= NULL
;
5454 pci_free_consistent(tp
->pdev
, sizeof(struct tg3_hw_stats
),
5455 tp
->hw_stats
, tp
->stats_mapping
);
5456 tp
->hw_stats
= NULL
;
5461 * Must not be invoked with interrupt sources disabled and
5462 * the hardware shutdown down. Can sleep.
5464 static int tg3_alloc_consistent(struct tg3
*tp
)
5466 tp
->rx_std_buffers
= kzalloc((sizeof(struct ring_info
) *
5468 TG3_RX_JUMBO_RING_SIZE
)) +
5469 (sizeof(struct tx_ring_info
) *
5472 if (!tp
->rx_std_buffers
)
5475 tp
->rx_jumbo_buffers
= &tp
->rx_std_buffers
[TG3_RX_RING_SIZE
];
5476 tp
->tx_buffers
= (struct tx_ring_info
*)
5477 &tp
->rx_jumbo_buffers
[TG3_RX_JUMBO_RING_SIZE
];
5479 tp
->rx_std
= pci_alloc_consistent(tp
->pdev
, TG3_RX_RING_BYTES
,
5480 &tp
->rx_std_mapping
);
5484 tp
->rx_jumbo
= pci_alloc_consistent(tp
->pdev
, TG3_RX_JUMBO_RING_BYTES
,
5485 &tp
->rx_jumbo_mapping
);
5490 tp
->rx_rcb
= pci_alloc_consistent(tp
->pdev
, TG3_RX_RCB_RING_BYTES(tp
),
5491 &tp
->rx_rcb_mapping
);
5495 tp
->tx_ring
= pci_alloc_consistent(tp
->pdev
, TG3_TX_RING_BYTES
,
5496 &tp
->tx_desc_mapping
);
5500 tp
->hw_status
= pci_alloc_consistent(tp
->pdev
,
5502 &tp
->status_mapping
);
5506 tp
->hw_stats
= pci_alloc_consistent(tp
->pdev
,
5507 sizeof(struct tg3_hw_stats
),
5508 &tp
->stats_mapping
);
5512 memset(tp
->hw_status
, 0, TG3_HW_STATUS_SIZE
);
5513 memset(tp
->hw_stats
, 0, sizeof(struct tg3_hw_stats
));
5518 tg3_free_consistent(tp
);
5522 #define MAX_WAIT_CNT 1000
5524 /* To stop a block, clear the enable bit and poll till it
5525 * clears. tp->lock is held.
5527 static int tg3_stop_block(struct tg3
*tp
, unsigned long ofs
, u32 enable_bit
, int silent
)
5532 if (tp
->tg3_flags2
& TG3_FLG2_5705_PLUS
) {
5539 /* We can't enable/disable these bits of the
5540 * 5705/5750, just say success.
5553 for (i
= 0; i
< MAX_WAIT_CNT
; i
++) {
5556 if ((val
& enable_bit
) == 0)
5560 if (i
== MAX_WAIT_CNT
&& !silent
) {
5561 printk(KERN_ERR PFX
"tg3_stop_block timed out, "
5562 "ofs=%lx enable_bit=%x\n",
5570 /* tp->lock is held. */
5571 static int tg3_abort_hw(struct tg3
*tp
, int silent
)
5575 tg3_disable_ints(tp
);
5577 tp
->rx_mode
&= ~RX_MODE_ENABLE
;
5578 tw32_f(MAC_RX_MODE
, tp
->rx_mode
);
5581 err
= tg3_stop_block(tp
, RCVBDI_MODE
, RCVBDI_MODE_ENABLE
, silent
);
5582 err
|= tg3_stop_block(tp
, RCVLPC_MODE
, RCVLPC_MODE_ENABLE
, silent
);
5583 err
|= tg3_stop_block(tp
, RCVLSC_MODE
, RCVLSC_MODE_ENABLE
, silent
);
5584 err
|= tg3_stop_block(tp
, RCVDBDI_MODE
, RCVDBDI_MODE_ENABLE
, silent
);
5585 err
|= tg3_stop_block(tp
, RCVDCC_MODE
, RCVDCC_MODE_ENABLE
, silent
);
5586 err
|= tg3_stop_block(tp
, RCVCC_MODE
, RCVCC_MODE_ENABLE
, silent
);
5588 err
|= tg3_stop_block(tp
, SNDBDS_MODE
, SNDBDS_MODE_ENABLE
, silent
);
5589 err
|= tg3_stop_block(tp
, SNDBDI_MODE
, SNDBDI_MODE_ENABLE
, silent
);
5590 err
|= tg3_stop_block(tp
, SNDDATAI_MODE
, SNDDATAI_MODE_ENABLE
, silent
);
5591 err
|= tg3_stop_block(tp
, RDMAC_MODE
, RDMAC_MODE_ENABLE
, silent
);
5592 err
|= tg3_stop_block(tp
, SNDDATAC_MODE
, SNDDATAC_MODE_ENABLE
, silent
);
5593 err
|= tg3_stop_block(tp
, DMAC_MODE
, DMAC_MODE_ENABLE
, silent
);
5594 err
|= tg3_stop_block(tp
, SNDBDC_MODE
, SNDBDC_MODE_ENABLE
, silent
);
5596 tp
->mac_mode
&= ~MAC_MODE_TDE_ENABLE
;
5597 tw32_f(MAC_MODE
, tp
->mac_mode
);
5600 tp
->tx_mode
&= ~TX_MODE_ENABLE
;
5601 tw32_f(MAC_TX_MODE
, tp
->tx_mode
);
5603 for (i
= 0; i
< MAX_WAIT_CNT
; i
++) {
5605 if (!(tr32(MAC_TX_MODE
) & TX_MODE_ENABLE
))
5608 if (i
>= MAX_WAIT_CNT
) {
5609 printk(KERN_ERR PFX
"tg3_abort_hw timed out for %s, "
5610 "TX_MODE_ENABLE will not clear MAC_TX_MODE=%08x\n",
5611 tp
->dev
->name
, tr32(MAC_TX_MODE
));
5615 err
|= tg3_stop_block(tp
, HOSTCC_MODE
, HOSTCC_MODE_ENABLE
, silent
);
5616 err
|= tg3_stop_block(tp
, WDMAC_MODE
, WDMAC_MODE_ENABLE
, silent
);
5617 err
|= tg3_stop_block(tp
, MBFREE_MODE
, MBFREE_MODE_ENABLE
, silent
);
5619 tw32(FTQ_RESET
, 0xffffffff);
5620 tw32(FTQ_RESET
, 0x00000000);
5622 err
|= tg3_stop_block(tp
, BUFMGR_MODE
, BUFMGR_MODE_ENABLE
, silent
);
5623 err
|= tg3_stop_block(tp
, MEMARB_MODE
, MEMARB_MODE_ENABLE
, silent
);
5626 memset(tp
->hw_status
, 0, TG3_HW_STATUS_SIZE
);
5628 memset(tp
->hw_stats
, 0, sizeof(struct tg3_hw_stats
));
5633 /* tp->lock is held. */
5634 static int tg3_nvram_lock(struct tg3
*tp
)
5636 if (tp
->tg3_flags
& TG3_FLAG_NVRAM
) {
5639 if (tp
->nvram_lock_cnt
== 0) {
5640 tw32(NVRAM_SWARB
, SWARB_REQ_SET1
);
5641 for (i
= 0; i
< 8000; i
++) {
5642 if (tr32(NVRAM_SWARB
) & SWARB_GNT1
)
5647 tw32(NVRAM_SWARB
, SWARB_REQ_CLR1
);
5651 tp
->nvram_lock_cnt
++;
5656 /* tp->lock is held. */
5657 static void tg3_nvram_unlock(struct tg3
*tp
)
5659 if (tp
->tg3_flags
& TG3_FLAG_NVRAM
) {
5660 if (tp
->nvram_lock_cnt
> 0)
5661 tp
->nvram_lock_cnt
--;
5662 if (tp
->nvram_lock_cnt
== 0)
5663 tw32_f(NVRAM_SWARB
, SWARB_REQ_CLR1
);
5667 /* tp->lock is held. */
5668 static void tg3_enable_nvram_access(struct tg3
*tp
)
5670 if ((tp
->tg3_flags2
& TG3_FLG2_5750_PLUS
) &&
5671 !(tp
->tg3_flags2
& TG3_FLG2_PROTECTED_NVRAM
)) {
5672 u32 nvaccess
= tr32(NVRAM_ACCESS
);
5674 tw32(NVRAM_ACCESS
, nvaccess
| ACCESS_ENABLE
);
5678 /* tp->lock is held. */
5679 static void tg3_disable_nvram_access(struct tg3
*tp
)
5681 if ((tp
->tg3_flags2
& TG3_FLG2_5750_PLUS
) &&
5682 !(tp
->tg3_flags2
& TG3_FLG2_PROTECTED_NVRAM
)) {
5683 u32 nvaccess
= tr32(NVRAM_ACCESS
);
5685 tw32(NVRAM_ACCESS
, nvaccess
& ~ACCESS_ENABLE
);
5689 static void tg3_ape_send_event(struct tg3
*tp
, u32 event
)
5694 apedata
= tg3_ape_read32(tp
, TG3_APE_SEG_SIG
);
5695 if (apedata
!= APE_SEG_SIG_MAGIC
)
5698 apedata
= tg3_ape_read32(tp
, TG3_APE_FW_STATUS
);
5699 if (!(apedata
& APE_FW_STATUS_READY
))
5702 /* Wait for up to 1 millisecond for APE to service previous event. */
5703 for (i
= 0; i
< 10; i
++) {
5704 if (tg3_ape_lock(tp
, TG3_APE_LOCK_MEM
))
5707 apedata
= tg3_ape_read32(tp
, TG3_APE_EVENT_STATUS
);
5709 if (!(apedata
& APE_EVENT_STATUS_EVENT_PENDING
))
5710 tg3_ape_write32(tp
, TG3_APE_EVENT_STATUS
,
5711 event
| APE_EVENT_STATUS_EVENT_PENDING
);
5713 tg3_ape_unlock(tp
, TG3_APE_LOCK_MEM
);
5715 if (!(apedata
& APE_EVENT_STATUS_EVENT_PENDING
))
5721 if (!(apedata
& APE_EVENT_STATUS_EVENT_PENDING
))
5722 tg3_ape_write32(tp
, TG3_APE_EVENT
, APE_EVENT_1
);
5725 static void tg3_ape_driver_state_change(struct tg3
*tp
, int kind
)
5730 if (!(tp
->tg3_flags3
& TG3_FLG3_ENABLE_APE
))
5734 case RESET_KIND_INIT
:
5735 tg3_ape_write32(tp
, TG3_APE_HOST_SEG_SIG
,
5736 APE_HOST_SEG_SIG_MAGIC
);
5737 tg3_ape_write32(tp
, TG3_APE_HOST_SEG_LEN
,
5738 APE_HOST_SEG_LEN_MAGIC
);
5739 apedata
= tg3_ape_read32(tp
, TG3_APE_HOST_INIT_COUNT
);
5740 tg3_ape_write32(tp
, TG3_APE_HOST_INIT_COUNT
, ++apedata
);
5741 tg3_ape_write32(tp
, TG3_APE_HOST_DRIVER_ID
,
5742 APE_HOST_DRIVER_ID_MAGIC
);
5743 tg3_ape_write32(tp
, TG3_APE_HOST_BEHAVIOR
,
5744 APE_HOST_BEHAV_NO_PHYLOCK
);
5746 event
= APE_EVENT_STATUS_STATE_START
;
5748 case RESET_KIND_SHUTDOWN
:
5749 /* With the interface we are currently using,
5750 * APE does not track driver state. Wiping
5751 * out the HOST SEGMENT SIGNATURE forces
5752 * the APE to assume OS absent status.
5754 tg3_ape_write32(tp
, TG3_APE_HOST_SEG_SIG
, 0x0);
5756 event
= APE_EVENT_STATUS_STATE_UNLOAD
;
5758 case RESET_KIND_SUSPEND
:
5759 event
= APE_EVENT_STATUS_STATE_SUSPEND
;
5765 event
|= APE_EVENT_STATUS_DRIVER_EVNT
| APE_EVENT_STATUS_STATE_CHNGE
;
5767 tg3_ape_send_event(tp
, event
);
5770 /* tp->lock is held. */
5771 static void tg3_write_sig_pre_reset(struct tg3
*tp
, int kind
)
5773 tg3_write_mem(tp
, NIC_SRAM_FIRMWARE_MBOX
,
5774 NIC_SRAM_FIRMWARE_MBOX_MAGIC1
);
5776 if (tp
->tg3_flags2
& TG3_FLG2_ASF_NEW_HANDSHAKE
) {
5778 case RESET_KIND_INIT
:
5779 tg3_write_mem(tp
, NIC_SRAM_FW_DRV_STATE_MBOX
,
5783 case RESET_KIND_SHUTDOWN
:
5784 tg3_write_mem(tp
, NIC_SRAM_FW_DRV_STATE_MBOX
,
5788 case RESET_KIND_SUSPEND
:
5789 tg3_write_mem(tp
, NIC_SRAM_FW_DRV_STATE_MBOX
,
5798 if (kind
== RESET_KIND_INIT
||
5799 kind
== RESET_KIND_SUSPEND
)
5800 tg3_ape_driver_state_change(tp
, kind
);
5803 /* tp->lock is held. */
5804 static void tg3_write_sig_post_reset(struct tg3
*tp
, int kind
)
5806 if (tp
->tg3_flags2
& TG3_FLG2_ASF_NEW_HANDSHAKE
) {
5808 case RESET_KIND_INIT
:
5809 tg3_write_mem(tp
, NIC_SRAM_FW_DRV_STATE_MBOX
,
5810 DRV_STATE_START_DONE
);
5813 case RESET_KIND_SHUTDOWN
:
5814 tg3_write_mem(tp
, NIC_SRAM_FW_DRV_STATE_MBOX
,
5815 DRV_STATE_UNLOAD_DONE
);
5823 if (kind
== RESET_KIND_SHUTDOWN
)
5824 tg3_ape_driver_state_change(tp
, kind
);
5827 /* tp->lock is held. */
5828 static void tg3_write_sig_legacy(struct tg3
*tp
, int kind
)
5830 if (tp
->tg3_flags
& TG3_FLAG_ENABLE_ASF
) {
5832 case RESET_KIND_INIT
:
5833 tg3_write_mem(tp
, NIC_SRAM_FW_DRV_STATE_MBOX
,
5837 case RESET_KIND_SHUTDOWN
:
5838 tg3_write_mem(tp
, NIC_SRAM_FW_DRV_STATE_MBOX
,
5842 case RESET_KIND_SUSPEND
:
5843 tg3_write_mem(tp
, NIC_SRAM_FW_DRV_STATE_MBOX
,
5853 static int tg3_poll_fw(struct tg3
*tp
)
5858 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5906
) {
5859 /* Wait up to 20ms for init done. */
5860 for (i
= 0; i
< 200; i
++) {
5861 if (tr32(VCPU_STATUS
) & VCPU_STATUS_INIT_DONE
)
5868 /* Wait for firmware initialization to complete. */
5869 for (i
= 0; i
< 100000; i
++) {
5870 tg3_read_mem(tp
, NIC_SRAM_FIRMWARE_MBOX
, &val
);
5871 if (val
== ~NIC_SRAM_FIRMWARE_MBOX_MAGIC1
)
5876 /* Chip might not be fitted with firmware. Some Sun onboard
5877 * parts are configured like that. So don't signal the timeout
5878 * of the above loop as an error, but do report the lack of
5879 * running firmware once.
5882 !(tp
->tg3_flags2
& TG3_FLG2_NO_FWARE_REPORTED
)) {
5883 tp
->tg3_flags2
|= TG3_FLG2_NO_FWARE_REPORTED
;
5885 printk(KERN_INFO PFX
"%s: No firmware running.\n",
5892 /* Save PCI command register before chip reset */
5893 static void tg3_save_pci_state(struct tg3
*tp
)
5895 pci_read_config_word(tp
->pdev
, PCI_COMMAND
, &tp
->pci_cmd
);
5898 /* Restore PCI state after chip reset */
5899 static void tg3_restore_pci_state(struct tg3
*tp
)
5903 /* Re-enable indirect register accesses. */
5904 pci_write_config_dword(tp
->pdev
, TG3PCI_MISC_HOST_CTRL
,
5905 tp
->misc_host_ctrl
);
5907 /* Set MAX PCI retry to zero. */
5908 val
= (PCISTATE_ROM_ENABLE
| PCISTATE_ROM_RETRY_ENABLE
);
5909 if (tp
->pci_chip_rev_id
== CHIPREV_ID_5704_A0
&&
5910 (tp
->tg3_flags
& TG3_FLAG_PCIX_MODE
))
5911 val
|= PCISTATE_RETRY_SAME_DMA
;
5912 /* Allow reads and writes to the APE register and memory space. */
5913 if (tp
->tg3_flags3
& TG3_FLG3_ENABLE_APE
)
5914 val
|= PCISTATE_ALLOW_APE_CTLSPC_WR
|
5915 PCISTATE_ALLOW_APE_SHMEM_WR
;
5916 pci_write_config_dword(tp
->pdev
, TG3PCI_PCISTATE
, val
);
5918 pci_write_config_word(tp
->pdev
, PCI_COMMAND
, tp
->pci_cmd
);
5920 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) != ASIC_REV_5785
) {
5921 if (tp
->tg3_flags2
& TG3_FLG2_PCI_EXPRESS
)
5922 pcie_set_readrq(tp
->pdev
, 4096);
5924 pci_write_config_byte(tp
->pdev
, PCI_CACHE_LINE_SIZE
,
5925 tp
->pci_cacheline_sz
);
5926 pci_write_config_byte(tp
->pdev
, PCI_LATENCY_TIMER
,
5931 /* Make sure PCI-X relaxed ordering bit is clear. */
5932 if (tp
->tg3_flags
& TG3_FLAG_PCIX_MODE
) {
5935 pci_read_config_word(tp
->pdev
, tp
->pcix_cap
+ PCI_X_CMD
,
5937 pcix_cmd
&= ~PCI_X_CMD_ERO
;
5938 pci_write_config_word(tp
->pdev
, tp
->pcix_cap
+ PCI_X_CMD
,
5942 if (tp
->tg3_flags2
& TG3_FLG2_5780_CLASS
) {
5944 /* Chip reset on 5780 will reset MSI enable bit,
5945 * so need to restore it.
5947 if (tp
->tg3_flags2
& TG3_FLG2_USING_MSI
) {
5950 pci_read_config_word(tp
->pdev
,
5951 tp
->msi_cap
+ PCI_MSI_FLAGS
,
5953 pci_write_config_word(tp
->pdev
,
5954 tp
->msi_cap
+ PCI_MSI_FLAGS
,
5955 ctrl
| PCI_MSI_FLAGS_ENABLE
);
5956 val
= tr32(MSGINT_MODE
);
5957 tw32(MSGINT_MODE
, val
| MSGINT_MODE_ENABLE
);
5962 static void tg3_stop_fw(struct tg3
*);
5964 /* tp->lock is held. */
5965 static int tg3_chip_reset(struct tg3
*tp
)
5968 void (*write_op
)(struct tg3
*, u32
, u32
);
5975 tg3_ape_lock(tp
, TG3_APE_LOCK_GRC
);
5977 /* No matching tg3_nvram_unlock() after this because
5978 * chip reset below will undo the nvram lock.
5980 tp
->nvram_lock_cnt
= 0;
5982 /* GRC_MISC_CFG core clock reset will clear the memory
5983 * enable bit in PCI register 4 and the MSI enable bit
5984 * on some chips, so we save relevant registers here.
5986 tg3_save_pci_state(tp
);
5988 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5752
||
5989 (tp
->tg3_flags3
& TG3_FLG3_5755_PLUS
))
5990 tw32(GRC_FASTBOOT_PC
, 0);
5993 * We must avoid the readl() that normally takes place.
5994 * It locks machines, causes machine checks, and other
5995 * fun things. So, temporarily disable the 5701
5996 * hardware workaround, while we do the reset.
5998 write_op
= tp
->write32
;
5999 if (write_op
== tg3_write_flush_reg32
)
6000 tp
->write32
= tg3_write32
;
6002 /* Prevent the irq handler from reading or writing PCI registers
6003 * during chip reset when the memory enable bit in the PCI command
6004 * register may be cleared. The chip does not generate interrupt
6005 * at this time, but the irq handler may still be called due to irq
6006 * sharing or irqpoll.
6008 tp
->tg3_flags
|= TG3_FLAG_CHIP_RESETTING
;
6009 if (tp
->hw_status
) {
6010 tp
->hw_status
->status
= 0;
6011 tp
->hw_status
->status_tag
= 0;
6015 synchronize_irq(tp
->pdev
->irq
);
6018 val
= GRC_MISC_CFG_CORECLK_RESET
;
6020 if (tp
->tg3_flags2
& TG3_FLG2_PCI_EXPRESS
) {
6021 if (tr32(0x7e2c) == 0x60) {
6024 if (tp
->pci_chip_rev_id
!= CHIPREV_ID_5750_A0
) {
6025 tw32(GRC_MISC_CFG
, (1 << 29));
6030 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5906
) {
6031 tw32(VCPU_STATUS
, tr32(VCPU_STATUS
) | VCPU_STATUS_DRV_RESET
);
6032 tw32(GRC_VCPU_EXT_CTRL
,
6033 tr32(GRC_VCPU_EXT_CTRL
) & ~GRC_VCPU_EXT_CTRL_HALT_CPU
);
6036 if (tp
->tg3_flags2
& TG3_FLG2_5705_PLUS
)
6037 val
|= GRC_MISC_CFG_KEEP_GPHY_POWER
;
6038 tw32(GRC_MISC_CFG
, val
);
6040 /* restore 5701 hardware bug workaround write method */
6041 tp
->write32
= write_op
;
6043 /* Unfortunately, we have to delay before the PCI read back.
6044 * Some 575X chips even will not respond to a PCI cfg access
6045 * when the reset command is given to the chip.
6047 * How do these hardware designers expect things to work
6048 * properly if the PCI write is posted for a long period
6049 * of time? It is always necessary to have some method by
6050 * which a register read back can occur to push the write
6051 * out which does the reset.
6053 * For most tg3 variants the trick below was working.
6058 /* Flush PCI posted writes. The normal MMIO registers
6059 * are inaccessible at this time so this is the only
6060 * way to make this reliably (actually, this is no longer
6061 * the case, see above). I tried to use indirect
6062 * register read/write but this upset some 5701 variants.
6064 pci_read_config_dword(tp
->pdev
, PCI_COMMAND
, &val
);
6068 if ((tp
->tg3_flags2
& TG3_FLG2_PCI_EXPRESS
) && tp
->pcie_cap
) {
6069 if (tp
->pci_chip_rev_id
== CHIPREV_ID_5750_A0
) {
6073 /* Wait for link training to complete. */
6074 for (i
= 0; i
< 5000; i
++)
6077 pci_read_config_dword(tp
->pdev
, 0xc4, &cfg_val
);
6078 pci_write_config_dword(tp
->pdev
, 0xc4,
6079 cfg_val
| (1 << 15));
6082 /* Set PCIE max payload size to 128 bytes and
6083 * clear the "no snoop" and "relaxed ordering" bits.
6085 pci_write_config_word(tp
->pdev
,
6086 tp
->pcie_cap
+ PCI_EXP_DEVCTL
,
6089 pcie_set_readrq(tp
->pdev
, 4096);
6091 /* Clear error status */
6092 pci_write_config_word(tp
->pdev
,
6093 tp
->pcie_cap
+ PCI_EXP_DEVSTA
,
6094 PCI_EXP_DEVSTA_CED
|
6095 PCI_EXP_DEVSTA_NFED
|
6096 PCI_EXP_DEVSTA_FED
|
6097 PCI_EXP_DEVSTA_URD
);
6100 tg3_restore_pci_state(tp
);
6102 tp
->tg3_flags
&= ~TG3_FLAG_CHIP_RESETTING
;
6105 if (tp
->tg3_flags2
& TG3_FLG2_5780_CLASS
)
6106 val
= tr32(MEMARB_MODE
);
6107 tw32(MEMARB_MODE
, val
| MEMARB_MODE_ENABLE
);
6109 if (tp
->pci_chip_rev_id
== CHIPREV_ID_5750_A3
) {
6111 tw32(0x5000, 0x400);
6114 tw32(GRC_MODE
, tp
->grc_mode
);
6116 if (tp
->pci_chip_rev_id
== CHIPREV_ID_5705_A0
) {
6119 tw32(0xc4, val
| (1 << 15));
6122 if ((tp
->nic_sram_data_cfg
& NIC_SRAM_DATA_CFG_MINI_PCI
) != 0 &&
6123 GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5705
) {
6124 tp
->pci_clock_ctrl
|= CLOCK_CTRL_CLKRUN_OENABLE
;
6125 if (tp
->pci_chip_rev_id
== CHIPREV_ID_5705_A0
)
6126 tp
->pci_clock_ctrl
|= CLOCK_CTRL_FORCE_CLKRUN
;
6127 tw32(TG3PCI_CLOCK_CTRL
, tp
->pci_clock_ctrl
);
6130 if (tp
->tg3_flags2
& TG3_FLG2_PHY_SERDES
) {
6131 tp
->mac_mode
= MAC_MODE_PORT_MODE_TBI
;
6132 tw32_f(MAC_MODE
, tp
->mac_mode
);
6133 } else if (tp
->tg3_flags2
& TG3_FLG2_MII_SERDES
) {
6134 tp
->mac_mode
= MAC_MODE_PORT_MODE_GMII
;
6135 tw32_f(MAC_MODE
, tp
->mac_mode
);
6136 } else if (tp
->tg3_flags3
& TG3_FLG3_ENABLE_APE
) {
6137 tp
->mac_mode
&= (MAC_MODE_APE_TX_EN
| MAC_MODE_APE_RX_EN
);
6138 if (tp
->mac_mode
& MAC_MODE_APE_TX_EN
)
6139 tp
->mac_mode
|= MAC_MODE_TDE_ENABLE
;
6140 tw32_f(MAC_MODE
, tp
->mac_mode
);
6142 tw32_f(MAC_MODE
, 0);
6147 tg3_ape_unlock(tp
, TG3_APE_LOCK_GRC
);
6149 err
= tg3_poll_fw(tp
);
6153 if ((tp
->tg3_flags2
& TG3_FLG2_PCI_EXPRESS
) &&
6154 tp
->pci_chip_rev_id
!= CHIPREV_ID_5750_A0
) {
6157 tw32(0x7c00, val
| (1 << 25));
6160 /* Reprobe ASF enable state. */
6161 tp
->tg3_flags
&= ~TG3_FLAG_ENABLE_ASF
;
6162 tp
->tg3_flags2
&= ~TG3_FLG2_ASF_NEW_HANDSHAKE
;
6163 tg3_read_mem(tp
, NIC_SRAM_DATA_SIG
, &val
);
6164 if (val
== NIC_SRAM_DATA_SIG_MAGIC
) {
6167 tg3_read_mem(tp
, NIC_SRAM_DATA_CFG
, &nic_cfg
);
6168 if (nic_cfg
& NIC_SRAM_DATA_CFG_ASF_ENABLE
) {
6169 tp
->tg3_flags
|= TG3_FLAG_ENABLE_ASF
;
6170 tp
->last_event_jiffies
= jiffies
;
6171 if (tp
->tg3_flags2
& TG3_FLG2_5750_PLUS
)
6172 tp
->tg3_flags2
|= TG3_FLG2_ASF_NEW_HANDSHAKE
;
6179 /* tp->lock is held. */
6180 static void tg3_stop_fw(struct tg3
*tp
)
6182 if ((tp
->tg3_flags
& TG3_FLAG_ENABLE_ASF
) &&
6183 !(tp
->tg3_flags3
& TG3_FLG3_ENABLE_APE
)) {
6184 /* Wait for RX cpu to ACK the previous event. */
6185 tg3_wait_for_event_ack(tp
);
6187 tg3_write_mem(tp
, NIC_SRAM_FW_CMD_MBOX
, FWCMD_NICDRV_PAUSE_FW
);
6189 tg3_generate_fw_event(tp
);
6191 /* Wait for RX cpu to ACK this event. */
6192 tg3_wait_for_event_ack(tp
);
6196 /* tp->lock is held. */
6197 static int tg3_halt(struct tg3
*tp
, int kind
, int silent
)
6203 tg3_write_sig_pre_reset(tp
, kind
);
6205 tg3_abort_hw(tp
, silent
);
6206 err
= tg3_chip_reset(tp
);
6208 tg3_write_sig_legacy(tp
, kind
);
6209 tg3_write_sig_post_reset(tp
, kind
);
6217 #define RX_CPU_SCRATCH_BASE 0x30000
6218 #define RX_CPU_SCRATCH_SIZE 0x04000
6219 #define TX_CPU_SCRATCH_BASE 0x34000
6220 #define TX_CPU_SCRATCH_SIZE 0x04000
6222 /* tp->lock is held. */
6223 static int tg3_halt_cpu(struct tg3
*tp
, u32 offset
)
6227 BUG_ON(offset
== TX_CPU_BASE
&&
6228 (tp
->tg3_flags2
& TG3_FLG2_5705_PLUS
));
6230 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5906
) {
6231 u32 val
= tr32(GRC_VCPU_EXT_CTRL
);
6233 tw32(GRC_VCPU_EXT_CTRL
, val
| GRC_VCPU_EXT_CTRL_HALT_CPU
);
6236 if (offset
== RX_CPU_BASE
) {
6237 for (i
= 0; i
< 10000; i
++) {
6238 tw32(offset
+ CPU_STATE
, 0xffffffff);
6239 tw32(offset
+ CPU_MODE
, CPU_MODE_HALT
);
6240 if (tr32(offset
+ CPU_MODE
) & CPU_MODE_HALT
)
6244 tw32(offset
+ CPU_STATE
, 0xffffffff);
6245 tw32_f(offset
+ CPU_MODE
, CPU_MODE_HALT
);
6248 for (i
= 0; i
< 10000; i
++) {
6249 tw32(offset
+ CPU_STATE
, 0xffffffff);
6250 tw32(offset
+ CPU_MODE
, CPU_MODE_HALT
);
6251 if (tr32(offset
+ CPU_MODE
) & CPU_MODE_HALT
)
6257 printk(KERN_ERR PFX
"tg3_reset_cpu timed out for %s, "
6260 (offset
== RX_CPU_BASE
? "RX" : "TX"));
6264 /* Clear firmware's nvram arbitration. */
6265 if (tp
->tg3_flags
& TG3_FLAG_NVRAM
)
6266 tw32(NVRAM_SWARB
, SWARB_REQ_CLR0
);
6271 unsigned int fw_base
;
6272 unsigned int fw_len
;
6273 const __be32
*fw_data
;
6276 /* tp->lock is held. */
6277 static int tg3_load_firmware_cpu(struct tg3
*tp
, u32 cpu_base
, u32 cpu_scratch_base
,
6278 int cpu_scratch_size
, struct fw_info
*info
)
6280 int err
, lock_err
, i
;
6281 void (*write_op
)(struct tg3
*, u32
, u32
);
6283 if (cpu_base
== TX_CPU_BASE
&&
6284 (tp
->tg3_flags2
& TG3_FLG2_5705_PLUS
)) {
6285 printk(KERN_ERR PFX
"tg3_load_firmware_cpu: Trying to load "
6286 "TX cpu firmware on %s which is 5705.\n",
6291 if (tp
->tg3_flags2
& TG3_FLG2_5705_PLUS
)
6292 write_op
= tg3_write_mem
;
6294 write_op
= tg3_write_indirect_reg32
;
6296 /* It is possible that bootcode is still loading at this point.
6297 * Get the nvram lock first before halting the cpu.
6299 lock_err
= tg3_nvram_lock(tp
);
6300 err
= tg3_halt_cpu(tp
, cpu_base
);
6302 tg3_nvram_unlock(tp
);
6306 for (i
= 0; i
< cpu_scratch_size
; i
+= sizeof(u32
))
6307 write_op(tp
, cpu_scratch_base
+ i
, 0);
6308 tw32(cpu_base
+ CPU_STATE
, 0xffffffff);
6309 tw32(cpu_base
+ CPU_MODE
, tr32(cpu_base
+CPU_MODE
)|CPU_MODE_HALT
);
6310 for (i
= 0; i
< (info
->fw_len
/ sizeof(u32
)); i
++)
6311 write_op(tp
, (cpu_scratch_base
+
6312 (info
->fw_base
& 0xffff) +
6314 be32_to_cpu(info
->fw_data
[i
]));
6322 /* tp->lock is held. */
6323 static int tg3_load_5701_a0_firmware_fix(struct tg3
*tp
)
6325 struct fw_info info
;
6326 const __be32
*fw_data
;
6329 fw_data
= (void *)tp
->fw
->data
;
6331 /* Firmware blob starts with version numbers, followed by
6332 start address and length. We are setting complete length.
6333 length = end_address_of_bss - start_address_of_text.
6334 Remainder is the blob to be loaded contiguously
6335 from start address. */
6337 info
.fw_base
= be32_to_cpu(fw_data
[1]);
6338 info
.fw_len
= tp
->fw
->size
- 12;
6339 info
.fw_data
= &fw_data
[3];
6341 err
= tg3_load_firmware_cpu(tp
, RX_CPU_BASE
,
6342 RX_CPU_SCRATCH_BASE
, RX_CPU_SCRATCH_SIZE
,
6347 err
= tg3_load_firmware_cpu(tp
, TX_CPU_BASE
,
6348 TX_CPU_SCRATCH_BASE
, TX_CPU_SCRATCH_SIZE
,
6353 /* Now startup only the RX cpu. */
6354 tw32(RX_CPU_BASE
+ CPU_STATE
, 0xffffffff);
6355 tw32_f(RX_CPU_BASE
+ CPU_PC
, info
.fw_base
);
6357 for (i
= 0; i
< 5; i
++) {
6358 if (tr32(RX_CPU_BASE
+ CPU_PC
) == info
.fw_base
)
6360 tw32(RX_CPU_BASE
+ CPU_STATE
, 0xffffffff);
6361 tw32(RX_CPU_BASE
+ CPU_MODE
, CPU_MODE_HALT
);
6362 tw32_f(RX_CPU_BASE
+ CPU_PC
, info
.fw_base
);
6366 printk(KERN_ERR PFX
"tg3_load_firmware fails for %s "
6367 "to set RX CPU PC, is %08x should be %08x\n",
6368 tp
->dev
->name
, tr32(RX_CPU_BASE
+ CPU_PC
),
6372 tw32(RX_CPU_BASE
+ CPU_STATE
, 0xffffffff);
6373 tw32_f(RX_CPU_BASE
+ CPU_MODE
, 0x00000000);
6378 /* 5705 needs a special version of the TSO firmware. */
6380 /* tp->lock is held. */
6381 static int tg3_load_tso_firmware(struct tg3
*tp
)
6383 struct fw_info info
;
6384 const __be32
*fw_data
;
6385 unsigned long cpu_base
, cpu_scratch_base
, cpu_scratch_size
;
6388 if (tp
->tg3_flags2
& TG3_FLG2_HW_TSO
)
6391 fw_data
= (void *)tp
->fw
->data
;
6393 /* Firmware blob starts with version numbers, followed by
6394 start address and length. We are setting complete length.
6395 length = end_address_of_bss - start_address_of_text.
6396 Remainder is the blob to be loaded contiguously
6397 from start address. */
6399 info
.fw_base
= be32_to_cpu(fw_data
[1]);
6400 cpu_scratch_size
= tp
->fw_len
;
6401 info
.fw_len
= tp
->fw
->size
- 12;
6402 info
.fw_data
= &fw_data
[3];
6404 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5705
) {
6405 cpu_base
= RX_CPU_BASE
;
6406 cpu_scratch_base
= NIC_SRAM_MBUF_POOL_BASE5705
;
6408 cpu_base
= TX_CPU_BASE
;
6409 cpu_scratch_base
= TX_CPU_SCRATCH_BASE
;
6410 cpu_scratch_size
= TX_CPU_SCRATCH_SIZE
;
6413 err
= tg3_load_firmware_cpu(tp
, cpu_base
,
6414 cpu_scratch_base
, cpu_scratch_size
,
6419 /* Now startup the cpu. */
6420 tw32(cpu_base
+ CPU_STATE
, 0xffffffff);
6421 tw32_f(cpu_base
+ CPU_PC
, info
.fw_base
);
6423 for (i
= 0; i
< 5; i
++) {
6424 if (tr32(cpu_base
+ CPU_PC
) == info
.fw_base
)
6426 tw32(cpu_base
+ CPU_STATE
, 0xffffffff);
6427 tw32(cpu_base
+ CPU_MODE
, CPU_MODE_HALT
);
6428 tw32_f(cpu_base
+ CPU_PC
, info
.fw_base
);
6432 printk(KERN_ERR PFX
"tg3_load_tso_firmware fails for %s "
6433 "to set CPU PC, is %08x should be %08x\n",
6434 tp
->dev
->name
, tr32(cpu_base
+ CPU_PC
),
6438 tw32(cpu_base
+ CPU_STATE
, 0xffffffff);
6439 tw32_f(cpu_base
+ CPU_MODE
, 0x00000000);
6444 static int tg3_set_mac_addr(struct net_device
*dev
, void *p
)
6446 struct tg3
*tp
= netdev_priv(dev
);
6447 struct sockaddr
*addr
= p
;
6448 int err
= 0, skip_mac_1
= 0;
6450 if (!is_valid_ether_addr(addr
->sa_data
))
6453 memcpy(dev
->dev_addr
, addr
->sa_data
, dev
->addr_len
);
6455 if (!netif_running(dev
))
6458 if (tp
->tg3_flags
& TG3_FLAG_ENABLE_ASF
) {
6459 u32 addr0_high
, addr0_low
, addr1_high
, addr1_low
;
6461 addr0_high
= tr32(MAC_ADDR_0_HIGH
);
6462 addr0_low
= tr32(MAC_ADDR_0_LOW
);
6463 addr1_high
= tr32(MAC_ADDR_1_HIGH
);
6464 addr1_low
= tr32(MAC_ADDR_1_LOW
);
6466 /* Skip MAC addr 1 if ASF is using it. */
6467 if ((addr0_high
!= addr1_high
|| addr0_low
!= addr1_low
) &&
6468 !(addr1_high
== 0 && addr1_low
== 0))
6471 spin_lock_bh(&tp
->lock
);
6472 __tg3_set_mac_addr(tp
, skip_mac_1
);
6473 spin_unlock_bh(&tp
->lock
);
6478 /* tp->lock is held. */
6479 static void tg3_set_bdinfo(struct tg3
*tp
, u32 bdinfo_addr
,
6480 dma_addr_t mapping
, u32 maxlen_flags
,
6484 (bdinfo_addr
+ TG3_BDINFO_HOST_ADDR
+ TG3_64BIT_REG_HIGH
),
6485 ((u64
) mapping
>> 32));
6487 (bdinfo_addr
+ TG3_BDINFO_HOST_ADDR
+ TG3_64BIT_REG_LOW
),
6488 ((u64
) mapping
& 0xffffffff));
6490 (bdinfo_addr
+ TG3_BDINFO_MAXLEN_FLAGS
),
6493 if (!(tp
->tg3_flags2
& TG3_FLG2_5705_PLUS
))
6495 (bdinfo_addr
+ TG3_BDINFO_NIC_ADDR
),
6499 static void __tg3_set_rx_mode(struct net_device
*);
6500 static void __tg3_set_coalesce(struct tg3
*tp
, struct ethtool_coalesce
*ec
)
6502 tw32(HOSTCC_RXCOL_TICKS
, ec
->rx_coalesce_usecs
);
6503 tw32(HOSTCC_TXCOL_TICKS
, ec
->tx_coalesce_usecs
);
6504 tw32(HOSTCC_RXMAX_FRAMES
, ec
->rx_max_coalesced_frames
);
6505 tw32(HOSTCC_TXMAX_FRAMES
, ec
->tx_max_coalesced_frames
);
6506 if (!(tp
->tg3_flags2
& TG3_FLG2_5705_PLUS
)) {
6507 tw32(HOSTCC_RXCOAL_TICK_INT
, ec
->rx_coalesce_usecs_irq
);
6508 tw32(HOSTCC_TXCOAL_TICK_INT
, ec
->tx_coalesce_usecs_irq
);
6510 tw32(HOSTCC_RXCOAL_MAXF_INT
, ec
->rx_max_coalesced_frames_irq
);
6511 tw32(HOSTCC_TXCOAL_MAXF_INT
, ec
->tx_max_coalesced_frames_irq
);
6512 if (!(tp
->tg3_flags2
& TG3_FLG2_5705_PLUS
)) {
6513 u32 val
= ec
->stats_block_coalesce_usecs
;
6515 if (!netif_carrier_ok(tp
->dev
))
6518 tw32(HOSTCC_STAT_COAL_TICKS
, val
);
6522 /* tp->lock is held. */
6523 static int tg3_reset_hw(struct tg3
*tp
, int reset_phy
)
6525 u32 val
, rdmac_mode
;
6528 tg3_disable_ints(tp
);
6532 tg3_write_sig_pre_reset(tp
, RESET_KIND_INIT
);
6534 if (tp
->tg3_flags
& TG3_FLAG_INIT_COMPLETE
) {
6535 tg3_abort_hw(tp
, 1);
6539 !(tp
->tg3_flags3
& TG3_FLG3_USE_PHYLIB
))
6542 err
= tg3_chip_reset(tp
);
6546 tg3_write_sig_legacy(tp
, RESET_KIND_INIT
);
6548 if (GET_CHIP_REV(tp
->pci_chip_rev_id
) == CHIPREV_5784_AX
) {
6549 val
= tr32(TG3_CPMU_CTRL
);
6550 val
&= ~(CPMU_CTRL_LINK_AWARE_MODE
| CPMU_CTRL_LINK_IDLE_MODE
);
6551 tw32(TG3_CPMU_CTRL
, val
);
6553 val
= tr32(TG3_CPMU_LSPD_10MB_CLK
);
6554 val
&= ~CPMU_LSPD_10MB_MACCLK_MASK
;
6555 val
|= CPMU_LSPD_10MB_MACCLK_6_25
;
6556 tw32(TG3_CPMU_LSPD_10MB_CLK
, val
);
6558 val
= tr32(TG3_CPMU_LNK_AWARE_PWRMD
);
6559 val
&= ~CPMU_LNK_AWARE_MACCLK_MASK
;
6560 val
|= CPMU_LNK_AWARE_MACCLK_6_25
;
6561 tw32(TG3_CPMU_LNK_AWARE_PWRMD
, val
);
6563 val
= tr32(TG3_CPMU_HST_ACC
);
6564 val
&= ~CPMU_HST_ACC_MACCLK_MASK
;
6565 val
|= CPMU_HST_ACC_MACCLK_6_25
;
6566 tw32(TG3_CPMU_HST_ACC
, val
);
6569 /* This works around an issue with Athlon chipsets on
6570 * B3 tigon3 silicon. This bit has no effect on any
6571 * other revision. But do not set this on PCI Express
6572 * chips and don't even touch the clocks if the CPMU is present.
6574 if (!(tp
->tg3_flags
& TG3_FLAG_CPMU_PRESENT
)) {
6575 if (!(tp
->tg3_flags2
& TG3_FLG2_PCI_EXPRESS
))
6576 tp
->pci_clock_ctrl
|= CLOCK_CTRL_DELAY_PCI_GRANT
;
6577 tw32_f(TG3PCI_CLOCK_CTRL
, tp
->pci_clock_ctrl
);
6580 if (tp
->pci_chip_rev_id
== CHIPREV_ID_5704_A0
&&
6581 (tp
->tg3_flags
& TG3_FLAG_PCIX_MODE
)) {
6582 val
= tr32(TG3PCI_PCISTATE
);
6583 val
|= PCISTATE_RETRY_SAME_DMA
;
6584 tw32(TG3PCI_PCISTATE
, val
);
6587 if (tp
->tg3_flags3
& TG3_FLG3_ENABLE_APE
) {
6588 /* Allow reads and writes to the
6589 * APE register and memory space.
6591 val
= tr32(TG3PCI_PCISTATE
);
6592 val
|= PCISTATE_ALLOW_APE_CTLSPC_WR
|
6593 PCISTATE_ALLOW_APE_SHMEM_WR
;
6594 tw32(TG3PCI_PCISTATE
, val
);
6597 if (GET_CHIP_REV(tp
->pci_chip_rev_id
) == CHIPREV_5704_BX
) {
6598 /* Enable some hw fixes. */
6599 val
= tr32(TG3PCI_MSI_DATA
);
6600 val
|= (1 << 26) | (1 << 28) | (1 << 29);
6601 tw32(TG3PCI_MSI_DATA
, val
);
6604 /* Descriptor ring init may make accesses to the
6605 * NIC SRAM area to setup the TX descriptors, so we
6606 * can only do this after the hardware has been
6607 * successfully reset.
6609 err
= tg3_init_rings(tp
);
6613 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) != ASIC_REV_5784
&&
6614 GET_ASIC_REV(tp
->pci_chip_rev_id
) != ASIC_REV_5761
) {
6615 /* This value is determined during the probe time DMA
6616 * engine test, tg3_test_dma.
6618 tw32(TG3PCI_DMA_RW_CTRL
, tp
->dma_rwctrl
);
6621 tp
->grc_mode
&= ~(GRC_MODE_HOST_SENDBDS
|
6622 GRC_MODE_4X_NIC_SEND_RINGS
|
6623 GRC_MODE_NO_TX_PHDR_CSUM
|
6624 GRC_MODE_NO_RX_PHDR_CSUM
);
6625 tp
->grc_mode
|= GRC_MODE_HOST_SENDBDS
;
6627 /* Pseudo-header checksum is done by hardware logic and not
6628 * the offload processers, so make the chip do the pseudo-
6629 * header checksums on receive. For transmit it is more
6630 * convenient to do the pseudo-header checksum in software
6631 * as Linux does that on transmit for us in all cases.
6633 tp
->grc_mode
|= GRC_MODE_NO_TX_PHDR_CSUM
;
6637 (GRC_MODE_IRQ_ON_MAC_ATTN
| GRC_MODE_HOST_STACKUP
));
6639 /* Setup the timer prescalar register. Clock is always 66Mhz. */
6640 val
= tr32(GRC_MISC_CFG
);
6642 val
|= (65 << GRC_MISC_CFG_PRESCALAR_SHIFT
);
6643 tw32(GRC_MISC_CFG
, val
);
6645 /* Initialize MBUF/DESC pool. */
6646 if (tp
->tg3_flags2
& TG3_FLG2_5750_PLUS
) {
6648 } else if (GET_ASIC_REV(tp
->pci_chip_rev_id
) != ASIC_REV_5705
) {
6649 tw32(BUFMGR_MB_POOL_ADDR
, NIC_SRAM_MBUF_POOL_BASE
);
6650 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5704
)
6651 tw32(BUFMGR_MB_POOL_SIZE
, NIC_SRAM_MBUF_POOL_SIZE64
);
6653 tw32(BUFMGR_MB_POOL_SIZE
, NIC_SRAM_MBUF_POOL_SIZE96
);
6654 tw32(BUFMGR_DMA_DESC_POOL_ADDR
, NIC_SRAM_DMA_DESC_POOL_BASE
);
6655 tw32(BUFMGR_DMA_DESC_POOL_SIZE
, NIC_SRAM_DMA_DESC_POOL_SIZE
);
6657 else if (tp
->tg3_flags2
& TG3_FLG2_TSO_CAPABLE
) {
6660 fw_len
= tp
->fw_len
;
6661 fw_len
= (fw_len
+ (0x80 - 1)) & ~(0x80 - 1);
6662 tw32(BUFMGR_MB_POOL_ADDR
,
6663 NIC_SRAM_MBUF_POOL_BASE5705
+ fw_len
);
6664 tw32(BUFMGR_MB_POOL_SIZE
,
6665 NIC_SRAM_MBUF_POOL_SIZE5705
- fw_len
- 0xa00);
6668 if (tp
->dev
->mtu
<= ETH_DATA_LEN
) {
6669 tw32(BUFMGR_MB_RDMA_LOW_WATER
,
6670 tp
->bufmgr_config
.mbuf_read_dma_low_water
);
6671 tw32(BUFMGR_MB_MACRX_LOW_WATER
,
6672 tp
->bufmgr_config
.mbuf_mac_rx_low_water
);
6673 tw32(BUFMGR_MB_HIGH_WATER
,
6674 tp
->bufmgr_config
.mbuf_high_water
);
6676 tw32(BUFMGR_MB_RDMA_LOW_WATER
,
6677 tp
->bufmgr_config
.mbuf_read_dma_low_water_jumbo
);
6678 tw32(BUFMGR_MB_MACRX_LOW_WATER
,
6679 tp
->bufmgr_config
.mbuf_mac_rx_low_water_jumbo
);
6680 tw32(BUFMGR_MB_HIGH_WATER
,
6681 tp
->bufmgr_config
.mbuf_high_water_jumbo
);
6683 tw32(BUFMGR_DMA_LOW_WATER
,
6684 tp
->bufmgr_config
.dma_low_water
);
6685 tw32(BUFMGR_DMA_HIGH_WATER
,
6686 tp
->bufmgr_config
.dma_high_water
);
6688 tw32(BUFMGR_MODE
, BUFMGR_MODE_ENABLE
| BUFMGR_MODE_ATTN_ENABLE
);
6689 for (i
= 0; i
< 2000; i
++) {
6690 if (tr32(BUFMGR_MODE
) & BUFMGR_MODE_ENABLE
)
6695 printk(KERN_ERR PFX
"tg3_reset_hw cannot enable BUFMGR for %s.\n",
6700 /* Setup replenish threshold. */
6701 val
= tp
->rx_pending
/ 8;
6704 else if (val
> tp
->rx_std_max_post
)
6705 val
= tp
->rx_std_max_post
;
6706 else if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5906
) {
6707 if (tp
->pci_chip_rev_id
== CHIPREV_ID_5906_A1
)
6708 tw32(ISO_PKT_TX
, (tr32(ISO_PKT_TX
) & ~0x3) | 0x2);
6710 if (val
> (TG3_RX_INTERNAL_RING_SZ_5906
/ 2))
6711 val
= TG3_RX_INTERNAL_RING_SZ_5906
/ 2;
6714 tw32(RCVBDI_STD_THRESH
, val
);
6716 /* Initialize TG3_BDINFO's at:
6717 * RCVDBDI_STD_BD: standard eth size rx ring
6718 * RCVDBDI_JUMBO_BD: jumbo frame rx ring
6719 * RCVDBDI_MINI_BD: small frame rx ring (??? does not work)
6722 * TG3_BDINFO_HOST_ADDR: high/low parts of DMA address of ring
6723 * TG3_BDINFO_MAXLEN_FLAGS: (rx max buffer size << 16) |
6724 * ring attribute flags
6725 * TG3_BDINFO_NIC_ADDR: location of descriptors in nic SRAM
6727 * Standard receive ring @ NIC_SRAM_RX_BUFFER_DESC, 512 entries.
6728 * Jumbo receive ring @ NIC_SRAM_RX_JUMBO_BUFFER_DESC, 256 entries.
6730 * The size of each ring is fixed in the firmware, but the location is
6733 tw32(RCVDBDI_STD_BD
+ TG3_BDINFO_HOST_ADDR
+ TG3_64BIT_REG_HIGH
,
6734 ((u64
) tp
->rx_std_mapping
>> 32));
6735 tw32(RCVDBDI_STD_BD
+ TG3_BDINFO_HOST_ADDR
+ TG3_64BIT_REG_LOW
,
6736 ((u64
) tp
->rx_std_mapping
& 0xffffffff));
6737 tw32(RCVDBDI_STD_BD
+ TG3_BDINFO_NIC_ADDR
,
6738 NIC_SRAM_RX_BUFFER_DESC
);
6740 /* Don't even try to program the JUMBO/MINI buffer descriptor
6743 if (tp
->tg3_flags2
& TG3_FLG2_5705_PLUS
) {
6744 tw32(RCVDBDI_STD_BD
+ TG3_BDINFO_MAXLEN_FLAGS
,
6745 RX_STD_MAX_SIZE_5705
<< BDINFO_FLAGS_MAXLEN_SHIFT
);
6747 tw32(RCVDBDI_STD_BD
+ TG3_BDINFO_MAXLEN_FLAGS
,
6748 RX_STD_MAX_SIZE
<< BDINFO_FLAGS_MAXLEN_SHIFT
);
6750 tw32(RCVDBDI_MINI_BD
+ TG3_BDINFO_MAXLEN_FLAGS
,
6751 BDINFO_FLAGS_DISABLED
);
6753 /* Setup replenish threshold. */
6754 tw32(RCVBDI_JUMBO_THRESH
, tp
->rx_jumbo_pending
/ 8);
6756 if (tp
->tg3_flags
& TG3_FLAG_JUMBO_RING_ENABLE
) {
6757 tw32(RCVDBDI_JUMBO_BD
+ TG3_BDINFO_HOST_ADDR
+ TG3_64BIT_REG_HIGH
,
6758 ((u64
) tp
->rx_jumbo_mapping
>> 32));
6759 tw32(RCVDBDI_JUMBO_BD
+ TG3_BDINFO_HOST_ADDR
+ TG3_64BIT_REG_LOW
,
6760 ((u64
) tp
->rx_jumbo_mapping
& 0xffffffff));
6761 tw32(RCVDBDI_JUMBO_BD
+ TG3_BDINFO_MAXLEN_FLAGS
,
6762 RX_JUMBO_MAX_SIZE
<< BDINFO_FLAGS_MAXLEN_SHIFT
);
6763 tw32(RCVDBDI_JUMBO_BD
+ TG3_BDINFO_NIC_ADDR
,
6764 NIC_SRAM_RX_JUMBO_BUFFER_DESC
);
6766 tw32(RCVDBDI_JUMBO_BD
+ TG3_BDINFO_MAXLEN_FLAGS
,
6767 BDINFO_FLAGS_DISABLED
);
6772 /* There is only one send ring on 5705/5750, no need to explicitly
6773 * disable the others.
6775 if (!(tp
->tg3_flags2
& TG3_FLG2_5705_PLUS
)) {
6776 /* Clear out send RCB ring in SRAM. */
6777 for (i
= NIC_SRAM_SEND_RCB
; i
< NIC_SRAM_RCV_RET_RCB
; i
+= TG3_BDINFO_SIZE
)
6778 tg3_write_mem(tp
, i
+ TG3_BDINFO_MAXLEN_FLAGS
,
6779 BDINFO_FLAGS_DISABLED
);
6784 tw32_mailbox(MAILBOX_SNDHOST_PROD_IDX_0
+ TG3_64BIT_REG_LOW
, 0);
6785 tw32_tx_mbox(MAILBOX_SNDNIC_PROD_IDX_0
+ TG3_64BIT_REG_LOW
, 0);
6787 tg3_set_bdinfo(tp
, NIC_SRAM_SEND_RCB
,
6788 tp
->tx_desc_mapping
,
6789 (TG3_TX_RING_SIZE
<<
6790 BDINFO_FLAGS_MAXLEN_SHIFT
),
6791 NIC_SRAM_TX_BUFFER_DESC
);
6793 /* There is only one receive return ring on 5705/5750, no need
6794 * to explicitly disable the others.
6796 if (!(tp
->tg3_flags2
& TG3_FLG2_5705_PLUS
)) {
6797 for (i
= NIC_SRAM_RCV_RET_RCB
; i
< NIC_SRAM_STATS_BLK
;
6798 i
+= TG3_BDINFO_SIZE
) {
6799 tg3_write_mem(tp
, i
+ TG3_BDINFO_MAXLEN_FLAGS
,
6800 BDINFO_FLAGS_DISABLED
);
6805 tw32_rx_mbox(MAILBOX_RCVRET_CON_IDX_0
+ TG3_64BIT_REG_LOW
, 0);
6807 tg3_set_bdinfo(tp
, NIC_SRAM_RCV_RET_RCB
,
6809 (TG3_RX_RCB_RING_SIZE(tp
) <<
6810 BDINFO_FLAGS_MAXLEN_SHIFT
),
6813 tp
->rx_std_ptr
= tp
->rx_pending
;
6814 tw32_rx_mbox(MAILBOX_RCV_STD_PROD_IDX
+ TG3_64BIT_REG_LOW
,
6817 tp
->rx_jumbo_ptr
= (tp
->tg3_flags
& TG3_FLAG_JUMBO_RING_ENABLE
) ?
6818 tp
->rx_jumbo_pending
: 0;
6819 tw32_rx_mbox(MAILBOX_RCV_JUMBO_PROD_IDX
+ TG3_64BIT_REG_LOW
,
6822 /* Initialize MAC address and backoff seed. */
6823 __tg3_set_mac_addr(tp
, 0);
6825 /* MTU + ethernet header + FCS + optional VLAN tag */
6826 tw32(MAC_RX_MTU_SIZE
, tp
->dev
->mtu
+ ETH_HLEN
+ 8);
6828 /* The slot time is changed by tg3_setup_phy if we
6829 * run at gigabit with half duplex.
6831 tw32(MAC_TX_LENGTHS
,
6832 (2 << TX_LENGTHS_IPG_CRS_SHIFT
) |
6833 (6 << TX_LENGTHS_IPG_SHIFT
) |
6834 (32 << TX_LENGTHS_SLOT_TIME_SHIFT
));
6836 /* Receive rules. */
6837 tw32(MAC_RCV_RULE_CFG
, RCV_RULE_CFG_DEFAULT_CLASS
);
6838 tw32(RCVLPC_CONFIG
, 0x0181);
6840 /* Calculate RDMAC_MODE setting early, we need it to determine
6841 * the RCVLPC_STATE_ENABLE mask.
6843 rdmac_mode
= (RDMAC_MODE_ENABLE
| RDMAC_MODE_TGTABORT_ENAB
|
6844 RDMAC_MODE_MSTABORT_ENAB
| RDMAC_MODE_PARITYERR_ENAB
|
6845 RDMAC_MODE_ADDROFLOW_ENAB
| RDMAC_MODE_FIFOOFLOW_ENAB
|
6846 RDMAC_MODE_FIFOURUN_ENAB
| RDMAC_MODE_FIFOOREAD_ENAB
|
6847 RDMAC_MODE_LNGREAD_ENAB
);
6849 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5784
||
6850 GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5785
||
6851 GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_57780
)
6852 rdmac_mode
|= RDMAC_MODE_BD_SBD_CRPT_ENAB
|
6853 RDMAC_MODE_MBUF_RBD_CRPT_ENAB
|
6854 RDMAC_MODE_MBUF_SBD_CRPT_ENAB
;
6856 /* If statement applies to 5705 and 5750 PCI devices only */
6857 if ((GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5705
&&
6858 tp
->pci_chip_rev_id
!= CHIPREV_ID_5705_A0
) ||
6859 (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5750
)) {
6860 if (tp
->tg3_flags2
& TG3_FLG2_TSO_CAPABLE
&&
6861 GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5705
) {
6862 rdmac_mode
|= RDMAC_MODE_FIFO_SIZE_128
;
6863 } else if (!(tr32(TG3PCI_PCISTATE
) & PCISTATE_BUS_SPEED_HIGH
) &&
6864 !(tp
->tg3_flags2
& TG3_FLG2_IS_5788
)) {
6865 rdmac_mode
|= RDMAC_MODE_FIFO_LONG_BURST
;
6869 if (tp
->tg3_flags2
& TG3_FLG2_PCI_EXPRESS
)
6870 rdmac_mode
|= RDMAC_MODE_FIFO_LONG_BURST
;
6872 if (tp
->tg3_flags2
& TG3_FLG2_HW_TSO
)
6873 rdmac_mode
|= RDMAC_MODE_IPV4_LSO_EN
;
6875 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5785
||
6876 GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_57780
)
6877 rdmac_mode
|= RDMAC_MODE_IPV6_LSO_EN
;
6879 /* Receive/send statistics. */
6880 if (tp
->tg3_flags2
& TG3_FLG2_5750_PLUS
) {
6881 val
= tr32(RCVLPC_STATS_ENABLE
);
6882 val
&= ~RCVLPC_STATSENAB_DACK_FIX
;
6883 tw32(RCVLPC_STATS_ENABLE
, val
);
6884 } else if ((rdmac_mode
& RDMAC_MODE_FIFO_SIZE_128
) &&
6885 (tp
->tg3_flags2
& TG3_FLG2_TSO_CAPABLE
)) {
6886 val
= tr32(RCVLPC_STATS_ENABLE
);
6887 val
&= ~RCVLPC_STATSENAB_LNGBRST_RFIX
;
6888 tw32(RCVLPC_STATS_ENABLE
, val
);
6890 tw32(RCVLPC_STATS_ENABLE
, 0xffffff);
6892 tw32(RCVLPC_STATSCTRL
, RCVLPC_STATSCTRL_ENABLE
);
6893 tw32(SNDDATAI_STATSENAB
, 0xffffff);
6894 tw32(SNDDATAI_STATSCTRL
,
6895 (SNDDATAI_SCTRL_ENABLE
|
6896 SNDDATAI_SCTRL_FASTUPD
));
6898 /* Setup host coalescing engine. */
6899 tw32(HOSTCC_MODE
, 0);
6900 for (i
= 0; i
< 2000; i
++) {
6901 if (!(tr32(HOSTCC_MODE
) & HOSTCC_MODE_ENABLE
))
6906 __tg3_set_coalesce(tp
, &tp
->coal
);
6908 /* set status block DMA address */
6909 tw32(HOSTCC_STATUS_BLK_HOST_ADDR
+ TG3_64BIT_REG_HIGH
,
6910 ((u64
) tp
->status_mapping
>> 32));
6911 tw32(HOSTCC_STATUS_BLK_HOST_ADDR
+ TG3_64BIT_REG_LOW
,
6912 ((u64
) tp
->status_mapping
& 0xffffffff));
6914 if (!(tp
->tg3_flags2
& TG3_FLG2_5705_PLUS
)) {
6915 /* Status/statistics block address. See tg3_timer,
6916 * the tg3_periodic_fetch_stats call there, and
6917 * tg3_get_stats to see how this works for 5705/5750 chips.
6919 tw32(HOSTCC_STATS_BLK_HOST_ADDR
+ TG3_64BIT_REG_HIGH
,
6920 ((u64
) tp
->stats_mapping
>> 32));
6921 tw32(HOSTCC_STATS_BLK_HOST_ADDR
+ TG3_64BIT_REG_LOW
,
6922 ((u64
) tp
->stats_mapping
& 0xffffffff));
6923 tw32(HOSTCC_STATS_BLK_NIC_ADDR
, NIC_SRAM_STATS_BLK
);
6924 tw32(HOSTCC_STATUS_BLK_NIC_ADDR
, NIC_SRAM_STATUS_BLK
);
6927 tw32(HOSTCC_MODE
, HOSTCC_MODE_ENABLE
| tp
->coalesce_mode
);
6929 tw32(RCVCC_MODE
, RCVCC_MODE_ENABLE
| RCVCC_MODE_ATTN_ENABLE
);
6930 tw32(RCVLPC_MODE
, RCVLPC_MODE_ENABLE
);
6931 if (!(tp
->tg3_flags2
& TG3_FLG2_5705_PLUS
))
6932 tw32(RCVLSC_MODE
, RCVLSC_MODE_ENABLE
| RCVLSC_MODE_ATTN_ENABLE
);
6934 /* Clear statistics/status block in chip, and status block in ram. */
6935 for (i
= NIC_SRAM_STATS_BLK
;
6936 i
< NIC_SRAM_STATUS_BLK
+ TG3_HW_STATUS_SIZE
;
6938 tg3_write_mem(tp
, i
, 0);
6941 memset(tp
->hw_status
, 0, TG3_HW_STATUS_SIZE
);
6943 if (tp
->tg3_flags2
& TG3_FLG2_MII_SERDES
) {
6944 tp
->tg3_flags2
&= ~TG3_FLG2_PARALLEL_DETECT
;
6945 /* reset to prevent losing 1st rx packet intermittently */
6946 tw32_f(MAC_RX_MODE
, RX_MODE_RESET
);
6950 if (tp
->tg3_flags3
& TG3_FLG3_ENABLE_APE
)
6951 tp
->mac_mode
&= MAC_MODE_APE_TX_EN
| MAC_MODE_APE_RX_EN
;
6954 tp
->mac_mode
|= MAC_MODE_TXSTAT_ENABLE
| MAC_MODE_RXSTAT_ENABLE
|
6955 MAC_MODE_TDE_ENABLE
| MAC_MODE_RDE_ENABLE
| MAC_MODE_FHDE_ENABLE
;
6956 if (!(tp
->tg3_flags2
& TG3_FLG2_5705_PLUS
) &&
6957 !(tp
->tg3_flags2
& TG3_FLG2_PHY_SERDES
) &&
6958 GET_ASIC_REV(tp
->pci_chip_rev_id
) != ASIC_REV_5700
)
6959 tp
->mac_mode
|= MAC_MODE_LINK_POLARITY
;
6960 tw32_f(MAC_MODE
, tp
->mac_mode
| MAC_MODE_RXSTAT_CLEAR
| MAC_MODE_TXSTAT_CLEAR
);
6963 /* tp->grc_local_ctrl is partially set up during tg3_get_invariants().
6964 * If TG3_FLG2_IS_NIC is zero, we should read the
6965 * register to preserve the GPIO settings for LOMs. The GPIOs,
6966 * whether used as inputs or outputs, are set by boot code after
6969 if (!(tp
->tg3_flags2
& TG3_FLG2_IS_NIC
)) {
6972 gpio_mask
= GRC_LCLCTRL_GPIO_OE0
| GRC_LCLCTRL_GPIO_OE1
|
6973 GRC_LCLCTRL_GPIO_OE2
| GRC_LCLCTRL_GPIO_OUTPUT0
|
6974 GRC_LCLCTRL_GPIO_OUTPUT1
| GRC_LCLCTRL_GPIO_OUTPUT2
;
6976 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5752
)
6977 gpio_mask
|= GRC_LCLCTRL_GPIO_OE3
|
6978 GRC_LCLCTRL_GPIO_OUTPUT3
;
6980 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5755
)
6981 gpio_mask
|= GRC_LCLCTRL_GPIO_UART_SEL
;
6983 tp
->grc_local_ctrl
&= ~gpio_mask
;
6984 tp
->grc_local_ctrl
|= tr32(GRC_LOCAL_CTRL
) & gpio_mask
;
6986 /* GPIO1 must be driven high for eeprom write protect */
6987 if (tp
->tg3_flags
& TG3_FLAG_EEPROM_WRITE_PROT
)
6988 tp
->grc_local_ctrl
|= (GRC_LCLCTRL_GPIO_OE1
|
6989 GRC_LCLCTRL_GPIO_OUTPUT1
);
6991 tw32_f(GRC_LOCAL_CTRL
, tp
->grc_local_ctrl
);
6994 tw32_mailbox_f(MAILBOX_INTERRUPT_0
+ TG3_64BIT_REG_LOW
, 0);
6997 if (!(tp
->tg3_flags2
& TG3_FLG2_5705_PLUS
)) {
6998 tw32_f(DMAC_MODE
, DMAC_MODE_ENABLE
);
7002 val
= (WDMAC_MODE_ENABLE
| WDMAC_MODE_TGTABORT_ENAB
|
7003 WDMAC_MODE_MSTABORT_ENAB
| WDMAC_MODE_PARITYERR_ENAB
|
7004 WDMAC_MODE_ADDROFLOW_ENAB
| WDMAC_MODE_FIFOOFLOW_ENAB
|
7005 WDMAC_MODE_FIFOURUN_ENAB
| WDMAC_MODE_FIFOOREAD_ENAB
|
7006 WDMAC_MODE_LNGREAD_ENAB
);
7008 /* If statement applies to 5705 and 5750 PCI devices only */
7009 if ((GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5705
&&
7010 tp
->pci_chip_rev_id
!= CHIPREV_ID_5705_A0
) ||
7011 GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5750
) {
7012 if ((tp
->tg3_flags
& TG3_FLG2_TSO_CAPABLE
) &&
7013 (tp
->pci_chip_rev_id
== CHIPREV_ID_5705_A1
||
7014 tp
->pci_chip_rev_id
== CHIPREV_ID_5705_A2
)) {
7016 } else if (!(tr32(TG3PCI_PCISTATE
) & PCISTATE_BUS_SPEED_HIGH
) &&
7017 !(tp
->tg3_flags2
& TG3_FLG2_IS_5788
) &&
7018 !(tp
->tg3_flags2
& TG3_FLG2_PCI_EXPRESS
)) {
7019 val
|= WDMAC_MODE_RX_ACCEL
;
7023 /* Enable host coalescing bug fix */
7024 if (tp
->tg3_flags3
& TG3_FLG3_5755_PLUS
)
7025 val
|= WDMAC_MODE_STATUS_TAG_FIX
;
7027 tw32_f(WDMAC_MODE
, val
);
7030 if (tp
->tg3_flags
& TG3_FLAG_PCIX_MODE
) {
7033 pci_read_config_word(tp
->pdev
, tp
->pcix_cap
+ PCI_X_CMD
,
7035 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5703
) {
7036 pcix_cmd
&= ~PCI_X_CMD_MAX_READ
;
7037 pcix_cmd
|= PCI_X_CMD_READ_2K
;
7038 } else if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5704
) {
7039 pcix_cmd
&= ~(PCI_X_CMD_MAX_SPLIT
| PCI_X_CMD_MAX_READ
);
7040 pcix_cmd
|= PCI_X_CMD_READ_2K
;
7042 pci_write_config_word(tp
->pdev
, tp
->pcix_cap
+ PCI_X_CMD
,
7046 tw32_f(RDMAC_MODE
, rdmac_mode
);
7049 tw32(RCVDCC_MODE
, RCVDCC_MODE_ENABLE
| RCVDCC_MODE_ATTN_ENABLE
);
7050 if (!(tp
->tg3_flags2
& TG3_FLG2_5705_PLUS
))
7051 tw32(MBFREE_MODE
, MBFREE_MODE_ENABLE
);
7053 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5761
)
7055 SNDDATAC_MODE_ENABLE
| SNDDATAC_MODE_CDELAY
);
7057 tw32(SNDDATAC_MODE
, SNDDATAC_MODE_ENABLE
);
7059 tw32(SNDBDC_MODE
, SNDBDC_MODE_ENABLE
| SNDBDC_MODE_ATTN_ENABLE
);
7060 tw32(RCVBDI_MODE
, RCVBDI_MODE_ENABLE
| RCVBDI_MODE_RCB_ATTN_ENAB
);
7061 tw32(RCVDBDI_MODE
, RCVDBDI_MODE_ENABLE
| RCVDBDI_MODE_INV_RING_SZ
);
7062 tw32(SNDDATAI_MODE
, SNDDATAI_MODE_ENABLE
);
7063 if (tp
->tg3_flags2
& TG3_FLG2_HW_TSO
)
7064 tw32(SNDDATAI_MODE
, SNDDATAI_MODE_ENABLE
| 0x8);
7065 tw32(SNDBDI_MODE
, SNDBDI_MODE_ENABLE
| SNDBDI_MODE_ATTN_ENABLE
);
7066 tw32(SNDBDS_MODE
, SNDBDS_MODE_ENABLE
| SNDBDS_MODE_ATTN_ENABLE
);
7068 if (tp
->pci_chip_rev_id
== CHIPREV_ID_5701_A0
) {
7069 err
= tg3_load_5701_a0_firmware_fix(tp
);
7074 if (tp
->tg3_flags2
& TG3_FLG2_TSO_CAPABLE
) {
7075 err
= tg3_load_tso_firmware(tp
);
7080 tp
->tx_mode
= TX_MODE_ENABLE
;
7081 tw32_f(MAC_TX_MODE
, tp
->tx_mode
);
7084 tp
->rx_mode
= RX_MODE_ENABLE
;
7085 if (tp
->tg3_flags3
& TG3_FLG3_5755_PLUS
)
7086 tp
->rx_mode
|= RX_MODE_IPV6_CSUM_ENABLE
;
7088 tw32_f(MAC_RX_MODE
, tp
->rx_mode
);
7091 tw32(MAC_LED_CTRL
, tp
->led_ctrl
);
7093 tw32(MAC_MI_STAT
, MAC_MI_STAT_LNKSTAT_ATTN_ENAB
);
7094 if (tp
->tg3_flags2
& TG3_FLG2_PHY_SERDES
) {
7095 tw32_f(MAC_RX_MODE
, RX_MODE_RESET
);
7098 tw32_f(MAC_RX_MODE
, tp
->rx_mode
);
7101 if (tp
->tg3_flags2
& TG3_FLG2_PHY_SERDES
) {
7102 if ((GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5704
) &&
7103 !(tp
->tg3_flags2
& TG3_FLG2_SERDES_PREEMPHASIS
)) {
7104 /* Set drive transmission level to 1.2V */
7105 /* only if the signal pre-emphasis bit is not set */
7106 val
= tr32(MAC_SERDES_CFG
);
7109 tw32(MAC_SERDES_CFG
, val
);
7111 if (tp
->pci_chip_rev_id
== CHIPREV_ID_5703_A1
)
7112 tw32(MAC_SERDES_CFG
, 0x616000);
7115 /* Prevent chip from dropping frames when flow control
7118 tw32_f(MAC_LOW_WMARK_MAX_RX_FRAME
, 2);
7120 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5704
&&
7121 (tp
->tg3_flags2
& TG3_FLG2_PHY_SERDES
)) {
7122 /* Use hardware link auto-negotiation */
7123 tp
->tg3_flags2
|= TG3_FLG2_HW_AUTONEG
;
7126 if ((tp
->tg3_flags2
& TG3_FLG2_MII_SERDES
) &&
7127 (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5714
)) {
7130 tmp
= tr32(SERDES_RX_CTRL
);
7131 tw32(SERDES_RX_CTRL
, tmp
| SERDES_RX_SIG_DETECT
);
7132 tp
->grc_local_ctrl
&= ~GRC_LCLCTRL_USE_EXT_SIG_DETECT
;
7133 tp
->grc_local_ctrl
|= GRC_LCLCTRL_USE_SIG_DETECT
;
7134 tw32(GRC_LOCAL_CTRL
, tp
->grc_local_ctrl
);
7137 if (!(tp
->tg3_flags3
& TG3_FLG3_USE_PHYLIB
)) {
7138 if (tp
->link_config
.phy_is_low_power
) {
7139 tp
->link_config
.phy_is_low_power
= 0;
7140 tp
->link_config
.speed
= tp
->link_config
.orig_speed
;
7141 tp
->link_config
.duplex
= tp
->link_config
.orig_duplex
;
7142 tp
->link_config
.autoneg
= tp
->link_config
.orig_autoneg
;
7145 err
= tg3_setup_phy(tp
, 0);
7149 if (!(tp
->tg3_flags2
& TG3_FLG2_PHY_SERDES
) &&
7150 GET_ASIC_REV(tp
->pci_chip_rev_id
) != ASIC_REV_5906
) {
7153 /* Clear CRC stats. */
7154 if (!tg3_readphy(tp
, MII_TG3_TEST1
, &tmp
)) {
7155 tg3_writephy(tp
, MII_TG3_TEST1
,
7156 tmp
| MII_TG3_TEST1_CRC_EN
);
7157 tg3_readphy(tp
, 0x14, &tmp
);
7162 __tg3_set_rx_mode(tp
->dev
);
7164 /* Initialize receive rules. */
7165 tw32(MAC_RCV_RULE_0
, 0xc2000000 & RCV_RULE_DISABLE_MASK
);
7166 tw32(MAC_RCV_VALUE_0
, 0xffffffff & RCV_RULE_DISABLE_MASK
);
7167 tw32(MAC_RCV_RULE_1
, 0x86000004 & RCV_RULE_DISABLE_MASK
);
7168 tw32(MAC_RCV_VALUE_1
, 0xffffffff & RCV_RULE_DISABLE_MASK
);
7170 if ((tp
->tg3_flags2
& TG3_FLG2_5705_PLUS
) &&
7171 !(tp
->tg3_flags2
& TG3_FLG2_5780_CLASS
))
7175 if (tp
->tg3_flags
& TG3_FLAG_ENABLE_ASF
)
7179 tw32(MAC_RCV_RULE_15
, 0); tw32(MAC_RCV_VALUE_15
, 0);
7181 tw32(MAC_RCV_RULE_14
, 0); tw32(MAC_RCV_VALUE_14
, 0);
7183 tw32(MAC_RCV_RULE_13
, 0); tw32(MAC_RCV_VALUE_13
, 0);
7185 tw32(MAC_RCV_RULE_12
, 0); tw32(MAC_RCV_VALUE_12
, 0);
7187 tw32(MAC_RCV_RULE_11
, 0); tw32(MAC_RCV_VALUE_11
, 0);
7189 tw32(MAC_RCV_RULE_10
, 0); tw32(MAC_RCV_VALUE_10
, 0);
7191 tw32(MAC_RCV_RULE_9
, 0); tw32(MAC_RCV_VALUE_9
, 0);
7193 tw32(MAC_RCV_RULE_8
, 0); tw32(MAC_RCV_VALUE_8
, 0);
7195 tw32(MAC_RCV_RULE_7
, 0); tw32(MAC_RCV_VALUE_7
, 0);
7197 tw32(MAC_RCV_RULE_6
, 0); tw32(MAC_RCV_VALUE_6
, 0);
7199 tw32(MAC_RCV_RULE_5
, 0); tw32(MAC_RCV_VALUE_5
, 0);
7201 tw32(MAC_RCV_RULE_4
, 0); tw32(MAC_RCV_VALUE_4
, 0);
7203 /* tw32(MAC_RCV_RULE_3, 0); tw32(MAC_RCV_VALUE_3, 0); */
7205 /* tw32(MAC_RCV_RULE_2, 0); tw32(MAC_RCV_VALUE_2, 0); */
7213 if (tp
->tg3_flags3
& TG3_FLG3_ENABLE_APE
)
7214 /* Write our heartbeat update interval to APE. */
7215 tg3_ape_write32(tp
, TG3_APE_HOST_HEARTBEAT_INT_MS
,
7216 APE_HOST_HEARTBEAT_INT_DISABLE
);
7218 tg3_write_sig_post_reset(tp
, RESET_KIND_INIT
);
7223 /* Called at device open time to get the chip ready for
7224 * packet processing. Invoked with tp->lock held.
7226 static int tg3_init_hw(struct tg3
*tp
, int reset_phy
)
7228 tg3_switch_clocks(tp
);
7230 tw32(TG3PCI_MEM_WIN_BASE_ADDR
, 0);
7232 return tg3_reset_hw(tp
, reset_phy
);
7235 #define TG3_STAT_ADD32(PSTAT, REG) \
7236 do { u32 __val = tr32(REG); \
7237 (PSTAT)->low += __val; \
7238 if ((PSTAT)->low < __val) \
7239 (PSTAT)->high += 1; \
7242 static void tg3_periodic_fetch_stats(struct tg3
*tp
)
7244 struct tg3_hw_stats
*sp
= tp
->hw_stats
;
7246 if (!netif_carrier_ok(tp
->dev
))
7249 TG3_STAT_ADD32(&sp
->tx_octets
, MAC_TX_STATS_OCTETS
);
7250 TG3_STAT_ADD32(&sp
->tx_collisions
, MAC_TX_STATS_COLLISIONS
);
7251 TG3_STAT_ADD32(&sp
->tx_xon_sent
, MAC_TX_STATS_XON_SENT
);
7252 TG3_STAT_ADD32(&sp
->tx_xoff_sent
, MAC_TX_STATS_XOFF_SENT
);
7253 TG3_STAT_ADD32(&sp
->tx_mac_errors
, MAC_TX_STATS_MAC_ERRORS
);
7254 TG3_STAT_ADD32(&sp
->tx_single_collisions
, MAC_TX_STATS_SINGLE_COLLISIONS
);
7255 TG3_STAT_ADD32(&sp
->tx_mult_collisions
, MAC_TX_STATS_MULT_COLLISIONS
);
7256 TG3_STAT_ADD32(&sp
->tx_deferred
, MAC_TX_STATS_DEFERRED
);
7257 TG3_STAT_ADD32(&sp
->tx_excessive_collisions
, MAC_TX_STATS_EXCESSIVE_COL
);
7258 TG3_STAT_ADD32(&sp
->tx_late_collisions
, MAC_TX_STATS_LATE_COL
);
7259 TG3_STAT_ADD32(&sp
->tx_ucast_packets
, MAC_TX_STATS_UCAST
);
7260 TG3_STAT_ADD32(&sp
->tx_mcast_packets
, MAC_TX_STATS_MCAST
);
7261 TG3_STAT_ADD32(&sp
->tx_bcast_packets
, MAC_TX_STATS_BCAST
);
7263 TG3_STAT_ADD32(&sp
->rx_octets
, MAC_RX_STATS_OCTETS
);
7264 TG3_STAT_ADD32(&sp
->rx_fragments
, MAC_RX_STATS_FRAGMENTS
);
7265 TG3_STAT_ADD32(&sp
->rx_ucast_packets
, MAC_RX_STATS_UCAST
);
7266 TG3_STAT_ADD32(&sp
->rx_mcast_packets
, MAC_RX_STATS_MCAST
);
7267 TG3_STAT_ADD32(&sp
->rx_bcast_packets
, MAC_RX_STATS_BCAST
);
7268 TG3_STAT_ADD32(&sp
->rx_fcs_errors
, MAC_RX_STATS_FCS_ERRORS
);
7269 TG3_STAT_ADD32(&sp
->rx_align_errors
, MAC_RX_STATS_ALIGN_ERRORS
);
7270 TG3_STAT_ADD32(&sp
->rx_xon_pause_rcvd
, MAC_RX_STATS_XON_PAUSE_RECVD
);
7271 TG3_STAT_ADD32(&sp
->rx_xoff_pause_rcvd
, MAC_RX_STATS_XOFF_PAUSE_RECVD
);
7272 TG3_STAT_ADD32(&sp
->rx_mac_ctrl_rcvd
, MAC_RX_STATS_MAC_CTRL_RECVD
);
7273 TG3_STAT_ADD32(&sp
->rx_xoff_entered
, MAC_RX_STATS_XOFF_ENTERED
);
7274 TG3_STAT_ADD32(&sp
->rx_frame_too_long_errors
, MAC_RX_STATS_FRAME_TOO_LONG
);
7275 TG3_STAT_ADD32(&sp
->rx_jabbers
, MAC_RX_STATS_JABBERS
);
7276 TG3_STAT_ADD32(&sp
->rx_undersize_packets
, MAC_RX_STATS_UNDERSIZE
);
7278 TG3_STAT_ADD32(&sp
->rxbds_empty
, RCVLPC_NO_RCV_BD_CNT
);
7279 TG3_STAT_ADD32(&sp
->rx_discards
, RCVLPC_IN_DISCARDS_CNT
);
7280 TG3_STAT_ADD32(&sp
->rx_errors
, RCVLPC_IN_ERRORS_CNT
);
7283 static void tg3_timer(unsigned long __opaque
)
7285 struct tg3
*tp
= (struct tg3
*) __opaque
;
7290 spin_lock(&tp
->lock
);
7292 if (!(tp
->tg3_flags
& TG3_FLAG_TAGGED_STATUS
)) {
7293 /* All of this garbage is because when using non-tagged
7294 * IRQ status the mailbox/status_block protocol the chip
7295 * uses with the cpu is race prone.
7297 if (tp
->hw_status
->status
& SD_STATUS_UPDATED
) {
7298 tw32(GRC_LOCAL_CTRL
,
7299 tp
->grc_local_ctrl
| GRC_LCLCTRL_SETINT
);
7301 tw32(HOSTCC_MODE
, tp
->coalesce_mode
|
7302 (HOSTCC_MODE_ENABLE
| HOSTCC_MODE_NOW
));
7305 if (!(tr32(WDMAC_MODE
) & WDMAC_MODE_ENABLE
)) {
7306 tp
->tg3_flags2
|= TG3_FLG2_RESTART_TIMER
;
7307 spin_unlock(&tp
->lock
);
7308 schedule_work(&tp
->reset_task
);
7313 /* This part only runs once per second. */
7314 if (!--tp
->timer_counter
) {
7315 if (tp
->tg3_flags2
& TG3_FLG2_5705_PLUS
)
7316 tg3_periodic_fetch_stats(tp
);
7318 if (tp
->tg3_flags
& TG3_FLAG_USE_LINKCHG_REG
) {
7322 mac_stat
= tr32(MAC_STATUS
);
7325 if (tp
->tg3_flags
& TG3_FLAG_USE_MI_INTERRUPT
) {
7326 if (mac_stat
& MAC_STATUS_MI_INTERRUPT
)
7328 } else if (mac_stat
& MAC_STATUS_LNKSTATE_CHANGED
)
7332 tg3_setup_phy(tp
, 0);
7333 } else if (tp
->tg3_flags
& TG3_FLAG_POLL_SERDES
) {
7334 u32 mac_stat
= tr32(MAC_STATUS
);
7337 if (netif_carrier_ok(tp
->dev
) &&
7338 (mac_stat
& MAC_STATUS_LNKSTATE_CHANGED
)) {
7341 if (! netif_carrier_ok(tp
->dev
) &&
7342 (mac_stat
& (MAC_STATUS_PCS_SYNCED
|
7343 MAC_STATUS_SIGNAL_DET
))) {
7347 if (!tp
->serdes_counter
) {
7350 ~MAC_MODE_PORT_MODE_MASK
));
7352 tw32_f(MAC_MODE
, tp
->mac_mode
);
7355 tg3_setup_phy(tp
, 0);
7357 } else if (tp
->tg3_flags2
& TG3_FLG2_MII_SERDES
)
7358 tg3_serdes_parallel_detect(tp
);
7360 tp
->timer_counter
= tp
->timer_multiplier
;
7363 /* Heartbeat is only sent once every 2 seconds.
7365 * The heartbeat is to tell the ASF firmware that the host
7366 * driver is still alive. In the event that the OS crashes,
7367 * ASF needs to reset the hardware to free up the FIFO space
7368 * that may be filled with rx packets destined for the host.
7369 * If the FIFO is full, ASF will no longer function properly.
7371 * Unintended resets have been reported on real time kernels
7372 * where the timer doesn't run on time. Netpoll will also have
7375 * The new FWCMD_NICDRV_ALIVE3 command tells the ASF firmware
7376 * to check the ring condition when the heartbeat is expiring
7377 * before doing the reset. This will prevent most unintended
7380 if (!--tp
->asf_counter
) {
7381 if ((tp
->tg3_flags
& TG3_FLAG_ENABLE_ASF
) &&
7382 !(tp
->tg3_flags3
& TG3_FLG3_ENABLE_APE
)) {
7383 tg3_wait_for_event_ack(tp
);
7385 tg3_write_mem(tp
, NIC_SRAM_FW_CMD_MBOX
,
7386 FWCMD_NICDRV_ALIVE3
);
7387 tg3_write_mem(tp
, NIC_SRAM_FW_CMD_LEN_MBOX
, 4);
7388 /* 5 seconds timeout */
7389 tg3_write_mem(tp
, NIC_SRAM_FW_CMD_DATA_MBOX
, 5);
7391 tg3_generate_fw_event(tp
);
7393 tp
->asf_counter
= tp
->asf_multiplier
;
7396 spin_unlock(&tp
->lock
);
7399 tp
->timer
.expires
= jiffies
+ tp
->timer_offset
;
7400 add_timer(&tp
->timer
);
7403 static int tg3_request_irq(struct tg3
*tp
)
7406 unsigned long flags
;
7407 struct net_device
*dev
= tp
->dev
;
7409 if (tp
->tg3_flags2
& TG3_FLG2_USING_MSI
) {
7411 if (tp
->tg3_flags2
& TG3_FLG2_1SHOT_MSI
)
7413 flags
= IRQF_SAMPLE_RANDOM
;
7416 if (tp
->tg3_flags
& TG3_FLAG_TAGGED_STATUS
)
7417 fn
= tg3_interrupt_tagged
;
7418 flags
= IRQF_SHARED
| IRQF_SAMPLE_RANDOM
;
7420 return (request_irq(tp
->pdev
->irq
, fn
, flags
, dev
->name
, dev
));
7423 static int tg3_test_interrupt(struct tg3
*tp
)
7425 struct net_device
*dev
= tp
->dev
;
7426 int err
, i
, intr_ok
= 0;
7428 if (!netif_running(dev
))
7431 tg3_disable_ints(tp
);
7433 free_irq(tp
->pdev
->irq
, dev
);
7435 err
= request_irq(tp
->pdev
->irq
, tg3_test_isr
,
7436 IRQF_SHARED
| IRQF_SAMPLE_RANDOM
, dev
->name
, dev
);
7440 tp
->hw_status
->status
&= ~SD_STATUS_UPDATED
;
7441 tg3_enable_ints(tp
);
7443 tw32_f(HOSTCC_MODE
, tp
->coalesce_mode
| HOSTCC_MODE_ENABLE
|
7446 for (i
= 0; i
< 5; i
++) {
7447 u32 int_mbox
, misc_host_ctrl
;
7449 int_mbox
= tr32_mailbox(MAILBOX_INTERRUPT_0
+
7451 misc_host_ctrl
= tr32(TG3PCI_MISC_HOST_CTRL
);
7453 if ((int_mbox
!= 0) ||
7454 (misc_host_ctrl
& MISC_HOST_CTRL_MASK_PCI_INT
)) {
7462 tg3_disable_ints(tp
);
7464 free_irq(tp
->pdev
->irq
, dev
);
7466 err
= tg3_request_irq(tp
);
7477 /* Returns 0 if MSI test succeeds or MSI test fails and INTx mode is
7478 * successfully restored
7480 static int tg3_test_msi(struct tg3
*tp
)
7482 struct net_device
*dev
= tp
->dev
;
7486 if (!(tp
->tg3_flags2
& TG3_FLG2_USING_MSI
))
7489 /* Turn off SERR reporting in case MSI terminates with Master
7492 pci_read_config_word(tp
->pdev
, PCI_COMMAND
, &pci_cmd
);
7493 pci_write_config_word(tp
->pdev
, PCI_COMMAND
,
7494 pci_cmd
& ~PCI_COMMAND_SERR
);
7496 err
= tg3_test_interrupt(tp
);
7498 pci_write_config_word(tp
->pdev
, PCI_COMMAND
, pci_cmd
);
7503 /* other failures */
7507 /* MSI test failed, go back to INTx mode */
7508 printk(KERN_WARNING PFX
"%s: No interrupt was generated using MSI, "
7509 "switching to INTx mode. Please report this failure to "
7510 "the PCI maintainer and include system chipset information.\n",
7513 free_irq(tp
->pdev
->irq
, dev
);
7514 pci_disable_msi(tp
->pdev
);
7516 tp
->tg3_flags2
&= ~TG3_FLG2_USING_MSI
;
7518 err
= tg3_request_irq(tp
);
7522 /* Need to reset the chip because the MSI cycle may have terminated
7523 * with Master Abort.
7525 tg3_full_lock(tp
, 1);
7527 tg3_halt(tp
, RESET_KIND_SHUTDOWN
, 1);
7528 err
= tg3_init_hw(tp
, 1);
7530 tg3_full_unlock(tp
);
7533 free_irq(tp
->pdev
->irq
, dev
);
7538 static int tg3_open(struct net_device
*dev
)
7540 struct tg3
*tp
= netdev_priv(dev
);
7543 netif_carrier_off(tp
->dev
);
7545 err
= tg3_set_power_state(tp
, PCI_D0
);
7549 tg3_full_lock(tp
, 0);
7551 tg3_disable_ints(tp
);
7552 tp
->tg3_flags
&= ~TG3_FLAG_INIT_COMPLETE
;
7554 tg3_full_unlock(tp
);
7556 /* The placement of this call is tied
7557 * to the setup and use of Host TX descriptors.
7559 err
= tg3_alloc_consistent(tp
);
7563 if (tp
->tg3_flags
& TG3_FLAG_SUPPORT_MSI
) {
7564 /* All MSI supporting chips should support tagged
7565 * status. Assert that this is the case.
7567 if (!(tp
->tg3_flags
& TG3_FLAG_TAGGED_STATUS
)) {
7568 printk(KERN_WARNING PFX
"%s: MSI without TAGGED? "
7569 "Not using MSI.\n", tp
->dev
->name
);
7570 } else if (pci_enable_msi(tp
->pdev
) == 0) {
7573 msi_mode
= tr32(MSGINT_MODE
);
7574 tw32(MSGINT_MODE
, msi_mode
| MSGINT_MODE_ENABLE
);
7575 tp
->tg3_flags2
|= TG3_FLG2_USING_MSI
;
7578 err
= tg3_request_irq(tp
);
7581 if (tp
->tg3_flags2
& TG3_FLG2_USING_MSI
) {
7582 pci_disable_msi(tp
->pdev
);
7583 tp
->tg3_flags2
&= ~TG3_FLG2_USING_MSI
;
7585 tg3_free_consistent(tp
);
7589 napi_enable(&tp
->napi
);
7591 tg3_full_lock(tp
, 0);
7593 err
= tg3_init_hw(tp
, 1);
7595 tg3_halt(tp
, RESET_KIND_SHUTDOWN
, 1);
7598 if (tp
->tg3_flags
& TG3_FLAG_TAGGED_STATUS
)
7599 tp
->timer_offset
= HZ
;
7601 tp
->timer_offset
= HZ
/ 10;
7603 BUG_ON(tp
->timer_offset
> HZ
);
7604 tp
->timer_counter
= tp
->timer_multiplier
=
7605 (HZ
/ tp
->timer_offset
);
7606 tp
->asf_counter
= tp
->asf_multiplier
=
7607 ((HZ
/ tp
->timer_offset
) * 2);
7609 init_timer(&tp
->timer
);
7610 tp
->timer
.expires
= jiffies
+ tp
->timer_offset
;
7611 tp
->timer
.data
= (unsigned long) tp
;
7612 tp
->timer
.function
= tg3_timer
;
7615 tg3_full_unlock(tp
);
7618 napi_disable(&tp
->napi
);
7619 free_irq(tp
->pdev
->irq
, dev
);
7620 if (tp
->tg3_flags2
& TG3_FLG2_USING_MSI
) {
7621 pci_disable_msi(tp
->pdev
);
7622 tp
->tg3_flags2
&= ~TG3_FLG2_USING_MSI
;
7624 tg3_free_consistent(tp
);
7628 if (tp
->tg3_flags2
& TG3_FLG2_USING_MSI
) {
7629 err
= tg3_test_msi(tp
);
7632 tg3_full_lock(tp
, 0);
7634 if (tp
->tg3_flags2
& TG3_FLG2_USING_MSI
) {
7635 pci_disable_msi(tp
->pdev
);
7636 tp
->tg3_flags2
&= ~TG3_FLG2_USING_MSI
;
7638 tg3_halt(tp
, RESET_KIND_SHUTDOWN
, 1);
7640 tg3_free_consistent(tp
);
7642 tg3_full_unlock(tp
);
7644 napi_disable(&tp
->napi
);
7649 if (tp
->tg3_flags2
& TG3_FLG2_USING_MSI
) {
7650 if (tp
->tg3_flags2
& TG3_FLG2_1SHOT_MSI
) {
7651 u32 val
= tr32(PCIE_TRANSACTION_CFG
);
7653 tw32(PCIE_TRANSACTION_CFG
,
7654 val
| PCIE_TRANS_CFG_1SHOT_MSI
);
7661 tg3_full_lock(tp
, 0);
7663 add_timer(&tp
->timer
);
7664 tp
->tg3_flags
|= TG3_FLAG_INIT_COMPLETE
;
7665 tg3_enable_ints(tp
);
7667 tg3_full_unlock(tp
);
7669 netif_start_queue(dev
);
7675 /*static*/ void tg3_dump_state(struct tg3
*tp
)
7677 u32 val32
, val32_2
, val32_3
, val32_4
, val32_5
;
7681 pci_read_config_word(tp
->pdev
, PCI_STATUS
, &val16
);
7682 pci_read_config_dword(tp
->pdev
, TG3PCI_PCISTATE
, &val32
);
7683 printk("DEBUG: PCI status [%04x] TG3PCI state[%08x]\n",
7687 printk("DEBUG: MAC_MODE[%08x] MAC_STATUS[%08x]\n",
7688 tr32(MAC_MODE
), tr32(MAC_STATUS
));
7689 printk(" MAC_EVENT[%08x] MAC_LED_CTRL[%08x]\n",
7690 tr32(MAC_EVENT
), tr32(MAC_LED_CTRL
));
7691 printk("DEBUG: MAC_TX_MODE[%08x] MAC_TX_STATUS[%08x]\n",
7692 tr32(MAC_TX_MODE
), tr32(MAC_TX_STATUS
));
7693 printk(" MAC_RX_MODE[%08x] MAC_RX_STATUS[%08x]\n",
7694 tr32(MAC_RX_MODE
), tr32(MAC_RX_STATUS
));
7696 /* Send data initiator control block */
7697 printk("DEBUG: SNDDATAI_MODE[%08x] SNDDATAI_STATUS[%08x]\n",
7698 tr32(SNDDATAI_MODE
), tr32(SNDDATAI_STATUS
));
7699 printk(" SNDDATAI_STATSCTRL[%08x]\n",
7700 tr32(SNDDATAI_STATSCTRL
));
7702 /* Send data completion control block */
7703 printk("DEBUG: SNDDATAC_MODE[%08x]\n", tr32(SNDDATAC_MODE
));
7705 /* Send BD ring selector block */
7706 printk("DEBUG: SNDBDS_MODE[%08x] SNDBDS_STATUS[%08x]\n",
7707 tr32(SNDBDS_MODE
), tr32(SNDBDS_STATUS
));
7709 /* Send BD initiator control block */
7710 printk("DEBUG: SNDBDI_MODE[%08x] SNDBDI_STATUS[%08x]\n",
7711 tr32(SNDBDI_MODE
), tr32(SNDBDI_STATUS
));
7713 /* Send BD completion control block */
7714 printk("DEBUG: SNDBDC_MODE[%08x]\n", tr32(SNDBDC_MODE
));
7716 /* Receive list placement control block */
7717 printk("DEBUG: RCVLPC_MODE[%08x] RCVLPC_STATUS[%08x]\n",
7718 tr32(RCVLPC_MODE
), tr32(RCVLPC_STATUS
));
7719 printk(" RCVLPC_STATSCTRL[%08x]\n",
7720 tr32(RCVLPC_STATSCTRL
));
7722 /* Receive data and receive BD initiator control block */
7723 printk("DEBUG: RCVDBDI_MODE[%08x] RCVDBDI_STATUS[%08x]\n",
7724 tr32(RCVDBDI_MODE
), tr32(RCVDBDI_STATUS
));
7726 /* Receive data completion control block */
7727 printk("DEBUG: RCVDCC_MODE[%08x]\n",
7730 /* Receive BD initiator control block */
7731 printk("DEBUG: RCVBDI_MODE[%08x] RCVBDI_STATUS[%08x]\n",
7732 tr32(RCVBDI_MODE
), tr32(RCVBDI_STATUS
));
7734 /* Receive BD completion control block */
7735 printk("DEBUG: RCVCC_MODE[%08x] RCVCC_STATUS[%08x]\n",
7736 tr32(RCVCC_MODE
), tr32(RCVCC_STATUS
));
7738 /* Receive list selector control block */
7739 printk("DEBUG: RCVLSC_MODE[%08x] RCVLSC_STATUS[%08x]\n",
7740 tr32(RCVLSC_MODE
), tr32(RCVLSC_STATUS
));
7742 /* Mbuf cluster free block */
7743 printk("DEBUG: MBFREE_MODE[%08x] MBFREE_STATUS[%08x]\n",
7744 tr32(MBFREE_MODE
), tr32(MBFREE_STATUS
));
7746 /* Host coalescing control block */
7747 printk("DEBUG: HOSTCC_MODE[%08x] HOSTCC_STATUS[%08x]\n",
7748 tr32(HOSTCC_MODE
), tr32(HOSTCC_STATUS
));
7749 printk("DEBUG: HOSTCC_STATS_BLK_HOST_ADDR[%08x%08x]\n",
7750 tr32(HOSTCC_STATS_BLK_HOST_ADDR
+ TG3_64BIT_REG_HIGH
),
7751 tr32(HOSTCC_STATS_BLK_HOST_ADDR
+ TG3_64BIT_REG_LOW
));
7752 printk("DEBUG: HOSTCC_STATUS_BLK_HOST_ADDR[%08x%08x]\n",
7753 tr32(HOSTCC_STATUS_BLK_HOST_ADDR
+ TG3_64BIT_REG_HIGH
),
7754 tr32(HOSTCC_STATUS_BLK_HOST_ADDR
+ TG3_64BIT_REG_LOW
));
7755 printk("DEBUG: HOSTCC_STATS_BLK_NIC_ADDR[%08x]\n",
7756 tr32(HOSTCC_STATS_BLK_NIC_ADDR
));
7757 printk("DEBUG: HOSTCC_STATUS_BLK_NIC_ADDR[%08x]\n",
7758 tr32(HOSTCC_STATUS_BLK_NIC_ADDR
));
7760 /* Memory arbiter control block */
7761 printk("DEBUG: MEMARB_MODE[%08x] MEMARB_STATUS[%08x]\n",
7762 tr32(MEMARB_MODE
), tr32(MEMARB_STATUS
));
7764 /* Buffer manager control block */
7765 printk("DEBUG: BUFMGR_MODE[%08x] BUFMGR_STATUS[%08x]\n",
7766 tr32(BUFMGR_MODE
), tr32(BUFMGR_STATUS
));
7767 printk("DEBUG: BUFMGR_MB_POOL_ADDR[%08x] BUFMGR_MB_POOL_SIZE[%08x]\n",
7768 tr32(BUFMGR_MB_POOL_ADDR
), tr32(BUFMGR_MB_POOL_SIZE
));
7769 printk("DEBUG: BUFMGR_DMA_DESC_POOL_ADDR[%08x] "
7770 "BUFMGR_DMA_DESC_POOL_SIZE[%08x]\n",
7771 tr32(BUFMGR_DMA_DESC_POOL_ADDR
),
7772 tr32(BUFMGR_DMA_DESC_POOL_SIZE
));
7774 /* Read DMA control block */
7775 printk("DEBUG: RDMAC_MODE[%08x] RDMAC_STATUS[%08x]\n",
7776 tr32(RDMAC_MODE
), tr32(RDMAC_STATUS
));
7778 /* Write DMA control block */
7779 printk("DEBUG: WDMAC_MODE[%08x] WDMAC_STATUS[%08x]\n",
7780 tr32(WDMAC_MODE
), tr32(WDMAC_STATUS
));
7782 /* DMA completion block */
7783 printk("DEBUG: DMAC_MODE[%08x]\n",
7787 printk("DEBUG: GRC_MODE[%08x] GRC_MISC_CFG[%08x]\n",
7788 tr32(GRC_MODE
), tr32(GRC_MISC_CFG
));
7789 printk("DEBUG: GRC_LOCAL_CTRL[%08x]\n",
7790 tr32(GRC_LOCAL_CTRL
));
7793 printk("DEBUG: RCVDBDI_JUMBO_BD[%08x%08x:%08x:%08x]\n",
7794 tr32(RCVDBDI_JUMBO_BD
+ 0x0),
7795 tr32(RCVDBDI_JUMBO_BD
+ 0x4),
7796 tr32(RCVDBDI_JUMBO_BD
+ 0x8),
7797 tr32(RCVDBDI_JUMBO_BD
+ 0xc));
7798 printk("DEBUG: RCVDBDI_STD_BD[%08x%08x:%08x:%08x]\n",
7799 tr32(RCVDBDI_STD_BD
+ 0x0),
7800 tr32(RCVDBDI_STD_BD
+ 0x4),
7801 tr32(RCVDBDI_STD_BD
+ 0x8),
7802 tr32(RCVDBDI_STD_BD
+ 0xc));
7803 printk("DEBUG: RCVDBDI_MINI_BD[%08x%08x:%08x:%08x]\n",
7804 tr32(RCVDBDI_MINI_BD
+ 0x0),
7805 tr32(RCVDBDI_MINI_BD
+ 0x4),
7806 tr32(RCVDBDI_MINI_BD
+ 0x8),
7807 tr32(RCVDBDI_MINI_BD
+ 0xc));
7809 tg3_read_mem(tp
, NIC_SRAM_SEND_RCB
+ 0x0, &val32
);
7810 tg3_read_mem(tp
, NIC_SRAM_SEND_RCB
+ 0x4, &val32_2
);
7811 tg3_read_mem(tp
, NIC_SRAM_SEND_RCB
+ 0x8, &val32_3
);
7812 tg3_read_mem(tp
, NIC_SRAM_SEND_RCB
+ 0xc, &val32_4
);
7813 printk("DEBUG: SRAM_SEND_RCB_0[%08x%08x:%08x:%08x]\n",
7814 val32
, val32_2
, val32_3
, val32_4
);
7816 tg3_read_mem(tp
, NIC_SRAM_RCV_RET_RCB
+ 0x0, &val32
);
7817 tg3_read_mem(tp
, NIC_SRAM_RCV_RET_RCB
+ 0x4, &val32_2
);
7818 tg3_read_mem(tp
, NIC_SRAM_RCV_RET_RCB
+ 0x8, &val32_3
);
7819 tg3_read_mem(tp
, NIC_SRAM_RCV_RET_RCB
+ 0xc, &val32_4
);
7820 printk("DEBUG: SRAM_RCV_RET_RCB_0[%08x%08x:%08x:%08x]\n",
7821 val32
, val32_2
, val32_3
, val32_4
);
7823 tg3_read_mem(tp
, NIC_SRAM_STATUS_BLK
+ 0x0, &val32
);
7824 tg3_read_mem(tp
, NIC_SRAM_STATUS_BLK
+ 0x4, &val32_2
);
7825 tg3_read_mem(tp
, NIC_SRAM_STATUS_BLK
+ 0x8, &val32_3
);
7826 tg3_read_mem(tp
, NIC_SRAM_STATUS_BLK
+ 0xc, &val32_4
);
7827 tg3_read_mem(tp
, NIC_SRAM_STATUS_BLK
+ 0x10, &val32_5
);
7828 printk("DEBUG: SRAM_STATUS_BLK[%08x:%08x:%08x:%08x:%08x]\n",
7829 val32
, val32_2
, val32_3
, val32_4
, val32_5
);
7831 /* SW status block */
7832 printk("DEBUG: Host status block [%08x:%08x:(%04x:%04x:%04x):(%04x:%04x)]\n",
7833 tp
->hw_status
->status
,
7834 tp
->hw_status
->status_tag
,
7835 tp
->hw_status
->rx_jumbo_consumer
,
7836 tp
->hw_status
->rx_consumer
,
7837 tp
->hw_status
->rx_mini_consumer
,
7838 tp
->hw_status
->idx
[0].rx_producer
,
7839 tp
->hw_status
->idx
[0].tx_consumer
);
7841 /* SW statistics block */
7842 printk("DEBUG: Host statistics block [%08x:%08x:%08x:%08x]\n",
7843 ((u32
*)tp
->hw_stats
)[0],
7844 ((u32
*)tp
->hw_stats
)[1],
7845 ((u32
*)tp
->hw_stats
)[2],
7846 ((u32
*)tp
->hw_stats
)[3]);
7849 printk("DEBUG: SNDHOST_PROD[%08x%08x] SNDNIC_PROD[%08x%08x]\n",
7850 tr32_mailbox(MAILBOX_SNDHOST_PROD_IDX_0
+ 0x0),
7851 tr32_mailbox(MAILBOX_SNDHOST_PROD_IDX_0
+ 0x4),
7852 tr32_mailbox(MAILBOX_SNDNIC_PROD_IDX_0
+ 0x0),
7853 tr32_mailbox(MAILBOX_SNDNIC_PROD_IDX_0
+ 0x4));
7855 /* NIC side send descriptors. */
7856 for (i
= 0; i
< 6; i
++) {
7859 txd
= tp
->regs
+ NIC_SRAM_WIN_BASE
+ NIC_SRAM_TX_BUFFER_DESC
7860 + (i
* sizeof(struct tg3_tx_buffer_desc
));
7861 printk("DEBUG: NIC TXD(%d)[%08x:%08x:%08x:%08x]\n",
7863 readl(txd
+ 0x0), readl(txd
+ 0x4),
7864 readl(txd
+ 0x8), readl(txd
+ 0xc));
7867 /* NIC side RX descriptors. */
7868 for (i
= 0; i
< 6; i
++) {
7871 rxd
= tp
->regs
+ NIC_SRAM_WIN_BASE
+ NIC_SRAM_RX_BUFFER_DESC
7872 + (i
* sizeof(struct tg3_rx_buffer_desc
));
7873 printk("DEBUG: NIC RXD_STD(%d)[0][%08x:%08x:%08x:%08x]\n",
7875 readl(rxd
+ 0x0), readl(rxd
+ 0x4),
7876 readl(rxd
+ 0x8), readl(rxd
+ 0xc));
7877 rxd
+= (4 * sizeof(u32
));
7878 printk("DEBUG: NIC RXD_STD(%d)[1][%08x:%08x:%08x:%08x]\n",
7880 readl(rxd
+ 0x0), readl(rxd
+ 0x4),
7881 readl(rxd
+ 0x8), readl(rxd
+ 0xc));
7884 for (i
= 0; i
< 6; i
++) {
7887 rxd
= tp
->regs
+ NIC_SRAM_WIN_BASE
+ NIC_SRAM_RX_JUMBO_BUFFER_DESC
7888 + (i
* sizeof(struct tg3_rx_buffer_desc
));
7889 printk("DEBUG: NIC RXD_JUMBO(%d)[0][%08x:%08x:%08x:%08x]\n",
7891 readl(rxd
+ 0x0), readl(rxd
+ 0x4),
7892 readl(rxd
+ 0x8), readl(rxd
+ 0xc));
7893 rxd
+= (4 * sizeof(u32
));
7894 printk("DEBUG: NIC RXD_JUMBO(%d)[1][%08x:%08x:%08x:%08x]\n",
7896 readl(rxd
+ 0x0), readl(rxd
+ 0x4),
7897 readl(rxd
+ 0x8), readl(rxd
+ 0xc));
7902 static struct net_device_stats
*tg3_get_stats(struct net_device
*);
7903 static struct tg3_ethtool_stats
*tg3_get_estats(struct tg3
*);
7905 static int tg3_close(struct net_device
*dev
)
7907 struct tg3
*tp
= netdev_priv(dev
);
7909 napi_disable(&tp
->napi
);
7910 cancel_work_sync(&tp
->reset_task
);
7912 netif_stop_queue(dev
);
7914 del_timer_sync(&tp
->timer
);
7916 tg3_full_lock(tp
, 1);
7921 tg3_disable_ints(tp
);
7923 tg3_halt(tp
, RESET_KIND_SHUTDOWN
, 1);
7925 tp
->tg3_flags
&= ~TG3_FLAG_INIT_COMPLETE
;
7927 tg3_full_unlock(tp
);
7929 free_irq(tp
->pdev
->irq
, dev
);
7930 if (tp
->tg3_flags2
& TG3_FLG2_USING_MSI
) {
7931 pci_disable_msi(tp
->pdev
);
7932 tp
->tg3_flags2
&= ~TG3_FLG2_USING_MSI
;
7935 memcpy(&tp
->net_stats_prev
, tg3_get_stats(tp
->dev
),
7936 sizeof(tp
->net_stats_prev
));
7937 memcpy(&tp
->estats_prev
, tg3_get_estats(tp
),
7938 sizeof(tp
->estats_prev
));
7940 tg3_free_consistent(tp
);
7942 tg3_set_power_state(tp
, PCI_D3hot
);
7944 netif_carrier_off(tp
->dev
);
7949 static inline unsigned long get_stat64(tg3_stat64_t
*val
)
7953 #if (BITS_PER_LONG == 32)
7956 ret
= ((u64
)val
->high
<< 32) | ((u64
)val
->low
);
7961 static inline u64
get_estat64(tg3_stat64_t
*val
)
7963 return ((u64
)val
->high
<< 32) | ((u64
)val
->low
);
7966 static unsigned long calc_crc_errors(struct tg3
*tp
)
7968 struct tg3_hw_stats
*hw_stats
= tp
->hw_stats
;
7970 if (!(tp
->tg3_flags2
& TG3_FLG2_PHY_SERDES
) &&
7971 (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5700
||
7972 GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5701
)) {
7975 spin_lock_bh(&tp
->lock
);
7976 if (!tg3_readphy(tp
, MII_TG3_TEST1
, &val
)) {
7977 tg3_writephy(tp
, MII_TG3_TEST1
,
7978 val
| MII_TG3_TEST1_CRC_EN
);
7979 tg3_readphy(tp
, 0x14, &val
);
7982 spin_unlock_bh(&tp
->lock
);
7984 tp
->phy_crc_errors
+= val
;
7986 return tp
->phy_crc_errors
;
7989 return get_stat64(&hw_stats
->rx_fcs_errors
);
7992 #define ESTAT_ADD(member) \
7993 estats->member = old_estats->member + \
7994 get_estat64(&hw_stats->member)
7996 static struct tg3_ethtool_stats
*tg3_get_estats(struct tg3
*tp
)
7998 struct tg3_ethtool_stats
*estats
= &tp
->estats
;
7999 struct tg3_ethtool_stats
*old_estats
= &tp
->estats_prev
;
8000 struct tg3_hw_stats
*hw_stats
= tp
->hw_stats
;
8005 ESTAT_ADD(rx_octets
);
8006 ESTAT_ADD(rx_fragments
);
8007 ESTAT_ADD(rx_ucast_packets
);
8008 ESTAT_ADD(rx_mcast_packets
);
8009 ESTAT_ADD(rx_bcast_packets
);
8010 ESTAT_ADD(rx_fcs_errors
);
8011 ESTAT_ADD(rx_align_errors
);
8012 ESTAT_ADD(rx_xon_pause_rcvd
);
8013 ESTAT_ADD(rx_xoff_pause_rcvd
);
8014 ESTAT_ADD(rx_mac_ctrl_rcvd
);
8015 ESTAT_ADD(rx_xoff_entered
);
8016 ESTAT_ADD(rx_frame_too_long_errors
);
8017 ESTAT_ADD(rx_jabbers
);
8018 ESTAT_ADD(rx_undersize_packets
);
8019 ESTAT_ADD(rx_in_length_errors
);
8020 ESTAT_ADD(rx_out_length_errors
);
8021 ESTAT_ADD(rx_64_or_less_octet_packets
);
8022 ESTAT_ADD(rx_65_to_127_octet_packets
);
8023 ESTAT_ADD(rx_128_to_255_octet_packets
);
8024 ESTAT_ADD(rx_256_to_511_octet_packets
);
8025 ESTAT_ADD(rx_512_to_1023_octet_packets
);
8026 ESTAT_ADD(rx_1024_to_1522_octet_packets
);
8027 ESTAT_ADD(rx_1523_to_2047_octet_packets
);
8028 ESTAT_ADD(rx_2048_to_4095_octet_packets
);
8029 ESTAT_ADD(rx_4096_to_8191_octet_packets
);
8030 ESTAT_ADD(rx_8192_to_9022_octet_packets
);
8032 ESTAT_ADD(tx_octets
);
8033 ESTAT_ADD(tx_collisions
);
8034 ESTAT_ADD(tx_xon_sent
);
8035 ESTAT_ADD(tx_xoff_sent
);
8036 ESTAT_ADD(tx_flow_control
);
8037 ESTAT_ADD(tx_mac_errors
);
8038 ESTAT_ADD(tx_single_collisions
);
8039 ESTAT_ADD(tx_mult_collisions
);
8040 ESTAT_ADD(tx_deferred
);
8041 ESTAT_ADD(tx_excessive_collisions
);
8042 ESTAT_ADD(tx_late_collisions
);
8043 ESTAT_ADD(tx_collide_2times
);
8044 ESTAT_ADD(tx_collide_3times
);
8045 ESTAT_ADD(tx_collide_4times
);
8046 ESTAT_ADD(tx_collide_5times
);
8047 ESTAT_ADD(tx_collide_6times
);
8048 ESTAT_ADD(tx_collide_7times
);
8049 ESTAT_ADD(tx_collide_8times
);
8050 ESTAT_ADD(tx_collide_9times
);
8051 ESTAT_ADD(tx_collide_10times
);
8052 ESTAT_ADD(tx_collide_11times
);
8053 ESTAT_ADD(tx_collide_12times
);
8054 ESTAT_ADD(tx_collide_13times
);
8055 ESTAT_ADD(tx_collide_14times
);
8056 ESTAT_ADD(tx_collide_15times
);
8057 ESTAT_ADD(tx_ucast_packets
);
8058 ESTAT_ADD(tx_mcast_packets
);
8059 ESTAT_ADD(tx_bcast_packets
);
8060 ESTAT_ADD(tx_carrier_sense_errors
);
8061 ESTAT_ADD(tx_discards
);
8062 ESTAT_ADD(tx_errors
);
8064 ESTAT_ADD(dma_writeq_full
);
8065 ESTAT_ADD(dma_write_prioq_full
);
8066 ESTAT_ADD(rxbds_empty
);
8067 ESTAT_ADD(rx_discards
);
8068 ESTAT_ADD(rx_errors
);
8069 ESTAT_ADD(rx_threshold_hit
);
8071 ESTAT_ADD(dma_readq_full
);
8072 ESTAT_ADD(dma_read_prioq_full
);
8073 ESTAT_ADD(tx_comp_queue_full
);
8075 ESTAT_ADD(ring_set_send_prod_index
);
8076 ESTAT_ADD(ring_status_update
);
8077 ESTAT_ADD(nic_irqs
);
8078 ESTAT_ADD(nic_avoided_irqs
);
8079 ESTAT_ADD(nic_tx_threshold_hit
);
8084 static struct net_device_stats
*tg3_get_stats(struct net_device
*dev
)
8086 struct tg3
*tp
= netdev_priv(dev
);
8087 struct net_device_stats
*stats
= &tp
->net_stats
;
8088 struct net_device_stats
*old_stats
= &tp
->net_stats_prev
;
8089 struct tg3_hw_stats
*hw_stats
= tp
->hw_stats
;
8094 stats
->rx_packets
= old_stats
->rx_packets
+
8095 get_stat64(&hw_stats
->rx_ucast_packets
) +
8096 get_stat64(&hw_stats
->rx_mcast_packets
) +
8097 get_stat64(&hw_stats
->rx_bcast_packets
);
8099 stats
->tx_packets
= old_stats
->tx_packets
+
8100 get_stat64(&hw_stats
->tx_ucast_packets
) +
8101 get_stat64(&hw_stats
->tx_mcast_packets
) +
8102 get_stat64(&hw_stats
->tx_bcast_packets
);
8104 stats
->rx_bytes
= old_stats
->rx_bytes
+
8105 get_stat64(&hw_stats
->rx_octets
);
8106 stats
->tx_bytes
= old_stats
->tx_bytes
+
8107 get_stat64(&hw_stats
->tx_octets
);
8109 stats
->rx_errors
= old_stats
->rx_errors
+
8110 get_stat64(&hw_stats
->rx_errors
);
8111 stats
->tx_errors
= old_stats
->tx_errors
+
8112 get_stat64(&hw_stats
->tx_errors
) +
8113 get_stat64(&hw_stats
->tx_mac_errors
) +
8114 get_stat64(&hw_stats
->tx_carrier_sense_errors
) +
8115 get_stat64(&hw_stats
->tx_discards
);
8117 stats
->multicast
= old_stats
->multicast
+
8118 get_stat64(&hw_stats
->rx_mcast_packets
);
8119 stats
->collisions
= old_stats
->collisions
+
8120 get_stat64(&hw_stats
->tx_collisions
);
8122 stats
->rx_length_errors
= old_stats
->rx_length_errors
+
8123 get_stat64(&hw_stats
->rx_frame_too_long_errors
) +
8124 get_stat64(&hw_stats
->rx_undersize_packets
);
8126 stats
->rx_over_errors
= old_stats
->rx_over_errors
+
8127 get_stat64(&hw_stats
->rxbds_empty
);
8128 stats
->rx_frame_errors
= old_stats
->rx_frame_errors
+
8129 get_stat64(&hw_stats
->rx_align_errors
);
8130 stats
->tx_aborted_errors
= old_stats
->tx_aborted_errors
+
8131 get_stat64(&hw_stats
->tx_discards
);
8132 stats
->tx_carrier_errors
= old_stats
->tx_carrier_errors
+
8133 get_stat64(&hw_stats
->tx_carrier_sense_errors
);
8135 stats
->rx_crc_errors
= old_stats
->rx_crc_errors
+
8136 calc_crc_errors(tp
);
8138 stats
->rx_missed_errors
= old_stats
->rx_missed_errors
+
8139 get_stat64(&hw_stats
->rx_discards
);
8144 static inline u32
calc_crc(unsigned char *buf
, int len
)
8152 for (j
= 0; j
< len
; j
++) {
8155 for (k
= 0; k
< 8; k
++) {
8169 static void tg3_set_multi(struct tg3
*tp
, unsigned int accept_all
)
8171 /* accept or reject all multicast frames */
8172 tw32(MAC_HASH_REG_0
, accept_all
? 0xffffffff : 0);
8173 tw32(MAC_HASH_REG_1
, accept_all
? 0xffffffff : 0);
8174 tw32(MAC_HASH_REG_2
, accept_all
? 0xffffffff : 0);
8175 tw32(MAC_HASH_REG_3
, accept_all
? 0xffffffff : 0);
8178 static void __tg3_set_rx_mode(struct net_device
*dev
)
8180 struct tg3
*tp
= netdev_priv(dev
);
8183 rx_mode
= tp
->rx_mode
& ~(RX_MODE_PROMISC
|
8184 RX_MODE_KEEP_VLAN_TAG
);
8186 /* When ASF is in use, we always keep the RX_MODE_KEEP_VLAN_TAG
8189 #if TG3_VLAN_TAG_USED
8191 !(tp
->tg3_flags
& TG3_FLAG_ENABLE_ASF
))
8192 rx_mode
|= RX_MODE_KEEP_VLAN_TAG
;
8194 /* By definition, VLAN is disabled always in this
8197 if (!(tp
->tg3_flags
& TG3_FLAG_ENABLE_ASF
))
8198 rx_mode
|= RX_MODE_KEEP_VLAN_TAG
;
8201 if (dev
->flags
& IFF_PROMISC
) {
8202 /* Promiscuous mode. */
8203 rx_mode
|= RX_MODE_PROMISC
;
8204 } else if (dev
->flags
& IFF_ALLMULTI
) {
8205 /* Accept all multicast. */
8206 tg3_set_multi (tp
, 1);
8207 } else if (dev
->mc_count
< 1) {
8208 /* Reject all multicast. */
8209 tg3_set_multi (tp
, 0);
8211 /* Accept one or more multicast(s). */
8212 struct dev_mc_list
*mclist
;
8214 u32 mc_filter
[4] = { 0, };
8219 for (i
= 0, mclist
= dev
->mc_list
; mclist
&& i
< dev
->mc_count
;
8220 i
++, mclist
= mclist
->next
) {
8222 crc
= calc_crc (mclist
->dmi_addr
, ETH_ALEN
);
8224 regidx
= (bit
& 0x60) >> 5;
8226 mc_filter
[regidx
] |= (1 << bit
);
8229 tw32(MAC_HASH_REG_0
, mc_filter
[0]);
8230 tw32(MAC_HASH_REG_1
, mc_filter
[1]);
8231 tw32(MAC_HASH_REG_2
, mc_filter
[2]);
8232 tw32(MAC_HASH_REG_3
, mc_filter
[3]);
8235 if (rx_mode
!= tp
->rx_mode
) {
8236 tp
->rx_mode
= rx_mode
;
8237 tw32_f(MAC_RX_MODE
, rx_mode
);
8242 static void tg3_set_rx_mode(struct net_device
*dev
)
8244 struct tg3
*tp
= netdev_priv(dev
);
8246 if (!netif_running(dev
))
8249 tg3_full_lock(tp
, 0);
8250 __tg3_set_rx_mode(dev
);
8251 tg3_full_unlock(tp
);
8254 #define TG3_REGDUMP_LEN (32 * 1024)
8256 static int tg3_get_regs_len(struct net_device
*dev
)
8258 return TG3_REGDUMP_LEN
;
8261 static void tg3_get_regs(struct net_device
*dev
,
8262 struct ethtool_regs
*regs
, void *_p
)
8265 struct tg3
*tp
= netdev_priv(dev
);
8271 memset(p
, 0, TG3_REGDUMP_LEN
);
8273 if (tp
->link_config
.phy_is_low_power
)
8276 tg3_full_lock(tp
, 0);
8278 #define __GET_REG32(reg) (*(p)++ = tr32(reg))
8279 #define GET_REG32_LOOP(base,len) \
8280 do { p = (u32 *)(orig_p + (base)); \
8281 for (i = 0; i < len; i += 4) \
8282 __GET_REG32((base) + i); \
8284 #define GET_REG32_1(reg) \
8285 do { p = (u32 *)(orig_p + (reg)); \
8286 __GET_REG32((reg)); \
8289 GET_REG32_LOOP(TG3PCI_VENDOR
, 0xb0);
8290 GET_REG32_LOOP(MAILBOX_INTERRUPT_0
, 0x200);
8291 GET_REG32_LOOP(MAC_MODE
, 0x4f0);
8292 GET_REG32_LOOP(SNDDATAI_MODE
, 0xe0);
8293 GET_REG32_1(SNDDATAC_MODE
);
8294 GET_REG32_LOOP(SNDBDS_MODE
, 0x80);
8295 GET_REG32_LOOP(SNDBDI_MODE
, 0x48);
8296 GET_REG32_1(SNDBDC_MODE
);
8297 GET_REG32_LOOP(RCVLPC_MODE
, 0x20);
8298 GET_REG32_LOOP(RCVLPC_SELLST_BASE
, 0x15c);
8299 GET_REG32_LOOP(RCVDBDI_MODE
, 0x0c);
8300 GET_REG32_LOOP(RCVDBDI_JUMBO_BD
, 0x3c);
8301 GET_REG32_LOOP(RCVDBDI_BD_PROD_IDX_0
, 0x44);
8302 GET_REG32_1(RCVDCC_MODE
);
8303 GET_REG32_LOOP(RCVBDI_MODE
, 0x20);
8304 GET_REG32_LOOP(RCVCC_MODE
, 0x14);
8305 GET_REG32_LOOP(RCVLSC_MODE
, 0x08);
8306 GET_REG32_1(MBFREE_MODE
);
8307 GET_REG32_LOOP(HOSTCC_MODE
, 0x100);
8308 GET_REG32_LOOP(MEMARB_MODE
, 0x10);
8309 GET_REG32_LOOP(BUFMGR_MODE
, 0x58);
8310 GET_REG32_LOOP(RDMAC_MODE
, 0x08);
8311 GET_REG32_LOOP(WDMAC_MODE
, 0x08);
8312 GET_REG32_1(RX_CPU_MODE
);
8313 GET_REG32_1(RX_CPU_STATE
);
8314 GET_REG32_1(RX_CPU_PGMCTR
);
8315 GET_REG32_1(RX_CPU_HWBKPT
);
8316 GET_REG32_1(TX_CPU_MODE
);
8317 GET_REG32_1(TX_CPU_STATE
);
8318 GET_REG32_1(TX_CPU_PGMCTR
);
8319 GET_REG32_LOOP(GRCMBOX_INTERRUPT_0
, 0x110);
8320 GET_REG32_LOOP(FTQ_RESET
, 0x120);
8321 GET_REG32_LOOP(MSGINT_MODE
, 0x0c);
8322 GET_REG32_1(DMAC_MODE
);
8323 GET_REG32_LOOP(GRC_MODE
, 0x4c);
8324 if (tp
->tg3_flags
& TG3_FLAG_NVRAM
)
8325 GET_REG32_LOOP(NVRAM_CMD
, 0x24);
8328 #undef GET_REG32_LOOP
8331 tg3_full_unlock(tp
);
8334 static int tg3_get_eeprom_len(struct net_device
*dev
)
8336 struct tg3
*tp
= netdev_priv(dev
);
8338 return tp
->nvram_size
;
8341 static int tg3_nvram_read(struct tg3
*tp
, u32 offset
, u32
*val
);
8342 static int tg3_nvram_read_le(struct tg3
*tp
, u32 offset
, __le32
*val
);
8343 static int tg3_nvram_read_swab(struct tg3
*tp
, u32 offset
, u32
*val
);
8345 static int tg3_get_eeprom(struct net_device
*dev
, struct ethtool_eeprom
*eeprom
, u8
*data
)
8347 struct tg3
*tp
= netdev_priv(dev
);
8350 u32 i
, offset
, len
, b_offset
, b_count
;
8353 if (tp
->link_config
.phy_is_low_power
)
8356 offset
= eeprom
->offset
;
8360 eeprom
->magic
= TG3_EEPROM_MAGIC
;
8363 /* adjustments to start on required 4 byte boundary */
8364 b_offset
= offset
& 3;
8365 b_count
= 4 - b_offset
;
8366 if (b_count
> len
) {
8367 /* i.e. offset=1 len=2 */
8370 ret
= tg3_nvram_read_le(tp
, offset
-b_offset
, &val
);
8373 memcpy(data
, ((char*)&val
) + b_offset
, b_count
);
8376 eeprom
->len
+= b_count
;
8379 /* read bytes upto the last 4 byte boundary */
8380 pd
= &data
[eeprom
->len
];
8381 for (i
= 0; i
< (len
- (len
& 3)); i
+= 4) {
8382 ret
= tg3_nvram_read_le(tp
, offset
+ i
, &val
);
8387 memcpy(pd
+ i
, &val
, 4);
8392 /* read last bytes not ending on 4 byte boundary */
8393 pd
= &data
[eeprom
->len
];
8395 b_offset
= offset
+ len
- b_count
;
8396 ret
= tg3_nvram_read_le(tp
, b_offset
, &val
);
8399 memcpy(pd
, &val
, b_count
);
8400 eeprom
->len
+= b_count
;
8405 static int tg3_nvram_write_block(struct tg3
*tp
, u32 offset
, u32 len
, u8
*buf
);
8407 static int tg3_set_eeprom(struct net_device
*dev
, struct ethtool_eeprom
*eeprom
, u8
*data
)
8409 struct tg3
*tp
= netdev_priv(dev
);
8411 u32 offset
, len
, b_offset
, odd_len
;
8415 if (tp
->link_config
.phy_is_low_power
)
8418 if (eeprom
->magic
!= TG3_EEPROM_MAGIC
)
8421 offset
= eeprom
->offset
;
8424 if ((b_offset
= (offset
& 3))) {
8425 /* adjustments to start on required 4 byte boundary */
8426 ret
= tg3_nvram_read_le(tp
, offset
-b_offset
, &start
);
8437 /* adjustments to end on required 4 byte boundary */
8439 len
= (len
+ 3) & ~3;
8440 ret
= tg3_nvram_read_le(tp
, offset
+len
-4, &end
);
8446 if (b_offset
|| odd_len
) {
8447 buf
= kmalloc(len
, GFP_KERNEL
);
8451 memcpy(buf
, &start
, 4);
8453 memcpy(buf
+len
-4, &end
, 4);
8454 memcpy(buf
+ b_offset
, data
, eeprom
->len
);
8457 ret
= tg3_nvram_write_block(tp
, offset
, len
, buf
);
8465 static int tg3_get_settings(struct net_device
*dev
, struct ethtool_cmd
*cmd
)
8467 struct tg3
*tp
= netdev_priv(dev
);
8469 if (tp
->tg3_flags3
& TG3_FLG3_USE_PHYLIB
) {
8470 if (!(tp
->tg3_flags3
& TG3_FLG3_PHY_CONNECTED
))
8472 return phy_ethtool_gset(tp
->mdio_bus
->phy_map
[PHY_ADDR
], cmd
);
8475 cmd
->supported
= (SUPPORTED_Autoneg
);
8477 if (!(tp
->tg3_flags
& TG3_FLAG_10_100_ONLY
))
8478 cmd
->supported
|= (SUPPORTED_1000baseT_Half
|
8479 SUPPORTED_1000baseT_Full
);
8481 if (!(tp
->tg3_flags2
& TG3_FLG2_ANY_SERDES
)) {
8482 cmd
->supported
|= (SUPPORTED_100baseT_Half
|
8483 SUPPORTED_100baseT_Full
|
8484 SUPPORTED_10baseT_Half
|
8485 SUPPORTED_10baseT_Full
|
8487 cmd
->port
= PORT_TP
;
8489 cmd
->supported
|= SUPPORTED_FIBRE
;
8490 cmd
->port
= PORT_FIBRE
;
8493 cmd
->advertising
= tp
->link_config
.advertising
;
8494 if (netif_running(dev
)) {
8495 cmd
->speed
= tp
->link_config
.active_speed
;
8496 cmd
->duplex
= tp
->link_config
.active_duplex
;
8498 cmd
->phy_address
= PHY_ADDR
;
8499 cmd
->transceiver
= 0;
8500 cmd
->autoneg
= tp
->link_config
.autoneg
;
8506 static int tg3_set_settings(struct net_device
*dev
, struct ethtool_cmd
*cmd
)
8508 struct tg3
*tp
= netdev_priv(dev
);
8510 if (tp
->tg3_flags3
& TG3_FLG3_USE_PHYLIB
) {
8511 if (!(tp
->tg3_flags3
& TG3_FLG3_PHY_CONNECTED
))
8513 return phy_ethtool_sset(tp
->mdio_bus
->phy_map
[PHY_ADDR
], cmd
);
8516 if (tp
->tg3_flags2
& TG3_FLG2_ANY_SERDES
) {
8517 /* These are the only valid advertisement bits allowed. */
8518 if (cmd
->autoneg
== AUTONEG_ENABLE
&&
8519 (cmd
->advertising
& ~(ADVERTISED_1000baseT_Half
|
8520 ADVERTISED_1000baseT_Full
|
8521 ADVERTISED_Autoneg
|
8524 /* Fiber can only do SPEED_1000. */
8525 else if ((cmd
->autoneg
!= AUTONEG_ENABLE
) &&
8526 (cmd
->speed
!= SPEED_1000
))
8528 /* Copper cannot force SPEED_1000. */
8529 } else if ((cmd
->autoneg
!= AUTONEG_ENABLE
) &&
8530 (cmd
->speed
== SPEED_1000
))
8532 else if ((cmd
->speed
== SPEED_1000
) &&
8533 (tp
->tg3_flags
& TG3_FLAG_10_100_ONLY
))
8536 tg3_full_lock(tp
, 0);
8538 tp
->link_config
.autoneg
= cmd
->autoneg
;
8539 if (cmd
->autoneg
== AUTONEG_ENABLE
) {
8540 tp
->link_config
.advertising
= (cmd
->advertising
|
8541 ADVERTISED_Autoneg
);
8542 tp
->link_config
.speed
= SPEED_INVALID
;
8543 tp
->link_config
.duplex
= DUPLEX_INVALID
;
8545 tp
->link_config
.advertising
= 0;
8546 tp
->link_config
.speed
= cmd
->speed
;
8547 tp
->link_config
.duplex
= cmd
->duplex
;
8550 tp
->link_config
.orig_speed
= tp
->link_config
.speed
;
8551 tp
->link_config
.orig_duplex
= tp
->link_config
.duplex
;
8552 tp
->link_config
.orig_autoneg
= tp
->link_config
.autoneg
;
8554 if (netif_running(dev
))
8555 tg3_setup_phy(tp
, 1);
8557 tg3_full_unlock(tp
);
8562 static void tg3_get_drvinfo(struct net_device
*dev
, struct ethtool_drvinfo
*info
)
8564 struct tg3
*tp
= netdev_priv(dev
);
8566 strcpy(info
->driver
, DRV_MODULE_NAME
);
8567 strcpy(info
->version
, DRV_MODULE_VERSION
);
8568 strcpy(info
->fw_version
, tp
->fw_ver
);
8569 strcpy(info
->bus_info
, pci_name(tp
->pdev
));
8572 static void tg3_get_wol(struct net_device
*dev
, struct ethtool_wolinfo
*wol
)
8574 struct tg3
*tp
= netdev_priv(dev
);
8576 if ((tp
->tg3_flags
& TG3_FLAG_WOL_CAP
) &&
8577 device_can_wakeup(&tp
->pdev
->dev
))
8578 wol
->supported
= WAKE_MAGIC
;
8582 if ((tp
->tg3_flags
& TG3_FLAG_WOL_ENABLE
) &&
8583 device_can_wakeup(&tp
->pdev
->dev
))
8584 wol
->wolopts
= WAKE_MAGIC
;
8585 memset(&wol
->sopass
, 0, sizeof(wol
->sopass
));
8588 static int tg3_set_wol(struct net_device
*dev
, struct ethtool_wolinfo
*wol
)
8590 struct tg3
*tp
= netdev_priv(dev
);
8591 struct device
*dp
= &tp
->pdev
->dev
;
8593 if (wol
->wolopts
& ~WAKE_MAGIC
)
8595 if ((wol
->wolopts
& WAKE_MAGIC
) &&
8596 !((tp
->tg3_flags
& TG3_FLAG_WOL_CAP
) && device_can_wakeup(dp
)))
8599 spin_lock_bh(&tp
->lock
);
8600 if (wol
->wolopts
& WAKE_MAGIC
) {
8601 tp
->tg3_flags
|= TG3_FLAG_WOL_ENABLE
;
8602 device_set_wakeup_enable(dp
, true);
8604 tp
->tg3_flags
&= ~TG3_FLAG_WOL_ENABLE
;
8605 device_set_wakeup_enable(dp
, false);
8607 spin_unlock_bh(&tp
->lock
);
8612 static u32
tg3_get_msglevel(struct net_device
*dev
)
8614 struct tg3
*tp
= netdev_priv(dev
);
8615 return tp
->msg_enable
;
8618 static void tg3_set_msglevel(struct net_device
*dev
, u32 value
)
8620 struct tg3
*tp
= netdev_priv(dev
);
8621 tp
->msg_enable
= value
;
8624 static int tg3_set_tso(struct net_device
*dev
, u32 value
)
8626 struct tg3
*tp
= netdev_priv(dev
);
8628 if (!(tp
->tg3_flags2
& TG3_FLG2_TSO_CAPABLE
)) {
8633 if ((dev
->features
& NETIF_F_IPV6_CSUM
) &&
8634 (tp
->tg3_flags2
& TG3_FLG2_HW_TSO_2
)) {
8636 dev
->features
|= NETIF_F_TSO6
;
8637 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5761
||
8638 (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5784
&&
8639 GET_CHIP_REV(tp
->pci_chip_rev_id
) != CHIPREV_5784_AX
) ||
8640 GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5785
||
8641 GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_57780
)
8642 dev
->features
|= NETIF_F_TSO_ECN
;
8644 dev
->features
&= ~(NETIF_F_TSO6
| NETIF_F_TSO_ECN
);
8646 return ethtool_op_set_tso(dev
, value
);
8649 static int tg3_nway_reset(struct net_device
*dev
)
8651 struct tg3
*tp
= netdev_priv(dev
);
8654 if (!netif_running(dev
))
8657 if (tp
->tg3_flags2
& TG3_FLG2_PHY_SERDES
)
8660 if (tp
->tg3_flags3
& TG3_FLG3_USE_PHYLIB
) {
8661 if (!(tp
->tg3_flags3
& TG3_FLG3_PHY_CONNECTED
))
8663 r
= phy_start_aneg(tp
->mdio_bus
->phy_map
[PHY_ADDR
]);
8667 spin_lock_bh(&tp
->lock
);
8669 tg3_readphy(tp
, MII_BMCR
, &bmcr
);
8670 if (!tg3_readphy(tp
, MII_BMCR
, &bmcr
) &&
8671 ((bmcr
& BMCR_ANENABLE
) ||
8672 (tp
->tg3_flags2
& TG3_FLG2_PARALLEL_DETECT
))) {
8673 tg3_writephy(tp
, MII_BMCR
, bmcr
| BMCR_ANRESTART
|
8677 spin_unlock_bh(&tp
->lock
);
8683 static void tg3_get_ringparam(struct net_device
*dev
, struct ethtool_ringparam
*ering
)
8685 struct tg3
*tp
= netdev_priv(dev
);
8687 ering
->rx_max_pending
= TG3_RX_RING_SIZE
- 1;
8688 ering
->rx_mini_max_pending
= 0;
8689 if (tp
->tg3_flags
& TG3_FLAG_JUMBO_RING_ENABLE
)
8690 ering
->rx_jumbo_max_pending
= TG3_RX_JUMBO_RING_SIZE
- 1;
8692 ering
->rx_jumbo_max_pending
= 0;
8694 ering
->tx_max_pending
= TG3_TX_RING_SIZE
- 1;
8696 ering
->rx_pending
= tp
->rx_pending
;
8697 ering
->rx_mini_pending
= 0;
8698 if (tp
->tg3_flags
& TG3_FLAG_JUMBO_RING_ENABLE
)
8699 ering
->rx_jumbo_pending
= tp
->rx_jumbo_pending
;
8701 ering
->rx_jumbo_pending
= 0;
8703 ering
->tx_pending
= tp
->tx_pending
;
8706 static int tg3_set_ringparam(struct net_device
*dev
, struct ethtool_ringparam
*ering
)
8708 struct tg3
*tp
= netdev_priv(dev
);
8709 int irq_sync
= 0, err
= 0;
8711 if ((ering
->rx_pending
> TG3_RX_RING_SIZE
- 1) ||
8712 (ering
->rx_jumbo_pending
> TG3_RX_JUMBO_RING_SIZE
- 1) ||
8713 (ering
->tx_pending
> TG3_TX_RING_SIZE
- 1) ||
8714 (ering
->tx_pending
<= MAX_SKB_FRAGS
) ||
8715 ((tp
->tg3_flags2
& TG3_FLG2_TSO_BUG
) &&
8716 (ering
->tx_pending
<= (MAX_SKB_FRAGS
* 3))))
8719 if (netif_running(dev
)) {
8725 tg3_full_lock(tp
, irq_sync
);
8727 tp
->rx_pending
= ering
->rx_pending
;
8729 if ((tp
->tg3_flags2
& TG3_FLG2_MAX_RXPEND_64
) &&
8730 tp
->rx_pending
> 63)
8731 tp
->rx_pending
= 63;
8732 tp
->rx_jumbo_pending
= ering
->rx_jumbo_pending
;
8733 tp
->tx_pending
= ering
->tx_pending
;
8735 if (netif_running(dev
)) {
8736 tg3_halt(tp
, RESET_KIND_SHUTDOWN
, 1);
8737 err
= tg3_restart_hw(tp
, 1);
8739 tg3_netif_start(tp
);
8742 tg3_full_unlock(tp
);
8744 if (irq_sync
&& !err
)
8750 static void tg3_get_pauseparam(struct net_device
*dev
, struct ethtool_pauseparam
*epause
)
8752 struct tg3
*tp
= netdev_priv(dev
);
8754 epause
->autoneg
= (tp
->tg3_flags
& TG3_FLAG_PAUSE_AUTONEG
) != 0;
8756 if (tp
->link_config
.active_flowctrl
& FLOW_CTRL_RX
)
8757 epause
->rx_pause
= 1;
8759 epause
->rx_pause
= 0;
8761 if (tp
->link_config
.active_flowctrl
& FLOW_CTRL_TX
)
8762 epause
->tx_pause
= 1;
8764 epause
->tx_pause
= 0;
8767 static int tg3_set_pauseparam(struct net_device
*dev
, struct ethtool_pauseparam
*epause
)
8769 struct tg3
*tp
= netdev_priv(dev
);
8772 if (tp
->tg3_flags3
& TG3_FLG3_USE_PHYLIB
) {
8773 if (!(tp
->tg3_flags3
& TG3_FLG3_PHY_CONNECTED
))
8776 if (epause
->autoneg
) {
8778 struct phy_device
*phydev
;
8780 phydev
= tp
->mdio_bus
->phy_map
[PHY_ADDR
];
8782 if (epause
->rx_pause
) {
8783 if (epause
->tx_pause
)
8784 newadv
= ADVERTISED_Pause
;
8786 newadv
= ADVERTISED_Pause
|
8787 ADVERTISED_Asym_Pause
;
8788 } else if (epause
->tx_pause
) {
8789 newadv
= ADVERTISED_Asym_Pause
;
8793 if (tp
->tg3_flags3
& TG3_FLG3_PHY_CONNECTED
) {
8794 u32 oldadv
= phydev
->advertising
&
8796 ADVERTISED_Asym_Pause
);
8797 if (oldadv
!= newadv
) {
8798 phydev
->advertising
&=
8799 ~(ADVERTISED_Pause
|
8800 ADVERTISED_Asym_Pause
);
8801 phydev
->advertising
|= newadv
;
8802 err
= phy_start_aneg(phydev
);
8805 tp
->link_config
.advertising
&=
8806 ~(ADVERTISED_Pause
|
8807 ADVERTISED_Asym_Pause
);
8808 tp
->link_config
.advertising
|= newadv
;
8811 if (epause
->rx_pause
)
8812 tp
->link_config
.flowctrl
|= FLOW_CTRL_RX
;
8814 tp
->link_config
.flowctrl
&= ~FLOW_CTRL_RX
;
8816 if (epause
->tx_pause
)
8817 tp
->link_config
.flowctrl
|= FLOW_CTRL_TX
;
8819 tp
->link_config
.flowctrl
&= ~FLOW_CTRL_TX
;
8821 if (netif_running(dev
))
8822 tg3_setup_flow_control(tp
, 0, 0);
8827 if (netif_running(dev
)) {
8832 tg3_full_lock(tp
, irq_sync
);
8834 if (epause
->autoneg
)
8835 tp
->tg3_flags
|= TG3_FLAG_PAUSE_AUTONEG
;
8837 tp
->tg3_flags
&= ~TG3_FLAG_PAUSE_AUTONEG
;
8838 if (epause
->rx_pause
)
8839 tp
->link_config
.flowctrl
|= FLOW_CTRL_RX
;
8841 tp
->link_config
.flowctrl
&= ~FLOW_CTRL_RX
;
8842 if (epause
->tx_pause
)
8843 tp
->link_config
.flowctrl
|= FLOW_CTRL_TX
;
8845 tp
->link_config
.flowctrl
&= ~FLOW_CTRL_TX
;
8847 if (netif_running(dev
)) {
8848 tg3_halt(tp
, RESET_KIND_SHUTDOWN
, 1);
8849 err
= tg3_restart_hw(tp
, 1);
8851 tg3_netif_start(tp
);
8854 tg3_full_unlock(tp
);
8860 static u32
tg3_get_rx_csum(struct net_device
*dev
)
8862 struct tg3
*tp
= netdev_priv(dev
);
8863 return (tp
->tg3_flags
& TG3_FLAG_RX_CHECKSUMS
) != 0;
8866 static int tg3_set_rx_csum(struct net_device
*dev
, u32 data
)
8868 struct tg3
*tp
= netdev_priv(dev
);
8870 if (tp
->tg3_flags
& TG3_FLAG_BROKEN_CHECKSUMS
) {
8876 spin_lock_bh(&tp
->lock
);
8878 tp
->tg3_flags
|= TG3_FLAG_RX_CHECKSUMS
;
8880 tp
->tg3_flags
&= ~TG3_FLAG_RX_CHECKSUMS
;
8881 spin_unlock_bh(&tp
->lock
);
8886 static int tg3_set_tx_csum(struct net_device
*dev
, u32 data
)
8888 struct tg3
*tp
= netdev_priv(dev
);
8890 if (tp
->tg3_flags
& TG3_FLAG_BROKEN_CHECKSUMS
) {
8896 if (tp
->tg3_flags3
& TG3_FLG3_5755_PLUS
)
8897 ethtool_op_set_tx_ipv6_csum(dev
, data
);
8899 ethtool_op_set_tx_csum(dev
, data
);
8904 static int tg3_get_sset_count (struct net_device
*dev
, int sset
)
8908 return TG3_NUM_TEST
;
8910 return TG3_NUM_STATS
;
8916 static void tg3_get_strings (struct net_device
*dev
, u32 stringset
, u8
*buf
)
8918 switch (stringset
) {
8920 memcpy(buf
, ðtool_stats_keys
, sizeof(ethtool_stats_keys
));
8923 memcpy(buf
, ðtool_test_keys
, sizeof(ethtool_test_keys
));
8926 WARN_ON(1); /* we need a WARN() */
8931 static int tg3_phys_id(struct net_device
*dev
, u32 data
)
8933 struct tg3
*tp
= netdev_priv(dev
);
8936 if (!netif_running(tp
->dev
))
8940 data
= UINT_MAX
/ 2;
8942 for (i
= 0; i
< (data
* 2); i
++) {
8944 tw32(MAC_LED_CTRL
, LED_CTRL_LNKLED_OVERRIDE
|
8945 LED_CTRL_1000MBPS_ON
|
8946 LED_CTRL_100MBPS_ON
|
8947 LED_CTRL_10MBPS_ON
|
8948 LED_CTRL_TRAFFIC_OVERRIDE
|
8949 LED_CTRL_TRAFFIC_BLINK
|
8950 LED_CTRL_TRAFFIC_LED
);
8953 tw32(MAC_LED_CTRL
, LED_CTRL_LNKLED_OVERRIDE
|
8954 LED_CTRL_TRAFFIC_OVERRIDE
);
8956 if (msleep_interruptible(500))
8959 tw32(MAC_LED_CTRL
, tp
->led_ctrl
);
8963 static void tg3_get_ethtool_stats (struct net_device
*dev
,
8964 struct ethtool_stats
*estats
, u64
*tmp_stats
)
8966 struct tg3
*tp
= netdev_priv(dev
);
8967 memcpy(tmp_stats
, tg3_get_estats(tp
), sizeof(tp
->estats
));
8970 #define NVRAM_TEST_SIZE 0x100
8971 #define NVRAM_SELFBOOT_FORMAT1_0_SIZE 0x14
8972 #define NVRAM_SELFBOOT_FORMAT1_2_SIZE 0x18
8973 #define NVRAM_SELFBOOT_FORMAT1_3_SIZE 0x1c
8974 #define NVRAM_SELFBOOT_HW_SIZE 0x20
8975 #define NVRAM_SELFBOOT_DATA_SIZE 0x1c
8977 static int tg3_test_nvram(struct tg3
*tp
)
8981 int i
, j
, k
, err
= 0, size
;
8983 if (tg3_nvram_read_swab(tp
, 0, &magic
) != 0)
8986 if (magic
== TG3_EEPROM_MAGIC
)
8987 size
= NVRAM_TEST_SIZE
;
8988 else if ((magic
& TG3_EEPROM_MAGIC_FW_MSK
) == TG3_EEPROM_MAGIC_FW
) {
8989 if ((magic
& TG3_EEPROM_SB_FORMAT_MASK
) ==
8990 TG3_EEPROM_SB_FORMAT_1
) {
8991 switch (magic
& TG3_EEPROM_SB_REVISION_MASK
) {
8992 case TG3_EEPROM_SB_REVISION_0
:
8993 size
= NVRAM_SELFBOOT_FORMAT1_0_SIZE
;
8995 case TG3_EEPROM_SB_REVISION_2
:
8996 size
= NVRAM_SELFBOOT_FORMAT1_2_SIZE
;
8998 case TG3_EEPROM_SB_REVISION_3
:
8999 size
= NVRAM_SELFBOOT_FORMAT1_3_SIZE
;
9006 } else if ((magic
& TG3_EEPROM_MAGIC_HW_MSK
) == TG3_EEPROM_MAGIC_HW
)
9007 size
= NVRAM_SELFBOOT_HW_SIZE
;
9011 buf
= kmalloc(size
, GFP_KERNEL
);
9016 for (i
= 0, j
= 0; i
< size
; i
+= 4, j
++) {
9017 if ((err
= tg3_nvram_read_le(tp
, i
, &buf
[j
])) != 0)
9023 /* Selfboot format */
9024 magic
= swab32(le32_to_cpu(buf
[0]));
9025 if ((magic
& TG3_EEPROM_MAGIC_FW_MSK
) ==
9026 TG3_EEPROM_MAGIC_FW
) {
9027 u8
*buf8
= (u8
*) buf
, csum8
= 0;
9029 if ((magic
& TG3_EEPROM_SB_REVISION_MASK
) ==
9030 TG3_EEPROM_SB_REVISION_2
) {
9031 /* For rev 2, the csum doesn't include the MBA. */
9032 for (i
= 0; i
< TG3_EEPROM_SB_F1R2_MBA_OFF
; i
++)
9034 for (i
= TG3_EEPROM_SB_F1R2_MBA_OFF
+ 4; i
< size
; i
++)
9037 for (i
= 0; i
< size
; i
++)
9050 if ((magic
& TG3_EEPROM_MAGIC_HW_MSK
) ==
9051 TG3_EEPROM_MAGIC_HW
) {
9052 u8 data
[NVRAM_SELFBOOT_DATA_SIZE
];
9053 u8 parity
[NVRAM_SELFBOOT_DATA_SIZE
];
9054 u8
*buf8
= (u8
*) buf
;
9056 /* Separate the parity bits and the data bytes. */
9057 for (i
= 0, j
= 0, k
= 0; i
< NVRAM_SELFBOOT_HW_SIZE
; i
++) {
9058 if ((i
== 0) || (i
== 8)) {
9062 for (l
= 0, msk
= 0x80; l
< 7; l
++, msk
>>= 1)
9063 parity
[k
++] = buf8
[i
] & msk
;
9070 for (l
= 0, msk
= 0x20; l
< 6; l
++, msk
>>= 1)
9071 parity
[k
++] = buf8
[i
] & msk
;
9074 for (l
= 0, msk
= 0x80; l
< 8; l
++, msk
>>= 1)
9075 parity
[k
++] = buf8
[i
] & msk
;
9078 data
[j
++] = buf8
[i
];
9082 for (i
= 0; i
< NVRAM_SELFBOOT_DATA_SIZE
; i
++) {
9083 u8 hw8
= hweight8(data
[i
]);
9085 if ((hw8
& 0x1) && parity
[i
])
9087 else if (!(hw8
& 0x1) && !parity
[i
])
9094 /* Bootstrap checksum at offset 0x10 */
9095 csum
= calc_crc((unsigned char *) buf
, 0x10);
9096 if(csum
!= le32_to_cpu(buf
[0x10/4]))
9099 /* Manufacturing block starts at offset 0x74, checksum at 0xfc */
9100 csum
= calc_crc((unsigned char *) &buf
[0x74/4], 0x88);
9101 if (csum
!= le32_to_cpu(buf
[0xfc/4]))
9111 #define TG3_SERDES_TIMEOUT_SEC 2
9112 #define TG3_COPPER_TIMEOUT_SEC 6
9114 static int tg3_test_link(struct tg3
*tp
)
9118 if (!netif_running(tp
->dev
))
9121 if (tp
->tg3_flags2
& TG3_FLG2_ANY_SERDES
)
9122 max
= TG3_SERDES_TIMEOUT_SEC
;
9124 max
= TG3_COPPER_TIMEOUT_SEC
;
9126 for (i
= 0; i
< max
; i
++) {
9127 if (netif_carrier_ok(tp
->dev
))
9130 if (msleep_interruptible(1000))
9137 /* Only test the commonly used registers */
9138 static int tg3_test_registers(struct tg3
*tp
)
9140 int i
, is_5705
, is_5750
;
9141 u32 offset
, read_mask
, write_mask
, val
, save_val
, read_val
;
9145 #define TG3_FL_5705 0x1
9146 #define TG3_FL_NOT_5705 0x2
9147 #define TG3_FL_NOT_5788 0x4
9148 #define TG3_FL_NOT_5750 0x8
9152 /* MAC Control Registers */
9153 { MAC_MODE
, TG3_FL_NOT_5705
,
9154 0x00000000, 0x00ef6f8c },
9155 { MAC_MODE
, TG3_FL_5705
,
9156 0x00000000, 0x01ef6b8c },
9157 { MAC_STATUS
, TG3_FL_NOT_5705
,
9158 0x03800107, 0x00000000 },
9159 { MAC_STATUS
, TG3_FL_5705
,
9160 0x03800100, 0x00000000 },
9161 { MAC_ADDR_0_HIGH
, 0x0000,
9162 0x00000000, 0x0000ffff },
9163 { MAC_ADDR_0_LOW
, 0x0000,
9164 0x00000000, 0xffffffff },
9165 { MAC_RX_MTU_SIZE
, 0x0000,
9166 0x00000000, 0x0000ffff },
9167 { MAC_TX_MODE
, 0x0000,
9168 0x00000000, 0x00000070 },
9169 { MAC_TX_LENGTHS
, 0x0000,
9170 0x00000000, 0x00003fff },
9171 { MAC_RX_MODE
, TG3_FL_NOT_5705
,
9172 0x00000000, 0x000007fc },
9173 { MAC_RX_MODE
, TG3_FL_5705
,
9174 0x00000000, 0x000007dc },
9175 { MAC_HASH_REG_0
, 0x0000,
9176 0x00000000, 0xffffffff },
9177 { MAC_HASH_REG_1
, 0x0000,
9178 0x00000000, 0xffffffff },
9179 { MAC_HASH_REG_2
, 0x0000,
9180 0x00000000, 0xffffffff },
9181 { MAC_HASH_REG_3
, 0x0000,
9182 0x00000000, 0xffffffff },
9184 /* Receive Data and Receive BD Initiator Control Registers. */
9185 { RCVDBDI_JUMBO_BD
+0, TG3_FL_NOT_5705
,
9186 0x00000000, 0xffffffff },
9187 { RCVDBDI_JUMBO_BD
+4, TG3_FL_NOT_5705
,
9188 0x00000000, 0xffffffff },
9189 { RCVDBDI_JUMBO_BD
+8, TG3_FL_NOT_5705
,
9190 0x00000000, 0x00000003 },
9191 { RCVDBDI_JUMBO_BD
+0xc, TG3_FL_NOT_5705
,
9192 0x00000000, 0xffffffff },
9193 { RCVDBDI_STD_BD
+0, 0x0000,
9194 0x00000000, 0xffffffff },
9195 { RCVDBDI_STD_BD
+4, 0x0000,
9196 0x00000000, 0xffffffff },
9197 { RCVDBDI_STD_BD
+8, 0x0000,
9198 0x00000000, 0xffff0002 },
9199 { RCVDBDI_STD_BD
+0xc, 0x0000,
9200 0x00000000, 0xffffffff },
9202 /* Receive BD Initiator Control Registers. */
9203 { RCVBDI_STD_THRESH
, TG3_FL_NOT_5705
,
9204 0x00000000, 0xffffffff },
9205 { RCVBDI_STD_THRESH
, TG3_FL_5705
,
9206 0x00000000, 0x000003ff },
9207 { RCVBDI_JUMBO_THRESH
, TG3_FL_NOT_5705
,
9208 0x00000000, 0xffffffff },
9210 /* Host Coalescing Control Registers. */
9211 { HOSTCC_MODE
, TG3_FL_NOT_5705
,
9212 0x00000000, 0x00000004 },
9213 { HOSTCC_MODE
, TG3_FL_5705
,
9214 0x00000000, 0x000000f6 },
9215 { HOSTCC_RXCOL_TICKS
, TG3_FL_NOT_5705
,
9216 0x00000000, 0xffffffff },
9217 { HOSTCC_RXCOL_TICKS
, TG3_FL_5705
,
9218 0x00000000, 0x000003ff },
9219 { HOSTCC_TXCOL_TICKS
, TG3_FL_NOT_5705
,
9220 0x00000000, 0xffffffff },
9221 { HOSTCC_TXCOL_TICKS
, TG3_FL_5705
,
9222 0x00000000, 0x000003ff },
9223 { HOSTCC_RXMAX_FRAMES
, TG3_FL_NOT_5705
,
9224 0x00000000, 0xffffffff },
9225 { HOSTCC_RXMAX_FRAMES
, TG3_FL_5705
| TG3_FL_NOT_5788
,
9226 0x00000000, 0x000000ff },
9227 { HOSTCC_TXMAX_FRAMES
, TG3_FL_NOT_5705
,
9228 0x00000000, 0xffffffff },
9229 { HOSTCC_TXMAX_FRAMES
, TG3_FL_5705
| TG3_FL_NOT_5788
,
9230 0x00000000, 0x000000ff },
9231 { HOSTCC_RXCOAL_TICK_INT
, TG3_FL_NOT_5705
,
9232 0x00000000, 0xffffffff },
9233 { HOSTCC_TXCOAL_TICK_INT
, TG3_FL_NOT_5705
,
9234 0x00000000, 0xffffffff },
9235 { HOSTCC_RXCOAL_MAXF_INT
, TG3_FL_NOT_5705
,
9236 0x00000000, 0xffffffff },
9237 { HOSTCC_RXCOAL_MAXF_INT
, TG3_FL_5705
| TG3_FL_NOT_5788
,
9238 0x00000000, 0x000000ff },
9239 { HOSTCC_TXCOAL_MAXF_INT
, TG3_FL_NOT_5705
,
9240 0x00000000, 0xffffffff },
9241 { HOSTCC_TXCOAL_MAXF_INT
, TG3_FL_5705
| TG3_FL_NOT_5788
,
9242 0x00000000, 0x000000ff },
9243 { HOSTCC_STAT_COAL_TICKS
, TG3_FL_NOT_5705
,
9244 0x00000000, 0xffffffff },
9245 { HOSTCC_STATS_BLK_HOST_ADDR
, TG3_FL_NOT_5705
,
9246 0x00000000, 0xffffffff },
9247 { HOSTCC_STATS_BLK_HOST_ADDR
+4, TG3_FL_NOT_5705
,
9248 0x00000000, 0xffffffff },
9249 { HOSTCC_STATUS_BLK_HOST_ADDR
, 0x0000,
9250 0x00000000, 0xffffffff },
9251 { HOSTCC_STATUS_BLK_HOST_ADDR
+4, 0x0000,
9252 0x00000000, 0xffffffff },
9253 { HOSTCC_STATS_BLK_NIC_ADDR
, 0x0000,
9254 0xffffffff, 0x00000000 },
9255 { HOSTCC_STATUS_BLK_NIC_ADDR
, 0x0000,
9256 0xffffffff, 0x00000000 },
9258 /* Buffer Manager Control Registers. */
9259 { BUFMGR_MB_POOL_ADDR
, TG3_FL_NOT_5750
,
9260 0x00000000, 0x007fff80 },
9261 { BUFMGR_MB_POOL_SIZE
, TG3_FL_NOT_5750
,
9262 0x00000000, 0x007fffff },
9263 { BUFMGR_MB_RDMA_LOW_WATER
, 0x0000,
9264 0x00000000, 0x0000003f },
9265 { BUFMGR_MB_MACRX_LOW_WATER
, 0x0000,
9266 0x00000000, 0x000001ff },
9267 { BUFMGR_MB_HIGH_WATER
, 0x0000,
9268 0x00000000, 0x000001ff },
9269 { BUFMGR_DMA_DESC_POOL_ADDR
, TG3_FL_NOT_5705
,
9270 0xffffffff, 0x00000000 },
9271 { BUFMGR_DMA_DESC_POOL_SIZE
, TG3_FL_NOT_5705
,
9272 0xffffffff, 0x00000000 },
9274 /* Mailbox Registers */
9275 { GRCMBOX_RCVSTD_PROD_IDX
+4, 0x0000,
9276 0x00000000, 0x000001ff },
9277 { GRCMBOX_RCVJUMBO_PROD_IDX
+4, TG3_FL_NOT_5705
,
9278 0x00000000, 0x000001ff },
9279 { GRCMBOX_RCVRET_CON_IDX_0
+4, 0x0000,
9280 0x00000000, 0x000007ff },
9281 { GRCMBOX_SNDHOST_PROD_IDX_0
+4, 0x0000,
9282 0x00000000, 0x000001ff },
9284 { 0xffff, 0x0000, 0x00000000, 0x00000000 },
9287 is_5705
= is_5750
= 0;
9288 if (tp
->tg3_flags2
& TG3_FLG2_5705_PLUS
) {
9290 if (tp
->tg3_flags2
& TG3_FLG2_5750_PLUS
)
9294 for (i
= 0; reg_tbl
[i
].offset
!= 0xffff; i
++) {
9295 if (is_5705
&& (reg_tbl
[i
].flags
& TG3_FL_NOT_5705
))
9298 if (!is_5705
&& (reg_tbl
[i
].flags
& TG3_FL_5705
))
9301 if ((tp
->tg3_flags2
& TG3_FLG2_IS_5788
) &&
9302 (reg_tbl
[i
].flags
& TG3_FL_NOT_5788
))
9305 if (is_5750
&& (reg_tbl
[i
].flags
& TG3_FL_NOT_5750
))
9308 offset
= (u32
) reg_tbl
[i
].offset
;
9309 read_mask
= reg_tbl
[i
].read_mask
;
9310 write_mask
= reg_tbl
[i
].write_mask
;
9312 /* Save the original register content */
9313 save_val
= tr32(offset
);
9315 /* Determine the read-only value. */
9316 read_val
= save_val
& read_mask
;
9318 /* Write zero to the register, then make sure the read-only bits
9319 * are not changed and the read/write bits are all zeros.
9325 /* Test the read-only and read/write bits. */
9326 if (((val
& read_mask
) != read_val
) || (val
& write_mask
))
9329 /* Write ones to all the bits defined by RdMask and WrMask, then
9330 * make sure the read-only bits are not changed and the
9331 * read/write bits are all ones.
9333 tw32(offset
, read_mask
| write_mask
);
9337 /* Test the read-only bits. */
9338 if ((val
& read_mask
) != read_val
)
9341 /* Test the read/write bits. */
9342 if ((val
& write_mask
) != write_mask
)
9345 tw32(offset
, save_val
);
9351 if (netif_msg_hw(tp
))
9352 printk(KERN_ERR PFX
"Register test failed at offset %x\n",
9354 tw32(offset
, save_val
);
9358 static int tg3_do_mem_test(struct tg3
*tp
, u32 offset
, u32 len
)
9360 static const u32 test_pattern
[] = { 0x00000000, 0xffffffff, 0xaa55a55a };
9364 for (i
= 0; i
< ARRAY_SIZE(test_pattern
); i
++) {
9365 for (j
= 0; j
< len
; j
+= 4) {
9368 tg3_write_mem(tp
, offset
+ j
, test_pattern
[i
]);
9369 tg3_read_mem(tp
, offset
+ j
, &val
);
9370 if (val
!= test_pattern
[i
])
9377 static int tg3_test_memory(struct tg3
*tp
)
9379 static struct mem_entry
{
9382 } mem_tbl_570x
[] = {
9383 { 0x00000000, 0x00b50},
9384 { 0x00002000, 0x1c000},
9385 { 0xffffffff, 0x00000}
9386 }, mem_tbl_5705
[] = {
9387 { 0x00000100, 0x0000c},
9388 { 0x00000200, 0x00008},
9389 { 0x00004000, 0x00800},
9390 { 0x00006000, 0x01000},
9391 { 0x00008000, 0x02000},
9392 { 0x00010000, 0x0e000},
9393 { 0xffffffff, 0x00000}
9394 }, mem_tbl_5755
[] = {
9395 { 0x00000200, 0x00008},
9396 { 0x00004000, 0x00800},
9397 { 0x00006000, 0x00800},
9398 { 0x00008000, 0x02000},
9399 { 0x00010000, 0x0c000},
9400 { 0xffffffff, 0x00000}
9401 }, mem_tbl_5906
[] = {
9402 { 0x00000200, 0x00008},
9403 { 0x00004000, 0x00400},
9404 { 0x00006000, 0x00400},
9405 { 0x00008000, 0x01000},
9406 { 0x00010000, 0x01000},
9407 { 0xffffffff, 0x00000}
9409 struct mem_entry
*mem_tbl
;
9413 if (tp
->tg3_flags3
& TG3_FLG3_5755_PLUS
)
9414 mem_tbl
= mem_tbl_5755
;
9415 else if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5906
)
9416 mem_tbl
= mem_tbl_5906
;
9417 else if (tp
->tg3_flags2
& TG3_FLG2_5705_PLUS
)
9418 mem_tbl
= mem_tbl_5705
;
9420 mem_tbl
= mem_tbl_570x
;
9422 for (i
= 0; mem_tbl
[i
].offset
!= 0xffffffff; i
++) {
9423 if ((err
= tg3_do_mem_test(tp
, mem_tbl
[i
].offset
,
9424 mem_tbl
[i
].len
)) != 0)
9431 #define TG3_MAC_LOOPBACK 0
9432 #define TG3_PHY_LOOPBACK 1
9434 static int tg3_run_loopback(struct tg3
*tp
, int loopback_mode
)
9436 u32 mac_mode
, rx_start_idx
, rx_idx
, tx_idx
, opaque_key
;
9438 struct sk_buff
*skb
, *rx_skb
;
9441 int num_pkts
, tx_len
, rx_len
, i
, err
;
9442 struct tg3_rx_buffer_desc
*desc
;
9444 if (loopback_mode
== TG3_MAC_LOOPBACK
) {
9445 /* HW errata - mac loopback fails in some cases on 5780.
9446 * Normal traffic and PHY loopback are not affected by
9449 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5780
)
9452 mac_mode
= (tp
->mac_mode
& ~MAC_MODE_PORT_MODE_MASK
) |
9453 MAC_MODE_PORT_INT_LPBACK
;
9454 if (!(tp
->tg3_flags2
& TG3_FLG2_5705_PLUS
))
9455 mac_mode
|= MAC_MODE_LINK_POLARITY
;
9456 if (tp
->tg3_flags
& TG3_FLAG_10_100_ONLY
)
9457 mac_mode
|= MAC_MODE_PORT_MODE_MII
;
9459 mac_mode
|= MAC_MODE_PORT_MODE_GMII
;
9460 tw32(MAC_MODE
, mac_mode
);
9461 } else if (loopback_mode
== TG3_PHY_LOOPBACK
) {
9464 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5906
) {
9467 if (!tg3_readphy(tp
, MII_TG3_EPHY_TEST
, &phytest
)) {
9470 tg3_writephy(tp
, MII_TG3_EPHY_TEST
,
9471 phytest
| MII_TG3_EPHY_SHADOW_EN
);
9472 if (!tg3_readphy(tp
, 0x1b, &phy
))
9473 tg3_writephy(tp
, 0x1b, phy
& ~0x20);
9474 tg3_writephy(tp
, MII_TG3_EPHY_TEST
, phytest
);
9476 val
= BMCR_LOOPBACK
| BMCR_FULLDPLX
| BMCR_SPEED100
;
9478 val
= BMCR_LOOPBACK
| BMCR_FULLDPLX
| BMCR_SPEED1000
;
9480 tg3_phy_toggle_automdix(tp
, 0);
9482 tg3_writephy(tp
, MII_BMCR
, val
);
9485 mac_mode
= tp
->mac_mode
& ~MAC_MODE_PORT_MODE_MASK
;
9486 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5906
) {
9487 tg3_writephy(tp
, MII_TG3_EPHY_PTEST
, 0x1800);
9488 mac_mode
|= MAC_MODE_PORT_MODE_MII
;
9490 mac_mode
|= MAC_MODE_PORT_MODE_GMII
;
9492 /* reset to prevent losing 1st rx packet intermittently */
9493 if (tp
->tg3_flags2
& TG3_FLG2_MII_SERDES
) {
9494 tw32_f(MAC_RX_MODE
, RX_MODE_RESET
);
9496 tw32_f(MAC_RX_MODE
, tp
->rx_mode
);
9498 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5700
) {
9499 if ((tp
->phy_id
& PHY_ID_MASK
) == PHY_ID_BCM5401
)
9500 mac_mode
&= ~MAC_MODE_LINK_POLARITY
;
9501 else if ((tp
->phy_id
& PHY_ID_MASK
) == PHY_ID_BCM5411
)
9502 mac_mode
|= MAC_MODE_LINK_POLARITY
;
9503 tg3_writephy(tp
, MII_TG3_EXT_CTRL
,
9504 MII_TG3_EXT_CTRL_LNK3_LED_MODE
);
9506 tw32(MAC_MODE
, mac_mode
);
9514 skb
= netdev_alloc_skb(tp
->dev
, tx_len
);
9518 tx_data
= skb_put(skb
, tx_len
);
9519 memcpy(tx_data
, tp
->dev
->dev_addr
, 6);
9520 memset(tx_data
+ 6, 0x0, 8);
9522 tw32(MAC_RX_MTU_SIZE
, tx_len
+ 4);
9524 for (i
= 14; i
< tx_len
; i
++)
9525 tx_data
[i
] = (u8
) (i
& 0xff);
9527 map
= pci_map_single(tp
->pdev
, skb
->data
, tx_len
, PCI_DMA_TODEVICE
);
9529 tw32_f(HOSTCC_MODE
, tp
->coalesce_mode
| HOSTCC_MODE_ENABLE
|
9534 rx_start_idx
= tp
->hw_status
->idx
[0].rx_producer
;
9538 tg3_set_txd(tp
, tp
->tx_prod
, map
, tx_len
, 0, 1);
9543 tw32_tx_mbox(MAILBOX_SNDHOST_PROD_IDX_0
+ TG3_64BIT_REG_LOW
,
9545 tr32_mailbox(MAILBOX_SNDHOST_PROD_IDX_0
+ TG3_64BIT_REG_LOW
);
9549 /* 250 usec to allow enough time on some 10/100 Mbps devices. */
9550 for (i
= 0; i
< 25; i
++) {
9551 tw32_f(HOSTCC_MODE
, tp
->coalesce_mode
| HOSTCC_MODE_ENABLE
|
9556 tx_idx
= tp
->hw_status
->idx
[0].tx_consumer
;
9557 rx_idx
= tp
->hw_status
->idx
[0].rx_producer
;
9558 if ((tx_idx
== tp
->tx_prod
) &&
9559 (rx_idx
== (rx_start_idx
+ num_pkts
)))
9563 pci_unmap_single(tp
->pdev
, map
, tx_len
, PCI_DMA_TODEVICE
);
9566 if (tx_idx
!= tp
->tx_prod
)
9569 if (rx_idx
!= rx_start_idx
+ num_pkts
)
9572 desc
= &tp
->rx_rcb
[rx_start_idx
];
9573 desc_idx
= desc
->opaque
& RXD_OPAQUE_INDEX_MASK
;
9574 opaque_key
= desc
->opaque
& RXD_OPAQUE_RING_MASK
;
9575 if (opaque_key
!= RXD_OPAQUE_RING_STD
)
9578 if ((desc
->err_vlan
& RXD_ERR_MASK
) != 0 &&
9579 (desc
->err_vlan
!= RXD_ERR_ODD_NIBBLE_RCVD_MII
))
9582 rx_len
= ((desc
->idx_len
& RXD_LEN_MASK
) >> RXD_LEN_SHIFT
) - 4;
9583 if (rx_len
!= tx_len
)
9586 rx_skb
= tp
->rx_std_buffers
[desc_idx
].skb
;
9588 map
= pci_unmap_addr(&tp
->rx_std_buffers
[desc_idx
], mapping
);
9589 pci_dma_sync_single_for_cpu(tp
->pdev
, map
, rx_len
, PCI_DMA_FROMDEVICE
);
9591 for (i
= 14; i
< tx_len
; i
++) {
9592 if (*(rx_skb
->data
+ i
) != (u8
) (i
& 0xff))
9597 /* tg3_free_rings will unmap and free the rx_skb */
9602 #define TG3_MAC_LOOPBACK_FAILED 1
9603 #define TG3_PHY_LOOPBACK_FAILED 2
9604 #define TG3_LOOPBACK_FAILED (TG3_MAC_LOOPBACK_FAILED | \
9605 TG3_PHY_LOOPBACK_FAILED)
9607 static int tg3_test_loopback(struct tg3
*tp
)
9612 if (!netif_running(tp
->dev
))
9613 return TG3_LOOPBACK_FAILED
;
9615 err
= tg3_reset_hw(tp
, 1);
9617 return TG3_LOOPBACK_FAILED
;
9619 /* Turn off gphy autopowerdown. */
9620 if (tp
->tg3_flags3
& TG3_FLG3_PHY_ENABLE_APD
)
9621 tg3_phy_toggle_apd(tp
, false);
9623 if (tp
->tg3_flags
& TG3_FLAG_CPMU_PRESENT
) {
9627 tw32(TG3_CPMU_MUTEX_REQ
, CPMU_MUTEX_REQ_DRIVER
);
9629 /* Wait for up to 40 microseconds to acquire lock. */
9630 for (i
= 0; i
< 4; i
++) {
9631 status
= tr32(TG3_CPMU_MUTEX_GNT
);
9632 if (status
== CPMU_MUTEX_GNT_DRIVER
)
9637 if (status
!= CPMU_MUTEX_GNT_DRIVER
)
9638 return TG3_LOOPBACK_FAILED
;
9640 /* Turn off link-based power management. */
9641 cpmuctrl
= tr32(TG3_CPMU_CTRL
);
9643 cpmuctrl
& ~(CPMU_CTRL_LINK_SPEED_MODE
|
9644 CPMU_CTRL_LINK_AWARE_MODE
));
9647 if (tg3_run_loopback(tp
, TG3_MAC_LOOPBACK
))
9648 err
|= TG3_MAC_LOOPBACK_FAILED
;
9650 if (tp
->tg3_flags
& TG3_FLAG_CPMU_PRESENT
) {
9651 tw32(TG3_CPMU_CTRL
, cpmuctrl
);
9653 /* Release the mutex */
9654 tw32(TG3_CPMU_MUTEX_GNT
, CPMU_MUTEX_GNT_DRIVER
);
9657 if (!(tp
->tg3_flags2
& TG3_FLG2_PHY_SERDES
) &&
9658 !(tp
->tg3_flags3
& TG3_FLG3_USE_PHYLIB
)) {
9659 if (tg3_run_loopback(tp
, TG3_PHY_LOOPBACK
))
9660 err
|= TG3_PHY_LOOPBACK_FAILED
;
9663 /* Re-enable gphy autopowerdown. */
9664 if (tp
->tg3_flags3
& TG3_FLG3_PHY_ENABLE_APD
)
9665 tg3_phy_toggle_apd(tp
, true);
9670 static void tg3_self_test(struct net_device
*dev
, struct ethtool_test
*etest
,
9673 struct tg3
*tp
= netdev_priv(dev
);
9675 if (tp
->link_config
.phy_is_low_power
)
9676 tg3_set_power_state(tp
, PCI_D0
);
9678 memset(data
, 0, sizeof(u64
) * TG3_NUM_TEST
);
9680 if (tg3_test_nvram(tp
) != 0) {
9681 etest
->flags
|= ETH_TEST_FL_FAILED
;
9684 if (tg3_test_link(tp
) != 0) {
9685 etest
->flags
|= ETH_TEST_FL_FAILED
;
9688 if (etest
->flags
& ETH_TEST_FL_OFFLINE
) {
9689 int err
, err2
= 0, irq_sync
= 0;
9691 if (netif_running(dev
)) {
9697 tg3_full_lock(tp
, irq_sync
);
9699 tg3_halt(tp
, RESET_KIND_SUSPEND
, 1);
9700 err
= tg3_nvram_lock(tp
);
9701 tg3_halt_cpu(tp
, RX_CPU_BASE
);
9702 if (!(tp
->tg3_flags2
& TG3_FLG2_5705_PLUS
))
9703 tg3_halt_cpu(tp
, TX_CPU_BASE
);
9705 tg3_nvram_unlock(tp
);
9707 if (tp
->tg3_flags2
& TG3_FLG2_MII_SERDES
)
9710 if (tg3_test_registers(tp
) != 0) {
9711 etest
->flags
|= ETH_TEST_FL_FAILED
;
9714 if (tg3_test_memory(tp
) != 0) {
9715 etest
->flags
|= ETH_TEST_FL_FAILED
;
9718 if ((data
[4] = tg3_test_loopback(tp
)) != 0)
9719 etest
->flags
|= ETH_TEST_FL_FAILED
;
9721 tg3_full_unlock(tp
);
9723 if (tg3_test_interrupt(tp
) != 0) {
9724 etest
->flags
|= ETH_TEST_FL_FAILED
;
9728 tg3_full_lock(tp
, 0);
9730 tg3_halt(tp
, RESET_KIND_SHUTDOWN
, 1);
9731 if (netif_running(dev
)) {
9732 tp
->tg3_flags
|= TG3_FLAG_INIT_COMPLETE
;
9733 err2
= tg3_restart_hw(tp
, 1);
9735 tg3_netif_start(tp
);
9738 tg3_full_unlock(tp
);
9740 if (irq_sync
&& !err2
)
9743 if (tp
->link_config
.phy_is_low_power
)
9744 tg3_set_power_state(tp
, PCI_D3hot
);
9748 static int tg3_ioctl(struct net_device
*dev
, struct ifreq
*ifr
, int cmd
)
9750 struct mii_ioctl_data
*data
= if_mii(ifr
);
9751 struct tg3
*tp
= netdev_priv(dev
);
9754 if (tp
->tg3_flags3
& TG3_FLG3_USE_PHYLIB
) {
9755 if (!(tp
->tg3_flags3
& TG3_FLG3_PHY_CONNECTED
))
9757 return phy_mii_ioctl(tp
->mdio_bus
->phy_map
[PHY_ADDR
], data
, cmd
);
9762 data
->phy_id
= PHY_ADDR
;
9768 if (tp
->tg3_flags2
& TG3_FLG2_PHY_SERDES
)
9769 break; /* We have no PHY */
9771 if (tp
->link_config
.phy_is_low_power
)
9774 spin_lock_bh(&tp
->lock
);
9775 err
= tg3_readphy(tp
, data
->reg_num
& 0x1f, &mii_regval
);
9776 spin_unlock_bh(&tp
->lock
);
9778 data
->val_out
= mii_regval
;
9784 if (tp
->tg3_flags2
& TG3_FLG2_PHY_SERDES
)
9785 break; /* We have no PHY */
9787 if (!capable(CAP_NET_ADMIN
))
9790 if (tp
->link_config
.phy_is_low_power
)
9793 spin_lock_bh(&tp
->lock
);
9794 err
= tg3_writephy(tp
, data
->reg_num
& 0x1f, data
->val_in
);
9795 spin_unlock_bh(&tp
->lock
);
9806 #if TG3_VLAN_TAG_USED
9807 static void tg3_vlan_rx_register(struct net_device
*dev
, struct vlan_group
*grp
)
9809 struct tg3
*tp
= netdev_priv(dev
);
9811 if (netif_running(dev
))
9814 tg3_full_lock(tp
, 0);
9818 /* Update RX_MODE_KEEP_VLAN_TAG bit in RX_MODE register. */
9819 __tg3_set_rx_mode(dev
);
9821 if (netif_running(dev
))
9822 tg3_netif_start(tp
);
9824 tg3_full_unlock(tp
);
9828 static int tg3_get_coalesce(struct net_device
*dev
, struct ethtool_coalesce
*ec
)
9830 struct tg3
*tp
= netdev_priv(dev
);
9832 memcpy(ec
, &tp
->coal
, sizeof(*ec
));
9836 static int tg3_set_coalesce(struct net_device
*dev
, struct ethtool_coalesce
*ec
)
9838 struct tg3
*tp
= netdev_priv(dev
);
9839 u32 max_rxcoal_tick_int
= 0, max_txcoal_tick_int
= 0;
9840 u32 max_stat_coal_ticks
= 0, min_stat_coal_ticks
= 0;
9842 if (!(tp
->tg3_flags2
& TG3_FLG2_5705_PLUS
)) {
9843 max_rxcoal_tick_int
= MAX_RXCOAL_TICK_INT
;
9844 max_txcoal_tick_int
= MAX_TXCOAL_TICK_INT
;
9845 max_stat_coal_ticks
= MAX_STAT_COAL_TICKS
;
9846 min_stat_coal_ticks
= MIN_STAT_COAL_TICKS
;
9849 if ((ec
->rx_coalesce_usecs
> MAX_RXCOL_TICKS
) ||
9850 (ec
->tx_coalesce_usecs
> MAX_TXCOL_TICKS
) ||
9851 (ec
->rx_max_coalesced_frames
> MAX_RXMAX_FRAMES
) ||
9852 (ec
->tx_max_coalesced_frames
> MAX_TXMAX_FRAMES
) ||
9853 (ec
->rx_coalesce_usecs_irq
> max_rxcoal_tick_int
) ||
9854 (ec
->tx_coalesce_usecs_irq
> max_txcoal_tick_int
) ||
9855 (ec
->rx_max_coalesced_frames_irq
> MAX_RXCOAL_MAXF_INT
) ||
9856 (ec
->tx_max_coalesced_frames_irq
> MAX_TXCOAL_MAXF_INT
) ||
9857 (ec
->stats_block_coalesce_usecs
> max_stat_coal_ticks
) ||
9858 (ec
->stats_block_coalesce_usecs
< min_stat_coal_ticks
))
9861 /* No rx interrupts will be generated if both are zero */
9862 if ((ec
->rx_coalesce_usecs
== 0) &&
9863 (ec
->rx_max_coalesced_frames
== 0))
9866 /* No tx interrupts will be generated if both are zero */
9867 if ((ec
->tx_coalesce_usecs
== 0) &&
9868 (ec
->tx_max_coalesced_frames
== 0))
9871 /* Only copy relevant parameters, ignore all others. */
9872 tp
->coal
.rx_coalesce_usecs
= ec
->rx_coalesce_usecs
;
9873 tp
->coal
.tx_coalesce_usecs
= ec
->tx_coalesce_usecs
;
9874 tp
->coal
.rx_max_coalesced_frames
= ec
->rx_max_coalesced_frames
;
9875 tp
->coal
.tx_max_coalesced_frames
= ec
->tx_max_coalesced_frames
;
9876 tp
->coal
.rx_coalesce_usecs_irq
= ec
->rx_coalesce_usecs_irq
;
9877 tp
->coal
.tx_coalesce_usecs_irq
= ec
->tx_coalesce_usecs_irq
;
9878 tp
->coal
.rx_max_coalesced_frames_irq
= ec
->rx_max_coalesced_frames_irq
;
9879 tp
->coal
.tx_max_coalesced_frames_irq
= ec
->tx_max_coalesced_frames_irq
;
9880 tp
->coal
.stats_block_coalesce_usecs
= ec
->stats_block_coalesce_usecs
;
9882 if (netif_running(dev
)) {
9883 tg3_full_lock(tp
, 0);
9884 __tg3_set_coalesce(tp
, &tp
->coal
);
9885 tg3_full_unlock(tp
);
9890 static const struct ethtool_ops tg3_ethtool_ops
= {
9891 .get_settings
= tg3_get_settings
,
9892 .set_settings
= tg3_set_settings
,
9893 .get_drvinfo
= tg3_get_drvinfo
,
9894 .get_regs_len
= tg3_get_regs_len
,
9895 .get_regs
= tg3_get_regs
,
9896 .get_wol
= tg3_get_wol
,
9897 .set_wol
= tg3_set_wol
,
9898 .get_msglevel
= tg3_get_msglevel
,
9899 .set_msglevel
= tg3_set_msglevel
,
9900 .nway_reset
= tg3_nway_reset
,
9901 .get_link
= ethtool_op_get_link
,
9902 .get_eeprom_len
= tg3_get_eeprom_len
,
9903 .get_eeprom
= tg3_get_eeprom
,
9904 .set_eeprom
= tg3_set_eeprom
,
9905 .get_ringparam
= tg3_get_ringparam
,
9906 .set_ringparam
= tg3_set_ringparam
,
9907 .get_pauseparam
= tg3_get_pauseparam
,
9908 .set_pauseparam
= tg3_set_pauseparam
,
9909 .get_rx_csum
= tg3_get_rx_csum
,
9910 .set_rx_csum
= tg3_set_rx_csum
,
9911 .set_tx_csum
= tg3_set_tx_csum
,
9912 .set_sg
= ethtool_op_set_sg
,
9913 .set_tso
= tg3_set_tso
,
9914 .self_test
= tg3_self_test
,
9915 .get_strings
= tg3_get_strings
,
9916 .phys_id
= tg3_phys_id
,
9917 .get_ethtool_stats
= tg3_get_ethtool_stats
,
9918 .get_coalesce
= tg3_get_coalesce
,
9919 .set_coalesce
= tg3_set_coalesce
,
9920 .get_sset_count
= tg3_get_sset_count
,
9923 static void __devinit
tg3_get_eeprom_size(struct tg3
*tp
)
9925 u32 cursize
, val
, magic
;
9927 tp
->nvram_size
= EEPROM_CHIP_SIZE
;
9929 if (tg3_nvram_read_swab(tp
, 0, &magic
) != 0)
9932 if ((magic
!= TG3_EEPROM_MAGIC
) &&
9933 ((magic
& TG3_EEPROM_MAGIC_FW_MSK
) != TG3_EEPROM_MAGIC_FW
) &&
9934 ((magic
& TG3_EEPROM_MAGIC_HW_MSK
) != TG3_EEPROM_MAGIC_HW
))
9938 * Size the chip by reading offsets at increasing powers of two.
9939 * When we encounter our validation signature, we know the addressing
9940 * has wrapped around, and thus have our chip size.
9944 while (cursize
< tp
->nvram_size
) {
9945 if (tg3_nvram_read_swab(tp
, cursize
, &val
) != 0)
9954 tp
->nvram_size
= cursize
;
9957 static void __devinit
tg3_get_nvram_size(struct tg3
*tp
)
9961 if (tg3_nvram_read_swab(tp
, 0, &val
) != 0)
9964 /* Selfboot format */
9965 if (val
!= TG3_EEPROM_MAGIC
) {
9966 tg3_get_eeprom_size(tp
);
9970 if (tg3_nvram_read(tp
, 0xf0, &val
) == 0) {
9972 tp
->nvram_size
= (val
>> 16) * 1024;
9976 tp
->nvram_size
= TG3_NVRAM_SIZE_512KB
;
9979 static void __devinit
tg3_get_nvram_info(struct tg3
*tp
)
9983 nvcfg1
= tr32(NVRAM_CFG1
);
9984 if (nvcfg1
& NVRAM_CFG1_FLASHIF_ENAB
) {
9985 tp
->tg3_flags2
|= TG3_FLG2_FLASH
;
9988 nvcfg1
&= ~NVRAM_CFG1_COMPAT_BYPASS
;
9989 tw32(NVRAM_CFG1
, nvcfg1
);
9992 if ((GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5750
) ||
9993 (tp
->tg3_flags2
& TG3_FLG2_5780_CLASS
)) {
9994 switch (nvcfg1
& NVRAM_CFG1_VENDOR_MASK
) {
9995 case FLASH_VENDOR_ATMEL_FLASH_BUFFERED
:
9996 tp
->nvram_jedecnum
= JEDEC_ATMEL
;
9997 tp
->nvram_pagesize
= ATMEL_AT45DB0X1B_PAGE_SIZE
;
9998 tp
->tg3_flags
|= TG3_FLAG_NVRAM_BUFFERED
;
10000 case FLASH_VENDOR_ATMEL_FLASH_UNBUFFERED
:
10001 tp
->nvram_jedecnum
= JEDEC_ATMEL
;
10002 tp
->nvram_pagesize
= ATMEL_AT25F512_PAGE_SIZE
;
10004 case FLASH_VENDOR_ATMEL_EEPROM
:
10005 tp
->nvram_jedecnum
= JEDEC_ATMEL
;
10006 tp
->nvram_pagesize
= ATMEL_AT24C512_CHIP_SIZE
;
10007 tp
->tg3_flags
|= TG3_FLAG_NVRAM_BUFFERED
;
10009 case FLASH_VENDOR_ST
:
10010 tp
->nvram_jedecnum
= JEDEC_ST
;
10011 tp
->nvram_pagesize
= ST_M45PEX0_PAGE_SIZE
;
10012 tp
->tg3_flags
|= TG3_FLAG_NVRAM_BUFFERED
;
10014 case FLASH_VENDOR_SAIFUN
:
10015 tp
->nvram_jedecnum
= JEDEC_SAIFUN
;
10016 tp
->nvram_pagesize
= SAIFUN_SA25F0XX_PAGE_SIZE
;
10018 case FLASH_VENDOR_SST_SMALL
:
10019 case FLASH_VENDOR_SST_LARGE
:
10020 tp
->nvram_jedecnum
= JEDEC_SST
;
10021 tp
->nvram_pagesize
= SST_25VF0X0_PAGE_SIZE
;
10026 tp
->nvram_jedecnum
= JEDEC_ATMEL
;
10027 tp
->nvram_pagesize
= ATMEL_AT45DB0X1B_PAGE_SIZE
;
10028 tp
->tg3_flags
|= TG3_FLAG_NVRAM_BUFFERED
;
10032 static void __devinit
tg3_get_5752_nvram_info(struct tg3
*tp
)
10036 nvcfg1
= tr32(NVRAM_CFG1
);
10038 /* NVRAM protection for TPM */
10039 if (nvcfg1
& (1 << 27))
10040 tp
->tg3_flags2
|= TG3_FLG2_PROTECTED_NVRAM
;
10042 switch (nvcfg1
& NVRAM_CFG1_5752VENDOR_MASK
) {
10043 case FLASH_5752VENDOR_ATMEL_EEPROM_64KHZ
:
10044 case FLASH_5752VENDOR_ATMEL_EEPROM_376KHZ
:
10045 tp
->nvram_jedecnum
= JEDEC_ATMEL
;
10046 tp
->tg3_flags
|= TG3_FLAG_NVRAM_BUFFERED
;
10048 case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED
:
10049 tp
->nvram_jedecnum
= JEDEC_ATMEL
;
10050 tp
->tg3_flags
|= TG3_FLAG_NVRAM_BUFFERED
;
10051 tp
->tg3_flags2
|= TG3_FLG2_FLASH
;
10053 case FLASH_5752VENDOR_ST_M45PE10
:
10054 case FLASH_5752VENDOR_ST_M45PE20
:
10055 case FLASH_5752VENDOR_ST_M45PE40
:
10056 tp
->nvram_jedecnum
= JEDEC_ST
;
10057 tp
->tg3_flags
|= TG3_FLAG_NVRAM_BUFFERED
;
10058 tp
->tg3_flags2
|= TG3_FLG2_FLASH
;
10062 if (tp
->tg3_flags2
& TG3_FLG2_FLASH
) {
10063 switch (nvcfg1
& NVRAM_CFG1_5752PAGE_SIZE_MASK
) {
10064 case FLASH_5752PAGE_SIZE_256
:
10065 tp
->nvram_pagesize
= 256;
10067 case FLASH_5752PAGE_SIZE_512
:
10068 tp
->nvram_pagesize
= 512;
10070 case FLASH_5752PAGE_SIZE_1K
:
10071 tp
->nvram_pagesize
= 1024;
10073 case FLASH_5752PAGE_SIZE_2K
:
10074 tp
->nvram_pagesize
= 2048;
10076 case FLASH_5752PAGE_SIZE_4K
:
10077 tp
->nvram_pagesize
= 4096;
10079 case FLASH_5752PAGE_SIZE_264
:
10080 tp
->nvram_pagesize
= 264;
10085 /* For eeprom, set pagesize to maximum eeprom size */
10086 tp
->nvram_pagesize
= ATMEL_AT24C512_CHIP_SIZE
;
10088 nvcfg1
&= ~NVRAM_CFG1_COMPAT_BYPASS
;
10089 tw32(NVRAM_CFG1
, nvcfg1
);
10093 static void __devinit
tg3_get_5755_nvram_info(struct tg3
*tp
)
10095 u32 nvcfg1
, protect
= 0;
10097 nvcfg1
= tr32(NVRAM_CFG1
);
10099 /* NVRAM protection for TPM */
10100 if (nvcfg1
& (1 << 27)) {
10101 tp
->tg3_flags2
|= TG3_FLG2_PROTECTED_NVRAM
;
10105 nvcfg1
&= NVRAM_CFG1_5752VENDOR_MASK
;
10107 case FLASH_5755VENDOR_ATMEL_FLASH_1
:
10108 case FLASH_5755VENDOR_ATMEL_FLASH_2
:
10109 case FLASH_5755VENDOR_ATMEL_FLASH_3
:
10110 case FLASH_5755VENDOR_ATMEL_FLASH_5
:
10111 tp
->nvram_jedecnum
= JEDEC_ATMEL
;
10112 tp
->tg3_flags
|= TG3_FLAG_NVRAM_BUFFERED
;
10113 tp
->tg3_flags2
|= TG3_FLG2_FLASH
;
10114 tp
->nvram_pagesize
= 264;
10115 if (nvcfg1
== FLASH_5755VENDOR_ATMEL_FLASH_1
||
10116 nvcfg1
== FLASH_5755VENDOR_ATMEL_FLASH_5
)
10117 tp
->nvram_size
= (protect
? 0x3e200 :
10118 TG3_NVRAM_SIZE_512KB
);
10119 else if (nvcfg1
== FLASH_5755VENDOR_ATMEL_FLASH_2
)
10120 tp
->nvram_size
= (protect
? 0x1f200 :
10121 TG3_NVRAM_SIZE_256KB
);
10123 tp
->nvram_size
= (protect
? 0x1f200 :
10124 TG3_NVRAM_SIZE_128KB
);
10126 case FLASH_5752VENDOR_ST_M45PE10
:
10127 case FLASH_5752VENDOR_ST_M45PE20
:
10128 case FLASH_5752VENDOR_ST_M45PE40
:
10129 tp
->nvram_jedecnum
= JEDEC_ST
;
10130 tp
->tg3_flags
|= TG3_FLAG_NVRAM_BUFFERED
;
10131 tp
->tg3_flags2
|= TG3_FLG2_FLASH
;
10132 tp
->nvram_pagesize
= 256;
10133 if (nvcfg1
== FLASH_5752VENDOR_ST_M45PE10
)
10134 tp
->nvram_size
= (protect
?
10135 TG3_NVRAM_SIZE_64KB
:
10136 TG3_NVRAM_SIZE_128KB
);
10137 else if (nvcfg1
== FLASH_5752VENDOR_ST_M45PE20
)
10138 tp
->nvram_size
= (protect
?
10139 TG3_NVRAM_SIZE_64KB
:
10140 TG3_NVRAM_SIZE_256KB
);
10142 tp
->nvram_size
= (protect
?
10143 TG3_NVRAM_SIZE_128KB
:
10144 TG3_NVRAM_SIZE_512KB
);
10149 static void __devinit
tg3_get_5787_nvram_info(struct tg3
*tp
)
10153 nvcfg1
= tr32(NVRAM_CFG1
);
10155 switch (nvcfg1
& NVRAM_CFG1_5752VENDOR_MASK
) {
10156 case FLASH_5787VENDOR_ATMEL_EEPROM_64KHZ
:
10157 case FLASH_5787VENDOR_ATMEL_EEPROM_376KHZ
:
10158 case FLASH_5787VENDOR_MICRO_EEPROM_64KHZ
:
10159 case FLASH_5787VENDOR_MICRO_EEPROM_376KHZ
:
10160 tp
->nvram_jedecnum
= JEDEC_ATMEL
;
10161 tp
->tg3_flags
|= TG3_FLAG_NVRAM_BUFFERED
;
10162 tp
->nvram_pagesize
= ATMEL_AT24C512_CHIP_SIZE
;
10164 nvcfg1
&= ~NVRAM_CFG1_COMPAT_BYPASS
;
10165 tw32(NVRAM_CFG1
, nvcfg1
);
10167 case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED
:
10168 case FLASH_5755VENDOR_ATMEL_FLASH_1
:
10169 case FLASH_5755VENDOR_ATMEL_FLASH_2
:
10170 case FLASH_5755VENDOR_ATMEL_FLASH_3
:
10171 tp
->nvram_jedecnum
= JEDEC_ATMEL
;
10172 tp
->tg3_flags
|= TG3_FLAG_NVRAM_BUFFERED
;
10173 tp
->tg3_flags2
|= TG3_FLG2_FLASH
;
10174 tp
->nvram_pagesize
= 264;
10176 case FLASH_5752VENDOR_ST_M45PE10
:
10177 case FLASH_5752VENDOR_ST_M45PE20
:
10178 case FLASH_5752VENDOR_ST_M45PE40
:
10179 tp
->nvram_jedecnum
= JEDEC_ST
;
10180 tp
->tg3_flags
|= TG3_FLAG_NVRAM_BUFFERED
;
10181 tp
->tg3_flags2
|= TG3_FLG2_FLASH
;
10182 tp
->nvram_pagesize
= 256;
10187 static void __devinit
tg3_get_5761_nvram_info(struct tg3
*tp
)
10189 u32 nvcfg1
, protect
= 0;
10191 nvcfg1
= tr32(NVRAM_CFG1
);
10193 /* NVRAM protection for TPM */
10194 if (nvcfg1
& (1 << 27)) {
10195 tp
->tg3_flags2
|= TG3_FLG2_PROTECTED_NVRAM
;
10199 nvcfg1
&= NVRAM_CFG1_5752VENDOR_MASK
;
10201 case FLASH_5761VENDOR_ATMEL_ADB021D
:
10202 case FLASH_5761VENDOR_ATMEL_ADB041D
:
10203 case FLASH_5761VENDOR_ATMEL_ADB081D
:
10204 case FLASH_5761VENDOR_ATMEL_ADB161D
:
10205 case FLASH_5761VENDOR_ATMEL_MDB021D
:
10206 case FLASH_5761VENDOR_ATMEL_MDB041D
:
10207 case FLASH_5761VENDOR_ATMEL_MDB081D
:
10208 case FLASH_5761VENDOR_ATMEL_MDB161D
:
10209 tp
->nvram_jedecnum
= JEDEC_ATMEL
;
10210 tp
->tg3_flags
|= TG3_FLAG_NVRAM_BUFFERED
;
10211 tp
->tg3_flags2
|= TG3_FLG2_FLASH
;
10212 tp
->tg3_flags3
|= TG3_FLG3_NO_NVRAM_ADDR_TRANS
;
10213 tp
->nvram_pagesize
= 256;
10215 case FLASH_5761VENDOR_ST_A_M45PE20
:
10216 case FLASH_5761VENDOR_ST_A_M45PE40
:
10217 case FLASH_5761VENDOR_ST_A_M45PE80
:
10218 case FLASH_5761VENDOR_ST_A_M45PE16
:
10219 case FLASH_5761VENDOR_ST_M_M45PE20
:
10220 case FLASH_5761VENDOR_ST_M_M45PE40
:
10221 case FLASH_5761VENDOR_ST_M_M45PE80
:
10222 case FLASH_5761VENDOR_ST_M_M45PE16
:
10223 tp
->nvram_jedecnum
= JEDEC_ST
;
10224 tp
->tg3_flags
|= TG3_FLAG_NVRAM_BUFFERED
;
10225 tp
->tg3_flags2
|= TG3_FLG2_FLASH
;
10226 tp
->nvram_pagesize
= 256;
10231 tp
->nvram_size
= tr32(NVRAM_ADDR_LOCKOUT
);
10234 case FLASH_5761VENDOR_ATMEL_ADB161D
:
10235 case FLASH_5761VENDOR_ATMEL_MDB161D
:
10236 case FLASH_5761VENDOR_ST_A_M45PE16
:
10237 case FLASH_5761VENDOR_ST_M_M45PE16
:
10238 tp
->nvram_size
= TG3_NVRAM_SIZE_2MB
;
10240 case FLASH_5761VENDOR_ATMEL_ADB081D
:
10241 case FLASH_5761VENDOR_ATMEL_MDB081D
:
10242 case FLASH_5761VENDOR_ST_A_M45PE80
:
10243 case FLASH_5761VENDOR_ST_M_M45PE80
:
10244 tp
->nvram_size
= TG3_NVRAM_SIZE_1MB
;
10246 case FLASH_5761VENDOR_ATMEL_ADB041D
:
10247 case FLASH_5761VENDOR_ATMEL_MDB041D
:
10248 case FLASH_5761VENDOR_ST_A_M45PE40
:
10249 case FLASH_5761VENDOR_ST_M_M45PE40
:
10250 tp
->nvram_size
= TG3_NVRAM_SIZE_512KB
;
10252 case FLASH_5761VENDOR_ATMEL_ADB021D
:
10253 case FLASH_5761VENDOR_ATMEL_MDB021D
:
10254 case FLASH_5761VENDOR_ST_A_M45PE20
:
10255 case FLASH_5761VENDOR_ST_M_M45PE20
:
10256 tp
->nvram_size
= TG3_NVRAM_SIZE_256KB
;
10262 static void __devinit
tg3_get_5906_nvram_info(struct tg3
*tp
)
10264 tp
->nvram_jedecnum
= JEDEC_ATMEL
;
10265 tp
->tg3_flags
|= TG3_FLAG_NVRAM_BUFFERED
;
10266 tp
->nvram_pagesize
= ATMEL_AT24C512_CHIP_SIZE
;
10269 static void __devinit
tg3_get_57780_nvram_info(struct tg3
*tp
)
10273 nvcfg1
= tr32(NVRAM_CFG1
);
10275 switch (nvcfg1
& NVRAM_CFG1_5752VENDOR_MASK
) {
10276 case FLASH_5787VENDOR_ATMEL_EEPROM_376KHZ
:
10277 case FLASH_5787VENDOR_MICRO_EEPROM_376KHZ
:
10278 tp
->nvram_jedecnum
= JEDEC_ATMEL
;
10279 tp
->tg3_flags
|= TG3_FLAG_NVRAM_BUFFERED
;
10280 tp
->nvram_pagesize
= ATMEL_AT24C512_CHIP_SIZE
;
10282 nvcfg1
&= ~NVRAM_CFG1_COMPAT_BYPASS
;
10283 tw32(NVRAM_CFG1
, nvcfg1
);
10285 case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED
:
10286 case FLASH_57780VENDOR_ATMEL_AT45DB011D
:
10287 case FLASH_57780VENDOR_ATMEL_AT45DB011B
:
10288 case FLASH_57780VENDOR_ATMEL_AT45DB021D
:
10289 case FLASH_57780VENDOR_ATMEL_AT45DB021B
:
10290 case FLASH_57780VENDOR_ATMEL_AT45DB041D
:
10291 case FLASH_57780VENDOR_ATMEL_AT45DB041B
:
10292 tp
->nvram_jedecnum
= JEDEC_ATMEL
;
10293 tp
->tg3_flags
|= TG3_FLAG_NVRAM_BUFFERED
;
10294 tp
->tg3_flags2
|= TG3_FLG2_FLASH
;
10296 switch (nvcfg1
& NVRAM_CFG1_5752VENDOR_MASK
) {
10297 case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED
:
10298 case FLASH_57780VENDOR_ATMEL_AT45DB011D
:
10299 case FLASH_57780VENDOR_ATMEL_AT45DB011B
:
10300 tp
->nvram_size
= TG3_NVRAM_SIZE_128KB
;
10302 case FLASH_57780VENDOR_ATMEL_AT45DB021D
:
10303 case FLASH_57780VENDOR_ATMEL_AT45DB021B
:
10304 tp
->nvram_size
= TG3_NVRAM_SIZE_256KB
;
10306 case FLASH_57780VENDOR_ATMEL_AT45DB041D
:
10307 case FLASH_57780VENDOR_ATMEL_AT45DB041B
:
10308 tp
->nvram_size
= TG3_NVRAM_SIZE_512KB
;
10312 case FLASH_5752VENDOR_ST_M45PE10
:
10313 case FLASH_5752VENDOR_ST_M45PE20
:
10314 case FLASH_5752VENDOR_ST_M45PE40
:
10315 tp
->nvram_jedecnum
= JEDEC_ST
;
10316 tp
->tg3_flags
|= TG3_FLAG_NVRAM_BUFFERED
;
10317 tp
->tg3_flags2
|= TG3_FLG2_FLASH
;
10319 switch (nvcfg1
& NVRAM_CFG1_5752VENDOR_MASK
) {
10320 case FLASH_5752VENDOR_ST_M45PE10
:
10321 tp
->nvram_size
= TG3_NVRAM_SIZE_128KB
;
10323 case FLASH_5752VENDOR_ST_M45PE20
:
10324 tp
->nvram_size
= TG3_NVRAM_SIZE_256KB
;
10326 case FLASH_5752VENDOR_ST_M45PE40
:
10327 tp
->nvram_size
= TG3_NVRAM_SIZE_512KB
;
10335 switch (nvcfg1
& NVRAM_CFG1_5752PAGE_SIZE_MASK
) {
10336 case FLASH_5752PAGE_SIZE_256
:
10337 tp
->tg3_flags3
|= TG3_FLG3_NO_NVRAM_ADDR_TRANS
;
10338 tp
->nvram_pagesize
= 256;
10340 case FLASH_5752PAGE_SIZE_512
:
10341 tp
->tg3_flags3
|= TG3_FLG3_NO_NVRAM_ADDR_TRANS
;
10342 tp
->nvram_pagesize
= 512;
10344 case FLASH_5752PAGE_SIZE_1K
:
10345 tp
->tg3_flags3
|= TG3_FLG3_NO_NVRAM_ADDR_TRANS
;
10346 tp
->nvram_pagesize
= 1024;
10348 case FLASH_5752PAGE_SIZE_2K
:
10349 tp
->tg3_flags3
|= TG3_FLG3_NO_NVRAM_ADDR_TRANS
;
10350 tp
->nvram_pagesize
= 2048;
10352 case FLASH_5752PAGE_SIZE_4K
:
10353 tp
->tg3_flags3
|= TG3_FLG3_NO_NVRAM_ADDR_TRANS
;
10354 tp
->nvram_pagesize
= 4096;
10356 case FLASH_5752PAGE_SIZE_264
:
10357 tp
->nvram_pagesize
= 264;
10359 case FLASH_5752PAGE_SIZE_528
:
10360 tp
->nvram_pagesize
= 528;
10365 /* Chips other than 5700/5701 use the NVRAM for fetching info. */
10366 static void __devinit
tg3_nvram_init(struct tg3
*tp
)
10368 tw32_f(GRC_EEPROM_ADDR
,
10369 (EEPROM_ADDR_FSM_RESET
|
10370 (EEPROM_DEFAULT_CLOCK_PERIOD
<<
10371 EEPROM_ADDR_CLKPERD_SHIFT
)));
10375 /* Enable seeprom accesses. */
10376 tw32_f(GRC_LOCAL_CTRL
,
10377 tr32(GRC_LOCAL_CTRL
) | GRC_LCLCTRL_AUTO_SEEPROM
);
10380 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) != ASIC_REV_5700
&&
10381 GET_ASIC_REV(tp
->pci_chip_rev_id
) != ASIC_REV_5701
) {
10382 tp
->tg3_flags
|= TG3_FLAG_NVRAM
;
10384 if (tg3_nvram_lock(tp
)) {
10385 printk(KERN_WARNING PFX
"%s: Cannot get nvarm lock, "
10386 "tg3_nvram_init failed.\n", tp
->dev
->name
);
10389 tg3_enable_nvram_access(tp
);
10391 tp
->nvram_size
= 0;
10393 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5752
)
10394 tg3_get_5752_nvram_info(tp
);
10395 else if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5755
)
10396 tg3_get_5755_nvram_info(tp
);
10397 else if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5787
||
10398 GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5784
||
10399 GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5785
)
10400 tg3_get_5787_nvram_info(tp
);
10401 else if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5761
)
10402 tg3_get_5761_nvram_info(tp
);
10403 else if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5906
)
10404 tg3_get_5906_nvram_info(tp
);
10405 else if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_57780
)
10406 tg3_get_57780_nvram_info(tp
);
10408 tg3_get_nvram_info(tp
);
10410 if (tp
->nvram_size
== 0)
10411 tg3_get_nvram_size(tp
);
10413 tg3_disable_nvram_access(tp
);
10414 tg3_nvram_unlock(tp
);
10417 tp
->tg3_flags
&= ~(TG3_FLAG_NVRAM
| TG3_FLAG_NVRAM_BUFFERED
);
10419 tg3_get_eeprom_size(tp
);
10423 static int tg3_nvram_read_using_eeprom(struct tg3
*tp
,
10424 u32 offset
, u32
*val
)
10429 if (offset
> EEPROM_ADDR_ADDR_MASK
||
10433 tmp
= tr32(GRC_EEPROM_ADDR
) & ~(EEPROM_ADDR_ADDR_MASK
|
10434 EEPROM_ADDR_DEVID_MASK
|
10436 tw32(GRC_EEPROM_ADDR
,
10438 (0 << EEPROM_ADDR_DEVID_SHIFT
) |
10439 ((offset
<< EEPROM_ADDR_ADDR_SHIFT
) &
10440 EEPROM_ADDR_ADDR_MASK
) |
10441 EEPROM_ADDR_READ
| EEPROM_ADDR_START
);
10443 for (i
= 0; i
< 1000; i
++) {
10444 tmp
= tr32(GRC_EEPROM_ADDR
);
10446 if (tmp
& EEPROM_ADDR_COMPLETE
)
10450 if (!(tmp
& EEPROM_ADDR_COMPLETE
))
10453 *val
= tr32(GRC_EEPROM_DATA
);
10457 #define NVRAM_CMD_TIMEOUT 10000
10459 static int tg3_nvram_exec_cmd(struct tg3
*tp
, u32 nvram_cmd
)
10463 tw32(NVRAM_CMD
, nvram_cmd
);
10464 for (i
= 0; i
< NVRAM_CMD_TIMEOUT
; i
++) {
10466 if (tr32(NVRAM_CMD
) & NVRAM_CMD_DONE
) {
10471 if (i
== NVRAM_CMD_TIMEOUT
) {
10477 static u32
tg3_nvram_phys_addr(struct tg3
*tp
, u32 addr
)
10479 if ((tp
->tg3_flags
& TG3_FLAG_NVRAM
) &&
10480 (tp
->tg3_flags
& TG3_FLAG_NVRAM_BUFFERED
) &&
10481 (tp
->tg3_flags2
& TG3_FLG2_FLASH
) &&
10482 !(tp
->tg3_flags3
& TG3_FLG3_NO_NVRAM_ADDR_TRANS
) &&
10483 (tp
->nvram_jedecnum
== JEDEC_ATMEL
))
10485 addr
= ((addr
/ tp
->nvram_pagesize
) <<
10486 ATMEL_AT45DB0X1B_PAGE_POS
) +
10487 (addr
% tp
->nvram_pagesize
);
10492 static u32
tg3_nvram_logical_addr(struct tg3
*tp
, u32 addr
)
10494 if ((tp
->tg3_flags
& TG3_FLAG_NVRAM
) &&
10495 (tp
->tg3_flags
& TG3_FLAG_NVRAM_BUFFERED
) &&
10496 (tp
->tg3_flags2
& TG3_FLG2_FLASH
) &&
10497 !(tp
->tg3_flags3
& TG3_FLG3_NO_NVRAM_ADDR_TRANS
) &&
10498 (tp
->nvram_jedecnum
== JEDEC_ATMEL
))
10500 addr
= ((addr
>> ATMEL_AT45DB0X1B_PAGE_POS
) *
10501 tp
->nvram_pagesize
) +
10502 (addr
& ((1 << ATMEL_AT45DB0X1B_PAGE_POS
) - 1));
10507 static int tg3_nvram_read(struct tg3
*tp
, u32 offset
, u32
*val
)
10511 if (!(tp
->tg3_flags
& TG3_FLAG_NVRAM
))
10512 return tg3_nvram_read_using_eeprom(tp
, offset
, val
);
10514 offset
= tg3_nvram_phys_addr(tp
, offset
);
10516 if (offset
> NVRAM_ADDR_MSK
)
10519 ret
= tg3_nvram_lock(tp
);
10523 tg3_enable_nvram_access(tp
);
10525 tw32(NVRAM_ADDR
, offset
);
10526 ret
= tg3_nvram_exec_cmd(tp
, NVRAM_CMD_RD
| NVRAM_CMD_GO
|
10527 NVRAM_CMD_FIRST
| NVRAM_CMD_LAST
| NVRAM_CMD_DONE
);
10530 *val
= swab32(tr32(NVRAM_RDDATA
));
10532 tg3_disable_nvram_access(tp
);
10534 tg3_nvram_unlock(tp
);
10539 static int tg3_nvram_read_le(struct tg3
*tp
, u32 offset
, __le32
*val
)
10542 int res
= tg3_nvram_read(tp
, offset
, &v
);
10544 *val
= cpu_to_le32(v
);
10548 static int tg3_nvram_read_swab(struct tg3
*tp
, u32 offset
, u32
*val
)
10553 err
= tg3_nvram_read(tp
, offset
, &tmp
);
10554 *val
= swab32(tmp
);
10558 static int tg3_nvram_write_block_using_eeprom(struct tg3
*tp
,
10559 u32 offset
, u32 len
, u8
*buf
)
10564 for (i
= 0; i
< len
; i
+= 4) {
10570 memcpy(&data
, buf
+ i
, 4);
10572 tw32(GRC_EEPROM_DATA
, le32_to_cpu(data
));
10574 val
= tr32(GRC_EEPROM_ADDR
);
10575 tw32(GRC_EEPROM_ADDR
, val
| EEPROM_ADDR_COMPLETE
);
10577 val
&= ~(EEPROM_ADDR_ADDR_MASK
| EEPROM_ADDR_DEVID_MASK
|
10579 tw32(GRC_EEPROM_ADDR
, val
|
10580 (0 << EEPROM_ADDR_DEVID_SHIFT
) |
10581 (addr
& EEPROM_ADDR_ADDR_MASK
) |
10582 EEPROM_ADDR_START
|
10583 EEPROM_ADDR_WRITE
);
10585 for (j
= 0; j
< 1000; j
++) {
10586 val
= tr32(GRC_EEPROM_ADDR
);
10588 if (val
& EEPROM_ADDR_COMPLETE
)
10592 if (!(val
& EEPROM_ADDR_COMPLETE
)) {
10601 /* offset and length are dword aligned */
10602 static int tg3_nvram_write_block_unbuffered(struct tg3
*tp
, u32 offset
, u32 len
,
10606 u32 pagesize
= tp
->nvram_pagesize
;
10607 u32 pagemask
= pagesize
- 1;
10611 tmp
= kmalloc(pagesize
, GFP_KERNEL
);
10617 u32 phy_addr
, page_off
, size
;
10619 phy_addr
= offset
& ~pagemask
;
10621 for (j
= 0; j
< pagesize
; j
+= 4) {
10622 if ((ret
= tg3_nvram_read_le(tp
, phy_addr
+ j
,
10623 (__le32
*) (tmp
+ j
))))
10629 page_off
= offset
& pagemask
;
10636 memcpy(tmp
+ page_off
, buf
, size
);
10638 offset
= offset
+ (pagesize
- page_off
);
10640 tg3_enable_nvram_access(tp
);
10643 * Before we can erase the flash page, we need
10644 * to issue a special "write enable" command.
10646 nvram_cmd
= NVRAM_CMD_WREN
| NVRAM_CMD_GO
| NVRAM_CMD_DONE
;
10648 if (tg3_nvram_exec_cmd(tp
, nvram_cmd
))
10651 /* Erase the target page */
10652 tw32(NVRAM_ADDR
, phy_addr
);
10654 nvram_cmd
= NVRAM_CMD_GO
| NVRAM_CMD_DONE
| NVRAM_CMD_WR
|
10655 NVRAM_CMD_FIRST
| NVRAM_CMD_LAST
| NVRAM_CMD_ERASE
;
10657 if (tg3_nvram_exec_cmd(tp
, nvram_cmd
))
10660 /* Issue another write enable to start the write. */
10661 nvram_cmd
= NVRAM_CMD_WREN
| NVRAM_CMD_GO
| NVRAM_CMD_DONE
;
10663 if (tg3_nvram_exec_cmd(tp
, nvram_cmd
))
10666 for (j
= 0; j
< pagesize
; j
+= 4) {
10669 data
= *((__be32
*) (tmp
+ j
));
10670 /* swab32(le32_to_cpu(data)), actually */
10671 tw32(NVRAM_WRDATA
, be32_to_cpu(data
));
10673 tw32(NVRAM_ADDR
, phy_addr
+ j
);
10675 nvram_cmd
= NVRAM_CMD_GO
| NVRAM_CMD_DONE
|
10679 nvram_cmd
|= NVRAM_CMD_FIRST
;
10680 else if (j
== (pagesize
- 4))
10681 nvram_cmd
|= NVRAM_CMD_LAST
;
10683 if ((ret
= tg3_nvram_exec_cmd(tp
, nvram_cmd
)))
10690 nvram_cmd
= NVRAM_CMD_WRDI
| NVRAM_CMD_GO
| NVRAM_CMD_DONE
;
10691 tg3_nvram_exec_cmd(tp
, nvram_cmd
);
10698 /* offset and length are dword aligned */
10699 static int tg3_nvram_write_block_buffered(struct tg3
*tp
, u32 offset
, u32 len
,
10704 for (i
= 0; i
< len
; i
+= 4, offset
+= 4) {
10705 u32 page_off
, phy_addr
, nvram_cmd
;
10708 memcpy(&data
, buf
+ i
, 4);
10709 tw32(NVRAM_WRDATA
, be32_to_cpu(data
));
10711 page_off
= offset
% tp
->nvram_pagesize
;
10713 phy_addr
= tg3_nvram_phys_addr(tp
, offset
);
10715 tw32(NVRAM_ADDR
, phy_addr
);
10717 nvram_cmd
= NVRAM_CMD_GO
| NVRAM_CMD_DONE
| NVRAM_CMD_WR
;
10719 if ((page_off
== 0) || (i
== 0))
10720 nvram_cmd
|= NVRAM_CMD_FIRST
;
10721 if (page_off
== (tp
->nvram_pagesize
- 4))
10722 nvram_cmd
|= NVRAM_CMD_LAST
;
10724 if (i
== (len
- 4))
10725 nvram_cmd
|= NVRAM_CMD_LAST
;
10727 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) != ASIC_REV_5752
&&
10728 !(tp
->tg3_flags3
& TG3_FLG3_5755_PLUS
) &&
10729 (tp
->nvram_jedecnum
== JEDEC_ST
) &&
10730 (nvram_cmd
& NVRAM_CMD_FIRST
)) {
10732 if ((ret
= tg3_nvram_exec_cmd(tp
,
10733 NVRAM_CMD_WREN
| NVRAM_CMD_GO
|
10738 if (!(tp
->tg3_flags2
& TG3_FLG2_FLASH
)) {
10739 /* We always do complete word writes to eeprom. */
10740 nvram_cmd
|= (NVRAM_CMD_FIRST
| NVRAM_CMD_LAST
);
10743 if ((ret
= tg3_nvram_exec_cmd(tp
, nvram_cmd
)))
10749 /* offset and length are dword aligned */
10750 static int tg3_nvram_write_block(struct tg3
*tp
, u32 offset
, u32 len
, u8
*buf
)
10754 if (tp
->tg3_flags
& TG3_FLAG_EEPROM_WRITE_PROT
) {
10755 tw32_f(GRC_LOCAL_CTRL
, tp
->grc_local_ctrl
&
10756 ~GRC_LCLCTRL_GPIO_OUTPUT1
);
10760 if (!(tp
->tg3_flags
& TG3_FLAG_NVRAM
)) {
10761 ret
= tg3_nvram_write_block_using_eeprom(tp
, offset
, len
, buf
);
10766 ret
= tg3_nvram_lock(tp
);
10770 tg3_enable_nvram_access(tp
);
10771 if ((tp
->tg3_flags2
& TG3_FLG2_5750_PLUS
) &&
10772 !(tp
->tg3_flags2
& TG3_FLG2_PROTECTED_NVRAM
))
10773 tw32(NVRAM_WRITE1
, 0x406);
10775 grc_mode
= tr32(GRC_MODE
);
10776 tw32(GRC_MODE
, grc_mode
| GRC_MODE_NVRAM_WR_ENABLE
);
10778 if ((tp
->tg3_flags
& TG3_FLAG_NVRAM_BUFFERED
) ||
10779 !(tp
->tg3_flags2
& TG3_FLG2_FLASH
)) {
10781 ret
= tg3_nvram_write_block_buffered(tp
, offset
, len
,
10785 ret
= tg3_nvram_write_block_unbuffered(tp
, offset
, len
,
10789 grc_mode
= tr32(GRC_MODE
);
10790 tw32(GRC_MODE
, grc_mode
& ~GRC_MODE_NVRAM_WR_ENABLE
);
10792 tg3_disable_nvram_access(tp
);
10793 tg3_nvram_unlock(tp
);
10796 if (tp
->tg3_flags
& TG3_FLAG_EEPROM_WRITE_PROT
) {
10797 tw32_f(GRC_LOCAL_CTRL
, tp
->grc_local_ctrl
);
10804 struct subsys_tbl_ent
{
10805 u16 subsys_vendor
, subsys_devid
;
10809 static struct subsys_tbl_ent subsys_id_to_phy_id
[] = {
10810 /* Broadcom boards. */
10811 { PCI_VENDOR_ID_BROADCOM
, 0x1644, PHY_ID_BCM5401
}, /* BCM95700A6 */
10812 { PCI_VENDOR_ID_BROADCOM
, 0x0001, PHY_ID_BCM5701
}, /* BCM95701A5 */
10813 { PCI_VENDOR_ID_BROADCOM
, 0x0002, PHY_ID_BCM8002
}, /* BCM95700T6 */
10814 { PCI_VENDOR_ID_BROADCOM
, 0x0003, 0 }, /* BCM95700A9 */
10815 { PCI_VENDOR_ID_BROADCOM
, 0x0005, PHY_ID_BCM5701
}, /* BCM95701T1 */
10816 { PCI_VENDOR_ID_BROADCOM
, 0x0006, PHY_ID_BCM5701
}, /* BCM95701T8 */
10817 { PCI_VENDOR_ID_BROADCOM
, 0x0007, 0 }, /* BCM95701A7 */
10818 { PCI_VENDOR_ID_BROADCOM
, 0x0008, PHY_ID_BCM5701
}, /* BCM95701A10 */
10819 { PCI_VENDOR_ID_BROADCOM
, 0x8008, PHY_ID_BCM5701
}, /* BCM95701A12 */
10820 { PCI_VENDOR_ID_BROADCOM
, 0x0009, PHY_ID_BCM5703
}, /* BCM95703Ax1 */
10821 { PCI_VENDOR_ID_BROADCOM
, 0x8009, PHY_ID_BCM5703
}, /* BCM95703Ax2 */
10824 { PCI_VENDOR_ID_3COM
, 0x1000, PHY_ID_BCM5401
}, /* 3C996T */
10825 { PCI_VENDOR_ID_3COM
, 0x1006, PHY_ID_BCM5701
}, /* 3C996BT */
10826 { PCI_VENDOR_ID_3COM
, 0x1004, 0 }, /* 3C996SX */
10827 { PCI_VENDOR_ID_3COM
, 0x1007, PHY_ID_BCM5701
}, /* 3C1000T */
10828 { PCI_VENDOR_ID_3COM
, 0x1008, PHY_ID_BCM5701
}, /* 3C940BR01 */
10831 { PCI_VENDOR_ID_DELL
, 0x00d1, PHY_ID_BCM5401
}, /* VIPER */
10832 { PCI_VENDOR_ID_DELL
, 0x0106, PHY_ID_BCM5401
}, /* JAGUAR */
10833 { PCI_VENDOR_ID_DELL
, 0x0109, PHY_ID_BCM5411
}, /* MERLOT */
10834 { PCI_VENDOR_ID_DELL
, 0x010a, PHY_ID_BCM5411
}, /* SLIM_MERLOT */
10836 /* Compaq boards. */
10837 { PCI_VENDOR_ID_COMPAQ
, 0x007c, PHY_ID_BCM5701
}, /* BANSHEE */
10838 { PCI_VENDOR_ID_COMPAQ
, 0x009a, PHY_ID_BCM5701
}, /* BANSHEE_2 */
10839 { PCI_VENDOR_ID_COMPAQ
, 0x007d, 0 }, /* CHANGELING */
10840 { PCI_VENDOR_ID_COMPAQ
, 0x0085, PHY_ID_BCM5701
}, /* NC7780 */
10841 { PCI_VENDOR_ID_COMPAQ
, 0x0099, PHY_ID_BCM5701
}, /* NC7780_2 */
10844 { PCI_VENDOR_ID_IBM
, 0x0281, 0 } /* IBM??? */
10847 static inline struct subsys_tbl_ent
*lookup_by_subsys(struct tg3
*tp
)
10851 for (i
= 0; i
< ARRAY_SIZE(subsys_id_to_phy_id
); i
++) {
10852 if ((subsys_id_to_phy_id
[i
].subsys_vendor
==
10853 tp
->pdev
->subsystem_vendor
) &&
10854 (subsys_id_to_phy_id
[i
].subsys_devid
==
10855 tp
->pdev
->subsystem_device
))
10856 return &subsys_id_to_phy_id
[i
];
10861 static void __devinit
tg3_get_eeprom_hw_cfg(struct tg3
*tp
)
10866 /* On some early chips the SRAM cannot be accessed in D3hot state,
10867 * so need make sure we're in D0.
10869 pci_read_config_word(tp
->pdev
, tp
->pm_cap
+ PCI_PM_CTRL
, &pmcsr
);
10870 pmcsr
&= ~PCI_PM_CTRL_STATE_MASK
;
10871 pci_write_config_word(tp
->pdev
, tp
->pm_cap
+ PCI_PM_CTRL
, pmcsr
);
10874 /* Make sure register accesses (indirect or otherwise)
10875 * will function correctly.
10877 pci_write_config_dword(tp
->pdev
, TG3PCI_MISC_HOST_CTRL
,
10878 tp
->misc_host_ctrl
);
10880 /* The memory arbiter has to be enabled in order for SRAM accesses
10881 * to succeed. Normally on powerup the tg3 chip firmware will make
10882 * sure it is enabled, but other entities such as system netboot
10883 * code might disable it.
10885 val
= tr32(MEMARB_MODE
);
10886 tw32(MEMARB_MODE
, val
| MEMARB_MODE_ENABLE
);
10888 tp
->phy_id
= PHY_ID_INVALID
;
10889 tp
->led_ctrl
= LED_CTRL_MODE_PHY_1
;
10891 /* Assume an onboard device and WOL capable by default. */
10892 tp
->tg3_flags
|= TG3_FLAG_EEPROM_WRITE_PROT
| TG3_FLAG_WOL_CAP
;
10894 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5906
) {
10895 if (!(tr32(PCIE_TRANSACTION_CFG
) & PCIE_TRANS_CFG_LOM
)) {
10896 tp
->tg3_flags
&= ~TG3_FLAG_EEPROM_WRITE_PROT
;
10897 tp
->tg3_flags2
|= TG3_FLG2_IS_NIC
;
10899 val
= tr32(VCPU_CFGSHDW
);
10900 if (val
& VCPU_CFGSHDW_ASPM_DBNC
)
10901 tp
->tg3_flags
|= TG3_FLAG_ASPM_WORKAROUND
;
10902 if ((val
& VCPU_CFGSHDW_WOL_ENABLE
) &&
10903 (val
& VCPU_CFGSHDW_WOL_MAGPKT
))
10904 tp
->tg3_flags
|= TG3_FLAG_WOL_ENABLE
;
10908 tg3_read_mem(tp
, NIC_SRAM_DATA_SIG
, &val
);
10909 if (val
== NIC_SRAM_DATA_SIG_MAGIC
) {
10910 u32 nic_cfg
, led_cfg
;
10911 u32 nic_phy_id
, ver
, cfg2
= 0, cfg4
= 0, eeprom_phy_id
;
10912 int eeprom_phy_serdes
= 0;
10914 tg3_read_mem(tp
, NIC_SRAM_DATA_CFG
, &nic_cfg
);
10915 tp
->nic_sram_data_cfg
= nic_cfg
;
10917 tg3_read_mem(tp
, NIC_SRAM_DATA_VER
, &ver
);
10918 ver
>>= NIC_SRAM_DATA_VER_SHIFT
;
10919 if ((GET_ASIC_REV(tp
->pci_chip_rev_id
) != ASIC_REV_5700
) &&
10920 (GET_ASIC_REV(tp
->pci_chip_rev_id
) != ASIC_REV_5701
) &&
10921 (GET_ASIC_REV(tp
->pci_chip_rev_id
) != ASIC_REV_5703
) &&
10922 (ver
> 0) && (ver
< 0x100))
10923 tg3_read_mem(tp
, NIC_SRAM_DATA_CFG_2
, &cfg2
);
10925 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5785
)
10926 tg3_read_mem(tp
, NIC_SRAM_DATA_CFG_4
, &cfg4
);
10928 if ((nic_cfg
& NIC_SRAM_DATA_CFG_PHY_TYPE_MASK
) ==
10929 NIC_SRAM_DATA_CFG_PHY_TYPE_FIBER
)
10930 eeprom_phy_serdes
= 1;
10932 tg3_read_mem(tp
, NIC_SRAM_DATA_PHY_ID
, &nic_phy_id
);
10933 if (nic_phy_id
!= 0) {
10934 u32 id1
= nic_phy_id
& NIC_SRAM_DATA_PHY_ID1_MASK
;
10935 u32 id2
= nic_phy_id
& NIC_SRAM_DATA_PHY_ID2_MASK
;
10937 eeprom_phy_id
= (id1
>> 16) << 10;
10938 eeprom_phy_id
|= (id2
& 0xfc00) << 16;
10939 eeprom_phy_id
|= (id2
& 0x03ff) << 0;
10943 tp
->phy_id
= eeprom_phy_id
;
10944 if (eeprom_phy_serdes
) {
10945 if (tp
->tg3_flags2
& TG3_FLG2_5780_CLASS
)
10946 tp
->tg3_flags2
|= TG3_FLG2_MII_SERDES
;
10948 tp
->tg3_flags2
|= TG3_FLG2_PHY_SERDES
;
10951 if (tp
->tg3_flags2
& TG3_FLG2_5750_PLUS
)
10952 led_cfg
= cfg2
& (NIC_SRAM_DATA_CFG_LED_MODE_MASK
|
10953 SHASTA_EXT_LED_MODE_MASK
);
10955 led_cfg
= nic_cfg
& NIC_SRAM_DATA_CFG_LED_MODE_MASK
;
10959 case NIC_SRAM_DATA_CFG_LED_MODE_PHY_1
:
10960 tp
->led_ctrl
= LED_CTRL_MODE_PHY_1
;
10963 case NIC_SRAM_DATA_CFG_LED_MODE_PHY_2
:
10964 tp
->led_ctrl
= LED_CTRL_MODE_PHY_2
;
10967 case NIC_SRAM_DATA_CFG_LED_MODE_MAC
:
10968 tp
->led_ctrl
= LED_CTRL_MODE_MAC
;
10970 /* Default to PHY_1_MODE if 0 (MAC_MODE) is
10971 * read on some older 5700/5701 bootcode.
10973 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) ==
10975 GET_ASIC_REV(tp
->pci_chip_rev_id
) ==
10977 tp
->led_ctrl
= LED_CTRL_MODE_PHY_1
;
10981 case SHASTA_EXT_LED_SHARED
:
10982 tp
->led_ctrl
= LED_CTRL_MODE_SHARED
;
10983 if (tp
->pci_chip_rev_id
!= CHIPREV_ID_5750_A0
&&
10984 tp
->pci_chip_rev_id
!= CHIPREV_ID_5750_A1
)
10985 tp
->led_ctrl
|= (LED_CTRL_MODE_PHY_1
|
10986 LED_CTRL_MODE_PHY_2
);
10989 case SHASTA_EXT_LED_MAC
:
10990 tp
->led_ctrl
= LED_CTRL_MODE_SHASTA_MAC
;
10993 case SHASTA_EXT_LED_COMBO
:
10994 tp
->led_ctrl
= LED_CTRL_MODE_COMBO
;
10995 if (tp
->pci_chip_rev_id
!= CHIPREV_ID_5750_A0
)
10996 tp
->led_ctrl
|= (LED_CTRL_MODE_PHY_1
|
10997 LED_CTRL_MODE_PHY_2
);
11002 if ((GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5700
||
11003 GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5701
) &&
11004 tp
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_DELL
)
11005 tp
->led_ctrl
= LED_CTRL_MODE_PHY_2
;
11007 if (GET_CHIP_REV(tp
->pci_chip_rev_id
) == CHIPREV_5784_AX
)
11008 tp
->led_ctrl
= LED_CTRL_MODE_PHY_1
;
11010 if (nic_cfg
& NIC_SRAM_DATA_CFG_EEPROM_WP
) {
11011 tp
->tg3_flags
|= TG3_FLAG_EEPROM_WRITE_PROT
;
11012 if ((tp
->pdev
->subsystem_vendor
==
11013 PCI_VENDOR_ID_ARIMA
) &&
11014 (tp
->pdev
->subsystem_device
== 0x205a ||
11015 tp
->pdev
->subsystem_device
== 0x2063))
11016 tp
->tg3_flags
&= ~TG3_FLAG_EEPROM_WRITE_PROT
;
11018 tp
->tg3_flags
&= ~TG3_FLAG_EEPROM_WRITE_PROT
;
11019 tp
->tg3_flags2
|= TG3_FLG2_IS_NIC
;
11022 if (nic_cfg
& NIC_SRAM_DATA_CFG_ASF_ENABLE
) {
11023 tp
->tg3_flags
|= TG3_FLAG_ENABLE_ASF
;
11024 if (tp
->tg3_flags2
& TG3_FLG2_5750_PLUS
)
11025 tp
->tg3_flags2
|= TG3_FLG2_ASF_NEW_HANDSHAKE
;
11028 if ((nic_cfg
& NIC_SRAM_DATA_CFG_APE_ENABLE
) &&
11029 (tp
->tg3_flags2
& TG3_FLG2_5750_PLUS
))
11030 tp
->tg3_flags3
|= TG3_FLG3_ENABLE_APE
;
11032 if (tp
->tg3_flags2
& TG3_FLG2_ANY_SERDES
&&
11033 !(nic_cfg
& NIC_SRAM_DATA_CFG_FIBER_WOL
))
11034 tp
->tg3_flags
&= ~TG3_FLAG_WOL_CAP
;
11036 if ((tp
->tg3_flags
& TG3_FLAG_WOL_CAP
) &&
11037 (nic_cfg
& NIC_SRAM_DATA_CFG_WOL_ENABLE
))
11038 tp
->tg3_flags
|= TG3_FLAG_WOL_ENABLE
;
11040 if (cfg2
& (1 << 17))
11041 tp
->tg3_flags2
|= TG3_FLG2_CAPACITIVE_COUPLING
;
11043 /* serdes signal pre-emphasis in register 0x590 set by */
11044 /* bootcode if bit 18 is set */
11045 if (cfg2
& (1 << 18))
11046 tp
->tg3_flags2
|= TG3_FLG2_SERDES_PREEMPHASIS
;
11048 if (((GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5784
&&
11049 GET_CHIP_REV(tp
->pci_chip_rev_id
) != CHIPREV_5784_AX
)) &&
11050 (cfg2
& NIC_SRAM_DATA_CFG_2_APD_EN
))
11051 tp
->tg3_flags3
|= TG3_FLG3_PHY_ENABLE_APD
;
11053 if (tp
->tg3_flags2
& TG3_FLG2_PCI_EXPRESS
) {
11056 tg3_read_mem(tp
, NIC_SRAM_DATA_CFG_3
, &cfg3
);
11057 if (cfg3
& NIC_SRAM_ASPM_DEBOUNCE
)
11058 tp
->tg3_flags
|= TG3_FLAG_ASPM_WORKAROUND
;
11061 if (cfg4
& NIC_SRAM_RGMII_STD_IBND_DISABLE
)
11062 tp
->tg3_flags3
|= TG3_FLG3_RGMII_STD_IBND_DISABLE
;
11063 if (cfg4
& NIC_SRAM_RGMII_EXT_IBND_RX_EN
)
11064 tp
->tg3_flags3
|= TG3_FLG3_RGMII_EXT_IBND_RX_EN
;
11065 if (cfg4
& NIC_SRAM_RGMII_EXT_IBND_TX_EN
)
11066 tp
->tg3_flags3
|= TG3_FLG3_RGMII_EXT_IBND_TX_EN
;
11069 device_init_wakeup(&tp
->pdev
->dev
, tp
->tg3_flags
& TG3_FLAG_WOL_CAP
);
11070 device_set_wakeup_enable(&tp
->pdev
->dev
,
11071 tp
->tg3_flags
& TG3_FLAG_WOL_ENABLE
);
11074 static int __devinit
tg3_issue_otp_command(struct tg3
*tp
, u32 cmd
)
11079 tw32(OTP_CTRL
, cmd
| OTP_CTRL_OTP_CMD_START
);
11080 tw32(OTP_CTRL
, cmd
);
11082 /* Wait for up to 1 ms for command to execute. */
11083 for (i
= 0; i
< 100; i
++) {
11084 val
= tr32(OTP_STATUS
);
11085 if (val
& OTP_STATUS_CMD_DONE
)
11090 return (val
& OTP_STATUS_CMD_DONE
) ? 0 : -EBUSY
;
11093 /* Read the gphy configuration from the OTP region of the chip. The gphy
11094 * configuration is a 32-bit value that straddles the alignment boundary.
11095 * We do two 32-bit reads and then shift and merge the results.
11097 static u32 __devinit
tg3_read_otp_phycfg(struct tg3
*tp
)
11099 u32 bhalf_otp
, thalf_otp
;
11101 tw32(OTP_MODE
, OTP_MODE_OTP_THRU_GRC
);
11103 if (tg3_issue_otp_command(tp
, OTP_CTRL_OTP_CMD_INIT
))
11106 tw32(OTP_ADDRESS
, OTP_ADDRESS_MAGIC1
);
11108 if (tg3_issue_otp_command(tp
, OTP_CTRL_OTP_CMD_READ
))
11111 thalf_otp
= tr32(OTP_READ_DATA
);
11113 tw32(OTP_ADDRESS
, OTP_ADDRESS_MAGIC2
);
11115 if (tg3_issue_otp_command(tp
, OTP_CTRL_OTP_CMD_READ
))
11118 bhalf_otp
= tr32(OTP_READ_DATA
);
11120 return ((thalf_otp
& 0x0000ffff) << 16) | (bhalf_otp
>> 16);
11123 static int __devinit
tg3_phy_probe(struct tg3
*tp
)
11125 u32 hw_phy_id_1
, hw_phy_id_2
;
11126 u32 hw_phy_id
, hw_phy_id_masked
;
11129 if (tp
->tg3_flags3
& TG3_FLG3_USE_PHYLIB
)
11130 return tg3_phy_init(tp
);
11132 /* Reading the PHY ID register can conflict with ASF
11133 * firwmare access to the PHY hardware.
11136 if ((tp
->tg3_flags
& TG3_FLAG_ENABLE_ASF
) ||
11137 (tp
->tg3_flags3
& TG3_FLG3_ENABLE_APE
)) {
11138 hw_phy_id
= hw_phy_id_masked
= PHY_ID_INVALID
;
11140 /* Now read the physical PHY_ID from the chip and verify
11141 * that it is sane. If it doesn't look good, we fall back
11142 * to either the hard-coded table based PHY_ID and failing
11143 * that the value found in the eeprom area.
11145 err
|= tg3_readphy(tp
, MII_PHYSID1
, &hw_phy_id_1
);
11146 err
|= tg3_readphy(tp
, MII_PHYSID2
, &hw_phy_id_2
);
11148 hw_phy_id
= (hw_phy_id_1
& 0xffff) << 10;
11149 hw_phy_id
|= (hw_phy_id_2
& 0xfc00) << 16;
11150 hw_phy_id
|= (hw_phy_id_2
& 0x03ff) << 0;
11152 hw_phy_id_masked
= hw_phy_id
& PHY_ID_MASK
;
11155 if (!err
&& KNOWN_PHY_ID(hw_phy_id_masked
)) {
11156 tp
->phy_id
= hw_phy_id
;
11157 if (hw_phy_id_masked
== PHY_ID_BCM8002
)
11158 tp
->tg3_flags2
|= TG3_FLG2_PHY_SERDES
;
11160 tp
->tg3_flags2
&= ~TG3_FLG2_PHY_SERDES
;
11162 if (tp
->phy_id
!= PHY_ID_INVALID
) {
11163 /* Do nothing, phy ID already set up in
11164 * tg3_get_eeprom_hw_cfg().
11167 struct subsys_tbl_ent
*p
;
11169 /* No eeprom signature? Try the hardcoded
11170 * subsys device table.
11172 p
= lookup_by_subsys(tp
);
11176 tp
->phy_id
= p
->phy_id
;
11178 tp
->phy_id
== PHY_ID_BCM8002
)
11179 tp
->tg3_flags2
|= TG3_FLG2_PHY_SERDES
;
11183 if (!(tp
->tg3_flags2
& TG3_FLG2_ANY_SERDES
) &&
11184 !(tp
->tg3_flags3
& TG3_FLG3_ENABLE_APE
) &&
11185 !(tp
->tg3_flags
& TG3_FLAG_ENABLE_ASF
)) {
11186 u32 bmsr
, adv_reg
, tg3_ctrl
, mask
;
11188 tg3_readphy(tp
, MII_BMSR
, &bmsr
);
11189 if (!tg3_readphy(tp
, MII_BMSR
, &bmsr
) &&
11190 (bmsr
& BMSR_LSTATUS
))
11191 goto skip_phy_reset
;
11193 err
= tg3_phy_reset(tp
);
11197 adv_reg
= (ADVERTISE_10HALF
| ADVERTISE_10FULL
|
11198 ADVERTISE_100HALF
| ADVERTISE_100FULL
|
11199 ADVERTISE_CSMA
| ADVERTISE_PAUSE_CAP
);
11201 if (!(tp
->tg3_flags
& TG3_FLAG_10_100_ONLY
)) {
11202 tg3_ctrl
= (MII_TG3_CTRL_ADV_1000_HALF
|
11203 MII_TG3_CTRL_ADV_1000_FULL
);
11204 if (tp
->pci_chip_rev_id
== CHIPREV_ID_5701_A0
||
11205 tp
->pci_chip_rev_id
== CHIPREV_ID_5701_B0
)
11206 tg3_ctrl
|= (MII_TG3_CTRL_AS_MASTER
|
11207 MII_TG3_CTRL_ENABLE_AS_MASTER
);
11210 mask
= (ADVERTISED_10baseT_Half
| ADVERTISED_10baseT_Full
|
11211 ADVERTISED_100baseT_Half
| ADVERTISED_100baseT_Full
|
11212 ADVERTISED_1000baseT_Half
| ADVERTISED_1000baseT_Full
);
11213 if (!tg3_copper_is_advertising_all(tp
, mask
)) {
11214 tg3_writephy(tp
, MII_ADVERTISE
, adv_reg
);
11216 if (!(tp
->tg3_flags
& TG3_FLAG_10_100_ONLY
))
11217 tg3_writephy(tp
, MII_TG3_CTRL
, tg3_ctrl
);
11219 tg3_writephy(tp
, MII_BMCR
,
11220 BMCR_ANENABLE
| BMCR_ANRESTART
);
11222 tg3_phy_set_wirespeed(tp
);
11224 tg3_writephy(tp
, MII_ADVERTISE
, adv_reg
);
11225 if (!(tp
->tg3_flags
& TG3_FLAG_10_100_ONLY
))
11226 tg3_writephy(tp
, MII_TG3_CTRL
, tg3_ctrl
);
11230 if ((tp
->phy_id
& PHY_ID_MASK
) == PHY_ID_BCM5401
) {
11231 err
= tg3_init_5401phy_dsp(tp
);
11236 if (!err
&& ((tp
->phy_id
& PHY_ID_MASK
) == PHY_ID_BCM5401
)) {
11237 err
= tg3_init_5401phy_dsp(tp
);
11240 if (tp
->tg3_flags2
& TG3_FLG2_ANY_SERDES
)
11241 tp
->link_config
.advertising
=
11242 (ADVERTISED_1000baseT_Half
|
11243 ADVERTISED_1000baseT_Full
|
11244 ADVERTISED_Autoneg
|
11246 if (tp
->tg3_flags
& TG3_FLAG_10_100_ONLY
)
11247 tp
->link_config
.advertising
&=
11248 ~(ADVERTISED_1000baseT_Half
|
11249 ADVERTISED_1000baseT_Full
);
11254 static void __devinit
tg3_read_partno(struct tg3
*tp
)
11256 unsigned char vpd_data
[256];
11260 if (tg3_nvram_read_swab(tp
, 0x0, &magic
))
11261 goto out_not_found
;
11263 if (magic
== TG3_EEPROM_MAGIC
) {
11264 for (i
= 0; i
< 256; i
+= 4) {
11267 if (tg3_nvram_read(tp
, 0x100 + i
, &tmp
))
11268 goto out_not_found
;
11270 vpd_data
[i
+ 0] = ((tmp
>> 0) & 0xff);
11271 vpd_data
[i
+ 1] = ((tmp
>> 8) & 0xff);
11272 vpd_data
[i
+ 2] = ((tmp
>> 16) & 0xff);
11273 vpd_data
[i
+ 3] = ((tmp
>> 24) & 0xff);
11278 vpd_cap
= pci_find_capability(tp
->pdev
, PCI_CAP_ID_VPD
);
11279 for (i
= 0; i
< 256; i
+= 4) {
11284 pci_write_config_word(tp
->pdev
, vpd_cap
+ PCI_VPD_ADDR
,
11286 while (j
++ < 100) {
11287 pci_read_config_word(tp
->pdev
, vpd_cap
+
11288 PCI_VPD_ADDR
, &tmp16
);
11289 if (tmp16
& 0x8000)
11293 if (!(tmp16
& 0x8000))
11294 goto out_not_found
;
11296 pci_read_config_dword(tp
->pdev
, vpd_cap
+ PCI_VPD_DATA
,
11298 v
= cpu_to_le32(tmp
);
11299 memcpy(&vpd_data
[i
], &v
, 4);
11303 /* Now parse and find the part number. */
11304 for (i
= 0; i
< 254; ) {
11305 unsigned char val
= vpd_data
[i
];
11306 unsigned int block_end
;
11308 if (val
== 0x82 || val
== 0x91) {
11311 (vpd_data
[i
+ 2] << 8)));
11316 goto out_not_found
;
11318 block_end
= (i
+ 3 +
11320 (vpd_data
[i
+ 2] << 8)));
11323 if (block_end
> 256)
11324 goto out_not_found
;
11326 while (i
< (block_end
- 2)) {
11327 if (vpd_data
[i
+ 0] == 'P' &&
11328 vpd_data
[i
+ 1] == 'N') {
11329 int partno_len
= vpd_data
[i
+ 2];
11332 if (partno_len
> 24 || (partno_len
+ i
) > 256)
11333 goto out_not_found
;
11335 memcpy(tp
->board_part_number
,
11336 &vpd_data
[i
], partno_len
);
11341 i
+= 3 + vpd_data
[i
+ 2];
11344 /* Part number not found. */
11345 goto out_not_found
;
11349 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5906
)
11350 strcpy(tp
->board_part_number
, "BCM95906");
11352 strcpy(tp
->board_part_number
, "none");
11355 static int __devinit
tg3_fw_img_is_valid(struct tg3
*tp
, u32 offset
)
11359 if (tg3_nvram_read_swab(tp
, offset
, &val
) ||
11360 (val
& 0xfc000000) != 0x0c000000 ||
11361 tg3_nvram_read_swab(tp
, offset
+ 4, &val
) ||
11368 static void __devinit
tg3_read_sb_ver(struct tg3
*tp
, u32 val
)
11370 u32 offset
, major
, minor
, build
;
11372 tp
->fw_ver
[0] = 's';
11373 tp
->fw_ver
[1] = 'b';
11374 tp
->fw_ver
[2] = '\0';
11376 if ((val
& TG3_EEPROM_SB_FORMAT_MASK
) != TG3_EEPROM_SB_FORMAT_1
)
11379 switch (val
& TG3_EEPROM_SB_REVISION_MASK
) {
11380 case TG3_EEPROM_SB_REVISION_0
:
11381 offset
= TG3_EEPROM_SB_F1R0_EDH_OFF
;
11383 case TG3_EEPROM_SB_REVISION_2
:
11384 offset
= TG3_EEPROM_SB_F1R2_EDH_OFF
;
11386 case TG3_EEPROM_SB_REVISION_3
:
11387 offset
= TG3_EEPROM_SB_F1R3_EDH_OFF
;
11393 if (tg3_nvram_read_swab(tp
, offset
, &val
))
11396 build
= (val
& TG3_EEPROM_SB_EDH_BLD_MASK
) >>
11397 TG3_EEPROM_SB_EDH_BLD_SHFT
;
11398 major
= (val
& TG3_EEPROM_SB_EDH_MAJ_MASK
) >>
11399 TG3_EEPROM_SB_EDH_MAJ_SHFT
;
11400 minor
= val
& TG3_EEPROM_SB_EDH_MIN_MASK
;
11402 if (minor
> 99 || build
> 26)
11405 snprintf(&tp
->fw_ver
[2], 30, " v%d.%02d", major
, minor
);
11408 tp
->fw_ver
[8] = 'a' + build
- 1;
11409 tp
->fw_ver
[9] = '\0';
11413 static void __devinit
tg3_read_fw_ver(struct tg3
*tp
)
11415 u32 val
, offset
, start
;
11419 if (tg3_nvram_read_swab(tp
, 0, &val
))
11422 if (val
!= TG3_EEPROM_MAGIC
) {
11423 if ((val
& TG3_EEPROM_MAGIC_FW_MSK
) == TG3_EEPROM_MAGIC_FW
)
11424 tg3_read_sb_ver(tp
, val
);
11429 if (tg3_nvram_read_swab(tp
, 0xc, &offset
) ||
11430 tg3_nvram_read_swab(tp
, 0x4, &start
))
11433 offset
= tg3_nvram_logical_addr(tp
, offset
);
11435 if (!tg3_fw_img_is_valid(tp
, offset
) ||
11436 tg3_nvram_read_swab(tp
, offset
+ 8, &ver_offset
))
11439 offset
= offset
+ ver_offset
- start
;
11440 for (i
= 0; i
< 16; i
+= 4) {
11442 if (tg3_nvram_read_le(tp
, offset
+ i
, &v
))
11445 memcpy(tp
->fw_ver
+ i
, &v
, 4);
11448 if (!(tp
->tg3_flags
& TG3_FLAG_ENABLE_ASF
) ||
11449 (tp
->tg3_flags3
& TG3_FLG3_ENABLE_APE
))
11452 for (offset
= TG3_NVM_DIR_START
;
11453 offset
< TG3_NVM_DIR_END
;
11454 offset
+= TG3_NVM_DIRENT_SIZE
) {
11455 if (tg3_nvram_read_swab(tp
, offset
, &val
))
11458 if ((val
>> TG3_NVM_DIRTYPE_SHIFT
) == TG3_NVM_DIRTYPE_ASFINI
)
11462 if (offset
== TG3_NVM_DIR_END
)
11465 if (!(tp
->tg3_flags2
& TG3_FLG2_5705_PLUS
))
11466 start
= 0x08000000;
11467 else if (tg3_nvram_read_swab(tp
, offset
- 4, &start
))
11470 if (tg3_nvram_read_swab(tp
, offset
+ 4, &offset
) ||
11471 !tg3_fw_img_is_valid(tp
, offset
) ||
11472 tg3_nvram_read_swab(tp
, offset
+ 8, &val
))
11475 offset
+= val
- start
;
11477 bcnt
= strlen(tp
->fw_ver
);
11479 tp
->fw_ver
[bcnt
++] = ',';
11480 tp
->fw_ver
[bcnt
++] = ' ';
11482 for (i
= 0; i
< 4; i
++) {
11484 if (tg3_nvram_read_le(tp
, offset
, &v
))
11487 offset
+= sizeof(v
);
11489 if (bcnt
> TG3_VER_SIZE
- sizeof(v
)) {
11490 memcpy(&tp
->fw_ver
[bcnt
], &v
, TG3_VER_SIZE
- bcnt
);
11494 memcpy(&tp
->fw_ver
[bcnt
], &v
, sizeof(v
));
11498 tp
->fw_ver
[TG3_VER_SIZE
- 1] = 0;
11501 static struct pci_dev
* __devinit
tg3_find_peer(struct tg3
*);
11503 static int __devinit
tg3_get_invariants(struct tg3
*tp
)
11505 static struct pci_device_id write_reorder_chipsets
[] = {
11506 { PCI_DEVICE(PCI_VENDOR_ID_AMD
,
11507 PCI_DEVICE_ID_AMD_FE_GATE_700C
) },
11508 { PCI_DEVICE(PCI_VENDOR_ID_AMD
,
11509 PCI_DEVICE_ID_AMD_8131_BRIDGE
) },
11510 { PCI_DEVICE(PCI_VENDOR_ID_VIA
,
11511 PCI_DEVICE_ID_VIA_8385_0
) },
11515 u32 pci_state_reg
, grc_misc_cfg
;
11520 /* Force memory write invalidate off. If we leave it on,
11521 * then on 5700_BX chips we have to enable a workaround.
11522 * The workaround is to set the TG3PCI_DMA_RW_CTRL boundary
11523 * to match the cacheline size. The Broadcom driver have this
11524 * workaround but turns MWI off all the times so never uses
11525 * it. This seems to suggest that the workaround is insufficient.
11527 pci_read_config_word(tp
->pdev
, PCI_COMMAND
, &pci_cmd
);
11528 pci_cmd
&= ~PCI_COMMAND_INVALIDATE
;
11529 pci_write_config_word(tp
->pdev
, PCI_COMMAND
, pci_cmd
);
11531 /* It is absolutely critical that TG3PCI_MISC_HOST_CTRL
11532 * has the register indirect write enable bit set before
11533 * we try to access any of the MMIO registers. It is also
11534 * critical that the PCI-X hw workaround situation is decided
11535 * before that as well.
11537 pci_read_config_dword(tp
->pdev
, TG3PCI_MISC_HOST_CTRL
,
11540 tp
->pci_chip_rev_id
= (misc_ctrl_reg
>>
11541 MISC_HOST_CTRL_CHIPREV_SHIFT
);
11542 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_USE_PROD_ID_REG
) {
11543 u32 prod_id_asic_rev
;
11545 pci_read_config_dword(tp
->pdev
, TG3PCI_PRODID_ASICREV
,
11546 &prod_id_asic_rev
);
11547 tp
->pci_chip_rev_id
= prod_id_asic_rev
;
11550 /* Wrong chip ID in 5752 A0. This code can be removed later
11551 * as A0 is not in production.
11553 if (tp
->pci_chip_rev_id
== CHIPREV_ID_5752_A0_HW
)
11554 tp
->pci_chip_rev_id
= CHIPREV_ID_5752_A0
;
11556 /* If we have 5702/03 A1 or A2 on certain ICH chipsets,
11557 * we need to disable memory and use config. cycles
11558 * only to access all registers. The 5702/03 chips
11559 * can mistakenly decode the special cycles from the
11560 * ICH chipsets as memory write cycles, causing corruption
11561 * of register and memory space. Only certain ICH bridges
11562 * will drive special cycles with non-zero data during the
11563 * address phase which can fall within the 5703's address
11564 * range. This is not an ICH bug as the PCI spec allows
11565 * non-zero address during special cycles. However, only
11566 * these ICH bridges are known to drive non-zero addresses
11567 * during special cycles.
11569 * Since special cycles do not cross PCI bridges, we only
11570 * enable this workaround if the 5703 is on the secondary
11571 * bus of these ICH bridges.
11573 if ((tp
->pci_chip_rev_id
== CHIPREV_ID_5703_A1
) ||
11574 (tp
->pci_chip_rev_id
== CHIPREV_ID_5703_A2
)) {
11575 static struct tg3_dev_id
{
11579 } ich_chipsets
[] = {
11580 { PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_82801AA_8
,
11582 { PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_82801AB_8
,
11584 { PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_82801BA_11
,
11586 { PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_82801BA_6
,
11590 struct tg3_dev_id
*pci_id
= &ich_chipsets
[0];
11591 struct pci_dev
*bridge
= NULL
;
11593 while (pci_id
->vendor
!= 0) {
11594 bridge
= pci_get_device(pci_id
->vendor
, pci_id
->device
,
11600 if (pci_id
->rev
!= PCI_ANY_ID
) {
11601 if (bridge
->revision
> pci_id
->rev
)
11604 if (bridge
->subordinate
&&
11605 (bridge
->subordinate
->number
==
11606 tp
->pdev
->bus
->number
)) {
11608 tp
->tg3_flags2
|= TG3_FLG2_ICH_WORKAROUND
;
11609 pci_dev_put(bridge
);
11615 if ((GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5701
)) {
11616 static struct tg3_dev_id
{
11619 } bridge_chipsets
[] = {
11620 { PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_PXH_0
},
11621 { PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_PXH_1
},
11624 struct tg3_dev_id
*pci_id
= &bridge_chipsets
[0];
11625 struct pci_dev
*bridge
= NULL
;
11627 while (pci_id
->vendor
!= 0) {
11628 bridge
= pci_get_device(pci_id
->vendor
,
11635 if (bridge
->subordinate
&&
11636 (bridge
->subordinate
->number
<=
11637 tp
->pdev
->bus
->number
) &&
11638 (bridge
->subordinate
->subordinate
>=
11639 tp
->pdev
->bus
->number
)) {
11640 tp
->tg3_flags3
|= TG3_FLG3_5701_DMA_BUG
;
11641 pci_dev_put(bridge
);
11647 /* The EPB bridge inside 5714, 5715, and 5780 cannot support
11648 * DMA addresses > 40-bit. This bridge may have other additional
11649 * 57xx devices behind it in some 4-port NIC designs for example.
11650 * Any tg3 device found behind the bridge will also need the 40-bit
11653 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5780
||
11654 GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5714
) {
11655 tp
->tg3_flags2
|= TG3_FLG2_5780_CLASS
;
11656 tp
->tg3_flags
|= TG3_FLAG_40BIT_DMA_BUG
;
11657 tp
->msi_cap
= pci_find_capability(tp
->pdev
, PCI_CAP_ID_MSI
);
11660 struct pci_dev
*bridge
= NULL
;
11663 bridge
= pci_get_device(PCI_VENDOR_ID_SERVERWORKS
,
11664 PCI_DEVICE_ID_SERVERWORKS_EPB
,
11666 if (bridge
&& bridge
->subordinate
&&
11667 (bridge
->subordinate
->number
<=
11668 tp
->pdev
->bus
->number
) &&
11669 (bridge
->subordinate
->subordinate
>=
11670 tp
->pdev
->bus
->number
)) {
11671 tp
->tg3_flags
|= TG3_FLAG_40BIT_DMA_BUG
;
11672 pci_dev_put(bridge
);
11678 /* Initialize misc host control in PCI block. */
11679 tp
->misc_host_ctrl
|= (misc_ctrl_reg
&
11680 MISC_HOST_CTRL_CHIPREV
);
11681 pci_write_config_dword(tp
->pdev
, TG3PCI_MISC_HOST_CTRL
,
11682 tp
->misc_host_ctrl
);
11684 if ((GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5704
) ||
11685 (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5714
))
11686 tp
->pdev_peer
= tg3_find_peer(tp
);
11688 /* Intentionally exclude ASIC_REV_5906 */
11689 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5755
||
11690 GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5787
||
11691 GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5784
||
11692 GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5761
||
11693 GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5785
||
11694 GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_57780
)
11695 tp
->tg3_flags3
|= TG3_FLG3_5755_PLUS
;
11697 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5750
||
11698 GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5752
||
11699 GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5906
||
11700 (tp
->tg3_flags3
& TG3_FLG3_5755_PLUS
) ||
11701 (tp
->tg3_flags2
& TG3_FLG2_5780_CLASS
))
11702 tp
->tg3_flags2
|= TG3_FLG2_5750_PLUS
;
11704 if ((GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5705
) ||
11705 (tp
->tg3_flags2
& TG3_FLG2_5750_PLUS
))
11706 tp
->tg3_flags2
|= TG3_FLG2_5705_PLUS
;
11708 /* 5700 B0 chips do not support checksumming correctly due
11709 * to hardware bugs.
11711 if (tp
->pci_chip_rev_id
== CHIPREV_ID_5700_B0
)
11712 tp
->tg3_flags
|= TG3_FLAG_BROKEN_CHECKSUMS
;
11714 tp
->tg3_flags
|= TG3_FLAG_RX_CHECKSUMS
;
11715 tp
->dev
->features
|= NETIF_F_IP_CSUM
| NETIF_F_SG
;
11716 if (tp
->tg3_flags3
& TG3_FLG3_5755_PLUS
)
11717 tp
->dev
->features
|= NETIF_F_IPV6_CSUM
;
11720 if (tp
->tg3_flags2
& TG3_FLG2_5750_PLUS
) {
11721 tp
->tg3_flags
|= TG3_FLAG_SUPPORT_MSI
;
11722 if (GET_CHIP_REV(tp
->pci_chip_rev_id
) == CHIPREV_5750_AX
||
11723 GET_CHIP_REV(tp
->pci_chip_rev_id
) == CHIPREV_5750_BX
||
11724 (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5714
&&
11725 tp
->pci_chip_rev_id
<= CHIPREV_ID_5714_A2
&&
11726 tp
->pdev_peer
== tp
->pdev
))
11727 tp
->tg3_flags
&= ~TG3_FLAG_SUPPORT_MSI
;
11729 if ((tp
->tg3_flags3
& TG3_FLG3_5755_PLUS
) ||
11730 GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5906
) {
11731 tp
->tg3_flags2
|= TG3_FLG2_HW_TSO_2
;
11732 tp
->tg3_flags2
|= TG3_FLG2_1SHOT_MSI
;
11734 tp
->tg3_flags2
|= TG3_FLG2_HW_TSO_1
| TG3_FLG2_TSO_BUG
;
11735 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) ==
11737 tp
->pci_chip_rev_id
>= CHIPREV_ID_5750_C2
)
11738 tp
->tg3_flags2
&= ~TG3_FLG2_TSO_BUG
;
11742 if (!(tp
->tg3_flags2
& TG3_FLG2_5705_PLUS
) ||
11743 (tp
->tg3_flags2
& TG3_FLG2_5780_CLASS
))
11744 tp
->tg3_flags2
|= TG3_FLG2_JUMBO_CAPABLE
;
11746 pci_read_config_dword(tp
->pdev
, TG3PCI_PCISTATE
,
11749 tp
->pcie_cap
= pci_find_capability(tp
->pdev
, PCI_CAP_ID_EXP
);
11750 if (tp
->pcie_cap
!= 0) {
11753 tp
->tg3_flags2
|= TG3_FLG2_PCI_EXPRESS
;
11755 pcie_set_readrq(tp
->pdev
, 4096);
11757 pci_read_config_word(tp
->pdev
,
11758 tp
->pcie_cap
+ PCI_EXP_LNKCTL
,
11760 if (lnkctl
& PCI_EXP_LNKCTL_CLKREQ_EN
) {
11761 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5906
)
11762 tp
->tg3_flags2
&= ~TG3_FLG2_HW_TSO_2
;
11763 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5784
||
11764 GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5761
||
11765 GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_57780
)
11766 tp
->tg3_flags3
|= TG3_FLG3_CLKREQ_BUG
;
11768 } else if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5785
) {
11769 tp
->tg3_flags2
|= TG3_FLG2_PCI_EXPRESS
;
11770 } else if (!(tp
->tg3_flags2
& TG3_FLG2_5705_PLUS
) ||
11771 (tp
->tg3_flags2
& TG3_FLG2_5780_CLASS
)) {
11772 tp
->pcix_cap
= pci_find_capability(tp
->pdev
, PCI_CAP_ID_PCIX
);
11773 if (!tp
->pcix_cap
) {
11774 printk(KERN_ERR PFX
"Cannot find PCI-X "
11775 "capability, aborting.\n");
11779 if (!(pci_state_reg
& PCISTATE_CONV_PCI_MODE
))
11780 tp
->tg3_flags
|= TG3_FLAG_PCIX_MODE
;
11783 /* If we have an AMD 762 or VIA K8T800 chipset, write
11784 * reordering to the mailbox registers done by the host
11785 * controller can cause major troubles. We read back from
11786 * every mailbox register write to force the writes to be
11787 * posted to the chip in order.
11789 if (pci_dev_present(write_reorder_chipsets
) &&
11790 !(tp
->tg3_flags2
& TG3_FLG2_PCI_EXPRESS
))
11791 tp
->tg3_flags
|= TG3_FLAG_MBOX_WRITE_REORDER
;
11793 pci_read_config_byte(tp
->pdev
, PCI_CACHE_LINE_SIZE
,
11794 &tp
->pci_cacheline_sz
);
11795 pci_read_config_byte(tp
->pdev
, PCI_LATENCY_TIMER
,
11796 &tp
->pci_lat_timer
);
11797 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5703
&&
11798 tp
->pci_lat_timer
< 64) {
11799 tp
->pci_lat_timer
= 64;
11800 pci_write_config_byte(tp
->pdev
, PCI_LATENCY_TIMER
,
11801 tp
->pci_lat_timer
);
11804 if (GET_CHIP_REV(tp
->pci_chip_rev_id
) == CHIPREV_5700_BX
) {
11805 /* 5700 BX chips need to have their TX producer index
11806 * mailboxes written twice to workaround a bug.
11808 tp
->tg3_flags
|= TG3_FLAG_TXD_MBOX_HWBUG
;
11810 /* If we are in PCI-X mode, enable register write workaround.
11812 * The workaround is to use indirect register accesses
11813 * for all chip writes not to mailbox registers.
11815 if (tp
->tg3_flags
& TG3_FLAG_PCIX_MODE
) {
11818 tp
->tg3_flags
|= TG3_FLAG_PCIX_TARGET_HWBUG
;
11820 /* The chip can have it's power management PCI config
11821 * space registers clobbered due to this bug.
11822 * So explicitly force the chip into D0 here.
11824 pci_read_config_dword(tp
->pdev
,
11825 tp
->pm_cap
+ PCI_PM_CTRL
,
11827 pm_reg
&= ~PCI_PM_CTRL_STATE_MASK
;
11828 pm_reg
|= PCI_PM_CTRL_PME_ENABLE
| 0 /* D0 */;
11829 pci_write_config_dword(tp
->pdev
,
11830 tp
->pm_cap
+ PCI_PM_CTRL
,
11833 /* Also, force SERR#/PERR# in PCI command. */
11834 pci_read_config_word(tp
->pdev
, PCI_COMMAND
, &pci_cmd
);
11835 pci_cmd
|= PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
;
11836 pci_write_config_word(tp
->pdev
, PCI_COMMAND
, pci_cmd
);
11840 if ((pci_state_reg
& PCISTATE_BUS_SPEED_HIGH
) != 0)
11841 tp
->tg3_flags
|= TG3_FLAG_PCI_HIGH_SPEED
;
11842 if ((pci_state_reg
& PCISTATE_BUS_32BIT
) != 0)
11843 tp
->tg3_flags
|= TG3_FLAG_PCI_32BIT
;
11845 /* Chip-specific fixup from Broadcom driver */
11846 if ((tp
->pci_chip_rev_id
== CHIPREV_ID_5704_A0
) &&
11847 (!(pci_state_reg
& PCISTATE_RETRY_SAME_DMA
))) {
11848 pci_state_reg
|= PCISTATE_RETRY_SAME_DMA
;
11849 pci_write_config_dword(tp
->pdev
, TG3PCI_PCISTATE
, pci_state_reg
);
11852 /* Default fast path register access methods */
11853 tp
->read32
= tg3_read32
;
11854 tp
->write32
= tg3_write32
;
11855 tp
->read32_mbox
= tg3_read32
;
11856 tp
->write32_mbox
= tg3_write32
;
11857 tp
->write32_tx_mbox
= tg3_write32
;
11858 tp
->write32_rx_mbox
= tg3_write32
;
11860 /* Various workaround register access methods */
11861 if (tp
->tg3_flags
& TG3_FLAG_PCIX_TARGET_HWBUG
)
11862 tp
->write32
= tg3_write_indirect_reg32
;
11863 else if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5701
||
11864 ((tp
->tg3_flags2
& TG3_FLG2_PCI_EXPRESS
) &&
11865 tp
->pci_chip_rev_id
== CHIPREV_ID_5750_A0
)) {
11867 * Back to back register writes can cause problems on these
11868 * chips, the workaround is to read back all reg writes
11869 * except those to mailbox regs.
11871 * See tg3_write_indirect_reg32().
11873 tp
->write32
= tg3_write_flush_reg32
;
11877 if ((tp
->tg3_flags
& TG3_FLAG_TXD_MBOX_HWBUG
) ||
11878 (tp
->tg3_flags
& TG3_FLAG_MBOX_WRITE_REORDER
)) {
11879 tp
->write32_tx_mbox
= tg3_write32_tx_mbox
;
11880 if (tp
->tg3_flags
& TG3_FLAG_MBOX_WRITE_REORDER
)
11881 tp
->write32_rx_mbox
= tg3_write_flush_reg32
;
11884 if (tp
->tg3_flags2
& TG3_FLG2_ICH_WORKAROUND
) {
11885 tp
->read32
= tg3_read_indirect_reg32
;
11886 tp
->write32
= tg3_write_indirect_reg32
;
11887 tp
->read32_mbox
= tg3_read_indirect_mbox
;
11888 tp
->write32_mbox
= tg3_write_indirect_mbox
;
11889 tp
->write32_tx_mbox
= tg3_write_indirect_mbox
;
11890 tp
->write32_rx_mbox
= tg3_write_indirect_mbox
;
11895 pci_read_config_word(tp
->pdev
, PCI_COMMAND
, &pci_cmd
);
11896 pci_cmd
&= ~PCI_COMMAND_MEMORY
;
11897 pci_write_config_word(tp
->pdev
, PCI_COMMAND
, pci_cmd
);
11899 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5906
) {
11900 tp
->read32_mbox
= tg3_read32_mbox_5906
;
11901 tp
->write32_mbox
= tg3_write32_mbox_5906
;
11902 tp
->write32_tx_mbox
= tg3_write32_mbox_5906
;
11903 tp
->write32_rx_mbox
= tg3_write32_mbox_5906
;
11906 if (tp
->write32
== tg3_write_indirect_reg32
||
11907 ((tp
->tg3_flags
& TG3_FLAG_PCIX_MODE
) &&
11908 (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5700
||
11909 GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5701
)))
11910 tp
->tg3_flags
|= TG3_FLAG_SRAM_USE_CONFIG
;
11912 /* Get eeprom hw config before calling tg3_set_power_state().
11913 * In particular, the TG3_FLG2_IS_NIC flag must be
11914 * determined before calling tg3_set_power_state() so that
11915 * we know whether or not to switch out of Vaux power.
11916 * When the flag is set, it means that GPIO1 is used for eeprom
11917 * write protect and also implies that it is a LOM where GPIOs
11918 * are not used to switch power.
11920 tg3_get_eeprom_hw_cfg(tp
);
11922 if (tp
->tg3_flags3
& TG3_FLG3_ENABLE_APE
) {
11923 /* Allow reads and writes to the
11924 * APE register and memory space.
11926 pci_state_reg
|= PCISTATE_ALLOW_APE_CTLSPC_WR
|
11927 PCISTATE_ALLOW_APE_SHMEM_WR
;
11928 pci_write_config_dword(tp
->pdev
, TG3PCI_PCISTATE
,
11932 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5784
||
11933 GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5761
||
11934 GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5785
||
11935 GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_57780
)
11936 tp
->tg3_flags
|= TG3_FLAG_CPMU_PRESENT
;
11938 /* Set up tp->grc_local_ctrl before calling tg3_set_power_state().
11939 * GPIO1 driven high will bring 5700's external PHY out of reset.
11940 * It is also used as eeprom write protect on LOMs.
11942 tp
->grc_local_ctrl
= GRC_LCLCTRL_INT_ON_ATTN
| GRC_LCLCTRL_AUTO_SEEPROM
;
11943 if ((GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5700
) ||
11944 (tp
->tg3_flags
& TG3_FLAG_EEPROM_WRITE_PROT
))
11945 tp
->grc_local_ctrl
|= (GRC_LCLCTRL_GPIO_OE1
|
11946 GRC_LCLCTRL_GPIO_OUTPUT1
);
11947 /* Unused GPIO3 must be driven as output on 5752 because there
11948 * are no pull-up resistors on unused GPIO pins.
11950 else if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5752
)
11951 tp
->grc_local_ctrl
|= GRC_LCLCTRL_GPIO_OE3
;
11953 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5755
||
11954 GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_57780
)
11955 tp
->grc_local_ctrl
|= GRC_LCLCTRL_GPIO_UART_SEL
;
11957 if (tp
->pdev
->device
== PCI_DEVICE_ID_TIGON3_5761
) {
11958 /* Turn off the debug UART. */
11959 tp
->grc_local_ctrl
|= GRC_LCLCTRL_GPIO_UART_SEL
;
11960 if (tp
->tg3_flags2
& TG3_FLG2_IS_NIC
)
11961 /* Keep VMain power. */
11962 tp
->grc_local_ctrl
|= GRC_LCLCTRL_GPIO_OE0
|
11963 GRC_LCLCTRL_GPIO_OUTPUT0
;
11966 /* Force the chip into D0. */
11967 err
= tg3_set_power_state(tp
, PCI_D0
);
11969 printk(KERN_ERR PFX
"(%s) transition to D0 failed\n",
11970 pci_name(tp
->pdev
));
11974 /* Derive initial jumbo mode from MTU assigned in
11975 * ether_setup() via the alloc_etherdev() call
11977 if (tp
->dev
->mtu
> ETH_DATA_LEN
&&
11978 !(tp
->tg3_flags2
& TG3_FLG2_5780_CLASS
))
11979 tp
->tg3_flags
|= TG3_FLAG_JUMBO_RING_ENABLE
;
11981 /* Determine WakeOnLan speed to use. */
11982 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5700
||
11983 tp
->pci_chip_rev_id
== CHIPREV_ID_5701_A0
||
11984 tp
->pci_chip_rev_id
== CHIPREV_ID_5701_B0
||
11985 tp
->pci_chip_rev_id
== CHIPREV_ID_5701_B2
) {
11986 tp
->tg3_flags
&= ~(TG3_FLAG_WOL_SPEED_100MB
);
11988 tp
->tg3_flags
|= TG3_FLAG_WOL_SPEED_100MB
;
11991 /* A few boards don't want Ethernet@WireSpeed phy feature */
11992 if ((GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5700
) ||
11993 ((GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5705
) &&
11994 (tp
->pci_chip_rev_id
!= CHIPREV_ID_5705_A0
) &&
11995 (tp
->pci_chip_rev_id
!= CHIPREV_ID_5705_A1
)) ||
11996 (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5906
) ||
11997 (tp
->tg3_flags2
& TG3_FLG2_ANY_SERDES
))
11998 tp
->tg3_flags2
|= TG3_FLG2_NO_ETH_WIRE_SPEED
;
12000 if (GET_CHIP_REV(tp
->pci_chip_rev_id
) == CHIPREV_5703_AX
||
12001 GET_CHIP_REV(tp
->pci_chip_rev_id
) == CHIPREV_5704_AX
)
12002 tp
->tg3_flags2
|= TG3_FLG2_PHY_ADC_BUG
;
12003 if (tp
->pci_chip_rev_id
== CHIPREV_ID_5704_A0
)
12004 tp
->tg3_flags2
|= TG3_FLG2_PHY_5704_A0_BUG
;
12006 if ((tp
->tg3_flags2
& TG3_FLG2_5705_PLUS
) &&
12007 GET_ASIC_REV(tp
->pci_chip_rev_id
) != ASIC_REV_5906
&&
12008 GET_ASIC_REV(tp
->pci_chip_rev_id
) != ASIC_REV_5785
&&
12009 GET_ASIC_REV(tp
->pci_chip_rev_id
) != ASIC_REV_57780
) {
12010 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5755
||
12011 GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5787
||
12012 GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5784
||
12013 GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5761
) {
12014 if (tp
->pdev
->device
!= PCI_DEVICE_ID_TIGON3_5756
&&
12015 tp
->pdev
->device
!= PCI_DEVICE_ID_TIGON3_5722
)
12016 tp
->tg3_flags2
|= TG3_FLG2_PHY_JITTER_BUG
;
12017 if (tp
->pdev
->device
== PCI_DEVICE_ID_TIGON3_5755M
)
12018 tp
->tg3_flags2
|= TG3_FLG2_PHY_ADJUST_TRIM
;
12020 tp
->tg3_flags2
|= TG3_FLG2_PHY_BER_BUG
;
12023 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5784
&&
12024 GET_CHIP_REV(tp
->pci_chip_rev_id
) != CHIPREV_5784_AX
) {
12025 tp
->phy_otp
= tg3_read_otp_phycfg(tp
);
12026 if (tp
->phy_otp
== 0)
12027 tp
->phy_otp
= TG3_OTP_DEFAULT
;
12030 if (tp
->tg3_flags
& TG3_FLAG_CPMU_PRESENT
)
12031 tp
->mi_mode
= MAC_MI_MODE_500KHZ_CONST
;
12033 tp
->mi_mode
= MAC_MI_MODE_BASE
;
12035 tp
->coalesce_mode
= 0;
12036 if (GET_CHIP_REV(tp
->pci_chip_rev_id
) != CHIPREV_5700_AX
&&
12037 GET_CHIP_REV(tp
->pci_chip_rev_id
) != CHIPREV_5700_BX
)
12038 tp
->coalesce_mode
|= HOSTCC_MODE_32BYTE
;
12040 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5785
||
12041 GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_57780
)
12042 tp
->tg3_flags3
|= TG3_FLG3_USE_PHYLIB
;
12044 err
= tg3_mdio_init(tp
);
12048 /* Initialize data/descriptor byte/word swapping. */
12049 val
= tr32(GRC_MODE
);
12050 val
&= GRC_MODE_HOST_STACKUP
;
12051 tw32(GRC_MODE
, val
| tp
->grc_mode
);
12053 tg3_switch_clocks(tp
);
12055 /* Clear this out for sanity. */
12056 tw32(TG3PCI_MEM_WIN_BASE_ADDR
, 0);
12058 pci_read_config_dword(tp
->pdev
, TG3PCI_PCISTATE
,
12060 if ((pci_state_reg
& PCISTATE_CONV_PCI_MODE
) == 0 &&
12061 (tp
->tg3_flags
& TG3_FLAG_PCIX_TARGET_HWBUG
) == 0) {
12062 u32 chiprevid
= GET_CHIP_REV_ID(tp
->misc_host_ctrl
);
12064 if (chiprevid
== CHIPREV_ID_5701_A0
||
12065 chiprevid
== CHIPREV_ID_5701_B0
||
12066 chiprevid
== CHIPREV_ID_5701_B2
||
12067 chiprevid
== CHIPREV_ID_5701_B5
) {
12068 void __iomem
*sram_base
;
12070 /* Write some dummy words into the SRAM status block
12071 * area, see if it reads back correctly. If the return
12072 * value is bad, force enable the PCIX workaround.
12074 sram_base
= tp
->regs
+ NIC_SRAM_WIN_BASE
+ NIC_SRAM_STATS_BLK
;
12076 writel(0x00000000, sram_base
);
12077 writel(0x00000000, sram_base
+ 4);
12078 writel(0xffffffff, sram_base
+ 4);
12079 if (readl(sram_base
) != 0x00000000)
12080 tp
->tg3_flags
|= TG3_FLAG_PCIX_TARGET_HWBUG
;
12085 tg3_nvram_init(tp
);
12087 grc_misc_cfg
= tr32(GRC_MISC_CFG
);
12088 grc_misc_cfg
&= GRC_MISC_CFG_BOARD_ID_MASK
;
12090 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5705
&&
12091 (grc_misc_cfg
== GRC_MISC_CFG_BOARD_ID_5788
||
12092 grc_misc_cfg
== GRC_MISC_CFG_BOARD_ID_5788M
))
12093 tp
->tg3_flags2
|= TG3_FLG2_IS_5788
;
12095 if (!(tp
->tg3_flags2
& TG3_FLG2_IS_5788
) &&
12096 (GET_ASIC_REV(tp
->pci_chip_rev_id
) != ASIC_REV_5700
))
12097 tp
->tg3_flags
|= TG3_FLAG_TAGGED_STATUS
;
12098 if (tp
->tg3_flags
& TG3_FLAG_TAGGED_STATUS
) {
12099 tp
->coalesce_mode
|= (HOSTCC_MODE_CLRTICK_RXBD
|
12100 HOSTCC_MODE_CLRTICK_TXBD
);
12102 tp
->misc_host_ctrl
|= MISC_HOST_CTRL_TAGGED_STATUS
;
12103 pci_write_config_dword(tp
->pdev
, TG3PCI_MISC_HOST_CTRL
,
12104 tp
->misc_host_ctrl
);
12107 /* Preserve the APE MAC_MODE bits */
12108 if (tp
->tg3_flags3
& TG3_FLG3_ENABLE_APE
)
12109 tp
->mac_mode
= tr32(MAC_MODE
) |
12110 MAC_MODE_APE_TX_EN
| MAC_MODE_APE_RX_EN
;
12112 tp
->mac_mode
= TG3_DEF_MAC_MODE
;
12114 /* these are limited to 10/100 only */
12115 if ((GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5703
&&
12116 (grc_misc_cfg
== 0x8000 || grc_misc_cfg
== 0x4000)) ||
12117 (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5705
&&
12118 tp
->pdev
->vendor
== PCI_VENDOR_ID_BROADCOM
&&
12119 (tp
->pdev
->device
== PCI_DEVICE_ID_TIGON3_5901
||
12120 tp
->pdev
->device
== PCI_DEVICE_ID_TIGON3_5901_2
||
12121 tp
->pdev
->device
== PCI_DEVICE_ID_TIGON3_5705F
)) ||
12122 (tp
->pdev
->vendor
== PCI_VENDOR_ID_BROADCOM
&&
12123 (tp
->pdev
->device
== PCI_DEVICE_ID_TIGON3_5751F
||
12124 tp
->pdev
->device
== PCI_DEVICE_ID_TIGON3_5753F
||
12125 tp
->pdev
->device
== PCI_DEVICE_ID_TIGON3_5787F
)) ||
12126 tp
->pdev
->device
== TG3PCI_DEVICE_TIGON3_57790
||
12127 GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5906
)
12128 tp
->tg3_flags
|= TG3_FLAG_10_100_ONLY
;
12130 err
= tg3_phy_probe(tp
);
12132 printk(KERN_ERR PFX
"(%s) phy probe failed, err %d\n",
12133 pci_name(tp
->pdev
), err
);
12134 /* ... but do not return immediately ... */
12138 tg3_read_partno(tp
);
12139 tg3_read_fw_ver(tp
);
12141 if (tp
->tg3_flags2
& TG3_FLG2_PHY_SERDES
) {
12142 tp
->tg3_flags
&= ~TG3_FLAG_USE_MI_INTERRUPT
;
12144 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5700
)
12145 tp
->tg3_flags
|= TG3_FLAG_USE_MI_INTERRUPT
;
12147 tp
->tg3_flags
&= ~TG3_FLAG_USE_MI_INTERRUPT
;
12150 /* 5700 {AX,BX} chips have a broken status block link
12151 * change bit implementation, so we must use the
12152 * status register in those cases.
12154 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5700
)
12155 tp
->tg3_flags
|= TG3_FLAG_USE_LINKCHG_REG
;
12157 tp
->tg3_flags
&= ~TG3_FLAG_USE_LINKCHG_REG
;
12159 /* The led_ctrl is set during tg3_phy_probe, here we might
12160 * have to force the link status polling mechanism based
12161 * upon subsystem IDs.
12163 if (tp
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_DELL
&&
12164 GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5701
&&
12165 !(tp
->tg3_flags2
& TG3_FLG2_PHY_SERDES
)) {
12166 tp
->tg3_flags
|= (TG3_FLAG_USE_MI_INTERRUPT
|
12167 TG3_FLAG_USE_LINKCHG_REG
);
12170 /* For all SERDES we poll the MAC status register. */
12171 if (tp
->tg3_flags2
& TG3_FLG2_PHY_SERDES
)
12172 tp
->tg3_flags
|= TG3_FLAG_POLL_SERDES
;
12174 tp
->tg3_flags
&= ~TG3_FLAG_POLL_SERDES
;
12176 tp
->rx_offset
= NET_IP_ALIGN
;
12177 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5701
&&
12178 (tp
->tg3_flags
& TG3_FLAG_PCIX_MODE
) != 0)
12181 tp
->rx_std_max_post
= TG3_RX_RING_SIZE
;
12183 /* Increment the rx prod index on the rx std ring by at most
12184 * 8 for these chips to workaround hw errata.
12186 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5750
||
12187 GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5752
||
12188 GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5755
)
12189 tp
->rx_std_max_post
= 8;
12191 if (tp
->tg3_flags
& TG3_FLAG_ASPM_WORKAROUND
)
12192 tp
->pwrmgmt_thresh
= tr32(PCIE_PWR_MGMT_THRESH
) &
12193 PCIE_PWR_MGMT_L1_THRESH_MSK
;
12198 #ifdef CONFIG_SPARC
12199 static int __devinit
tg3_get_macaddr_sparc(struct tg3
*tp
)
12201 struct net_device
*dev
= tp
->dev
;
12202 struct pci_dev
*pdev
= tp
->pdev
;
12203 struct device_node
*dp
= pci_device_to_OF_node(pdev
);
12204 const unsigned char *addr
;
12207 addr
= of_get_property(dp
, "local-mac-address", &len
);
12208 if (addr
&& len
== 6) {
12209 memcpy(dev
->dev_addr
, addr
, 6);
12210 memcpy(dev
->perm_addr
, dev
->dev_addr
, 6);
12216 static int __devinit
tg3_get_default_macaddr_sparc(struct tg3
*tp
)
12218 struct net_device
*dev
= tp
->dev
;
12220 memcpy(dev
->dev_addr
, idprom
->id_ethaddr
, 6);
12221 memcpy(dev
->perm_addr
, idprom
->id_ethaddr
, 6);
12226 static int __devinit
tg3_get_device_address(struct tg3
*tp
)
12228 struct net_device
*dev
= tp
->dev
;
12229 u32 hi
, lo
, mac_offset
;
12232 #ifdef CONFIG_SPARC
12233 if (!tg3_get_macaddr_sparc(tp
))
12238 if ((GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5704
) ||
12239 (tp
->tg3_flags2
& TG3_FLG2_5780_CLASS
)) {
12240 if (tr32(TG3PCI_DUAL_MAC_CTRL
) & DUAL_MAC_CTRL_ID
)
12242 if (tg3_nvram_lock(tp
))
12243 tw32_f(NVRAM_CMD
, NVRAM_CMD_RESET
);
12245 tg3_nvram_unlock(tp
);
12247 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5906
)
12250 /* First try to get it from MAC address mailbox. */
12251 tg3_read_mem(tp
, NIC_SRAM_MAC_ADDR_HIGH_MBOX
, &hi
);
12252 if ((hi
>> 16) == 0x484b) {
12253 dev
->dev_addr
[0] = (hi
>> 8) & 0xff;
12254 dev
->dev_addr
[1] = (hi
>> 0) & 0xff;
12256 tg3_read_mem(tp
, NIC_SRAM_MAC_ADDR_LOW_MBOX
, &lo
);
12257 dev
->dev_addr
[2] = (lo
>> 24) & 0xff;
12258 dev
->dev_addr
[3] = (lo
>> 16) & 0xff;
12259 dev
->dev_addr
[4] = (lo
>> 8) & 0xff;
12260 dev
->dev_addr
[5] = (lo
>> 0) & 0xff;
12262 /* Some old bootcode may report a 0 MAC address in SRAM */
12263 addr_ok
= is_valid_ether_addr(&dev
->dev_addr
[0]);
12266 /* Next, try NVRAM. */
12267 if (!tg3_nvram_read(tp
, mac_offset
+ 0, &hi
) &&
12268 !tg3_nvram_read(tp
, mac_offset
+ 4, &lo
)) {
12269 dev
->dev_addr
[0] = ((hi
>> 16) & 0xff);
12270 dev
->dev_addr
[1] = ((hi
>> 24) & 0xff);
12271 dev
->dev_addr
[2] = ((lo
>> 0) & 0xff);
12272 dev
->dev_addr
[3] = ((lo
>> 8) & 0xff);
12273 dev
->dev_addr
[4] = ((lo
>> 16) & 0xff);
12274 dev
->dev_addr
[5] = ((lo
>> 24) & 0xff);
12276 /* Finally just fetch it out of the MAC control regs. */
12278 hi
= tr32(MAC_ADDR_0_HIGH
);
12279 lo
= tr32(MAC_ADDR_0_LOW
);
12281 dev
->dev_addr
[5] = lo
& 0xff;
12282 dev
->dev_addr
[4] = (lo
>> 8) & 0xff;
12283 dev
->dev_addr
[3] = (lo
>> 16) & 0xff;
12284 dev
->dev_addr
[2] = (lo
>> 24) & 0xff;
12285 dev
->dev_addr
[1] = hi
& 0xff;
12286 dev
->dev_addr
[0] = (hi
>> 8) & 0xff;
12290 if (!is_valid_ether_addr(&dev
->dev_addr
[0])) {
12291 #ifdef CONFIG_SPARC
12292 if (!tg3_get_default_macaddr_sparc(tp
))
12297 memcpy(dev
->perm_addr
, dev
->dev_addr
, dev
->addr_len
);
12301 #define BOUNDARY_SINGLE_CACHELINE 1
12302 #define BOUNDARY_MULTI_CACHELINE 2
12304 static u32 __devinit
tg3_calc_dma_bndry(struct tg3
*tp
, u32 val
)
12306 int cacheline_size
;
12310 pci_read_config_byte(tp
->pdev
, PCI_CACHE_LINE_SIZE
, &byte
);
12312 cacheline_size
= 1024;
12314 cacheline_size
= (int) byte
* 4;
12316 /* On 5703 and later chips, the boundary bits have no
12319 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) != ASIC_REV_5700
&&
12320 GET_ASIC_REV(tp
->pci_chip_rev_id
) != ASIC_REV_5701
&&
12321 !(tp
->tg3_flags2
& TG3_FLG2_PCI_EXPRESS
))
12324 #if defined(CONFIG_PPC64) || defined(CONFIG_IA64) || defined(CONFIG_PARISC)
12325 goal
= BOUNDARY_MULTI_CACHELINE
;
12327 #if defined(CONFIG_SPARC64) || defined(CONFIG_ALPHA)
12328 goal
= BOUNDARY_SINGLE_CACHELINE
;
12337 /* PCI controllers on most RISC systems tend to disconnect
12338 * when a device tries to burst across a cache-line boundary.
12339 * Therefore, letting tg3 do so just wastes PCI bandwidth.
12341 * Unfortunately, for PCI-E there are only limited
12342 * write-side controls for this, and thus for reads
12343 * we will still get the disconnects. We'll also waste
12344 * these PCI cycles for both read and write for chips
12345 * other than 5700 and 5701 which do not implement the
12348 if ((tp
->tg3_flags
& TG3_FLAG_PCIX_MODE
) &&
12349 !(tp
->tg3_flags2
& TG3_FLG2_PCI_EXPRESS
)) {
12350 switch (cacheline_size
) {
12355 if (goal
== BOUNDARY_SINGLE_CACHELINE
) {
12356 val
|= (DMA_RWCTRL_READ_BNDRY_128_PCIX
|
12357 DMA_RWCTRL_WRITE_BNDRY_128_PCIX
);
12359 val
|= (DMA_RWCTRL_READ_BNDRY_384_PCIX
|
12360 DMA_RWCTRL_WRITE_BNDRY_384_PCIX
);
12365 val
|= (DMA_RWCTRL_READ_BNDRY_256_PCIX
|
12366 DMA_RWCTRL_WRITE_BNDRY_256_PCIX
);
12370 val
|= (DMA_RWCTRL_READ_BNDRY_384_PCIX
|
12371 DMA_RWCTRL_WRITE_BNDRY_384_PCIX
);
12374 } else if (tp
->tg3_flags2
& TG3_FLG2_PCI_EXPRESS
) {
12375 switch (cacheline_size
) {
12379 if (goal
== BOUNDARY_SINGLE_CACHELINE
) {
12380 val
&= ~DMA_RWCTRL_WRITE_BNDRY_DISAB_PCIE
;
12381 val
|= DMA_RWCTRL_WRITE_BNDRY_64_PCIE
;
12387 val
&= ~DMA_RWCTRL_WRITE_BNDRY_DISAB_PCIE
;
12388 val
|= DMA_RWCTRL_WRITE_BNDRY_128_PCIE
;
12392 switch (cacheline_size
) {
12394 if (goal
== BOUNDARY_SINGLE_CACHELINE
) {
12395 val
|= (DMA_RWCTRL_READ_BNDRY_16
|
12396 DMA_RWCTRL_WRITE_BNDRY_16
);
12401 if (goal
== BOUNDARY_SINGLE_CACHELINE
) {
12402 val
|= (DMA_RWCTRL_READ_BNDRY_32
|
12403 DMA_RWCTRL_WRITE_BNDRY_32
);
12408 if (goal
== BOUNDARY_SINGLE_CACHELINE
) {
12409 val
|= (DMA_RWCTRL_READ_BNDRY_64
|
12410 DMA_RWCTRL_WRITE_BNDRY_64
);
12415 if (goal
== BOUNDARY_SINGLE_CACHELINE
) {
12416 val
|= (DMA_RWCTRL_READ_BNDRY_128
|
12417 DMA_RWCTRL_WRITE_BNDRY_128
);
12422 val
|= (DMA_RWCTRL_READ_BNDRY_256
|
12423 DMA_RWCTRL_WRITE_BNDRY_256
);
12426 val
|= (DMA_RWCTRL_READ_BNDRY_512
|
12427 DMA_RWCTRL_WRITE_BNDRY_512
);
12431 val
|= (DMA_RWCTRL_READ_BNDRY_1024
|
12432 DMA_RWCTRL_WRITE_BNDRY_1024
);
12441 static int __devinit
tg3_do_test_dma(struct tg3
*tp
, u32
*buf
, dma_addr_t buf_dma
, int size
, int to_device
)
12443 struct tg3_internal_buffer_desc test_desc
;
12444 u32 sram_dma_descs
;
12447 sram_dma_descs
= NIC_SRAM_DMA_DESC_POOL_BASE
;
12449 tw32(FTQ_RCVBD_COMP_FIFO_ENQDEQ
, 0);
12450 tw32(FTQ_RCVDATA_COMP_FIFO_ENQDEQ
, 0);
12451 tw32(RDMAC_STATUS
, 0);
12452 tw32(WDMAC_STATUS
, 0);
12454 tw32(BUFMGR_MODE
, 0);
12455 tw32(FTQ_RESET
, 0);
12457 test_desc
.addr_hi
= ((u64
) buf_dma
) >> 32;
12458 test_desc
.addr_lo
= buf_dma
& 0xffffffff;
12459 test_desc
.nic_mbuf
= 0x00002100;
12460 test_desc
.len
= size
;
12463 * HP ZX1 was seeing test failures for 5701 cards running at 33Mhz
12464 * the *second* time the tg3 driver was getting loaded after an
12467 * Broadcom tells me:
12468 * ...the DMA engine is connected to the GRC block and a DMA
12469 * reset may affect the GRC block in some unpredictable way...
12470 * The behavior of resets to individual blocks has not been tested.
12472 * Broadcom noted the GRC reset will also reset all sub-components.
12475 test_desc
.cqid_sqid
= (13 << 8) | 2;
12477 tw32_f(RDMAC_MODE
, RDMAC_MODE_ENABLE
);
12480 test_desc
.cqid_sqid
= (16 << 8) | 7;
12482 tw32_f(WDMAC_MODE
, WDMAC_MODE_ENABLE
);
12485 test_desc
.flags
= 0x00000005;
12487 for (i
= 0; i
< (sizeof(test_desc
) / sizeof(u32
)); i
++) {
12490 val
= *(((u32
*)&test_desc
) + i
);
12491 pci_write_config_dword(tp
->pdev
, TG3PCI_MEM_WIN_BASE_ADDR
,
12492 sram_dma_descs
+ (i
* sizeof(u32
)));
12493 pci_write_config_dword(tp
->pdev
, TG3PCI_MEM_WIN_DATA
, val
);
12495 pci_write_config_dword(tp
->pdev
, TG3PCI_MEM_WIN_BASE_ADDR
, 0);
12498 tw32(FTQ_DMA_HIGH_READ_FIFO_ENQDEQ
, sram_dma_descs
);
12500 tw32(FTQ_DMA_HIGH_WRITE_FIFO_ENQDEQ
, sram_dma_descs
);
12504 for (i
= 0; i
< 40; i
++) {
12508 val
= tr32(FTQ_RCVBD_COMP_FIFO_ENQDEQ
);
12510 val
= tr32(FTQ_RCVDATA_COMP_FIFO_ENQDEQ
);
12511 if ((val
& 0xffff) == sram_dma_descs
) {
12522 #define TEST_BUFFER_SIZE 0x2000
12524 static int __devinit
tg3_test_dma(struct tg3
*tp
)
12526 dma_addr_t buf_dma
;
12527 u32
*buf
, saved_dma_rwctrl
;
12530 buf
= pci_alloc_consistent(tp
->pdev
, TEST_BUFFER_SIZE
, &buf_dma
);
12536 tp
->dma_rwctrl
= ((0x7 << DMA_RWCTRL_PCI_WRITE_CMD_SHIFT
) |
12537 (0x6 << DMA_RWCTRL_PCI_READ_CMD_SHIFT
));
12539 tp
->dma_rwctrl
= tg3_calc_dma_bndry(tp
, tp
->dma_rwctrl
);
12541 if (tp
->tg3_flags2
& TG3_FLG2_PCI_EXPRESS
) {
12542 /* DMA read watermark not used on PCIE */
12543 tp
->dma_rwctrl
|= 0x00180000;
12544 } else if (!(tp
->tg3_flags
& TG3_FLAG_PCIX_MODE
)) {
12545 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5705
||
12546 GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5750
)
12547 tp
->dma_rwctrl
|= 0x003f0000;
12549 tp
->dma_rwctrl
|= 0x003f000f;
12551 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5703
||
12552 GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5704
) {
12553 u32 ccval
= (tr32(TG3PCI_CLOCK_CTRL
) & 0x1f);
12554 u32 read_water
= 0x7;
12556 /* If the 5704 is behind the EPB bridge, we can
12557 * do the less restrictive ONE_DMA workaround for
12558 * better performance.
12560 if ((tp
->tg3_flags
& TG3_FLAG_40BIT_DMA_BUG
) &&
12561 GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5704
)
12562 tp
->dma_rwctrl
|= 0x8000;
12563 else if (ccval
== 0x6 || ccval
== 0x7)
12564 tp
->dma_rwctrl
|= DMA_RWCTRL_ONE_DMA
;
12566 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5703
)
12568 /* Set bit 23 to enable PCIX hw bug fix */
12570 (read_water
<< DMA_RWCTRL_READ_WATER_SHIFT
) |
12571 (0x3 << DMA_RWCTRL_WRITE_WATER_SHIFT
) |
12573 } else if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5780
) {
12574 /* 5780 always in PCIX mode */
12575 tp
->dma_rwctrl
|= 0x00144000;
12576 } else if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5714
) {
12577 /* 5714 always in PCIX mode */
12578 tp
->dma_rwctrl
|= 0x00148000;
12580 tp
->dma_rwctrl
|= 0x001b000f;
12584 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5703
||
12585 GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5704
)
12586 tp
->dma_rwctrl
&= 0xfffffff0;
12588 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5700
||
12589 GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5701
) {
12590 /* Remove this if it causes problems for some boards. */
12591 tp
->dma_rwctrl
|= DMA_RWCTRL_USE_MEM_READ_MULT
;
12593 /* On 5700/5701 chips, we need to set this bit.
12594 * Otherwise the chip will issue cacheline transactions
12595 * to streamable DMA memory with not all the byte
12596 * enables turned on. This is an error on several
12597 * RISC PCI controllers, in particular sparc64.
12599 * On 5703/5704 chips, this bit has been reassigned
12600 * a different meaning. In particular, it is used
12601 * on those chips to enable a PCI-X workaround.
12603 tp
->dma_rwctrl
|= DMA_RWCTRL_ASSERT_ALL_BE
;
12606 tw32(TG3PCI_DMA_RW_CTRL
, tp
->dma_rwctrl
);
12609 /* Unneeded, already done by tg3_get_invariants. */
12610 tg3_switch_clocks(tp
);
12614 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) != ASIC_REV_5700
&&
12615 GET_ASIC_REV(tp
->pci_chip_rev_id
) != ASIC_REV_5701
)
12618 /* It is best to perform DMA test with maximum write burst size
12619 * to expose the 5700/5701 write DMA bug.
12621 saved_dma_rwctrl
= tp
->dma_rwctrl
;
12622 tp
->dma_rwctrl
&= ~DMA_RWCTRL_WRITE_BNDRY_MASK
;
12623 tw32(TG3PCI_DMA_RW_CTRL
, tp
->dma_rwctrl
);
12628 for (i
= 0; i
< TEST_BUFFER_SIZE
/ sizeof(u32
); i
++)
12631 /* Send the buffer to the chip. */
12632 ret
= tg3_do_test_dma(tp
, buf
, buf_dma
, TEST_BUFFER_SIZE
, 1);
12634 printk(KERN_ERR
"tg3_test_dma() Write the buffer failed %d\n", ret
);
12639 /* validate data reached card RAM correctly. */
12640 for (i
= 0; i
< TEST_BUFFER_SIZE
/ sizeof(u32
); i
++) {
12642 tg3_read_mem(tp
, 0x2100 + (i
*4), &val
);
12643 if (le32_to_cpu(val
) != p
[i
]) {
12644 printk(KERN_ERR
" tg3_test_dma() Card buffer corrupted on write! (%d != %d)\n", val
, i
);
12645 /* ret = -ENODEV here? */
12650 /* Now read it back. */
12651 ret
= tg3_do_test_dma(tp
, buf
, buf_dma
, TEST_BUFFER_SIZE
, 0);
12653 printk(KERN_ERR
"tg3_test_dma() Read the buffer failed %d\n", ret
);
12659 for (i
= 0; i
< TEST_BUFFER_SIZE
/ sizeof(u32
); i
++) {
12663 if ((tp
->dma_rwctrl
& DMA_RWCTRL_WRITE_BNDRY_MASK
) !=
12664 DMA_RWCTRL_WRITE_BNDRY_16
) {
12665 tp
->dma_rwctrl
&= ~DMA_RWCTRL_WRITE_BNDRY_MASK
;
12666 tp
->dma_rwctrl
|= DMA_RWCTRL_WRITE_BNDRY_16
;
12667 tw32(TG3PCI_DMA_RW_CTRL
, tp
->dma_rwctrl
);
12670 printk(KERN_ERR
"tg3_test_dma() buffer corrupted on read back! (%d != %d)\n", p
[i
], i
);
12676 if (i
== (TEST_BUFFER_SIZE
/ sizeof(u32
))) {
12682 if ((tp
->dma_rwctrl
& DMA_RWCTRL_WRITE_BNDRY_MASK
) !=
12683 DMA_RWCTRL_WRITE_BNDRY_16
) {
12684 static struct pci_device_id dma_wait_state_chipsets
[] = {
12685 { PCI_DEVICE(PCI_VENDOR_ID_APPLE
,
12686 PCI_DEVICE_ID_APPLE_UNI_N_PCI15
) },
12690 /* DMA test passed without adjusting DMA boundary,
12691 * now look for chipsets that are known to expose the
12692 * DMA bug without failing the test.
12694 if (pci_dev_present(dma_wait_state_chipsets
)) {
12695 tp
->dma_rwctrl
&= ~DMA_RWCTRL_WRITE_BNDRY_MASK
;
12696 tp
->dma_rwctrl
|= DMA_RWCTRL_WRITE_BNDRY_16
;
12699 /* Safe to use the calculated DMA boundary. */
12700 tp
->dma_rwctrl
= saved_dma_rwctrl
;
12702 tw32(TG3PCI_DMA_RW_CTRL
, tp
->dma_rwctrl
);
12706 pci_free_consistent(tp
->pdev
, TEST_BUFFER_SIZE
, buf
, buf_dma
);
12711 static void __devinit
tg3_init_link_config(struct tg3
*tp
)
12713 tp
->link_config
.advertising
=
12714 (ADVERTISED_10baseT_Half
| ADVERTISED_10baseT_Full
|
12715 ADVERTISED_100baseT_Half
| ADVERTISED_100baseT_Full
|
12716 ADVERTISED_1000baseT_Half
| ADVERTISED_1000baseT_Full
|
12717 ADVERTISED_Autoneg
| ADVERTISED_MII
);
12718 tp
->link_config
.speed
= SPEED_INVALID
;
12719 tp
->link_config
.duplex
= DUPLEX_INVALID
;
12720 tp
->link_config
.autoneg
= AUTONEG_ENABLE
;
12721 tp
->link_config
.active_speed
= SPEED_INVALID
;
12722 tp
->link_config
.active_duplex
= DUPLEX_INVALID
;
12723 tp
->link_config
.phy_is_low_power
= 0;
12724 tp
->link_config
.orig_speed
= SPEED_INVALID
;
12725 tp
->link_config
.orig_duplex
= DUPLEX_INVALID
;
12726 tp
->link_config
.orig_autoneg
= AUTONEG_INVALID
;
12729 static void __devinit
tg3_init_bufmgr_config(struct tg3
*tp
)
12731 if (tp
->tg3_flags2
& TG3_FLG2_5705_PLUS
) {
12732 tp
->bufmgr_config
.mbuf_read_dma_low_water
=
12733 DEFAULT_MB_RDMA_LOW_WATER_5705
;
12734 tp
->bufmgr_config
.mbuf_mac_rx_low_water
=
12735 DEFAULT_MB_MACRX_LOW_WATER_5705
;
12736 tp
->bufmgr_config
.mbuf_high_water
=
12737 DEFAULT_MB_HIGH_WATER_5705
;
12738 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5906
) {
12739 tp
->bufmgr_config
.mbuf_mac_rx_low_water
=
12740 DEFAULT_MB_MACRX_LOW_WATER_5906
;
12741 tp
->bufmgr_config
.mbuf_high_water
=
12742 DEFAULT_MB_HIGH_WATER_5906
;
12745 tp
->bufmgr_config
.mbuf_read_dma_low_water_jumbo
=
12746 DEFAULT_MB_RDMA_LOW_WATER_JUMBO_5780
;
12747 tp
->bufmgr_config
.mbuf_mac_rx_low_water_jumbo
=
12748 DEFAULT_MB_MACRX_LOW_WATER_JUMBO_5780
;
12749 tp
->bufmgr_config
.mbuf_high_water_jumbo
=
12750 DEFAULT_MB_HIGH_WATER_JUMBO_5780
;
12752 tp
->bufmgr_config
.mbuf_read_dma_low_water
=
12753 DEFAULT_MB_RDMA_LOW_WATER
;
12754 tp
->bufmgr_config
.mbuf_mac_rx_low_water
=
12755 DEFAULT_MB_MACRX_LOW_WATER
;
12756 tp
->bufmgr_config
.mbuf_high_water
=
12757 DEFAULT_MB_HIGH_WATER
;
12759 tp
->bufmgr_config
.mbuf_read_dma_low_water_jumbo
=
12760 DEFAULT_MB_RDMA_LOW_WATER_JUMBO
;
12761 tp
->bufmgr_config
.mbuf_mac_rx_low_water_jumbo
=
12762 DEFAULT_MB_MACRX_LOW_WATER_JUMBO
;
12763 tp
->bufmgr_config
.mbuf_high_water_jumbo
=
12764 DEFAULT_MB_HIGH_WATER_JUMBO
;
12767 tp
->bufmgr_config
.dma_low_water
= DEFAULT_DMA_LOW_WATER
;
12768 tp
->bufmgr_config
.dma_high_water
= DEFAULT_DMA_HIGH_WATER
;
12771 static char * __devinit
tg3_phy_string(struct tg3
*tp
)
12773 switch (tp
->phy_id
& PHY_ID_MASK
) {
12774 case PHY_ID_BCM5400
: return "5400";
12775 case PHY_ID_BCM5401
: return "5401";
12776 case PHY_ID_BCM5411
: return "5411";
12777 case PHY_ID_BCM5701
: return "5701";
12778 case PHY_ID_BCM5703
: return "5703";
12779 case PHY_ID_BCM5704
: return "5704";
12780 case PHY_ID_BCM5705
: return "5705";
12781 case PHY_ID_BCM5750
: return "5750";
12782 case PHY_ID_BCM5752
: return "5752";
12783 case PHY_ID_BCM5714
: return "5714";
12784 case PHY_ID_BCM5780
: return "5780";
12785 case PHY_ID_BCM5755
: return "5755";
12786 case PHY_ID_BCM5787
: return "5787";
12787 case PHY_ID_BCM5784
: return "5784";
12788 case PHY_ID_BCM5756
: return "5722/5756";
12789 case PHY_ID_BCM5906
: return "5906";
12790 case PHY_ID_BCM5761
: return "5761";
12791 case PHY_ID_BCM8002
: return "8002/serdes";
12792 case 0: return "serdes";
12793 default: return "unknown";
12797 static char * __devinit
tg3_bus_string(struct tg3
*tp
, char *str
)
12799 if (tp
->tg3_flags2
& TG3_FLG2_PCI_EXPRESS
) {
12800 strcpy(str
, "PCI Express");
12802 } else if (tp
->tg3_flags
& TG3_FLAG_PCIX_MODE
) {
12803 u32 clock_ctrl
= tr32(TG3PCI_CLOCK_CTRL
) & 0x1f;
12805 strcpy(str
, "PCIX:");
12807 if ((clock_ctrl
== 7) ||
12808 ((tr32(GRC_MISC_CFG
) & GRC_MISC_CFG_BOARD_ID_MASK
) ==
12809 GRC_MISC_CFG_BOARD_ID_5704CIOBE
))
12810 strcat(str
, "133MHz");
12811 else if (clock_ctrl
== 0)
12812 strcat(str
, "33MHz");
12813 else if (clock_ctrl
== 2)
12814 strcat(str
, "50MHz");
12815 else if (clock_ctrl
== 4)
12816 strcat(str
, "66MHz");
12817 else if (clock_ctrl
== 6)
12818 strcat(str
, "100MHz");
12820 strcpy(str
, "PCI:");
12821 if (tp
->tg3_flags
& TG3_FLAG_PCI_HIGH_SPEED
)
12822 strcat(str
, "66MHz");
12824 strcat(str
, "33MHz");
12826 if (tp
->tg3_flags
& TG3_FLAG_PCI_32BIT
)
12827 strcat(str
, ":32-bit");
12829 strcat(str
, ":64-bit");
12833 static struct pci_dev
* __devinit
tg3_find_peer(struct tg3
*tp
)
12835 struct pci_dev
*peer
;
12836 unsigned int func
, devnr
= tp
->pdev
->devfn
& ~7;
12838 for (func
= 0; func
< 8; func
++) {
12839 peer
= pci_get_slot(tp
->pdev
->bus
, devnr
| func
);
12840 if (peer
&& peer
!= tp
->pdev
)
12844 /* 5704 can be configured in single-port mode, set peer to
12845 * tp->pdev in that case.
12853 * We don't need to keep the refcount elevated; there's no way
12854 * to remove one half of this device without removing the other
12861 static void __devinit
tg3_init_coal(struct tg3
*tp
)
12863 struct ethtool_coalesce
*ec
= &tp
->coal
;
12865 memset(ec
, 0, sizeof(*ec
));
12866 ec
->cmd
= ETHTOOL_GCOALESCE
;
12867 ec
->rx_coalesce_usecs
= LOW_RXCOL_TICKS
;
12868 ec
->tx_coalesce_usecs
= LOW_TXCOL_TICKS
;
12869 ec
->rx_max_coalesced_frames
= LOW_RXMAX_FRAMES
;
12870 ec
->tx_max_coalesced_frames
= LOW_TXMAX_FRAMES
;
12871 ec
->rx_coalesce_usecs_irq
= DEFAULT_RXCOAL_TICK_INT
;
12872 ec
->tx_coalesce_usecs_irq
= DEFAULT_TXCOAL_TICK_INT
;
12873 ec
->rx_max_coalesced_frames_irq
= DEFAULT_RXCOAL_MAXF_INT
;
12874 ec
->tx_max_coalesced_frames_irq
= DEFAULT_TXCOAL_MAXF_INT
;
12875 ec
->stats_block_coalesce_usecs
= DEFAULT_STAT_COAL_TICKS
;
12877 if (tp
->coalesce_mode
& (HOSTCC_MODE_CLRTICK_RXBD
|
12878 HOSTCC_MODE_CLRTICK_TXBD
)) {
12879 ec
->rx_coalesce_usecs
= LOW_RXCOL_TICKS_CLRTCKS
;
12880 ec
->rx_coalesce_usecs_irq
= DEFAULT_RXCOAL_TICK_INT_CLRTCKS
;
12881 ec
->tx_coalesce_usecs
= LOW_TXCOL_TICKS_CLRTCKS
;
12882 ec
->tx_coalesce_usecs_irq
= DEFAULT_TXCOAL_TICK_INT_CLRTCKS
;
12885 if (tp
->tg3_flags2
& TG3_FLG2_5705_PLUS
) {
12886 ec
->rx_coalesce_usecs_irq
= 0;
12887 ec
->tx_coalesce_usecs_irq
= 0;
12888 ec
->stats_block_coalesce_usecs
= 0;
12892 static const struct net_device_ops tg3_netdev_ops
= {
12893 .ndo_open
= tg3_open
,
12894 .ndo_stop
= tg3_close
,
12895 .ndo_start_xmit
= tg3_start_xmit
,
12896 .ndo_get_stats
= tg3_get_stats
,
12897 .ndo_validate_addr
= eth_validate_addr
,
12898 .ndo_set_multicast_list
= tg3_set_rx_mode
,
12899 .ndo_set_mac_address
= tg3_set_mac_addr
,
12900 .ndo_do_ioctl
= tg3_ioctl
,
12901 .ndo_tx_timeout
= tg3_tx_timeout
,
12902 .ndo_change_mtu
= tg3_change_mtu
,
12903 #if TG3_VLAN_TAG_USED
12904 .ndo_vlan_rx_register
= tg3_vlan_rx_register
,
12906 #ifdef CONFIG_NET_POLL_CONTROLLER
12907 .ndo_poll_controller
= tg3_poll_controller
,
12911 static const struct net_device_ops tg3_netdev_ops_dma_bug
= {
12912 .ndo_open
= tg3_open
,
12913 .ndo_stop
= tg3_close
,
12914 .ndo_start_xmit
= tg3_start_xmit_dma_bug
,
12915 .ndo_get_stats
= tg3_get_stats
,
12916 .ndo_validate_addr
= eth_validate_addr
,
12917 .ndo_set_multicast_list
= tg3_set_rx_mode
,
12918 .ndo_set_mac_address
= tg3_set_mac_addr
,
12919 .ndo_do_ioctl
= tg3_ioctl
,
12920 .ndo_tx_timeout
= tg3_tx_timeout
,
12921 .ndo_change_mtu
= tg3_change_mtu
,
12922 #if TG3_VLAN_TAG_USED
12923 .ndo_vlan_rx_register
= tg3_vlan_rx_register
,
12925 #ifdef CONFIG_NET_POLL_CONTROLLER
12926 .ndo_poll_controller
= tg3_poll_controller
,
12930 static int __devinit
tg3_init_one(struct pci_dev
*pdev
,
12931 const struct pci_device_id
*ent
)
12933 static int tg3_version_printed
= 0;
12934 struct net_device
*dev
;
12937 const char *fw_name
= NULL
;
12939 u64 dma_mask
, persist_dma_mask
;
12941 if (tg3_version_printed
++ == 0)
12942 printk(KERN_INFO
"%s", version
);
12944 err
= pci_enable_device(pdev
);
12946 printk(KERN_ERR PFX
"Cannot enable PCI device, "
12951 err
= pci_request_regions(pdev
, DRV_MODULE_NAME
);
12953 printk(KERN_ERR PFX
"Cannot obtain PCI resources, "
12955 goto err_out_disable_pdev
;
12958 pci_set_master(pdev
);
12960 /* Find power-management capability. */
12961 pm_cap
= pci_find_capability(pdev
, PCI_CAP_ID_PM
);
12963 printk(KERN_ERR PFX
"Cannot find PowerManagement capability, "
12966 goto err_out_free_res
;
12969 dev
= alloc_etherdev(sizeof(*tp
));
12971 printk(KERN_ERR PFX
"Etherdev alloc failed, aborting.\n");
12973 goto err_out_free_res
;
12976 SET_NETDEV_DEV(dev
, &pdev
->dev
);
12978 #if TG3_VLAN_TAG_USED
12979 dev
->features
|= NETIF_F_HW_VLAN_TX
| NETIF_F_HW_VLAN_RX
;
12982 tp
= netdev_priv(dev
);
12985 tp
->pm_cap
= pm_cap
;
12986 tp
->rx_mode
= TG3_DEF_RX_MODE
;
12987 tp
->tx_mode
= TG3_DEF_TX_MODE
;
12990 tp
->msg_enable
= tg3_debug
;
12992 tp
->msg_enable
= TG3_DEF_MSG_ENABLE
;
12994 /* The word/byte swap controls here control register access byte
12995 * swapping. DMA data byte swapping is controlled in the GRC_MODE
12998 tp
->misc_host_ctrl
=
12999 MISC_HOST_CTRL_MASK_PCI_INT
|
13000 MISC_HOST_CTRL_WORD_SWAP
|
13001 MISC_HOST_CTRL_INDIR_ACCESS
|
13002 MISC_HOST_CTRL_PCISTATE_RW
;
13004 /* The NONFRM (non-frame) byte/word swap controls take effect
13005 * on descriptor entries, anything which isn't packet data.
13007 * The StrongARM chips on the board (one for tx, one for rx)
13008 * are running in big-endian mode.
13010 tp
->grc_mode
= (GRC_MODE_WSWAP_DATA
| GRC_MODE_BSWAP_DATA
|
13011 GRC_MODE_WSWAP_NONFRM_DATA
);
13012 #ifdef __BIG_ENDIAN
13013 tp
->grc_mode
|= GRC_MODE_BSWAP_NONFRM_DATA
;
13015 spin_lock_init(&tp
->lock
);
13016 spin_lock_init(&tp
->indirect_lock
);
13017 INIT_WORK(&tp
->reset_task
, tg3_reset_task
);
13019 tp
->regs
= pci_ioremap_bar(pdev
, BAR_0
);
13021 printk(KERN_ERR PFX
"Cannot map device registers, "
13024 goto err_out_free_dev
;
13027 tg3_init_link_config(tp
);
13029 tp
->rx_pending
= TG3_DEF_RX_RING_PENDING
;
13030 tp
->rx_jumbo_pending
= TG3_DEF_RX_JUMBO_RING_PENDING
;
13031 tp
->tx_pending
= TG3_DEF_TX_RING_PENDING
;
13033 netif_napi_add(dev
, &tp
->napi
, tg3_poll
, 64);
13034 dev
->ethtool_ops
= &tg3_ethtool_ops
;
13035 dev
->watchdog_timeo
= TG3_TX_TIMEOUT
;
13036 dev
->irq
= pdev
->irq
;
13038 err
= tg3_get_invariants(tp
);
13040 printk(KERN_ERR PFX
"Problem fetching invariants of chip, "
13042 goto err_out_iounmap
;
13045 if ((tp
->tg3_flags3
& TG3_FLG3_5755_PLUS
) ||
13046 GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5906
)
13047 dev
->netdev_ops
= &tg3_netdev_ops
;
13049 dev
->netdev_ops
= &tg3_netdev_ops_dma_bug
;
13052 /* The EPB bridge inside 5714, 5715, and 5780 and any
13053 * device behind the EPB cannot support DMA addresses > 40-bit.
13054 * On 64-bit systems with IOMMU, use 40-bit dma_mask.
13055 * On 64-bit systems without IOMMU, use 64-bit dma_mask and
13056 * do DMA address check in tg3_start_xmit().
13058 if (tp
->tg3_flags2
& TG3_FLG2_IS_5788
)
13059 persist_dma_mask
= dma_mask
= DMA_32BIT_MASK
;
13060 else if (tp
->tg3_flags
& TG3_FLAG_40BIT_DMA_BUG
) {
13061 persist_dma_mask
= dma_mask
= DMA_40BIT_MASK
;
13062 #ifdef CONFIG_HIGHMEM
13063 dma_mask
= DMA_64BIT_MASK
;
13066 persist_dma_mask
= dma_mask
= DMA_64BIT_MASK
;
13068 /* Configure DMA attributes. */
13069 if (dma_mask
> DMA_32BIT_MASK
) {
13070 err
= pci_set_dma_mask(pdev
, dma_mask
);
13072 dev
->features
|= NETIF_F_HIGHDMA
;
13073 err
= pci_set_consistent_dma_mask(pdev
,
13076 printk(KERN_ERR PFX
"Unable to obtain 64 bit "
13077 "DMA for consistent allocations\n");
13078 goto err_out_iounmap
;
13082 if (err
|| dma_mask
== DMA_32BIT_MASK
) {
13083 err
= pci_set_dma_mask(pdev
, DMA_32BIT_MASK
);
13085 printk(KERN_ERR PFX
"No usable DMA configuration, "
13087 goto err_out_iounmap
;
13091 tg3_init_bufmgr_config(tp
);
13093 if (tp
->pci_chip_rev_id
== CHIPREV_ID_5701_A0
)
13094 fw_name
= FIRMWARE_TG3
;
13096 if (tp
->tg3_flags2
& TG3_FLG2_HW_TSO
) {
13097 tp
->tg3_flags2
|= TG3_FLG2_TSO_CAPABLE
;
13099 else if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5700
||
13100 GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5701
||
13101 tp
->pci_chip_rev_id
== CHIPREV_ID_5705_A0
||
13102 GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5906
||
13103 (tp
->tg3_flags
& TG3_FLAG_ENABLE_ASF
) != 0) {
13104 tp
->tg3_flags2
&= ~TG3_FLG2_TSO_CAPABLE
;
13106 tp
->tg3_flags2
|= TG3_FLG2_TSO_CAPABLE
| TG3_FLG2_TSO_BUG
;
13108 if (tp
->tg3_flags2
& TG3_FLG2_TSO_CAPABLE
) {
13109 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5705
)
13110 fw_name
= FIRMWARE_TG3TSO5
;
13112 fw_name
= FIRMWARE_TG3TSO
;
13116 const __be32
*fw_data
;
13118 err
= request_firmware(&tp
->fw
, fw_name
, &tp
->pdev
->dev
);
13120 printk(KERN_ERR
"tg3: Failed to load firmware \"%s\"\n",
13122 goto err_out_iounmap
;
13125 fw_data
= (void *)tp
->fw
->data
;
13127 /* Firmware blob starts with version numbers, followed by
13128 start address and _full_ length including BSS sections
13129 (which must be longer than the actual data, of course */
13131 tp
->fw_len
= be32_to_cpu(fw_data
[2]); /* includes bss */
13132 if (tp
->fw_len
< (tp
->fw
->size
- 12)) {
13133 printk(KERN_ERR
"tg3: bogus length %d in \"%s\"\n",
13134 tp
->fw_len
, fw_name
);
13140 /* TSO is on by default on chips that support hardware TSO.
13141 * Firmware TSO on older chips gives lower performance, so it
13142 * is off by default, but can be enabled using ethtool.
13144 if (tp
->tg3_flags2
& TG3_FLG2_HW_TSO
) {
13145 if (dev
->features
& NETIF_F_IP_CSUM
)
13146 dev
->features
|= NETIF_F_TSO
;
13147 if ((dev
->features
& NETIF_F_IPV6_CSUM
) &&
13148 (tp
->tg3_flags2
& TG3_FLG2_HW_TSO_2
))
13149 dev
->features
|= NETIF_F_TSO6
;
13150 if (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5761
||
13151 (GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5784
&&
13152 GET_CHIP_REV(tp
->pci_chip_rev_id
) != CHIPREV_5784_AX
) ||
13153 GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_5785
||
13154 GET_ASIC_REV(tp
->pci_chip_rev_id
) == ASIC_REV_57780
)
13155 dev
->features
|= NETIF_F_TSO_ECN
;
13159 if (tp
->pci_chip_rev_id
== CHIPREV_ID_5705_A1
&&
13160 !(tp
->tg3_flags2
& TG3_FLG2_TSO_CAPABLE
) &&
13161 !(tr32(TG3PCI_PCISTATE
) & PCISTATE_BUS_SPEED_HIGH
)) {
13162 tp
->tg3_flags2
|= TG3_FLG2_MAX_RXPEND_64
;
13163 tp
->rx_pending
= 63;
13166 err
= tg3_get_device_address(tp
);
13168 printk(KERN_ERR PFX
"Could not obtain valid ethernet address, "
13173 if (tp
->tg3_flags3
& TG3_FLG3_ENABLE_APE
) {
13174 tp
->aperegs
= pci_ioremap_bar(pdev
, BAR_2
);
13175 if (!tp
->aperegs
) {
13176 printk(KERN_ERR PFX
"Cannot map APE registers, "
13182 tg3_ape_lock_init(tp
);
13186 * Reset chip in case UNDI or EFI driver did not shutdown
13187 * DMA self test will enable WDMAC and we'll see (spurious)
13188 * pending DMA on the PCI bus at that point.
13190 if ((tr32(HOSTCC_MODE
) & HOSTCC_MODE_ENABLE
) ||
13191 (tr32(WDMAC_MODE
) & WDMAC_MODE_ENABLE
)) {
13192 tw32(MEMARB_MODE
, MEMARB_MODE_ENABLE
);
13193 tg3_halt(tp
, RESET_KIND_SHUTDOWN
, 1);
13196 err
= tg3_test_dma(tp
);
13198 printk(KERN_ERR PFX
"DMA engine test failed, aborting.\n");
13199 goto err_out_apeunmap
;
13202 /* flow control autonegotiation is default behavior */
13203 tp
->tg3_flags
|= TG3_FLAG_PAUSE_AUTONEG
;
13204 tp
->link_config
.flowctrl
= FLOW_CTRL_TX
| FLOW_CTRL_RX
;
13208 pci_set_drvdata(pdev
, dev
);
13210 err
= register_netdev(dev
);
13212 printk(KERN_ERR PFX
"Cannot register net device, "
13214 goto err_out_apeunmap
;
13217 printk(KERN_INFO
"%s: Tigon3 [partno(%s) rev %04x] (%s) MAC address %pM\n",
13219 tp
->board_part_number
,
13220 tp
->pci_chip_rev_id
,
13221 tg3_bus_string(tp
, str
),
13224 if (tp
->tg3_flags3
& TG3_FLG3_PHY_CONNECTED
)
13226 "%s: attached PHY driver [%s] (mii_bus:phy_addr=%s)\n",
13228 tp
->mdio_bus
->phy_map
[PHY_ADDR
]->drv
->name
,
13229 dev_name(&tp
->mdio_bus
->phy_map
[PHY_ADDR
]->dev
));
13232 "%s: attached PHY is %s (%s Ethernet) (WireSpeed[%d])\n",
13233 tp
->dev
->name
, tg3_phy_string(tp
),
13234 ((tp
->tg3_flags
& TG3_FLAG_10_100_ONLY
) ? "10/100Base-TX" :
13235 ((tp
->tg3_flags2
& TG3_FLG2_ANY_SERDES
) ? "1000Base-SX" :
13236 "10/100/1000Base-T")),
13237 (tp
->tg3_flags2
& TG3_FLG2_NO_ETH_WIRE_SPEED
) == 0);
13239 printk(KERN_INFO
"%s: RXcsums[%d] LinkChgREG[%d] MIirq[%d] ASF[%d] TSOcap[%d]\n",
13241 (tp
->tg3_flags
& TG3_FLAG_RX_CHECKSUMS
) != 0,
13242 (tp
->tg3_flags
& TG3_FLAG_USE_LINKCHG_REG
) != 0,
13243 (tp
->tg3_flags
& TG3_FLAG_USE_MI_INTERRUPT
) != 0,
13244 (tp
->tg3_flags
& TG3_FLAG_ENABLE_ASF
) != 0,
13245 (tp
->tg3_flags2
& TG3_FLG2_TSO_CAPABLE
) != 0);
13246 printk(KERN_INFO
"%s: dma_rwctrl[%08x] dma_mask[%d-bit]\n",
13247 dev
->name
, tp
->dma_rwctrl
,
13248 (pdev
->dma_mask
== DMA_32BIT_MASK
) ? 32 :
13249 (((u64
) pdev
->dma_mask
== DMA_40BIT_MASK
) ? 40 : 64));
13255 iounmap(tp
->aperegs
);
13256 tp
->aperegs
= NULL
;
13261 release_firmware(tp
->fw
);
13273 pci_release_regions(pdev
);
13275 err_out_disable_pdev
:
13276 pci_disable_device(pdev
);
13277 pci_set_drvdata(pdev
, NULL
);
13281 static void __devexit
tg3_remove_one(struct pci_dev
*pdev
)
13283 struct net_device
*dev
= pci_get_drvdata(pdev
);
13286 struct tg3
*tp
= netdev_priv(dev
);
13289 release_firmware(tp
->fw
);
13291 flush_scheduled_work();
13293 if (tp
->tg3_flags3
& TG3_FLG3_USE_PHYLIB
) {
13298 unregister_netdev(dev
);
13300 iounmap(tp
->aperegs
);
13301 tp
->aperegs
= NULL
;
13308 pci_release_regions(pdev
);
13309 pci_disable_device(pdev
);
13310 pci_set_drvdata(pdev
, NULL
);
13314 static int tg3_suspend(struct pci_dev
*pdev
, pm_message_t state
)
13316 struct net_device
*dev
= pci_get_drvdata(pdev
);
13317 struct tg3
*tp
= netdev_priv(dev
);
13318 pci_power_t target_state
;
13321 /* PCI register 4 needs to be saved whether netif_running() or not.
13322 * MSI address and data need to be saved if using MSI and
13325 pci_save_state(pdev
);
13327 if (!netif_running(dev
))
13330 flush_scheduled_work();
13332 tg3_netif_stop(tp
);
13334 del_timer_sync(&tp
->timer
);
13336 tg3_full_lock(tp
, 1);
13337 tg3_disable_ints(tp
);
13338 tg3_full_unlock(tp
);
13340 netif_device_detach(dev
);
13342 tg3_full_lock(tp
, 0);
13343 tg3_halt(tp
, RESET_KIND_SHUTDOWN
, 1);
13344 tp
->tg3_flags
&= ~TG3_FLAG_INIT_COMPLETE
;
13345 tg3_full_unlock(tp
);
13347 target_state
= pdev
->pm_cap
? pci_target_state(pdev
) : PCI_D3hot
;
13349 err
= tg3_set_power_state(tp
, target_state
);
13353 tg3_full_lock(tp
, 0);
13355 tp
->tg3_flags
|= TG3_FLAG_INIT_COMPLETE
;
13356 err2
= tg3_restart_hw(tp
, 1);
13360 tp
->timer
.expires
= jiffies
+ tp
->timer_offset
;
13361 add_timer(&tp
->timer
);
13363 netif_device_attach(dev
);
13364 tg3_netif_start(tp
);
13367 tg3_full_unlock(tp
);
13376 static int tg3_resume(struct pci_dev
*pdev
)
13378 struct net_device
*dev
= pci_get_drvdata(pdev
);
13379 struct tg3
*tp
= netdev_priv(dev
);
13382 pci_restore_state(tp
->pdev
);
13384 if (!netif_running(dev
))
13387 err
= tg3_set_power_state(tp
, PCI_D0
);
13391 netif_device_attach(dev
);
13393 tg3_full_lock(tp
, 0);
13395 tp
->tg3_flags
|= TG3_FLAG_INIT_COMPLETE
;
13396 err
= tg3_restart_hw(tp
, 1);
13400 tp
->timer
.expires
= jiffies
+ tp
->timer_offset
;
13401 add_timer(&tp
->timer
);
13403 tg3_netif_start(tp
);
13406 tg3_full_unlock(tp
);
13414 static struct pci_driver tg3_driver
= {
13415 .name
= DRV_MODULE_NAME
,
13416 .id_table
= tg3_pci_tbl
,
13417 .probe
= tg3_init_one
,
13418 .remove
= __devexit_p(tg3_remove_one
),
13419 .suspend
= tg3_suspend
,
13420 .resume
= tg3_resume
13423 static int __init
tg3_init(void)
13425 return pci_register_driver(&tg3_driver
);
13428 static void __exit
tg3_cleanup(void)
13430 pci_unregister_driver(&tg3_driver
);
13433 module_init(tg3_init
);
13434 module_exit(tg3_cleanup
);