2 * tg3.c: Broadcom Tigon3 ethernet driver.
4 * Copyright (C) 2001, 2002, 2003, 2004 David S. Miller (davem@redhat.com)
5 * Copyright (C) 2001, 2002, 2003 Jeff Garzik (jgarzik@pobox.com)
6 * Copyright (C) 2004 Sun Microsystems Inc.
7 * Copyright (C) 2005-2010 Broadcom Corporation.
10 * Derived from proprietary unpublished source code,
11 * Copyright (C) 2000-2003 Broadcom Corporation.
13 * Permission is hereby granted for the distribution of this firmware
14 * data in hexadecimal or equivalent format, provided this copyright
15 * notice is accompanying it.
19 #include <linux/module.h>
20 #include <linux/moduleparam.h>
21 #include <linux/kernel.h>
22 #include <linux/types.h>
23 #include <linux/compiler.h>
24 #include <linux/slab.h>
25 #include <linux/delay.h>
27 #include <linux/init.h>
28 #include <linux/ioport.h>
29 #include <linux/pci.h>
30 #include <linux/netdevice.h>
31 #include <linux/etherdevice.h>
32 #include <linux/skbuff.h>
33 #include <linux/ethtool.h>
34 #include <linux/mii.h>
35 #include <linux/phy.h>
36 #include <linux/brcmphy.h>
37 #include <linux/if_vlan.h>
39 #include <linux/tcp.h>
40 #include <linux/workqueue.h>
41 #include <linux/prefetch.h>
42 #include <linux/dma-mapping.h>
43 #include <linux/firmware.h>
45 #include <net/checksum.h>
48 #include <asm/system.h>
50 #include <asm/byteorder.h>
51 #include <asm/uaccess.h>
54 #include <asm/idprom.h>
61 #if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
62 #define TG3_VLAN_TAG_USED 1
64 #define TG3_VLAN_TAG_USED 0
69 #define DRV_MODULE_NAME "tg3"
70 #define DRV_MODULE_VERSION "3.108"
71 #define DRV_MODULE_RELDATE "February 17, 2010"
73 #define TG3_DEF_MAC_MODE 0
74 #define TG3_DEF_RX_MODE 0
75 #define TG3_DEF_TX_MODE 0
76 #define TG3_DEF_MSG_ENABLE \
86 /* length of time before we decide the hardware is borked,
87 * and dev->tx_timeout() should be called to fix the problem
89 #define TG3_TX_TIMEOUT (5 * HZ)
91 /* hardware minimum and maximum for a single frame's data payload */
92 #define TG3_MIN_MTU 60
93 #define TG3_MAX_MTU(tp) \
94 ((tp->tg3_flags & TG3_FLAG_JUMBO_CAPABLE) ? 9000 : 1500)
96 /* These numbers seem to be hard coded in the NIC firmware somehow.
97 * You can't change the ring sizes, but you can change where you place
98 * them in the NIC onboard memory.
100 #define TG3_RX_RING_SIZE 512
101 #define TG3_DEF_RX_RING_PENDING 200
102 #define TG3_RX_JUMBO_RING_SIZE 256
103 #define TG3_DEF_RX_JUMBO_RING_PENDING 100
104 #define TG3_RSS_INDIR_TBL_SIZE 128
106 /* Do not place this n-ring entries value into the tp struct itself,
107 * we really want to expose these constants to GCC so that modulo et
108 * al. operations are done with shifts and masks instead of with
109 * hw multiply/modulo instructions. Another solution would be to
110 * replace things like '% foo' with '& (foo - 1)'.
112 #define TG3_RX_RCB_RING_SIZE(tp) \
113 (((tp->tg3_flags & TG3_FLAG_JUMBO_CAPABLE) && \
114 !(tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) ? 1024 : 512)
116 #define TG3_TX_RING_SIZE 512
117 #define TG3_DEF_TX_RING_PENDING (TG3_TX_RING_SIZE - 1)
119 #define TG3_RX_RING_BYTES (sizeof(struct tg3_rx_buffer_desc) * \
121 #define TG3_RX_JUMBO_RING_BYTES (sizeof(struct tg3_ext_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) * \
127 #define NEXT_TX(N) (((N) + 1) & (TG3_TX_RING_SIZE - 1))
129 #define TG3_DMA_BYTE_ENAB 64
131 #define TG3_RX_STD_DMA_SZ 1536
132 #define TG3_RX_JMB_DMA_SZ 9046
134 #define TG3_RX_DMA_TO_MAP_SZ(x) ((x) + TG3_DMA_BYTE_ENAB)
136 #define TG3_RX_STD_MAP_SZ TG3_RX_DMA_TO_MAP_SZ(TG3_RX_STD_DMA_SZ)
137 #define TG3_RX_JMB_MAP_SZ TG3_RX_DMA_TO_MAP_SZ(TG3_RX_JMB_DMA_SZ)
139 #define TG3_RX_STD_BUFF_RING_SIZE \
140 (sizeof(struct ring_info) * TG3_RX_RING_SIZE)
142 #define TG3_RX_JMB_BUFF_RING_SIZE \
143 (sizeof(struct ring_info) * TG3_RX_JUMBO_RING_SIZE)
145 #define TG3_RSS_MIN_NUM_MSIX_VECS 2
147 /* minimum number of free TX descriptors required to wake up TX process */
148 #define TG3_TX_WAKEUP_THRESH(tnapi) ((tnapi)->tx_pending / 4)
150 #define TG3_RAW_IP_ALIGN 2
152 /* number of ETHTOOL_GSTATS u64's */
153 #define TG3_NUM_STATS (sizeof(struct tg3_ethtool_stats)/sizeof(u64))
155 #define TG3_NUM_TEST 6
157 #define TG3_FW_UPDATE_TIMEOUT_SEC 5
159 #define FIRMWARE_TG3 "tigon/tg3.bin"
160 #define FIRMWARE_TG3TSO "tigon/tg3_tso.bin"
161 #define FIRMWARE_TG3TSO5 "tigon/tg3_tso5.bin"
163 static char version[] __devinitdata =
164 DRV_MODULE_NAME ".c:v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")";
166 MODULE_AUTHOR("David S. Miller (davem@redhat.com) and Jeff Garzik (jgarzik@pobox.com)");
167 MODULE_DESCRIPTION("Broadcom Tigon3 ethernet driver");
168 MODULE_LICENSE("GPL");
169 MODULE_VERSION(DRV_MODULE_VERSION);
170 MODULE_FIRMWARE(FIRMWARE_TG3);
171 MODULE_FIRMWARE(FIRMWARE_TG3TSO);
172 MODULE_FIRMWARE(FIRMWARE_TG3TSO5);
174 static int tg3_debug = -1; /* -1 == use TG3_DEF_MSG_ENABLE as value */
175 module_param(tg3_debug, int, 0);
176 MODULE_PARM_DESC(tg3_debug, "Tigon3 bitmapped debugging message enable value");
178 static DEFINE_PCI_DEVICE_TABLE(tg3_pci_tbl) = {
179 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5700)},
180 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5701)},
181 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702)},
182 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5703)},
183 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5704)},
184 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702FE)},
185 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705)},
186 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705_2)},
187 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705M)},
188 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705M_2)},
189 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702X)},
190 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5703X)},
191 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5704S)},
192 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702A3)},
193 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5703A3)},
194 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5782)},
195 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5788)},
196 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5789)},
197 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5901)},
198 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5901_2)},
199 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5704S_2)},
200 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705F)},
201 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5720)},
202 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5721)},
203 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5722)},
204 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5750)},
205 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5751)},
206 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5750M)},
207 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5751M)},
208 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5751F)},
209 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5752)},
210 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5752M)},
211 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753)},
212 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753M)},
213 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753F)},
214 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5754)},
215 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5754M)},
216 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5755)},
217 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5755M)},
218 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5756)},
219 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5786)},
220 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5787)},
221 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5787M)},
222 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5787F)},
223 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5714)},
224 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5714S)},
225 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5715)},
226 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5715S)},
227 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5780)},
228 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5780S)},
229 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5781)},
230 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5906)},
231 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5906M)},
232 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5784)},
233 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5764)},
234 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5723)},
235 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5761)},
236 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5761E)},
237 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5761S)},
238 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5761SE)},
239 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5785_G)},
240 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5785_F)},
241 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57780)},
242 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57760)},
243 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57790)},
244 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57788)},
245 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5717)},
246 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5718)},
247 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5724)},
248 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57781)},
249 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57785)},
250 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57761)},
251 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57765)},
252 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57791)},
253 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57795)},
254 {PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_9DXX)},
255 {PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_9MXX)},
256 {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1000)},
257 {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1001)},
258 {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1003)},
259 {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC9100)},
260 {PCI_DEVICE(PCI_VENDOR_ID_APPLE, PCI_DEVICE_ID_APPLE_TIGON3)},
264 MODULE_DEVICE_TABLE(pci, tg3_pci_tbl);
266 static const struct {
267 const char string[ETH_GSTRING_LEN];
268 } ethtool_stats_keys[TG3_NUM_STATS] = {
271 { "rx_ucast_packets" },
272 { "rx_mcast_packets" },
273 { "rx_bcast_packets" },
275 { "rx_align_errors" },
276 { "rx_xon_pause_rcvd" },
277 { "rx_xoff_pause_rcvd" },
278 { "rx_mac_ctrl_rcvd" },
279 { "rx_xoff_entered" },
280 { "rx_frame_too_long_errors" },
282 { "rx_undersize_packets" },
283 { "rx_in_length_errors" },
284 { "rx_out_length_errors" },
285 { "rx_64_or_less_octet_packets" },
286 { "rx_65_to_127_octet_packets" },
287 { "rx_128_to_255_octet_packets" },
288 { "rx_256_to_511_octet_packets" },
289 { "rx_512_to_1023_octet_packets" },
290 { "rx_1024_to_1522_octet_packets" },
291 { "rx_1523_to_2047_octet_packets" },
292 { "rx_2048_to_4095_octet_packets" },
293 { "rx_4096_to_8191_octet_packets" },
294 { "rx_8192_to_9022_octet_packets" },
301 { "tx_flow_control" },
303 { "tx_single_collisions" },
304 { "tx_mult_collisions" },
306 { "tx_excessive_collisions" },
307 { "tx_late_collisions" },
308 { "tx_collide_2times" },
309 { "tx_collide_3times" },
310 { "tx_collide_4times" },
311 { "tx_collide_5times" },
312 { "tx_collide_6times" },
313 { "tx_collide_7times" },
314 { "tx_collide_8times" },
315 { "tx_collide_9times" },
316 { "tx_collide_10times" },
317 { "tx_collide_11times" },
318 { "tx_collide_12times" },
319 { "tx_collide_13times" },
320 { "tx_collide_14times" },
321 { "tx_collide_15times" },
322 { "tx_ucast_packets" },
323 { "tx_mcast_packets" },
324 { "tx_bcast_packets" },
325 { "tx_carrier_sense_errors" },
329 { "dma_writeq_full" },
330 { "dma_write_prioq_full" },
334 { "rx_threshold_hit" },
336 { "dma_readq_full" },
337 { "dma_read_prioq_full" },
338 { "tx_comp_queue_full" },
340 { "ring_set_send_prod_index" },
341 { "ring_status_update" },
343 { "nic_avoided_irqs" },
344 { "nic_tx_threshold_hit" }
347 static const struct {
348 const char string[ETH_GSTRING_LEN];
349 } ethtool_test_keys[TG3_NUM_TEST] = {
350 { "nvram test (online) " },
351 { "link test (online) " },
352 { "register test (offline)" },
353 { "memory test (offline)" },
354 { "loopback test (offline)" },
355 { "interrupt test (offline)" },
358 static void tg3_write32(struct tg3 *tp, u32 off, u32 val)
360 writel(val, tp->regs + off);
363 static u32 tg3_read32(struct tg3 *tp, u32 off)
365 return (readl(tp->regs + off));
368 static void tg3_ape_write32(struct tg3 *tp, u32 off, u32 val)
370 writel(val, tp->aperegs + off);
373 static u32 tg3_ape_read32(struct tg3 *tp, u32 off)
375 return (readl(tp->aperegs + off));
378 static void tg3_write_indirect_reg32(struct tg3 *tp, u32 off, u32 val)
382 spin_lock_irqsave(&tp->indirect_lock, flags);
383 pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off);
384 pci_write_config_dword(tp->pdev, TG3PCI_REG_DATA, val);
385 spin_unlock_irqrestore(&tp->indirect_lock, flags);
388 static void tg3_write_flush_reg32(struct tg3 *tp, u32 off, u32 val)
390 writel(val, tp->regs + off);
391 readl(tp->regs + off);
394 static u32 tg3_read_indirect_reg32(struct tg3 *tp, u32 off)
399 spin_lock_irqsave(&tp->indirect_lock, flags);
400 pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off);
401 pci_read_config_dword(tp->pdev, TG3PCI_REG_DATA, &val);
402 spin_unlock_irqrestore(&tp->indirect_lock, flags);
406 static void tg3_write_indirect_mbox(struct tg3 *tp, u32 off, u32 val)
410 if (off == (MAILBOX_RCVRET_CON_IDX_0 + TG3_64BIT_REG_LOW)) {
411 pci_write_config_dword(tp->pdev, TG3PCI_RCV_RET_RING_CON_IDX +
412 TG3_64BIT_REG_LOW, val);
415 if (off == TG3_RX_STD_PROD_IDX_REG) {
416 pci_write_config_dword(tp->pdev, TG3PCI_STD_RING_PROD_IDX +
417 TG3_64BIT_REG_LOW, val);
421 spin_lock_irqsave(&tp->indirect_lock, flags);
422 pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off + 0x5600);
423 pci_write_config_dword(tp->pdev, TG3PCI_REG_DATA, val);
424 spin_unlock_irqrestore(&tp->indirect_lock, flags);
426 /* In indirect mode when disabling interrupts, we also need
427 * to clear the interrupt bit in the GRC local ctrl register.
429 if ((off == (MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW)) &&
431 pci_write_config_dword(tp->pdev, TG3PCI_MISC_LOCAL_CTRL,
432 tp->grc_local_ctrl|GRC_LCLCTRL_CLEARINT);
436 static u32 tg3_read_indirect_mbox(struct tg3 *tp, u32 off)
441 spin_lock_irqsave(&tp->indirect_lock, flags);
442 pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off + 0x5600);
443 pci_read_config_dword(tp->pdev, TG3PCI_REG_DATA, &val);
444 spin_unlock_irqrestore(&tp->indirect_lock, flags);
448 /* usec_wait specifies the wait time in usec when writing to certain registers
449 * where it is unsafe to read back the register without some delay.
450 * GRC_LOCAL_CTRL is one example if the GPIOs are toggled to switch power.
451 * TG3PCI_CLOCK_CTRL is another example if the clock frequencies are changed.
453 static void _tw32_flush(struct tg3 *tp, u32 off, u32 val, u32 usec_wait)
455 if ((tp->tg3_flags & TG3_FLAG_PCIX_TARGET_HWBUG) ||
456 (tp->tg3_flags2 & TG3_FLG2_ICH_WORKAROUND))
457 /* Non-posted methods */
458 tp->write32(tp, off, val);
461 tg3_write32(tp, off, val);
466 /* Wait again after the read for the posted method to guarantee that
467 * the wait time is met.
473 static inline void tw32_mailbox_flush(struct tg3 *tp, u32 off, u32 val)
475 tp->write32_mbox(tp, off, val);
476 if (!(tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER) &&
477 !(tp->tg3_flags2 & TG3_FLG2_ICH_WORKAROUND))
478 tp->read32_mbox(tp, off);
481 static void tg3_write32_tx_mbox(struct tg3 *tp, u32 off, u32 val)
483 void __iomem *mbox = tp->regs + off;
485 if (tp->tg3_flags & TG3_FLAG_TXD_MBOX_HWBUG)
487 if (tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER)
491 static u32 tg3_read32_mbox_5906(struct tg3 *tp, u32 off)
493 return (readl(tp->regs + off + GRCMBOX_BASE));
496 static void tg3_write32_mbox_5906(struct tg3 *tp, u32 off, u32 val)
498 writel(val, tp->regs + off + GRCMBOX_BASE);
501 #define tw32_mailbox(reg, val) tp->write32_mbox(tp, reg, val)
502 #define tw32_mailbox_f(reg, val) tw32_mailbox_flush(tp, (reg), (val))
503 #define tw32_rx_mbox(reg, val) tp->write32_rx_mbox(tp, reg, val)
504 #define tw32_tx_mbox(reg, val) tp->write32_tx_mbox(tp, reg, val)
505 #define tr32_mailbox(reg) tp->read32_mbox(tp, reg)
507 #define tw32(reg, val) tp->write32(tp, reg, val)
508 #define tw32_f(reg, val) _tw32_flush(tp, (reg), (val), 0)
509 #define tw32_wait_f(reg, val, us) _tw32_flush(tp, (reg), (val), (us))
510 #define tr32(reg) tp->read32(tp, reg)
512 static void tg3_write_mem(struct tg3 *tp, u32 off, u32 val)
516 if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) &&
517 (off >= NIC_SRAM_STATS_BLK) && (off < NIC_SRAM_TX_BUFFER_DESC))
520 spin_lock_irqsave(&tp->indirect_lock, flags);
521 if (tp->tg3_flags & TG3_FLAG_SRAM_USE_CONFIG) {
522 pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, off);
523 pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val);
525 /* Always leave this as zero. */
526 pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0);
528 tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, off);
529 tw32_f(TG3PCI_MEM_WIN_DATA, val);
531 /* Always leave this as zero. */
532 tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, 0);
534 spin_unlock_irqrestore(&tp->indirect_lock, flags);
537 static void tg3_read_mem(struct tg3 *tp, u32 off, u32 *val)
541 if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) &&
542 (off >= NIC_SRAM_STATS_BLK) && (off < NIC_SRAM_TX_BUFFER_DESC)) {
547 spin_lock_irqsave(&tp->indirect_lock, flags);
548 if (tp->tg3_flags & TG3_FLAG_SRAM_USE_CONFIG) {
549 pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, off);
550 pci_read_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val);
552 /* Always leave this as zero. */
553 pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0);
555 tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, off);
556 *val = tr32(TG3PCI_MEM_WIN_DATA);
558 /* Always leave this as zero. */
559 tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, 0);
561 spin_unlock_irqrestore(&tp->indirect_lock, flags);
564 static void tg3_ape_lock_init(struct tg3 *tp)
568 /* Make sure the driver hasn't any stale locks. */
569 for (i = 0; i < 8; i++)
570 tg3_ape_write32(tp, TG3_APE_LOCK_GRANT + 4 * i,
571 APE_LOCK_GRANT_DRIVER);
574 static int tg3_ape_lock(struct tg3 *tp, int locknum)
580 if (!(tp->tg3_flags3 & TG3_FLG3_ENABLE_APE))
584 case TG3_APE_LOCK_GRC:
585 case TG3_APE_LOCK_MEM:
593 tg3_ape_write32(tp, TG3_APE_LOCK_REQ + off, APE_LOCK_REQ_DRIVER);
595 /* Wait for up to 1 millisecond to acquire lock. */
596 for (i = 0; i < 100; i++) {
597 status = tg3_ape_read32(tp, TG3_APE_LOCK_GRANT + off);
598 if (status == APE_LOCK_GRANT_DRIVER)
603 if (status != APE_LOCK_GRANT_DRIVER) {
604 /* Revoke the lock request. */
605 tg3_ape_write32(tp, TG3_APE_LOCK_GRANT + off,
606 APE_LOCK_GRANT_DRIVER);
614 static void tg3_ape_unlock(struct tg3 *tp, int locknum)
618 if (!(tp->tg3_flags3 & TG3_FLG3_ENABLE_APE))
622 case TG3_APE_LOCK_GRC:
623 case TG3_APE_LOCK_MEM:
630 tg3_ape_write32(tp, TG3_APE_LOCK_GRANT + off, APE_LOCK_GRANT_DRIVER);
633 static void tg3_disable_ints(struct tg3 *tp)
637 tw32(TG3PCI_MISC_HOST_CTRL,
638 (tp->misc_host_ctrl | MISC_HOST_CTRL_MASK_PCI_INT));
639 for (i = 0; i < tp->irq_max; i++)
640 tw32_mailbox_f(tp->napi[i].int_mbox, 0x00000001);
643 static void tg3_enable_ints(struct tg3 *tp)
650 tw32(TG3PCI_MISC_HOST_CTRL,
651 (tp->misc_host_ctrl & ~MISC_HOST_CTRL_MASK_PCI_INT));
653 tp->coal_now = tp->coalesce_mode | HOSTCC_MODE_ENABLE;
654 for (i = 0; i < tp->irq_cnt; i++) {
655 struct tg3_napi *tnapi = &tp->napi[i];
657 tw32_mailbox_f(tnapi->int_mbox, tnapi->last_tag << 24);
658 if (tp->tg3_flags2 & TG3_FLG2_1SHOT_MSI)
659 tw32_mailbox_f(tnapi->int_mbox, tnapi->last_tag << 24);
661 tp->coal_now |= tnapi->coal_now;
664 /* Force an initial interrupt */
665 if (!(tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) &&
666 (tp->napi[0].hw_status->status & SD_STATUS_UPDATED))
667 tw32(GRC_LOCAL_CTRL, tp->grc_local_ctrl | GRC_LCLCTRL_SETINT);
669 tw32(HOSTCC_MODE, tp->coal_now);
671 tp->coal_now &= ~(tp->napi[0].coal_now | tp->napi[1].coal_now);
674 static inline unsigned int tg3_has_work(struct tg3_napi *tnapi)
676 struct tg3 *tp = tnapi->tp;
677 struct tg3_hw_status *sblk = tnapi->hw_status;
678 unsigned int work_exists = 0;
680 /* check for phy events */
681 if (!(tp->tg3_flags &
682 (TG3_FLAG_USE_LINKCHG_REG |
683 TG3_FLAG_POLL_SERDES))) {
684 if (sblk->status & SD_STATUS_LINK_CHG)
687 /* check for RX/TX work to do */
688 if (sblk->idx[0].tx_consumer != tnapi->tx_cons ||
689 *(tnapi->rx_rcb_prod_idx) != tnapi->rx_rcb_ptr)
696 * similar to tg3_enable_ints, but it accurately determines whether there
697 * is new work pending and can return without flushing the PIO write
698 * which reenables interrupts
700 static void tg3_int_reenable(struct tg3_napi *tnapi)
702 struct tg3 *tp = tnapi->tp;
704 tw32_mailbox(tnapi->int_mbox, tnapi->last_tag << 24);
707 /* When doing tagged status, this work check is unnecessary.
708 * The last_tag we write above tells the chip which piece of
709 * work we've completed.
711 if (!(tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) &&
713 tw32(HOSTCC_MODE, tp->coalesce_mode |
714 HOSTCC_MODE_ENABLE | tnapi->coal_now);
717 static void tg3_napi_disable(struct tg3 *tp)
721 for (i = tp->irq_cnt - 1; i >= 0; i--)
722 napi_disable(&tp->napi[i].napi);
725 static void tg3_napi_enable(struct tg3 *tp)
729 for (i = 0; i < tp->irq_cnt; i++)
730 napi_enable(&tp->napi[i].napi);
733 static inline void tg3_netif_stop(struct tg3 *tp)
735 tp->dev->trans_start = jiffies; /* prevent tx timeout */
736 tg3_napi_disable(tp);
737 netif_tx_disable(tp->dev);
740 static inline void tg3_netif_start(struct tg3 *tp)
742 /* NOTE: unconditional netif_tx_wake_all_queues is only
743 * appropriate so long as all callers are assured to
744 * have free tx slots (such as after tg3_init_hw)
746 netif_tx_wake_all_queues(tp->dev);
749 tp->napi[0].hw_status->status |= SD_STATUS_UPDATED;
753 static void tg3_switch_clocks(struct tg3 *tp)
758 if ((tp->tg3_flags & TG3_FLAG_CPMU_PRESENT) ||
759 (tp->tg3_flags2 & TG3_FLG2_5780_CLASS))
762 clock_ctrl = tr32(TG3PCI_CLOCK_CTRL);
764 orig_clock_ctrl = clock_ctrl;
765 clock_ctrl &= (CLOCK_CTRL_FORCE_CLKRUN |
766 CLOCK_CTRL_CLKRUN_OENABLE |
768 tp->pci_clock_ctrl = clock_ctrl;
770 if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
771 if (orig_clock_ctrl & CLOCK_CTRL_625_CORE) {
772 tw32_wait_f(TG3PCI_CLOCK_CTRL,
773 clock_ctrl | CLOCK_CTRL_625_CORE, 40);
775 } else if ((orig_clock_ctrl & CLOCK_CTRL_44MHZ_CORE) != 0) {
776 tw32_wait_f(TG3PCI_CLOCK_CTRL,
778 (CLOCK_CTRL_44MHZ_CORE | CLOCK_CTRL_ALTCLK),
780 tw32_wait_f(TG3PCI_CLOCK_CTRL,
781 clock_ctrl | (CLOCK_CTRL_ALTCLK),
784 tw32_wait_f(TG3PCI_CLOCK_CTRL, clock_ctrl, 40);
787 #define PHY_BUSY_LOOPS 5000
789 static int tg3_readphy(struct tg3 *tp, int reg, u32 *val)
795 if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) {
797 (tp->mi_mode & ~MAC_MI_MODE_AUTO_POLL));
803 frame_val = ((tp->phy_addr << MI_COM_PHY_ADDR_SHIFT) &
804 MI_COM_PHY_ADDR_MASK);
805 frame_val |= ((reg << MI_COM_REG_ADDR_SHIFT) &
806 MI_COM_REG_ADDR_MASK);
807 frame_val |= (MI_COM_CMD_READ | MI_COM_START);
809 tw32_f(MAC_MI_COM, frame_val);
811 loops = PHY_BUSY_LOOPS;
814 frame_val = tr32(MAC_MI_COM);
816 if ((frame_val & MI_COM_BUSY) == 0) {
818 frame_val = tr32(MAC_MI_COM);
826 *val = frame_val & MI_COM_DATA_MASK;
830 if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) {
831 tw32_f(MAC_MI_MODE, tp->mi_mode);
838 static int tg3_writephy(struct tg3 *tp, int reg, u32 val)
844 if ((tp->tg3_flags3 & TG3_FLG3_PHY_IS_FET) &&
845 (reg == MII_TG3_CTRL || reg == MII_TG3_AUX_CTRL))
848 if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) {
850 (tp->mi_mode & ~MAC_MI_MODE_AUTO_POLL));
854 frame_val = ((tp->phy_addr << MI_COM_PHY_ADDR_SHIFT) &
855 MI_COM_PHY_ADDR_MASK);
856 frame_val |= ((reg << MI_COM_REG_ADDR_SHIFT) &
857 MI_COM_REG_ADDR_MASK);
858 frame_val |= (val & MI_COM_DATA_MASK);
859 frame_val |= (MI_COM_CMD_WRITE | MI_COM_START);
861 tw32_f(MAC_MI_COM, frame_val);
863 loops = PHY_BUSY_LOOPS;
866 frame_val = tr32(MAC_MI_COM);
867 if ((frame_val & MI_COM_BUSY) == 0) {
869 frame_val = tr32(MAC_MI_COM);
879 if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) {
880 tw32_f(MAC_MI_MODE, tp->mi_mode);
887 static int tg3_bmcr_reset(struct tg3 *tp)
892 /* OK, reset it, and poll the BMCR_RESET bit until it
893 * clears or we time out.
895 phy_control = BMCR_RESET;
896 err = tg3_writephy(tp, MII_BMCR, phy_control);
902 err = tg3_readphy(tp, MII_BMCR, &phy_control);
906 if ((phy_control & BMCR_RESET) == 0) {
918 static int tg3_mdio_read(struct mii_bus *bp, int mii_id, int reg)
920 struct tg3 *tp = bp->priv;
923 spin_lock_bh(&tp->lock);
925 if (tg3_readphy(tp, reg, &val))
928 spin_unlock_bh(&tp->lock);
933 static int tg3_mdio_write(struct mii_bus *bp, int mii_id, int reg, u16 val)
935 struct tg3 *tp = bp->priv;
938 spin_lock_bh(&tp->lock);
940 if (tg3_writephy(tp, reg, val))
943 spin_unlock_bh(&tp->lock);
948 static int tg3_mdio_reset(struct mii_bus *bp)
953 static void tg3_mdio_config_5785(struct tg3 *tp)
956 struct phy_device *phydev;
958 phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR];
959 switch (phydev->drv->phy_id & phydev->drv->phy_id_mask) {
960 case PHY_ID_BCM50610:
961 case PHY_ID_BCM50610M:
962 val = MAC_PHYCFG2_50610_LED_MODES;
964 case PHY_ID_BCMAC131:
965 val = MAC_PHYCFG2_AC131_LED_MODES;
967 case PHY_ID_RTL8211C:
968 val = MAC_PHYCFG2_RTL8211C_LED_MODES;
970 case PHY_ID_RTL8201E:
971 val = MAC_PHYCFG2_RTL8201E_LED_MODES;
977 if (phydev->interface != PHY_INTERFACE_MODE_RGMII) {
978 tw32(MAC_PHYCFG2, val);
980 val = tr32(MAC_PHYCFG1);
981 val &= ~(MAC_PHYCFG1_RGMII_INT |
982 MAC_PHYCFG1_RXCLK_TO_MASK | MAC_PHYCFG1_TXCLK_TO_MASK);
983 val |= MAC_PHYCFG1_RXCLK_TIMEOUT | MAC_PHYCFG1_TXCLK_TIMEOUT;
984 tw32(MAC_PHYCFG1, val);
989 if (!(tp->tg3_flags3 & TG3_FLG3_RGMII_INBAND_DISABLE))
990 val |= MAC_PHYCFG2_EMODE_MASK_MASK |
991 MAC_PHYCFG2_FMODE_MASK_MASK |
992 MAC_PHYCFG2_GMODE_MASK_MASK |
993 MAC_PHYCFG2_ACT_MASK_MASK |
994 MAC_PHYCFG2_QUAL_MASK_MASK |
995 MAC_PHYCFG2_INBAND_ENABLE;
997 tw32(MAC_PHYCFG2, val);
999 val = tr32(MAC_PHYCFG1);
1000 val &= ~(MAC_PHYCFG1_RXCLK_TO_MASK | MAC_PHYCFG1_TXCLK_TO_MASK |
1001 MAC_PHYCFG1_RGMII_EXT_RX_DEC | MAC_PHYCFG1_RGMII_SND_STAT_EN);
1002 if (!(tp->tg3_flags3 & TG3_FLG3_RGMII_INBAND_DISABLE)) {
1003 if (tp->tg3_flags3 & TG3_FLG3_RGMII_EXT_IBND_RX_EN)
1004 val |= MAC_PHYCFG1_RGMII_EXT_RX_DEC;
1005 if (tp->tg3_flags3 & TG3_FLG3_RGMII_EXT_IBND_TX_EN)
1006 val |= MAC_PHYCFG1_RGMII_SND_STAT_EN;
1008 val |= MAC_PHYCFG1_RXCLK_TIMEOUT | MAC_PHYCFG1_TXCLK_TIMEOUT |
1009 MAC_PHYCFG1_RGMII_INT | MAC_PHYCFG1_TXC_DRV;
1010 tw32(MAC_PHYCFG1, val);
1012 val = tr32(MAC_EXT_RGMII_MODE);
1013 val &= ~(MAC_RGMII_MODE_RX_INT_B |
1014 MAC_RGMII_MODE_RX_QUALITY |
1015 MAC_RGMII_MODE_RX_ACTIVITY |
1016 MAC_RGMII_MODE_RX_ENG_DET |
1017 MAC_RGMII_MODE_TX_ENABLE |
1018 MAC_RGMII_MODE_TX_LOWPWR |
1019 MAC_RGMII_MODE_TX_RESET);
1020 if (!(tp->tg3_flags3 & TG3_FLG3_RGMII_INBAND_DISABLE)) {
1021 if (tp->tg3_flags3 & TG3_FLG3_RGMII_EXT_IBND_RX_EN)
1022 val |= MAC_RGMII_MODE_RX_INT_B |
1023 MAC_RGMII_MODE_RX_QUALITY |
1024 MAC_RGMII_MODE_RX_ACTIVITY |
1025 MAC_RGMII_MODE_RX_ENG_DET;
1026 if (tp->tg3_flags3 & TG3_FLG3_RGMII_EXT_IBND_TX_EN)
1027 val |= MAC_RGMII_MODE_TX_ENABLE |
1028 MAC_RGMII_MODE_TX_LOWPWR |
1029 MAC_RGMII_MODE_TX_RESET;
1031 tw32(MAC_EXT_RGMII_MODE, val);
1034 static void tg3_mdio_start(struct tg3 *tp)
1036 tp->mi_mode &= ~MAC_MI_MODE_AUTO_POLL;
1037 tw32_f(MAC_MI_MODE, tp->mi_mode);
1040 if ((tp->tg3_flags3 & TG3_FLG3_MDIOBUS_INITED) &&
1041 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785)
1042 tg3_mdio_config_5785(tp);
1045 static int tg3_mdio_init(struct tg3 *tp)
1049 struct phy_device *phydev;
1051 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717) {
1052 u32 funcnum, is_serdes;
1054 funcnum = tr32(TG3_CPMU_STATUS) & TG3_CPMU_STATUS_PCIE_FUNC;
1060 if (tp->pci_chip_rev_id != CHIPREV_ID_5717_A0)
1061 is_serdes = tr32(SG_DIG_STATUS) & SG_DIG_IS_SERDES;
1063 is_serdes = tr32(TG3_CPMU_PHY_STRAP) &
1064 TG3_CPMU_PHY_STRAP_IS_SERDES;
1068 tp->phy_addr = TG3_PHY_MII_ADDR;
1072 if (!(tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB) ||
1073 (tp->tg3_flags3 & TG3_FLG3_MDIOBUS_INITED))
1076 tp->mdio_bus = mdiobus_alloc();
1077 if (tp->mdio_bus == NULL)
1080 tp->mdio_bus->name = "tg3 mdio bus";
1081 snprintf(tp->mdio_bus->id, MII_BUS_ID_SIZE, "%x",
1082 (tp->pdev->bus->number << 8) | tp->pdev->devfn);
1083 tp->mdio_bus->priv = tp;
1084 tp->mdio_bus->parent = &tp->pdev->dev;
1085 tp->mdio_bus->read = &tg3_mdio_read;
1086 tp->mdio_bus->write = &tg3_mdio_write;
1087 tp->mdio_bus->reset = &tg3_mdio_reset;
1088 tp->mdio_bus->phy_mask = ~(1 << TG3_PHY_MII_ADDR);
1089 tp->mdio_bus->irq = &tp->mdio_irq[0];
1091 for (i = 0; i < PHY_MAX_ADDR; i++)
1092 tp->mdio_bus->irq[i] = PHY_POLL;
1094 /* The bus registration will look for all the PHYs on the mdio bus.
1095 * Unfortunately, it does not ensure the PHY is powered up before
1096 * accessing the PHY ID registers. A chip reset is the
1097 * quickest way to bring the device back to an operational state..
1099 if (tg3_readphy(tp, MII_BMCR, ®) || (reg & BMCR_PDOWN))
1102 i = mdiobus_register(tp->mdio_bus);
1104 dev_warn(&tp->pdev->dev, "mdiobus_reg failed (0x%x)\n", i);
1105 mdiobus_free(tp->mdio_bus);
1109 phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR];
1111 if (!phydev || !phydev->drv) {
1112 dev_warn(&tp->pdev->dev, "No PHY devices\n");
1113 mdiobus_unregister(tp->mdio_bus);
1114 mdiobus_free(tp->mdio_bus);
1118 switch (phydev->drv->phy_id & phydev->drv->phy_id_mask) {
1119 case PHY_ID_BCM57780:
1120 phydev->interface = PHY_INTERFACE_MODE_GMII;
1121 phydev->dev_flags |= PHY_BRCM_AUTO_PWRDWN_ENABLE;
1123 case PHY_ID_BCM50610:
1124 case PHY_ID_BCM50610M:
1125 phydev->dev_flags |= PHY_BRCM_CLEAR_RGMII_MODE |
1126 PHY_BRCM_RX_REFCLK_UNUSED |
1127 PHY_BRCM_DIS_TXCRXC_NOENRGY |
1128 PHY_BRCM_AUTO_PWRDWN_ENABLE;
1129 if (tp->tg3_flags3 & TG3_FLG3_RGMII_INBAND_DISABLE)
1130 phydev->dev_flags |= PHY_BRCM_STD_IBND_DISABLE;
1131 if (tp->tg3_flags3 & TG3_FLG3_RGMII_EXT_IBND_RX_EN)
1132 phydev->dev_flags |= PHY_BRCM_EXT_IBND_RX_ENABLE;
1133 if (tp->tg3_flags3 & TG3_FLG3_RGMII_EXT_IBND_TX_EN)
1134 phydev->dev_flags |= PHY_BRCM_EXT_IBND_TX_ENABLE;
1136 case PHY_ID_RTL8211C:
1137 phydev->interface = PHY_INTERFACE_MODE_RGMII;
1139 case PHY_ID_RTL8201E:
1140 case PHY_ID_BCMAC131:
1141 phydev->interface = PHY_INTERFACE_MODE_MII;
1142 phydev->dev_flags |= PHY_BRCM_AUTO_PWRDWN_ENABLE;
1143 tp->tg3_flags3 |= TG3_FLG3_PHY_IS_FET;
1147 tp->tg3_flags3 |= TG3_FLG3_MDIOBUS_INITED;
1149 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785)
1150 tg3_mdio_config_5785(tp);
1155 static void tg3_mdio_fini(struct tg3 *tp)
1157 if (tp->tg3_flags3 & TG3_FLG3_MDIOBUS_INITED) {
1158 tp->tg3_flags3 &= ~TG3_FLG3_MDIOBUS_INITED;
1159 mdiobus_unregister(tp->mdio_bus);
1160 mdiobus_free(tp->mdio_bus);
1164 /* tp->lock is held. */
1165 static inline void tg3_generate_fw_event(struct tg3 *tp)
1169 val = tr32(GRC_RX_CPU_EVENT);
1170 val |= GRC_RX_CPU_DRIVER_EVENT;
1171 tw32_f(GRC_RX_CPU_EVENT, val);
1173 tp->last_event_jiffies = jiffies;
1176 #define TG3_FW_EVENT_TIMEOUT_USEC 2500
1178 /* tp->lock is held. */
1179 static void tg3_wait_for_event_ack(struct tg3 *tp)
1182 unsigned int delay_cnt;
1185 /* If enough time has passed, no wait is necessary. */
1186 time_remain = (long)(tp->last_event_jiffies + 1 +
1187 usecs_to_jiffies(TG3_FW_EVENT_TIMEOUT_USEC)) -
1189 if (time_remain < 0)
1192 /* Check if we can shorten the wait time. */
1193 delay_cnt = jiffies_to_usecs(time_remain);
1194 if (delay_cnt > TG3_FW_EVENT_TIMEOUT_USEC)
1195 delay_cnt = TG3_FW_EVENT_TIMEOUT_USEC;
1196 delay_cnt = (delay_cnt >> 3) + 1;
1198 for (i = 0; i < delay_cnt; i++) {
1199 if (!(tr32(GRC_RX_CPU_EVENT) & GRC_RX_CPU_DRIVER_EVENT))
1205 /* tp->lock is held. */
1206 static void tg3_ump_link_report(struct tg3 *tp)
1211 if (!(tp->tg3_flags2 & TG3_FLG2_5780_CLASS) ||
1212 !(tp->tg3_flags & TG3_FLAG_ENABLE_ASF))
1215 tg3_wait_for_event_ack(tp);
1217 tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX, FWCMD_NICDRV_LINK_UPDATE);
1219 tg3_write_mem(tp, NIC_SRAM_FW_CMD_LEN_MBOX, 14);
1222 if (!tg3_readphy(tp, MII_BMCR, ®))
1224 if (!tg3_readphy(tp, MII_BMSR, ®))
1225 val |= (reg & 0xffff);
1226 tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX, val);
1229 if (!tg3_readphy(tp, MII_ADVERTISE, ®))
1231 if (!tg3_readphy(tp, MII_LPA, ®))
1232 val |= (reg & 0xffff);
1233 tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX + 4, val);
1236 if (!(tp->tg3_flags2 & TG3_FLG2_MII_SERDES)) {
1237 if (!tg3_readphy(tp, MII_CTRL1000, ®))
1239 if (!tg3_readphy(tp, MII_STAT1000, ®))
1240 val |= (reg & 0xffff);
1242 tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX + 8, val);
1244 if (!tg3_readphy(tp, MII_PHYADDR, ®))
1248 tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX + 12, val);
1250 tg3_generate_fw_event(tp);
1253 static void tg3_link_report(struct tg3 *tp)
1255 if (!netif_carrier_ok(tp->dev)) {
1256 netif_info(tp, link, tp->dev, "Link is down\n");
1257 tg3_ump_link_report(tp);
1258 } else if (netif_msg_link(tp)) {
1259 netdev_info(tp->dev, "Link is up at %d Mbps, %s duplex\n",
1260 (tp->link_config.active_speed == SPEED_1000 ?
1262 (tp->link_config.active_speed == SPEED_100 ?
1264 (tp->link_config.active_duplex == DUPLEX_FULL ?
1267 netdev_info(tp->dev, "Flow control is %s for TX and %s for RX\n",
1268 (tp->link_config.active_flowctrl & FLOW_CTRL_TX) ?
1270 (tp->link_config.active_flowctrl & FLOW_CTRL_RX) ?
1272 tg3_ump_link_report(tp);
1276 static u16 tg3_advert_flowctrl_1000T(u8 flow_ctrl)
1280 if ((flow_ctrl & FLOW_CTRL_TX) && (flow_ctrl & FLOW_CTRL_RX))
1281 miireg = ADVERTISE_PAUSE_CAP;
1282 else if (flow_ctrl & FLOW_CTRL_TX)
1283 miireg = ADVERTISE_PAUSE_ASYM;
1284 else if (flow_ctrl & FLOW_CTRL_RX)
1285 miireg = ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM;
1292 static u16 tg3_advert_flowctrl_1000X(u8 flow_ctrl)
1296 if ((flow_ctrl & FLOW_CTRL_TX) && (flow_ctrl & FLOW_CTRL_RX))
1297 miireg = ADVERTISE_1000XPAUSE;
1298 else if (flow_ctrl & FLOW_CTRL_TX)
1299 miireg = ADVERTISE_1000XPSE_ASYM;
1300 else if (flow_ctrl & FLOW_CTRL_RX)
1301 miireg = ADVERTISE_1000XPAUSE | ADVERTISE_1000XPSE_ASYM;
1308 static u8 tg3_resolve_flowctrl_1000X(u16 lcladv, u16 rmtadv)
1312 if (lcladv & ADVERTISE_1000XPAUSE) {
1313 if (lcladv & ADVERTISE_1000XPSE_ASYM) {
1314 if (rmtadv & LPA_1000XPAUSE)
1315 cap = FLOW_CTRL_TX | FLOW_CTRL_RX;
1316 else if (rmtadv & LPA_1000XPAUSE_ASYM)
1319 if (rmtadv & LPA_1000XPAUSE)
1320 cap = FLOW_CTRL_TX | FLOW_CTRL_RX;
1322 } else if (lcladv & ADVERTISE_1000XPSE_ASYM) {
1323 if ((rmtadv & LPA_1000XPAUSE) && (rmtadv & LPA_1000XPAUSE_ASYM))
1330 static void tg3_setup_flow_control(struct tg3 *tp, u32 lcladv, u32 rmtadv)
1334 u32 old_rx_mode = tp->rx_mode;
1335 u32 old_tx_mode = tp->tx_mode;
1337 if (tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB)
1338 autoneg = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]->autoneg;
1340 autoneg = tp->link_config.autoneg;
1342 if (autoneg == AUTONEG_ENABLE &&
1343 (tp->tg3_flags & TG3_FLAG_PAUSE_AUTONEG)) {
1344 if (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES)
1345 flowctrl = tg3_resolve_flowctrl_1000X(lcladv, rmtadv);
1347 flowctrl = mii_resolve_flowctrl_fdx(lcladv, rmtadv);
1349 flowctrl = tp->link_config.flowctrl;
1351 tp->link_config.active_flowctrl = flowctrl;
1353 if (flowctrl & FLOW_CTRL_RX)
1354 tp->rx_mode |= RX_MODE_FLOW_CTRL_ENABLE;
1356 tp->rx_mode &= ~RX_MODE_FLOW_CTRL_ENABLE;
1358 if (old_rx_mode != tp->rx_mode)
1359 tw32_f(MAC_RX_MODE, tp->rx_mode);
1361 if (flowctrl & FLOW_CTRL_TX)
1362 tp->tx_mode |= TX_MODE_FLOW_CTRL_ENABLE;
1364 tp->tx_mode &= ~TX_MODE_FLOW_CTRL_ENABLE;
1366 if (old_tx_mode != tp->tx_mode)
1367 tw32_f(MAC_TX_MODE, tp->tx_mode);
1370 static void tg3_adjust_link(struct net_device *dev)
1372 u8 oldflowctrl, linkmesg = 0;
1373 u32 mac_mode, lcl_adv, rmt_adv;
1374 struct tg3 *tp = netdev_priv(dev);
1375 struct phy_device *phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR];
1377 spin_lock_bh(&tp->lock);
1379 mac_mode = tp->mac_mode & ~(MAC_MODE_PORT_MODE_MASK |
1380 MAC_MODE_HALF_DUPLEX);
1382 oldflowctrl = tp->link_config.active_flowctrl;
1388 if (phydev->speed == SPEED_100 || phydev->speed == SPEED_10)
1389 mac_mode |= MAC_MODE_PORT_MODE_MII;
1390 else if (phydev->speed == SPEED_1000 ||
1391 GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5785)
1392 mac_mode |= MAC_MODE_PORT_MODE_GMII;
1394 mac_mode |= MAC_MODE_PORT_MODE_MII;
1396 if (phydev->duplex == DUPLEX_HALF)
1397 mac_mode |= MAC_MODE_HALF_DUPLEX;
1399 lcl_adv = tg3_advert_flowctrl_1000T(
1400 tp->link_config.flowctrl);
1403 rmt_adv = LPA_PAUSE_CAP;
1404 if (phydev->asym_pause)
1405 rmt_adv |= LPA_PAUSE_ASYM;
1408 tg3_setup_flow_control(tp, lcl_adv, rmt_adv);
1410 mac_mode |= MAC_MODE_PORT_MODE_GMII;
1412 if (mac_mode != tp->mac_mode) {
1413 tp->mac_mode = mac_mode;
1414 tw32_f(MAC_MODE, tp->mac_mode);
1418 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) {
1419 if (phydev->speed == SPEED_10)
1421 MAC_MI_STAT_10MBPS_MODE |
1422 MAC_MI_STAT_LNKSTAT_ATTN_ENAB);
1424 tw32(MAC_MI_STAT, MAC_MI_STAT_LNKSTAT_ATTN_ENAB);
1427 if (phydev->speed == SPEED_1000 && phydev->duplex == DUPLEX_HALF)
1428 tw32(MAC_TX_LENGTHS,
1429 ((2 << TX_LENGTHS_IPG_CRS_SHIFT) |
1430 (6 << TX_LENGTHS_IPG_SHIFT) |
1431 (0xff << TX_LENGTHS_SLOT_TIME_SHIFT)));
1433 tw32(MAC_TX_LENGTHS,
1434 ((2 << TX_LENGTHS_IPG_CRS_SHIFT) |
1435 (6 << TX_LENGTHS_IPG_SHIFT) |
1436 (32 << TX_LENGTHS_SLOT_TIME_SHIFT)));
1438 if ((phydev->link && tp->link_config.active_speed == SPEED_INVALID) ||
1439 (!phydev->link && tp->link_config.active_speed != SPEED_INVALID) ||
1440 phydev->speed != tp->link_config.active_speed ||
1441 phydev->duplex != tp->link_config.active_duplex ||
1442 oldflowctrl != tp->link_config.active_flowctrl)
1445 tp->link_config.active_speed = phydev->speed;
1446 tp->link_config.active_duplex = phydev->duplex;
1448 spin_unlock_bh(&tp->lock);
1451 tg3_link_report(tp);
1454 static int tg3_phy_init(struct tg3 *tp)
1456 struct phy_device *phydev;
1458 if (tp->tg3_flags3 & TG3_FLG3_PHY_CONNECTED)
1461 /* Bring the PHY back to a known state. */
1464 phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR];
1466 /* Attach the MAC to the PHY. */
1467 phydev = phy_connect(tp->dev, dev_name(&phydev->dev), tg3_adjust_link,
1468 phydev->dev_flags, phydev->interface);
1469 if (IS_ERR(phydev)) {
1470 dev_err(&tp->pdev->dev, "Could not attach to PHY\n");
1471 return PTR_ERR(phydev);
1474 /* Mask with MAC supported features. */
1475 switch (phydev->interface) {
1476 case PHY_INTERFACE_MODE_GMII:
1477 case PHY_INTERFACE_MODE_RGMII:
1478 if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY)) {
1479 phydev->supported &= (PHY_GBIT_FEATURES |
1481 SUPPORTED_Asym_Pause);
1485 case PHY_INTERFACE_MODE_MII:
1486 phydev->supported &= (PHY_BASIC_FEATURES |
1488 SUPPORTED_Asym_Pause);
1491 phy_disconnect(tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]);
1495 tp->tg3_flags3 |= TG3_FLG3_PHY_CONNECTED;
1497 phydev->advertising = phydev->supported;
1502 static void tg3_phy_start(struct tg3 *tp)
1504 struct phy_device *phydev;
1506 if (!(tp->tg3_flags3 & TG3_FLG3_PHY_CONNECTED))
1509 phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR];
1511 if (tp->link_config.phy_is_low_power) {
1512 tp->link_config.phy_is_low_power = 0;
1513 phydev->speed = tp->link_config.orig_speed;
1514 phydev->duplex = tp->link_config.orig_duplex;
1515 phydev->autoneg = tp->link_config.orig_autoneg;
1516 phydev->advertising = tp->link_config.orig_advertising;
1521 phy_start_aneg(phydev);
1524 static void tg3_phy_stop(struct tg3 *tp)
1526 if (!(tp->tg3_flags3 & TG3_FLG3_PHY_CONNECTED))
1529 phy_stop(tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]);
1532 static void tg3_phy_fini(struct tg3 *tp)
1534 if (tp->tg3_flags3 & TG3_FLG3_PHY_CONNECTED) {
1535 phy_disconnect(tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]);
1536 tp->tg3_flags3 &= ~TG3_FLG3_PHY_CONNECTED;
1540 static void tg3_phydsp_write(struct tg3 *tp, u32 reg, u32 val)
1542 tg3_writephy(tp, MII_TG3_DSP_ADDRESS, reg);
1543 tg3_writephy(tp, MII_TG3_DSP_RW_PORT, val);
1546 static void tg3_phy_fet_toggle_apd(struct tg3 *tp, bool enable)
1550 if (!tg3_readphy(tp, MII_TG3_FET_TEST, &phytest)) {
1553 tg3_writephy(tp, MII_TG3_FET_TEST,
1554 phytest | MII_TG3_FET_SHADOW_EN);
1555 if (!tg3_readphy(tp, MII_TG3_FET_SHDW_AUXSTAT2, &phy)) {
1557 phy |= MII_TG3_FET_SHDW_AUXSTAT2_APD;
1559 phy &= ~MII_TG3_FET_SHDW_AUXSTAT2_APD;
1560 tg3_writephy(tp, MII_TG3_FET_SHDW_AUXSTAT2, phy);
1562 tg3_writephy(tp, MII_TG3_FET_TEST, phytest);
1566 static void tg3_phy_toggle_apd(struct tg3 *tp, bool enable)
1570 if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS) ||
1571 (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 &&
1572 (tp->tg3_flags2 & TG3_FLG2_MII_SERDES)))
1575 if (tp->tg3_flags3 & TG3_FLG3_PHY_IS_FET) {
1576 tg3_phy_fet_toggle_apd(tp, enable);
1580 reg = MII_TG3_MISC_SHDW_WREN |
1581 MII_TG3_MISC_SHDW_SCR5_SEL |
1582 MII_TG3_MISC_SHDW_SCR5_LPED |
1583 MII_TG3_MISC_SHDW_SCR5_DLPTLM |
1584 MII_TG3_MISC_SHDW_SCR5_SDTL |
1585 MII_TG3_MISC_SHDW_SCR5_C125OE;
1586 if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5784 || !enable)
1587 reg |= MII_TG3_MISC_SHDW_SCR5_DLLAPD;
1589 tg3_writephy(tp, MII_TG3_MISC_SHDW, reg);
1592 reg = MII_TG3_MISC_SHDW_WREN |
1593 MII_TG3_MISC_SHDW_APD_SEL |
1594 MII_TG3_MISC_SHDW_APD_WKTM_84MS;
1596 reg |= MII_TG3_MISC_SHDW_APD_ENABLE;
1598 tg3_writephy(tp, MII_TG3_MISC_SHDW, reg);
1601 static void tg3_phy_toggle_automdix(struct tg3 *tp, int enable)
1605 if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS) ||
1606 (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES))
1609 if (tp->tg3_flags3 & TG3_FLG3_PHY_IS_FET) {
1612 if (!tg3_readphy(tp, MII_TG3_FET_TEST, &ephy)) {
1613 u32 reg = MII_TG3_FET_SHDW_MISCCTRL;
1615 tg3_writephy(tp, MII_TG3_FET_TEST,
1616 ephy | MII_TG3_FET_SHADOW_EN);
1617 if (!tg3_readphy(tp, reg, &phy)) {
1619 phy |= MII_TG3_FET_SHDW_MISCCTRL_MDIX;
1621 phy &= ~MII_TG3_FET_SHDW_MISCCTRL_MDIX;
1622 tg3_writephy(tp, reg, phy);
1624 tg3_writephy(tp, MII_TG3_FET_TEST, ephy);
1627 phy = MII_TG3_AUXCTL_MISC_RDSEL_MISC |
1628 MII_TG3_AUXCTL_SHDWSEL_MISC;
1629 if (!tg3_writephy(tp, MII_TG3_AUX_CTRL, phy) &&
1630 !tg3_readphy(tp, MII_TG3_AUX_CTRL, &phy)) {
1632 phy |= MII_TG3_AUXCTL_MISC_FORCE_AMDIX;
1634 phy &= ~MII_TG3_AUXCTL_MISC_FORCE_AMDIX;
1635 phy |= MII_TG3_AUXCTL_MISC_WREN;
1636 tg3_writephy(tp, MII_TG3_AUX_CTRL, phy);
1641 static void tg3_phy_set_wirespeed(struct tg3 *tp)
1645 if (tp->tg3_flags2 & TG3_FLG2_NO_ETH_WIRE_SPEED)
1648 if (!tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x7007) &&
1649 !tg3_readphy(tp, MII_TG3_AUX_CTRL, &val))
1650 tg3_writephy(tp, MII_TG3_AUX_CTRL,
1651 (val | (1 << 15) | (1 << 4)));
1654 static void tg3_phy_apply_otp(struct tg3 *tp)
1663 /* Enable SM_DSP clock and tx 6dB coding. */
1664 phy = MII_TG3_AUXCTL_SHDWSEL_AUXCTL |
1665 MII_TG3_AUXCTL_ACTL_SMDSP_ENA |
1666 MII_TG3_AUXCTL_ACTL_TX_6DB;
1667 tg3_writephy(tp, MII_TG3_AUX_CTRL, phy);
1669 phy = ((otp & TG3_OTP_AGCTGT_MASK) >> TG3_OTP_AGCTGT_SHIFT);
1670 phy |= MII_TG3_DSP_TAP1_AGCTGT_DFLT;
1671 tg3_phydsp_write(tp, MII_TG3_DSP_TAP1, phy);
1673 phy = ((otp & TG3_OTP_HPFFLTR_MASK) >> TG3_OTP_HPFFLTR_SHIFT) |
1674 ((otp & TG3_OTP_HPFOVER_MASK) >> TG3_OTP_HPFOVER_SHIFT);
1675 tg3_phydsp_write(tp, MII_TG3_DSP_AADJ1CH0, phy);
1677 phy = ((otp & TG3_OTP_LPFDIS_MASK) >> TG3_OTP_LPFDIS_SHIFT);
1678 phy |= MII_TG3_DSP_AADJ1CH3_ADCCKADJ;
1679 tg3_phydsp_write(tp, MII_TG3_DSP_AADJ1CH3, phy);
1681 phy = ((otp & TG3_OTP_VDAC_MASK) >> TG3_OTP_VDAC_SHIFT);
1682 tg3_phydsp_write(tp, MII_TG3_DSP_EXP75, phy);
1684 phy = ((otp & TG3_OTP_10BTAMP_MASK) >> TG3_OTP_10BTAMP_SHIFT);
1685 tg3_phydsp_write(tp, MII_TG3_DSP_EXP96, phy);
1687 phy = ((otp & TG3_OTP_ROFF_MASK) >> TG3_OTP_ROFF_SHIFT) |
1688 ((otp & TG3_OTP_RCOFF_MASK) >> TG3_OTP_RCOFF_SHIFT);
1689 tg3_phydsp_write(tp, MII_TG3_DSP_EXP97, phy);
1691 /* Turn off SM_DSP clock. */
1692 phy = MII_TG3_AUXCTL_SHDWSEL_AUXCTL |
1693 MII_TG3_AUXCTL_ACTL_TX_6DB;
1694 tg3_writephy(tp, MII_TG3_AUX_CTRL, phy);
1697 static int tg3_wait_macro_done(struct tg3 *tp)
1704 if (!tg3_readphy(tp, 0x16, &tmp32)) {
1705 if ((tmp32 & 0x1000) == 0)
1715 static int tg3_phy_write_and_check_testpat(struct tg3 *tp, int *resetp)
1717 static const u32 test_pat[4][6] = {
1718 { 0x00005555, 0x00000005, 0x00002aaa, 0x0000000a, 0x00003456, 0x00000003 },
1719 { 0x00002aaa, 0x0000000a, 0x00003333, 0x00000003, 0x0000789a, 0x00000005 },
1720 { 0x00005a5a, 0x00000005, 0x00002a6a, 0x0000000a, 0x00001bcd, 0x00000003 },
1721 { 0x00002a5a, 0x0000000a, 0x000033c3, 0x00000003, 0x00002ef1, 0x00000005 }
1725 for (chan = 0; chan < 4; chan++) {
1728 tg3_writephy(tp, MII_TG3_DSP_ADDRESS,
1729 (chan * 0x2000) | 0x0200);
1730 tg3_writephy(tp, 0x16, 0x0002);
1732 for (i = 0; i < 6; i++)
1733 tg3_writephy(tp, MII_TG3_DSP_RW_PORT,
1736 tg3_writephy(tp, 0x16, 0x0202);
1737 if (tg3_wait_macro_done(tp)) {
1742 tg3_writephy(tp, MII_TG3_DSP_ADDRESS,
1743 (chan * 0x2000) | 0x0200);
1744 tg3_writephy(tp, 0x16, 0x0082);
1745 if (tg3_wait_macro_done(tp)) {
1750 tg3_writephy(tp, 0x16, 0x0802);
1751 if (tg3_wait_macro_done(tp)) {
1756 for (i = 0; i < 6; i += 2) {
1759 if (tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &low) ||
1760 tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &high) ||
1761 tg3_wait_macro_done(tp)) {
1767 if (low != test_pat[chan][i] ||
1768 high != test_pat[chan][i+1]) {
1769 tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000b);
1770 tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x4001);
1771 tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x4005);
1781 static int tg3_phy_reset_chanpat(struct tg3 *tp)
1785 for (chan = 0; chan < 4; chan++) {
1788 tg3_writephy(tp, MII_TG3_DSP_ADDRESS,
1789 (chan * 0x2000) | 0x0200);
1790 tg3_writephy(tp, 0x16, 0x0002);
1791 for (i = 0; i < 6; i++)
1792 tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x000);
1793 tg3_writephy(tp, 0x16, 0x0202);
1794 if (tg3_wait_macro_done(tp))
1801 static int tg3_phy_reset_5703_4_5(struct tg3 *tp)
1803 u32 reg32, phy9_orig;
1804 int retries, do_phy_reset, err;
1810 err = tg3_bmcr_reset(tp);
1816 /* Disable transmitter and interrupt. */
1817 if (tg3_readphy(tp, MII_TG3_EXT_CTRL, ®32))
1821 tg3_writephy(tp, MII_TG3_EXT_CTRL, reg32);
1823 /* Set full-duplex, 1000 mbps. */
1824 tg3_writephy(tp, MII_BMCR,
1825 BMCR_FULLDPLX | TG3_BMCR_SPEED1000);
1827 /* Set to master mode. */
1828 if (tg3_readphy(tp, MII_TG3_CTRL, &phy9_orig))
1831 tg3_writephy(tp, MII_TG3_CTRL,
1832 (MII_TG3_CTRL_AS_MASTER |
1833 MII_TG3_CTRL_ENABLE_AS_MASTER));
1835 /* Enable SM_DSP_CLOCK and 6dB. */
1836 tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0c00);
1838 /* Block the PHY control access. */
1839 tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8005);
1840 tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0800);
1842 err = tg3_phy_write_and_check_testpat(tp, &do_phy_reset);
1845 } while (--retries);
1847 err = tg3_phy_reset_chanpat(tp);
1851 tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8005);
1852 tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0000);
1854 tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8200);
1855 tg3_writephy(tp, 0x16, 0x0000);
1857 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 ||
1858 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) {
1859 /* Set Extended packet length bit for jumbo frames */
1860 tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x4400);
1863 tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0400);
1866 tg3_writephy(tp, MII_TG3_CTRL, phy9_orig);
1868 if (!tg3_readphy(tp, MII_TG3_EXT_CTRL, ®32)) {
1870 tg3_writephy(tp, MII_TG3_EXT_CTRL, reg32);
1877 /* This will reset the tigon3 PHY if there is no valid
1878 * link unless the FORCE argument is non-zero.
1880 static int tg3_phy_reset(struct tg3 *tp)
1886 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
1889 val = tr32(GRC_MISC_CFG);
1890 tw32_f(GRC_MISC_CFG, val & ~GRC_MISC_CFG_EPHY_IDDQ);
1893 err = tg3_readphy(tp, MII_BMSR, &phy_status);
1894 err |= tg3_readphy(tp, MII_BMSR, &phy_status);
1898 if (netif_running(tp->dev) && netif_carrier_ok(tp->dev)) {
1899 netif_carrier_off(tp->dev);
1900 tg3_link_report(tp);
1903 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 ||
1904 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 ||
1905 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) {
1906 err = tg3_phy_reset_5703_4_5(tp);
1913 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 &&
1914 GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5784_AX) {
1915 cpmuctrl = tr32(TG3_CPMU_CTRL);
1916 if (cpmuctrl & CPMU_CTRL_GPHY_10MB_RXONLY)
1918 cpmuctrl & ~CPMU_CTRL_GPHY_10MB_RXONLY);
1921 err = tg3_bmcr_reset(tp);
1925 if (cpmuctrl & CPMU_CTRL_GPHY_10MB_RXONLY) {
1928 phy = MII_TG3_DSP_EXP8_AEDW | MII_TG3_DSP_EXP8_REJ2MHz;
1929 tg3_phydsp_write(tp, MII_TG3_DSP_EXP8, phy);
1931 tw32(TG3_CPMU_CTRL, cpmuctrl);
1934 if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5784_AX ||
1935 GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5761_AX) {
1938 val = tr32(TG3_CPMU_LSPD_1000MB_CLK);
1939 if ((val & CPMU_LSPD_1000MB_MACCLK_MASK) ==
1940 CPMU_LSPD_1000MB_MACCLK_12_5) {
1941 val &= ~CPMU_LSPD_1000MB_MACCLK_MASK;
1943 tw32_f(TG3_CPMU_LSPD_1000MB_CLK, val);
1947 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 &&
1948 (tp->tg3_flags2 & TG3_FLG2_MII_SERDES))
1951 tg3_phy_apply_otp(tp);
1953 if (tp->tg3_flags3 & TG3_FLG3_PHY_ENABLE_APD)
1954 tg3_phy_toggle_apd(tp, true);
1956 tg3_phy_toggle_apd(tp, false);
1959 if (tp->tg3_flags2 & TG3_FLG2_PHY_ADC_BUG) {
1960 tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0c00);
1961 tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x201f);
1962 tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x2aaa);
1963 tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000a);
1964 tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0323);
1965 tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0400);
1967 if (tp->tg3_flags2 & TG3_FLG2_PHY_5704_A0_BUG) {
1968 tg3_writephy(tp, 0x1c, 0x8d68);
1969 tg3_writephy(tp, 0x1c, 0x8d68);
1971 if (tp->tg3_flags2 & TG3_FLG2_PHY_BER_BUG) {
1972 tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0c00);
1973 tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000a);
1974 tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x310b);
1975 tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x201f);
1976 tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x9506);
1977 tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x401f);
1978 tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x14e2);
1979 tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0400);
1981 else if (tp->tg3_flags2 & TG3_FLG2_PHY_JITTER_BUG) {
1982 tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0c00);
1983 tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000a);
1984 if (tp->tg3_flags2 & TG3_FLG2_PHY_ADJUST_TRIM) {
1985 tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x110b);
1986 tg3_writephy(tp, MII_TG3_TEST1,
1987 MII_TG3_TEST1_TRIM_EN | 0x4);
1989 tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x010b);
1990 tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0400);
1992 /* Set Extended packet length bit (bit 14) on all chips that */
1993 /* support jumbo frames */
1994 if ((tp->phy_id & TG3_PHY_ID_MASK) == TG3_PHY_ID_BCM5401) {
1995 /* Cannot do read-modify-write on 5401 */
1996 tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x4c20);
1997 } else if (tp->tg3_flags & TG3_FLAG_JUMBO_CAPABLE) {
2000 /* Set bit 14 with read-modify-write to preserve other bits */
2001 if (!tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0007) &&
2002 !tg3_readphy(tp, MII_TG3_AUX_CTRL, &phy_reg))
2003 tg3_writephy(tp, MII_TG3_AUX_CTRL, phy_reg | 0x4000);
2006 /* Set phy register 0x10 bit 0 to high fifo elasticity to support
2007 * jumbo frames transmission.
2009 if (tp->tg3_flags & TG3_FLAG_JUMBO_CAPABLE) {
2012 if (!tg3_readphy(tp, MII_TG3_EXT_CTRL, &phy_reg))
2013 tg3_writephy(tp, MII_TG3_EXT_CTRL,
2014 phy_reg | MII_TG3_EXT_CTRL_FIFO_ELASTIC);
2017 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
2018 /* adjust output voltage */
2019 tg3_writephy(tp, MII_TG3_FET_PTEST, 0x12);
2022 tg3_phy_toggle_automdix(tp, 1);
2023 tg3_phy_set_wirespeed(tp);
2027 static void tg3_frob_aux_power(struct tg3 *tp)
2029 struct tg3 *tp_peer = tp;
2031 /* The GPIOs do something completely different on 57765. */
2032 if ((tp->tg3_flags2 & TG3_FLG2_IS_NIC) == 0 ||
2033 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765)
2036 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 ||
2037 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714 ||
2038 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717) {
2039 struct net_device *dev_peer;
2041 dev_peer = pci_get_drvdata(tp->pdev_peer);
2042 /* remove_one() may have been run on the peer. */
2046 tp_peer = netdev_priv(dev_peer);
2049 if ((tp->tg3_flags & TG3_FLAG_WOL_ENABLE) != 0 ||
2050 (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) != 0 ||
2051 (tp_peer->tg3_flags & TG3_FLAG_WOL_ENABLE) != 0 ||
2052 (tp_peer->tg3_flags & TG3_FLAG_ENABLE_ASF) != 0) {
2053 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
2054 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) {
2055 tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
2056 (GRC_LCLCTRL_GPIO_OE0 |
2057 GRC_LCLCTRL_GPIO_OE1 |
2058 GRC_LCLCTRL_GPIO_OE2 |
2059 GRC_LCLCTRL_GPIO_OUTPUT0 |
2060 GRC_LCLCTRL_GPIO_OUTPUT1),
2062 } else if (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5761 ||
2063 tp->pdev->device == TG3PCI_DEVICE_TIGON3_5761S) {
2064 /* The 5761 non-e device swaps GPIO 0 and GPIO 2. */
2065 u32 grc_local_ctrl = GRC_LCLCTRL_GPIO_OE0 |
2066 GRC_LCLCTRL_GPIO_OE1 |
2067 GRC_LCLCTRL_GPIO_OE2 |
2068 GRC_LCLCTRL_GPIO_OUTPUT0 |
2069 GRC_LCLCTRL_GPIO_OUTPUT1 |
2071 tw32_wait_f(GRC_LOCAL_CTRL, grc_local_ctrl, 100);
2073 grc_local_ctrl |= GRC_LCLCTRL_GPIO_OUTPUT2;
2074 tw32_wait_f(GRC_LOCAL_CTRL, grc_local_ctrl, 100);
2076 grc_local_ctrl &= ~GRC_LCLCTRL_GPIO_OUTPUT0;
2077 tw32_wait_f(GRC_LOCAL_CTRL, grc_local_ctrl, 100);
2080 u32 grc_local_ctrl = 0;
2082 if (tp_peer != tp &&
2083 (tp_peer->tg3_flags & TG3_FLAG_INIT_COMPLETE) != 0)
2086 /* Workaround to prevent overdrawing Amps. */
2087 if (GET_ASIC_REV(tp->pci_chip_rev_id) ==
2089 grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE3;
2090 tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
2091 grc_local_ctrl, 100);
2094 /* On 5753 and variants, GPIO2 cannot be used. */
2095 no_gpio2 = tp->nic_sram_data_cfg &
2096 NIC_SRAM_DATA_CFG_NO_GPIO2;
2098 grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE0 |
2099 GRC_LCLCTRL_GPIO_OE1 |
2100 GRC_LCLCTRL_GPIO_OE2 |
2101 GRC_LCLCTRL_GPIO_OUTPUT1 |
2102 GRC_LCLCTRL_GPIO_OUTPUT2;
2104 grc_local_ctrl &= ~(GRC_LCLCTRL_GPIO_OE2 |
2105 GRC_LCLCTRL_GPIO_OUTPUT2);
2107 tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
2108 grc_local_ctrl, 100);
2110 grc_local_ctrl |= GRC_LCLCTRL_GPIO_OUTPUT0;
2112 tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
2113 grc_local_ctrl, 100);
2116 grc_local_ctrl &= ~GRC_LCLCTRL_GPIO_OUTPUT2;
2117 tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
2118 grc_local_ctrl, 100);
2122 if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 &&
2123 GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) {
2124 if (tp_peer != tp &&
2125 (tp_peer->tg3_flags & TG3_FLAG_INIT_COMPLETE) != 0)
2128 tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
2129 (GRC_LCLCTRL_GPIO_OE1 |
2130 GRC_LCLCTRL_GPIO_OUTPUT1), 100);
2132 tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
2133 GRC_LCLCTRL_GPIO_OE1, 100);
2135 tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
2136 (GRC_LCLCTRL_GPIO_OE1 |
2137 GRC_LCLCTRL_GPIO_OUTPUT1), 100);
2142 static int tg3_5700_link_polarity(struct tg3 *tp, u32 speed)
2144 if (tp->led_ctrl == LED_CTRL_MODE_PHY_2)
2146 else if ((tp->phy_id & TG3_PHY_ID_MASK) == TG3_PHY_ID_BCM5411) {
2147 if (speed != SPEED_10)
2149 } else if (speed == SPEED_10)
2155 static int tg3_setup_phy(struct tg3 *, int);
2157 #define RESET_KIND_SHUTDOWN 0
2158 #define RESET_KIND_INIT 1
2159 #define RESET_KIND_SUSPEND 2
2161 static void tg3_write_sig_post_reset(struct tg3 *, int);
2162 static int tg3_halt_cpu(struct tg3 *, u32);
2164 static void tg3_power_down_phy(struct tg3 *tp, bool do_low_power)
2168 if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) {
2169 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) {
2170 u32 sg_dig_ctrl = tr32(SG_DIG_CTRL);
2171 u32 serdes_cfg = tr32(MAC_SERDES_CFG);
2174 SG_DIG_USING_HW_AUTONEG | SG_DIG_SOFT_RESET;
2175 tw32(SG_DIG_CTRL, sg_dig_ctrl);
2176 tw32(MAC_SERDES_CFG, serdes_cfg | (1 << 15));
2181 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
2183 val = tr32(GRC_MISC_CFG);
2184 tw32_f(GRC_MISC_CFG, val | GRC_MISC_CFG_EPHY_IDDQ);
2187 } else if (tp->tg3_flags3 & TG3_FLG3_PHY_IS_FET) {
2189 if (!tg3_readphy(tp, MII_TG3_FET_TEST, &phytest)) {
2192 tg3_writephy(tp, MII_ADVERTISE, 0);
2193 tg3_writephy(tp, MII_BMCR,
2194 BMCR_ANENABLE | BMCR_ANRESTART);
2196 tg3_writephy(tp, MII_TG3_FET_TEST,
2197 phytest | MII_TG3_FET_SHADOW_EN);
2198 if (!tg3_readphy(tp, MII_TG3_FET_SHDW_AUXMODE4, &phy)) {
2199 phy |= MII_TG3_FET_SHDW_AUXMODE4_SBPD;
2201 MII_TG3_FET_SHDW_AUXMODE4,
2204 tg3_writephy(tp, MII_TG3_FET_TEST, phytest);
2207 } else if (do_low_power) {
2208 tg3_writephy(tp, MII_TG3_EXT_CTRL,
2209 MII_TG3_EXT_CTRL_FORCE_LED_OFF);
2211 tg3_writephy(tp, MII_TG3_AUX_CTRL,
2212 MII_TG3_AUXCTL_SHDWSEL_PWRCTL |
2213 MII_TG3_AUXCTL_PCTL_100TX_LPWR |
2214 MII_TG3_AUXCTL_PCTL_SPR_ISOLATE |
2215 MII_TG3_AUXCTL_PCTL_VREG_11V);
2218 /* The PHY should not be powered down on some chips because
2221 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
2222 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 ||
2223 (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780 &&
2224 (tp->tg3_flags2 & TG3_FLG2_MII_SERDES)))
2227 if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5784_AX ||
2228 GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5761_AX) {
2229 val = tr32(TG3_CPMU_LSPD_1000MB_CLK);
2230 val &= ~CPMU_LSPD_1000MB_MACCLK_MASK;
2231 val |= CPMU_LSPD_1000MB_MACCLK_12_5;
2232 tw32_f(TG3_CPMU_LSPD_1000MB_CLK, val);
2235 tg3_writephy(tp, MII_BMCR, BMCR_PDOWN);
2238 /* tp->lock is held. */
2239 static int tg3_nvram_lock(struct tg3 *tp)
2241 if (tp->tg3_flags & TG3_FLAG_NVRAM) {
2244 if (tp->nvram_lock_cnt == 0) {
2245 tw32(NVRAM_SWARB, SWARB_REQ_SET1);
2246 for (i = 0; i < 8000; i++) {
2247 if (tr32(NVRAM_SWARB) & SWARB_GNT1)
2252 tw32(NVRAM_SWARB, SWARB_REQ_CLR1);
2256 tp->nvram_lock_cnt++;
2261 /* tp->lock is held. */
2262 static void tg3_nvram_unlock(struct tg3 *tp)
2264 if (tp->tg3_flags & TG3_FLAG_NVRAM) {
2265 if (tp->nvram_lock_cnt > 0)
2266 tp->nvram_lock_cnt--;
2267 if (tp->nvram_lock_cnt == 0)
2268 tw32_f(NVRAM_SWARB, SWARB_REQ_CLR1);
2272 /* tp->lock is held. */
2273 static void tg3_enable_nvram_access(struct tg3 *tp)
2275 if ((tp->tg3_flags2 & TG3_FLG2_5750_PLUS) &&
2276 !(tp->tg3_flags3 & TG3_FLG3_PROTECTED_NVRAM)) {
2277 u32 nvaccess = tr32(NVRAM_ACCESS);
2279 tw32(NVRAM_ACCESS, nvaccess | ACCESS_ENABLE);
2283 /* tp->lock is held. */
2284 static void tg3_disable_nvram_access(struct tg3 *tp)
2286 if ((tp->tg3_flags2 & TG3_FLG2_5750_PLUS) &&
2287 !(tp->tg3_flags3 & TG3_FLG3_PROTECTED_NVRAM)) {
2288 u32 nvaccess = tr32(NVRAM_ACCESS);
2290 tw32(NVRAM_ACCESS, nvaccess & ~ACCESS_ENABLE);
2294 static int tg3_nvram_read_using_eeprom(struct tg3 *tp,
2295 u32 offset, u32 *val)
2300 if (offset > EEPROM_ADDR_ADDR_MASK || (offset % 4) != 0)
2303 tmp = tr32(GRC_EEPROM_ADDR) & ~(EEPROM_ADDR_ADDR_MASK |
2304 EEPROM_ADDR_DEVID_MASK |
2306 tw32(GRC_EEPROM_ADDR,
2308 (0 << EEPROM_ADDR_DEVID_SHIFT) |
2309 ((offset << EEPROM_ADDR_ADDR_SHIFT) &
2310 EEPROM_ADDR_ADDR_MASK) |
2311 EEPROM_ADDR_READ | EEPROM_ADDR_START);
2313 for (i = 0; i < 1000; i++) {
2314 tmp = tr32(GRC_EEPROM_ADDR);
2316 if (tmp & EEPROM_ADDR_COMPLETE)
2320 if (!(tmp & EEPROM_ADDR_COMPLETE))
2323 tmp = tr32(GRC_EEPROM_DATA);
2326 * The data will always be opposite the native endian
2327 * format. Perform a blind byteswap to compensate.
2334 #define NVRAM_CMD_TIMEOUT 10000
2336 static int tg3_nvram_exec_cmd(struct tg3 *tp, u32 nvram_cmd)
2340 tw32(NVRAM_CMD, nvram_cmd);
2341 for (i = 0; i < NVRAM_CMD_TIMEOUT; i++) {
2343 if (tr32(NVRAM_CMD) & NVRAM_CMD_DONE) {
2349 if (i == NVRAM_CMD_TIMEOUT)
2355 static u32 tg3_nvram_phys_addr(struct tg3 *tp, u32 addr)
2357 if ((tp->tg3_flags & TG3_FLAG_NVRAM) &&
2358 (tp->tg3_flags & TG3_FLAG_NVRAM_BUFFERED) &&
2359 (tp->tg3_flags2 & TG3_FLG2_FLASH) &&
2360 !(tp->tg3_flags3 & TG3_FLG3_NO_NVRAM_ADDR_TRANS) &&
2361 (tp->nvram_jedecnum == JEDEC_ATMEL))
2363 addr = ((addr / tp->nvram_pagesize) <<
2364 ATMEL_AT45DB0X1B_PAGE_POS) +
2365 (addr % tp->nvram_pagesize);
2370 static u32 tg3_nvram_logical_addr(struct tg3 *tp, u32 addr)
2372 if ((tp->tg3_flags & TG3_FLAG_NVRAM) &&
2373 (tp->tg3_flags & TG3_FLAG_NVRAM_BUFFERED) &&
2374 (tp->tg3_flags2 & TG3_FLG2_FLASH) &&
2375 !(tp->tg3_flags3 & TG3_FLG3_NO_NVRAM_ADDR_TRANS) &&
2376 (tp->nvram_jedecnum == JEDEC_ATMEL))
2378 addr = ((addr >> ATMEL_AT45DB0X1B_PAGE_POS) *
2379 tp->nvram_pagesize) +
2380 (addr & ((1 << ATMEL_AT45DB0X1B_PAGE_POS) - 1));
2385 /* NOTE: Data read in from NVRAM is byteswapped according to
2386 * the byteswapping settings for all other register accesses.
2387 * tg3 devices are BE devices, so on a BE machine, the data
2388 * returned will be exactly as it is seen in NVRAM. On a LE
2389 * machine, the 32-bit value will be byteswapped.
2391 static int tg3_nvram_read(struct tg3 *tp, u32 offset, u32 *val)
2395 if (!(tp->tg3_flags & TG3_FLAG_NVRAM))
2396 return tg3_nvram_read_using_eeprom(tp, offset, val);
2398 offset = tg3_nvram_phys_addr(tp, offset);
2400 if (offset > NVRAM_ADDR_MSK)
2403 ret = tg3_nvram_lock(tp);
2407 tg3_enable_nvram_access(tp);
2409 tw32(NVRAM_ADDR, offset);
2410 ret = tg3_nvram_exec_cmd(tp, NVRAM_CMD_RD | NVRAM_CMD_GO |
2411 NVRAM_CMD_FIRST | NVRAM_CMD_LAST | NVRAM_CMD_DONE);
2414 *val = tr32(NVRAM_RDDATA);
2416 tg3_disable_nvram_access(tp);
2418 tg3_nvram_unlock(tp);
2423 /* Ensures NVRAM data is in bytestream format. */
2424 static int tg3_nvram_read_be32(struct tg3 *tp, u32 offset, __be32 *val)
2427 int res = tg3_nvram_read(tp, offset, &v);
2429 *val = cpu_to_be32(v);
2433 /* tp->lock is held. */
2434 static void __tg3_set_mac_addr(struct tg3 *tp, int skip_mac_1)
2436 u32 addr_high, addr_low;
2439 addr_high = ((tp->dev->dev_addr[0] << 8) |
2440 tp->dev->dev_addr[1]);
2441 addr_low = ((tp->dev->dev_addr[2] << 24) |
2442 (tp->dev->dev_addr[3] << 16) |
2443 (tp->dev->dev_addr[4] << 8) |
2444 (tp->dev->dev_addr[5] << 0));
2445 for (i = 0; i < 4; i++) {
2446 if (i == 1 && skip_mac_1)
2448 tw32(MAC_ADDR_0_HIGH + (i * 8), addr_high);
2449 tw32(MAC_ADDR_0_LOW + (i * 8), addr_low);
2452 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 ||
2453 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) {
2454 for (i = 0; i < 12; i++) {
2455 tw32(MAC_EXTADDR_0_HIGH + (i * 8), addr_high);
2456 tw32(MAC_EXTADDR_0_LOW + (i * 8), addr_low);
2460 addr_high = (tp->dev->dev_addr[0] +
2461 tp->dev->dev_addr[1] +
2462 tp->dev->dev_addr[2] +
2463 tp->dev->dev_addr[3] +
2464 tp->dev->dev_addr[4] +
2465 tp->dev->dev_addr[5]) &
2466 TX_BACKOFF_SEED_MASK;
2467 tw32(MAC_TX_BACKOFF_SEED, addr_high);
2470 static int tg3_set_power_state(struct tg3 *tp, pci_power_t state)
2473 bool device_should_wake, do_low_power;
2475 /* Make sure register accesses (indirect or otherwise)
2476 * will function correctly.
2478 pci_write_config_dword(tp->pdev,
2479 TG3PCI_MISC_HOST_CTRL,
2480 tp->misc_host_ctrl);
2484 pci_enable_wake(tp->pdev, state, false);
2485 pci_set_power_state(tp->pdev, PCI_D0);
2487 /* Switch out of Vaux if it is a NIC */
2488 if (tp->tg3_flags2 & TG3_FLG2_IS_NIC)
2489 tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl, 100);
2499 netdev_err(tp->dev, "Invalid power state (D%d) requested\n",
2504 /* Restore the CLKREQ setting. */
2505 if (tp->tg3_flags3 & TG3_FLG3_CLKREQ_BUG) {
2508 pci_read_config_word(tp->pdev,
2509 tp->pcie_cap + PCI_EXP_LNKCTL,
2511 lnkctl |= PCI_EXP_LNKCTL_CLKREQ_EN;
2512 pci_write_config_word(tp->pdev,
2513 tp->pcie_cap + PCI_EXP_LNKCTL,
2517 misc_host_ctrl = tr32(TG3PCI_MISC_HOST_CTRL);
2518 tw32(TG3PCI_MISC_HOST_CTRL,
2519 misc_host_ctrl | MISC_HOST_CTRL_MASK_PCI_INT);
2521 device_should_wake = pci_pme_capable(tp->pdev, state) &&
2522 device_may_wakeup(&tp->pdev->dev) &&
2523 (tp->tg3_flags & TG3_FLAG_WOL_ENABLE);
2525 if (tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB) {
2526 do_low_power = false;
2527 if ((tp->tg3_flags3 & TG3_FLG3_PHY_CONNECTED) &&
2528 !tp->link_config.phy_is_low_power) {
2529 struct phy_device *phydev;
2530 u32 phyid, advertising;
2532 phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR];
2534 tp->link_config.phy_is_low_power = 1;
2536 tp->link_config.orig_speed = phydev->speed;
2537 tp->link_config.orig_duplex = phydev->duplex;
2538 tp->link_config.orig_autoneg = phydev->autoneg;
2539 tp->link_config.orig_advertising = phydev->advertising;
2541 advertising = ADVERTISED_TP |
2543 ADVERTISED_Autoneg |
2544 ADVERTISED_10baseT_Half;
2546 if ((tp->tg3_flags & TG3_FLAG_ENABLE_ASF) ||
2547 device_should_wake) {
2548 if (tp->tg3_flags & TG3_FLAG_WOL_SPEED_100MB)
2550 ADVERTISED_100baseT_Half |
2551 ADVERTISED_100baseT_Full |
2552 ADVERTISED_10baseT_Full;
2554 advertising |= ADVERTISED_10baseT_Full;
2557 phydev->advertising = advertising;
2559 phy_start_aneg(phydev);
2561 phyid = phydev->drv->phy_id & phydev->drv->phy_id_mask;
2562 if (phyid != PHY_ID_BCMAC131) {
2563 phyid &= PHY_BCM_OUI_MASK;
2564 if (phyid == PHY_BCM_OUI_1 ||
2565 phyid == PHY_BCM_OUI_2 ||
2566 phyid == PHY_BCM_OUI_3)
2567 do_low_power = true;
2571 do_low_power = true;
2573 if (tp->link_config.phy_is_low_power == 0) {
2574 tp->link_config.phy_is_low_power = 1;
2575 tp->link_config.orig_speed = tp->link_config.speed;
2576 tp->link_config.orig_duplex = tp->link_config.duplex;
2577 tp->link_config.orig_autoneg = tp->link_config.autoneg;
2580 if (!(tp->tg3_flags2 & TG3_FLG2_ANY_SERDES)) {
2581 tp->link_config.speed = SPEED_10;
2582 tp->link_config.duplex = DUPLEX_HALF;
2583 tp->link_config.autoneg = AUTONEG_ENABLE;
2584 tg3_setup_phy(tp, 0);
2588 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
2591 val = tr32(GRC_VCPU_EXT_CTRL);
2592 tw32(GRC_VCPU_EXT_CTRL, val | GRC_VCPU_EXT_CTRL_DISABLE_WOL);
2593 } else if (!(tp->tg3_flags & TG3_FLAG_ENABLE_ASF)) {
2597 for (i = 0; i < 200; i++) {
2598 tg3_read_mem(tp, NIC_SRAM_FW_ASF_STATUS_MBOX, &val);
2599 if (val == ~NIC_SRAM_FIRMWARE_MBOX_MAGIC1)
2604 if (tp->tg3_flags & TG3_FLAG_WOL_CAP)
2605 tg3_write_mem(tp, NIC_SRAM_WOL_MBOX, WOL_SIGNATURE |
2606 WOL_DRV_STATE_SHUTDOWN |
2610 if (device_should_wake) {
2613 if (!(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)) {
2615 tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x5a);
2619 if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES)
2620 mac_mode = MAC_MODE_PORT_MODE_GMII;
2622 mac_mode = MAC_MODE_PORT_MODE_MII;
2624 mac_mode |= tp->mac_mode & MAC_MODE_LINK_POLARITY;
2625 if (GET_ASIC_REV(tp->pci_chip_rev_id) ==
2627 u32 speed = (tp->tg3_flags &
2628 TG3_FLAG_WOL_SPEED_100MB) ?
2629 SPEED_100 : SPEED_10;
2630 if (tg3_5700_link_polarity(tp, speed))
2631 mac_mode |= MAC_MODE_LINK_POLARITY;
2633 mac_mode &= ~MAC_MODE_LINK_POLARITY;
2636 mac_mode = MAC_MODE_PORT_MODE_TBI;
2639 if (!(tp->tg3_flags2 & TG3_FLG2_5750_PLUS))
2640 tw32(MAC_LED_CTRL, tp->led_ctrl);
2642 mac_mode |= MAC_MODE_MAGIC_PKT_ENABLE;
2643 if (((tp->tg3_flags2 & TG3_FLG2_5705_PLUS) &&
2644 !(tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) &&
2645 ((tp->tg3_flags & TG3_FLAG_ENABLE_ASF) ||
2646 (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE)))
2647 mac_mode |= MAC_MODE_KEEP_FRAME_IN_WOL;
2649 if (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE) {
2650 mac_mode |= tp->mac_mode &
2651 (MAC_MODE_APE_TX_EN | MAC_MODE_APE_RX_EN);
2652 if (mac_mode & MAC_MODE_APE_TX_EN)
2653 mac_mode |= MAC_MODE_TDE_ENABLE;
2656 tw32_f(MAC_MODE, mac_mode);
2659 tw32_f(MAC_RX_MODE, RX_MODE_ENABLE);
2663 if (!(tp->tg3_flags & TG3_FLAG_WOL_SPEED_100MB) &&
2664 (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
2665 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701)) {
2668 base_val = tp->pci_clock_ctrl;
2669 base_val |= (CLOCK_CTRL_RXCLK_DISABLE |
2670 CLOCK_CTRL_TXCLK_DISABLE);
2672 tw32_wait_f(TG3PCI_CLOCK_CTRL, base_val | CLOCK_CTRL_ALTCLK |
2673 CLOCK_CTRL_PWRDOWN_PLL133, 40);
2674 } else if ((tp->tg3_flags2 & TG3_FLG2_5780_CLASS) ||
2675 (tp->tg3_flags & TG3_FLAG_CPMU_PRESENT) ||
2676 (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)) {
2678 } else if (!((tp->tg3_flags2 & TG3_FLG2_5750_PLUS) &&
2679 (tp->tg3_flags & TG3_FLAG_ENABLE_ASF))) {
2680 u32 newbits1, newbits2;
2682 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
2683 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) {
2684 newbits1 = (CLOCK_CTRL_RXCLK_DISABLE |
2685 CLOCK_CTRL_TXCLK_DISABLE |
2687 newbits2 = newbits1 | CLOCK_CTRL_44MHZ_CORE;
2688 } else if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
2689 newbits1 = CLOCK_CTRL_625_CORE;
2690 newbits2 = newbits1 | CLOCK_CTRL_ALTCLK;
2692 newbits1 = CLOCK_CTRL_ALTCLK;
2693 newbits2 = newbits1 | CLOCK_CTRL_44MHZ_CORE;
2696 tw32_wait_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl | newbits1,
2699 tw32_wait_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl | newbits2,
2702 if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
2705 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
2706 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) {
2707 newbits3 = (CLOCK_CTRL_RXCLK_DISABLE |
2708 CLOCK_CTRL_TXCLK_DISABLE |
2709 CLOCK_CTRL_44MHZ_CORE);
2711 newbits3 = CLOCK_CTRL_44MHZ_CORE;
2714 tw32_wait_f(TG3PCI_CLOCK_CTRL,
2715 tp->pci_clock_ctrl | newbits3, 40);
2719 if (!(device_should_wake) &&
2720 !(tp->tg3_flags & TG3_FLAG_ENABLE_ASF))
2721 tg3_power_down_phy(tp, do_low_power);
2723 tg3_frob_aux_power(tp);
2725 /* Workaround for unstable PLL clock */
2726 if ((GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_AX) ||
2727 (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_BX)) {
2728 u32 val = tr32(0x7d00);
2730 val &= ~((1 << 16) | (1 << 4) | (1 << 2) | (1 << 1) | 1);
2732 if (!(tp->tg3_flags & TG3_FLAG_ENABLE_ASF)) {
2735 err = tg3_nvram_lock(tp);
2736 tg3_halt_cpu(tp, RX_CPU_BASE);
2738 tg3_nvram_unlock(tp);
2742 tg3_write_sig_post_reset(tp, RESET_KIND_SHUTDOWN);
2744 if (device_should_wake)
2745 pci_enable_wake(tp->pdev, state, true);
2747 /* Finally, set the new power state. */
2748 pci_set_power_state(tp->pdev, state);
2753 static void tg3_aux_stat_to_speed_duplex(struct tg3 *tp, u32 val, u16 *speed, u8 *duplex)
2755 switch (val & MII_TG3_AUX_STAT_SPDMASK) {
2756 case MII_TG3_AUX_STAT_10HALF:
2758 *duplex = DUPLEX_HALF;
2761 case MII_TG3_AUX_STAT_10FULL:
2763 *duplex = DUPLEX_FULL;
2766 case MII_TG3_AUX_STAT_100HALF:
2768 *duplex = DUPLEX_HALF;
2771 case MII_TG3_AUX_STAT_100FULL:
2773 *duplex = DUPLEX_FULL;
2776 case MII_TG3_AUX_STAT_1000HALF:
2777 *speed = SPEED_1000;
2778 *duplex = DUPLEX_HALF;
2781 case MII_TG3_AUX_STAT_1000FULL:
2782 *speed = SPEED_1000;
2783 *duplex = DUPLEX_FULL;
2787 if (tp->tg3_flags3 & TG3_FLG3_PHY_IS_FET) {
2788 *speed = (val & MII_TG3_AUX_STAT_100) ? SPEED_100 :
2790 *duplex = (val & MII_TG3_AUX_STAT_FULL) ? DUPLEX_FULL :
2794 *speed = SPEED_INVALID;
2795 *duplex = DUPLEX_INVALID;
2800 static void tg3_phy_copper_begin(struct tg3 *tp)
2805 if (tp->link_config.phy_is_low_power) {
2806 /* Entering low power mode. Disable gigabit and
2807 * 100baseT advertisements.
2809 tg3_writephy(tp, MII_TG3_CTRL, 0);
2811 new_adv = (ADVERTISE_10HALF | ADVERTISE_10FULL |
2812 ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP);
2813 if (tp->tg3_flags & TG3_FLAG_WOL_SPEED_100MB)
2814 new_adv |= (ADVERTISE_100HALF | ADVERTISE_100FULL);
2816 tg3_writephy(tp, MII_ADVERTISE, new_adv);
2817 } else if (tp->link_config.speed == SPEED_INVALID) {
2818 if (tp->tg3_flags & TG3_FLAG_10_100_ONLY)
2819 tp->link_config.advertising &=
2820 ~(ADVERTISED_1000baseT_Half |
2821 ADVERTISED_1000baseT_Full);
2823 new_adv = ADVERTISE_CSMA;
2824 if (tp->link_config.advertising & ADVERTISED_10baseT_Half)
2825 new_adv |= ADVERTISE_10HALF;
2826 if (tp->link_config.advertising & ADVERTISED_10baseT_Full)
2827 new_adv |= ADVERTISE_10FULL;
2828 if (tp->link_config.advertising & ADVERTISED_100baseT_Half)
2829 new_adv |= ADVERTISE_100HALF;
2830 if (tp->link_config.advertising & ADVERTISED_100baseT_Full)
2831 new_adv |= ADVERTISE_100FULL;
2833 new_adv |= tg3_advert_flowctrl_1000T(tp->link_config.flowctrl);
2835 tg3_writephy(tp, MII_ADVERTISE, new_adv);
2837 if (tp->link_config.advertising &
2838 (ADVERTISED_1000baseT_Half | ADVERTISED_1000baseT_Full)) {
2840 if (tp->link_config.advertising & ADVERTISED_1000baseT_Half)
2841 new_adv |= MII_TG3_CTRL_ADV_1000_HALF;
2842 if (tp->link_config.advertising & ADVERTISED_1000baseT_Full)
2843 new_adv |= MII_TG3_CTRL_ADV_1000_FULL;
2844 if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY) &&
2845 (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 ||
2846 tp->pci_chip_rev_id == CHIPREV_ID_5701_B0))
2847 new_adv |= (MII_TG3_CTRL_AS_MASTER |
2848 MII_TG3_CTRL_ENABLE_AS_MASTER);
2849 tg3_writephy(tp, MII_TG3_CTRL, new_adv);
2851 tg3_writephy(tp, MII_TG3_CTRL, 0);
2854 new_adv = tg3_advert_flowctrl_1000T(tp->link_config.flowctrl);
2855 new_adv |= ADVERTISE_CSMA;
2857 /* Asking for a specific link mode. */
2858 if (tp->link_config.speed == SPEED_1000) {
2859 tg3_writephy(tp, MII_ADVERTISE, new_adv);
2861 if (tp->link_config.duplex == DUPLEX_FULL)
2862 new_adv = MII_TG3_CTRL_ADV_1000_FULL;
2864 new_adv = MII_TG3_CTRL_ADV_1000_HALF;
2865 if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 ||
2866 tp->pci_chip_rev_id == CHIPREV_ID_5701_B0)
2867 new_adv |= (MII_TG3_CTRL_AS_MASTER |
2868 MII_TG3_CTRL_ENABLE_AS_MASTER);
2870 if (tp->link_config.speed == SPEED_100) {
2871 if (tp->link_config.duplex == DUPLEX_FULL)
2872 new_adv |= ADVERTISE_100FULL;
2874 new_adv |= ADVERTISE_100HALF;
2876 if (tp->link_config.duplex == DUPLEX_FULL)
2877 new_adv |= ADVERTISE_10FULL;
2879 new_adv |= ADVERTISE_10HALF;
2881 tg3_writephy(tp, MII_ADVERTISE, new_adv);
2886 tg3_writephy(tp, MII_TG3_CTRL, new_adv);
2889 if (tp->link_config.autoneg == AUTONEG_DISABLE &&
2890 tp->link_config.speed != SPEED_INVALID) {
2891 u32 bmcr, orig_bmcr;
2893 tp->link_config.active_speed = tp->link_config.speed;
2894 tp->link_config.active_duplex = tp->link_config.duplex;
2897 switch (tp->link_config.speed) {
2903 bmcr |= BMCR_SPEED100;
2907 bmcr |= TG3_BMCR_SPEED1000;
2911 if (tp->link_config.duplex == DUPLEX_FULL)
2912 bmcr |= BMCR_FULLDPLX;
2914 if (!tg3_readphy(tp, MII_BMCR, &orig_bmcr) &&
2915 (bmcr != orig_bmcr)) {
2916 tg3_writephy(tp, MII_BMCR, BMCR_LOOPBACK);
2917 for (i = 0; i < 1500; i++) {
2921 if (tg3_readphy(tp, MII_BMSR, &tmp) ||
2922 tg3_readphy(tp, MII_BMSR, &tmp))
2924 if (!(tmp & BMSR_LSTATUS)) {
2929 tg3_writephy(tp, MII_BMCR, bmcr);
2933 tg3_writephy(tp, MII_BMCR,
2934 BMCR_ANENABLE | BMCR_ANRESTART);
2938 static int tg3_init_5401phy_dsp(struct tg3 *tp)
2942 /* Turn off tap power management. */
2943 /* Set Extended packet length bit */
2944 err = tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x4c20);
2946 err |= tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x0012);
2947 err |= tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x1804);
2949 err |= tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x0013);
2950 err |= tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x1204);
2952 err |= tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8006);
2953 err |= tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0132);
2955 err |= tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8006);
2956 err |= tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0232);
2958 err |= tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x201f);
2959 err |= tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0a20);
2966 static int tg3_copper_is_advertising_all(struct tg3 *tp, u32 mask)
2968 u32 adv_reg, all_mask = 0;
2970 if (mask & ADVERTISED_10baseT_Half)
2971 all_mask |= ADVERTISE_10HALF;
2972 if (mask & ADVERTISED_10baseT_Full)
2973 all_mask |= ADVERTISE_10FULL;
2974 if (mask & ADVERTISED_100baseT_Half)
2975 all_mask |= ADVERTISE_100HALF;
2976 if (mask & ADVERTISED_100baseT_Full)
2977 all_mask |= ADVERTISE_100FULL;
2979 if (tg3_readphy(tp, MII_ADVERTISE, &adv_reg))
2982 if ((adv_reg & all_mask) != all_mask)
2984 if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY)) {
2988 if (mask & ADVERTISED_1000baseT_Half)
2989 all_mask |= ADVERTISE_1000HALF;
2990 if (mask & ADVERTISED_1000baseT_Full)
2991 all_mask |= ADVERTISE_1000FULL;
2993 if (tg3_readphy(tp, MII_TG3_CTRL, &tg3_ctrl))
2996 if ((tg3_ctrl & all_mask) != all_mask)
3002 static int tg3_adv_1000T_flowctrl_ok(struct tg3 *tp, u32 *lcladv, u32 *rmtadv)
3006 if (tg3_readphy(tp, MII_ADVERTISE, lcladv))
3009 curadv = *lcladv & (ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM);
3010 reqadv = tg3_advert_flowctrl_1000T(tp->link_config.flowctrl);
3012 if (tp->link_config.active_duplex == DUPLEX_FULL) {
3013 if (curadv != reqadv)
3016 if (tp->tg3_flags & TG3_FLAG_PAUSE_AUTONEG)
3017 tg3_readphy(tp, MII_LPA, rmtadv);
3019 /* Reprogram the advertisement register, even if it
3020 * does not affect the current link. If the link
3021 * gets renegotiated in the future, we can save an
3022 * additional renegotiation cycle by advertising
3023 * it correctly in the first place.
3025 if (curadv != reqadv) {
3026 *lcladv &= ~(ADVERTISE_PAUSE_CAP |
3027 ADVERTISE_PAUSE_ASYM);
3028 tg3_writephy(tp, MII_ADVERTISE, *lcladv | reqadv);
3035 static int tg3_setup_copper_phy(struct tg3 *tp, int force_reset)
3037 int current_link_up;
3039 u32 lcl_adv, rmt_adv;
3047 (MAC_STATUS_SYNC_CHANGED |
3048 MAC_STATUS_CFG_CHANGED |
3049 MAC_STATUS_MI_COMPLETION |
3050 MAC_STATUS_LNKSTATE_CHANGED));
3053 if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) {
3055 (tp->mi_mode & ~MAC_MI_MODE_AUTO_POLL));
3059 tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x02);
3061 /* Some third-party PHYs need to be reset on link going
3064 if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 ||
3065 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 ||
3066 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) &&
3067 netif_carrier_ok(tp->dev)) {
3068 tg3_readphy(tp, MII_BMSR, &bmsr);
3069 if (!tg3_readphy(tp, MII_BMSR, &bmsr) &&
3070 !(bmsr & BMSR_LSTATUS))
3076 if ((tp->phy_id & TG3_PHY_ID_MASK) == TG3_PHY_ID_BCM5401) {
3077 tg3_readphy(tp, MII_BMSR, &bmsr);
3078 if (tg3_readphy(tp, MII_BMSR, &bmsr) ||
3079 !(tp->tg3_flags & TG3_FLAG_INIT_COMPLETE))
3082 if (!(bmsr & BMSR_LSTATUS)) {
3083 err = tg3_init_5401phy_dsp(tp);
3087 tg3_readphy(tp, MII_BMSR, &bmsr);
3088 for (i = 0; i < 1000; i++) {
3090 if (!tg3_readphy(tp, MII_BMSR, &bmsr) &&
3091 (bmsr & BMSR_LSTATUS)) {
3097 if ((tp->phy_id & TG3_PHY_ID_REV_MASK) ==
3098 TG3_PHY_REV_BCM5401_B0 &&
3099 !(bmsr & BMSR_LSTATUS) &&
3100 tp->link_config.active_speed == SPEED_1000) {
3101 err = tg3_phy_reset(tp);
3103 err = tg3_init_5401phy_dsp(tp);
3108 } else if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 ||
3109 tp->pci_chip_rev_id == CHIPREV_ID_5701_B0) {
3110 /* 5701 {A0,B0} CRC bug workaround */
3111 tg3_writephy(tp, 0x15, 0x0a75);
3112 tg3_writephy(tp, 0x1c, 0x8c68);
3113 tg3_writephy(tp, 0x1c, 0x8d68);
3114 tg3_writephy(tp, 0x1c, 0x8c68);
3117 /* Clear pending interrupts... */
3118 tg3_readphy(tp, MII_TG3_ISTAT, &dummy);
3119 tg3_readphy(tp, MII_TG3_ISTAT, &dummy);
3121 if (tp->tg3_flags & TG3_FLAG_USE_MI_INTERRUPT)
3122 tg3_writephy(tp, MII_TG3_IMASK, ~MII_TG3_INT_LINKCHG);
3123 else if (!(tp->tg3_flags3 & TG3_FLG3_PHY_IS_FET))
3124 tg3_writephy(tp, MII_TG3_IMASK, ~0);
3126 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
3127 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) {
3128 if (tp->led_ctrl == LED_CTRL_MODE_PHY_1)
3129 tg3_writephy(tp, MII_TG3_EXT_CTRL,
3130 MII_TG3_EXT_CTRL_LNK3_LED_MODE);
3132 tg3_writephy(tp, MII_TG3_EXT_CTRL, 0);
3135 current_link_up = 0;
3136 current_speed = SPEED_INVALID;
3137 current_duplex = DUPLEX_INVALID;
3139 if (tp->tg3_flags2 & TG3_FLG2_CAPACITIVE_COUPLING) {
3142 tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x4007);
3143 tg3_readphy(tp, MII_TG3_AUX_CTRL, &val);
3144 if (!(val & (1 << 10))) {
3146 tg3_writephy(tp, MII_TG3_AUX_CTRL, val);
3152 for (i = 0; i < 100; i++) {
3153 tg3_readphy(tp, MII_BMSR, &bmsr);
3154 if (!tg3_readphy(tp, MII_BMSR, &bmsr) &&
3155 (bmsr & BMSR_LSTATUS))
3160 if (bmsr & BMSR_LSTATUS) {
3163 tg3_readphy(tp, MII_TG3_AUX_STAT, &aux_stat);
3164 for (i = 0; i < 2000; i++) {
3166 if (!tg3_readphy(tp, MII_TG3_AUX_STAT, &aux_stat) &&
3171 tg3_aux_stat_to_speed_duplex(tp, aux_stat,
3176 for (i = 0; i < 200; i++) {
3177 tg3_readphy(tp, MII_BMCR, &bmcr);
3178 if (tg3_readphy(tp, MII_BMCR, &bmcr))
3180 if (bmcr && bmcr != 0x7fff)
3188 tp->link_config.active_speed = current_speed;
3189 tp->link_config.active_duplex = current_duplex;
3191 if (tp->link_config.autoneg == AUTONEG_ENABLE) {
3192 if ((bmcr & BMCR_ANENABLE) &&
3193 tg3_copper_is_advertising_all(tp,
3194 tp->link_config.advertising)) {
3195 if (tg3_adv_1000T_flowctrl_ok(tp, &lcl_adv,
3197 current_link_up = 1;
3200 if (!(bmcr & BMCR_ANENABLE) &&
3201 tp->link_config.speed == current_speed &&
3202 tp->link_config.duplex == current_duplex &&
3203 tp->link_config.flowctrl ==
3204 tp->link_config.active_flowctrl) {
3205 current_link_up = 1;
3209 if (current_link_up == 1 &&
3210 tp->link_config.active_duplex == DUPLEX_FULL)
3211 tg3_setup_flow_control(tp, lcl_adv, rmt_adv);
3215 if (current_link_up == 0 || tp->link_config.phy_is_low_power) {
3218 tg3_phy_copper_begin(tp);
3220 tg3_readphy(tp, MII_BMSR, &tmp);
3221 if (!tg3_readphy(tp, MII_BMSR, &tmp) &&
3222 (tmp & BMSR_LSTATUS))
3223 current_link_up = 1;
3226 tp->mac_mode &= ~MAC_MODE_PORT_MODE_MASK;
3227 if (current_link_up == 1) {
3228 if (tp->link_config.active_speed == SPEED_100 ||
3229 tp->link_config.active_speed == SPEED_10)
3230 tp->mac_mode |= MAC_MODE_PORT_MODE_MII;
3232 tp->mac_mode |= MAC_MODE_PORT_MODE_GMII;
3233 } else if (tp->tg3_flags3 & TG3_FLG3_PHY_IS_FET)
3234 tp->mac_mode |= MAC_MODE_PORT_MODE_MII;
3236 tp->mac_mode |= MAC_MODE_PORT_MODE_GMII;
3238 tp->mac_mode &= ~MAC_MODE_HALF_DUPLEX;
3239 if (tp->link_config.active_duplex == DUPLEX_HALF)
3240 tp->mac_mode |= MAC_MODE_HALF_DUPLEX;
3242 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) {
3243 if (current_link_up == 1 &&
3244 tg3_5700_link_polarity(tp, tp->link_config.active_speed))
3245 tp->mac_mode |= MAC_MODE_LINK_POLARITY;
3247 tp->mac_mode &= ~MAC_MODE_LINK_POLARITY;
3250 /* ??? Without this setting Netgear GA302T PHY does not
3251 * ??? send/receive packets...
3253 if ((tp->phy_id & TG3_PHY_ID_MASK) == TG3_PHY_ID_BCM5411 &&
3254 tp->pci_chip_rev_id == CHIPREV_ID_5700_ALTIMA) {
3255 tp->mi_mode |= MAC_MI_MODE_AUTO_POLL;
3256 tw32_f(MAC_MI_MODE, tp->mi_mode);
3260 tw32_f(MAC_MODE, tp->mac_mode);
3263 if (tp->tg3_flags & TG3_FLAG_USE_LINKCHG_REG) {
3264 /* Polled via timer. */
3265 tw32_f(MAC_EVENT, 0);
3267 tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED);
3271 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 &&
3272 current_link_up == 1 &&
3273 tp->link_config.active_speed == SPEED_1000 &&
3274 ((tp->tg3_flags & TG3_FLAG_PCIX_MODE) ||
3275 (tp->tg3_flags & TG3_FLAG_PCI_HIGH_SPEED))) {
3278 (MAC_STATUS_SYNC_CHANGED |
3279 MAC_STATUS_CFG_CHANGED));
3282 NIC_SRAM_FIRMWARE_MBOX,
3283 NIC_SRAM_FIRMWARE_MBOX_MAGIC2);
3286 /* Prevent send BD corruption. */
3287 if (tp->tg3_flags3 & TG3_FLG3_CLKREQ_BUG) {
3288 u16 oldlnkctl, newlnkctl;
3290 pci_read_config_word(tp->pdev,
3291 tp->pcie_cap + PCI_EXP_LNKCTL,
3293 if (tp->link_config.active_speed == SPEED_100 ||
3294 tp->link_config.active_speed == SPEED_10)
3295 newlnkctl = oldlnkctl & ~PCI_EXP_LNKCTL_CLKREQ_EN;
3297 newlnkctl = oldlnkctl | PCI_EXP_LNKCTL_CLKREQ_EN;
3298 if (newlnkctl != oldlnkctl)
3299 pci_write_config_word(tp->pdev,
3300 tp->pcie_cap + PCI_EXP_LNKCTL,
3304 if (current_link_up != netif_carrier_ok(tp->dev)) {
3305 if (current_link_up)
3306 netif_carrier_on(tp->dev);
3308 netif_carrier_off(tp->dev);
3309 tg3_link_report(tp);
3315 struct tg3_fiber_aneginfo {
3317 #define ANEG_STATE_UNKNOWN 0
3318 #define ANEG_STATE_AN_ENABLE 1
3319 #define ANEG_STATE_RESTART_INIT 2
3320 #define ANEG_STATE_RESTART 3
3321 #define ANEG_STATE_DISABLE_LINK_OK 4
3322 #define ANEG_STATE_ABILITY_DETECT_INIT 5
3323 #define ANEG_STATE_ABILITY_DETECT 6
3324 #define ANEG_STATE_ACK_DETECT_INIT 7
3325 #define ANEG_STATE_ACK_DETECT 8
3326 #define ANEG_STATE_COMPLETE_ACK_INIT 9
3327 #define ANEG_STATE_COMPLETE_ACK 10
3328 #define ANEG_STATE_IDLE_DETECT_INIT 11
3329 #define ANEG_STATE_IDLE_DETECT 12
3330 #define ANEG_STATE_LINK_OK 13
3331 #define ANEG_STATE_NEXT_PAGE_WAIT_INIT 14
3332 #define ANEG_STATE_NEXT_PAGE_WAIT 15
3335 #define MR_AN_ENABLE 0x00000001
3336 #define MR_RESTART_AN 0x00000002
3337 #define MR_AN_COMPLETE 0x00000004
3338 #define MR_PAGE_RX 0x00000008
3339 #define MR_NP_LOADED 0x00000010
3340 #define MR_TOGGLE_TX 0x00000020
3341 #define MR_LP_ADV_FULL_DUPLEX 0x00000040
3342 #define MR_LP_ADV_HALF_DUPLEX 0x00000080
3343 #define MR_LP_ADV_SYM_PAUSE 0x00000100
3344 #define MR_LP_ADV_ASYM_PAUSE 0x00000200
3345 #define MR_LP_ADV_REMOTE_FAULT1 0x00000400
3346 #define MR_LP_ADV_REMOTE_FAULT2 0x00000800
3347 #define MR_LP_ADV_NEXT_PAGE 0x00001000
3348 #define MR_TOGGLE_RX 0x00002000
3349 #define MR_NP_RX 0x00004000
3351 #define MR_LINK_OK 0x80000000
3353 unsigned long link_time, cur_time;
3355 u32 ability_match_cfg;
3356 int ability_match_count;
3358 char ability_match, idle_match, ack_match;
3360 u32 txconfig, rxconfig;
3361 #define ANEG_CFG_NP 0x00000080
3362 #define ANEG_CFG_ACK 0x00000040
3363 #define ANEG_CFG_RF2 0x00000020
3364 #define ANEG_CFG_RF1 0x00000010
3365 #define ANEG_CFG_PS2 0x00000001
3366 #define ANEG_CFG_PS1 0x00008000
3367 #define ANEG_CFG_HD 0x00004000
3368 #define ANEG_CFG_FD 0x00002000
3369 #define ANEG_CFG_INVAL 0x00001f06
3374 #define ANEG_TIMER_ENAB 2
3375 #define ANEG_FAILED -1
3377 #define ANEG_STATE_SETTLE_TIME 10000
3379 static int tg3_fiber_aneg_smachine(struct tg3 *tp,
3380 struct tg3_fiber_aneginfo *ap)
3383 unsigned long delta;
3387 if (ap->state == ANEG_STATE_UNKNOWN) {
3391 ap->ability_match_cfg = 0;
3392 ap->ability_match_count = 0;
3393 ap->ability_match = 0;
3399 if (tr32(MAC_STATUS) & MAC_STATUS_RCVD_CFG) {
3400 rx_cfg_reg = tr32(MAC_RX_AUTO_NEG);
3402 if (rx_cfg_reg != ap->ability_match_cfg) {
3403 ap->ability_match_cfg = rx_cfg_reg;
3404 ap->ability_match = 0;
3405 ap->ability_match_count = 0;
3407 if (++ap->ability_match_count > 1) {
3408 ap->ability_match = 1;
3409 ap->ability_match_cfg = rx_cfg_reg;
3412 if (rx_cfg_reg & ANEG_CFG_ACK)
3420 ap->ability_match_cfg = 0;
3421 ap->ability_match_count = 0;
3422 ap->ability_match = 0;
3428 ap->rxconfig = rx_cfg_reg;
3431 switch (ap->state) {
3432 case ANEG_STATE_UNKNOWN:
3433 if (ap->flags & (MR_AN_ENABLE | MR_RESTART_AN))
3434 ap->state = ANEG_STATE_AN_ENABLE;
3437 case ANEG_STATE_AN_ENABLE:
3438 ap->flags &= ~(MR_AN_COMPLETE | MR_PAGE_RX);
3439 if (ap->flags & MR_AN_ENABLE) {
3442 ap->ability_match_cfg = 0;
3443 ap->ability_match_count = 0;
3444 ap->ability_match = 0;
3448 ap->state = ANEG_STATE_RESTART_INIT;
3450 ap->state = ANEG_STATE_DISABLE_LINK_OK;
3454 case ANEG_STATE_RESTART_INIT:
3455 ap->link_time = ap->cur_time;
3456 ap->flags &= ~(MR_NP_LOADED);
3458 tw32(MAC_TX_AUTO_NEG, 0);
3459 tp->mac_mode |= MAC_MODE_SEND_CONFIGS;
3460 tw32_f(MAC_MODE, tp->mac_mode);
3463 ret = ANEG_TIMER_ENAB;
3464 ap->state = ANEG_STATE_RESTART;
3467 case ANEG_STATE_RESTART:
3468 delta = ap->cur_time - ap->link_time;
3469 if (delta > ANEG_STATE_SETTLE_TIME) {
3470 ap->state = ANEG_STATE_ABILITY_DETECT_INIT;
3472 ret = ANEG_TIMER_ENAB;
3476 case ANEG_STATE_DISABLE_LINK_OK:
3480 case ANEG_STATE_ABILITY_DETECT_INIT:
3481 ap->flags &= ~(MR_TOGGLE_TX);
3482 ap->txconfig = ANEG_CFG_FD;
3483 flowctrl = tg3_advert_flowctrl_1000X(tp->link_config.flowctrl);
3484 if (flowctrl & ADVERTISE_1000XPAUSE)
3485 ap->txconfig |= ANEG_CFG_PS1;
3486 if (flowctrl & ADVERTISE_1000XPSE_ASYM)
3487 ap->txconfig |= ANEG_CFG_PS2;
3488 tw32(MAC_TX_AUTO_NEG, ap->txconfig);
3489 tp->mac_mode |= MAC_MODE_SEND_CONFIGS;
3490 tw32_f(MAC_MODE, tp->mac_mode);
3493 ap->state = ANEG_STATE_ABILITY_DETECT;
3496 case ANEG_STATE_ABILITY_DETECT:
3497 if (ap->ability_match != 0 && ap->rxconfig != 0) {
3498 ap->state = ANEG_STATE_ACK_DETECT_INIT;
3502 case ANEG_STATE_ACK_DETECT_INIT:
3503 ap->txconfig |= ANEG_CFG_ACK;
3504 tw32(MAC_TX_AUTO_NEG, ap->txconfig);
3505 tp->mac_mode |= MAC_MODE_SEND_CONFIGS;
3506 tw32_f(MAC_MODE, tp->mac_mode);
3509 ap->state = ANEG_STATE_ACK_DETECT;
3512 case ANEG_STATE_ACK_DETECT:
3513 if (ap->ack_match != 0) {
3514 if ((ap->rxconfig & ~ANEG_CFG_ACK) ==
3515 (ap->ability_match_cfg & ~ANEG_CFG_ACK)) {
3516 ap->state = ANEG_STATE_COMPLETE_ACK_INIT;
3518 ap->state = ANEG_STATE_AN_ENABLE;
3520 } else if (ap->ability_match != 0 &&
3521 ap->rxconfig == 0) {
3522 ap->state = ANEG_STATE_AN_ENABLE;
3526 case ANEG_STATE_COMPLETE_ACK_INIT:
3527 if (ap->rxconfig & ANEG_CFG_INVAL) {
3531 ap->flags &= ~(MR_LP_ADV_FULL_DUPLEX |
3532 MR_LP_ADV_HALF_DUPLEX |
3533 MR_LP_ADV_SYM_PAUSE |
3534 MR_LP_ADV_ASYM_PAUSE |
3535 MR_LP_ADV_REMOTE_FAULT1 |
3536 MR_LP_ADV_REMOTE_FAULT2 |
3537 MR_LP_ADV_NEXT_PAGE |
3540 if (ap->rxconfig & ANEG_CFG_FD)
3541 ap->flags |= MR_LP_ADV_FULL_DUPLEX;
3542 if (ap->rxconfig & ANEG_CFG_HD)
3543 ap->flags |= MR_LP_ADV_HALF_DUPLEX;
3544 if (ap->rxconfig & ANEG_CFG_PS1)
3545 ap->flags |= MR_LP_ADV_SYM_PAUSE;
3546 if (ap->rxconfig & ANEG_CFG_PS2)
3547 ap->flags |= MR_LP_ADV_ASYM_PAUSE;
3548 if (ap->rxconfig & ANEG_CFG_RF1)
3549 ap->flags |= MR_LP_ADV_REMOTE_FAULT1;
3550 if (ap->rxconfig & ANEG_CFG_RF2)
3551 ap->flags |= MR_LP_ADV_REMOTE_FAULT2;
3552 if (ap->rxconfig & ANEG_CFG_NP)
3553 ap->flags |= MR_LP_ADV_NEXT_PAGE;
3555 ap->link_time = ap->cur_time;
3557 ap->flags ^= (MR_TOGGLE_TX);
3558 if (ap->rxconfig & 0x0008)
3559 ap->flags |= MR_TOGGLE_RX;
3560 if (ap->rxconfig & ANEG_CFG_NP)
3561 ap->flags |= MR_NP_RX;
3562 ap->flags |= MR_PAGE_RX;
3564 ap->state = ANEG_STATE_COMPLETE_ACK;
3565 ret = ANEG_TIMER_ENAB;
3568 case ANEG_STATE_COMPLETE_ACK:
3569 if (ap->ability_match != 0 &&
3570 ap->rxconfig == 0) {
3571 ap->state = ANEG_STATE_AN_ENABLE;
3574 delta = ap->cur_time - ap->link_time;
3575 if (delta > ANEG_STATE_SETTLE_TIME) {
3576 if (!(ap->flags & (MR_LP_ADV_NEXT_PAGE))) {
3577 ap->state = ANEG_STATE_IDLE_DETECT_INIT;
3579 if ((ap->txconfig & ANEG_CFG_NP) == 0 &&
3580 !(ap->flags & MR_NP_RX)) {
3581 ap->state = ANEG_STATE_IDLE_DETECT_INIT;
3589 case ANEG_STATE_IDLE_DETECT_INIT:
3590 ap->link_time = ap->cur_time;
3591 tp->mac_mode &= ~MAC_MODE_SEND_CONFIGS;
3592 tw32_f(MAC_MODE, tp->mac_mode);
3595 ap->state = ANEG_STATE_IDLE_DETECT;
3596 ret = ANEG_TIMER_ENAB;
3599 case ANEG_STATE_IDLE_DETECT:
3600 if (ap->ability_match != 0 &&
3601 ap->rxconfig == 0) {
3602 ap->state = ANEG_STATE_AN_ENABLE;
3605 delta = ap->cur_time - ap->link_time;
3606 if (delta > ANEG_STATE_SETTLE_TIME) {
3607 /* XXX another gem from the Broadcom driver :( */
3608 ap->state = ANEG_STATE_LINK_OK;
3612 case ANEG_STATE_LINK_OK:
3613 ap->flags |= (MR_AN_COMPLETE | MR_LINK_OK);
3617 case ANEG_STATE_NEXT_PAGE_WAIT_INIT:
3618 /* ??? unimplemented */
3621 case ANEG_STATE_NEXT_PAGE_WAIT:
3622 /* ??? unimplemented */
3633 static int fiber_autoneg(struct tg3 *tp, u32 *txflags, u32 *rxflags)
3636 struct tg3_fiber_aneginfo aninfo;
3637 int status = ANEG_FAILED;
3641 tw32_f(MAC_TX_AUTO_NEG, 0);
3643 tmp = tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK;
3644 tw32_f(MAC_MODE, tmp | MAC_MODE_PORT_MODE_GMII);
3647 tw32_f(MAC_MODE, tp->mac_mode | MAC_MODE_SEND_CONFIGS);
3650 memset(&aninfo, 0, sizeof(aninfo));
3651 aninfo.flags |= MR_AN_ENABLE;
3652 aninfo.state = ANEG_STATE_UNKNOWN;
3653 aninfo.cur_time = 0;
3655 while (++tick < 195000) {
3656 status = tg3_fiber_aneg_smachine(tp, &aninfo);
3657 if (status == ANEG_DONE || status == ANEG_FAILED)
3663 tp->mac_mode &= ~MAC_MODE_SEND_CONFIGS;
3664 tw32_f(MAC_MODE, tp->mac_mode);
3667 *txflags = aninfo.txconfig;
3668 *rxflags = aninfo.flags;
3670 if (status == ANEG_DONE &&
3671 (aninfo.flags & (MR_AN_COMPLETE | MR_LINK_OK |
3672 MR_LP_ADV_FULL_DUPLEX)))
3678 static void tg3_init_bcm8002(struct tg3 *tp)
3680 u32 mac_status = tr32(MAC_STATUS);
3683 /* Reset when initting first time or we have a link. */
3684 if ((tp->tg3_flags & TG3_FLAG_INIT_COMPLETE) &&
3685 !(mac_status & MAC_STATUS_PCS_SYNCED))
3688 /* Set PLL lock range. */
3689 tg3_writephy(tp, 0x16, 0x8007);
3692 tg3_writephy(tp, MII_BMCR, BMCR_RESET);
3694 /* Wait for reset to complete. */
3695 /* XXX schedule_timeout() ... */
3696 for (i = 0; i < 500; i++)
3699 /* Config mode; select PMA/Ch 1 regs. */
3700 tg3_writephy(tp, 0x10, 0x8411);
3702 /* Enable auto-lock and comdet, select txclk for tx. */
3703 tg3_writephy(tp, 0x11, 0x0a10);
3705 tg3_writephy(tp, 0x18, 0x00a0);
3706 tg3_writephy(tp, 0x16, 0x41ff);
3708 /* Assert and deassert POR. */
3709 tg3_writephy(tp, 0x13, 0x0400);
3711 tg3_writephy(tp, 0x13, 0x0000);
3713 tg3_writephy(tp, 0x11, 0x0a50);
3715 tg3_writephy(tp, 0x11, 0x0a10);
3717 /* Wait for signal to stabilize */
3718 /* XXX schedule_timeout() ... */
3719 for (i = 0; i < 15000; i++)
3722 /* Deselect the channel register so we can read the PHYID
3725 tg3_writephy(tp, 0x10, 0x8011);
3728 static int tg3_setup_fiber_hw_autoneg(struct tg3 *tp, u32 mac_status)
3731 u32 sg_dig_ctrl, sg_dig_status;
3732 u32 serdes_cfg, expected_sg_dig_ctrl;
3733 int workaround, port_a;
3734 int current_link_up;
3737 expected_sg_dig_ctrl = 0;
3740 current_link_up = 0;
3742 if (tp->pci_chip_rev_id != CHIPREV_ID_5704_A0 &&
3743 tp->pci_chip_rev_id != CHIPREV_ID_5704_A1) {
3745 if (tr32(TG3PCI_DUAL_MAC_CTRL) & DUAL_MAC_CTRL_ID)
3748 /* preserve bits 0-11,13,14 for signal pre-emphasis */
3749 /* preserve bits 20-23 for voltage regulator */
3750 serdes_cfg = tr32(MAC_SERDES_CFG) & 0x00f06fff;
3753 sg_dig_ctrl = tr32(SG_DIG_CTRL);
3755 if (tp->link_config.autoneg != AUTONEG_ENABLE) {
3756 if (sg_dig_ctrl & SG_DIG_USING_HW_AUTONEG) {
3758 u32 val = serdes_cfg;
3764 tw32_f(MAC_SERDES_CFG, val);
3767 tw32_f(SG_DIG_CTRL, SG_DIG_COMMON_SETUP);
3769 if (mac_status & MAC_STATUS_PCS_SYNCED) {
3770 tg3_setup_flow_control(tp, 0, 0);
3771 current_link_up = 1;
3776 /* Want auto-negotiation. */
3777 expected_sg_dig_ctrl = SG_DIG_USING_HW_AUTONEG | SG_DIG_COMMON_SETUP;
3779 flowctrl = tg3_advert_flowctrl_1000X(tp->link_config.flowctrl);
3780 if (flowctrl & ADVERTISE_1000XPAUSE)
3781 expected_sg_dig_ctrl |= SG_DIG_PAUSE_CAP;
3782 if (flowctrl & ADVERTISE_1000XPSE_ASYM)
3783 expected_sg_dig_ctrl |= SG_DIG_ASYM_PAUSE;
3785 if (sg_dig_ctrl != expected_sg_dig_ctrl) {
3786 if ((tp->tg3_flags2 & TG3_FLG2_PARALLEL_DETECT) &&
3787 tp->serdes_counter &&
3788 ((mac_status & (MAC_STATUS_PCS_SYNCED |
3789 MAC_STATUS_RCVD_CFG)) ==
3790 MAC_STATUS_PCS_SYNCED)) {
3791 tp->serdes_counter--;
3792 current_link_up = 1;
3797 tw32_f(MAC_SERDES_CFG, serdes_cfg | 0xc011000);
3798 tw32_f(SG_DIG_CTRL, expected_sg_dig_ctrl | SG_DIG_SOFT_RESET);
3800 tw32_f(SG_DIG_CTRL, expected_sg_dig_ctrl);
3802 tp->serdes_counter = SERDES_AN_TIMEOUT_5704S;
3803 tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
3804 } else if (mac_status & (MAC_STATUS_PCS_SYNCED |
3805 MAC_STATUS_SIGNAL_DET)) {
3806 sg_dig_status = tr32(SG_DIG_STATUS);
3807 mac_status = tr32(MAC_STATUS);
3809 if ((sg_dig_status & SG_DIG_AUTONEG_COMPLETE) &&
3810 (mac_status & MAC_STATUS_PCS_SYNCED)) {
3811 u32 local_adv = 0, remote_adv = 0;
3813 if (sg_dig_ctrl & SG_DIG_PAUSE_CAP)
3814 local_adv |= ADVERTISE_1000XPAUSE;
3815 if (sg_dig_ctrl & SG_DIG_ASYM_PAUSE)
3816 local_adv |= ADVERTISE_1000XPSE_ASYM;
3818 if (sg_dig_status & SG_DIG_PARTNER_PAUSE_CAPABLE)
3819 remote_adv |= LPA_1000XPAUSE;
3820 if (sg_dig_status & SG_DIG_PARTNER_ASYM_PAUSE)
3821 remote_adv |= LPA_1000XPAUSE_ASYM;
3823 tg3_setup_flow_control(tp, local_adv, remote_adv);
3824 current_link_up = 1;
3825 tp->serdes_counter = 0;
3826 tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
3827 } else if (!(sg_dig_status & SG_DIG_AUTONEG_COMPLETE)) {
3828 if (tp->serdes_counter)
3829 tp->serdes_counter--;
3832 u32 val = serdes_cfg;
3839 tw32_f(MAC_SERDES_CFG, val);
3842 tw32_f(SG_DIG_CTRL, SG_DIG_COMMON_SETUP);
3845 /* Link parallel detection - link is up */
3846 /* only if we have PCS_SYNC and not */
3847 /* receiving config code words */
3848 mac_status = tr32(MAC_STATUS);
3849 if ((mac_status & MAC_STATUS_PCS_SYNCED) &&
3850 !(mac_status & MAC_STATUS_RCVD_CFG)) {
3851 tg3_setup_flow_control(tp, 0, 0);
3852 current_link_up = 1;
3854 TG3_FLG2_PARALLEL_DETECT;
3855 tp->serdes_counter =
3856 SERDES_PARALLEL_DET_TIMEOUT;
3858 goto restart_autoneg;
3862 tp->serdes_counter = SERDES_AN_TIMEOUT_5704S;
3863 tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
3867 return current_link_up;
3870 static int tg3_setup_fiber_by_hand(struct tg3 *tp, u32 mac_status)
3872 int current_link_up = 0;
3874 if (!(mac_status & MAC_STATUS_PCS_SYNCED))
3877 if (tp->link_config.autoneg == AUTONEG_ENABLE) {
3878 u32 txflags, rxflags;
3881 if (fiber_autoneg(tp, &txflags, &rxflags)) {
3882 u32 local_adv = 0, remote_adv = 0;
3884 if (txflags & ANEG_CFG_PS1)
3885 local_adv |= ADVERTISE_1000XPAUSE;
3886 if (txflags & ANEG_CFG_PS2)
3887 local_adv |= ADVERTISE_1000XPSE_ASYM;
3889 if (rxflags & MR_LP_ADV_SYM_PAUSE)
3890 remote_adv |= LPA_1000XPAUSE;
3891 if (rxflags & MR_LP_ADV_ASYM_PAUSE)
3892 remote_adv |= LPA_1000XPAUSE_ASYM;
3894 tg3_setup_flow_control(tp, local_adv, remote_adv);
3896 current_link_up = 1;
3898 for (i = 0; i < 30; i++) {
3901 (MAC_STATUS_SYNC_CHANGED |
3902 MAC_STATUS_CFG_CHANGED));
3904 if ((tr32(MAC_STATUS) &
3905 (MAC_STATUS_SYNC_CHANGED |
3906 MAC_STATUS_CFG_CHANGED)) == 0)
3910 mac_status = tr32(MAC_STATUS);
3911 if (current_link_up == 0 &&
3912 (mac_status & MAC_STATUS_PCS_SYNCED) &&
3913 !(mac_status & MAC_STATUS_RCVD_CFG))
3914 current_link_up = 1;
3916 tg3_setup_flow_control(tp, 0, 0);
3918 /* Forcing 1000FD link up. */
3919 current_link_up = 1;
3921 tw32_f(MAC_MODE, (tp->mac_mode | MAC_MODE_SEND_CONFIGS));
3924 tw32_f(MAC_MODE, tp->mac_mode);
3929 return current_link_up;
3932 static int tg3_setup_fiber_phy(struct tg3 *tp, int force_reset)
3935 u16 orig_active_speed;
3936 u8 orig_active_duplex;
3938 int current_link_up;
3941 orig_pause_cfg = tp->link_config.active_flowctrl;
3942 orig_active_speed = tp->link_config.active_speed;
3943 orig_active_duplex = tp->link_config.active_duplex;
3945 if (!(tp->tg3_flags2 & TG3_FLG2_HW_AUTONEG) &&
3946 netif_carrier_ok(tp->dev) &&
3947 (tp->tg3_flags & TG3_FLAG_INIT_COMPLETE)) {
3948 mac_status = tr32(MAC_STATUS);
3949 mac_status &= (MAC_STATUS_PCS_SYNCED |
3950 MAC_STATUS_SIGNAL_DET |
3951 MAC_STATUS_CFG_CHANGED |
3952 MAC_STATUS_RCVD_CFG);
3953 if (mac_status == (MAC_STATUS_PCS_SYNCED |
3954 MAC_STATUS_SIGNAL_DET)) {
3955 tw32_f(MAC_STATUS, (MAC_STATUS_SYNC_CHANGED |
3956 MAC_STATUS_CFG_CHANGED));
3961 tw32_f(MAC_TX_AUTO_NEG, 0);
3963 tp->mac_mode &= ~(MAC_MODE_PORT_MODE_MASK | MAC_MODE_HALF_DUPLEX);
3964 tp->mac_mode |= MAC_MODE_PORT_MODE_TBI;
3965 tw32_f(MAC_MODE, tp->mac_mode);
3968 if (tp->phy_id == TG3_PHY_ID_BCM8002)
3969 tg3_init_bcm8002(tp);
3971 /* Enable link change event even when serdes polling. */
3972 tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED);
3975 current_link_up = 0;
3976 mac_status = tr32(MAC_STATUS);
3978 if (tp->tg3_flags2 & TG3_FLG2_HW_AUTONEG)
3979 current_link_up = tg3_setup_fiber_hw_autoneg(tp, mac_status);
3981 current_link_up = tg3_setup_fiber_by_hand(tp, mac_status);
3983 tp->napi[0].hw_status->status =
3984 (SD_STATUS_UPDATED |
3985 (tp->napi[0].hw_status->status & ~SD_STATUS_LINK_CHG));
3987 for (i = 0; i < 100; i++) {
3988 tw32_f(MAC_STATUS, (MAC_STATUS_SYNC_CHANGED |
3989 MAC_STATUS_CFG_CHANGED));
3991 if ((tr32(MAC_STATUS) & (MAC_STATUS_SYNC_CHANGED |
3992 MAC_STATUS_CFG_CHANGED |
3993 MAC_STATUS_LNKSTATE_CHANGED)) == 0)
3997 mac_status = tr32(MAC_STATUS);
3998 if ((mac_status & MAC_STATUS_PCS_SYNCED) == 0) {
3999 current_link_up = 0;
4000 if (tp->link_config.autoneg == AUTONEG_ENABLE &&
4001 tp->serdes_counter == 0) {
4002 tw32_f(MAC_MODE, (tp->mac_mode |
4003 MAC_MODE_SEND_CONFIGS));
4005 tw32_f(MAC_MODE, tp->mac_mode);
4009 if (current_link_up == 1) {
4010 tp->link_config.active_speed = SPEED_1000;
4011 tp->link_config.active_duplex = DUPLEX_FULL;
4012 tw32(MAC_LED_CTRL, (tp->led_ctrl |
4013 LED_CTRL_LNKLED_OVERRIDE |
4014 LED_CTRL_1000MBPS_ON));
4016 tp->link_config.active_speed = SPEED_INVALID;
4017 tp->link_config.active_duplex = DUPLEX_INVALID;
4018 tw32(MAC_LED_CTRL, (tp->led_ctrl |
4019 LED_CTRL_LNKLED_OVERRIDE |
4020 LED_CTRL_TRAFFIC_OVERRIDE));
4023 if (current_link_up != netif_carrier_ok(tp->dev)) {
4024 if (current_link_up)
4025 netif_carrier_on(tp->dev);
4027 netif_carrier_off(tp->dev);
4028 tg3_link_report(tp);
4030 u32 now_pause_cfg = tp->link_config.active_flowctrl;
4031 if (orig_pause_cfg != now_pause_cfg ||
4032 orig_active_speed != tp->link_config.active_speed ||
4033 orig_active_duplex != tp->link_config.active_duplex)
4034 tg3_link_report(tp);
4040 static int tg3_setup_fiber_mii_phy(struct tg3 *tp, int force_reset)
4042 int current_link_up, err = 0;
4046 u32 local_adv, remote_adv;
4048 tp->mac_mode |= MAC_MODE_PORT_MODE_GMII;
4049 tw32_f(MAC_MODE, tp->mac_mode);
4055 (MAC_STATUS_SYNC_CHANGED |
4056 MAC_STATUS_CFG_CHANGED |
4057 MAC_STATUS_MI_COMPLETION |
4058 MAC_STATUS_LNKSTATE_CHANGED));
4064 current_link_up = 0;
4065 current_speed = SPEED_INVALID;
4066 current_duplex = DUPLEX_INVALID;
4068 err |= tg3_readphy(tp, MII_BMSR, &bmsr);
4069 err |= tg3_readphy(tp, MII_BMSR, &bmsr);
4070 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) {
4071 if (tr32(MAC_TX_STATUS) & TX_STATUS_LINK_UP)
4072 bmsr |= BMSR_LSTATUS;
4074 bmsr &= ~BMSR_LSTATUS;
4077 err |= tg3_readphy(tp, MII_BMCR, &bmcr);
4079 if ((tp->link_config.autoneg == AUTONEG_ENABLE) && !force_reset &&
4080 (tp->tg3_flags2 & TG3_FLG2_PARALLEL_DETECT)) {
4081 /* do nothing, just check for link up at the end */
4082 } else if (tp->link_config.autoneg == AUTONEG_ENABLE) {
4085 err |= tg3_readphy(tp, MII_ADVERTISE, &adv);
4086 new_adv = adv & ~(ADVERTISE_1000XFULL | ADVERTISE_1000XHALF |
4087 ADVERTISE_1000XPAUSE |
4088 ADVERTISE_1000XPSE_ASYM |
4091 new_adv |= tg3_advert_flowctrl_1000X(tp->link_config.flowctrl);
4093 if (tp->link_config.advertising & ADVERTISED_1000baseT_Half)
4094 new_adv |= ADVERTISE_1000XHALF;
4095 if (tp->link_config.advertising & ADVERTISED_1000baseT_Full)
4096 new_adv |= ADVERTISE_1000XFULL;
4098 if ((new_adv != adv) || !(bmcr & BMCR_ANENABLE)) {
4099 tg3_writephy(tp, MII_ADVERTISE, new_adv);
4100 bmcr |= BMCR_ANENABLE | BMCR_ANRESTART;
4101 tg3_writephy(tp, MII_BMCR, bmcr);
4103 tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED);
4104 tp->serdes_counter = SERDES_AN_TIMEOUT_5714S;
4105 tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
4112 bmcr &= ~BMCR_SPEED1000;
4113 new_bmcr = bmcr & ~(BMCR_ANENABLE | BMCR_FULLDPLX);
4115 if (tp->link_config.duplex == DUPLEX_FULL)
4116 new_bmcr |= BMCR_FULLDPLX;
4118 if (new_bmcr != bmcr) {
4119 /* BMCR_SPEED1000 is a reserved bit that needs
4120 * to be set on write.
4122 new_bmcr |= BMCR_SPEED1000;
4124 /* Force a linkdown */
4125 if (netif_carrier_ok(tp->dev)) {
4128 err |= tg3_readphy(tp, MII_ADVERTISE, &adv);
4129 adv &= ~(ADVERTISE_1000XFULL |
4130 ADVERTISE_1000XHALF |
4132 tg3_writephy(tp, MII_ADVERTISE, adv);
4133 tg3_writephy(tp, MII_BMCR, bmcr |
4137 netif_carrier_off(tp->dev);
4139 tg3_writephy(tp, MII_BMCR, new_bmcr);
4141 err |= tg3_readphy(tp, MII_BMSR, &bmsr);
4142 err |= tg3_readphy(tp, MII_BMSR, &bmsr);
4143 if (GET_ASIC_REV(tp->pci_chip_rev_id) ==
4145 if (tr32(MAC_TX_STATUS) & TX_STATUS_LINK_UP)
4146 bmsr |= BMSR_LSTATUS;
4148 bmsr &= ~BMSR_LSTATUS;
4150 tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
4154 if (bmsr & BMSR_LSTATUS) {
4155 current_speed = SPEED_1000;
4156 current_link_up = 1;
4157 if (bmcr & BMCR_FULLDPLX)
4158 current_duplex = DUPLEX_FULL;
4160 current_duplex = DUPLEX_HALF;
4165 if (bmcr & BMCR_ANENABLE) {
4168 err |= tg3_readphy(tp, MII_ADVERTISE, &local_adv);
4169 err |= tg3_readphy(tp, MII_LPA, &remote_adv);
4170 common = local_adv & remote_adv;
4171 if (common & (ADVERTISE_1000XHALF |
4172 ADVERTISE_1000XFULL)) {
4173 if (common & ADVERTISE_1000XFULL)
4174 current_duplex = DUPLEX_FULL;
4176 current_duplex = DUPLEX_HALF;
4179 current_link_up = 0;
4183 if (current_link_up == 1 && current_duplex == DUPLEX_FULL)
4184 tg3_setup_flow_control(tp, local_adv, remote_adv);
4186 tp->mac_mode &= ~MAC_MODE_HALF_DUPLEX;
4187 if (tp->link_config.active_duplex == DUPLEX_HALF)
4188 tp->mac_mode |= MAC_MODE_HALF_DUPLEX;
4190 tw32_f(MAC_MODE, tp->mac_mode);
4193 tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED);
4195 tp->link_config.active_speed = current_speed;
4196 tp->link_config.active_duplex = current_duplex;
4198 if (current_link_up != netif_carrier_ok(tp->dev)) {
4199 if (current_link_up)
4200 netif_carrier_on(tp->dev);
4202 netif_carrier_off(tp->dev);
4203 tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
4205 tg3_link_report(tp);
4210 static void tg3_serdes_parallel_detect(struct tg3 *tp)
4212 if (tp->serdes_counter) {
4213 /* Give autoneg time to complete. */
4214 tp->serdes_counter--;
4218 if (!netif_carrier_ok(tp->dev) &&
4219 (tp->link_config.autoneg == AUTONEG_ENABLE)) {
4222 tg3_readphy(tp, MII_BMCR, &bmcr);
4223 if (bmcr & BMCR_ANENABLE) {
4226 /* Select shadow register 0x1f */
4227 tg3_writephy(tp, 0x1c, 0x7c00);
4228 tg3_readphy(tp, 0x1c, &phy1);
4230 /* Select expansion interrupt status register */
4231 tg3_writephy(tp, 0x17, 0x0f01);
4232 tg3_readphy(tp, 0x15, &phy2);
4233 tg3_readphy(tp, 0x15, &phy2);
4235 if ((phy1 & 0x10) && !(phy2 & 0x20)) {
4236 /* We have signal detect and not receiving
4237 * config code words, link is up by parallel
4241 bmcr &= ~BMCR_ANENABLE;
4242 bmcr |= BMCR_SPEED1000 | BMCR_FULLDPLX;
4243 tg3_writephy(tp, MII_BMCR, bmcr);
4244 tp->tg3_flags2 |= TG3_FLG2_PARALLEL_DETECT;
4248 else if (netif_carrier_ok(tp->dev) &&
4249 (tp->link_config.autoneg == AUTONEG_ENABLE) &&
4250 (tp->tg3_flags2 & TG3_FLG2_PARALLEL_DETECT)) {
4253 /* Select expansion interrupt status register */
4254 tg3_writephy(tp, 0x17, 0x0f01);
4255 tg3_readphy(tp, 0x15, &phy2);
4259 /* Config code words received, turn on autoneg. */
4260 tg3_readphy(tp, MII_BMCR, &bmcr);
4261 tg3_writephy(tp, MII_BMCR, bmcr | BMCR_ANENABLE);
4263 tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
4269 static int tg3_setup_phy(struct tg3 *tp, int force_reset)
4273 if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) {
4274 err = tg3_setup_fiber_phy(tp, force_reset);
4275 } else if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES) {
4276 err = tg3_setup_fiber_mii_phy(tp, force_reset);
4278 err = tg3_setup_copper_phy(tp, force_reset);
4281 if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5784_AX) {
4284 val = tr32(TG3_CPMU_CLCK_STAT) & CPMU_CLCK_STAT_MAC_CLCK_MASK;
4285 if (val == CPMU_CLCK_STAT_MAC_CLCK_62_5)
4287 else if (val == CPMU_CLCK_STAT_MAC_CLCK_6_25)
4292 val = tr32(GRC_MISC_CFG) & ~GRC_MISC_CFG_PRESCALAR_MASK;
4293 val |= (scale << GRC_MISC_CFG_PRESCALAR_SHIFT);
4294 tw32(GRC_MISC_CFG, val);
4297 if (tp->link_config.active_speed == SPEED_1000 &&
4298 tp->link_config.active_duplex == DUPLEX_HALF)
4299 tw32(MAC_TX_LENGTHS,
4300 ((2 << TX_LENGTHS_IPG_CRS_SHIFT) |
4301 (6 << TX_LENGTHS_IPG_SHIFT) |
4302 (0xff << TX_LENGTHS_SLOT_TIME_SHIFT)));
4304 tw32(MAC_TX_LENGTHS,
4305 ((2 << TX_LENGTHS_IPG_CRS_SHIFT) |
4306 (6 << TX_LENGTHS_IPG_SHIFT) |
4307 (32 << TX_LENGTHS_SLOT_TIME_SHIFT)));
4309 if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
4310 if (netif_carrier_ok(tp->dev)) {
4311 tw32(HOSTCC_STAT_COAL_TICKS,
4312 tp->coal.stats_block_coalesce_usecs);
4314 tw32(HOSTCC_STAT_COAL_TICKS, 0);
4318 if (tp->tg3_flags & TG3_FLAG_ASPM_WORKAROUND) {
4319 u32 val = tr32(PCIE_PWR_MGMT_THRESH);
4320 if (!netif_carrier_ok(tp->dev))
4321 val = (val & ~PCIE_PWR_MGMT_L1_THRESH_MSK) |
4324 val |= PCIE_PWR_MGMT_L1_THRESH_MSK;
4325 tw32(PCIE_PWR_MGMT_THRESH, val);
4331 /* This is called whenever we suspect that the system chipset is re-
4332 * ordering the sequence of MMIO to the tx send mailbox. The symptom
4333 * is bogus tx completions. We try to recover by setting the
4334 * TG3_FLAG_MBOX_WRITE_REORDER flag and resetting the chip later
4337 static void tg3_tx_recover(struct tg3 *tp)
4339 BUG_ON((tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER) ||
4340 tp->write32_tx_mbox == tg3_write_indirect_mbox);
4342 netdev_warn(tp->dev,
4343 "The system may be re-ordering memory-mapped I/O "
4344 "cycles to the network device, attempting to recover. "
4345 "Please report the problem to the driver maintainer "
4346 "and include system chipset information.\n");
4348 spin_lock(&tp->lock);
4349 tp->tg3_flags |= TG3_FLAG_TX_RECOVERY_PENDING;
4350 spin_unlock(&tp->lock);
4353 static inline u32 tg3_tx_avail(struct tg3_napi *tnapi)
4356 return tnapi->tx_pending -
4357 ((tnapi->tx_prod - tnapi->tx_cons) & (TG3_TX_RING_SIZE - 1));
4360 /* Tigon3 never reports partial packet sends. So we do not
4361 * need special logic to handle SKBs that have not had all
4362 * of their frags sent yet, like SunGEM does.
4364 static void tg3_tx(struct tg3_napi *tnapi)
4366 struct tg3 *tp = tnapi->tp;
4367 u32 hw_idx = tnapi->hw_status->idx[0].tx_consumer;
4368 u32 sw_idx = tnapi->tx_cons;
4369 struct netdev_queue *txq;
4370 int index = tnapi - tp->napi;
4372 if (tp->tg3_flags3 & TG3_FLG3_ENABLE_TSS)
4375 txq = netdev_get_tx_queue(tp->dev, index);
4377 while (sw_idx != hw_idx) {
4378 struct ring_info *ri = &tnapi->tx_buffers[sw_idx];
4379 struct sk_buff *skb = ri->skb;
4382 if (unlikely(skb == NULL)) {
4387 pci_unmap_single(tp->pdev,
4388 pci_unmap_addr(ri, mapping),
4394 sw_idx = NEXT_TX(sw_idx);
4396 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
4397 ri = &tnapi->tx_buffers[sw_idx];
4398 if (unlikely(ri->skb != NULL || sw_idx == hw_idx))
4401 pci_unmap_page(tp->pdev,
4402 pci_unmap_addr(ri, mapping),
4403 skb_shinfo(skb)->frags[i].size,
4405 sw_idx = NEXT_TX(sw_idx);
4410 if (unlikely(tx_bug)) {
4416 tnapi->tx_cons = sw_idx;
4418 /* Need to make the tx_cons update visible to tg3_start_xmit()
4419 * before checking for netif_queue_stopped(). Without the
4420 * memory barrier, there is a small possibility that tg3_start_xmit()
4421 * will miss it and cause the queue to be stopped forever.
4425 if (unlikely(netif_tx_queue_stopped(txq) &&
4426 (tg3_tx_avail(tnapi) > TG3_TX_WAKEUP_THRESH(tnapi)))) {
4427 __netif_tx_lock(txq, smp_processor_id());
4428 if (netif_tx_queue_stopped(txq) &&
4429 (tg3_tx_avail(tnapi) > TG3_TX_WAKEUP_THRESH(tnapi)))
4430 netif_tx_wake_queue(txq);
4431 __netif_tx_unlock(txq);
4435 static void tg3_rx_skb_free(struct tg3 *tp, struct ring_info *ri, u32 map_sz)
4440 pci_unmap_single(tp->pdev, pci_unmap_addr(ri, mapping),
4441 map_sz, PCI_DMA_FROMDEVICE);
4442 dev_kfree_skb_any(ri->skb);
4446 /* Returns size of skb allocated or < 0 on error.
4448 * We only need to fill in the address because the other members
4449 * of the RX descriptor are invariant, see tg3_init_rings.
4451 * Note the purposeful assymetry of cpu vs. chip accesses. For
4452 * posting buffers we only dirty the first cache line of the RX
4453 * descriptor (containing the address). Whereas for the RX status
4454 * buffers the cpu only reads the last cacheline of the RX descriptor
4455 * (to fetch the error flags, vlan tag, checksum, and opaque cookie).
4457 static int tg3_alloc_rx_skb(struct tg3 *tp, struct tg3_rx_prodring_set *tpr,
4458 u32 opaque_key, u32 dest_idx_unmasked)
4460 struct tg3_rx_buffer_desc *desc;
4461 struct ring_info *map, *src_map;
4462 struct sk_buff *skb;
4464 int skb_size, dest_idx;
4467 switch (opaque_key) {
4468 case RXD_OPAQUE_RING_STD:
4469 dest_idx = dest_idx_unmasked % TG3_RX_RING_SIZE;
4470 desc = &tpr->rx_std[dest_idx];
4471 map = &tpr->rx_std_buffers[dest_idx];
4472 skb_size = tp->rx_pkt_map_sz;
4475 case RXD_OPAQUE_RING_JUMBO:
4476 dest_idx = dest_idx_unmasked % TG3_RX_JUMBO_RING_SIZE;
4477 desc = &tpr->rx_jmb[dest_idx].std;
4478 map = &tpr->rx_jmb_buffers[dest_idx];
4479 skb_size = TG3_RX_JMB_MAP_SZ;
4486 /* Do not overwrite any of the map or rp information
4487 * until we are sure we can commit to a new buffer.
4489 * Callers depend upon this behavior and assume that
4490 * we leave everything unchanged if we fail.
4492 skb = netdev_alloc_skb(tp->dev, skb_size + tp->rx_offset);
4496 skb_reserve(skb, tp->rx_offset);
4498 mapping = pci_map_single(tp->pdev, skb->data, skb_size,
4499 PCI_DMA_FROMDEVICE);
4500 if (pci_dma_mapping_error(tp->pdev, mapping)) {
4506 pci_unmap_addr_set(map, mapping, mapping);
4508 desc->addr_hi = ((u64)mapping >> 32);
4509 desc->addr_lo = ((u64)mapping & 0xffffffff);
4514 /* We only need to move over in the address because the other
4515 * members of the RX descriptor are invariant. See notes above
4516 * tg3_alloc_rx_skb for full details.
4518 static void tg3_recycle_rx(struct tg3_napi *tnapi,
4519 struct tg3_rx_prodring_set *dpr,
4520 u32 opaque_key, int src_idx,
4521 u32 dest_idx_unmasked)
4523 struct tg3 *tp = tnapi->tp;
4524 struct tg3_rx_buffer_desc *src_desc, *dest_desc;
4525 struct ring_info *src_map, *dest_map;
4526 struct tg3_rx_prodring_set *spr = &tp->prodring[0];
4529 switch (opaque_key) {
4530 case RXD_OPAQUE_RING_STD:
4531 dest_idx = dest_idx_unmasked % TG3_RX_RING_SIZE;
4532 dest_desc = &dpr->rx_std[dest_idx];
4533 dest_map = &dpr->rx_std_buffers[dest_idx];
4534 src_desc = &spr->rx_std[src_idx];
4535 src_map = &spr->rx_std_buffers[src_idx];
4538 case RXD_OPAQUE_RING_JUMBO:
4539 dest_idx = dest_idx_unmasked % TG3_RX_JUMBO_RING_SIZE;
4540 dest_desc = &dpr->rx_jmb[dest_idx].std;
4541 dest_map = &dpr->rx_jmb_buffers[dest_idx];
4542 src_desc = &spr->rx_jmb[src_idx].std;
4543 src_map = &spr->rx_jmb_buffers[src_idx];
4550 dest_map->skb = src_map->skb;
4551 pci_unmap_addr_set(dest_map, mapping,
4552 pci_unmap_addr(src_map, mapping));
4553 dest_desc->addr_hi = src_desc->addr_hi;
4554 dest_desc->addr_lo = src_desc->addr_lo;
4556 /* Ensure that the update to the skb happens after the physical
4557 * addresses have been transferred to the new BD location.
4561 src_map->skb = NULL;
4564 /* The RX ring scheme is composed of multiple rings which post fresh
4565 * buffers to the chip, and one special ring the chip uses to report
4566 * status back to the host.
4568 * The special ring reports the status of received packets to the
4569 * host. The chip does not write into the original descriptor the
4570 * RX buffer was obtained from. The chip simply takes the original
4571 * descriptor as provided by the host, updates the status and length
4572 * field, then writes this into the next status ring entry.
4574 * Each ring the host uses to post buffers to the chip is described
4575 * by a TG3_BDINFO entry in the chips SRAM area. When a packet arrives,
4576 * it is first placed into the on-chip ram. When the packet's length
4577 * is known, it walks down the TG3_BDINFO entries to select the ring.
4578 * Each TG3_BDINFO specifies a MAXLEN field and the first TG3_BDINFO
4579 * which is within the range of the new packet's length is chosen.
4581 * The "separate ring for rx status" scheme may sound queer, but it makes
4582 * sense from a cache coherency perspective. If only the host writes
4583 * to the buffer post rings, and only the chip writes to the rx status
4584 * rings, then cache lines never move beyond shared-modified state.
4585 * If both the host and chip were to write into the same ring, cache line
4586 * eviction could occur since both entities want it in an exclusive state.
4588 static int tg3_rx(struct tg3_napi *tnapi, int budget)
4590 struct tg3 *tp = tnapi->tp;
4591 u32 work_mask, rx_std_posted = 0;
4592 u32 std_prod_idx, jmb_prod_idx;
4593 u32 sw_idx = tnapi->rx_rcb_ptr;
4596 struct tg3_rx_prodring_set *tpr = tnapi->prodring;
4598 hw_idx = *(tnapi->rx_rcb_prod_idx);
4600 * We need to order the read of hw_idx and the read of
4601 * the opaque cookie.
4606 std_prod_idx = tpr->rx_std_prod_idx;
4607 jmb_prod_idx = tpr->rx_jmb_prod_idx;
4608 while (sw_idx != hw_idx && budget > 0) {
4609 struct ring_info *ri;
4610 struct tg3_rx_buffer_desc *desc = &tnapi->rx_rcb[sw_idx];
4612 struct sk_buff *skb;
4613 dma_addr_t dma_addr;
4614 u32 opaque_key, desc_idx, *post_ptr;
4616 desc_idx = desc->opaque & RXD_OPAQUE_INDEX_MASK;
4617 opaque_key = desc->opaque & RXD_OPAQUE_RING_MASK;
4618 if (opaque_key == RXD_OPAQUE_RING_STD) {
4619 ri = &tp->prodring[0].rx_std_buffers[desc_idx];
4620 dma_addr = pci_unmap_addr(ri, mapping);
4622 post_ptr = &std_prod_idx;
4624 } else if (opaque_key == RXD_OPAQUE_RING_JUMBO) {
4625 ri = &tp->prodring[0].rx_jmb_buffers[desc_idx];
4626 dma_addr = pci_unmap_addr(ri, mapping);
4628 post_ptr = &jmb_prod_idx;
4630 goto next_pkt_nopost;
4632 work_mask |= opaque_key;
4634 if ((desc->err_vlan & RXD_ERR_MASK) != 0 &&
4635 (desc->err_vlan != RXD_ERR_ODD_NIBBLE_RCVD_MII)) {
4637 tg3_recycle_rx(tnapi, tpr, opaque_key,
4638 desc_idx, *post_ptr);
4640 /* Other statistics kept track of by card. */
4641 tp->net_stats.rx_dropped++;
4645 len = ((desc->idx_len & RXD_LEN_MASK) >> RXD_LEN_SHIFT) -
4648 if (len > RX_COPY_THRESHOLD &&
4649 tp->rx_offset == NET_IP_ALIGN) {
4650 /* rx_offset will likely not equal NET_IP_ALIGN
4651 * if this is a 5701 card running in PCI-X mode
4652 * [see tg3_get_invariants()]
4656 skb_size = tg3_alloc_rx_skb(tp, tpr, opaque_key,
4661 pci_unmap_single(tp->pdev, dma_addr, skb_size,
4662 PCI_DMA_FROMDEVICE);
4664 /* Ensure that the update to the skb happens
4665 * after the usage of the old DMA mapping.
4673 struct sk_buff *copy_skb;
4675 tg3_recycle_rx(tnapi, tpr, opaque_key,
4676 desc_idx, *post_ptr);
4678 copy_skb = netdev_alloc_skb(tp->dev,
4679 len + TG3_RAW_IP_ALIGN);
4680 if (copy_skb == NULL)
4681 goto drop_it_no_recycle;
4683 skb_reserve(copy_skb, TG3_RAW_IP_ALIGN);
4684 skb_put(copy_skb, len);
4685 pci_dma_sync_single_for_cpu(tp->pdev, dma_addr, len, PCI_DMA_FROMDEVICE);
4686 skb_copy_from_linear_data(skb, copy_skb->data, len);
4687 pci_dma_sync_single_for_device(tp->pdev, dma_addr, len, PCI_DMA_FROMDEVICE);
4689 /* We'll reuse the original ring buffer. */
4693 if ((tp->tg3_flags & TG3_FLAG_RX_CHECKSUMS) &&
4694 (desc->type_flags & RXD_FLAG_TCPUDP_CSUM) &&
4695 (((desc->ip_tcp_csum & RXD_TCPCSUM_MASK)
4696 >> RXD_TCPCSUM_SHIFT) == 0xffff))
4697 skb->ip_summed = CHECKSUM_UNNECESSARY;
4699 skb->ip_summed = CHECKSUM_NONE;
4701 skb->protocol = eth_type_trans(skb, tp->dev);
4703 if (len > (tp->dev->mtu + ETH_HLEN) &&
4704 skb->protocol != htons(ETH_P_8021Q)) {
4709 #if TG3_VLAN_TAG_USED
4710 if (tp->vlgrp != NULL &&
4711 desc->type_flags & RXD_FLAG_VLAN) {
4712 vlan_gro_receive(&tnapi->napi, tp->vlgrp,
4713 desc->err_vlan & RXD_VLAN_MASK, skb);
4716 napi_gro_receive(&tnapi->napi, skb);
4724 if (unlikely(rx_std_posted >= tp->rx_std_max_post)) {
4725 tpr->rx_std_prod_idx = std_prod_idx % TG3_RX_RING_SIZE;
4726 tw32_rx_mbox(TG3_RX_STD_PROD_IDX_REG,
4727 tpr->rx_std_prod_idx);
4728 work_mask &= ~RXD_OPAQUE_RING_STD;
4733 sw_idx &= (TG3_RX_RCB_RING_SIZE(tp) - 1);
4735 /* Refresh hw_idx to see if there is new work */
4736 if (sw_idx == hw_idx) {
4737 hw_idx = *(tnapi->rx_rcb_prod_idx);
4742 /* ACK the status ring. */
4743 tnapi->rx_rcb_ptr = sw_idx;
4744 tw32_rx_mbox(tnapi->consmbox, sw_idx);
4746 /* Refill RX ring(s). */
4747 if (!(tp->tg3_flags3 & TG3_FLG3_ENABLE_RSS)) {
4748 if (work_mask & RXD_OPAQUE_RING_STD) {
4749 tpr->rx_std_prod_idx = std_prod_idx % TG3_RX_RING_SIZE;
4750 tw32_rx_mbox(TG3_RX_STD_PROD_IDX_REG,
4751 tpr->rx_std_prod_idx);
4753 if (work_mask & RXD_OPAQUE_RING_JUMBO) {
4754 tpr->rx_jmb_prod_idx = jmb_prod_idx %
4755 TG3_RX_JUMBO_RING_SIZE;
4756 tw32_rx_mbox(TG3_RX_JMB_PROD_IDX_REG,
4757 tpr->rx_jmb_prod_idx);
4760 } else if (work_mask) {
4761 /* rx_std_buffers[] and rx_jmb_buffers[] entries must be
4762 * updated before the producer indices can be updated.
4766 tpr->rx_std_prod_idx = std_prod_idx % TG3_RX_RING_SIZE;
4767 tpr->rx_jmb_prod_idx = jmb_prod_idx % TG3_RX_JUMBO_RING_SIZE;
4769 if (tnapi != &tp->napi[1])
4770 napi_schedule(&tp->napi[1].napi);
4776 static void tg3_poll_link(struct tg3 *tp)
4778 /* handle link change and other phy events */
4779 if (!(tp->tg3_flags &
4780 (TG3_FLAG_USE_LINKCHG_REG |
4781 TG3_FLAG_POLL_SERDES))) {
4782 struct tg3_hw_status *sblk = tp->napi[0].hw_status;
4784 if (sblk->status & SD_STATUS_LINK_CHG) {
4785 sblk->status = SD_STATUS_UPDATED |
4786 (sblk->status & ~SD_STATUS_LINK_CHG);
4787 spin_lock(&tp->lock);
4788 if (tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB) {
4790 (MAC_STATUS_SYNC_CHANGED |
4791 MAC_STATUS_CFG_CHANGED |
4792 MAC_STATUS_MI_COMPLETION |
4793 MAC_STATUS_LNKSTATE_CHANGED));
4796 tg3_setup_phy(tp, 0);
4797 spin_unlock(&tp->lock);
4802 static int tg3_rx_prodring_xfer(struct tg3 *tp,
4803 struct tg3_rx_prodring_set *dpr,
4804 struct tg3_rx_prodring_set *spr)
4806 u32 si, di, cpycnt, src_prod_idx;
4810 src_prod_idx = spr->rx_std_prod_idx;
4812 /* Make sure updates to the rx_std_buffers[] entries and the
4813 * standard producer index are seen in the correct order.
4817 if (spr->rx_std_cons_idx == src_prod_idx)
4820 if (spr->rx_std_cons_idx < src_prod_idx)
4821 cpycnt = src_prod_idx - spr->rx_std_cons_idx;
4823 cpycnt = TG3_RX_RING_SIZE - spr->rx_std_cons_idx;
4825 cpycnt = min(cpycnt, TG3_RX_RING_SIZE - dpr->rx_std_prod_idx);
4827 si = spr->rx_std_cons_idx;
4828 di = dpr->rx_std_prod_idx;
4830 for (i = di; i < di + cpycnt; i++) {
4831 if (dpr->rx_std_buffers[i].skb) {
4841 /* Ensure that updates to the rx_std_buffers ring and the
4842 * shadowed hardware producer ring from tg3_recycle_skb() are
4843 * ordered correctly WRT the skb check above.
4847 memcpy(&dpr->rx_std_buffers[di],
4848 &spr->rx_std_buffers[si],
4849 cpycnt * sizeof(struct ring_info));
4851 for (i = 0; i < cpycnt; i++, di++, si++) {
4852 struct tg3_rx_buffer_desc *sbd, *dbd;
4853 sbd = &spr->rx_std[si];
4854 dbd = &dpr->rx_std[di];
4855 dbd->addr_hi = sbd->addr_hi;
4856 dbd->addr_lo = sbd->addr_lo;
4859 spr->rx_std_cons_idx = (spr->rx_std_cons_idx + cpycnt) %
4861 dpr->rx_std_prod_idx = (dpr->rx_std_prod_idx + cpycnt) %
4866 src_prod_idx = spr->rx_jmb_prod_idx;
4868 /* Make sure updates to the rx_jmb_buffers[] entries and
4869 * the jumbo producer index are seen in the correct order.
4873 if (spr->rx_jmb_cons_idx == src_prod_idx)
4876 if (spr->rx_jmb_cons_idx < src_prod_idx)
4877 cpycnt = src_prod_idx - spr->rx_jmb_cons_idx;
4879 cpycnt = TG3_RX_JUMBO_RING_SIZE - spr->rx_jmb_cons_idx;
4881 cpycnt = min(cpycnt,
4882 TG3_RX_JUMBO_RING_SIZE - dpr->rx_jmb_prod_idx);
4884 si = spr->rx_jmb_cons_idx;
4885 di = dpr->rx_jmb_prod_idx;
4887 for (i = di; i < di + cpycnt; i++) {
4888 if (dpr->rx_jmb_buffers[i].skb) {
4898 /* Ensure that updates to the rx_jmb_buffers ring and the
4899 * shadowed hardware producer ring from tg3_recycle_skb() are
4900 * ordered correctly WRT the skb check above.
4904 memcpy(&dpr->rx_jmb_buffers[di],
4905 &spr->rx_jmb_buffers[si],
4906 cpycnt * sizeof(struct ring_info));
4908 for (i = 0; i < cpycnt; i++, di++, si++) {
4909 struct tg3_rx_buffer_desc *sbd, *dbd;
4910 sbd = &spr->rx_jmb[si].std;
4911 dbd = &dpr->rx_jmb[di].std;
4912 dbd->addr_hi = sbd->addr_hi;
4913 dbd->addr_lo = sbd->addr_lo;
4916 spr->rx_jmb_cons_idx = (spr->rx_jmb_cons_idx + cpycnt) %
4917 TG3_RX_JUMBO_RING_SIZE;
4918 dpr->rx_jmb_prod_idx = (dpr->rx_jmb_prod_idx + cpycnt) %
4919 TG3_RX_JUMBO_RING_SIZE;
4925 static int tg3_poll_work(struct tg3_napi *tnapi, int work_done, int budget)
4927 struct tg3 *tp = tnapi->tp;
4929 /* run TX completion thread */
4930 if (tnapi->hw_status->idx[0].tx_consumer != tnapi->tx_cons) {
4932 if (unlikely(tp->tg3_flags & TG3_FLAG_TX_RECOVERY_PENDING))
4936 /* run RX thread, within the bounds set by NAPI.
4937 * All RX "locking" is done by ensuring outside
4938 * code synchronizes with tg3->napi.poll()
4940 if (*(tnapi->rx_rcb_prod_idx) != tnapi->rx_rcb_ptr)
4941 work_done += tg3_rx(tnapi, budget - work_done);
4943 if ((tp->tg3_flags3 & TG3_FLG3_ENABLE_RSS) && tnapi == &tp->napi[1]) {
4944 struct tg3_rx_prodring_set *dpr = &tp->prodring[0];
4946 u32 std_prod_idx = dpr->rx_std_prod_idx;
4947 u32 jmb_prod_idx = dpr->rx_jmb_prod_idx;
4949 for (i = 1; i < tp->irq_cnt; i++)
4950 err |= tg3_rx_prodring_xfer(tp, dpr,
4951 tp->napi[i].prodring);
4955 if (std_prod_idx != dpr->rx_std_prod_idx)
4956 tw32_rx_mbox(TG3_RX_STD_PROD_IDX_REG,
4957 dpr->rx_std_prod_idx);
4959 if (jmb_prod_idx != dpr->rx_jmb_prod_idx)
4960 tw32_rx_mbox(TG3_RX_JMB_PROD_IDX_REG,
4961 dpr->rx_jmb_prod_idx);
4966 tw32_f(HOSTCC_MODE, tp->coal_now);
4972 static int tg3_poll_msix(struct napi_struct *napi, int budget)
4974 struct tg3_napi *tnapi = container_of(napi, struct tg3_napi, napi);
4975 struct tg3 *tp = tnapi->tp;
4977 struct tg3_hw_status *sblk = tnapi->hw_status;
4980 work_done = tg3_poll_work(tnapi, work_done, budget);
4982 if (unlikely(tp->tg3_flags & TG3_FLAG_TX_RECOVERY_PENDING))
4985 if (unlikely(work_done >= budget))
4988 /* tp->last_tag is used in tg3_int_reenable() below
4989 * to tell the hw how much work has been processed,
4990 * so we must read it before checking for more work.
4992 tnapi->last_tag = sblk->status_tag;
4993 tnapi->last_irq_tag = tnapi->last_tag;
4996 /* check for RX/TX work to do */
4997 if (likely(sblk->idx[0].tx_consumer == tnapi->tx_cons &&
4998 *(tnapi->rx_rcb_prod_idx) == tnapi->rx_rcb_ptr)) {
4999 napi_complete(napi);
5000 /* Reenable interrupts. */
5001 tw32_mailbox(tnapi->int_mbox, tnapi->last_tag << 24);
5010 /* work_done is guaranteed to be less than budget. */
5011 napi_complete(napi);
5012 schedule_work(&tp->reset_task);
5016 static int tg3_poll(struct napi_struct *napi, int budget)
5018 struct tg3_napi *tnapi = container_of(napi, struct tg3_napi, napi);
5019 struct tg3 *tp = tnapi->tp;
5021 struct tg3_hw_status *sblk = tnapi->hw_status;
5026 work_done = tg3_poll_work(tnapi, work_done, budget);
5028 if (unlikely(tp->tg3_flags & TG3_FLAG_TX_RECOVERY_PENDING))
5031 if (unlikely(work_done >= budget))
5034 if (tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) {
5035 /* tp->last_tag is used in tg3_int_reenable() below
5036 * to tell the hw how much work has been processed,
5037 * so we must read it before checking for more work.
5039 tnapi->last_tag = sblk->status_tag;
5040 tnapi->last_irq_tag = tnapi->last_tag;
5043 sblk->status &= ~SD_STATUS_UPDATED;
5045 if (likely(!tg3_has_work(tnapi))) {
5046 napi_complete(napi);
5047 tg3_int_reenable(tnapi);
5055 /* work_done is guaranteed to be less than budget. */
5056 napi_complete(napi);
5057 schedule_work(&tp->reset_task);
5061 static void tg3_irq_quiesce(struct tg3 *tp)
5065 BUG_ON(tp->irq_sync);
5070 for (i = 0; i < tp->irq_cnt; i++)
5071 synchronize_irq(tp->napi[i].irq_vec);
5074 static inline int tg3_irq_sync(struct tg3 *tp)
5076 return tp->irq_sync;
5079 /* Fully shutdown all tg3 driver activity elsewhere in the system.
5080 * If irq_sync is non-zero, then the IRQ handler must be synchronized
5081 * with as well. Most of the time, this is not necessary except when
5082 * shutting down the device.
5084 static inline void tg3_full_lock(struct tg3 *tp, int irq_sync)
5086 spin_lock_bh(&tp->lock);
5088 tg3_irq_quiesce(tp);
5091 static inline void tg3_full_unlock(struct tg3 *tp)
5093 spin_unlock_bh(&tp->lock);
5096 /* One-shot MSI handler - Chip automatically disables interrupt
5097 * after sending MSI so driver doesn't have to do it.
5099 static irqreturn_t tg3_msi_1shot(int irq, void *dev_id)
5101 struct tg3_napi *tnapi = dev_id;
5102 struct tg3 *tp = tnapi->tp;
5104 prefetch(tnapi->hw_status);
5106 prefetch(&tnapi->rx_rcb[tnapi->rx_rcb_ptr]);
5108 if (likely(!tg3_irq_sync(tp)))
5109 napi_schedule(&tnapi->napi);
5114 /* MSI ISR - No need to check for interrupt sharing and no need to
5115 * flush status block and interrupt mailbox. PCI ordering rules
5116 * guarantee that MSI will arrive after the status block.
5118 static irqreturn_t tg3_msi(int irq, void *dev_id)
5120 struct tg3_napi *tnapi = dev_id;
5121 struct tg3 *tp = tnapi->tp;
5123 prefetch(tnapi->hw_status);
5125 prefetch(&tnapi->rx_rcb[tnapi->rx_rcb_ptr]);
5127 * Writing any value to intr-mbox-0 clears PCI INTA# and
5128 * chip-internal interrupt pending events.
5129 * Writing non-zero to intr-mbox-0 additional tells the
5130 * NIC to stop sending us irqs, engaging "in-intr-handler"
5133 tw32_mailbox(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001);
5134 if (likely(!tg3_irq_sync(tp)))
5135 napi_schedule(&tnapi->napi);
5137 return IRQ_RETVAL(1);
5140 static irqreturn_t tg3_interrupt(int irq, void *dev_id)
5142 struct tg3_napi *tnapi = dev_id;
5143 struct tg3 *tp = tnapi->tp;
5144 struct tg3_hw_status *sblk = tnapi->hw_status;
5145 unsigned int handled = 1;
5147 /* In INTx mode, it is possible for the interrupt to arrive at
5148 * the CPU before the status block posted prior to the interrupt.
5149 * Reading the PCI State register will confirm whether the
5150 * interrupt is ours and will flush the status block.
5152 if (unlikely(!(sblk->status & SD_STATUS_UPDATED))) {
5153 if ((tp->tg3_flags & TG3_FLAG_CHIP_RESETTING) ||
5154 (tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) {
5161 * Writing any value to intr-mbox-0 clears PCI INTA# and
5162 * chip-internal interrupt pending events.
5163 * Writing non-zero to intr-mbox-0 additional tells the
5164 * NIC to stop sending us irqs, engaging "in-intr-handler"
5167 * Flush the mailbox to de-assert the IRQ immediately to prevent
5168 * spurious interrupts. The flush impacts performance but
5169 * excessive spurious interrupts can be worse in some cases.
5171 tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001);
5172 if (tg3_irq_sync(tp))
5174 sblk->status &= ~SD_STATUS_UPDATED;
5175 if (likely(tg3_has_work(tnapi))) {
5176 prefetch(&tnapi->rx_rcb[tnapi->rx_rcb_ptr]);
5177 napi_schedule(&tnapi->napi);
5179 /* No work, shared interrupt perhaps? re-enable
5180 * interrupts, and flush that PCI write
5182 tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW,
5186 return IRQ_RETVAL(handled);
5189 static irqreturn_t tg3_interrupt_tagged(int irq, void *dev_id)
5191 struct tg3_napi *tnapi = dev_id;
5192 struct tg3 *tp = tnapi->tp;
5193 struct tg3_hw_status *sblk = tnapi->hw_status;
5194 unsigned int handled = 1;
5196 /* In INTx mode, it is possible for the interrupt to arrive at
5197 * the CPU before the status block posted prior to the interrupt.
5198 * Reading the PCI State register will confirm whether the
5199 * interrupt is ours and will flush the status block.
5201 if (unlikely(sblk->status_tag == tnapi->last_irq_tag)) {
5202 if ((tp->tg3_flags & TG3_FLAG_CHIP_RESETTING) ||
5203 (tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) {
5210 * writing any value to intr-mbox-0 clears PCI INTA# and
5211 * chip-internal interrupt pending events.
5212 * writing non-zero to intr-mbox-0 additional tells the
5213 * NIC to stop sending us irqs, engaging "in-intr-handler"
5216 * Flush the mailbox to de-assert the IRQ immediately to prevent
5217 * spurious interrupts. The flush impacts performance but
5218 * excessive spurious interrupts can be worse in some cases.
5220 tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001);
5223 * In a shared interrupt configuration, sometimes other devices'
5224 * interrupts will scream. We record the current status tag here
5225 * so that the above check can report that the screaming interrupts
5226 * are unhandled. Eventually they will be silenced.
5228 tnapi->last_irq_tag = sblk->status_tag;
5230 if (tg3_irq_sync(tp))
5233 prefetch(&tnapi->rx_rcb[tnapi->rx_rcb_ptr]);
5235 napi_schedule(&tnapi->napi);
5238 return IRQ_RETVAL(handled);
5241 /* ISR for interrupt test */
5242 static irqreturn_t tg3_test_isr(int irq, void *dev_id)
5244 struct tg3_napi *tnapi = dev_id;
5245 struct tg3 *tp = tnapi->tp;
5246 struct tg3_hw_status *sblk = tnapi->hw_status;
5248 if ((sblk->status & SD_STATUS_UPDATED) ||
5249 !(tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) {
5250 tg3_disable_ints(tp);
5251 return IRQ_RETVAL(1);
5253 return IRQ_RETVAL(0);
5256 static int tg3_init_hw(struct tg3 *, int);
5257 static int tg3_halt(struct tg3 *, int, int);
5259 /* Restart hardware after configuration changes, self-test, etc.
5260 * Invoked with tp->lock held.
5262 static int tg3_restart_hw(struct tg3 *tp, int reset_phy)
5263 __releases(tp->lock)
5264 __acquires(tp->lock)
5268 err = tg3_init_hw(tp, reset_phy);
5271 "Failed to re-initialize device, aborting\n");
5272 tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
5273 tg3_full_unlock(tp);
5274 del_timer_sync(&tp->timer);
5276 tg3_napi_enable(tp);
5278 tg3_full_lock(tp, 0);
5283 #ifdef CONFIG_NET_POLL_CONTROLLER
5284 static void tg3_poll_controller(struct net_device *dev)
5287 struct tg3 *tp = netdev_priv(dev);
5289 for (i = 0; i < tp->irq_cnt; i++)
5290 tg3_interrupt(tp->napi[i].irq_vec, &tp->napi[i]);
5294 static void tg3_reset_task(struct work_struct *work)
5296 struct tg3 *tp = container_of(work, struct tg3, reset_task);
5298 unsigned int restart_timer;
5300 tg3_full_lock(tp, 0);
5302 if (!netif_running(tp->dev)) {
5303 tg3_full_unlock(tp);
5307 tg3_full_unlock(tp);
5313 tg3_full_lock(tp, 1);
5315 restart_timer = tp->tg3_flags2 & TG3_FLG2_RESTART_TIMER;
5316 tp->tg3_flags2 &= ~TG3_FLG2_RESTART_TIMER;
5318 if (tp->tg3_flags & TG3_FLAG_TX_RECOVERY_PENDING) {
5319 tp->write32_tx_mbox = tg3_write32_tx_mbox;
5320 tp->write32_rx_mbox = tg3_write_flush_reg32;
5321 tp->tg3_flags |= TG3_FLAG_MBOX_WRITE_REORDER;
5322 tp->tg3_flags &= ~TG3_FLAG_TX_RECOVERY_PENDING;
5325 tg3_halt(tp, RESET_KIND_SHUTDOWN, 0);
5326 err = tg3_init_hw(tp, 1);
5330 tg3_netif_start(tp);
5333 mod_timer(&tp->timer, jiffies + 1);
5336 tg3_full_unlock(tp);
5342 static void tg3_dump_short_state(struct tg3 *tp)
5344 netdev_err(tp->dev, "DEBUG: MAC_TX_STATUS[%08x] MAC_RX_STATUS[%08x]\n",
5345 tr32(MAC_TX_STATUS), tr32(MAC_RX_STATUS));
5346 netdev_err(tp->dev, "DEBUG: RDMAC_STATUS[%08x] WDMAC_STATUS[%08x]\n",
5347 tr32(RDMAC_STATUS), tr32(WDMAC_STATUS));
5350 static void tg3_tx_timeout(struct net_device *dev)
5352 struct tg3 *tp = netdev_priv(dev);
5354 if (netif_msg_tx_err(tp)) {
5355 netdev_err(dev, "transmit timed out, resetting\n");
5356 tg3_dump_short_state(tp);
5359 schedule_work(&tp->reset_task);
5362 /* Test for DMA buffers crossing any 4GB boundaries: 4G, 8G, etc */
5363 static inline int tg3_4g_overflow_test(dma_addr_t mapping, int len)
5365 u32 base = (u32) mapping & 0xffffffff;
5367 return ((base > 0xffffdcc0) &&
5368 (base + len + 8 < base));
5371 /* Test for DMA addresses > 40-bit */
5372 static inline int tg3_40bit_overflow_test(struct tg3 *tp, dma_addr_t mapping,
5375 #if defined(CONFIG_HIGHMEM) && (BITS_PER_LONG == 64)
5376 if (tp->tg3_flags & TG3_FLAG_40BIT_DMA_BUG)
5377 return (((u64) mapping + len) > DMA_BIT_MASK(40));
5384 static void tg3_set_txd(struct tg3_napi *, int, dma_addr_t, int, u32, u32);
5386 /* Workaround 4GB and 40-bit hardware DMA bugs. */
5387 static int tigon3_dma_hwbug_workaround(struct tg3_napi *tnapi,
5388 struct sk_buff *skb, u32 last_plus_one,
5389 u32 *start, u32 base_flags, u32 mss)
5391 struct tg3 *tp = tnapi->tp;
5392 struct sk_buff *new_skb;
5393 dma_addr_t new_addr = 0;
5397 if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701)
5398 new_skb = skb_copy(skb, GFP_ATOMIC);
5400 int more_headroom = 4 - ((unsigned long)skb->data & 3);
5402 new_skb = skb_copy_expand(skb,
5403 skb_headroom(skb) + more_headroom,
5404 skb_tailroom(skb), GFP_ATOMIC);
5410 /* New SKB is guaranteed to be linear. */
5412 new_addr = pci_map_single(tp->pdev, new_skb->data, new_skb->len,
5414 /* Make sure the mapping succeeded */
5415 if (pci_dma_mapping_error(tp->pdev, new_addr)) {
5417 dev_kfree_skb(new_skb);
5420 /* Make sure new skb does not cross any 4G boundaries.
5421 * Drop the packet if it does.
5423 } else if ((tp->tg3_flags3 & TG3_FLG3_4G_DMA_BNDRY_BUG) &&
5424 tg3_4g_overflow_test(new_addr, new_skb->len)) {
5425 pci_unmap_single(tp->pdev, new_addr, new_skb->len,
5428 dev_kfree_skb(new_skb);
5431 tg3_set_txd(tnapi, entry, new_addr, new_skb->len,
5432 base_flags, 1 | (mss << 1));
5433 *start = NEXT_TX(entry);
5437 /* Now clean up the sw ring entries. */
5439 while (entry != last_plus_one) {
5443 len = skb_headlen(skb);
5445 len = skb_shinfo(skb)->frags[i-1].size;
5447 pci_unmap_single(tp->pdev,
5448 pci_unmap_addr(&tnapi->tx_buffers[entry],
5450 len, PCI_DMA_TODEVICE);
5452 tnapi->tx_buffers[entry].skb = new_skb;
5453 pci_unmap_addr_set(&tnapi->tx_buffers[entry], mapping,
5456 tnapi->tx_buffers[entry].skb = NULL;
5458 entry = NEXT_TX(entry);
5467 static void tg3_set_txd(struct tg3_napi *tnapi, int entry,
5468 dma_addr_t mapping, int len, u32 flags,
5471 struct tg3_tx_buffer_desc *txd = &tnapi->tx_ring[entry];
5472 int is_end = (mss_and_is_end & 0x1);
5473 u32 mss = (mss_and_is_end >> 1);
5477 flags |= TXD_FLAG_END;
5478 if (flags & TXD_FLAG_VLAN) {
5479 vlan_tag = flags >> 16;
5482 vlan_tag |= (mss << TXD_MSS_SHIFT);
5484 txd->addr_hi = ((u64) mapping >> 32);
5485 txd->addr_lo = ((u64) mapping & 0xffffffff);
5486 txd->len_flags = (len << TXD_LEN_SHIFT) | flags;
5487 txd->vlan_tag = vlan_tag << TXD_VLAN_TAG_SHIFT;
5490 /* hard_start_xmit for devices that don't have any bugs and
5491 * support TG3_FLG2_HW_TSO_2 and TG3_FLG2_HW_TSO_3 only.
5493 static netdev_tx_t tg3_start_xmit(struct sk_buff *skb,
5494 struct net_device *dev)
5496 struct tg3 *tp = netdev_priv(dev);
5497 u32 len, entry, base_flags, mss;
5499 struct tg3_napi *tnapi;
5500 struct netdev_queue *txq;
5501 unsigned int i, last;
5503 txq = netdev_get_tx_queue(dev, skb_get_queue_mapping(skb));
5504 tnapi = &tp->napi[skb_get_queue_mapping(skb)];
5505 if (tp->tg3_flags3 & TG3_FLG3_ENABLE_TSS)
5508 /* We are running in BH disabled context with netif_tx_lock
5509 * and TX reclaim runs via tp->napi.poll inside of a software
5510 * interrupt. Furthermore, IRQ processing runs lockless so we have
5511 * no IRQ context deadlocks to worry about either. Rejoice!
5513 if (unlikely(tg3_tx_avail(tnapi) <= (skb_shinfo(skb)->nr_frags + 1))) {
5514 if (!netif_tx_queue_stopped(txq)) {
5515 netif_tx_stop_queue(txq);
5517 /* This is a hard error, log it. */
5519 "BUG! Tx Ring full when queue awake!\n");
5521 return NETDEV_TX_BUSY;
5524 entry = tnapi->tx_prod;
5527 if ((mss = skb_shinfo(skb)->gso_size) != 0) {
5528 int tcp_opt_len, ip_tcp_len;
5531 if (skb_header_cloned(skb) &&
5532 pskb_expand_head(skb, 0, 0, GFP_ATOMIC)) {
5537 if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6)
5538 hdrlen = skb_headlen(skb) - ETH_HLEN;
5540 struct iphdr *iph = ip_hdr(skb);
5542 tcp_opt_len = tcp_optlen(skb);
5543 ip_tcp_len = ip_hdrlen(skb) + sizeof(struct tcphdr);
5546 iph->tot_len = htons(mss + ip_tcp_len + tcp_opt_len);
5547 hdrlen = ip_tcp_len + tcp_opt_len;
5550 if (tp->tg3_flags2 & TG3_FLG2_HW_TSO_3) {
5551 mss |= (hdrlen & 0xc) << 12;
5553 base_flags |= 0x00000010;
5554 base_flags |= (hdrlen & 0x3e0) << 5;
5558 base_flags |= (TXD_FLAG_CPU_PRE_DMA |
5559 TXD_FLAG_CPU_POST_DMA);
5561 tcp_hdr(skb)->check = 0;
5564 else if (skb->ip_summed == CHECKSUM_PARTIAL)
5565 base_flags |= TXD_FLAG_TCPUDP_CSUM;
5566 #if TG3_VLAN_TAG_USED
5567 if (tp->vlgrp != NULL && vlan_tx_tag_present(skb))
5568 base_flags |= (TXD_FLAG_VLAN |
5569 (vlan_tx_tag_get(skb) << 16));
5572 len = skb_headlen(skb);
5574 /* Queue skb data, a.k.a. the main skb fragment. */
5575 mapping = pci_map_single(tp->pdev, skb->data, len, PCI_DMA_TODEVICE);
5576 if (pci_dma_mapping_error(tp->pdev, mapping)) {
5581 tnapi->tx_buffers[entry].skb = skb;
5582 pci_unmap_addr_set(&tnapi->tx_buffers[entry], mapping, mapping);
5584 if ((tp->tg3_flags3 & TG3_FLG3_USE_JUMBO_BDFLAG) &&
5585 !mss && skb->len > ETH_DATA_LEN)
5586 base_flags |= TXD_FLAG_JMB_PKT;
5588 tg3_set_txd(tnapi, entry, mapping, len, base_flags,
5589 (skb_shinfo(skb)->nr_frags == 0) | (mss << 1));
5591 entry = NEXT_TX(entry);
5593 /* Now loop through additional data fragments, and queue them. */
5594 if (skb_shinfo(skb)->nr_frags > 0) {
5595 last = skb_shinfo(skb)->nr_frags - 1;
5596 for (i = 0; i <= last; i++) {
5597 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
5600 mapping = pci_map_page(tp->pdev,
5603 len, PCI_DMA_TODEVICE);
5604 if (pci_dma_mapping_error(tp->pdev, mapping))
5607 tnapi->tx_buffers[entry].skb = NULL;
5608 pci_unmap_addr_set(&tnapi->tx_buffers[entry], mapping,
5611 tg3_set_txd(tnapi, entry, mapping, len,
5612 base_flags, (i == last) | (mss << 1));
5614 entry = NEXT_TX(entry);
5618 /* Packets are ready, update Tx producer idx local and on card. */
5619 tw32_tx_mbox(tnapi->prodmbox, entry);
5621 tnapi->tx_prod = entry;
5622 if (unlikely(tg3_tx_avail(tnapi) <= (MAX_SKB_FRAGS + 1))) {
5623 netif_tx_stop_queue(txq);
5624 if (tg3_tx_avail(tnapi) > TG3_TX_WAKEUP_THRESH(tnapi))
5625 netif_tx_wake_queue(txq);
5631 return NETDEV_TX_OK;
5635 entry = tnapi->tx_prod;
5636 tnapi->tx_buffers[entry].skb = NULL;
5637 pci_unmap_single(tp->pdev,
5638 pci_unmap_addr(&tnapi->tx_buffers[entry], mapping),
5641 for (i = 0; i <= last; i++) {
5642 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
5643 entry = NEXT_TX(entry);
5645 pci_unmap_page(tp->pdev,
5646 pci_unmap_addr(&tnapi->tx_buffers[entry],
5648 frag->size, PCI_DMA_TODEVICE);
5652 return NETDEV_TX_OK;
5655 static netdev_tx_t tg3_start_xmit_dma_bug(struct sk_buff *,
5656 struct net_device *);
5658 /* Use GSO to workaround a rare TSO bug that may be triggered when the
5659 * TSO header is greater than 80 bytes.
5661 static int tg3_tso_bug(struct tg3 *tp, struct sk_buff *skb)
5663 struct sk_buff *segs, *nskb;
5664 u32 frag_cnt_est = skb_shinfo(skb)->gso_segs * 3;
5666 /* Estimate the number of fragments in the worst case */
5667 if (unlikely(tg3_tx_avail(&tp->napi[0]) <= frag_cnt_est)) {
5668 netif_stop_queue(tp->dev);
5669 if (tg3_tx_avail(&tp->napi[0]) <= frag_cnt_est)
5670 return NETDEV_TX_BUSY;
5672 netif_wake_queue(tp->dev);
5675 segs = skb_gso_segment(skb, tp->dev->features & ~NETIF_F_TSO);
5677 goto tg3_tso_bug_end;
5683 tg3_start_xmit_dma_bug(nskb, tp->dev);
5689 return NETDEV_TX_OK;
5692 /* hard_start_xmit for devices that have the 4G bug and/or 40-bit bug and
5693 * support TG3_FLG2_HW_TSO_1 or firmware TSO only.
5695 static netdev_tx_t tg3_start_xmit_dma_bug(struct sk_buff *skb,
5696 struct net_device *dev)
5698 struct tg3 *tp = netdev_priv(dev);
5699 u32 len, entry, base_flags, mss;
5700 int would_hit_hwbug;
5702 struct tg3_napi *tnapi;
5703 struct netdev_queue *txq;
5704 unsigned int i, last;
5706 txq = netdev_get_tx_queue(dev, skb_get_queue_mapping(skb));
5707 tnapi = &tp->napi[skb_get_queue_mapping(skb)];
5708 if (tp->tg3_flags3 & TG3_FLG3_ENABLE_TSS)
5711 /* We are running in BH disabled context with netif_tx_lock
5712 * and TX reclaim runs via tp->napi.poll inside of a software
5713 * interrupt. Furthermore, IRQ processing runs lockless so we have
5714 * no IRQ context deadlocks to worry about either. Rejoice!
5716 if (unlikely(tg3_tx_avail(tnapi) <= (skb_shinfo(skb)->nr_frags + 1))) {
5717 if (!netif_tx_queue_stopped(txq)) {
5718 netif_tx_stop_queue(txq);
5720 /* This is a hard error, log it. */
5722 "BUG! Tx Ring full when queue awake!\n");
5724 return NETDEV_TX_BUSY;
5727 entry = tnapi->tx_prod;
5729 if (skb->ip_summed == CHECKSUM_PARTIAL)
5730 base_flags |= TXD_FLAG_TCPUDP_CSUM;
5732 if ((mss = skb_shinfo(skb)->gso_size) != 0) {
5734 u32 tcp_opt_len, ip_tcp_len, hdr_len;
5736 if (skb_header_cloned(skb) &&
5737 pskb_expand_head(skb, 0, 0, GFP_ATOMIC)) {
5742 tcp_opt_len = tcp_optlen(skb);
5743 ip_tcp_len = ip_hdrlen(skb) + sizeof(struct tcphdr);
5745 hdr_len = ip_tcp_len + tcp_opt_len;
5746 if (unlikely((ETH_HLEN + hdr_len) > 80) &&
5747 (tp->tg3_flags2 & TG3_FLG2_TSO_BUG))
5748 return (tg3_tso_bug(tp, skb));
5750 base_flags |= (TXD_FLAG_CPU_PRE_DMA |
5751 TXD_FLAG_CPU_POST_DMA);
5755 iph->tot_len = htons(mss + hdr_len);
5756 if (tp->tg3_flags2 & TG3_FLG2_HW_TSO) {
5757 tcp_hdr(skb)->check = 0;
5758 base_flags &= ~TXD_FLAG_TCPUDP_CSUM;
5760 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
5765 if (tp->tg3_flags2 & TG3_FLG2_HW_TSO_3) {
5766 mss |= (hdr_len & 0xc) << 12;
5768 base_flags |= 0x00000010;
5769 base_flags |= (hdr_len & 0x3e0) << 5;
5770 } else if (tp->tg3_flags2 & TG3_FLG2_HW_TSO_2)
5771 mss |= hdr_len << 9;
5772 else if ((tp->tg3_flags2 & TG3_FLG2_HW_TSO_1) ||
5773 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) {
5774 if (tcp_opt_len || iph->ihl > 5) {
5777 tsflags = (iph->ihl - 5) + (tcp_opt_len >> 2);
5778 mss |= (tsflags << 11);
5781 if (tcp_opt_len || iph->ihl > 5) {
5784 tsflags = (iph->ihl - 5) + (tcp_opt_len >> 2);
5785 base_flags |= tsflags << 12;
5789 #if TG3_VLAN_TAG_USED
5790 if (tp->vlgrp != NULL && vlan_tx_tag_present(skb))
5791 base_flags |= (TXD_FLAG_VLAN |
5792 (vlan_tx_tag_get(skb) << 16));
5795 if ((tp->tg3_flags3 & TG3_FLG3_USE_JUMBO_BDFLAG) &&
5796 !mss && skb->len > ETH_DATA_LEN)
5797 base_flags |= TXD_FLAG_JMB_PKT;
5799 len = skb_headlen(skb);
5801 mapping = pci_map_single(tp->pdev, skb->data, len, PCI_DMA_TODEVICE);
5802 if (pci_dma_mapping_error(tp->pdev, mapping)) {
5807 tnapi->tx_buffers[entry].skb = skb;
5808 pci_unmap_addr_set(&tnapi->tx_buffers[entry], mapping, mapping);
5810 would_hit_hwbug = 0;
5812 if ((tp->tg3_flags3 & TG3_FLG3_SHORT_DMA_BUG) && len <= 8)
5813 would_hit_hwbug = 1;
5815 if ((tp->tg3_flags3 & TG3_FLG3_4G_DMA_BNDRY_BUG) &&
5816 tg3_4g_overflow_test(mapping, len))
5817 would_hit_hwbug = 1;
5819 if ((tp->tg3_flags3 & TG3_FLG3_40BIT_DMA_LIMIT_BUG) &&
5820 tg3_40bit_overflow_test(tp, mapping, len))
5821 would_hit_hwbug = 1;
5823 if (tp->tg3_flags3 & TG3_FLG3_5701_DMA_BUG)
5824 would_hit_hwbug = 1;
5826 tg3_set_txd(tnapi, entry, mapping, len, base_flags,
5827 (skb_shinfo(skb)->nr_frags == 0) | (mss << 1));
5829 entry = NEXT_TX(entry);
5831 /* Now loop through additional data fragments, and queue them. */
5832 if (skb_shinfo(skb)->nr_frags > 0) {
5833 last = skb_shinfo(skb)->nr_frags - 1;
5834 for (i = 0; i <= last; i++) {
5835 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
5838 mapping = pci_map_page(tp->pdev,
5841 len, PCI_DMA_TODEVICE);
5843 tnapi->tx_buffers[entry].skb = NULL;
5844 pci_unmap_addr_set(&tnapi->tx_buffers[entry], mapping,
5846 if (pci_dma_mapping_error(tp->pdev, mapping))
5849 if ((tp->tg3_flags3 & TG3_FLG3_SHORT_DMA_BUG) &&
5851 would_hit_hwbug = 1;
5853 if ((tp->tg3_flags3 & TG3_FLG3_4G_DMA_BNDRY_BUG) &&
5854 tg3_4g_overflow_test(mapping, len))
5855 would_hit_hwbug = 1;
5857 if ((tp->tg3_flags3 & TG3_FLG3_40BIT_DMA_LIMIT_BUG) &&
5858 tg3_40bit_overflow_test(tp, mapping, len))
5859 would_hit_hwbug = 1;
5861 if (tp->tg3_flags2 & TG3_FLG2_HW_TSO)
5862 tg3_set_txd(tnapi, entry, mapping, len,
5863 base_flags, (i == last)|(mss << 1));
5865 tg3_set_txd(tnapi, entry, mapping, len,
5866 base_flags, (i == last));
5868 entry = NEXT_TX(entry);
5872 if (would_hit_hwbug) {
5873 u32 last_plus_one = entry;
5876 start = entry - 1 - skb_shinfo(skb)->nr_frags;
5877 start &= (TG3_TX_RING_SIZE - 1);
5879 /* If the workaround fails due to memory/mapping
5880 * failure, silently drop this packet.
5882 if (tigon3_dma_hwbug_workaround(tnapi, skb, last_plus_one,
5883 &start, base_flags, mss))
5889 /* Packets are ready, update Tx producer idx local and on card. */
5890 tw32_tx_mbox(tnapi->prodmbox, entry);
5892 tnapi->tx_prod = entry;
5893 if (unlikely(tg3_tx_avail(tnapi) <= (MAX_SKB_FRAGS + 1))) {
5894 netif_tx_stop_queue(txq);
5895 if (tg3_tx_avail(tnapi) > TG3_TX_WAKEUP_THRESH(tnapi))
5896 netif_tx_wake_queue(txq);
5902 return NETDEV_TX_OK;
5906 entry = tnapi->tx_prod;
5907 tnapi->tx_buffers[entry].skb = NULL;
5908 pci_unmap_single(tp->pdev,
5909 pci_unmap_addr(&tnapi->tx_buffers[entry], mapping),
5912 for (i = 0; i <= last; i++) {
5913 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
5914 entry = NEXT_TX(entry);
5916 pci_unmap_page(tp->pdev,
5917 pci_unmap_addr(&tnapi->tx_buffers[entry],
5919 frag->size, PCI_DMA_TODEVICE);
5923 return NETDEV_TX_OK;
5926 static inline void tg3_set_mtu(struct net_device *dev, struct tg3 *tp,
5931 if (new_mtu > ETH_DATA_LEN) {
5932 if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS) {
5933 tp->tg3_flags2 &= ~TG3_FLG2_TSO_CAPABLE;
5934 ethtool_op_set_tso(dev, 0);
5937 tp->tg3_flags |= TG3_FLAG_JUMBO_RING_ENABLE;
5939 if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)
5940 tp->tg3_flags2 |= TG3_FLG2_TSO_CAPABLE;
5941 tp->tg3_flags &= ~TG3_FLAG_JUMBO_RING_ENABLE;
5945 static int tg3_change_mtu(struct net_device *dev, int new_mtu)
5947 struct tg3 *tp = netdev_priv(dev);
5950 if (new_mtu < TG3_MIN_MTU || new_mtu > TG3_MAX_MTU(tp))
5953 if (!netif_running(dev)) {
5954 /* We'll just catch it later when the
5957 tg3_set_mtu(dev, tp, new_mtu);
5965 tg3_full_lock(tp, 1);
5967 tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
5969 tg3_set_mtu(dev, tp, new_mtu);
5971 err = tg3_restart_hw(tp, 0);
5974 tg3_netif_start(tp);
5976 tg3_full_unlock(tp);
5984 static void tg3_rx_prodring_free(struct tg3 *tp,
5985 struct tg3_rx_prodring_set *tpr)
5989 if (tpr != &tp->prodring[0]) {
5990 for (i = tpr->rx_std_cons_idx; i != tpr->rx_std_prod_idx;
5991 i = (i + 1) % TG3_RX_RING_SIZE)
5992 tg3_rx_skb_free(tp, &tpr->rx_std_buffers[i],
5995 if (tp->tg3_flags & TG3_FLAG_JUMBO_CAPABLE) {
5996 for (i = tpr->rx_jmb_cons_idx;
5997 i != tpr->rx_jmb_prod_idx;
5998 i = (i + 1) % TG3_RX_JUMBO_RING_SIZE) {
5999 tg3_rx_skb_free(tp, &tpr->rx_jmb_buffers[i],
6007 for (i = 0; i < TG3_RX_RING_SIZE; i++)
6008 tg3_rx_skb_free(tp, &tpr->rx_std_buffers[i],
6011 if (tp->tg3_flags & TG3_FLAG_JUMBO_CAPABLE) {
6012 for (i = 0; i < TG3_RX_JUMBO_RING_SIZE; i++)
6013 tg3_rx_skb_free(tp, &tpr->rx_jmb_buffers[i],
6018 /* Initialize rx rings for packet processing.
6020 * The chip has been shut down and the driver detached from
6021 * the networking, so no interrupts or new tx packets will
6022 * end up in the driver. tp->{tx,}lock are held and thus
6025 static int tg3_rx_prodring_alloc(struct tg3 *tp,
6026 struct tg3_rx_prodring_set *tpr)
6028 u32 i, rx_pkt_dma_sz;
6030 tpr->rx_std_cons_idx = 0;
6031 tpr->rx_std_prod_idx = 0;
6032 tpr->rx_jmb_cons_idx = 0;
6033 tpr->rx_jmb_prod_idx = 0;
6035 if (tpr != &tp->prodring[0]) {
6036 memset(&tpr->rx_std_buffers[0], 0, TG3_RX_STD_BUFF_RING_SIZE);
6037 if (tp->tg3_flags & TG3_FLAG_JUMBO_CAPABLE)
6038 memset(&tpr->rx_jmb_buffers[0], 0,
6039 TG3_RX_JMB_BUFF_RING_SIZE);
6043 /* Zero out all descriptors. */
6044 memset(tpr->rx_std, 0, TG3_RX_RING_BYTES);
6046 rx_pkt_dma_sz = TG3_RX_STD_DMA_SZ;
6047 if ((tp->tg3_flags2 & TG3_FLG2_5780_CLASS) &&
6048 tp->dev->mtu > ETH_DATA_LEN)
6049 rx_pkt_dma_sz = TG3_RX_JMB_DMA_SZ;
6050 tp->rx_pkt_map_sz = TG3_RX_DMA_TO_MAP_SZ(rx_pkt_dma_sz);
6052 /* Initialize invariants of the rings, we only set this
6053 * stuff once. This works because the card does not
6054 * write into the rx buffer posting rings.
6056 for (i = 0; i < TG3_RX_RING_SIZE; i++) {
6057 struct tg3_rx_buffer_desc *rxd;
6059 rxd = &tpr->rx_std[i];
6060 rxd->idx_len = rx_pkt_dma_sz << RXD_LEN_SHIFT;
6061 rxd->type_flags = (RXD_FLAG_END << RXD_FLAGS_SHIFT);
6062 rxd->opaque = (RXD_OPAQUE_RING_STD |
6063 (i << RXD_OPAQUE_INDEX_SHIFT));
6066 /* Now allocate fresh SKBs for each rx ring. */
6067 for (i = 0; i < tp->rx_pending; i++) {
6068 if (tg3_alloc_rx_skb(tp, tpr, RXD_OPAQUE_RING_STD, i) < 0) {
6069 netdev_warn(tp->dev,
6070 "Using a smaller RX standard ring. Only "
6071 "%d out of %d buffers were allocated "
6072 "successfully\n", i, tp->rx_pending);
6080 if (!(tp->tg3_flags & TG3_FLAG_JUMBO_CAPABLE))
6083 memset(tpr->rx_jmb, 0, TG3_RX_JUMBO_RING_BYTES);
6085 if (!(tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE))
6088 for (i = 0; i < TG3_RX_JUMBO_RING_SIZE; i++) {
6089 struct tg3_rx_buffer_desc *rxd;
6091 rxd = &tpr->rx_jmb[i].std;
6092 rxd->idx_len = TG3_RX_JMB_DMA_SZ << RXD_LEN_SHIFT;
6093 rxd->type_flags = (RXD_FLAG_END << RXD_FLAGS_SHIFT) |
6095 rxd->opaque = (RXD_OPAQUE_RING_JUMBO |
6096 (i << RXD_OPAQUE_INDEX_SHIFT));
6099 for (i = 0; i < tp->rx_jumbo_pending; i++) {
6100 if (tg3_alloc_rx_skb(tp, tpr, RXD_OPAQUE_RING_JUMBO, i) < 0) {
6101 netdev_warn(tp->dev,
6102 "Using a smaller RX jumbo ring. Only %d "
6103 "out of %d buffers were allocated "
6104 "successfully\n", i, tp->rx_jumbo_pending);
6107 tp->rx_jumbo_pending = i;
6116 tg3_rx_prodring_free(tp, tpr);
6120 static void tg3_rx_prodring_fini(struct tg3 *tp,
6121 struct tg3_rx_prodring_set *tpr)
6123 kfree(tpr->rx_std_buffers);
6124 tpr->rx_std_buffers = NULL;
6125 kfree(tpr->rx_jmb_buffers);
6126 tpr->rx_jmb_buffers = NULL;
6128 pci_free_consistent(tp->pdev, TG3_RX_RING_BYTES,
6129 tpr->rx_std, tpr->rx_std_mapping);
6133 pci_free_consistent(tp->pdev, TG3_RX_JUMBO_RING_BYTES,
6134 tpr->rx_jmb, tpr->rx_jmb_mapping);
6139 static int tg3_rx_prodring_init(struct tg3 *tp,
6140 struct tg3_rx_prodring_set *tpr)
6142 tpr->rx_std_buffers = kzalloc(TG3_RX_STD_BUFF_RING_SIZE, GFP_KERNEL);
6143 if (!tpr->rx_std_buffers)
6146 tpr->rx_std = pci_alloc_consistent(tp->pdev, TG3_RX_RING_BYTES,
6147 &tpr->rx_std_mapping);
6151 if (tp->tg3_flags & TG3_FLAG_JUMBO_CAPABLE) {
6152 tpr->rx_jmb_buffers = kzalloc(TG3_RX_JMB_BUFF_RING_SIZE,
6154 if (!tpr->rx_jmb_buffers)
6157 tpr->rx_jmb = pci_alloc_consistent(tp->pdev,
6158 TG3_RX_JUMBO_RING_BYTES,
6159 &tpr->rx_jmb_mapping);
6167 tg3_rx_prodring_fini(tp, tpr);
6171 /* Free up pending packets in all rx/tx rings.
6173 * The chip has been shut down and the driver detached from
6174 * the networking, so no interrupts or new tx packets will
6175 * end up in the driver. tp->{tx,}lock is not held and we are not
6176 * in an interrupt context and thus may sleep.
6178 static void tg3_free_rings(struct tg3 *tp)
6182 for (j = 0; j < tp->irq_cnt; j++) {
6183 struct tg3_napi *tnapi = &tp->napi[j];
6185 if (!tnapi->tx_buffers)
6188 for (i = 0; i < TG3_TX_RING_SIZE; ) {
6189 struct ring_info *txp;
6190 struct sk_buff *skb;
6193 txp = &tnapi->tx_buffers[i];
6201 pci_unmap_single(tp->pdev,
6202 pci_unmap_addr(txp, mapping),
6209 for (k = 0; k < skb_shinfo(skb)->nr_frags; k++) {
6210 txp = &tnapi->tx_buffers[i & (TG3_TX_RING_SIZE - 1)];
6211 pci_unmap_page(tp->pdev,
6212 pci_unmap_addr(txp, mapping),
6213 skb_shinfo(skb)->frags[k].size,
6218 dev_kfree_skb_any(skb);
6221 tg3_rx_prodring_free(tp, &tp->prodring[j]);
6225 /* Initialize tx/rx rings for packet processing.
6227 * The chip has been shut down and the driver detached from
6228 * the networking, so no interrupts or new tx packets will
6229 * end up in the driver. tp->{tx,}lock are held and thus
6232 static int tg3_init_rings(struct tg3 *tp)
6236 /* Free up all the SKBs. */
6239 for (i = 0; i < tp->irq_cnt; i++) {
6240 struct tg3_napi *tnapi = &tp->napi[i];
6242 tnapi->last_tag = 0;
6243 tnapi->last_irq_tag = 0;
6244 tnapi->hw_status->status = 0;
6245 tnapi->hw_status->status_tag = 0;
6246 memset(tnapi->hw_status, 0, TG3_HW_STATUS_SIZE);
6251 memset(tnapi->tx_ring, 0, TG3_TX_RING_BYTES);
6253 tnapi->rx_rcb_ptr = 0;
6255 memset(tnapi->rx_rcb, 0, TG3_RX_RCB_RING_BYTES(tp));
6257 if (tg3_rx_prodring_alloc(tp, &tp->prodring[i])) {
6267 * Must not be invoked with interrupt sources disabled and
6268 * the hardware shutdown down.
6270 static void tg3_free_consistent(struct tg3 *tp)
6274 for (i = 0; i < tp->irq_cnt; i++) {
6275 struct tg3_napi *tnapi = &tp->napi[i];
6277 if (tnapi->tx_ring) {
6278 pci_free_consistent(tp->pdev, TG3_TX_RING_BYTES,
6279 tnapi->tx_ring, tnapi->tx_desc_mapping);
6280 tnapi->tx_ring = NULL;
6283 kfree(tnapi->tx_buffers);
6284 tnapi->tx_buffers = NULL;
6286 if (tnapi->rx_rcb) {
6287 pci_free_consistent(tp->pdev, TG3_RX_RCB_RING_BYTES(tp),
6289 tnapi->rx_rcb_mapping);
6290 tnapi->rx_rcb = NULL;
6293 if (tnapi->hw_status) {
6294 pci_free_consistent(tp->pdev, TG3_HW_STATUS_SIZE,
6296 tnapi->status_mapping);
6297 tnapi->hw_status = NULL;
6302 pci_free_consistent(tp->pdev, sizeof(struct tg3_hw_stats),
6303 tp->hw_stats, tp->stats_mapping);
6304 tp->hw_stats = NULL;
6307 for (i = 0; i < tp->irq_cnt; i++)
6308 tg3_rx_prodring_fini(tp, &tp->prodring[i]);
6312 * Must not be invoked with interrupt sources disabled and
6313 * the hardware shutdown down. Can sleep.
6315 static int tg3_alloc_consistent(struct tg3 *tp)
6319 for (i = 0; i < tp->irq_cnt; i++) {
6320 if (tg3_rx_prodring_init(tp, &tp->prodring[i]))
6324 tp->hw_stats = pci_alloc_consistent(tp->pdev,
6325 sizeof(struct tg3_hw_stats),
6326 &tp->stats_mapping);
6330 memset(tp->hw_stats, 0, sizeof(struct tg3_hw_stats));
6332 for (i = 0; i < tp->irq_cnt; i++) {
6333 struct tg3_napi *tnapi = &tp->napi[i];
6334 struct tg3_hw_status *sblk;
6336 tnapi->hw_status = pci_alloc_consistent(tp->pdev,
6338 &tnapi->status_mapping);
6339 if (!tnapi->hw_status)
6342 memset(tnapi->hw_status, 0, TG3_HW_STATUS_SIZE);
6343 sblk = tnapi->hw_status;
6345 /* If multivector TSS is enabled, vector 0 does not handle
6346 * tx interrupts. Don't allocate any resources for it.
6348 if ((!i && !(tp->tg3_flags3 & TG3_FLG3_ENABLE_TSS)) ||
6349 (i && (tp->tg3_flags3 & TG3_FLG3_ENABLE_TSS))) {
6350 tnapi->tx_buffers = kzalloc(sizeof(struct ring_info) *
6353 if (!tnapi->tx_buffers)
6356 tnapi->tx_ring = pci_alloc_consistent(tp->pdev,
6358 &tnapi->tx_desc_mapping);
6359 if (!tnapi->tx_ring)
6364 * When RSS is enabled, the status block format changes
6365 * slightly. The "rx_jumbo_consumer", "reserved",
6366 * and "rx_mini_consumer" members get mapped to the
6367 * other three rx return ring producer indexes.
6371 tnapi->rx_rcb_prod_idx = &sblk->idx[0].rx_producer;
6374 tnapi->rx_rcb_prod_idx = &sblk->rx_jumbo_consumer;
6377 tnapi->rx_rcb_prod_idx = &sblk->reserved;
6380 tnapi->rx_rcb_prod_idx = &sblk->rx_mini_consumer;
6384 tnapi->prodring = &tp->prodring[i];
6387 * If multivector RSS is enabled, vector 0 does not handle
6388 * rx or tx interrupts. Don't allocate any resources for it.
6390 if (!i && (tp->tg3_flags3 & TG3_FLG3_ENABLE_RSS))
6393 tnapi->rx_rcb = pci_alloc_consistent(tp->pdev,
6394 TG3_RX_RCB_RING_BYTES(tp),
6395 &tnapi->rx_rcb_mapping);
6399 memset(tnapi->rx_rcb, 0, TG3_RX_RCB_RING_BYTES(tp));
6405 tg3_free_consistent(tp);
6409 #define MAX_WAIT_CNT 1000
6411 /* To stop a block, clear the enable bit and poll till it
6412 * clears. tp->lock is held.
6414 static int tg3_stop_block(struct tg3 *tp, unsigned long ofs, u32 enable_bit, int silent)
6419 if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
6426 /* We can't enable/disable these bits of the
6427 * 5705/5750, just say success.
6440 for (i = 0; i < MAX_WAIT_CNT; i++) {
6443 if ((val & enable_bit) == 0)
6447 if (i == MAX_WAIT_CNT && !silent) {
6448 dev_err(&tp->pdev->dev,
6449 "tg3_stop_block timed out, ofs=%lx enable_bit=%x\n",
6457 /* tp->lock is held. */
6458 static int tg3_abort_hw(struct tg3 *tp, int silent)
6462 tg3_disable_ints(tp);
6464 tp->rx_mode &= ~RX_MODE_ENABLE;
6465 tw32_f(MAC_RX_MODE, tp->rx_mode);
6468 err = tg3_stop_block(tp, RCVBDI_MODE, RCVBDI_MODE_ENABLE, silent);
6469 err |= tg3_stop_block(tp, RCVLPC_MODE, RCVLPC_MODE_ENABLE, silent);
6470 err |= tg3_stop_block(tp, RCVLSC_MODE, RCVLSC_MODE_ENABLE, silent);
6471 err |= tg3_stop_block(tp, RCVDBDI_MODE, RCVDBDI_MODE_ENABLE, silent);
6472 err |= tg3_stop_block(tp, RCVDCC_MODE, RCVDCC_MODE_ENABLE, silent);
6473 err |= tg3_stop_block(tp, RCVCC_MODE, RCVCC_MODE_ENABLE, silent);
6475 err |= tg3_stop_block(tp, SNDBDS_MODE, SNDBDS_MODE_ENABLE, silent);
6476 err |= tg3_stop_block(tp, SNDBDI_MODE, SNDBDI_MODE_ENABLE, silent);
6477 err |= tg3_stop_block(tp, SNDDATAI_MODE, SNDDATAI_MODE_ENABLE, silent);
6478 err |= tg3_stop_block(tp, RDMAC_MODE, RDMAC_MODE_ENABLE, silent);
6479 err |= tg3_stop_block(tp, SNDDATAC_MODE, SNDDATAC_MODE_ENABLE, silent);
6480 err |= tg3_stop_block(tp, DMAC_MODE, DMAC_MODE_ENABLE, silent);
6481 err |= tg3_stop_block(tp, SNDBDC_MODE, SNDBDC_MODE_ENABLE, silent);
6483 tp->mac_mode &= ~MAC_MODE_TDE_ENABLE;
6484 tw32_f(MAC_MODE, tp->mac_mode);
6487 tp->tx_mode &= ~TX_MODE_ENABLE;
6488 tw32_f(MAC_TX_MODE, tp->tx_mode);
6490 for (i = 0; i < MAX_WAIT_CNT; i++) {
6492 if (!(tr32(MAC_TX_MODE) & TX_MODE_ENABLE))
6495 if (i >= MAX_WAIT_CNT) {
6496 dev_err(&tp->pdev->dev,
6497 "%s timed out, TX_MODE_ENABLE will not clear "
6498 "MAC_TX_MODE=%08x\n", __func__, tr32(MAC_TX_MODE));
6502 err |= tg3_stop_block(tp, HOSTCC_MODE, HOSTCC_MODE_ENABLE, silent);
6503 err |= tg3_stop_block(tp, WDMAC_MODE, WDMAC_MODE_ENABLE, silent);
6504 err |= tg3_stop_block(tp, MBFREE_MODE, MBFREE_MODE_ENABLE, silent);
6506 tw32(FTQ_RESET, 0xffffffff);
6507 tw32(FTQ_RESET, 0x00000000);
6509 err |= tg3_stop_block(tp, BUFMGR_MODE, BUFMGR_MODE_ENABLE, silent);
6510 err |= tg3_stop_block(tp, MEMARB_MODE, MEMARB_MODE_ENABLE, silent);
6512 for (i = 0; i < tp->irq_cnt; i++) {
6513 struct tg3_napi *tnapi = &tp->napi[i];
6514 if (tnapi->hw_status)
6515 memset(tnapi->hw_status, 0, TG3_HW_STATUS_SIZE);
6518 memset(tp->hw_stats, 0, sizeof(struct tg3_hw_stats));
6523 static void tg3_ape_send_event(struct tg3 *tp, u32 event)
6528 apedata = tg3_ape_read32(tp, TG3_APE_SEG_SIG);
6529 if (apedata != APE_SEG_SIG_MAGIC)
6532 apedata = tg3_ape_read32(tp, TG3_APE_FW_STATUS);
6533 if (!(apedata & APE_FW_STATUS_READY))
6536 /* Wait for up to 1 millisecond for APE to service previous event. */
6537 for (i = 0; i < 10; i++) {
6538 if (tg3_ape_lock(tp, TG3_APE_LOCK_MEM))
6541 apedata = tg3_ape_read32(tp, TG3_APE_EVENT_STATUS);
6543 if (!(apedata & APE_EVENT_STATUS_EVENT_PENDING))
6544 tg3_ape_write32(tp, TG3_APE_EVENT_STATUS,
6545 event | APE_EVENT_STATUS_EVENT_PENDING);
6547 tg3_ape_unlock(tp, TG3_APE_LOCK_MEM);
6549 if (!(apedata & APE_EVENT_STATUS_EVENT_PENDING))
6555 if (!(apedata & APE_EVENT_STATUS_EVENT_PENDING))
6556 tg3_ape_write32(tp, TG3_APE_EVENT, APE_EVENT_1);
6559 static void tg3_ape_driver_state_change(struct tg3 *tp, int kind)
6564 if (!(tp->tg3_flags3 & TG3_FLG3_ENABLE_APE))
6568 case RESET_KIND_INIT:
6569 tg3_ape_write32(tp, TG3_APE_HOST_SEG_SIG,
6570 APE_HOST_SEG_SIG_MAGIC);
6571 tg3_ape_write32(tp, TG3_APE_HOST_SEG_LEN,
6572 APE_HOST_SEG_LEN_MAGIC);
6573 apedata = tg3_ape_read32(tp, TG3_APE_HOST_INIT_COUNT);
6574 tg3_ape_write32(tp, TG3_APE_HOST_INIT_COUNT, ++apedata);
6575 tg3_ape_write32(tp, TG3_APE_HOST_DRIVER_ID,
6576 APE_HOST_DRIVER_ID_MAGIC);
6577 tg3_ape_write32(tp, TG3_APE_HOST_BEHAVIOR,
6578 APE_HOST_BEHAV_NO_PHYLOCK);
6580 event = APE_EVENT_STATUS_STATE_START;
6582 case RESET_KIND_SHUTDOWN:
6583 /* With the interface we are currently using,
6584 * APE does not track driver state. Wiping
6585 * out the HOST SEGMENT SIGNATURE forces
6586 * the APE to assume OS absent status.
6588 tg3_ape_write32(tp, TG3_APE_HOST_SEG_SIG, 0x0);
6590 event = APE_EVENT_STATUS_STATE_UNLOAD;
6592 case RESET_KIND_SUSPEND:
6593 event = APE_EVENT_STATUS_STATE_SUSPEND;
6599 event |= APE_EVENT_STATUS_DRIVER_EVNT | APE_EVENT_STATUS_STATE_CHNGE;
6601 tg3_ape_send_event(tp, event);
6604 /* tp->lock is held. */
6605 static void tg3_write_sig_pre_reset(struct tg3 *tp, int kind)
6607 tg3_write_mem(tp, NIC_SRAM_FIRMWARE_MBOX,
6608 NIC_SRAM_FIRMWARE_MBOX_MAGIC1);
6610 if (tp->tg3_flags2 & TG3_FLG2_ASF_NEW_HANDSHAKE) {
6612 case RESET_KIND_INIT:
6613 tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
6617 case RESET_KIND_SHUTDOWN:
6618 tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
6622 case RESET_KIND_SUSPEND:
6623 tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
6632 if (kind == RESET_KIND_INIT ||
6633 kind == RESET_KIND_SUSPEND)
6634 tg3_ape_driver_state_change(tp, kind);
6637 /* tp->lock is held. */
6638 static void tg3_write_sig_post_reset(struct tg3 *tp, int kind)
6640 if (tp->tg3_flags2 & TG3_FLG2_ASF_NEW_HANDSHAKE) {
6642 case RESET_KIND_INIT:
6643 tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
6644 DRV_STATE_START_DONE);
6647 case RESET_KIND_SHUTDOWN:
6648 tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
6649 DRV_STATE_UNLOAD_DONE);
6657 if (kind == RESET_KIND_SHUTDOWN)
6658 tg3_ape_driver_state_change(tp, kind);
6661 /* tp->lock is held. */
6662 static void tg3_write_sig_legacy(struct tg3 *tp, int kind)
6664 if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) {
6666 case RESET_KIND_INIT:
6667 tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
6671 case RESET_KIND_SHUTDOWN:
6672 tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
6676 case RESET_KIND_SUSPEND:
6677 tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
6687 static int tg3_poll_fw(struct tg3 *tp)
6692 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
6693 /* Wait up to 20ms for init done. */
6694 for (i = 0; i < 200; i++) {
6695 if (tr32(VCPU_STATUS) & VCPU_STATUS_INIT_DONE)
6702 /* Wait for firmware initialization to complete. */
6703 for (i = 0; i < 100000; i++) {
6704 tg3_read_mem(tp, NIC_SRAM_FIRMWARE_MBOX, &val);
6705 if (val == ~NIC_SRAM_FIRMWARE_MBOX_MAGIC1)
6710 /* Chip might not be fitted with firmware. Some Sun onboard
6711 * parts are configured like that. So don't signal the timeout
6712 * of the above loop as an error, but do report the lack of
6713 * running firmware once.
6716 !(tp->tg3_flags2 & TG3_FLG2_NO_FWARE_REPORTED)) {
6717 tp->tg3_flags2 |= TG3_FLG2_NO_FWARE_REPORTED;
6719 netdev_info(tp->dev, "No firmware running\n");
6722 if (tp->pci_chip_rev_id == CHIPREV_ID_57765_A0) {
6723 /* The 57765 A0 needs a little more
6724 * time to do some important work.
6732 /* Save PCI command register before chip reset */
6733 static void tg3_save_pci_state(struct tg3 *tp)
6735 pci_read_config_word(tp->pdev, PCI_COMMAND, &tp->pci_cmd);
6738 /* Restore PCI state after chip reset */
6739 static void tg3_restore_pci_state(struct tg3 *tp)
6743 /* Re-enable indirect register accesses. */
6744 pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL,
6745 tp->misc_host_ctrl);
6747 /* Set MAX PCI retry to zero. */
6748 val = (PCISTATE_ROM_ENABLE | PCISTATE_ROM_RETRY_ENABLE);
6749 if (tp->pci_chip_rev_id == CHIPREV_ID_5704_A0 &&
6750 (tp->tg3_flags & TG3_FLAG_PCIX_MODE))
6751 val |= PCISTATE_RETRY_SAME_DMA;
6752 /* Allow reads and writes to the APE register and memory space. */
6753 if (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE)
6754 val |= PCISTATE_ALLOW_APE_CTLSPC_WR |
6755 PCISTATE_ALLOW_APE_SHMEM_WR;
6756 pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE, val);
6758 pci_write_config_word(tp->pdev, PCI_COMMAND, tp->pci_cmd);
6760 if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5785) {
6761 if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS)
6762 pcie_set_readrq(tp->pdev, 4096);
6764 pci_write_config_byte(tp->pdev, PCI_CACHE_LINE_SIZE,
6765 tp->pci_cacheline_sz);
6766 pci_write_config_byte(tp->pdev, PCI_LATENCY_TIMER,
6771 /* Make sure PCI-X relaxed ordering bit is clear. */
6772 if (tp->tg3_flags & TG3_FLAG_PCIX_MODE) {
6775 pci_read_config_word(tp->pdev, tp->pcix_cap + PCI_X_CMD,
6777 pcix_cmd &= ~PCI_X_CMD_ERO;
6778 pci_write_config_word(tp->pdev, tp->pcix_cap + PCI_X_CMD,
6782 if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS) {
6784 /* Chip reset on 5780 will reset MSI enable bit,
6785 * so need to restore it.
6787 if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
6790 pci_read_config_word(tp->pdev,
6791 tp->msi_cap + PCI_MSI_FLAGS,
6793 pci_write_config_word(tp->pdev,
6794 tp->msi_cap + PCI_MSI_FLAGS,
6795 ctrl | PCI_MSI_FLAGS_ENABLE);
6796 val = tr32(MSGINT_MODE);
6797 tw32(MSGINT_MODE, val | MSGINT_MODE_ENABLE);
6802 static void tg3_stop_fw(struct tg3 *);
6804 /* tp->lock is held. */
6805 static int tg3_chip_reset(struct tg3 *tp)
6808 void (*write_op)(struct tg3 *, u32, u32);
6813 tg3_ape_lock(tp, TG3_APE_LOCK_GRC);
6815 /* No matching tg3_nvram_unlock() after this because
6816 * chip reset below will undo the nvram lock.
6818 tp->nvram_lock_cnt = 0;
6820 /* GRC_MISC_CFG core clock reset will clear the memory
6821 * enable bit in PCI register 4 and the MSI enable bit
6822 * on some chips, so we save relevant registers here.
6824 tg3_save_pci_state(tp);
6826 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 ||
6827 (tp->tg3_flags3 & TG3_FLG3_5755_PLUS))
6828 tw32(GRC_FASTBOOT_PC, 0);
6831 * We must avoid the readl() that normally takes place.
6832 * It locks machines, causes machine checks, and other
6833 * fun things. So, temporarily disable the 5701
6834 * hardware workaround, while we do the reset.
6836 write_op = tp->write32;
6837 if (write_op == tg3_write_flush_reg32)
6838 tp->write32 = tg3_write32;
6840 /* Prevent the irq handler from reading or writing PCI registers
6841 * during chip reset when the memory enable bit in the PCI command
6842 * register may be cleared. The chip does not generate interrupt
6843 * at this time, but the irq handler may still be called due to irq
6844 * sharing or irqpoll.
6846 tp->tg3_flags |= TG3_FLAG_CHIP_RESETTING;
6847 for (i = 0; i < tp->irq_cnt; i++) {
6848 struct tg3_napi *tnapi = &tp->napi[i];
6849 if (tnapi->hw_status) {
6850 tnapi->hw_status->status = 0;
6851 tnapi->hw_status->status_tag = 0;
6853 tnapi->last_tag = 0;
6854 tnapi->last_irq_tag = 0;
6858 for (i = 0; i < tp->irq_cnt; i++)
6859 synchronize_irq(tp->napi[i].irq_vec);
6861 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) {
6862 val = tr32(TG3_PCIE_LNKCTL) & ~TG3_PCIE_LNKCTL_L1_PLL_PD_EN;
6863 tw32(TG3_PCIE_LNKCTL, val | TG3_PCIE_LNKCTL_L1_PLL_PD_DIS);
6867 val = GRC_MISC_CFG_CORECLK_RESET;
6869 if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) {
6870 if (tr32(0x7e2c) == 0x60) {
6873 if (tp->pci_chip_rev_id != CHIPREV_ID_5750_A0) {
6874 tw32(GRC_MISC_CFG, (1 << 29));
6879 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
6880 tw32(VCPU_STATUS, tr32(VCPU_STATUS) | VCPU_STATUS_DRV_RESET);
6881 tw32(GRC_VCPU_EXT_CTRL,
6882 tr32(GRC_VCPU_EXT_CTRL) & ~GRC_VCPU_EXT_CTRL_HALT_CPU);
6885 if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS)
6886 val |= GRC_MISC_CFG_KEEP_GPHY_POWER;
6887 tw32(GRC_MISC_CFG, val);
6889 /* restore 5701 hardware bug workaround write method */
6890 tp->write32 = write_op;
6892 /* Unfortunately, we have to delay before the PCI read back.
6893 * Some 575X chips even will not respond to a PCI cfg access
6894 * when the reset command is given to the chip.
6896 * How do these hardware designers expect things to work
6897 * properly if the PCI write is posted for a long period
6898 * of time? It is always necessary to have some method by
6899 * which a register read back can occur to push the write
6900 * out which does the reset.
6902 * For most tg3 variants the trick below was working.
6907 /* Flush PCI posted writes. The normal MMIO registers
6908 * are inaccessible at this time so this is the only
6909 * way to make this reliably (actually, this is no longer
6910 * the case, see above). I tried to use indirect
6911 * register read/write but this upset some 5701 variants.
6913 pci_read_config_dword(tp->pdev, PCI_COMMAND, &val);
6917 if ((tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) && tp->pcie_cap) {
6920 if (tp->pci_chip_rev_id == CHIPREV_ID_5750_A0) {
6924 /* Wait for link training to complete. */
6925 for (i = 0; i < 5000; i++)
6928 pci_read_config_dword(tp->pdev, 0xc4, &cfg_val);
6929 pci_write_config_dword(tp->pdev, 0xc4,
6930 cfg_val | (1 << 15));
6933 /* Clear the "no snoop" and "relaxed ordering" bits. */
6934 pci_read_config_word(tp->pdev,
6935 tp->pcie_cap + PCI_EXP_DEVCTL,
6937 val16 &= ~(PCI_EXP_DEVCTL_RELAX_EN |
6938 PCI_EXP_DEVCTL_NOSNOOP_EN);
6940 * Older PCIe devices only support the 128 byte
6941 * MPS setting. Enforce the restriction.
6943 if (!(tp->tg3_flags & TG3_FLAG_CPMU_PRESENT) ||
6944 (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784))
6945 val16 &= ~PCI_EXP_DEVCTL_PAYLOAD;
6946 pci_write_config_word(tp->pdev,
6947 tp->pcie_cap + PCI_EXP_DEVCTL,
6950 pcie_set_readrq(tp->pdev, 4096);
6952 /* Clear error status */
6953 pci_write_config_word(tp->pdev,
6954 tp->pcie_cap + PCI_EXP_DEVSTA,
6955 PCI_EXP_DEVSTA_CED |
6956 PCI_EXP_DEVSTA_NFED |
6957 PCI_EXP_DEVSTA_FED |
6958 PCI_EXP_DEVSTA_URD);
6961 tg3_restore_pci_state(tp);
6963 tp->tg3_flags &= ~TG3_FLAG_CHIP_RESETTING;
6966 if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)
6967 val = tr32(MEMARB_MODE);
6968 tw32(MEMARB_MODE, val | MEMARB_MODE_ENABLE);
6970 if (tp->pci_chip_rev_id == CHIPREV_ID_5750_A3) {
6972 tw32(0x5000, 0x400);
6975 tw32(GRC_MODE, tp->grc_mode);
6977 if (tp->pci_chip_rev_id == CHIPREV_ID_5705_A0) {
6980 tw32(0xc4, val | (1 << 15));
6983 if ((tp->nic_sram_data_cfg & NIC_SRAM_DATA_CFG_MINI_PCI) != 0 &&
6984 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) {
6985 tp->pci_clock_ctrl |= CLOCK_CTRL_CLKRUN_OENABLE;
6986 if (tp->pci_chip_rev_id == CHIPREV_ID_5705_A0)
6987 tp->pci_clock_ctrl |= CLOCK_CTRL_FORCE_CLKRUN;
6988 tw32(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl);
6991 if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) {
6992 tp->mac_mode = MAC_MODE_PORT_MODE_TBI;
6993 tw32_f(MAC_MODE, tp->mac_mode);
6994 } else if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES) {
6995 tp->mac_mode = MAC_MODE_PORT_MODE_GMII;
6996 tw32_f(MAC_MODE, tp->mac_mode);
6997 } else if (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE) {
6998 tp->mac_mode &= (MAC_MODE_APE_TX_EN | MAC_MODE_APE_RX_EN);
6999 if (tp->mac_mode & MAC_MODE_APE_TX_EN)
7000 tp->mac_mode |= MAC_MODE_TDE_ENABLE;
7001 tw32_f(MAC_MODE, tp->mac_mode);
7003 tw32_f(MAC_MODE, 0);
7006 tg3_ape_unlock(tp, TG3_APE_LOCK_GRC);
7008 err = tg3_poll_fw(tp);
7014 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) {
7017 phy_addr = tp->phy_addr;
7018 tp->phy_addr = TG3_PHY_PCIE_ADDR;
7020 tg3_writephy(tp, TG3_PCIEPHY_BLOCK_ADDR,
7021 TG3_PCIEPHY_TXB_BLK << TG3_PCIEPHY_BLOCK_SHIFT);
7022 val = TG3_PCIEPHY_TX0CTRL1_TXOCM | TG3_PCIEPHY_TX0CTRL1_RDCTL |
7023 TG3_PCIEPHY_TX0CTRL1_TXCMV | TG3_PCIEPHY_TX0CTRL1_TKSEL |
7024 TG3_PCIEPHY_TX0CTRL1_NB_EN;
7025 tg3_writephy(tp, TG3_PCIEPHY_TX0CTRL1, val);
7028 tg3_writephy(tp, TG3_PCIEPHY_BLOCK_ADDR,
7029 TG3_PCIEPHY_XGXS_BLK1 << TG3_PCIEPHY_BLOCK_SHIFT);
7030 val = TG3_PCIEPHY_PWRMGMT4_LOWPWR_EN |
7031 TG3_PCIEPHY_PWRMGMT4_L1PLLPD_EN;
7032 tg3_writephy(tp, TG3_PCIEPHY_PWRMGMT4, val);
7035 tp->phy_addr = phy_addr;
7038 if ((tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) &&
7039 tp->pci_chip_rev_id != CHIPREV_ID_5750_A0 &&
7040 GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5785 &&
7041 GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5717 &&
7042 GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_57765) {
7045 tw32(0x7c00, val | (1 << 25));
7048 /* Reprobe ASF enable state. */
7049 tp->tg3_flags &= ~TG3_FLAG_ENABLE_ASF;
7050 tp->tg3_flags2 &= ~TG3_FLG2_ASF_NEW_HANDSHAKE;
7051 tg3_read_mem(tp, NIC_SRAM_DATA_SIG, &val);
7052 if (val == NIC_SRAM_DATA_SIG_MAGIC) {
7055 tg3_read_mem(tp, NIC_SRAM_DATA_CFG, &nic_cfg);
7056 if (nic_cfg & NIC_SRAM_DATA_CFG_ASF_ENABLE) {
7057 tp->tg3_flags |= TG3_FLAG_ENABLE_ASF;
7058 tp->last_event_jiffies = jiffies;
7059 if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS)
7060 tp->tg3_flags2 |= TG3_FLG2_ASF_NEW_HANDSHAKE;
7067 /* tp->lock is held. */
7068 static void tg3_stop_fw(struct tg3 *tp)
7070 if ((tp->tg3_flags & TG3_FLAG_ENABLE_ASF) &&
7071 !(tp->tg3_flags3 & TG3_FLG3_ENABLE_APE)) {
7072 /* Wait for RX cpu to ACK the previous event. */
7073 tg3_wait_for_event_ack(tp);
7075 tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX, FWCMD_NICDRV_PAUSE_FW);
7077 tg3_generate_fw_event(tp);
7079 /* Wait for RX cpu to ACK this event. */
7080 tg3_wait_for_event_ack(tp);
7084 /* tp->lock is held. */
7085 static int tg3_halt(struct tg3 *tp, int kind, int silent)
7091 tg3_write_sig_pre_reset(tp, kind);
7093 tg3_abort_hw(tp, silent);
7094 err = tg3_chip_reset(tp);
7096 __tg3_set_mac_addr(tp, 0);
7098 tg3_write_sig_legacy(tp, kind);
7099 tg3_write_sig_post_reset(tp, kind);
7107 #define RX_CPU_SCRATCH_BASE 0x30000
7108 #define RX_CPU_SCRATCH_SIZE 0x04000
7109 #define TX_CPU_SCRATCH_BASE 0x34000
7110 #define TX_CPU_SCRATCH_SIZE 0x04000
7112 /* tp->lock is held. */
7113 static int tg3_halt_cpu(struct tg3 *tp, u32 offset)
7117 BUG_ON(offset == TX_CPU_BASE &&
7118 (tp->tg3_flags2 & TG3_FLG2_5705_PLUS));
7120 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
7121 u32 val = tr32(GRC_VCPU_EXT_CTRL);
7123 tw32(GRC_VCPU_EXT_CTRL, val | GRC_VCPU_EXT_CTRL_HALT_CPU);
7126 if (offset == RX_CPU_BASE) {
7127 for (i = 0; i < 10000; i++) {
7128 tw32(offset + CPU_STATE, 0xffffffff);
7129 tw32(offset + CPU_MODE, CPU_MODE_HALT);
7130 if (tr32(offset + CPU_MODE) & CPU_MODE_HALT)
7134 tw32(offset + CPU_STATE, 0xffffffff);
7135 tw32_f(offset + CPU_MODE, CPU_MODE_HALT);
7138 for (i = 0; i < 10000; i++) {
7139 tw32(offset + CPU_STATE, 0xffffffff);
7140 tw32(offset + CPU_MODE, CPU_MODE_HALT);
7141 if (tr32(offset + CPU_MODE) & CPU_MODE_HALT)
7147 netdev_err(tp->dev, "%s timed out, %s CPU\n",
7148 __func__, offset == RX_CPU_BASE ? "RX" : "TX");
7152 /* Clear firmware's nvram arbitration. */
7153 if (tp->tg3_flags & TG3_FLAG_NVRAM)
7154 tw32(NVRAM_SWARB, SWARB_REQ_CLR0);
7159 unsigned int fw_base;
7160 unsigned int fw_len;
7161 const __be32 *fw_data;
7164 /* tp->lock is held. */
7165 static int tg3_load_firmware_cpu(struct tg3 *tp, u32 cpu_base, u32 cpu_scratch_base,
7166 int cpu_scratch_size, struct fw_info *info)
7168 int err, lock_err, i;
7169 void (*write_op)(struct tg3 *, u32, u32);
7171 if (cpu_base == TX_CPU_BASE &&
7172 (tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
7174 "%s: Trying to load TX cpu firmware which is 5705\n",
7179 if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS)
7180 write_op = tg3_write_mem;
7182 write_op = tg3_write_indirect_reg32;
7184 /* It is possible that bootcode is still loading at this point.
7185 * Get the nvram lock first before halting the cpu.
7187 lock_err = tg3_nvram_lock(tp);
7188 err = tg3_halt_cpu(tp, cpu_base);
7190 tg3_nvram_unlock(tp);
7194 for (i = 0; i < cpu_scratch_size; i += sizeof(u32))
7195 write_op(tp, cpu_scratch_base + i, 0);
7196 tw32(cpu_base + CPU_STATE, 0xffffffff);
7197 tw32(cpu_base + CPU_MODE, tr32(cpu_base+CPU_MODE)|CPU_MODE_HALT);
7198 for (i = 0; i < (info->fw_len / sizeof(u32)); i++)
7199 write_op(tp, (cpu_scratch_base +
7200 (info->fw_base & 0xffff) +
7202 be32_to_cpu(info->fw_data[i]));
7210 /* tp->lock is held. */
7211 static int tg3_load_5701_a0_firmware_fix(struct tg3 *tp)
7213 struct fw_info info;
7214 const __be32 *fw_data;
7217 fw_data = (void *)tp->fw->data;
7219 /* Firmware blob starts with version numbers, followed by
7220 start address and length. We are setting complete length.
7221 length = end_address_of_bss - start_address_of_text.
7222 Remainder is the blob to be loaded contiguously
7223 from start address. */
7225 info.fw_base = be32_to_cpu(fw_data[1]);
7226 info.fw_len = tp->fw->size - 12;
7227 info.fw_data = &fw_data[3];
7229 err = tg3_load_firmware_cpu(tp, RX_CPU_BASE,
7230 RX_CPU_SCRATCH_BASE, RX_CPU_SCRATCH_SIZE,
7235 err = tg3_load_firmware_cpu(tp, TX_CPU_BASE,
7236 TX_CPU_SCRATCH_BASE, TX_CPU_SCRATCH_SIZE,
7241 /* Now startup only the RX cpu. */
7242 tw32(RX_CPU_BASE + CPU_STATE, 0xffffffff);
7243 tw32_f(RX_CPU_BASE + CPU_PC, info.fw_base);
7245 for (i = 0; i < 5; i++) {
7246 if (tr32(RX_CPU_BASE + CPU_PC) == info.fw_base)
7248 tw32(RX_CPU_BASE + CPU_STATE, 0xffffffff);
7249 tw32(RX_CPU_BASE + CPU_MODE, CPU_MODE_HALT);
7250 tw32_f(RX_CPU_BASE + CPU_PC, info.fw_base);
7254 netdev_err(tp->dev, "%s fails to set RX CPU PC, is %08x "
7255 "should be %08x\n", __func__,
7256 tr32(RX_CPU_BASE + CPU_PC), info.fw_base);
7259 tw32(RX_CPU_BASE + CPU_STATE, 0xffffffff);
7260 tw32_f(RX_CPU_BASE + CPU_MODE, 0x00000000);
7265 /* 5705 needs a special version of the TSO firmware. */
7267 /* tp->lock is held. */
7268 static int tg3_load_tso_firmware(struct tg3 *tp)
7270 struct fw_info info;
7271 const __be32 *fw_data;
7272 unsigned long cpu_base, cpu_scratch_base, cpu_scratch_size;
7275 if (tp->tg3_flags2 & TG3_FLG2_HW_TSO)
7278 fw_data = (void *)tp->fw->data;
7280 /* Firmware blob starts with version numbers, followed by
7281 start address and length. We are setting complete length.
7282 length = end_address_of_bss - start_address_of_text.
7283 Remainder is the blob to be loaded contiguously
7284 from start address. */
7286 info.fw_base = be32_to_cpu(fw_data[1]);
7287 cpu_scratch_size = tp->fw_len;
7288 info.fw_len = tp->fw->size - 12;
7289 info.fw_data = &fw_data[3];
7291 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) {
7292 cpu_base = RX_CPU_BASE;
7293 cpu_scratch_base = NIC_SRAM_MBUF_POOL_BASE5705;
7295 cpu_base = TX_CPU_BASE;
7296 cpu_scratch_base = TX_CPU_SCRATCH_BASE;
7297 cpu_scratch_size = TX_CPU_SCRATCH_SIZE;
7300 err = tg3_load_firmware_cpu(tp, cpu_base,
7301 cpu_scratch_base, cpu_scratch_size,
7306 /* Now startup the cpu. */
7307 tw32(cpu_base + CPU_STATE, 0xffffffff);
7308 tw32_f(cpu_base + CPU_PC, info.fw_base);
7310 for (i = 0; i < 5; i++) {
7311 if (tr32(cpu_base + CPU_PC) == info.fw_base)
7313 tw32(cpu_base + CPU_STATE, 0xffffffff);
7314 tw32(cpu_base + CPU_MODE, CPU_MODE_HALT);
7315 tw32_f(cpu_base + CPU_PC, info.fw_base);
7320 "%s fails to set CPU PC, is %08x should be %08x\n",
7321 __func__, tr32(cpu_base + CPU_PC), info.fw_base);
7324 tw32(cpu_base + CPU_STATE, 0xffffffff);
7325 tw32_f(cpu_base + CPU_MODE, 0x00000000);
7330 static int tg3_set_mac_addr(struct net_device *dev, void *p)
7332 struct tg3 *tp = netdev_priv(dev);
7333 struct sockaddr *addr = p;
7334 int err = 0, skip_mac_1 = 0;
7336 if (!is_valid_ether_addr(addr->sa_data))
7339 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
7341 if (!netif_running(dev))
7344 if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) {
7345 u32 addr0_high, addr0_low, addr1_high, addr1_low;
7347 addr0_high = tr32(MAC_ADDR_0_HIGH);
7348 addr0_low = tr32(MAC_ADDR_0_LOW);
7349 addr1_high = tr32(MAC_ADDR_1_HIGH);
7350 addr1_low = tr32(MAC_ADDR_1_LOW);
7352 /* Skip MAC addr 1 if ASF is using it. */
7353 if ((addr0_high != addr1_high || addr0_low != addr1_low) &&
7354 !(addr1_high == 0 && addr1_low == 0))
7357 spin_lock_bh(&tp->lock);
7358 __tg3_set_mac_addr(tp, skip_mac_1);
7359 spin_unlock_bh(&tp->lock);
7364 /* tp->lock is held. */
7365 static void tg3_set_bdinfo(struct tg3 *tp, u32 bdinfo_addr,
7366 dma_addr_t mapping, u32 maxlen_flags,
7370 (bdinfo_addr + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH),
7371 ((u64) mapping >> 32));
7373 (bdinfo_addr + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW),
7374 ((u64) mapping & 0xffffffff));
7376 (bdinfo_addr + TG3_BDINFO_MAXLEN_FLAGS),
7379 if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS))
7381 (bdinfo_addr + TG3_BDINFO_NIC_ADDR),
7385 static void __tg3_set_rx_mode(struct net_device *);
7386 static void __tg3_set_coalesce(struct tg3 *tp, struct ethtool_coalesce *ec)
7390 if (!(tp->tg3_flags3 & TG3_FLG3_ENABLE_TSS)) {
7391 tw32(HOSTCC_TXCOL_TICKS, ec->tx_coalesce_usecs);
7392 tw32(HOSTCC_TXMAX_FRAMES, ec->tx_max_coalesced_frames);
7393 tw32(HOSTCC_TXCOAL_MAXF_INT, ec->tx_max_coalesced_frames_irq);
7395 tw32(HOSTCC_TXCOL_TICKS, 0);
7396 tw32(HOSTCC_TXMAX_FRAMES, 0);
7397 tw32(HOSTCC_TXCOAL_MAXF_INT, 0);
7400 if (!(tp->tg3_flags2 & TG3_FLG2_USING_MSIX)) {
7401 tw32(HOSTCC_RXCOL_TICKS, ec->rx_coalesce_usecs);
7402 tw32(HOSTCC_RXMAX_FRAMES, ec->rx_max_coalesced_frames);
7403 tw32(HOSTCC_RXCOAL_MAXF_INT, ec->rx_max_coalesced_frames_irq);
7405 tw32(HOSTCC_RXCOL_TICKS, 0);
7406 tw32(HOSTCC_RXMAX_FRAMES, 0);
7407 tw32(HOSTCC_RXCOAL_MAXF_INT, 0);
7410 if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
7411 u32 val = ec->stats_block_coalesce_usecs;
7413 tw32(HOSTCC_RXCOAL_TICK_INT, ec->rx_coalesce_usecs_irq);
7414 tw32(HOSTCC_TXCOAL_TICK_INT, ec->tx_coalesce_usecs_irq);
7416 if (!netif_carrier_ok(tp->dev))
7419 tw32(HOSTCC_STAT_COAL_TICKS, val);
7422 for (i = 0; i < tp->irq_cnt - 1; i++) {
7425 reg = HOSTCC_RXCOL_TICKS_VEC1 + i * 0x18;
7426 tw32(reg, ec->rx_coalesce_usecs);
7427 reg = HOSTCC_RXMAX_FRAMES_VEC1 + i * 0x18;
7428 tw32(reg, ec->rx_max_coalesced_frames);
7429 reg = HOSTCC_RXCOAL_MAXF_INT_VEC1 + i * 0x18;
7430 tw32(reg, ec->rx_max_coalesced_frames_irq);
7432 if (tp->tg3_flags3 & TG3_FLG3_ENABLE_TSS) {
7433 reg = HOSTCC_TXCOL_TICKS_VEC1 + i * 0x18;
7434 tw32(reg, ec->tx_coalesce_usecs);
7435 reg = HOSTCC_TXMAX_FRAMES_VEC1 + i * 0x18;
7436 tw32(reg, ec->tx_max_coalesced_frames);
7437 reg = HOSTCC_TXCOAL_MAXF_INT_VEC1 + i * 0x18;
7438 tw32(reg, ec->tx_max_coalesced_frames_irq);
7442 for (; i < tp->irq_max - 1; i++) {
7443 tw32(HOSTCC_RXCOL_TICKS_VEC1 + i * 0x18, 0);
7444 tw32(HOSTCC_RXMAX_FRAMES_VEC1 + i * 0x18, 0);
7445 tw32(HOSTCC_RXCOAL_MAXF_INT_VEC1 + i * 0x18, 0);
7447 if (tp->tg3_flags3 & TG3_FLG3_ENABLE_TSS) {
7448 tw32(HOSTCC_TXCOL_TICKS_VEC1 + i * 0x18, 0);
7449 tw32(HOSTCC_TXMAX_FRAMES_VEC1 + i * 0x18, 0);
7450 tw32(HOSTCC_TXCOAL_MAXF_INT_VEC1 + i * 0x18, 0);
7455 /* tp->lock is held. */
7456 static void tg3_rings_reset(struct tg3 *tp)
7459 u32 stblk, txrcb, rxrcb, limit;
7460 struct tg3_napi *tnapi = &tp->napi[0];
7462 /* Disable all transmit rings but the first. */
7463 if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS))
7464 limit = NIC_SRAM_SEND_RCB + TG3_BDINFO_SIZE * 16;
7465 else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765)
7466 limit = NIC_SRAM_SEND_RCB + TG3_BDINFO_SIZE * 2;
7468 limit = NIC_SRAM_SEND_RCB + TG3_BDINFO_SIZE;
7470 for (txrcb = NIC_SRAM_SEND_RCB + TG3_BDINFO_SIZE;
7471 txrcb < limit; txrcb += TG3_BDINFO_SIZE)
7472 tg3_write_mem(tp, txrcb + TG3_BDINFO_MAXLEN_FLAGS,
7473 BDINFO_FLAGS_DISABLED);
7476 /* Disable all receive return rings but the first. */
7477 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717)
7478 limit = NIC_SRAM_RCV_RET_RCB + TG3_BDINFO_SIZE * 17;
7479 else if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS))
7480 limit = NIC_SRAM_RCV_RET_RCB + TG3_BDINFO_SIZE * 16;
7481 else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
7482 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765)
7483 limit = NIC_SRAM_RCV_RET_RCB + TG3_BDINFO_SIZE * 4;
7485 limit = NIC_SRAM_RCV_RET_RCB + TG3_BDINFO_SIZE;
7487 for (rxrcb = NIC_SRAM_RCV_RET_RCB + TG3_BDINFO_SIZE;
7488 rxrcb < limit; rxrcb += TG3_BDINFO_SIZE)
7489 tg3_write_mem(tp, rxrcb + TG3_BDINFO_MAXLEN_FLAGS,
7490 BDINFO_FLAGS_DISABLED);
7492 /* Disable interrupts */
7493 tw32_mailbox_f(tp->napi[0].int_mbox, 1);
7495 /* Zero mailbox registers. */
7496 if (tp->tg3_flags & TG3_FLAG_SUPPORT_MSIX) {
7497 for (i = 1; i < TG3_IRQ_MAX_VECS; i++) {
7498 tp->napi[i].tx_prod = 0;
7499 tp->napi[i].tx_cons = 0;
7500 if (tp->tg3_flags3 & TG3_FLG3_ENABLE_TSS)
7501 tw32_mailbox(tp->napi[i].prodmbox, 0);
7502 tw32_rx_mbox(tp->napi[i].consmbox, 0);
7503 tw32_mailbox_f(tp->napi[i].int_mbox, 1);
7505 if (!(tp->tg3_flags3 & TG3_FLG3_ENABLE_TSS))
7506 tw32_mailbox(tp->napi[0].prodmbox, 0);
7508 tp->napi[0].tx_prod = 0;
7509 tp->napi[0].tx_cons = 0;
7510 tw32_mailbox(tp->napi[0].prodmbox, 0);
7511 tw32_rx_mbox(tp->napi[0].consmbox, 0);
7514 /* Make sure the NIC-based send BD rings are disabled. */
7515 if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
7516 u32 mbox = MAILBOX_SNDNIC_PROD_IDX_0 + TG3_64BIT_REG_LOW;
7517 for (i = 0; i < 16; i++)
7518 tw32_tx_mbox(mbox + i * 8, 0);
7521 txrcb = NIC_SRAM_SEND_RCB;
7522 rxrcb = NIC_SRAM_RCV_RET_RCB;
7524 /* Clear status block in ram. */
7525 memset(tnapi->hw_status, 0, TG3_HW_STATUS_SIZE);
7527 /* Set status block DMA address */
7528 tw32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH,
7529 ((u64) tnapi->status_mapping >> 32));
7530 tw32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW,
7531 ((u64) tnapi->status_mapping & 0xffffffff));
7533 if (tnapi->tx_ring) {
7534 tg3_set_bdinfo(tp, txrcb, tnapi->tx_desc_mapping,
7535 (TG3_TX_RING_SIZE <<
7536 BDINFO_FLAGS_MAXLEN_SHIFT),
7537 NIC_SRAM_TX_BUFFER_DESC);
7538 txrcb += TG3_BDINFO_SIZE;
7541 if (tnapi->rx_rcb) {
7542 tg3_set_bdinfo(tp, rxrcb, tnapi->rx_rcb_mapping,
7543 (TG3_RX_RCB_RING_SIZE(tp) <<
7544 BDINFO_FLAGS_MAXLEN_SHIFT), 0);
7545 rxrcb += TG3_BDINFO_SIZE;
7548 stblk = HOSTCC_STATBLCK_RING1;
7550 for (i = 1, tnapi++; i < tp->irq_cnt; i++, tnapi++) {
7551 u64 mapping = (u64)tnapi->status_mapping;
7552 tw32(stblk + TG3_64BIT_REG_HIGH, mapping >> 32);
7553 tw32(stblk + TG3_64BIT_REG_LOW, mapping & 0xffffffff);
7555 /* Clear status block in ram. */
7556 memset(tnapi->hw_status, 0, TG3_HW_STATUS_SIZE);
7558 if (tnapi->tx_ring) {
7559 tg3_set_bdinfo(tp, txrcb, tnapi->tx_desc_mapping,
7560 (TG3_TX_RING_SIZE <<
7561 BDINFO_FLAGS_MAXLEN_SHIFT),
7562 NIC_SRAM_TX_BUFFER_DESC);
7563 txrcb += TG3_BDINFO_SIZE;
7566 tg3_set_bdinfo(tp, rxrcb, tnapi->rx_rcb_mapping,
7567 (TG3_RX_RCB_RING_SIZE(tp) <<
7568 BDINFO_FLAGS_MAXLEN_SHIFT), 0);
7571 rxrcb += TG3_BDINFO_SIZE;
7575 /* tp->lock is held. */
7576 static int tg3_reset_hw(struct tg3 *tp, int reset_phy)
7578 u32 val, rdmac_mode;
7580 struct tg3_rx_prodring_set *tpr = &tp->prodring[0];
7582 tg3_disable_ints(tp);
7586 tg3_write_sig_pre_reset(tp, RESET_KIND_INIT);
7588 if (tp->tg3_flags & TG3_FLAG_INIT_COMPLETE) {
7589 tg3_abort_hw(tp, 1);
7595 err = tg3_chip_reset(tp);
7599 tg3_write_sig_legacy(tp, RESET_KIND_INIT);
7601 if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5784_AX) {
7602 val = tr32(TG3_CPMU_CTRL);
7603 val &= ~(CPMU_CTRL_LINK_AWARE_MODE | CPMU_CTRL_LINK_IDLE_MODE);
7604 tw32(TG3_CPMU_CTRL, val);
7606 val = tr32(TG3_CPMU_LSPD_10MB_CLK);
7607 val &= ~CPMU_LSPD_10MB_MACCLK_MASK;
7608 val |= CPMU_LSPD_10MB_MACCLK_6_25;
7609 tw32(TG3_CPMU_LSPD_10MB_CLK, val);
7611 val = tr32(TG3_CPMU_LNK_AWARE_PWRMD);
7612 val &= ~CPMU_LNK_AWARE_MACCLK_MASK;
7613 val |= CPMU_LNK_AWARE_MACCLK_6_25;
7614 tw32(TG3_CPMU_LNK_AWARE_PWRMD, val);
7616 val = tr32(TG3_CPMU_HST_ACC);
7617 val &= ~CPMU_HST_ACC_MACCLK_MASK;
7618 val |= CPMU_HST_ACC_MACCLK_6_25;
7619 tw32(TG3_CPMU_HST_ACC, val);
7622 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) {
7623 val = tr32(PCIE_PWR_MGMT_THRESH) & ~PCIE_PWR_MGMT_L1_THRESH_MSK;
7624 val |= PCIE_PWR_MGMT_EXT_ASPM_TMR_EN |
7625 PCIE_PWR_MGMT_L1_THRESH_4MS;
7626 tw32(PCIE_PWR_MGMT_THRESH, val);
7628 val = tr32(TG3_PCIE_EIDLE_DELAY) & ~TG3_PCIE_EIDLE_DELAY_MASK;
7629 tw32(TG3_PCIE_EIDLE_DELAY, val | TG3_PCIE_EIDLE_DELAY_13_CLKS);
7631 tw32(TG3_CORR_ERR_STAT, TG3_CORR_ERR_STAT_CLEAR);
7633 val = tr32(TG3_PCIE_LNKCTL) & ~TG3_PCIE_LNKCTL_L1_PLL_PD_EN;
7634 tw32(TG3_PCIE_LNKCTL, val | TG3_PCIE_LNKCTL_L1_PLL_PD_DIS);
7637 if (tp->tg3_flags3 & TG3_FLG3_L1PLLPD_EN) {
7638 u32 grc_mode = tr32(GRC_MODE);
7640 /* Access the lower 1K of PL PCIE block registers. */
7641 val = grc_mode & ~GRC_MODE_PCIE_PORT_MASK;
7642 tw32(GRC_MODE, val | GRC_MODE_PCIE_PL_SEL);
7644 val = tr32(TG3_PCIE_TLDLPL_PORT + TG3_PCIE_PL_LO_PHYCTL1);
7645 tw32(TG3_PCIE_TLDLPL_PORT + TG3_PCIE_PL_LO_PHYCTL1,
7646 val | TG3_PCIE_PL_LO_PHYCTL1_L1PLLPD_EN);
7648 tw32(GRC_MODE, grc_mode);
7651 /* This works around an issue with Athlon chipsets on
7652 * B3 tigon3 silicon. This bit has no effect on any
7653 * other revision. But do not set this on PCI Express
7654 * chips and don't even touch the clocks if the CPMU is present.
7656 if (!(tp->tg3_flags & TG3_FLAG_CPMU_PRESENT)) {
7657 if (!(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS))
7658 tp->pci_clock_ctrl |= CLOCK_CTRL_DELAY_PCI_GRANT;
7659 tw32_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl);
7662 if (tp->pci_chip_rev_id == CHIPREV_ID_5704_A0 &&
7663 (tp->tg3_flags & TG3_FLAG_PCIX_MODE)) {
7664 val = tr32(TG3PCI_PCISTATE);
7665 val |= PCISTATE_RETRY_SAME_DMA;
7666 tw32(TG3PCI_PCISTATE, val);
7669 if (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE) {
7670 /* Allow reads and writes to the
7671 * APE register and memory space.
7673 val = tr32(TG3PCI_PCISTATE);
7674 val |= PCISTATE_ALLOW_APE_CTLSPC_WR |
7675 PCISTATE_ALLOW_APE_SHMEM_WR;
7676 tw32(TG3PCI_PCISTATE, val);
7679 if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5704_BX) {
7680 /* Enable some hw fixes. */
7681 val = tr32(TG3PCI_MSI_DATA);
7682 val |= (1 << 26) | (1 << 28) | (1 << 29);
7683 tw32(TG3PCI_MSI_DATA, val);
7686 /* Descriptor ring init may make accesses to the
7687 * NIC SRAM area to setup the TX descriptors, so we
7688 * can only do this after the hardware has been
7689 * successfully reset.
7691 err = tg3_init_rings(tp);
7695 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 ||
7696 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) {
7697 val = tr32(TG3PCI_DMA_RW_CTRL) &
7698 ~DMA_RWCTRL_DIS_CACHE_ALIGNMENT;
7699 tw32(TG3PCI_DMA_RW_CTRL, val | tp->dma_rwctrl);
7700 } else if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5784 &&
7701 GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5761) {
7702 /* This value is determined during the probe time DMA
7703 * engine test, tg3_test_dma.
7705 tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl);
7708 tp->grc_mode &= ~(GRC_MODE_HOST_SENDBDS |
7709 GRC_MODE_4X_NIC_SEND_RINGS |
7710 GRC_MODE_NO_TX_PHDR_CSUM |
7711 GRC_MODE_NO_RX_PHDR_CSUM);
7712 tp->grc_mode |= GRC_MODE_HOST_SENDBDS;
7714 /* Pseudo-header checksum is done by hardware logic and not
7715 * the offload processers, so make the chip do the pseudo-
7716 * header checksums on receive. For transmit it is more
7717 * convenient to do the pseudo-header checksum in software
7718 * as Linux does that on transmit for us in all cases.
7720 tp->grc_mode |= GRC_MODE_NO_TX_PHDR_CSUM;
7724 (GRC_MODE_IRQ_ON_MAC_ATTN | GRC_MODE_HOST_STACKUP));
7726 /* Setup the timer prescalar register. Clock is always 66Mhz. */
7727 val = tr32(GRC_MISC_CFG);
7729 val |= (65 << GRC_MISC_CFG_PRESCALAR_SHIFT);
7730 tw32(GRC_MISC_CFG, val);
7732 /* Initialize MBUF/DESC pool. */
7733 if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS) {
7735 } else if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5705) {
7736 tw32(BUFMGR_MB_POOL_ADDR, NIC_SRAM_MBUF_POOL_BASE);
7737 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704)
7738 tw32(BUFMGR_MB_POOL_SIZE, NIC_SRAM_MBUF_POOL_SIZE64);
7740 tw32(BUFMGR_MB_POOL_SIZE, NIC_SRAM_MBUF_POOL_SIZE96);
7741 tw32(BUFMGR_DMA_DESC_POOL_ADDR, NIC_SRAM_DMA_DESC_POOL_BASE);
7742 tw32(BUFMGR_DMA_DESC_POOL_SIZE, NIC_SRAM_DMA_DESC_POOL_SIZE);
7744 else if (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) {
7747 fw_len = tp->fw_len;
7748 fw_len = (fw_len + (0x80 - 1)) & ~(0x80 - 1);
7749 tw32(BUFMGR_MB_POOL_ADDR,
7750 NIC_SRAM_MBUF_POOL_BASE5705 + fw_len);
7751 tw32(BUFMGR_MB_POOL_SIZE,
7752 NIC_SRAM_MBUF_POOL_SIZE5705 - fw_len - 0xa00);
7755 if (tp->dev->mtu <= ETH_DATA_LEN) {
7756 tw32(BUFMGR_MB_RDMA_LOW_WATER,
7757 tp->bufmgr_config.mbuf_read_dma_low_water);
7758 tw32(BUFMGR_MB_MACRX_LOW_WATER,
7759 tp->bufmgr_config.mbuf_mac_rx_low_water);
7760 tw32(BUFMGR_MB_HIGH_WATER,
7761 tp->bufmgr_config.mbuf_high_water);
7763 tw32(BUFMGR_MB_RDMA_LOW_WATER,
7764 tp->bufmgr_config.mbuf_read_dma_low_water_jumbo);
7765 tw32(BUFMGR_MB_MACRX_LOW_WATER,
7766 tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo);
7767 tw32(BUFMGR_MB_HIGH_WATER,
7768 tp->bufmgr_config.mbuf_high_water_jumbo);
7770 tw32(BUFMGR_DMA_LOW_WATER,
7771 tp->bufmgr_config.dma_low_water);
7772 tw32(BUFMGR_DMA_HIGH_WATER,
7773 tp->bufmgr_config.dma_high_water);
7775 tw32(BUFMGR_MODE, BUFMGR_MODE_ENABLE | BUFMGR_MODE_ATTN_ENABLE);
7776 for (i = 0; i < 2000; i++) {
7777 if (tr32(BUFMGR_MODE) & BUFMGR_MODE_ENABLE)
7782 netdev_err(tp->dev, "%s cannot enable BUFMGR\n", __func__);
7786 /* Setup replenish threshold. */
7787 val = tp->rx_pending / 8;
7790 else if (val > tp->rx_std_max_post)
7791 val = tp->rx_std_max_post;
7792 else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
7793 if (tp->pci_chip_rev_id == CHIPREV_ID_5906_A1)
7794 tw32(ISO_PKT_TX, (tr32(ISO_PKT_TX) & ~0x3) | 0x2);
7796 if (val > (TG3_RX_INTERNAL_RING_SZ_5906 / 2))
7797 val = TG3_RX_INTERNAL_RING_SZ_5906 / 2;
7800 tw32(RCVBDI_STD_THRESH, val);
7802 /* Initialize TG3_BDINFO's at:
7803 * RCVDBDI_STD_BD: standard eth size rx ring
7804 * RCVDBDI_JUMBO_BD: jumbo frame rx ring
7805 * RCVDBDI_MINI_BD: small frame rx ring (??? does not work)
7808 * TG3_BDINFO_HOST_ADDR: high/low parts of DMA address of ring
7809 * TG3_BDINFO_MAXLEN_FLAGS: (rx max buffer size << 16) |
7810 * ring attribute flags
7811 * TG3_BDINFO_NIC_ADDR: location of descriptors in nic SRAM
7813 * Standard receive ring @ NIC_SRAM_RX_BUFFER_DESC, 512 entries.
7814 * Jumbo receive ring @ NIC_SRAM_RX_JUMBO_BUFFER_DESC, 256 entries.
7816 * The size of each ring is fixed in the firmware, but the location is
7819 tw32(RCVDBDI_STD_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH,
7820 ((u64) tpr->rx_std_mapping >> 32));
7821 tw32(RCVDBDI_STD_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW,
7822 ((u64) tpr->rx_std_mapping & 0xffffffff));
7823 if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5717)
7824 tw32(RCVDBDI_STD_BD + TG3_BDINFO_NIC_ADDR,
7825 NIC_SRAM_RX_BUFFER_DESC);
7827 /* Disable the mini ring */
7828 if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS))
7829 tw32(RCVDBDI_MINI_BD + TG3_BDINFO_MAXLEN_FLAGS,
7830 BDINFO_FLAGS_DISABLED);
7832 /* Program the jumbo buffer descriptor ring control
7833 * blocks on those devices that have them.
7835 if ((tp->tg3_flags & TG3_FLAG_JUMBO_CAPABLE) &&
7836 !(tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) {
7837 /* Setup replenish threshold. */
7838 tw32(RCVBDI_JUMBO_THRESH, tp->rx_jumbo_pending / 8);
7840 if (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE) {
7841 tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH,
7842 ((u64) tpr->rx_jmb_mapping >> 32));
7843 tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW,
7844 ((u64) tpr->rx_jmb_mapping & 0xffffffff));
7845 tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_MAXLEN_FLAGS,
7846 (RX_JUMBO_MAX_SIZE << BDINFO_FLAGS_MAXLEN_SHIFT) |
7847 BDINFO_FLAGS_USE_EXT_RECV);
7848 if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5717)
7849 tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_NIC_ADDR,
7850 NIC_SRAM_RX_JUMBO_BUFFER_DESC);
7852 tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_MAXLEN_FLAGS,
7853 BDINFO_FLAGS_DISABLED);
7856 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 ||
7857 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765)
7858 val = (RX_STD_MAX_SIZE_5705 << BDINFO_FLAGS_MAXLEN_SHIFT) |
7859 (RX_STD_MAX_SIZE << 2);
7861 val = RX_STD_MAX_SIZE << BDINFO_FLAGS_MAXLEN_SHIFT;
7863 val = RX_STD_MAX_SIZE_5705 << BDINFO_FLAGS_MAXLEN_SHIFT;
7865 tw32(RCVDBDI_STD_BD + TG3_BDINFO_MAXLEN_FLAGS, val);
7867 tpr->rx_std_prod_idx = tp->rx_pending;
7868 tw32_rx_mbox(TG3_RX_STD_PROD_IDX_REG, tpr->rx_std_prod_idx);
7870 tpr->rx_jmb_prod_idx = (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE) ?
7871 tp->rx_jumbo_pending : 0;
7872 tw32_rx_mbox(TG3_RX_JMB_PROD_IDX_REG, tpr->rx_jmb_prod_idx);
7874 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 ||
7875 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) {
7876 tw32(STD_REPLENISH_LWM, 32);
7877 tw32(JMB_REPLENISH_LWM, 16);
7880 tg3_rings_reset(tp);
7882 /* Initialize MAC address and backoff seed. */
7883 __tg3_set_mac_addr(tp, 0);
7885 /* MTU + ethernet header + FCS + optional VLAN tag */
7886 tw32(MAC_RX_MTU_SIZE,
7887 tp->dev->mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN);
7889 /* The slot time is changed by tg3_setup_phy if we
7890 * run at gigabit with half duplex.
7892 tw32(MAC_TX_LENGTHS,
7893 (2 << TX_LENGTHS_IPG_CRS_SHIFT) |
7894 (6 << TX_LENGTHS_IPG_SHIFT) |
7895 (32 << TX_LENGTHS_SLOT_TIME_SHIFT));
7897 /* Receive rules. */
7898 tw32(MAC_RCV_RULE_CFG, RCV_RULE_CFG_DEFAULT_CLASS);
7899 tw32(RCVLPC_CONFIG, 0x0181);
7901 /* Calculate RDMAC_MODE setting early, we need it to determine
7902 * the RCVLPC_STATE_ENABLE mask.
7904 rdmac_mode = (RDMAC_MODE_ENABLE | RDMAC_MODE_TGTABORT_ENAB |
7905 RDMAC_MODE_MSTABORT_ENAB | RDMAC_MODE_PARITYERR_ENAB |
7906 RDMAC_MODE_ADDROFLOW_ENAB | RDMAC_MODE_FIFOOFLOW_ENAB |
7907 RDMAC_MODE_FIFOURUN_ENAB | RDMAC_MODE_FIFOOREAD_ENAB |
7908 RDMAC_MODE_LNGREAD_ENAB);
7910 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717)
7911 rdmac_mode |= RDMAC_MODE_MULT_DMA_RD_DIS;
7913 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 ||
7914 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 ||
7915 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780)
7916 rdmac_mode |= RDMAC_MODE_BD_SBD_CRPT_ENAB |
7917 RDMAC_MODE_MBUF_RBD_CRPT_ENAB |
7918 RDMAC_MODE_MBUF_SBD_CRPT_ENAB;
7920 /* If statement applies to 5705 and 5750 PCI devices only */
7921 if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 &&
7922 tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) ||
7923 (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750)) {
7924 if (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE &&
7925 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) {
7926 rdmac_mode |= RDMAC_MODE_FIFO_SIZE_128;
7927 } else if (!(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH) &&
7928 !(tp->tg3_flags2 & TG3_FLG2_IS_5788)) {
7929 rdmac_mode |= RDMAC_MODE_FIFO_LONG_BURST;
7933 if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS)
7934 rdmac_mode |= RDMAC_MODE_FIFO_LONG_BURST;
7936 if (tp->tg3_flags2 & TG3_FLG2_HW_TSO)
7937 rdmac_mode |= RDMAC_MODE_IPV4_LSO_EN;
7939 if ((tp->tg3_flags2 & TG3_FLG2_HW_TSO_3) ||
7940 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 ||
7941 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780)
7942 rdmac_mode |= RDMAC_MODE_IPV6_LSO_EN;
7944 /* Receive/send statistics. */
7945 if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS) {
7946 val = tr32(RCVLPC_STATS_ENABLE);
7947 val &= ~RCVLPC_STATSENAB_DACK_FIX;
7948 tw32(RCVLPC_STATS_ENABLE, val);
7949 } else if ((rdmac_mode & RDMAC_MODE_FIFO_SIZE_128) &&
7950 (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE)) {
7951 val = tr32(RCVLPC_STATS_ENABLE);
7952 val &= ~RCVLPC_STATSENAB_LNGBRST_RFIX;
7953 tw32(RCVLPC_STATS_ENABLE, val);
7955 tw32(RCVLPC_STATS_ENABLE, 0xffffff);
7957 tw32(RCVLPC_STATSCTRL, RCVLPC_STATSCTRL_ENABLE);
7958 tw32(SNDDATAI_STATSENAB, 0xffffff);
7959 tw32(SNDDATAI_STATSCTRL,
7960 (SNDDATAI_SCTRL_ENABLE |
7961 SNDDATAI_SCTRL_FASTUPD));
7963 /* Setup host coalescing engine. */
7964 tw32(HOSTCC_MODE, 0);
7965 for (i = 0; i < 2000; i++) {
7966 if (!(tr32(HOSTCC_MODE) & HOSTCC_MODE_ENABLE))
7971 __tg3_set_coalesce(tp, &tp->coal);
7973 if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
7974 /* Status/statistics block address. See tg3_timer,
7975 * the tg3_periodic_fetch_stats call there, and
7976 * tg3_get_stats to see how this works for 5705/5750 chips.
7978 tw32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH,
7979 ((u64) tp->stats_mapping >> 32));
7980 tw32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW,
7981 ((u64) tp->stats_mapping & 0xffffffff));
7982 tw32(HOSTCC_STATS_BLK_NIC_ADDR, NIC_SRAM_STATS_BLK);
7984 tw32(HOSTCC_STATUS_BLK_NIC_ADDR, NIC_SRAM_STATUS_BLK);
7986 /* Clear statistics and status block memory areas */
7987 for (i = NIC_SRAM_STATS_BLK;
7988 i < NIC_SRAM_STATUS_BLK + TG3_HW_STATUS_SIZE;
7990 tg3_write_mem(tp, i, 0);
7995 tw32(HOSTCC_MODE, HOSTCC_MODE_ENABLE | tp->coalesce_mode);
7997 tw32(RCVCC_MODE, RCVCC_MODE_ENABLE | RCVCC_MODE_ATTN_ENABLE);
7998 tw32(RCVLPC_MODE, RCVLPC_MODE_ENABLE);
7999 if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS))
8000 tw32(RCVLSC_MODE, RCVLSC_MODE_ENABLE | RCVLSC_MODE_ATTN_ENABLE);
8002 if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES) {
8003 tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
8004 /* reset to prevent losing 1st rx packet intermittently */
8005 tw32_f(MAC_RX_MODE, RX_MODE_RESET);
8009 if (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE)
8010 tp->mac_mode &= MAC_MODE_APE_TX_EN | MAC_MODE_APE_RX_EN;
8013 tp->mac_mode |= MAC_MODE_TXSTAT_ENABLE | MAC_MODE_RXSTAT_ENABLE |
8014 MAC_MODE_TDE_ENABLE | MAC_MODE_RDE_ENABLE | MAC_MODE_FHDE_ENABLE;
8015 if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS) &&
8016 !(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) &&
8017 GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700)
8018 tp->mac_mode |= MAC_MODE_LINK_POLARITY;
8019 tw32_f(MAC_MODE, tp->mac_mode | MAC_MODE_RXSTAT_CLEAR | MAC_MODE_TXSTAT_CLEAR);
8022 /* tp->grc_local_ctrl is partially set up during tg3_get_invariants().
8023 * If TG3_FLG2_IS_NIC is zero, we should read the
8024 * register to preserve the GPIO settings for LOMs. The GPIOs,
8025 * whether used as inputs or outputs, are set by boot code after
8028 if (!(tp->tg3_flags2 & TG3_FLG2_IS_NIC)) {
8031 gpio_mask = GRC_LCLCTRL_GPIO_OE0 | GRC_LCLCTRL_GPIO_OE1 |
8032 GRC_LCLCTRL_GPIO_OE2 | GRC_LCLCTRL_GPIO_OUTPUT0 |
8033 GRC_LCLCTRL_GPIO_OUTPUT1 | GRC_LCLCTRL_GPIO_OUTPUT2;
8035 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752)
8036 gpio_mask |= GRC_LCLCTRL_GPIO_OE3 |
8037 GRC_LCLCTRL_GPIO_OUTPUT3;
8039 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755)
8040 gpio_mask |= GRC_LCLCTRL_GPIO_UART_SEL;
8042 tp->grc_local_ctrl &= ~gpio_mask;
8043 tp->grc_local_ctrl |= tr32(GRC_LOCAL_CTRL) & gpio_mask;
8045 /* GPIO1 must be driven high for eeprom write protect */
8046 if (tp->tg3_flags & TG3_FLAG_EEPROM_WRITE_PROT)
8047 tp->grc_local_ctrl |= (GRC_LCLCTRL_GPIO_OE1 |
8048 GRC_LCLCTRL_GPIO_OUTPUT1);
8050 tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl);
8053 if (tp->tg3_flags2 & TG3_FLG2_USING_MSIX) {
8054 val = tr32(MSGINT_MODE);
8055 val |= MSGINT_MODE_MULTIVEC_EN | MSGINT_MODE_ENABLE;
8056 tw32(MSGINT_MODE, val);
8059 if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
8060 tw32_f(DMAC_MODE, DMAC_MODE_ENABLE);
8064 val = (WDMAC_MODE_ENABLE | WDMAC_MODE_TGTABORT_ENAB |
8065 WDMAC_MODE_MSTABORT_ENAB | WDMAC_MODE_PARITYERR_ENAB |
8066 WDMAC_MODE_ADDROFLOW_ENAB | WDMAC_MODE_FIFOOFLOW_ENAB |
8067 WDMAC_MODE_FIFOURUN_ENAB | WDMAC_MODE_FIFOOREAD_ENAB |
8068 WDMAC_MODE_LNGREAD_ENAB);
8070 /* If statement applies to 5705 and 5750 PCI devices only */
8071 if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 &&
8072 tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) ||
8073 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750) {
8074 if ((tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) &&
8075 (tp->pci_chip_rev_id == CHIPREV_ID_5705_A1 ||
8076 tp->pci_chip_rev_id == CHIPREV_ID_5705_A2)) {
8078 } else if (!(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH) &&
8079 !(tp->tg3_flags2 & TG3_FLG2_IS_5788) &&
8080 !(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS)) {
8081 val |= WDMAC_MODE_RX_ACCEL;
8085 /* Enable host coalescing bug fix */
8086 if (tp->tg3_flags3 & TG3_FLG3_5755_PLUS)
8087 val |= WDMAC_MODE_STATUS_TAG_FIX;
8089 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785)
8090 val |= WDMAC_MODE_BURST_ALL_DATA;
8092 tw32_f(WDMAC_MODE, val);
8095 if (tp->tg3_flags & TG3_FLAG_PCIX_MODE) {
8098 pci_read_config_word(tp->pdev, tp->pcix_cap + PCI_X_CMD,
8100 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703) {
8101 pcix_cmd &= ~PCI_X_CMD_MAX_READ;
8102 pcix_cmd |= PCI_X_CMD_READ_2K;
8103 } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) {
8104 pcix_cmd &= ~(PCI_X_CMD_MAX_SPLIT | PCI_X_CMD_MAX_READ);
8105 pcix_cmd |= PCI_X_CMD_READ_2K;
8107 pci_write_config_word(tp->pdev, tp->pcix_cap + PCI_X_CMD,
8111 tw32_f(RDMAC_MODE, rdmac_mode);
8114 tw32(RCVDCC_MODE, RCVDCC_MODE_ENABLE | RCVDCC_MODE_ATTN_ENABLE);
8115 if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS))
8116 tw32(MBFREE_MODE, MBFREE_MODE_ENABLE);
8118 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761)
8120 SNDDATAC_MODE_ENABLE | SNDDATAC_MODE_CDELAY);
8122 tw32(SNDDATAC_MODE, SNDDATAC_MODE_ENABLE);
8124 tw32(SNDBDC_MODE, SNDBDC_MODE_ENABLE | SNDBDC_MODE_ATTN_ENABLE);
8125 tw32(RCVBDI_MODE, RCVBDI_MODE_ENABLE | RCVBDI_MODE_RCB_ATTN_ENAB);
8126 tw32(RCVDBDI_MODE, RCVDBDI_MODE_ENABLE | RCVDBDI_MODE_INV_RING_SZ);
8127 tw32(SNDDATAI_MODE, SNDDATAI_MODE_ENABLE);
8128 if (tp->tg3_flags2 & TG3_FLG2_HW_TSO)
8129 tw32(SNDDATAI_MODE, SNDDATAI_MODE_ENABLE | 0x8);
8130 val = SNDBDI_MODE_ENABLE | SNDBDI_MODE_ATTN_ENABLE;
8131 if (tp->tg3_flags3 & TG3_FLG3_ENABLE_TSS)
8132 val |= SNDBDI_MODE_MULTI_TXQ_EN;
8133 tw32(SNDBDI_MODE, val);
8134 tw32(SNDBDS_MODE, SNDBDS_MODE_ENABLE | SNDBDS_MODE_ATTN_ENABLE);
8136 if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0) {
8137 err = tg3_load_5701_a0_firmware_fix(tp);
8142 if (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) {
8143 err = tg3_load_tso_firmware(tp);
8148 tp->tx_mode = TX_MODE_ENABLE;
8149 tw32_f(MAC_TX_MODE, tp->tx_mode);
8152 if (tp->tg3_flags3 & TG3_FLG3_ENABLE_RSS) {
8153 u32 reg = MAC_RSS_INDIR_TBL_0;
8154 u8 *ent = (u8 *)&val;
8156 /* Setup the indirection table */
8157 for (i = 0; i < TG3_RSS_INDIR_TBL_SIZE; i++) {
8158 int idx = i % sizeof(val);
8160 ent[idx] = i % (tp->irq_cnt - 1);
8161 if (idx == sizeof(val) - 1) {
8167 /* Setup the "secret" hash key. */
8168 tw32(MAC_RSS_HASH_KEY_0, 0x5f865437);
8169 tw32(MAC_RSS_HASH_KEY_1, 0xe4ac62cc);
8170 tw32(MAC_RSS_HASH_KEY_2, 0x50103a45);
8171 tw32(MAC_RSS_HASH_KEY_3, 0x36621985);
8172 tw32(MAC_RSS_HASH_KEY_4, 0xbf14c0e8);
8173 tw32(MAC_RSS_HASH_KEY_5, 0x1bc27a1e);
8174 tw32(MAC_RSS_HASH_KEY_6, 0x84f4b556);
8175 tw32(MAC_RSS_HASH_KEY_7, 0x094ea6fe);
8176 tw32(MAC_RSS_HASH_KEY_8, 0x7dda01e7);
8177 tw32(MAC_RSS_HASH_KEY_9, 0xc04d7481);
8180 tp->rx_mode = RX_MODE_ENABLE;
8181 if (tp->tg3_flags3 & TG3_FLG3_5755_PLUS)
8182 tp->rx_mode |= RX_MODE_IPV6_CSUM_ENABLE;
8184 if (tp->tg3_flags3 & TG3_FLG3_ENABLE_RSS)
8185 tp->rx_mode |= RX_MODE_RSS_ENABLE |
8186 RX_MODE_RSS_ITBL_HASH_BITS_7 |
8187 RX_MODE_RSS_IPV6_HASH_EN |
8188 RX_MODE_RSS_TCP_IPV6_HASH_EN |
8189 RX_MODE_RSS_IPV4_HASH_EN |
8190 RX_MODE_RSS_TCP_IPV4_HASH_EN;
8192 tw32_f(MAC_RX_MODE, tp->rx_mode);
8195 tw32(MAC_LED_CTRL, tp->led_ctrl);
8197 tw32(MAC_MI_STAT, MAC_MI_STAT_LNKSTAT_ATTN_ENAB);
8198 if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) {
8199 tw32_f(MAC_RX_MODE, RX_MODE_RESET);
8202 tw32_f(MAC_RX_MODE, tp->rx_mode);
8205 if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) {
8206 if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) &&
8207 !(tp->tg3_flags2 & TG3_FLG2_SERDES_PREEMPHASIS)) {
8208 /* Set drive transmission level to 1.2V */
8209 /* only if the signal pre-emphasis bit is not set */
8210 val = tr32(MAC_SERDES_CFG);
8213 tw32(MAC_SERDES_CFG, val);
8215 if (tp->pci_chip_rev_id == CHIPREV_ID_5703_A1)
8216 tw32(MAC_SERDES_CFG, 0x616000);
8219 /* Prevent chip from dropping frames when flow control
8222 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765)
8226 tw32_f(MAC_LOW_WMARK_MAX_RX_FRAME, val);
8228 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 &&
8229 (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)) {
8230 /* Use hardware link auto-negotiation */
8231 tp->tg3_flags2 |= TG3_FLG2_HW_AUTONEG;
8234 if ((tp->tg3_flags2 & TG3_FLG2_MII_SERDES) &&
8235 (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714)) {
8238 tmp = tr32(SERDES_RX_CTRL);
8239 tw32(SERDES_RX_CTRL, tmp | SERDES_RX_SIG_DETECT);
8240 tp->grc_local_ctrl &= ~GRC_LCLCTRL_USE_EXT_SIG_DETECT;
8241 tp->grc_local_ctrl |= GRC_LCLCTRL_USE_SIG_DETECT;
8242 tw32(GRC_LOCAL_CTRL, tp->grc_local_ctrl);
8245 if (!(tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB)) {
8246 if (tp->link_config.phy_is_low_power) {
8247 tp->link_config.phy_is_low_power = 0;
8248 tp->link_config.speed = tp->link_config.orig_speed;
8249 tp->link_config.duplex = tp->link_config.orig_duplex;
8250 tp->link_config.autoneg = tp->link_config.orig_autoneg;
8253 err = tg3_setup_phy(tp, 0);
8257 if (!(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) &&
8258 !(tp->tg3_flags3 & TG3_FLG3_PHY_IS_FET)) {
8261 /* Clear CRC stats. */
8262 if (!tg3_readphy(tp, MII_TG3_TEST1, &tmp)) {
8263 tg3_writephy(tp, MII_TG3_TEST1,
8264 tmp | MII_TG3_TEST1_CRC_EN);
8265 tg3_readphy(tp, 0x14, &tmp);
8270 __tg3_set_rx_mode(tp->dev);
8272 /* Initialize receive rules. */
8273 tw32(MAC_RCV_RULE_0, 0xc2000000 & RCV_RULE_DISABLE_MASK);
8274 tw32(MAC_RCV_VALUE_0, 0xffffffff & RCV_RULE_DISABLE_MASK);
8275 tw32(MAC_RCV_RULE_1, 0x86000004 & RCV_RULE_DISABLE_MASK);
8276 tw32(MAC_RCV_VALUE_1, 0xffffffff & RCV_RULE_DISABLE_MASK);
8278 if ((tp->tg3_flags2 & TG3_FLG2_5705_PLUS) &&
8279 !(tp->tg3_flags2 & TG3_FLG2_5780_CLASS))
8283 if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF)
8287 tw32(MAC_RCV_RULE_15, 0); tw32(MAC_RCV_VALUE_15, 0);
8289 tw32(MAC_RCV_RULE_14, 0); tw32(MAC_RCV_VALUE_14, 0);
8291 tw32(MAC_RCV_RULE_13, 0); tw32(MAC_RCV_VALUE_13, 0);
8293 tw32(MAC_RCV_RULE_12, 0); tw32(MAC_RCV_VALUE_12, 0);
8295 tw32(MAC_RCV_RULE_11, 0); tw32(MAC_RCV_VALUE_11, 0);
8297 tw32(MAC_RCV_RULE_10, 0); tw32(MAC_RCV_VALUE_10, 0);
8299 tw32(MAC_RCV_RULE_9, 0); tw32(MAC_RCV_VALUE_9, 0);
8301 tw32(MAC_RCV_RULE_8, 0); tw32(MAC_RCV_VALUE_8, 0);
8303 tw32(MAC_RCV_RULE_7, 0); tw32(MAC_RCV_VALUE_7, 0);
8305 tw32(MAC_RCV_RULE_6, 0); tw32(MAC_RCV_VALUE_6, 0);
8307 tw32(MAC_RCV_RULE_5, 0); tw32(MAC_RCV_VALUE_5, 0);
8309 tw32(MAC_RCV_RULE_4, 0); tw32(MAC_RCV_VALUE_4, 0);
8311 /* tw32(MAC_RCV_RULE_3, 0); tw32(MAC_RCV_VALUE_3, 0); */
8313 /* tw32(MAC_RCV_RULE_2, 0); tw32(MAC_RCV_VALUE_2, 0); */
8321 if (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE)
8322 /* Write our heartbeat update interval to APE. */
8323 tg3_ape_write32(tp, TG3_APE_HOST_HEARTBEAT_INT_MS,
8324 APE_HOST_HEARTBEAT_INT_DISABLE);
8326 tg3_write_sig_post_reset(tp, RESET_KIND_INIT);
8331 /* Called at device open time to get the chip ready for
8332 * packet processing. Invoked with tp->lock held.
8334 static int tg3_init_hw(struct tg3 *tp, int reset_phy)
8336 tg3_switch_clocks(tp);
8338 tw32(TG3PCI_MEM_WIN_BASE_ADDR, 0);
8340 return tg3_reset_hw(tp, reset_phy);
8343 #define TG3_STAT_ADD32(PSTAT, REG) \
8344 do { u32 __val = tr32(REG); \
8345 (PSTAT)->low += __val; \
8346 if ((PSTAT)->low < __val) \
8347 (PSTAT)->high += 1; \
8350 static void tg3_periodic_fetch_stats(struct tg3 *tp)
8352 struct tg3_hw_stats *sp = tp->hw_stats;
8354 if (!netif_carrier_ok(tp->dev))
8357 TG3_STAT_ADD32(&sp->tx_octets, MAC_TX_STATS_OCTETS);
8358 TG3_STAT_ADD32(&sp->tx_collisions, MAC_TX_STATS_COLLISIONS);
8359 TG3_STAT_ADD32(&sp->tx_xon_sent, MAC_TX_STATS_XON_SENT);
8360 TG3_STAT_ADD32(&sp->tx_xoff_sent, MAC_TX_STATS_XOFF_SENT);
8361 TG3_STAT_ADD32(&sp->tx_mac_errors, MAC_TX_STATS_MAC_ERRORS);
8362 TG3_STAT_ADD32(&sp->tx_single_collisions, MAC_TX_STATS_SINGLE_COLLISIONS);
8363 TG3_STAT_ADD32(&sp->tx_mult_collisions, MAC_TX_STATS_MULT_COLLISIONS);
8364 TG3_STAT_ADD32(&sp->tx_deferred, MAC_TX_STATS_DEFERRED);
8365 TG3_STAT_ADD32(&sp->tx_excessive_collisions, MAC_TX_STATS_EXCESSIVE_COL);
8366 TG3_STAT_ADD32(&sp->tx_late_collisions, MAC_TX_STATS_LATE_COL);
8367 TG3_STAT_ADD32(&sp->tx_ucast_packets, MAC_TX_STATS_UCAST);
8368 TG3_STAT_ADD32(&sp->tx_mcast_packets, MAC_TX_STATS_MCAST);
8369 TG3_STAT_ADD32(&sp->tx_bcast_packets, MAC_TX_STATS_BCAST);
8371 TG3_STAT_ADD32(&sp->rx_octets, MAC_RX_STATS_OCTETS);
8372 TG3_STAT_ADD32(&sp->rx_fragments, MAC_RX_STATS_FRAGMENTS);
8373 TG3_STAT_ADD32(&sp->rx_ucast_packets, MAC_RX_STATS_UCAST);
8374 TG3_STAT_ADD32(&sp->rx_mcast_packets, MAC_RX_STATS_MCAST);
8375 TG3_STAT_ADD32(&sp->rx_bcast_packets, MAC_RX_STATS_BCAST);
8376 TG3_STAT_ADD32(&sp->rx_fcs_errors, MAC_RX_STATS_FCS_ERRORS);
8377 TG3_STAT_ADD32(&sp->rx_align_errors, MAC_RX_STATS_ALIGN_ERRORS);
8378 TG3_STAT_ADD32(&sp->rx_xon_pause_rcvd, MAC_RX_STATS_XON_PAUSE_RECVD);
8379 TG3_STAT_ADD32(&sp->rx_xoff_pause_rcvd, MAC_RX_STATS_XOFF_PAUSE_RECVD);
8380 TG3_STAT_ADD32(&sp->rx_mac_ctrl_rcvd, MAC_RX_STATS_MAC_CTRL_RECVD);
8381 TG3_STAT_ADD32(&sp->rx_xoff_entered, MAC_RX_STATS_XOFF_ENTERED);
8382 TG3_STAT_ADD32(&sp->rx_frame_too_long_errors, MAC_RX_STATS_FRAME_TOO_LONG);
8383 TG3_STAT_ADD32(&sp->rx_jabbers, MAC_RX_STATS_JABBERS);
8384 TG3_STAT_ADD32(&sp->rx_undersize_packets, MAC_RX_STATS_UNDERSIZE);
8386 TG3_STAT_ADD32(&sp->rxbds_empty, RCVLPC_NO_RCV_BD_CNT);
8387 TG3_STAT_ADD32(&sp->rx_discards, RCVLPC_IN_DISCARDS_CNT);
8388 TG3_STAT_ADD32(&sp->rx_errors, RCVLPC_IN_ERRORS_CNT);
8391 static void tg3_timer(unsigned long __opaque)
8393 struct tg3 *tp = (struct tg3 *) __opaque;
8398 spin_lock(&tp->lock);
8400 if (!(tp->tg3_flags & TG3_FLAG_TAGGED_STATUS)) {
8401 /* All of this garbage is because when using non-tagged
8402 * IRQ status the mailbox/status_block protocol the chip
8403 * uses with the cpu is race prone.
8405 if (tp->napi[0].hw_status->status & SD_STATUS_UPDATED) {
8406 tw32(GRC_LOCAL_CTRL,
8407 tp->grc_local_ctrl | GRC_LCLCTRL_SETINT);
8409 tw32(HOSTCC_MODE, tp->coalesce_mode |
8410 HOSTCC_MODE_ENABLE | HOSTCC_MODE_NOW);
8413 if (!(tr32(WDMAC_MODE) & WDMAC_MODE_ENABLE)) {
8414 tp->tg3_flags2 |= TG3_FLG2_RESTART_TIMER;
8415 spin_unlock(&tp->lock);
8416 schedule_work(&tp->reset_task);
8421 /* This part only runs once per second. */
8422 if (!--tp->timer_counter) {
8423 if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS)
8424 tg3_periodic_fetch_stats(tp);
8426 if (tp->tg3_flags & TG3_FLAG_USE_LINKCHG_REG) {
8430 mac_stat = tr32(MAC_STATUS);
8433 if (tp->tg3_flags & TG3_FLAG_USE_MI_INTERRUPT) {
8434 if (mac_stat & MAC_STATUS_MI_INTERRUPT)
8436 } else if (mac_stat & MAC_STATUS_LNKSTATE_CHANGED)
8440 tg3_setup_phy(tp, 0);
8441 } else if (tp->tg3_flags & TG3_FLAG_POLL_SERDES) {
8442 u32 mac_stat = tr32(MAC_STATUS);
8445 if (netif_carrier_ok(tp->dev) &&
8446 (mac_stat & MAC_STATUS_LNKSTATE_CHANGED)) {
8449 if (! netif_carrier_ok(tp->dev) &&
8450 (mac_stat & (MAC_STATUS_PCS_SYNCED |
8451 MAC_STATUS_SIGNAL_DET))) {
8455 if (!tp->serdes_counter) {
8458 ~MAC_MODE_PORT_MODE_MASK));
8460 tw32_f(MAC_MODE, tp->mac_mode);
8463 tg3_setup_phy(tp, 0);
8465 } else if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES)
8466 tg3_serdes_parallel_detect(tp);
8468 tp->timer_counter = tp->timer_multiplier;
8471 /* Heartbeat is only sent once every 2 seconds.
8473 * The heartbeat is to tell the ASF firmware that the host
8474 * driver is still alive. In the event that the OS crashes,
8475 * ASF needs to reset the hardware to free up the FIFO space
8476 * that may be filled with rx packets destined for the host.
8477 * If the FIFO is full, ASF will no longer function properly.
8479 * Unintended resets have been reported on real time kernels
8480 * where the timer doesn't run on time. Netpoll will also have
8483 * The new FWCMD_NICDRV_ALIVE3 command tells the ASF firmware
8484 * to check the ring condition when the heartbeat is expiring
8485 * before doing the reset. This will prevent most unintended
8488 if (!--tp->asf_counter) {
8489 if ((tp->tg3_flags & TG3_FLAG_ENABLE_ASF) &&
8490 !(tp->tg3_flags3 & TG3_FLG3_ENABLE_APE)) {
8491 tg3_wait_for_event_ack(tp);
8493 tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX,
8494 FWCMD_NICDRV_ALIVE3);
8495 tg3_write_mem(tp, NIC_SRAM_FW_CMD_LEN_MBOX, 4);
8496 tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX,
8497 TG3_FW_UPDATE_TIMEOUT_SEC);
8499 tg3_generate_fw_event(tp);
8501 tp->asf_counter = tp->asf_multiplier;
8504 spin_unlock(&tp->lock);
8507 tp->timer.expires = jiffies + tp->timer_offset;
8508 add_timer(&tp->timer);
8511 static int tg3_request_irq(struct tg3 *tp, int irq_num)
8514 unsigned long flags;
8516 struct tg3_napi *tnapi = &tp->napi[irq_num];
8518 if (tp->irq_cnt == 1)
8519 name = tp->dev->name;
8521 name = &tnapi->irq_lbl[0];
8522 snprintf(name, IFNAMSIZ, "%s-%d", tp->dev->name, irq_num);
8523 name[IFNAMSIZ-1] = 0;
8526 if (tp->tg3_flags2 & TG3_FLG2_USING_MSI_OR_MSIX) {
8528 if (tp->tg3_flags2 & TG3_FLG2_1SHOT_MSI)
8530 flags = IRQF_SAMPLE_RANDOM;
8533 if (tp->tg3_flags & TG3_FLAG_TAGGED_STATUS)
8534 fn = tg3_interrupt_tagged;
8535 flags = IRQF_SHARED | IRQF_SAMPLE_RANDOM;
8538 return request_irq(tnapi->irq_vec, fn, flags, name, tnapi);
8541 static int tg3_test_interrupt(struct tg3 *tp)
8543 struct tg3_napi *tnapi = &tp->napi[0];
8544 struct net_device *dev = tp->dev;
8545 int err, i, intr_ok = 0;
8548 if (!netif_running(dev))
8551 tg3_disable_ints(tp);
8553 free_irq(tnapi->irq_vec, tnapi);
8556 * Turn off MSI one shot mode. Otherwise this test has no
8557 * observable way to know whether the interrupt was delivered.
8559 if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 ||
8560 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) &&
8561 (tp->tg3_flags2 & TG3_FLG2_USING_MSI)) {
8562 val = tr32(MSGINT_MODE) | MSGINT_MODE_ONE_SHOT_DISABLE;
8563 tw32(MSGINT_MODE, val);
8566 err = request_irq(tnapi->irq_vec, tg3_test_isr,
8567 IRQF_SHARED | IRQF_SAMPLE_RANDOM, dev->name, tnapi);
8571 tnapi->hw_status->status &= ~SD_STATUS_UPDATED;
8572 tg3_enable_ints(tp);
8574 tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE |
8577 for (i = 0; i < 5; i++) {
8578 u32 int_mbox, misc_host_ctrl;
8580 int_mbox = tr32_mailbox(tnapi->int_mbox);
8581 misc_host_ctrl = tr32(TG3PCI_MISC_HOST_CTRL);
8583 if ((int_mbox != 0) ||
8584 (misc_host_ctrl & MISC_HOST_CTRL_MASK_PCI_INT)) {
8592 tg3_disable_ints(tp);
8594 free_irq(tnapi->irq_vec, tnapi);
8596 err = tg3_request_irq(tp, 0);
8602 /* Reenable MSI one shot mode. */
8603 if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 ||
8604 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) &&
8605 (tp->tg3_flags2 & TG3_FLG2_USING_MSI)) {
8606 val = tr32(MSGINT_MODE) & ~MSGINT_MODE_ONE_SHOT_DISABLE;
8607 tw32(MSGINT_MODE, val);
8615 /* Returns 0 if MSI test succeeds or MSI test fails and INTx mode is
8616 * successfully restored
8618 static int tg3_test_msi(struct tg3 *tp)
8623 if (!(tp->tg3_flags2 & TG3_FLG2_USING_MSI))
8626 /* Turn off SERR reporting in case MSI terminates with Master
8629 pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd);
8630 pci_write_config_word(tp->pdev, PCI_COMMAND,
8631 pci_cmd & ~PCI_COMMAND_SERR);
8633 err = tg3_test_interrupt(tp);
8635 pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd);
8640 /* other failures */
8644 /* MSI test failed, go back to INTx mode */
8645 netdev_warn(tp->dev, "No interrupt was generated using MSI. Switching "
8646 "to INTx mode. Please report this failure to the PCI "
8647 "maintainer and include system chipset information\n");
8649 free_irq(tp->napi[0].irq_vec, &tp->napi[0]);
8651 pci_disable_msi(tp->pdev);
8653 tp->tg3_flags2 &= ~TG3_FLG2_USING_MSI;
8655 err = tg3_request_irq(tp, 0);
8659 /* Need to reset the chip because the MSI cycle may have terminated
8660 * with Master Abort.
8662 tg3_full_lock(tp, 1);
8664 tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
8665 err = tg3_init_hw(tp, 1);
8667 tg3_full_unlock(tp);
8670 free_irq(tp->napi[0].irq_vec, &tp->napi[0]);
8675 static int tg3_request_firmware(struct tg3 *tp)
8677 const __be32 *fw_data;
8679 if (request_firmware(&tp->fw, tp->fw_needed, &tp->pdev->dev)) {
8680 netdev_err(tp->dev, "Failed to load firmware \"%s\"\n",
8685 fw_data = (void *)tp->fw->data;
8687 /* Firmware blob starts with version numbers, followed by
8688 * start address and _full_ length including BSS sections
8689 * (which must be longer than the actual data, of course
8692 tp->fw_len = be32_to_cpu(fw_data[2]); /* includes bss */
8693 if (tp->fw_len < (tp->fw->size - 12)) {
8694 netdev_err(tp->dev, "bogus length %d in \"%s\"\n",
8695 tp->fw_len, tp->fw_needed);
8696 release_firmware(tp->fw);
8701 /* We no longer need firmware; we have it. */
8702 tp->fw_needed = NULL;
8706 static bool tg3_enable_msix(struct tg3 *tp)
8708 int i, rc, cpus = num_online_cpus();
8709 struct msix_entry msix_ent[tp->irq_max];
8712 /* Just fallback to the simpler MSI mode. */
8716 * We want as many rx rings enabled as there are cpus.
8717 * The first MSIX vector only deals with link interrupts, etc,
8718 * so we add one to the number of vectors we are requesting.
8720 tp->irq_cnt = min_t(unsigned, cpus + 1, tp->irq_max);
8722 for (i = 0; i < tp->irq_max; i++) {
8723 msix_ent[i].entry = i;
8724 msix_ent[i].vector = 0;
8727 rc = pci_enable_msix(tp->pdev, msix_ent, tp->irq_cnt);
8729 if (rc < TG3_RSS_MIN_NUM_MSIX_VECS)
8731 if (pci_enable_msix(tp->pdev, msix_ent, rc))
8733 netdev_notice(tp->dev, "Requested %d MSI-X vectors, received %d\n",
8738 tp->tg3_flags3 |= TG3_FLG3_ENABLE_RSS;
8740 for (i = 0; i < tp->irq_max; i++)
8741 tp->napi[i].irq_vec = msix_ent[i].vector;
8743 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717) {
8744 tp->tg3_flags3 |= TG3_FLG3_ENABLE_TSS;
8745 tp->dev->real_num_tx_queues = tp->irq_cnt - 1;
8747 tp->dev->real_num_tx_queues = 1;
8752 static void tg3_ints_init(struct tg3 *tp)
8754 if ((tp->tg3_flags & TG3_FLAG_SUPPORT_MSI_OR_MSIX) &&
8755 !(tp->tg3_flags & TG3_FLAG_TAGGED_STATUS)) {
8756 /* All MSI supporting chips should support tagged
8757 * status. Assert that this is the case.
8759 netdev_warn(tp->dev,
8760 "MSI without TAGGED_STATUS? Not using MSI\n");
8764 if ((tp->tg3_flags & TG3_FLAG_SUPPORT_MSIX) && tg3_enable_msix(tp))
8765 tp->tg3_flags2 |= TG3_FLG2_USING_MSIX;
8766 else if ((tp->tg3_flags & TG3_FLAG_SUPPORT_MSI) &&
8767 pci_enable_msi(tp->pdev) == 0)
8768 tp->tg3_flags2 |= TG3_FLG2_USING_MSI;
8770 if (tp->tg3_flags2 & TG3_FLG2_USING_MSI_OR_MSIX) {
8771 u32 msi_mode = tr32(MSGINT_MODE);
8772 if (tp->tg3_flags2 & TG3_FLG2_USING_MSIX)
8773 msi_mode |= MSGINT_MODE_MULTIVEC_EN;
8774 tw32(MSGINT_MODE, msi_mode | MSGINT_MODE_ENABLE);
8777 if (!(tp->tg3_flags2 & TG3_FLG2_USING_MSIX)) {
8779 tp->napi[0].irq_vec = tp->pdev->irq;
8780 tp->dev->real_num_tx_queues = 1;
8784 static void tg3_ints_fini(struct tg3 *tp)
8786 if (tp->tg3_flags2 & TG3_FLG2_USING_MSIX)
8787 pci_disable_msix(tp->pdev);
8788 else if (tp->tg3_flags2 & TG3_FLG2_USING_MSI)
8789 pci_disable_msi(tp->pdev);
8790 tp->tg3_flags2 &= ~TG3_FLG2_USING_MSI_OR_MSIX;
8791 tp->tg3_flags3 &= ~TG3_FLG3_ENABLE_RSS;
8794 static int tg3_open(struct net_device *dev)
8796 struct tg3 *tp = netdev_priv(dev);
8799 if (tp->fw_needed) {
8800 err = tg3_request_firmware(tp);
8801 if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0) {
8805 netdev_warn(tp->dev, "TSO capability disabled\n");
8806 tp->tg3_flags2 &= ~TG3_FLG2_TSO_CAPABLE;
8807 } else if (!(tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE)) {
8808 netdev_notice(tp->dev, "TSO capability restored\n");
8809 tp->tg3_flags2 |= TG3_FLG2_TSO_CAPABLE;
8813 netif_carrier_off(tp->dev);
8815 err = tg3_set_power_state(tp, PCI_D0);
8819 tg3_full_lock(tp, 0);
8821 tg3_disable_ints(tp);
8822 tp->tg3_flags &= ~TG3_FLAG_INIT_COMPLETE;
8824 tg3_full_unlock(tp);
8827 * Setup interrupts first so we know how
8828 * many NAPI resources to allocate
8832 /* The placement of this call is tied
8833 * to the setup and use of Host TX descriptors.
8835 err = tg3_alloc_consistent(tp);
8839 tg3_napi_enable(tp);
8841 for (i = 0; i < tp->irq_cnt; i++) {
8842 struct tg3_napi *tnapi = &tp->napi[i];
8843 err = tg3_request_irq(tp, i);
8845 for (i--; i >= 0; i--)
8846 free_irq(tnapi->irq_vec, tnapi);
8854 tg3_full_lock(tp, 0);
8856 err = tg3_init_hw(tp, 1);
8858 tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
8861 if (tp->tg3_flags & TG3_FLAG_TAGGED_STATUS)
8862 tp->timer_offset = HZ;
8864 tp->timer_offset = HZ / 10;
8866 BUG_ON(tp->timer_offset > HZ);
8867 tp->timer_counter = tp->timer_multiplier =
8868 (HZ / tp->timer_offset);
8869 tp->asf_counter = tp->asf_multiplier =
8870 ((HZ / tp->timer_offset) * 2);
8872 init_timer(&tp->timer);
8873 tp->timer.expires = jiffies + tp->timer_offset;
8874 tp->timer.data = (unsigned long) tp;
8875 tp->timer.function = tg3_timer;
8878 tg3_full_unlock(tp);
8883 if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
8884 err = tg3_test_msi(tp);
8887 tg3_full_lock(tp, 0);
8888 tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
8890 tg3_full_unlock(tp);
8895 if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5717 &&
8896 GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_57765 &&
8897 (tp->tg3_flags2 & TG3_FLG2_USING_MSI) &&
8898 (tp->tg3_flags2 & TG3_FLG2_1SHOT_MSI)) {
8899 u32 val = tr32(PCIE_TRANSACTION_CFG);
8901 tw32(PCIE_TRANSACTION_CFG,
8902 val | PCIE_TRANS_CFG_1SHOT_MSI);
8908 tg3_full_lock(tp, 0);
8910 add_timer(&tp->timer);
8911 tp->tg3_flags |= TG3_FLAG_INIT_COMPLETE;
8912 tg3_enable_ints(tp);
8914 tg3_full_unlock(tp);
8916 netif_tx_start_all_queues(dev);
8921 for (i = tp->irq_cnt - 1; i >= 0; i--) {
8922 struct tg3_napi *tnapi = &tp->napi[i];
8923 free_irq(tnapi->irq_vec, tnapi);
8927 tg3_napi_disable(tp);
8928 tg3_free_consistent(tp);
8936 /*static*/ void tg3_dump_state(struct tg3 *tp)
8938 u32 val32, val32_2, val32_3, val32_4, val32_5;
8941 struct tg3_hw_status *sblk = tp->napi[0]->hw_status;
8943 pci_read_config_word(tp->pdev, PCI_STATUS, &val16);
8944 pci_read_config_dword(tp->pdev, TG3PCI_PCISTATE, &val32);
8945 printk("DEBUG: PCI status [%04x] TG3PCI state[%08x]\n",
8949 printk("DEBUG: MAC_MODE[%08x] MAC_STATUS[%08x]\n",
8950 tr32(MAC_MODE), tr32(MAC_STATUS));
8951 printk(" MAC_EVENT[%08x] MAC_LED_CTRL[%08x]\n",
8952 tr32(MAC_EVENT), tr32(MAC_LED_CTRL));
8953 printk("DEBUG: MAC_TX_MODE[%08x] MAC_TX_STATUS[%08x]\n",
8954 tr32(MAC_TX_MODE), tr32(MAC_TX_STATUS));
8955 printk(" MAC_RX_MODE[%08x] MAC_RX_STATUS[%08x]\n",
8956 tr32(MAC_RX_MODE), tr32(MAC_RX_STATUS));
8958 /* Send data initiator control block */
8959 printk("DEBUG: SNDDATAI_MODE[%08x] SNDDATAI_STATUS[%08x]\n",
8960 tr32(SNDDATAI_MODE), tr32(SNDDATAI_STATUS));
8961 printk(" SNDDATAI_STATSCTRL[%08x]\n",
8962 tr32(SNDDATAI_STATSCTRL));
8964 /* Send data completion control block */
8965 printk("DEBUG: SNDDATAC_MODE[%08x]\n", tr32(SNDDATAC_MODE));
8967 /* Send BD ring selector block */
8968 printk("DEBUG: SNDBDS_MODE[%08x] SNDBDS_STATUS[%08x]\n",
8969 tr32(SNDBDS_MODE), tr32(SNDBDS_STATUS));
8971 /* Send BD initiator control block */
8972 printk("DEBUG: SNDBDI_MODE[%08x] SNDBDI_STATUS[%08x]\n",
8973 tr32(SNDBDI_MODE), tr32(SNDBDI_STATUS));
8975 /* Send BD completion control block */
8976 printk("DEBUG: SNDBDC_MODE[%08x]\n", tr32(SNDBDC_MODE));
8978 /* Receive list placement control block */
8979 printk("DEBUG: RCVLPC_MODE[%08x] RCVLPC_STATUS[%08x]\n",
8980 tr32(RCVLPC_MODE), tr32(RCVLPC_STATUS));
8981 printk(" RCVLPC_STATSCTRL[%08x]\n",
8982 tr32(RCVLPC_STATSCTRL));
8984 /* Receive data and receive BD initiator control block */
8985 printk("DEBUG: RCVDBDI_MODE[%08x] RCVDBDI_STATUS[%08x]\n",
8986 tr32(RCVDBDI_MODE), tr32(RCVDBDI_STATUS));
8988 /* Receive data completion control block */
8989 printk("DEBUG: RCVDCC_MODE[%08x]\n",
8992 /* Receive BD initiator control block */
8993 printk("DEBUG: RCVBDI_MODE[%08x] RCVBDI_STATUS[%08x]\n",
8994 tr32(RCVBDI_MODE), tr32(RCVBDI_STATUS));
8996 /* Receive BD completion control block */
8997 printk("DEBUG: RCVCC_MODE[%08x] RCVCC_STATUS[%08x]\n",
8998 tr32(RCVCC_MODE), tr32(RCVCC_STATUS));
9000 /* Receive list selector control block */
9001 printk("DEBUG: RCVLSC_MODE[%08x] RCVLSC_STATUS[%08x]\n",
9002 tr32(RCVLSC_MODE), tr32(RCVLSC_STATUS));
9004 /* Mbuf cluster free block */
9005 printk("DEBUG: MBFREE_MODE[%08x] MBFREE_STATUS[%08x]\n",
9006 tr32(MBFREE_MODE), tr32(MBFREE_STATUS));
9008 /* Host coalescing control block */
9009 printk("DEBUG: HOSTCC_MODE[%08x] HOSTCC_STATUS[%08x]\n",
9010 tr32(HOSTCC_MODE), tr32(HOSTCC_STATUS));
9011 printk("DEBUG: HOSTCC_STATS_BLK_HOST_ADDR[%08x%08x]\n",
9012 tr32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH),
9013 tr32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW));
9014 printk("DEBUG: HOSTCC_STATUS_BLK_HOST_ADDR[%08x%08x]\n",
9015 tr32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH),
9016 tr32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW));
9017 printk("DEBUG: HOSTCC_STATS_BLK_NIC_ADDR[%08x]\n",
9018 tr32(HOSTCC_STATS_BLK_NIC_ADDR));
9019 printk("DEBUG: HOSTCC_STATUS_BLK_NIC_ADDR[%08x]\n",
9020 tr32(HOSTCC_STATUS_BLK_NIC_ADDR));
9022 /* Memory arbiter control block */
9023 printk("DEBUG: MEMARB_MODE[%08x] MEMARB_STATUS[%08x]\n",
9024 tr32(MEMARB_MODE), tr32(MEMARB_STATUS));
9026 /* Buffer manager control block */
9027 printk("DEBUG: BUFMGR_MODE[%08x] BUFMGR_STATUS[%08x]\n",
9028 tr32(BUFMGR_MODE), tr32(BUFMGR_STATUS));
9029 printk("DEBUG: BUFMGR_MB_POOL_ADDR[%08x] BUFMGR_MB_POOL_SIZE[%08x]\n",
9030 tr32(BUFMGR_MB_POOL_ADDR), tr32(BUFMGR_MB_POOL_SIZE));
9031 printk("DEBUG: BUFMGR_DMA_DESC_POOL_ADDR[%08x] "
9032 "BUFMGR_DMA_DESC_POOL_SIZE[%08x]\n",
9033 tr32(BUFMGR_DMA_DESC_POOL_ADDR),
9034 tr32(BUFMGR_DMA_DESC_POOL_SIZE));
9036 /* Read DMA control block */
9037 printk("DEBUG: RDMAC_MODE[%08x] RDMAC_STATUS[%08x]\n",
9038 tr32(RDMAC_MODE), tr32(RDMAC_STATUS));
9040 /* Write DMA control block */
9041 printk("DEBUG: WDMAC_MODE[%08x] WDMAC_STATUS[%08x]\n",
9042 tr32(WDMAC_MODE), tr32(WDMAC_STATUS));
9044 /* DMA completion block */
9045 printk("DEBUG: DMAC_MODE[%08x]\n",
9049 printk("DEBUG: GRC_MODE[%08x] GRC_MISC_CFG[%08x]\n",
9050 tr32(GRC_MODE), tr32(GRC_MISC_CFG));
9051 printk("DEBUG: GRC_LOCAL_CTRL[%08x]\n",
9052 tr32(GRC_LOCAL_CTRL));
9055 printk("DEBUG: RCVDBDI_JUMBO_BD[%08x%08x:%08x:%08x]\n",
9056 tr32(RCVDBDI_JUMBO_BD + 0x0),
9057 tr32(RCVDBDI_JUMBO_BD + 0x4),
9058 tr32(RCVDBDI_JUMBO_BD + 0x8),
9059 tr32(RCVDBDI_JUMBO_BD + 0xc));
9060 printk("DEBUG: RCVDBDI_STD_BD[%08x%08x:%08x:%08x]\n",
9061 tr32(RCVDBDI_STD_BD + 0x0),
9062 tr32(RCVDBDI_STD_BD + 0x4),
9063 tr32(RCVDBDI_STD_BD + 0x8),
9064 tr32(RCVDBDI_STD_BD + 0xc));
9065 printk("DEBUG: RCVDBDI_MINI_BD[%08x%08x:%08x:%08x]\n",
9066 tr32(RCVDBDI_MINI_BD + 0x0),
9067 tr32(RCVDBDI_MINI_BD + 0x4),
9068 tr32(RCVDBDI_MINI_BD + 0x8),
9069 tr32(RCVDBDI_MINI_BD + 0xc));
9071 tg3_read_mem(tp, NIC_SRAM_SEND_RCB + 0x0, &val32);
9072 tg3_read_mem(tp, NIC_SRAM_SEND_RCB + 0x4, &val32_2);
9073 tg3_read_mem(tp, NIC_SRAM_SEND_RCB + 0x8, &val32_3);
9074 tg3_read_mem(tp, NIC_SRAM_SEND_RCB + 0xc, &val32_4);
9075 printk("DEBUG: SRAM_SEND_RCB_0[%08x%08x:%08x:%08x]\n",
9076 val32, val32_2, val32_3, val32_4);
9078 tg3_read_mem(tp, NIC_SRAM_RCV_RET_RCB + 0x0, &val32);
9079 tg3_read_mem(tp, NIC_SRAM_RCV_RET_RCB + 0x4, &val32_2);
9080 tg3_read_mem(tp, NIC_SRAM_RCV_RET_RCB + 0x8, &val32_3);
9081 tg3_read_mem(tp, NIC_SRAM_RCV_RET_RCB + 0xc, &val32_4);
9082 printk("DEBUG: SRAM_RCV_RET_RCB_0[%08x%08x:%08x:%08x]\n",
9083 val32, val32_2, val32_3, val32_4);
9085 tg3_read_mem(tp, NIC_SRAM_STATUS_BLK + 0x0, &val32);
9086 tg3_read_mem(tp, NIC_SRAM_STATUS_BLK + 0x4, &val32_2);
9087 tg3_read_mem(tp, NIC_SRAM_STATUS_BLK + 0x8, &val32_3);
9088 tg3_read_mem(tp, NIC_SRAM_STATUS_BLK + 0xc, &val32_4);
9089 tg3_read_mem(tp, NIC_SRAM_STATUS_BLK + 0x10, &val32_5);
9090 printk("DEBUG: SRAM_STATUS_BLK[%08x:%08x:%08x:%08x:%08x]\n",
9091 val32, val32_2, val32_3, val32_4, val32_5);
9093 /* SW status block */
9095 "Host status block [%08x:%08x:(%04x:%04x:%04x):(%04x:%04x)]\n",
9098 sblk->rx_jumbo_consumer,
9100 sblk->rx_mini_consumer,
9101 sblk->idx[0].rx_producer,
9102 sblk->idx[0].tx_consumer);
9104 /* SW statistics block */
9105 printk("DEBUG: Host statistics block [%08x:%08x:%08x:%08x]\n",
9106 ((u32 *)tp->hw_stats)[0],
9107 ((u32 *)tp->hw_stats)[1],
9108 ((u32 *)tp->hw_stats)[2],
9109 ((u32 *)tp->hw_stats)[3]);
9112 printk("DEBUG: SNDHOST_PROD[%08x%08x] SNDNIC_PROD[%08x%08x]\n",
9113 tr32_mailbox(MAILBOX_SNDHOST_PROD_IDX_0 + 0x0),
9114 tr32_mailbox(MAILBOX_SNDHOST_PROD_IDX_0 + 0x4),
9115 tr32_mailbox(MAILBOX_SNDNIC_PROD_IDX_0 + 0x0),
9116 tr32_mailbox(MAILBOX_SNDNIC_PROD_IDX_0 + 0x4));
9118 /* NIC side send descriptors. */
9119 for (i = 0; i < 6; i++) {
9122 txd = tp->regs + NIC_SRAM_WIN_BASE + NIC_SRAM_TX_BUFFER_DESC
9123 + (i * sizeof(struct tg3_tx_buffer_desc));
9124 printk("DEBUG: NIC TXD(%d)[%08x:%08x:%08x:%08x]\n",
9126 readl(txd + 0x0), readl(txd + 0x4),
9127 readl(txd + 0x8), readl(txd + 0xc));
9130 /* NIC side RX descriptors. */
9131 for (i = 0; i < 6; i++) {
9134 rxd = tp->regs + NIC_SRAM_WIN_BASE + NIC_SRAM_RX_BUFFER_DESC
9135 + (i * sizeof(struct tg3_rx_buffer_desc));
9136 printk("DEBUG: NIC RXD_STD(%d)[0][%08x:%08x:%08x:%08x]\n",
9138 readl(rxd + 0x0), readl(rxd + 0x4),
9139 readl(rxd + 0x8), readl(rxd + 0xc));
9140 rxd += (4 * sizeof(u32));
9141 printk("DEBUG: NIC RXD_STD(%d)[1][%08x:%08x:%08x:%08x]\n",
9143 readl(rxd + 0x0), readl(rxd + 0x4),
9144 readl(rxd + 0x8), readl(rxd + 0xc));
9147 for (i = 0; i < 6; i++) {
9150 rxd = tp->regs + NIC_SRAM_WIN_BASE + NIC_SRAM_RX_JUMBO_BUFFER_DESC
9151 + (i * sizeof(struct tg3_rx_buffer_desc));
9152 printk("DEBUG: NIC RXD_JUMBO(%d)[0][%08x:%08x:%08x:%08x]\n",
9154 readl(rxd + 0x0), readl(rxd + 0x4),
9155 readl(rxd + 0x8), readl(rxd + 0xc));
9156 rxd += (4 * sizeof(u32));
9157 printk("DEBUG: NIC RXD_JUMBO(%d)[1][%08x:%08x:%08x:%08x]\n",
9159 readl(rxd + 0x0), readl(rxd + 0x4),
9160 readl(rxd + 0x8), readl(rxd + 0xc));
9165 static struct net_device_stats *tg3_get_stats(struct net_device *);
9166 static struct tg3_ethtool_stats *tg3_get_estats(struct tg3 *);
9168 static int tg3_close(struct net_device *dev)
9171 struct tg3 *tp = netdev_priv(dev);
9173 tg3_napi_disable(tp);
9174 cancel_work_sync(&tp->reset_task);
9176 netif_tx_stop_all_queues(dev);
9178 del_timer_sync(&tp->timer);
9182 tg3_full_lock(tp, 1);
9187 tg3_disable_ints(tp);
9189 tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
9191 tp->tg3_flags &= ~TG3_FLAG_INIT_COMPLETE;
9193 tg3_full_unlock(tp);
9195 for (i = tp->irq_cnt - 1; i >= 0; i--) {
9196 struct tg3_napi *tnapi = &tp->napi[i];
9197 free_irq(tnapi->irq_vec, tnapi);
9202 memcpy(&tp->net_stats_prev, tg3_get_stats(tp->dev),
9203 sizeof(tp->net_stats_prev));
9204 memcpy(&tp->estats_prev, tg3_get_estats(tp),
9205 sizeof(tp->estats_prev));
9207 tg3_free_consistent(tp);
9209 tg3_set_power_state(tp, PCI_D3hot);
9211 netif_carrier_off(tp->dev);
9216 static inline unsigned long get_stat64(tg3_stat64_t *val)
9220 #if (BITS_PER_LONG == 32)
9223 ret = ((u64)val->high << 32) | ((u64)val->low);
9228 static inline u64 get_estat64(tg3_stat64_t *val)
9230 return ((u64)val->high << 32) | ((u64)val->low);
9233 static unsigned long calc_crc_errors(struct tg3 *tp)
9235 struct tg3_hw_stats *hw_stats = tp->hw_stats;
9237 if (!(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) &&
9238 (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
9239 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701)) {
9242 spin_lock_bh(&tp->lock);
9243 if (!tg3_readphy(tp, MII_TG3_TEST1, &val)) {
9244 tg3_writephy(tp, MII_TG3_TEST1,
9245 val | MII_TG3_TEST1_CRC_EN);
9246 tg3_readphy(tp, 0x14, &val);
9249 spin_unlock_bh(&tp->lock);
9251 tp->phy_crc_errors += val;
9253 return tp->phy_crc_errors;
9256 return get_stat64(&hw_stats->rx_fcs_errors);
9259 #define ESTAT_ADD(member) \
9260 estats->member = old_estats->member + \
9261 get_estat64(&hw_stats->member)
9263 static struct tg3_ethtool_stats *tg3_get_estats(struct tg3 *tp)
9265 struct tg3_ethtool_stats *estats = &tp->estats;
9266 struct tg3_ethtool_stats *old_estats = &tp->estats_prev;
9267 struct tg3_hw_stats *hw_stats = tp->hw_stats;
9272 ESTAT_ADD(rx_octets);
9273 ESTAT_ADD(rx_fragments);
9274 ESTAT_ADD(rx_ucast_packets);
9275 ESTAT_ADD(rx_mcast_packets);
9276 ESTAT_ADD(rx_bcast_packets);
9277 ESTAT_ADD(rx_fcs_errors);
9278 ESTAT_ADD(rx_align_errors);
9279 ESTAT_ADD(rx_xon_pause_rcvd);
9280 ESTAT_ADD(rx_xoff_pause_rcvd);
9281 ESTAT_ADD(rx_mac_ctrl_rcvd);
9282 ESTAT_ADD(rx_xoff_entered);
9283 ESTAT_ADD(rx_frame_too_long_errors);
9284 ESTAT_ADD(rx_jabbers);
9285 ESTAT_ADD(rx_undersize_packets);
9286 ESTAT_ADD(rx_in_length_errors);
9287 ESTAT_ADD(rx_out_length_errors);
9288 ESTAT_ADD(rx_64_or_less_octet_packets);
9289 ESTAT_ADD(rx_65_to_127_octet_packets);
9290 ESTAT_ADD(rx_128_to_255_octet_packets);
9291 ESTAT_ADD(rx_256_to_511_octet_packets);
9292 ESTAT_ADD(rx_512_to_1023_octet_packets);
9293 ESTAT_ADD(rx_1024_to_1522_octet_packets);
9294 ESTAT_ADD(rx_1523_to_2047_octet_packets);
9295 ESTAT_ADD(rx_2048_to_4095_octet_packets);
9296 ESTAT_ADD(rx_4096_to_8191_octet_packets);
9297 ESTAT_ADD(rx_8192_to_9022_octet_packets);
9299 ESTAT_ADD(tx_octets);
9300 ESTAT_ADD(tx_collisions);
9301 ESTAT_ADD(tx_xon_sent);
9302 ESTAT_ADD(tx_xoff_sent);
9303 ESTAT_ADD(tx_flow_control);
9304 ESTAT_ADD(tx_mac_errors);
9305 ESTAT_ADD(tx_single_collisions);
9306 ESTAT_ADD(tx_mult_collisions);
9307 ESTAT_ADD(tx_deferred);
9308 ESTAT_ADD(tx_excessive_collisions);
9309 ESTAT_ADD(tx_late_collisions);
9310 ESTAT_ADD(tx_collide_2times);
9311 ESTAT_ADD(tx_collide_3times);
9312 ESTAT_ADD(tx_collide_4times);
9313 ESTAT_ADD(tx_collide_5times);
9314 ESTAT_ADD(tx_collide_6times);
9315 ESTAT_ADD(tx_collide_7times);
9316 ESTAT_ADD(tx_collide_8times);
9317 ESTAT_ADD(tx_collide_9times);
9318 ESTAT_ADD(tx_collide_10times);
9319 ESTAT_ADD(tx_collide_11times);
9320 ESTAT_ADD(tx_collide_12times);
9321 ESTAT_ADD(tx_collide_13times);
9322 ESTAT_ADD(tx_collide_14times);
9323 ESTAT_ADD(tx_collide_15times);
9324 ESTAT_ADD(tx_ucast_packets);
9325 ESTAT_ADD(tx_mcast_packets);
9326 ESTAT_ADD(tx_bcast_packets);
9327 ESTAT_ADD(tx_carrier_sense_errors);
9328 ESTAT_ADD(tx_discards);
9329 ESTAT_ADD(tx_errors);
9331 ESTAT_ADD(dma_writeq_full);
9332 ESTAT_ADD(dma_write_prioq_full);
9333 ESTAT_ADD(rxbds_empty);
9334 ESTAT_ADD(rx_discards);
9335 ESTAT_ADD(rx_errors);
9336 ESTAT_ADD(rx_threshold_hit);
9338 ESTAT_ADD(dma_readq_full);
9339 ESTAT_ADD(dma_read_prioq_full);
9340 ESTAT_ADD(tx_comp_queue_full);
9342 ESTAT_ADD(ring_set_send_prod_index);
9343 ESTAT_ADD(ring_status_update);
9344 ESTAT_ADD(nic_irqs);
9345 ESTAT_ADD(nic_avoided_irqs);
9346 ESTAT_ADD(nic_tx_threshold_hit);
9351 static struct net_device_stats *tg3_get_stats(struct net_device *dev)
9353 struct tg3 *tp = netdev_priv(dev);
9354 struct net_device_stats *stats = &tp->net_stats;
9355 struct net_device_stats *old_stats = &tp->net_stats_prev;
9356 struct tg3_hw_stats *hw_stats = tp->hw_stats;
9361 stats->rx_packets = old_stats->rx_packets +
9362 get_stat64(&hw_stats->rx_ucast_packets) +
9363 get_stat64(&hw_stats->rx_mcast_packets) +
9364 get_stat64(&hw_stats->rx_bcast_packets);
9366 stats->tx_packets = old_stats->tx_packets +
9367 get_stat64(&hw_stats->tx_ucast_packets) +
9368 get_stat64(&hw_stats->tx_mcast_packets) +
9369 get_stat64(&hw_stats->tx_bcast_packets);
9371 stats->rx_bytes = old_stats->rx_bytes +
9372 get_stat64(&hw_stats->rx_octets);
9373 stats->tx_bytes = old_stats->tx_bytes +
9374 get_stat64(&hw_stats->tx_octets);
9376 stats->rx_errors = old_stats->rx_errors +
9377 get_stat64(&hw_stats->rx_errors);
9378 stats->tx_errors = old_stats->tx_errors +
9379 get_stat64(&hw_stats->tx_errors) +
9380 get_stat64(&hw_stats->tx_mac_errors) +
9381 get_stat64(&hw_stats->tx_carrier_sense_errors) +
9382 get_stat64(&hw_stats->tx_discards);
9384 stats->multicast = old_stats->multicast +
9385 get_stat64(&hw_stats->rx_mcast_packets);
9386 stats->collisions = old_stats->collisions +
9387 get_stat64(&hw_stats->tx_collisions);
9389 stats->rx_length_errors = old_stats->rx_length_errors +
9390 get_stat64(&hw_stats->rx_frame_too_long_errors) +
9391 get_stat64(&hw_stats->rx_undersize_packets);
9393 stats->rx_over_errors = old_stats->rx_over_errors +
9394 get_stat64(&hw_stats->rxbds_empty);
9395 stats->rx_frame_errors = old_stats->rx_frame_errors +
9396 get_stat64(&hw_stats->rx_align_errors);
9397 stats->tx_aborted_errors = old_stats->tx_aborted_errors +
9398 get_stat64(&hw_stats->tx_discards);
9399 stats->tx_carrier_errors = old_stats->tx_carrier_errors +
9400 get_stat64(&hw_stats->tx_carrier_sense_errors);
9402 stats->rx_crc_errors = old_stats->rx_crc_errors +
9403 calc_crc_errors(tp);
9405 stats->rx_missed_errors = old_stats->rx_missed_errors +
9406 get_stat64(&hw_stats->rx_discards);
9411 static inline u32 calc_crc(unsigned char *buf, int len)
9419 for (j = 0; j < len; j++) {
9422 for (k = 0; k < 8; k++) {
9436 static void tg3_set_multi(struct tg3 *tp, unsigned int accept_all)
9438 /* accept or reject all multicast frames */
9439 tw32(MAC_HASH_REG_0, accept_all ? 0xffffffff : 0);
9440 tw32(MAC_HASH_REG_1, accept_all ? 0xffffffff : 0);
9441 tw32(MAC_HASH_REG_2, accept_all ? 0xffffffff : 0);
9442 tw32(MAC_HASH_REG_3, accept_all ? 0xffffffff : 0);
9445 static void __tg3_set_rx_mode(struct net_device *dev)
9447 struct tg3 *tp = netdev_priv(dev);
9450 rx_mode = tp->rx_mode & ~(RX_MODE_PROMISC |
9451 RX_MODE_KEEP_VLAN_TAG);
9453 /* When ASF is in use, we always keep the RX_MODE_KEEP_VLAN_TAG
9456 #if TG3_VLAN_TAG_USED
9458 !(tp->tg3_flags & TG3_FLAG_ENABLE_ASF))
9459 rx_mode |= RX_MODE_KEEP_VLAN_TAG;
9461 /* By definition, VLAN is disabled always in this
9464 if (!(tp->tg3_flags & TG3_FLAG_ENABLE_ASF))
9465 rx_mode |= RX_MODE_KEEP_VLAN_TAG;
9468 if (dev->flags & IFF_PROMISC) {
9469 /* Promiscuous mode. */
9470 rx_mode |= RX_MODE_PROMISC;
9471 } else if (dev->flags & IFF_ALLMULTI) {
9472 /* Accept all multicast. */
9473 tg3_set_multi (tp, 1);
9474 } else if (netdev_mc_empty(dev)) {
9475 /* Reject all multicast. */
9476 tg3_set_multi (tp, 0);
9478 /* Accept one or more multicast(s). */
9479 struct netdev_hw_addr *ha;
9480 u32 mc_filter[4] = { 0, };
9485 netdev_for_each_mc_addr(ha, dev) {
9486 crc = calc_crc(ha->addr, ETH_ALEN);
9488 regidx = (bit & 0x60) >> 5;
9490 mc_filter[regidx] |= (1 << bit);
9493 tw32(MAC_HASH_REG_0, mc_filter[0]);
9494 tw32(MAC_HASH_REG_1, mc_filter[1]);
9495 tw32(MAC_HASH_REG_2, mc_filter[2]);
9496 tw32(MAC_HASH_REG_3, mc_filter[3]);
9499 if (rx_mode != tp->rx_mode) {
9500 tp->rx_mode = rx_mode;
9501 tw32_f(MAC_RX_MODE, rx_mode);
9506 static void tg3_set_rx_mode(struct net_device *dev)
9508 struct tg3 *tp = netdev_priv(dev);
9510 if (!netif_running(dev))
9513 tg3_full_lock(tp, 0);
9514 __tg3_set_rx_mode(dev);
9515 tg3_full_unlock(tp);
9518 #define TG3_REGDUMP_LEN (32 * 1024)
9520 static int tg3_get_regs_len(struct net_device *dev)
9522 return TG3_REGDUMP_LEN;
9525 static void tg3_get_regs(struct net_device *dev,
9526 struct ethtool_regs *regs, void *_p)
9529 struct tg3 *tp = netdev_priv(dev);
9535 memset(p, 0, TG3_REGDUMP_LEN);
9537 if (tp->link_config.phy_is_low_power)
9540 tg3_full_lock(tp, 0);
9542 #define __GET_REG32(reg) (*(p)++ = tr32(reg))
9543 #define GET_REG32_LOOP(base,len) \
9544 do { p = (u32 *)(orig_p + (base)); \
9545 for (i = 0; i < len; i += 4) \
9546 __GET_REG32((base) + i); \
9548 #define GET_REG32_1(reg) \
9549 do { p = (u32 *)(orig_p + (reg)); \
9550 __GET_REG32((reg)); \
9553 GET_REG32_LOOP(TG3PCI_VENDOR, 0xb0);
9554 GET_REG32_LOOP(MAILBOX_INTERRUPT_0, 0x200);
9555 GET_REG32_LOOP(MAC_MODE, 0x4f0);
9556 GET_REG32_LOOP(SNDDATAI_MODE, 0xe0);
9557 GET_REG32_1(SNDDATAC_MODE);
9558 GET_REG32_LOOP(SNDBDS_MODE, 0x80);
9559 GET_REG32_LOOP(SNDBDI_MODE, 0x48);
9560 GET_REG32_1(SNDBDC_MODE);
9561 GET_REG32_LOOP(RCVLPC_MODE, 0x20);
9562 GET_REG32_LOOP(RCVLPC_SELLST_BASE, 0x15c);
9563 GET_REG32_LOOP(RCVDBDI_MODE, 0x0c);
9564 GET_REG32_LOOP(RCVDBDI_JUMBO_BD, 0x3c);
9565 GET_REG32_LOOP(RCVDBDI_BD_PROD_IDX_0, 0x44);
9566 GET_REG32_1(RCVDCC_MODE);
9567 GET_REG32_LOOP(RCVBDI_MODE, 0x20);
9568 GET_REG32_LOOP(RCVCC_MODE, 0x14);
9569 GET_REG32_LOOP(RCVLSC_MODE, 0x08);
9570 GET_REG32_1(MBFREE_MODE);
9571 GET_REG32_LOOP(HOSTCC_MODE, 0x100);
9572 GET_REG32_LOOP(MEMARB_MODE, 0x10);
9573 GET_REG32_LOOP(BUFMGR_MODE, 0x58);
9574 GET_REG32_LOOP(RDMAC_MODE, 0x08);
9575 GET_REG32_LOOP(WDMAC_MODE, 0x08);
9576 GET_REG32_1(RX_CPU_MODE);
9577 GET_REG32_1(RX_CPU_STATE);
9578 GET_REG32_1(RX_CPU_PGMCTR);
9579 GET_REG32_1(RX_CPU_HWBKPT);
9580 GET_REG32_1(TX_CPU_MODE);
9581 GET_REG32_1(TX_CPU_STATE);
9582 GET_REG32_1(TX_CPU_PGMCTR);
9583 GET_REG32_LOOP(GRCMBOX_INTERRUPT_0, 0x110);
9584 GET_REG32_LOOP(FTQ_RESET, 0x120);
9585 GET_REG32_LOOP(MSGINT_MODE, 0x0c);
9586 GET_REG32_1(DMAC_MODE);
9587 GET_REG32_LOOP(GRC_MODE, 0x4c);
9588 if (tp->tg3_flags & TG3_FLAG_NVRAM)
9589 GET_REG32_LOOP(NVRAM_CMD, 0x24);
9592 #undef GET_REG32_LOOP
9595 tg3_full_unlock(tp);
9598 static int tg3_get_eeprom_len(struct net_device *dev)
9600 struct tg3 *tp = netdev_priv(dev);
9602 return tp->nvram_size;
9605 static int tg3_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, u8 *data)
9607 struct tg3 *tp = netdev_priv(dev);
9610 u32 i, offset, len, b_offset, b_count;
9613 if (tp->tg3_flags3 & TG3_FLG3_NO_NVRAM)
9616 if (tp->link_config.phy_is_low_power)
9619 offset = eeprom->offset;
9623 eeprom->magic = TG3_EEPROM_MAGIC;
9626 /* adjustments to start on required 4 byte boundary */
9627 b_offset = offset & 3;
9628 b_count = 4 - b_offset;
9629 if (b_count > len) {
9630 /* i.e. offset=1 len=2 */
9633 ret = tg3_nvram_read_be32(tp, offset-b_offset, &val);
9636 memcpy(data, ((char*)&val) + b_offset, b_count);
9639 eeprom->len += b_count;
9642 /* read bytes upto the last 4 byte boundary */
9643 pd = &data[eeprom->len];
9644 for (i = 0; i < (len - (len & 3)); i += 4) {
9645 ret = tg3_nvram_read_be32(tp, offset + i, &val);
9650 memcpy(pd + i, &val, 4);
9655 /* read last bytes not ending on 4 byte boundary */
9656 pd = &data[eeprom->len];
9658 b_offset = offset + len - b_count;
9659 ret = tg3_nvram_read_be32(tp, b_offset, &val);
9662 memcpy(pd, &val, b_count);
9663 eeprom->len += b_count;
9668 static int tg3_nvram_write_block(struct tg3 *tp, u32 offset, u32 len, u8 *buf);
9670 static int tg3_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, u8 *data)
9672 struct tg3 *tp = netdev_priv(dev);
9674 u32 offset, len, b_offset, odd_len;
9678 if (tp->link_config.phy_is_low_power)
9681 if ((tp->tg3_flags3 & TG3_FLG3_NO_NVRAM) ||
9682 eeprom->magic != TG3_EEPROM_MAGIC)
9685 offset = eeprom->offset;
9688 if ((b_offset = (offset & 3))) {
9689 /* adjustments to start on required 4 byte boundary */
9690 ret = tg3_nvram_read_be32(tp, offset-b_offset, &start);
9701 /* adjustments to end on required 4 byte boundary */
9703 len = (len + 3) & ~3;
9704 ret = tg3_nvram_read_be32(tp, offset+len-4, &end);
9710 if (b_offset || odd_len) {
9711 buf = kmalloc(len, GFP_KERNEL);
9715 memcpy(buf, &start, 4);
9717 memcpy(buf+len-4, &end, 4);
9718 memcpy(buf + b_offset, data, eeprom->len);
9721 ret = tg3_nvram_write_block(tp, offset, len, buf);
9729 static int tg3_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
9731 struct tg3 *tp = netdev_priv(dev);
9733 if (tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB) {
9734 struct phy_device *phydev;
9735 if (!(tp->tg3_flags3 & TG3_FLG3_PHY_CONNECTED))
9737 phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR];
9738 return phy_ethtool_gset(phydev, cmd);
9741 cmd->supported = (SUPPORTED_Autoneg);
9743 if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY))
9744 cmd->supported |= (SUPPORTED_1000baseT_Half |
9745 SUPPORTED_1000baseT_Full);
9747 if (!(tp->tg3_flags2 & TG3_FLG2_ANY_SERDES)) {
9748 cmd->supported |= (SUPPORTED_100baseT_Half |
9749 SUPPORTED_100baseT_Full |
9750 SUPPORTED_10baseT_Half |
9751 SUPPORTED_10baseT_Full |
9753 cmd->port = PORT_TP;
9755 cmd->supported |= SUPPORTED_FIBRE;
9756 cmd->port = PORT_FIBRE;
9759 cmd->advertising = tp->link_config.advertising;
9760 if (netif_running(dev)) {
9761 cmd->speed = tp->link_config.active_speed;
9762 cmd->duplex = tp->link_config.active_duplex;
9764 cmd->phy_address = tp->phy_addr;
9765 cmd->transceiver = XCVR_INTERNAL;
9766 cmd->autoneg = tp->link_config.autoneg;
9772 static int tg3_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
9774 struct tg3 *tp = netdev_priv(dev);
9776 if (tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB) {
9777 struct phy_device *phydev;
9778 if (!(tp->tg3_flags3 & TG3_FLG3_PHY_CONNECTED))
9780 phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR];
9781 return phy_ethtool_sset(phydev, cmd);
9784 if (cmd->autoneg != AUTONEG_ENABLE &&
9785 cmd->autoneg != AUTONEG_DISABLE)
9788 if (cmd->autoneg == AUTONEG_DISABLE &&
9789 cmd->duplex != DUPLEX_FULL &&
9790 cmd->duplex != DUPLEX_HALF)
9793 if (cmd->autoneg == AUTONEG_ENABLE) {
9794 u32 mask = ADVERTISED_Autoneg |
9796 ADVERTISED_Asym_Pause;
9798 if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY))
9799 mask |= ADVERTISED_1000baseT_Half |
9800 ADVERTISED_1000baseT_Full;
9802 if (!(tp->tg3_flags2 & TG3_FLG2_ANY_SERDES))
9803 mask |= ADVERTISED_100baseT_Half |
9804 ADVERTISED_100baseT_Full |
9805 ADVERTISED_10baseT_Half |
9806 ADVERTISED_10baseT_Full |
9809 mask |= ADVERTISED_FIBRE;
9811 if (cmd->advertising & ~mask)
9814 mask &= (ADVERTISED_1000baseT_Half |
9815 ADVERTISED_1000baseT_Full |
9816 ADVERTISED_100baseT_Half |
9817 ADVERTISED_100baseT_Full |
9818 ADVERTISED_10baseT_Half |
9819 ADVERTISED_10baseT_Full);
9821 cmd->advertising &= mask;
9823 if (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES) {
9824 if (cmd->speed != SPEED_1000)
9827 if (cmd->duplex != DUPLEX_FULL)
9830 if (cmd->speed != SPEED_100 &&
9831 cmd->speed != SPEED_10)
9836 tg3_full_lock(tp, 0);
9838 tp->link_config.autoneg = cmd->autoneg;
9839 if (cmd->autoneg == AUTONEG_ENABLE) {
9840 tp->link_config.advertising = (cmd->advertising |
9841 ADVERTISED_Autoneg);
9842 tp->link_config.speed = SPEED_INVALID;
9843 tp->link_config.duplex = DUPLEX_INVALID;
9845 tp->link_config.advertising = 0;
9846 tp->link_config.speed = cmd->speed;
9847 tp->link_config.duplex = cmd->duplex;
9850 tp->link_config.orig_speed = tp->link_config.speed;
9851 tp->link_config.orig_duplex = tp->link_config.duplex;
9852 tp->link_config.orig_autoneg = tp->link_config.autoneg;
9854 if (netif_running(dev))
9855 tg3_setup_phy(tp, 1);
9857 tg3_full_unlock(tp);
9862 static void tg3_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
9864 struct tg3 *tp = netdev_priv(dev);
9866 strcpy(info->driver, DRV_MODULE_NAME);
9867 strcpy(info->version, DRV_MODULE_VERSION);
9868 strcpy(info->fw_version, tp->fw_ver);
9869 strcpy(info->bus_info, pci_name(tp->pdev));
9872 static void tg3_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
9874 struct tg3 *tp = netdev_priv(dev);
9876 if ((tp->tg3_flags & TG3_FLAG_WOL_CAP) &&
9877 device_can_wakeup(&tp->pdev->dev))
9878 wol->supported = WAKE_MAGIC;
9882 if ((tp->tg3_flags & TG3_FLAG_WOL_ENABLE) &&
9883 device_can_wakeup(&tp->pdev->dev))
9884 wol->wolopts = WAKE_MAGIC;
9885 memset(&wol->sopass, 0, sizeof(wol->sopass));
9888 static int tg3_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
9890 struct tg3 *tp = netdev_priv(dev);
9891 struct device *dp = &tp->pdev->dev;
9893 if (wol->wolopts & ~WAKE_MAGIC)
9895 if ((wol->wolopts & WAKE_MAGIC) &&
9896 !((tp->tg3_flags & TG3_FLAG_WOL_CAP) && device_can_wakeup(dp)))
9899 spin_lock_bh(&tp->lock);
9900 if (wol->wolopts & WAKE_MAGIC) {
9901 tp->tg3_flags |= TG3_FLAG_WOL_ENABLE;
9902 device_set_wakeup_enable(dp, true);
9904 tp->tg3_flags &= ~TG3_FLAG_WOL_ENABLE;
9905 device_set_wakeup_enable(dp, false);
9907 spin_unlock_bh(&tp->lock);
9912 static u32 tg3_get_msglevel(struct net_device *dev)
9914 struct tg3 *tp = netdev_priv(dev);
9915 return tp->msg_enable;
9918 static void tg3_set_msglevel(struct net_device *dev, u32 value)
9920 struct tg3 *tp = netdev_priv(dev);
9921 tp->msg_enable = value;
9924 static int tg3_set_tso(struct net_device *dev, u32 value)
9926 struct tg3 *tp = netdev_priv(dev);
9928 if (!(tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE)) {
9933 if ((dev->features & NETIF_F_IPV6_CSUM) &&
9934 ((tp->tg3_flags2 & TG3_FLG2_HW_TSO_2) ||
9935 (tp->tg3_flags2 & TG3_FLG2_HW_TSO_3))) {
9937 dev->features |= NETIF_F_TSO6;
9938 if ((tp->tg3_flags2 & TG3_FLG2_HW_TSO_3) ||
9939 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761 ||
9940 (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 &&
9941 GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5784_AX) ||
9942 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 ||
9943 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780)
9944 dev->features |= NETIF_F_TSO_ECN;
9946 dev->features &= ~(NETIF_F_TSO6 | NETIF_F_TSO_ECN);
9948 return ethtool_op_set_tso(dev, value);
9951 static int tg3_nway_reset(struct net_device *dev)
9953 struct tg3 *tp = netdev_priv(dev);
9956 if (!netif_running(dev))
9959 if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)
9962 if (tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB) {
9963 if (!(tp->tg3_flags3 & TG3_FLG3_PHY_CONNECTED))
9965 r = phy_start_aneg(tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]);
9969 spin_lock_bh(&tp->lock);
9971 tg3_readphy(tp, MII_BMCR, &bmcr);
9972 if (!tg3_readphy(tp, MII_BMCR, &bmcr) &&
9973 ((bmcr & BMCR_ANENABLE) ||
9974 (tp->tg3_flags2 & TG3_FLG2_PARALLEL_DETECT))) {
9975 tg3_writephy(tp, MII_BMCR, bmcr | BMCR_ANRESTART |
9979 spin_unlock_bh(&tp->lock);
9985 static void tg3_get_ringparam(struct net_device *dev, struct ethtool_ringparam *ering)
9987 struct tg3 *tp = netdev_priv(dev);
9989 ering->rx_max_pending = TG3_RX_RING_SIZE - 1;
9990 ering->rx_mini_max_pending = 0;
9991 if (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE)
9992 ering->rx_jumbo_max_pending = TG3_RX_JUMBO_RING_SIZE - 1;
9994 ering->rx_jumbo_max_pending = 0;
9996 ering->tx_max_pending = TG3_TX_RING_SIZE - 1;
9998 ering->rx_pending = tp->rx_pending;
9999 ering->rx_mini_pending = 0;
10000 if (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE)
10001 ering->rx_jumbo_pending = tp->rx_jumbo_pending;
10003 ering->rx_jumbo_pending = 0;
10005 ering->tx_pending = tp->napi[0].tx_pending;
10008 static int tg3_set_ringparam(struct net_device *dev, struct ethtool_ringparam *ering)
10010 struct tg3 *tp = netdev_priv(dev);
10011 int i, irq_sync = 0, err = 0;
10013 if ((ering->rx_pending > TG3_RX_RING_SIZE - 1) ||
10014 (ering->rx_jumbo_pending > TG3_RX_JUMBO_RING_SIZE - 1) ||
10015 (ering->tx_pending > TG3_TX_RING_SIZE - 1) ||
10016 (ering->tx_pending <= MAX_SKB_FRAGS) ||
10017 ((tp->tg3_flags2 & TG3_FLG2_TSO_BUG) &&
10018 (ering->tx_pending <= (MAX_SKB_FRAGS * 3))))
10021 if (netif_running(dev)) {
10023 tg3_netif_stop(tp);
10027 tg3_full_lock(tp, irq_sync);
10029 tp->rx_pending = ering->rx_pending;
10031 if ((tp->tg3_flags2 & TG3_FLG2_MAX_RXPEND_64) &&
10032 tp->rx_pending > 63)
10033 tp->rx_pending = 63;
10034 tp->rx_jumbo_pending = ering->rx_jumbo_pending;
10036 for (i = 0; i < TG3_IRQ_MAX_VECS; i++)
10037 tp->napi[i].tx_pending = ering->tx_pending;
10039 if (netif_running(dev)) {
10040 tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
10041 err = tg3_restart_hw(tp, 1);
10043 tg3_netif_start(tp);
10046 tg3_full_unlock(tp);
10048 if (irq_sync && !err)
10054 static void tg3_get_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause)
10056 struct tg3 *tp = netdev_priv(dev);
10058 epause->autoneg = (tp->tg3_flags & TG3_FLAG_PAUSE_AUTONEG) != 0;
10060 if (tp->link_config.active_flowctrl & FLOW_CTRL_RX)
10061 epause->rx_pause = 1;
10063 epause->rx_pause = 0;
10065 if (tp->link_config.active_flowctrl & FLOW_CTRL_TX)
10066 epause->tx_pause = 1;
10068 epause->tx_pause = 0;
10071 static int tg3_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause)
10073 struct tg3 *tp = netdev_priv(dev);
10076 if (tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB) {
10078 struct phy_device *phydev;
10080 phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR];
10082 if (!(phydev->supported & SUPPORTED_Pause) ||
10083 (!(phydev->supported & SUPPORTED_Asym_Pause) &&
10084 ((epause->rx_pause && !epause->tx_pause) ||
10085 (!epause->rx_pause && epause->tx_pause))))
10088 tp->link_config.flowctrl = 0;
10089 if (epause->rx_pause) {
10090 tp->link_config.flowctrl |= FLOW_CTRL_RX;
10092 if (epause->tx_pause) {
10093 tp->link_config.flowctrl |= FLOW_CTRL_TX;
10094 newadv = ADVERTISED_Pause;
10096 newadv = ADVERTISED_Pause |
10097 ADVERTISED_Asym_Pause;
10098 } else if (epause->tx_pause) {
10099 tp->link_config.flowctrl |= FLOW_CTRL_TX;
10100 newadv = ADVERTISED_Asym_Pause;
10104 if (epause->autoneg)
10105 tp->tg3_flags |= TG3_FLAG_PAUSE_AUTONEG;
10107 tp->tg3_flags &= ~TG3_FLAG_PAUSE_AUTONEG;
10109 if (tp->tg3_flags3 & TG3_FLG3_PHY_CONNECTED) {
10110 u32 oldadv = phydev->advertising &
10111 (ADVERTISED_Pause | ADVERTISED_Asym_Pause);
10112 if (oldadv != newadv) {
10113 phydev->advertising &=
10114 ~(ADVERTISED_Pause |
10115 ADVERTISED_Asym_Pause);
10116 phydev->advertising |= newadv;
10117 if (phydev->autoneg) {
10119 * Always renegotiate the link to
10120 * inform our link partner of our
10121 * flow control settings, even if the
10122 * flow control is forced. Let
10123 * tg3_adjust_link() do the final
10124 * flow control setup.
10126 return phy_start_aneg(phydev);
10130 if (!epause->autoneg)
10131 tg3_setup_flow_control(tp, 0, 0);
10133 tp->link_config.orig_advertising &=
10134 ~(ADVERTISED_Pause |
10135 ADVERTISED_Asym_Pause);
10136 tp->link_config.orig_advertising |= newadv;
10141 if (netif_running(dev)) {
10142 tg3_netif_stop(tp);
10146 tg3_full_lock(tp, irq_sync);
10148 if (epause->autoneg)
10149 tp->tg3_flags |= TG3_FLAG_PAUSE_AUTONEG;
10151 tp->tg3_flags &= ~TG3_FLAG_PAUSE_AUTONEG;
10152 if (epause->rx_pause)
10153 tp->link_config.flowctrl |= FLOW_CTRL_RX;
10155 tp->link_config.flowctrl &= ~FLOW_CTRL_RX;
10156 if (epause->tx_pause)
10157 tp->link_config.flowctrl |= FLOW_CTRL_TX;
10159 tp->link_config.flowctrl &= ~FLOW_CTRL_TX;
10161 if (netif_running(dev)) {
10162 tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
10163 err = tg3_restart_hw(tp, 1);
10165 tg3_netif_start(tp);
10168 tg3_full_unlock(tp);
10174 static u32 tg3_get_rx_csum(struct net_device *dev)
10176 struct tg3 *tp = netdev_priv(dev);
10177 return (tp->tg3_flags & TG3_FLAG_RX_CHECKSUMS) != 0;
10180 static int tg3_set_rx_csum(struct net_device *dev, u32 data)
10182 struct tg3 *tp = netdev_priv(dev);
10184 if (tp->tg3_flags & TG3_FLAG_BROKEN_CHECKSUMS) {
10190 spin_lock_bh(&tp->lock);
10192 tp->tg3_flags |= TG3_FLAG_RX_CHECKSUMS;
10194 tp->tg3_flags &= ~TG3_FLAG_RX_CHECKSUMS;
10195 spin_unlock_bh(&tp->lock);
10200 static int tg3_set_tx_csum(struct net_device *dev, u32 data)
10202 struct tg3 *tp = netdev_priv(dev);
10204 if (tp->tg3_flags & TG3_FLAG_BROKEN_CHECKSUMS) {
10210 if (tp->tg3_flags3 & TG3_FLG3_5755_PLUS)
10211 ethtool_op_set_tx_ipv6_csum(dev, data);
10213 ethtool_op_set_tx_csum(dev, data);
10218 static int tg3_get_sset_count (struct net_device *dev, int sset)
10222 return TG3_NUM_TEST;
10224 return TG3_NUM_STATS;
10226 return -EOPNOTSUPP;
10230 static void tg3_get_strings (struct net_device *dev, u32 stringset, u8 *buf)
10232 switch (stringset) {
10234 memcpy(buf, ðtool_stats_keys, sizeof(ethtool_stats_keys));
10237 memcpy(buf, ðtool_test_keys, sizeof(ethtool_test_keys));
10240 WARN_ON(1); /* we need a WARN() */
10245 static int tg3_phys_id(struct net_device *dev, u32 data)
10247 struct tg3 *tp = netdev_priv(dev);
10250 if (!netif_running(tp->dev))
10254 data = UINT_MAX / 2;
10256 for (i = 0; i < (data * 2); i++) {
10258 tw32(MAC_LED_CTRL, LED_CTRL_LNKLED_OVERRIDE |
10259 LED_CTRL_1000MBPS_ON |
10260 LED_CTRL_100MBPS_ON |
10261 LED_CTRL_10MBPS_ON |
10262 LED_CTRL_TRAFFIC_OVERRIDE |
10263 LED_CTRL_TRAFFIC_BLINK |
10264 LED_CTRL_TRAFFIC_LED);
10267 tw32(MAC_LED_CTRL, LED_CTRL_LNKLED_OVERRIDE |
10268 LED_CTRL_TRAFFIC_OVERRIDE);
10270 if (msleep_interruptible(500))
10273 tw32(MAC_LED_CTRL, tp->led_ctrl);
10277 static void tg3_get_ethtool_stats (struct net_device *dev,
10278 struct ethtool_stats *estats, u64 *tmp_stats)
10280 struct tg3 *tp = netdev_priv(dev);
10281 memcpy(tmp_stats, tg3_get_estats(tp), sizeof(tp->estats));
10284 #define NVRAM_TEST_SIZE 0x100
10285 #define NVRAM_SELFBOOT_FORMAT1_0_SIZE 0x14
10286 #define NVRAM_SELFBOOT_FORMAT1_2_SIZE 0x18
10287 #define NVRAM_SELFBOOT_FORMAT1_3_SIZE 0x1c
10288 #define NVRAM_SELFBOOT_HW_SIZE 0x20
10289 #define NVRAM_SELFBOOT_DATA_SIZE 0x1c
10291 static int tg3_test_nvram(struct tg3 *tp)
10295 int i, j, k, err = 0, size;
10297 if (tp->tg3_flags3 & TG3_FLG3_NO_NVRAM)
10300 if (tg3_nvram_read(tp, 0, &magic) != 0)
10303 if (magic == TG3_EEPROM_MAGIC)
10304 size = NVRAM_TEST_SIZE;
10305 else if ((magic & TG3_EEPROM_MAGIC_FW_MSK) == TG3_EEPROM_MAGIC_FW) {
10306 if ((magic & TG3_EEPROM_SB_FORMAT_MASK) ==
10307 TG3_EEPROM_SB_FORMAT_1) {
10308 switch (magic & TG3_EEPROM_SB_REVISION_MASK) {
10309 case TG3_EEPROM_SB_REVISION_0:
10310 size = NVRAM_SELFBOOT_FORMAT1_0_SIZE;
10312 case TG3_EEPROM_SB_REVISION_2:
10313 size = NVRAM_SELFBOOT_FORMAT1_2_SIZE;
10315 case TG3_EEPROM_SB_REVISION_3:
10316 size = NVRAM_SELFBOOT_FORMAT1_3_SIZE;
10323 } else if ((magic & TG3_EEPROM_MAGIC_HW_MSK) == TG3_EEPROM_MAGIC_HW)
10324 size = NVRAM_SELFBOOT_HW_SIZE;
10328 buf = kmalloc(size, GFP_KERNEL);
10333 for (i = 0, j = 0; i < size; i += 4, j++) {
10334 err = tg3_nvram_read_be32(tp, i, &buf[j]);
10341 /* Selfboot format */
10342 magic = be32_to_cpu(buf[0]);
10343 if ((magic & TG3_EEPROM_MAGIC_FW_MSK) ==
10344 TG3_EEPROM_MAGIC_FW) {
10345 u8 *buf8 = (u8 *) buf, csum8 = 0;
10347 if ((magic & TG3_EEPROM_SB_REVISION_MASK) ==
10348 TG3_EEPROM_SB_REVISION_2) {
10349 /* For rev 2, the csum doesn't include the MBA. */
10350 for (i = 0; i < TG3_EEPROM_SB_F1R2_MBA_OFF; i++)
10352 for (i = TG3_EEPROM_SB_F1R2_MBA_OFF + 4; i < size; i++)
10355 for (i = 0; i < size; i++)
10368 if ((magic & TG3_EEPROM_MAGIC_HW_MSK) ==
10369 TG3_EEPROM_MAGIC_HW) {
10370 u8 data[NVRAM_SELFBOOT_DATA_SIZE];
10371 u8 parity[NVRAM_SELFBOOT_DATA_SIZE];
10372 u8 *buf8 = (u8 *) buf;
10374 /* Separate the parity bits and the data bytes. */
10375 for (i = 0, j = 0, k = 0; i < NVRAM_SELFBOOT_HW_SIZE; i++) {
10376 if ((i == 0) || (i == 8)) {
10380 for (l = 0, msk = 0x80; l < 7; l++, msk >>= 1)
10381 parity[k++] = buf8[i] & msk;
10384 else if (i == 16) {
10388 for (l = 0, msk = 0x20; l < 6; l++, msk >>= 1)
10389 parity[k++] = buf8[i] & msk;
10392 for (l = 0, msk = 0x80; l < 8; l++, msk >>= 1)
10393 parity[k++] = buf8[i] & msk;
10396 data[j++] = buf8[i];
10400 for (i = 0; i < NVRAM_SELFBOOT_DATA_SIZE; i++) {
10401 u8 hw8 = hweight8(data[i]);
10403 if ((hw8 & 0x1) && parity[i])
10405 else if (!(hw8 & 0x1) && !parity[i])
10412 /* Bootstrap checksum at offset 0x10 */
10413 csum = calc_crc((unsigned char *) buf, 0x10);
10414 if (csum != be32_to_cpu(buf[0x10/4]))
10417 /* Manufacturing block starts at offset 0x74, checksum at 0xfc */
10418 csum = calc_crc((unsigned char *) &buf[0x74/4], 0x88);
10419 if (csum != be32_to_cpu(buf[0xfc/4]))
10429 #define TG3_SERDES_TIMEOUT_SEC 2
10430 #define TG3_COPPER_TIMEOUT_SEC 6
10432 static int tg3_test_link(struct tg3 *tp)
10436 if (!netif_running(tp->dev))
10439 if (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES)
10440 max = TG3_SERDES_TIMEOUT_SEC;
10442 max = TG3_COPPER_TIMEOUT_SEC;
10444 for (i = 0; i < max; i++) {
10445 if (netif_carrier_ok(tp->dev))
10448 if (msleep_interruptible(1000))
10455 /* Only test the commonly used registers */
10456 static int tg3_test_registers(struct tg3 *tp)
10458 int i, is_5705, is_5750;
10459 u32 offset, read_mask, write_mask, val, save_val, read_val;
10463 #define TG3_FL_5705 0x1
10464 #define TG3_FL_NOT_5705 0x2
10465 #define TG3_FL_NOT_5788 0x4
10466 #define TG3_FL_NOT_5750 0x8
10470 /* MAC Control Registers */
10471 { MAC_MODE, TG3_FL_NOT_5705,
10472 0x00000000, 0x00ef6f8c },
10473 { MAC_MODE, TG3_FL_5705,
10474 0x00000000, 0x01ef6b8c },
10475 { MAC_STATUS, TG3_FL_NOT_5705,
10476 0x03800107, 0x00000000 },
10477 { MAC_STATUS, TG3_FL_5705,
10478 0x03800100, 0x00000000 },
10479 { MAC_ADDR_0_HIGH, 0x0000,
10480 0x00000000, 0x0000ffff },
10481 { MAC_ADDR_0_LOW, 0x0000,
10482 0x00000000, 0xffffffff },
10483 { MAC_RX_MTU_SIZE, 0x0000,
10484 0x00000000, 0x0000ffff },
10485 { MAC_TX_MODE, 0x0000,
10486 0x00000000, 0x00000070 },
10487 { MAC_TX_LENGTHS, 0x0000,
10488 0x00000000, 0x00003fff },
10489 { MAC_RX_MODE, TG3_FL_NOT_5705,
10490 0x00000000, 0x000007fc },
10491 { MAC_RX_MODE, TG3_FL_5705,
10492 0x00000000, 0x000007dc },
10493 { MAC_HASH_REG_0, 0x0000,
10494 0x00000000, 0xffffffff },
10495 { MAC_HASH_REG_1, 0x0000,
10496 0x00000000, 0xffffffff },
10497 { MAC_HASH_REG_2, 0x0000,
10498 0x00000000, 0xffffffff },
10499 { MAC_HASH_REG_3, 0x0000,
10500 0x00000000, 0xffffffff },
10502 /* Receive Data and Receive BD Initiator Control Registers. */
10503 { RCVDBDI_JUMBO_BD+0, TG3_FL_NOT_5705,
10504 0x00000000, 0xffffffff },
10505 { RCVDBDI_JUMBO_BD+4, TG3_FL_NOT_5705,
10506 0x00000000, 0xffffffff },
10507 { RCVDBDI_JUMBO_BD+8, TG3_FL_NOT_5705,
10508 0x00000000, 0x00000003 },
10509 { RCVDBDI_JUMBO_BD+0xc, TG3_FL_NOT_5705,
10510 0x00000000, 0xffffffff },
10511 { RCVDBDI_STD_BD+0, 0x0000,
10512 0x00000000, 0xffffffff },
10513 { RCVDBDI_STD_BD+4, 0x0000,
10514 0x00000000, 0xffffffff },
10515 { RCVDBDI_STD_BD+8, 0x0000,
10516 0x00000000, 0xffff0002 },
10517 { RCVDBDI_STD_BD+0xc, 0x0000,
10518 0x00000000, 0xffffffff },
10520 /* Receive BD Initiator Control Registers. */
10521 { RCVBDI_STD_THRESH, TG3_FL_NOT_5705,
10522 0x00000000, 0xffffffff },
10523 { RCVBDI_STD_THRESH, TG3_FL_5705,
10524 0x00000000, 0x000003ff },
10525 { RCVBDI_JUMBO_THRESH, TG3_FL_NOT_5705,
10526 0x00000000, 0xffffffff },
10528 /* Host Coalescing Control Registers. */
10529 { HOSTCC_MODE, TG3_FL_NOT_5705,
10530 0x00000000, 0x00000004 },
10531 { HOSTCC_MODE, TG3_FL_5705,
10532 0x00000000, 0x000000f6 },
10533 { HOSTCC_RXCOL_TICKS, TG3_FL_NOT_5705,
10534 0x00000000, 0xffffffff },
10535 { HOSTCC_RXCOL_TICKS, TG3_FL_5705,
10536 0x00000000, 0x000003ff },
10537 { HOSTCC_TXCOL_TICKS, TG3_FL_NOT_5705,
10538 0x00000000, 0xffffffff },
10539 { HOSTCC_TXCOL_TICKS, TG3_FL_5705,
10540 0x00000000, 0x000003ff },
10541 { HOSTCC_RXMAX_FRAMES, TG3_FL_NOT_5705,
10542 0x00000000, 0xffffffff },
10543 { HOSTCC_RXMAX_FRAMES, TG3_FL_5705 | TG3_FL_NOT_5788,
10544 0x00000000, 0x000000ff },
10545 { HOSTCC_TXMAX_FRAMES, TG3_FL_NOT_5705,
10546 0x00000000, 0xffffffff },
10547 { HOSTCC_TXMAX_FRAMES, TG3_FL_5705 | TG3_FL_NOT_5788,
10548 0x00000000, 0x000000ff },
10549 { HOSTCC_RXCOAL_TICK_INT, TG3_FL_NOT_5705,
10550 0x00000000, 0xffffffff },
10551 { HOSTCC_TXCOAL_TICK_INT, TG3_FL_NOT_5705,
10552 0x00000000, 0xffffffff },
10553 { HOSTCC_RXCOAL_MAXF_INT, TG3_FL_NOT_5705,
10554 0x00000000, 0xffffffff },
10555 { HOSTCC_RXCOAL_MAXF_INT, TG3_FL_5705 | TG3_FL_NOT_5788,
10556 0x00000000, 0x000000ff },
10557 { HOSTCC_TXCOAL_MAXF_INT, TG3_FL_NOT_5705,
10558 0x00000000, 0xffffffff },
10559 { HOSTCC_TXCOAL_MAXF_INT, TG3_FL_5705 | TG3_FL_NOT_5788,
10560 0x00000000, 0x000000ff },
10561 { HOSTCC_STAT_COAL_TICKS, TG3_FL_NOT_5705,
10562 0x00000000, 0xffffffff },
10563 { HOSTCC_STATS_BLK_HOST_ADDR, TG3_FL_NOT_5705,
10564 0x00000000, 0xffffffff },
10565 { HOSTCC_STATS_BLK_HOST_ADDR+4, TG3_FL_NOT_5705,
10566 0x00000000, 0xffffffff },
10567 { HOSTCC_STATUS_BLK_HOST_ADDR, 0x0000,
10568 0x00000000, 0xffffffff },
10569 { HOSTCC_STATUS_BLK_HOST_ADDR+4, 0x0000,
10570 0x00000000, 0xffffffff },
10571 { HOSTCC_STATS_BLK_NIC_ADDR, 0x0000,
10572 0xffffffff, 0x00000000 },
10573 { HOSTCC_STATUS_BLK_NIC_ADDR, 0x0000,
10574 0xffffffff, 0x00000000 },
10576 /* Buffer Manager Control Registers. */
10577 { BUFMGR_MB_POOL_ADDR, TG3_FL_NOT_5750,
10578 0x00000000, 0x007fff80 },
10579 { BUFMGR_MB_POOL_SIZE, TG3_FL_NOT_5750,
10580 0x00000000, 0x007fffff },
10581 { BUFMGR_MB_RDMA_LOW_WATER, 0x0000,
10582 0x00000000, 0x0000003f },
10583 { BUFMGR_MB_MACRX_LOW_WATER, 0x0000,
10584 0x00000000, 0x000001ff },
10585 { BUFMGR_MB_HIGH_WATER, 0x0000,
10586 0x00000000, 0x000001ff },
10587 { BUFMGR_DMA_DESC_POOL_ADDR, TG3_FL_NOT_5705,
10588 0xffffffff, 0x00000000 },
10589 { BUFMGR_DMA_DESC_POOL_SIZE, TG3_FL_NOT_5705,
10590 0xffffffff, 0x00000000 },
10592 /* Mailbox Registers */
10593 { GRCMBOX_RCVSTD_PROD_IDX+4, 0x0000,
10594 0x00000000, 0x000001ff },
10595 { GRCMBOX_RCVJUMBO_PROD_IDX+4, TG3_FL_NOT_5705,
10596 0x00000000, 0x000001ff },
10597 { GRCMBOX_RCVRET_CON_IDX_0+4, 0x0000,
10598 0x00000000, 0x000007ff },
10599 { GRCMBOX_SNDHOST_PROD_IDX_0+4, 0x0000,
10600 0x00000000, 0x000001ff },
10602 { 0xffff, 0x0000, 0x00000000, 0x00000000 },
10605 is_5705 = is_5750 = 0;
10606 if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
10608 if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS)
10612 for (i = 0; reg_tbl[i].offset != 0xffff; i++) {
10613 if (is_5705 && (reg_tbl[i].flags & TG3_FL_NOT_5705))
10616 if (!is_5705 && (reg_tbl[i].flags & TG3_FL_5705))
10619 if ((tp->tg3_flags2 & TG3_FLG2_IS_5788) &&
10620 (reg_tbl[i].flags & TG3_FL_NOT_5788))
10623 if (is_5750 && (reg_tbl[i].flags & TG3_FL_NOT_5750))
10626 offset = (u32) reg_tbl[i].offset;
10627 read_mask = reg_tbl[i].read_mask;
10628 write_mask = reg_tbl[i].write_mask;
10630 /* Save the original register content */
10631 save_val = tr32(offset);
10633 /* Determine the read-only value. */
10634 read_val = save_val & read_mask;
10636 /* Write zero to the register, then make sure the read-only bits
10637 * are not changed and the read/write bits are all zeros.
10641 val = tr32(offset);
10643 /* Test the read-only and read/write bits. */
10644 if (((val & read_mask) != read_val) || (val & write_mask))
10647 /* Write ones to all the bits defined by RdMask and WrMask, then
10648 * make sure the read-only bits are not changed and the
10649 * read/write bits are all ones.
10651 tw32(offset, read_mask | write_mask);
10653 val = tr32(offset);
10655 /* Test the read-only bits. */
10656 if ((val & read_mask) != read_val)
10659 /* Test the read/write bits. */
10660 if ((val & write_mask) != write_mask)
10663 tw32(offset, save_val);
10669 if (netif_msg_hw(tp))
10670 netdev_err(tp->dev,
10671 "Register test failed at offset %x\n", offset);
10672 tw32(offset, save_val);
10676 static int tg3_do_mem_test(struct tg3 *tp, u32 offset, u32 len)
10678 static const u32 test_pattern[] = { 0x00000000, 0xffffffff, 0xaa55a55a };
10682 for (i = 0; i < ARRAY_SIZE(test_pattern); i++) {
10683 for (j = 0; j < len; j += 4) {
10686 tg3_write_mem(tp, offset + j, test_pattern[i]);
10687 tg3_read_mem(tp, offset + j, &val);
10688 if (val != test_pattern[i])
10695 static int tg3_test_memory(struct tg3 *tp)
10697 static struct mem_entry {
10700 } mem_tbl_570x[] = {
10701 { 0x00000000, 0x00b50},
10702 { 0x00002000, 0x1c000},
10703 { 0xffffffff, 0x00000}
10704 }, mem_tbl_5705[] = {
10705 { 0x00000100, 0x0000c},
10706 { 0x00000200, 0x00008},
10707 { 0x00004000, 0x00800},
10708 { 0x00006000, 0x01000},
10709 { 0x00008000, 0x02000},
10710 { 0x00010000, 0x0e000},
10711 { 0xffffffff, 0x00000}
10712 }, mem_tbl_5755[] = {
10713 { 0x00000200, 0x00008},
10714 { 0x00004000, 0x00800},
10715 { 0x00006000, 0x00800},
10716 { 0x00008000, 0x02000},
10717 { 0x00010000, 0x0c000},
10718 { 0xffffffff, 0x00000}
10719 }, mem_tbl_5906[] = {
10720 { 0x00000200, 0x00008},
10721 { 0x00004000, 0x00400},
10722 { 0x00006000, 0x00400},
10723 { 0x00008000, 0x01000},
10724 { 0x00010000, 0x01000},
10725 { 0xffffffff, 0x00000}
10726 }, mem_tbl_5717[] = {
10727 { 0x00000200, 0x00008},
10728 { 0x00010000, 0x0a000},
10729 { 0x00020000, 0x13c00},
10730 { 0xffffffff, 0x00000}
10731 }, mem_tbl_57765[] = {
10732 { 0x00000200, 0x00008},
10733 { 0x00004000, 0x00800},
10734 { 0x00006000, 0x09800},
10735 { 0x00010000, 0x0a000},
10736 { 0xffffffff, 0x00000}
10738 struct mem_entry *mem_tbl;
10742 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717)
10743 mem_tbl = mem_tbl_5717;
10744 else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765)
10745 mem_tbl = mem_tbl_57765;
10746 else if (tp->tg3_flags3 & TG3_FLG3_5755_PLUS)
10747 mem_tbl = mem_tbl_5755;
10748 else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)
10749 mem_tbl = mem_tbl_5906;
10750 else if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS)
10751 mem_tbl = mem_tbl_5705;
10753 mem_tbl = mem_tbl_570x;
10755 for (i = 0; mem_tbl[i].offset != 0xffffffff; i++) {
10756 if ((err = tg3_do_mem_test(tp, mem_tbl[i].offset,
10757 mem_tbl[i].len)) != 0)
10764 #define TG3_MAC_LOOPBACK 0
10765 #define TG3_PHY_LOOPBACK 1
10767 static int tg3_run_loopback(struct tg3 *tp, int loopback_mode)
10769 u32 mac_mode, rx_start_idx, rx_idx, tx_idx, opaque_key;
10770 u32 desc_idx, coal_now;
10771 struct sk_buff *skb, *rx_skb;
10774 int num_pkts, tx_len, rx_len, i, err;
10775 struct tg3_rx_buffer_desc *desc;
10776 struct tg3_napi *tnapi, *rnapi;
10777 struct tg3_rx_prodring_set *tpr = &tp->prodring[0];
10779 tnapi = &tp->napi[0];
10780 rnapi = &tp->napi[0];
10781 if (tp->irq_cnt > 1) {
10782 rnapi = &tp->napi[1];
10783 if (tp->tg3_flags3 & TG3_FLG3_ENABLE_TSS)
10784 tnapi = &tp->napi[1];
10786 coal_now = tnapi->coal_now | rnapi->coal_now;
10788 if (loopback_mode == TG3_MAC_LOOPBACK) {
10789 /* HW errata - mac loopback fails in some cases on 5780.
10790 * Normal traffic and PHY loopback are not affected by
10793 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780)
10796 mac_mode = (tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK) |
10797 MAC_MODE_PORT_INT_LPBACK;
10798 if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS))
10799 mac_mode |= MAC_MODE_LINK_POLARITY;
10800 if (tp->tg3_flags & TG3_FLAG_10_100_ONLY)
10801 mac_mode |= MAC_MODE_PORT_MODE_MII;
10803 mac_mode |= MAC_MODE_PORT_MODE_GMII;
10804 tw32(MAC_MODE, mac_mode);
10805 } else if (loopback_mode == TG3_PHY_LOOPBACK) {
10808 if (tp->tg3_flags3 & TG3_FLG3_PHY_IS_FET) {
10809 tg3_phy_fet_toggle_apd(tp, false);
10810 val = BMCR_LOOPBACK | BMCR_FULLDPLX | BMCR_SPEED100;
10812 val = BMCR_LOOPBACK | BMCR_FULLDPLX | BMCR_SPEED1000;
10814 tg3_phy_toggle_automdix(tp, 0);
10816 tg3_writephy(tp, MII_BMCR, val);
10819 mac_mode = tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK;
10820 if (tp->tg3_flags3 & TG3_FLG3_PHY_IS_FET) {
10821 tg3_writephy(tp, MII_TG3_FET_PTEST,
10822 MII_TG3_FET_PTEST_FRC_TX_LINK |
10823 MII_TG3_FET_PTEST_FRC_TX_LOCK);
10824 /* The write needs to be flushed for the AC131 */
10825 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785)
10826 tg3_readphy(tp, MII_TG3_FET_PTEST, &val);
10827 mac_mode |= MAC_MODE_PORT_MODE_MII;
10829 mac_mode |= MAC_MODE_PORT_MODE_GMII;
10831 /* reset to prevent losing 1st rx packet intermittently */
10832 if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES) {
10833 tw32_f(MAC_RX_MODE, RX_MODE_RESET);
10835 tw32_f(MAC_RX_MODE, tp->rx_mode);
10837 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) {
10838 u32 masked_phy_id = tp->phy_id & TG3_PHY_ID_MASK;
10839 if (masked_phy_id == TG3_PHY_ID_BCM5401)
10840 mac_mode &= ~MAC_MODE_LINK_POLARITY;
10841 else if (masked_phy_id == TG3_PHY_ID_BCM5411)
10842 mac_mode |= MAC_MODE_LINK_POLARITY;
10843 tg3_writephy(tp, MII_TG3_EXT_CTRL,
10844 MII_TG3_EXT_CTRL_LNK3_LED_MODE);
10846 tw32(MAC_MODE, mac_mode);
10854 skb = netdev_alloc_skb(tp->dev, tx_len);
10858 tx_data = skb_put(skb, tx_len);
10859 memcpy(tx_data, tp->dev->dev_addr, 6);
10860 memset(tx_data + 6, 0x0, 8);
10862 tw32(MAC_RX_MTU_SIZE, tx_len + 4);
10864 for (i = 14; i < tx_len; i++)
10865 tx_data[i] = (u8) (i & 0xff);
10867 map = pci_map_single(tp->pdev, skb->data, tx_len, PCI_DMA_TODEVICE);
10868 if (pci_dma_mapping_error(tp->pdev, map)) {
10869 dev_kfree_skb(skb);
10873 tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE |
10878 rx_start_idx = rnapi->hw_status->idx[0].rx_producer;
10882 tg3_set_txd(tnapi, tnapi->tx_prod, map, tx_len, 0, 1);
10887 tw32_tx_mbox(tnapi->prodmbox, tnapi->tx_prod);
10888 tr32_mailbox(tnapi->prodmbox);
10892 /* 350 usec to allow enough time on some 10/100 Mbps devices. */
10893 for (i = 0; i < 35; i++) {
10894 tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE |
10899 tx_idx = tnapi->hw_status->idx[0].tx_consumer;
10900 rx_idx = rnapi->hw_status->idx[0].rx_producer;
10901 if ((tx_idx == tnapi->tx_prod) &&
10902 (rx_idx == (rx_start_idx + num_pkts)))
10906 pci_unmap_single(tp->pdev, map, tx_len, PCI_DMA_TODEVICE);
10907 dev_kfree_skb(skb);
10909 if (tx_idx != tnapi->tx_prod)
10912 if (rx_idx != rx_start_idx + num_pkts)
10915 desc = &rnapi->rx_rcb[rx_start_idx];
10916 desc_idx = desc->opaque & RXD_OPAQUE_INDEX_MASK;
10917 opaque_key = desc->opaque & RXD_OPAQUE_RING_MASK;
10918 if (opaque_key != RXD_OPAQUE_RING_STD)
10921 if ((desc->err_vlan & RXD_ERR_MASK) != 0 &&
10922 (desc->err_vlan != RXD_ERR_ODD_NIBBLE_RCVD_MII))
10925 rx_len = ((desc->idx_len & RXD_LEN_MASK) >> RXD_LEN_SHIFT) - 4;
10926 if (rx_len != tx_len)
10929 rx_skb = tpr->rx_std_buffers[desc_idx].skb;
10931 map = pci_unmap_addr(&tpr->rx_std_buffers[desc_idx], mapping);
10932 pci_dma_sync_single_for_cpu(tp->pdev, map, rx_len, PCI_DMA_FROMDEVICE);
10934 for (i = 14; i < tx_len; i++) {
10935 if (*(rx_skb->data + i) != (u8) (i & 0xff))
10940 /* tg3_free_rings will unmap and free the rx_skb */
10945 #define TG3_MAC_LOOPBACK_FAILED 1
10946 #define TG3_PHY_LOOPBACK_FAILED 2
10947 #define TG3_LOOPBACK_FAILED (TG3_MAC_LOOPBACK_FAILED | \
10948 TG3_PHY_LOOPBACK_FAILED)
10950 static int tg3_test_loopback(struct tg3 *tp)
10955 if (!netif_running(tp->dev))
10956 return TG3_LOOPBACK_FAILED;
10958 err = tg3_reset_hw(tp, 1);
10960 return TG3_LOOPBACK_FAILED;
10962 /* Turn off gphy autopowerdown. */
10963 if (tp->tg3_flags3 & TG3_FLG3_PHY_ENABLE_APD)
10964 tg3_phy_toggle_apd(tp, false);
10966 if (tp->tg3_flags & TG3_FLAG_CPMU_PRESENT) {
10970 tw32(TG3_CPMU_MUTEX_REQ, CPMU_MUTEX_REQ_DRIVER);
10972 /* Wait for up to 40 microseconds to acquire lock. */
10973 for (i = 0; i < 4; i++) {
10974 status = tr32(TG3_CPMU_MUTEX_GNT);
10975 if (status == CPMU_MUTEX_GNT_DRIVER)
10980 if (status != CPMU_MUTEX_GNT_DRIVER)
10981 return TG3_LOOPBACK_FAILED;
10983 /* Turn off link-based power management. */
10984 cpmuctrl = tr32(TG3_CPMU_CTRL);
10985 tw32(TG3_CPMU_CTRL,
10986 cpmuctrl & ~(CPMU_CTRL_LINK_SPEED_MODE |
10987 CPMU_CTRL_LINK_AWARE_MODE));
10990 if (tg3_run_loopback(tp, TG3_MAC_LOOPBACK))
10991 err |= TG3_MAC_LOOPBACK_FAILED;
10993 if (tp->tg3_flags & TG3_FLAG_CPMU_PRESENT) {
10994 tw32(TG3_CPMU_CTRL, cpmuctrl);
10996 /* Release the mutex */
10997 tw32(TG3_CPMU_MUTEX_GNT, CPMU_MUTEX_GNT_DRIVER);
11000 if (!(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) &&
11001 !(tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB)) {
11002 if (tg3_run_loopback(tp, TG3_PHY_LOOPBACK))
11003 err |= TG3_PHY_LOOPBACK_FAILED;
11006 /* Re-enable gphy autopowerdown. */
11007 if (tp->tg3_flags3 & TG3_FLG3_PHY_ENABLE_APD)
11008 tg3_phy_toggle_apd(tp, true);
11013 static void tg3_self_test(struct net_device *dev, struct ethtool_test *etest,
11016 struct tg3 *tp = netdev_priv(dev);
11018 if (tp->link_config.phy_is_low_power)
11019 tg3_set_power_state(tp, PCI_D0);
11021 memset(data, 0, sizeof(u64) * TG3_NUM_TEST);
11023 if (tg3_test_nvram(tp) != 0) {
11024 etest->flags |= ETH_TEST_FL_FAILED;
11027 if (tg3_test_link(tp) != 0) {
11028 etest->flags |= ETH_TEST_FL_FAILED;
11031 if (etest->flags & ETH_TEST_FL_OFFLINE) {
11032 int err, err2 = 0, irq_sync = 0;
11034 if (netif_running(dev)) {
11036 tg3_netif_stop(tp);
11040 tg3_full_lock(tp, irq_sync);
11042 tg3_halt(tp, RESET_KIND_SUSPEND, 1);
11043 err = tg3_nvram_lock(tp);
11044 tg3_halt_cpu(tp, RX_CPU_BASE);
11045 if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS))
11046 tg3_halt_cpu(tp, TX_CPU_BASE);
11048 tg3_nvram_unlock(tp);
11050 if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES)
11053 if (tg3_test_registers(tp) != 0) {
11054 etest->flags |= ETH_TEST_FL_FAILED;
11057 if (tg3_test_memory(tp) != 0) {
11058 etest->flags |= ETH_TEST_FL_FAILED;
11061 if ((data[4] = tg3_test_loopback(tp)) != 0)
11062 etest->flags |= ETH_TEST_FL_FAILED;
11064 tg3_full_unlock(tp);
11066 if (tg3_test_interrupt(tp) != 0) {
11067 etest->flags |= ETH_TEST_FL_FAILED;
11071 tg3_full_lock(tp, 0);
11073 tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
11074 if (netif_running(dev)) {
11075 tp->tg3_flags |= TG3_FLAG_INIT_COMPLETE;
11076 err2 = tg3_restart_hw(tp, 1);
11078 tg3_netif_start(tp);
11081 tg3_full_unlock(tp);
11083 if (irq_sync && !err2)
11086 if (tp->link_config.phy_is_low_power)
11087 tg3_set_power_state(tp, PCI_D3hot);
11091 static int tg3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
11093 struct mii_ioctl_data *data = if_mii(ifr);
11094 struct tg3 *tp = netdev_priv(dev);
11097 if (tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB) {
11098 struct phy_device *phydev;
11099 if (!(tp->tg3_flags3 & TG3_FLG3_PHY_CONNECTED))
11101 phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR];
11102 return phy_mii_ioctl(phydev, data, cmd);
11107 data->phy_id = tp->phy_addr;
11110 case SIOCGMIIREG: {
11113 if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)
11114 break; /* We have no PHY */
11116 if (tp->link_config.phy_is_low_power)
11119 spin_lock_bh(&tp->lock);
11120 err = tg3_readphy(tp, data->reg_num & 0x1f, &mii_regval);
11121 spin_unlock_bh(&tp->lock);
11123 data->val_out = mii_regval;
11129 if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)
11130 break; /* We have no PHY */
11132 if (tp->link_config.phy_is_low_power)
11135 spin_lock_bh(&tp->lock);
11136 err = tg3_writephy(tp, data->reg_num & 0x1f, data->val_in);
11137 spin_unlock_bh(&tp->lock);
11145 return -EOPNOTSUPP;
11148 #if TG3_VLAN_TAG_USED
11149 static void tg3_vlan_rx_register(struct net_device *dev, struct vlan_group *grp)
11151 struct tg3 *tp = netdev_priv(dev);
11153 if (!netif_running(dev)) {
11158 tg3_netif_stop(tp);
11160 tg3_full_lock(tp, 0);
11164 /* Update RX_MODE_KEEP_VLAN_TAG bit in RX_MODE register. */
11165 __tg3_set_rx_mode(dev);
11167 tg3_netif_start(tp);
11169 tg3_full_unlock(tp);
11173 static int tg3_get_coalesce(struct net_device *dev, struct ethtool_coalesce *ec)
11175 struct tg3 *tp = netdev_priv(dev);
11177 memcpy(ec, &tp->coal, sizeof(*ec));
11181 static int tg3_set_coalesce(struct net_device *dev, struct ethtool_coalesce *ec)
11183 struct tg3 *tp = netdev_priv(dev);
11184 u32 max_rxcoal_tick_int = 0, max_txcoal_tick_int = 0;
11185 u32 max_stat_coal_ticks = 0, min_stat_coal_ticks = 0;
11187 if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
11188 max_rxcoal_tick_int = MAX_RXCOAL_TICK_INT;
11189 max_txcoal_tick_int = MAX_TXCOAL_TICK_INT;
11190 max_stat_coal_ticks = MAX_STAT_COAL_TICKS;
11191 min_stat_coal_ticks = MIN_STAT_COAL_TICKS;
11194 if ((ec->rx_coalesce_usecs > MAX_RXCOL_TICKS) ||
11195 (ec->tx_coalesce_usecs > MAX_TXCOL_TICKS) ||
11196 (ec->rx_max_coalesced_frames > MAX_RXMAX_FRAMES) ||
11197 (ec->tx_max_coalesced_frames > MAX_TXMAX_FRAMES) ||
11198 (ec->rx_coalesce_usecs_irq > max_rxcoal_tick_int) ||
11199 (ec->tx_coalesce_usecs_irq > max_txcoal_tick_int) ||
11200 (ec->rx_max_coalesced_frames_irq > MAX_RXCOAL_MAXF_INT) ||
11201 (ec->tx_max_coalesced_frames_irq > MAX_TXCOAL_MAXF_INT) ||
11202 (ec->stats_block_coalesce_usecs > max_stat_coal_ticks) ||
11203 (ec->stats_block_coalesce_usecs < min_stat_coal_ticks))
11206 /* No rx interrupts will be generated if both are zero */
11207 if ((ec->rx_coalesce_usecs == 0) &&
11208 (ec->rx_max_coalesced_frames == 0))
11211 /* No tx interrupts will be generated if both are zero */
11212 if ((ec->tx_coalesce_usecs == 0) &&
11213 (ec->tx_max_coalesced_frames == 0))
11216 /* Only copy relevant parameters, ignore all others. */
11217 tp->coal.rx_coalesce_usecs = ec->rx_coalesce_usecs;
11218 tp->coal.tx_coalesce_usecs = ec->tx_coalesce_usecs;
11219 tp->coal.rx_max_coalesced_frames = ec->rx_max_coalesced_frames;
11220 tp->coal.tx_max_coalesced_frames = ec->tx_max_coalesced_frames;
11221 tp->coal.rx_coalesce_usecs_irq = ec->rx_coalesce_usecs_irq;
11222 tp->coal.tx_coalesce_usecs_irq = ec->tx_coalesce_usecs_irq;
11223 tp->coal.rx_max_coalesced_frames_irq = ec->rx_max_coalesced_frames_irq;
11224 tp->coal.tx_max_coalesced_frames_irq = ec->tx_max_coalesced_frames_irq;
11225 tp->coal.stats_block_coalesce_usecs = ec->stats_block_coalesce_usecs;
11227 if (netif_running(dev)) {
11228 tg3_full_lock(tp, 0);
11229 __tg3_set_coalesce(tp, &tp->coal);
11230 tg3_full_unlock(tp);
11235 static const struct ethtool_ops tg3_ethtool_ops = {
11236 .get_settings = tg3_get_settings,
11237 .set_settings = tg3_set_settings,
11238 .get_drvinfo = tg3_get_drvinfo,
11239 .get_regs_len = tg3_get_regs_len,
11240 .get_regs = tg3_get_regs,
11241 .get_wol = tg3_get_wol,
11242 .set_wol = tg3_set_wol,
11243 .get_msglevel = tg3_get_msglevel,
11244 .set_msglevel = tg3_set_msglevel,
11245 .nway_reset = tg3_nway_reset,
11246 .get_link = ethtool_op_get_link,
11247 .get_eeprom_len = tg3_get_eeprom_len,
11248 .get_eeprom = tg3_get_eeprom,
11249 .set_eeprom = tg3_set_eeprom,
11250 .get_ringparam = tg3_get_ringparam,
11251 .set_ringparam = tg3_set_ringparam,
11252 .get_pauseparam = tg3_get_pauseparam,
11253 .set_pauseparam = tg3_set_pauseparam,
11254 .get_rx_csum = tg3_get_rx_csum,
11255 .set_rx_csum = tg3_set_rx_csum,
11256 .set_tx_csum = tg3_set_tx_csum,
11257 .set_sg = ethtool_op_set_sg,
11258 .set_tso = tg3_set_tso,
11259 .self_test = tg3_self_test,
11260 .get_strings = tg3_get_strings,
11261 .phys_id = tg3_phys_id,
11262 .get_ethtool_stats = tg3_get_ethtool_stats,
11263 .get_coalesce = tg3_get_coalesce,
11264 .set_coalesce = tg3_set_coalesce,
11265 .get_sset_count = tg3_get_sset_count,
11268 static void __devinit tg3_get_eeprom_size(struct tg3 *tp)
11270 u32 cursize, val, magic;
11272 tp->nvram_size = EEPROM_CHIP_SIZE;
11274 if (tg3_nvram_read(tp, 0, &magic) != 0)
11277 if ((magic != TG3_EEPROM_MAGIC) &&
11278 ((magic & TG3_EEPROM_MAGIC_FW_MSK) != TG3_EEPROM_MAGIC_FW) &&
11279 ((magic & TG3_EEPROM_MAGIC_HW_MSK) != TG3_EEPROM_MAGIC_HW))
11283 * Size the chip by reading offsets at increasing powers of two.
11284 * When we encounter our validation signature, we know the addressing
11285 * has wrapped around, and thus have our chip size.
11289 while (cursize < tp->nvram_size) {
11290 if (tg3_nvram_read(tp, cursize, &val) != 0)
11299 tp->nvram_size = cursize;
11302 static void __devinit tg3_get_nvram_size(struct tg3 *tp)
11306 if ((tp->tg3_flags3 & TG3_FLG3_NO_NVRAM) ||
11307 tg3_nvram_read(tp, 0, &val) != 0)
11310 /* Selfboot format */
11311 if (val != TG3_EEPROM_MAGIC) {
11312 tg3_get_eeprom_size(tp);
11316 if (tg3_nvram_read(tp, 0xf0, &val) == 0) {
11318 /* This is confusing. We want to operate on the
11319 * 16-bit value at offset 0xf2. The tg3_nvram_read()
11320 * call will read from NVRAM and byteswap the data
11321 * according to the byteswapping settings for all
11322 * other register accesses. This ensures the data we
11323 * want will always reside in the lower 16-bits.
11324 * However, the data in NVRAM is in LE format, which
11325 * means the data from the NVRAM read will always be
11326 * opposite the endianness of the CPU. The 16-bit
11327 * byteswap then brings the data to CPU endianness.
11329 tp->nvram_size = swab16((u16)(val & 0x0000ffff)) * 1024;
11333 tp->nvram_size = TG3_NVRAM_SIZE_512KB;
11336 static void __devinit tg3_get_nvram_info(struct tg3 *tp)
11340 nvcfg1 = tr32(NVRAM_CFG1);
11341 if (nvcfg1 & NVRAM_CFG1_FLASHIF_ENAB) {
11342 tp->tg3_flags2 |= TG3_FLG2_FLASH;
11344 nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS;
11345 tw32(NVRAM_CFG1, nvcfg1);
11348 if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750) ||
11349 (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) {
11350 switch (nvcfg1 & NVRAM_CFG1_VENDOR_MASK) {
11351 case FLASH_VENDOR_ATMEL_FLASH_BUFFERED:
11352 tp->nvram_jedecnum = JEDEC_ATMEL;
11353 tp->nvram_pagesize = ATMEL_AT45DB0X1B_PAGE_SIZE;
11354 tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
11356 case FLASH_VENDOR_ATMEL_FLASH_UNBUFFERED:
11357 tp->nvram_jedecnum = JEDEC_ATMEL;
11358 tp->nvram_pagesize = ATMEL_AT25F512_PAGE_SIZE;
11360 case FLASH_VENDOR_ATMEL_EEPROM:
11361 tp->nvram_jedecnum = JEDEC_ATMEL;
11362 tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE;
11363 tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
11365 case FLASH_VENDOR_ST:
11366 tp->nvram_jedecnum = JEDEC_ST;
11367 tp->nvram_pagesize = ST_M45PEX0_PAGE_SIZE;
11368 tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
11370 case FLASH_VENDOR_SAIFUN:
11371 tp->nvram_jedecnum = JEDEC_SAIFUN;
11372 tp->nvram_pagesize = SAIFUN_SA25F0XX_PAGE_SIZE;
11374 case FLASH_VENDOR_SST_SMALL:
11375 case FLASH_VENDOR_SST_LARGE:
11376 tp->nvram_jedecnum = JEDEC_SST;
11377 tp->nvram_pagesize = SST_25VF0X0_PAGE_SIZE;
11381 tp->nvram_jedecnum = JEDEC_ATMEL;
11382 tp->nvram_pagesize = ATMEL_AT45DB0X1B_PAGE_SIZE;
11383 tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
11387 static void __devinit tg3_nvram_get_pagesize(struct tg3 *tp, u32 nvmcfg1)
11389 switch (nvmcfg1 & NVRAM_CFG1_5752PAGE_SIZE_MASK) {
11390 case FLASH_5752PAGE_SIZE_256:
11391 tp->nvram_pagesize = 256;
11393 case FLASH_5752PAGE_SIZE_512:
11394 tp->nvram_pagesize = 512;
11396 case FLASH_5752PAGE_SIZE_1K:
11397 tp->nvram_pagesize = 1024;
11399 case FLASH_5752PAGE_SIZE_2K:
11400 tp->nvram_pagesize = 2048;
11402 case FLASH_5752PAGE_SIZE_4K:
11403 tp->nvram_pagesize = 4096;
11405 case FLASH_5752PAGE_SIZE_264:
11406 tp->nvram_pagesize = 264;
11408 case FLASH_5752PAGE_SIZE_528:
11409 tp->nvram_pagesize = 528;
11414 static void __devinit tg3_get_5752_nvram_info(struct tg3 *tp)
11418 nvcfg1 = tr32(NVRAM_CFG1);
11420 /* NVRAM protection for TPM */
11421 if (nvcfg1 & (1 << 27))
11422 tp->tg3_flags3 |= TG3_FLG3_PROTECTED_NVRAM;
11424 switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) {
11425 case FLASH_5752VENDOR_ATMEL_EEPROM_64KHZ:
11426 case FLASH_5752VENDOR_ATMEL_EEPROM_376KHZ:
11427 tp->nvram_jedecnum = JEDEC_ATMEL;
11428 tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
11430 case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED:
11431 tp->nvram_jedecnum = JEDEC_ATMEL;
11432 tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
11433 tp->tg3_flags2 |= TG3_FLG2_FLASH;
11435 case FLASH_5752VENDOR_ST_M45PE10:
11436 case FLASH_5752VENDOR_ST_M45PE20:
11437 case FLASH_5752VENDOR_ST_M45PE40:
11438 tp->nvram_jedecnum = JEDEC_ST;
11439 tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
11440 tp->tg3_flags2 |= TG3_FLG2_FLASH;
11444 if (tp->tg3_flags2 & TG3_FLG2_FLASH) {
11445 tg3_nvram_get_pagesize(tp, nvcfg1);
11447 /* For eeprom, set pagesize to maximum eeprom size */
11448 tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE;
11450 nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS;
11451 tw32(NVRAM_CFG1, nvcfg1);
11455 static void __devinit tg3_get_5755_nvram_info(struct tg3 *tp)
11457 u32 nvcfg1, protect = 0;
11459 nvcfg1 = tr32(NVRAM_CFG1);
11461 /* NVRAM protection for TPM */
11462 if (nvcfg1 & (1 << 27)) {
11463 tp->tg3_flags3 |= TG3_FLG3_PROTECTED_NVRAM;
11467 nvcfg1 &= NVRAM_CFG1_5752VENDOR_MASK;
11469 case FLASH_5755VENDOR_ATMEL_FLASH_1:
11470 case FLASH_5755VENDOR_ATMEL_FLASH_2:
11471 case FLASH_5755VENDOR_ATMEL_FLASH_3:
11472 case FLASH_5755VENDOR_ATMEL_FLASH_5:
11473 tp->nvram_jedecnum = JEDEC_ATMEL;
11474 tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
11475 tp->tg3_flags2 |= TG3_FLG2_FLASH;
11476 tp->nvram_pagesize = 264;
11477 if (nvcfg1 == FLASH_5755VENDOR_ATMEL_FLASH_1 ||
11478 nvcfg1 == FLASH_5755VENDOR_ATMEL_FLASH_5)
11479 tp->nvram_size = (protect ? 0x3e200 :
11480 TG3_NVRAM_SIZE_512KB);
11481 else if (nvcfg1 == FLASH_5755VENDOR_ATMEL_FLASH_2)
11482 tp->nvram_size = (protect ? 0x1f200 :
11483 TG3_NVRAM_SIZE_256KB);
11485 tp->nvram_size = (protect ? 0x1f200 :
11486 TG3_NVRAM_SIZE_128KB);
11488 case FLASH_5752VENDOR_ST_M45PE10:
11489 case FLASH_5752VENDOR_ST_M45PE20:
11490 case FLASH_5752VENDOR_ST_M45PE40:
11491 tp->nvram_jedecnum = JEDEC_ST;
11492 tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
11493 tp->tg3_flags2 |= TG3_FLG2_FLASH;
11494 tp->nvram_pagesize = 256;
11495 if (nvcfg1 == FLASH_5752VENDOR_ST_M45PE10)
11496 tp->nvram_size = (protect ?
11497 TG3_NVRAM_SIZE_64KB :
11498 TG3_NVRAM_SIZE_128KB);
11499 else if (nvcfg1 == FLASH_5752VENDOR_ST_M45PE20)
11500 tp->nvram_size = (protect ?
11501 TG3_NVRAM_SIZE_64KB :
11502 TG3_NVRAM_SIZE_256KB);
11504 tp->nvram_size = (protect ?
11505 TG3_NVRAM_SIZE_128KB :
11506 TG3_NVRAM_SIZE_512KB);
11511 static void __devinit tg3_get_5787_nvram_info(struct tg3 *tp)
11515 nvcfg1 = tr32(NVRAM_CFG1);
11517 switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) {
11518 case FLASH_5787VENDOR_ATMEL_EEPROM_64KHZ:
11519 case FLASH_5787VENDOR_ATMEL_EEPROM_376KHZ:
11520 case FLASH_5787VENDOR_MICRO_EEPROM_64KHZ:
11521 case FLASH_5787VENDOR_MICRO_EEPROM_376KHZ:
11522 tp->nvram_jedecnum = JEDEC_ATMEL;
11523 tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
11524 tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE;
11526 nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS;
11527 tw32(NVRAM_CFG1, nvcfg1);
11529 case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED:
11530 case FLASH_5755VENDOR_ATMEL_FLASH_1:
11531 case FLASH_5755VENDOR_ATMEL_FLASH_2:
11532 case FLASH_5755VENDOR_ATMEL_FLASH_3:
11533 tp->nvram_jedecnum = JEDEC_ATMEL;
11534 tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
11535 tp->tg3_flags2 |= TG3_FLG2_FLASH;
11536 tp->nvram_pagesize = 264;
11538 case FLASH_5752VENDOR_ST_M45PE10:
11539 case FLASH_5752VENDOR_ST_M45PE20:
11540 case FLASH_5752VENDOR_ST_M45PE40:
11541 tp->nvram_jedecnum = JEDEC_ST;
11542 tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
11543 tp->tg3_flags2 |= TG3_FLG2_FLASH;
11544 tp->nvram_pagesize = 256;
11549 static void __devinit tg3_get_5761_nvram_info(struct tg3 *tp)
11551 u32 nvcfg1, protect = 0;
11553 nvcfg1 = tr32(NVRAM_CFG1);
11555 /* NVRAM protection for TPM */
11556 if (nvcfg1 & (1 << 27)) {
11557 tp->tg3_flags3 |= TG3_FLG3_PROTECTED_NVRAM;
11561 nvcfg1 &= NVRAM_CFG1_5752VENDOR_MASK;
11563 case FLASH_5761VENDOR_ATMEL_ADB021D:
11564 case FLASH_5761VENDOR_ATMEL_ADB041D:
11565 case FLASH_5761VENDOR_ATMEL_ADB081D:
11566 case FLASH_5761VENDOR_ATMEL_ADB161D:
11567 case FLASH_5761VENDOR_ATMEL_MDB021D:
11568 case FLASH_5761VENDOR_ATMEL_MDB041D:
11569 case FLASH_5761VENDOR_ATMEL_MDB081D:
11570 case FLASH_5761VENDOR_ATMEL_MDB161D:
11571 tp->nvram_jedecnum = JEDEC_ATMEL;
11572 tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
11573 tp->tg3_flags2 |= TG3_FLG2_FLASH;
11574 tp->tg3_flags3 |= TG3_FLG3_NO_NVRAM_ADDR_TRANS;
11575 tp->nvram_pagesize = 256;
11577 case FLASH_5761VENDOR_ST_A_M45PE20:
11578 case FLASH_5761VENDOR_ST_A_M45PE40:
11579 case FLASH_5761VENDOR_ST_A_M45PE80:
11580 case FLASH_5761VENDOR_ST_A_M45PE16:
11581 case FLASH_5761VENDOR_ST_M_M45PE20:
11582 case FLASH_5761VENDOR_ST_M_M45PE40:
11583 case FLASH_5761VENDOR_ST_M_M45PE80:
11584 case FLASH_5761VENDOR_ST_M_M45PE16:
11585 tp->nvram_jedecnum = JEDEC_ST;
11586 tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
11587 tp->tg3_flags2 |= TG3_FLG2_FLASH;
11588 tp->nvram_pagesize = 256;
11593 tp->nvram_size = tr32(NVRAM_ADDR_LOCKOUT);
11596 case FLASH_5761VENDOR_ATMEL_ADB161D:
11597 case FLASH_5761VENDOR_ATMEL_MDB161D:
11598 case FLASH_5761VENDOR_ST_A_M45PE16:
11599 case FLASH_5761VENDOR_ST_M_M45PE16:
11600 tp->nvram_size = TG3_NVRAM_SIZE_2MB;
11602 case FLASH_5761VENDOR_ATMEL_ADB081D:
11603 case FLASH_5761VENDOR_ATMEL_MDB081D:
11604 case FLASH_5761VENDOR_ST_A_M45PE80:
11605 case FLASH_5761VENDOR_ST_M_M45PE80:
11606 tp->nvram_size = TG3_NVRAM_SIZE_1MB;
11608 case FLASH_5761VENDOR_ATMEL_ADB041D:
11609 case FLASH_5761VENDOR_ATMEL_MDB041D:
11610 case FLASH_5761VENDOR_ST_A_M45PE40:
11611 case FLASH_5761VENDOR_ST_M_M45PE40:
11612 tp->nvram_size = TG3_NVRAM_SIZE_512KB;
11614 case FLASH_5761VENDOR_ATMEL_ADB021D:
11615 case FLASH_5761VENDOR_ATMEL_MDB021D:
11616 case FLASH_5761VENDOR_ST_A_M45PE20:
11617 case FLASH_5761VENDOR_ST_M_M45PE20:
11618 tp->nvram_size = TG3_NVRAM_SIZE_256KB;
11624 static void __devinit tg3_get_5906_nvram_info(struct tg3 *tp)
11626 tp->nvram_jedecnum = JEDEC_ATMEL;
11627 tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
11628 tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE;
11631 static void __devinit tg3_get_57780_nvram_info(struct tg3 *tp)
11635 nvcfg1 = tr32(NVRAM_CFG1);
11637 switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) {
11638 case FLASH_5787VENDOR_ATMEL_EEPROM_376KHZ:
11639 case FLASH_5787VENDOR_MICRO_EEPROM_376KHZ:
11640 tp->nvram_jedecnum = JEDEC_ATMEL;
11641 tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
11642 tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE;
11644 nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS;
11645 tw32(NVRAM_CFG1, nvcfg1);
11647 case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED:
11648 case FLASH_57780VENDOR_ATMEL_AT45DB011D:
11649 case FLASH_57780VENDOR_ATMEL_AT45DB011B:
11650 case FLASH_57780VENDOR_ATMEL_AT45DB021D:
11651 case FLASH_57780VENDOR_ATMEL_AT45DB021B:
11652 case FLASH_57780VENDOR_ATMEL_AT45DB041D:
11653 case FLASH_57780VENDOR_ATMEL_AT45DB041B:
11654 tp->nvram_jedecnum = JEDEC_ATMEL;
11655 tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
11656 tp->tg3_flags2 |= TG3_FLG2_FLASH;
11658 switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) {
11659 case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED:
11660 case FLASH_57780VENDOR_ATMEL_AT45DB011D:
11661 case FLASH_57780VENDOR_ATMEL_AT45DB011B:
11662 tp->nvram_size = TG3_NVRAM_SIZE_128KB;
11664 case FLASH_57780VENDOR_ATMEL_AT45DB021D:
11665 case FLASH_57780VENDOR_ATMEL_AT45DB021B:
11666 tp->nvram_size = TG3_NVRAM_SIZE_256KB;
11668 case FLASH_57780VENDOR_ATMEL_AT45DB041D:
11669 case FLASH_57780VENDOR_ATMEL_AT45DB041B:
11670 tp->nvram_size = TG3_NVRAM_SIZE_512KB;
11674 case FLASH_5752VENDOR_ST_M45PE10:
11675 case FLASH_5752VENDOR_ST_M45PE20:
11676 case FLASH_5752VENDOR_ST_M45PE40:
11677 tp->nvram_jedecnum = JEDEC_ST;
11678 tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
11679 tp->tg3_flags2 |= TG3_FLG2_FLASH;
11681 switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) {
11682 case FLASH_5752VENDOR_ST_M45PE10:
11683 tp->nvram_size = TG3_NVRAM_SIZE_128KB;
11685 case FLASH_5752VENDOR_ST_M45PE20:
11686 tp->nvram_size = TG3_NVRAM_SIZE_256KB;
11688 case FLASH_5752VENDOR_ST_M45PE40:
11689 tp->nvram_size = TG3_NVRAM_SIZE_512KB;
11694 tp->tg3_flags3 |= TG3_FLG3_NO_NVRAM;
11698 tg3_nvram_get_pagesize(tp, nvcfg1);
11699 if (tp->nvram_pagesize != 264 && tp->nvram_pagesize != 528)
11700 tp->tg3_flags3 |= TG3_FLG3_NO_NVRAM_ADDR_TRANS;
11704 static void __devinit tg3_get_5717_nvram_info(struct tg3 *tp)
11708 nvcfg1 = tr32(NVRAM_CFG1);
11710 switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) {
11711 case FLASH_5717VENDOR_ATMEL_EEPROM:
11712 case FLASH_5717VENDOR_MICRO_EEPROM:
11713 tp->nvram_jedecnum = JEDEC_ATMEL;
11714 tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
11715 tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE;
11717 nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS;
11718 tw32(NVRAM_CFG1, nvcfg1);
11720 case FLASH_5717VENDOR_ATMEL_MDB011D:
11721 case FLASH_5717VENDOR_ATMEL_ADB011B:
11722 case FLASH_5717VENDOR_ATMEL_ADB011D:
11723 case FLASH_5717VENDOR_ATMEL_MDB021D:
11724 case FLASH_5717VENDOR_ATMEL_ADB021B:
11725 case FLASH_5717VENDOR_ATMEL_ADB021D:
11726 case FLASH_5717VENDOR_ATMEL_45USPT:
11727 tp->nvram_jedecnum = JEDEC_ATMEL;
11728 tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
11729 tp->tg3_flags2 |= TG3_FLG2_FLASH;
11731 switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) {
11732 case FLASH_5717VENDOR_ATMEL_MDB021D:
11733 case FLASH_5717VENDOR_ATMEL_ADB021B:
11734 case FLASH_5717VENDOR_ATMEL_ADB021D:
11735 tp->nvram_size = TG3_NVRAM_SIZE_256KB;
11738 tp->nvram_size = TG3_NVRAM_SIZE_128KB;
11742 case FLASH_5717VENDOR_ST_M_M25PE10:
11743 case FLASH_5717VENDOR_ST_A_M25PE10:
11744 case FLASH_5717VENDOR_ST_M_M45PE10:
11745 case FLASH_5717VENDOR_ST_A_M45PE10:
11746 case FLASH_5717VENDOR_ST_M_M25PE20:
11747 case FLASH_5717VENDOR_ST_A_M25PE20:
11748 case FLASH_5717VENDOR_ST_M_M45PE20:
11749 case FLASH_5717VENDOR_ST_A_M45PE20:
11750 case FLASH_5717VENDOR_ST_25USPT:
11751 case FLASH_5717VENDOR_ST_45USPT:
11752 tp->nvram_jedecnum = JEDEC_ST;
11753 tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
11754 tp->tg3_flags2 |= TG3_FLG2_FLASH;
11756 switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) {
11757 case FLASH_5717VENDOR_ST_M_M25PE20:
11758 case FLASH_5717VENDOR_ST_A_M25PE20:
11759 case FLASH_5717VENDOR_ST_M_M45PE20:
11760 case FLASH_5717VENDOR_ST_A_M45PE20:
11761 tp->nvram_size = TG3_NVRAM_SIZE_256KB;
11764 tp->nvram_size = TG3_NVRAM_SIZE_128KB;
11769 tp->tg3_flags3 |= TG3_FLG3_NO_NVRAM;
11773 tg3_nvram_get_pagesize(tp, nvcfg1);
11774 if (tp->nvram_pagesize != 264 && tp->nvram_pagesize != 528)
11775 tp->tg3_flags3 |= TG3_FLG3_NO_NVRAM_ADDR_TRANS;
11778 /* Chips other than 5700/5701 use the NVRAM for fetching info. */
11779 static void __devinit tg3_nvram_init(struct tg3 *tp)
11781 tw32_f(GRC_EEPROM_ADDR,
11782 (EEPROM_ADDR_FSM_RESET |
11783 (EEPROM_DEFAULT_CLOCK_PERIOD <<
11784 EEPROM_ADDR_CLKPERD_SHIFT)));
11788 /* Enable seeprom accesses. */
11789 tw32_f(GRC_LOCAL_CTRL,
11790 tr32(GRC_LOCAL_CTRL) | GRC_LCLCTRL_AUTO_SEEPROM);
11793 if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 &&
11794 GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) {
11795 tp->tg3_flags |= TG3_FLAG_NVRAM;
11797 if (tg3_nvram_lock(tp)) {
11798 netdev_warn(tp->dev,
11799 "Cannot get nvram lock, %s failed\n",
11803 tg3_enable_nvram_access(tp);
11805 tp->nvram_size = 0;
11807 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752)
11808 tg3_get_5752_nvram_info(tp);
11809 else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755)
11810 tg3_get_5755_nvram_info(tp);
11811 else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 ||
11812 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 ||
11813 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785)
11814 tg3_get_5787_nvram_info(tp);
11815 else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761)
11816 tg3_get_5761_nvram_info(tp);
11817 else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)
11818 tg3_get_5906_nvram_info(tp);
11819 else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780 ||
11820 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765)
11821 tg3_get_57780_nvram_info(tp);
11822 else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717)
11823 tg3_get_5717_nvram_info(tp);
11825 tg3_get_nvram_info(tp);
11827 if (tp->nvram_size == 0)
11828 tg3_get_nvram_size(tp);
11830 tg3_disable_nvram_access(tp);
11831 tg3_nvram_unlock(tp);
11834 tp->tg3_flags &= ~(TG3_FLAG_NVRAM | TG3_FLAG_NVRAM_BUFFERED);
11836 tg3_get_eeprom_size(tp);
11840 static int tg3_nvram_write_block_using_eeprom(struct tg3 *tp,
11841 u32 offset, u32 len, u8 *buf)
11846 for (i = 0; i < len; i += 4) {
11852 memcpy(&data, buf + i, 4);
11855 * The SEEPROM interface expects the data to always be opposite
11856 * the native endian format. We accomplish this by reversing
11857 * all the operations that would have been performed on the
11858 * data from a call to tg3_nvram_read_be32().
11860 tw32(GRC_EEPROM_DATA, swab32(be32_to_cpu(data)));
11862 val = tr32(GRC_EEPROM_ADDR);
11863 tw32(GRC_EEPROM_ADDR, val | EEPROM_ADDR_COMPLETE);
11865 val &= ~(EEPROM_ADDR_ADDR_MASK | EEPROM_ADDR_DEVID_MASK |
11867 tw32(GRC_EEPROM_ADDR, val |
11868 (0 << EEPROM_ADDR_DEVID_SHIFT) |
11869 (addr & EEPROM_ADDR_ADDR_MASK) |
11870 EEPROM_ADDR_START |
11871 EEPROM_ADDR_WRITE);
11873 for (j = 0; j < 1000; j++) {
11874 val = tr32(GRC_EEPROM_ADDR);
11876 if (val & EEPROM_ADDR_COMPLETE)
11880 if (!(val & EEPROM_ADDR_COMPLETE)) {
11889 /* offset and length are dword aligned */
11890 static int tg3_nvram_write_block_unbuffered(struct tg3 *tp, u32 offset, u32 len,
11894 u32 pagesize = tp->nvram_pagesize;
11895 u32 pagemask = pagesize - 1;
11899 tmp = kmalloc(pagesize, GFP_KERNEL);
11905 u32 phy_addr, page_off, size;
11907 phy_addr = offset & ~pagemask;
11909 for (j = 0; j < pagesize; j += 4) {
11910 ret = tg3_nvram_read_be32(tp, phy_addr + j,
11911 (__be32 *) (tmp + j));
11918 page_off = offset & pagemask;
11925 memcpy(tmp + page_off, buf, size);
11927 offset = offset + (pagesize - page_off);
11929 tg3_enable_nvram_access(tp);
11932 * Before we can erase the flash page, we need
11933 * to issue a special "write enable" command.
11935 nvram_cmd = NVRAM_CMD_WREN | NVRAM_CMD_GO | NVRAM_CMD_DONE;
11937 if (tg3_nvram_exec_cmd(tp, nvram_cmd))
11940 /* Erase the target page */
11941 tw32(NVRAM_ADDR, phy_addr);
11943 nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE | NVRAM_CMD_WR |
11944 NVRAM_CMD_FIRST | NVRAM_CMD_LAST | NVRAM_CMD_ERASE;
11946 if (tg3_nvram_exec_cmd(tp, nvram_cmd))
11949 /* Issue another write enable to start the write. */
11950 nvram_cmd = NVRAM_CMD_WREN | NVRAM_CMD_GO | NVRAM_CMD_DONE;
11952 if (tg3_nvram_exec_cmd(tp, nvram_cmd))
11955 for (j = 0; j < pagesize; j += 4) {
11958 data = *((__be32 *) (tmp + j));
11960 tw32(NVRAM_WRDATA, be32_to_cpu(data));
11962 tw32(NVRAM_ADDR, phy_addr + j);
11964 nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE |
11968 nvram_cmd |= NVRAM_CMD_FIRST;
11969 else if (j == (pagesize - 4))
11970 nvram_cmd |= NVRAM_CMD_LAST;
11972 if ((ret = tg3_nvram_exec_cmd(tp, nvram_cmd)))
11979 nvram_cmd = NVRAM_CMD_WRDI | NVRAM_CMD_GO | NVRAM_CMD_DONE;
11980 tg3_nvram_exec_cmd(tp, nvram_cmd);
11987 /* offset and length are dword aligned */
11988 static int tg3_nvram_write_block_buffered(struct tg3 *tp, u32 offset, u32 len,
11993 for (i = 0; i < len; i += 4, offset += 4) {
11994 u32 page_off, phy_addr, nvram_cmd;
11997 memcpy(&data, buf + i, 4);
11998 tw32(NVRAM_WRDATA, be32_to_cpu(data));
12000 page_off = offset % tp->nvram_pagesize;
12002 phy_addr = tg3_nvram_phys_addr(tp, offset);
12004 tw32(NVRAM_ADDR, phy_addr);
12006 nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE | NVRAM_CMD_WR;
12008 if (page_off == 0 || i == 0)
12009 nvram_cmd |= NVRAM_CMD_FIRST;
12010 if (page_off == (tp->nvram_pagesize - 4))
12011 nvram_cmd |= NVRAM_CMD_LAST;
12013 if (i == (len - 4))
12014 nvram_cmd |= NVRAM_CMD_LAST;
12016 if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5752 &&
12017 !(tp->tg3_flags3 & TG3_FLG3_5755_PLUS) &&
12018 (tp->nvram_jedecnum == JEDEC_ST) &&
12019 (nvram_cmd & NVRAM_CMD_FIRST)) {
12021 if ((ret = tg3_nvram_exec_cmd(tp,
12022 NVRAM_CMD_WREN | NVRAM_CMD_GO |
12027 if (!(tp->tg3_flags2 & TG3_FLG2_FLASH)) {
12028 /* We always do complete word writes to eeprom. */
12029 nvram_cmd |= (NVRAM_CMD_FIRST | NVRAM_CMD_LAST);
12032 if ((ret = tg3_nvram_exec_cmd(tp, nvram_cmd)))
12038 /* offset and length are dword aligned */
12039 static int tg3_nvram_write_block(struct tg3 *tp, u32 offset, u32 len, u8 *buf)
12043 if (tp->tg3_flags & TG3_FLAG_EEPROM_WRITE_PROT) {
12044 tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl &
12045 ~GRC_LCLCTRL_GPIO_OUTPUT1);
12049 if (!(tp->tg3_flags & TG3_FLAG_NVRAM)) {
12050 ret = tg3_nvram_write_block_using_eeprom(tp, offset, len, buf);
12055 ret = tg3_nvram_lock(tp);
12059 tg3_enable_nvram_access(tp);
12060 if ((tp->tg3_flags2 & TG3_FLG2_5750_PLUS) &&
12061 !(tp->tg3_flags3 & TG3_FLG3_PROTECTED_NVRAM))
12062 tw32(NVRAM_WRITE1, 0x406);
12064 grc_mode = tr32(GRC_MODE);
12065 tw32(GRC_MODE, grc_mode | GRC_MODE_NVRAM_WR_ENABLE);
12067 if ((tp->tg3_flags & TG3_FLAG_NVRAM_BUFFERED) ||
12068 !(tp->tg3_flags2 & TG3_FLG2_FLASH)) {
12070 ret = tg3_nvram_write_block_buffered(tp, offset, len,
12074 ret = tg3_nvram_write_block_unbuffered(tp, offset, len,
12078 grc_mode = tr32(GRC_MODE);
12079 tw32(GRC_MODE, grc_mode & ~GRC_MODE_NVRAM_WR_ENABLE);
12081 tg3_disable_nvram_access(tp);
12082 tg3_nvram_unlock(tp);
12085 if (tp->tg3_flags & TG3_FLAG_EEPROM_WRITE_PROT) {
12086 tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl);
12093 struct subsys_tbl_ent {
12094 u16 subsys_vendor, subsys_devid;
12098 static struct subsys_tbl_ent subsys_id_to_phy_id[] __devinitdata = {
12099 /* Broadcom boards. */
12100 { TG3PCI_SUBVENDOR_ID_BROADCOM,
12101 TG3PCI_SUBDEVICE_ID_BROADCOM_95700A6, TG3_PHY_ID_BCM5401 },
12102 { TG3PCI_SUBVENDOR_ID_BROADCOM,
12103 TG3PCI_SUBDEVICE_ID_BROADCOM_95701A5, TG3_PHY_ID_BCM5701 },
12104 { TG3PCI_SUBVENDOR_ID_BROADCOM,
12105 TG3PCI_SUBDEVICE_ID_BROADCOM_95700T6, TG3_PHY_ID_BCM8002 },
12106 { TG3PCI_SUBVENDOR_ID_BROADCOM,
12107 TG3PCI_SUBDEVICE_ID_BROADCOM_95700A9, 0 },
12108 { TG3PCI_SUBVENDOR_ID_BROADCOM,
12109 TG3PCI_SUBDEVICE_ID_BROADCOM_95701T1, TG3_PHY_ID_BCM5701 },
12110 { TG3PCI_SUBVENDOR_ID_BROADCOM,
12111 TG3PCI_SUBDEVICE_ID_BROADCOM_95701T8, TG3_PHY_ID_BCM5701 },
12112 { TG3PCI_SUBVENDOR_ID_BROADCOM,
12113 TG3PCI_SUBDEVICE_ID_BROADCOM_95701A7, 0 },
12114 { TG3PCI_SUBVENDOR_ID_BROADCOM,
12115 TG3PCI_SUBDEVICE_ID_BROADCOM_95701A10, TG3_PHY_ID_BCM5701 },
12116 { TG3PCI_SUBVENDOR_ID_BROADCOM,
12117 TG3PCI_SUBDEVICE_ID_BROADCOM_95701A12, TG3_PHY_ID_BCM5701 },
12118 { TG3PCI_SUBVENDOR_ID_BROADCOM,
12119 TG3PCI_SUBDEVICE_ID_BROADCOM_95703AX1, TG3_PHY_ID_BCM5703 },
12120 { TG3PCI_SUBVENDOR_ID_BROADCOM,
12121 TG3PCI_SUBDEVICE_ID_BROADCOM_95703AX2, TG3_PHY_ID_BCM5703 },
12124 { TG3PCI_SUBVENDOR_ID_3COM,
12125 TG3PCI_SUBDEVICE_ID_3COM_3C996T, TG3_PHY_ID_BCM5401 },
12126 { TG3PCI_SUBVENDOR_ID_3COM,
12127 TG3PCI_SUBDEVICE_ID_3COM_3C996BT, TG3_PHY_ID_BCM5701 },
12128 { TG3PCI_SUBVENDOR_ID_3COM,
12129 TG3PCI_SUBDEVICE_ID_3COM_3C996SX, 0 },
12130 { TG3PCI_SUBVENDOR_ID_3COM,
12131 TG3PCI_SUBDEVICE_ID_3COM_3C1000T, TG3_PHY_ID_BCM5701 },
12132 { TG3PCI_SUBVENDOR_ID_3COM,
12133 TG3PCI_SUBDEVICE_ID_3COM_3C940BR01, TG3_PHY_ID_BCM5701 },
12136 { TG3PCI_SUBVENDOR_ID_DELL,
12137 TG3PCI_SUBDEVICE_ID_DELL_VIPER, TG3_PHY_ID_BCM5401 },
12138 { TG3PCI_SUBVENDOR_ID_DELL,
12139 TG3PCI_SUBDEVICE_ID_DELL_JAGUAR, TG3_PHY_ID_BCM5401 },
12140 { TG3PCI_SUBVENDOR_ID_DELL,
12141 TG3PCI_SUBDEVICE_ID_DELL_MERLOT, TG3_PHY_ID_BCM5411 },
12142 { TG3PCI_SUBVENDOR_ID_DELL,
12143 TG3PCI_SUBDEVICE_ID_DELL_SLIM_MERLOT, TG3_PHY_ID_BCM5411 },
12145 /* Compaq boards. */
12146 { TG3PCI_SUBVENDOR_ID_COMPAQ,
12147 TG3PCI_SUBDEVICE_ID_COMPAQ_BANSHEE, TG3_PHY_ID_BCM5701 },
12148 { TG3PCI_SUBVENDOR_ID_COMPAQ,
12149 TG3PCI_SUBDEVICE_ID_COMPAQ_BANSHEE_2, TG3_PHY_ID_BCM5701 },
12150 { TG3PCI_SUBVENDOR_ID_COMPAQ,
12151 TG3PCI_SUBDEVICE_ID_COMPAQ_CHANGELING, 0 },
12152 { TG3PCI_SUBVENDOR_ID_COMPAQ,
12153 TG3PCI_SUBDEVICE_ID_COMPAQ_NC7780, TG3_PHY_ID_BCM5701 },
12154 { TG3PCI_SUBVENDOR_ID_COMPAQ,
12155 TG3PCI_SUBDEVICE_ID_COMPAQ_NC7780_2, TG3_PHY_ID_BCM5701 },
12158 { TG3PCI_SUBVENDOR_ID_IBM,
12159 TG3PCI_SUBDEVICE_ID_IBM_5703SAX2, 0 }
12162 static struct subsys_tbl_ent * __devinit tg3_lookup_by_subsys(struct tg3 *tp)
12166 for (i = 0; i < ARRAY_SIZE(subsys_id_to_phy_id); i++) {
12167 if ((subsys_id_to_phy_id[i].subsys_vendor ==
12168 tp->pdev->subsystem_vendor) &&
12169 (subsys_id_to_phy_id[i].subsys_devid ==
12170 tp->pdev->subsystem_device))
12171 return &subsys_id_to_phy_id[i];
12176 static void __devinit tg3_get_eeprom_hw_cfg(struct tg3 *tp)
12181 /* On some early chips the SRAM cannot be accessed in D3hot state,
12182 * so need make sure we're in D0.
12184 pci_read_config_word(tp->pdev, tp->pm_cap + PCI_PM_CTRL, &pmcsr);
12185 pmcsr &= ~PCI_PM_CTRL_STATE_MASK;
12186 pci_write_config_word(tp->pdev, tp->pm_cap + PCI_PM_CTRL, pmcsr);
12189 /* Make sure register accesses (indirect or otherwise)
12190 * will function correctly.
12192 pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL,
12193 tp->misc_host_ctrl);
12195 /* The memory arbiter has to be enabled in order for SRAM accesses
12196 * to succeed. Normally on powerup the tg3 chip firmware will make
12197 * sure it is enabled, but other entities such as system netboot
12198 * code might disable it.
12200 val = tr32(MEMARB_MODE);
12201 tw32(MEMARB_MODE, val | MEMARB_MODE_ENABLE);
12203 tp->phy_id = TG3_PHY_ID_INVALID;
12204 tp->led_ctrl = LED_CTRL_MODE_PHY_1;
12206 /* Assume an onboard device and WOL capable by default. */
12207 tp->tg3_flags |= TG3_FLAG_EEPROM_WRITE_PROT | TG3_FLAG_WOL_CAP;
12209 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
12210 if (!(tr32(PCIE_TRANSACTION_CFG) & PCIE_TRANS_CFG_LOM)) {
12211 tp->tg3_flags &= ~TG3_FLAG_EEPROM_WRITE_PROT;
12212 tp->tg3_flags2 |= TG3_FLG2_IS_NIC;
12214 val = tr32(VCPU_CFGSHDW);
12215 if (val & VCPU_CFGSHDW_ASPM_DBNC)
12216 tp->tg3_flags |= TG3_FLAG_ASPM_WORKAROUND;
12217 if ((val & VCPU_CFGSHDW_WOL_ENABLE) &&
12218 (val & VCPU_CFGSHDW_WOL_MAGPKT))
12219 tp->tg3_flags |= TG3_FLAG_WOL_ENABLE;
12223 tg3_read_mem(tp, NIC_SRAM_DATA_SIG, &val);
12224 if (val == NIC_SRAM_DATA_SIG_MAGIC) {
12225 u32 nic_cfg, led_cfg;
12226 u32 nic_phy_id, ver, cfg2 = 0, cfg4 = 0, eeprom_phy_id;
12227 int eeprom_phy_serdes = 0;
12229 tg3_read_mem(tp, NIC_SRAM_DATA_CFG, &nic_cfg);
12230 tp->nic_sram_data_cfg = nic_cfg;
12232 tg3_read_mem(tp, NIC_SRAM_DATA_VER, &ver);
12233 ver >>= NIC_SRAM_DATA_VER_SHIFT;
12234 if ((GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700) &&
12235 (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) &&
12236 (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5703) &&
12237 (ver > 0) && (ver < 0x100))
12238 tg3_read_mem(tp, NIC_SRAM_DATA_CFG_2, &cfg2);
12240 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785)
12241 tg3_read_mem(tp, NIC_SRAM_DATA_CFG_4, &cfg4);
12243 if ((nic_cfg & NIC_SRAM_DATA_CFG_PHY_TYPE_MASK) ==
12244 NIC_SRAM_DATA_CFG_PHY_TYPE_FIBER)
12245 eeprom_phy_serdes = 1;
12247 tg3_read_mem(tp, NIC_SRAM_DATA_PHY_ID, &nic_phy_id);
12248 if (nic_phy_id != 0) {
12249 u32 id1 = nic_phy_id & NIC_SRAM_DATA_PHY_ID1_MASK;
12250 u32 id2 = nic_phy_id & NIC_SRAM_DATA_PHY_ID2_MASK;
12252 eeprom_phy_id = (id1 >> 16) << 10;
12253 eeprom_phy_id |= (id2 & 0xfc00) << 16;
12254 eeprom_phy_id |= (id2 & 0x03ff) << 0;
12258 tp->phy_id = eeprom_phy_id;
12259 if (eeprom_phy_serdes) {
12260 if ((tp->tg3_flags2 & TG3_FLG2_5780_CLASS) ||
12261 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717)
12262 tp->tg3_flags2 |= TG3_FLG2_MII_SERDES;
12264 tp->tg3_flags2 |= TG3_FLG2_PHY_SERDES;
12267 if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS)
12268 led_cfg = cfg2 & (NIC_SRAM_DATA_CFG_LED_MODE_MASK |
12269 SHASTA_EXT_LED_MODE_MASK);
12271 led_cfg = nic_cfg & NIC_SRAM_DATA_CFG_LED_MODE_MASK;
12275 case NIC_SRAM_DATA_CFG_LED_MODE_PHY_1:
12276 tp->led_ctrl = LED_CTRL_MODE_PHY_1;
12279 case NIC_SRAM_DATA_CFG_LED_MODE_PHY_2:
12280 tp->led_ctrl = LED_CTRL_MODE_PHY_2;
12283 case NIC_SRAM_DATA_CFG_LED_MODE_MAC:
12284 tp->led_ctrl = LED_CTRL_MODE_MAC;
12286 /* Default to PHY_1_MODE if 0 (MAC_MODE) is
12287 * read on some older 5700/5701 bootcode.
12289 if (GET_ASIC_REV(tp->pci_chip_rev_id) ==
12291 GET_ASIC_REV(tp->pci_chip_rev_id) ==
12293 tp->led_ctrl = LED_CTRL_MODE_PHY_1;
12297 case SHASTA_EXT_LED_SHARED:
12298 tp->led_ctrl = LED_CTRL_MODE_SHARED;
12299 if (tp->pci_chip_rev_id != CHIPREV_ID_5750_A0 &&
12300 tp->pci_chip_rev_id != CHIPREV_ID_5750_A1)
12301 tp->led_ctrl |= (LED_CTRL_MODE_PHY_1 |
12302 LED_CTRL_MODE_PHY_2);
12305 case SHASTA_EXT_LED_MAC:
12306 tp->led_ctrl = LED_CTRL_MODE_SHASTA_MAC;
12309 case SHASTA_EXT_LED_COMBO:
12310 tp->led_ctrl = LED_CTRL_MODE_COMBO;
12311 if (tp->pci_chip_rev_id != CHIPREV_ID_5750_A0)
12312 tp->led_ctrl |= (LED_CTRL_MODE_PHY_1 |
12313 LED_CTRL_MODE_PHY_2);
12318 if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
12319 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) &&
12320 tp->pdev->subsystem_vendor == PCI_VENDOR_ID_DELL)
12321 tp->led_ctrl = LED_CTRL_MODE_PHY_2;
12323 if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5784_AX)
12324 tp->led_ctrl = LED_CTRL_MODE_PHY_1;
12326 if (nic_cfg & NIC_SRAM_DATA_CFG_EEPROM_WP) {
12327 tp->tg3_flags |= TG3_FLAG_EEPROM_WRITE_PROT;
12328 if ((tp->pdev->subsystem_vendor ==
12329 PCI_VENDOR_ID_ARIMA) &&
12330 (tp->pdev->subsystem_device == 0x205a ||
12331 tp->pdev->subsystem_device == 0x2063))
12332 tp->tg3_flags &= ~TG3_FLAG_EEPROM_WRITE_PROT;
12334 tp->tg3_flags &= ~TG3_FLAG_EEPROM_WRITE_PROT;
12335 tp->tg3_flags2 |= TG3_FLG2_IS_NIC;
12338 if (nic_cfg & NIC_SRAM_DATA_CFG_ASF_ENABLE) {
12339 tp->tg3_flags |= TG3_FLAG_ENABLE_ASF;
12340 if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS)
12341 tp->tg3_flags2 |= TG3_FLG2_ASF_NEW_HANDSHAKE;
12344 if ((nic_cfg & NIC_SRAM_DATA_CFG_APE_ENABLE) &&
12345 (tp->tg3_flags2 & TG3_FLG2_5750_PLUS))
12346 tp->tg3_flags3 |= TG3_FLG3_ENABLE_APE;
12348 if (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES &&
12349 !(nic_cfg & NIC_SRAM_DATA_CFG_FIBER_WOL))
12350 tp->tg3_flags &= ~TG3_FLAG_WOL_CAP;
12352 if ((tp->tg3_flags & TG3_FLAG_WOL_CAP) &&
12353 (nic_cfg & NIC_SRAM_DATA_CFG_WOL_ENABLE))
12354 tp->tg3_flags |= TG3_FLAG_WOL_ENABLE;
12356 if (cfg2 & (1 << 17))
12357 tp->tg3_flags2 |= TG3_FLG2_CAPACITIVE_COUPLING;
12359 /* serdes signal pre-emphasis in register 0x590 set by */
12360 /* bootcode if bit 18 is set */
12361 if (cfg2 & (1 << 18))
12362 tp->tg3_flags2 |= TG3_FLG2_SERDES_PREEMPHASIS;
12364 if (((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 &&
12365 GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5784_AX)) &&
12366 (cfg2 & NIC_SRAM_DATA_CFG_2_APD_EN))
12367 tp->tg3_flags3 |= TG3_FLG3_PHY_ENABLE_APD;
12369 if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) {
12372 tg3_read_mem(tp, NIC_SRAM_DATA_CFG_3, &cfg3);
12373 if (cfg3 & NIC_SRAM_ASPM_DEBOUNCE)
12374 tp->tg3_flags |= TG3_FLAG_ASPM_WORKAROUND;
12377 if (cfg4 & NIC_SRAM_RGMII_INBAND_DISABLE)
12378 tp->tg3_flags3 |= TG3_FLG3_RGMII_INBAND_DISABLE;
12379 if (cfg4 & NIC_SRAM_RGMII_EXT_IBND_RX_EN)
12380 tp->tg3_flags3 |= TG3_FLG3_RGMII_EXT_IBND_RX_EN;
12381 if (cfg4 & NIC_SRAM_RGMII_EXT_IBND_TX_EN)
12382 tp->tg3_flags3 |= TG3_FLG3_RGMII_EXT_IBND_TX_EN;
12385 device_init_wakeup(&tp->pdev->dev, tp->tg3_flags & TG3_FLAG_WOL_CAP);
12386 device_set_wakeup_enable(&tp->pdev->dev,
12387 tp->tg3_flags & TG3_FLAG_WOL_ENABLE);
12390 static int __devinit tg3_issue_otp_command(struct tg3 *tp, u32 cmd)
12395 tw32(OTP_CTRL, cmd | OTP_CTRL_OTP_CMD_START);
12396 tw32(OTP_CTRL, cmd);
12398 /* Wait for up to 1 ms for command to execute. */
12399 for (i = 0; i < 100; i++) {
12400 val = tr32(OTP_STATUS);
12401 if (val & OTP_STATUS_CMD_DONE)
12406 return (val & OTP_STATUS_CMD_DONE) ? 0 : -EBUSY;
12409 /* Read the gphy configuration from the OTP region of the chip. The gphy
12410 * configuration is a 32-bit value that straddles the alignment boundary.
12411 * We do two 32-bit reads and then shift and merge the results.
12413 static u32 __devinit tg3_read_otp_phycfg(struct tg3 *tp)
12415 u32 bhalf_otp, thalf_otp;
12417 tw32(OTP_MODE, OTP_MODE_OTP_THRU_GRC);
12419 if (tg3_issue_otp_command(tp, OTP_CTRL_OTP_CMD_INIT))
12422 tw32(OTP_ADDRESS, OTP_ADDRESS_MAGIC1);
12424 if (tg3_issue_otp_command(tp, OTP_CTRL_OTP_CMD_READ))
12427 thalf_otp = tr32(OTP_READ_DATA);
12429 tw32(OTP_ADDRESS, OTP_ADDRESS_MAGIC2);
12431 if (tg3_issue_otp_command(tp, OTP_CTRL_OTP_CMD_READ))
12434 bhalf_otp = tr32(OTP_READ_DATA);
12436 return ((thalf_otp & 0x0000ffff) << 16) | (bhalf_otp >> 16);
12439 static int __devinit tg3_phy_probe(struct tg3 *tp)
12441 u32 hw_phy_id_1, hw_phy_id_2;
12442 u32 hw_phy_id, hw_phy_id_masked;
12445 if (tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB)
12446 return tg3_phy_init(tp);
12448 /* Reading the PHY ID register can conflict with ASF
12449 * firmware access to the PHY hardware.
12452 if ((tp->tg3_flags & TG3_FLAG_ENABLE_ASF) ||
12453 (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE)) {
12454 hw_phy_id = hw_phy_id_masked = TG3_PHY_ID_INVALID;
12456 /* Now read the physical PHY_ID from the chip and verify
12457 * that it is sane. If it doesn't look good, we fall back
12458 * to either the hard-coded table based PHY_ID and failing
12459 * that the value found in the eeprom area.
12461 err |= tg3_readphy(tp, MII_PHYSID1, &hw_phy_id_1);
12462 err |= tg3_readphy(tp, MII_PHYSID2, &hw_phy_id_2);
12464 hw_phy_id = (hw_phy_id_1 & 0xffff) << 10;
12465 hw_phy_id |= (hw_phy_id_2 & 0xfc00) << 16;
12466 hw_phy_id |= (hw_phy_id_2 & 0x03ff) << 0;
12468 hw_phy_id_masked = hw_phy_id & TG3_PHY_ID_MASK;
12471 if (!err && TG3_KNOWN_PHY_ID(hw_phy_id_masked)) {
12472 tp->phy_id = hw_phy_id;
12473 if (hw_phy_id_masked == TG3_PHY_ID_BCM8002)
12474 tp->tg3_flags2 |= TG3_FLG2_PHY_SERDES;
12476 tp->tg3_flags2 &= ~TG3_FLG2_PHY_SERDES;
12478 if (tp->phy_id != TG3_PHY_ID_INVALID) {
12479 /* Do nothing, phy ID already set up in
12480 * tg3_get_eeprom_hw_cfg().
12483 struct subsys_tbl_ent *p;
12485 /* No eeprom signature? Try the hardcoded
12486 * subsys device table.
12488 p = tg3_lookup_by_subsys(tp);
12492 tp->phy_id = p->phy_id;
12494 tp->phy_id == TG3_PHY_ID_BCM8002)
12495 tp->tg3_flags2 |= TG3_FLG2_PHY_SERDES;
12499 if (!(tp->tg3_flags2 & TG3_FLG2_ANY_SERDES) &&
12500 !(tp->tg3_flags3 & TG3_FLG3_ENABLE_APE) &&
12501 !(tp->tg3_flags & TG3_FLAG_ENABLE_ASF)) {
12502 u32 bmsr, adv_reg, tg3_ctrl, mask;
12504 tg3_readphy(tp, MII_BMSR, &bmsr);
12505 if (!tg3_readphy(tp, MII_BMSR, &bmsr) &&
12506 (bmsr & BMSR_LSTATUS))
12507 goto skip_phy_reset;
12509 err = tg3_phy_reset(tp);
12513 adv_reg = (ADVERTISE_10HALF | ADVERTISE_10FULL |
12514 ADVERTISE_100HALF | ADVERTISE_100FULL |
12515 ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP);
12517 if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY)) {
12518 tg3_ctrl = (MII_TG3_CTRL_ADV_1000_HALF |
12519 MII_TG3_CTRL_ADV_1000_FULL);
12520 if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 ||
12521 tp->pci_chip_rev_id == CHIPREV_ID_5701_B0)
12522 tg3_ctrl |= (MII_TG3_CTRL_AS_MASTER |
12523 MII_TG3_CTRL_ENABLE_AS_MASTER);
12526 mask = (ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full |
12527 ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full |
12528 ADVERTISED_1000baseT_Half | ADVERTISED_1000baseT_Full);
12529 if (!tg3_copper_is_advertising_all(tp, mask)) {
12530 tg3_writephy(tp, MII_ADVERTISE, adv_reg);
12532 if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY))
12533 tg3_writephy(tp, MII_TG3_CTRL, tg3_ctrl);
12535 tg3_writephy(tp, MII_BMCR,
12536 BMCR_ANENABLE | BMCR_ANRESTART);
12538 tg3_phy_set_wirespeed(tp);
12540 tg3_writephy(tp, MII_ADVERTISE, adv_reg);
12541 if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY))
12542 tg3_writephy(tp, MII_TG3_CTRL, tg3_ctrl);
12546 if ((tp->phy_id & TG3_PHY_ID_MASK) == TG3_PHY_ID_BCM5401) {
12547 err = tg3_init_5401phy_dsp(tp);
12551 err = tg3_init_5401phy_dsp(tp);
12554 if (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES)
12555 tp->link_config.advertising =
12556 (ADVERTISED_1000baseT_Half |
12557 ADVERTISED_1000baseT_Full |
12558 ADVERTISED_Autoneg |
12560 if (tp->tg3_flags & TG3_FLAG_10_100_ONLY)
12561 tp->link_config.advertising &=
12562 ~(ADVERTISED_1000baseT_Half |
12563 ADVERTISED_1000baseT_Full);
12568 static void __devinit tg3_read_vpd(struct tg3 *tp)
12570 u8 vpd_data[TG3_NVM_VPD_LEN];
12571 unsigned int block_end, rosize, len;
12575 if ((tp->tg3_flags3 & TG3_FLG3_NO_NVRAM) ||
12576 tg3_nvram_read(tp, 0x0, &magic))
12577 goto out_not_found;
12579 if (magic == TG3_EEPROM_MAGIC) {
12580 for (i = 0; i < TG3_NVM_VPD_LEN; i += 4) {
12583 /* The data is in little-endian format in NVRAM.
12584 * Use the big-endian read routines to preserve
12585 * the byte order as it exists in NVRAM.
12587 if (tg3_nvram_read_be32(tp, TG3_NVM_VPD_OFF + i, &tmp))
12588 goto out_not_found;
12590 memcpy(&vpd_data[i], &tmp, sizeof(tmp));
12594 unsigned int pos = 0;
12596 for (; pos < TG3_NVM_VPD_LEN && i < 3; i++, pos += cnt) {
12597 cnt = pci_read_vpd(tp->pdev, pos,
12598 TG3_NVM_VPD_LEN - pos,
12600 if (cnt == -ETIMEDOUT || -EINTR)
12603 goto out_not_found;
12605 if (pos != TG3_NVM_VPD_LEN)
12606 goto out_not_found;
12609 i = pci_vpd_find_tag(vpd_data, 0, TG3_NVM_VPD_LEN,
12610 PCI_VPD_LRDT_RO_DATA);
12612 goto out_not_found;
12614 rosize = pci_vpd_lrdt_size(&vpd_data[i]);
12615 block_end = i + PCI_VPD_LRDT_TAG_SIZE + rosize;
12616 i += PCI_VPD_LRDT_TAG_SIZE;
12618 if (block_end > TG3_NVM_VPD_LEN)
12619 goto out_not_found;
12621 j = pci_vpd_find_info_keyword(vpd_data, i, rosize,
12622 PCI_VPD_RO_KEYWORD_MFR_ID);
12624 len = pci_vpd_info_field_size(&vpd_data[j]);
12626 j += PCI_VPD_INFO_FLD_HDR_SIZE;
12627 if (j + len > block_end || len != 4 ||
12628 memcmp(&vpd_data[j], "1028", 4))
12631 j = pci_vpd_find_info_keyword(vpd_data, i, rosize,
12632 PCI_VPD_RO_KEYWORD_VENDOR0);
12636 len = pci_vpd_info_field_size(&vpd_data[j]);
12638 j += PCI_VPD_INFO_FLD_HDR_SIZE;
12639 if (j + len > block_end)
12642 memcpy(tp->fw_ver, &vpd_data[j], len);
12643 strncat(tp->fw_ver, " bc ", TG3_NVM_VPD_LEN - len - 1);
12647 i = pci_vpd_find_info_keyword(vpd_data, i, rosize,
12648 PCI_VPD_RO_KEYWORD_PARTNO);
12650 goto out_not_found;
12652 len = pci_vpd_info_field_size(&vpd_data[i]);
12654 i += PCI_VPD_INFO_FLD_HDR_SIZE;
12655 if (len > TG3_BPN_SIZE ||
12656 (len + i) > TG3_NVM_VPD_LEN)
12657 goto out_not_found;
12659 memcpy(tp->board_part_number, &vpd_data[i], len);
12664 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)
12665 strcpy(tp->board_part_number, "BCM95906");
12666 else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780 &&
12667 tp->pdev->device == TG3PCI_DEVICE_TIGON3_57780)
12668 strcpy(tp->board_part_number, "BCM57780");
12669 else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780 &&
12670 tp->pdev->device == TG3PCI_DEVICE_TIGON3_57760)
12671 strcpy(tp->board_part_number, "BCM57760");
12672 else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780 &&
12673 tp->pdev->device == TG3PCI_DEVICE_TIGON3_57790)
12674 strcpy(tp->board_part_number, "BCM57790");
12675 else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780 &&
12676 tp->pdev->device == TG3PCI_DEVICE_TIGON3_57788)
12677 strcpy(tp->board_part_number, "BCM57788");
12678 else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765 &&
12679 tp->pdev->device == TG3PCI_DEVICE_TIGON3_57761)
12680 strcpy(tp->board_part_number, "BCM57761");
12681 else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765 &&
12682 tp->pdev->device == TG3PCI_DEVICE_TIGON3_57765)
12683 strcpy(tp->board_part_number, "BCM57765");
12684 else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765 &&
12685 tp->pdev->device == TG3PCI_DEVICE_TIGON3_57781)
12686 strcpy(tp->board_part_number, "BCM57781");
12687 else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765 &&
12688 tp->pdev->device == TG3PCI_DEVICE_TIGON3_57785)
12689 strcpy(tp->board_part_number, "BCM57785");
12690 else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765 &&
12691 tp->pdev->device == TG3PCI_DEVICE_TIGON3_57791)
12692 strcpy(tp->board_part_number, "BCM57791");
12693 else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765 &&
12694 tp->pdev->device == TG3PCI_DEVICE_TIGON3_57795)
12695 strcpy(tp->board_part_number, "BCM57795");
12697 strcpy(tp->board_part_number, "none");
12700 static int __devinit tg3_fw_img_is_valid(struct tg3 *tp, u32 offset)
12704 if (tg3_nvram_read(tp, offset, &val) ||
12705 (val & 0xfc000000) != 0x0c000000 ||
12706 tg3_nvram_read(tp, offset + 4, &val) ||
12713 static void __devinit tg3_read_bc_ver(struct tg3 *tp)
12715 u32 val, offset, start, ver_offset;
12717 bool newver = false;
12719 if (tg3_nvram_read(tp, 0xc, &offset) ||
12720 tg3_nvram_read(tp, 0x4, &start))
12723 offset = tg3_nvram_logical_addr(tp, offset);
12725 if (tg3_nvram_read(tp, offset, &val))
12728 if ((val & 0xfc000000) == 0x0c000000) {
12729 if (tg3_nvram_read(tp, offset + 4, &val))
12736 dst_off = strlen(tp->fw_ver);
12739 if (TG3_VER_SIZE - dst_off < 16 ||
12740 tg3_nvram_read(tp, offset + 8, &ver_offset))
12743 offset = offset + ver_offset - start;
12744 for (i = 0; i < 16; i += 4) {
12746 if (tg3_nvram_read_be32(tp, offset + i, &v))
12749 memcpy(tp->fw_ver + dst_off + i, &v, sizeof(v));
12754 if (tg3_nvram_read(tp, TG3_NVM_PTREV_BCVER, &ver_offset))
12757 major = (ver_offset & TG3_NVM_BCVER_MAJMSK) >>
12758 TG3_NVM_BCVER_MAJSFT;
12759 minor = ver_offset & TG3_NVM_BCVER_MINMSK;
12760 snprintf(&tp->fw_ver[dst_off], TG3_VER_SIZE - dst_off,
12761 "v%d.%02d", major, minor);
12765 static void __devinit tg3_read_hwsb_ver(struct tg3 *tp)
12767 u32 val, major, minor;
12769 /* Use native endian representation */
12770 if (tg3_nvram_read(tp, TG3_NVM_HWSB_CFG1, &val))
12773 major = (val & TG3_NVM_HWSB_CFG1_MAJMSK) >>
12774 TG3_NVM_HWSB_CFG1_MAJSFT;
12775 minor = (val & TG3_NVM_HWSB_CFG1_MINMSK) >>
12776 TG3_NVM_HWSB_CFG1_MINSFT;
12778 snprintf(&tp->fw_ver[0], 32, "sb v%d.%02d", major, minor);
12781 static void __devinit tg3_read_sb_ver(struct tg3 *tp, u32 val)
12783 u32 offset, major, minor, build;
12785 strncat(tp->fw_ver, "sb", TG3_VER_SIZE - strlen(tp->fw_ver) - 1);
12787 if ((val & TG3_EEPROM_SB_FORMAT_MASK) != TG3_EEPROM_SB_FORMAT_1)
12790 switch (val & TG3_EEPROM_SB_REVISION_MASK) {
12791 case TG3_EEPROM_SB_REVISION_0:
12792 offset = TG3_EEPROM_SB_F1R0_EDH_OFF;
12794 case TG3_EEPROM_SB_REVISION_2:
12795 offset = TG3_EEPROM_SB_F1R2_EDH_OFF;
12797 case TG3_EEPROM_SB_REVISION_3:
12798 offset = TG3_EEPROM_SB_F1R3_EDH_OFF;
12800 case TG3_EEPROM_SB_REVISION_4:
12801 offset = TG3_EEPROM_SB_F1R4_EDH_OFF;
12803 case TG3_EEPROM_SB_REVISION_5:
12804 offset = TG3_EEPROM_SB_F1R5_EDH_OFF;
12810 if (tg3_nvram_read(tp, offset, &val))
12813 build = (val & TG3_EEPROM_SB_EDH_BLD_MASK) >>
12814 TG3_EEPROM_SB_EDH_BLD_SHFT;
12815 major = (val & TG3_EEPROM_SB_EDH_MAJ_MASK) >>
12816 TG3_EEPROM_SB_EDH_MAJ_SHFT;
12817 minor = val & TG3_EEPROM_SB_EDH_MIN_MASK;
12819 if (minor > 99 || build > 26)
12822 offset = strlen(tp->fw_ver);
12823 snprintf(&tp->fw_ver[offset], TG3_VER_SIZE - offset,
12824 " v%d.%02d", major, minor);
12827 offset = strlen(tp->fw_ver);
12828 if (offset < TG3_VER_SIZE - 1)
12829 tp->fw_ver[offset] = 'a' + build - 1;
12833 static void __devinit tg3_read_mgmtfw_ver(struct tg3 *tp)
12835 u32 val, offset, start;
12838 for (offset = TG3_NVM_DIR_START;
12839 offset < TG3_NVM_DIR_END;
12840 offset += TG3_NVM_DIRENT_SIZE) {
12841 if (tg3_nvram_read(tp, offset, &val))
12844 if ((val >> TG3_NVM_DIRTYPE_SHIFT) == TG3_NVM_DIRTYPE_ASFINI)
12848 if (offset == TG3_NVM_DIR_END)
12851 if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS))
12852 start = 0x08000000;
12853 else if (tg3_nvram_read(tp, offset - 4, &start))
12856 if (tg3_nvram_read(tp, offset + 4, &offset) ||
12857 !tg3_fw_img_is_valid(tp, offset) ||
12858 tg3_nvram_read(tp, offset + 8, &val))
12861 offset += val - start;
12863 vlen = strlen(tp->fw_ver);
12865 tp->fw_ver[vlen++] = ',';
12866 tp->fw_ver[vlen++] = ' ';
12868 for (i = 0; i < 4; i++) {
12870 if (tg3_nvram_read_be32(tp, offset, &v))
12873 offset += sizeof(v);
12875 if (vlen > TG3_VER_SIZE - sizeof(v)) {
12876 memcpy(&tp->fw_ver[vlen], &v, TG3_VER_SIZE - vlen);
12880 memcpy(&tp->fw_ver[vlen], &v, sizeof(v));
12885 static void __devinit tg3_read_dash_ver(struct tg3 *tp)
12890 if (!(tp->tg3_flags3 & TG3_FLG3_ENABLE_APE) ||
12891 !(tp->tg3_flags & TG3_FLAG_ENABLE_ASF))
12894 apedata = tg3_ape_read32(tp, TG3_APE_SEG_SIG);
12895 if (apedata != APE_SEG_SIG_MAGIC)
12898 apedata = tg3_ape_read32(tp, TG3_APE_FW_STATUS);
12899 if (!(apedata & APE_FW_STATUS_READY))
12902 apedata = tg3_ape_read32(tp, TG3_APE_FW_VERSION);
12904 vlen = strlen(tp->fw_ver);
12906 snprintf(&tp->fw_ver[vlen], TG3_VER_SIZE - vlen, " DASH v%d.%d.%d.%d",
12907 (apedata & APE_FW_VERSION_MAJMSK) >> APE_FW_VERSION_MAJSFT,
12908 (apedata & APE_FW_VERSION_MINMSK) >> APE_FW_VERSION_MINSFT,
12909 (apedata & APE_FW_VERSION_REVMSK) >> APE_FW_VERSION_REVSFT,
12910 (apedata & APE_FW_VERSION_BLDMSK));
12913 static void __devinit tg3_read_fw_ver(struct tg3 *tp)
12916 bool vpd_vers = false;
12918 if (tp->fw_ver[0] != 0)
12921 if (tp->tg3_flags3 & TG3_FLG3_NO_NVRAM) {
12922 strcat(tp->fw_ver, "sb");
12926 if (tg3_nvram_read(tp, 0, &val))
12929 if (val == TG3_EEPROM_MAGIC)
12930 tg3_read_bc_ver(tp);
12931 else if ((val & TG3_EEPROM_MAGIC_FW_MSK) == TG3_EEPROM_MAGIC_FW)
12932 tg3_read_sb_ver(tp, val);
12933 else if ((val & TG3_EEPROM_MAGIC_HW_MSK) == TG3_EEPROM_MAGIC_HW)
12934 tg3_read_hwsb_ver(tp);
12938 if (!(tp->tg3_flags & TG3_FLAG_ENABLE_ASF) ||
12939 (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE) || vpd_vers)
12942 tg3_read_mgmtfw_ver(tp);
12945 tp->fw_ver[TG3_VER_SIZE - 1] = 0;
12948 static struct pci_dev * __devinit tg3_find_peer(struct tg3 *);
12950 static int __devinit tg3_get_invariants(struct tg3 *tp)
12952 static struct pci_device_id write_reorder_chipsets[] = {
12953 { PCI_DEVICE(PCI_VENDOR_ID_AMD,
12954 PCI_DEVICE_ID_AMD_FE_GATE_700C) },
12955 { PCI_DEVICE(PCI_VENDOR_ID_AMD,
12956 PCI_DEVICE_ID_AMD_8131_BRIDGE) },
12957 { PCI_DEVICE(PCI_VENDOR_ID_VIA,
12958 PCI_DEVICE_ID_VIA_8385_0) },
12962 u32 pci_state_reg, grc_misc_cfg;
12967 /* Force memory write invalidate off. If we leave it on,
12968 * then on 5700_BX chips we have to enable a workaround.
12969 * The workaround is to set the TG3PCI_DMA_RW_CTRL boundary
12970 * to match the cacheline size. The Broadcom driver have this
12971 * workaround but turns MWI off all the times so never uses
12972 * it. This seems to suggest that the workaround is insufficient.
12974 pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd);
12975 pci_cmd &= ~PCI_COMMAND_INVALIDATE;
12976 pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd);
12978 /* It is absolutely critical that TG3PCI_MISC_HOST_CTRL
12979 * has the register indirect write enable bit set before
12980 * we try to access any of the MMIO registers. It is also
12981 * critical that the PCI-X hw workaround situation is decided
12982 * before that as well.
12984 pci_read_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL,
12987 tp->pci_chip_rev_id = (misc_ctrl_reg >>
12988 MISC_HOST_CTRL_CHIPREV_SHIFT);
12989 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_USE_PROD_ID_REG) {
12990 u32 prod_id_asic_rev;
12992 if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_5717 ||
12993 tp->pdev->device == TG3PCI_DEVICE_TIGON3_5718 ||
12994 tp->pdev->device == TG3PCI_DEVICE_TIGON3_5724)
12995 pci_read_config_dword(tp->pdev,
12996 TG3PCI_GEN2_PRODID_ASICREV,
12997 &prod_id_asic_rev);
12998 else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57781 ||
12999 tp->pdev->device == TG3PCI_DEVICE_TIGON3_57785 ||
13000 tp->pdev->device == TG3PCI_DEVICE_TIGON3_57761 ||
13001 tp->pdev->device == TG3PCI_DEVICE_TIGON3_57765 ||
13002 tp->pdev->device == TG3PCI_DEVICE_TIGON3_57791 ||
13003 tp->pdev->device == TG3PCI_DEVICE_TIGON3_57795)
13004 pci_read_config_dword(tp->pdev,
13005 TG3PCI_GEN15_PRODID_ASICREV,
13006 &prod_id_asic_rev);
13008 pci_read_config_dword(tp->pdev, TG3PCI_PRODID_ASICREV,
13009 &prod_id_asic_rev);
13011 tp->pci_chip_rev_id = prod_id_asic_rev;
13014 /* Wrong chip ID in 5752 A0. This code can be removed later
13015 * as A0 is not in production.
13017 if (tp->pci_chip_rev_id == CHIPREV_ID_5752_A0_HW)
13018 tp->pci_chip_rev_id = CHIPREV_ID_5752_A0;
13020 /* If we have 5702/03 A1 or A2 on certain ICH chipsets,
13021 * we need to disable memory and use config. cycles
13022 * only to access all registers. The 5702/03 chips
13023 * can mistakenly decode the special cycles from the
13024 * ICH chipsets as memory write cycles, causing corruption
13025 * of register and memory space. Only certain ICH bridges
13026 * will drive special cycles with non-zero data during the
13027 * address phase which can fall within the 5703's address
13028 * range. This is not an ICH bug as the PCI spec allows
13029 * non-zero address during special cycles. However, only
13030 * these ICH bridges are known to drive non-zero addresses
13031 * during special cycles.
13033 * Since special cycles do not cross PCI bridges, we only
13034 * enable this workaround if the 5703 is on the secondary
13035 * bus of these ICH bridges.
13037 if ((tp->pci_chip_rev_id == CHIPREV_ID_5703_A1) ||
13038 (tp->pci_chip_rev_id == CHIPREV_ID_5703_A2)) {
13039 static struct tg3_dev_id {
13043 } ich_chipsets[] = {
13044 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AA_8,
13046 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AB_8,
13048 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_11,
13050 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_6,
13054 struct tg3_dev_id *pci_id = &ich_chipsets[0];
13055 struct pci_dev *bridge = NULL;
13057 while (pci_id->vendor != 0) {
13058 bridge = pci_get_device(pci_id->vendor, pci_id->device,
13064 if (pci_id->rev != PCI_ANY_ID) {
13065 if (bridge->revision > pci_id->rev)
13068 if (bridge->subordinate &&
13069 (bridge->subordinate->number ==
13070 tp->pdev->bus->number)) {
13072 tp->tg3_flags2 |= TG3_FLG2_ICH_WORKAROUND;
13073 pci_dev_put(bridge);
13079 if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701)) {
13080 static struct tg3_dev_id {
13083 } bridge_chipsets[] = {
13084 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PXH_0 },
13085 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PXH_1 },
13088 struct tg3_dev_id *pci_id = &bridge_chipsets[0];
13089 struct pci_dev *bridge = NULL;
13091 while (pci_id->vendor != 0) {
13092 bridge = pci_get_device(pci_id->vendor,
13099 if (bridge->subordinate &&
13100 (bridge->subordinate->number <=
13101 tp->pdev->bus->number) &&
13102 (bridge->subordinate->subordinate >=
13103 tp->pdev->bus->number)) {
13104 tp->tg3_flags3 |= TG3_FLG3_5701_DMA_BUG;
13105 pci_dev_put(bridge);
13111 /* The EPB bridge inside 5714, 5715, and 5780 cannot support
13112 * DMA addresses > 40-bit. This bridge may have other additional
13113 * 57xx devices behind it in some 4-port NIC designs for example.
13114 * Any tg3 device found behind the bridge will also need the 40-bit
13117 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780 ||
13118 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) {
13119 tp->tg3_flags2 |= TG3_FLG2_5780_CLASS;
13120 tp->tg3_flags |= TG3_FLAG_40BIT_DMA_BUG;
13121 tp->msi_cap = pci_find_capability(tp->pdev, PCI_CAP_ID_MSI);
13124 struct pci_dev *bridge = NULL;
13127 bridge = pci_get_device(PCI_VENDOR_ID_SERVERWORKS,
13128 PCI_DEVICE_ID_SERVERWORKS_EPB,
13130 if (bridge && bridge->subordinate &&
13131 (bridge->subordinate->number <=
13132 tp->pdev->bus->number) &&
13133 (bridge->subordinate->subordinate >=
13134 tp->pdev->bus->number)) {
13135 tp->tg3_flags |= TG3_FLAG_40BIT_DMA_BUG;
13136 pci_dev_put(bridge);
13142 /* Initialize misc host control in PCI block. */
13143 tp->misc_host_ctrl |= (misc_ctrl_reg &
13144 MISC_HOST_CTRL_CHIPREV);
13145 pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL,
13146 tp->misc_host_ctrl);
13148 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 ||
13149 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714 ||
13150 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717)
13151 tp->pdev_peer = tg3_find_peer(tp);
13153 /* Intentionally exclude ASIC_REV_5906 */
13154 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
13155 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 ||
13156 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 ||
13157 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761 ||
13158 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 ||
13159 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780 ||
13160 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 ||
13161 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765)
13162 tp->tg3_flags3 |= TG3_FLG3_5755_PLUS;
13164 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750 ||
13165 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 ||
13166 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906 ||
13167 (tp->tg3_flags3 & TG3_FLG3_5755_PLUS) ||
13168 (tp->tg3_flags2 & TG3_FLG2_5780_CLASS))
13169 tp->tg3_flags2 |= TG3_FLG2_5750_PLUS;
13171 if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) ||
13172 (tp->tg3_flags2 & TG3_FLG2_5750_PLUS))
13173 tp->tg3_flags2 |= TG3_FLG2_5705_PLUS;
13175 /* 5700 B0 chips do not support checksumming correctly due
13176 * to hardware bugs.
13178 if (tp->pci_chip_rev_id == CHIPREV_ID_5700_B0)
13179 tp->tg3_flags |= TG3_FLAG_BROKEN_CHECKSUMS;
13181 tp->tg3_flags |= TG3_FLAG_RX_CHECKSUMS;
13182 tp->dev->features |= NETIF_F_IP_CSUM | NETIF_F_SG;
13183 if (tp->tg3_flags3 & TG3_FLG3_5755_PLUS)
13184 tp->dev->features |= NETIF_F_IPV6_CSUM;
13187 /* Determine TSO capabilities */
13188 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 ||
13189 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765)
13190 tp->tg3_flags2 |= TG3_FLG2_HW_TSO_3;
13191 else if ((tp->tg3_flags3 & TG3_FLG3_5755_PLUS) ||
13192 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)
13193 tp->tg3_flags2 |= TG3_FLG2_HW_TSO_2;
13194 else if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS) {
13195 tp->tg3_flags2 |= TG3_FLG2_HW_TSO_1 | TG3_FLG2_TSO_BUG;
13196 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750 &&
13197 tp->pci_chip_rev_id >= CHIPREV_ID_5750_C2)
13198 tp->tg3_flags2 &= ~TG3_FLG2_TSO_BUG;
13199 } else if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 &&
13200 GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701 &&
13201 tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) {
13202 tp->tg3_flags2 |= TG3_FLG2_TSO_BUG;
13203 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705)
13204 tp->fw_needed = FIRMWARE_TG3TSO5;
13206 tp->fw_needed = FIRMWARE_TG3TSO;
13211 if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS) {
13212 tp->tg3_flags |= TG3_FLAG_SUPPORT_MSI;
13213 if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_AX ||
13214 GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_BX ||
13215 (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714 &&
13216 tp->pci_chip_rev_id <= CHIPREV_ID_5714_A2 &&
13217 tp->pdev_peer == tp->pdev))
13218 tp->tg3_flags &= ~TG3_FLAG_SUPPORT_MSI;
13220 if ((tp->tg3_flags3 & TG3_FLG3_5755_PLUS) ||
13221 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
13222 tp->tg3_flags2 |= TG3_FLG2_1SHOT_MSI;
13225 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 ||
13226 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) {
13227 tp->tg3_flags |= TG3_FLAG_SUPPORT_MSIX;
13228 tp->irq_max = TG3_IRQ_MAX_VECS;
13232 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 ||
13233 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)
13234 tp->tg3_flags3 |= TG3_FLG3_SHORT_DMA_BUG;
13235 else if (!(tp->tg3_flags3 & TG3_FLG3_5755_PLUS)) {
13236 tp->tg3_flags3 |= TG3_FLG3_4G_DMA_BNDRY_BUG;
13237 tp->tg3_flags3 |= TG3_FLG3_40BIT_DMA_LIMIT_BUG;
13240 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 ||
13241 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765)
13242 tp->tg3_flags3 |= TG3_FLG3_USE_JUMBO_BDFLAG;
13244 if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS) ||
13245 (tp->tg3_flags2 & TG3_FLG2_5780_CLASS) ||
13246 (tp->tg3_flags3 & TG3_FLG3_USE_JUMBO_BDFLAG))
13247 tp->tg3_flags |= TG3_FLAG_JUMBO_CAPABLE;
13249 pci_read_config_dword(tp->pdev, TG3PCI_PCISTATE,
13252 tp->pcie_cap = pci_find_capability(tp->pdev, PCI_CAP_ID_EXP);
13253 if (tp->pcie_cap != 0) {
13256 tp->tg3_flags2 |= TG3_FLG2_PCI_EXPRESS;
13258 pcie_set_readrq(tp->pdev, 4096);
13260 pci_read_config_word(tp->pdev,
13261 tp->pcie_cap + PCI_EXP_LNKCTL,
13263 if (lnkctl & PCI_EXP_LNKCTL_CLKREQ_EN) {
13264 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)
13265 tp->tg3_flags2 &= ~TG3_FLG2_HW_TSO_2;
13266 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 ||
13267 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761 ||
13268 tp->pci_chip_rev_id == CHIPREV_ID_57780_A0 ||
13269 tp->pci_chip_rev_id == CHIPREV_ID_57780_A1)
13270 tp->tg3_flags3 |= TG3_FLG3_CLKREQ_BUG;
13271 } else if (tp->pci_chip_rev_id == CHIPREV_ID_5717_A0) {
13272 tp->tg3_flags3 |= TG3_FLG3_L1PLLPD_EN;
13274 } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) {
13275 tp->tg3_flags2 |= TG3_FLG2_PCI_EXPRESS;
13276 } else if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS) ||
13277 (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) {
13278 tp->pcix_cap = pci_find_capability(tp->pdev, PCI_CAP_ID_PCIX);
13279 if (!tp->pcix_cap) {
13280 dev_err(&tp->pdev->dev,
13281 "Cannot find PCI-X capability, aborting\n");
13285 if (!(pci_state_reg & PCISTATE_CONV_PCI_MODE))
13286 tp->tg3_flags |= TG3_FLAG_PCIX_MODE;
13289 /* If we have an AMD 762 or VIA K8T800 chipset, write
13290 * reordering to the mailbox registers done by the host
13291 * controller can cause major troubles. We read back from
13292 * every mailbox register write to force the writes to be
13293 * posted to the chip in order.
13295 if (pci_dev_present(write_reorder_chipsets) &&
13296 !(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS))
13297 tp->tg3_flags |= TG3_FLAG_MBOX_WRITE_REORDER;
13299 pci_read_config_byte(tp->pdev, PCI_CACHE_LINE_SIZE,
13300 &tp->pci_cacheline_sz);
13301 pci_read_config_byte(tp->pdev, PCI_LATENCY_TIMER,
13302 &tp->pci_lat_timer);
13303 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 &&
13304 tp->pci_lat_timer < 64) {
13305 tp->pci_lat_timer = 64;
13306 pci_write_config_byte(tp->pdev, PCI_LATENCY_TIMER,
13307 tp->pci_lat_timer);
13310 if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5700_BX) {
13311 /* 5700 BX chips need to have their TX producer index
13312 * mailboxes written twice to workaround a bug.
13314 tp->tg3_flags |= TG3_FLAG_TXD_MBOX_HWBUG;
13316 /* If we are in PCI-X mode, enable register write workaround.
13318 * The workaround is to use indirect register accesses
13319 * for all chip writes not to mailbox registers.
13321 if (tp->tg3_flags & TG3_FLAG_PCIX_MODE) {
13324 tp->tg3_flags |= TG3_FLAG_PCIX_TARGET_HWBUG;
13326 /* The chip can have it's power management PCI config
13327 * space registers clobbered due to this bug.
13328 * So explicitly force the chip into D0 here.
13330 pci_read_config_dword(tp->pdev,
13331 tp->pm_cap + PCI_PM_CTRL,
13333 pm_reg &= ~PCI_PM_CTRL_STATE_MASK;
13334 pm_reg |= PCI_PM_CTRL_PME_ENABLE | 0 /* D0 */;
13335 pci_write_config_dword(tp->pdev,
13336 tp->pm_cap + PCI_PM_CTRL,
13339 /* Also, force SERR#/PERR# in PCI command. */
13340 pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd);
13341 pci_cmd |= PCI_COMMAND_PARITY | PCI_COMMAND_SERR;
13342 pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd);
13346 if ((pci_state_reg & PCISTATE_BUS_SPEED_HIGH) != 0)
13347 tp->tg3_flags |= TG3_FLAG_PCI_HIGH_SPEED;
13348 if ((pci_state_reg & PCISTATE_BUS_32BIT) != 0)
13349 tp->tg3_flags |= TG3_FLAG_PCI_32BIT;
13351 /* Chip-specific fixup from Broadcom driver */
13352 if ((tp->pci_chip_rev_id == CHIPREV_ID_5704_A0) &&
13353 (!(pci_state_reg & PCISTATE_RETRY_SAME_DMA))) {
13354 pci_state_reg |= PCISTATE_RETRY_SAME_DMA;
13355 pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE, pci_state_reg);
13358 /* Default fast path register access methods */
13359 tp->read32 = tg3_read32;
13360 tp->write32 = tg3_write32;
13361 tp->read32_mbox = tg3_read32;
13362 tp->write32_mbox = tg3_write32;
13363 tp->write32_tx_mbox = tg3_write32;
13364 tp->write32_rx_mbox = tg3_write32;
13366 /* Various workaround register access methods */
13367 if (tp->tg3_flags & TG3_FLAG_PCIX_TARGET_HWBUG)
13368 tp->write32 = tg3_write_indirect_reg32;
13369 else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701 ||
13370 ((tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) &&
13371 tp->pci_chip_rev_id == CHIPREV_ID_5750_A0)) {
13373 * Back to back register writes can cause problems on these
13374 * chips, the workaround is to read back all reg writes
13375 * except those to mailbox regs.
13377 * See tg3_write_indirect_reg32().
13379 tp->write32 = tg3_write_flush_reg32;
13382 if ((tp->tg3_flags & TG3_FLAG_TXD_MBOX_HWBUG) ||
13383 (tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER)) {
13384 tp->write32_tx_mbox = tg3_write32_tx_mbox;
13385 if (tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER)
13386 tp->write32_rx_mbox = tg3_write_flush_reg32;
13389 if (tp->tg3_flags2 & TG3_FLG2_ICH_WORKAROUND) {
13390 tp->read32 = tg3_read_indirect_reg32;
13391 tp->write32 = tg3_write_indirect_reg32;
13392 tp->read32_mbox = tg3_read_indirect_mbox;
13393 tp->write32_mbox = tg3_write_indirect_mbox;
13394 tp->write32_tx_mbox = tg3_write_indirect_mbox;
13395 tp->write32_rx_mbox = tg3_write_indirect_mbox;
13400 pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd);
13401 pci_cmd &= ~PCI_COMMAND_MEMORY;
13402 pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd);
13404 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
13405 tp->read32_mbox = tg3_read32_mbox_5906;
13406 tp->write32_mbox = tg3_write32_mbox_5906;
13407 tp->write32_tx_mbox = tg3_write32_mbox_5906;
13408 tp->write32_rx_mbox = tg3_write32_mbox_5906;
13411 if (tp->write32 == tg3_write_indirect_reg32 ||
13412 ((tp->tg3_flags & TG3_FLAG_PCIX_MODE) &&
13413 (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
13414 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701)))
13415 tp->tg3_flags |= TG3_FLAG_SRAM_USE_CONFIG;
13417 /* Get eeprom hw config before calling tg3_set_power_state().
13418 * In particular, the TG3_FLG2_IS_NIC flag must be
13419 * determined before calling tg3_set_power_state() so that
13420 * we know whether or not to switch out of Vaux power.
13421 * When the flag is set, it means that GPIO1 is used for eeprom
13422 * write protect and also implies that it is a LOM where GPIOs
13423 * are not used to switch power.
13425 tg3_get_eeprom_hw_cfg(tp);
13427 if (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE) {
13428 /* Allow reads and writes to the
13429 * APE register and memory space.
13431 pci_state_reg |= PCISTATE_ALLOW_APE_CTLSPC_WR |
13432 PCISTATE_ALLOW_APE_SHMEM_WR;
13433 pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE,
13437 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 ||
13438 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761 ||
13439 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 ||
13440 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780 ||
13441 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 ||
13442 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765)
13443 tp->tg3_flags |= TG3_FLAG_CPMU_PRESENT;
13445 /* Set up tp->grc_local_ctrl before calling tg3_set_power_state().
13446 * GPIO1 driven high will bring 5700's external PHY out of reset.
13447 * It is also used as eeprom write protect on LOMs.
13449 tp->grc_local_ctrl = GRC_LCLCTRL_INT_ON_ATTN | GRC_LCLCTRL_AUTO_SEEPROM;
13450 if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) ||
13451 (tp->tg3_flags & TG3_FLAG_EEPROM_WRITE_PROT))
13452 tp->grc_local_ctrl |= (GRC_LCLCTRL_GPIO_OE1 |
13453 GRC_LCLCTRL_GPIO_OUTPUT1);
13454 /* Unused GPIO3 must be driven as output on 5752 because there
13455 * are no pull-up resistors on unused GPIO pins.
13457 else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752)
13458 tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE3;
13460 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
13461 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780 ||
13462 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765)
13463 tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_UART_SEL;
13465 if (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5761 ||
13466 tp->pdev->device == TG3PCI_DEVICE_TIGON3_5761S) {
13467 /* Turn off the debug UART. */
13468 tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_UART_SEL;
13469 if (tp->tg3_flags2 & TG3_FLG2_IS_NIC)
13470 /* Keep VMain power. */
13471 tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE0 |
13472 GRC_LCLCTRL_GPIO_OUTPUT0;
13475 /* Force the chip into D0. */
13476 err = tg3_set_power_state(tp, PCI_D0);
13478 dev_err(&tp->pdev->dev, "Transition to D0 failed\n");
13482 /* Derive initial jumbo mode from MTU assigned in
13483 * ether_setup() via the alloc_etherdev() call
13485 if (tp->dev->mtu > ETH_DATA_LEN &&
13486 !(tp->tg3_flags2 & TG3_FLG2_5780_CLASS))
13487 tp->tg3_flags |= TG3_FLAG_JUMBO_RING_ENABLE;
13489 /* Determine WakeOnLan speed to use. */
13490 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
13491 tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 ||
13492 tp->pci_chip_rev_id == CHIPREV_ID_5701_B0 ||
13493 tp->pci_chip_rev_id == CHIPREV_ID_5701_B2) {
13494 tp->tg3_flags &= ~(TG3_FLAG_WOL_SPEED_100MB);
13496 tp->tg3_flags |= TG3_FLAG_WOL_SPEED_100MB;
13499 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)
13500 tp->tg3_flags3 |= TG3_FLG3_PHY_IS_FET;
13502 /* A few boards don't want Ethernet@WireSpeed phy feature */
13503 if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) ||
13504 ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) &&
13505 (tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) &&
13506 (tp->pci_chip_rev_id != CHIPREV_ID_5705_A1)) ||
13507 (tp->tg3_flags3 & TG3_FLG3_PHY_IS_FET) ||
13508 (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES))
13509 tp->tg3_flags2 |= TG3_FLG2_NO_ETH_WIRE_SPEED;
13511 if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5703_AX ||
13512 GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5704_AX)
13513 tp->tg3_flags2 |= TG3_FLG2_PHY_ADC_BUG;
13514 if (tp->pci_chip_rev_id == CHIPREV_ID_5704_A0)
13515 tp->tg3_flags2 |= TG3_FLG2_PHY_5704_A0_BUG;
13517 if ((tp->tg3_flags2 & TG3_FLG2_5705_PLUS) &&
13518 !(tp->tg3_flags3 & TG3_FLG3_PHY_IS_FET) &&
13519 GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5785 &&
13520 GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_57780 &&
13521 GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5717 &&
13522 GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_57765) {
13523 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
13524 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 ||
13525 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 ||
13526 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) {
13527 if (tp->pdev->device != PCI_DEVICE_ID_TIGON3_5756 &&
13528 tp->pdev->device != PCI_DEVICE_ID_TIGON3_5722)
13529 tp->tg3_flags2 |= TG3_FLG2_PHY_JITTER_BUG;
13530 if (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5755M)
13531 tp->tg3_flags2 |= TG3_FLG2_PHY_ADJUST_TRIM;
13533 tp->tg3_flags2 |= TG3_FLG2_PHY_BER_BUG;
13536 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 &&
13537 GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5784_AX) {
13538 tp->phy_otp = tg3_read_otp_phycfg(tp);
13539 if (tp->phy_otp == 0)
13540 tp->phy_otp = TG3_OTP_DEFAULT;
13543 if (tp->tg3_flags & TG3_FLAG_CPMU_PRESENT)
13544 tp->mi_mode = MAC_MI_MODE_500KHZ_CONST;
13546 tp->mi_mode = MAC_MI_MODE_BASE;
13548 tp->coalesce_mode = 0;
13549 if (GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5700_AX &&
13550 GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5700_BX)
13551 tp->coalesce_mode |= HOSTCC_MODE_32BYTE;
13553 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 ||
13554 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780)
13555 tp->tg3_flags3 |= TG3_FLG3_USE_PHYLIB;
13557 err = tg3_mdio_init(tp);
13561 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 &&
13562 (tp->pci_chip_rev_id != CHIPREV_ID_5717_A0 ||
13563 (tp->tg3_flags2 & TG3_FLG2_MII_SERDES)))
13566 /* Initialize data/descriptor byte/word swapping. */
13567 val = tr32(GRC_MODE);
13568 val &= GRC_MODE_HOST_STACKUP;
13569 tw32(GRC_MODE, val | tp->grc_mode);
13571 tg3_switch_clocks(tp);
13573 /* Clear this out for sanity. */
13574 tw32(TG3PCI_MEM_WIN_BASE_ADDR, 0);
13576 pci_read_config_dword(tp->pdev, TG3PCI_PCISTATE,
13578 if ((pci_state_reg & PCISTATE_CONV_PCI_MODE) == 0 &&
13579 (tp->tg3_flags & TG3_FLAG_PCIX_TARGET_HWBUG) == 0) {
13580 u32 chiprevid = GET_CHIP_REV_ID(tp->misc_host_ctrl);
13582 if (chiprevid == CHIPREV_ID_5701_A0 ||
13583 chiprevid == CHIPREV_ID_5701_B0 ||
13584 chiprevid == CHIPREV_ID_5701_B2 ||
13585 chiprevid == CHIPREV_ID_5701_B5) {
13586 void __iomem *sram_base;
13588 /* Write some dummy words into the SRAM status block
13589 * area, see if it reads back correctly. If the return
13590 * value is bad, force enable the PCIX workaround.
13592 sram_base = tp->regs + NIC_SRAM_WIN_BASE + NIC_SRAM_STATS_BLK;
13594 writel(0x00000000, sram_base);
13595 writel(0x00000000, sram_base + 4);
13596 writel(0xffffffff, sram_base + 4);
13597 if (readl(sram_base) != 0x00000000)
13598 tp->tg3_flags |= TG3_FLAG_PCIX_TARGET_HWBUG;
13603 tg3_nvram_init(tp);
13605 grc_misc_cfg = tr32(GRC_MISC_CFG);
13606 grc_misc_cfg &= GRC_MISC_CFG_BOARD_ID_MASK;
13608 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 &&
13609 (grc_misc_cfg == GRC_MISC_CFG_BOARD_ID_5788 ||
13610 grc_misc_cfg == GRC_MISC_CFG_BOARD_ID_5788M))
13611 tp->tg3_flags2 |= TG3_FLG2_IS_5788;
13613 if (!(tp->tg3_flags2 & TG3_FLG2_IS_5788) &&
13614 (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700))
13615 tp->tg3_flags |= TG3_FLAG_TAGGED_STATUS;
13616 if (tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) {
13617 tp->coalesce_mode |= (HOSTCC_MODE_CLRTICK_RXBD |
13618 HOSTCC_MODE_CLRTICK_TXBD);
13620 tp->misc_host_ctrl |= MISC_HOST_CTRL_TAGGED_STATUS;
13621 pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL,
13622 tp->misc_host_ctrl);
13625 /* Preserve the APE MAC_MODE bits */
13626 if (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE)
13627 tp->mac_mode = tr32(MAC_MODE) |
13628 MAC_MODE_APE_TX_EN | MAC_MODE_APE_RX_EN;
13630 tp->mac_mode = TG3_DEF_MAC_MODE;
13632 /* these are limited to 10/100 only */
13633 if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 &&
13634 (grc_misc_cfg == 0x8000 || grc_misc_cfg == 0x4000)) ||
13635 (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 &&
13636 tp->pdev->vendor == PCI_VENDOR_ID_BROADCOM &&
13637 (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5901 ||
13638 tp->pdev->device == PCI_DEVICE_ID_TIGON3_5901_2 ||
13639 tp->pdev->device == PCI_DEVICE_ID_TIGON3_5705F)) ||
13640 (tp->pdev->vendor == PCI_VENDOR_ID_BROADCOM &&
13641 (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5751F ||
13642 tp->pdev->device == PCI_DEVICE_ID_TIGON3_5753F ||
13643 tp->pdev->device == PCI_DEVICE_ID_TIGON3_5787F)) ||
13644 tp->pdev->device == TG3PCI_DEVICE_TIGON3_57790 ||
13645 tp->pdev->device == TG3PCI_DEVICE_TIGON3_57791 ||
13646 tp->pdev->device == TG3PCI_DEVICE_TIGON3_57795 ||
13647 (tp->tg3_flags3 & TG3_FLG3_PHY_IS_FET))
13648 tp->tg3_flags |= TG3_FLAG_10_100_ONLY;
13650 err = tg3_phy_probe(tp);
13652 dev_err(&tp->pdev->dev, "phy probe failed, err %d\n", err);
13653 /* ... but do not return immediately ... */
13658 tg3_read_fw_ver(tp);
13660 if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) {
13661 tp->tg3_flags &= ~TG3_FLAG_USE_MI_INTERRUPT;
13663 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700)
13664 tp->tg3_flags |= TG3_FLAG_USE_MI_INTERRUPT;
13666 tp->tg3_flags &= ~TG3_FLAG_USE_MI_INTERRUPT;
13669 /* 5700 {AX,BX} chips have a broken status block link
13670 * change bit implementation, so we must use the
13671 * status register in those cases.
13673 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700)
13674 tp->tg3_flags |= TG3_FLAG_USE_LINKCHG_REG;
13676 tp->tg3_flags &= ~TG3_FLAG_USE_LINKCHG_REG;
13678 /* The led_ctrl is set during tg3_phy_probe, here we might
13679 * have to force the link status polling mechanism based
13680 * upon subsystem IDs.
13682 if (tp->pdev->subsystem_vendor == PCI_VENDOR_ID_DELL &&
13683 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701 &&
13684 !(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)) {
13685 tp->tg3_flags |= (TG3_FLAG_USE_MI_INTERRUPT |
13686 TG3_FLAG_USE_LINKCHG_REG);
13689 /* For all SERDES we poll the MAC status register. */
13690 if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)
13691 tp->tg3_flags |= TG3_FLAG_POLL_SERDES;
13693 tp->tg3_flags &= ~TG3_FLAG_POLL_SERDES;
13695 tp->rx_offset = NET_IP_ALIGN;
13696 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701 &&
13697 (tp->tg3_flags & TG3_FLAG_PCIX_MODE) != 0)
13700 tp->rx_std_max_post = TG3_RX_RING_SIZE;
13702 /* Increment the rx prod index on the rx std ring by at most
13703 * 8 for these chips to workaround hw errata.
13705 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750 ||
13706 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 ||
13707 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755)
13708 tp->rx_std_max_post = 8;
13710 if (tp->tg3_flags & TG3_FLAG_ASPM_WORKAROUND)
13711 tp->pwrmgmt_thresh = tr32(PCIE_PWR_MGMT_THRESH) &
13712 PCIE_PWR_MGMT_L1_THRESH_MSK;
13717 #ifdef CONFIG_SPARC
13718 static int __devinit tg3_get_macaddr_sparc(struct tg3 *tp)
13720 struct net_device *dev = tp->dev;
13721 struct pci_dev *pdev = tp->pdev;
13722 struct device_node *dp = pci_device_to_OF_node(pdev);
13723 const unsigned char *addr;
13726 addr = of_get_property(dp, "local-mac-address", &len);
13727 if (addr && len == 6) {
13728 memcpy(dev->dev_addr, addr, 6);
13729 memcpy(dev->perm_addr, dev->dev_addr, 6);
13735 static int __devinit tg3_get_default_macaddr_sparc(struct tg3 *tp)
13737 struct net_device *dev = tp->dev;
13739 memcpy(dev->dev_addr, idprom->id_ethaddr, 6);
13740 memcpy(dev->perm_addr, idprom->id_ethaddr, 6);
13745 static int __devinit tg3_get_device_address(struct tg3 *tp)
13747 struct net_device *dev = tp->dev;
13748 u32 hi, lo, mac_offset;
13751 #ifdef CONFIG_SPARC
13752 if (!tg3_get_macaddr_sparc(tp))
13757 if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) ||
13758 (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) {
13759 if (tr32(TG3PCI_DUAL_MAC_CTRL) & DUAL_MAC_CTRL_ID)
13761 if (tg3_nvram_lock(tp))
13762 tw32_f(NVRAM_CMD, NVRAM_CMD_RESET);
13764 tg3_nvram_unlock(tp);
13765 } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717) {
13766 if (tr32(TG3_CPMU_STATUS) & TG3_CPMU_STATUS_PCIE_FUNC)
13768 } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)
13771 /* First try to get it from MAC address mailbox. */
13772 tg3_read_mem(tp, NIC_SRAM_MAC_ADDR_HIGH_MBOX, &hi);
13773 if ((hi >> 16) == 0x484b) {
13774 dev->dev_addr[0] = (hi >> 8) & 0xff;
13775 dev->dev_addr[1] = (hi >> 0) & 0xff;
13777 tg3_read_mem(tp, NIC_SRAM_MAC_ADDR_LOW_MBOX, &lo);
13778 dev->dev_addr[2] = (lo >> 24) & 0xff;
13779 dev->dev_addr[3] = (lo >> 16) & 0xff;
13780 dev->dev_addr[4] = (lo >> 8) & 0xff;
13781 dev->dev_addr[5] = (lo >> 0) & 0xff;
13783 /* Some old bootcode may report a 0 MAC address in SRAM */
13784 addr_ok = is_valid_ether_addr(&dev->dev_addr[0]);
13787 /* Next, try NVRAM. */
13788 if (!(tp->tg3_flags3 & TG3_FLG3_NO_NVRAM) &&
13789 !tg3_nvram_read_be32(tp, mac_offset + 0, &hi) &&
13790 !tg3_nvram_read_be32(tp, mac_offset + 4, &lo)) {
13791 memcpy(&dev->dev_addr[0], ((char *)&hi) + 2, 2);
13792 memcpy(&dev->dev_addr[2], (char *)&lo, sizeof(lo));
13794 /* Finally just fetch it out of the MAC control regs. */
13796 hi = tr32(MAC_ADDR_0_HIGH);
13797 lo = tr32(MAC_ADDR_0_LOW);
13799 dev->dev_addr[5] = lo & 0xff;
13800 dev->dev_addr[4] = (lo >> 8) & 0xff;
13801 dev->dev_addr[3] = (lo >> 16) & 0xff;
13802 dev->dev_addr[2] = (lo >> 24) & 0xff;
13803 dev->dev_addr[1] = hi & 0xff;
13804 dev->dev_addr[0] = (hi >> 8) & 0xff;
13808 if (!is_valid_ether_addr(&dev->dev_addr[0])) {
13809 #ifdef CONFIG_SPARC
13810 if (!tg3_get_default_macaddr_sparc(tp))
13815 memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
13819 #define BOUNDARY_SINGLE_CACHELINE 1
13820 #define BOUNDARY_MULTI_CACHELINE 2
13822 static u32 __devinit tg3_calc_dma_bndry(struct tg3 *tp, u32 val)
13824 int cacheline_size;
13828 pci_read_config_byte(tp->pdev, PCI_CACHE_LINE_SIZE, &byte);
13830 cacheline_size = 1024;
13832 cacheline_size = (int) byte * 4;
13834 /* On 5703 and later chips, the boundary bits have no
13837 if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 &&
13838 GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701 &&
13839 !(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS))
13842 #if defined(CONFIG_PPC64) || defined(CONFIG_IA64) || defined(CONFIG_PARISC)
13843 goal = BOUNDARY_MULTI_CACHELINE;
13845 #if defined(CONFIG_SPARC64) || defined(CONFIG_ALPHA)
13846 goal = BOUNDARY_SINGLE_CACHELINE;
13852 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 ||
13853 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) {
13854 val = goal ? 0 : DMA_RWCTRL_DIS_CACHE_ALIGNMENT;
13861 /* PCI controllers on most RISC systems tend to disconnect
13862 * when a device tries to burst across a cache-line boundary.
13863 * Therefore, letting tg3 do so just wastes PCI bandwidth.
13865 * Unfortunately, for PCI-E there are only limited
13866 * write-side controls for this, and thus for reads
13867 * we will still get the disconnects. We'll also waste
13868 * these PCI cycles for both read and write for chips
13869 * other than 5700 and 5701 which do not implement the
13872 if ((tp->tg3_flags & TG3_FLAG_PCIX_MODE) &&
13873 !(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS)) {
13874 switch (cacheline_size) {
13879 if (goal == BOUNDARY_SINGLE_CACHELINE) {
13880 val |= (DMA_RWCTRL_READ_BNDRY_128_PCIX |
13881 DMA_RWCTRL_WRITE_BNDRY_128_PCIX);
13883 val |= (DMA_RWCTRL_READ_BNDRY_384_PCIX |
13884 DMA_RWCTRL_WRITE_BNDRY_384_PCIX);
13889 val |= (DMA_RWCTRL_READ_BNDRY_256_PCIX |
13890 DMA_RWCTRL_WRITE_BNDRY_256_PCIX);
13894 val |= (DMA_RWCTRL_READ_BNDRY_384_PCIX |
13895 DMA_RWCTRL_WRITE_BNDRY_384_PCIX);
13898 } else if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) {
13899 switch (cacheline_size) {
13903 if (goal == BOUNDARY_SINGLE_CACHELINE) {
13904 val &= ~DMA_RWCTRL_WRITE_BNDRY_DISAB_PCIE;
13905 val |= DMA_RWCTRL_WRITE_BNDRY_64_PCIE;
13911 val &= ~DMA_RWCTRL_WRITE_BNDRY_DISAB_PCIE;
13912 val |= DMA_RWCTRL_WRITE_BNDRY_128_PCIE;
13916 switch (cacheline_size) {
13918 if (goal == BOUNDARY_SINGLE_CACHELINE) {
13919 val |= (DMA_RWCTRL_READ_BNDRY_16 |
13920 DMA_RWCTRL_WRITE_BNDRY_16);
13925 if (goal == BOUNDARY_SINGLE_CACHELINE) {
13926 val |= (DMA_RWCTRL_READ_BNDRY_32 |
13927 DMA_RWCTRL_WRITE_BNDRY_32);
13932 if (goal == BOUNDARY_SINGLE_CACHELINE) {
13933 val |= (DMA_RWCTRL_READ_BNDRY_64 |
13934 DMA_RWCTRL_WRITE_BNDRY_64);
13939 if (goal == BOUNDARY_SINGLE_CACHELINE) {
13940 val |= (DMA_RWCTRL_READ_BNDRY_128 |
13941 DMA_RWCTRL_WRITE_BNDRY_128);
13946 val |= (DMA_RWCTRL_READ_BNDRY_256 |
13947 DMA_RWCTRL_WRITE_BNDRY_256);
13950 val |= (DMA_RWCTRL_READ_BNDRY_512 |
13951 DMA_RWCTRL_WRITE_BNDRY_512);
13955 val |= (DMA_RWCTRL_READ_BNDRY_1024 |
13956 DMA_RWCTRL_WRITE_BNDRY_1024);
13965 static int __devinit tg3_do_test_dma(struct tg3 *tp, u32 *buf, dma_addr_t buf_dma, int size, int to_device)
13967 struct tg3_internal_buffer_desc test_desc;
13968 u32 sram_dma_descs;
13971 sram_dma_descs = NIC_SRAM_DMA_DESC_POOL_BASE;
13973 tw32(FTQ_RCVBD_COMP_FIFO_ENQDEQ, 0);
13974 tw32(FTQ_RCVDATA_COMP_FIFO_ENQDEQ, 0);
13975 tw32(RDMAC_STATUS, 0);
13976 tw32(WDMAC_STATUS, 0);
13978 tw32(BUFMGR_MODE, 0);
13979 tw32(FTQ_RESET, 0);
13981 test_desc.addr_hi = ((u64) buf_dma) >> 32;
13982 test_desc.addr_lo = buf_dma & 0xffffffff;
13983 test_desc.nic_mbuf = 0x00002100;
13984 test_desc.len = size;
13987 * HP ZX1 was seeing test failures for 5701 cards running at 33Mhz
13988 * the *second* time the tg3 driver was getting loaded after an
13991 * Broadcom tells me:
13992 * ...the DMA engine is connected to the GRC block and a DMA
13993 * reset may affect the GRC block in some unpredictable way...
13994 * The behavior of resets to individual blocks has not been tested.
13996 * Broadcom noted the GRC reset will also reset all sub-components.
13999 test_desc.cqid_sqid = (13 << 8) | 2;
14001 tw32_f(RDMAC_MODE, RDMAC_MODE_ENABLE);
14004 test_desc.cqid_sqid = (16 << 8) | 7;
14006 tw32_f(WDMAC_MODE, WDMAC_MODE_ENABLE);
14009 test_desc.flags = 0x00000005;
14011 for (i = 0; i < (sizeof(test_desc) / sizeof(u32)); i++) {
14014 val = *(((u32 *)&test_desc) + i);
14015 pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR,
14016 sram_dma_descs + (i * sizeof(u32)));
14017 pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val);
14019 pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0);
14022 tw32(FTQ_DMA_HIGH_READ_FIFO_ENQDEQ, sram_dma_descs);
14024 tw32(FTQ_DMA_HIGH_WRITE_FIFO_ENQDEQ, sram_dma_descs);
14028 for (i = 0; i < 40; i++) {
14032 val = tr32(FTQ_RCVBD_COMP_FIFO_ENQDEQ);
14034 val = tr32(FTQ_RCVDATA_COMP_FIFO_ENQDEQ);
14035 if ((val & 0xffff) == sram_dma_descs) {
14046 #define TEST_BUFFER_SIZE 0x2000
14048 static int __devinit tg3_test_dma(struct tg3 *tp)
14050 dma_addr_t buf_dma;
14051 u32 *buf, saved_dma_rwctrl;
14054 buf = pci_alloc_consistent(tp->pdev, TEST_BUFFER_SIZE, &buf_dma);
14060 tp->dma_rwctrl = ((0x7 << DMA_RWCTRL_PCI_WRITE_CMD_SHIFT) |
14061 (0x6 << DMA_RWCTRL_PCI_READ_CMD_SHIFT));
14063 tp->dma_rwctrl = tg3_calc_dma_bndry(tp, tp->dma_rwctrl);
14065 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 ||
14066 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765)
14069 if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) {
14070 /* DMA read watermark not used on PCIE */
14071 tp->dma_rwctrl |= 0x00180000;
14072 } else if (!(tp->tg3_flags & TG3_FLAG_PCIX_MODE)) {
14073 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 ||
14074 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750)
14075 tp->dma_rwctrl |= 0x003f0000;
14077 tp->dma_rwctrl |= 0x003f000f;
14079 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 ||
14080 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) {
14081 u32 ccval = (tr32(TG3PCI_CLOCK_CTRL) & 0x1f);
14082 u32 read_water = 0x7;
14084 /* If the 5704 is behind the EPB bridge, we can
14085 * do the less restrictive ONE_DMA workaround for
14086 * better performance.
14088 if ((tp->tg3_flags & TG3_FLAG_40BIT_DMA_BUG) &&
14089 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704)
14090 tp->dma_rwctrl |= 0x8000;
14091 else if (ccval == 0x6 || ccval == 0x7)
14092 tp->dma_rwctrl |= DMA_RWCTRL_ONE_DMA;
14094 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703)
14096 /* Set bit 23 to enable PCIX hw bug fix */
14098 (read_water << DMA_RWCTRL_READ_WATER_SHIFT) |
14099 (0x3 << DMA_RWCTRL_WRITE_WATER_SHIFT) |
14101 } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780) {
14102 /* 5780 always in PCIX mode */
14103 tp->dma_rwctrl |= 0x00144000;
14104 } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) {
14105 /* 5714 always in PCIX mode */
14106 tp->dma_rwctrl |= 0x00148000;
14108 tp->dma_rwctrl |= 0x001b000f;
14112 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 ||
14113 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704)
14114 tp->dma_rwctrl &= 0xfffffff0;
14116 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
14117 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) {
14118 /* Remove this if it causes problems for some boards. */
14119 tp->dma_rwctrl |= DMA_RWCTRL_USE_MEM_READ_MULT;
14121 /* On 5700/5701 chips, we need to set this bit.
14122 * Otherwise the chip will issue cacheline transactions
14123 * to streamable DMA memory with not all the byte
14124 * enables turned on. This is an error on several
14125 * RISC PCI controllers, in particular sparc64.
14127 * On 5703/5704 chips, this bit has been reassigned
14128 * a different meaning. In particular, it is used
14129 * on those chips to enable a PCI-X workaround.
14131 tp->dma_rwctrl |= DMA_RWCTRL_ASSERT_ALL_BE;
14134 tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl);
14137 /* Unneeded, already done by tg3_get_invariants. */
14138 tg3_switch_clocks(tp);
14141 if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 &&
14142 GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701)
14145 /* It is best to perform DMA test with maximum write burst size
14146 * to expose the 5700/5701 write DMA bug.
14148 saved_dma_rwctrl = tp->dma_rwctrl;
14149 tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK;
14150 tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl);
14155 for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++)
14158 /* Send the buffer to the chip. */
14159 ret = tg3_do_test_dma(tp, buf, buf_dma, TEST_BUFFER_SIZE, 1);
14161 dev_err(&tp->pdev->dev,
14162 "%s: Buffer write failed. err = %d\n",
14168 /* validate data reached card RAM correctly. */
14169 for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++) {
14171 tg3_read_mem(tp, 0x2100 + (i*4), &val);
14172 if (le32_to_cpu(val) != p[i]) {
14173 dev_err(&tp->pdev->dev,
14174 "%s: Buffer corrupted on device! "
14175 "(%d != %d)\n", __func__, val, i);
14176 /* ret = -ENODEV here? */
14181 /* Now read it back. */
14182 ret = tg3_do_test_dma(tp, buf, buf_dma, TEST_BUFFER_SIZE, 0);
14184 dev_err(&tp->pdev->dev, "%s: Buffer read failed. "
14185 "err = %d\n", __func__, ret);
14190 for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++) {
14194 if ((tp->dma_rwctrl & DMA_RWCTRL_WRITE_BNDRY_MASK) !=
14195 DMA_RWCTRL_WRITE_BNDRY_16) {
14196 tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK;
14197 tp->dma_rwctrl |= DMA_RWCTRL_WRITE_BNDRY_16;
14198 tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl);
14201 dev_err(&tp->pdev->dev,
14202 "%s: Buffer corrupted on read back! "
14203 "(%d != %d)\n", __func__, p[i], i);
14209 if (i == (TEST_BUFFER_SIZE / sizeof(u32))) {
14215 if ((tp->dma_rwctrl & DMA_RWCTRL_WRITE_BNDRY_MASK) !=
14216 DMA_RWCTRL_WRITE_BNDRY_16) {
14217 static struct pci_device_id dma_wait_state_chipsets[] = {
14218 { PCI_DEVICE(PCI_VENDOR_ID_APPLE,
14219 PCI_DEVICE_ID_APPLE_UNI_N_PCI15) },
14223 /* DMA test passed without adjusting DMA boundary,
14224 * now look for chipsets that are known to expose the
14225 * DMA bug without failing the test.
14227 if (pci_dev_present(dma_wait_state_chipsets)) {
14228 tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK;
14229 tp->dma_rwctrl |= DMA_RWCTRL_WRITE_BNDRY_16;
14232 /* Safe to use the calculated DMA boundary. */
14233 tp->dma_rwctrl = saved_dma_rwctrl;
14235 tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl);
14239 pci_free_consistent(tp->pdev, TEST_BUFFER_SIZE, buf, buf_dma);
14244 static void __devinit tg3_init_link_config(struct tg3 *tp)
14246 tp->link_config.advertising =
14247 (ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full |
14248 ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full |
14249 ADVERTISED_1000baseT_Half | ADVERTISED_1000baseT_Full |
14250 ADVERTISED_Autoneg | ADVERTISED_MII);
14251 tp->link_config.speed = SPEED_INVALID;
14252 tp->link_config.duplex = DUPLEX_INVALID;
14253 tp->link_config.autoneg = AUTONEG_ENABLE;
14254 tp->link_config.active_speed = SPEED_INVALID;
14255 tp->link_config.active_duplex = DUPLEX_INVALID;
14256 tp->link_config.phy_is_low_power = 0;
14257 tp->link_config.orig_speed = SPEED_INVALID;
14258 tp->link_config.orig_duplex = DUPLEX_INVALID;
14259 tp->link_config.orig_autoneg = AUTONEG_INVALID;
14262 static void __devinit tg3_init_bufmgr_config(struct tg3 *tp)
14264 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 ||
14265 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) {
14266 tp->bufmgr_config.mbuf_read_dma_low_water =
14267 DEFAULT_MB_RDMA_LOW_WATER_5705;
14268 tp->bufmgr_config.mbuf_mac_rx_low_water =
14269 DEFAULT_MB_MACRX_LOW_WATER_57765;
14270 tp->bufmgr_config.mbuf_high_water =
14271 DEFAULT_MB_HIGH_WATER_57765;
14273 tp->bufmgr_config.mbuf_read_dma_low_water_jumbo =
14274 DEFAULT_MB_RDMA_LOW_WATER_5705;
14275 tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo =
14276 DEFAULT_MB_MACRX_LOW_WATER_JUMBO_57765;
14277 tp->bufmgr_config.mbuf_high_water_jumbo =
14278 DEFAULT_MB_HIGH_WATER_JUMBO_57765;
14279 } else if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
14280 tp->bufmgr_config.mbuf_read_dma_low_water =
14281 DEFAULT_MB_RDMA_LOW_WATER_5705;
14282 tp->bufmgr_config.mbuf_mac_rx_low_water =
14283 DEFAULT_MB_MACRX_LOW_WATER_5705;
14284 tp->bufmgr_config.mbuf_high_water =
14285 DEFAULT_MB_HIGH_WATER_5705;
14286 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
14287 tp->bufmgr_config.mbuf_mac_rx_low_water =
14288 DEFAULT_MB_MACRX_LOW_WATER_5906;
14289 tp->bufmgr_config.mbuf_high_water =
14290 DEFAULT_MB_HIGH_WATER_5906;
14293 tp->bufmgr_config.mbuf_read_dma_low_water_jumbo =
14294 DEFAULT_MB_RDMA_LOW_WATER_JUMBO_5780;
14295 tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo =
14296 DEFAULT_MB_MACRX_LOW_WATER_JUMBO_5780;
14297 tp->bufmgr_config.mbuf_high_water_jumbo =
14298 DEFAULT_MB_HIGH_WATER_JUMBO_5780;
14300 tp->bufmgr_config.mbuf_read_dma_low_water =
14301 DEFAULT_MB_RDMA_LOW_WATER;
14302 tp->bufmgr_config.mbuf_mac_rx_low_water =
14303 DEFAULT_MB_MACRX_LOW_WATER;
14304 tp->bufmgr_config.mbuf_high_water =
14305 DEFAULT_MB_HIGH_WATER;
14307 tp->bufmgr_config.mbuf_read_dma_low_water_jumbo =
14308 DEFAULT_MB_RDMA_LOW_WATER_JUMBO;
14309 tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo =
14310 DEFAULT_MB_MACRX_LOW_WATER_JUMBO;
14311 tp->bufmgr_config.mbuf_high_water_jumbo =
14312 DEFAULT_MB_HIGH_WATER_JUMBO;
14315 tp->bufmgr_config.dma_low_water = DEFAULT_DMA_LOW_WATER;
14316 tp->bufmgr_config.dma_high_water = DEFAULT_DMA_HIGH_WATER;
14319 static char * __devinit tg3_phy_string(struct tg3 *tp)
14321 switch (tp->phy_id & TG3_PHY_ID_MASK) {
14322 case TG3_PHY_ID_BCM5400: return "5400";
14323 case TG3_PHY_ID_BCM5401: return "5401";
14324 case TG3_PHY_ID_BCM5411: return "5411";
14325 case TG3_PHY_ID_BCM5701: return "5701";
14326 case TG3_PHY_ID_BCM5703: return "5703";
14327 case TG3_PHY_ID_BCM5704: return "5704";
14328 case TG3_PHY_ID_BCM5705: return "5705";
14329 case TG3_PHY_ID_BCM5750: return "5750";
14330 case TG3_PHY_ID_BCM5752: return "5752";
14331 case TG3_PHY_ID_BCM5714: return "5714";
14332 case TG3_PHY_ID_BCM5780: return "5780";
14333 case TG3_PHY_ID_BCM5755: return "5755";
14334 case TG3_PHY_ID_BCM5787: return "5787";
14335 case TG3_PHY_ID_BCM5784: return "5784";
14336 case TG3_PHY_ID_BCM5756: return "5722/5756";
14337 case TG3_PHY_ID_BCM5906: return "5906";
14338 case TG3_PHY_ID_BCM5761: return "5761";
14339 case TG3_PHY_ID_BCM5718C: return "5718C";
14340 case TG3_PHY_ID_BCM5718S: return "5718S";
14341 case TG3_PHY_ID_BCM57765: return "57765";
14342 case TG3_PHY_ID_BCM8002: return "8002/serdes";
14343 case 0: return "serdes";
14344 default: return "unknown";
14348 static char * __devinit tg3_bus_string(struct tg3 *tp, char *str)
14350 if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) {
14351 strcpy(str, "PCI Express");
14353 } else if (tp->tg3_flags & TG3_FLAG_PCIX_MODE) {
14354 u32 clock_ctrl = tr32(TG3PCI_CLOCK_CTRL) & 0x1f;
14356 strcpy(str, "PCIX:");
14358 if ((clock_ctrl == 7) ||
14359 ((tr32(GRC_MISC_CFG) & GRC_MISC_CFG_BOARD_ID_MASK) ==
14360 GRC_MISC_CFG_BOARD_ID_5704CIOBE))
14361 strcat(str, "133MHz");
14362 else if (clock_ctrl == 0)
14363 strcat(str, "33MHz");
14364 else if (clock_ctrl == 2)
14365 strcat(str, "50MHz");
14366 else if (clock_ctrl == 4)
14367 strcat(str, "66MHz");
14368 else if (clock_ctrl == 6)
14369 strcat(str, "100MHz");
14371 strcpy(str, "PCI:");
14372 if (tp->tg3_flags & TG3_FLAG_PCI_HIGH_SPEED)
14373 strcat(str, "66MHz");
14375 strcat(str, "33MHz");
14377 if (tp->tg3_flags & TG3_FLAG_PCI_32BIT)
14378 strcat(str, ":32-bit");
14380 strcat(str, ":64-bit");
14384 static struct pci_dev * __devinit tg3_find_peer(struct tg3 *tp)
14386 struct pci_dev *peer;
14387 unsigned int func, devnr = tp->pdev->devfn & ~7;
14389 for (func = 0; func < 8; func++) {
14390 peer = pci_get_slot(tp->pdev->bus, devnr | func);
14391 if (peer && peer != tp->pdev)
14395 /* 5704 can be configured in single-port mode, set peer to
14396 * tp->pdev in that case.
14404 * We don't need to keep the refcount elevated; there's no way
14405 * to remove one half of this device without removing the other
14412 static void __devinit tg3_init_coal(struct tg3 *tp)
14414 struct ethtool_coalesce *ec = &tp->coal;
14416 memset(ec, 0, sizeof(*ec));
14417 ec->cmd = ETHTOOL_GCOALESCE;
14418 ec->rx_coalesce_usecs = LOW_RXCOL_TICKS;
14419 ec->tx_coalesce_usecs = LOW_TXCOL_TICKS;
14420 ec->rx_max_coalesced_frames = LOW_RXMAX_FRAMES;
14421 ec->tx_max_coalesced_frames = LOW_TXMAX_FRAMES;
14422 ec->rx_coalesce_usecs_irq = DEFAULT_RXCOAL_TICK_INT;
14423 ec->tx_coalesce_usecs_irq = DEFAULT_TXCOAL_TICK_INT;
14424 ec->rx_max_coalesced_frames_irq = DEFAULT_RXCOAL_MAXF_INT;
14425 ec->tx_max_coalesced_frames_irq = DEFAULT_TXCOAL_MAXF_INT;
14426 ec->stats_block_coalesce_usecs = DEFAULT_STAT_COAL_TICKS;
14428 if (tp->coalesce_mode & (HOSTCC_MODE_CLRTICK_RXBD |
14429 HOSTCC_MODE_CLRTICK_TXBD)) {
14430 ec->rx_coalesce_usecs = LOW_RXCOL_TICKS_CLRTCKS;
14431 ec->rx_coalesce_usecs_irq = DEFAULT_RXCOAL_TICK_INT_CLRTCKS;
14432 ec->tx_coalesce_usecs = LOW_TXCOL_TICKS_CLRTCKS;
14433 ec->tx_coalesce_usecs_irq = DEFAULT_TXCOAL_TICK_INT_CLRTCKS;
14436 if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
14437 ec->rx_coalesce_usecs_irq = 0;
14438 ec->tx_coalesce_usecs_irq = 0;
14439 ec->stats_block_coalesce_usecs = 0;
14443 static const struct net_device_ops tg3_netdev_ops = {
14444 .ndo_open = tg3_open,
14445 .ndo_stop = tg3_close,
14446 .ndo_start_xmit = tg3_start_xmit,
14447 .ndo_get_stats = tg3_get_stats,
14448 .ndo_validate_addr = eth_validate_addr,
14449 .ndo_set_multicast_list = tg3_set_rx_mode,
14450 .ndo_set_mac_address = tg3_set_mac_addr,
14451 .ndo_do_ioctl = tg3_ioctl,
14452 .ndo_tx_timeout = tg3_tx_timeout,
14453 .ndo_change_mtu = tg3_change_mtu,
14454 #if TG3_VLAN_TAG_USED
14455 .ndo_vlan_rx_register = tg3_vlan_rx_register,
14457 #ifdef CONFIG_NET_POLL_CONTROLLER
14458 .ndo_poll_controller = tg3_poll_controller,
14462 static const struct net_device_ops tg3_netdev_ops_dma_bug = {
14463 .ndo_open = tg3_open,
14464 .ndo_stop = tg3_close,
14465 .ndo_start_xmit = tg3_start_xmit_dma_bug,
14466 .ndo_get_stats = tg3_get_stats,
14467 .ndo_validate_addr = eth_validate_addr,
14468 .ndo_set_multicast_list = tg3_set_rx_mode,
14469 .ndo_set_mac_address = tg3_set_mac_addr,
14470 .ndo_do_ioctl = tg3_ioctl,
14471 .ndo_tx_timeout = tg3_tx_timeout,
14472 .ndo_change_mtu = tg3_change_mtu,
14473 #if TG3_VLAN_TAG_USED
14474 .ndo_vlan_rx_register = tg3_vlan_rx_register,
14476 #ifdef CONFIG_NET_POLL_CONTROLLER
14477 .ndo_poll_controller = tg3_poll_controller,
14481 static int __devinit tg3_init_one(struct pci_dev *pdev,
14482 const struct pci_device_id *ent)
14484 struct net_device *dev;
14486 int i, err, pm_cap;
14487 u32 sndmbx, rcvmbx, intmbx;
14489 u64 dma_mask, persist_dma_mask;
14491 printk_once(KERN_INFO "%s\n", version);
14493 err = pci_enable_device(pdev);
14495 dev_err(&pdev->dev, "Cannot enable PCI device, aborting\n");
14499 err = pci_request_regions(pdev, DRV_MODULE_NAME);
14501 dev_err(&pdev->dev, "Cannot obtain PCI resources, aborting\n");
14502 goto err_out_disable_pdev;
14505 pci_set_master(pdev);
14507 /* Find power-management capability. */
14508 pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
14510 dev_err(&pdev->dev,
14511 "Cannot find Power Management capability, aborting\n");
14513 goto err_out_free_res;
14516 dev = alloc_etherdev_mq(sizeof(*tp), TG3_IRQ_MAX_VECS);
14518 dev_err(&pdev->dev, "Etherdev alloc failed, aborting\n");
14520 goto err_out_free_res;
14523 SET_NETDEV_DEV(dev, &pdev->dev);
14525 #if TG3_VLAN_TAG_USED
14526 dev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
14529 tp = netdev_priv(dev);
14532 tp->pm_cap = pm_cap;
14533 tp->rx_mode = TG3_DEF_RX_MODE;
14534 tp->tx_mode = TG3_DEF_TX_MODE;
14537 tp->msg_enable = tg3_debug;
14539 tp->msg_enable = TG3_DEF_MSG_ENABLE;
14541 /* The word/byte swap controls here control register access byte
14542 * swapping. DMA data byte swapping is controlled in the GRC_MODE
14545 tp->misc_host_ctrl =
14546 MISC_HOST_CTRL_MASK_PCI_INT |
14547 MISC_HOST_CTRL_WORD_SWAP |
14548 MISC_HOST_CTRL_INDIR_ACCESS |
14549 MISC_HOST_CTRL_PCISTATE_RW;
14551 /* The NONFRM (non-frame) byte/word swap controls take effect
14552 * on descriptor entries, anything which isn't packet data.
14554 * The StrongARM chips on the board (one for tx, one for rx)
14555 * are running in big-endian mode.
14557 tp->grc_mode = (GRC_MODE_WSWAP_DATA | GRC_MODE_BSWAP_DATA |
14558 GRC_MODE_WSWAP_NONFRM_DATA);
14559 #ifdef __BIG_ENDIAN
14560 tp->grc_mode |= GRC_MODE_BSWAP_NONFRM_DATA;
14562 spin_lock_init(&tp->lock);
14563 spin_lock_init(&tp->indirect_lock);
14564 INIT_WORK(&tp->reset_task, tg3_reset_task);
14566 tp->regs = pci_ioremap_bar(pdev, BAR_0);
14568 dev_err(&pdev->dev, "Cannot map device registers, aborting\n");
14570 goto err_out_free_dev;
14573 tg3_init_link_config(tp);
14575 tp->rx_pending = TG3_DEF_RX_RING_PENDING;
14576 tp->rx_jumbo_pending = TG3_DEF_RX_JUMBO_RING_PENDING;
14578 dev->ethtool_ops = &tg3_ethtool_ops;
14579 dev->watchdog_timeo = TG3_TX_TIMEOUT;
14580 dev->irq = pdev->irq;
14582 err = tg3_get_invariants(tp);
14584 dev_err(&pdev->dev,
14585 "Problem fetching invariants of chip, aborting\n");
14586 goto err_out_iounmap;
14589 if ((tp->tg3_flags3 & TG3_FLG3_5755_PLUS) &&
14590 tp->pci_chip_rev_id != CHIPREV_ID_5717_A0)
14591 dev->netdev_ops = &tg3_netdev_ops;
14593 dev->netdev_ops = &tg3_netdev_ops_dma_bug;
14596 /* The EPB bridge inside 5714, 5715, and 5780 and any
14597 * device behind the EPB cannot support DMA addresses > 40-bit.
14598 * On 64-bit systems with IOMMU, use 40-bit dma_mask.
14599 * On 64-bit systems without IOMMU, use 64-bit dma_mask and
14600 * do DMA address check in tg3_start_xmit().
14602 if (tp->tg3_flags2 & TG3_FLG2_IS_5788)
14603 persist_dma_mask = dma_mask = DMA_BIT_MASK(32);
14604 else if (tp->tg3_flags & TG3_FLAG_40BIT_DMA_BUG) {
14605 persist_dma_mask = dma_mask = DMA_BIT_MASK(40);
14606 #ifdef CONFIG_HIGHMEM
14607 dma_mask = DMA_BIT_MASK(64);
14610 persist_dma_mask = dma_mask = DMA_BIT_MASK(64);
14612 /* Configure DMA attributes. */
14613 if (dma_mask > DMA_BIT_MASK(32)) {
14614 err = pci_set_dma_mask(pdev, dma_mask);
14616 dev->features |= NETIF_F_HIGHDMA;
14617 err = pci_set_consistent_dma_mask(pdev,
14620 dev_err(&pdev->dev, "Unable to obtain 64 bit "
14621 "DMA for consistent allocations\n");
14622 goto err_out_iounmap;
14626 if (err || dma_mask == DMA_BIT_MASK(32)) {
14627 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
14629 dev_err(&pdev->dev,
14630 "No usable DMA configuration, aborting\n");
14631 goto err_out_iounmap;
14635 tg3_init_bufmgr_config(tp);
14637 /* Selectively allow TSO based on operating conditions */
14638 if ((tp->tg3_flags2 & TG3_FLG2_HW_TSO) ||
14639 (tp->fw_needed && !(tp->tg3_flags & TG3_FLAG_ENABLE_ASF)))
14640 tp->tg3_flags2 |= TG3_FLG2_TSO_CAPABLE;
14642 tp->tg3_flags2 &= ~(TG3_FLG2_TSO_CAPABLE | TG3_FLG2_TSO_BUG);
14643 tp->fw_needed = NULL;
14646 if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0)
14647 tp->fw_needed = FIRMWARE_TG3;
14649 /* TSO is on by default on chips that support hardware TSO.
14650 * Firmware TSO on older chips gives lower performance, so it
14651 * is off by default, but can be enabled using ethtool.
14653 if ((tp->tg3_flags2 & TG3_FLG2_HW_TSO) &&
14654 (dev->features & NETIF_F_IP_CSUM))
14655 dev->features |= NETIF_F_TSO;
14657 if ((tp->tg3_flags2 & TG3_FLG2_HW_TSO_2) ||
14658 (tp->tg3_flags2 & TG3_FLG2_HW_TSO_3)) {
14659 if (dev->features & NETIF_F_IPV6_CSUM)
14660 dev->features |= NETIF_F_TSO6;
14661 if ((tp->tg3_flags2 & TG3_FLG2_HW_TSO_3) ||
14662 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761 ||
14663 (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 &&
14664 GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5784_AX) ||
14665 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 ||
14666 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780)
14667 dev->features |= NETIF_F_TSO_ECN;
14670 if (tp->pci_chip_rev_id == CHIPREV_ID_5705_A1 &&
14671 !(tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) &&
14672 !(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH)) {
14673 tp->tg3_flags2 |= TG3_FLG2_MAX_RXPEND_64;
14674 tp->rx_pending = 63;
14677 err = tg3_get_device_address(tp);
14679 dev_err(&pdev->dev,
14680 "Could not obtain valid ethernet address, aborting\n");
14681 goto err_out_iounmap;
14684 if (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE) {
14685 tp->aperegs = pci_ioremap_bar(pdev, BAR_2);
14686 if (!tp->aperegs) {
14687 dev_err(&pdev->dev,
14688 "Cannot map APE registers, aborting\n");
14690 goto err_out_iounmap;
14693 tg3_ape_lock_init(tp);
14695 if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF)
14696 tg3_read_dash_ver(tp);
14700 * Reset chip in case UNDI or EFI driver did not shutdown
14701 * DMA self test will enable WDMAC and we'll see (spurious)
14702 * pending DMA on the PCI bus at that point.
14704 if ((tr32(HOSTCC_MODE) & HOSTCC_MODE_ENABLE) ||
14705 (tr32(WDMAC_MODE) & WDMAC_MODE_ENABLE)) {
14706 tw32(MEMARB_MODE, MEMARB_MODE_ENABLE);
14707 tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
14710 err = tg3_test_dma(tp);
14712 dev_err(&pdev->dev, "DMA engine test failed, aborting\n");
14713 goto err_out_apeunmap;
14716 /* flow control autonegotiation is default behavior */
14717 tp->tg3_flags |= TG3_FLAG_PAUSE_AUTONEG;
14718 tp->link_config.flowctrl = FLOW_CTRL_TX | FLOW_CTRL_RX;
14720 intmbx = MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW;
14721 rcvmbx = MAILBOX_RCVRET_CON_IDX_0 + TG3_64BIT_REG_LOW;
14722 sndmbx = MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW;
14723 for (i = 0; i < TG3_IRQ_MAX_VECS; i++) {
14724 struct tg3_napi *tnapi = &tp->napi[i];
14727 tnapi->tx_pending = TG3_DEF_TX_RING_PENDING;
14729 tnapi->int_mbox = intmbx;
14735 tnapi->consmbox = rcvmbx;
14736 tnapi->prodmbox = sndmbx;
14739 tnapi->coal_now = HOSTCC_MODE_COAL_VEC1_NOW << (i - 1);
14740 netif_napi_add(dev, &tnapi->napi, tg3_poll_msix, 64);
14742 tnapi->coal_now = HOSTCC_MODE_NOW;
14743 netif_napi_add(dev, &tnapi->napi, tg3_poll, 64);
14746 if (!(tp->tg3_flags & TG3_FLAG_SUPPORT_MSIX))
14750 * If we support MSIX, we'll be using RSS. If we're using
14751 * RSS, the first vector only handles link interrupts and the
14752 * remaining vectors handle rx and tx interrupts. Reuse the
14753 * mailbox values for the next iteration. The values we setup
14754 * above are still useful for the single vectored mode.
14769 pci_set_drvdata(pdev, dev);
14771 err = register_netdev(dev);
14773 dev_err(&pdev->dev, "Cannot register net device, aborting\n");
14774 goto err_out_apeunmap;
14777 netdev_info(dev, "Tigon3 [partno(%s) rev %04x] (%s) MAC address %pM\n",
14778 tp->board_part_number,
14779 tp->pci_chip_rev_id,
14780 tg3_bus_string(tp, str),
14783 if (tp->tg3_flags3 & TG3_FLG3_PHY_CONNECTED) {
14784 struct phy_device *phydev;
14785 phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR];
14787 "attached PHY driver [%s] (mii_bus:phy_addr=%s)\n",
14788 phydev->drv->name, dev_name(&phydev->dev));
14790 netdev_info(dev, "attached PHY is %s (%s Ethernet) "
14791 "(WireSpeed[%d])\n", tg3_phy_string(tp),
14792 ((tp->tg3_flags & TG3_FLAG_10_100_ONLY) ? "10/100Base-TX" :
14793 ((tp->tg3_flags2 & TG3_FLG2_ANY_SERDES) ? "1000Base-SX" :
14794 "10/100/1000Base-T")),
14795 (tp->tg3_flags2 & TG3_FLG2_NO_ETH_WIRE_SPEED) == 0);
14797 netdev_info(dev, "RXcsums[%d] LinkChgREG[%d] MIirq[%d] ASF[%d] TSOcap[%d]\n",
14798 (tp->tg3_flags & TG3_FLAG_RX_CHECKSUMS) != 0,
14799 (tp->tg3_flags & TG3_FLAG_USE_LINKCHG_REG) != 0,
14800 (tp->tg3_flags & TG3_FLAG_USE_MI_INTERRUPT) != 0,
14801 (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) != 0,
14802 (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) != 0);
14803 netdev_info(dev, "dma_rwctrl[%08x] dma_mask[%d-bit]\n",
14805 pdev->dma_mask == DMA_BIT_MASK(32) ? 32 :
14806 ((u64)pdev->dma_mask) == DMA_BIT_MASK(40) ? 40 : 64);
14812 iounmap(tp->aperegs);
14813 tp->aperegs = NULL;
14826 pci_release_regions(pdev);
14828 err_out_disable_pdev:
14829 pci_disable_device(pdev);
14830 pci_set_drvdata(pdev, NULL);
14834 static void __devexit tg3_remove_one(struct pci_dev *pdev)
14836 struct net_device *dev = pci_get_drvdata(pdev);
14839 struct tg3 *tp = netdev_priv(dev);
14842 release_firmware(tp->fw);
14844 flush_scheduled_work();
14846 if (tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB) {
14851 unregister_netdev(dev);
14853 iounmap(tp->aperegs);
14854 tp->aperegs = NULL;
14861 pci_release_regions(pdev);
14862 pci_disable_device(pdev);
14863 pci_set_drvdata(pdev, NULL);
14867 static int tg3_suspend(struct pci_dev *pdev, pm_message_t state)
14869 struct net_device *dev = pci_get_drvdata(pdev);
14870 struct tg3 *tp = netdev_priv(dev);
14871 pci_power_t target_state;
14874 /* PCI register 4 needs to be saved whether netif_running() or not.
14875 * MSI address and data need to be saved if using MSI and
14878 pci_save_state(pdev);
14880 if (!netif_running(dev))
14883 flush_scheduled_work();
14885 tg3_netif_stop(tp);
14887 del_timer_sync(&tp->timer);
14889 tg3_full_lock(tp, 1);
14890 tg3_disable_ints(tp);
14891 tg3_full_unlock(tp);
14893 netif_device_detach(dev);
14895 tg3_full_lock(tp, 0);
14896 tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
14897 tp->tg3_flags &= ~TG3_FLAG_INIT_COMPLETE;
14898 tg3_full_unlock(tp);
14900 target_state = pdev->pm_cap ? pci_target_state(pdev) : PCI_D3hot;
14902 err = tg3_set_power_state(tp, target_state);
14906 tg3_full_lock(tp, 0);
14908 tp->tg3_flags |= TG3_FLAG_INIT_COMPLETE;
14909 err2 = tg3_restart_hw(tp, 1);
14913 tp->timer.expires = jiffies + tp->timer_offset;
14914 add_timer(&tp->timer);
14916 netif_device_attach(dev);
14917 tg3_netif_start(tp);
14920 tg3_full_unlock(tp);
14929 static int tg3_resume(struct pci_dev *pdev)
14931 struct net_device *dev = pci_get_drvdata(pdev);
14932 struct tg3 *tp = netdev_priv(dev);
14935 pci_restore_state(tp->pdev);
14937 if (!netif_running(dev))
14940 err = tg3_set_power_state(tp, PCI_D0);
14944 netif_device_attach(dev);
14946 tg3_full_lock(tp, 0);
14948 tp->tg3_flags |= TG3_FLAG_INIT_COMPLETE;
14949 err = tg3_restart_hw(tp, 1);
14953 tp->timer.expires = jiffies + tp->timer_offset;
14954 add_timer(&tp->timer);
14956 tg3_netif_start(tp);
14959 tg3_full_unlock(tp);
14967 static struct pci_driver tg3_driver = {
14968 .name = DRV_MODULE_NAME,
14969 .id_table = tg3_pci_tbl,
14970 .probe = tg3_init_one,
14971 .remove = __devexit_p(tg3_remove_one),
14972 .suspend = tg3_suspend,
14973 .resume = tg3_resume
14976 static int __init tg3_init(void)
14978 return pci_register_driver(&tg3_driver);
14981 static void __exit tg3_cleanup(void)
14983 pci_unregister_driver(&tg3_driver);
14986 module_init(tg3_init);
14987 module_exit(tg3_cleanup);