]> bbs.cooldavid.org Git - net-next-2.6.git/blame - drivers/net/tg3.c
[TG3]: Add new one-shot MSI handler
[net-next-2.6.git] / drivers / net / tg3.c
CommitLineData
1da177e4
LT
1/*
2 * tg3.c: Broadcom Tigon3 ethernet driver.
3 *
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 Broadcom Corporation.
8 *
9 * Firmware is:
49cabf49
MC
10 * Derived from proprietary unpublished source code,
11 * Copyright (C) 2000-2003 Broadcom Corporation.
12 *
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.
1da177e4
LT
16 */
17
18#include <linux/config.h>
19
20#include <linux/module.h>
21#include <linux/moduleparam.h>
22#include <linux/kernel.h>
23#include <linux/types.h>
24#include <linux/compiler.h>
25#include <linux/slab.h>
26#include <linux/delay.h>
14c85021 27#include <linux/in.h>
1da177e4
LT
28#include <linux/init.h>
29#include <linux/ioport.h>
30#include <linux/pci.h>
31#include <linux/netdevice.h>
32#include <linux/etherdevice.h>
33#include <linux/skbuff.h>
34#include <linux/ethtool.h>
35#include <linux/mii.h>
36#include <linux/if_vlan.h>
37#include <linux/ip.h>
38#include <linux/tcp.h>
39#include <linux/workqueue.h>
61487480 40#include <linux/prefetch.h>
f9a5f7d3 41#include <linux/dma-mapping.h>
1da177e4
LT
42
43#include <net/checksum.h>
44
45#include <asm/system.h>
46#include <asm/io.h>
47#include <asm/byteorder.h>
48#include <asm/uaccess.h>
49
50#ifdef CONFIG_SPARC64
51#include <asm/idprom.h>
52#include <asm/oplib.h>
53#include <asm/pbm.h>
54#endif
55
56#if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
57#define TG3_VLAN_TAG_USED 1
58#else
59#define TG3_VLAN_TAG_USED 0
60#endif
61
62#ifdef NETIF_F_TSO
63#define TG3_TSO_SUPPORT 1
64#else
65#define TG3_TSO_SUPPORT 0
66#endif
67
68#include "tg3.h"
69
70#define DRV_MODULE_NAME "tg3"
71#define PFX DRV_MODULE_NAME ": "
4f81c32b
MC
72#define DRV_MODULE_VERSION "3.51"
73#define DRV_MODULE_RELDATE "Feb 21, 2006"
1da177e4
LT
74
75#define TG3_DEF_MAC_MODE 0
76#define TG3_DEF_RX_MODE 0
77#define TG3_DEF_TX_MODE 0
78#define TG3_DEF_MSG_ENABLE \
79 (NETIF_MSG_DRV | \
80 NETIF_MSG_PROBE | \
81 NETIF_MSG_LINK | \
82 NETIF_MSG_TIMER | \
83 NETIF_MSG_IFDOWN | \
84 NETIF_MSG_IFUP | \
85 NETIF_MSG_RX_ERR | \
86 NETIF_MSG_TX_ERR)
87
88/* length of time before we decide the hardware is borked,
89 * and dev->tx_timeout() should be called to fix the problem
90 */
91#define TG3_TX_TIMEOUT (5 * HZ)
92
93/* hardware minimum and maximum for a single frame's data payload */
94#define TG3_MIN_MTU 60
95#define TG3_MAX_MTU(tp) \
0f893dc6 96 ((tp->tg3_flags2 & TG3_FLG2_JUMBO_CAPABLE) ? 9000 : 1500)
1da177e4
LT
97
98/* These numbers seem to be hard coded in the NIC firmware somehow.
99 * You can't change the ring sizes, but you can change where you place
100 * them in the NIC onboard memory.
101 */
102#define TG3_RX_RING_SIZE 512
103#define TG3_DEF_RX_RING_PENDING 200
104#define TG3_RX_JUMBO_RING_SIZE 256
105#define TG3_DEF_RX_JUMBO_RING_PENDING 100
106
107/* Do not place this n-ring entries value into the tp struct itself,
108 * we really want to expose these constants to GCC so that modulo et
109 * al. operations are done with shifts and masks instead of with
110 * hw multiply/modulo instructions. Another solution would be to
111 * replace things like '% foo' with '& (foo - 1)'.
112 */
113#define TG3_RX_RCB_RING_SIZE(tp) \
114 ((tp->tg3_flags2 & TG3_FLG2_5705_PLUS) ? 512 : 1024)
115
116#define TG3_TX_RING_SIZE 512
117#define TG3_DEF_TX_RING_PENDING (TG3_TX_RING_SIZE - 1)
118
119#define TG3_RX_RING_BYTES (sizeof(struct tg3_rx_buffer_desc) * \
120 TG3_RX_RING_SIZE)
121#define TG3_RX_JUMBO_RING_BYTES (sizeof(struct tg3_rx_buffer_desc) * \
122 TG3_RX_JUMBO_RING_SIZE)
123#define TG3_RX_RCB_RING_BYTES(tp) (sizeof(struct tg3_rx_buffer_desc) * \
124 TG3_RX_RCB_RING_SIZE(tp))
125#define TG3_TX_RING_BYTES (sizeof(struct tg3_tx_buffer_desc) * \
126 TG3_TX_RING_SIZE)
1da177e4 127#define TX_BUFFS_AVAIL(TP) \
51b91468
MC
128 ((TP)->tx_pending - \
129 (((TP)->tx_prod - (TP)->tx_cons) & (TG3_TX_RING_SIZE - 1)))
1da177e4
LT
130#define NEXT_TX(N) (((N) + 1) & (TG3_TX_RING_SIZE - 1))
131
132#define RX_PKT_BUF_SZ (1536 + tp->rx_offset + 64)
133#define RX_JUMBO_PKT_BUF_SZ (9046 + tp->rx_offset + 64)
134
135/* minimum number of free TX descriptors required to wake up TX process */
136#define TG3_TX_WAKEUP_THRESH (TG3_TX_RING_SIZE / 4)
137
138/* number of ETHTOOL_GSTATS u64's */
139#define TG3_NUM_STATS (sizeof(struct tg3_ethtool_stats)/sizeof(u64))
140
4cafd3f5
MC
141#define TG3_NUM_TEST 6
142
1da177e4
LT
143static char version[] __devinitdata =
144 DRV_MODULE_NAME ".c:v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
145
146MODULE_AUTHOR("David S. Miller (davem@redhat.com) and Jeff Garzik (jgarzik@pobox.com)");
147MODULE_DESCRIPTION("Broadcom Tigon3 ethernet driver");
148MODULE_LICENSE("GPL");
149MODULE_VERSION(DRV_MODULE_VERSION);
150
151static int tg3_debug = -1; /* -1 == use TG3_DEF_MSG_ENABLE as value */
152module_param(tg3_debug, int, 0);
153MODULE_PARM_DESC(tg3_debug, "Tigon3 bitmapped debugging message enable value");
154
155static struct pci_device_id tg3_pci_tbl[] = {
156 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5700,
157 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
158 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5701,
159 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
160 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702,
161 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
162 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5703,
163 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
164 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5704,
165 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
166 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702FE,
167 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
168 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705,
169 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
170 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705_2,
171 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
172 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705M,
173 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
174 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705M_2,
175 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
176 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702X,
177 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
178 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5703X,
179 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
180 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5704S,
181 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
182 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702A3,
183 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
184 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5703A3,
185 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
186 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5782,
187 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
188 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5788,
189 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
190 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5789,
191 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
192 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5901,
193 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
194 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5901_2,
195 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
196 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5704S_2,
197 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
198 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705F,
199 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
200 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5720,
201 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
202 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5721,
203 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
204 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5750,
205 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
206 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5751,
207 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
208 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5750M,
209 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
210 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5751M,
211 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
212 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5751F,
213 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
6e9017a7 214 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5752,
af2bcd97 215 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
d8659255
XVP
216 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5752M,
217 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
1da177e4
LT
218 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753,
219 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
220 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753M,
221 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
222 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753F,
223 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
d9ab5ad1
MC
224 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5754,
225 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
226 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5754M,
227 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
228 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5787,
229 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
230 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5787M,
231 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
a4e2b347
MC
232 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5714,
233 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
d4d2c558
MC
234 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5714S,
235 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
a4e2b347
MC
236 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5715,
237 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
d4d2c558
MC
238 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5715S,
239 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
4cf78e4f
MC
240 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5780,
241 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
242 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5780S,
243 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
1da177e4
LT
244 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5781,
245 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
246 { PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_9DXX,
247 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
248 { PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_9MXX,
249 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
250 { PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1000,
251 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
252 { PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1001,
253 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
254 { PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1003,
255 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
256 { PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC9100,
257 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
258 { PCI_VENDOR_ID_APPLE, PCI_DEVICE_ID_APPLE_TIGON3,
259 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
260 { 0, }
261};
262
263MODULE_DEVICE_TABLE(pci, tg3_pci_tbl);
264
265static struct {
266 const char string[ETH_GSTRING_LEN];
267} ethtool_stats_keys[TG3_NUM_STATS] = {
268 { "rx_octets" },
269 { "rx_fragments" },
270 { "rx_ucast_packets" },
271 { "rx_mcast_packets" },
272 { "rx_bcast_packets" },
273 { "rx_fcs_errors" },
274 { "rx_align_errors" },
275 { "rx_xon_pause_rcvd" },
276 { "rx_xoff_pause_rcvd" },
277 { "rx_mac_ctrl_rcvd" },
278 { "rx_xoff_entered" },
279 { "rx_frame_too_long_errors" },
280 { "rx_jabbers" },
281 { "rx_undersize_packets" },
282 { "rx_in_length_errors" },
283 { "rx_out_length_errors" },
284 { "rx_64_or_less_octet_packets" },
285 { "rx_65_to_127_octet_packets" },
286 { "rx_128_to_255_octet_packets" },
287 { "rx_256_to_511_octet_packets" },
288 { "rx_512_to_1023_octet_packets" },
289 { "rx_1024_to_1522_octet_packets" },
290 { "rx_1523_to_2047_octet_packets" },
291 { "rx_2048_to_4095_octet_packets" },
292 { "rx_4096_to_8191_octet_packets" },
293 { "rx_8192_to_9022_octet_packets" },
294
295 { "tx_octets" },
296 { "tx_collisions" },
297
298 { "tx_xon_sent" },
299 { "tx_xoff_sent" },
300 { "tx_flow_control" },
301 { "tx_mac_errors" },
302 { "tx_single_collisions" },
303 { "tx_mult_collisions" },
304 { "tx_deferred" },
305 { "tx_excessive_collisions" },
306 { "tx_late_collisions" },
307 { "tx_collide_2times" },
308 { "tx_collide_3times" },
309 { "tx_collide_4times" },
310 { "tx_collide_5times" },
311 { "tx_collide_6times" },
312 { "tx_collide_7times" },
313 { "tx_collide_8times" },
314 { "tx_collide_9times" },
315 { "tx_collide_10times" },
316 { "tx_collide_11times" },
317 { "tx_collide_12times" },
318 { "tx_collide_13times" },
319 { "tx_collide_14times" },
320 { "tx_collide_15times" },
321 { "tx_ucast_packets" },
322 { "tx_mcast_packets" },
323 { "tx_bcast_packets" },
324 { "tx_carrier_sense_errors" },
325 { "tx_discards" },
326 { "tx_errors" },
327
328 { "dma_writeq_full" },
329 { "dma_write_prioq_full" },
330 { "rxbds_empty" },
331 { "rx_discards" },
332 { "rx_errors" },
333 { "rx_threshold_hit" },
334
335 { "dma_readq_full" },
336 { "dma_read_prioq_full" },
337 { "tx_comp_queue_full" },
338
339 { "ring_set_send_prod_index" },
340 { "ring_status_update" },
341 { "nic_irqs" },
342 { "nic_avoided_irqs" },
343 { "nic_tx_threshold_hit" }
344};
345
4cafd3f5
MC
346static struct {
347 const char string[ETH_GSTRING_LEN];
348} ethtool_test_keys[TG3_NUM_TEST] = {
349 { "nvram test (online) " },
350 { "link test (online) " },
351 { "register test (offline)" },
352 { "memory test (offline)" },
353 { "loopback test (offline)" },
354 { "interrupt test (offline)" },
355};
356
b401e9e2
MC
357static void tg3_write32(struct tg3 *tp, u32 off, u32 val)
358{
359 writel(val, tp->regs + off);
360}
361
362static u32 tg3_read32(struct tg3 *tp, u32 off)
363{
364 return (readl(tp->regs + off));
365}
366
1da177e4
LT
367static void tg3_write_indirect_reg32(struct tg3 *tp, u32 off, u32 val)
368{
6892914f
MC
369 unsigned long flags;
370
371 spin_lock_irqsave(&tp->indirect_lock, flags);
1ee582d8
MC
372 pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off);
373 pci_write_config_dword(tp->pdev, TG3PCI_REG_DATA, val);
6892914f 374 spin_unlock_irqrestore(&tp->indirect_lock, flags);
1ee582d8
MC
375}
376
377static void tg3_write_flush_reg32(struct tg3 *tp, u32 off, u32 val)
378{
379 writel(val, tp->regs + off);
380 readl(tp->regs + off);
1da177e4
LT
381}
382
6892914f 383static u32 tg3_read_indirect_reg32(struct tg3 *tp, u32 off)
1da177e4 384{
6892914f
MC
385 unsigned long flags;
386 u32 val;
387
388 spin_lock_irqsave(&tp->indirect_lock, flags);
389 pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off);
390 pci_read_config_dword(tp->pdev, TG3PCI_REG_DATA, &val);
391 spin_unlock_irqrestore(&tp->indirect_lock, flags);
392 return val;
393}
394
395static void tg3_write_indirect_mbox(struct tg3 *tp, u32 off, u32 val)
396{
397 unsigned long flags;
398
399 if (off == (MAILBOX_RCVRET_CON_IDX_0 + TG3_64BIT_REG_LOW)) {
400 pci_write_config_dword(tp->pdev, TG3PCI_RCV_RET_RING_CON_IDX +
401 TG3_64BIT_REG_LOW, val);
402 return;
403 }
404 if (off == (MAILBOX_RCV_STD_PROD_IDX + TG3_64BIT_REG_LOW)) {
405 pci_write_config_dword(tp->pdev, TG3PCI_STD_RING_PROD_IDX +
406 TG3_64BIT_REG_LOW, val);
407 return;
1da177e4 408 }
6892914f
MC
409
410 spin_lock_irqsave(&tp->indirect_lock, flags);
411 pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off + 0x5600);
412 pci_write_config_dword(tp->pdev, TG3PCI_REG_DATA, val);
413 spin_unlock_irqrestore(&tp->indirect_lock, flags);
414
415 /* In indirect mode when disabling interrupts, we also need
416 * to clear the interrupt bit in the GRC local ctrl register.
417 */
418 if ((off == (MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW)) &&
419 (val == 0x1)) {
420 pci_write_config_dword(tp->pdev, TG3PCI_MISC_LOCAL_CTRL,
421 tp->grc_local_ctrl|GRC_LCLCTRL_CLEARINT);
422 }
423}
424
425static u32 tg3_read_indirect_mbox(struct tg3 *tp, u32 off)
426{
427 unsigned long flags;
428 u32 val;
429
430 spin_lock_irqsave(&tp->indirect_lock, flags);
431 pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off + 0x5600);
432 pci_read_config_dword(tp->pdev, TG3PCI_REG_DATA, &val);
433 spin_unlock_irqrestore(&tp->indirect_lock, flags);
434 return val;
435}
436
b401e9e2
MC
437/* usec_wait specifies the wait time in usec when writing to certain registers
438 * where it is unsafe to read back the register without some delay.
439 * GRC_LOCAL_CTRL is one example if the GPIOs are toggled to switch power.
440 * TG3PCI_CLOCK_CTRL is another example if the clock frequencies are changed.
441 */
442static void _tw32_flush(struct tg3 *tp, u32 off, u32 val, u32 usec_wait)
6892914f 443{
b401e9e2
MC
444 if ((tp->tg3_flags & TG3_FLAG_PCIX_TARGET_HWBUG) ||
445 (tp->tg3_flags2 & TG3_FLG2_ICH_WORKAROUND))
446 /* Non-posted methods */
447 tp->write32(tp, off, val);
448 else {
449 /* Posted method */
450 tg3_write32(tp, off, val);
451 if (usec_wait)
452 udelay(usec_wait);
453 tp->read32(tp, off);
454 }
455 /* Wait again after the read for the posted method to guarantee that
456 * the wait time is met.
457 */
458 if (usec_wait)
459 udelay(usec_wait);
1da177e4
LT
460}
461
09ee929c
MC
462static inline void tw32_mailbox_flush(struct tg3 *tp, u32 off, u32 val)
463{
464 tp->write32_mbox(tp, off, val);
6892914f
MC
465 if (!(tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER) &&
466 !(tp->tg3_flags2 & TG3_FLG2_ICH_WORKAROUND))
467 tp->read32_mbox(tp, off);
09ee929c
MC
468}
469
20094930 470static void tg3_write32_tx_mbox(struct tg3 *tp, u32 off, u32 val)
1da177e4
LT
471{
472 void __iomem *mbox = tp->regs + off;
473 writel(val, mbox);
474 if (tp->tg3_flags & TG3_FLAG_TXD_MBOX_HWBUG)
475 writel(val, mbox);
476 if (tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER)
477 readl(mbox);
478}
479
20094930 480#define tw32_mailbox(reg, val) tp->write32_mbox(tp, reg, val)
09ee929c 481#define tw32_mailbox_f(reg, val) tw32_mailbox_flush(tp, (reg), (val))
20094930
MC
482#define tw32_rx_mbox(reg, val) tp->write32_rx_mbox(tp, reg, val)
483#define tw32_tx_mbox(reg, val) tp->write32_tx_mbox(tp, reg, val)
09ee929c 484#define tr32_mailbox(reg) tp->read32_mbox(tp, reg)
20094930
MC
485
486#define tw32(reg,val) tp->write32(tp, reg, val)
b401e9e2
MC
487#define tw32_f(reg,val) _tw32_flush(tp,(reg),(val), 0)
488#define tw32_wait_f(reg,val,us) _tw32_flush(tp,(reg),(val), (us))
20094930 489#define tr32(reg) tp->read32(tp, reg)
1da177e4
LT
490
491static void tg3_write_mem(struct tg3 *tp, u32 off, u32 val)
492{
6892914f
MC
493 unsigned long flags;
494
495 spin_lock_irqsave(&tp->indirect_lock, flags);
1da177e4
LT
496 pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, off);
497 pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val);
498
499 /* Always leave this as zero. */
500 pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0);
6892914f 501 spin_unlock_irqrestore(&tp->indirect_lock, flags);
1da177e4
LT
502}
503
28fbef78
MC
504static void tg3_write_mem_fast(struct tg3 *tp, u32 off, u32 val)
505{
506 /* If no workaround is needed, write to mem space directly */
507 if (tp->write32 != tg3_write_indirect_reg32)
508 tw32(NIC_SRAM_WIN_BASE + off, val);
509 else
510 tg3_write_mem(tp, off, val);
511}
512
1da177e4
LT
513static void tg3_read_mem(struct tg3 *tp, u32 off, u32 *val)
514{
6892914f
MC
515 unsigned long flags;
516
517 spin_lock_irqsave(&tp->indirect_lock, flags);
1da177e4
LT
518 pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, off);
519 pci_read_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val);
520
521 /* Always leave this as zero. */
522 pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0);
6892914f 523 spin_unlock_irqrestore(&tp->indirect_lock, flags);
1da177e4
LT
524}
525
526static void tg3_disable_ints(struct tg3 *tp)
527{
528 tw32(TG3PCI_MISC_HOST_CTRL,
529 (tp->misc_host_ctrl | MISC_HOST_CTRL_MASK_PCI_INT));
09ee929c 530 tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001);
1da177e4
LT
531}
532
533static inline void tg3_cond_int(struct tg3 *tp)
534{
38f3843e
MC
535 if (!(tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) &&
536 (tp->hw_status->status & SD_STATUS_UPDATED))
1da177e4
LT
537 tw32(GRC_LOCAL_CTRL, tp->grc_local_ctrl | GRC_LCLCTRL_SETINT);
538}
539
540static void tg3_enable_ints(struct tg3 *tp)
541{
bbe832c0
MC
542 tp->irq_sync = 0;
543 wmb();
544
1da177e4
LT
545 tw32(TG3PCI_MISC_HOST_CTRL,
546 (tp->misc_host_ctrl & ~MISC_HOST_CTRL_MASK_PCI_INT));
09ee929c
MC
547 tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW,
548 (tp->last_tag << 24));
fcfa0a32
MC
549 if (tp->tg3_flags2 & TG3_FLG2_1SHOT_MSI)
550 tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW,
551 (tp->last_tag << 24));
1da177e4
LT
552 tg3_cond_int(tp);
553}
554
04237ddd
MC
555static inline unsigned int tg3_has_work(struct tg3 *tp)
556{
557 struct tg3_hw_status *sblk = tp->hw_status;
558 unsigned int work_exists = 0;
559
560 /* check for phy events */
561 if (!(tp->tg3_flags &
562 (TG3_FLAG_USE_LINKCHG_REG |
563 TG3_FLAG_POLL_SERDES))) {
564 if (sblk->status & SD_STATUS_LINK_CHG)
565 work_exists = 1;
566 }
567 /* check for RX/TX work to do */
568 if (sblk->idx[0].tx_consumer != tp->tx_cons ||
569 sblk->idx[0].rx_producer != tp->rx_rcb_ptr)
570 work_exists = 1;
571
572 return work_exists;
573}
574
1da177e4 575/* tg3_restart_ints
04237ddd
MC
576 * similar to tg3_enable_ints, but it accurately determines whether there
577 * is new work pending and can return without flushing the PIO write
578 * which reenables interrupts
1da177e4
LT
579 */
580static void tg3_restart_ints(struct tg3 *tp)
581{
fac9b83e
DM
582 tw32_mailbox(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW,
583 tp->last_tag << 24);
1da177e4
LT
584 mmiowb();
585
fac9b83e
DM
586 /* When doing tagged status, this work check is unnecessary.
587 * The last_tag we write above tells the chip which piece of
588 * work we've completed.
589 */
590 if (!(tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) &&
591 tg3_has_work(tp))
04237ddd
MC
592 tw32(HOSTCC_MODE, tp->coalesce_mode |
593 (HOSTCC_MODE_ENABLE | HOSTCC_MODE_NOW));
1da177e4
LT
594}
595
596static inline void tg3_netif_stop(struct tg3 *tp)
597{
bbe832c0 598 tp->dev->trans_start = jiffies; /* prevent tx timeout */
1da177e4
LT
599 netif_poll_disable(tp->dev);
600 netif_tx_disable(tp->dev);
601}
602
603static inline void tg3_netif_start(struct tg3 *tp)
604{
605 netif_wake_queue(tp->dev);
606 /* NOTE: unconditional netif_wake_queue is only appropriate
607 * so long as all callers are assured to have free tx slots
608 * (such as after tg3_init_hw)
609 */
610 netif_poll_enable(tp->dev);
f47c11ee
DM
611 tp->hw_status->status |= SD_STATUS_UPDATED;
612 tg3_enable_ints(tp);
1da177e4
LT
613}
614
615static void tg3_switch_clocks(struct tg3 *tp)
616{
617 u32 clock_ctrl = tr32(TG3PCI_CLOCK_CTRL);
618 u32 orig_clock_ctrl;
619
a4e2b347 620 if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)
4cf78e4f
MC
621 return;
622
1da177e4
LT
623 orig_clock_ctrl = clock_ctrl;
624 clock_ctrl &= (CLOCK_CTRL_FORCE_CLKRUN |
625 CLOCK_CTRL_CLKRUN_OENABLE |
626 0x1f);
627 tp->pci_clock_ctrl = clock_ctrl;
628
629 if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
630 if (orig_clock_ctrl & CLOCK_CTRL_625_CORE) {
b401e9e2
MC
631 tw32_wait_f(TG3PCI_CLOCK_CTRL,
632 clock_ctrl | CLOCK_CTRL_625_CORE, 40);
1da177e4
LT
633 }
634 } else if ((orig_clock_ctrl & CLOCK_CTRL_44MHZ_CORE) != 0) {
b401e9e2
MC
635 tw32_wait_f(TG3PCI_CLOCK_CTRL,
636 clock_ctrl |
637 (CLOCK_CTRL_44MHZ_CORE | CLOCK_CTRL_ALTCLK),
638 40);
639 tw32_wait_f(TG3PCI_CLOCK_CTRL,
640 clock_ctrl | (CLOCK_CTRL_ALTCLK),
641 40);
1da177e4 642 }
b401e9e2 643 tw32_wait_f(TG3PCI_CLOCK_CTRL, clock_ctrl, 40);
1da177e4
LT
644}
645
646#define PHY_BUSY_LOOPS 5000
647
648static int tg3_readphy(struct tg3 *tp, int reg, u32 *val)
649{
650 u32 frame_val;
651 unsigned int loops;
652 int ret;
653
654 if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) {
655 tw32_f(MAC_MI_MODE,
656 (tp->mi_mode & ~MAC_MI_MODE_AUTO_POLL));
657 udelay(80);
658 }
659
660 *val = 0x0;
661
662 frame_val = ((PHY_ADDR << MI_COM_PHY_ADDR_SHIFT) &
663 MI_COM_PHY_ADDR_MASK);
664 frame_val |= ((reg << MI_COM_REG_ADDR_SHIFT) &
665 MI_COM_REG_ADDR_MASK);
666 frame_val |= (MI_COM_CMD_READ | MI_COM_START);
667
668 tw32_f(MAC_MI_COM, frame_val);
669
670 loops = PHY_BUSY_LOOPS;
671 while (loops != 0) {
672 udelay(10);
673 frame_val = tr32(MAC_MI_COM);
674
675 if ((frame_val & MI_COM_BUSY) == 0) {
676 udelay(5);
677 frame_val = tr32(MAC_MI_COM);
678 break;
679 }
680 loops -= 1;
681 }
682
683 ret = -EBUSY;
684 if (loops != 0) {
685 *val = frame_val & MI_COM_DATA_MASK;
686 ret = 0;
687 }
688
689 if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) {
690 tw32_f(MAC_MI_MODE, tp->mi_mode);
691 udelay(80);
692 }
693
694 return ret;
695}
696
697static int tg3_writephy(struct tg3 *tp, int reg, u32 val)
698{
699 u32 frame_val;
700 unsigned int loops;
701 int ret;
702
703 if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) {
704 tw32_f(MAC_MI_MODE,
705 (tp->mi_mode & ~MAC_MI_MODE_AUTO_POLL));
706 udelay(80);
707 }
708
709 frame_val = ((PHY_ADDR << MI_COM_PHY_ADDR_SHIFT) &
710 MI_COM_PHY_ADDR_MASK);
711 frame_val |= ((reg << MI_COM_REG_ADDR_SHIFT) &
712 MI_COM_REG_ADDR_MASK);
713 frame_val |= (val & MI_COM_DATA_MASK);
714 frame_val |= (MI_COM_CMD_WRITE | MI_COM_START);
715
716 tw32_f(MAC_MI_COM, frame_val);
717
718 loops = PHY_BUSY_LOOPS;
719 while (loops != 0) {
720 udelay(10);
721 frame_val = tr32(MAC_MI_COM);
722 if ((frame_val & MI_COM_BUSY) == 0) {
723 udelay(5);
724 frame_val = tr32(MAC_MI_COM);
725 break;
726 }
727 loops -= 1;
728 }
729
730 ret = -EBUSY;
731 if (loops != 0)
732 ret = 0;
733
734 if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) {
735 tw32_f(MAC_MI_MODE, tp->mi_mode);
736 udelay(80);
737 }
738
739 return ret;
740}
741
742static void tg3_phy_set_wirespeed(struct tg3 *tp)
743{
744 u32 val;
745
746 if (tp->tg3_flags2 & TG3_FLG2_NO_ETH_WIRE_SPEED)
747 return;
748
749 if (!tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x7007) &&
750 !tg3_readphy(tp, MII_TG3_AUX_CTRL, &val))
751 tg3_writephy(tp, MII_TG3_AUX_CTRL,
752 (val | (1 << 15) | (1 << 4)));
753}
754
755static int tg3_bmcr_reset(struct tg3 *tp)
756{
757 u32 phy_control;
758 int limit, err;
759
760 /* OK, reset it, and poll the BMCR_RESET bit until it
761 * clears or we time out.
762 */
763 phy_control = BMCR_RESET;
764 err = tg3_writephy(tp, MII_BMCR, phy_control);
765 if (err != 0)
766 return -EBUSY;
767
768 limit = 5000;
769 while (limit--) {
770 err = tg3_readphy(tp, MII_BMCR, &phy_control);
771 if (err != 0)
772 return -EBUSY;
773
774 if ((phy_control & BMCR_RESET) == 0) {
775 udelay(40);
776 break;
777 }
778 udelay(10);
779 }
780 if (limit <= 0)
781 return -EBUSY;
782
783 return 0;
784}
785
786static int tg3_wait_macro_done(struct tg3 *tp)
787{
788 int limit = 100;
789
790 while (limit--) {
791 u32 tmp32;
792
793 if (!tg3_readphy(tp, 0x16, &tmp32)) {
794 if ((tmp32 & 0x1000) == 0)
795 break;
796 }
797 }
798 if (limit <= 0)
799 return -EBUSY;
800
801 return 0;
802}
803
804static int tg3_phy_write_and_check_testpat(struct tg3 *tp, int *resetp)
805{
806 static const u32 test_pat[4][6] = {
807 { 0x00005555, 0x00000005, 0x00002aaa, 0x0000000a, 0x00003456, 0x00000003 },
808 { 0x00002aaa, 0x0000000a, 0x00003333, 0x00000003, 0x0000789a, 0x00000005 },
809 { 0x00005a5a, 0x00000005, 0x00002a6a, 0x0000000a, 0x00001bcd, 0x00000003 },
810 { 0x00002a5a, 0x0000000a, 0x000033c3, 0x00000003, 0x00002ef1, 0x00000005 }
811 };
812 int chan;
813
814 for (chan = 0; chan < 4; chan++) {
815 int i;
816
817 tg3_writephy(tp, MII_TG3_DSP_ADDRESS,
818 (chan * 0x2000) | 0x0200);
819 tg3_writephy(tp, 0x16, 0x0002);
820
821 for (i = 0; i < 6; i++)
822 tg3_writephy(tp, MII_TG3_DSP_RW_PORT,
823 test_pat[chan][i]);
824
825 tg3_writephy(tp, 0x16, 0x0202);
826 if (tg3_wait_macro_done(tp)) {
827 *resetp = 1;
828 return -EBUSY;
829 }
830
831 tg3_writephy(tp, MII_TG3_DSP_ADDRESS,
832 (chan * 0x2000) | 0x0200);
833 tg3_writephy(tp, 0x16, 0x0082);
834 if (tg3_wait_macro_done(tp)) {
835 *resetp = 1;
836 return -EBUSY;
837 }
838
839 tg3_writephy(tp, 0x16, 0x0802);
840 if (tg3_wait_macro_done(tp)) {
841 *resetp = 1;
842 return -EBUSY;
843 }
844
845 for (i = 0; i < 6; i += 2) {
846 u32 low, high;
847
848 if (tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &low) ||
849 tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &high) ||
850 tg3_wait_macro_done(tp)) {
851 *resetp = 1;
852 return -EBUSY;
853 }
854 low &= 0x7fff;
855 high &= 0x000f;
856 if (low != test_pat[chan][i] ||
857 high != test_pat[chan][i+1]) {
858 tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000b);
859 tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x4001);
860 tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x4005);
861
862 return -EBUSY;
863 }
864 }
865 }
866
867 return 0;
868}
869
870static int tg3_phy_reset_chanpat(struct tg3 *tp)
871{
872 int chan;
873
874 for (chan = 0; chan < 4; chan++) {
875 int i;
876
877 tg3_writephy(tp, MII_TG3_DSP_ADDRESS,
878 (chan * 0x2000) | 0x0200);
879 tg3_writephy(tp, 0x16, 0x0002);
880 for (i = 0; i < 6; i++)
881 tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x000);
882 tg3_writephy(tp, 0x16, 0x0202);
883 if (tg3_wait_macro_done(tp))
884 return -EBUSY;
885 }
886
887 return 0;
888}
889
890static int tg3_phy_reset_5703_4_5(struct tg3 *tp)
891{
892 u32 reg32, phy9_orig;
893 int retries, do_phy_reset, err;
894
895 retries = 10;
896 do_phy_reset = 1;
897 do {
898 if (do_phy_reset) {
899 err = tg3_bmcr_reset(tp);
900 if (err)
901 return err;
902 do_phy_reset = 0;
903 }
904
905 /* Disable transmitter and interrupt. */
906 if (tg3_readphy(tp, MII_TG3_EXT_CTRL, &reg32))
907 continue;
908
909 reg32 |= 0x3000;
910 tg3_writephy(tp, MII_TG3_EXT_CTRL, reg32);
911
912 /* Set full-duplex, 1000 mbps. */
913 tg3_writephy(tp, MII_BMCR,
914 BMCR_FULLDPLX | TG3_BMCR_SPEED1000);
915
916 /* Set to master mode. */
917 if (tg3_readphy(tp, MII_TG3_CTRL, &phy9_orig))
918 continue;
919
920 tg3_writephy(tp, MII_TG3_CTRL,
921 (MII_TG3_CTRL_AS_MASTER |
922 MII_TG3_CTRL_ENABLE_AS_MASTER));
923
924 /* Enable SM_DSP_CLOCK and 6dB. */
925 tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0c00);
926
927 /* Block the PHY control access. */
928 tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8005);
929 tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0800);
930
931 err = tg3_phy_write_and_check_testpat(tp, &do_phy_reset);
932 if (!err)
933 break;
934 } while (--retries);
935
936 err = tg3_phy_reset_chanpat(tp);
937 if (err)
938 return err;
939
940 tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8005);
941 tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0000);
942
943 tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8200);
944 tg3_writephy(tp, 0x16, 0x0000);
945
946 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 ||
947 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) {
948 /* Set Extended packet length bit for jumbo frames */
949 tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x4400);
950 }
951 else {
952 tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0400);
953 }
954
955 tg3_writephy(tp, MII_TG3_CTRL, phy9_orig);
956
957 if (!tg3_readphy(tp, MII_TG3_EXT_CTRL, &reg32)) {
958 reg32 &= ~0x3000;
959 tg3_writephy(tp, MII_TG3_EXT_CTRL, reg32);
960 } else if (!err)
961 err = -EBUSY;
962
963 return err;
964}
965
966/* This will reset the tigon3 PHY if there is no valid
967 * link unless the FORCE argument is non-zero.
968 */
969static int tg3_phy_reset(struct tg3 *tp)
970{
971 u32 phy_status;
972 int err;
973
974 err = tg3_readphy(tp, MII_BMSR, &phy_status);
975 err |= tg3_readphy(tp, MII_BMSR, &phy_status);
976 if (err != 0)
977 return -EBUSY;
978
979 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 ||
980 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 ||
981 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) {
982 err = tg3_phy_reset_5703_4_5(tp);
983 if (err)
984 return err;
985 goto out;
986 }
987
988 err = tg3_bmcr_reset(tp);
989 if (err)
990 return err;
991
992out:
993 if (tp->tg3_flags2 & TG3_FLG2_PHY_ADC_BUG) {
994 tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0c00);
995 tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x201f);
996 tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x2aaa);
997 tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000a);
998 tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0323);
999 tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0400);
1000 }
1001 if (tp->tg3_flags2 & TG3_FLG2_PHY_5704_A0_BUG) {
1002 tg3_writephy(tp, 0x1c, 0x8d68);
1003 tg3_writephy(tp, 0x1c, 0x8d68);
1004 }
1005 if (tp->tg3_flags2 & TG3_FLG2_PHY_BER_BUG) {
1006 tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0c00);
1007 tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000a);
1008 tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x310b);
1009 tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x201f);
1010 tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x9506);
1011 tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x401f);
1012 tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x14e2);
1013 tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0400);
1014 }
1015 /* Set Extended packet length bit (bit 14) on all chips that */
1016 /* support jumbo frames */
1017 if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5401) {
1018 /* Cannot do read-modify-write on 5401 */
1019 tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x4c20);
0f893dc6 1020 } else if (tp->tg3_flags2 & TG3_FLG2_JUMBO_CAPABLE) {
1da177e4
LT
1021 u32 phy_reg;
1022
1023 /* Set bit 14 with read-modify-write to preserve other bits */
1024 if (!tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0007) &&
1025 !tg3_readphy(tp, MII_TG3_AUX_CTRL, &phy_reg))
1026 tg3_writephy(tp, MII_TG3_AUX_CTRL, phy_reg | 0x4000);
1027 }
1028
1029 /* Set phy register 0x10 bit 0 to high fifo elasticity to support
1030 * jumbo frames transmission.
1031 */
0f893dc6 1032 if (tp->tg3_flags2 & TG3_FLG2_JUMBO_CAPABLE) {
1da177e4
LT
1033 u32 phy_reg;
1034
1035 if (!tg3_readphy(tp, MII_TG3_EXT_CTRL, &phy_reg))
1036 tg3_writephy(tp, MII_TG3_EXT_CTRL,
1037 phy_reg | MII_TG3_EXT_CTRL_FIFO_ELASTIC);
1038 }
1039
1040 tg3_phy_set_wirespeed(tp);
1041 return 0;
1042}
1043
1044static void tg3_frob_aux_power(struct tg3 *tp)
1045{
1046 struct tg3 *tp_peer = tp;
1047
1048 if ((tp->tg3_flags & TG3_FLAG_EEPROM_WRITE_PROT) != 0)
1049 return;
1050
8c2dc7e1
MC
1051 if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) ||
1052 (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714)) {
1053 struct net_device *dev_peer;
1054
1055 dev_peer = pci_get_drvdata(tp->pdev_peer);
bc1c7567 1056 /* remove_one() may have been run on the peer. */
8c2dc7e1 1057 if (!dev_peer)
bc1c7567
MC
1058 tp_peer = tp;
1059 else
1060 tp_peer = netdev_priv(dev_peer);
1da177e4
LT
1061 }
1062
1da177e4 1063 if ((tp->tg3_flags & TG3_FLAG_WOL_ENABLE) != 0 ||
6921d201
MC
1064 (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) != 0 ||
1065 (tp_peer->tg3_flags & TG3_FLAG_WOL_ENABLE) != 0 ||
1066 (tp_peer->tg3_flags & TG3_FLAG_ENABLE_ASF) != 0) {
1da177e4
LT
1067 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
1068 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) {
b401e9e2
MC
1069 tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
1070 (GRC_LCLCTRL_GPIO_OE0 |
1071 GRC_LCLCTRL_GPIO_OE1 |
1072 GRC_LCLCTRL_GPIO_OE2 |
1073 GRC_LCLCTRL_GPIO_OUTPUT0 |
1074 GRC_LCLCTRL_GPIO_OUTPUT1),
1075 100);
1da177e4
LT
1076 } else {
1077 u32 no_gpio2;
dc56b7d4 1078 u32 grc_local_ctrl = 0;
1da177e4
LT
1079
1080 if (tp_peer != tp &&
1081 (tp_peer->tg3_flags & TG3_FLAG_INIT_COMPLETE) != 0)
1082 return;
1083
dc56b7d4
MC
1084 /* Workaround to prevent overdrawing Amps. */
1085 if (GET_ASIC_REV(tp->pci_chip_rev_id) ==
1086 ASIC_REV_5714) {
1087 grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE3;
b401e9e2
MC
1088 tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
1089 grc_local_ctrl, 100);
dc56b7d4
MC
1090 }
1091
1da177e4
LT
1092 /* On 5753 and variants, GPIO2 cannot be used. */
1093 no_gpio2 = tp->nic_sram_data_cfg &
1094 NIC_SRAM_DATA_CFG_NO_GPIO2;
1095
dc56b7d4 1096 grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE0 |
1da177e4
LT
1097 GRC_LCLCTRL_GPIO_OE1 |
1098 GRC_LCLCTRL_GPIO_OE2 |
1099 GRC_LCLCTRL_GPIO_OUTPUT1 |
1100 GRC_LCLCTRL_GPIO_OUTPUT2;
1101 if (no_gpio2) {
1102 grc_local_ctrl &= ~(GRC_LCLCTRL_GPIO_OE2 |
1103 GRC_LCLCTRL_GPIO_OUTPUT2);
1104 }
b401e9e2
MC
1105 tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
1106 grc_local_ctrl, 100);
1da177e4
LT
1107
1108 grc_local_ctrl |= GRC_LCLCTRL_GPIO_OUTPUT0;
1109
b401e9e2
MC
1110 tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
1111 grc_local_ctrl, 100);
1da177e4
LT
1112
1113 if (!no_gpio2) {
1114 grc_local_ctrl &= ~GRC_LCLCTRL_GPIO_OUTPUT2;
b401e9e2
MC
1115 tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
1116 grc_local_ctrl, 100);
1da177e4
LT
1117 }
1118 }
1119 } else {
1120 if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 &&
1121 GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) {
1122 if (tp_peer != tp &&
1123 (tp_peer->tg3_flags & TG3_FLAG_INIT_COMPLETE) != 0)
1124 return;
1125
b401e9e2
MC
1126 tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
1127 (GRC_LCLCTRL_GPIO_OE1 |
1128 GRC_LCLCTRL_GPIO_OUTPUT1), 100);
1da177e4 1129
b401e9e2
MC
1130 tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
1131 GRC_LCLCTRL_GPIO_OE1, 100);
1da177e4 1132
b401e9e2
MC
1133 tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
1134 (GRC_LCLCTRL_GPIO_OE1 |
1135 GRC_LCLCTRL_GPIO_OUTPUT1), 100);
1da177e4
LT
1136 }
1137 }
1138}
1139
1140static int tg3_setup_phy(struct tg3 *, int);
1141
1142#define RESET_KIND_SHUTDOWN 0
1143#define RESET_KIND_INIT 1
1144#define RESET_KIND_SUSPEND 2
1145
1146static void tg3_write_sig_post_reset(struct tg3 *, int);
1147static int tg3_halt_cpu(struct tg3 *, u32);
6921d201
MC
1148static int tg3_nvram_lock(struct tg3 *);
1149static void tg3_nvram_unlock(struct tg3 *);
1da177e4 1150
bc1c7567 1151static int tg3_set_power_state(struct tg3 *tp, pci_power_t state)
1da177e4
LT
1152{
1153 u32 misc_host_ctrl;
1154 u16 power_control, power_caps;
1155 int pm = tp->pm_cap;
1156
1157 /* Make sure register accesses (indirect or otherwise)
1158 * will function correctly.
1159 */
1160 pci_write_config_dword(tp->pdev,
1161 TG3PCI_MISC_HOST_CTRL,
1162 tp->misc_host_ctrl);
1163
1164 pci_read_config_word(tp->pdev,
1165 pm + PCI_PM_CTRL,
1166 &power_control);
1167 power_control |= PCI_PM_CTRL_PME_STATUS;
1168 power_control &= ~(PCI_PM_CTRL_STATE_MASK);
1169 switch (state) {
bc1c7567 1170 case PCI_D0:
1da177e4
LT
1171 power_control |= 0;
1172 pci_write_config_word(tp->pdev,
1173 pm + PCI_PM_CTRL,
1174 power_control);
8c6bda1a
MC
1175 udelay(100); /* Delay after power state change */
1176
1177 /* Switch out of Vaux if it is not a LOM */
b401e9e2
MC
1178 if (!(tp->tg3_flags & TG3_FLAG_EEPROM_WRITE_PROT))
1179 tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl, 100);
1da177e4
LT
1180
1181 return 0;
1182
bc1c7567 1183 case PCI_D1:
1da177e4
LT
1184 power_control |= 1;
1185 break;
1186
bc1c7567 1187 case PCI_D2:
1da177e4
LT
1188 power_control |= 2;
1189 break;
1190
bc1c7567 1191 case PCI_D3hot:
1da177e4
LT
1192 power_control |= 3;
1193 break;
1194
1195 default:
1196 printk(KERN_WARNING PFX "%s: Invalid power state (%d) "
1197 "requested.\n",
1198 tp->dev->name, state);
1199 return -EINVAL;
1200 };
1201
1202 power_control |= PCI_PM_CTRL_PME_ENABLE;
1203
1204 misc_host_ctrl = tr32(TG3PCI_MISC_HOST_CTRL);
1205 tw32(TG3PCI_MISC_HOST_CTRL,
1206 misc_host_ctrl | MISC_HOST_CTRL_MASK_PCI_INT);
1207
1208 if (tp->link_config.phy_is_low_power == 0) {
1209 tp->link_config.phy_is_low_power = 1;
1210 tp->link_config.orig_speed = tp->link_config.speed;
1211 tp->link_config.orig_duplex = tp->link_config.duplex;
1212 tp->link_config.orig_autoneg = tp->link_config.autoneg;
1213 }
1214
747e8f8b 1215 if (!(tp->tg3_flags2 & TG3_FLG2_ANY_SERDES)) {
1da177e4
LT
1216 tp->link_config.speed = SPEED_10;
1217 tp->link_config.duplex = DUPLEX_HALF;
1218 tp->link_config.autoneg = AUTONEG_ENABLE;
1219 tg3_setup_phy(tp, 0);
1220 }
1221
6921d201
MC
1222 if (!(tp->tg3_flags & TG3_FLAG_ENABLE_ASF)) {
1223 int i;
1224 u32 val;
1225
1226 for (i = 0; i < 200; i++) {
1227 tg3_read_mem(tp, NIC_SRAM_FW_ASF_STATUS_MBOX, &val);
1228 if (val == ~NIC_SRAM_FIRMWARE_MBOX_MAGIC1)
1229 break;
1230 msleep(1);
1231 }
1232 }
1233 tg3_write_mem(tp, NIC_SRAM_WOL_MBOX, WOL_SIGNATURE |
1234 WOL_DRV_STATE_SHUTDOWN |
1235 WOL_DRV_WOL | WOL_SET_MAGIC_PKT);
1236
1da177e4
LT
1237 pci_read_config_word(tp->pdev, pm + PCI_PM_PMC, &power_caps);
1238
1239 if (tp->tg3_flags & TG3_FLAG_WOL_ENABLE) {
1240 u32 mac_mode;
1241
1242 if (!(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)) {
1243 tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x5a);
1244 udelay(40);
1245
1246 mac_mode = MAC_MODE_PORT_MODE_MII;
1247
1248 if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 ||
1249 !(tp->tg3_flags & TG3_FLAG_WOL_SPEED_100MB))
1250 mac_mode |= MAC_MODE_LINK_POLARITY;
1251 } else {
1252 mac_mode = MAC_MODE_PORT_MODE_TBI;
1253 }
1254
cbf46853 1255 if (!(tp->tg3_flags2 & TG3_FLG2_5750_PLUS))
1da177e4
LT
1256 tw32(MAC_LED_CTRL, tp->led_ctrl);
1257
1258 if (((power_caps & PCI_PM_CAP_PME_D3cold) &&
1259 (tp->tg3_flags & TG3_FLAG_WOL_ENABLE)))
1260 mac_mode |= MAC_MODE_MAGIC_PKT_ENABLE;
1261
1262 tw32_f(MAC_MODE, mac_mode);
1263 udelay(100);
1264
1265 tw32_f(MAC_RX_MODE, RX_MODE_ENABLE);
1266 udelay(10);
1267 }
1268
1269 if (!(tp->tg3_flags & TG3_FLAG_WOL_SPEED_100MB) &&
1270 (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
1271 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701)) {
1272 u32 base_val;
1273
1274 base_val = tp->pci_clock_ctrl;
1275 base_val |= (CLOCK_CTRL_RXCLK_DISABLE |
1276 CLOCK_CTRL_TXCLK_DISABLE);
1277
b401e9e2
MC
1278 tw32_wait_f(TG3PCI_CLOCK_CTRL, base_val | CLOCK_CTRL_ALTCLK |
1279 CLOCK_CTRL_PWRDOWN_PLL133, 40);
a4e2b347 1280 } else if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS) {
4cf78e4f 1281 /* do nothing */
85e94ced 1282 } else if (!((tp->tg3_flags2 & TG3_FLG2_5750_PLUS) &&
1da177e4
LT
1283 (tp->tg3_flags & TG3_FLAG_ENABLE_ASF))) {
1284 u32 newbits1, newbits2;
1285
1286 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
1287 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) {
1288 newbits1 = (CLOCK_CTRL_RXCLK_DISABLE |
1289 CLOCK_CTRL_TXCLK_DISABLE |
1290 CLOCK_CTRL_ALTCLK);
1291 newbits2 = newbits1 | CLOCK_CTRL_44MHZ_CORE;
1292 } else if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
1293 newbits1 = CLOCK_CTRL_625_CORE;
1294 newbits2 = newbits1 | CLOCK_CTRL_ALTCLK;
1295 } else {
1296 newbits1 = CLOCK_CTRL_ALTCLK;
1297 newbits2 = newbits1 | CLOCK_CTRL_44MHZ_CORE;
1298 }
1299
b401e9e2
MC
1300 tw32_wait_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl | newbits1,
1301 40);
1da177e4 1302
b401e9e2
MC
1303 tw32_wait_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl | newbits2,
1304 40);
1da177e4
LT
1305
1306 if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
1307 u32 newbits3;
1308
1309 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
1310 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) {
1311 newbits3 = (CLOCK_CTRL_RXCLK_DISABLE |
1312 CLOCK_CTRL_TXCLK_DISABLE |
1313 CLOCK_CTRL_44MHZ_CORE);
1314 } else {
1315 newbits3 = CLOCK_CTRL_44MHZ_CORE;
1316 }
1317
b401e9e2
MC
1318 tw32_wait_f(TG3PCI_CLOCK_CTRL,
1319 tp->pci_clock_ctrl | newbits3, 40);
1da177e4
LT
1320 }
1321 }
1322
6921d201
MC
1323 if (!(tp->tg3_flags & TG3_FLAG_WOL_ENABLE) &&
1324 !(tp->tg3_flags & TG3_FLAG_ENABLE_ASF)) {
1325 /* Turn off the PHY */
1326 if (!(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)) {
1327 tg3_writephy(tp, MII_TG3_EXT_CTRL,
1328 MII_TG3_EXT_CTRL_FORCE_LED_OFF);
1329 tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x01b2);
dc56b7d4
MC
1330 if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700)
1331 tg3_writephy(tp, MII_BMCR, BMCR_PDOWN);
6921d201
MC
1332 }
1333 }
1334
1da177e4
LT
1335 tg3_frob_aux_power(tp);
1336
1337 /* Workaround for unstable PLL clock */
1338 if ((GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_AX) ||
1339 (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_BX)) {
1340 u32 val = tr32(0x7d00);
1341
1342 val &= ~((1 << 16) | (1 << 4) | (1 << 2) | (1 << 1) | 1);
1343 tw32(0x7d00, val);
6921d201 1344 if (!(tp->tg3_flags & TG3_FLAG_ENABLE_ASF)) {
ec41c7df
MC
1345 int err;
1346
1347 err = tg3_nvram_lock(tp);
1da177e4 1348 tg3_halt_cpu(tp, RX_CPU_BASE);
ec41c7df
MC
1349 if (!err)
1350 tg3_nvram_unlock(tp);
6921d201 1351 }
1da177e4
LT
1352 }
1353
1354 /* Finally, set the new power state. */
1355 pci_write_config_word(tp->pdev, pm + PCI_PM_CTRL, power_control);
8c6bda1a 1356 udelay(100); /* Delay after power state change */
1da177e4
LT
1357
1358 tg3_write_sig_post_reset(tp, RESET_KIND_SHUTDOWN);
1359
1360 return 0;
1361}
1362
1363static void tg3_link_report(struct tg3 *tp)
1364{
1365 if (!netif_carrier_ok(tp->dev)) {
1366 printk(KERN_INFO PFX "%s: Link is down.\n", tp->dev->name);
1367 } else {
1368 printk(KERN_INFO PFX "%s: Link is up at %d Mbps, %s duplex.\n",
1369 tp->dev->name,
1370 (tp->link_config.active_speed == SPEED_1000 ?
1371 1000 :
1372 (tp->link_config.active_speed == SPEED_100 ?
1373 100 : 10)),
1374 (tp->link_config.active_duplex == DUPLEX_FULL ?
1375 "full" : "half"));
1376
1377 printk(KERN_INFO PFX "%s: Flow control is %s for TX and "
1378 "%s for RX.\n",
1379 tp->dev->name,
1380 (tp->tg3_flags & TG3_FLAG_TX_PAUSE) ? "on" : "off",
1381 (tp->tg3_flags & TG3_FLAG_RX_PAUSE) ? "on" : "off");
1382 }
1383}
1384
1385static void tg3_setup_flow_control(struct tg3 *tp, u32 local_adv, u32 remote_adv)
1386{
1387 u32 new_tg3_flags = 0;
1388 u32 old_rx_mode = tp->rx_mode;
1389 u32 old_tx_mode = tp->tx_mode;
1390
1391 if (tp->tg3_flags & TG3_FLAG_PAUSE_AUTONEG) {
747e8f8b
MC
1392
1393 /* Convert 1000BaseX flow control bits to 1000BaseT
1394 * bits before resolving flow control.
1395 */
1396 if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES) {
1397 local_adv &= ~(ADVERTISE_PAUSE_CAP |
1398 ADVERTISE_PAUSE_ASYM);
1399 remote_adv &= ~(LPA_PAUSE_CAP | LPA_PAUSE_ASYM);
1400
1401 if (local_adv & ADVERTISE_1000XPAUSE)
1402 local_adv |= ADVERTISE_PAUSE_CAP;
1403 if (local_adv & ADVERTISE_1000XPSE_ASYM)
1404 local_adv |= ADVERTISE_PAUSE_ASYM;
1405 if (remote_adv & LPA_1000XPAUSE)
1406 remote_adv |= LPA_PAUSE_CAP;
1407 if (remote_adv & LPA_1000XPAUSE_ASYM)
1408 remote_adv |= LPA_PAUSE_ASYM;
1409 }
1410
1da177e4
LT
1411 if (local_adv & ADVERTISE_PAUSE_CAP) {
1412 if (local_adv & ADVERTISE_PAUSE_ASYM) {
1413 if (remote_adv & LPA_PAUSE_CAP)
1414 new_tg3_flags |=
1415 (TG3_FLAG_RX_PAUSE |
1416 TG3_FLAG_TX_PAUSE);
1417 else if (remote_adv & LPA_PAUSE_ASYM)
1418 new_tg3_flags |=
1419 (TG3_FLAG_RX_PAUSE);
1420 } else {
1421 if (remote_adv & LPA_PAUSE_CAP)
1422 new_tg3_flags |=
1423 (TG3_FLAG_RX_PAUSE |
1424 TG3_FLAG_TX_PAUSE);
1425 }
1426 } else if (local_adv & ADVERTISE_PAUSE_ASYM) {
1427 if ((remote_adv & LPA_PAUSE_CAP) &&
1428 (remote_adv & LPA_PAUSE_ASYM))
1429 new_tg3_flags |= TG3_FLAG_TX_PAUSE;
1430 }
1431
1432 tp->tg3_flags &= ~(TG3_FLAG_RX_PAUSE | TG3_FLAG_TX_PAUSE);
1433 tp->tg3_flags |= new_tg3_flags;
1434 } else {
1435 new_tg3_flags = tp->tg3_flags;
1436 }
1437
1438 if (new_tg3_flags & TG3_FLAG_RX_PAUSE)
1439 tp->rx_mode |= RX_MODE_FLOW_CTRL_ENABLE;
1440 else
1441 tp->rx_mode &= ~RX_MODE_FLOW_CTRL_ENABLE;
1442
1443 if (old_rx_mode != tp->rx_mode) {
1444 tw32_f(MAC_RX_MODE, tp->rx_mode);
1445 }
1446
1447 if (new_tg3_flags & TG3_FLAG_TX_PAUSE)
1448 tp->tx_mode |= TX_MODE_FLOW_CTRL_ENABLE;
1449 else
1450 tp->tx_mode &= ~TX_MODE_FLOW_CTRL_ENABLE;
1451
1452 if (old_tx_mode != tp->tx_mode) {
1453 tw32_f(MAC_TX_MODE, tp->tx_mode);
1454 }
1455}
1456
1457static void tg3_aux_stat_to_speed_duplex(struct tg3 *tp, u32 val, u16 *speed, u8 *duplex)
1458{
1459 switch (val & MII_TG3_AUX_STAT_SPDMASK) {
1460 case MII_TG3_AUX_STAT_10HALF:
1461 *speed = SPEED_10;
1462 *duplex = DUPLEX_HALF;
1463 break;
1464
1465 case MII_TG3_AUX_STAT_10FULL:
1466 *speed = SPEED_10;
1467 *duplex = DUPLEX_FULL;
1468 break;
1469
1470 case MII_TG3_AUX_STAT_100HALF:
1471 *speed = SPEED_100;
1472 *duplex = DUPLEX_HALF;
1473 break;
1474
1475 case MII_TG3_AUX_STAT_100FULL:
1476 *speed = SPEED_100;
1477 *duplex = DUPLEX_FULL;
1478 break;
1479
1480 case MII_TG3_AUX_STAT_1000HALF:
1481 *speed = SPEED_1000;
1482 *duplex = DUPLEX_HALF;
1483 break;
1484
1485 case MII_TG3_AUX_STAT_1000FULL:
1486 *speed = SPEED_1000;
1487 *duplex = DUPLEX_FULL;
1488 break;
1489
1490 default:
1491 *speed = SPEED_INVALID;
1492 *duplex = DUPLEX_INVALID;
1493 break;
1494 };
1495}
1496
1497static void tg3_phy_copper_begin(struct tg3 *tp)
1498{
1499 u32 new_adv;
1500 int i;
1501
1502 if (tp->link_config.phy_is_low_power) {
1503 /* Entering low power mode. Disable gigabit and
1504 * 100baseT advertisements.
1505 */
1506 tg3_writephy(tp, MII_TG3_CTRL, 0);
1507
1508 new_adv = (ADVERTISE_10HALF | ADVERTISE_10FULL |
1509 ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP);
1510 if (tp->tg3_flags & TG3_FLAG_WOL_SPEED_100MB)
1511 new_adv |= (ADVERTISE_100HALF | ADVERTISE_100FULL);
1512
1513 tg3_writephy(tp, MII_ADVERTISE, new_adv);
1514 } else if (tp->link_config.speed == SPEED_INVALID) {
1515 tp->link_config.advertising =
1516 (ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full |
1517 ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full |
1518 ADVERTISED_1000baseT_Half | ADVERTISED_1000baseT_Full |
1519 ADVERTISED_Autoneg | ADVERTISED_MII);
1520
1521 if (tp->tg3_flags & TG3_FLAG_10_100_ONLY)
1522 tp->link_config.advertising &=
1523 ~(ADVERTISED_1000baseT_Half |
1524 ADVERTISED_1000baseT_Full);
1525
1526 new_adv = (ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP);
1527 if (tp->link_config.advertising & ADVERTISED_10baseT_Half)
1528 new_adv |= ADVERTISE_10HALF;
1529 if (tp->link_config.advertising & ADVERTISED_10baseT_Full)
1530 new_adv |= ADVERTISE_10FULL;
1531 if (tp->link_config.advertising & ADVERTISED_100baseT_Half)
1532 new_adv |= ADVERTISE_100HALF;
1533 if (tp->link_config.advertising & ADVERTISED_100baseT_Full)
1534 new_adv |= ADVERTISE_100FULL;
1535 tg3_writephy(tp, MII_ADVERTISE, new_adv);
1536
1537 if (tp->link_config.advertising &
1538 (ADVERTISED_1000baseT_Half | ADVERTISED_1000baseT_Full)) {
1539 new_adv = 0;
1540 if (tp->link_config.advertising & ADVERTISED_1000baseT_Half)
1541 new_adv |= MII_TG3_CTRL_ADV_1000_HALF;
1542 if (tp->link_config.advertising & ADVERTISED_1000baseT_Full)
1543 new_adv |= MII_TG3_CTRL_ADV_1000_FULL;
1544 if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY) &&
1545 (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 ||
1546 tp->pci_chip_rev_id == CHIPREV_ID_5701_B0))
1547 new_adv |= (MII_TG3_CTRL_AS_MASTER |
1548 MII_TG3_CTRL_ENABLE_AS_MASTER);
1549 tg3_writephy(tp, MII_TG3_CTRL, new_adv);
1550 } else {
1551 tg3_writephy(tp, MII_TG3_CTRL, 0);
1552 }
1553 } else {
1554 /* Asking for a specific link mode. */
1555 if (tp->link_config.speed == SPEED_1000) {
1556 new_adv = ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP;
1557 tg3_writephy(tp, MII_ADVERTISE, new_adv);
1558
1559 if (tp->link_config.duplex == DUPLEX_FULL)
1560 new_adv = MII_TG3_CTRL_ADV_1000_FULL;
1561 else
1562 new_adv = MII_TG3_CTRL_ADV_1000_HALF;
1563 if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 ||
1564 tp->pci_chip_rev_id == CHIPREV_ID_5701_B0)
1565 new_adv |= (MII_TG3_CTRL_AS_MASTER |
1566 MII_TG3_CTRL_ENABLE_AS_MASTER);
1567 tg3_writephy(tp, MII_TG3_CTRL, new_adv);
1568 } else {
1569 tg3_writephy(tp, MII_TG3_CTRL, 0);
1570
1571 new_adv = ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP;
1572 if (tp->link_config.speed == SPEED_100) {
1573 if (tp->link_config.duplex == DUPLEX_FULL)
1574 new_adv |= ADVERTISE_100FULL;
1575 else
1576 new_adv |= ADVERTISE_100HALF;
1577 } else {
1578 if (tp->link_config.duplex == DUPLEX_FULL)
1579 new_adv |= ADVERTISE_10FULL;
1580 else
1581 new_adv |= ADVERTISE_10HALF;
1582 }
1583 tg3_writephy(tp, MII_ADVERTISE, new_adv);
1584 }
1585 }
1586
1587 if (tp->link_config.autoneg == AUTONEG_DISABLE &&
1588 tp->link_config.speed != SPEED_INVALID) {
1589 u32 bmcr, orig_bmcr;
1590
1591 tp->link_config.active_speed = tp->link_config.speed;
1592 tp->link_config.active_duplex = tp->link_config.duplex;
1593
1594 bmcr = 0;
1595 switch (tp->link_config.speed) {
1596 default:
1597 case SPEED_10:
1598 break;
1599
1600 case SPEED_100:
1601 bmcr |= BMCR_SPEED100;
1602 break;
1603
1604 case SPEED_1000:
1605 bmcr |= TG3_BMCR_SPEED1000;
1606 break;
1607 };
1608
1609 if (tp->link_config.duplex == DUPLEX_FULL)
1610 bmcr |= BMCR_FULLDPLX;
1611
1612 if (!tg3_readphy(tp, MII_BMCR, &orig_bmcr) &&
1613 (bmcr != orig_bmcr)) {
1614 tg3_writephy(tp, MII_BMCR, BMCR_LOOPBACK);
1615 for (i = 0; i < 1500; i++) {
1616 u32 tmp;
1617
1618 udelay(10);
1619 if (tg3_readphy(tp, MII_BMSR, &tmp) ||
1620 tg3_readphy(tp, MII_BMSR, &tmp))
1621 continue;
1622 if (!(tmp & BMSR_LSTATUS)) {
1623 udelay(40);
1624 break;
1625 }
1626 }
1627 tg3_writephy(tp, MII_BMCR, bmcr);
1628 udelay(40);
1629 }
1630 } else {
1631 tg3_writephy(tp, MII_BMCR,
1632 BMCR_ANENABLE | BMCR_ANRESTART);
1633 }
1634}
1635
1636static int tg3_init_5401phy_dsp(struct tg3 *tp)
1637{
1638 int err;
1639
1640 /* Turn off tap power management. */
1641 /* Set Extended packet length bit */
1642 err = tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x4c20);
1643
1644 err |= tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x0012);
1645 err |= tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x1804);
1646
1647 err |= tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x0013);
1648 err |= tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x1204);
1649
1650 err |= tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8006);
1651 err |= tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0132);
1652
1653 err |= tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8006);
1654 err |= tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0232);
1655
1656 err |= tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x201f);
1657 err |= tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0a20);
1658
1659 udelay(40);
1660
1661 return err;
1662}
1663
1664static int tg3_copper_is_advertising_all(struct tg3 *tp)
1665{
1666 u32 adv_reg, all_mask;
1667
1668 if (tg3_readphy(tp, MII_ADVERTISE, &adv_reg))
1669 return 0;
1670
1671 all_mask = (ADVERTISE_10HALF | ADVERTISE_10FULL |
1672 ADVERTISE_100HALF | ADVERTISE_100FULL);
1673 if ((adv_reg & all_mask) != all_mask)
1674 return 0;
1675 if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY)) {
1676 u32 tg3_ctrl;
1677
1678 if (tg3_readphy(tp, MII_TG3_CTRL, &tg3_ctrl))
1679 return 0;
1680
1681 all_mask = (MII_TG3_CTRL_ADV_1000_HALF |
1682 MII_TG3_CTRL_ADV_1000_FULL);
1683 if ((tg3_ctrl & all_mask) != all_mask)
1684 return 0;
1685 }
1686 return 1;
1687}
1688
1689static int tg3_setup_copper_phy(struct tg3 *tp, int force_reset)
1690{
1691 int current_link_up;
1692 u32 bmsr, dummy;
1693 u16 current_speed;
1694 u8 current_duplex;
1695 int i, err;
1696
1697 tw32(MAC_EVENT, 0);
1698
1699 tw32_f(MAC_STATUS,
1700 (MAC_STATUS_SYNC_CHANGED |
1701 MAC_STATUS_CFG_CHANGED |
1702 MAC_STATUS_MI_COMPLETION |
1703 MAC_STATUS_LNKSTATE_CHANGED));
1704 udelay(40);
1705
1706 tp->mi_mode = MAC_MI_MODE_BASE;
1707 tw32_f(MAC_MI_MODE, tp->mi_mode);
1708 udelay(80);
1709
1710 tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x02);
1711
1712 /* Some third-party PHYs need to be reset on link going
1713 * down.
1714 */
1715 if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 ||
1716 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 ||
1717 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) &&
1718 netif_carrier_ok(tp->dev)) {
1719 tg3_readphy(tp, MII_BMSR, &bmsr);
1720 if (!tg3_readphy(tp, MII_BMSR, &bmsr) &&
1721 !(bmsr & BMSR_LSTATUS))
1722 force_reset = 1;
1723 }
1724 if (force_reset)
1725 tg3_phy_reset(tp);
1726
1727 if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5401) {
1728 tg3_readphy(tp, MII_BMSR, &bmsr);
1729 if (tg3_readphy(tp, MII_BMSR, &bmsr) ||
1730 !(tp->tg3_flags & TG3_FLAG_INIT_COMPLETE))
1731 bmsr = 0;
1732
1733 if (!(bmsr & BMSR_LSTATUS)) {
1734 err = tg3_init_5401phy_dsp(tp);
1735 if (err)
1736 return err;
1737
1738 tg3_readphy(tp, MII_BMSR, &bmsr);
1739 for (i = 0; i < 1000; i++) {
1740 udelay(10);
1741 if (!tg3_readphy(tp, MII_BMSR, &bmsr) &&
1742 (bmsr & BMSR_LSTATUS)) {
1743 udelay(40);
1744 break;
1745 }
1746 }
1747
1748 if ((tp->phy_id & PHY_ID_REV_MASK) == PHY_REV_BCM5401_B0 &&
1749 !(bmsr & BMSR_LSTATUS) &&
1750 tp->link_config.active_speed == SPEED_1000) {
1751 err = tg3_phy_reset(tp);
1752 if (!err)
1753 err = tg3_init_5401phy_dsp(tp);
1754 if (err)
1755 return err;
1756 }
1757 }
1758 } else if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 ||
1759 tp->pci_chip_rev_id == CHIPREV_ID_5701_B0) {
1760 /* 5701 {A0,B0} CRC bug workaround */
1761 tg3_writephy(tp, 0x15, 0x0a75);
1762 tg3_writephy(tp, 0x1c, 0x8c68);
1763 tg3_writephy(tp, 0x1c, 0x8d68);
1764 tg3_writephy(tp, 0x1c, 0x8c68);
1765 }
1766
1767 /* Clear pending interrupts... */
1768 tg3_readphy(tp, MII_TG3_ISTAT, &dummy);
1769 tg3_readphy(tp, MII_TG3_ISTAT, &dummy);
1770
1771 if (tp->tg3_flags & TG3_FLAG_USE_MI_INTERRUPT)
1772 tg3_writephy(tp, MII_TG3_IMASK, ~MII_TG3_INT_LINKCHG);
1773 else
1774 tg3_writephy(tp, MII_TG3_IMASK, ~0);
1775
1776 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
1777 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) {
1778 if (tp->led_ctrl == LED_CTRL_MODE_PHY_1)
1779 tg3_writephy(tp, MII_TG3_EXT_CTRL,
1780 MII_TG3_EXT_CTRL_LNK3_LED_MODE);
1781 else
1782 tg3_writephy(tp, MII_TG3_EXT_CTRL, 0);
1783 }
1784
1785 current_link_up = 0;
1786 current_speed = SPEED_INVALID;
1787 current_duplex = DUPLEX_INVALID;
1788
1789 if (tp->tg3_flags2 & TG3_FLG2_CAPACITIVE_COUPLING) {
1790 u32 val;
1791
1792 tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x4007);
1793 tg3_readphy(tp, MII_TG3_AUX_CTRL, &val);
1794 if (!(val & (1 << 10))) {
1795 val |= (1 << 10);
1796 tg3_writephy(tp, MII_TG3_AUX_CTRL, val);
1797 goto relink;
1798 }
1799 }
1800
1801 bmsr = 0;
1802 for (i = 0; i < 100; i++) {
1803 tg3_readphy(tp, MII_BMSR, &bmsr);
1804 if (!tg3_readphy(tp, MII_BMSR, &bmsr) &&
1805 (bmsr & BMSR_LSTATUS))
1806 break;
1807 udelay(40);
1808 }
1809
1810 if (bmsr & BMSR_LSTATUS) {
1811 u32 aux_stat, bmcr;
1812
1813 tg3_readphy(tp, MII_TG3_AUX_STAT, &aux_stat);
1814 for (i = 0; i < 2000; i++) {
1815 udelay(10);
1816 if (!tg3_readphy(tp, MII_TG3_AUX_STAT, &aux_stat) &&
1817 aux_stat)
1818 break;
1819 }
1820
1821 tg3_aux_stat_to_speed_duplex(tp, aux_stat,
1822 &current_speed,
1823 &current_duplex);
1824
1825 bmcr = 0;
1826 for (i = 0; i < 200; i++) {
1827 tg3_readphy(tp, MII_BMCR, &bmcr);
1828 if (tg3_readphy(tp, MII_BMCR, &bmcr))
1829 continue;
1830 if (bmcr && bmcr != 0x7fff)
1831 break;
1832 udelay(10);
1833 }
1834
1835 if (tp->link_config.autoneg == AUTONEG_ENABLE) {
1836 if (bmcr & BMCR_ANENABLE) {
1837 current_link_up = 1;
1838
1839 /* Force autoneg restart if we are exiting
1840 * low power mode.
1841 */
1842 if (!tg3_copper_is_advertising_all(tp))
1843 current_link_up = 0;
1844 } else {
1845 current_link_up = 0;
1846 }
1847 } else {
1848 if (!(bmcr & BMCR_ANENABLE) &&
1849 tp->link_config.speed == current_speed &&
1850 tp->link_config.duplex == current_duplex) {
1851 current_link_up = 1;
1852 } else {
1853 current_link_up = 0;
1854 }
1855 }
1856
1857 tp->link_config.active_speed = current_speed;
1858 tp->link_config.active_duplex = current_duplex;
1859 }
1860
1861 if (current_link_up == 1 &&
1862 (tp->link_config.active_duplex == DUPLEX_FULL) &&
1863 (tp->link_config.autoneg == AUTONEG_ENABLE)) {
1864 u32 local_adv, remote_adv;
1865
1866 if (tg3_readphy(tp, MII_ADVERTISE, &local_adv))
1867 local_adv = 0;
1868 local_adv &= (ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM);
1869
1870 if (tg3_readphy(tp, MII_LPA, &remote_adv))
1871 remote_adv = 0;
1872
1873 remote_adv &= (LPA_PAUSE_CAP | LPA_PAUSE_ASYM);
1874
1875 /* If we are not advertising full pause capability,
1876 * something is wrong. Bring the link down and reconfigure.
1877 */
1878 if (local_adv != ADVERTISE_PAUSE_CAP) {
1879 current_link_up = 0;
1880 } else {
1881 tg3_setup_flow_control(tp, local_adv, remote_adv);
1882 }
1883 }
1884relink:
6921d201 1885 if (current_link_up == 0 || tp->link_config.phy_is_low_power) {
1da177e4
LT
1886 u32 tmp;
1887
1888 tg3_phy_copper_begin(tp);
1889
1890 tg3_readphy(tp, MII_BMSR, &tmp);
1891 if (!tg3_readphy(tp, MII_BMSR, &tmp) &&
1892 (tmp & BMSR_LSTATUS))
1893 current_link_up = 1;
1894 }
1895
1896 tp->mac_mode &= ~MAC_MODE_PORT_MODE_MASK;
1897 if (current_link_up == 1) {
1898 if (tp->link_config.active_speed == SPEED_100 ||
1899 tp->link_config.active_speed == SPEED_10)
1900 tp->mac_mode |= MAC_MODE_PORT_MODE_MII;
1901 else
1902 tp->mac_mode |= MAC_MODE_PORT_MODE_GMII;
1903 } else
1904 tp->mac_mode |= MAC_MODE_PORT_MODE_GMII;
1905
1906 tp->mac_mode &= ~MAC_MODE_HALF_DUPLEX;
1907 if (tp->link_config.active_duplex == DUPLEX_HALF)
1908 tp->mac_mode |= MAC_MODE_HALF_DUPLEX;
1909
1910 tp->mac_mode &= ~MAC_MODE_LINK_POLARITY;
1911 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) {
1912 if ((tp->led_ctrl == LED_CTRL_MODE_PHY_2) ||
1913 (current_link_up == 1 &&
1914 tp->link_config.active_speed == SPEED_10))
1915 tp->mac_mode |= MAC_MODE_LINK_POLARITY;
1916 } else {
1917 if (current_link_up == 1)
1918 tp->mac_mode |= MAC_MODE_LINK_POLARITY;
1919 }
1920
1921 /* ??? Without this setting Netgear GA302T PHY does not
1922 * ??? send/receive packets...
1923 */
1924 if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5411 &&
1925 tp->pci_chip_rev_id == CHIPREV_ID_5700_ALTIMA) {
1926 tp->mi_mode |= MAC_MI_MODE_AUTO_POLL;
1927 tw32_f(MAC_MI_MODE, tp->mi_mode);
1928 udelay(80);
1929 }
1930
1931 tw32_f(MAC_MODE, tp->mac_mode);
1932 udelay(40);
1933
1934 if (tp->tg3_flags & TG3_FLAG_USE_LINKCHG_REG) {
1935 /* Polled via timer. */
1936 tw32_f(MAC_EVENT, 0);
1937 } else {
1938 tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED);
1939 }
1940 udelay(40);
1941
1942 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 &&
1943 current_link_up == 1 &&
1944 tp->link_config.active_speed == SPEED_1000 &&
1945 ((tp->tg3_flags & TG3_FLAG_PCIX_MODE) ||
1946 (tp->tg3_flags & TG3_FLAG_PCI_HIGH_SPEED))) {
1947 udelay(120);
1948 tw32_f(MAC_STATUS,
1949 (MAC_STATUS_SYNC_CHANGED |
1950 MAC_STATUS_CFG_CHANGED));
1951 udelay(40);
1952 tg3_write_mem(tp,
1953 NIC_SRAM_FIRMWARE_MBOX,
1954 NIC_SRAM_FIRMWARE_MBOX_MAGIC2);
1955 }
1956
1957 if (current_link_up != netif_carrier_ok(tp->dev)) {
1958 if (current_link_up)
1959 netif_carrier_on(tp->dev);
1960 else
1961 netif_carrier_off(tp->dev);
1962 tg3_link_report(tp);
1963 }
1964
1965 return 0;
1966}
1967
1968struct tg3_fiber_aneginfo {
1969 int state;
1970#define ANEG_STATE_UNKNOWN 0
1971#define ANEG_STATE_AN_ENABLE 1
1972#define ANEG_STATE_RESTART_INIT 2
1973#define ANEG_STATE_RESTART 3
1974#define ANEG_STATE_DISABLE_LINK_OK 4
1975#define ANEG_STATE_ABILITY_DETECT_INIT 5
1976#define ANEG_STATE_ABILITY_DETECT 6
1977#define ANEG_STATE_ACK_DETECT_INIT 7
1978#define ANEG_STATE_ACK_DETECT 8
1979#define ANEG_STATE_COMPLETE_ACK_INIT 9
1980#define ANEG_STATE_COMPLETE_ACK 10
1981#define ANEG_STATE_IDLE_DETECT_INIT 11
1982#define ANEG_STATE_IDLE_DETECT 12
1983#define ANEG_STATE_LINK_OK 13
1984#define ANEG_STATE_NEXT_PAGE_WAIT_INIT 14
1985#define ANEG_STATE_NEXT_PAGE_WAIT 15
1986
1987 u32 flags;
1988#define MR_AN_ENABLE 0x00000001
1989#define MR_RESTART_AN 0x00000002
1990#define MR_AN_COMPLETE 0x00000004
1991#define MR_PAGE_RX 0x00000008
1992#define MR_NP_LOADED 0x00000010
1993#define MR_TOGGLE_TX 0x00000020
1994#define MR_LP_ADV_FULL_DUPLEX 0x00000040
1995#define MR_LP_ADV_HALF_DUPLEX 0x00000080
1996#define MR_LP_ADV_SYM_PAUSE 0x00000100
1997#define MR_LP_ADV_ASYM_PAUSE 0x00000200
1998#define MR_LP_ADV_REMOTE_FAULT1 0x00000400
1999#define MR_LP_ADV_REMOTE_FAULT2 0x00000800
2000#define MR_LP_ADV_NEXT_PAGE 0x00001000
2001#define MR_TOGGLE_RX 0x00002000
2002#define MR_NP_RX 0x00004000
2003
2004#define MR_LINK_OK 0x80000000
2005
2006 unsigned long link_time, cur_time;
2007
2008 u32 ability_match_cfg;
2009 int ability_match_count;
2010
2011 char ability_match, idle_match, ack_match;
2012
2013 u32 txconfig, rxconfig;
2014#define ANEG_CFG_NP 0x00000080
2015#define ANEG_CFG_ACK 0x00000040
2016#define ANEG_CFG_RF2 0x00000020
2017#define ANEG_CFG_RF1 0x00000010
2018#define ANEG_CFG_PS2 0x00000001
2019#define ANEG_CFG_PS1 0x00008000
2020#define ANEG_CFG_HD 0x00004000
2021#define ANEG_CFG_FD 0x00002000
2022#define ANEG_CFG_INVAL 0x00001f06
2023
2024};
2025#define ANEG_OK 0
2026#define ANEG_DONE 1
2027#define ANEG_TIMER_ENAB 2
2028#define ANEG_FAILED -1
2029
2030#define ANEG_STATE_SETTLE_TIME 10000
2031
2032static int tg3_fiber_aneg_smachine(struct tg3 *tp,
2033 struct tg3_fiber_aneginfo *ap)
2034{
2035 unsigned long delta;
2036 u32 rx_cfg_reg;
2037 int ret;
2038
2039 if (ap->state == ANEG_STATE_UNKNOWN) {
2040 ap->rxconfig = 0;
2041 ap->link_time = 0;
2042 ap->cur_time = 0;
2043 ap->ability_match_cfg = 0;
2044 ap->ability_match_count = 0;
2045 ap->ability_match = 0;
2046 ap->idle_match = 0;
2047 ap->ack_match = 0;
2048 }
2049 ap->cur_time++;
2050
2051 if (tr32(MAC_STATUS) & MAC_STATUS_RCVD_CFG) {
2052 rx_cfg_reg = tr32(MAC_RX_AUTO_NEG);
2053
2054 if (rx_cfg_reg != ap->ability_match_cfg) {
2055 ap->ability_match_cfg = rx_cfg_reg;
2056 ap->ability_match = 0;
2057 ap->ability_match_count = 0;
2058 } else {
2059 if (++ap->ability_match_count > 1) {
2060 ap->ability_match = 1;
2061 ap->ability_match_cfg = rx_cfg_reg;
2062 }
2063 }
2064 if (rx_cfg_reg & ANEG_CFG_ACK)
2065 ap->ack_match = 1;
2066 else
2067 ap->ack_match = 0;
2068
2069 ap->idle_match = 0;
2070 } else {
2071 ap->idle_match = 1;
2072 ap->ability_match_cfg = 0;
2073 ap->ability_match_count = 0;
2074 ap->ability_match = 0;
2075 ap->ack_match = 0;
2076
2077 rx_cfg_reg = 0;
2078 }
2079
2080 ap->rxconfig = rx_cfg_reg;
2081 ret = ANEG_OK;
2082
2083 switch(ap->state) {
2084 case ANEG_STATE_UNKNOWN:
2085 if (ap->flags & (MR_AN_ENABLE | MR_RESTART_AN))
2086 ap->state = ANEG_STATE_AN_ENABLE;
2087
2088 /* fallthru */
2089 case ANEG_STATE_AN_ENABLE:
2090 ap->flags &= ~(MR_AN_COMPLETE | MR_PAGE_RX);
2091 if (ap->flags & MR_AN_ENABLE) {
2092 ap->link_time = 0;
2093 ap->cur_time = 0;
2094 ap->ability_match_cfg = 0;
2095 ap->ability_match_count = 0;
2096 ap->ability_match = 0;
2097 ap->idle_match = 0;
2098 ap->ack_match = 0;
2099
2100 ap->state = ANEG_STATE_RESTART_INIT;
2101 } else {
2102 ap->state = ANEG_STATE_DISABLE_LINK_OK;
2103 }
2104 break;
2105
2106 case ANEG_STATE_RESTART_INIT:
2107 ap->link_time = ap->cur_time;
2108 ap->flags &= ~(MR_NP_LOADED);
2109 ap->txconfig = 0;
2110 tw32(MAC_TX_AUTO_NEG, 0);
2111 tp->mac_mode |= MAC_MODE_SEND_CONFIGS;
2112 tw32_f(MAC_MODE, tp->mac_mode);
2113 udelay(40);
2114
2115 ret = ANEG_TIMER_ENAB;
2116 ap->state = ANEG_STATE_RESTART;
2117
2118 /* fallthru */
2119 case ANEG_STATE_RESTART:
2120 delta = ap->cur_time - ap->link_time;
2121 if (delta > ANEG_STATE_SETTLE_TIME) {
2122 ap->state = ANEG_STATE_ABILITY_DETECT_INIT;
2123 } else {
2124 ret = ANEG_TIMER_ENAB;
2125 }
2126 break;
2127
2128 case ANEG_STATE_DISABLE_LINK_OK:
2129 ret = ANEG_DONE;
2130 break;
2131
2132 case ANEG_STATE_ABILITY_DETECT_INIT:
2133 ap->flags &= ~(MR_TOGGLE_TX);
2134 ap->txconfig = (ANEG_CFG_FD | ANEG_CFG_PS1);
2135 tw32(MAC_TX_AUTO_NEG, ap->txconfig);
2136 tp->mac_mode |= MAC_MODE_SEND_CONFIGS;
2137 tw32_f(MAC_MODE, tp->mac_mode);
2138 udelay(40);
2139
2140 ap->state = ANEG_STATE_ABILITY_DETECT;
2141 break;
2142
2143 case ANEG_STATE_ABILITY_DETECT:
2144 if (ap->ability_match != 0 && ap->rxconfig != 0) {
2145 ap->state = ANEG_STATE_ACK_DETECT_INIT;
2146 }
2147 break;
2148
2149 case ANEG_STATE_ACK_DETECT_INIT:
2150 ap->txconfig |= ANEG_CFG_ACK;
2151 tw32(MAC_TX_AUTO_NEG, ap->txconfig);
2152 tp->mac_mode |= MAC_MODE_SEND_CONFIGS;
2153 tw32_f(MAC_MODE, tp->mac_mode);
2154 udelay(40);
2155
2156 ap->state = ANEG_STATE_ACK_DETECT;
2157
2158 /* fallthru */
2159 case ANEG_STATE_ACK_DETECT:
2160 if (ap->ack_match != 0) {
2161 if ((ap->rxconfig & ~ANEG_CFG_ACK) ==
2162 (ap->ability_match_cfg & ~ANEG_CFG_ACK)) {
2163 ap->state = ANEG_STATE_COMPLETE_ACK_INIT;
2164 } else {
2165 ap->state = ANEG_STATE_AN_ENABLE;
2166 }
2167 } else if (ap->ability_match != 0 &&
2168 ap->rxconfig == 0) {
2169 ap->state = ANEG_STATE_AN_ENABLE;
2170 }
2171 break;
2172
2173 case ANEG_STATE_COMPLETE_ACK_INIT:
2174 if (ap->rxconfig & ANEG_CFG_INVAL) {
2175 ret = ANEG_FAILED;
2176 break;
2177 }
2178 ap->flags &= ~(MR_LP_ADV_FULL_DUPLEX |
2179 MR_LP_ADV_HALF_DUPLEX |
2180 MR_LP_ADV_SYM_PAUSE |
2181 MR_LP_ADV_ASYM_PAUSE |
2182 MR_LP_ADV_REMOTE_FAULT1 |
2183 MR_LP_ADV_REMOTE_FAULT2 |
2184 MR_LP_ADV_NEXT_PAGE |
2185 MR_TOGGLE_RX |
2186 MR_NP_RX);
2187 if (ap->rxconfig & ANEG_CFG_FD)
2188 ap->flags |= MR_LP_ADV_FULL_DUPLEX;
2189 if (ap->rxconfig & ANEG_CFG_HD)
2190 ap->flags |= MR_LP_ADV_HALF_DUPLEX;
2191 if (ap->rxconfig & ANEG_CFG_PS1)
2192 ap->flags |= MR_LP_ADV_SYM_PAUSE;
2193 if (ap->rxconfig & ANEG_CFG_PS2)
2194 ap->flags |= MR_LP_ADV_ASYM_PAUSE;
2195 if (ap->rxconfig & ANEG_CFG_RF1)
2196 ap->flags |= MR_LP_ADV_REMOTE_FAULT1;
2197 if (ap->rxconfig & ANEG_CFG_RF2)
2198 ap->flags |= MR_LP_ADV_REMOTE_FAULT2;
2199 if (ap->rxconfig & ANEG_CFG_NP)
2200 ap->flags |= MR_LP_ADV_NEXT_PAGE;
2201
2202 ap->link_time = ap->cur_time;
2203
2204 ap->flags ^= (MR_TOGGLE_TX);
2205 if (ap->rxconfig & 0x0008)
2206 ap->flags |= MR_TOGGLE_RX;
2207 if (ap->rxconfig & ANEG_CFG_NP)
2208 ap->flags |= MR_NP_RX;
2209 ap->flags |= MR_PAGE_RX;
2210
2211 ap->state = ANEG_STATE_COMPLETE_ACK;
2212 ret = ANEG_TIMER_ENAB;
2213 break;
2214
2215 case ANEG_STATE_COMPLETE_ACK:
2216 if (ap->ability_match != 0 &&
2217 ap->rxconfig == 0) {
2218 ap->state = ANEG_STATE_AN_ENABLE;
2219 break;
2220 }
2221 delta = ap->cur_time - ap->link_time;
2222 if (delta > ANEG_STATE_SETTLE_TIME) {
2223 if (!(ap->flags & (MR_LP_ADV_NEXT_PAGE))) {
2224 ap->state = ANEG_STATE_IDLE_DETECT_INIT;
2225 } else {
2226 if ((ap->txconfig & ANEG_CFG_NP) == 0 &&
2227 !(ap->flags & MR_NP_RX)) {
2228 ap->state = ANEG_STATE_IDLE_DETECT_INIT;
2229 } else {
2230 ret = ANEG_FAILED;
2231 }
2232 }
2233 }
2234 break;
2235
2236 case ANEG_STATE_IDLE_DETECT_INIT:
2237 ap->link_time = ap->cur_time;
2238 tp->mac_mode &= ~MAC_MODE_SEND_CONFIGS;
2239 tw32_f(MAC_MODE, tp->mac_mode);
2240 udelay(40);
2241
2242 ap->state = ANEG_STATE_IDLE_DETECT;
2243 ret = ANEG_TIMER_ENAB;
2244 break;
2245
2246 case ANEG_STATE_IDLE_DETECT:
2247 if (ap->ability_match != 0 &&
2248 ap->rxconfig == 0) {
2249 ap->state = ANEG_STATE_AN_ENABLE;
2250 break;
2251 }
2252 delta = ap->cur_time - ap->link_time;
2253 if (delta > ANEG_STATE_SETTLE_TIME) {
2254 /* XXX another gem from the Broadcom driver :( */
2255 ap->state = ANEG_STATE_LINK_OK;
2256 }
2257 break;
2258
2259 case ANEG_STATE_LINK_OK:
2260 ap->flags |= (MR_AN_COMPLETE | MR_LINK_OK);
2261 ret = ANEG_DONE;
2262 break;
2263
2264 case ANEG_STATE_NEXT_PAGE_WAIT_INIT:
2265 /* ??? unimplemented */
2266 break;
2267
2268 case ANEG_STATE_NEXT_PAGE_WAIT:
2269 /* ??? unimplemented */
2270 break;
2271
2272 default:
2273 ret = ANEG_FAILED;
2274 break;
2275 };
2276
2277 return ret;
2278}
2279
2280static int fiber_autoneg(struct tg3 *tp, u32 *flags)
2281{
2282 int res = 0;
2283 struct tg3_fiber_aneginfo aninfo;
2284 int status = ANEG_FAILED;
2285 unsigned int tick;
2286 u32 tmp;
2287
2288 tw32_f(MAC_TX_AUTO_NEG, 0);
2289
2290 tmp = tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK;
2291 tw32_f(MAC_MODE, tmp | MAC_MODE_PORT_MODE_GMII);
2292 udelay(40);
2293
2294 tw32_f(MAC_MODE, tp->mac_mode | MAC_MODE_SEND_CONFIGS);
2295 udelay(40);
2296
2297 memset(&aninfo, 0, sizeof(aninfo));
2298 aninfo.flags |= MR_AN_ENABLE;
2299 aninfo.state = ANEG_STATE_UNKNOWN;
2300 aninfo.cur_time = 0;
2301 tick = 0;
2302 while (++tick < 195000) {
2303 status = tg3_fiber_aneg_smachine(tp, &aninfo);
2304 if (status == ANEG_DONE || status == ANEG_FAILED)
2305 break;
2306
2307 udelay(1);
2308 }
2309
2310 tp->mac_mode &= ~MAC_MODE_SEND_CONFIGS;
2311 tw32_f(MAC_MODE, tp->mac_mode);
2312 udelay(40);
2313
2314 *flags = aninfo.flags;
2315
2316 if (status == ANEG_DONE &&
2317 (aninfo.flags & (MR_AN_COMPLETE | MR_LINK_OK |
2318 MR_LP_ADV_FULL_DUPLEX)))
2319 res = 1;
2320
2321 return res;
2322}
2323
2324static void tg3_init_bcm8002(struct tg3 *tp)
2325{
2326 u32 mac_status = tr32(MAC_STATUS);
2327 int i;
2328
2329 /* Reset when initting first time or we have a link. */
2330 if ((tp->tg3_flags & TG3_FLAG_INIT_COMPLETE) &&
2331 !(mac_status & MAC_STATUS_PCS_SYNCED))
2332 return;
2333
2334 /* Set PLL lock range. */
2335 tg3_writephy(tp, 0x16, 0x8007);
2336
2337 /* SW reset */
2338 tg3_writephy(tp, MII_BMCR, BMCR_RESET);
2339
2340 /* Wait for reset to complete. */
2341 /* XXX schedule_timeout() ... */
2342 for (i = 0; i < 500; i++)
2343 udelay(10);
2344
2345 /* Config mode; select PMA/Ch 1 regs. */
2346 tg3_writephy(tp, 0x10, 0x8411);
2347
2348 /* Enable auto-lock and comdet, select txclk for tx. */
2349 tg3_writephy(tp, 0x11, 0x0a10);
2350
2351 tg3_writephy(tp, 0x18, 0x00a0);
2352 tg3_writephy(tp, 0x16, 0x41ff);
2353
2354 /* Assert and deassert POR. */
2355 tg3_writephy(tp, 0x13, 0x0400);
2356 udelay(40);
2357 tg3_writephy(tp, 0x13, 0x0000);
2358
2359 tg3_writephy(tp, 0x11, 0x0a50);
2360 udelay(40);
2361 tg3_writephy(tp, 0x11, 0x0a10);
2362
2363 /* Wait for signal to stabilize */
2364 /* XXX schedule_timeout() ... */
2365 for (i = 0; i < 15000; i++)
2366 udelay(10);
2367
2368 /* Deselect the channel register so we can read the PHYID
2369 * later.
2370 */
2371 tg3_writephy(tp, 0x10, 0x8011);
2372}
2373
2374static int tg3_setup_fiber_hw_autoneg(struct tg3 *tp, u32 mac_status)
2375{
2376 u32 sg_dig_ctrl, sg_dig_status;
2377 u32 serdes_cfg, expected_sg_dig_ctrl;
2378 int workaround, port_a;
2379 int current_link_up;
2380
2381 serdes_cfg = 0;
2382 expected_sg_dig_ctrl = 0;
2383 workaround = 0;
2384 port_a = 1;
2385 current_link_up = 0;
2386
2387 if (tp->pci_chip_rev_id != CHIPREV_ID_5704_A0 &&
2388 tp->pci_chip_rev_id != CHIPREV_ID_5704_A1) {
2389 workaround = 1;
2390 if (tr32(TG3PCI_DUAL_MAC_CTRL) & DUAL_MAC_CTRL_ID)
2391 port_a = 0;
2392
2393 /* preserve bits 0-11,13,14 for signal pre-emphasis */
2394 /* preserve bits 20-23 for voltage regulator */
2395 serdes_cfg = tr32(MAC_SERDES_CFG) & 0x00f06fff;
2396 }
2397
2398 sg_dig_ctrl = tr32(SG_DIG_CTRL);
2399
2400 if (tp->link_config.autoneg != AUTONEG_ENABLE) {
2401 if (sg_dig_ctrl & (1 << 31)) {
2402 if (workaround) {
2403 u32 val = serdes_cfg;
2404
2405 if (port_a)
2406 val |= 0xc010000;
2407 else
2408 val |= 0x4010000;
2409 tw32_f(MAC_SERDES_CFG, val);
2410 }
2411 tw32_f(SG_DIG_CTRL, 0x01388400);
2412 }
2413 if (mac_status & MAC_STATUS_PCS_SYNCED) {
2414 tg3_setup_flow_control(tp, 0, 0);
2415 current_link_up = 1;
2416 }
2417 goto out;
2418 }
2419
2420 /* Want auto-negotiation. */
2421 expected_sg_dig_ctrl = 0x81388400;
2422
2423 /* Pause capability */
2424 expected_sg_dig_ctrl |= (1 << 11);
2425
2426 /* Asymettric pause */
2427 expected_sg_dig_ctrl |= (1 << 12);
2428
2429 if (sg_dig_ctrl != expected_sg_dig_ctrl) {
2430 if (workaround)
2431 tw32_f(MAC_SERDES_CFG, serdes_cfg | 0xc011000);
2432 tw32_f(SG_DIG_CTRL, expected_sg_dig_ctrl | (1 << 30));
2433 udelay(5);
2434 tw32_f(SG_DIG_CTRL, expected_sg_dig_ctrl);
2435
2436 tp->tg3_flags2 |= TG3_FLG2_PHY_JUST_INITTED;
2437 } else if (mac_status & (MAC_STATUS_PCS_SYNCED |
2438 MAC_STATUS_SIGNAL_DET)) {
2439 int i;
2440
2441 /* Giver time to negotiate (~200ms) */
2442 for (i = 0; i < 40000; i++) {
2443 sg_dig_status = tr32(SG_DIG_STATUS);
2444 if (sg_dig_status & (0x3))
2445 break;
2446 udelay(5);
2447 }
2448 mac_status = tr32(MAC_STATUS);
2449
2450 if ((sg_dig_status & (1 << 1)) &&
2451 (mac_status & MAC_STATUS_PCS_SYNCED)) {
2452 u32 local_adv, remote_adv;
2453
2454 local_adv = ADVERTISE_PAUSE_CAP;
2455 remote_adv = 0;
2456 if (sg_dig_status & (1 << 19))
2457 remote_adv |= LPA_PAUSE_CAP;
2458 if (sg_dig_status & (1 << 20))
2459 remote_adv |= LPA_PAUSE_ASYM;
2460
2461 tg3_setup_flow_control(tp, local_adv, remote_adv);
2462 current_link_up = 1;
2463 tp->tg3_flags2 &= ~TG3_FLG2_PHY_JUST_INITTED;
2464 } else if (!(sg_dig_status & (1 << 1))) {
2465 if (tp->tg3_flags2 & TG3_FLG2_PHY_JUST_INITTED)
2466 tp->tg3_flags2 &= ~TG3_FLG2_PHY_JUST_INITTED;
2467 else {
2468 if (workaround) {
2469 u32 val = serdes_cfg;
2470
2471 if (port_a)
2472 val |= 0xc010000;
2473 else
2474 val |= 0x4010000;
2475
2476 tw32_f(MAC_SERDES_CFG, val);
2477 }
2478
2479 tw32_f(SG_DIG_CTRL, 0x01388400);
2480 udelay(40);
2481
2482 /* Link parallel detection - link is up */
2483 /* only if we have PCS_SYNC and not */
2484 /* receiving config code words */
2485 mac_status = tr32(MAC_STATUS);
2486 if ((mac_status & MAC_STATUS_PCS_SYNCED) &&
2487 !(mac_status & MAC_STATUS_RCVD_CFG)) {
2488 tg3_setup_flow_control(tp, 0, 0);
2489 current_link_up = 1;
2490 }
2491 }
2492 }
2493 }
2494
2495out:
2496 return current_link_up;
2497}
2498
2499static int tg3_setup_fiber_by_hand(struct tg3 *tp, u32 mac_status)
2500{
2501 int current_link_up = 0;
2502
2503 if (!(mac_status & MAC_STATUS_PCS_SYNCED)) {
2504 tp->tg3_flags &= ~TG3_FLAG_GOT_SERDES_FLOWCTL;
2505 goto out;
2506 }
2507
2508 if (tp->link_config.autoneg == AUTONEG_ENABLE) {
2509 u32 flags;
2510 int i;
2511
2512 if (fiber_autoneg(tp, &flags)) {
2513 u32 local_adv, remote_adv;
2514
2515 local_adv = ADVERTISE_PAUSE_CAP;
2516 remote_adv = 0;
2517 if (flags & MR_LP_ADV_SYM_PAUSE)
2518 remote_adv |= LPA_PAUSE_CAP;
2519 if (flags & MR_LP_ADV_ASYM_PAUSE)
2520 remote_adv |= LPA_PAUSE_ASYM;
2521
2522 tg3_setup_flow_control(tp, local_adv, remote_adv);
2523
2524 tp->tg3_flags |= TG3_FLAG_GOT_SERDES_FLOWCTL;
2525 current_link_up = 1;
2526 }
2527 for (i = 0; i < 30; i++) {
2528 udelay(20);
2529 tw32_f(MAC_STATUS,
2530 (MAC_STATUS_SYNC_CHANGED |
2531 MAC_STATUS_CFG_CHANGED));
2532 udelay(40);
2533 if ((tr32(MAC_STATUS) &
2534 (MAC_STATUS_SYNC_CHANGED |
2535 MAC_STATUS_CFG_CHANGED)) == 0)
2536 break;
2537 }
2538
2539 mac_status = tr32(MAC_STATUS);
2540 if (current_link_up == 0 &&
2541 (mac_status & MAC_STATUS_PCS_SYNCED) &&
2542 !(mac_status & MAC_STATUS_RCVD_CFG))
2543 current_link_up = 1;
2544 } else {
2545 /* Forcing 1000FD link up. */
2546 current_link_up = 1;
2547 tp->tg3_flags |= TG3_FLAG_GOT_SERDES_FLOWCTL;
2548
2549 tw32_f(MAC_MODE, (tp->mac_mode | MAC_MODE_SEND_CONFIGS));
2550 udelay(40);
2551 }
2552
2553out:
2554 return current_link_up;
2555}
2556
2557static int tg3_setup_fiber_phy(struct tg3 *tp, int force_reset)
2558{
2559 u32 orig_pause_cfg;
2560 u16 orig_active_speed;
2561 u8 orig_active_duplex;
2562 u32 mac_status;
2563 int current_link_up;
2564 int i;
2565
2566 orig_pause_cfg =
2567 (tp->tg3_flags & (TG3_FLAG_RX_PAUSE |
2568 TG3_FLAG_TX_PAUSE));
2569 orig_active_speed = tp->link_config.active_speed;
2570 orig_active_duplex = tp->link_config.active_duplex;
2571
2572 if (!(tp->tg3_flags2 & TG3_FLG2_HW_AUTONEG) &&
2573 netif_carrier_ok(tp->dev) &&
2574 (tp->tg3_flags & TG3_FLAG_INIT_COMPLETE)) {
2575 mac_status = tr32(MAC_STATUS);
2576 mac_status &= (MAC_STATUS_PCS_SYNCED |
2577 MAC_STATUS_SIGNAL_DET |
2578 MAC_STATUS_CFG_CHANGED |
2579 MAC_STATUS_RCVD_CFG);
2580 if (mac_status == (MAC_STATUS_PCS_SYNCED |
2581 MAC_STATUS_SIGNAL_DET)) {
2582 tw32_f(MAC_STATUS, (MAC_STATUS_SYNC_CHANGED |
2583 MAC_STATUS_CFG_CHANGED));
2584 return 0;
2585 }
2586 }
2587
2588 tw32_f(MAC_TX_AUTO_NEG, 0);
2589
2590 tp->mac_mode &= ~(MAC_MODE_PORT_MODE_MASK | MAC_MODE_HALF_DUPLEX);
2591 tp->mac_mode |= MAC_MODE_PORT_MODE_TBI;
2592 tw32_f(MAC_MODE, tp->mac_mode);
2593 udelay(40);
2594
2595 if (tp->phy_id == PHY_ID_BCM8002)
2596 tg3_init_bcm8002(tp);
2597
2598 /* Enable link change event even when serdes polling. */
2599 tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED);
2600 udelay(40);
2601
2602 current_link_up = 0;
2603 mac_status = tr32(MAC_STATUS);
2604
2605 if (tp->tg3_flags2 & TG3_FLG2_HW_AUTONEG)
2606 current_link_up = tg3_setup_fiber_hw_autoneg(tp, mac_status);
2607 else
2608 current_link_up = tg3_setup_fiber_by_hand(tp, mac_status);
2609
2610 tp->mac_mode &= ~MAC_MODE_LINK_POLARITY;
2611 tw32_f(MAC_MODE, tp->mac_mode);
2612 udelay(40);
2613
2614 tp->hw_status->status =
2615 (SD_STATUS_UPDATED |
2616 (tp->hw_status->status & ~SD_STATUS_LINK_CHG));
2617
2618 for (i = 0; i < 100; i++) {
2619 tw32_f(MAC_STATUS, (MAC_STATUS_SYNC_CHANGED |
2620 MAC_STATUS_CFG_CHANGED));
2621 udelay(5);
2622 if ((tr32(MAC_STATUS) & (MAC_STATUS_SYNC_CHANGED |
2623 MAC_STATUS_CFG_CHANGED)) == 0)
2624 break;
2625 }
2626
2627 mac_status = tr32(MAC_STATUS);
2628 if ((mac_status & MAC_STATUS_PCS_SYNCED) == 0) {
2629 current_link_up = 0;
2630 if (tp->link_config.autoneg == AUTONEG_ENABLE) {
2631 tw32_f(MAC_MODE, (tp->mac_mode |
2632 MAC_MODE_SEND_CONFIGS));
2633 udelay(1);
2634 tw32_f(MAC_MODE, tp->mac_mode);
2635 }
2636 }
2637
2638 if (current_link_up == 1) {
2639 tp->link_config.active_speed = SPEED_1000;
2640 tp->link_config.active_duplex = DUPLEX_FULL;
2641 tw32(MAC_LED_CTRL, (tp->led_ctrl |
2642 LED_CTRL_LNKLED_OVERRIDE |
2643 LED_CTRL_1000MBPS_ON));
2644 } else {
2645 tp->link_config.active_speed = SPEED_INVALID;
2646 tp->link_config.active_duplex = DUPLEX_INVALID;
2647 tw32(MAC_LED_CTRL, (tp->led_ctrl |
2648 LED_CTRL_LNKLED_OVERRIDE |
2649 LED_CTRL_TRAFFIC_OVERRIDE));
2650 }
2651
2652 if (current_link_up != netif_carrier_ok(tp->dev)) {
2653 if (current_link_up)
2654 netif_carrier_on(tp->dev);
2655 else
2656 netif_carrier_off(tp->dev);
2657 tg3_link_report(tp);
2658 } else {
2659 u32 now_pause_cfg =
2660 tp->tg3_flags & (TG3_FLAG_RX_PAUSE |
2661 TG3_FLAG_TX_PAUSE);
2662 if (orig_pause_cfg != now_pause_cfg ||
2663 orig_active_speed != tp->link_config.active_speed ||
2664 orig_active_duplex != tp->link_config.active_duplex)
2665 tg3_link_report(tp);
2666 }
2667
2668 return 0;
2669}
2670
747e8f8b
MC
2671static int tg3_setup_fiber_mii_phy(struct tg3 *tp, int force_reset)
2672{
2673 int current_link_up, err = 0;
2674 u32 bmsr, bmcr;
2675 u16 current_speed;
2676 u8 current_duplex;
2677
2678 tp->mac_mode |= MAC_MODE_PORT_MODE_GMII;
2679 tw32_f(MAC_MODE, tp->mac_mode);
2680 udelay(40);
2681
2682 tw32(MAC_EVENT, 0);
2683
2684 tw32_f(MAC_STATUS,
2685 (MAC_STATUS_SYNC_CHANGED |
2686 MAC_STATUS_CFG_CHANGED |
2687 MAC_STATUS_MI_COMPLETION |
2688 MAC_STATUS_LNKSTATE_CHANGED));
2689 udelay(40);
2690
2691 if (force_reset)
2692 tg3_phy_reset(tp);
2693
2694 current_link_up = 0;
2695 current_speed = SPEED_INVALID;
2696 current_duplex = DUPLEX_INVALID;
2697
2698 err |= tg3_readphy(tp, MII_BMSR, &bmsr);
2699 err |= tg3_readphy(tp, MII_BMSR, &bmsr);
d4d2c558
MC
2700 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) {
2701 if (tr32(MAC_TX_STATUS) & TX_STATUS_LINK_UP)
2702 bmsr |= BMSR_LSTATUS;
2703 else
2704 bmsr &= ~BMSR_LSTATUS;
2705 }
747e8f8b
MC
2706
2707 err |= tg3_readphy(tp, MII_BMCR, &bmcr);
2708
2709 if ((tp->link_config.autoneg == AUTONEG_ENABLE) && !force_reset &&
2710 (tp->tg3_flags2 & TG3_FLG2_PARALLEL_DETECT)) {
2711 /* do nothing, just check for link up at the end */
2712 } else if (tp->link_config.autoneg == AUTONEG_ENABLE) {
2713 u32 adv, new_adv;
2714
2715 err |= tg3_readphy(tp, MII_ADVERTISE, &adv);
2716 new_adv = adv & ~(ADVERTISE_1000XFULL | ADVERTISE_1000XHALF |
2717 ADVERTISE_1000XPAUSE |
2718 ADVERTISE_1000XPSE_ASYM |
2719 ADVERTISE_SLCT);
2720
2721 /* Always advertise symmetric PAUSE just like copper */
2722 new_adv |= ADVERTISE_1000XPAUSE;
2723
2724 if (tp->link_config.advertising & ADVERTISED_1000baseT_Half)
2725 new_adv |= ADVERTISE_1000XHALF;
2726 if (tp->link_config.advertising & ADVERTISED_1000baseT_Full)
2727 new_adv |= ADVERTISE_1000XFULL;
2728
2729 if ((new_adv != adv) || !(bmcr & BMCR_ANENABLE)) {
2730 tg3_writephy(tp, MII_ADVERTISE, new_adv);
2731 bmcr |= BMCR_ANENABLE | BMCR_ANRESTART;
2732 tg3_writephy(tp, MII_BMCR, bmcr);
2733
2734 tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED);
2735 tp->tg3_flags2 |= TG3_FLG2_PHY_JUST_INITTED;
2736 tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
2737
2738 return err;
2739 }
2740 } else {
2741 u32 new_bmcr;
2742
2743 bmcr &= ~BMCR_SPEED1000;
2744 new_bmcr = bmcr & ~(BMCR_ANENABLE | BMCR_FULLDPLX);
2745
2746 if (tp->link_config.duplex == DUPLEX_FULL)
2747 new_bmcr |= BMCR_FULLDPLX;
2748
2749 if (new_bmcr != bmcr) {
2750 /* BMCR_SPEED1000 is a reserved bit that needs
2751 * to be set on write.
2752 */
2753 new_bmcr |= BMCR_SPEED1000;
2754
2755 /* Force a linkdown */
2756 if (netif_carrier_ok(tp->dev)) {
2757 u32 adv;
2758
2759 err |= tg3_readphy(tp, MII_ADVERTISE, &adv);
2760 adv &= ~(ADVERTISE_1000XFULL |
2761 ADVERTISE_1000XHALF |
2762 ADVERTISE_SLCT);
2763 tg3_writephy(tp, MII_ADVERTISE, adv);
2764 tg3_writephy(tp, MII_BMCR, bmcr |
2765 BMCR_ANRESTART |
2766 BMCR_ANENABLE);
2767 udelay(10);
2768 netif_carrier_off(tp->dev);
2769 }
2770 tg3_writephy(tp, MII_BMCR, new_bmcr);
2771 bmcr = new_bmcr;
2772 err |= tg3_readphy(tp, MII_BMSR, &bmsr);
2773 err |= tg3_readphy(tp, MII_BMSR, &bmsr);
d4d2c558
MC
2774 if (GET_ASIC_REV(tp->pci_chip_rev_id) ==
2775 ASIC_REV_5714) {
2776 if (tr32(MAC_TX_STATUS) & TX_STATUS_LINK_UP)
2777 bmsr |= BMSR_LSTATUS;
2778 else
2779 bmsr &= ~BMSR_LSTATUS;
2780 }
747e8f8b
MC
2781 tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
2782 }
2783 }
2784
2785 if (bmsr & BMSR_LSTATUS) {
2786 current_speed = SPEED_1000;
2787 current_link_up = 1;
2788 if (bmcr & BMCR_FULLDPLX)
2789 current_duplex = DUPLEX_FULL;
2790 else
2791 current_duplex = DUPLEX_HALF;
2792
2793 if (bmcr & BMCR_ANENABLE) {
2794 u32 local_adv, remote_adv, common;
2795
2796 err |= tg3_readphy(tp, MII_ADVERTISE, &local_adv);
2797 err |= tg3_readphy(tp, MII_LPA, &remote_adv);
2798 common = local_adv & remote_adv;
2799 if (common & (ADVERTISE_1000XHALF |
2800 ADVERTISE_1000XFULL)) {
2801 if (common & ADVERTISE_1000XFULL)
2802 current_duplex = DUPLEX_FULL;
2803 else
2804 current_duplex = DUPLEX_HALF;
2805
2806 tg3_setup_flow_control(tp, local_adv,
2807 remote_adv);
2808 }
2809 else
2810 current_link_up = 0;
2811 }
2812 }
2813
2814 tp->mac_mode &= ~MAC_MODE_HALF_DUPLEX;
2815 if (tp->link_config.active_duplex == DUPLEX_HALF)
2816 tp->mac_mode |= MAC_MODE_HALF_DUPLEX;
2817
2818 tw32_f(MAC_MODE, tp->mac_mode);
2819 udelay(40);
2820
2821 tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED);
2822
2823 tp->link_config.active_speed = current_speed;
2824 tp->link_config.active_duplex = current_duplex;
2825
2826 if (current_link_up != netif_carrier_ok(tp->dev)) {
2827 if (current_link_up)
2828 netif_carrier_on(tp->dev);
2829 else {
2830 netif_carrier_off(tp->dev);
2831 tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
2832 }
2833 tg3_link_report(tp);
2834 }
2835 return err;
2836}
2837
2838static void tg3_serdes_parallel_detect(struct tg3 *tp)
2839{
2840 if (tp->tg3_flags2 & TG3_FLG2_PHY_JUST_INITTED) {
2841 /* Give autoneg time to complete. */
2842 tp->tg3_flags2 &= ~TG3_FLG2_PHY_JUST_INITTED;
2843 return;
2844 }
2845 if (!netif_carrier_ok(tp->dev) &&
2846 (tp->link_config.autoneg == AUTONEG_ENABLE)) {
2847 u32 bmcr;
2848
2849 tg3_readphy(tp, MII_BMCR, &bmcr);
2850 if (bmcr & BMCR_ANENABLE) {
2851 u32 phy1, phy2;
2852
2853 /* Select shadow register 0x1f */
2854 tg3_writephy(tp, 0x1c, 0x7c00);
2855 tg3_readphy(tp, 0x1c, &phy1);
2856
2857 /* Select expansion interrupt status register */
2858 tg3_writephy(tp, 0x17, 0x0f01);
2859 tg3_readphy(tp, 0x15, &phy2);
2860 tg3_readphy(tp, 0x15, &phy2);
2861
2862 if ((phy1 & 0x10) && !(phy2 & 0x20)) {
2863 /* We have signal detect and not receiving
2864 * config code words, link is up by parallel
2865 * detection.
2866 */
2867
2868 bmcr &= ~BMCR_ANENABLE;
2869 bmcr |= BMCR_SPEED1000 | BMCR_FULLDPLX;
2870 tg3_writephy(tp, MII_BMCR, bmcr);
2871 tp->tg3_flags2 |= TG3_FLG2_PARALLEL_DETECT;
2872 }
2873 }
2874 }
2875 else if (netif_carrier_ok(tp->dev) &&
2876 (tp->link_config.autoneg == AUTONEG_ENABLE) &&
2877 (tp->tg3_flags2 & TG3_FLG2_PARALLEL_DETECT)) {
2878 u32 phy2;
2879
2880 /* Select expansion interrupt status register */
2881 tg3_writephy(tp, 0x17, 0x0f01);
2882 tg3_readphy(tp, 0x15, &phy2);
2883 if (phy2 & 0x20) {
2884 u32 bmcr;
2885
2886 /* Config code words received, turn on autoneg. */
2887 tg3_readphy(tp, MII_BMCR, &bmcr);
2888 tg3_writephy(tp, MII_BMCR, bmcr | BMCR_ANENABLE);
2889
2890 tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
2891
2892 }
2893 }
2894}
2895
1da177e4
LT
2896static int tg3_setup_phy(struct tg3 *tp, int force_reset)
2897{
2898 int err;
2899
2900 if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) {
2901 err = tg3_setup_fiber_phy(tp, force_reset);
747e8f8b
MC
2902 } else if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES) {
2903 err = tg3_setup_fiber_mii_phy(tp, force_reset);
1da177e4
LT
2904 } else {
2905 err = tg3_setup_copper_phy(tp, force_reset);
2906 }
2907
2908 if (tp->link_config.active_speed == SPEED_1000 &&
2909 tp->link_config.active_duplex == DUPLEX_HALF)
2910 tw32(MAC_TX_LENGTHS,
2911 ((2 << TX_LENGTHS_IPG_CRS_SHIFT) |
2912 (6 << TX_LENGTHS_IPG_SHIFT) |
2913 (0xff << TX_LENGTHS_SLOT_TIME_SHIFT)));
2914 else
2915 tw32(MAC_TX_LENGTHS,
2916 ((2 << TX_LENGTHS_IPG_CRS_SHIFT) |
2917 (6 << TX_LENGTHS_IPG_SHIFT) |
2918 (32 << TX_LENGTHS_SLOT_TIME_SHIFT)));
2919
2920 if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
2921 if (netif_carrier_ok(tp->dev)) {
2922 tw32(HOSTCC_STAT_COAL_TICKS,
15f9850d 2923 tp->coal.stats_block_coalesce_usecs);
1da177e4
LT
2924 } else {
2925 tw32(HOSTCC_STAT_COAL_TICKS, 0);
2926 }
2927 }
2928
2929 return err;
2930}
2931
2932/* Tigon3 never reports partial packet sends. So we do not
2933 * need special logic to handle SKBs that have not had all
2934 * of their frags sent yet, like SunGEM does.
2935 */
2936static void tg3_tx(struct tg3 *tp)
2937{
2938 u32 hw_idx = tp->hw_status->idx[0].tx_consumer;
2939 u32 sw_idx = tp->tx_cons;
2940
2941 while (sw_idx != hw_idx) {
2942 struct tx_ring_info *ri = &tp->tx_buffers[sw_idx];
2943 struct sk_buff *skb = ri->skb;
2944 int i;
2945
2946 if (unlikely(skb == NULL))
2947 BUG();
2948
2949 pci_unmap_single(tp->pdev,
2950 pci_unmap_addr(ri, mapping),
2951 skb_headlen(skb),
2952 PCI_DMA_TODEVICE);
2953
2954 ri->skb = NULL;
2955
2956 sw_idx = NEXT_TX(sw_idx);
2957
2958 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
2959 if (unlikely(sw_idx == hw_idx))
2960 BUG();
2961
2962 ri = &tp->tx_buffers[sw_idx];
2963 if (unlikely(ri->skb != NULL))
2964 BUG();
2965
2966 pci_unmap_page(tp->pdev,
2967 pci_unmap_addr(ri, mapping),
2968 skb_shinfo(skb)->frags[i].size,
2969 PCI_DMA_TODEVICE);
2970
2971 sw_idx = NEXT_TX(sw_idx);
2972 }
2973
f47c11ee 2974 dev_kfree_skb(skb);
1da177e4
LT
2975 }
2976
2977 tp->tx_cons = sw_idx;
2978
51b91468
MC
2979 if (unlikely(netif_queue_stopped(tp->dev))) {
2980 spin_lock(&tp->tx_lock);
2981 if (netif_queue_stopped(tp->dev) &&
2982 (TX_BUFFS_AVAIL(tp) > TG3_TX_WAKEUP_THRESH))
2983 netif_wake_queue(tp->dev);
2984 spin_unlock(&tp->tx_lock);
2985 }
1da177e4
LT
2986}
2987
2988/* Returns size of skb allocated or < 0 on error.
2989 *
2990 * We only need to fill in the address because the other members
2991 * of the RX descriptor are invariant, see tg3_init_rings.
2992 *
2993 * Note the purposeful assymetry of cpu vs. chip accesses. For
2994 * posting buffers we only dirty the first cache line of the RX
2995 * descriptor (containing the address). Whereas for the RX status
2996 * buffers the cpu only reads the last cacheline of the RX descriptor
2997 * (to fetch the error flags, vlan tag, checksum, and opaque cookie).
2998 */
2999static int tg3_alloc_rx_skb(struct tg3 *tp, u32 opaque_key,
3000 int src_idx, u32 dest_idx_unmasked)
3001{
3002 struct tg3_rx_buffer_desc *desc;
3003 struct ring_info *map, *src_map;
3004 struct sk_buff *skb;
3005 dma_addr_t mapping;
3006 int skb_size, dest_idx;
3007
3008 src_map = NULL;
3009 switch (opaque_key) {
3010 case RXD_OPAQUE_RING_STD:
3011 dest_idx = dest_idx_unmasked % TG3_RX_RING_SIZE;
3012 desc = &tp->rx_std[dest_idx];
3013 map = &tp->rx_std_buffers[dest_idx];
3014 if (src_idx >= 0)
3015 src_map = &tp->rx_std_buffers[src_idx];
7e72aad4 3016 skb_size = tp->rx_pkt_buf_sz;
1da177e4
LT
3017 break;
3018
3019 case RXD_OPAQUE_RING_JUMBO:
3020 dest_idx = dest_idx_unmasked % TG3_RX_JUMBO_RING_SIZE;
3021 desc = &tp->rx_jumbo[dest_idx];
3022 map = &tp->rx_jumbo_buffers[dest_idx];
3023 if (src_idx >= 0)
3024 src_map = &tp->rx_jumbo_buffers[src_idx];
3025 skb_size = RX_JUMBO_PKT_BUF_SZ;
3026 break;
3027
3028 default:
3029 return -EINVAL;
3030 };
3031
3032 /* Do not overwrite any of the map or rp information
3033 * until we are sure we can commit to a new buffer.
3034 *
3035 * Callers depend upon this behavior and assume that
3036 * we leave everything unchanged if we fail.
3037 */
3038 skb = dev_alloc_skb(skb_size);
3039 if (skb == NULL)
3040 return -ENOMEM;
3041
3042 skb->dev = tp->dev;
3043 skb_reserve(skb, tp->rx_offset);
3044
3045 mapping = pci_map_single(tp->pdev, skb->data,
3046 skb_size - tp->rx_offset,
3047 PCI_DMA_FROMDEVICE);
3048
3049 map->skb = skb;
3050 pci_unmap_addr_set(map, mapping, mapping);
3051
3052 if (src_map != NULL)
3053 src_map->skb = NULL;
3054
3055 desc->addr_hi = ((u64)mapping >> 32);
3056 desc->addr_lo = ((u64)mapping & 0xffffffff);
3057
3058 return skb_size;
3059}
3060
3061/* We only need to move over in the address because the other
3062 * members of the RX descriptor are invariant. See notes above
3063 * tg3_alloc_rx_skb for full details.
3064 */
3065static void tg3_recycle_rx(struct tg3 *tp, u32 opaque_key,
3066 int src_idx, u32 dest_idx_unmasked)
3067{
3068 struct tg3_rx_buffer_desc *src_desc, *dest_desc;
3069 struct ring_info *src_map, *dest_map;
3070 int dest_idx;
3071
3072 switch (opaque_key) {
3073 case RXD_OPAQUE_RING_STD:
3074 dest_idx = dest_idx_unmasked % TG3_RX_RING_SIZE;
3075 dest_desc = &tp->rx_std[dest_idx];
3076 dest_map = &tp->rx_std_buffers[dest_idx];
3077 src_desc = &tp->rx_std[src_idx];
3078 src_map = &tp->rx_std_buffers[src_idx];
3079 break;
3080
3081 case RXD_OPAQUE_RING_JUMBO:
3082 dest_idx = dest_idx_unmasked % TG3_RX_JUMBO_RING_SIZE;
3083 dest_desc = &tp->rx_jumbo[dest_idx];
3084 dest_map = &tp->rx_jumbo_buffers[dest_idx];
3085 src_desc = &tp->rx_jumbo[src_idx];
3086 src_map = &tp->rx_jumbo_buffers[src_idx];
3087 break;
3088
3089 default:
3090 return;
3091 };
3092
3093 dest_map->skb = src_map->skb;
3094 pci_unmap_addr_set(dest_map, mapping,
3095 pci_unmap_addr(src_map, mapping));
3096 dest_desc->addr_hi = src_desc->addr_hi;
3097 dest_desc->addr_lo = src_desc->addr_lo;
3098
3099 src_map->skb = NULL;
3100}
3101
3102#if TG3_VLAN_TAG_USED
3103static int tg3_vlan_rx(struct tg3 *tp, struct sk_buff *skb, u16 vlan_tag)
3104{
3105 return vlan_hwaccel_receive_skb(skb, tp->vlgrp, vlan_tag);
3106}
3107#endif
3108
3109/* The RX ring scheme is composed of multiple rings which post fresh
3110 * buffers to the chip, and one special ring the chip uses to report
3111 * status back to the host.
3112 *
3113 * The special ring reports the status of received packets to the
3114 * host. The chip does not write into the original descriptor the
3115 * RX buffer was obtained from. The chip simply takes the original
3116 * descriptor as provided by the host, updates the status and length
3117 * field, then writes this into the next status ring entry.
3118 *
3119 * Each ring the host uses to post buffers to the chip is described
3120 * by a TG3_BDINFO entry in the chips SRAM area. When a packet arrives,
3121 * it is first placed into the on-chip ram. When the packet's length
3122 * is known, it walks down the TG3_BDINFO entries to select the ring.
3123 * Each TG3_BDINFO specifies a MAXLEN field and the first TG3_BDINFO
3124 * which is within the range of the new packet's length is chosen.
3125 *
3126 * The "separate ring for rx status" scheme may sound queer, but it makes
3127 * sense from a cache coherency perspective. If only the host writes
3128 * to the buffer post rings, and only the chip writes to the rx status
3129 * rings, then cache lines never move beyond shared-modified state.
3130 * If both the host and chip were to write into the same ring, cache line
3131 * eviction could occur since both entities want it in an exclusive state.
3132 */
3133static int tg3_rx(struct tg3 *tp, int budget)
3134{
3135 u32 work_mask;
483ba50b
MC
3136 u32 sw_idx = tp->rx_rcb_ptr;
3137 u16 hw_idx;
1da177e4
LT
3138 int received;
3139
3140 hw_idx = tp->hw_status->idx[0].rx_producer;
3141 /*
3142 * We need to order the read of hw_idx and the read of
3143 * the opaque cookie.
3144 */
3145 rmb();
1da177e4
LT
3146 work_mask = 0;
3147 received = 0;
3148 while (sw_idx != hw_idx && budget > 0) {
3149 struct tg3_rx_buffer_desc *desc = &tp->rx_rcb[sw_idx];
3150 unsigned int len;
3151 struct sk_buff *skb;
3152 dma_addr_t dma_addr;
3153 u32 opaque_key, desc_idx, *post_ptr;
3154
3155 desc_idx = desc->opaque & RXD_OPAQUE_INDEX_MASK;
3156 opaque_key = desc->opaque & RXD_OPAQUE_RING_MASK;
3157 if (opaque_key == RXD_OPAQUE_RING_STD) {
3158 dma_addr = pci_unmap_addr(&tp->rx_std_buffers[desc_idx],
3159 mapping);
3160 skb = tp->rx_std_buffers[desc_idx].skb;
3161 post_ptr = &tp->rx_std_ptr;
3162 } else if (opaque_key == RXD_OPAQUE_RING_JUMBO) {
3163 dma_addr = pci_unmap_addr(&tp->rx_jumbo_buffers[desc_idx],
3164 mapping);
3165 skb = tp->rx_jumbo_buffers[desc_idx].skb;
3166 post_ptr = &tp->rx_jumbo_ptr;
3167 }
3168 else {
3169 goto next_pkt_nopost;
3170 }
3171
3172 work_mask |= opaque_key;
3173
3174 if ((desc->err_vlan & RXD_ERR_MASK) != 0 &&
3175 (desc->err_vlan != RXD_ERR_ODD_NIBBLE_RCVD_MII)) {
3176 drop_it:
3177 tg3_recycle_rx(tp, opaque_key,
3178 desc_idx, *post_ptr);
3179 drop_it_no_recycle:
3180 /* Other statistics kept track of by card. */
3181 tp->net_stats.rx_dropped++;
3182 goto next_pkt;
3183 }
3184
3185 len = ((desc->idx_len & RXD_LEN_MASK) >> RXD_LEN_SHIFT) - 4; /* omit crc */
3186
3187 if (len > RX_COPY_THRESHOLD
3188 && tp->rx_offset == 2
3189 /* rx_offset != 2 iff this is a 5701 card running
3190 * in PCI-X mode [see tg3_get_invariants()] */
3191 ) {
3192 int skb_size;
3193
3194 skb_size = tg3_alloc_rx_skb(tp, opaque_key,
3195 desc_idx, *post_ptr);
3196 if (skb_size < 0)
3197 goto drop_it;
3198
3199 pci_unmap_single(tp->pdev, dma_addr,
3200 skb_size - tp->rx_offset,
3201 PCI_DMA_FROMDEVICE);
3202
3203 skb_put(skb, len);
3204 } else {
3205 struct sk_buff *copy_skb;
3206
3207 tg3_recycle_rx(tp, opaque_key,
3208 desc_idx, *post_ptr);
3209
3210 copy_skb = dev_alloc_skb(len + 2);
3211 if (copy_skb == NULL)
3212 goto drop_it_no_recycle;
3213
3214 copy_skb->dev = tp->dev;
3215 skb_reserve(copy_skb, 2);
3216 skb_put(copy_skb, len);
3217 pci_dma_sync_single_for_cpu(tp->pdev, dma_addr, len, PCI_DMA_FROMDEVICE);
3218 memcpy(copy_skb->data, skb->data, len);
3219 pci_dma_sync_single_for_device(tp->pdev, dma_addr, len, PCI_DMA_FROMDEVICE);
3220
3221 /* We'll reuse the original ring buffer. */
3222 skb = copy_skb;
3223 }
3224
3225 if ((tp->tg3_flags & TG3_FLAG_RX_CHECKSUMS) &&
3226 (desc->type_flags & RXD_FLAG_TCPUDP_CSUM) &&
3227 (((desc->ip_tcp_csum & RXD_TCPCSUM_MASK)
3228 >> RXD_TCPCSUM_SHIFT) == 0xffff))
3229 skb->ip_summed = CHECKSUM_UNNECESSARY;
3230 else
3231 skb->ip_summed = CHECKSUM_NONE;
3232
3233 skb->protocol = eth_type_trans(skb, tp->dev);
3234#if TG3_VLAN_TAG_USED
3235 if (tp->vlgrp != NULL &&
3236 desc->type_flags & RXD_FLAG_VLAN) {
3237 tg3_vlan_rx(tp, skb,
3238 desc->err_vlan & RXD_VLAN_MASK);
3239 } else
3240#endif
3241 netif_receive_skb(skb);
3242
3243 tp->dev->last_rx = jiffies;
3244 received++;
3245 budget--;
3246
3247next_pkt:
3248 (*post_ptr)++;
3249next_pkt_nopost:
483ba50b
MC
3250 sw_idx++;
3251 sw_idx %= TG3_RX_RCB_RING_SIZE(tp);
52f6d697
MC
3252
3253 /* Refresh hw_idx to see if there is new work */
3254 if (sw_idx == hw_idx) {
3255 hw_idx = tp->hw_status->idx[0].rx_producer;
3256 rmb();
3257 }
1da177e4
LT
3258 }
3259
3260 /* ACK the status ring. */
483ba50b
MC
3261 tp->rx_rcb_ptr = sw_idx;
3262 tw32_rx_mbox(MAILBOX_RCVRET_CON_IDX_0 + TG3_64BIT_REG_LOW, sw_idx);
1da177e4
LT
3263
3264 /* Refill RX ring(s). */
3265 if (work_mask & RXD_OPAQUE_RING_STD) {
3266 sw_idx = tp->rx_std_ptr % TG3_RX_RING_SIZE;
3267 tw32_rx_mbox(MAILBOX_RCV_STD_PROD_IDX + TG3_64BIT_REG_LOW,
3268 sw_idx);
3269 }
3270 if (work_mask & RXD_OPAQUE_RING_JUMBO) {
3271 sw_idx = tp->rx_jumbo_ptr % TG3_RX_JUMBO_RING_SIZE;
3272 tw32_rx_mbox(MAILBOX_RCV_JUMBO_PROD_IDX + TG3_64BIT_REG_LOW,
3273 sw_idx);
3274 }
3275 mmiowb();
3276
3277 return received;
3278}
3279
3280static int tg3_poll(struct net_device *netdev, int *budget)
3281{
3282 struct tg3 *tp = netdev_priv(netdev);
3283 struct tg3_hw_status *sblk = tp->hw_status;
1da177e4
LT
3284 int done;
3285
1da177e4
LT
3286 /* handle link change and other phy events */
3287 if (!(tp->tg3_flags &
3288 (TG3_FLAG_USE_LINKCHG_REG |
3289 TG3_FLAG_POLL_SERDES))) {
3290 if (sblk->status & SD_STATUS_LINK_CHG) {
3291 sblk->status = SD_STATUS_UPDATED |
3292 (sblk->status & ~SD_STATUS_LINK_CHG);
f47c11ee 3293 spin_lock(&tp->lock);
1da177e4 3294 tg3_setup_phy(tp, 0);
f47c11ee 3295 spin_unlock(&tp->lock);
1da177e4
LT
3296 }
3297 }
3298
3299 /* run TX completion thread */
3300 if (sblk->idx[0].tx_consumer != tp->tx_cons) {
1da177e4 3301 tg3_tx(tp);
1da177e4
LT
3302 }
3303
1da177e4
LT
3304 /* run RX thread, within the bounds set by NAPI.
3305 * All RX "locking" is done by ensuring outside
3306 * code synchronizes with dev->poll()
3307 */
1da177e4
LT
3308 if (sblk->idx[0].rx_producer != tp->rx_rcb_ptr) {
3309 int orig_budget = *budget;
3310 int work_done;
3311
3312 if (orig_budget > netdev->quota)
3313 orig_budget = netdev->quota;
3314
3315 work_done = tg3_rx(tp, orig_budget);
3316
3317 *budget -= work_done;
3318 netdev->quota -= work_done;
1da177e4
LT
3319 }
3320
38f3843e 3321 if (tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) {
f7383c22 3322 tp->last_tag = sblk->status_tag;
38f3843e
MC
3323 rmb();
3324 } else
3325 sblk->status &= ~SD_STATUS_UPDATED;
f7383c22 3326
1da177e4 3327 /* if no more work, tell net stack and NIC we're done */
f7383c22 3328 done = !tg3_has_work(tp);
1da177e4 3329 if (done) {
f47c11ee 3330 netif_rx_complete(netdev);
1da177e4 3331 tg3_restart_ints(tp);
1da177e4
LT
3332 }
3333
3334 return (done ? 0 : 1);
3335}
3336
f47c11ee
DM
3337static void tg3_irq_quiesce(struct tg3 *tp)
3338{
3339 BUG_ON(tp->irq_sync);
3340
3341 tp->irq_sync = 1;
3342 smp_mb();
3343
3344 synchronize_irq(tp->pdev->irq);
3345}
3346
3347static inline int tg3_irq_sync(struct tg3 *tp)
3348{
3349 return tp->irq_sync;
3350}
3351
3352/* Fully shutdown all tg3 driver activity elsewhere in the system.
3353 * If irq_sync is non-zero, then the IRQ handler must be synchronized
3354 * with as well. Most of the time, this is not necessary except when
3355 * shutting down the device.
3356 */
3357static inline void tg3_full_lock(struct tg3 *tp, int irq_sync)
3358{
3359 if (irq_sync)
3360 tg3_irq_quiesce(tp);
3361 spin_lock_bh(&tp->lock);
3362 spin_lock(&tp->tx_lock);
3363}
3364
3365static inline void tg3_full_unlock(struct tg3 *tp)
3366{
3367 spin_unlock(&tp->tx_lock);
3368 spin_unlock_bh(&tp->lock);
3369}
3370
fcfa0a32
MC
3371/* One-shot MSI handler - Chip automatically disables interrupt
3372 * after sending MSI so driver doesn't have to do it.
3373 */
3374static irqreturn_t tg3_msi_1shot(int irq, void *dev_id, struct pt_regs *regs)
3375{
3376 struct net_device *dev = dev_id;
3377 struct tg3 *tp = netdev_priv(dev);
3378
3379 prefetch(tp->hw_status);
3380 prefetch(&tp->rx_rcb[tp->rx_rcb_ptr]);
3381
3382 if (likely(!tg3_irq_sync(tp)))
3383 netif_rx_schedule(dev); /* schedule NAPI poll */
3384
3385 return IRQ_HANDLED;
3386}
3387
88b06bc2
MC
3388/* MSI ISR - No need to check for interrupt sharing and no need to
3389 * flush status block and interrupt mailbox. PCI ordering rules
3390 * guarantee that MSI will arrive after the status block.
3391 */
3392static irqreturn_t tg3_msi(int irq, void *dev_id, struct pt_regs *regs)
3393{
3394 struct net_device *dev = dev_id;
3395 struct tg3 *tp = netdev_priv(dev);
88b06bc2 3396
61487480
MC
3397 prefetch(tp->hw_status);
3398 prefetch(&tp->rx_rcb[tp->rx_rcb_ptr]);
88b06bc2 3399 /*
fac9b83e 3400 * Writing any value to intr-mbox-0 clears PCI INTA# and
88b06bc2 3401 * chip-internal interrupt pending events.
fac9b83e 3402 * Writing non-zero to intr-mbox-0 additional tells the
88b06bc2
MC
3403 * NIC to stop sending us irqs, engaging "in-intr-handler"
3404 * event coalescing.
3405 */
3406 tw32_mailbox(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001);
61487480 3407 if (likely(!tg3_irq_sync(tp)))
88b06bc2 3408 netif_rx_schedule(dev); /* schedule NAPI poll */
61487480 3409
88b06bc2
MC
3410 return IRQ_RETVAL(1);
3411}
3412
1da177e4
LT
3413static irqreturn_t tg3_interrupt(int irq, void *dev_id, struct pt_regs *regs)
3414{
3415 struct net_device *dev = dev_id;
3416 struct tg3 *tp = netdev_priv(dev);
3417 struct tg3_hw_status *sblk = tp->hw_status;
1da177e4
LT
3418 unsigned int handled = 1;
3419
1da177e4
LT
3420 /* In INTx mode, it is possible for the interrupt to arrive at
3421 * the CPU before the status block posted prior to the interrupt.
3422 * Reading the PCI State register will confirm whether the
3423 * interrupt is ours and will flush the status block.
3424 */
3425 if ((sblk->status & SD_STATUS_UPDATED) ||
3426 !(tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) {
3427 /*
fac9b83e 3428 * Writing any value to intr-mbox-0 clears PCI INTA# and
1da177e4 3429 * chip-internal interrupt pending events.
fac9b83e 3430 * Writing non-zero to intr-mbox-0 additional tells the
1da177e4
LT
3431 * NIC to stop sending us irqs, engaging "in-intr-handler"
3432 * event coalescing.
3433 */
3434 tw32_mailbox(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW,
3435 0x00000001);
f47c11ee
DM
3436 if (tg3_irq_sync(tp))
3437 goto out;
fac9b83e 3438 sblk->status &= ~SD_STATUS_UPDATED;
61487480
MC
3439 if (likely(tg3_has_work(tp))) {
3440 prefetch(&tp->rx_rcb[tp->rx_rcb_ptr]);
fac9b83e 3441 netif_rx_schedule(dev); /* schedule NAPI poll */
61487480 3442 } else {
fac9b83e
DM
3443 /* No work, shared interrupt perhaps? re-enable
3444 * interrupts, and flush that PCI write
3445 */
09ee929c 3446 tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW,
fac9b83e 3447 0x00000000);
fac9b83e
DM
3448 }
3449 } else { /* shared interrupt */
3450 handled = 0;
3451 }
f47c11ee 3452out:
fac9b83e
DM
3453 return IRQ_RETVAL(handled);
3454}
3455
3456static irqreturn_t tg3_interrupt_tagged(int irq, void *dev_id, struct pt_regs *regs)
3457{
3458 struct net_device *dev = dev_id;
3459 struct tg3 *tp = netdev_priv(dev);
3460 struct tg3_hw_status *sblk = tp->hw_status;
fac9b83e
DM
3461 unsigned int handled = 1;
3462
fac9b83e
DM
3463 /* In INTx mode, it is possible for the interrupt to arrive at
3464 * the CPU before the status block posted prior to the interrupt.
3465 * Reading the PCI State register will confirm whether the
3466 * interrupt is ours and will flush the status block.
3467 */
38f3843e 3468 if ((sblk->status_tag != tp->last_tag) ||
fac9b83e 3469 !(tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) {
1da177e4 3470 /*
fac9b83e
DM
3471 * writing any value to intr-mbox-0 clears PCI INTA# and
3472 * chip-internal interrupt pending events.
3473 * writing non-zero to intr-mbox-0 additional tells the
3474 * NIC to stop sending us irqs, engaging "in-intr-handler"
3475 * event coalescing.
1da177e4 3476 */
fac9b83e
DM
3477 tw32_mailbox(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW,
3478 0x00000001);
f47c11ee
DM
3479 if (tg3_irq_sync(tp))
3480 goto out;
38f3843e 3481 if (netif_rx_schedule_prep(dev)) {
61487480 3482 prefetch(&tp->rx_rcb[tp->rx_rcb_ptr]);
38f3843e
MC
3483 /* Update last_tag to mark that this status has been
3484 * seen. Because interrupt may be shared, we may be
3485 * racing with tg3_poll(), so only update last_tag
3486 * if tg3_poll() is not scheduled.
1da177e4 3487 */
38f3843e
MC
3488 tp->last_tag = sblk->status_tag;
3489 __netif_rx_schedule(dev);
1da177e4
LT
3490 }
3491 } else { /* shared interrupt */
3492 handled = 0;
3493 }
f47c11ee 3494out:
1da177e4
LT
3495 return IRQ_RETVAL(handled);
3496}
3497
7938109f
MC
3498/* ISR for interrupt test */
3499static irqreturn_t tg3_test_isr(int irq, void *dev_id,
3500 struct pt_regs *regs)
3501{
3502 struct net_device *dev = dev_id;
3503 struct tg3 *tp = netdev_priv(dev);
3504 struct tg3_hw_status *sblk = tp->hw_status;
3505
f9804ddb
MC
3506 if ((sblk->status & SD_STATUS_UPDATED) ||
3507 !(tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) {
7938109f
MC
3508 tw32_mailbox(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW,
3509 0x00000001);
3510 return IRQ_RETVAL(1);
3511 }
3512 return IRQ_RETVAL(0);
3513}
3514
1da177e4 3515static int tg3_init_hw(struct tg3 *);
944d980e 3516static int tg3_halt(struct tg3 *, int, int);
1da177e4
LT
3517
3518#ifdef CONFIG_NET_POLL_CONTROLLER
3519static void tg3_poll_controller(struct net_device *dev)
3520{
88b06bc2
MC
3521 struct tg3 *tp = netdev_priv(dev);
3522
3523 tg3_interrupt(tp->pdev->irq, dev, NULL);
1da177e4
LT
3524}
3525#endif
3526
3527static void tg3_reset_task(void *_data)
3528{
3529 struct tg3 *tp = _data;
3530 unsigned int restart_timer;
3531
7faa006f
MC
3532 tg3_full_lock(tp, 0);
3533 tp->tg3_flags |= TG3_FLAG_IN_RESET_TASK;
3534
3535 if (!netif_running(tp->dev)) {
3536 tp->tg3_flags &= ~TG3_FLAG_IN_RESET_TASK;
3537 tg3_full_unlock(tp);
3538 return;
3539 }
3540
3541 tg3_full_unlock(tp);
3542
1da177e4
LT
3543 tg3_netif_stop(tp);
3544
f47c11ee 3545 tg3_full_lock(tp, 1);
1da177e4
LT
3546
3547 restart_timer = tp->tg3_flags2 & TG3_FLG2_RESTART_TIMER;
3548 tp->tg3_flags2 &= ~TG3_FLG2_RESTART_TIMER;
3549
944d980e 3550 tg3_halt(tp, RESET_KIND_SHUTDOWN, 0);
1da177e4
LT
3551 tg3_init_hw(tp);
3552
3553 tg3_netif_start(tp);
3554
1da177e4
LT
3555 if (restart_timer)
3556 mod_timer(&tp->timer, jiffies + 1);
7faa006f
MC
3557
3558 tp->tg3_flags &= ~TG3_FLAG_IN_RESET_TASK;
3559
3560 tg3_full_unlock(tp);
1da177e4
LT
3561}
3562
3563static void tg3_tx_timeout(struct net_device *dev)
3564{
3565 struct tg3 *tp = netdev_priv(dev);
3566
3567 printk(KERN_ERR PFX "%s: transmit timed out, resetting\n",
3568 dev->name);
3569
3570 schedule_work(&tp->reset_task);
3571}
3572
c58ec932
MC
3573/* Test for DMA buffers crossing any 4GB boundaries: 4G, 8G, etc */
3574static inline int tg3_4g_overflow_test(dma_addr_t mapping, int len)
3575{
3576 u32 base = (u32) mapping & 0xffffffff;
3577
3578 return ((base > 0xffffdcc0) &&
3579 (base + len + 8 < base));
3580}
3581
72f2afb8
MC
3582/* Test for DMA addresses > 40-bit */
3583static inline int tg3_40bit_overflow_test(struct tg3 *tp, dma_addr_t mapping,
3584 int len)
3585{
3586#if defined(CONFIG_HIGHMEM) && (BITS_PER_LONG == 64)
3587 if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)
3588 return (((u64) mapping + len) > DMA_40BIT_MASK);
3589 return 0;
3590#else
3591 return 0;
3592#endif
3593}
3594
1da177e4
LT
3595static void tg3_set_txd(struct tg3 *, int, dma_addr_t, int, u32, u32);
3596
72f2afb8
MC
3597/* Workaround 4GB and 40-bit hardware DMA bugs. */
3598static int tigon3_dma_hwbug_workaround(struct tg3 *tp, struct sk_buff *skb,
c58ec932
MC
3599 u32 last_plus_one, u32 *start,
3600 u32 base_flags, u32 mss)
1da177e4
LT
3601{
3602 struct sk_buff *new_skb = skb_copy(skb, GFP_ATOMIC);
c58ec932 3603 dma_addr_t new_addr = 0;
1da177e4 3604 u32 entry = *start;
c58ec932 3605 int i, ret = 0;
1da177e4
LT
3606
3607 if (!new_skb) {
c58ec932
MC
3608 ret = -1;
3609 } else {
3610 /* New SKB is guaranteed to be linear. */
3611 entry = *start;
3612 new_addr = pci_map_single(tp->pdev, new_skb->data, new_skb->len,
3613 PCI_DMA_TODEVICE);
3614 /* Make sure new skb does not cross any 4G boundaries.
3615 * Drop the packet if it does.
3616 */
3617 if (tg3_4g_overflow_test(new_addr, new_skb->len)) {
3618 ret = -1;
3619 dev_kfree_skb(new_skb);
3620 new_skb = NULL;
3621 } else {
3622 tg3_set_txd(tp, entry, new_addr, new_skb->len,
3623 base_flags, 1 | (mss << 1));
3624 *start = NEXT_TX(entry);
3625 }
1da177e4
LT
3626 }
3627
1da177e4
LT
3628 /* Now clean up the sw ring entries. */
3629 i = 0;
3630 while (entry != last_plus_one) {
3631 int len;
3632
3633 if (i == 0)
3634 len = skb_headlen(skb);
3635 else
3636 len = skb_shinfo(skb)->frags[i-1].size;
3637 pci_unmap_single(tp->pdev,
3638 pci_unmap_addr(&tp->tx_buffers[entry], mapping),
3639 len, PCI_DMA_TODEVICE);
3640 if (i == 0) {
3641 tp->tx_buffers[entry].skb = new_skb;
3642 pci_unmap_addr_set(&tp->tx_buffers[entry], mapping, new_addr);
3643 } else {
3644 tp->tx_buffers[entry].skb = NULL;
3645 }
3646 entry = NEXT_TX(entry);
3647 i++;
3648 }
3649
3650 dev_kfree_skb(skb);
3651
c58ec932 3652 return ret;
1da177e4
LT
3653}
3654
3655static void tg3_set_txd(struct tg3 *tp, int entry,
3656 dma_addr_t mapping, int len, u32 flags,
3657 u32 mss_and_is_end)
3658{
3659 struct tg3_tx_buffer_desc *txd = &tp->tx_ring[entry];
3660 int is_end = (mss_and_is_end & 0x1);
3661 u32 mss = (mss_and_is_end >> 1);
3662 u32 vlan_tag = 0;
3663
3664 if (is_end)
3665 flags |= TXD_FLAG_END;
3666 if (flags & TXD_FLAG_VLAN) {
3667 vlan_tag = flags >> 16;
3668 flags &= 0xffff;
3669 }
3670 vlan_tag |= (mss << TXD_MSS_SHIFT);
3671
3672 txd->addr_hi = ((u64) mapping >> 32);
3673 txd->addr_lo = ((u64) mapping & 0xffffffff);
3674 txd->len_flags = (len << TXD_LEN_SHIFT) | flags;
3675 txd->vlan_tag = vlan_tag << TXD_VLAN_TAG_SHIFT;
3676}
3677
5a6f3074
MC
3678/* hard_start_xmit for devices that don't have any bugs and
3679 * support TG3_FLG2_HW_TSO_2 only.
3680 */
1da177e4 3681static int tg3_start_xmit(struct sk_buff *skb, struct net_device *dev)
5a6f3074
MC
3682{
3683 struct tg3 *tp = netdev_priv(dev);
3684 dma_addr_t mapping;
3685 u32 len, entry, base_flags, mss;
3686
3687 len = skb_headlen(skb);
3688
3689 /* No BH disabling for tx_lock here. We are running in BH disabled
3690 * context and TX reclaim runs via tp->poll inside of a software
3691 * interrupt. Furthermore, IRQ processing runs lockless so we have
3692 * no IRQ context deadlocks to worry about either. Rejoice!
3693 */
3694 if (!spin_trylock(&tp->tx_lock))
3695 return NETDEV_TX_LOCKED;
3696
3697 if (unlikely(TX_BUFFS_AVAIL(tp) <= (skb_shinfo(skb)->nr_frags + 1))) {
3698 if (!netif_queue_stopped(dev)) {
3699 netif_stop_queue(dev);
3700
3701 /* This is a hard error, log it. */
3702 printk(KERN_ERR PFX "%s: BUG! Tx Ring full when "
3703 "queue awake!\n", dev->name);
3704 }
3705 spin_unlock(&tp->tx_lock);
3706 return NETDEV_TX_BUSY;
3707 }
3708
3709 entry = tp->tx_prod;
3710 base_flags = 0;
3711#if TG3_TSO_SUPPORT != 0
3712 mss = 0;
3713 if (skb->len > (tp->dev->mtu + ETH_HLEN) &&
3714 (mss = skb_shinfo(skb)->tso_size) != 0) {
3715 int tcp_opt_len, ip_tcp_len;
3716
3717 if (skb_header_cloned(skb) &&
3718 pskb_expand_head(skb, 0, 0, GFP_ATOMIC)) {
3719 dev_kfree_skb(skb);
3720 goto out_unlock;
3721 }
3722
3723 tcp_opt_len = ((skb->h.th->doff - 5) * 4);
3724 ip_tcp_len = (skb->nh.iph->ihl * 4) + sizeof(struct tcphdr);
3725
3726 base_flags |= (TXD_FLAG_CPU_PRE_DMA |
3727 TXD_FLAG_CPU_POST_DMA);
3728
3729 skb->nh.iph->check = 0;
3730 skb->nh.iph->tot_len = htons(mss + ip_tcp_len + tcp_opt_len);
3731
3732 skb->h.th->check = 0;
3733
3734 mss |= (ip_tcp_len + tcp_opt_len) << 9;
3735 }
3736 else if (skb->ip_summed == CHECKSUM_HW)
3737 base_flags |= TXD_FLAG_TCPUDP_CSUM;
3738#else
3739 mss = 0;
3740 if (skb->ip_summed == CHECKSUM_HW)
3741 base_flags |= TXD_FLAG_TCPUDP_CSUM;
3742#endif
3743#if TG3_VLAN_TAG_USED
3744 if (tp->vlgrp != NULL && vlan_tx_tag_present(skb))
3745 base_flags |= (TXD_FLAG_VLAN |
3746 (vlan_tx_tag_get(skb) << 16));
3747#endif
3748
3749 /* Queue skb data, a.k.a. the main skb fragment. */
3750 mapping = pci_map_single(tp->pdev, skb->data, len, PCI_DMA_TODEVICE);
3751
3752 tp->tx_buffers[entry].skb = skb;
3753 pci_unmap_addr_set(&tp->tx_buffers[entry], mapping, mapping);
3754
3755 tg3_set_txd(tp, entry, mapping, len, base_flags,
3756 (skb_shinfo(skb)->nr_frags == 0) | (mss << 1));
3757
3758 entry = NEXT_TX(entry);
3759
3760 /* Now loop through additional data fragments, and queue them. */
3761 if (skb_shinfo(skb)->nr_frags > 0) {
3762 unsigned int i, last;
3763
3764 last = skb_shinfo(skb)->nr_frags - 1;
3765 for (i = 0; i <= last; i++) {
3766 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
3767
3768 len = frag->size;
3769 mapping = pci_map_page(tp->pdev,
3770 frag->page,
3771 frag->page_offset,
3772 len, PCI_DMA_TODEVICE);
3773
3774 tp->tx_buffers[entry].skb = NULL;
3775 pci_unmap_addr_set(&tp->tx_buffers[entry], mapping, mapping);
3776
3777 tg3_set_txd(tp, entry, mapping, len,
3778 base_flags, (i == last) | (mss << 1));
3779
3780 entry = NEXT_TX(entry);
3781 }
3782 }
3783
3784 /* Packets are ready, update Tx producer idx local and on card. */
3785 tw32_tx_mbox((MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW), entry);
3786
3787 tp->tx_prod = entry;
3788 if (TX_BUFFS_AVAIL(tp) <= (MAX_SKB_FRAGS + 1)) {
3789 netif_stop_queue(dev);
3790 if (TX_BUFFS_AVAIL(tp) > TG3_TX_WAKEUP_THRESH)
3791 netif_wake_queue(tp->dev);
3792 }
3793
3794out_unlock:
3795 mmiowb();
3796 spin_unlock(&tp->tx_lock);
3797
3798 dev->trans_start = jiffies;
3799
3800 return NETDEV_TX_OK;
3801}
3802
3803/* hard_start_xmit for devices that have the 4G bug and/or 40-bit bug and
3804 * support TG3_FLG2_HW_TSO_1 or firmware TSO only.
3805 */
3806static int tg3_start_xmit_dma_bug(struct sk_buff *skb, struct net_device *dev)
1da177e4
LT
3807{
3808 struct tg3 *tp = netdev_priv(dev);
3809 dma_addr_t mapping;
1da177e4
LT
3810 u32 len, entry, base_flags, mss;
3811 int would_hit_hwbug;
1da177e4
LT
3812
3813 len = skb_headlen(skb);
3814
3815 /* No BH disabling for tx_lock here. We are running in BH disabled
3816 * context and TX reclaim runs via tp->poll inside of a software
f47c11ee
DM
3817 * interrupt. Furthermore, IRQ processing runs lockless so we have
3818 * no IRQ context deadlocks to worry about either. Rejoice!
1da177e4 3819 */
f47c11ee 3820 if (!spin_trylock(&tp->tx_lock))
1da177e4 3821 return NETDEV_TX_LOCKED;
1da177e4 3822
1da177e4 3823 if (unlikely(TX_BUFFS_AVAIL(tp) <= (skb_shinfo(skb)->nr_frags + 1))) {
1f064a87
SH
3824 if (!netif_queue_stopped(dev)) {
3825 netif_stop_queue(dev);
3826
3827 /* This is a hard error, log it. */
3828 printk(KERN_ERR PFX "%s: BUG! Tx Ring full when "
3829 "queue awake!\n", dev->name);
3830 }
f47c11ee 3831 spin_unlock(&tp->tx_lock);
1da177e4
LT
3832 return NETDEV_TX_BUSY;
3833 }
3834
3835 entry = tp->tx_prod;
3836 base_flags = 0;
3837 if (skb->ip_summed == CHECKSUM_HW)
3838 base_flags |= TXD_FLAG_TCPUDP_CSUM;
3839#if TG3_TSO_SUPPORT != 0
3840 mss = 0;
3841 if (skb->len > (tp->dev->mtu + ETH_HLEN) &&
3842 (mss = skb_shinfo(skb)->tso_size) != 0) {
3843 int tcp_opt_len, ip_tcp_len;
3844
3845 if (skb_header_cloned(skb) &&
3846 pskb_expand_head(skb, 0, 0, GFP_ATOMIC)) {
3847 dev_kfree_skb(skb);
3848 goto out_unlock;
3849 }
3850
3851 tcp_opt_len = ((skb->h.th->doff - 5) * 4);
3852 ip_tcp_len = (skb->nh.iph->ihl * 4) + sizeof(struct tcphdr);
3853
3854 base_flags |= (TXD_FLAG_CPU_PRE_DMA |
3855 TXD_FLAG_CPU_POST_DMA);
3856
3857 skb->nh.iph->check = 0;
fd30333d 3858 skb->nh.iph->tot_len = htons(mss + ip_tcp_len + tcp_opt_len);
1da177e4
LT
3859 if (tp->tg3_flags2 & TG3_FLG2_HW_TSO) {
3860 skb->h.th->check = 0;
3861 base_flags &= ~TXD_FLAG_TCPUDP_CSUM;
3862 }
3863 else {
3864 skb->h.th->check =
3865 ~csum_tcpudp_magic(skb->nh.iph->saddr,
3866 skb->nh.iph->daddr,
3867 0, IPPROTO_TCP, 0);
3868 }
3869
3870 if ((tp->tg3_flags2 & TG3_FLG2_HW_TSO) ||
3871 (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705)) {
3872 if (tcp_opt_len || skb->nh.iph->ihl > 5) {
3873 int tsflags;
3874
3875 tsflags = ((skb->nh.iph->ihl - 5) +
3876 (tcp_opt_len >> 2));
3877 mss |= (tsflags << 11);
3878 }
3879 } else {
3880 if (tcp_opt_len || skb->nh.iph->ihl > 5) {
3881 int tsflags;
3882
3883 tsflags = ((skb->nh.iph->ihl - 5) +
3884 (tcp_opt_len >> 2));
3885 base_flags |= tsflags << 12;
3886 }
3887 }
3888 }
3889#else
3890 mss = 0;
3891#endif
3892#if TG3_VLAN_TAG_USED
3893 if (tp->vlgrp != NULL && vlan_tx_tag_present(skb))
3894 base_flags |= (TXD_FLAG_VLAN |
3895 (vlan_tx_tag_get(skb) << 16));
3896#endif
3897
3898 /* Queue skb data, a.k.a. the main skb fragment. */
3899 mapping = pci_map_single(tp->pdev, skb->data, len, PCI_DMA_TODEVICE);
3900
3901 tp->tx_buffers[entry].skb = skb;
3902 pci_unmap_addr_set(&tp->tx_buffers[entry], mapping, mapping);
3903
3904 would_hit_hwbug = 0;
3905
3906 if (tg3_4g_overflow_test(mapping, len))
c58ec932 3907 would_hit_hwbug = 1;
1da177e4
LT
3908
3909 tg3_set_txd(tp, entry, mapping, len, base_flags,
3910 (skb_shinfo(skb)->nr_frags == 0) | (mss << 1));
3911
3912 entry = NEXT_TX(entry);
3913
3914 /* Now loop through additional data fragments, and queue them. */
3915 if (skb_shinfo(skb)->nr_frags > 0) {
3916 unsigned int i, last;
3917
3918 last = skb_shinfo(skb)->nr_frags - 1;
3919 for (i = 0; i <= last; i++) {
3920 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
3921
3922 len = frag->size;
3923 mapping = pci_map_page(tp->pdev,
3924 frag->page,
3925 frag->page_offset,
3926 len, PCI_DMA_TODEVICE);
3927
3928 tp->tx_buffers[entry].skb = NULL;
3929 pci_unmap_addr_set(&tp->tx_buffers[entry], mapping, mapping);
3930
c58ec932
MC
3931 if (tg3_4g_overflow_test(mapping, len))
3932 would_hit_hwbug = 1;
1da177e4 3933
72f2afb8
MC
3934 if (tg3_40bit_overflow_test(tp, mapping, len))
3935 would_hit_hwbug = 1;
3936
1da177e4
LT
3937 if (tp->tg3_flags2 & TG3_FLG2_HW_TSO)
3938 tg3_set_txd(tp, entry, mapping, len,
3939 base_flags, (i == last)|(mss << 1));
3940 else
3941 tg3_set_txd(tp, entry, mapping, len,
3942 base_flags, (i == last));
3943
3944 entry = NEXT_TX(entry);
3945 }
3946 }
3947
3948 if (would_hit_hwbug) {
3949 u32 last_plus_one = entry;
3950 u32 start;
1da177e4 3951
c58ec932
MC
3952 start = entry - 1 - skb_shinfo(skb)->nr_frags;
3953 start &= (TG3_TX_RING_SIZE - 1);
1da177e4
LT
3954
3955 /* If the workaround fails due to memory/mapping
3956 * failure, silently drop this packet.
3957 */
72f2afb8 3958 if (tigon3_dma_hwbug_workaround(tp, skb, last_plus_one,
c58ec932 3959 &start, base_flags, mss))
1da177e4
LT
3960 goto out_unlock;
3961
3962 entry = start;
3963 }
3964
3965 /* Packets are ready, update Tx producer idx local and on card. */
3966 tw32_tx_mbox((MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW), entry);
3967
3968 tp->tx_prod = entry;
51b91468 3969 if (TX_BUFFS_AVAIL(tp) <= (MAX_SKB_FRAGS + 1)) {
1da177e4 3970 netif_stop_queue(dev);
51b91468
MC
3971 if (TX_BUFFS_AVAIL(tp) > TG3_TX_WAKEUP_THRESH)
3972 netif_wake_queue(tp->dev);
3973 }
1da177e4
LT
3974
3975out_unlock:
3976 mmiowb();
f47c11ee 3977 spin_unlock(&tp->tx_lock);
1da177e4
LT
3978
3979 dev->trans_start = jiffies;
3980
3981 return NETDEV_TX_OK;
3982}
3983
3984static inline void tg3_set_mtu(struct net_device *dev, struct tg3 *tp,
3985 int new_mtu)
3986{
3987 dev->mtu = new_mtu;
3988
ef7f5ec0 3989 if (new_mtu > ETH_DATA_LEN) {
a4e2b347 3990 if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS) {
ef7f5ec0
MC
3991 tp->tg3_flags2 &= ~TG3_FLG2_TSO_CAPABLE;
3992 ethtool_op_set_tso(dev, 0);
3993 }
3994 else
3995 tp->tg3_flags |= TG3_FLAG_JUMBO_RING_ENABLE;
3996 } else {
a4e2b347 3997 if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)
ef7f5ec0 3998 tp->tg3_flags2 |= TG3_FLG2_TSO_CAPABLE;
0f893dc6 3999 tp->tg3_flags &= ~TG3_FLAG_JUMBO_RING_ENABLE;
ef7f5ec0 4000 }
1da177e4
LT
4001}
4002
4003static int tg3_change_mtu(struct net_device *dev, int new_mtu)
4004{
4005 struct tg3 *tp = netdev_priv(dev);
4006
4007 if (new_mtu < TG3_MIN_MTU || new_mtu > TG3_MAX_MTU(tp))
4008 return -EINVAL;
4009
4010 if (!netif_running(dev)) {
4011 /* We'll just catch it later when the
4012 * device is up'd.
4013 */
4014 tg3_set_mtu(dev, tp, new_mtu);
4015 return 0;
4016 }
4017
4018 tg3_netif_stop(tp);
f47c11ee
DM
4019
4020 tg3_full_lock(tp, 1);
1da177e4 4021
944d980e 4022 tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
1da177e4
LT
4023
4024 tg3_set_mtu(dev, tp, new_mtu);
4025
4026 tg3_init_hw(tp);
4027
4028 tg3_netif_start(tp);
4029
f47c11ee 4030 tg3_full_unlock(tp);
1da177e4
LT
4031
4032 return 0;
4033}
4034
4035/* Free up pending packets in all rx/tx rings.
4036 *
4037 * The chip has been shut down and the driver detached from
4038 * the networking, so no interrupts or new tx packets will
4039 * end up in the driver. tp->{tx,}lock is not held and we are not
4040 * in an interrupt context and thus may sleep.
4041 */
4042static void tg3_free_rings(struct tg3 *tp)
4043{
4044 struct ring_info *rxp;
4045 int i;
4046
4047 for (i = 0; i < TG3_RX_RING_SIZE; i++) {
4048 rxp = &tp->rx_std_buffers[i];
4049
4050 if (rxp->skb == NULL)
4051 continue;
4052 pci_unmap_single(tp->pdev,
4053 pci_unmap_addr(rxp, mapping),
7e72aad4 4054 tp->rx_pkt_buf_sz - tp->rx_offset,
1da177e4
LT
4055 PCI_DMA_FROMDEVICE);
4056 dev_kfree_skb_any(rxp->skb);
4057 rxp->skb = NULL;
4058 }
4059
4060 for (i = 0; i < TG3_RX_JUMBO_RING_SIZE; i++) {
4061 rxp = &tp->rx_jumbo_buffers[i];
4062
4063 if (rxp->skb == NULL)
4064 continue;
4065 pci_unmap_single(tp->pdev,
4066 pci_unmap_addr(rxp, mapping),
4067 RX_JUMBO_PKT_BUF_SZ - tp->rx_offset,
4068 PCI_DMA_FROMDEVICE);
4069 dev_kfree_skb_any(rxp->skb);
4070 rxp->skb = NULL;
4071 }
4072
4073 for (i = 0; i < TG3_TX_RING_SIZE; ) {
4074 struct tx_ring_info *txp;
4075 struct sk_buff *skb;
4076 int j;
4077
4078 txp = &tp->tx_buffers[i];
4079 skb = txp->skb;
4080
4081 if (skb == NULL) {
4082 i++;
4083 continue;
4084 }
4085
4086 pci_unmap_single(tp->pdev,
4087 pci_unmap_addr(txp, mapping),
4088 skb_headlen(skb),
4089 PCI_DMA_TODEVICE);
4090 txp->skb = NULL;
4091
4092 i++;
4093
4094 for (j = 0; j < skb_shinfo(skb)->nr_frags; j++) {
4095 txp = &tp->tx_buffers[i & (TG3_TX_RING_SIZE - 1)];
4096 pci_unmap_page(tp->pdev,
4097 pci_unmap_addr(txp, mapping),
4098 skb_shinfo(skb)->frags[j].size,
4099 PCI_DMA_TODEVICE);
4100 i++;
4101 }
4102
4103 dev_kfree_skb_any(skb);
4104 }
4105}
4106
4107/* Initialize tx/rx rings for packet processing.
4108 *
4109 * The chip has been shut down and the driver detached from
4110 * the networking, so no interrupts or new tx packets will
4111 * end up in the driver. tp->{tx,}lock are held and thus
4112 * we may not sleep.
4113 */
4114static void tg3_init_rings(struct tg3 *tp)
4115{
4116 u32 i;
4117
4118 /* Free up all the SKBs. */
4119 tg3_free_rings(tp);
4120
4121 /* Zero out all descriptors. */
4122 memset(tp->rx_std, 0, TG3_RX_RING_BYTES);
4123 memset(tp->rx_jumbo, 0, TG3_RX_JUMBO_RING_BYTES);
4124 memset(tp->rx_rcb, 0, TG3_RX_RCB_RING_BYTES(tp));
4125 memset(tp->tx_ring, 0, TG3_TX_RING_BYTES);
4126
7e72aad4 4127 tp->rx_pkt_buf_sz = RX_PKT_BUF_SZ;
a4e2b347 4128 if ((tp->tg3_flags2 & TG3_FLG2_5780_CLASS) &&
7e72aad4
MC
4129 (tp->dev->mtu > ETH_DATA_LEN))
4130 tp->rx_pkt_buf_sz = RX_JUMBO_PKT_BUF_SZ;
4131
1da177e4
LT
4132 /* Initialize invariants of the rings, we only set this
4133 * stuff once. This works because the card does not
4134 * write into the rx buffer posting rings.
4135 */
4136 for (i = 0; i < TG3_RX_RING_SIZE; i++) {
4137 struct tg3_rx_buffer_desc *rxd;
4138
4139 rxd = &tp->rx_std[i];
7e72aad4 4140 rxd->idx_len = (tp->rx_pkt_buf_sz - tp->rx_offset - 64)
1da177e4
LT
4141 << RXD_LEN_SHIFT;
4142 rxd->type_flags = (RXD_FLAG_END << RXD_FLAGS_SHIFT);
4143 rxd->opaque = (RXD_OPAQUE_RING_STD |
4144 (i << RXD_OPAQUE_INDEX_SHIFT));
4145 }
4146
0f893dc6 4147 if (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE) {
1da177e4
LT
4148 for (i = 0; i < TG3_RX_JUMBO_RING_SIZE; i++) {
4149 struct tg3_rx_buffer_desc *rxd;
4150
4151 rxd = &tp->rx_jumbo[i];
4152 rxd->idx_len = (RX_JUMBO_PKT_BUF_SZ - tp->rx_offset - 64)
4153 << RXD_LEN_SHIFT;
4154 rxd->type_flags = (RXD_FLAG_END << RXD_FLAGS_SHIFT) |
4155 RXD_FLAG_JUMBO;
4156 rxd->opaque = (RXD_OPAQUE_RING_JUMBO |
4157 (i << RXD_OPAQUE_INDEX_SHIFT));
4158 }
4159 }
4160
4161 /* Now allocate fresh SKBs for each rx ring. */
4162 for (i = 0; i < tp->rx_pending; i++) {
4163 if (tg3_alloc_rx_skb(tp, RXD_OPAQUE_RING_STD,
4164 -1, i) < 0)
4165 break;
4166 }
4167
0f893dc6 4168 if (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE) {
1da177e4
LT
4169 for (i = 0; i < tp->rx_jumbo_pending; i++) {
4170 if (tg3_alloc_rx_skb(tp, RXD_OPAQUE_RING_JUMBO,
4171 -1, i) < 0)
4172 break;
4173 }
4174 }
4175}
4176
4177/*
4178 * Must not be invoked with interrupt sources disabled and
4179 * the hardware shutdown down.
4180 */
4181static void tg3_free_consistent(struct tg3 *tp)
4182{
b4558ea9
JJ
4183 kfree(tp->rx_std_buffers);
4184 tp->rx_std_buffers = NULL;
1da177e4
LT
4185 if (tp->rx_std) {
4186 pci_free_consistent(tp->pdev, TG3_RX_RING_BYTES,
4187 tp->rx_std, tp->rx_std_mapping);
4188 tp->rx_std = NULL;
4189 }
4190 if (tp->rx_jumbo) {
4191 pci_free_consistent(tp->pdev, TG3_RX_JUMBO_RING_BYTES,
4192 tp->rx_jumbo, tp->rx_jumbo_mapping);
4193 tp->rx_jumbo = NULL;
4194 }
4195 if (tp->rx_rcb) {
4196 pci_free_consistent(tp->pdev, TG3_RX_RCB_RING_BYTES(tp),
4197 tp->rx_rcb, tp->rx_rcb_mapping);
4198 tp->rx_rcb = NULL;
4199 }
4200 if (tp->tx_ring) {
4201 pci_free_consistent(tp->pdev, TG3_TX_RING_BYTES,
4202 tp->tx_ring, tp->tx_desc_mapping);
4203 tp->tx_ring = NULL;
4204 }
4205 if (tp->hw_status) {
4206 pci_free_consistent(tp->pdev, TG3_HW_STATUS_SIZE,
4207 tp->hw_status, tp->status_mapping);
4208 tp->hw_status = NULL;
4209 }
4210 if (tp->hw_stats) {
4211 pci_free_consistent(tp->pdev, sizeof(struct tg3_hw_stats),
4212 tp->hw_stats, tp->stats_mapping);
4213 tp->hw_stats = NULL;
4214 }
4215}
4216
4217/*
4218 * Must not be invoked with interrupt sources disabled and
4219 * the hardware shutdown down. Can sleep.
4220 */
4221static int tg3_alloc_consistent(struct tg3 *tp)
4222{
4223 tp->rx_std_buffers = kmalloc((sizeof(struct ring_info) *
4224 (TG3_RX_RING_SIZE +
4225 TG3_RX_JUMBO_RING_SIZE)) +
4226 (sizeof(struct tx_ring_info) *
4227 TG3_TX_RING_SIZE),
4228 GFP_KERNEL);
4229 if (!tp->rx_std_buffers)
4230 return -ENOMEM;
4231
4232 memset(tp->rx_std_buffers, 0,
4233 (sizeof(struct ring_info) *
4234 (TG3_RX_RING_SIZE +
4235 TG3_RX_JUMBO_RING_SIZE)) +
4236 (sizeof(struct tx_ring_info) *
4237 TG3_TX_RING_SIZE));
4238
4239 tp->rx_jumbo_buffers = &tp->rx_std_buffers[TG3_RX_RING_SIZE];
4240 tp->tx_buffers = (struct tx_ring_info *)
4241 &tp->rx_jumbo_buffers[TG3_RX_JUMBO_RING_SIZE];
4242
4243 tp->rx_std = pci_alloc_consistent(tp->pdev, TG3_RX_RING_BYTES,
4244 &tp->rx_std_mapping);
4245 if (!tp->rx_std)
4246 goto err_out;
4247
4248 tp->rx_jumbo = pci_alloc_consistent(tp->pdev, TG3_RX_JUMBO_RING_BYTES,
4249 &tp->rx_jumbo_mapping);
4250
4251 if (!tp->rx_jumbo)
4252 goto err_out;
4253
4254 tp->rx_rcb = pci_alloc_consistent(tp->pdev, TG3_RX_RCB_RING_BYTES(tp),
4255 &tp->rx_rcb_mapping);
4256 if (!tp->rx_rcb)
4257 goto err_out;
4258
4259 tp->tx_ring = pci_alloc_consistent(tp->pdev, TG3_TX_RING_BYTES,
4260 &tp->tx_desc_mapping);
4261 if (!tp->tx_ring)
4262 goto err_out;
4263
4264 tp->hw_status = pci_alloc_consistent(tp->pdev,
4265 TG3_HW_STATUS_SIZE,
4266 &tp->status_mapping);
4267 if (!tp->hw_status)
4268 goto err_out;
4269
4270 tp->hw_stats = pci_alloc_consistent(tp->pdev,
4271 sizeof(struct tg3_hw_stats),
4272 &tp->stats_mapping);
4273 if (!tp->hw_stats)
4274 goto err_out;
4275
4276 memset(tp->hw_status, 0, TG3_HW_STATUS_SIZE);
4277 memset(tp->hw_stats, 0, sizeof(struct tg3_hw_stats));
4278
4279 return 0;
4280
4281err_out:
4282 tg3_free_consistent(tp);
4283 return -ENOMEM;
4284}
4285
4286#define MAX_WAIT_CNT 1000
4287
4288/* To stop a block, clear the enable bit and poll till it
4289 * clears. tp->lock is held.
4290 */
b3b7d6be 4291static int tg3_stop_block(struct tg3 *tp, unsigned long ofs, u32 enable_bit, int silent)
1da177e4
LT
4292{
4293 unsigned int i;
4294 u32 val;
4295
4296 if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
4297 switch (ofs) {
4298 case RCVLSC_MODE:
4299 case DMAC_MODE:
4300 case MBFREE_MODE:
4301 case BUFMGR_MODE:
4302 case MEMARB_MODE:
4303 /* We can't enable/disable these bits of the
4304 * 5705/5750, just say success.
4305 */
4306 return 0;
4307
4308 default:
4309 break;
4310 };
4311 }
4312
4313 val = tr32(ofs);
4314 val &= ~enable_bit;
4315 tw32_f(ofs, val);
4316
4317 for (i = 0; i < MAX_WAIT_CNT; i++) {
4318 udelay(100);
4319 val = tr32(ofs);
4320 if ((val & enable_bit) == 0)
4321 break;
4322 }
4323
b3b7d6be 4324 if (i == MAX_WAIT_CNT && !silent) {
1da177e4
LT
4325 printk(KERN_ERR PFX "tg3_stop_block timed out, "
4326 "ofs=%lx enable_bit=%x\n",
4327 ofs, enable_bit);
4328 return -ENODEV;
4329 }
4330
4331 return 0;
4332}
4333
4334/* tp->lock is held. */
b3b7d6be 4335static int tg3_abort_hw(struct tg3 *tp, int silent)
1da177e4
LT
4336{
4337 int i, err;
4338
4339 tg3_disable_ints(tp);
4340
4341 tp->rx_mode &= ~RX_MODE_ENABLE;
4342 tw32_f(MAC_RX_MODE, tp->rx_mode);
4343 udelay(10);
4344
b3b7d6be
DM
4345 err = tg3_stop_block(tp, RCVBDI_MODE, RCVBDI_MODE_ENABLE, silent);
4346 err |= tg3_stop_block(tp, RCVLPC_MODE, RCVLPC_MODE_ENABLE, silent);
4347 err |= tg3_stop_block(tp, RCVLSC_MODE, RCVLSC_MODE_ENABLE, silent);
4348 err |= tg3_stop_block(tp, RCVDBDI_MODE, RCVDBDI_MODE_ENABLE, silent);
4349 err |= tg3_stop_block(tp, RCVDCC_MODE, RCVDCC_MODE_ENABLE, silent);
4350 err |= tg3_stop_block(tp, RCVCC_MODE, RCVCC_MODE_ENABLE, silent);
4351
4352 err |= tg3_stop_block(tp, SNDBDS_MODE, SNDBDS_MODE_ENABLE, silent);
4353 err |= tg3_stop_block(tp, SNDBDI_MODE, SNDBDI_MODE_ENABLE, silent);
4354 err |= tg3_stop_block(tp, SNDDATAI_MODE, SNDDATAI_MODE_ENABLE, silent);
4355 err |= tg3_stop_block(tp, RDMAC_MODE, RDMAC_MODE_ENABLE, silent);
4356 err |= tg3_stop_block(tp, SNDDATAC_MODE, SNDDATAC_MODE_ENABLE, silent);
4357 err |= tg3_stop_block(tp, DMAC_MODE, DMAC_MODE_ENABLE, silent);
4358 err |= tg3_stop_block(tp, SNDBDC_MODE, SNDBDC_MODE_ENABLE, silent);
1da177e4
LT
4359
4360 tp->mac_mode &= ~MAC_MODE_TDE_ENABLE;
4361 tw32_f(MAC_MODE, tp->mac_mode);
4362 udelay(40);
4363
4364 tp->tx_mode &= ~TX_MODE_ENABLE;
4365 tw32_f(MAC_TX_MODE, tp->tx_mode);
4366
4367 for (i = 0; i < MAX_WAIT_CNT; i++) {
4368 udelay(100);
4369 if (!(tr32(MAC_TX_MODE) & TX_MODE_ENABLE))
4370 break;
4371 }
4372 if (i >= MAX_WAIT_CNT) {
4373 printk(KERN_ERR PFX "tg3_abort_hw timed out for %s, "
4374 "TX_MODE_ENABLE will not clear MAC_TX_MODE=%08x\n",
4375 tp->dev->name, tr32(MAC_TX_MODE));
e6de8ad1 4376 err |= -ENODEV;
1da177e4
LT
4377 }
4378
e6de8ad1 4379 err |= tg3_stop_block(tp, HOSTCC_MODE, HOSTCC_MODE_ENABLE, silent);
b3b7d6be
DM
4380 err |= tg3_stop_block(tp, WDMAC_MODE, WDMAC_MODE_ENABLE, silent);
4381 err |= tg3_stop_block(tp, MBFREE_MODE, MBFREE_MODE_ENABLE, silent);
1da177e4
LT
4382
4383 tw32(FTQ_RESET, 0xffffffff);
4384 tw32(FTQ_RESET, 0x00000000);
4385
b3b7d6be
DM
4386 err |= tg3_stop_block(tp, BUFMGR_MODE, BUFMGR_MODE_ENABLE, silent);
4387 err |= tg3_stop_block(tp, MEMARB_MODE, MEMARB_MODE_ENABLE, silent);
1da177e4
LT
4388
4389 if (tp->hw_status)
4390 memset(tp->hw_status, 0, TG3_HW_STATUS_SIZE);
4391 if (tp->hw_stats)
4392 memset(tp->hw_stats, 0, sizeof(struct tg3_hw_stats));
4393
1da177e4
LT
4394 return err;
4395}
4396
4397/* tp->lock is held. */
4398static int tg3_nvram_lock(struct tg3 *tp)
4399{
4400 if (tp->tg3_flags & TG3_FLAG_NVRAM) {
4401 int i;
4402
ec41c7df
MC
4403 if (tp->nvram_lock_cnt == 0) {
4404 tw32(NVRAM_SWARB, SWARB_REQ_SET1);
4405 for (i = 0; i < 8000; i++) {
4406 if (tr32(NVRAM_SWARB) & SWARB_GNT1)
4407 break;
4408 udelay(20);
4409 }
4410 if (i == 8000) {
4411 tw32(NVRAM_SWARB, SWARB_REQ_CLR1);
4412 return -ENODEV;
4413 }
1da177e4 4414 }
ec41c7df 4415 tp->nvram_lock_cnt++;
1da177e4
LT
4416 }
4417 return 0;
4418}
4419
4420/* tp->lock is held. */
4421static void tg3_nvram_unlock(struct tg3 *tp)
4422{
ec41c7df
MC
4423 if (tp->tg3_flags & TG3_FLAG_NVRAM) {
4424 if (tp->nvram_lock_cnt > 0)
4425 tp->nvram_lock_cnt--;
4426 if (tp->nvram_lock_cnt == 0)
4427 tw32_f(NVRAM_SWARB, SWARB_REQ_CLR1);
4428 }
1da177e4
LT
4429}
4430
e6af301b
MC
4431/* tp->lock is held. */
4432static void tg3_enable_nvram_access(struct tg3 *tp)
4433{
4434 if ((tp->tg3_flags2 & TG3_FLG2_5750_PLUS) &&
4435 !(tp->tg3_flags2 & TG3_FLG2_PROTECTED_NVRAM)) {
4436 u32 nvaccess = tr32(NVRAM_ACCESS);
4437
4438 tw32(NVRAM_ACCESS, nvaccess | ACCESS_ENABLE);
4439 }
4440}
4441
4442/* tp->lock is held. */
4443static void tg3_disable_nvram_access(struct tg3 *tp)
4444{
4445 if ((tp->tg3_flags2 & TG3_FLG2_5750_PLUS) &&
4446 !(tp->tg3_flags2 & TG3_FLG2_PROTECTED_NVRAM)) {
4447 u32 nvaccess = tr32(NVRAM_ACCESS);
4448
4449 tw32(NVRAM_ACCESS, nvaccess & ~ACCESS_ENABLE);
4450 }
4451}
4452
1da177e4
LT
4453/* tp->lock is held. */
4454static void tg3_write_sig_pre_reset(struct tg3 *tp, int kind)
4455{
4456 if (!(tp->tg3_flags2 & TG3_FLG2_SUN_570X))
4457 tg3_write_mem(tp, NIC_SRAM_FIRMWARE_MBOX,
4458 NIC_SRAM_FIRMWARE_MBOX_MAGIC1);
4459
4460 if (tp->tg3_flags2 & TG3_FLG2_ASF_NEW_HANDSHAKE) {
4461 switch (kind) {
4462 case RESET_KIND_INIT:
4463 tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
4464 DRV_STATE_START);
4465 break;
4466
4467 case RESET_KIND_SHUTDOWN:
4468 tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
4469 DRV_STATE_UNLOAD);
4470 break;
4471
4472 case RESET_KIND_SUSPEND:
4473 tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
4474 DRV_STATE_SUSPEND);
4475 break;
4476
4477 default:
4478 break;
4479 };
4480 }
4481}
4482
4483/* tp->lock is held. */
4484static void tg3_write_sig_post_reset(struct tg3 *tp, int kind)
4485{
4486 if (tp->tg3_flags2 & TG3_FLG2_ASF_NEW_HANDSHAKE) {
4487 switch (kind) {
4488 case RESET_KIND_INIT:
4489 tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
4490 DRV_STATE_START_DONE);
4491 break;
4492
4493 case RESET_KIND_SHUTDOWN:
4494 tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
4495 DRV_STATE_UNLOAD_DONE);
4496 break;
4497
4498 default:
4499 break;
4500 };
4501 }
4502}
4503
4504/* tp->lock is held. */
4505static void tg3_write_sig_legacy(struct tg3 *tp, int kind)
4506{
4507 if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) {
4508 switch (kind) {
4509 case RESET_KIND_INIT:
4510 tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
4511 DRV_STATE_START);
4512 break;
4513
4514 case RESET_KIND_SHUTDOWN:
4515 tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
4516 DRV_STATE_UNLOAD);
4517 break;
4518
4519 case RESET_KIND_SUSPEND:
4520 tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
4521 DRV_STATE_SUSPEND);
4522 break;
4523
4524 default:
4525 break;
4526 };
4527 }
4528}
4529
4530static void tg3_stop_fw(struct tg3 *);
4531
4532/* tp->lock is held. */
4533static int tg3_chip_reset(struct tg3 *tp)
4534{
4535 u32 val;
1ee582d8 4536 void (*write_op)(struct tg3 *, u32, u32);
1da177e4
LT
4537 int i;
4538
ec41c7df 4539 if (!(tp->tg3_flags2 & TG3_FLG2_SUN_570X)) {
1da177e4 4540 tg3_nvram_lock(tp);
ec41c7df
MC
4541 /* No matching tg3_nvram_unlock() after this because
4542 * chip reset below will undo the nvram lock.
4543 */
4544 tp->nvram_lock_cnt = 0;
4545 }
1da177e4 4546
d9ab5ad1
MC
4547 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 ||
4548 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787)
4549 tw32(GRC_FASTBOOT_PC, 0);
4550
1da177e4
LT
4551 /*
4552 * We must avoid the readl() that normally takes place.
4553 * It locks machines, causes machine checks, and other
4554 * fun things. So, temporarily disable the 5701
4555 * hardware workaround, while we do the reset.
4556 */
1ee582d8
MC
4557 write_op = tp->write32;
4558 if (write_op == tg3_write_flush_reg32)
4559 tp->write32 = tg3_write32;
1da177e4
LT
4560
4561 /* do the reset */
4562 val = GRC_MISC_CFG_CORECLK_RESET;
4563
4564 if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) {
4565 if (tr32(0x7e2c) == 0x60) {
4566 tw32(0x7e2c, 0x20);
4567 }
4568 if (tp->pci_chip_rev_id != CHIPREV_ID_5750_A0) {
4569 tw32(GRC_MISC_CFG, (1 << 29));
4570 val |= (1 << 29);
4571 }
4572 }
4573
4574 if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS)
4575 val |= GRC_MISC_CFG_KEEP_GPHY_POWER;
4576 tw32(GRC_MISC_CFG, val);
4577
1ee582d8
MC
4578 /* restore 5701 hardware bug workaround write method */
4579 tp->write32 = write_op;
1da177e4
LT
4580
4581 /* Unfortunately, we have to delay before the PCI read back.
4582 * Some 575X chips even will not respond to a PCI cfg access
4583 * when the reset command is given to the chip.
4584 *
4585 * How do these hardware designers expect things to work
4586 * properly if the PCI write is posted for a long period
4587 * of time? It is always necessary to have some method by
4588 * which a register read back can occur to push the write
4589 * out which does the reset.
4590 *
4591 * For most tg3 variants the trick below was working.
4592 * Ho hum...
4593 */
4594 udelay(120);
4595
4596 /* Flush PCI posted writes. The normal MMIO registers
4597 * are inaccessible at this time so this is the only
4598 * way to make this reliably (actually, this is no longer
4599 * the case, see above). I tried to use indirect
4600 * register read/write but this upset some 5701 variants.
4601 */
4602 pci_read_config_dword(tp->pdev, PCI_COMMAND, &val);
4603
4604 udelay(120);
4605
4606 if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) {
4607 if (tp->pci_chip_rev_id == CHIPREV_ID_5750_A0) {
4608 int i;
4609 u32 cfg_val;
4610
4611 /* Wait for link training to complete. */
4612 for (i = 0; i < 5000; i++)
4613 udelay(100);
4614
4615 pci_read_config_dword(tp->pdev, 0xc4, &cfg_val);
4616 pci_write_config_dword(tp->pdev, 0xc4,
4617 cfg_val | (1 << 15));
4618 }
4619 /* Set PCIE max payload size and clear error status. */
4620 pci_write_config_dword(tp->pdev, 0xd8, 0xf5000);
4621 }
4622
4623 /* Re-enable indirect register accesses. */
4624 pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL,
4625 tp->misc_host_ctrl);
4626
4627 /* Set MAX PCI retry to zero. */
4628 val = (PCISTATE_ROM_ENABLE | PCISTATE_ROM_RETRY_ENABLE);
4629 if (tp->pci_chip_rev_id == CHIPREV_ID_5704_A0 &&
4630 (tp->tg3_flags & TG3_FLAG_PCIX_MODE))
4631 val |= PCISTATE_RETRY_SAME_DMA;
4632 pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE, val);
4633
4634 pci_restore_state(tp->pdev);
4635
4636 /* Make sure PCI-X relaxed ordering bit is clear. */
4637 pci_read_config_dword(tp->pdev, TG3PCI_X_CAPS, &val);
4638 val &= ~PCIX_CAPS_RELAXED_ORDERING;
4639 pci_write_config_dword(tp->pdev, TG3PCI_X_CAPS, val);
4640
a4e2b347 4641 if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS) {
4cf78e4f
MC
4642 u32 val;
4643
4644 /* Chip reset on 5780 will reset MSI enable bit,
4645 * so need to restore it.
4646 */
4647 if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
4648 u16 ctrl;
4649
4650 pci_read_config_word(tp->pdev,
4651 tp->msi_cap + PCI_MSI_FLAGS,
4652 &ctrl);
4653 pci_write_config_word(tp->pdev,
4654 tp->msi_cap + PCI_MSI_FLAGS,
4655 ctrl | PCI_MSI_FLAGS_ENABLE);
4656 val = tr32(MSGINT_MODE);
4657 tw32(MSGINT_MODE, val | MSGINT_MODE_ENABLE);
4658 }
4659
4660 val = tr32(MEMARB_MODE);
4661 tw32(MEMARB_MODE, val | MEMARB_MODE_ENABLE);
4662
4663 } else
4664 tw32(MEMARB_MODE, MEMARB_MODE_ENABLE);
1da177e4
LT
4665
4666 if (tp->pci_chip_rev_id == CHIPREV_ID_5750_A3) {
4667 tg3_stop_fw(tp);
4668 tw32(0x5000, 0x400);
4669 }
4670
4671 tw32(GRC_MODE, tp->grc_mode);
4672
4673 if (tp->pci_chip_rev_id == CHIPREV_ID_5705_A0) {
4674 u32 val = tr32(0xc4);
4675
4676 tw32(0xc4, val | (1 << 15));
4677 }
4678
4679 if ((tp->nic_sram_data_cfg & NIC_SRAM_DATA_CFG_MINI_PCI) != 0 &&
4680 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) {
4681 tp->pci_clock_ctrl |= CLOCK_CTRL_CLKRUN_OENABLE;
4682 if (tp->pci_chip_rev_id == CHIPREV_ID_5705_A0)
4683 tp->pci_clock_ctrl |= CLOCK_CTRL_FORCE_CLKRUN;
4684 tw32(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl);
4685 }
4686
4687 if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) {
4688 tp->mac_mode = MAC_MODE_PORT_MODE_TBI;
4689 tw32_f(MAC_MODE, tp->mac_mode);
747e8f8b
MC
4690 } else if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES) {
4691 tp->mac_mode = MAC_MODE_PORT_MODE_GMII;
4692 tw32_f(MAC_MODE, tp->mac_mode);
1da177e4
LT
4693 } else
4694 tw32_f(MAC_MODE, 0);
4695 udelay(40);
4696
4697 if (!(tp->tg3_flags2 & TG3_FLG2_SUN_570X)) {
4698 /* Wait for firmware initialization to complete. */
4699 for (i = 0; i < 100000; i++) {
4700 tg3_read_mem(tp, NIC_SRAM_FIRMWARE_MBOX, &val);
4701 if (val == ~NIC_SRAM_FIRMWARE_MBOX_MAGIC1)
4702 break;
4703 udelay(10);
4704 }
4705 if (i >= 100000) {
4706 printk(KERN_ERR PFX "tg3_reset_hw timed out for %s, "
4707 "firmware will not restart magic=%08x\n",
4708 tp->dev->name, val);
4709 return -ENODEV;
4710 }
4711 }
4712
4713 if ((tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) &&
4714 tp->pci_chip_rev_id != CHIPREV_ID_5750_A0) {
4715 u32 val = tr32(0x7c00);
4716
4717 tw32(0x7c00, val | (1 << 25));
4718 }
4719
4720 /* Reprobe ASF enable state. */
4721 tp->tg3_flags &= ~TG3_FLAG_ENABLE_ASF;
4722 tp->tg3_flags2 &= ~TG3_FLG2_ASF_NEW_HANDSHAKE;
4723 tg3_read_mem(tp, NIC_SRAM_DATA_SIG, &val);
4724 if (val == NIC_SRAM_DATA_SIG_MAGIC) {
4725 u32 nic_cfg;
4726
4727 tg3_read_mem(tp, NIC_SRAM_DATA_CFG, &nic_cfg);
4728 if (nic_cfg & NIC_SRAM_DATA_CFG_ASF_ENABLE) {
4729 tp->tg3_flags |= TG3_FLAG_ENABLE_ASF;
cbf46853 4730 if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS)
1da177e4
LT
4731 tp->tg3_flags2 |= TG3_FLG2_ASF_NEW_HANDSHAKE;
4732 }
4733 }
4734
4735 return 0;
4736}
4737
4738/* tp->lock is held. */
4739static void tg3_stop_fw(struct tg3 *tp)
4740{
4741 if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) {
4742 u32 val;
4743 int i;
4744
4745 tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX, FWCMD_NICDRV_PAUSE_FW);
4746 val = tr32(GRC_RX_CPU_EVENT);
4747 val |= (1 << 14);
4748 tw32(GRC_RX_CPU_EVENT, val);
4749
4750 /* Wait for RX cpu to ACK the event. */
4751 for (i = 0; i < 100; i++) {
4752 if (!(tr32(GRC_RX_CPU_EVENT) & (1 << 14)))
4753 break;
4754 udelay(1);
4755 }
4756 }
4757}
4758
4759/* tp->lock is held. */
944d980e 4760static int tg3_halt(struct tg3 *tp, int kind, int silent)
1da177e4
LT
4761{
4762 int err;
4763
4764 tg3_stop_fw(tp);
4765
944d980e 4766 tg3_write_sig_pre_reset(tp, kind);
1da177e4 4767
b3b7d6be 4768 tg3_abort_hw(tp, silent);
1da177e4
LT
4769 err = tg3_chip_reset(tp);
4770
944d980e
MC
4771 tg3_write_sig_legacy(tp, kind);
4772 tg3_write_sig_post_reset(tp, kind);
1da177e4
LT
4773
4774 if (err)
4775 return err;
4776
4777 return 0;
4778}
4779
4780#define TG3_FW_RELEASE_MAJOR 0x0
4781#define TG3_FW_RELASE_MINOR 0x0
4782#define TG3_FW_RELEASE_FIX 0x0
4783#define TG3_FW_START_ADDR 0x08000000
4784#define TG3_FW_TEXT_ADDR 0x08000000
4785#define TG3_FW_TEXT_LEN 0x9c0
4786#define TG3_FW_RODATA_ADDR 0x080009c0
4787#define TG3_FW_RODATA_LEN 0x60
4788#define TG3_FW_DATA_ADDR 0x08000a40
4789#define TG3_FW_DATA_LEN 0x20
4790#define TG3_FW_SBSS_ADDR 0x08000a60
4791#define TG3_FW_SBSS_LEN 0xc
4792#define TG3_FW_BSS_ADDR 0x08000a70
4793#define TG3_FW_BSS_LEN 0x10
4794
4795static u32 tg3FwText[(TG3_FW_TEXT_LEN / sizeof(u32)) + 1] = {
4796 0x00000000, 0x10000003, 0x00000000, 0x0000000d, 0x0000000d, 0x3c1d0800,
4797 0x37bd3ffc, 0x03a0f021, 0x3c100800, 0x26100000, 0x0e000018, 0x00000000,
4798 0x0000000d, 0x3c1d0800, 0x37bd3ffc, 0x03a0f021, 0x3c100800, 0x26100034,
4799 0x0e00021c, 0x00000000, 0x0000000d, 0x00000000, 0x00000000, 0x00000000,
4800 0x27bdffe0, 0x3c1cc000, 0xafbf0018, 0xaf80680c, 0x0e00004c, 0x241b2105,
4801 0x97850000, 0x97870002, 0x9782002c, 0x9783002e, 0x3c040800, 0x248409c0,
4802 0xafa00014, 0x00021400, 0x00621825, 0x00052c00, 0xafa30010, 0x8f860010,
4803 0x00e52825, 0x0e000060, 0x24070102, 0x3c02ac00, 0x34420100, 0x3c03ac01,
4804 0x34630100, 0xaf820490, 0x3c02ffff, 0xaf820494, 0xaf830498, 0xaf82049c,
4805 0x24020001, 0xaf825ce0, 0x0e00003f, 0xaf825d00, 0x0e000140, 0x00000000,
4806 0x8fbf0018, 0x03e00008, 0x27bd0020, 0x2402ffff, 0xaf825404, 0x8f835400,
4807 0x34630400, 0xaf835400, 0xaf825404, 0x3c020800, 0x24420034, 0xaf82541c,
4808 0x03e00008, 0xaf805400, 0x00000000, 0x00000000, 0x3c020800, 0x34423000,
4809 0x3c030800, 0x34633000, 0x3c040800, 0x348437ff, 0x3c010800, 0xac220a64,
4810 0x24020040, 0x3c010800, 0xac220a68, 0x3c010800, 0xac200a60, 0xac600000,
4811 0x24630004, 0x0083102b, 0x5040fffd, 0xac600000, 0x03e00008, 0x00000000,
4812 0x00804821, 0x8faa0010, 0x3c020800, 0x8c420a60, 0x3c040800, 0x8c840a68,
4813 0x8fab0014, 0x24430001, 0x0044102b, 0x3c010800, 0xac230a60, 0x14400003,
4814 0x00004021, 0x3c010800, 0xac200a60, 0x3c020800, 0x8c420a60, 0x3c030800,
4815 0x8c630a64, 0x91240000, 0x00021140, 0x00431021, 0x00481021, 0x25080001,
4816 0xa0440000, 0x29020008, 0x1440fff4, 0x25290001, 0x3c020800, 0x8c420a60,
4817 0x3c030800, 0x8c630a64, 0x8f84680c, 0x00021140, 0x00431021, 0xac440008,
4818 0xac45000c, 0xac460010, 0xac470014, 0xac4a0018, 0x03e00008, 0xac4b001c,
4819 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4820 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4821 0, 0, 0, 0, 0, 0,
4822 0x02000008, 0x00000000, 0x0a0001e3, 0x3c0a0001, 0x0a0001e3, 0x3c0a0002,
4823 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000,
4824 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000,
4825 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000,
4826 0x0a0001e3, 0x3c0a0007, 0x0a0001e3, 0x3c0a0008, 0x0a0001e3, 0x3c0a0009,
4827 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x3c0a000b,
4828 0x0a0001e3, 0x3c0a000c, 0x0a0001e3, 0x3c0a000d, 0x0a0001e3, 0x00000000,
4829 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x3c0a000e, 0x0a0001e3, 0x00000000,
4830 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000,
4831 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000,
4832 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x3c0a0013, 0x0a0001e3, 0x3c0a0014,
4833 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4834 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4835 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4836 0x27bdffe0, 0x00001821, 0x00001021, 0xafbf0018, 0xafb10014, 0xafb00010,
4837 0x3c010800, 0x00220821, 0xac200a70, 0x3c010800, 0x00220821, 0xac200a74,
4838 0x3c010800, 0x00220821, 0xac200a78, 0x24630001, 0x1860fff5, 0x2442000c,
4839 0x24110001, 0x8f906810, 0x32020004, 0x14400005, 0x24040001, 0x3c020800,
4840 0x8c420a78, 0x18400003, 0x00002021, 0x0e000182, 0x00000000, 0x32020001,
4841 0x10400003, 0x00000000, 0x0e000169, 0x00000000, 0x0a000153, 0xaf915028,
4842 0x8fbf0018, 0x8fb10014, 0x8fb00010, 0x03e00008, 0x27bd0020, 0x3c050800,
4843 0x8ca50a70, 0x3c060800, 0x8cc60a80, 0x3c070800, 0x8ce70a78, 0x27bdffe0,
4844 0x3c040800, 0x248409d0, 0xafbf0018, 0xafa00010, 0x0e000060, 0xafa00014,
4845 0x0e00017b, 0x00002021, 0x8fbf0018, 0x03e00008, 0x27bd0020, 0x24020001,
4846 0x8f836810, 0x00821004, 0x00021027, 0x00621824, 0x03e00008, 0xaf836810,
4847 0x27bdffd8, 0xafbf0024, 0x1080002e, 0xafb00020, 0x8f825cec, 0xafa20018,
4848 0x8f825cec, 0x3c100800, 0x26100a78, 0xafa2001c, 0x34028000, 0xaf825cec,
4849 0x8e020000, 0x18400016, 0x00000000, 0x3c020800, 0x94420a74, 0x8fa3001c,
4850 0x000221c0, 0xac830004, 0x8fa2001c, 0x3c010800, 0x0e000201, 0xac220a74,
4851 0x10400005, 0x00000000, 0x8e020000, 0x24420001, 0x0a0001df, 0xae020000,
4852 0x3c020800, 0x8c420a70, 0x00021c02, 0x000321c0, 0x0a0001c5, 0xafa2001c,
4853 0x0e000201, 0x00000000, 0x1040001f, 0x00000000, 0x8e020000, 0x8fa3001c,
4854 0x24420001, 0x3c010800, 0xac230a70, 0x3c010800, 0xac230a74, 0x0a0001df,
4855 0xae020000, 0x3c100800, 0x26100a78, 0x8e020000, 0x18400028, 0x00000000,
4856 0x0e000201, 0x00000000, 0x14400024, 0x00000000, 0x8e020000, 0x3c030800,
4857 0x8c630a70, 0x2442ffff, 0xafa3001c, 0x18400006, 0xae020000, 0x00031402,
4858 0x000221c0, 0x8c820004, 0x3c010800, 0xac220a70, 0x97a2001e, 0x2442ff00,
4859 0x2c420300, 0x1440000b, 0x24024000, 0x3c040800, 0x248409dc, 0xafa00010,
4860 0xafa00014, 0x8fa6001c, 0x24050008, 0x0e000060, 0x00003821, 0x0a0001df,
4861 0x00000000, 0xaf825cf8, 0x3c020800, 0x8c420a40, 0x8fa3001c, 0x24420001,
4862 0xaf835cf8, 0x3c010800, 0xac220a40, 0x8fbf0024, 0x8fb00020, 0x03e00008,
4863 0x27bd0028, 0x27bdffe0, 0x3c040800, 0x248409e8, 0x00002821, 0x00003021,
4864 0x00003821, 0xafbf0018, 0xafa00010, 0x0e000060, 0xafa00014, 0x8fbf0018,
4865 0x03e00008, 0x27bd0020, 0x8f82680c, 0x8f85680c, 0x00021827, 0x0003182b,
4866 0x00031823, 0x00431024, 0x00441021, 0x00a2282b, 0x10a00006, 0x00000000,
4867 0x00401821, 0x8f82680c, 0x0043102b, 0x1440fffd, 0x00000000, 0x03e00008,
4868 0x00000000, 0x3c040800, 0x8c840000, 0x3c030800, 0x8c630a40, 0x0064102b,
4869 0x54400002, 0x00831023, 0x00641023, 0x2c420008, 0x03e00008, 0x38420001,
4870 0x27bdffe0, 0x00802821, 0x3c040800, 0x24840a00, 0x00003021, 0x00003821,
4871 0xafbf0018, 0xafa00010, 0x0e000060, 0xafa00014, 0x0a000216, 0x00000000,
4872 0x8fbf0018, 0x03e00008, 0x27bd0020, 0x00000000, 0x27bdffe0, 0x3c1cc000,
4873 0xafbf0018, 0x0e00004c, 0xaf80680c, 0x3c040800, 0x24840a10, 0x03802821,
4874 0x00003021, 0x00003821, 0xafa00010, 0x0e000060, 0xafa00014, 0x2402ffff,
4875 0xaf825404, 0x3c0200aa, 0x0e000234, 0xaf825434, 0x8fbf0018, 0x03e00008,
4876 0x27bd0020, 0x00000000, 0x00000000, 0x00000000, 0x27bdffe8, 0xafb00010,
4877 0x24100001, 0xafbf0014, 0x3c01c003, 0xac200000, 0x8f826810, 0x30422000,
4878 0x10400003, 0x00000000, 0x0e000246, 0x00000000, 0x0a00023a, 0xaf905428,
4879 0x8fbf0014, 0x8fb00010, 0x03e00008, 0x27bd0018, 0x27bdfff8, 0x8f845d0c,
4880 0x3c0200ff, 0x3c030800, 0x8c630a50, 0x3442fff8, 0x00821024, 0x1043001e,
4881 0x3c0500ff, 0x34a5fff8, 0x3c06c003, 0x3c074000, 0x00851824, 0x8c620010,
4882 0x3c010800, 0xac230a50, 0x30420008, 0x10400005, 0x00871025, 0x8cc20000,
4883 0x24420001, 0xacc20000, 0x00871025, 0xaf825d0c, 0x8fa20000, 0x24420001,
4884 0xafa20000, 0x8fa20000, 0x8fa20000, 0x24420001, 0xafa20000, 0x8fa20000,
4885 0x8f845d0c, 0x3c030800, 0x8c630a50, 0x00851024, 0x1443ffe8, 0x00851824,
4886 0x27bd0008, 0x03e00008, 0x00000000, 0x00000000, 0x00000000
4887};
4888
4889static u32 tg3FwRodata[(TG3_FW_RODATA_LEN / sizeof(u32)) + 1] = {
4890 0x35373031, 0x726c7341, 0x00000000, 0x00000000, 0x53774576, 0x656e7430,
4891 0x00000000, 0x726c7045, 0x76656e74, 0x31000000, 0x556e6b6e, 0x45766e74,
4892 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x66617461, 0x6c457272,
4893 0x00000000, 0x00000000, 0x4d61696e, 0x43707542, 0x00000000, 0x00000000,
4894 0x00000000
4895};
4896
4897#if 0 /* All zeros, don't eat up space with it. */
4898u32 tg3FwData[(TG3_FW_DATA_LEN / sizeof(u32)) + 1] = {
4899 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
4900 0x00000000, 0x00000000, 0x00000000, 0x00000000
4901};
4902#endif
4903
4904#define RX_CPU_SCRATCH_BASE 0x30000
4905#define RX_CPU_SCRATCH_SIZE 0x04000
4906#define TX_CPU_SCRATCH_BASE 0x34000
4907#define TX_CPU_SCRATCH_SIZE 0x04000
4908
4909/* tp->lock is held. */
4910static int tg3_halt_cpu(struct tg3 *tp, u32 offset)
4911{
4912 int i;
4913
4914 if (offset == TX_CPU_BASE &&
4915 (tp->tg3_flags2 & TG3_FLG2_5705_PLUS))
4916 BUG();
4917
4918 if (offset == RX_CPU_BASE) {
4919 for (i = 0; i < 10000; i++) {
4920 tw32(offset + CPU_STATE, 0xffffffff);
4921 tw32(offset + CPU_MODE, CPU_MODE_HALT);
4922 if (tr32(offset + CPU_MODE) & CPU_MODE_HALT)
4923 break;
4924 }
4925
4926 tw32(offset + CPU_STATE, 0xffffffff);
4927 tw32_f(offset + CPU_MODE, CPU_MODE_HALT);
4928 udelay(10);
4929 } else {
4930 for (i = 0; i < 10000; i++) {
4931 tw32(offset + CPU_STATE, 0xffffffff);
4932 tw32(offset + CPU_MODE, CPU_MODE_HALT);
4933 if (tr32(offset + CPU_MODE) & CPU_MODE_HALT)
4934 break;
4935 }
4936 }
4937
4938 if (i >= 10000) {
4939 printk(KERN_ERR PFX "tg3_reset_cpu timed out for %s, "
4940 "and %s CPU\n",
4941 tp->dev->name,
4942 (offset == RX_CPU_BASE ? "RX" : "TX"));
4943 return -ENODEV;
4944 }
ec41c7df
MC
4945
4946 /* Clear firmware's nvram arbitration. */
4947 if (tp->tg3_flags & TG3_FLAG_NVRAM)
4948 tw32(NVRAM_SWARB, SWARB_REQ_CLR0);
1da177e4
LT
4949 return 0;
4950}
4951
4952struct fw_info {
4953 unsigned int text_base;
4954 unsigned int text_len;
4955 u32 *text_data;
4956 unsigned int rodata_base;
4957 unsigned int rodata_len;
4958 u32 *rodata_data;
4959 unsigned int data_base;
4960 unsigned int data_len;
4961 u32 *data_data;
4962};
4963
4964/* tp->lock is held. */
4965static int tg3_load_firmware_cpu(struct tg3 *tp, u32 cpu_base, u32 cpu_scratch_base,
4966 int cpu_scratch_size, struct fw_info *info)
4967{
ec41c7df 4968 int err, lock_err, i;
1da177e4
LT
4969 void (*write_op)(struct tg3 *, u32, u32);
4970
4971 if (cpu_base == TX_CPU_BASE &&
4972 (tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
4973 printk(KERN_ERR PFX "tg3_load_firmware_cpu: Trying to load "
4974 "TX cpu firmware on %s which is 5705.\n",
4975 tp->dev->name);
4976 return -EINVAL;
4977 }
4978
4979 if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS)
4980 write_op = tg3_write_mem;
4981 else
4982 write_op = tg3_write_indirect_reg32;
4983
1b628151
MC
4984 /* It is possible that bootcode is still loading at this point.
4985 * Get the nvram lock first before halting the cpu.
4986 */
ec41c7df 4987 lock_err = tg3_nvram_lock(tp);
1da177e4 4988 err = tg3_halt_cpu(tp, cpu_base);
ec41c7df
MC
4989 if (!lock_err)
4990 tg3_nvram_unlock(tp);
1da177e4
LT
4991 if (err)
4992 goto out;
4993
4994 for (i = 0; i < cpu_scratch_size; i += sizeof(u32))
4995 write_op(tp, cpu_scratch_base + i, 0);
4996 tw32(cpu_base + CPU_STATE, 0xffffffff);
4997 tw32(cpu_base + CPU_MODE, tr32(cpu_base+CPU_MODE)|CPU_MODE_HALT);
4998 for (i = 0; i < (info->text_len / sizeof(u32)); i++)
4999 write_op(tp, (cpu_scratch_base +
5000 (info->text_base & 0xffff) +
5001 (i * sizeof(u32))),
5002 (info->text_data ?
5003 info->text_data[i] : 0));
5004 for (i = 0; i < (info->rodata_len / sizeof(u32)); i++)
5005 write_op(tp, (cpu_scratch_base +
5006 (info->rodata_base & 0xffff) +
5007 (i * sizeof(u32))),
5008 (info->rodata_data ?
5009 info->rodata_data[i] : 0));
5010 for (i = 0; i < (info->data_len / sizeof(u32)); i++)
5011 write_op(tp, (cpu_scratch_base +
5012 (info->data_base & 0xffff) +
5013 (i * sizeof(u32))),
5014 (info->data_data ?
5015 info->data_data[i] : 0));
5016
5017 err = 0;
5018
5019out:
1da177e4
LT
5020 return err;
5021}
5022
5023/* tp->lock is held. */
5024static int tg3_load_5701_a0_firmware_fix(struct tg3 *tp)
5025{
5026 struct fw_info info;
5027 int err, i;
5028
5029 info.text_base = TG3_FW_TEXT_ADDR;
5030 info.text_len = TG3_FW_TEXT_LEN;
5031 info.text_data = &tg3FwText[0];
5032 info.rodata_base = TG3_FW_RODATA_ADDR;
5033 info.rodata_len = TG3_FW_RODATA_LEN;
5034 info.rodata_data = &tg3FwRodata[0];
5035 info.data_base = TG3_FW_DATA_ADDR;
5036 info.data_len = TG3_FW_DATA_LEN;
5037 info.data_data = NULL;
5038
5039 err = tg3_load_firmware_cpu(tp, RX_CPU_BASE,
5040 RX_CPU_SCRATCH_BASE, RX_CPU_SCRATCH_SIZE,
5041 &info);
5042 if (err)
5043 return err;
5044
5045 err = tg3_load_firmware_cpu(tp, TX_CPU_BASE,
5046 TX_CPU_SCRATCH_BASE, TX_CPU_SCRATCH_SIZE,
5047 &info);
5048 if (err)
5049 return err;
5050
5051 /* Now startup only the RX cpu. */
5052 tw32(RX_CPU_BASE + CPU_STATE, 0xffffffff);
5053 tw32_f(RX_CPU_BASE + CPU_PC, TG3_FW_TEXT_ADDR);
5054
5055 for (i = 0; i < 5; i++) {
5056 if (tr32(RX_CPU_BASE + CPU_PC) == TG3_FW_TEXT_ADDR)
5057 break;
5058 tw32(RX_CPU_BASE + CPU_STATE, 0xffffffff);
5059 tw32(RX_CPU_BASE + CPU_MODE, CPU_MODE_HALT);
5060 tw32_f(RX_CPU_BASE + CPU_PC, TG3_FW_TEXT_ADDR);
5061 udelay(1000);
5062 }
5063 if (i >= 5) {
5064 printk(KERN_ERR PFX "tg3_load_firmware fails for %s "
5065 "to set RX CPU PC, is %08x should be %08x\n",
5066 tp->dev->name, tr32(RX_CPU_BASE + CPU_PC),
5067 TG3_FW_TEXT_ADDR);
5068 return -ENODEV;
5069 }
5070 tw32(RX_CPU_BASE + CPU_STATE, 0xffffffff);
5071 tw32_f(RX_CPU_BASE + CPU_MODE, 0x00000000);
5072
5073 return 0;
5074}
5075
5076#if TG3_TSO_SUPPORT != 0
5077
5078#define TG3_TSO_FW_RELEASE_MAJOR 0x1
5079#define TG3_TSO_FW_RELASE_MINOR 0x6
5080#define TG3_TSO_FW_RELEASE_FIX 0x0
5081#define TG3_TSO_FW_START_ADDR 0x08000000
5082#define TG3_TSO_FW_TEXT_ADDR 0x08000000
5083#define TG3_TSO_FW_TEXT_LEN 0x1aa0
5084#define TG3_TSO_FW_RODATA_ADDR 0x08001aa0
5085#define TG3_TSO_FW_RODATA_LEN 0x60
5086#define TG3_TSO_FW_DATA_ADDR 0x08001b20
5087#define TG3_TSO_FW_DATA_LEN 0x30
5088#define TG3_TSO_FW_SBSS_ADDR 0x08001b50
5089#define TG3_TSO_FW_SBSS_LEN 0x2c
5090#define TG3_TSO_FW_BSS_ADDR 0x08001b80
5091#define TG3_TSO_FW_BSS_LEN 0x894
5092
5093static u32 tg3TsoFwText[(TG3_TSO_FW_TEXT_LEN / 4) + 1] = {
5094 0x0e000003, 0x00000000, 0x08001b24, 0x00000000, 0x10000003, 0x00000000,
5095 0x0000000d, 0x0000000d, 0x3c1d0800, 0x37bd4000, 0x03a0f021, 0x3c100800,
5096 0x26100000, 0x0e000010, 0x00000000, 0x0000000d, 0x27bdffe0, 0x3c04fefe,
5097 0xafbf0018, 0x0e0005d8, 0x34840002, 0x0e000668, 0x00000000, 0x3c030800,
5098 0x90631b68, 0x24020002, 0x3c040800, 0x24841aac, 0x14620003, 0x24050001,
5099 0x3c040800, 0x24841aa0, 0x24060006, 0x00003821, 0xafa00010, 0x0e00067c,
5100 0xafa00014, 0x8f625c50, 0x34420001, 0xaf625c50, 0x8f625c90, 0x34420001,
5101 0xaf625c90, 0x2402ffff, 0x0e000034, 0xaf625404, 0x8fbf0018, 0x03e00008,
5102 0x27bd0020, 0x00000000, 0x00000000, 0x00000000, 0x27bdffe0, 0xafbf001c,
5103 0xafb20018, 0xafb10014, 0x0e00005b, 0xafb00010, 0x24120002, 0x24110001,
5104 0x8f706820, 0x32020100, 0x10400003, 0x00000000, 0x0e0000bb, 0x00000000,
5105 0x8f706820, 0x32022000, 0x10400004, 0x32020001, 0x0e0001f0, 0x24040001,
5106 0x32020001, 0x10400003, 0x00000000, 0x0e0000a3, 0x00000000, 0x3c020800,
5107 0x90421b98, 0x14520003, 0x00000000, 0x0e0004c0, 0x00000000, 0x0a00003c,
5108 0xaf715028, 0x8fbf001c, 0x8fb20018, 0x8fb10014, 0x8fb00010, 0x03e00008,
5109 0x27bd0020, 0x27bdffe0, 0x3c040800, 0x24841ac0, 0x00002821, 0x00003021,
5110 0x00003821, 0xafbf0018, 0xafa00010, 0x0e00067c, 0xafa00014, 0x3c040800,
5111 0x248423d8, 0xa4800000, 0x3c010800, 0xa0201b98, 0x3c010800, 0xac201b9c,
5112 0x3c010800, 0xac201ba0, 0x3c010800, 0xac201ba4, 0x3c010800, 0xac201bac,
5113 0x3c010800, 0xac201bb8, 0x3c010800, 0xac201bbc, 0x8f624434, 0x3c010800,
5114 0xac221b88, 0x8f624438, 0x3c010800, 0xac221b8c, 0x8f624410, 0xac80f7a8,
5115 0x3c010800, 0xac201b84, 0x3c010800, 0xac2023e0, 0x3c010800, 0xac2023c8,
5116 0x3c010800, 0xac2023cc, 0x3c010800, 0xac202400, 0x3c010800, 0xac221b90,
5117 0x8f620068, 0x24030007, 0x00021702, 0x10430005, 0x00000000, 0x8f620068,
5118 0x00021702, 0x14400004, 0x24020001, 0x3c010800, 0x0a000097, 0xac20240c,
5119 0xac820034, 0x3c040800, 0x24841acc, 0x3c050800, 0x8ca5240c, 0x00003021,
5120 0x00003821, 0xafa00010, 0x0e00067c, 0xafa00014, 0x8fbf0018, 0x03e00008,
5121 0x27bd0020, 0x27bdffe0, 0x3c040800, 0x24841ad8, 0x00002821, 0x00003021,
5122 0x00003821, 0xafbf0018, 0xafa00010, 0x0e00067c, 0xafa00014, 0x0e00005b,
5123 0x00000000, 0x0e0000b4, 0x00002021, 0x8fbf0018, 0x03e00008, 0x27bd0020,
5124 0x24020001, 0x8f636820, 0x00821004, 0x00021027, 0x00621824, 0x03e00008,
5125 0xaf636820, 0x27bdffd0, 0xafbf002c, 0xafb60028, 0xafb50024, 0xafb40020,
5126 0xafb3001c, 0xafb20018, 0xafb10014, 0xafb00010, 0x8f675c5c, 0x3c030800,
5127 0x24631bbc, 0x8c620000, 0x14470005, 0x3c0200ff, 0x3c020800, 0x90421b98,
5128 0x14400119, 0x3c0200ff, 0x3442fff8, 0x00e28824, 0xac670000, 0x00111902,
5129 0x306300ff, 0x30e20003, 0x000211c0, 0x00622825, 0x00a04021, 0x00071602,
5130 0x3c030800, 0x90631b98, 0x3044000f, 0x14600036, 0x00804821, 0x24020001,
5131 0x3c010800, 0xa0221b98, 0x00051100, 0x00821025, 0x3c010800, 0xac201b9c,
5132 0x3c010800, 0xac201ba0, 0x3c010800, 0xac201ba4, 0x3c010800, 0xac201bac,
5133 0x3c010800, 0xac201bb8, 0x3c010800, 0xac201bb0, 0x3c010800, 0xac201bb4,
5134 0x3c010800, 0xa42223d8, 0x9622000c, 0x30437fff, 0x3c010800, 0xa4222410,
5135 0x30428000, 0x3c010800, 0xa4231bc6, 0x10400005, 0x24020001, 0x3c010800,
5136 0xac2223f4, 0x0a000102, 0x2406003e, 0x24060036, 0x3c010800, 0xac2023f4,
5137 0x9622000a, 0x3c030800, 0x94631bc6, 0x3c010800, 0xac2023f0, 0x3c010800,
5138 0xac2023f8, 0x00021302, 0x00021080, 0x00c21021, 0x00621821, 0x3c010800,
5139 0xa42223d0, 0x3c010800, 0x0a000115, 0xa4231b96, 0x9622000c, 0x3c010800,
5140 0xa42223ec, 0x3c040800, 0x24841b9c, 0x8c820000, 0x00021100, 0x3c010800,
5141 0x00220821, 0xac311bc8, 0x8c820000, 0x00021100, 0x3c010800, 0x00220821,
5142 0xac271bcc, 0x8c820000, 0x25030001, 0x306601ff, 0x00021100, 0x3c010800,
5143 0x00220821, 0xac261bd0, 0x8c820000, 0x00021100, 0x3c010800, 0x00220821,
5144 0xac291bd4, 0x96230008, 0x3c020800, 0x8c421bac, 0x00432821, 0x3c010800,
5145 0xac251bac, 0x9622000a, 0x30420004, 0x14400018, 0x00061100, 0x8f630c14,
5146 0x3063000f, 0x2c620002, 0x1440000b, 0x3c02c000, 0x8f630c14, 0x3c020800,
5147 0x8c421b40, 0x3063000f, 0x24420001, 0x3c010800, 0xac221b40, 0x2c620002,
5148 0x1040fff7, 0x3c02c000, 0x00e21825, 0xaf635c5c, 0x8f625c50, 0x30420002,
5149 0x10400014, 0x00000000, 0x0a000147, 0x00000000, 0x3c030800, 0x8c631b80,
5150 0x3c040800, 0x94841b94, 0x01221025, 0x3c010800, 0xa42223da, 0x24020001,
5151 0x3c010800, 0xac221bb8, 0x24630001, 0x0085202a, 0x3c010800, 0x10800003,
5152 0xac231b80, 0x3c010800, 0xa4251b94, 0x3c060800, 0x24c61b9c, 0x8cc20000,
5153 0x24420001, 0xacc20000, 0x28420080, 0x14400005, 0x00000000, 0x0e000656,
5154 0x24040002, 0x0a0001e6, 0x00000000, 0x3c020800, 0x8c421bb8, 0x10400078,
5155 0x24020001, 0x3c050800, 0x90a51b98, 0x14a20072, 0x00000000, 0x3c150800,
5156 0x96b51b96, 0x3c040800, 0x8c841bac, 0x32a3ffff, 0x0083102a, 0x1440006c,
5157 0x00000000, 0x14830003, 0x00000000, 0x3c010800, 0xac2523f0, 0x1060005c,
5158 0x00009021, 0x24d60004, 0x0060a021, 0x24d30014, 0x8ec20000, 0x00028100,
5159 0x3c110800, 0x02308821, 0x0e000625, 0x8e311bc8, 0x00402821, 0x10a00054,
5160 0x00000000, 0x9628000a, 0x31020040, 0x10400005, 0x2407180c, 0x8e22000c,
5161 0x2407188c, 0x00021400, 0xaca20018, 0x3c030800, 0x00701821, 0x8c631bd0,
5162 0x3c020800, 0x00501021, 0x8c421bd4, 0x00031d00, 0x00021400, 0x00621825,
5163 0xaca30014, 0x8ec30004, 0x96220008, 0x00432023, 0x3242ffff, 0x3083ffff,
5164 0x00431021, 0x0282102a, 0x14400002, 0x02b23023, 0x00803021, 0x8e620000,
5165 0x30c4ffff, 0x00441021, 0xae620000, 0x8e220000, 0xaca20000, 0x8e220004,
5166 0x8e63fff4, 0x00431021, 0xaca20004, 0xa4a6000e, 0x8e62fff4, 0x00441021,
5167 0xae62fff4, 0x96230008, 0x0043102a, 0x14400005, 0x02469021, 0x8e62fff0,
5168 0xae60fff4, 0x24420001, 0xae62fff0, 0xaca00008, 0x3242ffff, 0x14540008,
5169 0x24020305, 0x31020080, 0x54400001, 0x34e70010, 0x24020905, 0xa4a2000c,
5170 0x0a0001cb, 0x34e70020, 0xa4a2000c, 0x3c020800, 0x8c4223f0, 0x10400003,
5171 0x3c024b65, 0x0a0001d3, 0x34427654, 0x3c02b49a, 0x344289ab, 0xaca2001c,
5172 0x30e2ffff, 0xaca20010, 0x0e0005a2, 0x00a02021, 0x3242ffff, 0x0054102b,
5173 0x1440ffa9, 0x00000000, 0x24020002, 0x3c010800, 0x0a0001e6, 0xa0221b98,
5174 0x8ec2083c, 0x24420001, 0x0a0001e6, 0xaec2083c, 0x0e0004c0, 0x00000000,
5175 0x8fbf002c, 0x8fb60028, 0x8fb50024, 0x8fb40020, 0x8fb3001c, 0x8fb20018,
5176 0x8fb10014, 0x8fb00010, 0x03e00008, 0x27bd0030, 0x27bdffd0, 0xafbf0028,
5177 0xafb30024, 0xafb20020, 0xafb1001c, 0xafb00018, 0x8f725c9c, 0x3c0200ff,
5178 0x3442fff8, 0x3c070800, 0x24e71bb4, 0x02428824, 0x9623000e, 0x8ce20000,
5179 0x00431021, 0xace20000, 0x8e220010, 0x30420020, 0x14400011, 0x00809821,
5180 0x0e00063b, 0x02202021, 0x3c02c000, 0x02421825, 0xaf635c9c, 0x8f625c90,
5181 0x30420002, 0x1040011e, 0x00000000, 0xaf635c9c, 0x8f625c90, 0x30420002,
5182 0x10400119, 0x00000000, 0x0a00020d, 0x00000000, 0x8e240008, 0x8e230014,
5183 0x00041402, 0x000231c0, 0x00031502, 0x304201ff, 0x2442ffff, 0x3042007f,
5184 0x00031942, 0x30637800, 0x00021100, 0x24424000, 0x00624821, 0x9522000a,
5185 0x3084ffff, 0x30420008, 0x104000b0, 0x000429c0, 0x3c020800, 0x8c422400,
5186 0x14400024, 0x24c50008, 0x94c20014, 0x3c010800, 0xa42223d0, 0x8cc40010,
5187 0x00041402, 0x3c010800, 0xa42223d2, 0x3c010800, 0xa42423d4, 0x94c2000e,
5188 0x3083ffff, 0x00431023, 0x3c010800, 0xac222408, 0x94c2001a, 0x3c010800,
5189 0xac262400, 0x3c010800, 0xac322404, 0x3c010800, 0xac2223fc, 0x3c02c000,
5190 0x02421825, 0xaf635c9c, 0x8f625c90, 0x30420002, 0x104000e5, 0x00000000,
5191 0xaf635c9c, 0x8f625c90, 0x30420002, 0x104000e0, 0x00000000, 0x0a000246,
5192 0x00000000, 0x94c2000e, 0x3c030800, 0x946323d4, 0x00434023, 0x3103ffff,
5193 0x2c620008, 0x1040001c, 0x00000000, 0x94c20014, 0x24420028, 0x00a22821,
5194 0x00031042, 0x1840000b, 0x00002021, 0x24e60848, 0x00403821, 0x94a30000,
5195 0x8cc20000, 0x24840001, 0x00431021, 0xacc20000, 0x0087102a, 0x1440fff9,
5196 0x24a50002, 0x31020001, 0x1040001f, 0x3c024000, 0x3c040800, 0x248423fc,
5197 0xa0a00001, 0x94a30000, 0x8c820000, 0x00431021, 0x0a000285, 0xac820000,
5198 0x8f626800, 0x3c030010, 0x00431024, 0x10400009, 0x00000000, 0x94c2001a,
5199 0x3c030800, 0x8c6323fc, 0x00431021, 0x3c010800, 0xac2223fc, 0x0a000286,
5200 0x3c024000, 0x94c2001a, 0x94c4001c, 0x3c030800, 0x8c6323fc, 0x00441023,
5201 0x00621821, 0x3c010800, 0xac2323fc, 0x3c024000, 0x02421825, 0xaf635c9c,
5202 0x8f625c90, 0x30420002, 0x1440fffc, 0x00000000, 0x9522000a, 0x30420010,
5203 0x1040009b, 0x00000000, 0x3c030800, 0x946323d4, 0x3c070800, 0x24e72400,
5204 0x8ce40000, 0x8f626800, 0x24630030, 0x00832821, 0x3c030010, 0x00431024,
5205 0x1440000a, 0x00000000, 0x94a20004, 0x3c040800, 0x8c842408, 0x3c030800,
5206 0x8c6323fc, 0x00441023, 0x00621821, 0x3c010800, 0xac2323fc, 0x3c040800,
5207 0x8c8423fc, 0x00041c02, 0x3082ffff, 0x00622021, 0x00041402, 0x00822021,
5208 0x00041027, 0xa4a20006, 0x3c030800, 0x8c632404, 0x3c0200ff, 0x3442fff8,
5209 0x00628824, 0x96220008, 0x24050001, 0x24034000, 0x000231c0, 0x00801021,
5210 0xa4c2001a, 0xa4c0001c, 0xace00000, 0x3c010800, 0xac251b60, 0xaf635cb8,
5211 0x8f625cb0, 0x30420002, 0x10400003, 0x00000000, 0x3c010800, 0xac201b60,
5212 0x8e220008, 0xaf625cb8, 0x8f625cb0, 0x30420002, 0x10400003, 0x00000000,
5213 0x3c010800, 0xac201b60, 0x3c020800, 0x8c421b60, 0x1040ffec, 0x00000000,
5214 0x3c040800, 0x0e00063b, 0x8c842404, 0x0a00032a, 0x00000000, 0x3c030800,
5215 0x90631b98, 0x24020002, 0x14620003, 0x3c034b65, 0x0a0002e1, 0x00008021,
5216 0x8e22001c, 0x34637654, 0x10430002, 0x24100002, 0x24100001, 0x00c02021,
5217 0x0e000350, 0x02003021, 0x24020003, 0x3c010800, 0xa0221b98, 0x24020002,
5218 0x1202000a, 0x24020001, 0x3c030800, 0x8c6323f0, 0x10620006, 0x00000000,
5219 0x3c020800, 0x944223d8, 0x00021400, 0x0a00031f, 0xae220014, 0x3c040800,
5220 0x248423da, 0x94820000, 0x00021400, 0xae220014, 0x3c020800, 0x8c421bbc,
5221 0x3c03c000, 0x3c010800, 0xa0201b98, 0x00431025, 0xaf625c5c, 0x8f625c50,
5222 0x30420002, 0x10400009, 0x00000000, 0x2484f7e2, 0x8c820000, 0x00431025,
5223 0xaf625c5c, 0x8f625c50, 0x30420002, 0x1440fffa, 0x00000000, 0x3c020800,
5224 0x24421b84, 0x8c430000, 0x24630001, 0xac430000, 0x8f630c14, 0x3063000f,
5225 0x2c620002, 0x1440000c, 0x3c024000, 0x8f630c14, 0x3c020800, 0x8c421b40,
5226 0x3063000f, 0x24420001, 0x3c010800, 0xac221b40, 0x2c620002, 0x1040fff7,
5227 0x00000000, 0x3c024000, 0x02421825, 0xaf635c9c, 0x8f625c90, 0x30420002,
5228 0x1440fffc, 0x00000000, 0x12600003, 0x00000000, 0x0e0004c0, 0x00000000,
5229 0x8fbf0028, 0x8fb30024, 0x8fb20020, 0x8fb1001c, 0x8fb00018, 0x03e00008,
5230 0x27bd0030, 0x8f634450, 0x3c040800, 0x24841b88, 0x8c820000, 0x00031c02,
5231 0x0043102b, 0x14400007, 0x3c038000, 0x8c840004, 0x8f624450, 0x00021c02,
5232 0x0083102b, 0x1040fffc, 0x3c038000, 0xaf634444, 0x8f624444, 0x00431024,
5233 0x1440fffd, 0x00000000, 0x8f624448, 0x03e00008, 0x3042ffff, 0x3c024000,
5234 0x00822025, 0xaf645c38, 0x8f625c30, 0x30420002, 0x1440fffc, 0x00000000,
5235 0x03e00008, 0x00000000, 0x27bdffe0, 0x00805821, 0x14c00011, 0x256e0008,
5236 0x3c020800, 0x8c4223f4, 0x10400007, 0x24020016, 0x3c010800, 0xa42223d2,
5237 0x2402002a, 0x3c010800, 0x0a000364, 0xa42223d4, 0x8d670010, 0x00071402,
5238 0x3c010800, 0xa42223d2, 0x3c010800, 0xa42723d4, 0x3c040800, 0x948423d4,
5239 0x3c030800, 0x946323d2, 0x95cf0006, 0x3c020800, 0x944223d0, 0x00832023,
5240 0x01e2c023, 0x3065ffff, 0x24a20028, 0x01c24821, 0x3082ffff, 0x14c0001a,
5241 0x01226021, 0x9582000c, 0x3042003f, 0x3c010800, 0xa42223d6, 0x95820004,
5242 0x95830006, 0x3c010800, 0xac2023e4, 0x3c010800, 0xac2023e8, 0x00021400,
5243 0x00431025, 0x3c010800, 0xac221bc0, 0x95220004, 0x3c010800, 0xa4221bc4,
5244 0x95230002, 0x01e51023, 0x0043102a, 0x10400010, 0x24020001, 0x3c010800,
5245 0x0a000398, 0xac2223f8, 0x3c030800, 0x8c6323e8, 0x3c020800, 0x94421bc4,
5246 0x00431021, 0xa5220004, 0x3c020800, 0x94421bc0, 0xa5820004, 0x3c020800,
5247 0x8c421bc0, 0xa5820006, 0x3c020800, 0x8c4223f0, 0x3c0d0800, 0x8dad23e4,
5248 0x3c0a0800, 0x144000e5, 0x8d4a23e8, 0x3c020800, 0x94421bc4, 0x004a1821,
5249 0x3063ffff, 0x0062182b, 0x24020002, 0x10c2000d, 0x01435023, 0x3c020800,
5250 0x944223d6, 0x30420009, 0x10400008, 0x00000000, 0x9582000c, 0x3042fff6,
5251 0xa582000c, 0x3c020800, 0x944223d6, 0x30420009, 0x01a26823, 0x3c020800,
5252 0x8c4223f8, 0x1040004a, 0x01203821, 0x3c020800, 0x944223d2, 0x00004021,
5253 0xa520000a, 0x01e21023, 0xa5220002, 0x3082ffff, 0x00021042, 0x18400008,
5254 0x00003021, 0x00401821, 0x94e20000, 0x25080001, 0x00c23021, 0x0103102a,
5255 0x1440fffb, 0x24e70002, 0x00061c02, 0x30c2ffff, 0x00623021, 0x00061402,
5256 0x00c23021, 0x00c02821, 0x00061027, 0xa522000a, 0x00003021, 0x2527000c,
5257 0x00004021, 0x94e20000, 0x25080001, 0x00c23021, 0x2d020004, 0x1440fffb,
5258 0x24e70002, 0x95220002, 0x00004021, 0x91230009, 0x00442023, 0x01803821,
5259 0x3082ffff, 0xa4e00010, 0x00621821, 0x00021042, 0x18400010, 0x00c33021,
5260 0x00404821, 0x94e20000, 0x24e70002, 0x00c23021, 0x30e2007f, 0x14400006,
5261 0x25080001, 0x8d630000, 0x3c02007f, 0x3442ff80, 0x00625824, 0x25670008,
5262 0x0109102a, 0x1440fff3, 0x00000000, 0x30820001, 0x10400005, 0x00061c02,
5263 0xa0e00001, 0x94e20000, 0x00c23021, 0x00061c02, 0x30c2ffff, 0x00623021,
5264 0x00061402, 0x00c23021, 0x0a00047d, 0x30c6ffff, 0x24020002, 0x14c20081,
5265 0x00000000, 0x3c020800, 0x8c42240c, 0x14400007, 0x00000000, 0x3c020800,
5266 0x944223d2, 0x95230002, 0x01e21023, 0x10620077, 0x00000000, 0x3c020800,
5267 0x944223d2, 0x01e21023, 0xa5220002, 0x3c020800, 0x8c42240c, 0x1040001a,
5268 0x31e3ffff, 0x8dc70010, 0x3c020800, 0x94421b96, 0x00e04021, 0x00072c02,
5269 0x00aa2021, 0x00431023, 0x00823823, 0x00072402, 0x30e2ffff, 0x00823821,
5270 0x00071027, 0xa522000a, 0x3102ffff, 0x3c040800, 0x948423d4, 0x00453023,
5271 0x00e02821, 0x00641823, 0x006d1821, 0x00c33021, 0x00061c02, 0x30c2ffff,
5272 0x0a00047d, 0x00623021, 0x01203821, 0x00004021, 0x3082ffff, 0x00021042,
5273 0x18400008, 0x00003021, 0x00401821, 0x94e20000, 0x25080001, 0x00c23021,
5274 0x0103102a, 0x1440fffb, 0x24e70002, 0x00061c02, 0x30c2ffff, 0x00623021,
5275 0x00061402, 0x00c23021, 0x00c02821, 0x00061027, 0xa522000a, 0x00003021,
5276 0x2527000c, 0x00004021, 0x94e20000, 0x25080001, 0x00c23021, 0x2d020004,
5277 0x1440fffb, 0x24e70002, 0x95220002, 0x00004021, 0x91230009, 0x00442023,
5278 0x01803821, 0x3082ffff, 0xa4e00010, 0x3c040800, 0x948423d4, 0x00621821,
5279 0x00c33021, 0x00061c02, 0x30c2ffff, 0x00623021, 0x00061c02, 0x3c020800,
5280 0x944223d0, 0x00c34821, 0x00441023, 0x00021fc2, 0x00431021, 0x00021043,
5281 0x18400010, 0x00003021, 0x00402021, 0x94e20000, 0x24e70002, 0x00c23021,
5282 0x30e2007f, 0x14400006, 0x25080001, 0x8d630000, 0x3c02007f, 0x3442ff80,
5283 0x00625824, 0x25670008, 0x0104102a, 0x1440fff3, 0x00000000, 0x3c020800,
5284 0x944223ec, 0x00c23021, 0x3122ffff, 0x00c23021, 0x00061c02, 0x30c2ffff,
5285 0x00623021, 0x00061402, 0x00c23021, 0x00c04021, 0x00061027, 0xa5820010,
5286 0xadc00014, 0x0a00049d, 0xadc00000, 0x8dc70010, 0x00e04021, 0x11400007,
5287 0x00072c02, 0x00aa3021, 0x00061402, 0x30c3ffff, 0x00433021, 0x00061402,
5288 0x00c22821, 0x00051027, 0xa522000a, 0x3c030800, 0x946323d4, 0x3102ffff,
5289 0x01e21021, 0x00433023, 0x00cd3021, 0x00061c02, 0x30c2ffff, 0x00623021,
5290 0x00061402, 0x00c23021, 0x00c04021, 0x00061027, 0xa5820010, 0x3102ffff,
5291 0x00051c00, 0x00431025, 0xadc20010, 0x3c020800, 0x8c4223f4, 0x10400005,
5292 0x2de205eb, 0x14400002, 0x25e2fff2, 0x34028870, 0xa5c20034, 0x3c030800,
5293 0x246323e8, 0x8c620000, 0x24420001, 0xac620000, 0x3c040800, 0x8c8423e4,
5294 0x3c020800, 0x8c421bc0, 0x3303ffff, 0x00832021, 0x00431821, 0x0062102b,
5295 0x3c010800, 0xac2423e4, 0x10400003, 0x2482ffff, 0x3c010800, 0xac2223e4,
5296 0x3c010800, 0xac231bc0, 0x03e00008, 0x27bd0020, 0x27bdffb8, 0x3c050800,
5297 0x24a51b96, 0xafbf0044, 0xafbe0040, 0xafb7003c, 0xafb60038, 0xafb50034,
5298 0xafb40030, 0xafb3002c, 0xafb20028, 0xafb10024, 0xafb00020, 0x94a90000,
5299 0x3c020800, 0x944223d0, 0x3c030800, 0x8c631bb0, 0x3c040800, 0x8c841bac,
5300 0x01221023, 0x0064182a, 0xa7a9001e, 0x106000be, 0xa7a20016, 0x24be0022,
5301 0x97b6001e, 0x24b3001a, 0x24b70016, 0x8fc20000, 0x14400008, 0x00000000,
5302 0x8fc2fff8, 0x97a30016, 0x8fc4fff4, 0x00431021, 0x0082202a, 0x148000b0,
5303 0x00000000, 0x97d50818, 0x32a2ffff, 0x104000a3, 0x00009021, 0x0040a021,
5304 0x00008821, 0x0e000625, 0x00000000, 0x00403021, 0x14c00007, 0x00000000,
5305 0x3c020800, 0x8c4223dc, 0x24420001, 0x3c010800, 0x0a000596, 0xac2223dc,
5306 0x3c100800, 0x02118021, 0x8e101bc8, 0x9608000a, 0x31020040, 0x10400005,
5307 0x2407180c, 0x8e02000c, 0x2407188c, 0x00021400, 0xacc20018, 0x31020080,
5308 0x54400001, 0x34e70010, 0x3c020800, 0x00511021, 0x8c421bd0, 0x3c030800,
5309 0x00711821, 0x8c631bd4, 0x00021500, 0x00031c00, 0x00431025, 0xacc20014,
5310 0x96040008, 0x3242ffff, 0x00821021, 0x0282102a, 0x14400002, 0x02b22823,
5311 0x00802821, 0x8e020000, 0x02459021, 0xacc20000, 0x8e020004, 0x00c02021,
5312 0x26310010, 0xac820004, 0x30e2ffff, 0xac800008, 0xa485000e, 0xac820010,
5313 0x24020305, 0x0e0005a2, 0xa482000c, 0x3242ffff, 0x0054102b, 0x1440ffc5,
5314 0x3242ffff, 0x0a00058e, 0x00000000, 0x8e620000, 0x8e63fffc, 0x0043102a,
5315 0x10400067, 0x00000000, 0x8e62fff0, 0x00028900, 0x3c100800, 0x02118021,
5316 0x0e000625, 0x8e101bc8, 0x00403021, 0x14c00005, 0x00000000, 0x8e62082c,
5317 0x24420001, 0x0a000596, 0xae62082c, 0x9608000a, 0x31020040, 0x10400005,
5318 0x2407180c, 0x8e02000c, 0x2407188c, 0x00021400, 0xacc20018, 0x3c020800,
5319 0x00511021, 0x8c421bd0, 0x3c030800, 0x00711821, 0x8c631bd4, 0x00021500,
5320 0x00031c00, 0x00431025, 0xacc20014, 0x8e63fff4, 0x96020008, 0x00432023,
5321 0x3242ffff, 0x3083ffff, 0x00431021, 0x02c2102a, 0x10400003, 0x00802821,
5322 0x97a9001e, 0x01322823, 0x8e620000, 0x30a4ffff, 0x00441021, 0xae620000,
5323 0xa4c5000e, 0x8e020000, 0xacc20000, 0x8e020004, 0x8e63fff4, 0x00431021,
5324 0xacc20004, 0x8e63fff4, 0x96020008, 0x00641821, 0x0062102a, 0x14400006,
5325 0x02459021, 0x8e62fff0, 0xae60fff4, 0x24420001, 0x0a000571, 0xae62fff0,
5326 0xae63fff4, 0xacc00008, 0x3242ffff, 0x10560003, 0x31020004, 0x10400006,
5327 0x24020305, 0x31020080, 0x54400001, 0x34e70010, 0x34e70020, 0x24020905,
5328 0xa4c2000c, 0x8ee30000, 0x8ee20004, 0x14620007, 0x3c02b49a, 0x8ee20860,
5329 0x54400001, 0x34e70400, 0x3c024b65, 0x0a000588, 0x34427654, 0x344289ab,
5330 0xacc2001c, 0x30e2ffff, 0xacc20010, 0x0e0005a2, 0x00c02021, 0x3242ffff,
5331 0x0056102b, 0x1440ff9b, 0x00000000, 0x8e620000, 0x8e63fffc, 0x0043102a,
5332 0x1440ff48, 0x00000000, 0x8fbf0044, 0x8fbe0040, 0x8fb7003c, 0x8fb60038,
5333 0x8fb50034, 0x8fb40030, 0x8fb3002c, 0x8fb20028, 0x8fb10024, 0x8fb00020,
5334 0x03e00008, 0x27bd0048, 0x27bdffe8, 0xafbf0014, 0xafb00010, 0x8f624450,
5335 0x8f634410, 0x0a0005b1, 0x00808021, 0x8f626820, 0x30422000, 0x10400003,
5336 0x00000000, 0x0e0001f0, 0x00002021, 0x8f624450, 0x8f634410, 0x3042ffff,
5337 0x0043102b, 0x1440fff5, 0x00000000, 0x8f630c14, 0x3063000f, 0x2c620002,
5338 0x1440000b, 0x00000000, 0x8f630c14, 0x3c020800, 0x8c421b40, 0x3063000f,
5339 0x24420001, 0x3c010800, 0xac221b40, 0x2c620002, 0x1040fff7, 0x00000000,
5340 0xaf705c18, 0x8f625c10, 0x30420002, 0x10400009, 0x00000000, 0x8f626820,
5341 0x30422000, 0x1040fff8, 0x00000000, 0x0e0001f0, 0x00002021, 0x0a0005c4,
5342 0x00000000, 0x8fbf0014, 0x8fb00010, 0x03e00008, 0x27bd0018, 0x00000000,
5343 0x00000000, 0x00000000, 0x27bdffe8, 0x3c1bc000, 0xafbf0014, 0xafb00010,
5344 0xaf60680c, 0x8f626804, 0x34420082, 0xaf626804, 0x8f634000, 0x24020b50,
5345 0x3c010800, 0xac221b54, 0x24020b78, 0x3c010800, 0xac221b64, 0x34630002,
5346 0xaf634000, 0x0e000605, 0x00808021, 0x3c010800, 0xa0221b68, 0x304200ff,
5347 0x24030002, 0x14430005, 0x00000000, 0x3c020800, 0x8c421b54, 0x0a0005f8,
5348 0xac5000c0, 0x3c020800, 0x8c421b54, 0xac5000bc, 0x8f624434, 0x8f634438,
5349 0x8f644410, 0x3c010800, 0xac221b5c, 0x3c010800, 0xac231b6c, 0x3c010800,
5350 0xac241b58, 0x8fbf0014, 0x8fb00010, 0x03e00008, 0x27bd0018, 0x3c040800,
5351 0x8c870000, 0x3c03aa55, 0x3463aa55, 0x3c06c003, 0xac830000, 0x8cc20000,
5352 0x14430007, 0x24050002, 0x3c0355aa, 0x346355aa, 0xac830000, 0x8cc20000,
5353 0x50430001, 0x24050001, 0x3c020800, 0xac470000, 0x03e00008, 0x00a01021,
5354 0x27bdfff8, 0x18800009, 0x00002821, 0x8f63680c, 0x8f62680c, 0x1043fffe,
5355 0x00000000, 0x24a50001, 0x00a4102a, 0x1440fff9, 0x00000000, 0x03e00008,
5356 0x27bd0008, 0x8f634450, 0x3c020800, 0x8c421b5c, 0x00031c02, 0x0043102b,
5357 0x14400008, 0x3c038000, 0x3c040800, 0x8c841b6c, 0x8f624450, 0x00021c02,
5358 0x0083102b, 0x1040fffc, 0x3c038000, 0xaf634444, 0x8f624444, 0x00431024,
5359 0x1440fffd, 0x00000000, 0x8f624448, 0x03e00008, 0x3042ffff, 0x3082ffff,
5360 0x2442e000, 0x2c422001, 0x14400003, 0x3c024000, 0x0a000648, 0x2402ffff,
5361 0x00822025, 0xaf645c38, 0x8f625c30, 0x30420002, 0x1440fffc, 0x00001021,
5362 0x03e00008, 0x00000000, 0x8f624450, 0x3c030800, 0x8c631b58, 0x0a000651,
5363 0x3042ffff, 0x8f624450, 0x3042ffff, 0x0043102b, 0x1440fffc, 0x00000000,
5364 0x03e00008, 0x00000000, 0x27bdffe0, 0x00802821, 0x3c040800, 0x24841af0,
5365 0x00003021, 0x00003821, 0xafbf0018, 0xafa00010, 0x0e00067c, 0xafa00014,
5366 0x0a000660, 0x00000000, 0x8fbf0018, 0x03e00008, 0x27bd0020, 0x00000000,
5367 0x00000000, 0x00000000, 0x3c020800, 0x34423000, 0x3c030800, 0x34633000,
5368 0x3c040800, 0x348437ff, 0x3c010800, 0xac221b74, 0x24020040, 0x3c010800,
5369 0xac221b78, 0x3c010800, 0xac201b70, 0xac600000, 0x24630004, 0x0083102b,
5370 0x5040fffd, 0xac600000, 0x03e00008, 0x00000000, 0x00804821, 0x8faa0010,
5371 0x3c020800, 0x8c421b70, 0x3c040800, 0x8c841b78, 0x8fab0014, 0x24430001,
5372 0x0044102b, 0x3c010800, 0xac231b70, 0x14400003, 0x00004021, 0x3c010800,
5373 0xac201b70, 0x3c020800, 0x8c421b70, 0x3c030800, 0x8c631b74, 0x91240000,
5374 0x00021140, 0x00431021, 0x00481021, 0x25080001, 0xa0440000, 0x29020008,
5375 0x1440fff4, 0x25290001, 0x3c020800, 0x8c421b70, 0x3c030800, 0x8c631b74,
5376 0x8f64680c, 0x00021140, 0x00431021, 0xac440008, 0xac45000c, 0xac460010,
5377 0xac470014, 0xac4a0018, 0x03e00008, 0xac4b001c, 0x00000000, 0x00000000,
5378};
5379
5380static u32 tg3TsoFwRodata[] = {
5381 0x4d61696e, 0x43707542, 0x00000000, 0x4d61696e, 0x43707541, 0x00000000,
5382 0x00000000, 0x00000000, 0x73746b6f, 0x66666c64, 0x496e0000, 0x73746b6f,
5383 0x66662a2a, 0x00000000, 0x53774576, 0x656e7430, 0x00000000, 0x00000000,
5384 0x00000000, 0x00000000, 0x66617461, 0x6c457272, 0x00000000, 0x00000000,
5385 0x00000000,
5386};
5387
5388static u32 tg3TsoFwData[] = {
5389 0x00000000, 0x73746b6f, 0x66666c64, 0x5f76312e, 0x362e3000, 0x00000000,
5390 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
5391 0x00000000,
5392};
5393
5394/* 5705 needs a special version of the TSO firmware. */
5395#define TG3_TSO5_FW_RELEASE_MAJOR 0x1
5396#define TG3_TSO5_FW_RELASE_MINOR 0x2
5397#define TG3_TSO5_FW_RELEASE_FIX 0x0
5398#define TG3_TSO5_FW_START_ADDR 0x00010000
5399#define TG3_TSO5_FW_TEXT_ADDR 0x00010000
5400#define TG3_TSO5_FW_TEXT_LEN 0xe90
5401#define TG3_TSO5_FW_RODATA_ADDR 0x00010e90
5402#define TG3_TSO5_FW_RODATA_LEN 0x50
5403#define TG3_TSO5_FW_DATA_ADDR 0x00010f00
5404#define TG3_TSO5_FW_DATA_LEN 0x20
5405#define TG3_TSO5_FW_SBSS_ADDR 0x00010f20
5406#define TG3_TSO5_FW_SBSS_LEN 0x28
5407#define TG3_TSO5_FW_BSS_ADDR 0x00010f50
5408#define TG3_TSO5_FW_BSS_LEN 0x88
5409
5410static u32 tg3Tso5FwText[(TG3_TSO5_FW_TEXT_LEN / 4) + 1] = {
5411 0x0c004003, 0x00000000, 0x00010f04, 0x00000000, 0x10000003, 0x00000000,
5412 0x0000000d, 0x0000000d, 0x3c1d0001, 0x37bde000, 0x03a0f021, 0x3c100001,
5413 0x26100000, 0x0c004010, 0x00000000, 0x0000000d, 0x27bdffe0, 0x3c04fefe,
5414 0xafbf0018, 0x0c0042e8, 0x34840002, 0x0c004364, 0x00000000, 0x3c030001,
5415 0x90630f34, 0x24020002, 0x3c040001, 0x24840e9c, 0x14620003, 0x24050001,
5416 0x3c040001, 0x24840e90, 0x24060002, 0x00003821, 0xafa00010, 0x0c004378,
5417 0xafa00014, 0x0c00402c, 0x00000000, 0x8fbf0018, 0x03e00008, 0x27bd0020,
5418 0x00000000, 0x00000000, 0x27bdffe0, 0xafbf001c, 0xafb20018, 0xafb10014,
5419 0x0c0042d4, 0xafb00010, 0x3c128000, 0x24110001, 0x8f706810, 0x32020400,
5420 0x10400007, 0x00000000, 0x8f641008, 0x00921024, 0x14400003, 0x00000000,
5421 0x0c004064, 0x00000000, 0x3c020001, 0x90420f56, 0x10510003, 0x32020200,
5422 0x1040fff1, 0x00000000, 0x0c0041b4, 0x00000000, 0x08004034, 0x00000000,
5423 0x8fbf001c, 0x8fb20018, 0x8fb10014, 0x8fb00010, 0x03e00008, 0x27bd0020,
5424 0x27bdffe0, 0x3c040001, 0x24840eb0, 0x00002821, 0x00003021, 0x00003821,
5425 0xafbf0018, 0xafa00010, 0x0c004378, 0xafa00014, 0x0000d021, 0x24020130,
5426 0xaf625000, 0x3c010001, 0xa4200f50, 0x3c010001, 0xa0200f57, 0x8fbf0018,
5427 0x03e00008, 0x27bd0020, 0x00000000, 0x00000000, 0x3c030001, 0x24630f60,
5428 0x90620000, 0x27bdfff0, 0x14400003, 0x0080c021, 0x08004073, 0x00004821,
5429 0x3c022000, 0x03021024, 0x10400003, 0x24090002, 0x08004073, 0xa0600000,
5430 0x24090001, 0x00181040, 0x30431f80, 0x346f8008, 0x1520004b, 0x25eb0028,
5431 0x3c040001, 0x00832021, 0x8c848010, 0x3c050001, 0x24a50f7a, 0x00041402,
5432 0xa0a20000, 0x3c010001, 0xa0240f7b, 0x3c020001, 0x00431021, 0x94428014,
5433 0x3c010001, 0xa0220f7c, 0x3c0c0001, 0x01836021, 0x8d8c8018, 0x304200ff,
5434 0x24420008, 0x000220c3, 0x24020001, 0x3c010001, 0xa0220f60, 0x0124102b,
5435 0x1040000c, 0x00003821, 0x24a6000e, 0x01602821, 0x8ca20000, 0x8ca30004,
5436 0x24a50008, 0x24e70001, 0xacc20000, 0xacc30004, 0x00e4102b, 0x1440fff8,
5437 0x24c60008, 0x00003821, 0x3c080001, 0x25080f7b, 0x91060000, 0x3c020001,
5438 0x90420f7c, 0x2503000d, 0x00c32821, 0x00461023, 0x00021fc2, 0x00431021,
5439 0x00021043, 0x1840000c, 0x00002021, 0x91020001, 0x00461023, 0x00021fc2,
5440 0x00431021, 0x00021843, 0x94a20000, 0x24e70001, 0x00822021, 0x00e3102a,
5441 0x1440fffb, 0x24a50002, 0x00041c02, 0x3082ffff, 0x00622021, 0x00041402,
5442 0x00822021, 0x3c02ffff, 0x01821024, 0x3083ffff, 0x00431025, 0x3c010001,
5443 0x080040fa, 0xac220f80, 0x3c050001, 0x24a50f7c, 0x90a20000, 0x3c0c0001,
5444 0x01836021, 0x8d8c8018, 0x000220c2, 0x1080000e, 0x00003821, 0x01603021,
5445 0x24a5000c, 0x8ca20000, 0x8ca30004, 0x24a50008, 0x24e70001, 0xacc20000,
5446 0xacc30004, 0x00e4102b, 0x1440fff8, 0x24c60008, 0x3c050001, 0x24a50f7c,
5447 0x90a20000, 0x30430007, 0x24020004, 0x10620011, 0x28620005, 0x10400005,
5448 0x24020002, 0x10620008, 0x000710c0, 0x080040fa, 0x00000000, 0x24020006,
5449 0x1062000e, 0x000710c0, 0x080040fa, 0x00000000, 0x00a21821, 0x9463000c,
5450 0x004b1021, 0x080040fa, 0xa4430000, 0x000710c0, 0x00a21821, 0x8c63000c,
5451 0x004b1021, 0x080040fa, 0xac430000, 0x00a21821, 0x8c63000c, 0x004b2021,
5452 0x00a21021, 0xac830000, 0x94420010, 0xa4820004, 0x95e70006, 0x3c020001,
5453 0x90420f7c, 0x3c030001, 0x90630f7a, 0x00e2c823, 0x3c020001, 0x90420f7b,
5454 0x24630028, 0x01e34021, 0x24420028, 0x15200012, 0x01e23021, 0x94c2000c,
5455 0x3c010001, 0xa4220f78, 0x94c20004, 0x94c30006, 0x3c010001, 0xa4200f76,
5456 0x3c010001, 0xa4200f72, 0x00021400, 0x00431025, 0x3c010001, 0xac220f6c,
5457 0x95020004, 0x3c010001, 0x08004124, 0xa4220f70, 0x3c020001, 0x94420f70,
5458 0x3c030001, 0x94630f72, 0x00431021, 0xa5020004, 0x3c020001, 0x94420f6c,
5459 0xa4c20004, 0x3c020001, 0x8c420f6c, 0xa4c20006, 0x3c040001, 0x94840f72,
5460 0x3c020001, 0x94420f70, 0x3c0a0001, 0x954a0f76, 0x00441821, 0x3063ffff,
5461 0x0062182a, 0x24020002, 0x1122000b, 0x00832023, 0x3c030001, 0x94630f78,
5462 0x30620009, 0x10400006, 0x3062fff6, 0xa4c2000c, 0x3c020001, 0x94420f78,
5463 0x30420009, 0x01425023, 0x24020001, 0x1122001b, 0x29220002, 0x50400005,
5464 0x24020002, 0x11200007, 0x31a2ffff, 0x08004197, 0x00000000, 0x1122001d,
5465 0x24020016, 0x08004197, 0x31a2ffff, 0x3c0e0001, 0x95ce0f80, 0x10800005,
5466 0x01806821, 0x01c42021, 0x00041c02, 0x3082ffff, 0x00627021, 0x000e1027,
5467 0xa502000a, 0x3c030001, 0x90630f7b, 0x31a2ffff, 0x00e21021, 0x0800418d,
5468 0x00432023, 0x3c020001, 0x94420f80, 0x00442021, 0x00041c02, 0x3082ffff,
5469 0x00622021, 0x00807021, 0x00041027, 0x08004185, 0xa502000a, 0x3c050001,
5470 0x24a50f7a, 0x90a30000, 0x14620002, 0x24e2fff2, 0xa5e20034, 0x90a20000,
5471 0x00e21023, 0xa5020002, 0x3c030001, 0x94630f80, 0x3c020001, 0x94420f5a,
5472 0x30e5ffff, 0x00641821, 0x00451023, 0x00622023, 0x00041c02, 0x3082ffff,
5473 0x00622021, 0x00041027, 0xa502000a, 0x3c030001, 0x90630f7c, 0x24620001,
5474 0x14a20005, 0x00807021, 0x01631021, 0x90420000, 0x08004185, 0x00026200,
5475 0x24620002, 0x14a20003, 0x306200fe, 0x004b1021, 0x944c0000, 0x3c020001,
5476 0x94420f82, 0x3183ffff, 0x3c040001, 0x90840f7b, 0x00431021, 0x00e21021,
5477 0x00442023, 0x008a2021, 0x00041c02, 0x3082ffff, 0x00622021, 0x00041402,
5478 0x00822021, 0x00806821, 0x00041027, 0xa4c20010, 0x31a2ffff, 0x000e1c00,
5479 0x00431025, 0x3c040001, 0x24840f72, 0xade20010, 0x94820000, 0x3c050001,
5480 0x94a50f76, 0x3c030001, 0x8c630f6c, 0x24420001, 0x00b92821, 0xa4820000,
5481 0x3322ffff, 0x00622021, 0x0083182b, 0x3c010001, 0xa4250f76, 0x10600003,
5482 0x24a2ffff, 0x3c010001, 0xa4220f76, 0x3c024000, 0x03021025, 0x3c010001,
5483 0xac240f6c, 0xaf621008, 0x03e00008, 0x27bd0010, 0x3c030001, 0x90630f56,
5484 0x27bdffe8, 0x24020001, 0xafbf0014, 0x10620026, 0xafb00010, 0x8f620cf4,
5485 0x2442ffff, 0x3042007f, 0x00021100, 0x8c434000, 0x3c010001, 0xac230f64,
5486 0x8c434008, 0x24444000, 0x8c5c4004, 0x30620040, 0x14400002, 0x24020088,
5487 0x24020008, 0x3c010001, 0xa4220f68, 0x30620004, 0x10400005, 0x24020001,
5488 0x3c010001, 0xa0220f57, 0x080041d5, 0x00031402, 0x3c010001, 0xa0200f57,
5489 0x00031402, 0x3c010001, 0xa4220f54, 0x9483000c, 0x24020001, 0x3c010001,
5490 0xa4200f50, 0x3c010001, 0xa0220f56, 0x3c010001, 0xa4230f62, 0x24020001,
5491 0x1342001e, 0x00000000, 0x13400005, 0x24020003, 0x13420067, 0x00000000,
5492 0x080042cf, 0x00000000, 0x3c020001, 0x94420f62, 0x241a0001, 0x3c010001,
5493 0xa4200f5e, 0x3c010001, 0xa4200f52, 0x304407ff, 0x00021bc2, 0x00031823,
5494 0x3063003e, 0x34630036, 0x00021242, 0x3042003c, 0x00621821, 0x3c010001,
5495 0xa4240f58, 0x00832021, 0x24630030, 0x3c010001, 0xa4240f5a, 0x3c010001,
5496 0xa4230f5c, 0x3c060001, 0x24c60f52, 0x94c50000, 0x94c30002, 0x3c040001,
5497 0x94840f5a, 0x00651021, 0x0044102a, 0x10400013, 0x3c108000, 0x00a31021,
5498 0xa4c20000, 0x3c02a000, 0xaf620cf4, 0x3c010001, 0xa0200f56, 0x8f641008,
5499 0x00901024, 0x14400003, 0x00000000, 0x0c004064, 0x00000000, 0x8f620cf4,
5500 0x00501024, 0x104000b7, 0x00000000, 0x0800420f, 0x00000000, 0x3c030001,
5501 0x94630f50, 0x00851023, 0xa4c40000, 0x00621821, 0x3042ffff, 0x3c010001,
5502 0xa4230f50, 0xaf620ce8, 0x3c020001, 0x94420f68, 0x34420024, 0xaf620cec,
5503 0x94c30002, 0x3c020001, 0x94420f50, 0x14620012, 0x3c028000, 0x3c108000,
5504 0x3c02a000, 0xaf620cf4, 0x3c010001, 0xa0200f56, 0x8f641008, 0x00901024,
5505 0x14400003, 0x00000000, 0x0c004064, 0x00000000, 0x8f620cf4, 0x00501024,
5506 0x1440fff7, 0x00000000, 0x080042cf, 0x241a0003, 0xaf620cf4, 0x3c108000,
5507 0x8f641008, 0x00901024, 0x14400003, 0x00000000, 0x0c004064, 0x00000000,
5508 0x8f620cf4, 0x00501024, 0x1440fff7, 0x00000000, 0x080042cf, 0x241a0003,
5509 0x3c070001, 0x24e70f50, 0x94e20000, 0x03821021, 0xaf620ce0, 0x3c020001,
5510 0x8c420f64, 0xaf620ce4, 0x3c050001, 0x94a50f54, 0x94e30000, 0x3c040001,
5511 0x94840f58, 0x3c020001, 0x94420f5e, 0x00a32823, 0x00822023, 0x30a6ffff,
5512 0x3083ffff, 0x00c3102b, 0x14400043, 0x00000000, 0x3c020001, 0x94420f5c,
5513 0x00021400, 0x00621025, 0xaf620ce8, 0x94e20000, 0x3c030001, 0x94630f54,
5514 0x00441021, 0xa4e20000, 0x3042ffff, 0x14430021, 0x3c020008, 0x3c020001,
5515 0x90420f57, 0x10400006, 0x3c03000c, 0x3c020001, 0x94420f68, 0x34630624,
5516 0x0800427c, 0x0000d021, 0x3c020001, 0x94420f68, 0x3c030008, 0x34630624,
5517 0x00431025, 0xaf620cec, 0x3c108000, 0x3c02a000, 0xaf620cf4, 0x3c010001,
5518 0xa0200f56, 0x8f641008, 0x00901024, 0x14400003, 0x00000000, 0x0c004064,
5519 0x00000000, 0x8f620cf4, 0x00501024, 0x10400015, 0x00000000, 0x08004283,
5520 0x00000000, 0x3c030001, 0x94630f68, 0x34420624, 0x3c108000, 0x00621825,
5521 0x3c028000, 0xaf630cec, 0xaf620cf4, 0x8f641008, 0x00901024, 0x14400003,
5522 0x00000000, 0x0c004064, 0x00000000, 0x8f620cf4, 0x00501024, 0x1440fff7,
5523 0x00000000, 0x3c010001, 0x080042cf, 0xa4200f5e, 0x3c020001, 0x94420f5c,
5524 0x00021400, 0x00c21025, 0xaf620ce8, 0x3c020001, 0x90420f57, 0x10400009,
5525 0x3c03000c, 0x3c020001, 0x94420f68, 0x34630624, 0x0000d021, 0x00431025,
5526 0xaf620cec, 0x080042c1, 0x3c108000, 0x3c020001, 0x94420f68, 0x3c030008,
5527 0x34630604, 0x00431025, 0xaf620cec, 0x3c020001, 0x94420f5e, 0x00451021,
5528 0x3c010001, 0xa4220f5e, 0x3c108000, 0x3c02a000, 0xaf620cf4, 0x3c010001,
5529 0xa0200f56, 0x8f641008, 0x00901024, 0x14400003, 0x00000000, 0x0c004064,
5530 0x00000000, 0x8f620cf4, 0x00501024, 0x1440fff7, 0x00000000, 0x8fbf0014,
5531 0x8fb00010, 0x03e00008, 0x27bd0018, 0x00000000, 0x27bdffe0, 0x3c040001,
5532 0x24840ec0, 0x00002821, 0x00003021, 0x00003821, 0xafbf0018, 0xafa00010,
5533 0x0c004378, 0xafa00014, 0x0000d021, 0x24020130, 0xaf625000, 0x3c010001,
5534 0xa4200f50, 0x3c010001, 0xa0200f57, 0x8fbf0018, 0x03e00008, 0x27bd0020,
5535 0x27bdffe8, 0x3c1bc000, 0xafbf0014, 0xafb00010, 0xaf60680c, 0x8f626804,
5536 0x34420082, 0xaf626804, 0x8f634000, 0x24020b50, 0x3c010001, 0xac220f20,
5537 0x24020b78, 0x3c010001, 0xac220f30, 0x34630002, 0xaf634000, 0x0c004315,
5538 0x00808021, 0x3c010001, 0xa0220f34, 0x304200ff, 0x24030002, 0x14430005,
5539 0x00000000, 0x3c020001, 0x8c420f20, 0x08004308, 0xac5000c0, 0x3c020001,
5540 0x8c420f20, 0xac5000bc, 0x8f624434, 0x8f634438, 0x8f644410, 0x3c010001,
5541 0xac220f28, 0x3c010001, 0xac230f38, 0x3c010001, 0xac240f24, 0x8fbf0014,
5542 0x8fb00010, 0x03e00008, 0x27bd0018, 0x03e00008, 0x24020001, 0x27bdfff8,
5543 0x18800009, 0x00002821, 0x8f63680c, 0x8f62680c, 0x1043fffe, 0x00000000,
5544 0x24a50001, 0x00a4102a, 0x1440fff9, 0x00000000, 0x03e00008, 0x27bd0008,
5545 0x8f634450, 0x3c020001, 0x8c420f28, 0x00031c02, 0x0043102b, 0x14400008,
5546 0x3c038000, 0x3c040001, 0x8c840f38, 0x8f624450, 0x00021c02, 0x0083102b,
5547 0x1040fffc, 0x3c038000, 0xaf634444, 0x8f624444, 0x00431024, 0x1440fffd,
5548 0x00000000, 0x8f624448, 0x03e00008, 0x3042ffff, 0x3082ffff, 0x2442e000,
5549 0x2c422001, 0x14400003, 0x3c024000, 0x08004347, 0x2402ffff, 0x00822025,
5550 0xaf645c38, 0x8f625c30, 0x30420002, 0x1440fffc, 0x00001021, 0x03e00008,
5551 0x00000000, 0x8f624450, 0x3c030001, 0x8c630f24, 0x08004350, 0x3042ffff,
5552 0x8f624450, 0x3042ffff, 0x0043102b, 0x1440fffc, 0x00000000, 0x03e00008,
5553 0x00000000, 0x27bdffe0, 0x00802821, 0x3c040001, 0x24840ed0, 0x00003021,
5554 0x00003821, 0xafbf0018, 0xafa00010, 0x0c004378, 0xafa00014, 0x0800435f,
5555 0x00000000, 0x8fbf0018, 0x03e00008, 0x27bd0020, 0x3c020001, 0x3442d600,
5556 0x3c030001, 0x3463d600, 0x3c040001, 0x3484ddff, 0x3c010001, 0xac220f40,
5557 0x24020040, 0x3c010001, 0xac220f44, 0x3c010001, 0xac200f3c, 0xac600000,
5558 0x24630004, 0x0083102b, 0x5040fffd, 0xac600000, 0x03e00008, 0x00000000,
5559 0x00804821, 0x8faa0010, 0x3c020001, 0x8c420f3c, 0x3c040001, 0x8c840f44,
5560 0x8fab0014, 0x24430001, 0x0044102b, 0x3c010001, 0xac230f3c, 0x14400003,
5561 0x00004021, 0x3c010001, 0xac200f3c, 0x3c020001, 0x8c420f3c, 0x3c030001,
5562 0x8c630f40, 0x91240000, 0x00021140, 0x00431021, 0x00481021, 0x25080001,
5563 0xa0440000, 0x29020008, 0x1440fff4, 0x25290001, 0x3c020001, 0x8c420f3c,
5564 0x3c030001, 0x8c630f40, 0x8f64680c, 0x00021140, 0x00431021, 0xac440008,
5565 0xac45000c, 0xac460010, 0xac470014, 0xac4a0018, 0x03e00008, 0xac4b001c,
5566 0x00000000, 0x00000000, 0x00000000,
5567};
5568
5569static u32 tg3Tso5FwRodata[(TG3_TSO5_FW_RODATA_LEN / 4) + 1] = {
5570 0x4d61696e, 0x43707542, 0x00000000, 0x4d61696e, 0x43707541, 0x00000000,
5571 0x00000000, 0x00000000, 0x73746b6f, 0x66666c64, 0x00000000, 0x00000000,
5572 0x73746b6f, 0x66666c64, 0x00000000, 0x00000000, 0x66617461, 0x6c457272,
5573 0x00000000, 0x00000000, 0x00000000,
5574};
5575
5576static u32 tg3Tso5FwData[(TG3_TSO5_FW_DATA_LEN / 4) + 1] = {
5577 0x00000000, 0x73746b6f, 0x66666c64, 0x5f76312e, 0x322e3000, 0x00000000,
5578 0x00000000, 0x00000000, 0x00000000,
5579};
5580
5581/* tp->lock is held. */
5582static int tg3_load_tso_firmware(struct tg3 *tp)
5583{
5584 struct fw_info info;
5585 unsigned long cpu_base, cpu_scratch_base, cpu_scratch_size;
5586 int err, i;
5587
5588 if (tp->tg3_flags2 & TG3_FLG2_HW_TSO)
5589 return 0;
5590
5591 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) {
5592 info.text_base = TG3_TSO5_FW_TEXT_ADDR;
5593 info.text_len = TG3_TSO5_FW_TEXT_LEN;
5594 info.text_data = &tg3Tso5FwText[0];
5595 info.rodata_base = TG3_TSO5_FW_RODATA_ADDR;
5596 info.rodata_len = TG3_TSO5_FW_RODATA_LEN;
5597 info.rodata_data = &tg3Tso5FwRodata[0];
5598 info.data_base = TG3_TSO5_FW_DATA_ADDR;
5599 info.data_len = TG3_TSO5_FW_DATA_LEN;
5600 info.data_data = &tg3Tso5FwData[0];
5601 cpu_base = RX_CPU_BASE;
5602 cpu_scratch_base = NIC_SRAM_MBUF_POOL_BASE5705;
5603 cpu_scratch_size = (info.text_len +
5604 info.rodata_len +
5605 info.data_len +
5606 TG3_TSO5_FW_SBSS_LEN +
5607 TG3_TSO5_FW_BSS_LEN);
5608 } else {
5609 info.text_base = TG3_TSO_FW_TEXT_ADDR;
5610 info.text_len = TG3_TSO_FW_TEXT_LEN;
5611 info.text_data = &tg3TsoFwText[0];
5612 info.rodata_base = TG3_TSO_FW_RODATA_ADDR;
5613 info.rodata_len = TG3_TSO_FW_RODATA_LEN;
5614 info.rodata_data = &tg3TsoFwRodata[0];
5615 info.data_base = TG3_TSO_FW_DATA_ADDR;
5616 info.data_len = TG3_TSO_FW_DATA_LEN;
5617 info.data_data = &tg3TsoFwData[0];
5618 cpu_base = TX_CPU_BASE;
5619 cpu_scratch_base = TX_CPU_SCRATCH_BASE;
5620 cpu_scratch_size = TX_CPU_SCRATCH_SIZE;
5621 }
5622
5623 err = tg3_load_firmware_cpu(tp, cpu_base,
5624 cpu_scratch_base, cpu_scratch_size,
5625 &info);
5626 if (err)
5627 return err;
5628
5629 /* Now startup the cpu. */
5630 tw32(cpu_base + CPU_STATE, 0xffffffff);
5631 tw32_f(cpu_base + CPU_PC, info.text_base);
5632
5633 for (i = 0; i < 5; i++) {
5634 if (tr32(cpu_base + CPU_PC) == info.text_base)
5635 break;
5636 tw32(cpu_base + CPU_STATE, 0xffffffff);
5637 tw32(cpu_base + CPU_MODE, CPU_MODE_HALT);
5638 tw32_f(cpu_base + CPU_PC, info.text_base);
5639 udelay(1000);
5640 }
5641 if (i >= 5) {
5642 printk(KERN_ERR PFX "tg3_load_tso_firmware fails for %s "
5643 "to set CPU PC, is %08x should be %08x\n",
5644 tp->dev->name, tr32(cpu_base + CPU_PC),
5645 info.text_base);
5646 return -ENODEV;
5647 }
5648 tw32(cpu_base + CPU_STATE, 0xffffffff);
5649 tw32_f(cpu_base + CPU_MODE, 0x00000000);
5650 return 0;
5651}
5652
5653#endif /* TG3_TSO_SUPPORT != 0 */
5654
5655/* tp->lock is held. */
5656static void __tg3_set_mac_addr(struct tg3 *tp)
5657{
5658 u32 addr_high, addr_low;
5659 int i;
5660
5661 addr_high = ((tp->dev->dev_addr[0] << 8) |
5662 tp->dev->dev_addr[1]);
5663 addr_low = ((tp->dev->dev_addr[2] << 24) |
5664 (tp->dev->dev_addr[3] << 16) |
5665 (tp->dev->dev_addr[4] << 8) |
5666 (tp->dev->dev_addr[5] << 0));
5667 for (i = 0; i < 4; i++) {
5668 tw32(MAC_ADDR_0_HIGH + (i * 8), addr_high);
5669 tw32(MAC_ADDR_0_LOW + (i * 8), addr_low);
5670 }
5671
5672 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 ||
5673 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) {
5674 for (i = 0; i < 12; i++) {
5675 tw32(MAC_EXTADDR_0_HIGH + (i * 8), addr_high);
5676 tw32(MAC_EXTADDR_0_LOW + (i * 8), addr_low);
5677 }
5678 }
5679
5680 addr_high = (tp->dev->dev_addr[0] +
5681 tp->dev->dev_addr[1] +
5682 tp->dev->dev_addr[2] +
5683 tp->dev->dev_addr[3] +
5684 tp->dev->dev_addr[4] +
5685 tp->dev->dev_addr[5]) &
5686 TX_BACKOFF_SEED_MASK;
5687 tw32(MAC_TX_BACKOFF_SEED, addr_high);
5688}
5689
5690static int tg3_set_mac_addr(struct net_device *dev, void *p)
5691{
5692 struct tg3 *tp = netdev_priv(dev);
5693 struct sockaddr *addr = p;
5694
f9804ddb
MC
5695 if (!is_valid_ether_addr(addr->sa_data))
5696 return -EINVAL;
5697
1da177e4
LT
5698 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
5699
e75f7c90
MC
5700 if (!netif_running(dev))
5701 return 0;
5702
f47c11ee 5703 spin_lock_bh(&tp->lock);
1da177e4 5704 __tg3_set_mac_addr(tp);
f47c11ee 5705 spin_unlock_bh(&tp->lock);
1da177e4
LT
5706
5707 return 0;
5708}
5709
5710/* tp->lock is held. */
5711static void tg3_set_bdinfo(struct tg3 *tp, u32 bdinfo_addr,
5712 dma_addr_t mapping, u32 maxlen_flags,
5713 u32 nic_addr)
5714{
5715 tg3_write_mem(tp,
5716 (bdinfo_addr + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH),
5717 ((u64) mapping >> 32));
5718 tg3_write_mem(tp,
5719 (bdinfo_addr + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW),
5720 ((u64) mapping & 0xffffffff));
5721 tg3_write_mem(tp,
5722 (bdinfo_addr + TG3_BDINFO_MAXLEN_FLAGS),
5723 maxlen_flags);
5724
5725 if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS))
5726 tg3_write_mem(tp,
5727 (bdinfo_addr + TG3_BDINFO_NIC_ADDR),
5728 nic_addr);
5729}
5730
5731static void __tg3_set_rx_mode(struct net_device *);
d244c892 5732static void __tg3_set_coalesce(struct tg3 *tp, struct ethtool_coalesce *ec)
15f9850d
DM
5733{
5734 tw32(HOSTCC_RXCOL_TICKS, ec->rx_coalesce_usecs);
5735 tw32(HOSTCC_TXCOL_TICKS, ec->tx_coalesce_usecs);
5736 tw32(HOSTCC_RXMAX_FRAMES, ec->rx_max_coalesced_frames);
5737 tw32(HOSTCC_TXMAX_FRAMES, ec->tx_max_coalesced_frames);
5738 if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
5739 tw32(HOSTCC_RXCOAL_TICK_INT, ec->rx_coalesce_usecs_irq);
5740 tw32(HOSTCC_TXCOAL_TICK_INT, ec->tx_coalesce_usecs_irq);
5741 }
5742 tw32(HOSTCC_RXCOAL_MAXF_INT, ec->rx_max_coalesced_frames_irq);
5743 tw32(HOSTCC_TXCOAL_MAXF_INT, ec->tx_max_coalesced_frames_irq);
5744 if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
5745 u32 val = ec->stats_block_coalesce_usecs;
5746
5747 if (!netif_carrier_ok(tp->dev))
5748 val = 0;
5749
5750 tw32(HOSTCC_STAT_COAL_TICKS, val);
5751 }
5752}
1da177e4
LT
5753
5754/* tp->lock is held. */
5755static int tg3_reset_hw(struct tg3 *tp)
5756{
5757 u32 val, rdmac_mode;
5758 int i, err, limit;
5759
5760 tg3_disable_ints(tp);
5761
5762 tg3_stop_fw(tp);
5763
5764 tg3_write_sig_pre_reset(tp, RESET_KIND_INIT);
5765
5766 if (tp->tg3_flags & TG3_FLAG_INIT_COMPLETE) {
e6de8ad1 5767 tg3_abort_hw(tp, 1);
1da177e4
LT
5768 }
5769
d4d2c558
MC
5770 if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES)
5771 tg3_phy_reset(tp);
5772
1da177e4
LT
5773 err = tg3_chip_reset(tp);
5774 if (err)
5775 return err;
5776
5777 tg3_write_sig_legacy(tp, RESET_KIND_INIT);
5778
5779 /* This works around an issue with Athlon chipsets on
5780 * B3 tigon3 silicon. This bit has no effect on any
5781 * other revision. But do not set this on PCI Express
5782 * chips.
5783 */
5784 if (!(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS))
5785 tp->pci_clock_ctrl |= CLOCK_CTRL_DELAY_PCI_GRANT;
5786 tw32_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl);
5787
5788 if (tp->pci_chip_rev_id == CHIPREV_ID_5704_A0 &&
5789 (tp->tg3_flags & TG3_FLAG_PCIX_MODE)) {
5790 val = tr32(TG3PCI_PCISTATE);
5791 val |= PCISTATE_RETRY_SAME_DMA;
5792 tw32(TG3PCI_PCISTATE, val);
5793 }
5794
5795 if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5704_BX) {
5796 /* Enable some hw fixes. */
5797 val = tr32(TG3PCI_MSI_DATA);
5798 val |= (1 << 26) | (1 << 28) | (1 << 29);
5799 tw32(TG3PCI_MSI_DATA, val);
5800 }
5801
5802 /* Descriptor ring init may make accesses to the
5803 * NIC SRAM area to setup the TX descriptors, so we
5804 * can only do this after the hardware has been
5805 * successfully reset.
5806 */
5807 tg3_init_rings(tp);
5808
5809 /* This value is determined during the probe time DMA
5810 * engine test, tg3_test_dma.
5811 */
5812 tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl);
5813
5814 tp->grc_mode &= ~(GRC_MODE_HOST_SENDBDS |
5815 GRC_MODE_4X_NIC_SEND_RINGS |
5816 GRC_MODE_NO_TX_PHDR_CSUM |
5817 GRC_MODE_NO_RX_PHDR_CSUM);
5818 tp->grc_mode |= GRC_MODE_HOST_SENDBDS;
5819 if (tp->tg3_flags & TG3_FLAG_NO_TX_PSEUDO_CSUM)
5820 tp->grc_mode |= GRC_MODE_NO_TX_PHDR_CSUM;
5821 if (tp->tg3_flags & TG3_FLAG_NO_RX_PSEUDO_CSUM)
5822 tp->grc_mode |= GRC_MODE_NO_RX_PHDR_CSUM;
5823
5824 tw32(GRC_MODE,
5825 tp->grc_mode |
5826 (GRC_MODE_IRQ_ON_MAC_ATTN | GRC_MODE_HOST_STACKUP));
5827
5828 /* Setup the timer prescalar register. Clock is always 66Mhz. */
5829 val = tr32(GRC_MISC_CFG);
5830 val &= ~0xff;
5831 val |= (65 << GRC_MISC_CFG_PRESCALAR_SHIFT);
5832 tw32(GRC_MISC_CFG, val);
5833
5834 /* Initialize MBUF/DESC pool. */
cbf46853 5835 if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS) {
1da177e4
LT
5836 /* Do nothing. */
5837 } else if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5705) {
5838 tw32(BUFMGR_MB_POOL_ADDR, NIC_SRAM_MBUF_POOL_BASE);
5839 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704)
5840 tw32(BUFMGR_MB_POOL_SIZE, NIC_SRAM_MBUF_POOL_SIZE64);
5841 else
5842 tw32(BUFMGR_MB_POOL_SIZE, NIC_SRAM_MBUF_POOL_SIZE96);
5843 tw32(BUFMGR_DMA_DESC_POOL_ADDR, NIC_SRAM_DMA_DESC_POOL_BASE);
5844 tw32(BUFMGR_DMA_DESC_POOL_SIZE, NIC_SRAM_DMA_DESC_POOL_SIZE);
5845 }
5846#if TG3_TSO_SUPPORT != 0
5847 else if (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) {
5848 int fw_len;
5849
5850 fw_len = (TG3_TSO5_FW_TEXT_LEN +
5851 TG3_TSO5_FW_RODATA_LEN +
5852 TG3_TSO5_FW_DATA_LEN +
5853 TG3_TSO5_FW_SBSS_LEN +
5854 TG3_TSO5_FW_BSS_LEN);
5855 fw_len = (fw_len + (0x80 - 1)) & ~(0x80 - 1);
5856 tw32(BUFMGR_MB_POOL_ADDR,
5857 NIC_SRAM_MBUF_POOL_BASE5705 + fw_len);
5858 tw32(BUFMGR_MB_POOL_SIZE,
5859 NIC_SRAM_MBUF_POOL_SIZE5705 - fw_len - 0xa00);
5860 }
5861#endif
5862
0f893dc6 5863 if (tp->dev->mtu <= ETH_DATA_LEN) {
1da177e4
LT
5864 tw32(BUFMGR_MB_RDMA_LOW_WATER,
5865 tp->bufmgr_config.mbuf_read_dma_low_water);
5866 tw32(BUFMGR_MB_MACRX_LOW_WATER,
5867 tp->bufmgr_config.mbuf_mac_rx_low_water);
5868 tw32(BUFMGR_MB_HIGH_WATER,
5869 tp->bufmgr_config.mbuf_high_water);
5870 } else {
5871 tw32(BUFMGR_MB_RDMA_LOW_WATER,
5872 tp->bufmgr_config.mbuf_read_dma_low_water_jumbo);
5873 tw32(BUFMGR_MB_MACRX_LOW_WATER,
5874 tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo);
5875 tw32(BUFMGR_MB_HIGH_WATER,
5876 tp->bufmgr_config.mbuf_high_water_jumbo);
5877 }
5878 tw32(BUFMGR_DMA_LOW_WATER,
5879 tp->bufmgr_config.dma_low_water);
5880 tw32(BUFMGR_DMA_HIGH_WATER,
5881 tp->bufmgr_config.dma_high_water);
5882
5883 tw32(BUFMGR_MODE, BUFMGR_MODE_ENABLE | BUFMGR_MODE_ATTN_ENABLE);
5884 for (i = 0; i < 2000; i++) {
5885 if (tr32(BUFMGR_MODE) & BUFMGR_MODE_ENABLE)
5886 break;
5887 udelay(10);
5888 }
5889 if (i >= 2000) {
5890 printk(KERN_ERR PFX "tg3_reset_hw cannot enable BUFMGR for %s.\n",
5891 tp->dev->name);
5892 return -ENODEV;
5893 }
5894
5895 /* Setup replenish threshold. */
5896 tw32(RCVBDI_STD_THRESH, tp->rx_pending / 8);
5897
5898 /* Initialize TG3_BDINFO's at:
5899 * RCVDBDI_STD_BD: standard eth size rx ring
5900 * RCVDBDI_JUMBO_BD: jumbo frame rx ring
5901 * RCVDBDI_MINI_BD: small frame rx ring (??? does not work)
5902 *
5903 * like so:
5904 * TG3_BDINFO_HOST_ADDR: high/low parts of DMA address of ring
5905 * TG3_BDINFO_MAXLEN_FLAGS: (rx max buffer size << 16) |
5906 * ring attribute flags
5907 * TG3_BDINFO_NIC_ADDR: location of descriptors in nic SRAM
5908 *
5909 * Standard receive ring @ NIC_SRAM_RX_BUFFER_DESC, 512 entries.
5910 * Jumbo receive ring @ NIC_SRAM_RX_JUMBO_BUFFER_DESC, 256 entries.
5911 *
5912 * The size of each ring is fixed in the firmware, but the location is
5913 * configurable.
5914 */
5915 tw32(RCVDBDI_STD_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH,
5916 ((u64) tp->rx_std_mapping >> 32));
5917 tw32(RCVDBDI_STD_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW,
5918 ((u64) tp->rx_std_mapping & 0xffffffff));
5919 tw32(RCVDBDI_STD_BD + TG3_BDINFO_NIC_ADDR,
5920 NIC_SRAM_RX_BUFFER_DESC);
5921
5922 /* Don't even try to program the JUMBO/MINI buffer descriptor
5923 * configs on 5705.
5924 */
5925 if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
5926 tw32(RCVDBDI_STD_BD + TG3_BDINFO_MAXLEN_FLAGS,
5927 RX_STD_MAX_SIZE_5705 << BDINFO_FLAGS_MAXLEN_SHIFT);
5928 } else {
5929 tw32(RCVDBDI_STD_BD + TG3_BDINFO_MAXLEN_FLAGS,
5930 RX_STD_MAX_SIZE << BDINFO_FLAGS_MAXLEN_SHIFT);
5931
5932 tw32(RCVDBDI_MINI_BD + TG3_BDINFO_MAXLEN_FLAGS,
5933 BDINFO_FLAGS_DISABLED);
5934
5935 /* Setup replenish threshold. */
5936 tw32(RCVBDI_JUMBO_THRESH, tp->rx_jumbo_pending / 8);
5937
0f893dc6 5938 if (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE) {
1da177e4
LT
5939 tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH,
5940 ((u64) tp->rx_jumbo_mapping >> 32));
5941 tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW,
5942 ((u64) tp->rx_jumbo_mapping & 0xffffffff));
5943 tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_MAXLEN_FLAGS,
5944 RX_JUMBO_MAX_SIZE << BDINFO_FLAGS_MAXLEN_SHIFT);
5945 tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_NIC_ADDR,
5946 NIC_SRAM_RX_JUMBO_BUFFER_DESC);
5947 } else {
5948 tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_MAXLEN_FLAGS,
5949 BDINFO_FLAGS_DISABLED);
5950 }
5951
5952 }
5953
5954 /* There is only one send ring on 5705/5750, no need to explicitly
5955 * disable the others.
5956 */
5957 if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
5958 /* Clear out send RCB ring in SRAM. */
5959 for (i = NIC_SRAM_SEND_RCB; i < NIC_SRAM_RCV_RET_RCB; i += TG3_BDINFO_SIZE)
5960 tg3_write_mem(tp, i + TG3_BDINFO_MAXLEN_FLAGS,
5961 BDINFO_FLAGS_DISABLED);
5962 }
5963
5964 tp->tx_prod = 0;
5965 tp->tx_cons = 0;
5966 tw32_mailbox(MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW, 0);
5967 tw32_tx_mbox(MAILBOX_SNDNIC_PROD_IDX_0 + TG3_64BIT_REG_LOW, 0);
5968
5969 tg3_set_bdinfo(tp, NIC_SRAM_SEND_RCB,
5970 tp->tx_desc_mapping,
5971 (TG3_TX_RING_SIZE <<
5972 BDINFO_FLAGS_MAXLEN_SHIFT),
5973 NIC_SRAM_TX_BUFFER_DESC);
5974
5975 /* There is only one receive return ring on 5705/5750, no need
5976 * to explicitly disable the others.
5977 */
5978 if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
5979 for (i = NIC_SRAM_RCV_RET_RCB; i < NIC_SRAM_STATS_BLK;
5980 i += TG3_BDINFO_SIZE) {
5981 tg3_write_mem(tp, i + TG3_BDINFO_MAXLEN_FLAGS,
5982 BDINFO_FLAGS_DISABLED);
5983 }
5984 }
5985
5986 tp->rx_rcb_ptr = 0;
5987 tw32_rx_mbox(MAILBOX_RCVRET_CON_IDX_0 + TG3_64BIT_REG_LOW, 0);
5988
5989 tg3_set_bdinfo(tp, NIC_SRAM_RCV_RET_RCB,
5990 tp->rx_rcb_mapping,
5991 (TG3_RX_RCB_RING_SIZE(tp) <<
5992 BDINFO_FLAGS_MAXLEN_SHIFT),
5993 0);
5994
5995 tp->rx_std_ptr = tp->rx_pending;
5996 tw32_rx_mbox(MAILBOX_RCV_STD_PROD_IDX + TG3_64BIT_REG_LOW,
5997 tp->rx_std_ptr);
5998
0f893dc6 5999 tp->rx_jumbo_ptr = (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE) ?
1da177e4
LT
6000 tp->rx_jumbo_pending : 0;
6001 tw32_rx_mbox(MAILBOX_RCV_JUMBO_PROD_IDX + TG3_64BIT_REG_LOW,
6002 tp->rx_jumbo_ptr);
6003
6004 /* Initialize MAC address and backoff seed. */
6005 __tg3_set_mac_addr(tp);
6006
6007 /* MTU + ethernet header + FCS + optional VLAN tag */
6008 tw32(MAC_RX_MTU_SIZE, tp->dev->mtu + ETH_HLEN + 8);
6009
6010 /* The slot time is changed by tg3_setup_phy if we
6011 * run at gigabit with half duplex.
6012 */
6013 tw32(MAC_TX_LENGTHS,
6014 (2 << TX_LENGTHS_IPG_CRS_SHIFT) |
6015 (6 << TX_LENGTHS_IPG_SHIFT) |
6016 (32 << TX_LENGTHS_SLOT_TIME_SHIFT));
6017
6018 /* Receive rules. */
6019 tw32(MAC_RCV_RULE_CFG, RCV_RULE_CFG_DEFAULT_CLASS);
6020 tw32(RCVLPC_CONFIG, 0x0181);
6021
6022 /* Calculate RDMAC_MODE setting early, we need it to determine
6023 * the RCVLPC_STATE_ENABLE mask.
6024 */
6025 rdmac_mode = (RDMAC_MODE_ENABLE | RDMAC_MODE_TGTABORT_ENAB |
6026 RDMAC_MODE_MSTABORT_ENAB | RDMAC_MODE_PARITYERR_ENAB |
6027 RDMAC_MODE_ADDROFLOW_ENAB | RDMAC_MODE_FIFOOFLOW_ENAB |
6028 RDMAC_MODE_FIFOURUN_ENAB | RDMAC_MODE_FIFOOREAD_ENAB |
6029 RDMAC_MODE_LNGREAD_ENAB);
6030 if (tp->tg3_flags & TG3_FLAG_SPLIT_MODE)
6031 rdmac_mode |= RDMAC_MODE_SPLIT_ENABLE;
85e94ced
MC
6032
6033 /* If statement applies to 5705 and 5750 PCI devices only */
6034 if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 &&
6035 tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) ||
6036 (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750)) {
1da177e4
LT
6037 if (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE &&
6038 (tp->pci_chip_rev_id == CHIPREV_ID_5705_A1 ||
6039 tp->pci_chip_rev_id == CHIPREV_ID_5705_A2)) {
6040 rdmac_mode |= RDMAC_MODE_FIFO_SIZE_128;
6041 } else if (!(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH) &&
6042 !(tp->tg3_flags2 & TG3_FLG2_IS_5788)) {
6043 rdmac_mode |= RDMAC_MODE_FIFO_LONG_BURST;
6044 }
6045 }
6046
85e94ced
MC
6047 if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS)
6048 rdmac_mode |= RDMAC_MODE_FIFO_LONG_BURST;
6049
1da177e4
LT
6050#if TG3_TSO_SUPPORT != 0
6051 if (tp->tg3_flags2 & TG3_FLG2_HW_TSO)
6052 rdmac_mode |= (1 << 27);
6053#endif
6054
6055 /* Receive/send statistics. */
6056 if ((rdmac_mode & RDMAC_MODE_FIFO_SIZE_128) &&
6057 (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE)) {
6058 val = tr32(RCVLPC_STATS_ENABLE);
6059 val &= ~RCVLPC_STATSENAB_LNGBRST_RFIX;
6060 tw32(RCVLPC_STATS_ENABLE, val);
6061 } else {
6062 tw32(RCVLPC_STATS_ENABLE, 0xffffff);
6063 }
6064 tw32(RCVLPC_STATSCTRL, RCVLPC_STATSCTRL_ENABLE);
6065 tw32(SNDDATAI_STATSENAB, 0xffffff);
6066 tw32(SNDDATAI_STATSCTRL,
6067 (SNDDATAI_SCTRL_ENABLE |
6068 SNDDATAI_SCTRL_FASTUPD));
6069
6070 /* Setup host coalescing engine. */
6071 tw32(HOSTCC_MODE, 0);
6072 for (i = 0; i < 2000; i++) {
6073 if (!(tr32(HOSTCC_MODE) & HOSTCC_MODE_ENABLE))
6074 break;
6075 udelay(10);
6076 }
6077
d244c892 6078 __tg3_set_coalesce(tp, &tp->coal);
1da177e4
LT
6079
6080 /* set status block DMA address */
6081 tw32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH,
6082 ((u64) tp->status_mapping >> 32));
6083 tw32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW,
6084 ((u64) tp->status_mapping & 0xffffffff));
6085
6086 if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
6087 /* Status/statistics block address. See tg3_timer,
6088 * the tg3_periodic_fetch_stats call there, and
6089 * tg3_get_stats to see how this works for 5705/5750 chips.
6090 */
1da177e4
LT
6091 tw32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH,
6092 ((u64) tp->stats_mapping >> 32));
6093 tw32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW,
6094 ((u64) tp->stats_mapping & 0xffffffff));
6095 tw32(HOSTCC_STATS_BLK_NIC_ADDR, NIC_SRAM_STATS_BLK);
6096 tw32(HOSTCC_STATUS_BLK_NIC_ADDR, NIC_SRAM_STATUS_BLK);
6097 }
6098
6099 tw32(HOSTCC_MODE, HOSTCC_MODE_ENABLE | tp->coalesce_mode);
6100
6101 tw32(RCVCC_MODE, RCVCC_MODE_ENABLE | RCVCC_MODE_ATTN_ENABLE);
6102 tw32(RCVLPC_MODE, RCVLPC_MODE_ENABLE);
6103 if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS))
6104 tw32(RCVLSC_MODE, RCVLSC_MODE_ENABLE | RCVLSC_MODE_ATTN_ENABLE);
6105
6106 /* Clear statistics/status block in chip, and status block in ram. */
6107 for (i = NIC_SRAM_STATS_BLK;
6108 i < NIC_SRAM_STATUS_BLK + TG3_HW_STATUS_SIZE;
6109 i += sizeof(u32)) {
6110 tg3_write_mem(tp, i, 0);
6111 udelay(40);
6112 }
6113 memset(tp->hw_status, 0, TG3_HW_STATUS_SIZE);
6114
c94e3941
MC
6115 if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES) {
6116 tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
6117 /* reset to prevent losing 1st rx packet intermittently */
6118 tw32_f(MAC_RX_MODE, RX_MODE_RESET);
6119 udelay(10);
6120 }
6121
1da177e4
LT
6122 tp->mac_mode = MAC_MODE_TXSTAT_ENABLE | MAC_MODE_RXSTAT_ENABLE |
6123 MAC_MODE_TDE_ENABLE | MAC_MODE_RDE_ENABLE | MAC_MODE_FHDE_ENABLE;
6124 tw32_f(MAC_MODE, tp->mac_mode | MAC_MODE_RXSTAT_CLEAR | MAC_MODE_TXSTAT_CLEAR);
6125 udelay(40);
6126
314fba34
MC
6127 /* tp->grc_local_ctrl is partially set up during tg3_get_invariants().
6128 * If TG3_FLAG_EEPROM_WRITE_PROT is set, we should read the
6129 * register to preserve the GPIO settings for LOMs. The GPIOs,
6130 * whether used as inputs or outputs, are set by boot code after
6131 * reset.
6132 */
6133 if (tp->tg3_flags & TG3_FLAG_EEPROM_WRITE_PROT) {
6134 u32 gpio_mask;
6135
6136 gpio_mask = GRC_LCLCTRL_GPIO_OE0 | GRC_LCLCTRL_GPIO_OE2 |
6137 GRC_LCLCTRL_GPIO_OUTPUT0 | GRC_LCLCTRL_GPIO_OUTPUT2;
3e7d83bc
MC
6138
6139 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752)
6140 gpio_mask |= GRC_LCLCTRL_GPIO_OE3 |
6141 GRC_LCLCTRL_GPIO_OUTPUT3;
6142
314fba34
MC
6143 tp->grc_local_ctrl |= tr32(GRC_LOCAL_CTRL) & gpio_mask;
6144
6145 /* GPIO1 must be driven high for eeprom write protect */
1da177e4
LT
6146 tp->grc_local_ctrl |= (GRC_LCLCTRL_GPIO_OE1 |
6147 GRC_LCLCTRL_GPIO_OUTPUT1);
314fba34 6148 }
1da177e4
LT
6149 tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl);
6150 udelay(100);
6151
09ee929c 6152 tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0);
fac9b83e 6153 tp->last_tag = 0;
1da177e4
LT
6154
6155 if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
6156 tw32_f(DMAC_MODE, DMAC_MODE_ENABLE);
6157 udelay(40);
6158 }
6159
6160 val = (WDMAC_MODE_ENABLE | WDMAC_MODE_TGTABORT_ENAB |
6161 WDMAC_MODE_MSTABORT_ENAB | WDMAC_MODE_PARITYERR_ENAB |
6162 WDMAC_MODE_ADDROFLOW_ENAB | WDMAC_MODE_FIFOOFLOW_ENAB |
6163 WDMAC_MODE_FIFOURUN_ENAB | WDMAC_MODE_FIFOOREAD_ENAB |
6164 WDMAC_MODE_LNGREAD_ENAB);
6165
85e94ced
MC
6166 /* If statement applies to 5705 and 5750 PCI devices only */
6167 if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 &&
6168 tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) ||
6169 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750) {
1da177e4
LT
6170 if ((tp->tg3_flags & TG3_FLG2_TSO_CAPABLE) &&
6171 (tp->pci_chip_rev_id == CHIPREV_ID_5705_A1 ||
6172 tp->pci_chip_rev_id == CHIPREV_ID_5705_A2)) {
6173 /* nothing */
6174 } else if (!(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH) &&
6175 !(tp->tg3_flags2 & TG3_FLG2_IS_5788) &&
6176 !(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS)) {
6177 val |= WDMAC_MODE_RX_ACCEL;
6178 }
6179 }
6180
d9ab5ad1
MC
6181 /* Enable host coalescing bug fix */
6182 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787)
6183 val |= (1 << 29);
6184
1da177e4
LT
6185 tw32_f(WDMAC_MODE, val);
6186 udelay(40);
6187
6188 if ((tp->tg3_flags & TG3_FLAG_PCIX_MODE) != 0) {
6189 val = tr32(TG3PCI_X_CAPS);
6190 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703) {
6191 val &= ~PCIX_CAPS_BURST_MASK;
6192 val |= (PCIX_CAPS_MAX_BURST_CPIOB << PCIX_CAPS_BURST_SHIFT);
6193 } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) {
6194 val &= ~(PCIX_CAPS_SPLIT_MASK | PCIX_CAPS_BURST_MASK);
6195 val |= (PCIX_CAPS_MAX_BURST_CPIOB << PCIX_CAPS_BURST_SHIFT);
6196 if (tp->tg3_flags & TG3_FLAG_SPLIT_MODE)
6197 val |= (tp->split_mode_max_reqs <<
6198 PCIX_CAPS_SPLIT_SHIFT);
6199 }
6200 tw32(TG3PCI_X_CAPS, val);
6201 }
6202
6203 tw32_f(RDMAC_MODE, rdmac_mode);
6204 udelay(40);
6205
6206 tw32(RCVDCC_MODE, RCVDCC_MODE_ENABLE | RCVDCC_MODE_ATTN_ENABLE);
6207 if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS))
6208 tw32(MBFREE_MODE, MBFREE_MODE_ENABLE);
6209 tw32(SNDDATAC_MODE, SNDDATAC_MODE_ENABLE);
6210 tw32(SNDBDC_MODE, SNDBDC_MODE_ENABLE | SNDBDC_MODE_ATTN_ENABLE);
6211 tw32(RCVBDI_MODE, RCVBDI_MODE_ENABLE | RCVBDI_MODE_RCB_ATTN_ENAB);
6212 tw32(RCVDBDI_MODE, RCVDBDI_MODE_ENABLE | RCVDBDI_MODE_INV_RING_SZ);
6213 tw32(SNDDATAI_MODE, SNDDATAI_MODE_ENABLE);
6214#if TG3_TSO_SUPPORT != 0
6215 if (tp->tg3_flags2 & TG3_FLG2_HW_TSO)
6216 tw32(SNDDATAI_MODE, SNDDATAI_MODE_ENABLE | 0x8);
6217#endif
6218 tw32(SNDBDI_MODE, SNDBDI_MODE_ENABLE | SNDBDI_MODE_ATTN_ENABLE);
6219 tw32(SNDBDS_MODE, SNDBDS_MODE_ENABLE | SNDBDS_MODE_ATTN_ENABLE);
6220
6221 if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0) {
6222 err = tg3_load_5701_a0_firmware_fix(tp);
6223 if (err)
6224 return err;
6225 }
6226
6227#if TG3_TSO_SUPPORT != 0
6228 if (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) {
6229 err = tg3_load_tso_firmware(tp);
6230 if (err)
6231 return err;
6232 }
6233#endif
6234
6235 tp->tx_mode = TX_MODE_ENABLE;
6236 tw32_f(MAC_TX_MODE, tp->tx_mode);
6237 udelay(100);
6238
6239 tp->rx_mode = RX_MODE_ENABLE;
6240 tw32_f(MAC_RX_MODE, tp->rx_mode);
6241 udelay(10);
6242
6243 if (tp->link_config.phy_is_low_power) {
6244 tp->link_config.phy_is_low_power = 0;
6245 tp->link_config.speed = tp->link_config.orig_speed;
6246 tp->link_config.duplex = tp->link_config.orig_duplex;
6247 tp->link_config.autoneg = tp->link_config.orig_autoneg;
6248 }
6249
6250 tp->mi_mode = MAC_MI_MODE_BASE;
6251 tw32_f(MAC_MI_MODE, tp->mi_mode);
6252 udelay(80);
6253
6254 tw32(MAC_LED_CTRL, tp->led_ctrl);
6255
6256 tw32(MAC_MI_STAT, MAC_MI_STAT_LNKSTAT_ATTN_ENAB);
c94e3941 6257 if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) {
1da177e4
LT
6258 tw32_f(MAC_RX_MODE, RX_MODE_RESET);
6259 udelay(10);
6260 }
6261 tw32_f(MAC_RX_MODE, tp->rx_mode);
6262 udelay(10);
6263
6264 if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) {
6265 if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) &&
6266 !(tp->tg3_flags2 & TG3_FLG2_SERDES_PREEMPHASIS)) {
6267 /* Set drive transmission level to 1.2V */
6268 /* only if the signal pre-emphasis bit is not set */
6269 val = tr32(MAC_SERDES_CFG);
6270 val &= 0xfffff000;
6271 val |= 0x880;
6272 tw32(MAC_SERDES_CFG, val);
6273 }
6274 if (tp->pci_chip_rev_id == CHIPREV_ID_5703_A1)
6275 tw32(MAC_SERDES_CFG, 0x616000);
6276 }
6277
6278 /* Prevent chip from dropping frames when flow control
6279 * is enabled.
6280 */
6281 tw32_f(MAC_LOW_WMARK_MAX_RX_FRAME, 2);
6282
6283 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 &&
6284 (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)) {
6285 /* Use hardware link auto-negotiation */
6286 tp->tg3_flags2 |= TG3_FLG2_HW_AUTONEG;
6287 }
6288
d4d2c558
MC
6289 if ((tp->tg3_flags2 & TG3_FLG2_MII_SERDES) &&
6290 (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714)) {
6291 u32 tmp;
6292
6293 tmp = tr32(SERDES_RX_CTRL);
6294 tw32(SERDES_RX_CTRL, tmp | SERDES_RX_SIG_DETECT);
6295 tp->grc_local_ctrl &= ~GRC_LCLCTRL_USE_EXT_SIG_DETECT;
6296 tp->grc_local_ctrl |= GRC_LCLCTRL_USE_SIG_DETECT;
6297 tw32(GRC_LOCAL_CTRL, tp->grc_local_ctrl);
6298 }
6299
1da177e4
LT
6300 err = tg3_setup_phy(tp, 1);
6301 if (err)
6302 return err;
6303
6304 if (!(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)) {
6305 u32 tmp;
6306
6307 /* Clear CRC stats. */
6308 if (!tg3_readphy(tp, 0x1e, &tmp)) {
6309 tg3_writephy(tp, 0x1e, tmp | 0x8000);
6310 tg3_readphy(tp, 0x14, &tmp);
6311 }
6312 }
6313
6314 __tg3_set_rx_mode(tp->dev);
6315
6316 /* Initialize receive rules. */
6317 tw32(MAC_RCV_RULE_0, 0xc2000000 & RCV_RULE_DISABLE_MASK);
6318 tw32(MAC_RCV_VALUE_0, 0xffffffff & RCV_RULE_DISABLE_MASK);
6319 tw32(MAC_RCV_RULE_1, 0x86000004 & RCV_RULE_DISABLE_MASK);
6320 tw32(MAC_RCV_VALUE_1, 0xffffffff & RCV_RULE_DISABLE_MASK);
6321
4cf78e4f 6322 if ((tp->tg3_flags2 & TG3_FLG2_5705_PLUS) &&
a4e2b347 6323 !(tp->tg3_flags2 & TG3_FLG2_5780_CLASS))
1da177e4
LT
6324 limit = 8;
6325 else
6326 limit = 16;
6327 if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF)
6328 limit -= 4;
6329 switch (limit) {
6330 case 16:
6331 tw32(MAC_RCV_RULE_15, 0); tw32(MAC_RCV_VALUE_15, 0);
6332 case 15:
6333 tw32(MAC_RCV_RULE_14, 0); tw32(MAC_RCV_VALUE_14, 0);
6334 case 14:
6335 tw32(MAC_RCV_RULE_13, 0); tw32(MAC_RCV_VALUE_13, 0);
6336 case 13:
6337 tw32(MAC_RCV_RULE_12, 0); tw32(MAC_RCV_VALUE_12, 0);
6338 case 12:
6339 tw32(MAC_RCV_RULE_11, 0); tw32(MAC_RCV_VALUE_11, 0);
6340 case 11:
6341 tw32(MAC_RCV_RULE_10, 0); tw32(MAC_RCV_VALUE_10, 0);
6342 case 10:
6343 tw32(MAC_RCV_RULE_9, 0); tw32(MAC_RCV_VALUE_9, 0);
6344 case 9:
6345 tw32(MAC_RCV_RULE_8, 0); tw32(MAC_RCV_VALUE_8, 0);
6346 case 8:
6347 tw32(MAC_RCV_RULE_7, 0); tw32(MAC_RCV_VALUE_7, 0);
6348 case 7:
6349 tw32(MAC_RCV_RULE_6, 0); tw32(MAC_RCV_VALUE_6, 0);
6350 case 6:
6351 tw32(MAC_RCV_RULE_5, 0); tw32(MAC_RCV_VALUE_5, 0);
6352 case 5:
6353 tw32(MAC_RCV_RULE_4, 0); tw32(MAC_RCV_VALUE_4, 0);
6354 case 4:
6355 /* tw32(MAC_RCV_RULE_3, 0); tw32(MAC_RCV_VALUE_3, 0); */
6356 case 3:
6357 /* tw32(MAC_RCV_RULE_2, 0); tw32(MAC_RCV_VALUE_2, 0); */
6358 case 2:
6359 case 1:
6360
6361 default:
6362 break;
6363 };
6364
6365 tg3_write_sig_post_reset(tp, RESET_KIND_INIT);
6366
1da177e4
LT
6367 return 0;
6368}
6369
6370/* Called at device open time to get the chip ready for
6371 * packet processing. Invoked with tp->lock held.
6372 */
6373static int tg3_init_hw(struct tg3 *tp)
6374{
6375 int err;
6376
6377 /* Force the chip into D0. */
bc1c7567 6378 err = tg3_set_power_state(tp, PCI_D0);
1da177e4
LT
6379 if (err)
6380 goto out;
6381
6382 tg3_switch_clocks(tp);
6383
6384 tw32(TG3PCI_MEM_WIN_BASE_ADDR, 0);
6385
6386 err = tg3_reset_hw(tp);
6387
6388out:
6389 return err;
6390}
6391
6392#define TG3_STAT_ADD32(PSTAT, REG) \
6393do { u32 __val = tr32(REG); \
6394 (PSTAT)->low += __val; \
6395 if ((PSTAT)->low < __val) \
6396 (PSTAT)->high += 1; \
6397} while (0)
6398
6399static void tg3_periodic_fetch_stats(struct tg3 *tp)
6400{
6401 struct tg3_hw_stats *sp = tp->hw_stats;
6402
6403 if (!netif_carrier_ok(tp->dev))
6404 return;
6405
6406 TG3_STAT_ADD32(&sp->tx_octets, MAC_TX_STATS_OCTETS);
6407 TG3_STAT_ADD32(&sp->tx_collisions, MAC_TX_STATS_COLLISIONS);
6408 TG3_STAT_ADD32(&sp->tx_xon_sent, MAC_TX_STATS_XON_SENT);
6409 TG3_STAT_ADD32(&sp->tx_xoff_sent, MAC_TX_STATS_XOFF_SENT);
6410 TG3_STAT_ADD32(&sp->tx_mac_errors, MAC_TX_STATS_MAC_ERRORS);
6411 TG3_STAT_ADD32(&sp->tx_single_collisions, MAC_TX_STATS_SINGLE_COLLISIONS);
6412 TG3_STAT_ADD32(&sp->tx_mult_collisions, MAC_TX_STATS_MULT_COLLISIONS);
6413 TG3_STAT_ADD32(&sp->tx_deferred, MAC_TX_STATS_DEFERRED);
6414 TG3_STAT_ADD32(&sp->tx_excessive_collisions, MAC_TX_STATS_EXCESSIVE_COL);
6415 TG3_STAT_ADD32(&sp->tx_late_collisions, MAC_TX_STATS_LATE_COL);
6416 TG3_STAT_ADD32(&sp->tx_ucast_packets, MAC_TX_STATS_UCAST);
6417 TG3_STAT_ADD32(&sp->tx_mcast_packets, MAC_TX_STATS_MCAST);
6418 TG3_STAT_ADD32(&sp->tx_bcast_packets, MAC_TX_STATS_BCAST);
6419
6420 TG3_STAT_ADD32(&sp->rx_octets, MAC_RX_STATS_OCTETS);
6421 TG3_STAT_ADD32(&sp->rx_fragments, MAC_RX_STATS_FRAGMENTS);
6422 TG3_STAT_ADD32(&sp->rx_ucast_packets, MAC_RX_STATS_UCAST);
6423 TG3_STAT_ADD32(&sp->rx_mcast_packets, MAC_RX_STATS_MCAST);
6424 TG3_STAT_ADD32(&sp->rx_bcast_packets, MAC_RX_STATS_BCAST);
6425 TG3_STAT_ADD32(&sp->rx_fcs_errors, MAC_RX_STATS_FCS_ERRORS);
6426 TG3_STAT_ADD32(&sp->rx_align_errors, MAC_RX_STATS_ALIGN_ERRORS);
6427 TG3_STAT_ADD32(&sp->rx_xon_pause_rcvd, MAC_RX_STATS_XON_PAUSE_RECVD);
6428 TG3_STAT_ADD32(&sp->rx_xoff_pause_rcvd, MAC_RX_STATS_XOFF_PAUSE_RECVD);
6429 TG3_STAT_ADD32(&sp->rx_mac_ctrl_rcvd, MAC_RX_STATS_MAC_CTRL_RECVD);
6430 TG3_STAT_ADD32(&sp->rx_xoff_entered, MAC_RX_STATS_XOFF_ENTERED);
6431 TG3_STAT_ADD32(&sp->rx_frame_too_long_errors, MAC_RX_STATS_FRAME_TOO_LONG);
6432 TG3_STAT_ADD32(&sp->rx_jabbers, MAC_RX_STATS_JABBERS);
6433 TG3_STAT_ADD32(&sp->rx_undersize_packets, MAC_RX_STATS_UNDERSIZE);
6434}
6435
6436static void tg3_timer(unsigned long __opaque)
6437{
6438 struct tg3 *tp = (struct tg3 *) __opaque;
1da177e4 6439
f47c11ee 6440 spin_lock(&tp->lock);
1da177e4 6441
fac9b83e
DM
6442 if (!(tp->tg3_flags & TG3_FLAG_TAGGED_STATUS)) {
6443 /* All of this garbage is because when using non-tagged
6444 * IRQ status the mailbox/status_block protocol the chip
6445 * uses with the cpu is race prone.
6446 */
6447 if (tp->hw_status->status & SD_STATUS_UPDATED) {
6448 tw32(GRC_LOCAL_CTRL,
6449 tp->grc_local_ctrl | GRC_LCLCTRL_SETINT);
6450 } else {
6451 tw32(HOSTCC_MODE, tp->coalesce_mode |
6452 (HOSTCC_MODE_ENABLE | HOSTCC_MODE_NOW));
6453 }
1da177e4 6454
fac9b83e
DM
6455 if (!(tr32(WDMAC_MODE) & WDMAC_MODE_ENABLE)) {
6456 tp->tg3_flags2 |= TG3_FLG2_RESTART_TIMER;
f47c11ee 6457 spin_unlock(&tp->lock);
fac9b83e
DM
6458 schedule_work(&tp->reset_task);
6459 return;
6460 }
1da177e4
LT
6461 }
6462
1da177e4
LT
6463 /* This part only runs once per second. */
6464 if (!--tp->timer_counter) {
fac9b83e
DM
6465 if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS)
6466 tg3_periodic_fetch_stats(tp);
6467
1da177e4
LT
6468 if (tp->tg3_flags & TG3_FLAG_USE_LINKCHG_REG) {
6469 u32 mac_stat;
6470 int phy_event;
6471
6472 mac_stat = tr32(MAC_STATUS);
6473
6474 phy_event = 0;
6475 if (tp->tg3_flags & TG3_FLAG_USE_MI_INTERRUPT) {
6476 if (mac_stat & MAC_STATUS_MI_INTERRUPT)
6477 phy_event = 1;
6478 } else if (mac_stat & MAC_STATUS_LNKSTATE_CHANGED)
6479 phy_event = 1;
6480
6481 if (phy_event)
6482 tg3_setup_phy(tp, 0);
6483 } else if (tp->tg3_flags & TG3_FLAG_POLL_SERDES) {
6484 u32 mac_stat = tr32(MAC_STATUS);
6485 int need_setup = 0;
6486
6487 if (netif_carrier_ok(tp->dev) &&
6488 (mac_stat & MAC_STATUS_LNKSTATE_CHANGED)) {
6489 need_setup = 1;
6490 }
6491 if (! netif_carrier_ok(tp->dev) &&
6492 (mac_stat & (MAC_STATUS_PCS_SYNCED |
6493 MAC_STATUS_SIGNAL_DET))) {
6494 need_setup = 1;
6495 }
6496 if (need_setup) {
6497 tw32_f(MAC_MODE,
6498 (tp->mac_mode &
6499 ~MAC_MODE_PORT_MODE_MASK));
6500 udelay(40);
6501 tw32_f(MAC_MODE, tp->mac_mode);
6502 udelay(40);
6503 tg3_setup_phy(tp, 0);
6504 }
747e8f8b
MC
6505 } else if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES)
6506 tg3_serdes_parallel_detect(tp);
1da177e4
LT
6507
6508 tp->timer_counter = tp->timer_multiplier;
6509 }
6510
28fbef78 6511 /* Heartbeat is only sent once every 2 seconds. */
1da177e4
LT
6512 if (!--tp->asf_counter) {
6513 if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) {
6514 u32 val;
6515
28fbef78
MC
6516 tg3_write_mem_fast(tp, NIC_SRAM_FW_CMD_MBOX,
6517 FWCMD_NICDRV_ALIVE2);
6518 tg3_write_mem_fast(tp, NIC_SRAM_FW_CMD_LEN_MBOX, 4);
6519 /* 5 seconds timeout */
6520 tg3_write_mem_fast(tp, NIC_SRAM_FW_CMD_DATA_MBOX, 5);
1da177e4
LT
6521 val = tr32(GRC_RX_CPU_EVENT);
6522 val |= (1 << 14);
6523 tw32(GRC_RX_CPU_EVENT, val);
6524 }
6525 tp->asf_counter = tp->asf_multiplier;
6526 }
6527
f47c11ee 6528 spin_unlock(&tp->lock);
1da177e4
LT
6529
6530 tp->timer.expires = jiffies + tp->timer_offset;
6531 add_timer(&tp->timer);
6532}
6533
fcfa0a32
MC
6534int tg3_request_irq(struct tg3 *tp)
6535{
6536 irqreturn_t (*fn)(int, void *, struct pt_regs *);
6537 unsigned long flags;
6538 struct net_device *dev = tp->dev;
6539
6540 if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
6541 fn = tg3_msi;
6542 if (tp->tg3_flags2 & TG3_FLG2_1SHOT_MSI)
6543 fn = tg3_msi_1shot;
6544 flags = SA_SAMPLE_RANDOM;
6545 } else {
6546 fn = tg3_interrupt;
6547 if (tp->tg3_flags & TG3_FLAG_TAGGED_STATUS)
6548 fn = tg3_interrupt_tagged;
6549 flags = SA_SHIRQ | SA_SAMPLE_RANDOM;
6550 }
6551 return (request_irq(tp->pdev->irq, fn, flags, dev->name, dev));
6552}
6553
7938109f
MC
6554static int tg3_test_interrupt(struct tg3 *tp)
6555{
6556 struct net_device *dev = tp->dev;
6557 int err, i;
6558 u32 int_mbox = 0;
6559
d4bc3927
MC
6560 if (!netif_running(dev))
6561 return -ENODEV;
6562
7938109f
MC
6563 tg3_disable_ints(tp);
6564
6565 free_irq(tp->pdev->irq, dev);
6566
6567 err = request_irq(tp->pdev->irq, tg3_test_isr,
f4d0ee98 6568 SA_SHIRQ | SA_SAMPLE_RANDOM, dev->name, dev);
7938109f
MC
6569 if (err)
6570 return err;
6571
38f3843e 6572 tp->hw_status->status &= ~SD_STATUS_UPDATED;
7938109f
MC
6573 tg3_enable_ints(tp);
6574
6575 tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE |
6576 HOSTCC_MODE_NOW);
6577
6578 for (i = 0; i < 5; i++) {
09ee929c
MC
6579 int_mbox = tr32_mailbox(MAILBOX_INTERRUPT_0 +
6580 TG3_64BIT_REG_LOW);
7938109f
MC
6581 if (int_mbox != 0)
6582 break;
6583 msleep(10);
6584 }
6585
6586 tg3_disable_ints(tp);
6587
6588 free_irq(tp->pdev->irq, dev);
6589
fcfa0a32 6590 err = tg3_request_irq(tp);
7938109f
MC
6591
6592 if (err)
6593 return err;
6594
6595 if (int_mbox != 0)
6596 return 0;
6597
6598 return -EIO;
6599}
6600
6601/* Returns 0 if MSI test succeeds or MSI test fails and INTx mode is
6602 * successfully restored
6603 */
6604static int tg3_test_msi(struct tg3 *tp)
6605{
6606 struct net_device *dev = tp->dev;
6607 int err;
6608 u16 pci_cmd;
6609
6610 if (!(tp->tg3_flags2 & TG3_FLG2_USING_MSI))
6611 return 0;
6612
6613 /* Turn off SERR reporting in case MSI terminates with Master
6614 * Abort.
6615 */
6616 pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd);
6617 pci_write_config_word(tp->pdev, PCI_COMMAND,
6618 pci_cmd & ~PCI_COMMAND_SERR);
6619
6620 err = tg3_test_interrupt(tp);
6621
6622 pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd);
6623
6624 if (!err)
6625 return 0;
6626
6627 /* other failures */
6628 if (err != -EIO)
6629 return err;
6630
6631 /* MSI test failed, go back to INTx mode */
6632 printk(KERN_WARNING PFX "%s: No interrupt was generated using MSI, "
6633 "switching to INTx mode. Please report this failure to "
6634 "the PCI maintainer and include system chipset information.\n",
6635 tp->dev->name);
6636
6637 free_irq(tp->pdev->irq, dev);
6638 pci_disable_msi(tp->pdev);
6639
6640 tp->tg3_flags2 &= ~TG3_FLG2_USING_MSI;
6641
fcfa0a32 6642 err = tg3_request_irq(tp);
7938109f
MC
6643 if (err)
6644 return err;
6645
6646 /* Need to reset the chip because the MSI cycle may have terminated
6647 * with Master Abort.
6648 */
f47c11ee 6649 tg3_full_lock(tp, 1);
7938109f 6650
944d980e 6651 tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
7938109f
MC
6652 err = tg3_init_hw(tp);
6653
f47c11ee 6654 tg3_full_unlock(tp);
7938109f
MC
6655
6656 if (err)
6657 free_irq(tp->pdev->irq, dev);
6658
6659 return err;
6660}
6661
1da177e4
LT
6662static int tg3_open(struct net_device *dev)
6663{
6664 struct tg3 *tp = netdev_priv(dev);
6665 int err;
6666
f47c11ee 6667 tg3_full_lock(tp, 0);
1da177e4 6668
bc1c7567
MC
6669 err = tg3_set_power_state(tp, PCI_D0);
6670 if (err)
6671 return err;
6672
1da177e4
LT
6673 tg3_disable_ints(tp);
6674 tp->tg3_flags &= ~TG3_FLAG_INIT_COMPLETE;
6675
f47c11ee 6676 tg3_full_unlock(tp);
1da177e4
LT
6677
6678 /* The placement of this call is tied
6679 * to the setup and use of Host TX descriptors.
6680 */
6681 err = tg3_alloc_consistent(tp);
6682 if (err)
6683 return err;
6684
88b06bc2
MC
6685 if ((tp->tg3_flags2 & TG3_FLG2_5750_PLUS) &&
6686 (GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5750_AX) &&
d4d2c558
MC
6687 (GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5750_BX) &&
6688 !((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) &&
6689 (tp->pdev_peer == tp->pdev))) {
fac9b83e
DM
6690 /* All MSI supporting chips should support tagged
6691 * status. Assert that this is the case.
6692 */
6693 if (!(tp->tg3_flags & TG3_FLAG_TAGGED_STATUS)) {
6694 printk(KERN_WARNING PFX "%s: MSI without TAGGED? "
6695 "Not using MSI.\n", tp->dev->name);
6696 } else if (pci_enable_msi(tp->pdev) == 0) {
88b06bc2
MC
6697 u32 msi_mode;
6698
6699 msi_mode = tr32(MSGINT_MODE);
6700 tw32(MSGINT_MODE, msi_mode | MSGINT_MODE_ENABLE);
6701 tp->tg3_flags2 |= TG3_FLG2_USING_MSI;
6702 }
6703 }
fcfa0a32 6704 err = tg3_request_irq(tp);
1da177e4
LT
6705
6706 if (err) {
88b06bc2
MC
6707 if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
6708 pci_disable_msi(tp->pdev);
6709 tp->tg3_flags2 &= ~TG3_FLG2_USING_MSI;
6710 }
1da177e4
LT
6711 tg3_free_consistent(tp);
6712 return err;
6713 }
6714
f47c11ee 6715 tg3_full_lock(tp, 0);
1da177e4
LT
6716
6717 err = tg3_init_hw(tp);
6718 if (err) {
944d980e 6719 tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
1da177e4
LT
6720 tg3_free_rings(tp);
6721 } else {
fac9b83e
DM
6722 if (tp->tg3_flags & TG3_FLAG_TAGGED_STATUS)
6723 tp->timer_offset = HZ;
6724 else
6725 tp->timer_offset = HZ / 10;
6726
6727 BUG_ON(tp->timer_offset > HZ);
6728 tp->timer_counter = tp->timer_multiplier =
6729 (HZ / tp->timer_offset);
6730 tp->asf_counter = tp->asf_multiplier =
28fbef78 6731 ((HZ / tp->timer_offset) * 2);
1da177e4
LT
6732
6733 init_timer(&tp->timer);
6734 tp->timer.expires = jiffies + tp->timer_offset;
6735 tp->timer.data = (unsigned long) tp;
6736 tp->timer.function = tg3_timer;
1da177e4
LT
6737 }
6738
f47c11ee 6739 tg3_full_unlock(tp);
1da177e4
LT
6740
6741 if (err) {
88b06bc2
MC
6742 free_irq(tp->pdev->irq, dev);
6743 if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
6744 pci_disable_msi(tp->pdev);
6745 tp->tg3_flags2 &= ~TG3_FLG2_USING_MSI;
6746 }
1da177e4
LT
6747 tg3_free_consistent(tp);
6748 return err;
6749 }
6750
7938109f
MC
6751 if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
6752 err = tg3_test_msi(tp);
fac9b83e 6753
7938109f 6754 if (err) {
f47c11ee 6755 tg3_full_lock(tp, 0);
7938109f
MC
6756
6757 if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
6758 pci_disable_msi(tp->pdev);
6759 tp->tg3_flags2 &= ~TG3_FLG2_USING_MSI;
6760 }
944d980e 6761 tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
7938109f
MC
6762 tg3_free_rings(tp);
6763 tg3_free_consistent(tp);
6764
f47c11ee 6765 tg3_full_unlock(tp);
7938109f
MC
6766
6767 return err;
6768 }
fcfa0a32
MC
6769
6770 if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
6771 if (tp->tg3_flags2 & TG3_FLG2_1SHOT_MSI) {
6772 u32 val = tr32(0x7c04);
6773
6774 tw32(0x7c04, val | (1 << 29));
6775 }
6776 }
7938109f
MC
6777 }
6778
f47c11ee 6779 tg3_full_lock(tp, 0);
1da177e4 6780
7938109f
MC
6781 add_timer(&tp->timer);
6782 tp->tg3_flags |= TG3_FLAG_INIT_COMPLETE;
1da177e4
LT
6783 tg3_enable_ints(tp);
6784
f47c11ee 6785 tg3_full_unlock(tp);
1da177e4
LT
6786
6787 netif_start_queue(dev);
6788
6789 return 0;
6790}
6791
6792#if 0
6793/*static*/ void tg3_dump_state(struct tg3 *tp)
6794{
6795 u32 val32, val32_2, val32_3, val32_4, val32_5;
6796 u16 val16;
6797 int i;
6798
6799 pci_read_config_word(tp->pdev, PCI_STATUS, &val16);
6800 pci_read_config_dword(tp->pdev, TG3PCI_PCISTATE, &val32);
6801 printk("DEBUG: PCI status [%04x] TG3PCI state[%08x]\n",
6802 val16, val32);
6803
6804 /* MAC block */
6805 printk("DEBUG: MAC_MODE[%08x] MAC_STATUS[%08x]\n",
6806 tr32(MAC_MODE), tr32(MAC_STATUS));
6807 printk(" MAC_EVENT[%08x] MAC_LED_CTRL[%08x]\n",
6808 tr32(MAC_EVENT), tr32(MAC_LED_CTRL));
6809 printk("DEBUG: MAC_TX_MODE[%08x] MAC_TX_STATUS[%08x]\n",
6810 tr32(MAC_TX_MODE), tr32(MAC_TX_STATUS));
6811 printk(" MAC_RX_MODE[%08x] MAC_RX_STATUS[%08x]\n",
6812 tr32(MAC_RX_MODE), tr32(MAC_RX_STATUS));
6813
6814 /* Send data initiator control block */
6815 printk("DEBUG: SNDDATAI_MODE[%08x] SNDDATAI_STATUS[%08x]\n",
6816 tr32(SNDDATAI_MODE), tr32(SNDDATAI_STATUS));
6817 printk(" SNDDATAI_STATSCTRL[%08x]\n",
6818 tr32(SNDDATAI_STATSCTRL));
6819
6820 /* Send data completion control block */
6821 printk("DEBUG: SNDDATAC_MODE[%08x]\n", tr32(SNDDATAC_MODE));
6822
6823 /* Send BD ring selector block */
6824 printk("DEBUG: SNDBDS_MODE[%08x] SNDBDS_STATUS[%08x]\n",
6825 tr32(SNDBDS_MODE), tr32(SNDBDS_STATUS));
6826
6827 /* Send BD initiator control block */
6828 printk("DEBUG: SNDBDI_MODE[%08x] SNDBDI_STATUS[%08x]\n",
6829 tr32(SNDBDI_MODE), tr32(SNDBDI_STATUS));
6830
6831 /* Send BD completion control block */
6832 printk("DEBUG: SNDBDC_MODE[%08x]\n", tr32(SNDBDC_MODE));
6833
6834 /* Receive list placement control block */
6835 printk("DEBUG: RCVLPC_MODE[%08x] RCVLPC_STATUS[%08x]\n",
6836 tr32(RCVLPC_MODE), tr32(RCVLPC_STATUS));
6837 printk(" RCVLPC_STATSCTRL[%08x]\n",
6838 tr32(RCVLPC_STATSCTRL));
6839
6840 /* Receive data and receive BD initiator control block */
6841 printk("DEBUG: RCVDBDI_MODE[%08x] RCVDBDI_STATUS[%08x]\n",
6842 tr32(RCVDBDI_MODE), tr32(RCVDBDI_STATUS));
6843
6844 /* Receive data completion control block */
6845 printk("DEBUG: RCVDCC_MODE[%08x]\n",
6846 tr32(RCVDCC_MODE));
6847
6848 /* Receive BD initiator control block */
6849 printk("DEBUG: RCVBDI_MODE[%08x] RCVBDI_STATUS[%08x]\n",
6850 tr32(RCVBDI_MODE), tr32(RCVBDI_STATUS));
6851
6852 /* Receive BD completion control block */
6853 printk("DEBUG: RCVCC_MODE[%08x] RCVCC_STATUS[%08x]\n",
6854 tr32(RCVCC_MODE), tr32(RCVCC_STATUS));
6855
6856 /* Receive list selector control block */
6857 printk("DEBUG: RCVLSC_MODE[%08x] RCVLSC_STATUS[%08x]\n",
6858 tr32(RCVLSC_MODE), tr32(RCVLSC_STATUS));
6859
6860 /* Mbuf cluster free block */
6861 printk("DEBUG: MBFREE_MODE[%08x] MBFREE_STATUS[%08x]\n",
6862 tr32(MBFREE_MODE), tr32(MBFREE_STATUS));
6863
6864 /* Host coalescing control block */
6865 printk("DEBUG: HOSTCC_MODE[%08x] HOSTCC_STATUS[%08x]\n",
6866 tr32(HOSTCC_MODE), tr32(HOSTCC_STATUS));
6867 printk("DEBUG: HOSTCC_STATS_BLK_HOST_ADDR[%08x%08x]\n",
6868 tr32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH),
6869 tr32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW));
6870 printk("DEBUG: HOSTCC_STATUS_BLK_HOST_ADDR[%08x%08x]\n",
6871 tr32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH),
6872 tr32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW));
6873 printk("DEBUG: HOSTCC_STATS_BLK_NIC_ADDR[%08x]\n",
6874 tr32(HOSTCC_STATS_BLK_NIC_ADDR));
6875 printk("DEBUG: HOSTCC_STATUS_BLK_NIC_ADDR[%08x]\n",
6876 tr32(HOSTCC_STATUS_BLK_NIC_ADDR));
6877
6878 /* Memory arbiter control block */
6879 printk("DEBUG: MEMARB_MODE[%08x] MEMARB_STATUS[%08x]\n",
6880 tr32(MEMARB_MODE), tr32(MEMARB_STATUS));
6881
6882 /* Buffer manager control block */
6883 printk("DEBUG: BUFMGR_MODE[%08x] BUFMGR_STATUS[%08x]\n",
6884 tr32(BUFMGR_MODE), tr32(BUFMGR_STATUS));
6885 printk("DEBUG: BUFMGR_MB_POOL_ADDR[%08x] BUFMGR_MB_POOL_SIZE[%08x]\n",
6886 tr32(BUFMGR_MB_POOL_ADDR), tr32(BUFMGR_MB_POOL_SIZE));
6887 printk("DEBUG: BUFMGR_DMA_DESC_POOL_ADDR[%08x] "
6888 "BUFMGR_DMA_DESC_POOL_SIZE[%08x]\n",
6889 tr32(BUFMGR_DMA_DESC_POOL_ADDR),
6890 tr32(BUFMGR_DMA_DESC_POOL_SIZE));
6891
6892 /* Read DMA control block */
6893 printk("DEBUG: RDMAC_MODE[%08x] RDMAC_STATUS[%08x]\n",
6894 tr32(RDMAC_MODE), tr32(RDMAC_STATUS));
6895
6896 /* Write DMA control block */
6897 printk("DEBUG: WDMAC_MODE[%08x] WDMAC_STATUS[%08x]\n",
6898 tr32(WDMAC_MODE), tr32(WDMAC_STATUS));
6899
6900 /* DMA completion block */
6901 printk("DEBUG: DMAC_MODE[%08x]\n",
6902 tr32(DMAC_MODE));
6903
6904 /* GRC block */
6905 printk("DEBUG: GRC_MODE[%08x] GRC_MISC_CFG[%08x]\n",
6906 tr32(GRC_MODE), tr32(GRC_MISC_CFG));
6907 printk("DEBUG: GRC_LOCAL_CTRL[%08x]\n",
6908 tr32(GRC_LOCAL_CTRL));
6909
6910 /* TG3_BDINFOs */
6911 printk("DEBUG: RCVDBDI_JUMBO_BD[%08x%08x:%08x:%08x]\n",
6912 tr32(RCVDBDI_JUMBO_BD + 0x0),
6913 tr32(RCVDBDI_JUMBO_BD + 0x4),
6914 tr32(RCVDBDI_JUMBO_BD + 0x8),
6915 tr32(RCVDBDI_JUMBO_BD + 0xc));
6916 printk("DEBUG: RCVDBDI_STD_BD[%08x%08x:%08x:%08x]\n",
6917 tr32(RCVDBDI_STD_BD + 0x0),
6918 tr32(RCVDBDI_STD_BD + 0x4),
6919 tr32(RCVDBDI_STD_BD + 0x8),
6920 tr32(RCVDBDI_STD_BD + 0xc));
6921 printk("DEBUG: RCVDBDI_MINI_BD[%08x%08x:%08x:%08x]\n",
6922 tr32(RCVDBDI_MINI_BD + 0x0),
6923 tr32(RCVDBDI_MINI_BD + 0x4),
6924 tr32(RCVDBDI_MINI_BD + 0x8),
6925 tr32(RCVDBDI_MINI_BD + 0xc));
6926
6927 tg3_read_mem(tp, NIC_SRAM_SEND_RCB + 0x0, &val32);
6928 tg3_read_mem(tp, NIC_SRAM_SEND_RCB + 0x4, &val32_2);
6929 tg3_read_mem(tp, NIC_SRAM_SEND_RCB + 0x8, &val32_3);
6930 tg3_read_mem(tp, NIC_SRAM_SEND_RCB + 0xc, &val32_4);
6931 printk("DEBUG: SRAM_SEND_RCB_0[%08x%08x:%08x:%08x]\n",
6932 val32, val32_2, val32_3, val32_4);
6933
6934 tg3_read_mem(tp, NIC_SRAM_RCV_RET_RCB + 0x0, &val32);
6935 tg3_read_mem(tp, NIC_SRAM_RCV_RET_RCB + 0x4, &val32_2);
6936 tg3_read_mem(tp, NIC_SRAM_RCV_RET_RCB + 0x8, &val32_3);
6937 tg3_read_mem(tp, NIC_SRAM_RCV_RET_RCB + 0xc, &val32_4);
6938 printk("DEBUG: SRAM_RCV_RET_RCB_0[%08x%08x:%08x:%08x]\n",
6939 val32, val32_2, val32_3, val32_4);
6940
6941 tg3_read_mem(tp, NIC_SRAM_STATUS_BLK + 0x0, &val32);
6942 tg3_read_mem(tp, NIC_SRAM_STATUS_BLK + 0x4, &val32_2);
6943 tg3_read_mem(tp, NIC_SRAM_STATUS_BLK + 0x8, &val32_3);
6944 tg3_read_mem(tp, NIC_SRAM_STATUS_BLK + 0xc, &val32_4);
6945 tg3_read_mem(tp, NIC_SRAM_STATUS_BLK + 0x10, &val32_5);
6946 printk("DEBUG: SRAM_STATUS_BLK[%08x:%08x:%08x:%08x:%08x]\n",
6947 val32, val32_2, val32_3, val32_4, val32_5);
6948
6949 /* SW status block */
6950 printk("DEBUG: Host status block [%08x:%08x:(%04x:%04x:%04x):(%04x:%04x)]\n",
6951 tp->hw_status->status,
6952 tp->hw_status->status_tag,
6953 tp->hw_status->rx_jumbo_consumer,
6954 tp->hw_status->rx_consumer,
6955 tp->hw_status->rx_mini_consumer,
6956 tp->hw_status->idx[0].rx_producer,
6957 tp->hw_status->idx[0].tx_consumer);
6958
6959 /* SW statistics block */
6960 printk("DEBUG: Host statistics block [%08x:%08x:%08x:%08x]\n",
6961 ((u32 *)tp->hw_stats)[0],
6962 ((u32 *)tp->hw_stats)[1],
6963 ((u32 *)tp->hw_stats)[2],
6964 ((u32 *)tp->hw_stats)[3]);
6965
6966 /* Mailboxes */
6967 printk("DEBUG: SNDHOST_PROD[%08x%08x] SNDNIC_PROD[%08x%08x]\n",
09ee929c
MC
6968 tr32_mailbox(MAILBOX_SNDHOST_PROD_IDX_0 + 0x0),
6969 tr32_mailbox(MAILBOX_SNDHOST_PROD_IDX_0 + 0x4),
6970 tr32_mailbox(MAILBOX_SNDNIC_PROD_IDX_0 + 0x0),
6971 tr32_mailbox(MAILBOX_SNDNIC_PROD_IDX_0 + 0x4));
1da177e4
LT
6972
6973 /* NIC side send descriptors. */
6974 for (i = 0; i < 6; i++) {
6975 unsigned long txd;
6976
6977 txd = tp->regs + NIC_SRAM_WIN_BASE + NIC_SRAM_TX_BUFFER_DESC
6978 + (i * sizeof(struct tg3_tx_buffer_desc));
6979 printk("DEBUG: NIC TXD(%d)[%08x:%08x:%08x:%08x]\n",
6980 i,
6981 readl(txd + 0x0), readl(txd + 0x4),
6982 readl(txd + 0x8), readl(txd + 0xc));
6983 }
6984
6985 /* NIC side RX descriptors. */
6986 for (i = 0; i < 6; i++) {
6987 unsigned long rxd;
6988
6989 rxd = tp->regs + NIC_SRAM_WIN_BASE + NIC_SRAM_RX_BUFFER_DESC
6990 + (i * sizeof(struct tg3_rx_buffer_desc));
6991 printk("DEBUG: NIC RXD_STD(%d)[0][%08x:%08x:%08x:%08x]\n",
6992 i,
6993 readl(rxd + 0x0), readl(rxd + 0x4),
6994 readl(rxd + 0x8), readl(rxd + 0xc));
6995 rxd += (4 * sizeof(u32));
6996 printk("DEBUG: NIC RXD_STD(%d)[1][%08x:%08x:%08x:%08x]\n",
6997 i,
6998 readl(rxd + 0x0), readl(rxd + 0x4),
6999 readl(rxd + 0x8), readl(rxd + 0xc));
7000 }
7001
7002 for (i = 0; i < 6; i++) {
7003 unsigned long rxd;
7004
7005 rxd = tp->regs + NIC_SRAM_WIN_BASE + NIC_SRAM_RX_JUMBO_BUFFER_DESC
7006 + (i * sizeof(struct tg3_rx_buffer_desc));
7007 printk("DEBUG: NIC RXD_JUMBO(%d)[0][%08x:%08x:%08x:%08x]\n",
7008 i,
7009 readl(rxd + 0x0), readl(rxd + 0x4),
7010 readl(rxd + 0x8), readl(rxd + 0xc));
7011 rxd += (4 * sizeof(u32));
7012 printk("DEBUG: NIC RXD_JUMBO(%d)[1][%08x:%08x:%08x:%08x]\n",
7013 i,
7014 readl(rxd + 0x0), readl(rxd + 0x4),
7015 readl(rxd + 0x8), readl(rxd + 0xc));
7016 }
7017}
7018#endif
7019
7020static struct net_device_stats *tg3_get_stats(struct net_device *);
7021static struct tg3_ethtool_stats *tg3_get_estats(struct tg3 *);
7022
7023static int tg3_close(struct net_device *dev)
7024{
7025 struct tg3 *tp = netdev_priv(dev);
7026
7faa006f
MC
7027 /* Calling flush_scheduled_work() may deadlock because
7028 * linkwatch_event() may be on the workqueue and it will try to get
7029 * the rtnl_lock which we are holding.
7030 */
7031 while (tp->tg3_flags & TG3_FLAG_IN_RESET_TASK)
7032 msleep(1);
7033
1da177e4
LT
7034 netif_stop_queue(dev);
7035
7036 del_timer_sync(&tp->timer);
7037
f47c11ee 7038 tg3_full_lock(tp, 1);
1da177e4
LT
7039#if 0
7040 tg3_dump_state(tp);
7041#endif
7042
7043 tg3_disable_ints(tp);
7044
944d980e 7045 tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
1da177e4
LT
7046 tg3_free_rings(tp);
7047 tp->tg3_flags &=
7048 ~(TG3_FLAG_INIT_COMPLETE |
7049 TG3_FLAG_GOT_SERDES_FLOWCTL);
1da177e4 7050
f47c11ee 7051 tg3_full_unlock(tp);
1da177e4 7052
88b06bc2
MC
7053 free_irq(tp->pdev->irq, dev);
7054 if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
7055 pci_disable_msi(tp->pdev);
7056 tp->tg3_flags2 &= ~TG3_FLG2_USING_MSI;
7057 }
1da177e4
LT
7058
7059 memcpy(&tp->net_stats_prev, tg3_get_stats(tp->dev),
7060 sizeof(tp->net_stats_prev));
7061 memcpy(&tp->estats_prev, tg3_get_estats(tp),
7062 sizeof(tp->estats_prev));
7063
7064 tg3_free_consistent(tp);
7065
bc1c7567
MC
7066 tg3_set_power_state(tp, PCI_D3hot);
7067
7068 netif_carrier_off(tp->dev);
7069
1da177e4
LT
7070 return 0;
7071}
7072
7073static inline unsigned long get_stat64(tg3_stat64_t *val)
7074{
7075 unsigned long ret;
7076
7077#if (BITS_PER_LONG == 32)
7078 ret = val->low;
7079#else
7080 ret = ((u64)val->high << 32) | ((u64)val->low);
7081#endif
7082 return ret;
7083}
7084
7085static unsigned long calc_crc_errors(struct tg3 *tp)
7086{
7087 struct tg3_hw_stats *hw_stats = tp->hw_stats;
7088
7089 if (!(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) &&
7090 (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
7091 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701)) {
1da177e4
LT
7092 u32 val;
7093
f47c11ee 7094 spin_lock_bh(&tp->lock);
1da177e4
LT
7095 if (!tg3_readphy(tp, 0x1e, &val)) {
7096 tg3_writephy(tp, 0x1e, val | 0x8000);
7097 tg3_readphy(tp, 0x14, &val);
7098 } else
7099 val = 0;
f47c11ee 7100 spin_unlock_bh(&tp->lock);
1da177e4
LT
7101
7102 tp->phy_crc_errors += val;
7103
7104 return tp->phy_crc_errors;
7105 }
7106
7107 return get_stat64(&hw_stats->rx_fcs_errors);
7108}
7109
7110#define ESTAT_ADD(member) \
7111 estats->member = old_estats->member + \
7112 get_stat64(&hw_stats->member)
7113
7114static struct tg3_ethtool_stats *tg3_get_estats(struct tg3 *tp)
7115{
7116 struct tg3_ethtool_stats *estats = &tp->estats;
7117 struct tg3_ethtool_stats *old_estats = &tp->estats_prev;
7118 struct tg3_hw_stats *hw_stats = tp->hw_stats;
7119
7120 if (!hw_stats)
7121 return old_estats;
7122
7123 ESTAT_ADD(rx_octets);
7124 ESTAT_ADD(rx_fragments);
7125 ESTAT_ADD(rx_ucast_packets);
7126 ESTAT_ADD(rx_mcast_packets);
7127 ESTAT_ADD(rx_bcast_packets);
7128 ESTAT_ADD(rx_fcs_errors);
7129 ESTAT_ADD(rx_align_errors);
7130 ESTAT_ADD(rx_xon_pause_rcvd);
7131 ESTAT_ADD(rx_xoff_pause_rcvd);
7132 ESTAT_ADD(rx_mac_ctrl_rcvd);
7133 ESTAT_ADD(rx_xoff_entered);
7134 ESTAT_ADD(rx_frame_too_long_errors);
7135 ESTAT_ADD(rx_jabbers);
7136 ESTAT_ADD(rx_undersize_packets);
7137 ESTAT_ADD(rx_in_length_errors);
7138 ESTAT_ADD(rx_out_length_errors);
7139 ESTAT_ADD(rx_64_or_less_octet_packets);
7140 ESTAT_ADD(rx_65_to_127_octet_packets);
7141 ESTAT_ADD(rx_128_to_255_octet_packets);
7142 ESTAT_ADD(rx_256_to_511_octet_packets);
7143 ESTAT_ADD(rx_512_to_1023_octet_packets);
7144 ESTAT_ADD(rx_1024_to_1522_octet_packets);
7145 ESTAT_ADD(rx_1523_to_2047_octet_packets);
7146 ESTAT_ADD(rx_2048_to_4095_octet_packets);
7147 ESTAT_ADD(rx_4096_to_8191_octet_packets);
7148 ESTAT_ADD(rx_8192_to_9022_octet_packets);
7149
7150 ESTAT_ADD(tx_octets);
7151 ESTAT_ADD(tx_collisions);
7152 ESTAT_ADD(tx_xon_sent);
7153 ESTAT_ADD(tx_xoff_sent);
7154 ESTAT_ADD(tx_flow_control);
7155 ESTAT_ADD(tx_mac_errors);
7156 ESTAT_ADD(tx_single_collisions);
7157 ESTAT_ADD(tx_mult_collisions);
7158 ESTAT_ADD(tx_deferred);
7159 ESTAT_ADD(tx_excessive_collisions);
7160 ESTAT_ADD(tx_late_collisions);
7161 ESTAT_ADD(tx_collide_2times);
7162 ESTAT_ADD(tx_collide_3times);
7163 ESTAT_ADD(tx_collide_4times);
7164 ESTAT_ADD(tx_collide_5times);
7165 ESTAT_ADD(tx_collide_6times);
7166 ESTAT_ADD(tx_collide_7times);
7167 ESTAT_ADD(tx_collide_8times);
7168 ESTAT_ADD(tx_collide_9times);
7169 ESTAT_ADD(tx_collide_10times);
7170 ESTAT_ADD(tx_collide_11times);
7171 ESTAT_ADD(tx_collide_12times);
7172 ESTAT_ADD(tx_collide_13times);
7173 ESTAT_ADD(tx_collide_14times);
7174 ESTAT_ADD(tx_collide_15times);
7175 ESTAT_ADD(tx_ucast_packets);
7176 ESTAT_ADD(tx_mcast_packets);
7177 ESTAT_ADD(tx_bcast_packets);
7178 ESTAT_ADD(tx_carrier_sense_errors);
7179 ESTAT_ADD(tx_discards);
7180 ESTAT_ADD(tx_errors);
7181
7182 ESTAT_ADD(dma_writeq_full);
7183 ESTAT_ADD(dma_write_prioq_full);
7184 ESTAT_ADD(rxbds_empty);
7185 ESTAT_ADD(rx_discards);
7186 ESTAT_ADD(rx_errors);
7187 ESTAT_ADD(rx_threshold_hit);
7188
7189 ESTAT_ADD(dma_readq_full);
7190 ESTAT_ADD(dma_read_prioq_full);
7191 ESTAT_ADD(tx_comp_queue_full);
7192
7193 ESTAT_ADD(ring_set_send_prod_index);
7194 ESTAT_ADD(ring_status_update);
7195 ESTAT_ADD(nic_irqs);
7196 ESTAT_ADD(nic_avoided_irqs);
7197 ESTAT_ADD(nic_tx_threshold_hit);
7198
7199 return estats;
7200}
7201
7202static struct net_device_stats *tg3_get_stats(struct net_device *dev)
7203{
7204 struct tg3 *tp = netdev_priv(dev);
7205 struct net_device_stats *stats = &tp->net_stats;
7206 struct net_device_stats *old_stats = &tp->net_stats_prev;
7207 struct tg3_hw_stats *hw_stats = tp->hw_stats;
7208
7209 if (!hw_stats)
7210 return old_stats;
7211
7212 stats->rx_packets = old_stats->rx_packets +
7213 get_stat64(&hw_stats->rx_ucast_packets) +
7214 get_stat64(&hw_stats->rx_mcast_packets) +
7215 get_stat64(&hw_stats->rx_bcast_packets);
7216
7217 stats->tx_packets = old_stats->tx_packets +
7218 get_stat64(&hw_stats->tx_ucast_packets) +
7219 get_stat64(&hw_stats->tx_mcast_packets) +
7220 get_stat64(&hw_stats->tx_bcast_packets);
7221
7222 stats->rx_bytes = old_stats->rx_bytes +
7223 get_stat64(&hw_stats->rx_octets);
7224 stats->tx_bytes = old_stats->tx_bytes +
7225 get_stat64(&hw_stats->tx_octets);
7226
7227 stats->rx_errors = old_stats->rx_errors +
4f63b877 7228 get_stat64(&hw_stats->rx_errors);
1da177e4
LT
7229 stats->tx_errors = old_stats->tx_errors +
7230 get_stat64(&hw_stats->tx_errors) +
7231 get_stat64(&hw_stats->tx_mac_errors) +
7232 get_stat64(&hw_stats->tx_carrier_sense_errors) +
7233 get_stat64(&hw_stats->tx_discards);
7234
7235 stats->multicast = old_stats->multicast +
7236 get_stat64(&hw_stats->rx_mcast_packets);
7237 stats->collisions = old_stats->collisions +
7238 get_stat64(&hw_stats->tx_collisions);
7239
7240 stats->rx_length_errors = old_stats->rx_length_errors +
7241 get_stat64(&hw_stats->rx_frame_too_long_errors) +
7242 get_stat64(&hw_stats->rx_undersize_packets);
7243
7244 stats->rx_over_errors = old_stats->rx_over_errors +
7245 get_stat64(&hw_stats->rxbds_empty);
7246 stats->rx_frame_errors = old_stats->rx_frame_errors +
7247 get_stat64(&hw_stats->rx_align_errors);
7248 stats->tx_aborted_errors = old_stats->tx_aborted_errors +
7249 get_stat64(&hw_stats->tx_discards);
7250 stats->tx_carrier_errors = old_stats->tx_carrier_errors +
7251 get_stat64(&hw_stats->tx_carrier_sense_errors);
7252
7253 stats->rx_crc_errors = old_stats->rx_crc_errors +
7254 calc_crc_errors(tp);
7255
4f63b877
JL
7256 stats->rx_missed_errors = old_stats->rx_missed_errors +
7257 get_stat64(&hw_stats->rx_discards);
7258
1da177e4
LT
7259 return stats;
7260}
7261
7262static inline u32 calc_crc(unsigned char *buf, int len)
7263{
7264 u32 reg;
7265 u32 tmp;
7266 int j, k;
7267
7268 reg = 0xffffffff;
7269
7270 for (j = 0; j < len; j++) {
7271 reg ^= buf[j];
7272
7273 for (k = 0; k < 8; k++) {
7274 tmp = reg & 0x01;
7275
7276 reg >>= 1;
7277
7278 if (tmp) {
7279 reg ^= 0xedb88320;
7280 }
7281 }
7282 }
7283
7284 return ~reg;
7285}
7286
7287static void tg3_set_multi(struct tg3 *tp, unsigned int accept_all)
7288{
7289 /* accept or reject all multicast frames */
7290 tw32(MAC_HASH_REG_0, accept_all ? 0xffffffff : 0);
7291 tw32(MAC_HASH_REG_1, accept_all ? 0xffffffff : 0);
7292 tw32(MAC_HASH_REG_2, accept_all ? 0xffffffff : 0);
7293 tw32(MAC_HASH_REG_3, accept_all ? 0xffffffff : 0);
7294}
7295
7296static void __tg3_set_rx_mode(struct net_device *dev)
7297{
7298 struct tg3 *tp = netdev_priv(dev);
7299 u32 rx_mode;
7300
7301 rx_mode = tp->rx_mode & ~(RX_MODE_PROMISC |
7302 RX_MODE_KEEP_VLAN_TAG);
7303
7304 /* When ASF is in use, we always keep the RX_MODE_KEEP_VLAN_TAG
7305 * flag clear.
7306 */
7307#if TG3_VLAN_TAG_USED
7308 if (!tp->vlgrp &&
7309 !(tp->tg3_flags & TG3_FLAG_ENABLE_ASF))
7310 rx_mode |= RX_MODE_KEEP_VLAN_TAG;
7311#else
7312 /* By definition, VLAN is disabled always in this
7313 * case.
7314 */
7315 if (!(tp->tg3_flags & TG3_FLAG_ENABLE_ASF))
7316 rx_mode |= RX_MODE_KEEP_VLAN_TAG;
7317#endif
7318
7319 if (dev->flags & IFF_PROMISC) {
7320 /* Promiscuous mode. */
7321 rx_mode |= RX_MODE_PROMISC;
7322 } else if (dev->flags & IFF_ALLMULTI) {
7323 /* Accept all multicast. */
7324 tg3_set_multi (tp, 1);
7325 } else if (dev->mc_count < 1) {
7326 /* Reject all multicast. */
7327 tg3_set_multi (tp, 0);
7328 } else {
7329 /* Accept one or more multicast(s). */
7330 struct dev_mc_list *mclist;
7331 unsigned int i;
7332 u32 mc_filter[4] = { 0, };
7333 u32 regidx;
7334 u32 bit;
7335 u32 crc;
7336
7337 for (i = 0, mclist = dev->mc_list; mclist && i < dev->mc_count;
7338 i++, mclist = mclist->next) {
7339
7340 crc = calc_crc (mclist->dmi_addr, ETH_ALEN);
7341 bit = ~crc & 0x7f;
7342 regidx = (bit & 0x60) >> 5;
7343 bit &= 0x1f;
7344 mc_filter[regidx] |= (1 << bit);
7345 }
7346
7347 tw32(MAC_HASH_REG_0, mc_filter[0]);
7348 tw32(MAC_HASH_REG_1, mc_filter[1]);
7349 tw32(MAC_HASH_REG_2, mc_filter[2]);
7350 tw32(MAC_HASH_REG_3, mc_filter[3]);
7351 }
7352
7353 if (rx_mode != tp->rx_mode) {
7354 tp->rx_mode = rx_mode;
7355 tw32_f(MAC_RX_MODE, rx_mode);
7356 udelay(10);
7357 }
7358}
7359
7360static void tg3_set_rx_mode(struct net_device *dev)
7361{
7362 struct tg3 *tp = netdev_priv(dev);
7363
e75f7c90
MC
7364 if (!netif_running(dev))
7365 return;
7366
f47c11ee 7367 tg3_full_lock(tp, 0);
1da177e4 7368 __tg3_set_rx_mode(dev);
f47c11ee 7369 tg3_full_unlock(tp);
1da177e4
LT
7370}
7371
7372#define TG3_REGDUMP_LEN (32 * 1024)
7373
7374static int tg3_get_regs_len(struct net_device *dev)
7375{
7376 return TG3_REGDUMP_LEN;
7377}
7378
7379static void tg3_get_regs(struct net_device *dev,
7380 struct ethtool_regs *regs, void *_p)
7381{
7382 u32 *p = _p;
7383 struct tg3 *tp = netdev_priv(dev);
7384 u8 *orig_p = _p;
7385 int i;
7386
7387 regs->version = 0;
7388
7389 memset(p, 0, TG3_REGDUMP_LEN);
7390
bc1c7567
MC
7391 if (tp->link_config.phy_is_low_power)
7392 return;
7393
f47c11ee 7394 tg3_full_lock(tp, 0);
1da177e4
LT
7395
7396#define __GET_REG32(reg) (*(p)++ = tr32(reg))
7397#define GET_REG32_LOOP(base,len) \
7398do { p = (u32 *)(orig_p + (base)); \
7399 for (i = 0; i < len; i += 4) \
7400 __GET_REG32((base) + i); \
7401} while (0)
7402#define GET_REG32_1(reg) \
7403do { p = (u32 *)(orig_p + (reg)); \
7404 __GET_REG32((reg)); \
7405} while (0)
7406
7407 GET_REG32_LOOP(TG3PCI_VENDOR, 0xb0);
7408 GET_REG32_LOOP(MAILBOX_INTERRUPT_0, 0x200);
7409 GET_REG32_LOOP(MAC_MODE, 0x4f0);
7410 GET_REG32_LOOP(SNDDATAI_MODE, 0xe0);
7411 GET_REG32_1(SNDDATAC_MODE);
7412 GET_REG32_LOOP(SNDBDS_MODE, 0x80);
7413 GET_REG32_LOOP(SNDBDI_MODE, 0x48);
7414 GET_REG32_1(SNDBDC_MODE);
7415 GET_REG32_LOOP(RCVLPC_MODE, 0x20);
7416 GET_REG32_LOOP(RCVLPC_SELLST_BASE, 0x15c);
7417 GET_REG32_LOOP(RCVDBDI_MODE, 0x0c);
7418 GET_REG32_LOOP(RCVDBDI_JUMBO_BD, 0x3c);
7419 GET_REG32_LOOP(RCVDBDI_BD_PROD_IDX_0, 0x44);
7420 GET_REG32_1(RCVDCC_MODE);
7421 GET_REG32_LOOP(RCVBDI_MODE, 0x20);
7422 GET_REG32_LOOP(RCVCC_MODE, 0x14);
7423 GET_REG32_LOOP(RCVLSC_MODE, 0x08);
7424 GET_REG32_1(MBFREE_MODE);
7425 GET_REG32_LOOP(HOSTCC_MODE, 0x100);
7426 GET_REG32_LOOP(MEMARB_MODE, 0x10);
7427 GET_REG32_LOOP(BUFMGR_MODE, 0x58);
7428 GET_REG32_LOOP(RDMAC_MODE, 0x08);
7429 GET_REG32_LOOP(WDMAC_MODE, 0x08);
091465d7
CE
7430 GET_REG32_1(RX_CPU_MODE);
7431 GET_REG32_1(RX_CPU_STATE);
7432 GET_REG32_1(RX_CPU_PGMCTR);
7433 GET_REG32_1(RX_CPU_HWBKPT);
7434 GET_REG32_1(TX_CPU_MODE);
7435 GET_REG32_1(TX_CPU_STATE);
7436 GET_REG32_1(TX_CPU_PGMCTR);
1da177e4
LT
7437 GET_REG32_LOOP(GRCMBOX_INTERRUPT_0, 0x110);
7438 GET_REG32_LOOP(FTQ_RESET, 0x120);
7439 GET_REG32_LOOP(MSGINT_MODE, 0x0c);
7440 GET_REG32_1(DMAC_MODE);
7441 GET_REG32_LOOP(GRC_MODE, 0x4c);
7442 if (tp->tg3_flags & TG3_FLAG_NVRAM)
7443 GET_REG32_LOOP(NVRAM_CMD, 0x24);
7444
7445#undef __GET_REG32
7446#undef GET_REG32_LOOP
7447#undef GET_REG32_1
7448
f47c11ee 7449 tg3_full_unlock(tp);
1da177e4
LT
7450}
7451
7452static int tg3_get_eeprom_len(struct net_device *dev)
7453{
7454 struct tg3 *tp = netdev_priv(dev);
7455
7456 return tp->nvram_size;
7457}
7458
7459static int tg3_nvram_read(struct tg3 *tp, u32 offset, u32 *val);
7460
7461static int tg3_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, u8 *data)
7462{
7463 struct tg3 *tp = netdev_priv(dev);
7464 int ret;
7465 u8 *pd;
7466 u32 i, offset, len, val, b_offset, b_count;
7467
bc1c7567
MC
7468 if (tp->link_config.phy_is_low_power)
7469 return -EAGAIN;
7470
1da177e4
LT
7471 offset = eeprom->offset;
7472 len = eeprom->len;
7473 eeprom->len = 0;
7474
7475 eeprom->magic = TG3_EEPROM_MAGIC;
7476
7477 if (offset & 3) {
7478 /* adjustments to start on required 4 byte boundary */
7479 b_offset = offset & 3;
7480 b_count = 4 - b_offset;
7481 if (b_count > len) {
7482 /* i.e. offset=1 len=2 */
7483 b_count = len;
7484 }
7485 ret = tg3_nvram_read(tp, offset-b_offset, &val);
7486 if (ret)
7487 return ret;
7488 val = cpu_to_le32(val);
7489 memcpy(data, ((char*)&val) + b_offset, b_count);
7490 len -= b_count;
7491 offset += b_count;
7492 eeprom->len += b_count;
7493 }
7494
7495 /* read bytes upto the last 4 byte boundary */
7496 pd = &data[eeprom->len];
7497 for (i = 0; i < (len - (len & 3)); i += 4) {
7498 ret = tg3_nvram_read(tp, offset + i, &val);
7499 if (ret) {
7500 eeprom->len += i;
7501 return ret;
7502 }
7503 val = cpu_to_le32(val);
7504 memcpy(pd + i, &val, 4);
7505 }
7506 eeprom->len += i;
7507
7508 if (len & 3) {
7509 /* read last bytes not ending on 4 byte boundary */
7510 pd = &data[eeprom->len];
7511 b_count = len & 3;
7512 b_offset = offset + len - b_count;
7513 ret = tg3_nvram_read(tp, b_offset, &val);
7514 if (ret)
7515 return ret;
7516 val = cpu_to_le32(val);
7517 memcpy(pd, ((char*)&val), b_count);
7518 eeprom->len += b_count;
7519 }
7520 return 0;
7521}
7522
7523static int tg3_nvram_write_block(struct tg3 *tp, u32 offset, u32 len, u8 *buf);
7524
7525static int tg3_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, u8 *data)
7526{
7527 struct tg3 *tp = netdev_priv(dev);
7528 int ret;
7529 u32 offset, len, b_offset, odd_len, start, end;
7530 u8 *buf;
7531
bc1c7567
MC
7532 if (tp->link_config.phy_is_low_power)
7533 return -EAGAIN;
7534
1da177e4
LT
7535 if (eeprom->magic != TG3_EEPROM_MAGIC)
7536 return -EINVAL;
7537
7538 offset = eeprom->offset;
7539 len = eeprom->len;
7540
7541 if ((b_offset = (offset & 3))) {
7542 /* adjustments to start on required 4 byte boundary */
7543 ret = tg3_nvram_read(tp, offset-b_offset, &start);
7544 if (ret)
7545 return ret;
7546 start = cpu_to_le32(start);
7547 len += b_offset;
7548 offset &= ~3;
1c8594b4
MC
7549 if (len < 4)
7550 len = 4;
1da177e4
LT
7551 }
7552
7553 odd_len = 0;
1c8594b4 7554 if (len & 3) {
1da177e4
LT
7555 /* adjustments to end on required 4 byte boundary */
7556 odd_len = 1;
7557 len = (len + 3) & ~3;
7558 ret = tg3_nvram_read(tp, offset+len-4, &end);
7559 if (ret)
7560 return ret;
7561 end = cpu_to_le32(end);
7562 }
7563
7564 buf = data;
7565 if (b_offset || odd_len) {
7566 buf = kmalloc(len, GFP_KERNEL);
7567 if (buf == 0)
7568 return -ENOMEM;
7569 if (b_offset)
7570 memcpy(buf, &start, 4);
7571 if (odd_len)
7572 memcpy(buf+len-4, &end, 4);
7573 memcpy(buf + b_offset, data, eeprom->len);
7574 }
7575
7576 ret = tg3_nvram_write_block(tp, offset, len, buf);
7577
7578 if (buf != data)
7579 kfree(buf);
7580
7581 return ret;
7582}
7583
7584static int tg3_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
7585{
7586 struct tg3 *tp = netdev_priv(dev);
7587
7588 cmd->supported = (SUPPORTED_Autoneg);
7589
7590 if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY))
7591 cmd->supported |= (SUPPORTED_1000baseT_Half |
7592 SUPPORTED_1000baseT_Full);
7593
a4e2b347 7594 if (!(tp->tg3_flags2 & TG3_FLG2_ANY_SERDES))
1da177e4
LT
7595 cmd->supported |= (SUPPORTED_100baseT_Half |
7596 SUPPORTED_100baseT_Full |
7597 SUPPORTED_10baseT_Half |
7598 SUPPORTED_10baseT_Full |
7599 SUPPORTED_MII);
7600 else
7601 cmd->supported |= SUPPORTED_FIBRE;
7602
7603 cmd->advertising = tp->link_config.advertising;
7604 if (netif_running(dev)) {
7605 cmd->speed = tp->link_config.active_speed;
7606 cmd->duplex = tp->link_config.active_duplex;
7607 }
7608 cmd->port = 0;
7609 cmd->phy_address = PHY_ADDR;
7610 cmd->transceiver = 0;
7611 cmd->autoneg = tp->link_config.autoneg;
7612 cmd->maxtxpkt = 0;
7613 cmd->maxrxpkt = 0;
7614 return 0;
7615}
7616
7617static int tg3_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
7618{
7619 struct tg3 *tp = netdev_priv(dev);
7620
37ff238d 7621 if (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES) {
1da177e4
LT
7622 /* These are the only valid advertisement bits allowed. */
7623 if (cmd->autoneg == AUTONEG_ENABLE &&
7624 (cmd->advertising & ~(ADVERTISED_1000baseT_Half |
7625 ADVERTISED_1000baseT_Full |
7626 ADVERTISED_Autoneg |
7627 ADVERTISED_FIBRE)))
7628 return -EINVAL;
37ff238d
MC
7629 /* Fiber can only do SPEED_1000. */
7630 else if ((cmd->autoneg != AUTONEG_ENABLE) &&
7631 (cmd->speed != SPEED_1000))
7632 return -EINVAL;
7633 /* Copper cannot force SPEED_1000. */
7634 } else if ((cmd->autoneg != AUTONEG_ENABLE) &&
7635 (cmd->speed == SPEED_1000))
7636 return -EINVAL;
7637 else if ((cmd->speed == SPEED_1000) &&
7638 (tp->tg3_flags2 & TG3_FLAG_10_100_ONLY))
7639 return -EINVAL;
1da177e4 7640
f47c11ee 7641 tg3_full_lock(tp, 0);
1da177e4
LT
7642
7643 tp->link_config.autoneg = cmd->autoneg;
7644 if (cmd->autoneg == AUTONEG_ENABLE) {
7645 tp->link_config.advertising = cmd->advertising;
7646 tp->link_config.speed = SPEED_INVALID;
7647 tp->link_config.duplex = DUPLEX_INVALID;
7648 } else {
7649 tp->link_config.advertising = 0;
7650 tp->link_config.speed = cmd->speed;
7651 tp->link_config.duplex = cmd->duplex;
7652 }
7653
7654 if (netif_running(dev))
7655 tg3_setup_phy(tp, 1);
7656
f47c11ee 7657 tg3_full_unlock(tp);
1da177e4
LT
7658
7659 return 0;
7660}
7661
7662static void tg3_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
7663{
7664 struct tg3 *tp = netdev_priv(dev);
7665
7666 strcpy(info->driver, DRV_MODULE_NAME);
7667 strcpy(info->version, DRV_MODULE_VERSION);
7668 strcpy(info->bus_info, pci_name(tp->pdev));
7669}
7670
7671static void tg3_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
7672{
7673 struct tg3 *tp = netdev_priv(dev);
7674
7675 wol->supported = WAKE_MAGIC;
7676 wol->wolopts = 0;
7677 if (tp->tg3_flags & TG3_FLAG_WOL_ENABLE)
7678 wol->wolopts = WAKE_MAGIC;
7679 memset(&wol->sopass, 0, sizeof(wol->sopass));
7680}
7681
7682static int tg3_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
7683{
7684 struct tg3 *tp = netdev_priv(dev);
7685
7686 if (wol->wolopts & ~WAKE_MAGIC)
7687 return -EINVAL;
7688 if ((wol->wolopts & WAKE_MAGIC) &&
7689 tp->tg3_flags2 & TG3_FLG2_PHY_SERDES &&
7690 !(tp->tg3_flags & TG3_FLAG_SERDES_WOL_CAP))
7691 return -EINVAL;
7692
f47c11ee 7693 spin_lock_bh(&tp->lock);
1da177e4
LT
7694 if (wol->wolopts & WAKE_MAGIC)
7695 tp->tg3_flags |= TG3_FLAG_WOL_ENABLE;
7696 else
7697 tp->tg3_flags &= ~TG3_FLAG_WOL_ENABLE;
f47c11ee 7698 spin_unlock_bh(&tp->lock);
1da177e4
LT
7699
7700 return 0;
7701}
7702
7703static u32 tg3_get_msglevel(struct net_device *dev)
7704{
7705 struct tg3 *tp = netdev_priv(dev);
7706 return tp->msg_enable;
7707}
7708
7709static void tg3_set_msglevel(struct net_device *dev, u32 value)
7710{
7711 struct tg3 *tp = netdev_priv(dev);
7712 tp->msg_enable = value;
7713}
7714
7715#if TG3_TSO_SUPPORT != 0
7716static int tg3_set_tso(struct net_device *dev, u32 value)
7717{
7718 struct tg3 *tp = netdev_priv(dev);
7719
7720 if (!(tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE)) {
7721 if (value)
7722 return -EINVAL;
7723 return 0;
7724 }
7725 return ethtool_op_set_tso(dev, value);
7726}
7727#endif
7728
7729static int tg3_nway_reset(struct net_device *dev)
7730{
7731 struct tg3 *tp = netdev_priv(dev);
7732 u32 bmcr;
7733 int r;
7734
7735 if (!netif_running(dev))
7736 return -EAGAIN;
7737
c94e3941
MC
7738 if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)
7739 return -EINVAL;
7740
f47c11ee 7741 spin_lock_bh(&tp->lock);
1da177e4
LT
7742 r = -EINVAL;
7743 tg3_readphy(tp, MII_BMCR, &bmcr);
7744 if (!tg3_readphy(tp, MII_BMCR, &bmcr) &&
c94e3941
MC
7745 ((bmcr & BMCR_ANENABLE) ||
7746 (tp->tg3_flags2 & TG3_FLG2_PARALLEL_DETECT))) {
7747 tg3_writephy(tp, MII_BMCR, bmcr | BMCR_ANRESTART |
7748 BMCR_ANENABLE);
1da177e4
LT
7749 r = 0;
7750 }
f47c11ee 7751 spin_unlock_bh(&tp->lock);
1da177e4
LT
7752
7753 return r;
7754}
7755
7756static void tg3_get_ringparam(struct net_device *dev, struct ethtool_ringparam *ering)
7757{
7758 struct tg3 *tp = netdev_priv(dev);
7759
7760 ering->rx_max_pending = TG3_RX_RING_SIZE - 1;
7761 ering->rx_mini_max_pending = 0;
4f81c32b
MC
7762 if (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE)
7763 ering->rx_jumbo_max_pending = TG3_RX_JUMBO_RING_SIZE - 1;
7764 else
7765 ering->rx_jumbo_max_pending = 0;
7766
7767 ering->tx_max_pending = TG3_TX_RING_SIZE - 1;
1da177e4
LT
7768
7769 ering->rx_pending = tp->rx_pending;
7770 ering->rx_mini_pending = 0;
4f81c32b
MC
7771 if (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE)
7772 ering->rx_jumbo_pending = tp->rx_jumbo_pending;
7773 else
7774 ering->rx_jumbo_pending = 0;
7775
1da177e4
LT
7776 ering->tx_pending = tp->tx_pending;
7777}
7778
7779static int tg3_set_ringparam(struct net_device *dev, struct ethtool_ringparam *ering)
7780{
7781 struct tg3 *tp = netdev_priv(dev);
bbe832c0 7782 int irq_sync = 0;
1da177e4
LT
7783
7784 if ((ering->rx_pending > TG3_RX_RING_SIZE - 1) ||
7785 (ering->rx_jumbo_pending > TG3_RX_JUMBO_RING_SIZE - 1) ||
7786 (ering->tx_pending > TG3_TX_RING_SIZE - 1))
7787 return -EINVAL;
7788
bbe832c0 7789 if (netif_running(dev)) {
1da177e4 7790 tg3_netif_stop(tp);
bbe832c0
MC
7791 irq_sync = 1;
7792 }
1da177e4 7793
bbe832c0 7794 tg3_full_lock(tp, irq_sync);
1da177e4
LT
7795
7796 tp->rx_pending = ering->rx_pending;
7797
7798 if ((tp->tg3_flags2 & TG3_FLG2_MAX_RXPEND_64) &&
7799 tp->rx_pending > 63)
7800 tp->rx_pending = 63;
7801 tp->rx_jumbo_pending = ering->rx_jumbo_pending;
7802 tp->tx_pending = ering->tx_pending;
7803
7804 if (netif_running(dev)) {
944d980e 7805 tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
1da177e4
LT
7806 tg3_init_hw(tp);
7807 tg3_netif_start(tp);
7808 }
7809
f47c11ee 7810 tg3_full_unlock(tp);
1da177e4
LT
7811
7812 return 0;
7813}
7814
7815static void tg3_get_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause)
7816{
7817 struct tg3 *tp = netdev_priv(dev);
7818
7819 epause->autoneg = (tp->tg3_flags & TG3_FLAG_PAUSE_AUTONEG) != 0;
7820 epause->rx_pause = (tp->tg3_flags & TG3_FLAG_RX_PAUSE) != 0;
7821 epause->tx_pause = (tp->tg3_flags & TG3_FLAG_TX_PAUSE) != 0;
7822}
7823
7824static int tg3_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause)
7825{
7826 struct tg3 *tp = netdev_priv(dev);
bbe832c0 7827 int irq_sync = 0;
1da177e4 7828
bbe832c0 7829 if (netif_running(dev)) {
1da177e4 7830 tg3_netif_stop(tp);
bbe832c0
MC
7831 irq_sync = 1;
7832 }
1da177e4 7833
bbe832c0 7834 tg3_full_lock(tp, irq_sync);
f47c11ee 7835
1da177e4
LT
7836 if (epause->autoneg)
7837 tp->tg3_flags |= TG3_FLAG_PAUSE_AUTONEG;
7838 else
7839 tp->tg3_flags &= ~TG3_FLAG_PAUSE_AUTONEG;
7840 if (epause->rx_pause)
7841 tp->tg3_flags |= TG3_FLAG_RX_PAUSE;
7842 else
7843 tp->tg3_flags &= ~TG3_FLAG_RX_PAUSE;
7844 if (epause->tx_pause)
7845 tp->tg3_flags |= TG3_FLAG_TX_PAUSE;
7846 else
7847 tp->tg3_flags &= ~TG3_FLAG_TX_PAUSE;
7848
7849 if (netif_running(dev)) {
944d980e 7850 tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
1da177e4
LT
7851 tg3_init_hw(tp);
7852 tg3_netif_start(tp);
7853 }
f47c11ee
DM
7854
7855 tg3_full_unlock(tp);
1da177e4
LT
7856
7857 return 0;
7858}
7859
7860static u32 tg3_get_rx_csum(struct net_device *dev)
7861{
7862 struct tg3 *tp = netdev_priv(dev);
7863 return (tp->tg3_flags & TG3_FLAG_RX_CHECKSUMS) != 0;
7864}
7865
7866static int tg3_set_rx_csum(struct net_device *dev, u32 data)
7867{
7868 struct tg3 *tp = netdev_priv(dev);
7869
7870 if (tp->tg3_flags & TG3_FLAG_BROKEN_CHECKSUMS) {
7871 if (data != 0)
7872 return -EINVAL;
7873 return 0;
7874 }
7875
f47c11ee 7876 spin_lock_bh(&tp->lock);
1da177e4
LT
7877 if (data)
7878 tp->tg3_flags |= TG3_FLAG_RX_CHECKSUMS;
7879 else
7880 tp->tg3_flags &= ~TG3_FLAG_RX_CHECKSUMS;
f47c11ee 7881 spin_unlock_bh(&tp->lock);
1da177e4
LT
7882
7883 return 0;
7884}
7885
7886static int tg3_set_tx_csum(struct net_device *dev, u32 data)
7887{
7888 struct tg3 *tp = netdev_priv(dev);
7889
7890 if (tp->tg3_flags & TG3_FLAG_BROKEN_CHECKSUMS) {
7891 if (data != 0)
7892 return -EINVAL;
7893 return 0;
7894 }
7895
9c27dbdf
MC
7896 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787)
7897 ethtool_op_set_tx_hw_csum(dev, data);
1da177e4 7898 else
9c27dbdf 7899 ethtool_op_set_tx_csum(dev, data);
1da177e4
LT
7900
7901 return 0;
7902}
7903
7904static int tg3_get_stats_count (struct net_device *dev)
7905{
7906 return TG3_NUM_STATS;
7907}
7908
4cafd3f5
MC
7909static int tg3_get_test_count (struct net_device *dev)
7910{
7911 return TG3_NUM_TEST;
7912}
7913
1da177e4
LT
7914static void tg3_get_strings (struct net_device *dev, u32 stringset, u8 *buf)
7915{
7916 switch (stringset) {
7917 case ETH_SS_STATS:
7918 memcpy(buf, &ethtool_stats_keys, sizeof(ethtool_stats_keys));
7919 break;
4cafd3f5
MC
7920 case ETH_SS_TEST:
7921 memcpy(buf, &ethtool_test_keys, sizeof(ethtool_test_keys));
7922 break;
1da177e4
LT
7923 default:
7924 WARN_ON(1); /* we need a WARN() */
7925 break;
7926 }
7927}
7928
4009a93d
MC
7929static int tg3_phys_id(struct net_device *dev, u32 data)
7930{
7931 struct tg3 *tp = netdev_priv(dev);
7932 int i;
7933
7934 if (!netif_running(tp->dev))
7935 return -EAGAIN;
7936
7937 if (data == 0)
7938 data = 2;
7939
7940 for (i = 0; i < (data * 2); i++) {
7941 if ((i % 2) == 0)
7942 tw32(MAC_LED_CTRL, LED_CTRL_LNKLED_OVERRIDE |
7943 LED_CTRL_1000MBPS_ON |
7944 LED_CTRL_100MBPS_ON |
7945 LED_CTRL_10MBPS_ON |
7946 LED_CTRL_TRAFFIC_OVERRIDE |
7947 LED_CTRL_TRAFFIC_BLINK |
7948 LED_CTRL_TRAFFIC_LED);
7949
7950 else
7951 tw32(MAC_LED_CTRL, LED_CTRL_LNKLED_OVERRIDE |
7952 LED_CTRL_TRAFFIC_OVERRIDE);
7953
7954 if (msleep_interruptible(500))
7955 break;
7956 }
7957 tw32(MAC_LED_CTRL, tp->led_ctrl);
7958 return 0;
7959}
7960
1da177e4
LT
7961static void tg3_get_ethtool_stats (struct net_device *dev,
7962 struct ethtool_stats *estats, u64 *tmp_stats)
7963{
7964 struct tg3 *tp = netdev_priv(dev);
7965 memcpy(tmp_stats, tg3_get_estats(tp), sizeof(tp->estats));
7966}
7967
566f86ad 7968#define NVRAM_TEST_SIZE 0x100
1b27777a 7969#define NVRAM_SELFBOOT_FORMAT1_SIZE 0x14
566f86ad
MC
7970
7971static int tg3_test_nvram(struct tg3 *tp)
7972{
1b27777a
MC
7973 u32 *buf, csum, magic;
7974 int i, j, err = 0, size;
566f86ad 7975
1b27777a
MC
7976 if (tg3_nvram_read(tp, 0, &magic) != 0)
7977 return -EIO;
7978
7979 magic = swab32(magic);
7980 if (magic == TG3_EEPROM_MAGIC)
7981 size = NVRAM_TEST_SIZE;
7982 else if ((magic & 0xff000000) == 0xa5000000) {
7983 if ((magic & 0xe00000) == 0x200000)
7984 size = NVRAM_SELFBOOT_FORMAT1_SIZE;
7985 else
7986 return 0;
7987 } else
7988 return -EIO;
7989
7990 buf = kmalloc(size, GFP_KERNEL);
566f86ad
MC
7991 if (buf == NULL)
7992 return -ENOMEM;
7993
1b27777a
MC
7994 err = -EIO;
7995 for (i = 0, j = 0; i < size; i += 4, j++) {
566f86ad
MC
7996 u32 val;
7997
7998 if ((err = tg3_nvram_read(tp, i, &val)) != 0)
7999 break;
8000 buf[j] = cpu_to_le32(val);
8001 }
1b27777a 8002 if (i < size)
566f86ad
MC
8003 goto out;
8004
1b27777a
MC
8005 /* Selfboot format */
8006 if (cpu_to_be32(buf[0]) != TG3_EEPROM_MAGIC) {
8007 u8 *buf8 = (u8 *) buf, csum8 = 0;
8008
8009 for (i = 0; i < size; i++)
8010 csum8 += buf8[i];
8011
8012 if (csum8 == 0)
8013 return 0;
8014 return -EIO;
8015 }
566f86ad
MC
8016
8017 /* Bootstrap checksum at offset 0x10 */
8018 csum = calc_crc((unsigned char *) buf, 0x10);
8019 if(csum != cpu_to_le32(buf[0x10/4]))
8020 goto out;
8021
8022 /* Manufacturing block starts at offset 0x74, checksum at 0xfc */
8023 csum = calc_crc((unsigned char *) &buf[0x74/4], 0x88);
8024 if (csum != cpu_to_le32(buf[0xfc/4]))
8025 goto out;
8026
8027 err = 0;
8028
8029out:
8030 kfree(buf);
8031 return err;
8032}
8033
ca43007a
MC
8034#define TG3_SERDES_TIMEOUT_SEC 2
8035#define TG3_COPPER_TIMEOUT_SEC 6
8036
8037static int tg3_test_link(struct tg3 *tp)
8038{
8039 int i, max;
8040
8041 if (!netif_running(tp->dev))
8042 return -ENODEV;
8043
4c987487 8044 if (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES)
ca43007a
MC
8045 max = TG3_SERDES_TIMEOUT_SEC;
8046 else
8047 max = TG3_COPPER_TIMEOUT_SEC;
8048
8049 for (i = 0; i < max; i++) {
8050 if (netif_carrier_ok(tp->dev))
8051 return 0;
8052
8053 if (msleep_interruptible(1000))
8054 break;
8055 }
8056
8057 return -EIO;
8058}
8059
a71116d1 8060/* Only test the commonly used registers */
f71e1309 8061static const int tg3_test_registers(struct tg3 *tp)
a71116d1
MC
8062{
8063 int i, is_5705;
8064 u32 offset, read_mask, write_mask, val, save_val, read_val;
8065 static struct {
8066 u16 offset;
8067 u16 flags;
8068#define TG3_FL_5705 0x1
8069#define TG3_FL_NOT_5705 0x2
8070#define TG3_FL_NOT_5788 0x4
8071 u32 read_mask;
8072 u32 write_mask;
8073 } reg_tbl[] = {
8074 /* MAC Control Registers */
8075 { MAC_MODE, TG3_FL_NOT_5705,
8076 0x00000000, 0x00ef6f8c },
8077 { MAC_MODE, TG3_FL_5705,
8078 0x00000000, 0x01ef6b8c },
8079 { MAC_STATUS, TG3_FL_NOT_5705,
8080 0x03800107, 0x00000000 },
8081 { MAC_STATUS, TG3_FL_5705,
8082 0x03800100, 0x00000000 },
8083 { MAC_ADDR_0_HIGH, 0x0000,
8084 0x00000000, 0x0000ffff },
8085 { MAC_ADDR_0_LOW, 0x0000,
8086 0x00000000, 0xffffffff },
8087 { MAC_RX_MTU_SIZE, 0x0000,
8088 0x00000000, 0x0000ffff },
8089 { MAC_TX_MODE, 0x0000,
8090 0x00000000, 0x00000070 },
8091 { MAC_TX_LENGTHS, 0x0000,
8092 0x00000000, 0x00003fff },
8093 { MAC_RX_MODE, TG3_FL_NOT_5705,
8094 0x00000000, 0x000007fc },
8095 { MAC_RX_MODE, TG3_FL_5705,
8096 0x00000000, 0x000007dc },
8097 { MAC_HASH_REG_0, 0x0000,
8098 0x00000000, 0xffffffff },
8099 { MAC_HASH_REG_1, 0x0000,
8100 0x00000000, 0xffffffff },
8101 { MAC_HASH_REG_2, 0x0000,
8102 0x00000000, 0xffffffff },
8103 { MAC_HASH_REG_3, 0x0000,
8104 0x00000000, 0xffffffff },
8105
8106 /* Receive Data and Receive BD Initiator Control Registers. */
8107 { RCVDBDI_JUMBO_BD+0, TG3_FL_NOT_5705,
8108 0x00000000, 0xffffffff },
8109 { RCVDBDI_JUMBO_BD+4, TG3_FL_NOT_5705,
8110 0x00000000, 0xffffffff },
8111 { RCVDBDI_JUMBO_BD+8, TG3_FL_NOT_5705,
8112 0x00000000, 0x00000003 },
8113 { RCVDBDI_JUMBO_BD+0xc, TG3_FL_NOT_5705,
8114 0x00000000, 0xffffffff },
8115 { RCVDBDI_STD_BD+0, 0x0000,
8116 0x00000000, 0xffffffff },
8117 { RCVDBDI_STD_BD+4, 0x0000,
8118 0x00000000, 0xffffffff },
8119 { RCVDBDI_STD_BD+8, 0x0000,
8120 0x00000000, 0xffff0002 },
8121 { RCVDBDI_STD_BD+0xc, 0x0000,
8122 0x00000000, 0xffffffff },
8123
8124 /* Receive BD Initiator Control Registers. */
8125 { RCVBDI_STD_THRESH, TG3_FL_NOT_5705,
8126 0x00000000, 0xffffffff },
8127 { RCVBDI_STD_THRESH, TG3_FL_5705,
8128 0x00000000, 0x000003ff },
8129 { RCVBDI_JUMBO_THRESH, TG3_FL_NOT_5705,
8130 0x00000000, 0xffffffff },
8131
8132 /* Host Coalescing Control Registers. */
8133 { HOSTCC_MODE, TG3_FL_NOT_5705,
8134 0x00000000, 0x00000004 },
8135 { HOSTCC_MODE, TG3_FL_5705,
8136 0x00000000, 0x000000f6 },
8137 { HOSTCC_RXCOL_TICKS, TG3_FL_NOT_5705,
8138 0x00000000, 0xffffffff },
8139 { HOSTCC_RXCOL_TICKS, TG3_FL_5705,
8140 0x00000000, 0x000003ff },
8141 { HOSTCC_TXCOL_TICKS, TG3_FL_NOT_5705,
8142 0x00000000, 0xffffffff },
8143 { HOSTCC_TXCOL_TICKS, TG3_FL_5705,
8144 0x00000000, 0x000003ff },
8145 { HOSTCC_RXMAX_FRAMES, TG3_FL_NOT_5705,
8146 0x00000000, 0xffffffff },
8147 { HOSTCC_RXMAX_FRAMES, TG3_FL_5705 | TG3_FL_NOT_5788,
8148 0x00000000, 0x000000ff },
8149 { HOSTCC_TXMAX_FRAMES, TG3_FL_NOT_5705,
8150 0x00000000, 0xffffffff },
8151 { HOSTCC_TXMAX_FRAMES, TG3_FL_5705 | TG3_FL_NOT_5788,
8152 0x00000000, 0x000000ff },
8153 { HOSTCC_RXCOAL_TICK_INT, TG3_FL_NOT_5705,
8154 0x00000000, 0xffffffff },
8155 { HOSTCC_TXCOAL_TICK_INT, TG3_FL_NOT_5705,
8156 0x00000000, 0xffffffff },
8157 { HOSTCC_RXCOAL_MAXF_INT, TG3_FL_NOT_5705,
8158 0x00000000, 0xffffffff },
8159 { HOSTCC_RXCOAL_MAXF_INT, TG3_FL_5705 | TG3_FL_NOT_5788,
8160 0x00000000, 0x000000ff },
8161 { HOSTCC_TXCOAL_MAXF_INT, TG3_FL_NOT_5705,
8162 0x00000000, 0xffffffff },
8163 { HOSTCC_TXCOAL_MAXF_INT, TG3_FL_5705 | TG3_FL_NOT_5788,
8164 0x00000000, 0x000000ff },
8165 { HOSTCC_STAT_COAL_TICKS, TG3_FL_NOT_5705,
8166 0x00000000, 0xffffffff },
8167 { HOSTCC_STATS_BLK_HOST_ADDR, TG3_FL_NOT_5705,
8168 0x00000000, 0xffffffff },
8169 { HOSTCC_STATS_BLK_HOST_ADDR+4, TG3_FL_NOT_5705,
8170 0x00000000, 0xffffffff },
8171 { HOSTCC_STATUS_BLK_HOST_ADDR, 0x0000,
8172 0x00000000, 0xffffffff },
8173 { HOSTCC_STATUS_BLK_HOST_ADDR+4, 0x0000,
8174 0x00000000, 0xffffffff },
8175 { HOSTCC_STATS_BLK_NIC_ADDR, 0x0000,
8176 0xffffffff, 0x00000000 },
8177 { HOSTCC_STATUS_BLK_NIC_ADDR, 0x0000,
8178 0xffffffff, 0x00000000 },
8179
8180 /* Buffer Manager Control Registers. */
8181 { BUFMGR_MB_POOL_ADDR, 0x0000,
8182 0x00000000, 0x007fff80 },
8183 { BUFMGR_MB_POOL_SIZE, 0x0000,
8184 0x00000000, 0x007fffff },
8185 { BUFMGR_MB_RDMA_LOW_WATER, 0x0000,
8186 0x00000000, 0x0000003f },
8187 { BUFMGR_MB_MACRX_LOW_WATER, 0x0000,
8188 0x00000000, 0x000001ff },
8189 { BUFMGR_MB_HIGH_WATER, 0x0000,
8190 0x00000000, 0x000001ff },
8191 { BUFMGR_DMA_DESC_POOL_ADDR, TG3_FL_NOT_5705,
8192 0xffffffff, 0x00000000 },
8193 { BUFMGR_DMA_DESC_POOL_SIZE, TG3_FL_NOT_5705,
8194 0xffffffff, 0x00000000 },
8195
8196 /* Mailbox Registers */
8197 { GRCMBOX_RCVSTD_PROD_IDX+4, 0x0000,
8198 0x00000000, 0x000001ff },
8199 { GRCMBOX_RCVJUMBO_PROD_IDX+4, TG3_FL_NOT_5705,
8200 0x00000000, 0x000001ff },
8201 { GRCMBOX_RCVRET_CON_IDX_0+4, 0x0000,
8202 0x00000000, 0x000007ff },
8203 { GRCMBOX_SNDHOST_PROD_IDX_0+4, 0x0000,
8204 0x00000000, 0x000001ff },
8205
8206 { 0xffff, 0x0000, 0x00000000, 0x00000000 },
8207 };
8208
8209 if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS)
8210 is_5705 = 1;
8211 else
8212 is_5705 = 0;
8213
8214 for (i = 0; reg_tbl[i].offset != 0xffff; i++) {
8215 if (is_5705 && (reg_tbl[i].flags & TG3_FL_NOT_5705))
8216 continue;
8217
8218 if (!is_5705 && (reg_tbl[i].flags & TG3_FL_5705))
8219 continue;
8220
8221 if ((tp->tg3_flags2 & TG3_FLG2_IS_5788) &&
8222 (reg_tbl[i].flags & TG3_FL_NOT_5788))
8223 continue;
8224
8225 offset = (u32) reg_tbl[i].offset;
8226 read_mask = reg_tbl[i].read_mask;
8227 write_mask = reg_tbl[i].write_mask;
8228
8229 /* Save the original register content */
8230 save_val = tr32(offset);
8231
8232 /* Determine the read-only value. */
8233 read_val = save_val & read_mask;
8234
8235 /* Write zero to the register, then make sure the read-only bits
8236 * are not changed and the read/write bits are all zeros.
8237 */
8238 tw32(offset, 0);
8239
8240 val = tr32(offset);
8241
8242 /* Test the read-only and read/write bits. */
8243 if (((val & read_mask) != read_val) || (val & write_mask))
8244 goto out;
8245
8246 /* Write ones to all the bits defined by RdMask and WrMask, then
8247 * make sure the read-only bits are not changed and the
8248 * read/write bits are all ones.
8249 */
8250 tw32(offset, read_mask | write_mask);
8251
8252 val = tr32(offset);
8253
8254 /* Test the read-only bits. */
8255 if ((val & read_mask) != read_val)
8256 goto out;
8257
8258 /* Test the read/write bits. */
8259 if ((val & write_mask) != write_mask)
8260 goto out;
8261
8262 tw32(offset, save_val);
8263 }
8264
8265 return 0;
8266
8267out:
8268 printk(KERN_ERR PFX "Register test failed at offset %x\n", offset);
8269 tw32(offset, save_val);
8270 return -EIO;
8271}
8272
7942e1db
MC
8273static int tg3_do_mem_test(struct tg3 *tp, u32 offset, u32 len)
8274{
f71e1309 8275 static const u32 test_pattern[] = { 0x00000000, 0xffffffff, 0xaa55a55a };
7942e1db
MC
8276 int i;
8277 u32 j;
8278
8279 for (i = 0; i < sizeof(test_pattern)/sizeof(u32); i++) {
8280 for (j = 0; j < len; j += 4) {
8281 u32 val;
8282
8283 tg3_write_mem(tp, offset + j, test_pattern[i]);
8284 tg3_read_mem(tp, offset + j, &val);
8285 if (val != test_pattern[i])
8286 return -EIO;
8287 }
8288 }
8289 return 0;
8290}
8291
8292static int tg3_test_memory(struct tg3 *tp)
8293{
8294 static struct mem_entry {
8295 u32 offset;
8296 u32 len;
8297 } mem_tbl_570x[] = {
38690194 8298 { 0x00000000, 0x00b50},
7942e1db
MC
8299 { 0x00002000, 0x1c000},
8300 { 0xffffffff, 0x00000}
8301 }, mem_tbl_5705[] = {
8302 { 0x00000100, 0x0000c},
8303 { 0x00000200, 0x00008},
7942e1db
MC
8304 { 0x00004000, 0x00800},
8305 { 0x00006000, 0x01000},
8306 { 0x00008000, 0x02000},
8307 { 0x00010000, 0x0e000},
8308 { 0xffffffff, 0x00000}
8309 };
8310 struct mem_entry *mem_tbl;
8311 int err = 0;
8312 int i;
8313
8314 if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS)
8315 mem_tbl = mem_tbl_5705;
8316 else
8317 mem_tbl = mem_tbl_570x;
8318
8319 for (i = 0; mem_tbl[i].offset != 0xffffffff; i++) {
8320 if ((err = tg3_do_mem_test(tp, mem_tbl[i].offset,
8321 mem_tbl[i].len)) != 0)
8322 break;
8323 }
8324
8325 return err;
8326}
8327
9f40dead
MC
8328#define TG3_MAC_LOOPBACK 0
8329#define TG3_PHY_LOOPBACK 1
8330
8331static int tg3_run_loopback(struct tg3 *tp, int loopback_mode)
c76949a6 8332{
9f40dead 8333 u32 mac_mode, rx_start_idx, rx_idx, tx_idx, opaque_key;
c76949a6
MC
8334 u32 desc_idx;
8335 struct sk_buff *skb, *rx_skb;
8336 u8 *tx_data;
8337 dma_addr_t map;
8338 int num_pkts, tx_len, rx_len, i, err;
8339 struct tg3_rx_buffer_desc *desc;
8340
9f40dead 8341 if (loopback_mode == TG3_MAC_LOOPBACK) {
c94e3941
MC
8342 /* HW errata - mac loopback fails in some cases on 5780.
8343 * Normal traffic and PHY loopback are not affected by
8344 * errata.
8345 */
8346 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780)
8347 return 0;
8348
9f40dead
MC
8349 mac_mode = (tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK) |
8350 MAC_MODE_PORT_INT_LPBACK | MAC_MODE_LINK_POLARITY |
8351 MAC_MODE_PORT_MODE_GMII;
8352 tw32(MAC_MODE, mac_mode);
8353 } else if (loopback_mode == TG3_PHY_LOOPBACK) {
c94e3941
MC
8354 tg3_writephy(tp, MII_BMCR, BMCR_LOOPBACK | BMCR_FULLDPLX |
8355 BMCR_SPEED1000);
8356 udelay(40);
8357 /* reset to prevent losing 1st rx packet intermittently */
8358 if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES) {
8359 tw32_f(MAC_RX_MODE, RX_MODE_RESET);
8360 udelay(10);
8361 tw32_f(MAC_RX_MODE, tp->rx_mode);
8362 }
9f40dead
MC
8363 mac_mode = (tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK) |
8364 MAC_MODE_LINK_POLARITY | MAC_MODE_PORT_MODE_GMII;
8365 if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5401)
8366 mac_mode &= ~MAC_MODE_LINK_POLARITY;
8367 tw32(MAC_MODE, mac_mode);
9f40dead
MC
8368 }
8369 else
8370 return -EINVAL;
c76949a6
MC
8371
8372 err = -EIO;
8373
c76949a6
MC
8374 tx_len = 1514;
8375 skb = dev_alloc_skb(tx_len);
8376 tx_data = skb_put(skb, tx_len);
8377 memcpy(tx_data, tp->dev->dev_addr, 6);
8378 memset(tx_data + 6, 0x0, 8);
8379
8380 tw32(MAC_RX_MTU_SIZE, tx_len + 4);
8381
8382 for (i = 14; i < tx_len; i++)
8383 tx_data[i] = (u8) (i & 0xff);
8384
8385 map = pci_map_single(tp->pdev, skb->data, tx_len, PCI_DMA_TODEVICE);
8386
8387 tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE |
8388 HOSTCC_MODE_NOW);
8389
8390 udelay(10);
8391
8392 rx_start_idx = tp->hw_status->idx[0].rx_producer;
8393
c76949a6
MC
8394 num_pkts = 0;
8395
9f40dead 8396 tg3_set_txd(tp, tp->tx_prod, map, tx_len, 0, 1);
c76949a6 8397
9f40dead 8398 tp->tx_prod++;
c76949a6
MC
8399 num_pkts++;
8400
9f40dead
MC
8401 tw32_tx_mbox(MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW,
8402 tp->tx_prod);
09ee929c 8403 tr32_mailbox(MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW);
c76949a6
MC
8404
8405 udelay(10);
8406
8407 for (i = 0; i < 10; i++) {
8408 tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE |
8409 HOSTCC_MODE_NOW);
8410
8411 udelay(10);
8412
8413 tx_idx = tp->hw_status->idx[0].tx_consumer;
8414 rx_idx = tp->hw_status->idx[0].rx_producer;
9f40dead 8415 if ((tx_idx == tp->tx_prod) &&
c76949a6
MC
8416 (rx_idx == (rx_start_idx + num_pkts)))
8417 break;
8418 }
8419
8420 pci_unmap_single(tp->pdev, map, tx_len, PCI_DMA_TODEVICE);
8421 dev_kfree_skb(skb);
8422
9f40dead 8423 if (tx_idx != tp->tx_prod)
c76949a6
MC
8424 goto out;
8425
8426 if (rx_idx != rx_start_idx + num_pkts)
8427 goto out;
8428
8429 desc = &tp->rx_rcb[rx_start_idx];
8430 desc_idx = desc->opaque & RXD_OPAQUE_INDEX_MASK;
8431 opaque_key = desc->opaque & RXD_OPAQUE_RING_MASK;
8432 if (opaque_key != RXD_OPAQUE_RING_STD)
8433 goto out;
8434
8435 if ((desc->err_vlan & RXD_ERR_MASK) != 0 &&
8436 (desc->err_vlan != RXD_ERR_ODD_NIBBLE_RCVD_MII))
8437 goto out;
8438
8439 rx_len = ((desc->idx_len & RXD_LEN_MASK) >> RXD_LEN_SHIFT) - 4;
8440 if (rx_len != tx_len)
8441 goto out;
8442
8443 rx_skb = tp->rx_std_buffers[desc_idx].skb;
8444
8445 map = pci_unmap_addr(&tp->rx_std_buffers[desc_idx], mapping);
8446 pci_dma_sync_single_for_cpu(tp->pdev, map, rx_len, PCI_DMA_FROMDEVICE);
8447
8448 for (i = 14; i < tx_len; i++) {
8449 if (*(rx_skb->data + i) != (u8) (i & 0xff))
8450 goto out;
8451 }
8452 err = 0;
8453
8454 /* tg3_free_rings will unmap and free the rx_skb */
8455out:
8456 return err;
8457}
8458
9f40dead
MC
8459#define TG3_MAC_LOOPBACK_FAILED 1
8460#define TG3_PHY_LOOPBACK_FAILED 2
8461#define TG3_LOOPBACK_FAILED (TG3_MAC_LOOPBACK_FAILED | \
8462 TG3_PHY_LOOPBACK_FAILED)
8463
8464static int tg3_test_loopback(struct tg3 *tp)
8465{
8466 int err = 0;
8467
8468 if (!netif_running(tp->dev))
8469 return TG3_LOOPBACK_FAILED;
8470
8471 tg3_reset_hw(tp);
8472
8473 if (tg3_run_loopback(tp, TG3_MAC_LOOPBACK))
8474 err |= TG3_MAC_LOOPBACK_FAILED;
8475 if (!(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)) {
8476 if (tg3_run_loopback(tp, TG3_PHY_LOOPBACK))
8477 err |= TG3_PHY_LOOPBACK_FAILED;
8478 }
8479
8480 return err;
8481}
8482
4cafd3f5
MC
8483static void tg3_self_test(struct net_device *dev, struct ethtool_test *etest,
8484 u64 *data)
8485{
566f86ad
MC
8486 struct tg3 *tp = netdev_priv(dev);
8487
bc1c7567
MC
8488 if (tp->link_config.phy_is_low_power)
8489 tg3_set_power_state(tp, PCI_D0);
8490
566f86ad
MC
8491 memset(data, 0, sizeof(u64) * TG3_NUM_TEST);
8492
8493 if (tg3_test_nvram(tp) != 0) {
8494 etest->flags |= ETH_TEST_FL_FAILED;
8495 data[0] = 1;
8496 }
ca43007a
MC
8497 if (tg3_test_link(tp) != 0) {
8498 etest->flags |= ETH_TEST_FL_FAILED;
8499 data[1] = 1;
8500 }
a71116d1 8501 if (etest->flags & ETH_TEST_FL_OFFLINE) {
ec41c7df 8502 int err, irq_sync = 0;
bbe832c0
MC
8503
8504 if (netif_running(dev)) {
a71116d1 8505 tg3_netif_stop(tp);
bbe832c0
MC
8506 irq_sync = 1;
8507 }
a71116d1 8508
bbe832c0 8509 tg3_full_lock(tp, irq_sync);
a71116d1
MC
8510
8511 tg3_halt(tp, RESET_KIND_SUSPEND, 1);
ec41c7df 8512 err = tg3_nvram_lock(tp);
a71116d1
MC
8513 tg3_halt_cpu(tp, RX_CPU_BASE);
8514 if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS))
8515 tg3_halt_cpu(tp, TX_CPU_BASE);
ec41c7df
MC
8516 if (!err)
8517 tg3_nvram_unlock(tp);
a71116d1 8518
d9ab5ad1
MC
8519 if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES)
8520 tg3_phy_reset(tp);
8521
a71116d1
MC
8522 if (tg3_test_registers(tp) != 0) {
8523 etest->flags |= ETH_TEST_FL_FAILED;
8524 data[2] = 1;
8525 }
7942e1db
MC
8526 if (tg3_test_memory(tp) != 0) {
8527 etest->flags |= ETH_TEST_FL_FAILED;
8528 data[3] = 1;
8529 }
9f40dead 8530 if ((data[4] = tg3_test_loopback(tp)) != 0)
c76949a6 8531 etest->flags |= ETH_TEST_FL_FAILED;
a71116d1 8532
f47c11ee
DM
8533 tg3_full_unlock(tp);
8534
d4bc3927
MC
8535 if (tg3_test_interrupt(tp) != 0) {
8536 etest->flags |= ETH_TEST_FL_FAILED;
8537 data[5] = 1;
8538 }
f47c11ee
DM
8539
8540 tg3_full_lock(tp, 0);
d4bc3927 8541
a71116d1
MC
8542 tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
8543 if (netif_running(dev)) {
8544 tp->tg3_flags |= TG3_FLAG_INIT_COMPLETE;
8545 tg3_init_hw(tp);
8546 tg3_netif_start(tp);
8547 }
f47c11ee
DM
8548
8549 tg3_full_unlock(tp);
a71116d1 8550 }
bc1c7567
MC
8551 if (tp->link_config.phy_is_low_power)
8552 tg3_set_power_state(tp, PCI_D3hot);
8553
4cafd3f5
MC
8554}
8555
1da177e4
LT
8556static int tg3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
8557{
8558 struct mii_ioctl_data *data = if_mii(ifr);
8559 struct tg3 *tp = netdev_priv(dev);
8560 int err;
8561
8562 switch(cmd) {
8563 case SIOCGMIIPHY:
8564 data->phy_id = PHY_ADDR;
8565
8566 /* fallthru */
8567 case SIOCGMIIREG: {
8568 u32 mii_regval;
8569
8570 if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)
8571 break; /* We have no PHY */
8572
bc1c7567
MC
8573 if (tp->link_config.phy_is_low_power)
8574 return -EAGAIN;
8575
f47c11ee 8576 spin_lock_bh(&tp->lock);
1da177e4 8577 err = tg3_readphy(tp, data->reg_num & 0x1f, &mii_regval);
f47c11ee 8578 spin_unlock_bh(&tp->lock);
1da177e4
LT
8579
8580 data->val_out = mii_regval;
8581
8582 return err;
8583 }
8584
8585 case SIOCSMIIREG:
8586 if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)
8587 break; /* We have no PHY */
8588
8589 if (!capable(CAP_NET_ADMIN))
8590 return -EPERM;
8591
bc1c7567
MC
8592 if (tp->link_config.phy_is_low_power)
8593 return -EAGAIN;
8594
f47c11ee 8595 spin_lock_bh(&tp->lock);
1da177e4 8596 err = tg3_writephy(tp, data->reg_num & 0x1f, data->val_in);
f47c11ee 8597 spin_unlock_bh(&tp->lock);
1da177e4
LT
8598
8599 return err;
8600
8601 default:
8602 /* do nothing */
8603 break;
8604 }
8605 return -EOPNOTSUPP;
8606}
8607
8608#if TG3_VLAN_TAG_USED
8609static void tg3_vlan_rx_register(struct net_device *dev, struct vlan_group *grp)
8610{
8611 struct tg3 *tp = netdev_priv(dev);
8612
f47c11ee 8613 tg3_full_lock(tp, 0);
1da177e4
LT
8614
8615 tp->vlgrp = grp;
8616
8617 /* Update RX_MODE_KEEP_VLAN_TAG bit in RX_MODE register. */
8618 __tg3_set_rx_mode(dev);
8619
f47c11ee 8620 tg3_full_unlock(tp);
1da177e4
LT
8621}
8622
8623static void tg3_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
8624{
8625 struct tg3 *tp = netdev_priv(dev);
8626
f47c11ee 8627 tg3_full_lock(tp, 0);
1da177e4
LT
8628 if (tp->vlgrp)
8629 tp->vlgrp->vlan_devices[vid] = NULL;
f47c11ee 8630 tg3_full_unlock(tp);
1da177e4
LT
8631}
8632#endif
8633
15f9850d
DM
8634static int tg3_get_coalesce(struct net_device *dev, struct ethtool_coalesce *ec)
8635{
8636 struct tg3 *tp = netdev_priv(dev);
8637
8638 memcpy(ec, &tp->coal, sizeof(*ec));
8639 return 0;
8640}
8641
d244c892
MC
8642static int tg3_set_coalesce(struct net_device *dev, struct ethtool_coalesce *ec)
8643{
8644 struct tg3 *tp = netdev_priv(dev);
8645 u32 max_rxcoal_tick_int = 0, max_txcoal_tick_int = 0;
8646 u32 max_stat_coal_ticks = 0, min_stat_coal_ticks = 0;
8647
8648 if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
8649 max_rxcoal_tick_int = MAX_RXCOAL_TICK_INT;
8650 max_txcoal_tick_int = MAX_TXCOAL_TICK_INT;
8651 max_stat_coal_ticks = MAX_STAT_COAL_TICKS;
8652 min_stat_coal_ticks = MIN_STAT_COAL_TICKS;
8653 }
8654
8655 if ((ec->rx_coalesce_usecs > MAX_RXCOL_TICKS) ||
8656 (ec->tx_coalesce_usecs > MAX_TXCOL_TICKS) ||
8657 (ec->rx_max_coalesced_frames > MAX_RXMAX_FRAMES) ||
8658 (ec->tx_max_coalesced_frames > MAX_TXMAX_FRAMES) ||
8659 (ec->rx_coalesce_usecs_irq > max_rxcoal_tick_int) ||
8660 (ec->tx_coalesce_usecs_irq > max_txcoal_tick_int) ||
8661 (ec->rx_max_coalesced_frames_irq > MAX_RXCOAL_MAXF_INT) ||
8662 (ec->tx_max_coalesced_frames_irq > MAX_TXCOAL_MAXF_INT) ||
8663 (ec->stats_block_coalesce_usecs > max_stat_coal_ticks) ||
8664 (ec->stats_block_coalesce_usecs < min_stat_coal_ticks))
8665 return -EINVAL;
8666
8667 /* No rx interrupts will be generated if both are zero */
8668 if ((ec->rx_coalesce_usecs == 0) &&
8669 (ec->rx_max_coalesced_frames == 0))
8670 return -EINVAL;
8671
8672 /* No tx interrupts will be generated if both are zero */
8673 if ((ec->tx_coalesce_usecs == 0) &&
8674 (ec->tx_max_coalesced_frames == 0))
8675 return -EINVAL;
8676
8677 /* Only copy relevant parameters, ignore all others. */
8678 tp->coal.rx_coalesce_usecs = ec->rx_coalesce_usecs;
8679 tp->coal.tx_coalesce_usecs = ec->tx_coalesce_usecs;
8680 tp->coal.rx_max_coalesced_frames = ec->rx_max_coalesced_frames;
8681 tp->coal.tx_max_coalesced_frames = ec->tx_max_coalesced_frames;
8682 tp->coal.rx_coalesce_usecs_irq = ec->rx_coalesce_usecs_irq;
8683 tp->coal.tx_coalesce_usecs_irq = ec->tx_coalesce_usecs_irq;
8684 tp->coal.rx_max_coalesced_frames_irq = ec->rx_max_coalesced_frames_irq;
8685 tp->coal.tx_max_coalesced_frames_irq = ec->tx_max_coalesced_frames_irq;
8686 tp->coal.stats_block_coalesce_usecs = ec->stats_block_coalesce_usecs;
8687
8688 if (netif_running(dev)) {
8689 tg3_full_lock(tp, 0);
8690 __tg3_set_coalesce(tp, &tp->coal);
8691 tg3_full_unlock(tp);
8692 }
8693 return 0;
8694}
8695
1da177e4
LT
8696static struct ethtool_ops tg3_ethtool_ops = {
8697 .get_settings = tg3_get_settings,
8698 .set_settings = tg3_set_settings,
8699 .get_drvinfo = tg3_get_drvinfo,
8700 .get_regs_len = tg3_get_regs_len,
8701 .get_regs = tg3_get_regs,
8702 .get_wol = tg3_get_wol,
8703 .set_wol = tg3_set_wol,
8704 .get_msglevel = tg3_get_msglevel,
8705 .set_msglevel = tg3_set_msglevel,
8706 .nway_reset = tg3_nway_reset,
8707 .get_link = ethtool_op_get_link,
8708 .get_eeprom_len = tg3_get_eeprom_len,
8709 .get_eeprom = tg3_get_eeprom,
8710 .set_eeprom = tg3_set_eeprom,
8711 .get_ringparam = tg3_get_ringparam,
8712 .set_ringparam = tg3_set_ringparam,
8713 .get_pauseparam = tg3_get_pauseparam,
8714 .set_pauseparam = tg3_set_pauseparam,
8715 .get_rx_csum = tg3_get_rx_csum,
8716 .set_rx_csum = tg3_set_rx_csum,
8717 .get_tx_csum = ethtool_op_get_tx_csum,
8718 .set_tx_csum = tg3_set_tx_csum,
8719 .get_sg = ethtool_op_get_sg,
8720 .set_sg = ethtool_op_set_sg,
8721#if TG3_TSO_SUPPORT != 0
8722 .get_tso = ethtool_op_get_tso,
8723 .set_tso = tg3_set_tso,
8724#endif
4cafd3f5
MC
8725 .self_test_count = tg3_get_test_count,
8726 .self_test = tg3_self_test,
1da177e4 8727 .get_strings = tg3_get_strings,
4009a93d 8728 .phys_id = tg3_phys_id,
1da177e4
LT
8729 .get_stats_count = tg3_get_stats_count,
8730 .get_ethtool_stats = tg3_get_ethtool_stats,
15f9850d 8731 .get_coalesce = tg3_get_coalesce,
d244c892 8732 .set_coalesce = tg3_set_coalesce,
2ff43697 8733 .get_perm_addr = ethtool_op_get_perm_addr,
1da177e4
LT
8734};
8735
8736static void __devinit tg3_get_eeprom_size(struct tg3 *tp)
8737{
1b27777a 8738 u32 cursize, val, magic;
1da177e4
LT
8739
8740 tp->nvram_size = EEPROM_CHIP_SIZE;
8741
8742 if (tg3_nvram_read(tp, 0, &val) != 0)
8743 return;
8744
1b27777a
MC
8745 magic = swab32(val);
8746 if ((magic != TG3_EEPROM_MAGIC) && ((magic & 0xff000000) != 0xa5000000))
1da177e4
LT
8747 return;
8748
8749 /*
8750 * Size the chip by reading offsets at increasing powers of two.
8751 * When we encounter our validation signature, we know the addressing
8752 * has wrapped around, and thus have our chip size.
8753 */
1b27777a 8754 cursize = 0x10;
1da177e4
LT
8755
8756 while (cursize < tp->nvram_size) {
8757 if (tg3_nvram_read(tp, cursize, &val) != 0)
8758 return;
8759
1b27777a 8760 if (swab32(val) == magic)
1da177e4
LT
8761 break;
8762
8763 cursize <<= 1;
8764 }
8765
8766 tp->nvram_size = cursize;
8767}
8768
8769static void __devinit tg3_get_nvram_size(struct tg3 *tp)
8770{
8771 u32 val;
8772
1b27777a
MC
8773 if (tg3_nvram_read(tp, 0, &val) != 0)
8774 return;
8775
8776 /* Selfboot format */
8777 if (swab32(val) != TG3_EEPROM_MAGIC) {
8778 tg3_get_eeprom_size(tp);
8779 return;
8780 }
8781
1da177e4
LT
8782 if (tg3_nvram_read(tp, 0xf0, &val) == 0) {
8783 if (val != 0) {
8784 tp->nvram_size = (val >> 16) * 1024;
8785 return;
8786 }
8787 }
8788 tp->nvram_size = 0x20000;
8789}
8790
8791static void __devinit tg3_get_nvram_info(struct tg3 *tp)
8792{
8793 u32 nvcfg1;
8794
8795 nvcfg1 = tr32(NVRAM_CFG1);
8796 if (nvcfg1 & NVRAM_CFG1_FLASHIF_ENAB) {
8797 tp->tg3_flags2 |= TG3_FLG2_FLASH;
8798 }
8799 else {
8800 nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS;
8801 tw32(NVRAM_CFG1, nvcfg1);
8802 }
8803
4c987487 8804 if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750) ||
a4e2b347 8805 (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) {
1da177e4
LT
8806 switch (nvcfg1 & NVRAM_CFG1_VENDOR_MASK) {
8807 case FLASH_VENDOR_ATMEL_FLASH_BUFFERED:
8808 tp->nvram_jedecnum = JEDEC_ATMEL;
8809 tp->nvram_pagesize = ATMEL_AT45DB0X1B_PAGE_SIZE;
8810 tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
8811 break;
8812 case FLASH_VENDOR_ATMEL_FLASH_UNBUFFERED:
8813 tp->nvram_jedecnum = JEDEC_ATMEL;
8814 tp->nvram_pagesize = ATMEL_AT25F512_PAGE_SIZE;
8815 break;
8816 case FLASH_VENDOR_ATMEL_EEPROM:
8817 tp->nvram_jedecnum = JEDEC_ATMEL;
8818 tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE;
8819 tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
8820 break;
8821 case FLASH_VENDOR_ST:
8822 tp->nvram_jedecnum = JEDEC_ST;
8823 tp->nvram_pagesize = ST_M45PEX0_PAGE_SIZE;
8824 tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
8825 break;
8826 case FLASH_VENDOR_SAIFUN:
8827 tp->nvram_jedecnum = JEDEC_SAIFUN;
8828 tp->nvram_pagesize = SAIFUN_SA25F0XX_PAGE_SIZE;
8829 break;
8830 case FLASH_VENDOR_SST_SMALL:
8831 case FLASH_VENDOR_SST_LARGE:
8832 tp->nvram_jedecnum = JEDEC_SST;
8833 tp->nvram_pagesize = SST_25VF0X0_PAGE_SIZE;
8834 break;
8835 }
8836 }
8837 else {
8838 tp->nvram_jedecnum = JEDEC_ATMEL;
8839 tp->nvram_pagesize = ATMEL_AT45DB0X1B_PAGE_SIZE;
8840 tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
8841 }
8842}
8843
361b4ac2
MC
8844static void __devinit tg3_get_5752_nvram_info(struct tg3 *tp)
8845{
8846 u32 nvcfg1;
8847
8848 nvcfg1 = tr32(NVRAM_CFG1);
8849
e6af301b
MC
8850 /* NVRAM protection for TPM */
8851 if (nvcfg1 & (1 << 27))
8852 tp->tg3_flags2 |= TG3_FLG2_PROTECTED_NVRAM;
8853
361b4ac2
MC
8854 switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) {
8855 case FLASH_5752VENDOR_ATMEL_EEPROM_64KHZ:
8856 case FLASH_5752VENDOR_ATMEL_EEPROM_376KHZ:
8857 tp->nvram_jedecnum = JEDEC_ATMEL;
8858 tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
8859 break;
8860 case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED:
8861 tp->nvram_jedecnum = JEDEC_ATMEL;
8862 tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
8863 tp->tg3_flags2 |= TG3_FLG2_FLASH;
8864 break;
8865 case FLASH_5752VENDOR_ST_M45PE10:
8866 case FLASH_5752VENDOR_ST_M45PE20:
8867 case FLASH_5752VENDOR_ST_M45PE40:
8868 tp->nvram_jedecnum = JEDEC_ST;
8869 tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
8870 tp->tg3_flags2 |= TG3_FLG2_FLASH;
8871 break;
8872 }
8873
8874 if (tp->tg3_flags2 & TG3_FLG2_FLASH) {
8875 switch (nvcfg1 & NVRAM_CFG1_5752PAGE_SIZE_MASK) {
8876 case FLASH_5752PAGE_SIZE_256:
8877 tp->nvram_pagesize = 256;
8878 break;
8879 case FLASH_5752PAGE_SIZE_512:
8880 tp->nvram_pagesize = 512;
8881 break;
8882 case FLASH_5752PAGE_SIZE_1K:
8883 tp->nvram_pagesize = 1024;
8884 break;
8885 case FLASH_5752PAGE_SIZE_2K:
8886 tp->nvram_pagesize = 2048;
8887 break;
8888 case FLASH_5752PAGE_SIZE_4K:
8889 tp->nvram_pagesize = 4096;
8890 break;
8891 case FLASH_5752PAGE_SIZE_264:
8892 tp->nvram_pagesize = 264;
8893 break;
8894 }
8895 }
8896 else {
8897 /* For eeprom, set pagesize to maximum eeprom size */
8898 tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE;
8899
8900 nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS;
8901 tw32(NVRAM_CFG1, nvcfg1);
8902 }
8903}
8904
1b27777a
MC
8905static void __devinit tg3_get_5787_nvram_info(struct tg3 *tp)
8906{
8907 u32 nvcfg1;
8908
8909 nvcfg1 = tr32(NVRAM_CFG1);
8910
8911 switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) {
8912 case FLASH_5787VENDOR_ATMEL_EEPROM_64KHZ:
8913 case FLASH_5787VENDOR_ATMEL_EEPROM_376KHZ:
8914 case FLASH_5787VENDOR_MICRO_EEPROM_64KHZ:
8915 case FLASH_5787VENDOR_MICRO_EEPROM_376KHZ:
8916 tp->nvram_jedecnum = JEDEC_ATMEL;
8917 tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
8918 tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE;
8919
8920 nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS;
8921 tw32(NVRAM_CFG1, nvcfg1);
8922 break;
8923 case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED:
8924 case FLASH_5755VENDOR_ATMEL_FLASH_1:
8925 case FLASH_5755VENDOR_ATMEL_FLASH_2:
8926 case FLASH_5755VENDOR_ATMEL_FLASH_3:
8927 tp->nvram_jedecnum = JEDEC_ATMEL;
8928 tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
8929 tp->tg3_flags2 |= TG3_FLG2_FLASH;
8930 tp->nvram_pagesize = 264;
8931 break;
8932 case FLASH_5752VENDOR_ST_M45PE10:
8933 case FLASH_5752VENDOR_ST_M45PE20:
8934 case FLASH_5752VENDOR_ST_M45PE40:
8935 tp->nvram_jedecnum = JEDEC_ST;
8936 tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
8937 tp->tg3_flags2 |= TG3_FLG2_FLASH;
8938 tp->nvram_pagesize = 256;
8939 break;
8940 }
8941}
8942
1da177e4
LT
8943/* Chips other than 5700/5701 use the NVRAM for fetching info. */
8944static void __devinit tg3_nvram_init(struct tg3 *tp)
8945{
8946 int j;
8947
8948 if (tp->tg3_flags2 & TG3_FLG2_SUN_570X)
8949 return;
8950
8951 tw32_f(GRC_EEPROM_ADDR,
8952 (EEPROM_ADDR_FSM_RESET |
8953 (EEPROM_DEFAULT_CLOCK_PERIOD <<
8954 EEPROM_ADDR_CLKPERD_SHIFT)));
8955
8956 /* XXX schedule_timeout() ... */
8957 for (j = 0; j < 100; j++)
8958 udelay(10);
8959
8960 /* Enable seeprom accesses. */
8961 tw32_f(GRC_LOCAL_CTRL,
8962 tr32(GRC_LOCAL_CTRL) | GRC_LCLCTRL_AUTO_SEEPROM);
8963 udelay(100);
8964
8965 if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 &&
8966 GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) {
8967 tp->tg3_flags |= TG3_FLAG_NVRAM;
8968
ec41c7df
MC
8969 if (tg3_nvram_lock(tp)) {
8970 printk(KERN_WARNING PFX "%s: Cannot get nvarm lock, "
8971 "tg3_nvram_init failed.\n", tp->dev->name);
8972 return;
8973 }
e6af301b 8974 tg3_enable_nvram_access(tp);
1da177e4 8975
361b4ac2
MC
8976 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752)
8977 tg3_get_5752_nvram_info(tp);
1b27777a
MC
8978 else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787)
8979 tg3_get_5787_nvram_info(tp);
361b4ac2
MC
8980 else
8981 tg3_get_nvram_info(tp);
8982
1da177e4
LT
8983 tg3_get_nvram_size(tp);
8984
e6af301b 8985 tg3_disable_nvram_access(tp);
381291b7 8986 tg3_nvram_unlock(tp);
1da177e4
LT
8987
8988 } else {
8989 tp->tg3_flags &= ~(TG3_FLAG_NVRAM | TG3_FLAG_NVRAM_BUFFERED);
8990
8991 tg3_get_eeprom_size(tp);
8992 }
8993}
8994
8995static int tg3_nvram_read_using_eeprom(struct tg3 *tp,
8996 u32 offset, u32 *val)
8997{
8998 u32 tmp;
8999 int i;
9000
9001 if (offset > EEPROM_ADDR_ADDR_MASK ||
9002 (offset % 4) != 0)
9003 return -EINVAL;
9004
9005 tmp = tr32(GRC_EEPROM_ADDR) & ~(EEPROM_ADDR_ADDR_MASK |
9006 EEPROM_ADDR_DEVID_MASK |
9007 EEPROM_ADDR_READ);
9008 tw32(GRC_EEPROM_ADDR,
9009 tmp |
9010 (0 << EEPROM_ADDR_DEVID_SHIFT) |
9011 ((offset << EEPROM_ADDR_ADDR_SHIFT) &
9012 EEPROM_ADDR_ADDR_MASK) |
9013 EEPROM_ADDR_READ | EEPROM_ADDR_START);
9014
9015 for (i = 0; i < 10000; i++) {
9016 tmp = tr32(GRC_EEPROM_ADDR);
9017
9018 if (tmp & EEPROM_ADDR_COMPLETE)
9019 break;
9020 udelay(100);
9021 }
9022 if (!(tmp & EEPROM_ADDR_COMPLETE))
9023 return -EBUSY;
9024
9025 *val = tr32(GRC_EEPROM_DATA);
9026 return 0;
9027}
9028
9029#define NVRAM_CMD_TIMEOUT 10000
9030
9031static int tg3_nvram_exec_cmd(struct tg3 *tp, u32 nvram_cmd)
9032{
9033 int i;
9034
9035 tw32(NVRAM_CMD, nvram_cmd);
9036 for (i = 0; i < NVRAM_CMD_TIMEOUT; i++) {
9037 udelay(10);
9038 if (tr32(NVRAM_CMD) & NVRAM_CMD_DONE) {
9039 udelay(10);
9040 break;
9041 }
9042 }
9043 if (i == NVRAM_CMD_TIMEOUT) {
9044 return -EBUSY;
9045 }
9046 return 0;
9047}
9048
9049static int tg3_nvram_read(struct tg3 *tp, u32 offset, u32 *val)
9050{
9051 int ret;
9052
9053 if (tp->tg3_flags2 & TG3_FLG2_SUN_570X) {
9054 printk(KERN_ERR PFX "Attempt to do nvram_read on Sun 570X\n");
9055 return -EINVAL;
9056 }
9057
9058 if (!(tp->tg3_flags & TG3_FLAG_NVRAM))
9059 return tg3_nvram_read_using_eeprom(tp, offset, val);
9060
9061 if ((tp->tg3_flags & TG3_FLAG_NVRAM_BUFFERED) &&
9062 (tp->tg3_flags2 & TG3_FLG2_FLASH) &&
9063 (tp->nvram_jedecnum == JEDEC_ATMEL)) {
9064
9065 offset = ((offset / tp->nvram_pagesize) <<
9066 ATMEL_AT45DB0X1B_PAGE_POS) +
9067 (offset % tp->nvram_pagesize);
9068 }
9069
9070 if (offset > NVRAM_ADDR_MSK)
9071 return -EINVAL;
9072
ec41c7df
MC
9073 ret = tg3_nvram_lock(tp);
9074 if (ret)
9075 return ret;
1da177e4 9076
e6af301b 9077 tg3_enable_nvram_access(tp);
1da177e4
LT
9078
9079 tw32(NVRAM_ADDR, offset);
9080 ret = tg3_nvram_exec_cmd(tp, NVRAM_CMD_RD | NVRAM_CMD_GO |
9081 NVRAM_CMD_FIRST | NVRAM_CMD_LAST | NVRAM_CMD_DONE);
9082
9083 if (ret == 0)
9084 *val = swab32(tr32(NVRAM_RDDATA));
9085
e6af301b 9086 tg3_disable_nvram_access(tp);
1da177e4 9087
381291b7
MC
9088 tg3_nvram_unlock(tp);
9089
1da177e4
LT
9090 return ret;
9091}
9092
9093static int tg3_nvram_write_block_using_eeprom(struct tg3 *tp,
9094 u32 offset, u32 len, u8 *buf)
9095{
9096 int i, j, rc = 0;
9097 u32 val;
9098
9099 for (i = 0; i < len; i += 4) {
9100 u32 addr, data;
9101
9102 addr = offset + i;
9103
9104 memcpy(&data, buf + i, 4);
9105
9106 tw32(GRC_EEPROM_DATA, cpu_to_le32(data));
9107
9108 val = tr32(GRC_EEPROM_ADDR);
9109 tw32(GRC_EEPROM_ADDR, val | EEPROM_ADDR_COMPLETE);
9110
9111 val &= ~(EEPROM_ADDR_ADDR_MASK | EEPROM_ADDR_DEVID_MASK |
9112 EEPROM_ADDR_READ);
9113 tw32(GRC_EEPROM_ADDR, val |
9114 (0 << EEPROM_ADDR_DEVID_SHIFT) |
9115 (addr & EEPROM_ADDR_ADDR_MASK) |
9116 EEPROM_ADDR_START |
9117 EEPROM_ADDR_WRITE);
9118
9119 for (j = 0; j < 10000; j++) {
9120 val = tr32(GRC_EEPROM_ADDR);
9121
9122 if (val & EEPROM_ADDR_COMPLETE)
9123 break;
9124 udelay(100);
9125 }
9126 if (!(val & EEPROM_ADDR_COMPLETE)) {
9127 rc = -EBUSY;
9128 break;
9129 }
9130 }
9131
9132 return rc;
9133}
9134
9135/* offset and length are dword aligned */
9136static int tg3_nvram_write_block_unbuffered(struct tg3 *tp, u32 offset, u32 len,
9137 u8 *buf)
9138{
9139 int ret = 0;
9140 u32 pagesize = tp->nvram_pagesize;
9141 u32 pagemask = pagesize - 1;
9142 u32 nvram_cmd;
9143 u8 *tmp;
9144
9145 tmp = kmalloc(pagesize, GFP_KERNEL);
9146 if (tmp == NULL)
9147 return -ENOMEM;
9148
9149 while (len) {
9150 int j;
e6af301b 9151 u32 phy_addr, page_off, size;
1da177e4
LT
9152
9153 phy_addr = offset & ~pagemask;
9154
9155 for (j = 0; j < pagesize; j += 4) {
9156 if ((ret = tg3_nvram_read(tp, phy_addr + j,
9157 (u32 *) (tmp + j))))
9158 break;
9159 }
9160 if (ret)
9161 break;
9162
9163 page_off = offset & pagemask;
9164 size = pagesize;
9165 if (len < size)
9166 size = len;
9167
9168 len -= size;
9169
9170 memcpy(tmp + page_off, buf, size);
9171
9172 offset = offset + (pagesize - page_off);
9173
e6af301b 9174 tg3_enable_nvram_access(tp);
1da177e4
LT
9175
9176 /*
9177 * Before we can erase the flash page, we need
9178 * to issue a special "write enable" command.
9179 */
9180 nvram_cmd = NVRAM_CMD_WREN | NVRAM_CMD_GO | NVRAM_CMD_DONE;
9181
9182 if (tg3_nvram_exec_cmd(tp, nvram_cmd))
9183 break;
9184
9185 /* Erase the target page */
9186 tw32(NVRAM_ADDR, phy_addr);
9187
9188 nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE | NVRAM_CMD_WR |
9189 NVRAM_CMD_FIRST | NVRAM_CMD_LAST | NVRAM_CMD_ERASE;
9190
9191 if (tg3_nvram_exec_cmd(tp, nvram_cmd))
9192 break;
9193
9194 /* Issue another write enable to start the write. */
9195 nvram_cmd = NVRAM_CMD_WREN | NVRAM_CMD_GO | NVRAM_CMD_DONE;
9196
9197 if (tg3_nvram_exec_cmd(tp, nvram_cmd))
9198 break;
9199
9200 for (j = 0; j < pagesize; j += 4) {
9201 u32 data;
9202
9203 data = *((u32 *) (tmp + j));
9204 tw32(NVRAM_WRDATA, cpu_to_be32(data));
9205
9206 tw32(NVRAM_ADDR, phy_addr + j);
9207
9208 nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE |
9209 NVRAM_CMD_WR;
9210
9211 if (j == 0)
9212 nvram_cmd |= NVRAM_CMD_FIRST;
9213 else if (j == (pagesize - 4))
9214 nvram_cmd |= NVRAM_CMD_LAST;
9215
9216 if ((ret = tg3_nvram_exec_cmd(tp, nvram_cmd)))
9217 break;
9218 }
9219 if (ret)
9220 break;
9221 }
9222
9223 nvram_cmd = NVRAM_CMD_WRDI | NVRAM_CMD_GO | NVRAM_CMD_DONE;
9224 tg3_nvram_exec_cmd(tp, nvram_cmd);
9225
9226 kfree(tmp);
9227
9228 return ret;
9229}
9230
9231/* offset and length are dword aligned */
9232static int tg3_nvram_write_block_buffered(struct tg3 *tp, u32 offset, u32 len,
9233 u8 *buf)
9234{
9235 int i, ret = 0;
9236
9237 for (i = 0; i < len; i += 4, offset += 4) {
9238 u32 data, page_off, phy_addr, nvram_cmd;
9239
9240 memcpy(&data, buf + i, 4);
9241 tw32(NVRAM_WRDATA, cpu_to_be32(data));
9242
9243 page_off = offset % tp->nvram_pagesize;
9244
9245 if ((tp->tg3_flags2 & TG3_FLG2_FLASH) &&
9246 (tp->nvram_jedecnum == JEDEC_ATMEL)) {
9247
9248 phy_addr = ((offset / tp->nvram_pagesize) <<
9249 ATMEL_AT45DB0X1B_PAGE_POS) + page_off;
9250 }
9251 else {
9252 phy_addr = offset;
9253 }
9254
9255 tw32(NVRAM_ADDR, phy_addr);
9256
9257 nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE | NVRAM_CMD_WR;
9258
9259 if ((page_off == 0) || (i == 0))
9260 nvram_cmd |= NVRAM_CMD_FIRST;
9261 else if (page_off == (tp->nvram_pagesize - 4))
9262 nvram_cmd |= NVRAM_CMD_LAST;
9263
9264 if (i == (len - 4))
9265 nvram_cmd |= NVRAM_CMD_LAST;
9266
4c987487 9267 if ((GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5752) &&
1b27777a 9268 (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5787) &&
4c987487
MC
9269 (tp->nvram_jedecnum == JEDEC_ST) &&
9270 (nvram_cmd & NVRAM_CMD_FIRST)) {
1da177e4
LT
9271
9272 if ((ret = tg3_nvram_exec_cmd(tp,
9273 NVRAM_CMD_WREN | NVRAM_CMD_GO |
9274 NVRAM_CMD_DONE)))
9275
9276 break;
9277 }
9278 if (!(tp->tg3_flags2 & TG3_FLG2_FLASH)) {
9279 /* We always do complete word writes to eeprom. */
9280 nvram_cmd |= (NVRAM_CMD_FIRST | NVRAM_CMD_LAST);
9281 }
9282
9283 if ((ret = tg3_nvram_exec_cmd(tp, nvram_cmd)))
9284 break;
9285 }
9286 return ret;
9287}
9288
9289/* offset and length are dword aligned */
9290static int tg3_nvram_write_block(struct tg3 *tp, u32 offset, u32 len, u8 *buf)
9291{
9292 int ret;
9293
9294 if (tp->tg3_flags2 & TG3_FLG2_SUN_570X) {
9295 printk(KERN_ERR PFX "Attempt to do nvram_write on Sun 570X\n");
9296 return -EINVAL;
9297 }
9298
9299 if (tp->tg3_flags & TG3_FLAG_EEPROM_WRITE_PROT) {
314fba34
MC
9300 tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl &
9301 ~GRC_LCLCTRL_GPIO_OUTPUT1);
1da177e4
LT
9302 udelay(40);
9303 }
9304
9305 if (!(tp->tg3_flags & TG3_FLAG_NVRAM)) {
9306 ret = tg3_nvram_write_block_using_eeprom(tp, offset, len, buf);
9307 }
9308 else {
9309 u32 grc_mode;
9310
ec41c7df
MC
9311 ret = tg3_nvram_lock(tp);
9312 if (ret)
9313 return ret;
1da177e4 9314
e6af301b
MC
9315 tg3_enable_nvram_access(tp);
9316 if ((tp->tg3_flags2 & TG3_FLG2_5750_PLUS) &&
9317 !(tp->tg3_flags2 & TG3_FLG2_PROTECTED_NVRAM))
1da177e4 9318 tw32(NVRAM_WRITE1, 0x406);
1da177e4
LT
9319
9320 grc_mode = tr32(GRC_MODE);
9321 tw32(GRC_MODE, grc_mode | GRC_MODE_NVRAM_WR_ENABLE);
9322
9323 if ((tp->tg3_flags & TG3_FLAG_NVRAM_BUFFERED) ||
9324 !(tp->tg3_flags2 & TG3_FLG2_FLASH)) {
9325
9326 ret = tg3_nvram_write_block_buffered(tp, offset, len,
9327 buf);
9328 }
9329 else {
9330 ret = tg3_nvram_write_block_unbuffered(tp, offset, len,
9331 buf);
9332 }
9333
9334 grc_mode = tr32(GRC_MODE);
9335 tw32(GRC_MODE, grc_mode & ~GRC_MODE_NVRAM_WR_ENABLE);
9336
e6af301b 9337 tg3_disable_nvram_access(tp);
1da177e4
LT
9338 tg3_nvram_unlock(tp);
9339 }
9340
9341 if (tp->tg3_flags & TG3_FLAG_EEPROM_WRITE_PROT) {
314fba34 9342 tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl);
1da177e4
LT
9343 udelay(40);
9344 }
9345
9346 return ret;
9347}
9348
9349struct subsys_tbl_ent {
9350 u16 subsys_vendor, subsys_devid;
9351 u32 phy_id;
9352};
9353
9354static struct subsys_tbl_ent subsys_id_to_phy_id[] = {
9355 /* Broadcom boards. */
9356 { PCI_VENDOR_ID_BROADCOM, 0x1644, PHY_ID_BCM5401 }, /* BCM95700A6 */
9357 { PCI_VENDOR_ID_BROADCOM, 0x0001, PHY_ID_BCM5701 }, /* BCM95701A5 */
9358 { PCI_VENDOR_ID_BROADCOM, 0x0002, PHY_ID_BCM8002 }, /* BCM95700T6 */
9359 { PCI_VENDOR_ID_BROADCOM, 0x0003, 0 }, /* BCM95700A9 */
9360 { PCI_VENDOR_ID_BROADCOM, 0x0005, PHY_ID_BCM5701 }, /* BCM95701T1 */
9361 { PCI_VENDOR_ID_BROADCOM, 0x0006, PHY_ID_BCM5701 }, /* BCM95701T8 */
9362 { PCI_VENDOR_ID_BROADCOM, 0x0007, 0 }, /* BCM95701A7 */
9363 { PCI_VENDOR_ID_BROADCOM, 0x0008, PHY_ID_BCM5701 }, /* BCM95701A10 */
9364 { PCI_VENDOR_ID_BROADCOM, 0x8008, PHY_ID_BCM5701 }, /* BCM95701A12 */
9365 { PCI_VENDOR_ID_BROADCOM, 0x0009, PHY_ID_BCM5703 }, /* BCM95703Ax1 */
9366 { PCI_VENDOR_ID_BROADCOM, 0x8009, PHY_ID_BCM5703 }, /* BCM95703Ax2 */
9367
9368 /* 3com boards. */
9369 { PCI_VENDOR_ID_3COM, 0x1000, PHY_ID_BCM5401 }, /* 3C996T */
9370 { PCI_VENDOR_ID_3COM, 0x1006, PHY_ID_BCM5701 }, /* 3C996BT */
9371 { PCI_VENDOR_ID_3COM, 0x1004, 0 }, /* 3C996SX */
9372 { PCI_VENDOR_ID_3COM, 0x1007, PHY_ID_BCM5701 }, /* 3C1000T */
9373 { PCI_VENDOR_ID_3COM, 0x1008, PHY_ID_BCM5701 }, /* 3C940BR01 */
9374
9375 /* DELL boards. */
9376 { PCI_VENDOR_ID_DELL, 0x00d1, PHY_ID_BCM5401 }, /* VIPER */
9377 { PCI_VENDOR_ID_DELL, 0x0106, PHY_ID_BCM5401 }, /* JAGUAR */
9378 { PCI_VENDOR_ID_DELL, 0x0109, PHY_ID_BCM5411 }, /* MERLOT */
9379 { PCI_VENDOR_ID_DELL, 0x010a, PHY_ID_BCM5411 }, /* SLIM_MERLOT */
9380
9381 /* Compaq boards. */
9382 { PCI_VENDOR_ID_COMPAQ, 0x007c, PHY_ID_BCM5701 }, /* BANSHEE */
9383 { PCI_VENDOR_ID_COMPAQ, 0x009a, PHY_ID_BCM5701 }, /* BANSHEE_2 */
9384 { PCI_VENDOR_ID_COMPAQ, 0x007d, 0 }, /* CHANGELING */
9385 { PCI_VENDOR_ID_COMPAQ, 0x0085, PHY_ID_BCM5701 }, /* NC7780 */
9386 { PCI_VENDOR_ID_COMPAQ, 0x0099, PHY_ID_BCM5701 }, /* NC7780_2 */
9387
9388 /* IBM boards. */
9389 { PCI_VENDOR_ID_IBM, 0x0281, 0 } /* IBM??? */
9390};
9391
9392static inline struct subsys_tbl_ent *lookup_by_subsys(struct tg3 *tp)
9393{
9394 int i;
9395
9396 for (i = 0; i < ARRAY_SIZE(subsys_id_to_phy_id); i++) {
9397 if ((subsys_id_to_phy_id[i].subsys_vendor ==
9398 tp->pdev->subsystem_vendor) &&
9399 (subsys_id_to_phy_id[i].subsys_devid ==
9400 tp->pdev->subsystem_device))
9401 return &subsys_id_to_phy_id[i];
9402 }
9403 return NULL;
9404}
9405
7d0c41ef
MC
9406/* Since this function may be called in D3-hot power state during
9407 * tg3_init_one(), only config cycles are allowed.
9408 */
9409static void __devinit tg3_get_eeprom_hw_cfg(struct tg3 *tp)
1da177e4 9410{
1da177e4 9411 u32 val;
7d0c41ef
MC
9412
9413 /* Make sure register accesses (indirect or otherwise)
9414 * will function correctly.
9415 */
9416 pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL,
9417 tp->misc_host_ctrl);
1da177e4
LT
9418
9419 tp->phy_id = PHY_ID_INVALID;
7d0c41ef
MC
9420 tp->led_ctrl = LED_CTRL_MODE_PHY_1;
9421
72b845e0
DM
9422 /* Do not even try poking around in here on Sun parts. */
9423 if (tp->tg3_flags2 & TG3_FLG2_SUN_570X)
9424 return;
9425
1da177e4
LT
9426 tg3_read_mem(tp, NIC_SRAM_DATA_SIG, &val);
9427 if (val == NIC_SRAM_DATA_SIG_MAGIC) {
9428 u32 nic_cfg, led_cfg;
7d0c41ef
MC
9429 u32 nic_phy_id, ver, cfg2 = 0, eeprom_phy_id;
9430 int eeprom_phy_serdes = 0;
1da177e4
LT
9431
9432 tg3_read_mem(tp, NIC_SRAM_DATA_CFG, &nic_cfg);
9433 tp->nic_sram_data_cfg = nic_cfg;
9434
9435 tg3_read_mem(tp, NIC_SRAM_DATA_VER, &ver);
9436 ver >>= NIC_SRAM_DATA_VER_SHIFT;
9437 if ((GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700) &&
9438 (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) &&
9439 (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5703) &&
9440 (ver > 0) && (ver < 0x100))
9441 tg3_read_mem(tp, NIC_SRAM_DATA_CFG_2, &cfg2);
9442
1da177e4
LT
9443 if ((nic_cfg & NIC_SRAM_DATA_CFG_PHY_TYPE_MASK) ==
9444 NIC_SRAM_DATA_CFG_PHY_TYPE_FIBER)
9445 eeprom_phy_serdes = 1;
9446
9447 tg3_read_mem(tp, NIC_SRAM_DATA_PHY_ID, &nic_phy_id);
9448 if (nic_phy_id != 0) {
9449 u32 id1 = nic_phy_id & NIC_SRAM_DATA_PHY_ID1_MASK;
9450 u32 id2 = nic_phy_id & NIC_SRAM_DATA_PHY_ID2_MASK;
9451
9452 eeprom_phy_id = (id1 >> 16) << 10;
9453 eeprom_phy_id |= (id2 & 0xfc00) << 16;
9454 eeprom_phy_id |= (id2 & 0x03ff) << 0;
9455 } else
9456 eeprom_phy_id = 0;
9457
7d0c41ef 9458 tp->phy_id = eeprom_phy_id;
747e8f8b 9459 if (eeprom_phy_serdes) {
a4e2b347 9460 if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)
747e8f8b
MC
9461 tp->tg3_flags2 |= TG3_FLG2_MII_SERDES;
9462 else
9463 tp->tg3_flags2 |= TG3_FLG2_PHY_SERDES;
9464 }
7d0c41ef 9465
cbf46853 9466 if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS)
1da177e4
LT
9467 led_cfg = cfg2 & (NIC_SRAM_DATA_CFG_LED_MODE_MASK |
9468 SHASTA_EXT_LED_MODE_MASK);
cbf46853 9469 else
1da177e4
LT
9470 led_cfg = nic_cfg & NIC_SRAM_DATA_CFG_LED_MODE_MASK;
9471
9472 switch (led_cfg) {
9473 default:
9474 case NIC_SRAM_DATA_CFG_LED_MODE_PHY_1:
9475 tp->led_ctrl = LED_CTRL_MODE_PHY_1;
9476 break;
9477
9478 case NIC_SRAM_DATA_CFG_LED_MODE_PHY_2:
9479 tp->led_ctrl = LED_CTRL_MODE_PHY_2;
9480 break;
9481
9482 case NIC_SRAM_DATA_CFG_LED_MODE_MAC:
9483 tp->led_ctrl = LED_CTRL_MODE_MAC;
9ba27794
MC
9484
9485 /* Default to PHY_1_MODE if 0 (MAC_MODE) is
9486 * read on some older 5700/5701 bootcode.
9487 */
9488 if (GET_ASIC_REV(tp->pci_chip_rev_id) ==
9489 ASIC_REV_5700 ||
9490 GET_ASIC_REV(tp->pci_chip_rev_id) ==
9491 ASIC_REV_5701)
9492 tp->led_ctrl = LED_CTRL_MODE_PHY_1;
9493
1da177e4
LT
9494 break;
9495
9496 case SHASTA_EXT_LED_SHARED:
9497 tp->led_ctrl = LED_CTRL_MODE_SHARED;
9498 if (tp->pci_chip_rev_id != CHIPREV_ID_5750_A0 &&
9499 tp->pci_chip_rev_id != CHIPREV_ID_5750_A1)
9500 tp->led_ctrl |= (LED_CTRL_MODE_PHY_1 |
9501 LED_CTRL_MODE_PHY_2);
9502 break;
9503
9504 case SHASTA_EXT_LED_MAC:
9505 tp->led_ctrl = LED_CTRL_MODE_SHASTA_MAC;
9506 break;
9507
9508 case SHASTA_EXT_LED_COMBO:
9509 tp->led_ctrl = LED_CTRL_MODE_COMBO;
9510 if (tp->pci_chip_rev_id != CHIPREV_ID_5750_A0)
9511 tp->led_ctrl |= (LED_CTRL_MODE_PHY_1 |
9512 LED_CTRL_MODE_PHY_2);
9513 break;
9514
9515 };
9516
9517 if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
9518 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) &&
9519 tp->pdev->subsystem_vendor == PCI_VENDOR_ID_DELL)
9520 tp->led_ctrl = LED_CTRL_MODE_PHY_2;
9521
9522 if ((GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700) &&
9523 (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) &&
9524 (nic_cfg & NIC_SRAM_DATA_CFG_EEPROM_WP))
9525 tp->tg3_flags |= TG3_FLAG_EEPROM_WRITE_PROT;
9526
9527 if (nic_cfg & NIC_SRAM_DATA_CFG_ASF_ENABLE) {
9528 tp->tg3_flags |= TG3_FLAG_ENABLE_ASF;
cbf46853 9529 if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS)
1da177e4
LT
9530 tp->tg3_flags2 |= TG3_FLG2_ASF_NEW_HANDSHAKE;
9531 }
9532 if (nic_cfg & NIC_SRAM_DATA_CFG_FIBER_WOL)
9533 tp->tg3_flags |= TG3_FLAG_SERDES_WOL_CAP;
9534
9535 if (cfg2 & (1 << 17))
9536 tp->tg3_flags2 |= TG3_FLG2_CAPACITIVE_COUPLING;
9537
9538 /* serdes signal pre-emphasis in register 0x590 set by */
9539 /* bootcode if bit 18 is set */
9540 if (cfg2 & (1 << 18))
9541 tp->tg3_flags2 |= TG3_FLG2_SERDES_PREEMPHASIS;
9542 }
7d0c41ef
MC
9543}
9544
9545static int __devinit tg3_phy_probe(struct tg3 *tp)
9546{
9547 u32 hw_phy_id_1, hw_phy_id_2;
9548 u32 hw_phy_id, hw_phy_id_masked;
9549 int err;
1da177e4
LT
9550
9551 /* Reading the PHY ID register can conflict with ASF
9552 * firwmare access to the PHY hardware.
9553 */
9554 err = 0;
9555 if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) {
9556 hw_phy_id = hw_phy_id_masked = PHY_ID_INVALID;
9557 } else {
9558 /* Now read the physical PHY_ID from the chip and verify
9559 * that it is sane. If it doesn't look good, we fall back
9560 * to either the hard-coded table based PHY_ID and failing
9561 * that the value found in the eeprom area.
9562 */
9563 err |= tg3_readphy(tp, MII_PHYSID1, &hw_phy_id_1);
9564 err |= tg3_readphy(tp, MII_PHYSID2, &hw_phy_id_2);
9565
9566 hw_phy_id = (hw_phy_id_1 & 0xffff) << 10;
9567 hw_phy_id |= (hw_phy_id_2 & 0xfc00) << 16;
9568 hw_phy_id |= (hw_phy_id_2 & 0x03ff) << 0;
9569
9570 hw_phy_id_masked = hw_phy_id & PHY_ID_MASK;
9571 }
9572
9573 if (!err && KNOWN_PHY_ID(hw_phy_id_masked)) {
9574 tp->phy_id = hw_phy_id;
9575 if (hw_phy_id_masked == PHY_ID_BCM8002)
9576 tp->tg3_flags2 |= TG3_FLG2_PHY_SERDES;
da6b2d01
MC
9577 else
9578 tp->tg3_flags2 &= ~TG3_FLG2_PHY_SERDES;
1da177e4 9579 } else {
7d0c41ef
MC
9580 if (tp->phy_id != PHY_ID_INVALID) {
9581 /* Do nothing, phy ID already set up in
9582 * tg3_get_eeprom_hw_cfg().
9583 */
1da177e4
LT
9584 } else {
9585 struct subsys_tbl_ent *p;
9586
9587 /* No eeprom signature? Try the hardcoded
9588 * subsys device table.
9589 */
9590 p = lookup_by_subsys(tp);
9591 if (!p)
9592 return -ENODEV;
9593
9594 tp->phy_id = p->phy_id;
9595 if (!tp->phy_id ||
9596 tp->phy_id == PHY_ID_BCM8002)
9597 tp->tg3_flags2 |= TG3_FLG2_PHY_SERDES;
9598 }
9599 }
9600
747e8f8b 9601 if (!(tp->tg3_flags2 & TG3_FLG2_ANY_SERDES) &&
1da177e4
LT
9602 !(tp->tg3_flags & TG3_FLAG_ENABLE_ASF)) {
9603 u32 bmsr, adv_reg, tg3_ctrl;
9604
9605 tg3_readphy(tp, MII_BMSR, &bmsr);
9606 if (!tg3_readphy(tp, MII_BMSR, &bmsr) &&
9607 (bmsr & BMSR_LSTATUS))
9608 goto skip_phy_reset;
9609
9610 err = tg3_phy_reset(tp);
9611 if (err)
9612 return err;
9613
9614 adv_reg = (ADVERTISE_10HALF | ADVERTISE_10FULL |
9615 ADVERTISE_100HALF | ADVERTISE_100FULL |
9616 ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP);
9617 tg3_ctrl = 0;
9618 if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY)) {
9619 tg3_ctrl = (MII_TG3_CTRL_ADV_1000_HALF |
9620 MII_TG3_CTRL_ADV_1000_FULL);
9621 if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 ||
9622 tp->pci_chip_rev_id == CHIPREV_ID_5701_B0)
9623 tg3_ctrl |= (MII_TG3_CTRL_AS_MASTER |
9624 MII_TG3_CTRL_ENABLE_AS_MASTER);
9625 }
9626
9627 if (!tg3_copper_is_advertising_all(tp)) {
9628 tg3_writephy(tp, MII_ADVERTISE, adv_reg);
9629
9630 if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY))
9631 tg3_writephy(tp, MII_TG3_CTRL, tg3_ctrl);
9632
9633 tg3_writephy(tp, MII_BMCR,
9634 BMCR_ANENABLE | BMCR_ANRESTART);
9635 }
9636 tg3_phy_set_wirespeed(tp);
9637
9638 tg3_writephy(tp, MII_ADVERTISE, adv_reg);
9639 if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY))
9640 tg3_writephy(tp, MII_TG3_CTRL, tg3_ctrl);
9641 }
9642
9643skip_phy_reset:
9644 if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5401) {
9645 err = tg3_init_5401phy_dsp(tp);
9646 if (err)
9647 return err;
9648 }
9649
9650 if (!err && ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5401)) {
9651 err = tg3_init_5401phy_dsp(tp);
9652 }
9653
747e8f8b 9654 if (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES)
1da177e4
LT
9655 tp->link_config.advertising =
9656 (ADVERTISED_1000baseT_Half |
9657 ADVERTISED_1000baseT_Full |
9658 ADVERTISED_Autoneg |
9659 ADVERTISED_FIBRE);
9660 if (tp->tg3_flags & TG3_FLAG_10_100_ONLY)
9661 tp->link_config.advertising &=
9662 ~(ADVERTISED_1000baseT_Half |
9663 ADVERTISED_1000baseT_Full);
9664
9665 return err;
9666}
9667
9668static void __devinit tg3_read_partno(struct tg3 *tp)
9669{
9670 unsigned char vpd_data[256];
9671 int i;
1b27777a 9672 u32 magic;
1da177e4
LT
9673
9674 if (tp->tg3_flags2 & TG3_FLG2_SUN_570X) {
9675 /* Sun decided not to put the necessary bits in the
9676 * NVRAM of their onboard tg3 parts :(
9677 */
9678 strcpy(tp->board_part_number, "Sun 570X");
9679 return;
9680 }
9681
1b27777a
MC
9682 if (tg3_nvram_read(tp, 0x0, &magic))
9683 return;
1da177e4 9684
1b27777a
MC
9685 if (swab32(magic) == TG3_EEPROM_MAGIC) {
9686 for (i = 0; i < 256; i += 4) {
9687 u32 tmp;
1da177e4 9688
1b27777a
MC
9689 if (tg3_nvram_read(tp, 0x100 + i, &tmp))
9690 goto out_not_found;
9691
9692 vpd_data[i + 0] = ((tmp >> 0) & 0xff);
9693 vpd_data[i + 1] = ((tmp >> 8) & 0xff);
9694 vpd_data[i + 2] = ((tmp >> 16) & 0xff);
9695 vpd_data[i + 3] = ((tmp >> 24) & 0xff);
9696 }
9697 } else {
9698 int vpd_cap;
9699
9700 vpd_cap = pci_find_capability(tp->pdev, PCI_CAP_ID_VPD);
9701 for (i = 0; i < 256; i += 4) {
9702 u32 tmp, j = 0;
9703 u16 tmp16;
9704
9705 pci_write_config_word(tp->pdev, vpd_cap + PCI_VPD_ADDR,
9706 i);
9707 while (j++ < 100) {
9708 pci_read_config_word(tp->pdev, vpd_cap +
9709 PCI_VPD_ADDR, &tmp16);
9710 if (tmp16 & 0x8000)
9711 break;
9712 msleep(1);
9713 }
9714 pci_read_config_dword(tp->pdev, vpd_cap + PCI_VPD_DATA,
9715 &tmp);
9716 tmp = cpu_to_le32(tmp);
9717 memcpy(&vpd_data[i], &tmp, 4);
9718 }
1da177e4
LT
9719 }
9720
9721 /* Now parse and find the part number. */
9722 for (i = 0; i < 256; ) {
9723 unsigned char val = vpd_data[i];
9724 int block_end;
9725
9726 if (val == 0x82 || val == 0x91) {
9727 i = (i + 3 +
9728 (vpd_data[i + 1] +
9729 (vpd_data[i + 2] << 8)));
9730 continue;
9731 }
9732
9733 if (val != 0x90)
9734 goto out_not_found;
9735
9736 block_end = (i + 3 +
9737 (vpd_data[i + 1] +
9738 (vpd_data[i + 2] << 8)));
9739 i += 3;
9740 while (i < block_end) {
9741 if (vpd_data[i + 0] == 'P' &&
9742 vpd_data[i + 1] == 'N') {
9743 int partno_len = vpd_data[i + 2];
9744
9745 if (partno_len > 24)
9746 goto out_not_found;
9747
9748 memcpy(tp->board_part_number,
9749 &vpd_data[i + 3],
9750 partno_len);
9751
9752 /* Success. */
9753 return;
9754 }
9755 }
9756
9757 /* Part number not found. */
9758 goto out_not_found;
9759 }
9760
9761out_not_found:
9762 strcpy(tp->board_part_number, "none");
9763}
9764
9765#ifdef CONFIG_SPARC64
9766static int __devinit tg3_is_sun_570X(struct tg3 *tp)
9767{
9768 struct pci_dev *pdev = tp->pdev;
9769 struct pcidev_cookie *pcp = pdev->sysdata;
9770
9771 if (pcp != NULL) {
9772 int node = pcp->prom_node;
9773 u32 venid;
9774 int err;
9775
9776 err = prom_getproperty(node, "subsystem-vendor-id",
9777 (char *) &venid, sizeof(venid));
9778 if (err == 0 || err == -1)
9779 return 0;
9780 if (venid == PCI_VENDOR_ID_SUN)
9781 return 1;
051d3cbd
DM
9782
9783 /* TG3 chips onboard the SunBlade-2500 don't have the
9784 * subsystem-vendor-id set to PCI_VENDOR_ID_SUN but they
9785 * are distinguishable from non-Sun variants by being
9786 * named "network" by the firmware. Non-Sun cards will
9787 * show up as being named "ethernet".
9788 */
9789 if (!strcmp(pcp->prom_name, "network"))
9790 return 1;
1da177e4
LT
9791 }
9792 return 0;
9793}
9794#endif
9795
9796static int __devinit tg3_get_invariants(struct tg3 *tp)
9797{
9798 static struct pci_device_id write_reorder_chipsets[] = {
1da177e4
LT
9799 { PCI_DEVICE(PCI_VENDOR_ID_AMD,
9800 PCI_DEVICE_ID_AMD_FE_GATE_700C) },
399de50b
MC
9801 { PCI_DEVICE(PCI_VENDOR_ID_VIA,
9802 PCI_DEVICE_ID_VIA_8385_0) },
1da177e4
LT
9803 { },
9804 };
9805 u32 misc_ctrl_reg;
9806 u32 cacheline_sz_reg;
9807 u32 pci_state_reg, grc_misc_cfg;
9808 u32 val;
9809 u16 pci_cmd;
9810 int err;
9811
9812#ifdef CONFIG_SPARC64
9813 if (tg3_is_sun_570X(tp))
9814 tp->tg3_flags2 |= TG3_FLG2_SUN_570X;
9815#endif
9816
1da177e4
LT
9817 /* Force memory write invalidate off. If we leave it on,
9818 * then on 5700_BX chips we have to enable a workaround.
9819 * The workaround is to set the TG3PCI_DMA_RW_CTRL boundary
9820 * to match the cacheline size. The Broadcom driver have this
9821 * workaround but turns MWI off all the times so never uses
9822 * it. This seems to suggest that the workaround is insufficient.
9823 */
9824 pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd);
9825 pci_cmd &= ~PCI_COMMAND_INVALIDATE;
9826 pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd);
9827
9828 /* It is absolutely critical that TG3PCI_MISC_HOST_CTRL
9829 * has the register indirect write enable bit set before
9830 * we try to access any of the MMIO registers. It is also
9831 * critical that the PCI-X hw workaround situation is decided
9832 * before that as well.
9833 */
9834 pci_read_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL,
9835 &misc_ctrl_reg);
9836
9837 tp->pci_chip_rev_id = (misc_ctrl_reg >>
9838 MISC_HOST_CTRL_CHIPREV_SHIFT);
9839
ff645bec
MC
9840 /* Wrong chip ID in 5752 A0. This code can be removed later
9841 * as A0 is not in production.
9842 */
9843 if (tp->pci_chip_rev_id == CHIPREV_ID_5752_A0_HW)
9844 tp->pci_chip_rev_id = CHIPREV_ID_5752_A0;
9845
6892914f
MC
9846 /* If we have 5702/03 A1 or A2 on certain ICH chipsets,
9847 * we need to disable memory and use config. cycles
9848 * only to access all registers. The 5702/03 chips
9849 * can mistakenly decode the special cycles from the
9850 * ICH chipsets as memory write cycles, causing corruption
9851 * of register and memory space. Only certain ICH bridges
9852 * will drive special cycles with non-zero data during the
9853 * address phase which can fall within the 5703's address
9854 * range. This is not an ICH bug as the PCI spec allows
9855 * non-zero address during special cycles. However, only
9856 * these ICH bridges are known to drive non-zero addresses
9857 * during special cycles.
9858 *
9859 * Since special cycles do not cross PCI bridges, we only
9860 * enable this workaround if the 5703 is on the secondary
9861 * bus of these ICH bridges.
9862 */
9863 if ((tp->pci_chip_rev_id == CHIPREV_ID_5703_A1) ||
9864 (tp->pci_chip_rev_id == CHIPREV_ID_5703_A2)) {
9865 static struct tg3_dev_id {
9866 u32 vendor;
9867 u32 device;
9868 u32 rev;
9869 } ich_chipsets[] = {
9870 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AA_8,
9871 PCI_ANY_ID },
9872 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AB_8,
9873 PCI_ANY_ID },
9874 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_11,
9875 0xa },
9876 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_6,
9877 PCI_ANY_ID },
9878 { },
9879 };
9880 struct tg3_dev_id *pci_id = &ich_chipsets[0];
9881 struct pci_dev *bridge = NULL;
9882
9883 while (pci_id->vendor != 0) {
9884 bridge = pci_get_device(pci_id->vendor, pci_id->device,
9885 bridge);
9886 if (!bridge) {
9887 pci_id++;
9888 continue;
9889 }
9890 if (pci_id->rev != PCI_ANY_ID) {
9891 u8 rev;
9892
9893 pci_read_config_byte(bridge, PCI_REVISION_ID,
9894 &rev);
9895 if (rev > pci_id->rev)
9896 continue;
9897 }
9898 if (bridge->subordinate &&
9899 (bridge->subordinate->number ==
9900 tp->pdev->bus->number)) {
9901
9902 tp->tg3_flags2 |= TG3_FLG2_ICH_WORKAROUND;
9903 pci_dev_put(bridge);
9904 break;
9905 }
9906 }
9907 }
9908
4a29cc2e
MC
9909 /* The EPB bridge inside 5714, 5715, and 5780 cannot support
9910 * DMA addresses > 40-bit. This bridge may have other additional
9911 * 57xx devices behind it in some 4-port NIC designs for example.
9912 * Any tg3 device found behind the bridge will also need the 40-bit
9913 * DMA workaround.
9914 */
a4e2b347
MC
9915 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780 ||
9916 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) {
9917 tp->tg3_flags2 |= TG3_FLG2_5780_CLASS;
4a29cc2e 9918 tp->tg3_flags |= TG3_FLAG_40BIT_DMA_BUG;
4cf78e4f 9919 tp->msi_cap = pci_find_capability(tp->pdev, PCI_CAP_ID_MSI);
a4e2b347 9920 }
4a29cc2e
MC
9921 else {
9922 struct pci_dev *bridge = NULL;
9923
9924 do {
9925 bridge = pci_get_device(PCI_VENDOR_ID_SERVERWORKS,
9926 PCI_DEVICE_ID_SERVERWORKS_EPB,
9927 bridge);
9928 if (bridge && bridge->subordinate &&
9929 (bridge->subordinate->number <=
9930 tp->pdev->bus->number) &&
9931 (bridge->subordinate->subordinate >=
9932 tp->pdev->bus->number)) {
9933 tp->tg3_flags |= TG3_FLAG_40BIT_DMA_BUG;
9934 pci_dev_put(bridge);
9935 break;
9936 }
9937 } while (bridge);
9938 }
4cf78e4f 9939
1da177e4
LT
9940 /* Initialize misc host control in PCI block. */
9941 tp->misc_host_ctrl |= (misc_ctrl_reg &
9942 MISC_HOST_CTRL_CHIPREV);
9943 pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL,
9944 tp->misc_host_ctrl);
9945
9946 pci_read_config_dword(tp->pdev, TG3PCI_CACHELINESZ,
9947 &cacheline_sz_reg);
9948
9949 tp->pci_cacheline_sz = (cacheline_sz_reg >> 0) & 0xff;
9950 tp->pci_lat_timer = (cacheline_sz_reg >> 8) & 0xff;
9951 tp->pci_hdr_type = (cacheline_sz_reg >> 16) & 0xff;
9952 tp->pci_bist = (cacheline_sz_reg >> 24) & 0xff;
9953
6708e5cc 9954 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750 ||
4cf78e4f 9955 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 ||
d9ab5ad1 9956 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 ||
a4e2b347 9957 (tp->tg3_flags2 & TG3_FLG2_5780_CLASS))
6708e5cc
JL
9958 tp->tg3_flags2 |= TG3_FLG2_5750_PLUS;
9959
1b440c56
JL
9960 if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) ||
9961 (tp->tg3_flags2 & TG3_FLG2_5750_PLUS))
9962 tp->tg3_flags2 |= TG3_FLG2_5705_PLUS;
9963
5a6f3074 9964 if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS) {
fcfa0a32 9965 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787) {
5a6f3074 9966 tp->tg3_flags2 |= TG3_FLG2_HW_TSO_2;
fcfa0a32
MC
9967 tp->tg3_flags2 |= TG3_FLG2_1SHOT_MSI;
9968 } else
5a6f3074
MC
9969 tp->tg3_flags2 |= TG3_FLG2_HW_TSO_1;
9970 }
1da177e4 9971
0f893dc6
MC
9972 if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5705 &&
9973 GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5750 &&
d9ab5ad1
MC
9974 GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5752 &&
9975 GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5787)
0f893dc6
MC
9976 tp->tg3_flags2 |= TG3_FLG2_JUMBO_CAPABLE;
9977
1da177e4
LT
9978 if (pci_find_capability(tp->pdev, PCI_CAP_ID_EXP) != 0)
9979 tp->tg3_flags2 |= TG3_FLG2_PCI_EXPRESS;
9980
399de50b
MC
9981 /* If we have an AMD 762 or VIA K8T800 chipset, write
9982 * reordering to the mailbox registers done by the host
9983 * controller can cause major troubles. We read back from
9984 * every mailbox register write to force the writes to be
9985 * posted to the chip in order.
9986 */
9987 if (pci_dev_present(write_reorder_chipsets) &&
9988 !(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS))
9989 tp->tg3_flags |= TG3_FLAG_MBOX_WRITE_REORDER;
9990
1da177e4
LT
9991 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 &&
9992 tp->pci_lat_timer < 64) {
9993 tp->pci_lat_timer = 64;
9994
9995 cacheline_sz_reg = ((tp->pci_cacheline_sz & 0xff) << 0);
9996 cacheline_sz_reg |= ((tp->pci_lat_timer & 0xff) << 8);
9997 cacheline_sz_reg |= ((tp->pci_hdr_type & 0xff) << 16);
9998 cacheline_sz_reg |= ((tp->pci_bist & 0xff) << 24);
9999
10000 pci_write_config_dword(tp->pdev, TG3PCI_CACHELINESZ,
10001 cacheline_sz_reg);
10002 }
10003
10004 pci_read_config_dword(tp->pdev, TG3PCI_PCISTATE,
10005 &pci_state_reg);
10006
10007 if ((pci_state_reg & PCISTATE_CONV_PCI_MODE) == 0) {
10008 tp->tg3_flags |= TG3_FLAG_PCIX_MODE;
10009
10010 /* If this is a 5700 BX chipset, and we are in PCI-X
10011 * mode, enable register write workaround.
10012 *
10013 * The workaround is to use indirect register accesses
10014 * for all chip writes not to mailbox registers.
10015 */
10016 if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5700_BX) {
10017 u32 pm_reg;
10018 u16 pci_cmd;
10019
10020 tp->tg3_flags |= TG3_FLAG_PCIX_TARGET_HWBUG;
10021
10022 /* The chip can have it's power management PCI config
10023 * space registers clobbered due to this bug.
10024 * So explicitly force the chip into D0 here.
10025 */
10026 pci_read_config_dword(tp->pdev, TG3PCI_PM_CTRL_STAT,
10027 &pm_reg);
10028 pm_reg &= ~PCI_PM_CTRL_STATE_MASK;
10029 pm_reg |= PCI_PM_CTRL_PME_ENABLE | 0 /* D0 */;
10030 pci_write_config_dword(tp->pdev, TG3PCI_PM_CTRL_STAT,
10031 pm_reg);
10032
10033 /* Also, force SERR#/PERR# in PCI command. */
10034 pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd);
10035 pci_cmd |= PCI_COMMAND_PARITY | PCI_COMMAND_SERR;
10036 pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd);
10037 }
10038 }
10039
087fe256
MC
10040 /* 5700 BX chips need to have their TX producer index mailboxes
10041 * written twice to workaround a bug.
10042 */
10043 if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5700_BX)
10044 tp->tg3_flags |= TG3_FLAG_TXD_MBOX_HWBUG;
10045
1da177e4
LT
10046 /* Back to back register writes can cause problems on this chip,
10047 * the workaround is to read back all reg writes except those to
10048 * mailbox regs. See tg3_write_indirect_reg32().
10049 *
10050 * PCI Express 5750_A0 rev chips need this workaround too.
10051 */
10052 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701 ||
10053 ((tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) &&
10054 tp->pci_chip_rev_id == CHIPREV_ID_5750_A0))
10055 tp->tg3_flags |= TG3_FLAG_5701_REG_WRITE_BUG;
10056
10057 if ((pci_state_reg & PCISTATE_BUS_SPEED_HIGH) != 0)
10058 tp->tg3_flags |= TG3_FLAG_PCI_HIGH_SPEED;
10059 if ((pci_state_reg & PCISTATE_BUS_32BIT) != 0)
10060 tp->tg3_flags |= TG3_FLAG_PCI_32BIT;
10061
10062 /* Chip-specific fixup from Broadcom driver */
10063 if ((tp->pci_chip_rev_id == CHIPREV_ID_5704_A0) &&
10064 (!(pci_state_reg & PCISTATE_RETRY_SAME_DMA))) {
10065 pci_state_reg |= PCISTATE_RETRY_SAME_DMA;
10066 pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE, pci_state_reg);
10067 }
10068
1ee582d8 10069 /* Default fast path register access methods */
20094930 10070 tp->read32 = tg3_read32;
1ee582d8 10071 tp->write32 = tg3_write32;
09ee929c 10072 tp->read32_mbox = tg3_read32;
20094930 10073 tp->write32_mbox = tg3_write32;
1ee582d8
MC
10074 tp->write32_tx_mbox = tg3_write32;
10075 tp->write32_rx_mbox = tg3_write32;
10076
10077 /* Various workaround register access methods */
10078 if (tp->tg3_flags & TG3_FLAG_PCIX_TARGET_HWBUG)
10079 tp->write32 = tg3_write_indirect_reg32;
10080 else if (tp->tg3_flags & TG3_FLAG_5701_REG_WRITE_BUG)
10081 tp->write32 = tg3_write_flush_reg32;
10082
10083 if ((tp->tg3_flags & TG3_FLAG_TXD_MBOX_HWBUG) ||
10084 (tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER)) {
10085 tp->write32_tx_mbox = tg3_write32_tx_mbox;
10086 if (tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER)
10087 tp->write32_rx_mbox = tg3_write_flush_reg32;
10088 }
20094930 10089
6892914f
MC
10090 if (tp->tg3_flags2 & TG3_FLG2_ICH_WORKAROUND) {
10091 tp->read32 = tg3_read_indirect_reg32;
10092 tp->write32 = tg3_write_indirect_reg32;
10093 tp->read32_mbox = tg3_read_indirect_mbox;
10094 tp->write32_mbox = tg3_write_indirect_mbox;
10095 tp->write32_tx_mbox = tg3_write_indirect_mbox;
10096 tp->write32_rx_mbox = tg3_write_indirect_mbox;
10097
10098 iounmap(tp->regs);
22abe310 10099 tp->regs = NULL;
6892914f
MC
10100
10101 pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd);
10102 pci_cmd &= ~PCI_COMMAND_MEMORY;
10103 pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd);
10104 }
10105
7d0c41ef
MC
10106 /* Get eeprom hw config before calling tg3_set_power_state().
10107 * In particular, the TG3_FLAG_EEPROM_WRITE_PROT flag must be
10108 * determined before calling tg3_set_power_state() so that
10109 * we know whether or not to switch out of Vaux power.
10110 * When the flag is set, it means that GPIO1 is used for eeprom
10111 * write protect and also implies that it is a LOM where GPIOs
10112 * are not used to switch power.
10113 */
10114 tg3_get_eeprom_hw_cfg(tp);
10115
314fba34
MC
10116 /* Set up tp->grc_local_ctrl before calling tg3_set_power_state().
10117 * GPIO1 driven high will bring 5700's external PHY out of reset.
10118 * It is also used as eeprom write protect on LOMs.
10119 */
10120 tp->grc_local_ctrl = GRC_LCLCTRL_INT_ON_ATTN | GRC_LCLCTRL_AUTO_SEEPROM;
10121 if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) ||
10122 (tp->tg3_flags & TG3_FLAG_EEPROM_WRITE_PROT))
10123 tp->grc_local_ctrl |= (GRC_LCLCTRL_GPIO_OE1 |
10124 GRC_LCLCTRL_GPIO_OUTPUT1);
3e7d83bc
MC
10125 /* Unused GPIO3 must be driven as output on 5752 because there
10126 * are no pull-up resistors on unused GPIO pins.
10127 */
10128 else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752)
10129 tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE3;
314fba34 10130
1da177e4 10131 /* Force the chip into D0. */
bc1c7567 10132 err = tg3_set_power_state(tp, PCI_D0);
1da177e4
LT
10133 if (err) {
10134 printk(KERN_ERR PFX "(%s) transition to D0 failed\n",
10135 pci_name(tp->pdev));
10136 return err;
10137 }
10138
10139 /* 5700 B0 chips do not support checksumming correctly due
10140 * to hardware bugs.
10141 */
10142 if (tp->pci_chip_rev_id == CHIPREV_ID_5700_B0)
10143 tp->tg3_flags |= TG3_FLAG_BROKEN_CHECKSUMS;
10144
10145 /* Pseudo-header checksum is done by hardware logic and not
10146 * the offload processers, so make the chip do the pseudo-
10147 * header checksums on receive. For transmit it is more
10148 * convenient to do the pseudo-header checksum in software
10149 * as Linux does that on transmit for us in all cases.
10150 */
10151 tp->tg3_flags |= TG3_FLAG_NO_TX_PSEUDO_CSUM;
10152 tp->tg3_flags &= ~TG3_FLAG_NO_RX_PSEUDO_CSUM;
10153
10154 /* Derive initial jumbo mode from MTU assigned in
10155 * ether_setup() via the alloc_etherdev() call
10156 */
0f893dc6 10157 if (tp->dev->mtu > ETH_DATA_LEN &&
a4e2b347 10158 !(tp->tg3_flags2 & TG3_FLG2_5780_CLASS))
0f893dc6 10159 tp->tg3_flags |= TG3_FLAG_JUMBO_RING_ENABLE;
1da177e4
LT
10160
10161 /* Determine WakeOnLan speed to use. */
10162 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
10163 tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 ||
10164 tp->pci_chip_rev_id == CHIPREV_ID_5701_B0 ||
10165 tp->pci_chip_rev_id == CHIPREV_ID_5701_B2) {
10166 tp->tg3_flags &= ~(TG3_FLAG_WOL_SPEED_100MB);
10167 } else {
10168 tp->tg3_flags |= TG3_FLAG_WOL_SPEED_100MB;
10169 }
10170
10171 /* A few boards don't want Ethernet@WireSpeed phy feature */
10172 if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) ||
10173 ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) &&
10174 (tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) &&
747e8f8b
MC
10175 (tp->pci_chip_rev_id != CHIPREV_ID_5705_A1)) ||
10176 (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES))
1da177e4
LT
10177 tp->tg3_flags2 |= TG3_FLG2_NO_ETH_WIRE_SPEED;
10178
10179 if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5703_AX ||
10180 GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5704_AX)
10181 tp->tg3_flags2 |= TG3_FLG2_PHY_ADC_BUG;
10182 if (tp->pci_chip_rev_id == CHIPREV_ID_5704_A0)
10183 tp->tg3_flags2 |= TG3_FLG2_PHY_5704_A0_BUG;
10184
d9ab5ad1
MC
10185 if ((tp->tg3_flags2 & TG3_FLG2_5705_PLUS) &&
10186 (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5787))
1da177e4
LT
10187 tp->tg3_flags2 |= TG3_FLG2_PHY_BER_BUG;
10188
1da177e4 10189 tp->coalesce_mode = 0;
1da177e4
LT
10190 if (GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5700_AX &&
10191 GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5700_BX)
10192 tp->coalesce_mode |= HOSTCC_MODE_32BYTE;
10193
10194 /* Initialize MAC MI mode, polling disabled. */
10195 tw32_f(MAC_MI_MODE, tp->mi_mode);
10196 udelay(80);
10197
10198 /* Initialize data/descriptor byte/word swapping. */
10199 val = tr32(GRC_MODE);
10200 val &= GRC_MODE_HOST_STACKUP;
10201 tw32(GRC_MODE, val | tp->grc_mode);
10202
10203 tg3_switch_clocks(tp);
10204
10205 /* Clear this out for sanity. */
10206 tw32(TG3PCI_MEM_WIN_BASE_ADDR, 0);
10207
10208 pci_read_config_dword(tp->pdev, TG3PCI_PCISTATE,
10209 &pci_state_reg);
10210 if ((pci_state_reg & PCISTATE_CONV_PCI_MODE) == 0 &&
10211 (tp->tg3_flags & TG3_FLAG_PCIX_TARGET_HWBUG) == 0) {
10212 u32 chiprevid = GET_CHIP_REV_ID(tp->misc_host_ctrl);
10213
10214 if (chiprevid == CHIPREV_ID_5701_A0 ||
10215 chiprevid == CHIPREV_ID_5701_B0 ||
10216 chiprevid == CHIPREV_ID_5701_B2 ||
10217 chiprevid == CHIPREV_ID_5701_B5) {
10218 void __iomem *sram_base;
10219
10220 /* Write some dummy words into the SRAM status block
10221 * area, see if it reads back correctly. If the return
10222 * value is bad, force enable the PCIX workaround.
10223 */
10224 sram_base = tp->regs + NIC_SRAM_WIN_BASE + NIC_SRAM_STATS_BLK;
10225
10226 writel(0x00000000, sram_base);
10227 writel(0x00000000, sram_base + 4);
10228 writel(0xffffffff, sram_base + 4);
10229 if (readl(sram_base) != 0x00000000)
10230 tp->tg3_flags |= TG3_FLAG_PCIX_TARGET_HWBUG;
10231 }
10232 }
10233
10234 udelay(50);
10235 tg3_nvram_init(tp);
10236
10237 grc_misc_cfg = tr32(GRC_MISC_CFG);
10238 grc_misc_cfg &= GRC_MISC_CFG_BOARD_ID_MASK;
10239
10240 /* Broadcom's driver says that CIOBE multisplit has a bug */
10241#if 0
10242 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 &&
10243 grc_misc_cfg == GRC_MISC_CFG_BOARD_ID_5704CIOBE) {
10244 tp->tg3_flags |= TG3_FLAG_SPLIT_MODE;
10245 tp->split_mode_max_reqs = SPLIT_MODE_5704_MAX_REQ;
10246 }
10247#endif
10248 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 &&
10249 (grc_misc_cfg == GRC_MISC_CFG_BOARD_ID_5788 ||
10250 grc_misc_cfg == GRC_MISC_CFG_BOARD_ID_5788M))
10251 tp->tg3_flags2 |= TG3_FLG2_IS_5788;
10252
fac9b83e
DM
10253 if (!(tp->tg3_flags2 & TG3_FLG2_IS_5788) &&
10254 (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700))
10255 tp->tg3_flags |= TG3_FLAG_TAGGED_STATUS;
10256 if (tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) {
10257 tp->coalesce_mode |= (HOSTCC_MODE_CLRTICK_RXBD |
10258 HOSTCC_MODE_CLRTICK_TXBD);
10259
10260 tp->misc_host_ctrl |= MISC_HOST_CTRL_TAGGED_STATUS;
10261 pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL,
10262 tp->misc_host_ctrl);
10263 }
10264
1da177e4
LT
10265 /* these are limited to 10/100 only */
10266 if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 &&
10267 (grc_misc_cfg == 0x8000 || grc_misc_cfg == 0x4000)) ||
10268 (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 &&
10269 tp->pdev->vendor == PCI_VENDOR_ID_BROADCOM &&
10270 (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5901 ||
10271 tp->pdev->device == PCI_DEVICE_ID_TIGON3_5901_2 ||
10272 tp->pdev->device == PCI_DEVICE_ID_TIGON3_5705F)) ||
10273 (tp->pdev->vendor == PCI_VENDOR_ID_BROADCOM &&
10274 (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5751F ||
10275 tp->pdev->device == PCI_DEVICE_ID_TIGON3_5753F)))
10276 tp->tg3_flags |= TG3_FLAG_10_100_ONLY;
10277
10278 err = tg3_phy_probe(tp);
10279 if (err) {
10280 printk(KERN_ERR PFX "(%s) phy probe failed, err %d\n",
10281 pci_name(tp->pdev), err);
10282 /* ... but do not return immediately ... */
10283 }
10284
10285 tg3_read_partno(tp);
10286
10287 if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) {
10288 tp->tg3_flags &= ~TG3_FLAG_USE_MI_INTERRUPT;
10289 } else {
10290 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700)
10291 tp->tg3_flags |= TG3_FLAG_USE_MI_INTERRUPT;
10292 else
10293 tp->tg3_flags &= ~TG3_FLAG_USE_MI_INTERRUPT;
10294 }
10295
10296 /* 5700 {AX,BX} chips have a broken status block link
10297 * change bit implementation, so we must use the
10298 * status register in those cases.
10299 */
10300 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700)
10301 tp->tg3_flags |= TG3_FLAG_USE_LINKCHG_REG;
10302 else
10303 tp->tg3_flags &= ~TG3_FLAG_USE_LINKCHG_REG;
10304
10305 /* The led_ctrl is set during tg3_phy_probe, here we might
10306 * have to force the link status polling mechanism based
10307 * upon subsystem IDs.
10308 */
10309 if (tp->pdev->subsystem_vendor == PCI_VENDOR_ID_DELL &&
10310 !(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)) {
10311 tp->tg3_flags |= (TG3_FLAG_USE_MI_INTERRUPT |
10312 TG3_FLAG_USE_LINKCHG_REG);
10313 }
10314
10315 /* For all SERDES we poll the MAC status register. */
10316 if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)
10317 tp->tg3_flags |= TG3_FLAG_POLL_SERDES;
10318 else
10319 tp->tg3_flags &= ~TG3_FLAG_POLL_SERDES;
10320
5a6f3074 10321 /* All chips before 5787 can get confused if TX buffers
1da177e4
LT
10322 * straddle the 4GB address boundary in some cases.
10323 */
5a6f3074
MC
10324 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787)
10325 tp->dev->hard_start_xmit = tg3_start_xmit;
10326 else
10327 tp->dev->hard_start_xmit = tg3_start_xmit_dma_bug;
1da177e4
LT
10328
10329 tp->rx_offset = 2;
10330 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701 &&
10331 (tp->tg3_flags & TG3_FLAG_PCIX_MODE) != 0)
10332 tp->rx_offset = 0;
10333
10334 /* By default, disable wake-on-lan. User can change this
10335 * using ETHTOOL_SWOL.
10336 */
10337 tp->tg3_flags &= ~TG3_FLAG_WOL_ENABLE;
10338
10339 return err;
10340}
10341
10342#ifdef CONFIG_SPARC64
10343static int __devinit tg3_get_macaddr_sparc(struct tg3 *tp)
10344{
10345 struct net_device *dev = tp->dev;
10346 struct pci_dev *pdev = tp->pdev;
10347 struct pcidev_cookie *pcp = pdev->sysdata;
10348
10349 if (pcp != NULL) {
10350 int node = pcp->prom_node;
10351
10352 if (prom_getproplen(node, "local-mac-address") == 6) {
10353 prom_getproperty(node, "local-mac-address",
10354 dev->dev_addr, 6);
2ff43697 10355 memcpy(dev->perm_addr, dev->dev_addr, 6);
1da177e4
LT
10356 return 0;
10357 }
10358 }
10359 return -ENODEV;
10360}
10361
10362static int __devinit tg3_get_default_macaddr_sparc(struct tg3 *tp)
10363{
10364 struct net_device *dev = tp->dev;
10365
10366 memcpy(dev->dev_addr, idprom->id_ethaddr, 6);
2ff43697 10367 memcpy(dev->perm_addr, idprom->id_ethaddr, 6);
1da177e4
LT
10368 return 0;
10369}
10370#endif
10371
10372static int __devinit tg3_get_device_address(struct tg3 *tp)
10373{
10374 struct net_device *dev = tp->dev;
10375 u32 hi, lo, mac_offset;
10376
10377#ifdef CONFIG_SPARC64
10378 if (!tg3_get_macaddr_sparc(tp))
10379 return 0;
10380#endif
10381
10382 mac_offset = 0x7c;
4cf78e4f
MC
10383 if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 &&
10384 !(tp->tg3_flags & TG3_FLG2_SUN_570X)) ||
a4e2b347 10385 (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) {
1da177e4
LT
10386 if (tr32(TG3PCI_DUAL_MAC_CTRL) & DUAL_MAC_CTRL_ID)
10387 mac_offset = 0xcc;
10388 if (tg3_nvram_lock(tp))
10389 tw32_f(NVRAM_CMD, NVRAM_CMD_RESET);
10390 else
10391 tg3_nvram_unlock(tp);
10392 }
10393
10394 /* First try to get it from MAC address mailbox. */
10395 tg3_read_mem(tp, NIC_SRAM_MAC_ADDR_HIGH_MBOX, &hi);
10396 if ((hi >> 16) == 0x484b) {
10397 dev->dev_addr[0] = (hi >> 8) & 0xff;
10398 dev->dev_addr[1] = (hi >> 0) & 0xff;
10399
10400 tg3_read_mem(tp, NIC_SRAM_MAC_ADDR_LOW_MBOX, &lo);
10401 dev->dev_addr[2] = (lo >> 24) & 0xff;
10402 dev->dev_addr[3] = (lo >> 16) & 0xff;
10403 dev->dev_addr[4] = (lo >> 8) & 0xff;
10404 dev->dev_addr[5] = (lo >> 0) & 0xff;
10405 }
10406 /* Next, try NVRAM. */
10407 else if (!(tp->tg3_flags & TG3_FLG2_SUN_570X) &&
10408 !tg3_nvram_read(tp, mac_offset + 0, &hi) &&
10409 !tg3_nvram_read(tp, mac_offset + 4, &lo)) {
10410 dev->dev_addr[0] = ((hi >> 16) & 0xff);
10411 dev->dev_addr[1] = ((hi >> 24) & 0xff);
10412 dev->dev_addr[2] = ((lo >> 0) & 0xff);
10413 dev->dev_addr[3] = ((lo >> 8) & 0xff);
10414 dev->dev_addr[4] = ((lo >> 16) & 0xff);
10415 dev->dev_addr[5] = ((lo >> 24) & 0xff);
10416 }
10417 /* Finally just fetch it out of the MAC control regs. */
10418 else {
10419 hi = tr32(MAC_ADDR_0_HIGH);
10420 lo = tr32(MAC_ADDR_0_LOW);
10421
10422 dev->dev_addr[5] = lo & 0xff;
10423 dev->dev_addr[4] = (lo >> 8) & 0xff;
10424 dev->dev_addr[3] = (lo >> 16) & 0xff;
10425 dev->dev_addr[2] = (lo >> 24) & 0xff;
10426 dev->dev_addr[1] = hi & 0xff;
10427 dev->dev_addr[0] = (hi >> 8) & 0xff;
10428 }
10429
10430 if (!is_valid_ether_addr(&dev->dev_addr[0])) {
10431#ifdef CONFIG_SPARC64
10432 if (!tg3_get_default_macaddr_sparc(tp))
10433 return 0;
10434#endif
10435 return -EINVAL;
10436 }
2ff43697 10437 memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
1da177e4
LT
10438 return 0;
10439}
10440
59e6b434
DM
10441#define BOUNDARY_SINGLE_CACHELINE 1
10442#define BOUNDARY_MULTI_CACHELINE 2
10443
10444static u32 __devinit tg3_calc_dma_bndry(struct tg3 *tp, u32 val)
10445{
10446 int cacheline_size;
10447 u8 byte;
10448 int goal;
10449
10450 pci_read_config_byte(tp->pdev, PCI_CACHE_LINE_SIZE, &byte);
10451 if (byte == 0)
10452 cacheline_size = 1024;
10453 else
10454 cacheline_size = (int) byte * 4;
10455
10456 /* On 5703 and later chips, the boundary bits have no
10457 * effect.
10458 */
10459 if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 &&
10460 GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701 &&
10461 !(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS))
10462 goto out;
10463
10464#if defined(CONFIG_PPC64) || defined(CONFIG_IA64) || defined(CONFIG_PARISC)
10465 goal = BOUNDARY_MULTI_CACHELINE;
10466#else
10467#if defined(CONFIG_SPARC64) || defined(CONFIG_ALPHA)
10468 goal = BOUNDARY_SINGLE_CACHELINE;
10469#else
10470 goal = 0;
10471#endif
10472#endif
10473
10474 if (!goal)
10475 goto out;
10476
10477 /* PCI controllers on most RISC systems tend to disconnect
10478 * when a device tries to burst across a cache-line boundary.
10479 * Therefore, letting tg3 do so just wastes PCI bandwidth.
10480 *
10481 * Unfortunately, for PCI-E there are only limited
10482 * write-side controls for this, and thus for reads
10483 * we will still get the disconnects. We'll also waste
10484 * these PCI cycles for both read and write for chips
10485 * other than 5700 and 5701 which do not implement the
10486 * boundary bits.
10487 */
10488 if ((tp->tg3_flags & TG3_FLAG_PCIX_MODE) &&
10489 !(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS)) {
10490 switch (cacheline_size) {
10491 case 16:
10492 case 32:
10493 case 64:
10494 case 128:
10495 if (goal == BOUNDARY_SINGLE_CACHELINE) {
10496 val |= (DMA_RWCTRL_READ_BNDRY_128_PCIX |
10497 DMA_RWCTRL_WRITE_BNDRY_128_PCIX);
10498 } else {
10499 val |= (DMA_RWCTRL_READ_BNDRY_384_PCIX |
10500 DMA_RWCTRL_WRITE_BNDRY_384_PCIX);
10501 }
10502 break;
10503
10504 case 256:
10505 val |= (DMA_RWCTRL_READ_BNDRY_256_PCIX |
10506 DMA_RWCTRL_WRITE_BNDRY_256_PCIX);
10507 break;
10508
10509 default:
10510 val |= (DMA_RWCTRL_READ_BNDRY_384_PCIX |
10511 DMA_RWCTRL_WRITE_BNDRY_384_PCIX);
10512 break;
10513 };
10514 } else if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) {
10515 switch (cacheline_size) {
10516 case 16:
10517 case 32:
10518 case 64:
10519 if (goal == BOUNDARY_SINGLE_CACHELINE) {
10520 val &= ~DMA_RWCTRL_WRITE_BNDRY_DISAB_PCIE;
10521 val |= DMA_RWCTRL_WRITE_BNDRY_64_PCIE;
10522 break;
10523 }
10524 /* fallthrough */
10525 case 128:
10526 default:
10527 val &= ~DMA_RWCTRL_WRITE_BNDRY_DISAB_PCIE;
10528 val |= DMA_RWCTRL_WRITE_BNDRY_128_PCIE;
10529 break;
10530 };
10531 } else {
10532 switch (cacheline_size) {
10533 case 16:
10534 if (goal == BOUNDARY_SINGLE_CACHELINE) {
10535 val |= (DMA_RWCTRL_READ_BNDRY_16 |
10536 DMA_RWCTRL_WRITE_BNDRY_16);
10537 break;
10538 }
10539 /* fallthrough */
10540 case 32:
10541 if (goal == BOUNDARY_SINGLE_CACHELINE) {
10542 val |= (DMA_RWCTRL_READ_BNDRY_32 |
10543 DMA_RWCTRL_WRITE_BNDRY_32);
10544 break;
10545 }
10546 /* fallthrough */
10547 case 64:
10548 if (goal == BOUNDARY_SINGLE_CACHELINE) {
10549 val |= (DMA_RWCTRL_READ_BNDRY_64 |
10550 DMA_RWCTRL_WRITE_BNDRY_64);
10551 break;
10552 }
10553 /* fallthrough */
10554 case 128:
10555 if (goal == BOUNDARY_SINGLE_CACHELINE) {
10556 val |= (DMA_RWCTRL_READ_BNDRY_128 |
10557 DMA_RWCTRL_WRITE_BNDRY_128);
10558 break;
10559 }
10560 /* fallthrough */
10561 case 256:
10562 val |= (DMA_RWCTRL_READ_BNDRY_256 |
10563 DMA_RWCTRL_WRITE_BNDRY_256);
10564 break;
10565 case 512:
10566 val |= (DMA_RWCTRL_READ_BNDRY_512 |
10567 DMA_RWCTRL_WRITE_BNDRY_512);
10568 break;
10569 case 1024:
10570 default:
10571 val |= (DMA_RWCTRL_READ_BNDRY_1024 |
10572 DMA_RWCTRL_WRITE_BNDRY_1024);
10573 break;
10574 };
10575 }
10576
10577out:
10578 return val;
10579}
10580
1da177e4
LT
10581static int __devinit tg3_do_test_dma(struct tg3 *tp, u32 *buf, dma_addr_t buf_dma, int size, int to_device)
10582{
10583 struct tg3_internal_buffer_desc test_desc;
10584 u32 sram_dma_descs;
10585 int i, ret;
10586
10587 sram_dma_descs = NIC_SRAM_DMA_DESC_POOL_BASE;
10588
10589 tw32(FTQ_RCVBD_COMP_FIFO_ENQDEQ, 0);
10590 tw32(FTQ_RCVDATA_COMP_FIFO_ENQDEQ, 0);
10591 tw32(RDMAC_STATUS, 0);
10592 tw32(WDMAC_STATUS, 0);
10593
10594 tw32(BUFMGR_MODE, 0);
10595 tw32(FTQ_RESET, 0);
10596
10597 test_desc.addr_hi = ((u64) buf_dma) >> 32;
10598 test_desc.addr_lo = buf_dma & 0xffffffff;
10599 test_desc.nic_mbuf = 0x00002100;
10600 test_desc.len = size;
10601
10602 /*
10603 * HP ZX1 was seeing test failures for 5701 cards running at 33Mhz
10604 * the *second* time the tg3 driver was getting loaded after an
10605 * initial scan.
10606 *
10607 * Broadcom tells me:
10608 * ...the DMA engine is connected to the GRC block and a DMA
10609 * reset may affect the GRC block in some unpredictable way...
10610 * The behavior of resets to individual blocks has not been tested.
10611 *
10612 * Broadcom noted the GRC reset will also reset all sub-components.
10613 */
10614 if (to_device) {
10615 test_desc.cqid_sqid = (13 << 8) | 2;
10616
10617 tw32_f(RDMAC_MODE, RDMAC_MODE_ENABLE);
10618 udelay(40);
10619 } else {
10620 test_desc.cqid_sqid = (16 << 8) | 7;
10621
10622 tw32_f(WDMAC_MODE, WDMAC_MODE_ENABLE);
10623 udelay(40);
10624 }
10625 test_desc.flags = 0x00000005;
10626
10627 for (i = 0; i < (sizeof(test_desc) / sizeof(u32)); i++) {
10628 u32 val;
10629
10630 val = *(((u32 *)&test_desc) + i);
10631 pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR,
10632 sram_dma_descs + (i * sizeof(u32)));
10633 pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val);
10634 }
10635 pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0);
10636
10637 if (to_device) {
10638 tw32(FTQ_DMA_HIGH_READ_FIFO_ENQDEQ, sram_dma_descs);
10639 } else {
10640 tw32(FTQ_DMA_HIGH_WRITE_FIFO_ENQDEQ, sram_dma_descs);
10641 }
10642
10643 ret = -ENODEV;
10644 for (i = 0; i < 40; i++) {
10645 u32 val;
10646
10647 if (to_device)
10648 val = tr32(FTQ_RCVBD_COMP_FIFO_ENQDEQ);
10649 else
10650 val = tr32(FTQ_RCVDATA_COMP_FIFO_ENQDEQ);
10651 if ((val & 0xffff) == sram_dma_descs) {
10652 ret = 0;
10653 break;
10654 }
10655
10656 udelay(100);
10657 }
10658
10659 return ret;
10660}
10661
ded7340d 10662#define TEST_BUFFER_SIZE 0x2000
1da177e4
LT
10663
10664static int __devinit tg3_test_dma(struct tg3 *tp)
10665{
10666 dma_addr_t buf_dma;
59e6b434 10667 u32 *buf, saved_dma_rwctrl;
1da177e4
LT
10668 int ret;
10669
10670 buf = pci_alloc_consistent(tp->pdev, TEST_BUFFER_SIZE, &buf_dma);
10671 if (!buf) {
10672 ret = -ENOMEM;
10673 goto out_nofree;
10674 }
10675
10676 tp->dma_rwctrl = ((0x7 << DMA_RWCTRL_PCI_WRITE_CMD_SHIFT) |
10677 (0x6 << DMA_RWCTRL_PCI_READ_CMD_SHIFT));
10678
59e6b434 10679 tp->dma_rwctrl = tg3_calc_dma_bndry(tp, tp->dma_rwctrl);
1da177e4
LT
10680
10681 if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) {
10682 /* DMA read watermark not used on PCIE */
10683 tp->dma_rwctrl |= 0x00180000;
10684 } else if (!(tp->tg3_flags & TG3_FLAG_PCIX_MODE)) {
85e94ced
MC
10685 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 ||
10686 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750)
1da177e4
LT
10687 tp->dma_rwctrl |= 0x003f0000;
10688 else
10689 tp->dma_rwctrl |= 0x003f000f;
10690 } else {
10691 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 ||
10692 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) {
10693 u32 ccval = (tr32(TG3PCI_CLOCK_CTRL) & 0x1f);
10694
4a29cc2e
MC
10695 /* If the 5704 is behind the EPB bridge, we can
10696 * do the less restrictive ONE_DMA workaround for
10697 * better performance.
10698 */
10699 if ((tp->tg3_flags & TG3_FLAG_40BIT_DMA_BUG) &&
10700 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704)
10701 tp->dma_rwctrl |= 0x8000;
10702 else if (ccval == 0x6 || ccval == 0x7)
1da177e4
LT
10703 tp->dma_rwctrl |= DMA_RWCTRL_ONE_DMA;
10704
59e6b434 10705 /* Set bit 23 to enable PCIX hw bug fix */
1da177e4 10706 tp->dma_rwctrl |= 0x009f0000;
4cf78e4f
MC
10707 } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780) {
10708 /* 5780 always in PCIX mode */
10709 tp->dma_rwctrl |= 0x00144000;
a4e2b347
MC
10710 } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) {
10711 /* 5714 always in PCIX mode */
10712 tp->dma_rwctrl |= 0x00148000;
1da177e4
LT
10713 } else {
10714 tp->dma_rwctrl |= 0x001b000f;
10715 }
10716 }
10717
10718 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 ||
10719 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704)
10720 tp->dma_rwctrl &= 0xfffffff0;
10721
10722 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
10723 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) {
10724 /* Remove this if it causes problems for some boards. */
10725 tp->dma_rwctrl |= DMA_RWCTRL_USE_MEM_READ_MULT;
10726
10727 /* On 5700/5701 chips, we need to set this bit.
10728 * Otherwise the chip will issue cacheline transactions
10729 * to streamable DMA memory with not all the byte
10730 * enables turned on. This is an error on several
10731 * RISC PCI controllers, in particular sparc64.
10732 *
10733 * On 5703/5704 chips, this bit has been reassigned
10734 * a different meaning. In particular, it is used
10735 * on those chips to enable a PCI-X workaround.
10736 */
10737 tp->dma_rwctrl |= DMA_RWCTRL_ASSERT_ALL_BE;
10738 }
10739
10740 tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl);
10741
10742#if 0
10743 /* Unneeded, already done by tg3_get_invariants. */
10744 tg3_switch_clocks(tp);
10745#endif
10746
10747 ret = 0;
10748 if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 &&
10749 GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701)
10750 goto out;
10751
59e6b434
DM
10752 /* It is best to perform DMA test with maximum write burst size
10753 * to expose the 5700/5701 write DMA bug.
10754 */
10755 saved_dma_rwctrl = tp->dma_rwctrl;
10756 tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK;
10757 tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl);
10758
1da177e4
LT
10759 while (1) {
10760 u32 *p = buf, i;
10761
10762 for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++)
10763 p[i] = i;
10764
10765 /* Send the buffer to the chip. */
10766 ret = tg3_do_test_dma(tp, buf, buf_dma, TEST_BUFFER_SIZE, 1);
10767 if (ret) {
10768 printk(KERN_ERR "tg3_test_dma() Write the buffer failed %d\n", ret);
10769 break;
10770 }
10771
10772#if 0
10773 /* validate data reached card RAM correctly. */
10774 for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++) {
10775 u32 val;
10776 tg3_read_mem(tp, 0x2100 + (i*4), &val);
10777 if (le32_to_cpu(val) != p[i]) {
10778 printk(KERN_ERR " tg3_test_dma() Card buffer corrupted on write! (%d != %d)\n", val, i);
10779 /* ret = -ENODEV here? */
10780 }
10781 p[i] = 0;
10782 }
10783#endif
10784 /* Now read it back. */
10785 ret = tg3_do_test_dma(tp, buf, buf_dma, TEST_BUFFER_SIZE, 0);
10786 if (ret) {
10787 printk(KERN_ERR "tg3_test_dma() Read the buffer failed %d\n", ret);
10788
10789 break;
10790 }
10791
10792 /* Verify it. */
10793 for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++) {
10794 if (p[i] == i)
10795 continue;
10796
59e6b434
DM
10797 if ((tp->dma_rwctrl & DMA_RWCTRL_WRITE_BNDRY_MASK) !=
10798 DMA_RWCTRL_WRITE_BNDRY_16) {
10799 tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK;
1da177e4
LT
10800 tp->dma_rwctrl |= DMA_RWCTRL_WRITE_BNDRY_16;
10801 tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl);
10802 break;
10803 } else {
10804 printk(KERN_ERR "tg3_test_dma() buffer corrupted on read back! (%d != %d)\n", p[i], i);
10805 ret = -ENODEV;
10806 goto out;
10807 }
10808 }
10809
10810 if (i == (TEST_BUFFER_SIZE / sizeof(u32))) {
10811 /* Success. */
10812 ret = 0;
10813 break;
10814 }
10815 }
59e6b434
DM
10816 if ((tp->dma_rwctrl & DMA_RWCTRL_WRITE_BNDRY_MASK) !=
10817 DMA_RWCTRL_WRITE_BNDRY_16) {
6d1cfbab
MC
10818 static struct pci_device_id dma_wait_state_chipsets[] = {
10819 { PCI_DEVICE(PCI_VENDOR_ID_APPLE,
10820 PCI_DEVICE_ID_APPLE_UNI_N_PCI15) },
10821 { },
10822 };
10823
59e6b434 10824 /* DMA test passed without adjusting DMA boundary,
6d1cfbab
MC
10825 * now look for chipsets that are known to expose the
10826 * DMA bug without failing the test.
59e6b434 10827 */
6d1cfbab
MC
10828 if (pci_dev_present(dma_wait_state_chipsets)) {
10829 tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK;
10830 tp->dma_rwctrl |= DMA_RWCTRL_WRITE_BNDRY_16;
10831 }
10832 else
10833 /* Safe to use the calculated DMA boundary. */
10834 tp->dma_rwctrl = saved_dma_rwctrl;
10835
59e6b434
DM
10836 tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl);
10837 }
1da177e4
LT
10838
10839out:
10840 pci_free_consistent(tp->pdev, TEST_BUFFER_SIZE, buf, buf_dma);
10841out_nofree:
10842 return ret;
10843}
10844
10845static void __devinit tg3_init_link_config(struct tg3 *tp)
10846{
10847 tp->link_config.advertising =
10848 (ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full |
10849 ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full |
10850 ADVERTISED_1000baseT_Half | ADVERTISED_1000baseT_Full |
10851 ADVERTISED_Autoneg | ADVERTISED_MII);
10852 tp->link_config.speed = SPEED_INVALID;
10853 tp->link_config.duplex = DUPLEX_INVALID;
10854 tp->link_config.autoneg = AUTONEG_ENABLE;
10855 netif_carrier_off(tp->dev);
10856 tp->link_config.active_speed = SPEED_INVALID;
10857 tp->link_config.active_duplex = DUPLEX_INVALID;
10858 tp->link_config.phy_is_low_power = 0;
10859 tp->link_config.orig_speed = SPEED_INVALID;
10860 tp->link_config.orig_duplex = DUPLEX_INVALID;
10861 tp->link_config.orig_autoneg = AUTONEG_INVALID;
10862}
10863
10864static void __devinit tg3_init_bufmgr_config(struct tg3 *tp)
10865{
fdfec172
MC
10866 if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
10867 tp->bufmgr_config.mbuf_read_dma_low_water =
10868 DEFAULT_MB_RDMA_LOW_WATER_5705;
10869 tp->bufmgr_config.mbuf_mac_rx_low_water =
10870 DEFAULT_MB_MACRX_LOW_WATER_5705;
10871 tp->bufmgr_config.mbuf_high_water =
10872 DEFAULT_MB_HIGH_WATER_5705;
10873
10874 tp->bufmgr_config.mbuf_read_dma_low_water_jumbo =
10875 DEFAULT_MB_RDMA_LOW_WATER_JUMBO_5780;
10876 tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo =
10877 DEFAULT_MB_MACRX_LOW_WATER_JUMBO_5780;
10878 tp->bufmgr_config.mbuf_high_water_jumbo =
10879 DEFAULT_MB_HIGH_WATER_JUMBO_5780;
10880 } else {
10881 tp->bufmgr_config.mbuf_read_dma_low_water =
10882 DEFAULT_MB_RDMA_LOW_WATER;
10883 tp->bufmgr_config.mbuf_mac_rx_low_water =
10884 DEFAULT_MB_MACRX_LOW_WATER;
10885 tp->bufmgr_config.mbuf_high_water =
10886 DEFAULT_MB_HIGH_WATER;
10887
10888 tp->bufmgr_config.mbuf_read_dma_low_water_jumbo =
10889 DEFAULT_MB_RDMA_LOW_WATER_JUMBO;
10890 tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo =
10891 DEFAULT_MB_MACRX_LOW_WATER_JUMBO;
10892 tp->bufmgr_config.mbuf_high_water_jumbo =
10893 DEFAULT_MB_HIGH_WATER_JUMBO;
10894 }
1da177e4
LT
10895
10896 tp->bufmgr_config.dma_low_water = DEFAULT_DMA_LOW_WATER;
10897 tp->bufmgr_config.dma_high_water = DEFAULT_DMA_HIGH_WATER;
10898}
10899
10900static char * __devinit tg3_phy_string(struct tg3 *tp)
10901{
10902 switch (tp->phy_id & PHY_ID_MASK) {
10903 case PHY_ID_BCM5400: return "5400";
10904 case PHY_ID_BCM5401: return "5401";
10905 case PHY_ID_BCM5411: return "5411";
10906 case PHY_ID_BCM5701: return "5701";
10907 case PHY_ID_BCM5703: return "5703";
10908 case PHY_ID_BCM5704: return "5704";
10909 case PHY_ID_BCM5705: return "5705";
10910 case PHY_ID_BCM5750: return "5750";
85e94ced 10911 case PHY_ID_BCM5752: return "5752";
a4e2b347 10912 case PHY_ID_BCM5714: return "5714";
4cf78e4f 10913 case PHY_ID_BCM5780: return "5780";
d9ab5ad1 10914 case PHY_ID_BCM5787: return "5787";
1da177e4
LT
10915 case PHY_ID_BCM8002: return "8002/serdes";
10916 case 0: return "serdes";
10917 default: return "unknown";
10918 };
10919}
10920
f9804ddb
MC
10921static char * __devinit tg3_bus_string(struct tg3 *tp, char *str)
10922{
10923 if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) {
10924 strcpy(str, "PCI Express");
10925 return str;
10926 } else if (tp->tg3_flags & TG3_FLAG_PCIX_MODE) {
10927 u32 clock_ctrl = tr32(TG3PCI_CLOCK_CTRL) & 0x1f;
10928
10929 strcpy(str, "PCIX:");
10930
10931 if ((clock_ctrl == 7) ||
10932 ((tr32(GRC_MISC_CFG) & GRC_MISC_CFG_BOARD_ID_MASK) ==
10933 GRC_MISC_CFG_BOARD_ID_5704CIOBE))
10934 strcat(str, "133MHz");
10935 else if (clock_ctrl == 0)
10936 strcat(str, "33MHz");
10937 else if (clock_ctrl == 2)
10938 strcat(str, "50MHz");
10939 else if (clock_ctrl == 4)
10940 strcat(str, "66MHz");
10941 else if (clock_ctrl == 6)
10942 strcat(str, "100MHz");
f9804ddb
MC
10943 } else {
10944 strcpy(str, "PCI:");
10945 if (tp->tg3_flags & TG3_FLAG_PCI_HIGH_SPEED)
10946 strcat(str, "66MHz");
10947 else
10948 strcat(str, "33MHz");
10949 }
10950 if (tp->tg3_flags & TG3_FLAG_PCI_32BIT)
10951 strcat(str, ":32-bit");
10952 else
10953 strcat(str, ":64-bit");
10954 return str;
10955}
10956
8c2dc7e1 10957static struct pci_dev * __devinit tg3_find_peer(struct tg3 *tp)
1da177e4
LT
10958{
10959 struct pci_dev *peer;
10960 unsigned int func, devnr = tp->pdev->devfn & ~7;
10961
10962 for (func = 0; func < 8; func++) {
10963 peer = pci_get_slot(tp->pdev->bus, devnr | func);
10964 if (peer && peer != tp->pdev)
10965 break;
10966 pci_dev_put(peer);
10967 }
16fe9d74
MC
10968 /* 5704 can be configured in single-port mode, set peer to
10969 * tp->pdev in that case.
10970 */
10971 if (!peer) {
10972 peer = tp->pdev;
10973 return peer;
10974 }
1da177e4
LT
10975
10976 /*
10977 * We don't need to keep the refcount elevated; there's no way
10978 * to remove one half of this device without removing the other
10979 */
10980 pci_dev_put(peer);
10981
10982 return peer;
10983}
10984
15f9850d
DM
10985static void __devinit tg3_init_coal(struct tg3 *tp)
10986{
10987 struct ethtool_coalesce *ec = &tp->coal;
10988
10989 memset(ec, 0, sizeof(*ec));
10990 ec->cmd = ETHTOOL_GCOALESCE;
10991 ec->rx_coalesce_usecs = LOW_RXCOL_TICKS;
10992 ec->tx_coalesce_usecs = LOW_TXCOL_TICKS;
10993 ec->rx_max_coalesced_frames = LOW_RXMAX_FRAMES;
10994 ec->tx_max_coalesced_frames = LOW_TXMAX_FRAMES;
10995 ec->rx_coalesce_usecs_irq = DEFAULT_RXCOAL_TICK_INT;
10996 ec->tx_coalesce_usecs_irq = DEFAULT_TXCOAL_TICK_INT;
10997 ec->rx_max_coalesced_frames_irq = DEFAULT_RXCOAL_MAXF_INT;
10998 ec->tx_max_coalesced_frames_irq = DEFAULT_TXCOAL_MAXF_INT;
10999 ec->stats_block_coalesce_usecs = DEFAULT_STAT_COAL_TICKS;
11000
11001 if (tp->coalesce_mode & (HOSTCC_MODE_CLRTICK_RXBD |
11002 HOSTCC_MODE_CLRTICK_TXBD)) {
11003 ec->rx_coalesce_usecs = LOW_RXCOL_TICKS_CLRTCKS;
11004 ec->rx_coalesce_usecs_irq = DEFAULT_RXCOAL_TICK_INT_CLRTCKS;
11005 ec->tx_coalesce_usecs = LOW_TXCOL_TICKS_CLRTCKS;
11006 ec->tx_coalesce_usecs_irq = DEFAULT_TXCOAL_TICK_INT_CLRTCKS;
11007 }
d244c892
MC
11008
11009 if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
11010 ec->rx_coalesce_usecs_irq = 0;
11011 ec->tx_coalesce_usecs_irq = 0;
11012 ec->stats_block_coalesce_usecs = 0;
11013 }
15f9850d
DM
11014}
11015
1da177e4
LT
11016static int __devinit tg3_init_one(struct pci_dev *pdev,
11017 const struct pci_device_id *ent)
11018{
11019 static int tg3_version_printed = 0;
11020 unsigned long tg3reg_base, tg3reg_len;
11021 struct net_device *dev;
11022 struct tg3 *tp;
72f2afb8 11023 int i, err, pm_cap;
f9804ddb 11024 char str[40];
72f2afb8 11025 u64 dma_mask, persist_dma_mask;
1da177e4
LT
11026
11027 if (tg3_version_printed++ == 0)
11028 printk(KERN_INFO "%s", version);
11029
11030 err = pci_enable_device(pdev);
11031 if (err) {
11032 printk(KERN_ERR PFX "Cannot enable PCI device, "
11033 "aborting.\n");
11034 return err;
11035 }
11036
11037 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
11038 printk(KERN_ERR PFX "Cannot find proper PCI device "
11039 "base address, aborting.\n");
11040 err = -ENODEV;
11041 goto err_out_disable_pdev;
11042 }
11043
11044 err = pci_request_regions(pdev, DRV_MODULE_NAME);
11045 if (err) {
11046 printk(KERN_ERR PFX "Cannot obtain PCI resources, "
11047 "aborting.\n");
11048 goto err_out_disable_pdev;
11049 }
11050
11051 pci_set_master(pdev);
11052
11053 /* Find power-management capability. */
11054 pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
11055 if (pm_cap == 0) {
11056 printk(KERN_ERR PFX "Cannot find PowerManagement capability, "
11057 "aborting.\n");
11058 err = -EIO;
11059 goto err_out_free_res;
11060 }
11061
1da177e4
LT
11062 tg3reg_base = pci_resource_start(pdev, 0);
11063 tg3reg_len = pci_resource_len(pdev, 0);
11064
11065 dev = alloc_etherdev(sizeof(*tp));
11066 if (!dev) {
11067 printk(KERN_ERR PFX "Etherdev alloc failed, aborting.\n");
11068 err = -ENOMEM;
11069 goto err_out_free_res;
11070 }
11071
11072 SET_MODULE_OWNER(dev);
11073 SET_NETDEV_DEV(dev, &pdev->dev);
11074
1da177e4
LT
11075 dev->features |= NETIF_F_LLTX;
11076#if TG3_VLAN_TAG_USED
11077 dev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
11078 dev->vlan_rx_register = tg3_vlan_rx_register;
11079 dev->vlan_rx_kill_vid = tg3_vlan_rx_kill_vid;
11080#endif
11081
11082 tp = netdev_priv(dev);
11083 tp->pdev = pdev;
11084 tp->dev = dev;
11085 tp->pm_cap = pm_cap;
11086 tp->mac_mode = TG3_DEF_MAC_MODE;
11087 tp->rx_mode = TG3_DEF_RX_MODE;
11088 tp->tx_mode = TG3_DEF_TX_MODE;
11089 tp->mi_mode = MAC_MI_MODE_BASE;
11090 if (tg3_debug > 0)
11091 tp->msg_enable = tg3_debug;
11092 else
11093 tp->msg_enable = TG3_DEF_MSG_ENABLE;
11094
11095 /* The word/byte swap controls here control register access byte
11096 * swapping. DMA data byte swapping is controlled in the GRC_MODE
11097 * setting below.
11098 */
11099 tp->misc_host_ctrl =
11100 MISC_HOST_CTRL_MASK_PCI_INT |
11101 MISC_HOST_CTRL_WORD_SWAP |
11102 MISC_HOST_CTRL_INDIR_ACCESS |
11103 MISC_HOST_CTRL_PCISTATE_RW;
11104
11105 /* The NONFRM (non-frame) byte/word swap controls take effect
11106 * on descriptor entries, anything which isn't packet data.
11107 *
11108 * The StrongARM chips on the board (one for tx, one for rx)
11109 * are running in big-endian mode.
11110 */
11111 tp->grc_mode = (GRC_MODE_WSWAP_DATA | GRC_MODE_BSWAP_DATA |
11112 GRC_MODE_WSWAP_NONFRM_DATA);
11113#ifdef __BIG_ENDIAN
11114 tp->grc_mode |= GRC_MODE_BSWAP_NONFRM_DATA;
11115#endif
11116 spin_lock_init(&tp->lock);
11117 spin_lock_init(&tp->tx_lock);
11118 spin_lock_init(&tp->indirect_lock);
11119 INIT_WORK(&tp->reset_task, tg3_reset_task, tp);
11120
11121 tp->regs = ioremap_nocache(tg3reg_base, tg3reg_len);
11122 if (tp->regs == 0UL) {
11123 printk(KERN_ERR PFX "Cannot map device registers, "
11124 "aborting.\n");
11125 err = -ENOMEM;
11126 goto err_out_free_dev;
11127 }
11128
11129 tg3_init_link_config(tp);
11130
1da177e4
LT
11131 tp->rx_pending = TG3_DEF_RX_RING_PENDING;
11132 tp->rx_jumbo_pending = TG3_DEF_RX_JUMBO_RING_PENDING;
11133 tp->tx_pending = TG3_DEF_TX_RING_PENDING;
11134
11135 dev->open = tg3_open;
11136 dev->stop = tg3_close;
11137 dev->get_stats = tg3_get_stats;
11138 dev->set_multicast_list = tg3_set_rx_mode;
11139 dev->set_mac_address = tg3_set_mac_addr;
11140 dev->do_ioctl = tg3_ioctl;
11141 dev->tx_timeout = tg3_tx_timeout;
11142 dev->poll = tg3_poll;
11143 dev->ethtool_ops = &tg3_ethtool_ops;
11144 dev->weight = 64;
11145 dev->watchdog_timeo = TG3_TX_TIMEOUT;
11146 dev->change_mtu = tg3_change_mtu;
11147 dev->irq = pdev->irq;
11148#ifdef CONFIG_NET_POLL_CONTROLLER
11149 dev->poll_controller = tg3_poll_controller;
11150#endif
11151
11152 err = tg3_get_invariants(tp);
11153 if (err) {
11154 printk(KERN_ERR PFX "Problem fetching invariants of chip, "
11155 "aborting.\n");
11156 goto err_out_iounmap;
11157 }
11158
4a29cc2e
MC
11159 /* The EPB bridge inside 5714, 5715, and 5780 and any
11160 * device behind the EPB cannot support DMA addresses > 40-bit.
72f2afb8
MC
11161 * On 64-bit systems with IOMMU, use 40-bit dma_mask.
11162 * On 64-bit systems without IOMMU, use 64-bit dma_mask and
11163 * do DMA address check in tg3_start_xmit().
11164 */
4a29cc2e
MC
11165 if (tp->tg3_flags2 & TG3_FLG2_IS_5788)
11166 persist_dma_mask = dma_mask = DMA_32BIT_MASK;
11167 else if (tp->tg3_flags & TG3_FLAG_40BIT_DMA_BUG) {
72f2afb8
MC
11168 persist_dma_mask = dma_mask = DMA_40BIT_MASK;
11169#ifdef CONFIG_HIGHMEM
11170 dma_mask = DMA_64BIT_MASK;
11171#endif
4a29cc2e 11172 } else
72f2afb8
MC
11173 persist_dma_mask = dma_mask = DMA_64BIT_MASK;
11174
11175 /* Configure DMA attributes. */
11176 if (dma_mask > DMA_32BIT_MASK) {
11177 err = pci_set_dma_mask(pdev, dma_mask);
11178 if (!err) {
11179 dev->features |= NETIF_F_HIGHDMA;
11180 err = pci_set_consistent_dma_mask(pdev,
11181 persist_dma_mask);
11182 if (err < 0) {
11183 printk(KERN_ERR PFX "Unable to obtain 64 bit "
11184 "DMA for consistent allocations\n");
11185 goto err_out_iounmap;
11186 }
11187 }
11188 }
11189 if (err || dma_mask == DMA_32BIT_MASK) {
11190 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
11191 if (err) {
11192 printk(KERN_ERR PFX "No usable DMA configuration, "
11193 "aborting.\n");
11194 goto err_out_iounmap;
11195 }
11196 }
11197
fdfec172 11198 tg3_init_bufmgr_config(tp);
1da177e4
LT
11199
11200#if TG3_TSO_SUPPORT != 0
11201 if (tp->tg3_flags2 & TG3_FLG2_HW_TSO) {
11202 tp->tg3_flags2 |= TG3_FLG2_TSO_CAPABLE;
11203 }
11204 else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
11205 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701 ||
11206 tp->pci_chip_rev_id == CHIPREV_ID_5705_A0 ||
11207 (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) != 0) {
11208 tp->tg3_flags2 &= ~TG3_FLG2_TSO_CAPABLE;
11209 } else {
11210 tp->tg3_flags2 |= TG3_FLG2_TSO_CAPABLE;
11211 }
11212
4e3a7aaa
MC
11213 /* TSO is on by default on chips that support hardware TSO.
11214 * Firmware TSO on older chips gives lower performance, so it
11215 * is off by default, but can be enabled using ethtool.
11216 */
11217 if (tp->tg3_flags2 & TG3_FLG2_HW_TSO)
1da177e4 11218 dev->features |= NETIF_F_TSO;
1da177e4
LT
11219
11220#endif
11221
11222 if (tp->pci_chip_rev_id == CHIPREV_ID_5705_A1 &&
11223 !(tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) &&
11224 !(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH)) {
11225 tp->tg3_flags2 |= TG3_FLG2_MAX_RXPEND_64;
11226 tp->rx_pending = 63;
11227 }
11228
8c2dc7e1
MC
11229 if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) ||
11230 (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714))
11231 tp->pdev_peer = tg3_find_peer(tp);
1da177e4
LT
11232
11233 err = tg3_get_device_address(tp);
11234 if (err) {
11235 printk(KERN_ERR PFX "Could not obtain valid ethernet address, "
11236 "aborting.\n");
11237 goto err_out_iounmap;
11238 }
11239
11240 /*
11241 * Reset chip in case UNDI or EFI driver did not shutdown
11242 * DMA self test will enable WDMAC and we'll see (spurious)
11243 * pending DMA on the PCI bus at that point.
11244 */
11245 if ((tr32(HOSTCC_MODE) & HOSTCC_MODE_ENABLE) ||
11246 (tr32(WDMAC_MODE) & WDMAC_MODE_ENABLE)) {
11247 pci_save_state(tp->pdev);
11248 tw32(MEMARB_MODE, MEMARB_MODE_ENABLE);
944d980e 11249 tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
1da177e4
LT
11250 }
11251
11252 err = tg3_test_dma(tp);
11253 if (err) {
11254 printk(KERN_ERR PFX "DMA engine test failed, aborting.\n");
11255 goto err_out_iounmap;
11256 }
11257
11258 /* Tigon3 can do ipv4 only... and some chips have buggy
11259 * checksumming.
11260 */
11261 if ((tp->tg3_flags & TG3_FLAG_BROKEN_CHECKSUMS) == 0) {
9c27dbdf
MC
11262 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787)
11263 dev->features |= NETIF_F_HW_CSUM;
11264 else
11265 dev->features |= NETIF_F_IP_CSUM;
11266 dev->features |= NETIF_F_SG;
1da177e4
LT
11267 tp->tg3_flags |= TG3_FLAG_RX_CHECKSUMS;
11268 } else
11269 tp->tg3_flags &= ~TG3_FLAG_RX_CHECKSUMS;
11270
1da177e4
LT
11271 /* flow control autonegotiation is default behavior */
11272 tp->tg3_flags |= TG3_FLAG_PAUSE_AUTONEG;
11273
15f9850d
DM
11274 tg3_init_coal(tp);
11275
7d3f4c97
DM
11276 /* Now that we have fully setup the chip, save away a snapshot
11277 * of the PCI config space. We need to restore this after
11278 * GRC_MISC_CFG core clock resets and some resume events.
11279 */
11280 pci_save_state(tp->pdev);
11281
1da177e4
LT
11282 err = register_netdev(dev);
11283 if (err) {
11284 printk(KERN_ERR PFX "Cannot register net device, "
11285 "aborting.\n");
11286 goto err_out_iounmap;
11287 }
11288
11289 pci_set_drvdata(pdev, dev);
11290
f9804ddb 11291 printk(KERN_INFO "%s: Tigon3 [partno(%s) rev %04x PHY(%s)] (%s) %sBaseT Ethernet ",
1da177e4
LT
11292 dev->name,
11293 tp->board_part_number,
11294 tp->pci_chip_rev_id,
11295 tg3_phy_string(tp),
f9804ddb 11296 tg3_bus_string(tp, str),
1da177e4
LT
11297 (tp->tg3_flags & TG3_FLAG_10_100_ONLY) ? "10/100" : "10/100/1000");
11298
11299 for (i = 0; i < 6; i++)
11300 printk("%2.2x%c", dev->dev_addr[i],
11301 i == 5 ? '\n' : ':');
11302
11303 printk(KERN_INFO "%s: RXcsums[%d] LinkChgREG[%d] "
11304 "MIirq[%d] ASF[%d] Split[%d] WireSpeed[%d] "
11305 "TSOcap[%d] \n",
11306 dev->name,
11307 (tp->tg3_flags & TG3_FLAG_RX_CHECKSUMS) != 0,
11308 (tp->tg3_flags & TG3_FLAG_USE_LINKCHG_REG) != 0,
11309 (tp->tg3_flags & TG3_FLAG_USE_MI_INTERRUPT) != 0,
11310 (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) != 0,
11311 (tp->tg3_flags & TG3_FLAG_SPLIT_MODE) != 0,
11312 (tp->tg3_flags2 & TG3_FLG2_NO_ETH_WIRE_SPEED) == 0,
11313 (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) != 0);
4a29cc2e
MC
11314 printk(KERN_INFO "%s: dma_rwctrl[%08x] dma_mask[%d-bit]\n",
11315 dev->name, tp->dma_rwctrl,
11316 (pdev->dma_mask == DMA_32BIT_MASK) ? 32 :
11317 (((u64) pdev->dma_mask == DMA_40BIT_MASK) ? 40 : 64));
1da177e4
LT
11318
11319 return 0;
11320
11321err_out_iounmap:
6892914f
MC
11322 if (tp->regs) {
11323 iounmap(tp->regs);
22abe310 11324 tp->regs = NULL;
6892914f 11325 }
1da177e4
LT
11326
11327err_out_free_dev:
11328 free_netdev(dev);
11329
11330err_out_free_res:
11331 pci_release_regions(pdev);
11332
11333err_out_disable_pdev:
11334 pci_disable_device(pdev);
11335 pci_set_drvdata(pdev, NULL);
11336 return err;
11337}
11338
11339static void __devexit tg3_remove_one(struct pci_dev *pdev)
11340{
11341 struct net_device *dev = pci_get_drvdata(pdev);
11342
11343 if (dev) {
11344 struct tg3 *tp = netdev_priv(dev);
11345
7faa006f 11346 flush_scheduled_work();
1da177e4 11347 unregister_netdev(dev);
6892914f
MC
11348 if (tp->regs) {
11349 iounmap(tp->regs);
22abe310 11350 tp->regs = NULL;
6892914f 11351 }
1da177e4
LT
11352 free_netdev(dev);
11353 pci_release_regions(pdev);
11354 pci_disable_device(pdev);
11355 pci_set_drvdata(pdev, NULL);
11356 }
11357}
11358
11359static int tg3_suspend(struct pci_dev *pdev, pm_message_t state)
11360{
11361 struct net_device *dev = pci_get_drvdata(pdev);
11362 struct tg3 *tp = netdev_priv(dev);
11363 int err;
11364
11365 if (!netif_running(dev))
11366 return 0;
11367
7faa006f 11368 flush_scheduled_work();
1da177e4
LT
11369 tg3_netif_stop(tp);
11370
11371 del_timer_sync(&tp->timer);
11372
f47c11ee 11373 tg3_full_lock(tp, 1);
1da177e4 11374 tg3_disable_ints(tp);
f47c11ee 11375 tg3_full_unlock(tp);
1da177e4
LT
11376
11377 netif_device_detach(dev);
11378
f47c11ee 11379 tg3_full_lock(tp, 0);
944d980e 11380 tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
6a9eba15 11381 tp->tg3_flags &= ~TG3_FLAG_INIT_COMPLETE;
f47c11ee 11382 tg3_full_unlock(tp);
1da177e4
LT
11383
11384 err = tg3_set_power_state(tp, pci_choose_state(pdev, state));
11385 if (err) {
f47c11ee 11386 tg3_full_lock(tp, 0);
1da177e4 11387
6a9eba15 11388 tp->tg3_flags |= TG3_FLAG_INIT_COMPLETE;
1da177e4
LT
11389 tg3_init_hw(tp);
11390
11391 tp->timer.expires = jiffies + tp->timer_offset;
11392 add_timer(&tp->timer);
11393
11394 netif_device_attach(dev);
11395 tg3_netif_start(tp);
11396
f47c11ee 11397 tg3_full_unlock(tp);
1da177e4
LT
11398 }
11399
11400 return err;
11401}
11402
11403static int tg3_resume(struct pci_dev *pdev)
11404{
11405 struct net_device *dev = pci_get_drvdata(pdev);
11406 struct tg3 *tp = netdev_priv(dev);
11407 int err;
11408
11409 if (!netif_running(dev))
11410 return 0;
11411
11412 pci_restore_state(tp->pdev);
11413
bc1c7567 11414 err = tg3_set_power_state(tp, PCI_D0);
1da177e4
LT
11415 if (err)
11416 return err;
11417
11418 netif_device_attach(dev);
11419
f47c11ee 11420 tg3_full_lock(tp, 0);
1da177e4 11421
6a9eba15 11422 tp->tg3_flags |= TG3_FLAG_INIT_COMPLETE;
1da177e4
LT
11423 tg3_init_hw(tp);
11424
11425 tp->timer.expires = jiffies + tp->timer_offset;
11426 add_timer(&tp->timer);
11427
1da177e4
LT
11428 tg3_netif_start(tp);
11429
f47c11ee 11430 tg3_full_unlock(tp);
1da177e4
LT
11431
11432 return 0;
11433}
11434
11435static struct pci_driver tg3_driver = {
11436 .name = DRV_MODULE_NAME,
11437 .id_table = tg3_pci_tbl,
11438 .probe = tg3_init_one,
11439 .remove = __devexit_p(tg3_remove_one),
11440 .suspend = tg3_suspend,
11441 .resume = tg3_resume
11442};
11443
11444static int __init tg3_init(void)
11445{
11446 return pci_module_init(&tg3_driver);
11447}
11448
11449static void __exit tg3_cleanup(void)
11450{
11451 pci_unregister_driver(&tg3_driver);
11452}
11453
11454module_init(tg3_init);
11455module_exit(tg3_cleanup);