Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * tg3.c: Broadcom Tigon3 ethernet driver. | |
3 | * | |
4 | * Copyright (C) 2001, 2002, 2003, 2004 David S. Miller (davem@redhat.com) | |
5 | * Copyright (C) 2001, 2002, 2003 Jeff Garzik (jgarzik@pobox.com) | |
6 | * Copyright (C) 2004 Sun Microsystems Inc. | |
b86fb2cf | 7 | * Copyright (C) 2005-2011 Broadcom Corporation. |
1da177e4 LT |
8 | * |
9 | * Firmware is: | |
49cabf49 MC |
10 | * Derived from proprietary unpublished source code, |
11 | * Copyright (C) 2000-2003 Broadcom Corporation. | |
12 | * | |
13 | * Permission is hereby granted for the distribution of this firmware | |
14 | * data in hexadecimal or equivalent format, provided this copyright | |
15 | * notice is accompanying it. | |
1da177e4 LT |
16 | */ |
17 | ||
1da177e4 LT |
18 | |
19 | #include <linux/module.h> | |
20 | #include <linux/moduleparam.h> | |
6867c843 | 21 | #include <linux/stringify.h> |
1da177e4 LT |
22 | #include <linux/kernel.h> |
23 | #include <linux/types.h> | |
24 | #include <linux/compiler.h> | |
25 | #include <linux/slab.h> | |
26 | #include <linux/delay.h> | |
14c85021 | 27 | #include <linux/in.h> |
1da177e4 | 28 | #include <linux/init.h> |
a6b7a407 | 29 | #include <linux/interrupt.h> |
1da177e4 LT |
30 | #include <linux/ioport.h> |
31 | #include <linux/pci.h> | |
32 | #include <linux/netdevice.h> | |
33 | #include <linux/etherdevice.h> | |
34 | #include <linux/skbuff.h> | |
35 | #include <linux/ethtool.h> | |
3110f5f5 | 36 | #include <linux/mdio.h> |
1da177e4 | 37 | #include <linux/mii.h> |
158d7abd | 38 | #include <linux/phy.h> |
a9daf367 | 39 | #include <linux/brcmphy.h> |
1da177e4 LT |
40 | #include <linux/if_vlan.h> |
41 | #include <linux/ip.h> | |
42 | #include <linux/tcp.h> | |
43 | #include <linux/workqueue.h> | |
61487480 | 44 | #include <linux/prefetch.h> |
f9a5f7d3 | 45 | #include <linux/dma-mapping.h> |
077f849d | 46 | #include <linux/firmware.h> |
1da177e4 LT |
47 | |
48 | #include <net/checksum.h> | |
c9bdd4b5 | 49 | #include <net/ip.h> |
1da177e4 LT |
50 | |
51 | #include <asm/system.h> | |
27fd9de8 | 52 | #include <linux/io.h> |
1da177e4 | 53 | #include <asm/byteorder.h> |
27fd9de8 | 54 | #include <linux/uaccess.h> |
1da177e4 | 55 | |
49b6e95f | 56 | #ifdef CONFIG_SPARC |
1da177e4 | 57 | #include <asm/idprom.h> |
49b6e95f | 58 | #include <asm/prom.h> |
1da177e4 LT |
59 | #endif |
60 | ||
63532394 MC |
61 | #define BAR_0 0 |
62 | #define BAR_2 2 | |
63 | ||
1da177e4 LT |
64 | #include "tg3.h" |
65 | ||
63c3a66f JP |
66 | /* Functions & macros to verify TG3_FLAGS types */ |
67 | ||
68 | static inline int _tg3_flag(enum TG3_FLAGS flag, unsigned long *bits) | |
69 | { | |
70 | return test_bit(flag, bits); | |
71 | } | |
72 | ||
73 | static inline void _tg3_flag_set(enum TG3_FLAGS flag, unsigned long *bits) | |
74 | { | |
75 | set_bit(flag, bits); | |
76 | } | |
77 | ||
78 | static inline void _tg3_flag_clear(enum TG3_FLAGS flag, unsigned long *bits) | |
79 | { | |
80 | clear_bit(flag, bits); | |
81 | } | |
82 | ||
83 | #define tg3_flag(tp, flag) \ | |
84 | _tg3_flag(TG3_FLAG_##flag, (tp)->tg3_flags) | |
85 | #define tg3_flag_set(tp, flag) \ | |
86 | _tg3_flag_set(TG3_FLAG_##flag, (tp)->tg3_flags) | |
87 | #define tg3_flag_clear(tp, flag) \ | |
88 | _tg3_flag_clear(TG3_FLAG_##flag, (tp)->tg3_flags) | |
89 | ||
1da177e4 | 90 | #define DRV_MODULE_NAME "tg3" |
6867c843 | 91 | #define TG3_MAJ_NUM 3 |
eaa36660 | 92 | #define TG3_MIN_NUM 120 |
6867c843 MC |
93 | #define DRV_MODULE_VERSION \ |
94 | __stringify(TG3_MAJ_NUM) "." __stringify(TG3_MIN_NUM) | |
eaa36660 | 95 | #define DRV_MODULE_RELDATE "August 18, 2011" |
1da177e4 | 96 | |
fd6d3f0e MC |
97 | #define RESET_KIND_SHUTDOWN 0 |
98 | #define RESET_KIND_INIT 1 | |
99 | #define RESET_KIND_SUSPEND 2 | |
100 | ||
1da177e4 LT |
101 | #define TG3_DEF_RX_MODE 0 |
102 | #define TG3_DEF_TX_MODE 0 | |
103 | #define TG3_DEF_MSG_ENABLE \ | |
104 | (NETIF_MSG_DRV | \ | |
105 | NETIF_MSG_PROBE | \ | |
106 | NETIF_MSG_LINK | \ | |
107 | NETIF_MSG_TIMER | \ | |
108 | NETIF_MSG_IFDOWN | \ | |
109 | NETIF_MSG_IFUP | \ | |
110 | NETIF_MSG_RX_ERR | \ | |
111 | NETIF_MSG_TX_ERR) | |
112 | ||
520b2756 MC |
113 | #define TG3_GRC_LCLCTL_PWRSW_DELAY 100 |
114 | ||
1da177e4 LT |
115 | /* length of time before we decide the hardware is borked, |
116 | * and dev->tx_timeout() should be called to fix the problem | |
117 | */ | |
63c3a66f | 118 | |
1da177e4 LT |
119 | #define TG3_TX_TIMEOUT (5 * HZ) |
120 | ||
121 | /* hardware minimum and maximum for a single frame's data payload */ | |
122 | #define TG3_MIN_MTU 60 | |
123 | #define TG3_MAX_MTU(tp) \ | |
63c3a66f | 124 | (tg3_flag(tp, JUMBO_CAPABLE) ? 9000 : 1500) |
1da177e4 LT |
125 | |
126 | /* These numbers seem to be hard coded in the NIC firmware somehow. | |
127 | * You can't change the ring sizes, but you can change where you place | |
128 | * them in the NIC onboard memory. | |
129 | */ | |
7cb32cf2 | 130 | #define TG3_RX_STD_RING_SIZE(tp) \ |
63c3a66f | 131 | (tg3_flag(tp, LRG_PROD_RING_CAP) ? \ |
de9f5230 | 132 | TG3_RX_STD_MAX_SIZE_5717 : TG3_RX_STD_MAX_SIZE_5700) |
1da177e4 | 133 | #define TG3_DEF_RX_RING_PENDING 200 |
7cb32cf2 | 134 | #define TG3_RX_JMB_RING_SIZE(tp) \ |
63c3a66f | 135 | (tg3_flag(tp, LRG_PROD_RING_CAP) ? \ |
de9f5230 | 136 | TG3_RX_JMB_MAX_SIZE_5717 : TG3_RX_JMB_MAX_SIZE_5700) |
1da177e4 | 137 | #define TG3_DEF_RX_JUMBO_RING_PENDING 100 |
c6cdf436 | 138 | #define TG3_RSS_INDIR_TBL_SIZE 128 |
1da177e4 LT |
139 | |
140 | /* Do not place this n-ring entries value into the tp struct itself, | |
141 | * we really want to expose these constants to GCC so that modulo et | |
142 | * al. operations are done with shifts and masks instead of with | |
143 | * hw multiply/modulo instructions. Another solution would be to | |
144 | * replace things like '% foo' with '& (foo - 1)'. | |
145 | */ | |
1da177e4 LT |
146 | |
147 | #define TG3_TX_RING_SIZE 512 | |
148 | #define TG3_DEF_TX_RING_PENDING (TG3_TX_RING_SIZE - 1) | |
149 | ||
2c49a44d MC |
150 | #define TG3_RX_STD_RING_BYTES(tp) \ |
151 | (sizeof(struct tg3_rx_buffer_desc) * TG3_RX_STD_RING_SIZE(tp)) | |
152 | #define TG3_RX_JMB_RING_BYTES(tp) \ | |
153 | (sizeof(struct tg3_ext_rx_buffer_desc) * TG3_RX_JMB_RING_SIZE(tp)) | |
154 | #define TG3_RX_RCB_RING_BYTES(tp) \ | |
7cb32cf2 | 155 | (sizeof(struct tg3_rx_buffer_desc) * (tp->rx_ret_ring_mask + 1)) |
1da177e4 LT |
156 | #define TG3_TX_RING_BYTES (sizeof(struct tg3_tx_buffer_desc) * \ |
157 | TG3_TX_RING_SIZE) | |
1da177e4 LT |
158 | #define NEXT_TX(N) (((N) + 1) & (TG3_TX_RING_SIZE - 1)) |
159 | ||
287be12e MC |
160 | #define TG3_DMA_BYTE_ENAB 64 |
161 | ||
162 | #define TG3_RX_STD_DMA_SZ 1536 | |
163 | #define TG3_RX_JMB_DMA_SZ 9046 | |
164 | ||
165 | #define TG3_RX_DMA_TO_MAP_SZ(x) ((x) + TG3_DMA_BYTE_ENAB) | |
166 | ||
167 | #define TG3_RX_STD_MAP_SZ TG3_RX_DMA_TO_MAP_SZ(TG3_RX_STD_DMA_SZ) | |
168 | #define TG3_RX_JMB_MAP_SZ TG3_RX_DMA_TO_MAP_SZ(TG3_RX_JMB_DMA_SZ) | |
1da177e4 | 169 | |
2c49a44d MC |
170 | #define TG3_RX_STD_BUFF_RING_SIZE(tp) \ |
171 | (sizeof(struct ring_info) * TG3_RX_STD_RING_SIZE(tp)) | |
2b2cdb65 | 172 | |
2c49a44d MC |
173 | #define TG3_RX_JMB_BUFF_RING_SIZE(tp) \ |
174 | (sizeof(struct ring_info) * TG3_RX_JMB_RING_SIZE(tp)) | |
2b2cdb65 | 175 | |
d2757fc4 MC |
176 | /* Due to a hardware bug, the 5701 can only DMA to memory addresses |
177 | * that are at least dword aligned when used in PCIX mode. The driver | |
178 | * works around this bug by double copying the packet. This workaround | |
179 | * is built into the normal double copy length check for efficiency. | |
180 | * | |
181 | * However, the double copy is only necessary on those architectures | |
182 | * where unaligned memory accesses are inefficient. For those architectures | |
183 | * where unaligned memory accesses incur little penalty, we can reintegrate | |
184 | * the 5701 in the normal rx path. Doing so saves a device structure | |
185 | * dereference by hardcoding the double copy threshold in place. | |
186 | */ | |
187 | #define TG3_RX_COPY_THRESHOLD 256 | |
188 | #if NET_IP_ALIGN == 0 || defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) | |
189 | #define TG3_RX_COPY_THRESH(tp) TG3_RX_COPY_THRESHOLD | |
190 | #else | |
191 | #define TG3_RX_COPY_THRESH(tp) ((tp)->rx_copy_thresh) | |
192 | #endif | |
193 | ||
81389f57 MC |
194 | #if (NET_IP_ALIGN != 0) |
195 | #define TG3_RX_OFFSET(tp) ((tp)->rx_offset) | |
196 | #else | |
197 | #define TG3_RX_OFFSET(tp) 0 | |
198 | #endif | |
199 | ||
1da177e4 | 200 | /* minimum number of free TX descriptors required to wake up TX process */ |
f3f3f27e | 201 | #define TG3_TX_WAKEUP_THRESH(tnapi) ((tnapi)->tx_pending / 4) |
e31aa987 | 202 | #define TG3_TX_BD_DMA_MAX 4096 |
1da177e4 | 203 | |
ad829268 MC |
204 | #define TG3_RAW_IP_ALIGN 2 |
205 | ||
c6cdf436 MC |
206 | #define TG3_FW_UPDATE_TIMEOUT_SEC 5 |
207 | ||
077f849d JSR |
208 | #define FIRMWARE_TG3 "tigon/tg3.bin" |
209 | #define FIRMWARE_TG3TSO "tigon/tg3_tso.bin" | |
210 | #define FIRMWARE_TG3TSO5 "tigon/tg3_tso5.bin" | |
211 | ||
1da177e4 | 212 | static char version[] __devinitdata = |
05dbe005 | 213 | DRV_MODULE_NAME ".c:v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")"; |
1da177e4 LT |
214 | |
215 | MODULE_AUTHOR("David S. Miller (davem@redhat.com) and Jeff Garzik (jgarzik@pobox.com)"); | |
216 | MODULE_DESCRIPTION("Broadcom Tigon3 ethernet driver"); | |
217 | MODULE_LICENSE("GPL"); | |
218 | MODULE_VERSION(DRV_MODULE_VERSION); | |
077f849d JSR |
219 | MODULE_FIRMWARE(FIRMWARE_TG3); |
220 | MODULE_FIRMWARE(FIRMWARE_TG3TSO); | |
221 | MODULE_FIRMWARE(FIRMWARE_TG3TSO5); | |
222 | ||
1da177e4 LT |
223 | static int tg3_debug = -1; /* -1 == use TG3_DEF_MSG_ENABLE as value */ |
224 | module_param(tg3_debug, int, 0); | |
225 | MODULE_PARM_DESC(tg3_debug, "Tigon3 bitmapped debugging message enable value"); | |
226 | ||
a3aa1884 | 227 | static DEFINE_PCI_DEVICE_TABLE(tg3_pci_tbl) = { |
13185217 HK |
228 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5700)}, |
229 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5701)}, | |
230 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702)}, | |
231 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5703)}, | |
232 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5704)}, | |
233 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702FE)}, | |
234 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705)}, | |
235 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705_2)}, | |
236 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705M)}, | |
237 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705M_2)}, | |
238 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702X)}, | |
239 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5703X)}, | |
240 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5704S)}, | |
241 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702A3)}, | |
242 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5703A3)}, | |
243 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5782)}, | |
244 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5788)}, | |
245 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5789)}, | |
246 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5901)}, | |
247 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5901_2)}, | |
248 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5704S_2)}, | |
249 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705F)}, | |
13185217 | 250 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5721)}, |
126a3368 | 251 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5722)}, |
13185217 | 252 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5751)}, |
13185217 HK |
253 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5751M)}, |
254 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5751F)}, | |
255 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5752)}, | |
256 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5752M)}, | |
257 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753)}, | |
258 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753M)}, | |
259 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753F)}, | |
260 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5754)}, | |
261 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5754M)}, | |
262 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5755)}, | |
263 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5755M)}, | |
126a3368 | 264 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5756)}, |
13185217 HK |
265 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5786)}, |
266 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5787)}, | |
267 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5787M)}, | |
676917d4 | 268 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5787F)}, |
13185217 HK |
269 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5714)}, |
270 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5714S)}, | |
271 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5715)}, | |
272 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5715S)}, | |
273 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5780)}, | |
274 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5780S)}, | |
275 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5781)}, | |
b5d3772c MC |
276 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5906)}, |
277 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5906M)}, | |
d30cdd28 MC |
278 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5784)}, |
279 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5764)}, | |
6c7af27c | 280 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5723)}, |
9936bcf6 MC |
281 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5761)}, |
282 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5761E)}, | |
c88e668b MC |
283 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5761S)}, |
284 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5761SE)}, | |
2befdcea MC |
285 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5785_G)}, |
286 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5785_F)}, | |
321d32a0 MC |
287 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57780)}, |
288 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57760)}, | |
289 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57790)}, | |
5e7ccf20 | 290 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57788)}, |
5001e2f6 MC |
291 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5717)}, |
292 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5718)}, | |
b0f75221 MC |
293 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57781)}, |
294 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57785)}, | |
295 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57761)}, | |
296 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57765)}, | |
297 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57791)}, | |
298 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57795)}, | |
302b500b | 299 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5719)}, |
ba1f3c76 | 300 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5720)}, |
13185217 HK |
301 | {PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_9DXX)}, |
302 | {PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_9MXX)}, | |
303 | {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1000)}, | |
304 | {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1001)}, | |
305 | {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1003)}, | |
306 | {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC9100)}, | |
307 | {PCI_DEVICE(PCI_VENDOR_ID_APPLE, PCI_DEVICE_ID_APPLE_TIGON3)}, | |
1dcb14d9 | 308 | {PCI_DEVICE(0x10cf, 0x11a2)}, /* Fujitsu 1000base-SX with BCM5703SKHB */ |
13185217 | 309 | {} |
1da177e4 LT |
310 | }; |
311 | ||
312 | MODULE_DEVICE_TABLE(pci, tg3_pci_tbl); | |
313 | ||
50da859d | 314 | static const struct { |
1da177e4 | 315 | const char string[ETH_GSTRING_LEN]; |
48fa55a0 | 316 | } ethtool_stats_keys[] = { |
1da177e4 LT |
317 | { "rx_octets" }, |
318 | { "rx_fragments" }, | |
319 | { "rx_ucast_packets" }, | |
320 | { "rx_mcast_packets" }, | |
321 | { "rx_bcast_packets" }, | |
322 | { "rx_fcs_errors" }, | |
323 | { "rx_align_errors" }, | |
324 | { "rx_xon_pause_rcvd" }, | |
325 | { "rx_xoff_pause_rcvd" }, | |
326 | { "rx_mac_ctrl_rcvd" }, | |
327 | { "rx_xoff_entered" }, | |
328 | { "rx_frame_too_long_errors" }, | |
329 | { "rx_jabbers" }, | |
330 | { "rx_undersize_packets" }, | |
331 | { "rx_in_length_errors" }, | |
332 | { "rx_out_length_errors" }, | |
333 | { "rx_64_or_less_octet_packets" }, | |
334 | { "rx_65_to_127_octet_packets" }, | |
335 | { "rx_128_to_255_octet_packets" }, | |
336 | { "rx_256_to_511_octet_packets" }, | |
337 | { "rx_512_to_1023_octet_packets" }, | |
338 | { "rx_1024_to_1522_octet_packets" }, | |
339 | { "rx_1523_to_2047_octet_packets" }, | |
340 | { "rx_2048_to_4095_octet_packets" }, | |
341 | { "rx_4096_to_8191_octet_packets" }, | |
342 | { "rx_8192_to_9022_octet_packets" }, | |
343 | ||
344 | { "tx_octets" }, | |
345 | { "tx_collisions" }, | |
346 | ||
347 | { "tx_xon_sent" }, | |
348 | { "tx_xoff_sent" }, | |
349 | { "tx_flow_control" }, | |
350 | { "tx_mac_errors" }, | |
351 | { "tx_single_collisions" }, | |
352 | { "tx_mult_collisions" }, | |
353 | { "tx_deferred" }, | |
354 | { "tx_excessive_collisions" }, | |
355 | { "tx_late_collisions" }, | |
356 | { "tx_collide_2times" }, | |
357 | { "tx_collide_3times" }, | |
358 | { "tx_collide_4times" }, | |
359 | { "tx_collide_5times" }, | |
360 | { "tx_collide_6times" }, | |
361 | { "tx_collide_7times" }, | |
362 | { "tx_collide_8times" }, | |
363 | { "tx_collide_9times" }, | |
364 | { "tx_collide_10times" }, | |
365 | { "tx_collide_11times" }, | |
366 | { "tx_collide_12times" }, | |
367 | { "tx_collide_13times" }, | |
368 | { "tx_collide_14times" }, | |
369 | { "tx_collide_15times" }, | |
370 | { "tx_ucast_packets" }, | |
371 | { "tx_mcast_packets" }, | |
372 | { "tx_bcast_packets" }, | |
373 | { "tx_carrier_sense_errors" }, | |
374 | { "tx_discards" }, | |
375 | { "tx_errors" }, | |
376 | ||
377 | { "dma_writeq_full" }, | |
378 | { "dma_write_prioq_full" }, | |
379 | { "rxbds_empty" }, | |
380 | { "rx_discards" }, | |
381 | { "rx_errors" }, | |
382 | { "rx_threshold_hit" }, | |
383 | ||
384 | { "dma_readq_full" }, | |
385 | { "dma_read_prioq_full" }, | |
386 | { "tx_comp_queue_full" }, | |
387 | ||
388 | { "ring_set_send_prod_index" }, | |
389 | { "ring_status_update" }, | |
390 | { "nic_irqs" }, | |
391 | { "nic_avoided_irqs" }, | |
4452d099 MC |
392 | { "nic_tx_threshold_hit" }, |
393 | ||
394 | { "mbuf_lwm_thresh_hit" }, | |
1da177e4 LT |
395 | }; |
396 | ||
48fa55a0 MC |
397 | #define TG3_NUM_STATS ARRAY_SIZE(ethtool_stats_keys) |
398 | ||
399 | ||
50da859d | 400 | static const struct { |
4cafd3f5 | 401 | const char string[ETH_GSTRING_LEN]; |
48fa55a0 | 402 | } ethtool_test_keys[] = { |
28a45957 MC |
403 | { "nvram test (online) " }, |
404 | { "link test (online) " }, | |
405 | { "register test (offline)" }, | |
406 | { "memory test (offline)" }, | |
407 | { "mac loopback test (offline)" }, | |
408 | { "phy loopback test (offline)" }, | |
941ec90f | 409 | { "ext loopback test (offline)" }, |
28a45957 | 410 | { "interrupt test (offline)" }, |
4cafd3f5 MC |
411 | }; |
412 | ||
48fa55a0 MC |
413 | #define TG3_NUM_TEST ARRAY_SIZE(ethtool_test_keys) |
414 | ||
415 | ||
b401e9e2 MC |
416 | static void tg3_write32(struct tg3 *tp, u32 off, u32 val) |
417 | { | |
418 | writel(val, tp->regs + off); | |
419 | } | |
420 | ||
421 | static u32 tg3_read32(struct tg3 *tp, u32 off) | |
422 | { | |
de6f31eb | 423 | return readl(tp->regs + off); |
b401e9e2 MC |
424 | } |
425 | ||
0d3031d9 MC |
426 | static void tg3_ape_write32(struct tg3 *tp, u32 off, u32 val) |
427 | { | |
428 | writel(val, tp->aperegs + off); | |
429 | } | |
430 | ||
431 | static u32 tg3_ape_read32(struct tg3 *tp, u32 off) | |
432 | { | |
de6f31eb | 433 | return readl(tp->aperegs + off); |
0d3031d9 MC |
434 | } |
435 | ||
1da177e4 LT |
436 | static void tg3_write_indirect_reg32(struct tg3 *tp, u32 off, u32 val) |
437 | { | |
6892914f MC |
438 | unsigned long flags; |
439 | ||
440 | spin_lock_irqsave(&tp->indirect_lock, flags); | |
1ee582d8 MC |
441 | pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off); |
442 | pci_write_config_dword(tp->pdev, TG3PCI_REG_DATA, val); | |
6892914f | 443 | spin_unlock_irqrestore(&tp->indirect_lock, flags); |
1ee582d8 MC |
444 | } |
445 | ||
446 | static void tg3_write_flush_reg32(struct tg3 *tp, u32 off, u32 val) | |
447 | { | |
448 | writel(val, tp->regs + off); | |
449 | readl(tp->regs + off); | |
1da177e4 LT |
450 | } |
451 | ||
6892914f | 452 | static u32 tg3_read_indirect_reg32(struct tg3 *tp, u32 off) |
1da177e4 | 453 | { |
6892914f MC |
454 | unsigned long flags; |
455 | u32 val; | |
456 | ||
457 | spin_lock_irqsave(&tp->indirect_lock, flags); | |
458 | pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off); | |
459 | pci_read_config_dword(tp->pdev, TG3PCI_REG_DATA, &val); | |
460 | spin_unlock_irqrestore(&tp->indirect_lock, flags); | |
461 | return val; | |
462 | } | |
463 | ||
464 | static void tg3_write_indirect_mbox(struct tg3 *tp, u32 off, u32 val) | |
465 | { | |
466 | unsigned long flags; | |
467 | ||
468 | if (off == (MAILBOX_RCVRET_CON_IDX_0 + TG3_64BIT_REG_LOW)) { | |
469 | pci_write_config_dword(tp->pdev, TG3PCI_RCV_RET_RING_CON_IDX + | |
470 | TG3_64BIT_REG_LOW, val); | |
471 | return; | |
472 | } | |
66711e66 | 473 | if (off == TG3_RX_STD_PROD_IDX_REG) { |
6892914f MC |
474 | pci_write_config_dword(tp->pdev, TG3PCI_STD_RING_PROD_IDX + |
475 | TG3_64BIT_REG_LOW, val); | |
476 | return; | |
1da177e4 | 477 | } |
6892914f MC |
478 | |
479 | spin_lock_irqsave(&tp->indirect_lock, flags); | |
480 | pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off + 0x5600); | |
481 | pci_write_config_dword(tp->pdev, TG3PCI_REG_DATA, val); | |
482 | spin_unlock_irqrestore(&tp->indirect_lock, flags); | |
483 | ||
484 | /* In indirect mode when disabling interrupts, we also need | |
485 | * to clear the interrupt bit in the GRC local ctrl register. | |
486 | */ | |
487 | if ((off == (MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW)) && | |
488 | (val == 0x1)) { | |
489 | pci_write_config_dword(tp->pdev, TG3PCI_MISC_LOCAL_CTRL, | |
490 | tp->grc_local_ctrl|GRC_LCLCTRL_CLEARINT); | |
491 | } | |
492 | } | |
493 | ||
494 | static u32 tg3_read_indirect_mbox(struct tg3 *tp, u32 off) | |
495 | { | |
496 | unsigned long flags; | |
497 | u32 val; | |
498 | ||
499 | spin_lock_irqsave(&tp->indirect_lock, flags); | |
500 | pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off + 0x5600); | |
501 | pci_read_config_dword(tp->pdev, TG3PCI_REG_DATA, &val); | |
502 | spin_unlock_irqrestore(&tp->indirect_lock, flags); | |
503 | return val; | |
504 | } | |
505 | ||
b401e9e2 MC |
506 | /* usec_wait specifies the wait time in usec when writing to certain registers |
507 | * where it is unsafe to read back the register without some delay. | |
508 | * GRC_LOCAL_CTRL is one example if the GPIOs are toggled to switch power. | |
509 | * TG3PCI_CLOCK_CTRL is another example if the clock frequencies are changed. | |
510 | */ | |
511 | static void _tw32_flush(struct tg3 *tp, u32 off, u32 val, u32 usec_wait) | |
6892914f | 512 | { |
63c3a66f | 513 | if (tg3_flag(tp, PCIX_TARGET_HWBUG) || tg3_flag(tp, ICH_WORKAROUND)) |
b401e9e2 MC |
514 | /* Non-posted methods */ |
515 | tp->write32(tp, off, val); | |
516 | else { | |
517 | /* Posted method */ | |
518 | tg3_write32(tp, off, val); | |
519 | if (usec_wait) | |
520 | udelay(usec_wait); | |
521 | tp->read32(tp, off); | |
522 | } | |
523 | /* Wait again after the read for the posted method to guarantee that | |
524 | * the wait time is met. | |
525 | */ | |
526 | if (usec_wait) | |
527 | udelay(usec_wait); | |
1da177e4 LT |
528 | } |
529 | ||
09ee929c MC |
530 | static inline void tw32_mailbox_flush(struct tg3 *tp, u32 off, u32 val) |
531 | { | |
532 | tp->write32_mbox(tp, off, val); | |
63c3a66f | 533 | if (!tg3_flag(tp, MBOX_WRITE_REORDER) && !tg3_flag(tp, ICH_WORKAROUND)) |
6892914f | 534 | tp->read32_mbox(tp, off); |
09ee929c MC |
535 | } |
536 | ||
20094930 | 537 | static void tg3_write32_tx_mbox(struct tg3 *tp, u32 off, u32 val) |
1da177e4 LT |
538 | { |
539 | void __iomem *mbox = tp->regs + off; | |
540 | writel(val, mbox); | |
63c3a66f | 541 | if (tg3_flag(tp, TXD_MBOX_HWBUG)) |
1da177e4 | 542 | writel(val, mbox); |
63c3a66f | 543 | if (tg3_flag(tp, MBOX_WRITE_REORDER)) |
1da177e4 LT |
544 | readl(mbox); |
545 | } | |
546 | ||
b5d3772c MC |
547 | static u32 tg3_read32_mbox_5906(struct tg3 *tp, u32 off) |
548 | { | |
de6f31eb | 549 | return readl(tp->regs + off + GRCMBOX_BASE); |
b5d3772c MC |
550 | } |
551 | ||
552 | static void tg3_write32_mbox_5906(struct tg3 *tp, u32 off, u32 val) | |
553 | { | |
554 | writel(val, tp->regs + off + GRCMBOX_BASE); | |
555 | } | |
556 | ||
c6cdf436 | 557 | #define tw32_mailbox(reg, val) tp->write32_mbox(tp, reg, val) |
09ee929c | 558 | #define tw32_mailbox_f(reg, val) tw32_mailbox_flush(tp, (reg), (val)) |
c6cdf436 MC |
559 | #define tw32_rx_mbox(reg, val) tp->write32_rx_mbox(tp, reg, val) |
560 | #define tw32_tx_mbox(reg, val) tp->write32_tx_mbox(tp, reg, val) | |
561 | #define tr32_mailbox(reg) tp->read32_mbox(tp, reg) | |
20094930 | 562 | |
c6cdf436 MC |
563 | #define tw32(reg, val) tp->write32(tp, reg, val) |
564 | #define tw32_f(reg, val) _tw32_flush(tp, (reg), (val), 0) | |
565 | #define tw32_wait_f(reg, val, us) _tw32_flush(tp, (reg), (val), (us)) | |
566 | #define tr32(reg) tp->read32(tp, reg) | |
1da177e4 LT |
567 | |
568 | static void tg3_write_mem(struct tg3 *tp, u32 off, u32 val) | |
569 | { | |
6892914f MC |
570 | unsigned long flags; |
571 | ||
6ff6f81d | 572 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906 && |
b5d3772c MC |
573 | (off >= NIC_SRAM_STATS_BLK) && (off < NIC_SRAM_TX_BUFFER_DESC)) |
574 | return; | |
575 | ||
6892914f | 576 | spin_lock_irqsave(&tp->indirect_lock, flags); |
63c3a66f | 577 | if (tg3_flag(tp, SRAM_USE_CONFIG)) { |
bbadf503 MC |
578 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, off); |
579 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val); | |
1da177e4 | 580 | |
bbadf503 MC |
581 | /* Always leave this as zero. */ |
582 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0); | |
583 | } else { | |
584 | tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, off); | |
585 | tw32_f(TG3PCI_MEM_WIN_DATA, val); | |
28fbef78 | 586 | |
bbadf503 MC |
587 | /* Always leave this as zero. */ |
588 | tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, 0); | |
589 | } | |
590 | spin_unlock_irqrestore(&tp->indirect_lock, flags); | |
758a6139 DM |
591 | } |
592 | ||
1da177e4 LT |
593 | static void tg3_read_mem(struct tg3 *tp, u32 off, u32 *val) |
594 | { | |
6892914f MC |
595 | unsigned long flags; |
596 | ||
6ff6f81d | 597 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906 && |
b5d3772c MC |
598 | (off >= NIC_SRAM_STATS_BLK) && (off < NIC_SRAM_TX_BUFFER_DESC)) { |
599 | *val = 0; | |
600 | return; | |
601 | } | |
602 | ||
6892914f | 603 | spin_lock_irqsave(&tp->indirect_lock, flags); |
63c3a66f | 604 | if (tg3_flag(tp, SRAM_USE_CONFIG)) { |
bbadf503 MC |
605 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, off); |
606 | pci_read_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val); | |
1da177e4 | 607 | |
bbadf503 MC |
608 | /* Always leave this as zero. */ |
609 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0); | |
610 | } else { | |
611 | tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, off); | |
612 | *val = tr32(TG3PCI_MEM_WIN_DATA); | |
613 | ||
614 | /* Always leave this as zero. */ | |
615 | tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, 0); | |
616 | } | |
6892914f | 617 | spin_unlock_irqrestore(&tp->indirect_lock, flags); |
1da177e4 LT |
618 | } |
619 | ||
0d3031d9 MC |
620 | static void tg3_ape_lock_init(struct tg3 *tp) |
621 | { | |
622 | int i; | |
6f5c8f83 | 623 | u32 regbase, bit; |
f92d9dc1 MC |
624 | |
625 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) | |
626 | regbase = TG3_APE_LOCK_GRANT; | |
627 | else | |
628 | regbase = TG3_APE_PER_LOCK_GRANT; | |
0d3031d9 MC |
629 | |
630 | /* Make sure the driver hasn't any stale locks. */ | |
6f5c8f83 MC |
631 | for (i = 0; i < 8; i++) { |
632 | if (i == TG3_APE_LOCK_GPIO) | |
633 | continue; | |
f92d9dc1 | 634 | tg3_ape_write32(tp, regbase + 4 * i, APE_LOCK_GRANT_DRIVER); |
6f5c8f83 MC |
635 | } |
636 | ||
637 | /* Clear the correct bit of the GPIO lock too. */ | |
638 | if (!tp->pci_fn) | |
639 | bit = APE_LOCK_GRANT_DRIVER; | |
640 | else | |
641 | bit = 1 << tp->pci_fn; | |
642 | ||
643 | tg3_ape_write32(tp, regbase + 4 * TG3_APE_LOCK_GPIO, bit); | |
0d3031d9 MC |
644 | } |
645 | ||
646 | static int tg3_ape_lock(struct tg3 *tp, int locknum) | |
647 | { | |
648 | int i, off; | |
649 | int ret = 0; | |
6f5c8f83 | 650 | u32 status, req, gnt, bit; |
0d3031d9 | 651 | |
63c3a66f | 652 | if (!tg3_flag(tp, ENABLE_APE)) |
0d3031d9 MC |
653 | return 0; |
654 | ||
655 | switch (locknum) { | |
6f5c8f83 MC |
656 | case TG3_APE_LOCK_GPIO: |
657 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) | |
658 | return 0; | |
33f401ae MC |
659 | case TG3_APE_LOCK_GRC: |
660 | case TG3_APE_LOCK_MEM: | |
661 | break; | |
662 | default: | |
663 | return -EINVAL; | |
0d3031d9 MC |
664 | } |
665 | ||
f92d9dc1 MC |
666 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) { |
667 | req = TG3_APE_LOCK_REQ; | |
668 | gnt = TG3_APE_LOCK_GRANT; | |
669 | } else { | |
670 | req = TG3_APE_PER_LOCK_REQ; | |
671 | gnt = TG3_APE_PER_LOCK_GRANT; | |
672 | } | |
673 | ||
0d3031d9 MC |
674 | off = 4 * locknum; |
675 | ||
6f5c8f83 MC |
676 | if (locknum != TG3_APE_LOCK_GPIO || !tp->pci_fn) |
677 | bit = APE_LOCK_REQ_DRIVER; | |
678 | else | |
679 | bit = 1 << tp->pci_fn; | |
680 | ||
681 | tg3_ape_write32(tp, req + off, bit); | |
0d3031d9 MC |
682 | |
683 | /* Wait for up to 1 millisecond to acquire lock. */ | |
684 | for (i = 0; i < 100; i++) { | |
f92d9dc1 | 685 | status = tg3_ape_read32(tp, gnt + off); |
6f5c8f83 | 686 | if (status == bit) |
0d3031d9 MC |
687 | break; |
688 | udelay(10); | |
689 | } | |
690 | ||
6f5c8f83 | 691 | if (status != bit) { |
0d3031d9 | 692 | /* Revoke the lock request. */ |
6f5c8f83 | 693 | tg3_ape_write32(tp, gnt + off, bit); |
0d3031d9 MC |
694 | ret = -EBUSY; |
695 | } | |
696 | ||
697 | return ret; | |
698 | } | |
699 | ||
700 | static void tg3_ape_unlock(struct tg3 *tp, int locknum) | |
701 | { | |
6f5c8f83 | 702 | u32 gnt, bit; |
0d3031d9 | 703 | |
63c3a66f | 704 | if (!tg3_flag(tp, ENABLE_APE)) |
0d3031d9 MC |
705 | return; |
706 | ||
707 | switch (locknum) { | |
6f5c8f83 MC |
708 | case TG3_APE_LOCK_GPIO: |
709 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) | |
710 | return; | |
33f401ae MC |
711 | case TG3_APE_LOCK_GRC: |
712 | case TG3_APE_LOCK_MEM: | |
713 | break; | |
714 | default: | |
715 | return; | |
0d3031d9 MC |
716 | } |
717 | ||
f92d9dc1 MC |
718 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) |
719 | gnt = TG3_APE_LOCK_GRANT; | |
720 | else | |
721 | gnt = TG3_APE_PER_LOCK_GRANT; | |
722 | ||
6f5c8f83 MC |
723 | if (locknum != TG3_APE_LOCK_GPIO || !tp->pci_fn) |
724 | bit = APE_LOCK_GRANT_DRIVER; | |
725 | else | |
726 | bit = 1 << tp->pci_fn; | |
727 | ||
728 | tg3_ape_write32(tp, gnt + 4 * locknum, bit); | |
0d3031d9 MC |
729 | } |
730 | ||
fd6d3f0e MC |
731 | static void tg3_ape_send_event(struct tg3 *tp, u32 event) |
732 | { | |
733 | int i; | |
734 | u32 apedata; | |
735 | ||
736 | /* NCSI does not support APE events */ | |
737 | if (tg3_flag(tp, APE_HAS_NCSI)) | |
738 | return; | |
739 | ||
740 | apedata = tg3_ape_read32(tp, TG3_APE_SEG_SIG); | |
741 | if (apedata != APE_SEG_SIG_MAGIC) | |
742 | return; | |
743 | ||
744 | apedata = tg3_ape_read32(tp, TG3_APE_FW_STATUS); | |
745 | if (!(apedata & APE_FW_STATUS_READY)) | |
746 | return; | |
747 | ||
748 | /* Wait for up to 1 millisecond for APE to service previous event. */ | |
749 | for (i = 0; i < 10; i++) { | |
750 | if (tg3_ape_lock(tp, TG3_APE_LOCK_MEM)) | |
751 | return; | |
752 | ||
753 | apedata = tg3_ape_read32(tp, TG3_APE_EVENT_STATUS); | |
754 | ||
755 | if (!(apedata & APE_EVENT_STATUS_EVENT_PENDING)) | |
756 | tg3_ape_write32(tp, TG3_APE_EVENT_STATUS, | |
757 | event | APE_EVENT_STATUS_EVENT_PENDING); | |
758 | ||
759 | tg3_ape_unlock(tp, TG3_APE_LOCK_MEM); | |
760 | ||
761 | if (!(apedata & APE_EVENT_STATUS_EVENT_PENDING)) | |
762 | break; | |
763 | ||
764 | udelay(100); | |
765 | } | |
766 | ||
767 | if (!(apedata & APE_EVENT_STATUS_EVENT_PENDING)) | |
768 | tg3_ape_write32(tp, TG3_APE_EVENT, APE_EVENT_1); | |
769 | } | |
770 | ||
771 | static void tg3_ape_driver_state_change(struct tg3 *tp, int kind) | |
772 | { | |
773 | u32 event; | |
774 | u32 apedata; | |
775 | ||
776 | if (!tg3_flag(tp, ENABLE_APE)) | |
777 | return; | |
778 | ||
779 | switch (kind) { | |
780 | case RESET_KIND_INIT: | |
781 | tg3_ape_write32(tp, TG3_APE_HOST_SEG_SIG, | |
782 | APE_HOST_SEG_SIG_MAGIC); | |
783 | tg3_ape_write32(tp, TG3_APE_HOST_SEG_LEN, | |
784 | APE_HOST_SEG_LEN_MAGIC); | |
785 | apedata = tg3_ape_read32(tp, TG3_APE_HOST_INIT_COUNT); | |
786 | tg3_ape_write32(tp, TG3_APE_HOST_INIT_COUNT, ++apedata); | |
787 | tg3_ape_write32(tp, TG3_APE_HOST_DRIVER_ID, | |
788 | APE_HOST_DRIVER_ID_MAGIC(TG3_MAJ_NUM, TG3_MIN_NUM)); | |
789 | tg3_ape_write32(tp, TG3_APE_HOST_BEHAVIOR, | |
790 | APE_HOST_BEHAV_NO_PHYLOCK); | |
791 | tg3_ape_write32(tp, TG3_APE_HOST_DRVR_STATE, | |
792 | TG3_APE_HOST_DRVR_STATE_START); | |
793 | ||
794 | event = APE_EVENT_STATUS_STATE_START; | |
795 | break; | |
796 | case RESET_KIND_SHUTDOWN: | |
797 | /* With the interface we are currently using, | |
798 | * APE does not track driver state. Wiping | |
799 | * out the HOST SEGMENT SIGNATURE forces | |
800 | * the APE to assume OS absent status. | |
801 | */ | |
802 | tg3_ape_write32(tp, TG3_APE_HOST_SEG_SIG, 0x0); | |
803 | ||
804 | if (device_may_wakeup(&tp->pdev->dev) && | |
805 | tg3_flag(tp, WOL_ENABLE)) { | |
806 | tg3_ape_write32(tp, TG3_APE_HOST_WOL_SPEED, | |
807 | TG3_APE_HOST_WOL_SPEED_AUTO); | |
808 | apedata = TG3_APE_HOST_DRVR_STATE_WOL; | |
809 | } else | |
810 | apedata = TG3_APE_HOST_DRVR_STATE_UNLOAD; | |
811 | ||
812 | tg3_ape_write32(tp, TG3_APE_HOST_DRVR_STATE, apedata); | |
813 | ||
814 | event = APE_EVENT_STATUS_STATE_UNLOAD; | |
815 | break; | |
816 | case RESET_KIND_SUSPEND: | |
817 | event = APE_EVENT_STATUS_STATE_SUSPEND; | |
818 | break; | |
819 | default: | |
820 | return; | |
821 | } | |
822 | ||
823 | event |= APE_EVENT_STATUS_DRIVER_EVNT | APE_EVENT_STATUS_STATE_CHNGE; | |
824 | ||
825 | tg3_ape_send_event(tp, event); | |
826 | } | |
827 | ||
1da177e4 LT |
828 | static void tg3_disable_ints(struct tg3 *tp) |
829 | { | |
89aeb3bc MC |
830 | int i; |
831 | ||
1da177e4 LT |
832 | tw32(TG3PCI_MISC_HOST_CTRL, |
833 | (tp->misc_host_ctrl | MISC_HOST_CTRL_MASK_PCI_INT)); | |
89aeb3bc MC |
834 | for (i = 0; i < tp->irq_max; i++) |
835 | tw32_mailbox_f(tp->napi[i].int_mbox, 0x00000001); | |
1da177e4 LT |
836 | } |
837 | ||
1da177e4 LT |
838 | static void tg3_enable_ints(struct tg3 *tp) |
839 | { | |
89aeb3bc | 840 | int i; |
89aeb3bc | 841 | |
bbe832c0 MC |
842 | tp->irq_sync = 0; |
843 | wmb(); | |
844 | ||
1da177e4 LT |
845 | tw32(TG3PCI_MISC_HOST_CTRL, |
846 | (tp->misc_host_ctrl & ~MISC_HOST_CTRL_MASK_PCI_INT)); | |
89aeb3bc | 847 | |
f89f38b8 | 848 | tp->coal_now = tp->coalesce_mode | HOSTCC_MODE_ENABLE; |
89aeb3bc MC |
849 | for (i = 0; i < tp->irq_cnt; i++) { |
850 | struct tg3_napi *tnapi = &tp->napi[i]; | |
c6cdf436 | 851 | |
898a56f8 | 852 | tw32_mailbox_f(tnapi->int_mbox, tnapi->last_tag << 24); |
63c3a66f | 853 | if (tg3_flag(tp, 1SHOT_MSI)) |
89aeb3bc | 854 | tw32_mailbox_f(tnapi->int_mbox, tnapi->last_tag << 24); |
f19af9c2 | 855 | |
f89f38b8 | 856 | tp->coal_now |= tnapi->coal_now; |
89aeb3bc | 857 | } |
f19af9c2 MC |
858 | |
859 | /* Force an initial interrupt */ | |
63c3a66f | 860 | if (!tg3_flag(tp, TAGGED_STATUS) && |
f19af9c2 MC |
861 | (tp->napi[0].hw_status->status & SD_STATUS_UPDATED)) |
862 | tw32(GRC_LOCAL_CTRL, tp->grc_local_ctrl | GRC_LCLCTRL_SETINT); | |
863 | else | |
f89f38b8 MC |
864 | tw32(HOSTCC_MODE, tp->coal_now); |
865 | ||
866 | tp->coal_now &= ~(tp->napi[0].coal_now | tp->napi[1].coal_now); | |
1da177e4 LT |
867 | } |
868 | ||
17375d25 | 869 | static inline unsigned int tg3_has_work(struct tg3_napi *tnapi) |
04237ddd | 870 | { |
17375d25 | 871 | struct tg3 *tp = tnapi->tp; |
898a56f8 | 872 | struct tg3_hw_status *sblk = tnapi->hw_status; |
04237ddd MC |
873 | unsigned int work_exists = 0; |
874 | ||
875 | /* check for phy events */ | |
63c3a66f | 876 | if (!(tg3_flag(tp, USE_LINKCHG_REG) || tg3_flag(tp, POLL_SERDES))) { |
04237ddd MC |
877 | if (sblk->status & SD_STATUS_LINK_CHG) |
878 | work_exists = 1; | |
879 | } | |
880 | /* check for RX/TX work to do */ | |
f3f3f27e | 881 | if (sblk->idx[0].tx_consumer != tnapi->tx_cons || |
8d9d7cfc | 882 | *(tnapi->rx_rcb_prod_idx) != tnapi->rx_rcb_ptr) |
04237ddd MC |
883 | work_exists = 1; |
884 | ||
885 | return work_exists; | |
886 | } | |
887 | ||
17375d25 | 888 | /* tg3_int_reenable |
04237ddd MC |
889 | * similar to tg3_enable_ints, but it accurately determines whether there |
890 | * is new work pending and can return without flushing the PIO write | |
6aa20a22 | 891 | * which reenables interrupts |
1da177e4 | 892 | */ |
17375d25 | 893 | static void tg3_int_reenable(struct tg3_napi *tnapi) |
1da177e4 | 894 | { |
17375d25 MC |
895 | struct tg3 *tp = tnapi->tp; |
896 | ||
898a56f8 | 897 | tw32_mailbox(tnapi->int_mbox, tnapi->last_tag << 24); |
1da177e4 LT |
898 | mmiowb(); |
899 | ||
fac9b83e DM |
900 | /* When doing tagged status, this work check is unnecessary. |
901 | * The last_tag we write above tells the chip which piece of | |
902 | * work we've completed. | |
903 | */ | |
63c3a66f | 904 | if (!tg3_flag(tp, TAGGED_STATUS) && tg3_has_work(tnapi)) |
04237ddd | 905 | tw32(HOSTCC_MODE, tp->coalesce_mode | |
fd2ce37f | 906 | HOSTCC_MODE_ENABLE | tnapi->coal_now); |
1da177e4 LT |
907 | } |
908 | ||
1da177e4 LT |
909 | static void tg3_switch_clocks(struct tg3 *tp) |
910 | { | |
f6eb9b1f | 911 | u32 clock_ctrl; |
1da177e4 LT |
912 | u32 orig_clock_ctrl; |
913 | ||
63c3a66f | 914 | if (tg3_flag(tp, CPMU_PRESENT) || tg3_flag(tp, 5780_CLASS)) |
4cf78e4f MC |
915 | return; |
916 | ||
f6eb9b1f MC |
917 | clock_ctrl = tr32(TG3PCI_CLOCK_CTRL); |
918 | ||
1da177e4 LT |
919 | orig_clock_ctrl = clock_ctrl; |
920 | clock_ctrl &= (CLOCK_CTRL_FORCE_CLKRUN | | |
921 | CLOCK_CTRL_CLKRUN_OENABLE | | |
922 | 0x1f); | |
923 | tp->pci_clock_ctrl = clock_ctrl; | |
924 | ||
63c3a66f | 925 | if (tg3_flag(tp, 5705_PLUS)) { |
1da177e4 | 926 | if (orig_clock_ctrl & CLOCK_CTRL_625_CORE) { |
b401e9e2 MC |
927 | tw32_wait_f(TG3PCI_CLOCK_CTRL, |
928 | clock_ctrl | CLOCK_CTRL_625_CORE, 40); | |
1da177e4 LT |
929 | } |
930 | } else if ((orig_clock_ctrl & CLOCK_CTRL_44MHZ_CORE) != 0) { | |
b401e9e2 MC |
931 | tw32_wait_f(TG3PCI_CLOCK_CTRL, |
932 | clock_ctrl | | |
933 | (CLOCK_CTRL_44MHZ_CORE | CLOCK_CTRL_ALTCLK), | |
934 | 40); | |
935 | tw32_wait_f(TG3PCI_CLOCK_CTRL, | |
936 | clock_ctrl | (CLOCK_CTRL_ALTCLK), | |
937 | 40); | |
1da177e4 | 938 | } |
b401e9e2 | 939 | tw32_wait_f(TG3PCI_CLOCK_CTRL, clock_ctrl, 40); |
1da177e4 LT |
940 | } |
941 | ||
942 | #define PHY_BUSY_LOOPS 5000 | |
943 | ||
944 | static int tg3_readphy(struct tg3 *tp, int reg, u32 *val) | |
945 | { | |
946 | u32 frame_val; | |
947 | unsigned int loops; | |
948 | int ret; | |
949 | ||
950 | if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) { | |
951 | tw32_f(MAC_MI_MODE, | |
952 | (tp->mi_mode & ~MAC_MI_MODE_AUTO_POLL)); | |
953 | udelay(80); | |
954 | } | |
955 | ||
956 | *val = 0x0; | |
957 | ||
882e9793 | 958 | frame_val = ((tp->phy_addr << MI_COM_PHY_ADDR_SHIFT) & |
1da177e4 LT |
959 | MI_COM_PHY_ADDR_MASK); |
960 | frame_val |= ((reg << MI_COM_REG_ADDR_SHIFT) & | |
961 | MI_COM_REG_ADDR_MASK); | |
962 | frame_val |= (MI_COM_CMD_READ | MI_COM_START); | |
6aa20a22 | 963 | |
1da177e4 LT |
964 | tw32_f(MAC_MI_COM, frame_val); |
965 | ||
966 | loops = PHY_BUSY_LOOPS; | |
967 | while (loops != 0) { | |
968 | udelay(10); | |
969 | frame_val = tr32(MAC_MI_COM); | |
970 | ||
971 | if ((frame_val & MI_COM_BUSY) == 0) { | |
972 | udelay(5); | |
973 | frame_val = tr32(MAC_MI_COM); | |
974 | break; | |
975 | } | |
976 | loops -= 1; | |
977 | } | |
978 | ||
979 | ret = -EBUSY; | |
980 | if (loops != 0) { | |
981 | *val = frame_val & MI_COM_DATA_MASK; | |
982 | ret = 0; | |
983 | } | |
984 | ||
985 | if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) { | |
986 | tw32_f(MAC_MI_MODE, tp->mi_mode); | |
987 | udelay(80); | |
988 | } | |
989 | ||
990 | return ret; | |
991 | } | |
992 | ||
993 | static int tg3_writephy(struct tg3 *tp, int reg, u32 val) | |
994 | { | |
995 | u32 frame_val; | |
996 | unsigned int loops; | |
997 | int ret; | |
998 | ||
f07e9af3 | 999 | if ((tp->phy_flags & TG3_PHYFLG_IS_FET) && |
221c5637 | 1000 | (reg == MII_CTRL1000 || reg == MII_TG3_AUX_CTRL)) |
b5d3772c MC |
1001 | return 0; |
1002 | ||
1da177e4 LT |
1003 | if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) { |
1004 | tw32_f(MAC_MI_MODE, | |
1005 | (tp->mi_mode & ~MAC_MI_MODE_AUTO_POLL)); | |
1006 | udelay(80); | |
1007 | } | |
1008 | ||
882e9793 | 1009 | frame_val = ((tp->phy_addr << MI_COM_PHY_ADDR_SHIFT) & |
1da177e4 LT |
1010 | MI_COM_PHY_ADDR_MASK); |
1011 | frame_val |= ((reg << MI_COM_REG_ADDR_SHIFT) & | |
1012 | MI_COM_REG_ADDR_MASK); | |
1013 | frame_val |= (val & MI_COM_DATA_MASK); | |
1014 | frame_val |= (MI_COM_CMD_WRITE | MI_COM_START); | |
6aa20a22 | 1015 | |
1da177e4 LT |
1016 | tw32_f(MAC_MI_COM, frame_val); |
1017 | ||
1018 | loops = PHY_BUSY_LOOPS; | |
1019 | while (loops != 0) { | |
1020 | udelay(10); | |
1021 | frame_val = tr32(MAC_MI_COM); | |
1022 | if ((frame_val & MI_COM_BUSY) == 0) { | |
1023 | udelay(5); | |
1024 | frame_val = tr32(MAC_MI_COM); | |
1025 | break; | |
1026 | } | |
1027 | loops -= 1; | |
1028 | } | |
1029 | ||
1030 | ret = -EBUSY; | |
1031 | if (loops != 0) | |
1032 | ret = 0; | |
1033 | ||
1034 | if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) { | |
1035 | tw32_f(MAC_MI_MODE, tp->mi_mode); | |
1036 | udelay(80); | |
1037 | } | |
1038 | ||
1039 | return ret; | |
1040 | } | |
1041 | ||
b0988c15 MC |
1042 | static int tg3_phy_cl45_write(struct tg3 *tp, u32 devad, u32 addr, u32 val) |
1043 | { | |
1044 | int err; | |
1045 | ||
1046 | err = tg3_writephy(tp, MII_TG3_MMD_CTRL, devad); | |
1047 | if (err) | |
1048 | goto done; | |
1049 | ||
1050 | err = tg3_writephy(tp, MII_TG3_MMD_ADDRESS, addr); | |
1051 | if (err) | |
1052 | goto done; | |
1053 | ||
1054 | err = tg3_writephy(tp, MII_TG3_MMD_CTRL, | |
1055 | MII_TG3_MMD_CTRL_DATA_NOINC | devad); | |
1056 | if (err) | |
1057 | goto done; | |
1058 | ||
1059 | err = tg3_writephy(tp, MII_TG3_MMD_ADDRESS, val); | |
1060 | ||
1061 | done: | |
1062 | return err; | |
1063 | } | |
1064 | ||
1065 | static int tg3_phy_cl45_read(struct tg3 *tp, u32 devad, u32 addr, u32 *val) | |
1066 | { | |
1067 | int err; | |
1068 | ||
1069 | err = tg3_writephy(tp, MII_TG3_MMD_CTRL, devad); | |
1070 | if (err) | |
1071 | goto done; | |
1072 | ||
1073 | err = tg3_writephy(tp, MII_TG3_MMD_ADDRESS, addr); | |
1074 | if (err) | |
1075 | goto done; | |
1076 | ||
1077 | err = tg3_writephy(tp, MII_TG3_MMD_CTRL, | |
1078 | MII_TG3_MMD_CTRL_DATA_NOINC | devad); | |
1079 | if (err) | |
1080 | goto done; | |
1081 | ||
1082 | err = tg3_readphy(tp, MII_TG3_MMD_ADDRESS, val); | |
1083 | ||
1084 | done: | |
1085 | return err; | |
1086 | } | |
1087 | ||
1088 | static int tg3_phydsp_read(struct tg3 *tp, u32 reg, u32 *val) | |
1089 | { | |
1090 | int err; | |
1091 | ||
1092 | err = tg3_writephy(tp, MII_TG3_DSP_ADDRESS, reg); | |
1093 | if (!err) | |
1094 | err = tg3_readphy(tp, MII_TG3_DSP_RW_PORT, val); | |
1095 | ||
1096 | return err; | |
1097 | } | |
1098 | ||
1099 | static int tg3_phydsp_write(struct tg3 *tp, u32 reg, u32 val) | |
1100 | { | |
1101 | int err; | |
1102 | ||
1103 | err = tg3_writephy(tp, MII_TG3_DSP_ADDRESS, reg); | |
1104 | if (!err) | |
1105 | err = tg3_writephy(tp, MII_TG3_DSP_RW_PORT, val); | |
1106 | ||
1107 | return err; | |
1108 | } | |
1109 | ||
15ee95c3 MC |
1110 | static int tg3_phy_auxctl_read(struct tg3 *tp, int reg, u32 *val) |
1111 | { | |
1112 | int err; | |
1113 | ||
1114 | err = tg3_writephy(tp, MII_TG3_AUX_CTRL, | |
1115 | (reg << MII_TG3_AUXCTL_MISC_RDSEL_SHIFT) | | |
1116 | MII_TG3_AUXCTL_SHDWSEL_MISC); | |
1117 | if (!err) | |
1118 | err = tg3_readphy(tp, MII_TG3_AUX_CTRL, val); | |
1119 | ||
1120 | return err; | |
1121 | } | |
1122 | ||
b4bd2929 MC |
1123 | static int tg3_phy_auxctl_write(struct tg3 *tp, int reg, u32 set) |
1124 | { | |
1125 | if (reg == MII_TG3_AUXCTL_SHDWSEL_MISC) | |
1126 | set |= MII_TG3_AUXCTL_MISC_WREN; | |
1127 | ||
1128 | return tg3_writephy(tp, MII_TG3_AUX_CTRL, set | reg); | |
1129 | } | |
1130 | ||
1d36ba45 MC |
1131 | #define TG3_PHY_AUXCTL_SMDSP_ENABLE(tp) \ |
1132 | tg3_phy_auxctl_write((tp), MII_TG3_AUXCTL_SHDWSEL_AUXCTL, \ | |
1133 | MII_TG3_AUXCTL_ACTL_SMDSP_ENA | \ | |
1134 | MII_TG3_AUXCTL_ACTL_TX_6DB) | |
1135 | ||
1136 | #define TG3_PHY_AUXCTL_SMDSP_DISABLE(tp) \ | |
1137 | tg3_phy_auxctl_write((tp), MII_TG3_AUXCTL_SHDWSEL_AUXCTL, \ | |
1138 | MII_TG3_AUXCTL_ACTL_TX_6DB); | |
1139 | ||
95e2869a MC |
1140 | static int tg3_bmcr_reset(struct tg3 *tp) |
1141 | { | |
1142 | u32 phy_control; | |
1143 | int limit, err; | |
1144 | ||
1145 | /* OK, reset it, and poll the BMCR_RESET bit until it | |
1146 | * clears or we time out. | |
1147 | */ | |
1148 | phy_control = BMCR_RESET; | |
1149 | err = tg3_writephy(tp, MII_BMCR, phy_control); | |
1150 | if (err != 0) | |
1151 | return -EBUSY; | |
1152 | ||
1153 | limit = 5000; | |
1154 | while (limit--) { | |
1155 | err = tg3_readphy(tp, MII_BMCR, &phy_control); | |
1156 | if (err != 0) | |
1157 | return -EBUSY; | |
1158 | ||
1159 | if ((phy_control & BMCR_RESET) == 0) { | |
1160 | udelay(40); | |
1161 | break; | |
1162 | } | |
1163 | udelay(10); | |
1164 | } | |
d4675b52 | 1165 | if (limit < 0) |
95e2869a MC |
1166 | return -EBUSY; |
1167 | ||
1168 | return 0; | |
1169 | } | |
1170 | ||
158d7abd MC |
1171 | static int tg3_mdio_read(struct mii_bus *bp, int mii_id, int reg) |
1172 | { | |
3d16543d | 1173 | struct tg3 *tp = bp->priv; |
158d7abd MC |
1174 | u32 val; |
1175 | ||
24bb4fb6 | 1176 | spin_lock_bh(&tp->lock); |
158d7abd MC |
1177 | |
1178 | if (tg3_readphy(tp, reg, &val)) | |
24bb4fb6 MC |
1179 | val = -EIO; |
1180 | ||
1181 | spin_unlock_bh(&tp->lock); | |
158d7abd MC |
1182 | |
1183 | return val; | |
1184 | } | |
1185 | ||
1186 | static int tg3_mdio_write(struct mii_bus *bp, int mii_id, int reg, u16 val) | |
1187 | { | |
3d16543d | 1188 | struct tg3 *tp = bp->priv; |
24bb4fb6 | 1189 | u32 ret = 0; |
158d7abd | 1190 | |
24bb4fb6 | 1191 | spin_lock_bh(&tp->lock); |
158d7abd MC |
1192 | |
1193 | if (tg3_writephy(tp, reg, val)) | |
24bb4fb6 | 1194 | ret = -EIO; |
158d7abd | 1195 | |
24bb4fb6 MC |
1196 | spin_unlock_bh(&tp->lock); |
1197 | ||
1198 | return ret; | |
158d7abd MC |
1199 | } |
1200 | ||
1201 | static int tg3_mdio_reset(struct mii_bus *bp) | |
1202 | { | |
1203 | return 0; | |
1204 | } | |
1205 | ||
9c61d6bc | 1206 | static void tg3_mdio_config_5785(struct tg3 *tp) |
a9daf367 MC |
1207 | { |
1208 | u32 val; | |
fcb389df | 1209 | struct phy_device *phydev; |
a9daf367 | 1210 | |
3f0e3ad7 | 1211 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
fcb389df | 1212 | switch (phydev->drv->phy_id & phydev->drv->phy_id_mask) { |
6a443a0f MC |
1213 | case PHY_ID_BCM50610: |
1214 | case PHY_ID_BCM50610M: | |
fcb389df MC |
1215 | val = MAC_PHYCFG2_50610_LED_MODES; |
1216 | break; | |
6a443a0f | 1217 | case PHY_ID_BCMAC131: |
fcb389df MC |
1218 | val = MAC_PHYCFG2_AC131_LED_MODES; |
1219 | break; | |
6a443a0f | 1220 | case PHY_ID_RTL8211C: |
fcb389df MC |
1221 | val = MAC_PHYCFG2_RTL8211C_LED_MODES; |
1222 | break; | |
6a443a0f | 1223 | case PHY_ID_RTL8201E: |
fcb389df MC |
1224 | val = MAC_PHYCFG2_RTL8201E_LED_MODES; |
1225 | break; | |
1226 | default: | |
a9daf367 | 1227 | return; |
fcb389df MC |
1228 | } |
1229 | ||
1230 | if (phydev->interface != PHY_INTERFACE_MODE_RGMII) { | |
1231 | tw32(MAC_PHYCFG2, val); | |
1232 | ||
1233 | val = tr32(MAC_PHYCFG1); | |
bb85fbb6 MC |
1234 | val &= ~(MAC_PHYCFG1_RGMII_INT | |
1235 | MAC_PHYCFG1_RXCLK_TO_MASK | MAC_PHYCFG1_TXCLK_TO_MASK); | |
1236 | val |= MAC_PHYCFG1_RXCLK_TIMEOUT | MAC_PHYCFG1_TXCLK_TIMEOUT; | |
fcb389df MC |
1237 | tw32(MAC_PHYCFG1, val); |
1238 | ||
1239 | return; | |
1240 | } | |
1241 | ||
63c3a66f | 1242 | if (!tg3_flag(tp, RGMII_INBAND_DISABLE)) |
fcb389df MC |
1243 | val |= MAC_PHYCFG2_EMODE_MASK_MASK | |
1244 | MAC_PHYCFG2_FMODE_MASK_MASK | | |
1245 | MAC_PHYCFG2_GMODE_MASK_MASK | | |
1246 | MAC_PHYCFG2_ACT_MASK_MASK | | |
1247 | MAC_PHYCFG2_QUAL_MASK_MASK | | |
1248 | MAC_PHYCFG2_INBAND_ENABLE; | |
1249 | ||
1250 | tw32(MAC_PHYCFG2, val); | |
a9daf367 | 1251 | |
bb85fbb6 MC |
1252 | val = tr32(MAC_PHYCFG1); |
1253 | val &= ~(MAC_PHYCFG1_RXCLK_TO_MASK | MAC_PHYCFG1_TXCLK_TO_MASK | | |
1254 | MAC_PHYCFG1_RGMII_EXT_RX_DEC | MAC_PHYCFG1_RGMII_SND_STAT_EN); | |
63c3a66f JP |
1255 | if (!tg3_flag(tp, RGMII_INBAND_DISABLE)) { |
1256 | if (tg3_flag(tp, RGMII_EXT_IBND_RX_EN)) | |
a9daf367 | 1257 | val |= MAC_PHYCFG1_RGMII_EXT_RX_DEC; |
63c3a66f | 1258 | if (tg3_flag(tp, RGMII_EXT_IBND_TX_EN)) |
a9daf367 MC |
1259 | val |= MAC_PHYCFG1_RGMII_SND_STAT_EN; |
1260 | } | |
bb85fbb6 MC |
1261 | val |= MAC_PHYCFG1_RXCLK_TIMEOUT | MAC_PHYCFG1_TXCLK_TIMEOUT | |
1262 | MAC_PHYCFG1_RGMII_INT | MAC_PHYCFG1_TXC_DRV; | |
1263 | tw32(MAC_PHYCFG1, val); | |
a9daf367 | 1264 | |
a9daf367 MC |
1265 | val = tr32(MAC_EXT_RGMII_MODE); |
1266 | val &= ~(MAC_RGMII_MODE_RX_INT_B | | |
1267 | MAC_RGMII_MODE_RX_QUALITY | | |
1268 | MAC_RGMII_MODE_RX_ACTIVITY | | |
1269 | MAC_RGMII_MODE_RX_ENG_DET | | |
1270 | MAC_RGMII_MODE_TX_ENABLE | | |
1271 | MAC_RGMII_MODE_TX_LOWPWR | | |
1272 | MAC_RGMII_MODE_TX_RESET); | |
63c3a66f JP |
1273 | if (!tg3_flag(tp, RGMII_INBAND_DISABLE)) { |
1274 | if (tg3_flag(tp, RGMII_EXT_IBND_RX_EN)) | |
a9daf367 MC |
1275 | val |= MAC_RGMII_MODE_RX_INT_B | |
1276 | MAC_RGMII_MODE_RX_QUALITY | | |
1277 | MAC_RGMII_MODE_RX_ACTIVITY | | |
1278 | MAC_RGMII_MODE_RX_ENG_DET; | |
63c3a66f | 1279 | if (tg3_flag(tp, RGMII_EXT_IBND_TX_EN)) |
a9daf367 MC |
1280 | val |= MAC_RGMII_MODE_TX_ENABLE | |
1281 | MAC_RGMII_MODE_TX_LOWPWR | | |
1282 | MAC_RGMII_MODE_TX_RESET; | |
1283 | } | |
1284 | tw32(MAC_EXT_RGMII_MODE, val); | |
1285 | } | |
1286 | ||
158d7abd MC |
1287 | static void tg3_mdio_start(struct tg3 *tp) |
1288 | { | |
158d7abd MC |
1289 | tp->mi_mode &= ~MAC_MI_MODE_AUTO_POLL; |
1290 | tw32_f(MAC_MI_MODE, tp->mi_mode); | |
1291 | udelay(80); | |
a9daf367 | 1292 | |
63c3a66f | 1293 | if (tg3_flag(tp, MDIOBUS_INITED) && |
9ea4818d MC |
1294 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) |
1295 | tg3_mdio_config_5785(tp); | |
1296 | } | |
1297 | ||
1298 | static int tg3_mdio_init(struct tg3 *tp) | |
1299 | { | |
1300 | int i; | |
1301 | u32 reg; | |
1302 | struct phy_device *phydev; | |
1303 | ||
63c3a66f | 1304 | if (tg3_flag(tp, 5717_PLUS)) { |
9c7df915 | 1305 | u32 is_serdes; |
882e9793 | 1306 | |
69f11c99 | 1307 | tp->phy_addr = tp->pci_fn + 1; |
882e9793 | 1308 | |
d1ec96af MC |
1309 | if (tp->pci_chip_rev_id != CHIPREV_ID_5717_A0) |
1310 | is_serdes = tr32(SG_DIG_STATUS) & SG_DIG_IS_SERDES; | |
1311 | else | |
1312 | is_serdes = tr32(TG3_CPMU_PHY_STRAP) & | |
1313 | TG3_CPMU_PHY_STRAP_IS_SERDES; | |
882e9793 MC |
1314 | if (is_serdes) |
1315 | tp->phy_addr += 7; | |
1316 | } else | |
3f0e3ad7 | 1317 | tp->phy_addr = TG3_PHY_MII_ADDR; |
882e9793 | 1318 | |
158d7abd MC |
1319 | tg3_mdio_start(tp); |
1320 | ||
63c3a66f | 1321 | if (!tg3_flag(tp, USE_PHYLIB) || tg3_flag(tp, MDIOBUS_INITED)) |
158d7abd MC |
1322 | return 0; |
1323 | ||
298cf9be LB |
1324 | tp->mdio_bus = mdiobus_alloc(); |
1325 | if (tp->mdio_bus == NULL) | |
1326 | return -ENOMEM; | |
158d7abd | 1327 | |
298cf9be LB |
1328 | tp->mdio_bus->name = "tg3 mdio bus"; |
1329 | snprintf(tp->mdio_bus->id, MII_BUS_ID_SIZE, "%x", | |
158d7abd | 1330 | (tp->pdev->bus->number << 8) | tp->pdev->devfn); |
298cf9be LB |
1331 | tp->mdio_bus->priv = tp; |
1332 | tp->mdio_bus->parent = &tp->pdev->dev; | |
1333 | tp->mdio_bus->read = &tg3_mdio_read; | |
1334 | tp->mdio_bus->write = &tg3_mdio_write; | |
1335 | tp->mdio_bus->reset = &tg3_mdio_reset; | |
3f0e3ad7 | 1336 | tp->mdio_bus->phy_mask = ~(1 << TG3_PHY_MII_ADDR); |
298cf9be | 1337 | tp->mdio_bus->irq = &tp->mdio_irq[0]; |
158d7abd MC |
1338 | |
1339 | for (i = 0; i < PHY_MAX_ADDR; i++) | |
298cf9be | 1340 | tp->mdio_bus->irq[i] = PHY_POLL; |
158d7abd MC |
1341 | |
1342 | /* The bus registration will look for all the PHYs on the mdio bus. | |
1343 | * Unfortunately, it does not ensure the PHY is powered up before | |
1344 | * accessing the PHY ID registers. A chip reset is the | |
1345 | * quickest way to bring the device back to an operational state.. | |
1346 | */ | |
1347 | if (tg3_readphy(tp, MII_BMCR, ®) || (reg & BMCR_PDOWN)) | |
1348 | tg3_bmcr_reset(tp); | |
1349 | ||
298cf9be | 1350 | i = mdiobus_register(tp->mdio_bus); |
a9daf367 | 1351 | if (i) { |
ab96b241 | 1352 | dev_warn(&tp->pdev->dev, "mdiobus_reg failed (0x%x)\n", i); |
9c61d6bc | 1353 | mdiobus_free(tp->mdio_bus); |
a9daf367 MC |
1354 | return i; |
1355 | } | |
158d7abd | 1356 | |
3f0e3ad7 | 1357 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
a9daf367 | 1358 | |
9c61d6bc | 1359 | if (!phydev || !phydev->drv) { |
ab96b241 | 1360 | dev_warn(&tp->pdev->dev, "No PHY devices\n"); |
9c61d6bc MC |
1361 | mdiobus_unregister(tp->mdio_bus); |
1362 | mdiobus_free(tp->mdio_bus); | |
1363 | return -ENODEV; | |
1364 | } | |
1365 | ||
1366 | switch (phydev->drv->phy_id & phydev->drv->phy_id_mask) { | |
6a443a0f | 1367 | case PHY_ID_BCM57780: |
321d32a0 | 1368 | phydev->interface = PHY_INTERFACE_MODE_GMII; |
c704dc23 | 1369 | phydev->dev_flags |= PHY_BRCM_AUTO_PWRDWN_ENABLE; |
321d32a0 | 1370 | break; |
6a443a0f MC |
1371 | case PHY_ID_BCM50610: |
1372 | case PHY_ID_BCM50610M: | |
32e5a8d6 | 1373 | phydev->dev_flags |= PHY_BRCM_CLEAR_RGMII_MODE | |
c704dc23 | 1374 | PHY_BRCM_RX_REFCLK_UNUSED | |
52fae083 | 1375 | PHY_BRCM_DIS_TXCRXC_NOENRGY | |
c704dc23 | 1376 | PHY_BRCM_AUTO_PWRDWN_ENABLE; |
63c3a66f | 1377 | if (tg3_flag(tp, RGMII_INBAND_DISABLE)) |
a9daf367 | 1378 | phydev->dev_flags |= PHY_BRCM_STD_IBND_DISABLE; |
63c3a66f | 1379 | if (tg3_flag(tp, RGMII_EXT_IBND_RX_EN)) |
a9daf367 | 1380 | phydev->dev_flags |= PHY_BRCM_EXT_IBND_RX_ENABLE; |
63c3a66f | 1381 | if (tg3_flag(tp, RGMII_EXT_IBND_TX_EN)) |
a9daf367 | 1382 | phydev->dev_flags |= PHY_BRCM_EXT_IBND_TX_ENABLE; |
fcb389df | 1383 | /* fallthru */ |
6a443a0f | 1384 | case PHY_ID_RTL8211C: |
fcb389df | 1385 | phydev->interface = PHY_INTERFACE_MODE_RGMII; |
a9daf367 | 1386 | break; |
6a443a0f MC |
1387 | case PHY_ID_RTL8201E: |
1388 | case PHY_ID_BCMAC131: | |
a9daf367 | 1389 | phydev->interface = PHY_INTERFACE_MODE_MII; |
cdd4e09d | 1390 | phydev->dev_flags |= PHY_BRCM_AUTO_PWRDWN_ENABLE; |
f07e9af3 | 1391 | tp->phy_flags |= TG3_PHYFLG_IS_FET; |
a9daf367 MC |
1392 | break; |
1393 | } | |
1394 | ||
63c3a66f | 1395 | tg3_flag_set(tp, MDIOBUS_INITED); |
9c61d6bc MC |
1396 | |
1397 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) | |
1398 | tg3_mdio_config_5785(tp); | |
a9daf367 MC |
1399 | |
1400 | return 0; | |
158d7abd MC |
1401 | } |
1402 | ||
1403 | static void tg3_mdio_fini(struct tg3 *tp) | |
1404 | { | |
63c3a66f JP |
1405 | if (tg3_flag(tp, MDIOBUS_INITED)) { |
1406 | tg3_flag_clear(tp, MDIOBUS_INITED); | |
298cf9be LB |
1407 | mdiobus_unregister(tp->mdio_bus); |
1408 | mdiobus_free(tp->mdio_bus); | |
158d7abd MC |
1409 | } |
1410 | } | |
1411 | ||
4ba526ce MC |
1412 | /* tp->lock is held. */ |
1413 | static inline void tg3_generate_fw_event(struct tg3 *tp) | |
1414 | { | |
1415 | u32 val; | |
1416 | ||
1417 | val = tr32(GRC_RX_CPU_EVENT); | |
1418 | val |= GRC_RX_CPU_DRIVER_EVENT; | |
1419 | tw32_f(GRC_RX_CPU_EVENT, val); | |
1420 | ||
1421 | tp->last_event_jiffies = jiffies; | |
1422 | } | |
1423 | ||
1424 | #define TG3_FW_EVENT_TIMEOUT_USEC 2500 | |
1425 | ||
95e2869a MC |
1426 | /* tp->lock is held. */ |
1427 | static void tg3_wait_for_event_ack(struct tg3 *tp) | |
1428 | { | |
1429 | int i; | |
4ba526ce MC |
1430 | unsigned int delay_cnt; |
1431 | long time_remain; | |
1432 | ||
1433 | /* If enough time has passed, no wait is necessary. */ | |
1434 | time_remain = (long)(tp->last_event_jiffies + 1 + | |
1435 | usecs_to_jiffies(TG3_FW_EVENT_TIMEOUT_USEC)) - | |
1436 | (long)jiffies; | |
1437 | if (time_remain < 0) | |
1438 | return; | |
1439 | ||
1440 | /* Check if we can shorten the wait time. */ | |
1441 | delay_cnt = jiffies_to_usecs(time_remain); | |
1442 | if (delay_cnt > TG3_FW_EVENT_TIMEOUT_USEC) | |
1443 | delay_cnt = TG3_FW_EVENT_TIMEOUT_USEC; | |
1444 | delay_cnt = (delay_cnt >> 3) + 1; | |
95e2869a | 1445 | |
4ba526ce | 1446 | for (i = 0; i < delay_cnt; i++) { |
95e2869a MC |
1447 | if (!(tr32(GRC_RX_CPU_EVENT) & GRC_RX_CPU_DRIVER_EVENT)) |
1448 | break; | |
4ba526ce | 1449 | udelay(8); |
95e2869a MC |
1450 | } |
1451 | } | |
1452 | ||
1453 | /* tp->lock is held. */ | |
1454 | static void tg3_ump_link_report(struct tg3 *tp) | |
1455 | { | |
1456 | u32 reg; | |
1457 | u32 val; | |
1458 | ||
63c3a66f | 1459 | if (!tg3_flag(tp, 5780_CLASS) || !tg3_flag(tp, ENABLE_ASF)) |
95e2869a MC |
1460 | return; |
1461 | ||
1462 | tg3_wait_for_event_ack(tp); | |
1463 | ||
1464 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX, FWCMD_NICDRV_LINK_UPDATE); | |
1465 | ||
1466 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_LEN_MBOX, 14); | |
1467 | ||
1468 | val = 0; | |
1469 | if (!tg3_readphy(tp, MII_BMCR, ®)) | |
1470 | val = reg << 16; | |
1471 | if (!tg3_readphy(tp, MII_BMSR, ®)) | |
1472 | val |= (reg & 0xffff); | |
1473 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX, val); | |
1474 | ||
1475 | val = 0; | |
1476 | if (!tg3_readphy(tp, MII_ADVERTISE, ®)) | |
1477 | val = reg << 16; | |
1478 | if (!tg3_readphy(tp, MII_LPA, ®)) | |
1479 | val |= (reg & 0xffff); | |
1480 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX + 4, val); | |
1481 | ||
1482 | val = 0; | |
f07e9af3 | 1483 | if (!(tp->phy_flags & TG3_PHYFLG_MII_SERDES)) { |
95e2869a MC |
1484 | if (!tg3_readphy(tp, MII_CTRL1000, ®)) |
1485 | val = reg << 16; | |
1486 | if (!tg3_readphy(tp, MII_STAT1000, ®)) | |
1487 | val |= (reg & 0xffff); | |
1488 | } | |
1489 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX + 8, val); | |
1490 | ||
1491 | if (!tg3_readphy(tp, MII_PHYADDR, ®)) | |
1492 | val = reg << 16; | |
1493 | else | |
1494 | val = 0; | |
1495 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX + 12, val); | |
1496 | ||
4ba526ce | 1497 | tg3_generate_fw_event(tp); |
95e2869a MC |
1498 | } |
1499 | ||
8d5a89b3 MC |
1500 | /* tp->lock is held. */ |
1501 | static void tg3_stop_fw(struct tg3 *tp) | |
1502 | { | |
1503 | if (tg3_flag(tp, ENABLE_ASF) && !tg3_flag(tp, ENABLE_APE)) { | |
1504 | /* Wait for RX cpu to ACK the previous event. */ | |
1505 | tg3_wait_for_event_ack(tp); | |
1506 | ||
1507 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX, FWCMD_NICDRV_PAUSE_FW); | |
1508 | ||
1509 | tg3_generate_fw_event(tp); | |
1510 | ||
1511 | /* Wait for RX cpu to ACK this event. */ | |
1512 | tg3_wait_for_event_ack(tp); | |
1513 | } | |
1514 | } | |
1515 | ||
fd6d3f0e MC |
1516 | /* tp->lock is held. */ |
1517 | static void tg3_write_sig_pre_reset(struct tg3 *tp, int kind) | |
1518 | { | |
1519 | tg3_write_mem(tp, NIC_SRAM_FIRMWARE_MBOX, | |
1520 | NIC_SRAM_FIRMWARE_MBOX_MAGIC1); | |
1521 | ||
1522 | if (tg3_flag(tp, ASF_NEW_HANDSHAKE)) { | |
1523 | switch (kind) { | |
1524 | case RESET_KIND_INIT: | |
1525 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, | |
1526 | DRV_STATE_START); | |
1527 | break; | |
1528 | ||
1529 | case RESET_KIND_SHUTDOWN: | |
1530 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, | |
1531 | DRV_STATE_UNLOAD); | |
1532 | break; | |
1533 | ||
1534 | case RESET_KIND_SUSPEND: | |
1535 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, | |
1536 | DRV_STATE_SUSPEND); | |
1537 | break; | |
1538 | ||
1539 | default: | |
1540 | break; | |
1541 | } | |
1542 | } | |
1543 | ||
1544 | if (kind == RESET_KIND_INIT || | |
1545 | kind == RESET_KIND_SUSPEND) | |
1546 | tg3_ape_driver_state_change(tp, kind); | |
1547 | } | |
1548 | ||
1549 | /* tp->lock is held. */ | |
1550 | static void tg3_write_sig_post_reset(struct tg3 *tp, int kind) | |
1551 | { | |
1552 | if (tg3_flag(tp, ASF_NEW_HANDSHAKE)) { | |
1553 | switch (kind) { | |
1554 | case RESET_KIND_INIT: | |
1555 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, | |
1556 | DRV_STATE_START_DONE); | |
1557 | break; | |
1558 | ||
1559 | case RESET_KIND_SHUTDOWN: | |
1560 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, | |
1561 | DRV_STATE_UNLOAD_DONE); | |
1562 | break; | |
1563 | ||
1564 | default: | |
1565 | break; | |
1566 | } | |
1567 | } | |
1568 | ||
1569 | if (kind == RESET_KIND_SHUTDOWN) | |
1570 | tg3_ape_driver_state_change(tp, kind); | |
1571 | } | |
1572 | ||
1573 | /* tp->lock is held. */ | |
1574 | static void tg3_write_sig_legacy(struct tg3 *tp, int kind) | |
1575 | { | |
1576 | if (tg3_flag(tp, ENABLE_ASF)) { | |
1577 | switch (kind) { | |
1578 | case RESET_KIND_INIT: | |
1579 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, | |
1580 | DRV_STATE_START); | |
1581 | break; | |
1582 | ||
1583 | case RESET_KIND_SHUTDOWN: | |
1584 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, | |
1585 | DRV_STATE_UNLOAD); | |
1586 | break; | |
1587 | ||
1588 | case RESET_KIND_SUSPEND: | |
1589 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, | |
1590 | DRV_STATE_SUSPEND); | |
1591 | break; | |
1592 | ||
1593 | default: | |
1594 | break; | |
1595 | } | |
1596 | } | |
1597 | } | |
1598 | ||
1599 | static int tg3_poll_fw(struct tg3 *tp) | |
1600 | { | |
1601 | int i; | |
1602 | u32 val; | |
1603 | ||
1604 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { | |
1605 | /* Wait up to 20ms for init done. */ | |
1606 | for (i = 0; i < 200; i++) { | |
1607 | if (tr32(VCPU_STATUS) & VCPU_STATUS_INIT_DONE) | |
1608 | return 0; | |
1609 | udelay(100); | |
1610 | } | |
1611 | return -ENODEV; | |
1612 | } | |
1613 | ||
1614 | /* Wait for firmware initialization to complete. */ | |
1615 | for (i = 0; i < 100000; i++) { | |
1616 | tg3_read_mem(tp, NIC_SRAM_FIRMWARE_MBOX, &val); | |
1617 | if (val == ~NIC_SRAM_FIRMWARE_MBOX_MAGIC1) | |
1618 | break; | |
1619 | udelay(10); | |
1620 | } | |
1621 | ||
1622 | /* Chip might not be fitted with firmware. Some Sun onboard | |
1623 | * parts are configured like that. So don't signal the timeout | |
1624 | * of the above loop as an error, but do report the lack of | |
1625 | * running firmware once. | |
1626 | */ | |
1627 | if (i >= 100000 && !tg3_flag(tp, NO_FWARE_REPORTED)) { | |
1628 | tg3_flag_set(tp, NO_FWARE_REPORTED); | |
1629 | ||
1630 | netdev_info(tp->dev, "No firmware running\n"); | |
1631 | } | |
1632 | ||
1633 | if (tp->pci_chip_rev_id == CHIPREV_ID_57765_A0) { | |
1634 | /* The 57765 A0 needs a little more | |
1635 | * time to do some important work. | |
1636 | */ | |
1637 | mdelay(10); | |
1638 | } | |
1639 | ||
1640 | return 0; | |
1641 | } | |
1642 | ||
95e2869a MC |
1643 | static void tg3_link_report(struct tg3 *tp) |
1644 | { | |
1645 | if (!netif_carrier_ok(tp->dev)) { | |
05dbe005 | 1646 | netif_info(tp, link, tp->dev, "Link is down\n"); |
95e2869a MC |
1647 | tg3_ump_link_report(tp); |
1648 | } else if (netif_msg_link(tp)) { | |
05dbe005 JP |
1649 | netdev_info(tp->dev, "Link is up at %d Mbps, %s duplex\n", |
1650 | (tp->link_config.active_speed == SPEED_1000 ? | |
1651 | 1000 : | |
1652 | (tp->link_config.active_speed == SPEED_100 ? | |
1653 | 100 : 10)), | |
1654 | (tp->link_config.active_duplex == DUPLEX_FULL ? | |
1655 | "full" : "half")); | |
1656 | ||
1657 | netdev_info(tp->dev, "Flow control is %s for TX and %s for RX\n", | |
1658 | (tp->link_config.active_flowctrl & FLOW_CTRL_TX) ? | |
1659 | "on" : "off", | |
1660 | (tp->link_config.active_flowctrl & FLOW_CTRL_RX) ? | |
1661 | "on" : "off"); | |
47007831 MC |
1662 | |
1663 | if (tp->phy_flags & TG3_PHYFLG_EEE_CAP) | |
1664 | netdev_info(tp->dev, "EEE is %s\n", | |
1665 | tp->setlpicnt ? "enabled" : "disabled"); | |
1666 | ||
95e2869a MC |
1667 | tg3_ump_link_report(tp); |
1668 | } | |
1669 | } | |
1670 | ||
1671 | static u16 tg3_advert_flowctrl_1000T(u8 flow_ctrl) | |
1672 | { | |
1673 | u16 miireg; | |
1674 | ||
e18ce346 | 1675 | if ((flow_ctrl & FLOW_CTRL_TX) && (flow_ctrl & FLOW_CTRL_RX)) |
95e2869a | 1676 | miireg = ADVERTISE_PAUSE_CAP; |
e18ce346 | 1677 | else if (flow_ctrl & FLOW_CTRL_TX) |
95e2869a | 1678 | miireg = ADVERTISE_PAUSE_ASYM; |
e18ce346 | 1679 | else if (flow_ctrl & FLOW_CTRL_RX) |
95e2869a MC |
1680 | miireg = ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM; |
1681 | else | |
1682 | miireg = 0; | |
1683 | ||
1684 | return miireg; | |
1685 | } | |
1686 | ||
1687 | static u16 tg3_advert_flowctrl_1000X(u8 flow_ctrl) | |
1688 | { | |
1689 | u16 miireg; | |
1690 | ||
e18ce346 | 1691 | if ((flow_ctrl & FLOW_CTRL_TX) && (flow_ctrl & FLOW_CTRL_RX)) |
95e2869a | 1692 | miireg = ADVERTISE_1000XPAUSE; |
e18ce346 | 1693 | else if (flow_ctrl & FLOW_CTRL_TX) |
95e2869a | 1694 | miireg = ADVERTISE_1000XPSE_ASYM; |
e18ce346 | 1695 | else if (flow_ctrl & FLOW_CTRL_RX) |
95e2869a MC |
1696 | miireg = ADVERTISE_1000XPAUSE | ADVERTISE_1000XPSE_ASYM; |
1697 | else | |
1698 | miireg = 0; | |
1699 | ||
1700 | return miireg; | |
1701 | } | |
1702 | ||
95e2869a MC |
1703 | static u8 tg3_resolve_flowctrl_1000X(u16 lcladv, u16 rmtadv) |
1704 | { | |
1705 | u8 cap = 0; | |
1706 | ||
1707 | if (lcladv & ADVERTISE_1000XPAUSE) { | |
1708 | if (lcladv & ADVERTISE_1000XPSE_ASYM) { | |
1709 | if (rmtadv & LPA_1000XPAUSE) | |
e18ce346 | 1710 | cap = FLOW_CTRL_TX | FLOW_CTRL_RX; |
95e2869a | 1711 | else if (rmtadv & LPA_1000XPAUSE_ASYM) |
e18ce346 | 1712 | cap = FLOW_CTRL_RX; |
95e2869a MC |
1713 | } else { |
1714 | if (rmtadv & LPA_1000XPAUSE) | |
e18ce346 | 1715 | cap = FLOW_CTRL_TX | FLOW_CTRL_RX; |
95e2869a MC |
1716 | } |
1717 | } else if (lcladv & ADVERTISE_1000XPSE_ASYM) { | |
1718 | if ((rmtadv & LPA_1000XPAUSE) && (rmtadv & LPA_1000XPAUSE_ASYM)) | |
e18ce346 | 1719 | cap = FLOW_CTRL_TX; |
95e2869a MC |
1720 | } |
1721 | ||
1722 | return cap; | |
1723 | } | |
1724 | ||
f51f3562 | 1725 | static void tg3_setup_flow_control(struct tg3 *tp, u32 lcladv, u32 rmtadv) |
95e2869a | 1726 | { |
b02fd9e3 | 1727 | u8 autoneg; |
f51f3562 | 1728 | u8 flowctrl = 0; |
95e2869a MC |
1729 | u32 old_rx_mode = tp->rx_mode; |
1730 | u32 old_tx_mode = tp->tx_mode; | |
1731 | ||
63c3a66f | 1732 | if (tg3_flag(tp, USE_PHYLIB)) |
3f0e3ad7 | 1733 | autoneg = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]->autoneg; |
b02fd9e3 MC |
1734 | else |
1735 | autoneg = tp->link_config.autoneg; | |
1736 | ||
63c3a66f | 1737 | if (autoneg == AUTONEG_ENABLE && tg3_flag(tp, PAUSE_AUTONEG)) { |
f07e9af3 | 1738 | if (tp->phy_flags & TG3_PHYFLG_ANY_SERDES) |
f51f3562 | 1739 | flowctrl = tg3_resolve_flowctrl_1000X(lcladv, rmtadv); |
95e2869a | 1740 | else |
bc02ff95 | 1741 | flowctrl = mii_resolve_flowctrl_fdx(lcladv, rmtadv); |
f51f3562 MC |
1742 | } else |
1743 | flowctrl = tp->link_config.flowctrl; | |
95e2869a | 1744 | |
f51f3562 | 1745 | tp->link_config.active_flowctrl = flowctrl; |
95e2869a | 1746 | |
e18ce346 | 1747 | if (flowctrl & FLOW_CTRL_RX) |
95e2869a MC |
1748 | tp->rx_mode |= RX_MODE_FLOW_CTRL_ENABLE; |
1749 | else | |
1750 | tp->rx_mode &= ~RX_MODE_FLOW_CTRL_ENABLE; | |
1751 | ||
f51f3562 | 1752 | if (old_rx_mode != tp->rx_mode) |
95e2869a | 1753 | tw32_f(MAC_RX_MODE, tp->rx_mode); |
95e2869a | 1754 | |
e18ce346 | 1755 | if (flowctrl & FLOW_CTRL_TX) |
95e2869a MC |
1756 | tp->tx_mode |= TX_MODE_FLOW_CTRL_ENABLE; |
1757 | else | |
1758 | tp->tx_mode &= ~TX_MODE_FLOW_CTRL_ENABLE; | |
1759 | ||
f51f3562 | 1760 | if (old_tx_mode != tp->tx_mode) |
95e2869a | 1761 | tw32_f(MAC_TX_MODE, tp->tx_mode); |
95e2869a MC |
1762 | } |
1763 | ||
b02fd9e3 MC |
1764 | static void tg3_adjust_link(struct net_device *dev) |
1765 | { | |
1766 | u8 oldflowctrl, linkmesg = 0; | |
1767 | u32 mac_mode, lcl_adv, rmt_adv; | |
1768 | struct tg3 *tp = netdev_priv(dev); | |
3f0e3ad7 | 1769 | struct phy_device *phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
b02fd9e3 | 1770 | |
24bb4fb6 | 1771 | spin_lock_bh(&tp->lock); |
b02fd9e3 MC |
1772 | |
1773 | mac_mode = tp->mac_mode & ~(MAC_MODE_PORT_MODE_MASK | | |
1774 | MAC_MODE_HALF_DUPLEX); | |
1775 | ||
1776 | oldflowctrl = tp->link_config.active_flowctrl; | |
1777 | ||
1778 | if (phydev->link) { | |
1779 | lcl_adv = 0; | |
1780 | rmt_adv = 0; | |
1781 | ||
1782 | if (phydev->speed == SPEED_100 || phydev->speed == SPEED_10) | |
1783 | mac_mode |= MAC_MODE_PORT_MODE_MII; | |
c3df0748 MC |
1784 | else if (phydev->speed == SPEED_1000 || |
1785 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5785) | |
b02fd9e3 | 1786 | mac_mode |= MAC_MODE_PORT_MODE_GMII; |
c3df0748 MC |
1787 | else |
1788 | mac_mode |= MAC_MODE_PORT_MODE_MII; | |
b02fd9e3 MC |
1789 | |
1790 | if (phydev->duplex == DUPLEX_HALF) | |
1791 | mac_mode |= MAC_MODE_HALF_DUPLEX; | |
1792 | else { | |
1793 | lcl_adv = tg3_advert_flowctrl_1000T( | |
1794 | tp->link_config.flowctrl); | |
1795 | ||
1796 | if (phydev->pause) | |
1797 | rmt_adv = LPA_PAUSE_CAP; | |
1798 | if (phydev->asym_pause) | |
1799 | rmt_adv |= LPA_PAUSE_ASYM; | |
1800 | } | |
1801 | ||
1802 | tg3_setup_flow_control(tp, lcl_adv, rmt_adv); | |
1803 | } else | |
1804 | mac_mode |= MAC_MODE_PORT_MODE_GMII; | |
1805 | ||
1806 | if (mac_mode != tp->mac_mode) { | |
1807 | tp->mac_mode = mac_mode; | |
1808 | tw32_f(MAC_MODE, tp->mac_mode); | |
1809 | udelay(40); | |
1810 | } | |
1811 | ||
fcb389df MC |
1812 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) { |
1813 | if (phydev->speed == SPEED_10) | |
1814 | tw32(MAC_MI_STAT, | |
1815 | MAC_MI_STAT_10MBPS_MODE | | |
1816 | MAC_MI_STAT_LNKSTAT_ATTN_ENAB); | |
1817 | else | |
1818 | tw32(MAC_MI_STAT, MAC_MI_STAT_LNKSTAT_ATTN_ENAB); | |
1819 | } | |
1820 | ||
b02fd9e3 MC |
1821 | if (phydev->speed == SPEED_1000 && phydev->duplex == DUPLEX_HALF) |
1822 | tw32(MAC_TX_LENGTHS, | |
1823 | ((2 << TX_LENGTHS_IPG_CRS_SHIFT) | | |
1824 | (6 << TX_LENGTHS_IPG_SHIFT) | | |
1825 | (0xff << TX_LENGTHS_SLOT_TIME_SHIFT))); | |
1826 | else | |
1827 | tw32(MAC_TX_LENGTHS, | |
1828 | ((2 << TX_LENGTHS_IPG_CRS_SHIFT) | | |
1829 | (6 << TX_LENGTHS_IPG_SHIFT) | | |
1830 | (32 << TX_LENGTHS_SLOT_TIME_SHIFT))); | |
1831 | ||
1832 | if ((phydev->link && tp->link_config.active_speed == SPEED_INVALID) || | |
1833 | (!phydev->link && tp->link_config.active_speed != SPEED_INVALID) || | |
1834 | phydev->speed != tp->link_config.active_speed || | |
1835 | phydev->duplex != tp->link_config.active_duplex || | |
1836 | oldflowctrl != tp->link_config.active_flowctrl) | |
c6cdf436 | 1837 | linkmesg = 1; |
b02fd9e3 MC |
1838 | |
1839 | tp->link_config.active_speed = phydev->speed; | |
1840 | tp->link_config.active_duplex = phydev->duplex; | |
1841 | ||
24bb4fb6 | 1842 | spin_unlock_bh(&tp->lock); |
b02fd9e3 MC |
1843 | |
1844 | if (linkmesg) | |
1845 | tg3_link_report(tp); | |
1846 | } | |
1847 | ||
1848 | static int tg3_phy_init(struct tg3 *tp) | |
1849 | { | |
1850 | struct phy_device *phydev; | |
1851 | ||
f07e9af3 | 1852 | if (tp->phy_flags & TG3_PHYFLG_IS_CONNECTED) |
b02fd9e3 MC |
1853 | return 0; |
1854 | ||
1855 | /* Bring the PHY back to a known state. */ | |
1856 | tg3_bmcr_reset(tp); | |
1857 | ||
3f0e3ad7 | 1858 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
b02fd9e3 MC |
1859 | |
1860 | /* Attach the MAC to the PHY. */ | |
fb28ad35 | 1861 | phydev = phy_connect(tp->dev, dev_name(&phydev->dev), tg3_adjust_link, |
a9daf367 | 1862 | phydev->dev_flags, phydev->interface); |
b02fd9e3 | 1863 | if (IS_ERR(phydev)) { |
ab96b241 | 1864 | dev_err(&tp->pdev->dev, "Could not attach to PHY\n"); |
b02fd9e3 MC |
1865 | return PTR_ERR(phydev); |
1866 | } | |
1867 | ||
b02fd9e3 | 1868 | /* Mask with MAC supported features. */ |
9c61d6bc MC |
1869 | switch (phydev->interface) { |
1870 | case PHY_INTERFACE_MODE_GMII: | |
1871 | case PHY_INTERFACE_MODE_RGMII: | |
f07e9af3 | 1872 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) { |
321d32a0 MC |
1873 | phydev->supported &= (PHY_GBIT_FEATURES | |
1874 | SUPPORTED_Pause | | |
1875 | SUPPORTED_Asym_Pause); | |
1876 | break; | |
1877 | } | |
1878 | /* fallthru */ | |
9c61d6bc MC |
1879 | case PHY_INTERFACE_MODE_MII: |
1880 | phydev->supported &= (PHY_BASIC_FEATURES | | |
1881 | SUPPORTED_Pause | | |
1882 | SUPPORTED_Asym_Pause); | |
1883 | break; | |
1884 | default: | |
3f0e3ad7 | 1885 | phy_disconnect(tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]); |
9c61d6bc MC |
1886 | return -EINVAL; |
1887 | } | |
1888 | ||
f07e9af3 | 1889 | tp->phy_flags |= TG3_PHYFLG_IS_CONNECTED; |
b02fd9e3 MC |
1890 | |
1891 | phydev->advertising = phydev->supported; | |
1892 | ||
b02fd9e3 MC |
1893 | return 0; |
1894 | } | |
1895 | ||
1896 | static void tg3_phy_start(struct tg3 *tp) | |
1897 | { | |
1898 | struct phy_device *phydev; | |
1899 | ||
f07e9af3 | 1900 | if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) |
b02fd9e3 MC |
1901 | return; |
1902 | ||
3f0e3ad7 | 1903 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
b02fd9e3 | 1904 | |
80096068 MC |
1905 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) { |
1906 | tp->phy_flags &= ~TG3_PHYFLG_IS_LOW_POWER; | |
b02fd9e3 MC |
1907 | phydev->speed = tp->link_config.orig_speed; |
1908 | phydev->duplex = tp->link_config.orig_duplex; | |
1909 | phydev->autoneg = tp->link_config.orig_autoneg; | |
1910 | phydev->advertising = tp->link_config.orig_advertising; | |
1911 | } | |
1912 | ||
1913 | phy_start(phydev); | |
1914 | ||
1915 | phy_start_aneg(phydev); | |
1916 | } | |
1917 | ||
1918 | static void tg3_phy_stop(struct tg3 *tp) | |
1919 | { | |
f07e9af3 | 1920 | if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) |
b02fd9e3 MC |
1921 | return; |
1922 | ||
3f0e3ad7 | 1923 | phy_stop(tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]); |
b02fd9e3 MC |
1924 | } |
1925 | ||
1926 | static void tg3_phy_fini(struct tg3 *tp) | |
1927 | { | |
f07e9af3 | 1928 | if (tp->phy_flags & TG3_PHYFLG_IS_CONNECTED) { |
3f0e3ad7 | 1929 | phy_disconnect(tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]); |
f07e9af3 | 1930 | tp->phy_flags &= ~TG3_PHYFLG_IS_CONNECTED; |
b02fd9e3 MC |
1931 | } |
1932 | } | |
1933 | ||
941ec90f MC |
1934 | static int tg3_phy_set_extloopbk(struct tg3 *tp) |
1935 | { | |
1936 | int err; | |
1937 | u32 val; | |
1938 | ||
1939 | if (tp->phy_flags & TG3_PHYFLG_IS_FET) | |
1940 | return 0; | |
1941 | ||
1942 | if ((tp->phy_id & TG3_PHY_ID_MASK) == TG3_PHY_ID_BCM5401) { | |
1943 | /* Cannot do read-modify-write on 5401 */ | |
1944 | err = tg3_phy_auxctl_write(tp, | |
1945 | MII_TG3_AUXCTL_SHDWSEL_AUXCTL, | |
1946 | MII_TG3_AUXCTL_ACTL_EXTLOOPBK | | |
1947 | 0x4c20); | |
1948 | goto done; | |
1949 | } | |
1950 | ||
1951 | err = tg3_phy_auxctl_read(tp, | |
1952 | MII_TG3_AUXCTL_SHDWSEL_AUXCTL, &val); | |
1953 | if (err) | |
1954 | return err; | |
1955 | ||
1956 | val |= MII_TG3_AUXCTL_ACTL_EXTLOOPBK; | |
1957 | err = tg3_phy_auxctl_write(tp, | |
1958 | MII_TG3_AUXCTL_SHDWSEL_AUXCTL, val); | |
1959 | ||
1960 | done: | |
1961 | return err; | |
1962 | } | |
1963 | ||
7f97a4bd MC |
1964 | static void tg3_phy_fet_toggle_apd(struct tg3 *tp, bool enable) |
1965 | { | |
1966 | u32 phytest; | |
1967 | ||
1968 | if (!tg3_readphy(tp, MII_TG3_FET_TEST, &phytest)) { | |
1969 | u32 phy; | |
1970 | ||
1971 | tg3_writephy(tp, MII_TG3_FET_TEST, | |
1972 | phytest | MII_TG3_FET_SHADOW_EN); | |
1973 | if (!tg3_readphy(tp, MII_TG3_FET_SHDW_AUXSTAT2, &phy)) { | |
1974 | if (enable) | |
1975 | phy |= MII_TG3_FET_SHDW_AUXSTAT2_APD; | |
1976 | else | |
1977 | phy &= ~MII_TG3_FET_SHDW_AUXSTAT2_APD; | |
1978 | tg3_writephy(tp, MII_TG3_FET_SHDW_AUXSTAT2, phy); | |
1979 | } | |
1980 | tg3_writephy(tp, MII_TG3_FET_TEST, phytest); | |
1981 | } | |
1982 | } | |
1983 | ||
6833c043 MC |
1984 | static void tg3_phy_toggle_apd(struct tg3 *tp, bool enable) |
1985 | { | |
1986 | u32 reg; | |
1987 | ||
63c3a66f JP |
1988 | if (!tg3_flag(tp, 5705_PLUS) || |
1989 | (tg3_flag(tp, 5717_PLUS) && | |
f07e9af3 | 1990 | (tp->phy_flags & TG3_PHYFLG_MII_SERDES))) |
6833c043 MC |
1991 | return; |
1992 | ||
f07e9af3 | 1993 | if (tp->phy_flags & TG3_PHYFLG_IS_FET) { |
7f97a4bd MC |
1994 | tg3_phy_fet_toggle_apd(tp, enable); |
1995 | return; | |
1996 | } | |
1997 | ||
6833c043 MC |
1998 | reg = MII_TG3_MISC_SHDW_WREN | |
1999 | MII_TG3_MISC_SHDW_SCR5_SEL | | |
2000 | MII_TG3_MISC_SHDW_SCR5_LPED | | |
2001 | MII_TG3_MISC_SHDW_SCR5_DLPTLM | | |
2002 | MII_TG3_MISC_SHDW_SCR5_SDTL | | |
2003 | MII_TG3_MISC_SHDW_SCR5_C125OE; | |
2004 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5784 || !enable) | |
2005 | reg |= MII_TG3_MISC_SHDW_SCR5_DLLAPD; | |
2006 | ||
2007 | tg3_writephy(tp, MII_TG3_MISC_SHDW, reg); | |
2008 | ||
2009 | ||
2010 | reg = MII_TG3_MISC_SHDW_WREN | | |
2011 | MII_TG3_MISC_SHDW_APD_SEL | | |
2012 | MII_TG3_MISC_SHDW_APD_WKTM_84MS; | |
2013 | if (enable) | |
2014 | reg |= MII_TG3_MISC_SHDW_APD_ENABLE; | |
2015 | ||
2016 | tg3_writephy(tp, MII_TG3_MISC_SHDW, reg); | |
2017 | } | |
2018 | ||
9ef8ca99 MC |
2019 | static void tg3_phy_toggle_automdix(struct tg3 *tp, int enable) |
2020 | { | |
2021 | u32 phy; | |
2022 | ||
63c3a66f | 2023 | if (!tg3_flag(tp, 5705_PLUS) || |
f07e9af3 | 2024 | (tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) |
9ef8ca99 MC |
2025 | return; |
2026 | ||
f07e9af3 | 2027 | if (tp->phy_flags & TG3_PHYFLG_IS_FET) { |
9ef8ca99 MC |
2028 | u32 ephy; |
2029 | ||
535ef6e1 MC |
2030 | if (!tg3_readphy(tp, MII_TG3_FET_TEST, &ephy)) { |
2031 | u32 reg = MII_TG3_FET_SHDW_MISCCTRL; | |
2032 | ||
2033 | tg3_writephy(tp, MII_TG3_FET_TEST, | |
2034 | ephy | MII_TG3_FET_SHADOW_EN); | |
2035 | if (!tg3_readphy(tp, reg, &phy)) { | |
9ef8ca99 | 2036 | if (enable) |
535ef6e1 | 2037 | phy |= MII_TG3_FET_SHDW_MISCCTRL_MDIX; |
9ef8ca99 | 2038 | else |
535ef6e1 MC |
2039 | phy &= ~MII_TG3_FET_SHDW_MISCCTRL_MDIX; |
2040 | tg3_writephy(tp, reg, phy); | |
9ef8ca99 | 2041 | } |
535ef6e1 | 2042 | tg3_writephy(tp, MII_TG3_FET_TEST, ephy); |
9ef8ca99 MC |
2043 | } |
2044 | } else { | |
15ee95c3 MC |
2045 | int ret; |
2046 | ||
2047 | ret = tg3_phy_auxctl_read(tp, | |
2048 | MII_TG3_AUXCTL_SHDWSEL_MISC, &phy); | |
2049 | if (!ret) { | |
9ef8ca99 MC |
2050 | if (enable) |
2051 | phy |= MII_TG3_AUXCTL_MISC_FORCE_AMDIX; | |
2052 | else | |
2053 | phy &= ~MII_TG3_AUXCTL_MISC_FORCE_AMDIX; | |
b4bd2929 MC |
2054 | tg3_phy_auxctl_write(tp, |
2055 | MII_TG3_AUXCTL_SHDWSEL_MISC, phy); | |
9ef8ca99 MC |
2056 | } |
2057 | } | |
2058 | } | |
2059 | ||
1da177e4 LT |
2060 | static void tg3_phy_set_wirespeed(struct tg3 *tp) |
2061 | { | |
15ee95c3 | 2062 | int ret; |
1da177e4 LT |
2063 | u32 val; |
2064 | ||
f07e9af3 | 2065 | if (tp->phy_flags & TG3_PHYFLG_NO_ETH_WIRE_SPEED) |
1da177e4 LT |
2066 | return; |
2067 | ||
15ee95c3 MC |
2068 | ret = tg3_phy_auxctl_read(tp, MII_TG3_AUXCTL_SHDWSEL_MISC, &val); |
2069 | if (!ret) | |
b4bd2929 MC |
2070 | tg3_phy_auxctl_write(tp, MII_TG3_AUXCTL_SHDWSEL_MISC, |
2071 | val | MII_TG3_AUXCTL_MISC_WIRESPD_EN); | |
1da177e4 LT |
2072 | } |
2073 | ||
b2a5c19c MC |
2074 | static void tg3_phy_apply_otp(struct tg3 *tp) |
2075 | { | |
2076 | u32 otp, phy; | |
2077 | ||
2078 | if (!tp->phy_otp) | |
2079 | return; | |
2080 | ||
2081 | otp = tp->phy_otp; | |
2082 | ||
1d36ba45 MC |
2083 | if (TG3_PHY_AUXCTL_SMDSP_ENABLE(tp)) |
2084 | return; | |
b2a5c19c MC |
2085 | |
2086 | phy = ((otp & TG3_OTP_AGCTGT_MASK) >> TG3_OTP_AGCTGT_SHIFT); | |
2087 | phy |= MII_TG3_DSP_TAP1_AGCTGT_DFLT; | |
2088 | tg3_phydsp_write(tp, MII_TG3_DSP_TAP1, phy); | |
2089 | ||
2090 | phy = ((otp & TG3_OTP_HPFFLTR_MASK) >> TG3_OTP_HPFFLTR_SHIFT) | | |
2091 | ((otp & TG3_OTP_HPFOVER_MASK) >> TG3_OTP_HPFOVER_SHIFT); | |
2092 | tg3_phydsp_write(tp, MII_TG3_DSP_AADJ1CH0, phy); | |
2093 | ||
2094 | phy = ((otp & TG3_OTP_LPFDIS_MASK) >> TG3_OTP_LPFDIS_SHIFT); | |
2095 | phy |= MII_TG3_DSP_AADJ1CH3_ADCCKADJ; | |
2096 | tg3_phydsp_write(tp, MII_TG3_DSP_AADJ1CH3, phy); | |
2097 | ||
2098 | phy = ((otp & TG3_OTP_VDAC_MASK) >> TG3_OTP_VDAC_SHIFT); | |
2099 | tg3_phydsp_write(tp, MII_TG3_DSP_EXP75, phy); | |
2100 | ||
2101 | phy = ((otp & TG3_OTP_10BTAMP_MASK) >> TG3_OTP_10BTAMP_SHIFT); | |
2102 | tg3_phydsp_write(tp, MII_TG3_DSP_EXP96, phy); | |
2103 | ||
2104 | phy = ((otp & TG3_OTP_ROFF_MASK) >> TG3_OTP_ROFF_SHIFT) | | |
2105 | ((otp & TG3_OTP_RCOFF_MASK) >> TG3_OTP_RCOFF_SHIFT); | |
2106 | tg3_phydsp_write(tp, MII_TG3_DSP_EXP97, phy); | |
2107 | ||
1d36ba45 | 2108 | TG3_PHY_AUXCTL_SMDSP_DISABLE(tp); |
b2a5c19c MC |
2109 | } |
2110 | ||
52b02d04 MC |
2111 | static void tg3_phy_eee_adjust(struct tg3 *tp, u32 current_link_up) |
2112 | { | |
2113 | u32 val; | |
2114 | ||
2115 | if (!(tp->phy_flags & TG3_PHYFLG_EEE_CAP)) | |
2116 | return; | |
2117 | ||
2118 | tp->setlpicnt = 0; | |
2119 | ||
2120 | if (tp->link_config.autoneg == AUTONEG_ENABLE && | |
2121 | current_link_up == 1 && | |
a6b68dab MC |
2122 | tp->link_config.active_duplex == DUPLEX_FULL && |
2123 | (tp->link_config.active_speed == SPEED_100 || | |
2124 | tp->link_config.active_speed == SPEED_1000)) { | |
52b02d04 MC |
2125 | u32 eeectl; |
2126 | ||
2127 | if (tp->link_config.active_speed == SPEED_1000) | |
2128 | eeectl = TG3_CPMU_EEE_CTRL_EXIT_16_5_US; | |
2129 | else | |
2130 | eeectl = TG3_CPMU_EEE_CTRL_EXIT_36_US; | |
2131 | ||
2132 | tw32(TG3_CPMU_EEE_CTRL, eeectl); | |
2133 | ||
3110f5f5 MC |
2134 | tg3_phy_cl45_read(tp, MDIO_MMD_AN, |
2135 | TG3_CL45_D7_EEERES_STAT, &val); | |
52b02d04 | 2136 | |
b0c5943f MC |
2137 | if (val == TG3_CL45_D7_EEERES_STAT_LP_1000T || |
2138 | val == TG3_CL45_D7_EEERES_STAT_LP_100TX) | |
52b02d04 MC |
2139 | tp->setlpicnt = 2; |
2140 | } | |
2141 | ||
2142 | if (!tp->setlpicnt) { | |
b715ce94 MC |
2143 | if (current_link_up == 1 && |
2144 | !TG3_PHY_AUXCTL_SMDSP_ENABLE(tp)) { | |
2145 | tg3_phydsp_write(tp, MII_TG3_DSP_TAP26, 0x0000); | |
2146 | TG3_PHY_AUXCTL_SMDSP_DISABLE(tp); | |
2147 | } | |
2148 | ||
52b02d04 MC |
2149 | val = tr32(TG3_CPMU_EEE_MODE); |
2150 | tw32(TG3_CPMU_EEE_MODE, val & ~TG3_CPMU_EEEMD_LPI_ENABLE); | |
2151 | } | |
2152 | } | |
2153 | ||
b0c5943f MC |
2154 | static void tg3_phy_eee_enable(struct tg3 *tp) |
2155 | { | |
2156 | u32 val; | |
2157 | ||
2158 | if (tp->link_config.active_speed == SPEED_1000 && | |
2159 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || | |
2160 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719 || | |
2161 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) && | |
2162 | !TG3_PHY_AUXCTL_SMDSP_ENABLE(tp)) { | |
b715ce94 MC |
2163 | val = MII_TG3_DSP_TAP26_ALNOKO | |
2164 | MII_TG3_DSP_TAP26_RMRXSTO; | |
2165 | tg3_phydsp_write(tp, MII_TG3_DSP_TAP26, val); | |
b0c5943f MC |
2166 | TG3_PHY_AUXCTL_SMDSP_DISABLE(tp); |
2167 | } | |
2168 | ||
2169 | val = tr32(TG3_CPMU_EEE_MODE); | |
2170 | tw32(TG3_CPMU_EEE_MODE, val | TG3_CPMU_EEEMD_LPI_ENABLE); | |
2171 | } | |
2172 | ||
1da177e4 LT |
2173 | static int tg3_wait_macro_done(struct tg3 *tp) |
2174 | { | |
2175 | int limit = 100; | |
2176 | ||
2177 | while (limit--) { | |
2178 | u32 tmp32; | |
2179 | ||
f08aa1a8 | 2180 | if (!tg3_readphy(tp, MII_TG3_DSP_CONTROL, &tmp32)) { |
1da177e4 LT |
2181 | if ((tmp32 & 0x1000) == 0) |
2182 | break; | |
2183 | } | |
2184 | } | |
d4675b52 | 2185 | if (limit < 0) |
1da177e4 LT |
2186 | return -EBUSY; |
2187 | ||
2188 | return 0; | |
2189 | } | |
2190 | ||
2191 | static int tg3_phy_write_and_check_testpat(struct tg3 *tp, int *resetp) | |
2192 | { | |
2193 | static const u32 test_pat[4][6] = { | |
2194 | { 0x00005555, 0x00000005, 0x00002aaa, 0x0000000a, 0x00003456, 0x00000003 }, | |
2195 | { 0x00002aaa, 0x0000000a, 0x00003333, 0x00000003, 0x0000789a, 0x00000005 }, | |
2196 | { 0x00005a5a, 0x00000005, 0x00002a6a, 0x0000000a, 0x00001bcd, 0x00000003 }, | |
2197 | { 0x00002a5a, 0x0000000a, 0x000033c3, 0x00000003, 0x00002ef1, 0x00000005 } | |
2198 | }; | |
2199 | int chan; | |
2200 | ||
2201 | for (chan = 0; chan < 4; chan++) { | |
2202 | int i; | |
2203 | ||
2204 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, | |
2205 | (chan * 0x2000) | 0x0200); | |
f08aa1a8 | 2206 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0002); |
1da177e4 LT |
2207 | |
2208 | for (i = 0; i < 6; i++) | |
2209 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, | |
2210 | test_pat[chan][i]); | |
2211 | ||
f08aa1a8 | 2212 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0202); |
1da177e4 LT |
2213 | if (tg3_wait_macro_done(tp)) { |
2214 | *resetp = 1; | |
2215 | return -EBUSY; | |
2216 | } | |
2217 | ||
2218 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, | |
2219 | (chan * 0x2000) | 0x0200); | |
f08aa1a8 | 2220 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0082); |
1da177e4 LT |
2221 | if (tg3_wait_macro_done(tp)) { |
2222 | *resetp = 1; | |
2223 | return -EBUSY; | |
2224 | } | |
2225 | ||
f08aa1a8 | 2226 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0802); |
1da177e4 LT |
2227 | if (tg3_wait_macro_done(tp)) { |
2228 | *resetp = 1; | |
2229 | return -EBUSY; | |
2230 | } | |
2231 | ||
2232 | for (i = 0; i < 6; i += 2) { | |
2233 | u32 low, high; | |
2234 | ||
2235 | if (tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &low) || | |
2236 | tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &high) || | |
2237 | tg3_wait_macro_done(tp)) { | |
2238 | *resetp = 1; | |
2239 | return -EBUSY; | |
2240 | } | |
2241 | low &= 0x7fff; | |
2242 | high &= 0x000f; | |
2243 | if (low != test_pat[chan][i] || | |
2244 | high != test_pat[chan][i+1]) { | |
2245 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000b); | |
2246 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x4001); | |
2247 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x4005); | |
2248 | ||
2249 | return -EBUSY; | |
2250 | } | |
2251 | } | |
2252 | } | |
2253 | ||
2254 | return 0; | |
2255 | } | |
2256 | ||
2257 | static int tg3_phy_reset_chanpat(struct tg3 *tp) | |
2258 | { | |
2259 | int chan; | |
2260 | ||
2261 | for (chan = 0; chan < 4; chan++) { | |
2262 | int i; | |
2263 | ||
2264 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, | |
2265 | (chan * 0x2000) | 0x0200); | |
f08aa1a8 | 2266 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0002); |
1da177e4 LT |
2267 | for (i = 0; i < 6; i++) |
2268 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x000); | |
f08aa1a8 | 2269 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0202); |
1da177e4 LT |
2270 | if (tg3_wait_macro_done(tp)) |
2271 | return -EBUSY; | |
2272 | } | |
2273 | ||
2274 | return 0; | |
2275 | } | |
2276 | ||
2277 | static int tg3_phy_reset_5703_4_5(struct tg3 *tp) | |
2278 | { | |
2279 | u32 reg32, phy9_orig; | |
2280 | int retries, do_phy_reset, err; | |
2281 | ||
2282 | retries = 10; | |
2283 | do_phy_reset = 1; | |
2284 | do { | |
2285 | if (do_phy_reset) { | |
2286 | err = tg3_bmcr_reset(tp); | |
2287 | if (err) | |
2288 | return err; | |
2289 | do_phy_reset = 0; | |
2290 | } | |
2291 | ||
2292 | /* Disable transmitter and interrupt. */ | |
2293 | if (tg3_readphy(tp, MII_TG3_EXT_CTRL, ®32)) | |
2294 | continue; | |
2295 | ||
2296 | reg32 |= 0x3000; | |
2297 | tg3_writephy(tp, MII_TG3_EXT_CTRL, reg32); | |
2298 | ||
2299 | /* Set full-duplex, 1000 mbps. */ | |
2300 | tg3_writephy(tp, MII_BMCR, | |
221c5637 | 2301 | BMCR_FULLDPLX | BMCR_SPEED1000); |
1da177e4 LT |
2302 | |
2303 | /* Set to master mode. */ | |
221c5637 | 2304 | if (tg3_readphy(tp, MII_CTRL1000, &phy9_orig)) |
1da177e4 LT |
2305 | continue; |
2306 | ||
221c5637 MC |
2307 | tg3_writephy(tp, MII_CTRL1000, |
2308 | CTL1000_AS_MASTER | CTL1000_ENABLE_MASTER); | |
1da177e4 | 2309 | |
1d36ba45 MC |
2310 | err = TG3_PHY_AUXCTL_SMDSP_ENABLE(tp); |
2311 | if (err) | |
2312 | return err; | |
1da177e4 LT |
2313 | |
2314 | /* Block the PHY control access. */ | |
6ee7c0a0 | 2315 | tg3_phydsp_write(tp, 0x8005, 0x0800); |
1da177e4 LT |
2316 | |
2317 | err = tg3_phy_write_and_check_testpat(tp, &do_phy_reset); | |
2318 | if (!err) | |
2319 | break; | |
2320 | } while (--retries); | |
2321 | ||
2322 | err = tg3_phy_reset_chanpat(tp); | |
2323 | if (err) | |
2324 | return err; | |
2325 | ||
6ee7c0a0 | 2326 | tg3_phydsp_write(tp, 0x8005, 0x0000); |
1da177e4 LT |
2327 | |
2328 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8200); | |
f08aa1a8 | 2329 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0000); |
1da177e4 | 2330 | |
1d36ba45 | 2331 | TG3_PHY_AUXCTL_SMDSP_DISABLE(tp); |
1da177e4 | 2332 | |
221c5637 | 2333 | tg3_writephy(tp, MII_CTRL1000, phy9_orig); |
1da177e4 LT |
2334 | |
2335 | if (!tg3_readphy(tp, MII_TG3_EXT_CTRL, ®32)) { | |
2336 | reg32 &= ~0x3000; | |
2337 | tg3_writephy(tp, MII_TG3_EXT_CTRL, reg32); | |
2338 | } else if (!err) | |
2339 | err = -EBUSY; | |
2340 | ||
2341 | return err; | |
2342 | } | |
2343 | ||
2344 | /* This will reset the tigon3 PHY if there is no valid | |
2345 | * link unless the FORCE argument is non-zero. | |
2346 | */ | |
2347 | static int tg3_phy_reset(struct tg3 *tp) | |
2348 | { | |
f833c4c1 | 2349 | u32 val, cpmuctrl; |
1da177e4 LT |
2350 | int err; |
2351 | ||
60189ddf | 2352 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
60189ddf MC |
2353 | val = tr32(GRC_MISC_CFG); |
2354 | tw32_f(GRC_MISC_CFG, val & ~GRC_MISC_CFG_EPHY_IDDQ); | |
2355 | udelay(40); | |
2356 | } | |
f833c4c1 MC |
2357 | err = tg3_readphy(tp, MII_BMSR, &val); |
2358 | err |= tg3_readphy(tp, MII_BMSR, &val); | |
1da177e4 LT |
2359 | if (err != 0) |
2360 | return -EBUSY; | |
2361 | ||
c8e1e82b MC |
2362 | if (netif_running(tp->dev) && netif_carrier_ok(tp->dev)) { |
2363 | netif_carrier_off(tp->dev); | |
2364 | tg3_link_report(tp); | |
2365 | } | |
2366 | ||
1da177e4 LT |
2367 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 || |
2368 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 || | |
2369 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) { | |
2370 | err = tg3_phy_reset_5703_4_5(tp); | |
2371 | if (err) | |
2372 | return err; | |
2373 | goto out; | |
2374 | } | |
2375 | ||
b2a5c19c MC |
2376 | cpmuctrl = 0; |
2377 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 && | |
2378 | GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5784_AX) { | |
2379 | cpmuctrl = tr32(TG3_CPMU_CTRL); | |
2380 | if (cpmuctrl & CPMU_CTRL_GPHY_10MB_RXONLY) | |
2381 | tw32(TG3_CPMU_CTRL, | |
2382 | cpmuctrl & ~CPMU_CTRL_GPHY_10MB_RXONLY); | |
2383 | } | |
2384 | ||
1da177e4 LT |
2385 | err = tg3_bmcr_reset(tp); |
2386 | if (err) | |
2387 | return err; | |
2388 | ||
b2a5c19c | 2389 | if (cpmuctrl & CPMU_CTRL_GPHY_10MB_RXONLY) { |
f833c4c1 MC |
2390 | val = MII_TG3_DSP_EXP8_AEDW | MII_TG3_DSP_EXP8_REJ2MHz; |
2391 | tg3_phydsp_write(tp, MII_TG3_DSP_EXP8, val); | |
b2a5c19c MC |
2392 | |
2393 | tw32(TG3_CPMU_CTRL, cpmuctrl); | |
2394 | } | |
2395 | ||
bcb37f6c MC |
2396 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5784_AX || |
2397 | GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5761_AX) { | |
ce057f01 MC |
2398 | val = tr32(TG3_CPMU_LSPD_1000MB_CLK); |
2399 | if ((val & CPMU_LSPD_1000MB_MACCLK_MASK) == | |
2400 | CPMU_LSPD_1000MB_MACCLK_12_5) { | |
2401 | val &= ~CPMU_LSPD_1000MB_MACCLK_MASK; | |
2402 | udelay(40); | |
2403 | tw32_f(TG3_CPMU_LSPD_1000MB_CLK, val); | |
2404 | } | |
2405 | } | |
2406 | ||
63c3a66f | 2407 | if (tg3_flag(tp, 5717_PLUS) && |
f07e9af3 | 2408 | (tp->phy_flags & TG3_PHYFLG_MII_SERDES)) |
ecf1410b MC |
2409 | return 0; |
2410 | ||
b2a5c19c MC |
2411 | tg3_phy_apply_otp(tp); |
2412 | ||
f07e9af3 | 2413 | if (tp->phy_flags & TG3_PHYFLG_ENABLE_APD) |
6833c043 MC |
2414 | tg3_phy_toggle_apd(tp, true); |
2415 | else | |
2416 | tg3_phy_toggle_apd(tp, false); | |
2417 | ||
1da177e4 | 2418 | out: |
1d36ba45 MC |
2419 | if ((tp->phy_flags & TG3_PHYFLG_ADC_BUG) && |
2420 | !TG3_PHY_AUXCTL_SMDSP_ENABLE(tp)) { | |
6ee7c0a0 MC |
2421 | tg3_phydsp_write(tp, 0x201f, 0x2aaa); |
2422 | tg3_phydsp_write(tp, 0x000a, 0x0323); | |
1d36ba45 | 2423 | TG3_PHY_AUXCTL_SMDSP_DISABLE(tp); |
1da177e4 | 2424 | } |
1d36ba45 | 2425 | |
f07e9af3 | 2426 | if (tp->phy_flags & TG3_PHYFLG_5704_A0_BUG) { |
f08aa1a8 MC |
2427 | tg3_writephy(tp, MII_TG3_MISC_SHDW, 0x8d68); |
2428 | tg3_writephy(tp, MII_TG3_MISC_SHDW, 0x8d68); | |
1da177e4 | 2429 | } |
1d36ba45 | 2430 | |
f07e9af3 | 2431 | if (tp->phy_flags & TG3_PHYFLG_BER_BUG) { |
1d36ba45 MC |
2432 | if (!TG3_PHY_AUXCTL_SMDSP_ENABLE(tp)) { |
2433 | tg3_phydsp_write(tp, 0x000a, 0x310b); | |
2434 | tg3_phydsp_write(tp, 0x201f, 0x9506); | |
2435 | tg3_phydsp_write(tp, 0x401f, 0x14e2); | |
2436 | TG3_PHY_AUXCTL_SMDSP_DISABLE(tp); | |
2437 | } | |
f07e9af3 | 2438 | } else if (tp->phy_flags & TG3_PHYFLG_JITTER_BUG) { |
1d36ba45 MC |
2439 | if (!TG3_PHY_AUXCTL_SMDSP_ENABLE(tp)) { |
2440 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000a); | |
2441 | if (tp->phy_flags & TG3_PHYFLG_ADJUST_TRIM) { | |
2442 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x110b); | |
2443 | tg3_writephy(tp, MII_TG3_TEST1, | |
2444 | MII_TG3_TEST1_TRIM_EN | 0x4); | |
2445 | } else | |
2446 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x010b); | |
2447 | ||
2448 | TG3_PHY_AUXCTL_SMDSP_DISABLE(tp); | |
2449 | } | |
c424cb24 | 2450 | } |
1d36ba45 | 2451 | |
1da177e4 LT |
2452 | /* Set Extended packet length bit (bit 14) on all chips that */ |
2453 | /* support jumbo frames */ | |
79eb6904 | 2454 | if ((tp->phy_id & TG3_PHY_ID_MASK) == TG3_PHY_ID_BCM5401) { |
1da177e4 | 2455 | /* Cannot do read-modify-write on 5401 */ |
b4bd2929 | 2456 | tg3_phy_auxctl_write(tp, MII_TG3_AUXCTL_SHDWSEL_AUXCTL, 0x4c20); |
63c3a66f | 2457 | } else if (tg3_flag(tp, JUMBO_CAPABLE)) { |
1da177e4 | 2458 | /* Set bit 14 with read-modify-write to preserve other bits */ |
15ee95c3 MC |
2459 | err = tg3_phy_auxctl_read(tp, |
2460 | MII_TG3_AUXCTL_SHDWSEL_AUXCTL, &val); | |
2461 | if (!err) | |
b4bd2929 MC |
2462 | tg3_phy_auxctl_write(tp, MII_TG3_AUXCTL_SHDWSEL_AUXCTL, |
2463 | val | MII_TG3_AUXCTL_ACTL_EXTPKTLEN); | |
1da177e4 LT |
2464 | } |
2465 | ||
2466 | /* Set phy register 0x10 bit 0 to high fifo elasticity to support | |
2467 | * jumbo frames transmission. | |
2468 | */ | |
63c3a66f | 2469 | if (tg3_flag(tp, JUMBO_CAPABLE)) { |
f833c4c1 | 2470 | if (!tg3_readphy(tp, MII_TG3_EXT_CTRL, &val)) |
c6cdf436 | 2471 | tg3_writephy(tp, MII_TG3_EXT_CTRL, |
f833c4c1 | 2472 | val | MII_TG3_EXT_CTRL_FIFO_ELASTIC); |
1da177e4 LT |
2473 | } |
2474 | ||
715116a1 | 2475 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
715116a1 | 2476 | /* adjust output voltage */ |
535ef6e1 | 2477 | tg3_writephy(tp, MII_TG3_FET_PTEST, 0x12); |
715116a1 MC |
2478 | } |
2479 | ||
9ef8ca99 | 2480 | tg3_phy_toggle_automdix(tp, 1); |
1da177e4 LT |
2481 | tg3_phy_set_wirespeed(tp); |
2482 | return 0; | |
2483 | } | |
2484 | ||
3a1e19d3 MC |
2485 | #define TG3_GPIO_MSG_DRVR_PRES 0x00000001 |
2486 | #define TG3_GPIO_MSG_NEED_VAUX 0x00000002 | |
2487 | #define TG3_GPIO_MSG_MASK (TG3_GPIO_MSG_DRVR_PRES | \ | |
2488 | TG3_GPIO_MSG_NEED_VAUX) | |
2489 | #define TG3_GPIO_MSG_ALL_DRVR_PRES_MASK \ | |
2490 | ((TG3_GPIO_MSG_DRVR_PRES << 0) | \ | |
2491 | (TG3_GPIO_MSG_DRVR_PRES << 4) | \ | |
2492 | (TG3_GPIO_MSG_DRVR_PRES << 8) | \ | |
2493 | (TG3_GPIO_MSG_DRVR_PRES << 12)) | |
2494 | ||
2495 | #define TG3_GPIO_MSG_ALL_NEED_VAUX_MASK \ | |
2496 | ((TG3_GPIO_MSG_NEED_VAUX << 0) | \ | |
2497 | (TG3_GPIO_MSG_NEED_VAUX << 4) | \ | |
2498 | (TG3_GPIO_MSG_NEED_VAUX << 8) | \ | |
2499 | (TG3_GPIO_MSG_NEED_VAUX << 12)) | |
2500 | ||
2501 | static inline u32 tg3_set_function_status(struct tg3 *tp, u32 newstat) | |
2502 | { | |
2503 | u32 status, shift; | |
2504 | ||
2505 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || | |
2506 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719) | |
2507 | status = tg3_ape_read32(tp, TG3_APE_GPIO_MSG); | |
2508 | else | |
2509 | status = tr32(TG3_CPMU_DRV_STATUS); | |
2510 | ||
2511 | shift = TG3_APE_GPIO_MSG_SHIFT + 4 * tp->pci_fn; | |
2512 | status &= ~(TG3_GPIO_MSG_MASK << shift); | |
2513 | status |= (newstat << shift); | |
2514 | ||
2515 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || | |
2516 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719) | |
2517 | tg3_ape_write32(tp, TG3_APE_GPIO_MSG, status); | |
2518 | else | |
2519 | tw32(TG3_CPMU_DRV_STATUS, status); | |
2520 | ||
2521 | return status >> TG3_APE_GPIO_MSG_SHIFT; | |
2522 | } | |
2523 | ||
520b2756 MC |
2524 | static inline int tg3_pwrsrc_switch_to_vmain(struct tg3 *tp) |
2525 | { | |
2526 | if (!tg3_flag(tp, IS_NIC)) | |
2527 | return 0; | |
2528 | ||
3a1e19d3 MC |
2529 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
2530 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719 || | |
2531 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) { | |
2532 | if (tg3_ape_lock(tp, TG3_APE_LOCK_GPIO)) | |
2533 | return -EIO; | |
520b2756 | 2534 | |
3a1e19d3 MC |
2535 | tg3_set_function_status(tp, TG3_GPIO_MSG_DRVR_PRES); |
2536 | ||
2537 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl, | |
2538 | TG3_GRC_LCLCTL_PWRSW_DELAY); | |
2539 | ||
2540 | tg3_ape_unlock(tp, TG3_APE_LOCK_GPIO); | |
2541 | } else { | |
2542 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl, | |
2543 | TG3_GRC_LCLCTL_PWRSW_DELAY); | |
2544 | } | |
6f5c8f83 | 2545 | |
520b2756 MC |
2546 | return 0; |
2547 | } | |
2548 | ||
2549 | static void tg3_pwrsrc_die_with_vmain(struct tg3 *tp) | |
2550 | { | |
2551 | u32 grc_local_ctrl; | |
2552 | ||
2553 | if (!tg3_flag(tp, IS_NIC) || | |
2554 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || | |
2555 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) | |
2556 | return; | |
2557 | ||
2558 | grc_local_ctrl = tp->grc_local_ctrl | GRC_LCLCTRL_GPIO_OE1; | |
2559 | ||
2560 | tw32_wait_f(GRC_LOCAL_CTRL, | |
2561 | grc_local_ctrl | GRC_LCLCTRL_GPIO_OUTPUT1, | |
2562 | TG3_GRC_LCLCTL_PWRSW_DELAY); | |
2563 | ||
2564 | tw32_wait_f(GRC_LOCAL_CTRL, | |
2565 | grc_local_ctrl, | |
2566 | TG3_GRC_LCLCTL_PWRSW_DELAY); | |
2567 | ||
2568 | tw32_wait_f(GRC_LOCAL_CTRL, | |
2569 | grc_local_ctrl | GRC_LCLCTRL_GPIO_OUTPUT1, | |
2570 | TG3_GRC_LCLCTL_PWRSW_DELAY); | |
2571 | } | |
2572 | ||
2573 | static void tg3_pwrsrc_switch_to_vaux(struct tg3 *tp) | |
2574 | { | |
2575 | if (!tg3_flag(tp, IS_NIC)) | |
2576 | return; | |
2577 | ||
2578 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || | |
2579 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) { | |
2580 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl | | |
2581 | (GRC_LCLCTRL_GPIO_OE0 | | |
2582 | GRC_LCLCTRL_GPIO_OE1 | | |
2583 | GRC_LCLCTRL_GPIO_OE2 | | |
2584 | GRC_LCLCTRL_GPIO_OUTPUT0 | | |
2585 | GRC_LCLCTRL_GPIO_OUTPUT1), | |
2586 | TG3_GRC_LCLCTL_PWRSW_DELAY); | |
2587 | } else if (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5761 || | |
2588 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5761S) { | |
2589 | /* The 5761 non-e device swaps GPIO 0 and GPIO 2. */ | |
2590 | u32 grc_local_ctrl = GRC_LCLCTRL_GPIO_OE0 | | |
2591 | GRC_LCLCTRL_GPIO_OE1 | | |
2592 | GRC_LCLCTRL_GPIO_OE2 | | |
2593 | GRC_LCLCTRL_GPIO_OUTPUT0 | | |
2594 | GRC_LCLCTRL_GPIO_OUTPUT1 | | |
2595 | tp->grc_local_ctrl; | |
2596 | tw32_wait_f(GRC_LOCAL_CTRL, grc_local_ctrl, | |
2597 | TG3_GRC_LCLCTL_PWRSW_DELAY); | |
2598 | ||
2599 | grc_local_ctrl |= GRC_LCLCTRL_GPIO_OUTPUT2; | |
2600 | tw32_wait_f(GRC_LOCAL_CTRL, grc_local_ctrl, | |
2601 | TG3_GRC_LCLCTL_PWRSW_DELAY); | |
2602 | ||
2603 | grc_local_ctrl &= ~GRC_LCLCTRL_GPIO_OUTPUT0; | |
2604 | tw32_wait_f(GRC_LOCAL_CTRL, grc_local_ctrl, | |
2605 | TG3_GRC_LCLCTL_PWRSW_DELAY); | |
2606 | } else { | |
2607 | u32 no_gpio2; | |
2608 | u32 grc_local_ctrl = 0; | |
2609 | ||
2610 | /* Workaround to prevent overdrawing Amps. */ | |
2611 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) { | |
2612 | grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE3; | |
2613 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl | | |
2614 | grc_local_ctrl, | |
2615 | TG3_GRC_LCLCTL_PWRSW_DELAY); | |
2616 | } | |
2617 | ||
2618 | /* On 5753 and variants, GPIO2 cannot be used. */ | |
2619 | no_gpio2 = tp->nic_sram_data_cfg & | |
2620 | NIC_SRAM_DATA_CFG_NO_GPIO2; | |
2621 | ||
2622 | grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE0 | | |
2623 | GRC_LCLCTRL_GPIO_OE1 | | |
2624 | GRC_LCLCTRL_GPIO_OE2 | | |
2625 | GRC_LCLCTRL_GPIO_OUTPUT1 | | |
2626 | GRC_LCLCTRL_GPIO_OUTPUT2; | |
2627 | if (no_gpio2) { | |
2628 | grc_local_ctrl &= ~(GRC_LCLCTRL_GPIO_OE2 | | |
2629 | GRC_LCLCTRL_GPIO_OUTPUT2); | |
2630 | } | |
2631 | tw32_wait_f(GRC_LOCAL_CTRL, | |
2632 | tp->grc_local_ctrl | grc_local_ctrl, | |
2633 | TG3_GRC_LCLCTL_PWRSW_DELAY); | |
2634 | ||
2635 | grc_local_ctrl |= GRC_LCLCTRL_GPIO_OUTPUT0; | |
2636 | ||
2637 | tw32_wait_f(GRC_LOCAL_CTRL, | |
2638 | tp->grc_local_ctrl | grc_local_ctrl, | |
2639 | TG3_GRC_LCLCTL_PWRSW_DELAY); | |
2640 | ||
2641 | if (!no_gpio2) { | |
2642 | grc_local_ctrl &= ~GRC_LCLCTRL_GPIO_OUTPUT2; | |
2643 | tw32_wait_f(GRC_LOCAL_CTRL, | |
2644 | tp->grc_local_ctrl | grc_local_ctrl, | |
2645 | TG3_GRC_LCLCTL_PWRSW_DELAY); | |
2646 | } | |
2647 | } | |
3a1e19d3 MC |
2648 | } |
2649 | ||
cd0d7228 | 2650 | static void tg3_frob_aux_power_5717(struct tg3 *tp, bool wol_enable) |
3a1e19d3 MC |
2651 | { |
2652 | u32 msg = 0; | |
2653 | ||
2654 | /* Serialize power state transitions */ | |
2655 | if (tg3_ape_lock(tp, TG3_APE_LOCK_GPIO)) | |
2656 | return; | |
2657 | ||
cd0d7228 | 2658 | if (tg3_flag(tp, ENABLE_ASF) || tg3_flag(tp, ENABLE_APE) || wol_enable) |
3a1e19d3 MC |
2659 | msg = TG3_GPIO_MSG_NEED_VAUX; |
2660 | ||
2661 | msg = tg3_set_function_status(tp, msg); | |
2662 | ||
2663 | if (msg & TG3_GPIO_MSG_ALL_DRVR_PRES_MASK) | |
2664 | goto done; | |
6f5c8f83 | 2665 | |
3a1e19d3 MC |
2666 | if (msg & TG3_GPIO_MSG_ALL_NEED_VAUX_MASK) |
2667 | tg3_pwrsrc_switch_to_vaux(tp); | |
2668 | else | |
2669 | tg3_pwrsrc_die_with_vmain(tp); | |
2670 | ||
2671 | done: | |
6f5c8f83 | 2672 | tg3_ape_unlock(tp, TG3_APE_LOCK_GPIO); |
520b2756 MC |
2673 | } |
2674 | ||
cd0d7228 | 2675 | static void tg3_frob_aux_power(struct tg3 *tp, bool include_wol) |
1da177e4 | 2676 | { |
683644b7 | 2677 | bool need_vaux = false; |
1da177e4 | 2678 | |
334355aa | 2679 | /* The GPIOs do something completely different on 57765. */ |
63c3a66f | 2680 | if (!tg3_flag(tp, IS_NIC) || |
334355aa | 2681 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) |
1da177e4 LT |
2682 | return; |
2683 | ||
3a1e19d3 MC |
2684 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
2685 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719 || | |
2686 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) { | |
cd0d7228 MC |
2687 | tg3_frob_aux_power_5717(tp, include_wol ? |
2688 | tg3_flag(tp, WOL_ENABLE) != 0 : 0); | |
3a1e19d3 MC |
2689 | return; |
2690 | } | |
2691 | ||
2692 | if (tp->pdev_peer && tp->pdev_peer != tp->pdev) { | |
8c2dc7e1 MC |
2693 | struct net_device *dev_peer; |
2694 | ||
2695 | dev_peer = pci_get_drvdata(tp->pdev_peer); | |
683644b7 | 2696 | |
bc1c7567 | 2697 | /* remove_one() may have been run on the peer. */ |
683644b7 MC |
2698 | if (dev_peer) { |
2699 | struct tg3 *tp_peer = netdev_priv(dev_peer); | |
2700 | ||
63c3a66f | 2701 | if (tg3_flag(tp_peer, INIT_COMPLETE)) |
683644b7 MC |
2702 | return; |
2703 | ||
cd0d7228 | 2704 | if ((include_wol && tg3_flag(tp_peer, WOL_ENABLE)) || |
63c3a66f | 2705 | tg3_flag(tp_peer, ENABLE_ASF)) |
683644b7 MC |
2706 | need_vaux = true; |
2707 | } | |
1da177e4 LT |
2708 | } |
2709 | ||
cd0d7228 MC |
2710 | if ((include_wol && tg3_flag(tp, WOL_ENABLE)) || |
2711 | tg3_flag(tp, ENABLE_ASF)) | |
683644b7 MC |
2712 | need_vaux = true; |
2713 | ||
520b2756 MC |
2714 | if (need_vaux) |
2715 | tg3_pwrsrc_switch_to_vaux(tp); | |
2716 | else | |
2717 | tg3_pwrsrc_die_with_vmain(tp); | |
1da177e4 LT |
2718 | } |
2719 | ||
e8f3f6ca MC |
2720 | static int tg3_5700_link_polarity(struct tg3 *tp, u32 speed) |
2721 | { | |
2722 | if (tp->led_ctrl == LED_CTRL_MODE_PHY_2) | |
2723 | return 1; | |
79eb6904 | 2724 | else if ((tp->phy_id & TG3_PHY_ID_MASK) == TG3_PHY_ID_BCM5411) { |
e8f3f6ca MC |
2725 | if (speed != SPEED_10) |
2726 | return 1; | |
2727 | } else if (speed == SPEED_10) | |
2728 | return 1; | |
2729 | ||
2730 | return 0; | |
2731 | } | |
2732 | ||
1da177e4 | 2733 | static int tg3_setup_phy(struct tg3 *, int); |
1da177e4 LT |
2734 | static int tg3_halt_cpu(struct tg3 *, u32); |
2735 | ||
0a459aac | 2736 | static void tg3_power_down_phy(struct tg3 *tp, bool do_low_power) |
15c3b696 | 2737 | { |
ce057f01 MC |
2738 | u32 val; |
2739 | ||
f07e9af3 | 2740 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) { |
5129724a MC |
2741 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) { |
2742 | u32 sg_dig_ctrl = tr32(SG_DIG_CTRL); | |
2743 | u32 serdes_cfg = tr32(MAC_SERDES_CFG); | |
2744 | ||
2745 | sg_dig_ctrl |= | |
2746 | SG_DIG_USING_HW_AUTONEG | SG_DIG_SOFT_RESET; | |
2747 | tw32(SG_DIG_CTRL, sg_dig_ctrl); | |
2748 | tw32(MAC_SERDES_CFG, serdes_cfg | (1 << 15)); | |
2749 | } | |
3f7045c1 | 2750 | return; |
5129724a | 2751 | } |
3f7045c1 | 2752 | |
60189ddf | 2753 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
60189ddf MC |
2754 | tg3_bmcr_reset(tp); |
2755 | val = tr32(GRC_MISC_CFG); | |
2756 | tw32_f(GRC_MISC_CFG, val | GRC_MISC_CFG_EPHY_IDDQ); | |
2757 | udelay(40); | |
2758 | return; | |
f07e9af3 | 2759 | } else if (tp->phy_flags & TG3_PHYFLG_IS_FET) { |
0e5f784c MC |
2760 | u32 phytest; |
2761 | if (!tg3_readphy(tp, MII_TG3_FET_TEST, &phytest)) { | |
2762 | u32 phy; | |
2763 | ||
2764 | tg3_writephy(tp, MII_ADVERTISE, 0); | |
2765 | tg3_writephy(tp, MII_BMCR, | |
2766 | BMCR_ANENABLE | BMCR_ANRESTART); | |
2767 | ||
2768 | tg3_writephy(tp, MII_TG3_FET_TEST, | |
2769 | phytest | MII_TG3_FET_SHADOW_EN); | |
2770 | if (!tg3_readphy(tp, MII_TG3_FET_SHDW_AUXMODE4, &phy)) { | |
2771 | phy |= MII_TG3_FET_SHDW_AUXMODE4_SBPD; | |
2772 | tg3_writephy(tp, | |
2773 | MII_TG3_FET_SHDW_AUXMODE4, | |
2774 | phy); | |
2775 | } | |
2776 | tg3_writephy(tp, MII_TG3_FET_TEST, phytest); | |
2777 | } | |
2778 | return; | |
0a459aac | 2779 | } else if (do_low_power) { |
715116a1 MC |
2780 | tg3_writephy(tp, MII_TG3_EXT_CTRL, |
2781 | MII_TG3_EXT_CTRL_FORCE_LED_OFF); | |
0a459aac | 2782 | |
b4bd2929 MC |
2783 | val = MII_TG3_AUXCTL_PCTL_100TX_LPWR | |
2784 | MII_TG3_AUXCTL_PCTL_SPR_ISOLATE | | |
2785 | MII_TG3_AUXCTL_PCTL_VREG_11V; | |
2786 | tg3_phy_auxctl_write(tp, MII_TG3_AUXCTL_SHDWSEL_PWRCTL, val); | |
715116a1 | 2787 | } |
3f7045c1 | 2788 | |
15c3b696 MC |
2789 | /* The PHY should not be powered down on some chips because |
2790 | * of bugs. | |
2791 | */ | |
2792 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || | |
2793 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 || | |
2794 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780 && | |
f07e9af3 | 2795 | (tp->phy_flags & TG3_PHYFLG_MII_SERDES))) |
15c3b696 | 2796 | return; |
ce057f01 | 2797 | |
bcb37f6c MC |
2798 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5784_AX || |
2799 | GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5761_AX) { | |
ce057f01 MC |
2800 | val = tr32(TG3_CPMU_LSPD_1000MB_CLK); |
2801 | val &= ~CPMU_LSPD_1000MB_MACCLK_MASK; | |
2802 | val |= CPMU_LSPD_1000MB_MACCLK_12_5; | |
2803 | tw32_f(TG3_CPMU_LSPD_1000MB_CLK, val); | |
2804 | } | |
2805 | ||
15c3b696 MC |
2806 | tg3_writephy(tp, MII_BMCR, BMCR_PDOWN); |
2807 | } | |
2808 | ||
ffbcfed4 MC |
2809 | /* tp->lock is held. */ |
2810 | static int tg3_nvram_lock(struct tg3 *tp) | |
2811 | { | |
63c3a66f | 2812 | if (tg3_flag(tp, NVRAM)) { |
ffbcfed4 MC |
2813 | int i; |
2814 | ||
2815 | if (tp->nvram_lock_cnt == 0) { | |
2816 | tw32(NVRAM_SWARB, SWARB_REQ_SET1); | |
2817 | for (i = 0; i < 8000; i++) { | |
2818 | if (tr32(NVRAM_SWARB) & SWARB_GNT1) | |
2819 | break; | |
2820 | udelay(20); | |
2821 | } | |
2822 | if (i == 8000) { | |
2823 | tw32(NVRAM_SWARB, SWARB_REQ_CLR1); | |
2824 | return -ENODEV; | |
2825 | } | |
2826 | } | |
2827 | tp->nvram_lock_cnt++; | |
2828 | } | |
2829 | return 0; | |
2830 | } | |
2831 | ||
2832 | /* tp->lock is held. */ | |
2833 | static void tg3_nvram_unlock(struct tg3 *tp) | |
2834 | { | |
63c3a66f | 2835 | if (tg3_flag(tp, NVRAM)) { |
ffbcfed4 MC |
2836 | if (tp->nvram_lock_cnt > 0) |
2837 | tp->nvram_lock_cnt--; | |
2838 | if (tp->nvram_lock_cnt == 0) | |
2839 | tw32_f(NVRAM_SWARB, SWARB_REQ_CLR1); | |
2840 | } | |
2841 | } | |
2842 | ||
2843 | /* tp->lock is held. */ | |
2844 | static void tg3_enable_nvram_access(struct tg3 *tp) | |
2845 | { | |
63c3a66f | 2846 | if (tg3_flag(tp, 5750_PLUS) && !tg3_flag(tp, PROTECTED_NVRAM)) { |
ffbcfed4 MC |
2847 | u32 nvaccess = tr32(NVRAM_ACCESS); |
2848 | ||
2849 | tw32(NVRAM_ACCESS, nvaccess | ACCESS_ENABLE); | |
2850 | } | |
2851 | } | |
2852 | ||
2853 | /* tp->lock is held. */ | |
2854 | static void tg3_disable_nvram_access(struct tg3 *tp) | |
2855 | { | |
63c3a66f | 2856 | if (tg3_flag(tp, 5750_PLUS) && !tg3_flag(tp, PROTECTED_NVRAM)) { |
ffbcfed4 MC |
2857 | u32 nvaccess = tr32(NVRAM_ACCESS); |
2858 | ||
2859 | tw32(NVRAM_ACCESS, nvaccess & ~ACCESS_ENABLE); | |
2860 | } | |
2861 | } | |
2862 | ||
2863 | static int tg3_nvram_read_using_eeprom(struct tg3 *tp, | |
2864 | u32 offset, u32 *val) | |
2865 | { | |
2866 | u32 tmp; | |
2867 | int i; | |
2868 | ||
2869 | if (offset > EEPROM_ADDR_ADDR_MASK || (offset % 4) != 0) | |
2870 | return -EINVAL; | |
2871 | ||
2872 | tmp = tr32(GRC_EEPROM_ADDR) & ~(EEPROM_ADDR_ADDR_MASK | | |
2873 | EEPROM_ADDR_DEVID_MASK | | |
2874 | EEPROM_ADDR_READ); | |
2875 | tw32(GRC_EEPROM_ADDR, | |
2876 | tmp | | |
2877 | (0 << EEPROM_ADDR_DEVID_SHIFT) | | |
2878 | ((offset << EEPROM_ADDR_ADDR_SHIFT) & | |
2879 | EEPROM_ADDR_ADDR_MASK) | | |
2880 | EEPROM_ADDR_READ | EEPROM_ADDR_START); | |
2881 | ||
2882 | for (i = 0; i < 1000; i++) { | |
2883 | tmp = tr32(GRC_EEPROM_ADDR); | |
2884 | ||
2885 | if (tmp & EEPROM_ADDR_COMPLETE) | |
2886 | break; | |
2887 | msleep(1); | |
2888 | } | |
2889 | if (!(tmp & EEPROM_ADDR_COMPLETE)) | |
2890 | return -EBUSY; | |
2891 | ||
62cedd11 MC |
2892 | tmp = tr32(GRC_EEPROM_DATA); |
2893 | ||
2894 | /* | |
2895 | * The data will always be opposite the native endian | |
2896 | * format. Perform a blind byteswap to compensate. | |
2897 | */ | |
2898 | *val = swab32(tmp); | |
2899 | ||
ffbcfed4 MC |
2900 | return 0; |
2901 | } | |
2902 | ||
2903 | #define NVRAM_CMD_TIMEOUT 10000 | |
2904 | ||
2905 | static int tg3_nvram_exec_cmd(struct tg3 *tp, u32 nvram_cmd) | |
2906 | { | |
2907 | int i; | |
2908 | ||
2909 | tw32(NVRAM_CMD, nvram_cmd); | |
2910 | for (i = 0; i < NVRAM_CMD_TIMEOUT; i++) { | |
2911 | udelay(10); | |
2912 | if (tr32(NVRAM_CMD) & NVRAM_CMD_DONE) { | |
2913 | udelay(10); | |
2914 | break; | |
2915 | } | |
2916 | } | |
2917 | ||
2918 | if (i == NVRAM_CMD_TIMEOUT) | |
2919 | return -EBUSY; | |
2920 | ||
2921 | return 0; | |
2922 | } | |
2923 | ||
2924 | static u32 tg3_nvram_phys_addr(struct tg3 *tp, u32 addr) | |
2925 | { | |
63c3a66f JP |
2926 | if (tg3_flag(tp, NVRAM) && |
2927 | tg3_flag(tp, NVRAM_BUFFERED) && | |
2928 | tg3_flag(tp, FLASH) && | |
2929 | !tg3_flag(tp, NO_NVRAM_ADDR_TRANS) && | |
ffbcfed4 MC |
2930 | (tp->nvram_jedecnum == JEDEC_ATMEL)) |
2931 | ||
2932 | addr = ((addr / tp->nvram_pagesize) << | |
2933 | ATMEL_AT45DB0X1B_PAGE_POS) + | |
2934 | (addr % tp->nvram_pagesize); | |
2935 | ||
2936 | return addr; | |
2937 | } | |
2938 | ||
2939 | static u32 tg3_nvram_logical_addr(struct tg3 *tp, u32 addr) | |
2940 | { | |
63c3a66f JP |
2941 | if (tg3_flag(tp, NVRAM) && |
2942 | tg3_flag(tp, NVRAM_BUFFERED) && | |
2943 | tg3_flag(tp, FLASH) && | |
2944 | !tg3_flag(tp, NO_NVRAM_ADDR_TRANS) && | |
ffbcfed4 MC |
2945 | (tp->nvram_jedecnum == JEDEC_ATMEL)) |
2946 | ||
2947 | addr = ((addr >> ATMEL_AT45DB0X1B_PAGE_POS) * | |
2948 | tp->nvram_pagesize) + | |
2949 | (addr & ((1 << ATMEL_AT45DB0X1B_PAGE_POS) - 1)); | |
2950 | ||
2951 | return addr; | |
2952 | } | |
2953 | ||
e4f34110 MC |
2954 | /* NOTE: Data read in from NVRAM is byteswapped according to |
2955 | * the byteswapping settings for all other register accesses. | |
2956 | * tg3 devices are BE devices, so on a BE machine, the data | |
2957 | * returned will be exactly as it is seen in NVRAM. On a LE | |
2958 | * machine, the 32-bit value will be byteswapped. | |
2959 | */ | |
ffbcfed4 MC |
2960 | static int tg3_nvram_read(struct tg3 *tp, u32 offset, u32 *val) |
2961 | { | |
2962 | int ret; | |
2963 | ||
63c3a66f | 2964 | if (!tg3_flag(tp, NVRAM)) |
ffbcfed4 MC |
2965 | return tg3_nvram_read_using_eeprom(tp, offset, val); |
2966 | ||
2967 | offset = tg3_nvram_phys_addr(tp, offset); | |
2968 | ||
2969 | if (offset > NVRAM_ADDR_MSK) | |
2970 | return -EINVAL; | |
2971 | ||
2972 | ret = tg3_nvram_lock(tp); | |
2973 | if (ret) | |
2974 | return ret; | |
2975 | ||
2976 | tg3_enable_nvram_access(tp); | |
2977 | ||
2978 | tw32(NVRAM_ADDR, offset); | |
2979 | ret = tg3_nvram_exec_cmd(tp, NVRAM_CMD_RD | NVRAM_CMD_GO | | |
2980 | NVRAM_CMD_FIRST | NVRAM_CMD_LAST | NVRAM_CMD_DONE); | |
2981 | ||
2982 | if (ret == 0) | |
e4f34110 | 2983 | *val = tr32(NVRAM_RDDATA); |
ffbcfed4 MC |
2984 | |
2985 | tg3_disable_nvram_access(tp); | |
2986 | ||
2987 | tg3_nvram_unlock(tp); | |
2988 | ||
2989 | return ret; | |
2990 | } | |
2991 | ||
a9dc529d MC |
2992 | /* Ensures NVRAM data is in bytestream format. */ |
2993 | static int tg3_nvram_read_be32(struct tg3 *tp, u32 offset, __be32 *val) | |
ffbcfed4 MC |
2994 | { |
2995 | u32 v; | |
a9dc529d | 2996 | int res = tg3_nvram_read(tp, offset, &v); |
ffbcfed4 | 2997 | if (!res) |
a9dc529d | 2998 | *val = cpu_to_be32(v); |
ffbcfed4 MC |
2999 | return res; |
3000 | } | |
3001 | ||
3f007891 MC |
3002 | /* tp->lock is held. */ |
3003 | static void __tg3_set_mac_addr(struct tg3 *tp, int skip_mac_1) | |
3004 | { | |
3005 | u32 addr_high, addr_low; | |
3006 | int i; | |
3007 | ||
3008 | addr_high = ((tp->dev->dev_addr[0] << 8) | | |
3009 | tp->dev->dev_addr[1]); | |
3010 | addr_low = ((tp->dev->dev_addr[2] << 24) | | |
3011 | (tp->dev->dev_addr[3] << 16) | | |
3012 | (tp->dev->dev_addr[4] << 8) | | |
3013 | (tp->dev->dev_addr[5] << 0)); | |
3014 | for (i = 0; i < 4; i++) { | |
3015 | if (i == 1 && skip_mac_1) | |
3016 | continue; | |
3017 | tw32(MAC_ADDR_0_HIGH + (i * 8), addr_high); | |
3018 | tw32(MAC_ADDR_0_LOW + (i * 8), addr_low); | |
3019 | } | |
3020 | ||
3021 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 || | |
3022 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) { | |
3023 | for (i = 0; i < 12; i++) { | |
3024 | tw32(MAC_EXTADDR_0_HIGH + (i * 8), addr_high); | |
3025 | tw32(MAC_EXTADDR_0_LOW + (i * 8), addr_low); | |
3026 | } | |
3027 | } | |
3028 | ||
3029 | addr_high = (tp->dev->dev_addr[0] + | |
3030 | tp->dev->dev_addr[1] + | |
3031 | tp->dev->dev_addr[2] + | |
3032 | tp->dev->dev_addr[3] + | |
3033 | tp->dev->dev_addr[4] + | |
3034 | tp->dev->dev_addr[5]) & | |
3035 | TX_BACKOFF_SEED_MASK; | |
3036 | tw32(MAC_TX_BACKOFF_SEED, addr_high); | |
3037 | } | |
3038 | ||
c866b7ea | 3039 | static void tg3_enable_register_access(struct tg3 *tp) |
1da177e4 | 3040 | { |
c866b7ea RW |
3041 | /* |
3042 | * Make sure register accesses (indirect or otherwise) will function | |
3043 | * correctly. | |
1da177e4 LT |
3044 | */ |
3045 | pci_write_config_dword(tp->pdev, | |
c866b7ea RW |
3046 | TG3PCI_MISC_HOST_CTRL, tp->misc_host_ctrl); |
3047 | } | |
1da177e4 | 3048 | |
c866b7ea RW |
3049 | static int tg3_power_up(struct tg3 *tp) |
3050 | { | |
bed9829f | 3051 | int err; |
8c6bda1a | 3052 | |
bed9829f | 3053 | tg3_enable_register_access(tp); |
1da177e4 | 3054 | |
bed9829f MC |
3055 | err = pci_set_power_state(tp->pdev, PCI_D0); |
3056 | if (!err) { | |
3057 | /* Switch out of Vaux if it is a NIC */ | |
3058 | tg3_pwrsrc_switch_to_vmain(tp); | |
3059 | } else { | |
3060 | netdev_err(tp->dev, "Transition to D0 failed\n"); | |
3061 | } | |
1da177e4 | 3062 | |
bed9829f | 3063 | return err; |
c866b7ea | 3064 | } |
1da177e4 | 3065 | |
c866b7ea RW |
3066 | static int tg3_power_down_prepare(struct tg3 *tp) |
3067 | { | |
3068 | u32 misc_host_ctrl; | |
3069 | bool device_should_wake, do_low_power; | |
3070 | ||
3071 | tg3_enable_register_access(tp); | |
5e7dfd0f MC |
3072 | |
3073 | /* Restore the CLKREQ setting. */ | |
63c3a66f | 3074 | if (tg3_flag(tp, CLKREQ_BUG)) { |
5e7dfd0f MC |
3075 | u16 lnkctl; |
3076 | ||
3077 | pci_read_config_word(tp->pdev, | |
708ebb3a | 3078 | pci_pcie_cap(tp->pdev) + PCI_EXP_LNKCTL, |
5e7dfd0f MC |
3079 | &lnkctl); |
3080 | lnkctl |= PCI_EXP_LNKCTL_CLKREQ_EN; | |
3081 | pci_write_config_word(tp->pdev, | |
708ebb3a | 3082 | pci_pcie_cap(tp->pdev) + PCI_EXP_LNKCTL, |
5e7dfd0f MC |
3083 | lnkctl); |
3084 | } | |
3085 | ||
1da177e4 LT |
3086 | misc_host_ctrl = tr32(TG3PCI_MISC_HOST_CTRL); |
3087 | tw32(TG3PCI_MISC_HOST_CTRL, | |
3088 | misc_host_ctrl | MISC_HOST_CTRL_MASK_PCI_INT); | |
3089 | ||
c866b7ea | 3090 | device_should_wake = device_may_wakeup(&tp->pdev->dev) && |
63c3a66f | 3091 | tg3_flag(tp, WOL_ENABLE); |
05ac4cb7 | 3092 | |
63c3a66f | 3093 | if (tg3_flag(tp, USE_PHYLIB)) { |
0a459aac | 3094 | do_low_power = false; |
f07e9af3 | 3095 | if ((tp->phy_flags & TG3_PHYFLG_IS_CONNECTED) && |
80096068 | 3096 | !(tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER)) { |
b02fd9e3 | 3097 | struct phy_device *phydev; |
0a459aac | 3098 | u32 phyid, advertising; |
b02fd9e3 | 3099 | |
3f0e3ad7 | 3100 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
b02fd9e3 | 3101 | |
80096068 | 3102 | tp->phy_flags |= TG3_PHYFLG_IS_LOW_POWER; |
b02fd9e3 MC |
3103 | |
3104 | tp->link_config.orig_speed = phydev->speed; | |
3105 | tp->link_config.orig_duplex = phydev->duplex; | |
3106 | tp->link_config.orig_autoneg = phydev->autoneg; | |
3107 | tp->link_config.orig_advertising = phydev->advertising; | |
3108 | ||
3109 | advertising = ADVERTISED_TP | | |
3110 | ADVERTISED_Pause | | |
3111 | ADVERTISED_Autoneg | | |
3112 | ADVERTISED_10baseT_Half; | |
3113 | ||
63c3a66f JP |
3114 | if (tg3_flag(tp, ENABLE_ASF) || device_should_wake) { |
3115 | if (tg3_flag(tp, WOL_SPEED_100MB)) | |
b02fd9e3 MC |
3116 | advertising |= |
3117 | ADVERTISED_100baseT_Half | | |
3118 | ADVERTISED_100baseT_Full | | |
3119 | ADVERTISED_10baseT_Full; | |
3120 | else | |
3121 | advertising |= ADVERTISED_10baseT_Full; | |
3122 | } | |
3123 | ||
3124 | phydev->advertising = advertising; | |
3125 | ||
3126 | phy_start_aneg(phydev); | |
0a459aac MC |
3127 | |
3128 | phyid = phydev->drv->phy_id & phydev->drv->phy_id_mask; | |
6a443a0f MC |
3129 | if (phyid != PHY_ID_BCMAC131) { |
3130 | phyid &= PHY_BCM_OUI_MASK; | |
3131 | if (phyid == PHY_BCM_OUI_1 || | |
3132 | phyid == PHY_BCM_OUI_2 || | |
3133 | phyid == PHY_BCM_OUI_3) | |
0a459aac MC |
3134 | do_low_power = true; |
3135 | } | |
b02fd9e3 | 3136 | } |
dd477003 | 3137 | } else { |
2023276e | 3138 | do_low_power = true; |
0a459aac | 3139 | |
80096068 MC |
3140 | if (!(tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER)) { |
3141 | tp->phy_flags |= TG3_PHYFLG_IS_LOW_POWER; | |
dd477003 MC |
3142 | tp->link_config.orig_speed = tp->link_config.speed; |
3143 | tp->link_config.orig_duplex = tp->link_config.duplex; | |
3144 | tp->link_config.orig_autoneg = tp->link_config.autoneg; | |
3145 | } | |
1da177e4 | 3146 | |
f07e9af3 | 3147 | if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) { |
dd477003 MC |
3148 | tp->link_config.speed = SPEED_10; |
3149 | tp->link_config.duplex = DUPLEX_HALF; | |
3150 | tp->link_config.autoneg = AUTONEG_ENABLE; | |
3151 | tg3_setup_phy(tp, 0); | |
3152 | } | |
1da177e4 LT |
3153 | } |
3154 | ||
b5d3772c MC |
3155 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
3156 | u32 val; | |
3157 | ||
3158 | val = tr32(GRC_VCPU_EXT_CTRL); | |
3159 | tw32(GRC_VCPU_EXT_CTRL, val | GRC_VCPU_EXT_CTRL_DISABLE_WOL); | |
63c3a66f | 3160 | } else if (!tg3_flag(tp, ENABLE_ASF)) { |
6921d201 MC |
3161 | int i; |
3162 | u32 val; | |
3163 | ||
3164 | for (i = 0; i < 200; i++) { | |
3165 | tg3_read_mem(tp, NIC_SRAM_FW_ASF_STATUS_MBOX, &val); | |
3166 | if (val == ~NIC_SRAM_FIRMWARE_MBOX_MAGIC1) | |
3167 | break; | |
3168 | msleep(1); | |
3169 | } | |
3170 | } | |
63c3a66f | 3171 | if (tg3_flag(tp, WOL_CAP)) |
a85feb8c GZ |
3172 | tg3_write_mem(tp, NIC_SRAM_WOL_MBOX, WOL_SIGNATURE | |
3173 | WOL_DRV_STATE_SHUTDOWN | | |
3174 | WOL_DRV_WOL | | |
3175 | WOL_SET_MAGIC_PKT); | |
6921d201 | 3176 | |
05ac4cb7 | 3177 | if (device_should_wake) { |
1da177e4 LT |
3178 | u32 mac_mode; |
3179 | ||
f07e9af3 | 3180 | if (!(tp->phy_flags & TG3_PHYFLG_PHY_SERDES)) { |
b4bd2929 MC |
3181 | if (do_low_power && |
3182 | !(tp->phy_flags & TG3_PHYFLG_IS_FET)) { | |
3183 | tg3_phy_auxctl_write(tp, | |
3184 | MII_TG3_AUXCTL_SHDWSEL_PWRCTL, | |
3185 | MII_TG3_AUXCTL_PCTL_WOL_EN | | |
3186 | MII_TG3_AUXCTL_PCTL_100TX_LPWR | | |
3187 | MII_TG3_AUXCTL_PCTL_CL_AB_TXDAC); | |
dd477003 MC |
3188 | udelay(40); |
3189 | } | |
1da177e4 | 3190 | |
f07e9af3 | 3191 | if (tp->phy_flags & TG3_PHYFLG_MII_SERDES) |
3f7045c1 MC |
3192 | mac_mode = MAC_MODE_PORT_MODE_GMII; |
3193 | else | |
3194 | mac_mode = MAC_MODE_PORT_MODE_MII; | |
1da177e4 | 3195 | |
e8f3f6ca MC |
3196 | mac_mode |= tp->mac_mode & MAC_MODE_LINK_POLARITY; |
3197 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == | |
3198 | ASIC_REV_5700) { | |
63c3a66f | 3199 | u32 speed = tg3_flag(tp, WOL_SPEED_100MB) ? |
e8f3f6ca MC |
3200 | SPEED_100 : SPEED_10; |
3201 | if (tg3_5700_link_polarity(tp, speed)) | |
3202 | mac_mode |= MAC_MODE_LINK_POLARITY; | |
3203 | else | |
3204 | mac_mode &= ~MAC_MODE_LINK_POLARITY; | |
3205 | } | |
1da177e4 LT |
3206 | } else { |
3207 | mac_mode = MAC_MODE_PORT_MODE_TBI; | |
3208 | } | |
3209 | ||
63c3a66f | 3210 | if (!tg3_flag(tp, 5750_PLUS)) |
1da177e4 LT |
3211 | tw32(MAC_LED_CTRL, tp->led_ctrl); |
3212 | ||
05ac4cb7 | 3213 | mac_mode |= MAC_MODE_MAGIC_PKT_ENABLE; |
63c3a66f JP |
3214 | if ((tg3_flag(tp, 5705_PLUS) && !tg3_flag(tp, 5780_CLASS)) && |
3215 | (tg3_flag(tp, ENABLE_ASF) || tg3_flag(tp, ENABLE_APE))) | |
05ac4cb7 | 3216 | mac_mode |= MAC_MODE_KEEP_FRAME_IN_WOL; |
1da177e4 | 3217 | |
63c3a66f | 3218 | if (tg3_flag(tp, ENABLE_APE)) |
d2394e6b MC |
3219 | mac_mode |= MAC_MODE_APE_TX_EN | |
3220 | MAC_MODE_APE_RX_EN | | |
3221 | MAC_MODE_TDE_ENABLE; | |
3bda1258 | 3222 | |
1da177e4 LT |
3223 | tw32_f(MAC_MODE, mac_mode); |
3224 | udelay(100); | |
3225 | ||
3226 | tw32_f(MAC_RX_MODE, RX_MODE_ENABLE); | |
3227 | udelay(10); | |
3228 | } | |
3229 | ||
63c3a66f | 3230 | if (!tg3_flag(tp, WOL_SPEED_100MB) && |
1da177e4 LT |
3231 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
3232 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701)) { | |
3233 | u32 base_val; | |
3234 | ||
3235 | base_val = tp->pci_clock_ctrl; | |
3236 | base_val |= (CLOCK_CTRL_RXCLK_DISABLE | | |
3237 | CLOCK_CTRL_TXCLK_DISABLE); | |
3238 | ||
b401e9e2 MC |
3239 | tw32_wait_f(TG3PCI_CLOCK_CTRL, base_val | CLOCK_CTRL_ALTCLK | |
3240 | CLOCK_CTRL_PWRDOWN_PLL133, 40); | |
63c3a66f JP |
3241 | } else if (tg3_flag(tp, 5780_CLASS) || |
3242 | tg3_flag(tp, CPMU_PRESENT) || | |
6ff6f81d | 3243 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
4cf78e4f | 3244 | /* do nothing */ |
63c3a66f | 3245 | } else if (!(tg3_flag(tp, 5750_PLUS) && tg3_flag(tp, ENABLE_ASF))) { |
1da177e4 LT |
3246 | u32 newbits1, newbits2; |
3247 | ||
3248 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || | |
3249 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) { | |
3250 | newbits1 = (CLOCK_CTRL_RXCLK_DISABLE | | |
3251 | CLOCK_CTRL_TXCLK_DISABLE | | |
3252 | CLOCK_CTRL_ALTCLK); | |
3253 | newbits2 = newbits1 | CLOCK_CTRL_44MHZ_CORE; | |
63c3a66f | 3254 | } else if (tg3_flag(tp, 5705_PLUS)) { |
1da177e4 LT |
3255 | newbits1 = CLOCK_CTRL_625_CORE; |
3256 | newbits2 = newbits1 | CLOCK_CTRL_ALTCLK; | |
3257 | } else { | |
3258 | newbits1 = CLOCK_CTRL_ALTCLK; | |
3259 | newbits2 = newbits1 | CLOCK_CTRL_44MHZ_CORE; | |
3260 | } | |
3261 | ||
b401e9e2 MC |
3262 | tw32_wait_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl | newbits1, |
3263 | 40); | |
1da177e4 | 3264 | |
b401e9e2 MC |
3265 | tw32_wait_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl | newbits2, |
3266 | 40); | |
1da177e4 | 3267 | |
63c3a66f | 3268 | if (!tg3_flag(tp, 5705_PLUS)) { |
1da177e4 LT |
3269 | u32 newbits3; |
3270 | ||
3271 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || | |
3272 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) { | |
3273 | newbits3 = (CLOCK_CTRL_RXCLK_DISABLE | | |
3274 | CLOCK_CTRL_TXCLK_DISABLE | | |
3275 | CLOCK_CTRL_44MHZ_CORE); | |
3276 | } else { | |
3277 | newbits3 = CLOCK_CTRL_44MHZ_CORE; | |
3278 | } | |
3279 | ||
b401e9e2 MC |
3280 | tw32_wait_f(TG3PCI_CLOCK_CTRL, |
3281 | tp->pci_clock_ctrl | newbits3, 40); | |
1da177e4 LT |
3282 | } |
3283 | } | |
3284 | ||
63c3a66f | 3285 | if (!(device_should_wake) && !tg3_flag(tp, ENABLE_ASF)) |
0a459aac | 3286 | tg3_power_down_phy(tp, do_low_power); |
6921d201 | 3287 | |
cd0d7228 | 3288 | tg3_frob_aux_power(tp, true); |
1da177e4 LT |
3289 | |
3290 | /* Workaround for unstable PLL clock */ | |
3291 | if ((GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_AX) || | |
3292 | (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_BX)) { | |
3293 | u32 val = tr32(0x7d00); | |
3294 | ||
3295 | val &= ~((1 << 16) | (1 << 4) | (1 << 2) | (1 << 1) | 1); | |
3296 | tw32(0x7d00, val); | |
63c3a66f | 3297 | if (!tg3_flag(tp, ENABLE_ASF)) { |
ec41c7df MC |
3298 | int err; |
3299 | ||
3300 | err = tg3_nvram_lock(tp); | |
1da177e4 | 3301 | tg3_halt_cpu(tp, RX_CPU_BASE); |
ec41c7df MC |
3302 | if (!err) |
3303 | tg3_nvram_unlock(tp); | |
6921d201 | 3304 | } |
1da177e4 LT |
3305 | } |
3306 | ||
bbadf503 MC |
3307 | tg3_write_sig_post_reset(tp, RESET_KIND_SHUTDOWN); |
3308 | ||
c866b7ea RW |
3309 | return 0; |
3310 | } | |
12dac075 | 3311 | |
c866b7ea RW |
3312 | static void tg3_power_down(struct tg3 *tp) |
3313 | { | |
3314 | tg3_power_down_prepare(tp); | |
1da177e4 | 3315 | |
63c3a66f | 3316 | pci_wake_from_d3(tp->pdev, tg3_flag(tp, WOL_ENABLE)); |
c866b7ea | 3317 | pci_set_power_state(tp->pdev, PCI_D3hot); |
1da177e4 LT |
3318 | } |
3319 | ||
1da177e4 LT |
3320 | static void tg3_aux_stat_to_speed_duplex(struct tg3 *tp, u32 val, u16 *speed, u8 *duplex) |
3321 | { | |
3322 | switch (val & MII_TG3_AUX_STAT_SPDMASK) { | |
3323 | case MII_TG3_AUX_STAT_10HALF: | |
3324 | *speed = SPEED_10; | |
3325 | *duplex = DUPLEX_HALF; | |
3326 | break; | |
3327 | ||
3328 | case MII_TG3_AUX_STAT_10FULL: | |
3329 | *speed = SPEED_10; | |
3330 | *duplex = DUPLEX_FULL; | |
3331 | break; | |
3332 | ||
3333 | case MII_TG3_AUX_STAT_100HALF: | |
3334 | *speed = SPEED_100; | |
3335 | *duplex = DUPLEX_HALF; | |
3336 | break; | |
3337 | ||
3338 | case MII_TG3_AUX_STAT_100FULL: | |
3339 | *speed = SPEED_100; | |
3340 | *duplex = DUPLEX_FULL; | |
3341 | break; | |
3342 | ||
3343 | case MII_TG3_AUX_STAT_1000HALF: | |
3344 | *speed = SPEED_1000; | |
3345 | *duplex = DUPLEX_HALF; | |
3346 | break; | |
3347 | ||
3348 | case MII_TG3_AUX_STAT_1000FULL: | |
3349 | *speed = SPEED_1000; | |
3350 | *duplex = DUPLEX_FULL; | |
3351 | break; | |
3352 | ||
3353 | default: | |
f07e9af3 | 3354 | if (tp->phy_flags & TG3_PHYFLG_IS_FET) { |
715116a1 MC |
3355 | *speed = (val & MII_TG3_AUX_STAT_100) ? SPEED_100 : |
3356 | SPEED_10; | |
3357 | *duplex = (val & MII_TG3_AUX_STAT_FULL) ? DUPLEX_FULL : | |
3358 | DUPLEX_HALF; | |
3359 | break; | |
3360 | } | |
1da177e4 LT |
3361 | *speed = SPEED_INVALID; |
3362 | *duplex = DUPLEX_INVALID; | |
3363 | break; | |
855e1111 | 3364 | } |
1da177e4 LT |
3365 | } |
3366 | ||
42b64a45 | 3367 | static int tg3_phy_autoneg_cfg(struct tg3 *tp, u32 advertise, u32 flowctrl) |
1da177e4 | 3368 | { |
42b64a45 MC |
3369 | int err = 0; |
3370 | u32 val, new_adv; | |
1da177e4 | 3371 | |
42b64a45 MC |
3372 | new_adv = ADVERTISE_CSMA; |
3373 | if (advertise & ADVERTISED_10baseT_Half) | |
3374 | new_adv |= ADVERTISE_10HALF; | |
3375 | if (advertise & ADVERTISED_10baseT_Full) | |
3376 | new_adv |= ADVERTISE_10FULL; | |
3377 | if (advertise & ADVERTISED_100baseT_Half) | |
3378 | new_adv |= ADVERTISE_100HALF; | |
3379 | if (advertise & ADVERTISED_100baseT_Full) | |
3380 | new_adv |= ADVERTISE_100FULL; | |
1da177e4 | 3381 | |
42b64a45 | 3382 | new_adv |= tg3_advert_flowctrl_1000T(flowctrl); |
1da177e4 | 3383 | |
42b64a45 MC |
3384 | err = tg3_writephy(tp, MII_ADVERTISE, new_adv); |
3385 | if (err) | |
3386 | goto done; | |
ba4d07a8 | 3387 | |
42b64a45 MC |
3388 | if (tp->phy_flags & TG3_PHYFLG_10_100_ONLY) |
3389 | goto done; | |
1da177e4 | 3390 | |
42b64a45 MC |
3391 | new_adv = 0; |
3392 | if (advertise & ADVERTISED_1000baseT_Half) | |
221c5637 | 3393 | new_adv |= ADVERTISE_1000HALF; |
42b64a45 | 3394 | if (advertise & ADVERTISED_1000baseT_Full) |
221c5637 | 3395 | new_adv |= ADVERTISE_1000FULL; |
ba4d07a8 | 3396 | |
42b64a45 MC |
3397 | if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 || |
3398 | tp->pci_chip_rev_id == CHIPREV_ID_5701_B0) | |
221c5637 | 3399 | new_adv |= CTL1000_AS_MASTER | CTL1000_ENABLE_MASTER; |
ba4d07a8 | 3400 | |
221c5637 | 3401 | err = tg3_writephy(tp, MII_CTRL1000, new_adv); |
42b64a45 MC |
3402 | if (err) |
3403 | goto done; | |
1da177e4 | 3404 | |
42b64a45 MC |
3405 | if (!(tp->phy_flags & TG3_PHYFLG_EEE_CAP)) |
3406 | goto done; | |
52b02d04 | 3407 | |
42b64a45 MC |
3408 | tw32(TG3_CPMU_EEE_MODE, |
3409 | tr32(TG3_CPMU_EEE_MODE) & ~TG3_CPMU_EEEMD_LPI_ENABLE); | |
52b02d04 | 3410 | |
42b64a45 MC |
3411 | err = TG3_PHY_AUXCTL_SMDSP_ENABLE(tp); |
3412 | if (!err) { | |
3413 | u32 err2; | |
52b02d04 | 3414 | |
b715ce94 MC |
3415 | val = 0; |
3416 | /* Advertise 100-BaseTX EEE ability */ | |
3417 | if (advertise & ADVERTISED_100baseT_Full) | |
3418 | val |= MDIO_AN_EEE_ADV_100TX; | |
3419 | /* Advertise 1000-BaseT EEE ability */ | |
3420 | if (advertise & ADVERTISED_1000baseT_Full) | |
3421 | val |= MDIO_AN_EEE_ADV_1000T; | |
3422 | err = tg3_phy_cl45_write(tp, MDIO_MMD_AN, MDIO_AN_EEE_ADV, val); | |
3423 | if (err) | |
3424 | val = 0; | |
3425 | ||
21a00ab2 MC |
3426 | switch (GET_ASIC_REV(tp->pci_chip_rev_id)) { |
3427 | case ASIC_REV_5717: | |
3428 | case ASIC_REV_57765: | |
21a00ab2 | 3429 | case ASIC_REV_5719: |
b715ce94 MC |
3430 | /* If we advertised any eee advertisements above... */ |
3431 | if (val) | |
3432 | val = MII_TG3_DSP_TAP26_ALNOKO | | |
3433 | MII_TG3_DSP_TAP26_RMRXSTO | | |
3434 | MII_TG3_DSP_TAP26_OPCSINPT; | |
21a00ab2 | 3435 | tg3_phydsp_write(tp, MII_TG3_DSP_TAP26, val); |
be671947 MC |
3436 | /* Fall through */ |
3437 | case ASIC_REV_5720: | |
3438 | if (!tg3_phydsp_read(tp, MII_TG3_DSP_CH34TP2, &val)) | |
3439 | tg3_phydsp_write(tp, MII_TG3_DSP_CH34TP2, val | | |
3440 | MII_TG3_DSP_CH34TP2_HIBW01); | |
21a00ab2 | 3441 | } |
52b02d04 | 3442 | |
42b64a45 MC |
3443 | err2 = TG3_PHY_AUXCTL_SMDSP_DISABLE(tp); |
3444 | if (!err) | |
3445 | err = err2; | |
3446 | } | |
3447 | ||
3448 | done: | |
3449 | return err; | |
3450 | } | |
3451 | ||
3452 | static void tg3_phy_copper_begin(struct tg3 *tp) | |
3453 | { | |
3454 | u32 new_adv; | |
3455 | int i; | |
3456 | ||
3457 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) { | |
3458 | new_adv = ADVERTISED_10baseT_Half | | |
3459 | ADVERTISED_10baseT_Full; | |
3460 | if (tg3_flag(tp, WOL_SPEED_100MB)) | |
3461 | new_adv |= ADVERTISED_100baseT_Half | | |
3462 | ADVERTISED_100baseT_Full; | |
3463 | ||
3464 | tg3_phy_autoneg_cfg(tp, new_adv, | |
3465 | FLOW_CTRL_TX | FLOW_CTRL_RX); | |
3466 | } else if (tp->link_config.speed == SPEED_INVALID) { | |
3467 | if (tp->phy_flags & TG3_PHYFLG_10_100_ONLY) | |
3468 | tp->link_config.advertising &= | |
3469 | ~(ADVERTISED_1000baseT_Half | | |
3470 | ADVERTISED_1000baseT_Full); | |
3471 | ||
3472 | tg3_phy_autoneg_cfg(tp, tp->link_config.advertising, | |
3473 | tp->link_config.flowctrl); | |
3474 | } else { | |
3475 | /* Asking for a specific link mode. */ | |
3476 | if (tp->link_config.speed == SPEED_1000) { | |
3477 | if (tp->link_config.duplex == DUPLEX_FULL) | |
3478 | new_adv = ADVERTISED_1000baseT_Full; | |
3479 | else | |
3480 | new_adv = ADVERTISED_1000baseT_Half; | |
3481 | } else if (tp->link_config.speed == SPEED_100) { | |
3482 | if (tp->link_config.duplex == DUPLEX_FULL) | |
3483 | new_adv = ADVERTISED_100baseT_Full; | |
3484 | else | |
3485 | new_adv = ADVERTISED_100baseT_Half; | |
3486 | } else { | |
3487 | if (tp->link_config.duplex == DUPLEX_FULL) | |
3488 | new_adv = ADVERTISED_10baseT_Full; | |
3489 | else | |
3490 | new_adv = ADVERTISED_10baseT_Half; | |
52b02d04 | 3491 | } |
52b02d04 | 3492 | |
42b64a45 MC |
3493 | tg3_phy_autoneg_cfg(tp, new_adv, |
3494 | tp->link_config.flowctrl); | |
52b02d04 MC |
3495 | } |
3496 | ||
1da177e4 LT |
3497 | if (tp->link_config.autoneg == AUTONEG_DISABLE && |
3498 | tp->link_config.speed != SPEED_INVALID) { | |
3499 | u32 bmcr, orig_bmcr; | |
3500 | ||
3501 | tp->link_config.active_speed = tp->link_config.speed; | |
3502 | tp->link_config.active_duplex = tp->link_config.duplex; | |
3503 | ||
3504 | bmcr = 0; | |
3505 | switch (tp->link_config.speed) { | |
3506 | default: | |
3507 | case SPEED_10: | |
3508 | break; | |
3509 | ||
3510 | case SPEED_100: | |
3511 | bmcr |= BMCR_SPEED100; | |
3512 | break; | |
3513 | ||
3514 | case SPEED_1000: | |
221c5637 | 3515 | bmcr |= BMCR_SPEED1000; |
1da177e4 | 3516 | break; |
855e1111 | 3517 | } |
1da177e4 LT |
3518 | |
3519 | if (tp->link_config.duplex == DUPLEX_FULL) | |
3520 | bmcr |= BMCR_FULLDPLX; | |
3521 | ||
3522 | if (!tg3_readphy(tp, MII_BMCR, &orig_bmcr) && | |
3523 | (bmcr != orig_bmcr)) { | |
3524 | tg3_writephy(tp, MII_BMCR, BMCR_LOOPBACK); | |
3525 | for (i = 0; i < 1500; i++) { | |
3526 | u32 tmp; | |
3527 | ||
3528 | udelay(10); | |
3529 | if (tg3_readphy(tp, MII_BMSR, &tmp) || | |
3530 | tg3_readphy(tp, MII_BMSR, &tmp)) | |
3531 | continue; | |
3532 | if (!(tmp & BMSR_LSTATUS)) { | |
3533 | udelay(40); | |
3534 | break; | |
3535 | } | |
3536 | } | |
3537 | tg3_writephy(tp, MII_BMCR, bmcr); | |
3538 | udelay(40); | |
3539 | } | |
3540 | } else { | |
3541 | tg3_writephy(tp, MII_BMCR, | |
3542 | BMCR_ANENABLE | BMCR_ANRESTART); | |
3543 | } | |
3544 | } | |
3545 | ||
3546 | static int tg3_init_5401phy_dsp(struct tg3 *tp) | |
3547 | { | |
3548 | int err; | |
3549 | ||
3550 | /* Turn off tap power management. */ | |
3551 | /* Set Extended packet length bit */ | |
b4bd2929 | 3552 | err = tg3_phy_auxctl_write(tp, MII_TG3_AUXCTL_SHDWSEL_AUXCTL, 0x4c20); |
1da177e4 | 3553 | |
6ee7c0a0 MC |
3554 | err |= tg3_phydsp_write(tp, 0x0012, 0x1804); |
3555 | err |= tg3_phydsp_write(tp, 0x0013, 0x1204); | |
3556 | err |= tg3_phydsp_write(tp, 0x8006, 0x0132); | |
3557 | err |= tg3_phydsp_write(tp, 0x8006, 0x0232); | |
3558 | err |= tg3_phydsp_write(tp, 0x201f, 0x0a20); | |
1da177e4 LT |
3559 | |
3560 | udelay(40); | |
3561 | ||
3562 | return err; | |
3563 | } | |
3564 | ||
3600d918 | 3565 | static int tg3_copper_is_advertising_all(struct tg3 *tp, u32 mask) |
1da177e4 | 3566 | { |
3600d918 MC |
3567 | u32 adv_reg, all_mask = 0; |
3568 | ||
3569 | if (mask & ADVERTISED_10baseT_Half) | |
3570 | all_mask |= ADVERTISE_10HALF; | |
3571 | if (mask & ADVERTISED_10baseT_Full) | |
3572 | all_mask |= ADVERTISE_10FULL; | |
3573 | if (mask & ADVERTISED_100baseT_Half) | |
3574 | all_mask |= ADVERTISE_100HALF; | |
3575 | if (mask & ADVERTISED_100baseT_Full) | |
3576 | all_mask |= ADVERTISE_100FULL; | |
1da177e4 LT |
3577 | |
3578 | if (tg3_readphy(tp, MII_ADVERTISE, &adv_reg)) | |
3579 | return 0; | |
3580 | ||
b99d2a57 | 3581 | if ((adv_reg & ADVERTISE_ALL) != all_mask) |
1da177e4 | 3582 | return 0; |
b99d2a57 | 3583 | |
f07e9af3 | 3584 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) { |
1da177e4 LT |
3585 | u32 tg3_ctrl; |
3586 | ||
3600d918 MC |
3587 | all_mask = 0; |
3588 | if (mask & ADVERTISED_1000baseT_Half) | |
3589 | all_mask |= ADVERTISE_1000HALF; | |
3590 | if (mask & ADVERTISED_1000baseT_Full) | |
3591 | all_mask |= ADVERTISE_1000FULL; | |
3592 | ||
221c5637 | 3593 | if (tg3_readphy(tp, MII_CTRL1000, &tg3_ctrl)) |
1da177e4 LT |
3594 | return 0; |
3595 | ||
b99d2a57 MC |
3596 | tg3_ctrl &= (ADVERTISE_1000HALF | ADVERTISE_1000FULL); |
3597 | if (tg3_ctrl != all_mask) | |
1da177e4 LT |
3598 | return 0; |
3599 | } | |
3600 | return 1; | |
3601 | } | |
3602 | ||
ef167e27 MC |
3603 | static int tg3_adv_1000T_flowctrl_ok(struct tg3 *tp, u32 *lcladv, u32 *rmtadv) |
3604 | { | |
3605 | u32 curadv, reqadv; | |
3606 | ||
3607 | if (tg3_readphy(tp, MII_ADVERTISE, lcladv)) | |
3608 | return 1; | |
3609 | ||
3610 | curadv = *lcladv & (ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM); | |
3611 | reqadv = tg3_advert_flowctrl_1000T(tp->link_config.flowctrl); | |
3612 | ||
3613 | if (tp->link_config.active_duplex == DUPLEX_FULL) { | |
3614 | if (curadv != reqadv) | |
3615 | return 0; | |
3616 | ||
63c3a66f | 3617 | if (tg3_flag(tp, PAUSE_AUTONEG)) |
ef167e27 MC |
3618 | tg3_readphy(tp, MII_LPA, rmtadv); |
3619 | } else { | |
3620 | /* Reprogram the advertisement register, even if it | |
3621 | * does not affect the current link. If the link | |
3622 | * gets renegotiated in the future, we can save an | |
3623 | * additional renegotiation cycle by advertising | |
3624 | * it correctly in the first place. | |
3625 | */ | |
3626 | if (curadv != reqadv) { | |
3627 | *lcladv &= ~(ADVERTISE_PAUSE_CAP | | |
3628 | ADVERTISE_PAUSE_ASYM); | |
3629 | tg3_writephy(tp, MII_ADVERTISE, *lcladv | reqadv); | |
3630 | } | |
3631 | } | |
3632 | ||
3633 | return 1; | |
3634 | } | |
3635 | ||
1da177e4 LT |
3636 | static int tg3_setup_copper_phy(struct tg3 *tp, int force_reset) |
3637 | { | |
3638 | int current_link_up; | |
f833c4c1 | 3639 | u32 bmsr, val; |
ef167e27 | 3640 | u32 lcl_adv, rmt_adv; |
1da177e4 LT |
3641 | u16 current_speed; |
3642 | u8 current_duplex; | |
3643 | int i, err; | |
3644 | ||
3645 | tw32(MAC_EVENT, 0); | |
3646 | ||
3647 | tw32_f(MAC_STATUS, | |
3648 | (MAC_STATUS_SYNC_CHANGED | | |
3649 | MAC_STATUS_CFG_CHANGED | | |
3650 | MAC_STATUS_MI_COMPLETION | | |
3651 | MAC_STATUS_LNKSTATE_CHANGED)); | |
3652 | udelay(40); | |
3653 | ||
8ef21428 MC |
3654 | if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) { |
3655 | tw32_f(MAC_MI_MODE, | |
3656 | (tp->mi_mode & ~MAC_MI_MODE_AUTO_POLL)); | |
3657 | udelay(80); | |
3658 | } | |
1da177e4 | 3659 | |
b4bd2929 | 3660 | tg3_phy_auxctl_write(tp, MII_TG3_AUXCTL_SHDWSEL_PWRCTL, 0); |
1da177e4 LT |
3661 | |
3662 | /* Some third-party PHYs need to be reset on link going | |
3663 | * down. | |
3664 | */ | |
3665 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 || | |
3666 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 || | |
3667 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) && | |
3668 | netif_carrier_ok(tp->dev)) { | |
3669 | tg3_readphy(tp, MII_BMSR, &bmsr); | |
3670 | if (!tg3_readphy(tp, MII_BMSR, &bmsr) && | |
3671 | !(bmsr & BMSR_LSTATUS)) | |
3672 | force_reset = 1; | |
3673 | } | |
3674 | if (force_reset) | |
3675 | tg3_phy_reset(tp); | |
3676 | ||
79eb6904 | 3677 | if ((tp->phy_id & TG3_PHY_ID_MASK) == TG3_PHY_ID_BCM5401) { |
1da177e4 LT |
3678 | tg3_readphy(tp, MII_BMSR, &bmsr); |
3679 | if (tg3_readphy(tp, MII_BMSR, &bmsr) || | |
63c3a66f | 3680 | !tg3_flag(tp, INIT_COMPLETE)) |
1da177e4 LT |
3681 | bmsr = 0; |
3682 | ||
3683 | if (!(bmsr & BMSR_LSTATUS)) { | |
3684 | err = tg3_init_5401phy_dsp(tp); | |
3685 | if (err) | |
3686 | return err; | |
3687 | ||
3688 | tg3_readphy(tp, MII_BMSR, &bmsr); | |
3689 | for (i = 0; i < 1000; i++) { | |
3690 | udelay(10); | |
3691 | if (!tg3_readphy(tp, MII_BMSR, &bmsr) && | |
3692 | (bmsr & BMSR_LSTATUS)) { | |
3693 | udelay(40); | |
3694 | break; | |
3695 | } | |
3696 | } | |
3697 | ||
79eb6904 MC |
3698 | if ((tp->phy_id & TG3_PHY_ID_REV_MASK) == |
3699 | TG3_PHY_REV_BCM5401_B0 && | |
1da177e4 LT |
3700 | !(bmsr & BMSR_LSTATUS) && |
3701 | tp->link_config.active_speed == SPEED_1000) { | |
3702 | err = tg3_phy_reset(tp); | |
3703 | if (!err) | |
3704 | err = tg3_init_5401phy_dsp(tp); | |
3705 | if (err) | |
3706 | return err; | |
3707 | } | |
3708 | } | |
3709 | } else if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 || | |
3710 | tp->pci_chip_rev_id == CHIPREV_ID_5701_B0) { | |
3711 | /* 5701 {A0,B0} CRC bug workaround */ | |
3712 | tg3_writephy(tp, 0x15, 0x0a75); | |
f08aa1a8 MC |
3713 | tg3_writephy(tp, MII_TG3_MISC_SHDW, 0x8c68); |
3714 | tg3_writephy(tp, MII_TG3_MISC_SHDW, 0x8d68); | |
3715 | tg3_writephy(tp, MII_TG3_MISC_SHDW, 0x8c68); | |
1da177e4 LT |
3716 | } |
3717 | ||
3718 | /* Clear pending interrupts... */ | |
f833c4c1 MC |
3719 | tg3_readphy(tp, MII_TG3_ISTAT, &val); |
3720 | tg3_readphy(tp, MII_TG3_ISTAT, &val); | |
1da177e4 | 3721 | |
f07e9af3 | 3722 | if (tp->phy_flags & TG3_PHYFLG_USE_MI_INTERRUPT) |
1da177e4 | 3723 | tg3_writephy(tp, MII_TG3_IMASK, ~MII_TG3_INT_LINKCHG); |
f07e9af3 | 3724 | else if (!(tp->phy_flags & TG3_PHYFLG_IS_FET)) |
1da177e4 LT |
3725 | tg3_writephy(tp, MII_TG3_IMASK, ~0); |
3726 | ||
3727 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || | |
3728 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) { | |
3729 | if (tp->led_ctrl == LED_CTRL_MODE_PHY_1) | |
3730 | tg3_writephy(tp, MII_TG3_EXT_CTRL, | |
3731 | MII_TG3_EXT_CTRL_LNK3_LED_MODE); | |
3732 | else | |
3733 | tg3_writephy(tp, MII_TG3_EXT_CTRL, 0); | |
3734 | } | |
3735 | ||
3736 | current_link_up = 0; | |
3737 | current_speed = SPEED_INVALID; | |
3738 | current_duplex = DUPLEX_INVALID; | |
3739 | ||
f07e9af3 | 3740 | if (tp->phy_flags & TG3_PHYFLG_CAPACITIVE_COUPLING) { |
15ee95c3 MC |
3741 | err = tg3_phy_auxctl_read(tp, |
3742 | MII_TG3_AUXCTL_SHDWSEL_MISCTEST, | |
3743 | &val); | |
3744 | if (!err && !(val & (1 << 10))) { | |
b4bd2929 MC |
3745 | tg3_phy_auxctl_write(tp, |
3746 | MII_TG3_AUXCTL_SHDWSEL_MISCTEST, | |
3747 | val | (1 << 10)); | |
1da177e4 LT |
3748 | goto relink; |
3749 | } | |
3750 | } | |
3751 | ||
3752 | bmsr = 0; | |
3753 | for (i = 0; i < 100; i++) { | |
3754 | tg3_readphy(tp, MII_BMSR, &bmsr); | |
3755 | if (!tg3_readphy(tp, MII_BMSR, &bmsr) && | |
3756 | (bmsr & BMSR_LSTATUS)) | |
3757 | break; | |
3758 | udelay(40); | |
3759 | } | |
3760 | ||
3761 | if (bmsr & BMSR_LSTATUS) { | |
3762 | u32 aux_stat, bmcr; | |
3763 | ||
3764 | tg3_readphy(tp, MII_TG3_AUX_STAT, &aux_stat); | |
3765 | for (i = 0; i < 2000; i++) { | |
3766 | udelay(10); | |
3767 | if (!tg3_readphy(tp, MII_TG3_AUX_STAT, &aux_stat) && | |
3768 | aux_stat) | |
3769 | break; | |
3770 | } | |
3771 | ||
3772 | tg3_aux_stat_to_speed_duplex(tp, aux_stat, | |
3773 | ¤t_speed, | |
3774 | ¤t_duplex); | |
3775 | ||
3776 | bmcr = 0; | |
3777 | for (i = 0; i < 200; i++) { | |
3778 | tg3_readphy(tp, MII_BMCR, &bmcr); | |
3779 | if (tg3_readphy(tp, MII_BMCR, &bmcr)) | |
3780 | continue; | |
3781 | if (bmcr && bmcr != 0x7fff) | |
3782 | break; | |
3783 | udelay(10); | |
3784 | } | |
3785 | ||
ef167e27 MC |
3786 | lcl_adv = 0; |
3787 | rmt_adv = 0; | |
1da177e4 | 3788 | |
ef167e27 MC |
3789 | tp->link_config.active_speed = current_speed; |
3790 | tp->link_config.active_duplex = current_duplex; | |
3791 | ||
3792 | if (tp->link_config.autoneg == AUTONEG_ENABLE) { | |
3793 | if ((bmcr & BMCR_ANENABLE) && | |
3794 | tg3_copper_is_advertising_all(tp, | |
3795 | tp->link_config.advertising)) { | |
3796 | if (tg3_adv_1000T_flowctrl_ok(tp, &lcl_adv, | |
3797 | &rmt_adv)) | |
3798 | current_link_up = 1; | |
1da177e4 LT |
3799 | } |
3800 | } else { | |
3801 | if (!(bmcr & BMCR_ANENABLE) && | |
3802 | tp->link_config.speed == current_speed && | |
ef167e27 MC |
3803 | tp->link_config.duplex == current_duplex && |
3804 | tp->link_config.flowctrl == | |
3805 | tp->link_config.active_flowctrl) { | |
1da177e4 | 3806 | current_link_up = 1; |
1da177e4 LT |
3807 | } |
3808 | } | |
3809 | ||
ef167e27 MC |
3810 | if (current_link_up == 1 && |
3811 | tp->link_config.active_duplex == DUPLEX_FULL) | |
3812 | tg3_setup_flow_control(tp, lcl_adv, rmt_adv); | |
1da177e4 LT |
3813 | } |
3814 | ||
1da177e4 | 3815 | relink: |
80096068 | 3816 | if (current_link_up == 0 || (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER)) { |
1da177e4 LT |
3817 | tg3_phy_copper_begin(tp); |
3818 | ||
f833c4c1 | 3819 | tg3_readphy(tp, MII_BMSR, &bmsr); |
06c03c02 MB |
3820 | if ((!tg3_readphy(tp, MII_BMSR, &bmsr) && (bmsr & BMSR_LSTATUS)) || |
3821 | (tp->mac_mode & MAC_MODE_PORT_INT_LPBACK)) | |
1da177e4 LT |
3822 | current_link_up = 1; |
3823 | } | |
3824 | ||
3825 | tp->mac_mode &= ~MAC_MODE_PORT_MODE_MASK; | |
3826 | if (current_link_up == 1) { | |
3827 | if (tp->link_config.active_speed == SPEED_100 || | |
3828 | tp->link_config.active_speed == SPEED_10) | |
3829 | tp->mac_mode |= MAC_MODE_PORT_MODE_MII; | |
3830 | else | |
3831 | tp->mac_mode |= MAC_MODE_PORT_MODE_GMII; | |
f07e9af3 | 3832 | } else if (tp->phy_flags & TG3_PHYFLG_IS_FET) |
7f97a4bd MC |
3833 | tp->mac_mode |= MAC_MODE_PORT_MODE_MII; |
3834 | else | |
1da177e4 LT |
3835 | tp->mac_mode |= MAC_MODE_PORT_MODE_GMII; |
3836 | ||
3837 | tp->mac_mode &= ~MAC_MODE_HALF_DUPLEX; | |
3838 | if (tp->link_config.active_duplex == DUPLEX_HALF) | |
3839 | tp->mac_mode |= MAC_MODE_HALF_DUPLEX; | |
3840 | ||
1da177e4 | 3841 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) { |
e8f3f6ca MC |
3842 | if (current_link_up == 1 && |
3843 | tg3_5700_link_polarity(tp, tp->link_config.active_speed)) | |
1da177e4 | 3844 | tp->mac_mode |= MAC_MODE_LINK_POLARITY; |
e8f3f6ca MC |
3845 | else |
3846 | tp->mac_mode &= ~MAC_MODE_LINK_POLARITY; | |
1da177e4 LT |
3847 | } |
3848 | ||
3849 | /* ??? Without this setting Netgear GA302T PHY does not | |
3850 | * ??? send/receive packets... | |
3851 | */ | |
79eb6904 | 3852 | if ((tp->phy_id & TG3_PHY_ID_MASK) == TG3_PHY_ID_BCM5411 && |
1da177e4 LT |
3853 | tp->pci_chip_rev_id == CHIPREV_ID_5700_ALTIMA) { |
3854 | tp->mi_mode |= MAC_MI_MODE_AUTO_POLL; | |
3855 | tw32_f(MAC_MI_MODE, tp->mi_mode); | |
3856 | udelay(80); | |
3857 | } | |
3858 | ||
3859 | tw32_f(MAC_MODE, tp->mac_mode); | |
3860 | udelay(40); | |
3861 | ||
52b02d04 MC |
3862 | tg3_phy_eee_adjust(tp, current_link_up); |
3863 | ||
63c3a66f | 3864 | if (tg3_flag(tp, USE_LINKCHG_REG)) { |
1da177e4 LT |
3865 | /* Polled via timer. */ |
3866 | tw32_f(MAC_EVENT, 0); | |
3867 | } else { | |
3868 | tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED); | |
3869 | } | |
3870 | udelay(40); | |
3871 | ||
3872 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 && | |
3873 | current_link_up == 1 && | |
3874 | tp->link_config.active_speed == SPEED_1000 && | |
63c3a66f | 3875 | (tg3_flag(tp, PCIX_MODE) || tg3_flag(tp, PCI_HIGH_SPEED))) { |
1da177e4 LT |
3876 | udelay(120); |
3877 | tw32_f(MAC_STATUS, | |
3878 | (MAC_STATUS_SYNC_CHANGED | | |
3879 | MAC_STATUS_CFG_CHANGED)); | |
3880 | udelay(40); | |
3881 | tg3_write_mem(tp, | |
3882 | NIC_SRAM_FIRMWARE_MBOX, | |
3883 | NIC_SRAM_FIRMWARE_MBOX_MAGIC2); | |
3884 | } | |
3885 | ||
5e7dfd0f | 3886 | /* Prevent send BD corruption. */ |
63c3a66f | 3887 | if (tg3_flag(tp, CLKREQ_BUG)) { |
5e7dfd0f MC |
3888 | u16 oldlnkctl, newlnkctl; |
3889 | ||
3890 | pci_read_config_word(tp->pdev, | |
708ebb3a | 3891 | pci_pcie_cap(tp->pdev) + PCI_EXP_LNKCTL, |
5e7dfd0f MC |
3892 | &oldlnkctl); |
3893 | if (tp->link_config.active_speed == SPEED_100 || | |
3894 | tp->link_config.active_speed == SPEED_10) | |
3895 | newlnkctl = oldlnkctl & ~PCI_EXP_LNKCTL_CLKREQ_EN; | |
3896 | else | |
3897 | newlnkctl = oldlnkctl | PCI_EXP_LNKCTL_CLKREQ_EN; | |
3898 | if (newlnkctl != oldlnkctl) | |
3899 | pci_write_config_word(tp->pdev, | |
708ebb3a | 3900 | pci_pcie_cap(tp->pdev) + PCI_EXP_LNKCTL, |
5e7dfd0f MC |
3901 | newlnkctl); |
3902 | } | |
3903 | ||
1da177e4 LT |
3904 | if (current_link_up != netif_carrier_ok(tp->dev)) { |
3905 | if (current_link_up) | |
3906 | netif_carrier_on(tp->dev); | |
3907 | else | |
3908 | netif_carrier_off(tp->dev); | |
3909 | tg3_link_report(tp); | |
3910 | } | |
3911 | ||
3912 | return 0; | |
3913 | } | |
3914 | ||
3915 | struct tg3_fiber_aneginfo { | |
3916 | int state; | |
3917 | #define ANEG_STATE_UNKNOWN 0 | |
3918 | #define ANEG_STATE_AN_ENABLE 1 | |
3919 | #define ANEG_STATE_RESTART_INIT 2 | |
3920 | #define ANEG_STATE_RESTART 3 | |
3921 | #define ANEG_STATE_DISABLE_LINK_OK 4 | |
3922 | #define ANEG_STATE_ABILITY_DETECT_INIT 5 | |
3923 | #define ANEG_STATE_ABILITY_DETECT 6 | |
3924 | #define ANEG_STATE_ACK_DETECT_INIT 7 | |
3925 | #define ANEG_STATE_ACK_DETECT 8 | |
3926 | #define ANEG_STATE_COMPLETE_ACK_INIT 9 | |
3927 | #define ANEG_STATE_COMPLETE_ACK 10 | |
3928 | #define ANEG_STATE_IDLE_DETECT_INIT 11 | |
3929 | #define ANEG_STATE_IDLE_DETECT 12 | |
3930 | #define ANEG_STATE_LINK_OK 13 | |
3931 | #define ANEG_STATE_NEXT_PAGE_WAIT_INIT 14 | |
3932 | #define ANEG_STATE_NEXT_PAGE_WAIT 15 | |
3933 | ||
3934 | u32 flags; | |
3935 | #define MR_AN_ENABLE 0x00000001 | |
3936 | #define MR_RESTART_AN 0x00000002 | |
3937 | #define MR_AN_COMPLETE 0x00000004 | |
3938 | #define MR_PAGE_RX 0x00000008 | |
3939 | #define MR_NP_LOADED 0x00000010 | |
3940 | #define MR_TOGGLE_TX 0x00000020 | |
3941 | #define MR_LP_ADV_FULL_DUPLEX 0x00000040 | |
3942 | #define MR_LP_ADV_HALF_DUPLEX 0x00000080 | |
3943 | #define MR_LP_ADV_SYM_PAUSE 0x00000100 | |
3944 | #define MR_LP_ADV_ASYM_PAUSE 0x00000200 | |
3945 | #define MR_LP_ADV_REMOTE_FAULT1 0x00000400 | |
3946 | #define MR_LP_ADV_REMOTE_FAULT2 0x00000800 | |
3947 | #define MR_LP_ADV_NEXT_PAGE 0x00001000 | |
3948 | #define MR_TOGGLE_RX 0x00002000 | |
3949 | #define MR_NP_RX 0x00004000 | |
3950 | ||
3951 | #define MR_LINK_OK 0x80000000 | |
3952 | ||
3953 | unsigned long link_time, cur_time; | |
3954 | ||
3955 | u32 ability_match_cfg; | |
3956 | int ability_match_count; | |
3957 | ||
3958 | char ability_match, idle_match, ack_match; | |
3959 | ||
3960 | u32 txconfig, rxconfig; | |
3961 | #define ANEG_CFG_NP 0x00000080 | |
3962 | #define ANEG_CFG_ACK 0x00000040 | |
3963 | #define ANEG_CFG_RF2 0x00000020 | |
3964 | #define ANEG_CFG_RF1 0x00000010 | |
3965 | #define ANEG_CFG_PS2 0x00000001 | |
3966 | #define ANEG_CFG_PS1 0x00008000 | |
3967 | #define ANEG_CFG_HD 0x00004000 | |
3968 | #define ANEG_CFG_FD 0x00002000 | |
3969 | #define ANEG_CFG_INVAL 0x00001f06 | |
3970 | ||
3971 | }; | |
3972 | #define ANEG_OK 0 | |
3973 | #define ANEG_DONE 1 | |
3974 | #define ANEG_TIMER_ENAB 2 | |
3975 | #define ANEG_FAILED -1 | |
3976 | ||
3977 | #define ANEG_STATE_SETTLE_TIME 10000 | |
3978 | ||
3979 | static int tg3_fiber_aneg_smachine(struct tg3 *tp, | |
3980 | struct tg3_fiber_aneginfo *ap) | |
3981 | { | |
5be73b47 | 3982 | u16 flowctrl; |
1da177e4 LT |
3983 | unsigned long delta; |
3984 | u32 rx_cfg_reg; | |
3985 | int ret; | |
3986 | ||
3987 | if (ap->state == ANEG_STATE_UNKNOWN) { | |
3988 | ap->rxconfig = 0; | |
3989 | ap->link_time = 0; | |
3990 | ap->cur_time = 0; | |
3991 | ap->ability_match_cfg = 0; | |
3992 | ap->ability_match_count = 0; | |
3993 | ap->ability_match = 0; | |
3994 | ap->idle_match = 0; | |
3995 | ap->ack_match = 0; | |
3996 | } | |
3997 | ap->cur_time++; | |
3998 | ||
3999 | if (tr32(MAC_STATUS) & MAC_STATUS_RCVD_CFG) { | |
4000 | rx_cfg_reg = tr32(MAC_RX_AUTO_NEG); | |
4001 | ||
4002 | if (rx_cfg_reg != ap->ability_match_cfg) { | |
4003 | ap->ability_match_cfg = rx_cfg_reg; | |
4004 | ap->ability_match = 0; | |
4005 | ap->ability_match_count = 0; | |
4006 | } else { | |
4007 | if (++ap->ability_match_count > 1) { | |
4008 | ap->ability_match = 1; | |
4009 | ap->ability_match_cfg = rx_cfg_reg; | |
4010 | } | |
4011 | } | |
4012 | if (rx_cfg_reg & ANEG_CFG_ACK) | |
4013 | ap->ack_match = 1; | |
4014 | else | |
4015 | ap->ack_match = 0; | |
4016 | ||
4017 | ap->idle_match = 0; | |
4018 | } else { | |
4019 | ap->idle_match = 1; | |
4020 | ap->ability_match_cfg = 0; | |
4021 | ap->ability_match_count = 0; | |
4022 | ap->ability_match = 0; | |
4023 | ap->ack_match = 0; | |
4024 | ||
4025 | rx_cfg_reg = 0; | |
4026 | } | |
4027 | ||
4028 | ap->rxconfig = rx_cfg_reg; | |
4029 | ret = ANEG_OK; | |
4030 | ||
33f401ae | 4031 | switch (ap->state) { |
1da177e4 LT |
4032 | case ANEG_STATE_UNKNOWN: |
4033 | if (ap->flags & (MR_AN_ENABLE | MR_RESTART_AN)) | |
4034 | ap->state = ANEG_STATE_AN_ENABLE; | |
4035 | ||
4036 | /* fallthru */ | |
4037 | case ANEG_STATE_AN_ENABLE: | |
4038 | ap->flags &= ~(MR_AN_COMPLETE | MR_PAGE_RX); | |
4039 | if (ap->flags & MR_AN_ENABLE) { | |
4040 | ap->link_time = 0; | |
4041 | ap->cur_time = 0; | |
4042 | ap->ability_match_cfg = 0; | |
4043 | ap->ability_match_count = 0; | |
4044 | ap->ability_match = 0; | |
4045 | ap->idle_match = 0; | |
4046 | ap->ack_match = 0; | |
4047 | ||
4048 | ap->state = ANEG_STATE_RESTART_INIT; | |
4049 | } else { | |
4050 | ap->state = ANEG_STATE_DISABLE_LINK_OK; | |
4051 | } | |
4052 | break; | |
4053 | ||
4054 | case ANEG_STATE_RESTART_INIT: | |
4055 | ap->link_time = ap->cur_time; | |
4056 | ap->flags &= ~(MR_NP_LOADED); | |
4057 | ap->txconfig = 0; | |
4058 | tw32(MAC_TX_AUTO_NEG, 0); | |
4059 | tp->mac_mode |= MAC_MODE_SEND_CONFIGS; | |
4060 | tw32_f(MAC_MODE, tp->mac_mode); | |
4061 | udelay(40); | |
4062 | ||
4063 | ret = ANEG_TIMER_ENAB; | |
4064 | ap->state = ANEG_STATE_RESTART; | |
4065 | ||
4066 | /* fallthru */ | |
4067 | case ANEG_STATE_RESTART: | |
4068 | delta = ap->cur_time - ap->link_time; | |
859a5887 | 4069 | if (delta > ANEG_STATE_SETTLE_TIME) |
1da177e4 | 4070 | ap->state = ANEG_STATE_ABILITY_DETECT_INIT; |
859a5887 | 4071 | else |
1da177e4 | 4072 | ret = ANEG_TIMER_ENAB; |
1da177e4 LT |
4073 | break; |
4074 | ||
4075 | case ANEG_STATE_DISABLE_LINK_OK: | |
4076 | ret = ANEG_DONE; | |
4077 | break; | |
4078 | ||
4079 | case ANEG_STATE_ABILITY_DETECT_INIT: | |
4080 | ap->flags &= ~(MR_TOGGLE_TX); | |
5be73b47 MC |
4081 | ap->txconfig = ANEG_CFG_FD; |
4082 | flowctrl = tg3_advert_flowctrl_1000X(tp->link_config.flowctrl); | |
4083 | if (flowctrl & ADVERTISE_1000XPAUSE) | |
4084 | ap->txconfig |= ANEG_CFG_PS1; | |
4085 | if (flowctrl & ADVERTISE_1000XPSE_ASYM) | |
4086 | ap->txconfig |= ANEG_CFG_PS2; | |
1da177e4 LT |
4087 | tw32(MAC_TX_AUTO_NEG, ap->txconfig); |
4088 | tp->mac_mode |= MAC_MODE_SEND_CONFIGS; | |
4089 | tw32_f(MAC_MODE, tp->mac_mode); | |
4090 | udelay(40); | |
4091 | ||
4092 | ap->state = ANEG_STATE_ABILITY_DETECT; | |
4093 | break; | |
4094 | ||
4095 | case ANEG_STATE_ABILITY_DETECT: | |
859a5887 | 4096 | if (ap->ability_match != 0 && ap->rxconfig != 0) |
1da177e4 | 4097 | ap->state = ANEG_STATE_ACK_DETECT_INIT; |
1da177e4 LT |
4098 | break; |
4099 | ||
4100 | case ANEG_STATE_ACK_DETECT_INIT: | |
4101 | ap->txconfig |= ANEG_CFG_ACK; | |
4102 | tw32(MAC_TX_AUTO_NEG, ap->txconfig); | |
4103 | tp->mac_mode |= MAC_MODE_SEND_CONFIGS; | |
4104 | tw32_f(MAC_MODE, tp->mac_mode); | |
4105 | udelay(40); | |
4106 | ||
4107 | ap->state = ANEG_STATE_ACK_DETECT; | |
4108 | ||
4109 | /* fallthru */ | |
4110 | case ANEG_STATE_ACK_DETECT: | |
4111 | if (ap->ack_match != 0) { | |
4112 | if ((ap->rxconfig & ~ANEG_CFG_ACK) == | |
4113 | (ap->ability_match_cfg & ~ANEG_CFG_ACK)) { | |
4114 | ap->state = ANEG_STATE_COMPLETE_ACK_INIT; | |
4115 | } else { | |
4116 | ap->state = ANEG_STATE_AN_ENABLE; | |
4117 | } | |
4118 | } else if (ap->ability_match != 0 && | |
4119 | ap->rxconfig == 0) { | |
4120 | ap->state = ANEG_STATE_AN_ENABLE; | |
4121 | } | |
4122 | break; | |
4123 | ||
4124 | case ANEG_STATE_COMPLETE_ACK_INIT: | |
4125 | if (ap->rxconfig & ANEG_CFG_INVAL) { | |
4126 | ret = ANEG_FAILED; | |
4127 | break; | |
4128 | } | |
4129 | ap->flags &= ~(MR_LP_ADV_FULL_DUPLEX | | |
4130 | MR_LP_ADV_HALF_DUPLEX | | |
4131 | MR_LP_ADV_SYM_PAUSE | | |
4132 | MR_LP_ADV_ASYM_PAUSE | | |
4133 | MR_LP_ADV_REMOTE_FAULT1 | | |
4134 | MR_LP_ADV_REMOTE_FAULT2 | | |
4135 | MR_LP_ADV_NEXT_PAGE | | |
4136 | MR_TOGGLE_RX | | |
4137 | MR_NP_RX); | |
4138 | if (ap->rxconfig & ANEG_CFG_FD) | |
4139 | ap->flags |= MR_LP_ADV_FULL_DUPLEX; | |
4140 | if (ap->rxconfig & ANEG_CFG_HD) | |
4141 | ap->flags |= MR_LP_ADV_HALF_DUPLEX; | |
4142 | if (ap->rxconfig & ANEG_CFG_PS1) | |
4143 | ap->flags |= MR_LP_ADV_SYM_PAUSE; | |
4144 | if (ap->rxconfig & ANEG_CFG_PS2) | |
4145 | ap->flags |= MR_LP_ADV_ASYM_PAUSE; | |
4146 | if (ap->rxconfig & ANEG_CFG_RF1) | |
4147 | ap->flags |= MR_LP_ADV_REMOTE_FAULT1; | |
4148 | if (ap->rxconfig & ANEG_CFG_RF2) | |
4149 | ap->flags |= MR_LP_ADV_REMOTE_FAULT2; | |
4150 | if (ap->rxconfig & ANEG_CFG_NP) | |
4151 | ap->flags |= MR_LP_ADV_NEXT_PAGE; | |
4152 | ||
4153 | ap->link_time = ap->cur_time; | |
4154 | ||
4155 | ap->flags ^= (MR_TOGGLE_TX); | |
4156 | if (ap->rxconfig & 0x0008) | |
4157 | ap->flags |= MR_TOGGLE_RX; | |
4158 | if (ap->rxconfig & ANEG_CFG_NP) | |
4159 | ap->flags |= MR_NP_RX; | |
4160 | ap->flags |= MR_PAGE_RX; | |
4161 | ||
4162 | ap->state = ANEG_STATE_COMPLETE_ACK; | |
4163 | ret = ANEG_TIMER_ENAB; | |
4164 | break; | |
4165 | ||
4166 | case ANEG_STATE_COMPLETE_ACK: | |
4167 | if (ap->ability_match != 0 && | |
4168 | ap->rxconfig == 0) { | |
4169 | ap->state = ANEG_STATE_AN_ENABLE; | |
4170 | break; | |
4171 | } | |
4172 | delta = ap->cur_time - ap->link_time; | |
4173 | if (delta > ANEG_STATE_SETTLE_TIME) { | |
4174 | if (!(ap->flags & (MR_LP_ADV_NEXT_PAGE))) { | |
4175 | ap->state = ANEG_STATE_IDLE_DETECT_INIT; | |
4176 | } else { | |
4177 | if ((ap->txconfig & ANEG_CFG_NP) == 0 && | |
4178 | !(ap->flags & MR_NP_RX)) { | |
4179 | ap->state = ANEG_STATE_IDLE_DETECT_INIT; | |
4180 | } else { | |
4181 | ret = ANEG_FAILED; | |
4182 | } | |
4183 | } | |
4184 | } | |
4185 | break; | |
4186 | ||
4187 | case ANEG_STATE_IDLE_DETECT_INIT: | |
4188 | ap->link_time = ap->cur_time; | |
4189 | tp->mac_mode &= ~MAC_MODE_SEND_CONFIGS; | |
4190 | tw32_f(MAC_MODE, tp->mac_mode); | |
4191 | udelay(40); | |
4192 | ||
4193 | ap->state = ANEG_STATE_IDLE_DETECT; | |
4194 | ret = ANEG_TIMER_ENAB; | |
4195 | break; | |
4196 | ||
4197 | case ANEG_STATE_IDLE_DETECT: | |
4198 | if (ap->ability_match != 0 && | |
4199 | ap->rxconfig == 0) { | |
4200 | ap->state = ANEG_STATE_AN_ENABLE; | |
4201 | break; | |
4202 | } | |
4203 | delta = ap->cur_time - ap->link_time; | |
4204 | if (delta > ANEG_STATE_SETTLE_TIME) { | |
4205 | /* XXX another gem from the Broadcom driver :( */ | |
4206 | ap->state = ANEG_STATE_LINK_OK; | |
4207 | } | |
4208 | break; | |
4209 | ||
4210 | case ANEG_STATE_LINK_OK: | |
4211 | ap->flags |= (MR_AN_COMPLETE | MR_LINK_OK); | |
4212 | ret = ANEG_DONE; | |
4213 | break; | |
4214 | ||
4215 | case ANEG_STATE_NEXT_PAGE_WAIT_INIT: | |
4216 | /* ??? unimplemented */ | |
4217 | break; | |
4218 | ||
4219 | case ANEG_STATE_NEXT_PAGE_WAIT: | |
4220 | /* ??? unimplemented */ | |
4221 | break; | |
4222 | ||
4223 | default: | |
4224 | ret = ANEG_FAILED; | |
4225 | break; | |
855e1111 | 4226 | } |
1da177e4 LT |
4227 | |
4228 | return ret; | |
4229 | } | |
4230 | ||
5be73b47 | 4231 | static int fiber_autoneg(struct tg3 *tp, u32 *txflags, u32 *rxflags) |
1da177e4 LT |
4232 | { |
4233 | int res = 0; | |
4234 | struct tg3_fiber_aneginfo aninfo; | |
4235 | int status = ANEG_FAILED; | |
4236 | unsigned int tick; | |
4237 | u32 tmp; | |
4238 | ||
4239 | tw32_f(MAC_TX_AUTO_NEG, 0); | |
4240 | ||
4241 | tmp = tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK; | |
4242 | tw32_f(MAC_MODE, tmp | MAC_MODE_PORT_MODE_GMII); | |
4243 | udelay(40); | |
4244 | ||
4245 | tw32_f(MAC_MODE, tp->mac_mode | MAC_MODE_SEND_CONFIGS); | |
4246 | udelay(40); | |
4247 | ||
4248 | memset(&aninfo, 0, sizeof(aninfo)); | |
4249 | aninfo.flags |= MR_AN_ENABLE; | |
4250 | aninfo.state = ANEG_STATE_UNKNOWN; | |
4251 | aninfo.cur_time = 0; | |
4252 | tick = 0; | |
4253 | while (++tick < 195000) { | |
4254 | status = tg3_fiber_aneg_smachine(tp, &aninfo); | |
4255 | if (status == ANEG_DONE || status == ANEG_FAILED) | |
4256 | break; | |
4257 | ||
4258 | udelay(1); | |
4259 | } | |
4260 | ||
4261 | tp->mac_mode &= ~MAC_MODE_SEND_CONFIGS; | |
4262 | tw32_f(MAC_MODE, tp->mac_mode); | |
4263 | udelay(40); | |
4264 | ||
5be73b47 MC |
4265 | *txflags = aninfo.txconfig; |
4266 | *rxflags = aninfo.flags; | |
1da177e4 LT |
4267 | |
4268 | if (status == ANEG_DONE && | |
4269 | (aninfo.flags & (MR_AN_COMPLETE | MR_LINK_OK | | |
4270 | MR_LP_ADV_FULL_DUPLEX))) | |
4271 | res = 1; | |
4272 | ||
4273 | return res; | |
4274 | } | |
4275 | ||
4276 | static void tg3_init_bcm8002(struct tg3 *tp) | |
4277 | { | |
4278 | u32 mac_status = tr32(MAC_STATUS); | |
4279 | int i; | |
4280 | ||
4281 | /* Reset when initting first time or we have a link. */ | |
63c3a66f | 4282 | if (tg3_flag(tp, INIT_COMPLETE) && |
1da177e4 LT |
4283 | !(mac_status & MAC_STATUS_PCS_SYNCED)) |
4284 | return; | |
4285 | ||
4286 | /* Set PLL lock range. */ | |
4287 | tg3_writephy(tp, 0x16, 0x8007); | |
4288 | ||
4289 | /* SW reset */ | |
4290 | tg3_writephy(tp, MII_BMCR, BMCR_RESET); | |
4291 | ||
4292 | /* Wait for reset to complete. */ | |
4293 | /* XXX schedule_timeout() ... */ | |
4294 | for (i = 0; i < 500; i++) | |
4295 | udelay(10); | |
4296 | ||
4297 | /* Config mode; select PMA/Ch 1 regs. */ | |
4298 | tg3_writephy(tp, 0x10, 0x8411); | |
4299 | ||
4300 | /* Enable auto-lock and comdet, select txclk for tx. */ | |
4301 | tg3_writephy(tp, 0x11, 0x0a10); | |
4302 | ||
4303 | tg3_writephy(tp, 0x18, 0x00a0); | |
4304 | tg3_writephy(tp, 0x16, 0x41ff); | |
4305 | ||
4306 | /* Assert and deassert POR. */ | |
4307 | tg3_writephy(tp, 0x13, 0x0400); | |
4308 | udelay(40); | |
4309 | tg3_writephy(tp, 0x13, 0x0000); | |
4310 | ||
4311 | tg3_writephy(tp, 0x11, 0x0a50); | |
4312 | udelay(40); | |
4313 | tg3_writephy(tp, 0x11, 0x0a10); | |
4314 | ||
4315 | /* Wait for signal to stabilize */ | |
4316 | /* XXX schedule_timeout() ... */ | |
4317 | for (i = 0; i < 15000; i++) | |
4318 | udelay(10); | |
4319 | ||
4320 | /* Deselect the channel register so we can read the PHYID | |
4321 | * later. | |
4322 | */ | |
4323 | tg3_writephy(tp, 0x10, 0x8011); | |
4324 | } | |
4325 | ||
4326 | static int tg3_setup_fiber_hw_autoneg(struct tg3 *tp, u32 mac_status) | |
4327 | { | |
82cd3d11 | 4328 | u16 flowctrl; |
1da177e4 LT |
4329 | u32 sg_dig_ctrl, sg_dig_status; |
4330 | u32 serdes_cfg, expected_sg_dig_ctrl; | |
4331 | int workaround, port_a; | |
4332 | int current_link_up; | |
4333 | ||
4334 | serdes_cfg = 0; | |
4335 | expected_sg_dig_ctrl = 0; | |
4336 | workaround = 0; | |
4337 | port_a = 1; | |
4338 | current_link_up = 0; | |
4339 | ||
4340 | if (tp->pci_chip_rev_id != CHIPREV_ID_5704_A0 && | |
4341 | tp->pci_chip_rev_id != CHIPREV_ID_5704_A1) { | |
4342 | workaround = 1; | |
4343 | if (tr32(TG3PCI_DUAL_MAC_CTRL) & DUAL_MAC_CTRL_ID) | |
4344 | port_a = 0; | |
4345 | ||
4346 | /* preserve bits 0-11,13,14 for signal pre-emphasis */ | |
4347 | /* preserve bits 20-23 for voltage regulator */ | |
4348 | serdes_cfg = tr32(MAC_SERDES_CFG) & 0x00f06fff; | |
4349 | } | |
4350 | ||
4351 | sg_dig_ctrl = tr32(SG_DIG_CTRL); | |
4352 | ||
4353 | if (tp->link_config.autoneg != AUTONEG_ENABLE) { | |
c98f6e3b | 4354 | if (sg_dig_ctrl & SG_DIG_USING_HW_AUTONEG) { |
1da177e4 LT |
4355 | if (workaround) { |
4356 | u32 val = serdes_cfg; | |
4357 | ||
4358 | if (port_a) | |
4359 | val |= 0xc010000; | |
4360 | else | |
4361 | val |= 0x4010000; | |
4362 | tw32_f(MAC_SERDES_CFG, val); | |
4363 | } | |
c98f6e3b MC |
4364 | |
4365 | tw32_f(SG_DIG_CTRL, SG_DIG_COMMON_SETUP); | |
1da177e4 LT |
4366 | } |
4367 | if (mac_status & MAC_STATUS_PCS_SYNCED) { | |
4368 | tg3_setup_flow_control(tp, 0, 0); | |
4369 | current_link_up = 1; | |
4370 | } | |
4371 | goto out; | |
4372 | } | |
4373 | ||
4374 | /* Want auto-negotiation. */ | |
c98f6e3b | 4375 | expected_sg_dig_ctrl = SG_DIG_USING_HW_AUTONEG | SG_DIG_COMMON_SETUP; |
1da177e4 | 4376 | |
82cd3d11 MC |
4377 | flowctrl = tg3_advert_flowctrl_1000X(tp->link_config.flowctrl); |
4378 | if (flowctrl & ADVERTISE_1000XPAUSE) | |
4379 | expected_sg_dig_ctrl |= SG_DIG_PAUSE_CAP; | |
4380 | if (flowctrl & ADVERTISE_1000XPSE_ASYM) | |
4381 | expected_sg_dig_ctrl |= SG_DIG_ASYM_PAUSE; | |
1da177e4 LT |
4382 | |
4383 | if (sg_dig_ctrl != expected_sg_dig_ctrl) { | |
f07e9af3 | 4384 | if ((tp->phy_flags & TG3_PHYFLG_PARALLEL_DETECT) && |
3d3ebe74 MC |
4385 | tp->serdes_counter && |
4386 | ((mac_status & (MAC_STATUS_PCS_SYNCED | | |
4387 | MAC_STATUS_RCVD_CFG)) == | |
4388 | MAC_STATUS_PCS_SYNCED)) { | |
4389 | tp->serdes_counter--; | |
4390 | current_link_up = 1; | |
4391 | goto out; | |
4392 | } | |
4393 | restart_autoneg: | |
1da177e4 LT |
4394 | if (workaround) |
4395 | tw32_f(MAC_SERDES_CFG, serdes_cfg | 0xc011000); | |
c98f6e3b | 4396 | tw32_f(SG_DIG_CTRL, expected_sg_dig_ctrl | SG_DIG_SOFT_RESET); |
1da177e4 LT |
4397 | udelay(5); |
4398 | tw32_f(SG_DIG_CTRL, expected_sg_dig_ctrl); | |
4399 | ||
3d3ebe74 | 4400 | tp->serdes_counter = SERDES_AN_TIMEOUT_5704S; |
f07e9af3 | 4401 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
1da177e4 LT |
4402 | } else if (mac_status & (MAC_STATUS_PCS_SYNCED | |
4403 | MAC_STATUS_SIGNAL_DET)) { | |
3d3ebe74 | 4404 | sg_dig_status = tr32(SG_DIG_STATUS); |
1da177e4 LT |
4405 | mac_status = tr32(MAC_STATUS); |
4406 | ||
c98f6e3b | 4407 | if ((sg_dig_status & SG_DIG_AUTONEG_COMPLETE) && |
1da177e4 | 4408 | (mac_status & MAC_STATUS_PCS_SYNCED)) { |
82cd3d11 MC |
4409 | u32 local_adv = 0, remote_adv = 0; |
4410 | ||
4411 | if (sg_dig_ctrl & SG_DIG_PAUSE_CAP) | |
4412 | local_adv |= ADVERTISE_1000XPAUSE; | |
4413 | if (sg_dig_ctrl & SG_DIG_ASYM_PAUSE) | |
4414 | local_adv |= ADVERTISE_1000XPSE_ASYM; | |
1da177e4 | 4415 | |
c98f6e3b | 4416 | if (sg_dig_status & SG_DIG_PARTNER_PAUSE_CAPABLE) |
82cd3d11 | 4417 | remote_adv |= LPA_1000XPAUSE; |
c98f6e3b | 4418 | if (sg_dig_status & SG_DIG_PARTNER_ASYM_PAUSE) |
82cd3d11 | 4419 | remote_adv |= LPA_1000XPAUSE_ASYM; |
1da177e4 LT |
4420 | |
4421 | tg3_setup_flow_control(tp, local_adv, remote_adv); | |
4422 | current_link_up = 1; | |
3d3ebe74 | 4423 | tp->serdes_counter = 0; |
f07e9af3 | 4424 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
c98f6e3b | 4425 | } else if (!(sg_dig_status & SG_DIG_AUTONEG_COMPLETE)) { |
3d3ebe74 MC |
4426 | if (tp->serdes_counter) |
4427 | tp->serdes_counter--; | |
1da177e4 LT |
4428 | else { |
4429 | if (workaround) { | |
4430 | u32 val = serdes_cfg; | |
4431 | ||
4432 | if (port_a) | |
4433 | val |= 0xc010000; | |
4434 | else | |
4435 | val |= 0x4010000; | |
4436 | ||
4437 | tw32_f(MAC_SERDES_CFG, val); | |
4438 | } | |
4439 | ||
c98f6e3b | 4440 | tw32_f(SG_DIG_CTRL, SG_DIG_COMMON_SETUP); |
1da177e4 LT |
4441 | udelay(40); |
4442 | ||
4443 | /* Link parallel detection - link is up */ | |
4444 | /* only if we have PCS_SYNC and not */ | |
4445 | /* receiving config code words */ | |
4446 | mac_status = tr32(MAC_STATUS); | |
4447 | if ((mac_status & MAC_STATUS_PCS_SYNCED) && | |
4448 | !(mac_status & MAC_STATUS_RCVD_CFG)) { | |
4449 | tg3_setup_flow_control(tp, 0, 0); | |
4450 | current_link_up = 1; | |
f07e9af3 MC |
4451 | tp->phy_flags |= |
4452 | TG3_PHYFLG_PARALLEL_DETECT; | |
3d3ebe74 MC |
4453 | tp->serdes_counter = |
4454 | SERDES_PARALLEL_DET_TIMEOUT; | |
4455 | } else | |
4456 | goto restart_autoneg; | |
1da177e4 LT |
4457 | } |
4458 | } | |
3d3ebe74 MC |
4459 | } else { |
4460 | tp->serdes_counter = SERDES_AN_TIMEOUT_5704S; | |
f07e9af3 | 4461 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
1da177e4 LT |
4462 | } |
4463 | ||
4464 | out: | |
4465 | return current_link_up; | |
4466 | } | |
4467 | ||
4468 | static int tg3_setup_fiber_by_hand(struct tg3 *tp, u32 mac_status) | |
4469 | { | |
4470 | int current_link_up = 0; | |
4471 | ||
5cf64b8a | 4472 | if (!(mac_status & MAC_STATUS_PCS_SYNCED)) |
1da177e4 | 4473 | goto out; |
1da177e4 LT |
4474 | |
4475 | if (tp->link_config.autoneg == AUTONEG_ENABLE) { | |
5be73b47 | 4476 | u32 txflags, rxflags; |
1da177e4 | 4477 | int i; |
6aa20a22 | 4478 | |
5be73b47 MC |
4479 | if (fiber_autoneg(tp, &txflags, &rxflags)) { |
4480 | u32 local_adv = 0, remote_adv = 0; | |
1da177e4 | 4481 | |
5be73b47 MC |
4482 | if (txflags & ANEG_CFG_PS1) |
4483 | local_adv |= ADVERTISE_1000XPAUSE; | |
4484 | if (txflags & ANEG_CFG_PS2) | |
4485 | local_adv |= ADVERTISE_1000XPSE_ASYM; | |
4486 | ||
4487 | if (rxflags & MR_LP_ADV_SYM_PAUSE) | |
4488 | remote_adv |= LPA_1000XPAUSE; | |
4489 | if (rxflags & MR_LP_ADV_ASYM_PAUSE) | |
4490 | remote_adv |= LPA_1000XPAUSE_ASYM; | |
1da177e4 LT |
4491 | |
4492 | tg3_setup_flow_control(tp, local_adv, remote_adv); | |
4493 | ||
1da177e4 LT |
4494 | current_link_up = 1; |
4495 | } | |
4496 | for (i = 0; i < 30; i++) { | |
4497 | udelay(20); | |
4498 | tw32_f(MAC_STATUS, | |
4499 | (MAC_STATUS_SYNC_CHANGED | | |
4500 | MAC_STATUS_CFG_CHANGED)); | |
4501 | udelay(40); | |
4502 | if ((tr32(MAC_STATUS) & | |
4503 | (MAC_STATUS_SYNC_CHANGED | | |
4504 | MAC_STATUS_CFG_CHANGED)) == 0) | |
4505 | break; | |
4506 | } | |
4507 | ||
4508 | mac_status = tr32(MAC_STATUS); | |
4509 | if (current_link_up == 0 && | |
4510 | (mac_status & MAC_STATUS_PCS_SYNCED) && | |
4511 | !(mac_status & MAC_STATUS_RCVD_CFG)) | |
4512 | current_link_up = 1; | |
4513 | } else { | |
5be73b47 MC |
4514 | tg3_setup_flow_control(tp, 0, 0); |
4515 | ||
1da177e4 LT |
4516 | /* Forcing 1000FD link up. */ |
4517 | current_link_up = 1; | |
1da177e4 LT |
4518 | |
4519 | tw32_f(MAC_MODE, (tp->mac_mode | MAC_MODE_SEND_CONFIGS)); | |
4520 | udelay(40); | |
e8f3f6ca MC |
4521 | |
4522 | tw32_f(MAC_MODE, tp->mac_mode); | |
4523 | udelay(40); | |
1da177e4 LT |
4524 | } |
4525 | ||
4526 | out: | |
4527 | return current_link_up; | |
4528 | } | |
4529 | ||
4530 | static int tg3_setup_fiber_phy(struct tg3 *tp, int force_reset) | |
4531 | { | |
4532 | u32 orig_pause_cfg; | |
4533 | u16 orig_active_speed; | |
4534 | u8 orig_active_duplex; | |
4535 | u32 mac_status; | |
4536 | int current_link_up; | |
4537 | int i; | |
4538 | ||
8d018621 | 4539 | orig_pause_cfg = tp->link_config.active_flowctrl; |
1da177e4 LT |
4540 | orig_active_speed = tp->link_config.active_speed; |
4541 | orig_active_duplex = tp->link_config.active_duplex; | |
4542 | ||
63c3a66f | 4543 | if (!tg3_flag(tp, HW_AUTONEG) && |
1da177e4 | 4544 | netif_carrier_ok(tp->dev) && |
63c3a66f | 4545 | tg3_flag(tp, INIT_COMPLETE)) { |
1da177e4 LT |
4546 | mac_status = tr32(MAC_STATUS); |
4547 | mac_status &= (MAC_STATUS_PCS_SYNCED | | |
4548 | MAC_STATUS_SIGNAL_DET | | |
4549 | MAC_STATUS_CFG_CHANGED | | |
4550 | MAC_STATUS_RCVD_CFG); | |
4551 | if (mac_status == (MAC_STATUS_PCS_SYNCED | | |
4552 | MAC_STATUS_SIGNAL_DET)) { | |
4553 | tw32_f(MAC_STATUS, (MAC_STATUS_SYNC_CHANGED | | |
4554 | MAC_STATUS_CFG_CHANGED)); | |
4555 | return 0; | |
4556 | } | |
4557 | } | |
4558 | ||
4559 | tw32_f(MAC_TX_AUTO_NEG, 0); | |
4560 | ||
4561 | tp->mac_mode &= ~(MAC_MODE_PORT_MODE_MASK | MAC_MODE_HALF_DUPLEX); | |
4562 | tp->mac_mode |= MAC_MODE_PORT_MODE_TBI; | |
4563 | tw32_f(MAC_MODE, tp->mac_mode); | |
4564 | udelay(40); | |
4565 | ||
79eb6904 | 4566 | if (tp->phy_id == TG3_PHY_ID_BCM8002) |
1da177e4 LT |
4567 | tg3_init_bcm8002(tp); |
4568 | ||
4569 | /* Enable link change event even when serdes polling. */ | |
4570 | tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED); | |
4571 | udelay(40); | |
4572 | ||
4573 | current_link_up = 0; | |
4574 | mac_status = tr32(MAC_STATUS); | |
4575 | ||
63c3a66f | 4576 | if (tg3_flag(tp, HW_AUTONEG)) |
1da177e4 LT |
4577 | current_link_up = tg3_setup_fiber_hw_autoneg(tp, mac_status); |
4578 | else | |
4579 | current_link_up = tg3_setup_fiber_by_hand(tp, mac_status); | |
4580 | ||
898a56f8 | 4581 | tp->napi[0].hw_status->status = |
1da177e4 | 4582 | (SD_STATUS_UPDATED | |
898a56f8 | 4583 | (tp->napi[0].hw_status->status & ~SD_STATUS_LINK_CHG)); |
1da177e4 LT |
4584 | |
4585 | for (i = 0; i < 100; i++) { | |
4586 | tw32_f(MAC_STATUS, (MAC_STATUS_SYNC_CHANGED | | |
4587 | MAC_STATUS_CFG_CHANGED)); | |
4588 | udelay(5); | |
4589 | if ((tr32(MAC_STATUS) & (MAC_STATUS_SYNC_CHANGED | | |
3d3ebe74 MC |
4590 | MAC_STATUS_CFG_CHANGED | |
4591 | MAC_STATUS_LNKSTATE_CHANGED)) == 0) | |
1da177e4 LT |
4592 | break; |
4593 | } | |
4594 | ||
4595 | mac_status = tr32(MAC_STATUS); | |
4596 | if ((mac_status & MAC_STATUS_PCS_SYNCED) == 0) { | |
4597 | current_link_up = 0; | |
3d3ebe74 MC |
4598 | if (tp->link_config.autoneg == AUTONEG_ENABLE && |
4599 | tp->serdes_counter == 0) { | |
1da177e4 LT |
4600 | tw32_f(MAC_MODE, (tp->mac_mode | |
4601 | MAC_MODE_SEND_CONFIGS)); | |
4602 | udelay(1); | |
4603 | tw32_f(MAC_MODE, tp->mac_mode); | |
4604 | } | |
4605 | } | |
4606 | ||
4607 | if (current_link_up == 1) { | |
4608 | tp->link_config.active_speed = SPEED_1000; | |
4609 | tp->link_config.active_duplex = DUPLEX_FULL; | |
4610 | tw32(MAC_LED_CTRL, (tp->led_ctrl | | |
4611 | LED_CTRL_LNKLED_OVERRIDE | | |
4612 | LED_CTRL_1000MBPS_ON)); | |
4613 | } else { | |
4614 | tp->link_config.active_speed = SPEED_INVALID; | |
4615 | tp->link_config.active_duplex = DUPLEX_INVALID; | |
4616 | tw32(MAC_LED_CTRL, (tp->led_ctrl | | |
4617 | LED_CTRL_LNKLED_OVERRIDE | | |
4618 | LED_CTRL_TRAFFIC_OVERRIDE)); | |
4619 | } | |
4620 | ||
4621 | if (current_link_up != netif_carrier_ok(tp->dev)) { | |
4622 | if (current_link_up) | |
4623 | netif_carrier_on(tp->dev); | |
4624 | else | |
4625 | netif_carrier_off(tp->dev); | |
4626 | tg3_link_report(tp); | |
4627 | } else { | |
8d018621 | 4628 | u32 now_pause_cfg = tp->link_config.active_flowctrl; |
1da177e4 LT |
4629 | if (orig_pause_cfg != now_pause_cfg || |
4630 | orig_active_speed != tp->link_config.active_speed || | |
4631 | orig_active_duplex != tp->link_config.active_duplex) | |
4632 | tg3_link_report(tp); | |
4633 | } | |
4634 | ||
4635 | return 0; | |
4636 | } | |
4637 | ||
747e8f8b MC |
4638 | static int tg3_setup_fiber_mii_phy(struct tg3 *tp, int force_reset) |
4639 | { | |
4640 | int current_link_up, err = 0; | |
4641 | u32 bmsr, bmcr; | |
4642 | u16 current_speed; | |
4643 | u8 current_duplex; | |
ef167e27 | 4644 | u32 local_adv, remote_adv; |
747e8f8b MC |
4645 | |
4646 | tp->mac_mode |= MAC_MODE_PORT_MODE_GMII; | |
4647 | tw32_f(MAC_MODE, tp->mac_mode); | |
4648 | udelay(40); | |
4649 | ||
4650 | tw32(MAC_EVENT, 0); | |
4651 | ||
4652 | tw32_f(MAC_STATUS, | |
4653 | (MAC_STATUS_SYNC_CHANGED | | |
4654 | MAC_STATUS_CFG_CHANGED | | |
4655 | MAC_STATUS_MI_COMPLETION | | |
4656 | MAC_STATUS_LNKSTATE_CHANGED)); | |
4657 | udelay(40); | |
4658 | ||
4659 | if (force_reset) | |
4660 | tg3_phy_reset(tp); | |
4661 | ||
4662 | current_link_up = 0; | |
4663 | current_speed = SPEED_INVALID; | |
4664 | current_duplex = DUPLEX_INVALID; | |
4665 | ||
4666 | err |= tg3_readphy(tp, MII_BMSR, &bmsr); | |
4667 | err |= tg3_readphy(tp, MII_BMSR, &bmsr); | |
d4d2c558 MC |
4668 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) { |
4669 | if (tr32(MAC_TX_STATUS) & TX_STATUS_LINK_UP) | |
4670 | bmsr |= BMSR_LSTATUS; | |
4671 | else | |
4672 | bmsr &= ~BMSR_LSTATUS; | |
4673 | } | |
747e8f8b MC |
4674 | |
4675 | err |= tg3_readphy(tp, MII_BMCR, &bmcr); | |
4676 | ||
4677 | if ((tp->link_config.autoneg == AUTONEG_ENABLE) && !force_reset && | |
f07e9af3 | 4678 | (tp->phy_flags & TG3_PHYFLG_PARALLEL_DETECT)) { |
747e8f8b MC |
4679 | /* do nothing, just check for link up at the end */ |
4680 | } else if (tp->link_config.autoneg == AUTONEG_ENABLE) { | |
4681 | u32 adv, new_adv; | |
4682 | ||
4683 | err |= tg3_readphy(tp, MII_ADVERTISE, &adv); | |
4684 | new_adv = adv & ~(ADVERTISE_1000XFULL | ADVERTISE_1000XHALF | | |
4685 | ADVERTISE_1000XPAUSE | | |
4686 | ADVERTISE_1000XPSE_ASYM | | |
4687 | ADVERTISE_SLCT); | |
4688 | ||
ba4d07a8 | 4689 | new_adv |= tg3_advert_flowctrl_1000X(tp->link_config.flowctrl); |
747e8f8b MC |
4690 | |
4691 | if (tp->link_config.advertising & ADVERTISED_1000baseT_Half) | |
4692 | new_adv |= ADVERTISE_1000XHALF; | |
4693 | if (tp->link_config.advertising & ADVERTISED_1000baseT_Full) | |
4694 | new_adv |= ADVERTISE_1000XFULL; | |
4695 | ||
4696 | if ((new_adv != adv) || !(bmcr & BMCR_ANENABLE)) { | |
4697 | tg3_writephy(tp, MII_ADVERTISE, new_adv); | |
4698 | bmcr |= BMCR_ANENABLE | BMCR_ANRESTART; | |
4699 | tg3_writephy(tp, MII_BMCR, bmcr); | |
4700 | ||
4701 | tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED); | |
3d3ebe74 | 4702 | tp->serdes_counter = SERDES_AN_TIMEOUT_5714S; |
f07e9af3 | 4703 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
747e8f8b MC |
4704 | |
4705 | return err; | |
4706 | } | |
4707 | } else { | |
4708 | u32 new_bmcr; | |
4709 | ||
4710 | bmcr &= ~BMCR_SPEED1000; | |
4711 | new_bmcr = bmcr & ~(BMCR_ANENABLE | BMCR_FULLDPLX); | |
4712 | ||
4713 | if (tp->link_config.duplex == DUPLEX_FULL) | |
4714 | new_bmcr |= BMCR_FULLDPLX; | |
4715 | ||
4716 | if (new_bmcr != bmcr) { | |
4717 | /* BMCR_SPEED1000 is a reserved bit that needs | |
4718 | * to be set on write. | |
4719 | */ | |
4720 | new_bmcr |= BMCR_SPEED1000; | |
4721 | ||
4722 | /* Force a linkdown */ | |
4723 | if (netif_carrier_ok(tp->dev)) { | |
4724 | u32 adv; | |
4725 | ||
4726 | err |= tg3_readphy(tp, MII_ADVERTISE, &adv); | |
4727 | adv &= ~(ADVERTISE_1000XFULL | | |
4728 | ADVERTISE_1000XHALF | | |
4729 | ADVERTISE_SLCT); | |
4730 | tg3_writephy(tp, MII_ADVERTISE, adv); | |
4731 | tg3_writephy(tp, MII_BMCR, bmcr | | |
4732 | BMCR_ANRESTART | | |
4733 | BMCR_ANENABLE); | |
4734 | udelay(10); | |
4735 | netif_carrier_off(tp->dev); | |
4736 | } | |
4737 | tg3_writephy(tp, MII_BMCR, new_bmcr); | |
4738 | bmcr = new_bmcr; | |
4739 | err |= tg3_readphy(tp, MII_BMSR, &bmsr); | |
4740 | err |= tg3_readphy(tp, MII_BMSR, &bmsr); | |
d4d2c558 MC |
4741 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == |
4742 | ASIC_REV_5714) { | |
4743 | if (tr32(MAC_TX_STATUS) & TX_STATUS_LINK_UP) | |
4744 | bmsr |= BMSR_LSTATUS; | |
4745 | else | |
4746 | bmsr &= ~BMSR_LSTATUS; | |
4747 | } | |
f07e9af3 | 4748 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
747e8f8b MC |
4749 | } |
4750 | } | |
4751 | ||
4752 | if (bmsr & BMSR_LSTATUS) { | |
4753 | current_speed = SPEED_1000; | |
4754 | current_link_up = 1; | |
4755 | if (bmcr & BMCR_FULLDPLX) | |
4756 | current_duplex = DUPLEX_FULL; | |
4757 | else | |
4758 | current_duplex = DUPLEX_HALF; | |
4759 | ||
ef167e27 MC |
4760 | local_adv = 0; |
4761 | remote_adv = 0; | |
4762 | ||
747e8f8b | 4763 | if (bmcr & BMCR_ANENABLE) { |
ef167e27 | 4764 | u32 common; |
747e8f8b MC |
4765 | |
4766 | err |= tg3_readphy(tp, MII_ADVERTISE, &local_adv); | |
4767 | err |= tg3_readphy(tp, MII_LPA, &remote_adv); | |
4768 | common = local_adv & remote_adv; | |
4769 | if (common & (ADVERTISE_1000XHALF | | |
4770 | ADVERTISE_1000XFULL)) { | |
4771 | if (common & ADVERTISE_1000XFULL) | |
4772 | current_duplex = DUPLEX_FULL; | |
4773 | else | |
4774 | current_duplex = DUPLEX_HALF; | |
63c3a66f | 4775 | } else if (!tg3_flag(tp, 5780_CLASS)) { |
57d8b880 | 4776 | /* Link is up via parallel detect */ |
859a5887 | 4777 | } else { |
747e8f8b | 4778 | current_link_up = 0; |
859a5887 | 4779 | } |
747e8f8b MC |
4780 | } |
4781 | } | |
4782 | ||
ef167e27 MC |
4783 | if (current_link_up == 1 && current_duplex == DUPLEX_FULL) |
4784 | tg3_setup_flow_control(tp, local_adv, remote_adv); | |
4785 | ||
747e8f8b MC |
4786 | tp->mac_mode &= ~MAC_MODE_HALF_DUPLEX; |
4787 | if (tp->link_config.active_duplex == DUPLEX_HALF) | |
4788 | tp->mac_mode |= MAC_MODE_HALF_DUPLEX; | |
4789 | ||
4790 | tw32_f(MAC_MODE, tp->mac_mode); | |
4791 | udelay(40); | |
4792 | ||
4793 | tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED); | |
4794 | ||
4795 | tp->link_config.active_speed = current_speed; | |
4796 | tp->link_config.active_duplex = current_duplex; | |
4797 | ||
4798 | if (current_link_up != netif_carrier_ok(tp->dev)) { | |
4799 | if (current_link_up) | |
4800 | netif_carrier_on(tp->dev); | |
4801 | else { | |
4802 | netif_carrier_off(tp->dev); | |
f07e9af3 | 4803 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
747e8f8b MC |
4804 | } |
4805 | tg3_link_report(tp); | |
4806 | } | |
4807 | return err; | |
4808 | } | |
4809 | ||
4810 | static void tg3_serdes_parallel_detect(struct tg3 *tp) | |
4811 | { | |
3d3ebe74 | 4812 | if (tp->serdes_counter) { |
747e8f8b | 4813 | /* Give autoneg time to complete. */ |
3d3ebe74 | 4814 | tp->serdes_counter--; |
747e8f8b MC |
4815 | return; |
4816 | } | |
c6cdf436 | 4817 | |
747e8f8b MC |
4818 | if (!netif_carrier_ok(tp->dev) && |
4819 | (tp->link_config.autoneg == AUTONEG_ENABLE)) { | |
4820 | u32 bmcr; | |
4821 | ||
4822 | tg3_readphy(tp, MII_BMCR, &bmcr); | |
4823 | if (bmcr & BMCR_ANENABLE) { | |
4824 | u32 phy1, phy2; | |
4825 | ||
4826 | /* Select shadow register 0x1f */ | |
f08aa1a8 MC |
4827 | tg3_writephy(tp, MII_TG3_MISC_SHDW, 0x7c00); |
4828 | tg3_readphy(tp, MII_TG3_MISC_SHDW, &phy1); | |
747e8f8b MC |
4829 | |
4830 | /* Select expansion interrupt status register */ | |
f08aa1a8 MC |
4831 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, |
4832 | MII_TG3_DSP_EXP1_INT_STAT); | |
4833 | tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &phy2); | |
4834 | tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &phy2); | |
747e8f8b MC |
4835 | |
4836 | if ((phy1 & 0x10) && !(phy2 & 0x20)) { | |
4837 | /* We have signal detect and not receiving | |
4838 | * config code words, link is up by parallel | |
4839 | * detection. | |
4840 | */ | |
4841 | ||
4842 | bmcr &= ~BMCR_ANENABLE; | |
4843 | bmcr |= BMCR_SPEED1000 | BMCR_FULLDPLX; | |
4844 | tg3_writephy(tp, MII_BMCR, bmcr); | |
f07e9af3 | 4845 | tp->phy_flags |= TG3_PHYFLG_PARALLEL_DETECT; |
747e8f8b MC |
4846 | } |
4847 | } | |
859a5887 MC |
4848 | } else if (netif_carrier_ok(tp->dev) && |
4849 | (tp->link_config.autoneg == AUTONEG_ENABLE) && | |
f07e9af3 | 4850 | (tp->phy_flags & TG3_PHYFLG_PARALLEL_DETECT)) { |
747e8f8b MC |
4851 | u32 phy2; |
4852 | ||
4853 | /* Select expansion interrupt status register */ | |
f08aa1a8 MC |
4854 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, |
4855 | MII_TG3_DSP_EXP1_INT_STAT); | |
4856 | tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &phy2); | |
747e8f8b MC |
4857 | if (phy2 & 0x20) { |
4858 | u32 bmcr; | |
4859 | ||
4860 | /* Config code words received, turn on autoneg. */ | |
4861 | tg3_readphy(tp, MII_BMCR, &bmcr); | |
4862 | tg3_writephy(tp, MII_BMCR, bmcr | BMCR_ANENABLE); | |
4863 | ||
f07e9af3 | 4864 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
747e8f8b MC |
4865 | |
4866 | } | |
4867 | } | |
4868 | } | |
4869 | ||
1da177e4 LT |
4870 | static int tg3_setup_phy(struct tg3 *tp, int force_reset) |
4871 | { | |
f2096f94 | 4872 | u32 val; |
1da177e4 LT |
4873 | int err; |
4874 | ||
f07e9af3 | 4875 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) |
1da177e4 | 4876 | err = tg3_setup_fiber_phy(tp, force_reset); |
f07e9af3 | 4877 | else if (tp->phy_flags & TG3_PHYFLG_MII_SERDES) |
747e8f8b | 4878 | err = tg3_setup_fiber_mii_phy(tp, force_reset); |
859a5887 | 4879 | else |
1da177e4 | 4880 | err = tg3_setup_copper_phy(tp, force_reset); |
1da177e4 | 4881 | |
bcb37f6c | 4882 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5784_AX) { |
f2096f94 | 4883 | u32 scale; |
aa6c91fe MC |
4884 | |
4885 | val = tr32(TG3_CPMU_CLCK_STAT) & CPMU_CLCK_STAT_MAC_CLCK_MASK; | |
4886 | if (val == CPMU_CLCK_STAT_MAC_CLCK_62_5) | |
4887 | scale = 65; | |
4888 | else if (val == CPMU_CLCK_STAT_MAC_CLCK_6_25) | |
4889 | scale = 6; | |
4890 | else | |
4891 | scale = 12; | |
4892 | ||
4893 | val = tr32(GRC_MISC_CFG) & ~GRC_MISC_CFG_PRESCALAR_MASK; | |
4894 | val |= (scale << GRC_MISC_CFG_PRESCALAR_SHIFT); | |
4895 | tw32(GRC_MISC_CFG, val); | |
4896 | } | |
4897 | ||
f2096f94 MC |
4898 | val = (2 << TX_LENGTHS_IPG_CRS_SHIFT) | |
4899 | (6 << TX_LENGTHS_IPG_SHIFT); | |
4900 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) | |
4901 | val |= tr32(MAC_TX_LENGTHS) & | |
4902 | (TX_LENGTHS_JMB_FRM_LEN_MSK | | |
4903 | TX_LENGTHS_CNT_DWN_VAL_MSK); | |
4904 | ||
1da177e4 LT |
4905 | if (tp->link_config.active_speed == SPEED_1000 && |
4906 | tp->link_config.active_duplex == DUPLEX_HALF) | |
f2096f94 MC |
4907 | tw32(MAC_TX_LENGTHS, val | |
4908 | (0xff << TX_LENGTHS_SLOT_TIME_SHIFT)); | |
1da177e4 | 4909 | else |
f2096f94 MC |
4910 | tw32(MAC_TX_LENGTHS, val | |
4911 | (32 << TX_LENGTHS_SLOT_TIME_SHIFT)); | |
1da177e4 | 4912 | |
63c3a66f | 4913 | if (!tg3_flag(tp, 5705_PLUS)) { |
1da177e4 LT |
4914 | if (netif_carrier_ok(tp->dev)) { |
4915 | tw32(HOSTCC_STAT_COAL_TICKS, | |
15f9850d | 4916 | tp->coal.stats_block_coalesce_usecs); |
1da177e4 LT |
4917 | } else { |
4918 | tw32(HOSTCC_STAT_COAL_TICKS, 0); | |
4919 | } | |
4920 | } | |
4921 | ||
63c3a66f | 4922 | if (tg3_flag(tp, ASPM_WORKAROUND)) { |
f2096f94 | 4923 | val = tr32(PCIE_PWR_MGMT_THRESH); |
8ed5d97e MC |
4924 | if (!netif_carrier_ok(tp->dev)) |
4925 | val = (val & ~PCIE_PWR_MGMT_L1_THRESH_MSK) | | |
4926 | tp->pwrmgmt_thresh; | |
4927 | else | |
4928 | val |= PCIE_PWR_MGMT_L1_THRESH_MSK; | |
4929 | tw32(PCIE_PWR_MGMT_THRESH, val); | |
4930 | } | |
4931 | ||
1da177e4 LT |
4932 | return err; |
4933 | } | |
4934 | ||
66cfd1bd MC |
4935 | static inline int tg3_irq_sync(struct tg3 *tp) |
4936 | { | |
4937 | return tp->irq_sync; | |
4938 | } | |
4939 | ||
97bd8e49 MC |
4940 | static inline void tg3_rd32_loop(struct tg3 *tp, u32 *dst, u32 off, u32 len) |
4941 | { | |
4942 | int i; | |
4943 | ||
4944 | dst = (u32 *)((u8 *)dst + off); | |
4945 | for (i = 0; i < len; i += sizeof(u32)) | |
4946 | *dst++ = tr32(off + i); | |
4947 | } | |
4948 | ||
4949 | static void tg3_dump_legacy_regs(struct tg3 *tp, u32 *regs) | |
4950 | { | |
4951 | tg3_rd32_loop(tp, regs, TG3PCI_VENDOR, 0xb0); | |
4952 | tg3_rd32_loop(tp, regs, MAILBOX_INTERRUPT_0, 0x200); | |
4953 | tg3_rd32_loop(tp, regs, MAC_MODE, 0x4f0); | |
4954 | tg3_rd32_loop(tp, regs, SNDDATAI_MODE, 0xe0); | |
4955 | tg3_rd32_loop(tp, regs, SNDDATAC_MODE, 0x04); | |
4956 | tg3_rd32_loop(tp, regs, SNDBDS_MODE, 0x80); | |
4957 | tg3_rd32_loop(tp, regs, SNDBDI_MODE, 0x48); | |
4958 | tg3_rd32_loop(tp, regs, SNDBDC_MODE, 0x04); | |
4959 | tg3_rd32_loop(tp, regs, RCVLPC_MODE, 0x20); | |
4960 | tg3_rd32_loop(tp, regs, RCVLPC_SELLST_BASE, 0x15c); | |
4961 | tg3_rd32_loop(tp, regs, RCVDBDI_MODE, 0x0c); | |
4962 | tg3_rd32_loop(tp, regs, RCVDBDI_JUMBO_BD, 0x3c); | |
4963 | tg3_rd32_loop(tp, regs, RCVDBDI_BD_PROD_IDX_0, 0x44); | |
4964 | tg3_rd32_loop(tp, regs, RCVDCC_MODE, 0x04); | |
4965 | tg3_rd32_loop(tp, regs, RCVBDI_MODE, 0x20); | |
4966 | tg3_rd32_loop(tp, regs, RCVCC_MODE, 0x14); | |
4967 | tg3_rd32_loop(tp, regs, RCVLSC_MODE, 0x08); | |
4968 | tg3_rd32_loop(tp, regs, MBFREE_MODE, 0x08); | |
4969 | tg3_rd32_loop(tp, regs, HOSTCC_MODE, 0x100); | |
4970 | ||
63c3a66f | 4971 | if (tg3_flag(tp, SUPPORT_MSIX)) |
97bd8e49 MC |
4972 | tg3_rd32_loop(tp, regs, HOSTCC_RXCOL_TICKS_VEC1, 0x180); |
4973 | ||
4974 | tg3_rd32_loop(tp, regs, MEMARB_MODE, 0x10); | |
4975 | tg3_rd32_loop(tp, regs, BUFMGR_MODE, 0x58); | |
4976 | tg3_rd32_loop(tp, regs, RDMAC_MODE, 0x08); | |
4977 | tg3_rd32_loop(tp, regs, WDMAC_MODE, 0x08); | |
4978 | tg3_rd32_loop(tp, regs, RX_CPU_MODE, 0x04); | |
4979 | tg3_rd32_loop(tp, regs, RX_CPU_STATE, 0x04); | |
4980 | tg3_rd32_loop(tp, regs, RX_CPU_PGMCTR, 0x04); | |
4981 | tg3_rd32_loop(tp, regs, RX_CPU_HWBKPT, 0x04); | |
4982 | ||
63c3a66f | 4983 | if (!tg3_flag(tp, 5705_PLUS)) { |
97bd8e49 MC |
4984 | tg3_rd32_loop(tp, regs, TX_CPU_MODE, 0x04); |
4985 | tg3_rd32_loop(tp, regs, TX_CPU_STATE, 0x04); | |
4986 | tg3_rd32_loop(tp, regs, TX_CPU_PGMCTR, 0x04); | |
4987 | } | |
4988 | ||
4989 | tg3_rd32_loop(tp, regs, GRCMBOX_INTERRUPT_0, 0x110); | |
4990 | tg3_rd32_loop(tp, regs, FTQ_RESET, 0x120); | |
4991 | tg3_rd32_loop(tp, regs, MSGINT_MODE, 0x0c); | |
4992 | tg3_rd32_loop(tp, regs, DMAC_MODE, 0x04); | |
4993 | tg3_rd32_loop(tp, regs, GRC_MODE, 0x4c); | |
4994 | ||
63c3a66f | 4995 | if (tg3_flag(tp, NVRAM)) |
97bd8e49 MC |
4996 | tg3_rd32_loop(tp, regs, NVRAM_CMD, 0x24); |
4997 | } | |
4998 | ||
4999 | static void tg3_dump_state(struct tg3 *tp) | |
5000 | { | |
5001 | int i; | |
5002 | u32 *regs; | |
5003 | ||
5004 | regs = kzalloc(TG3_REG_BLK_SIZE, GFP_ATOMIC); | |
5005 | if (!regs) { | |
5006 | netdev_err(tp->dev, "Failed allocating register dump buffer\n"); | |
5007 | return; | |
5008 | } | |
5009 | ||
63c3a66f | 5010 | if (tg3_flag(tp, PCI_EXPRESS)) { |
97bd8e49 MC |
5011 | /* Read up to but not including private PCI registers */ |
5012 | for (i = 0; i < TG3_PCIE_TLDLPL_PORT; i += sizeof(u32)) | |
5013 | regs[i / sizeof(u32)] = tr32(i); | |
5014 | } else | |
5015 | tg3_dump_legacy_regs(tp, regs); | |
5016 | ||
5017 | for (i = 0; i < TG3_REG_BLK_SIZE / sizeof(u32); i += 4) { | |
5018 | if (!regs[i + 0] && !regs[i + 1] && | |
5019 | !regs[i + 2] && !regs[i + 3]) | |
5020 | continue; | |
5021 | ||
5022 | netdev_err(tp->dev, "0x%08x: 0x%08x, 0x%08x, 0x%08x, 0x%08x\n", | |
5023 | i * 4, | |
5024 | regs[i + 0], regs[i + 1], regs[i + 2], regs[i + 3]); | |
5025 | } | |
5026 | ||
5027 | kfree(regs); | |
5028 | ||
5029 | for (i = 0; i < tp->irq_cnt; i++) { | |
5030 | struct tg3_napi *tnapi = &tp->napi[i]; | |
5031 | ||
5032 | /* SW status block */ | |
5033 | netdev_err(tp->dev, | |
5034 | "%d: Host status block [%08x:%08x:(%04x:%04x:%04x):(%04x:%04x)]\n", | |
5035 | i, | |
5036 | tnapi->hw_status->status, | |
5037 | tnapi->hw_status->status_tag, | |
5038 | tnapi->hw_status->rx_jumbo_consumer, | |
5039 | tnapi->hw_status->rx_consumer, | |
5040 | tnapi->hw_status->rx_mini_consumer, | |
5041 | tnapi->hw_status->idx[0].rx_producer, | |
5042 | tnapi->hw_status->idx[0].tx_consumer); | |
5043 | ||
5044 | netdev_err(tp->dev, | |
5045 | "%d: NAPI info [%08x:%08x:(%04x:%04x:%04x):%04x:(%04x:%04x:%04x:%04x)]\n", | |
5046 | i, | |
5047 | tnapi->last_tag, tnapi->last_irq_tag, | |
5048 | tnapi->tx_prod, tnapi->tx_cons, tnapi->tx_pending, | |
5049 | tnapi->rx_rcb_ptr, | |
5050 | tnapi->prodring.rx_std_prod_idx, | |
5051 | tnapi->prodring.rx_std_cons_idx, | |
5052 | tnapi->prodring.rx_jmb_prod_idx, | |
5053 | tnapi->prodring.rx_jmb_cons_idx); | |
5054 | } | |
5055 | } | |
5056 | ||
df3e6548 MC |
5057 | /* This is called whenever we suspect that the system chipset is re- |
5058 | * ordering the sequence of MMIO to the tx send mailbox. The symptom | |
5059 | * is bogus tx completions. We try to recover by setting the | |
5060 | * TG3_FLAG_MBOX_WRITE_REORDER flag and resetting the chip later | |
5061 | * in the workqueue. | |
5062 | */ | |
5063 | static void tg3_tx_recover(struct tg3 *tp) | |
5064 | { | |
63c3a66f | 5065 | BUG_ON(tg3_flag(tp, MBOX_WRITE_REORDER) || |
df3e6548 MC |
5066 | tp->write32_tx_mbox == tg3_write_indirect_mbox); |
5067 | ||
5129c3a3 MC |
5068 | netdev_warn(tp->dev, |
5069 | "The system may be re-ordering memory-mapped I/O " | |
5070 | "cycles to the network device, attempting to recover. " | |
5071 | "Please report the problem to the driver maintainer " | |
5072 | "and include system chipset information.\n"); | |
df3e6548 MC |
5073 | |
5074 | spin_lock(&tp->lock); | |
63c3a66f | 5075 | tg3_flag_set(tp, TX_RECOVERY_PENDING); |
df3e6548 MC |
5076 | spin_unlock(&tp->lock); |
5077 | } | |
5078 | ||
f3f3f27e | 5079 | static inline u32 tg3_tx_avail(struct tg3_napi *tnapi) |
1b2a7205 | 5080 | { |
f65aac16 MC |
5081 | /* Tell compiler to fetch tx indices from memory. */ |
5082 | barrier(); | |
f3f3f27e MC |
5083 | return tnapi->tx_pending - |
5084 | ((tnapi->tx_prod - tnapi->tx_cons) & (TG3_TX_RING_SIZE - 1)); | |
1b2a7205 MC |
5085 | } |
5086 | ||
1da177e4 LT |
5087 | /* Tigon3 never reports partial packet sends. So we do not |
5088 | * need special logic to handle SKBs that have not had all | |
5089 | * of their frags sent yet, like SunGEM does. | |
5090 | */ | |
17375d25 | 5091 | static void tg3_tx(struct tg3_napi *tnapi) |
1da177e4 | 5092 | { |
17375d25 | 5093 | struct tg3 *tp = tnapi->tp; |
898a56f8 | 5094 | u32 hw_idx = tnapi->hw_status->idx[0].tx_consumer; |
f3f3f27e | 5095 | u32 sw_idx = tnapi->tx_cons; |
fe5f5787 MC |
5096 | struct netdev_queue *txq; |
5097 | int index = tnapi - tp->napi; | |
5098 | ||
63c3a66f | 5099 | if (tg3_flag(tp, ENABLE_TSS)) |
fe5f5787 MC |
5100 | index--; |
5101 | ||
5102 | txq = netdev_get_tx_queue(tp->dev, index); | |
1da177e4 LT |
5103 | |
5104 | while (sw_idx != hw_idx) { | |
df8944cf | 5105 | struct tg3_tx_ring_info *ri = &tnapi->tx_buffers[sw_idx]; |
1da177e4 | 5106 | struct sk_buff *skb = ri->skb; |
df3e6548 MC |
5107 | int i, tx_bug = 0; |
5108 | ||
5109 | if (unlikely(skb == NULL)) { | |
5110 | tg3_tx_recover(tp); | |
5111 | return; | |
5112 | } | |
1da177e4 | 5113 | |
f4188d8a | 5114 | pci_unmap_single(tp->pdev, |
4e5e4f0d | 5115 | dma_unmap_addr(ri, mapping), |
f4188d8a AD |
5116 | skb_headlen(skb), |
5117 | PCI_DMA_TODEVICE); | |
1da177e4 LT |
5118 | |
5119 | ri->skb = NULL; | |
5120 | ||
e01ee14d MC |
5121 | while (ri->fragmented) { |
5122 | ri->fragmented = false; | |
5123 | sw_idx = NEXT_TX(sw_idx); | |
5124 | ri = &tnapi->tx_buffers[sw_idx]; | |
5125 | } | |
5126 | ||
1da177e4 LT |
5127 | sw_idx = NEXT_TX(sw_idx); |
5128 | ||
5129 | for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { | |
f3f3f27e | 5130 | ri = &tnapi->tx_buffers[sw_idx]; |
df3e6548 MC |
5131 | if (unlikely(ri->skb != NULL || sw_idx == hw_idx)) |
5132 | tx_bug = 1; | |
f4188d8a AD |
5133 | |
5134 | pci_unmap_page(tp->pdev, | |
4e5e4f0d | 5135 | dma_unmap_addr(ri, mapping), |
f4188d8a AD |
5136 | skb_shinfo(skb)->frags[i].size, |
5137 | PCI_DMA_TODEVICE); | |
e01ee14d MC |
5138 | |
5139 | while (ri->fragmented) { | |
5140 | ri->fragmented = false; | |
5141 | sw_idx = NEXT_TX(sw_idx); | |
5142 | ri = &tnapi->tx_buffers[sw_idx]; | |
5143 | } | |
5144 | ||
1da177e4 LT |
5145 | sw_idx = NEXT_TX(sw_idx); |
5146 | } | |
5147 | ||
f47c11ee | 5148 | dev_kfree_skb(skb); |
df3e6548 MC |
5149 | |
5150 | if (unlikely(tx_bug)) { | |
5151 | tg3_tx_recover(tp); | |
5152 | return; | |
5153 | } | |
1da177e4 LT |
5154 | } |
5155 | ||
f3f3f27e | 5156 | tnapi->tx_cons = sw_idx; |
1da177e4 | 5157 | |
1b2a7205 MC |
5158 | /* Need to make the tx_cons update visible to tg3_start_xmit() |
5159 | * before checking for netif_queue_stopped(). Without the | |
5160 | * memory barrier, there is a small possibility that tg3_start_xmit() | |
5161 | * will miss it and cause the queue to be stopped forever. | |
5162 | */ | |
5163 | smp_mb(); | |
5164 | ||
fe5f5787 | 5165 | if (unlikely(netif_tx_queue_stopped(txq) && |
f3f3f27e | 5166 | (tg3_tx_avail(tnapi) > TG3_TX_WAKEUP_THRESH(tnapi)))) { |
fe5f5787 MC |
5167 | __netif_tx_lock(txq, smp_processor_id()); |
5168 | if (netif_tx_queue_stopped(txq) && | |
f3f3f27e | 5169 | (tg3_tx_avail(tnapi) > TG3_TX_WAKEUP_THRESH(tnapi))) |
fe5f5787 MC |
5170 | netif_tx_wake_queue(txq); |
5171 | __netif_tx_unlock(txq); | |
51b91468 | 5172 | } |
1da177e4 LT |
5173 | } |
5174 | ||
2b2cdb65 MC |
5175 | static void tg3_rx_skb_free(struct tg3 *tp, struct ring_info *ri, u32 map_sz) |
5176 | { | |
5177 | if (!ri->skb) | |
5178 | return; | |
5179 | ||
4e5e4f0d | 5180 | pci_unmap_single(tp->pdev, dma_unmap_addr(ri, mapping), |
2b2cdb65 MC |
5181 | map_sz, PCI_DMA_FROMDEVICE); |
5182 | dev_kfree_skb_any(ri->skb); | |
5183 | ri->skb = NULL; | |
5184 | } | |
5185 | ||
1da177e4 LT |
5186 | /* Returns size of skb allocated or < 0 on error. |
5187 | * | |
5188 | * We only need to fill in the address because the other members | |
5189 | * of the RX descriptor are invariant, see tg3_init_rings. | |
5190 | * | |
5191 | * Note the purposeful assymetry of cpu vs. chip accesses. For | |
5192 | * posting buffers we only dirty the first cache line of the RX | |
5193 | * descriptor (containing the address). Whereas for the RX status | |
5194 | * buffers the cpu only reads the last cacheline of the RX descriptor | |
5195 | * (to fetch the error flags, vlan tag, checksum, and opaque cookie). | |
5196 | */ | |
86b21e59 | 5197 | static int tg3_alloc_rx_skb(struct tg3 *tp, struct tg3_rx_prodring_set *tpr, |
a3896167 | 5198 | u32 opaque_key, u32 dest_idx_unmasked) |
1da177e4 LT |
5199 | { |
5200 | struct tg3_rx_buffer_desc *desc; | |
f94e290e | 5201 | struct ring_info *map; |
1da177e4 LT |
5202 | struct sk_buff *skb; |
5203 | dma_addr_t mapping; | |
5204 | int skb_size, dest_idx; | |
5205 | ||
1da177e4 LT |
5206 | switch (opaque_key) { |
5207 | case RXD_OPAQUE_RING_STD: | |
2c49a44d | 5208 | dest_idx = dest_idx_unmasked & tp->rx_std_ring_mask; |
21f581a5 MC |
5209 | desc = &tpr->rx_std[dest_idx]; |
5210 | map = &tpr->rx_std_buffers[dest_idx]; | |
287be12e | 5211 | skb_size = tp->rx_pkt_map_sz; |
1da177e4 LT |
5212 | break; |
5213 | ||
5214 | case RXD_OPAQUE_RING_JUMBO: | |
2c49a44d | 5215 | dest_idx = dest_idx_unmasked & tp->rx_jmb_ring_mask; |
79ed5ac7 | 5216 | desc = &tpr->rx_jmb[dest_idx].std; |
21f581a5 | 5217 | map = &tpr->rx_jmb_buffers[dest_idx]; |
287be12e | 5218 | skb_size = TG3_RX_JMB_MAP_SZ; |
1da177e4 LT |
5219 | break; |
5220 | ||
5221 | default: | |
5222 | return -EINVAL; | |
855e1111 | 5223 | } |
1da177e4 LT |
5224 | |
5225 | /* Do not overwrite any of the map or rp information | |
5226 | * until we are sure we can commit to a new buffer. | |
5227 | * | |
5228 | * Callers depend upon this behavior and assume that | |
5229 | * we leave everything unchanged if we fail. | |
5230 | */ | |
81389f57 | 5231 | skb = netdev_alloc_skb(tp->dev, skb_size + TG3_RX_OFFSET(tp)); |
1da177e4 LT |
5232 | if (skb == NULL) |
5233 | return -ENOMEM; | |
5234 | ||
81389f57 | 5235 | skb_reserve(skb, TG3_RX_OFFSET(tp)); |
1da177e4 | 5236 | |
287be12e | 5237 | mapping = pci_map_single(tp->pdev, skb->data, skb_size, |
1da177e4 | 5238 | PCI_DMA_FROMDEVICE); |
a21771dd MC |
5239 | if (pci_dma_mapping_error(tp->pdev, mapping)) { |
5240 | dev_kfree_skb(skb); | |
5241 | return -EIO; | |
5242 | } | |
1da177e4 LT |
5243 | |
5244 | map->skb = skb; | |
4e5e4f0d | 5245 | dma_unmap_addr_set(map, mapping, mapping); |
1da177e4 | 5246 | |
1da177e4 LT |
5247 | desc->addr_hi = ((u64)mapping >> 32); |
5248 | desc->addr_lo = ((u64)mapping & 0xffffffff); | |
5249 | ||
5250 | return skb_size; | |
5251 | } | |
5252 | ||
5253 | /* We only need to move over in the address because the other | |
5254 | * members of the RX descriptor are invariant. See notes above | |
5255 | * tg3_alloc_rx_skb for full details. | |
5256 | */ | |
a3896167 MC |
5257 | static void tg3_recycle_rx(struct tg3_napi *tnapi, |
5258 | struct tg3_rx_prodring_set *dpr, | |
5259 | u32 opaque_key, int src_idx, | |
5260 | u32 dest_idx_unmasked) | |
1da177e4 | 5261 | { |
17375d25 | 5262 | struct tg3 *tp = tnapi->tp; |
1da177e4 LT |
5263 | struct tg3_rx_buffer_desc *src_desc, *dest_desc; |
5264 | struct ring_info *src_map, *dest_map; | |
8fea32b9 | 5265 | struct tg3_rx_prodring_set *spr = &tp->napi[0].prodring; |
c6cdf436 | 5266 | int dest_idx; |
1da177e4 LT |
5267 | |
5268 | switch (opaque_key) { | |
5269 | case RXD_OPAQUE_RING_STD: | |
2c49a44d | 5270 | dest_idx = dest_idx_unmasked & tp->rx_std_ring_mask; |
a3896167 MC |
5271 | dest_desc = &dpr->rx_std[dest_idx]; |
5272 | dest_map = &dpr->rx_std_buffers[dest_idx]; | |
5273 | src_desc = &spr->rx_std[src_idx]; | |
5274 | src_map = &spr->rx_std_buffers[src_idx]; | |
1da177e4 LT |
5275 | break; |
5276 | ||
5277 | case RXD_OPAQUE_RING_JUMBO: | |
2c49a44d | 5278 | dest_idx = dest_idx_unmasked & tp->rx_jmb_ring_mask; |
a3896167 MC |
5279 | dest_desc = &dpr->rx_jmb[dest_idx].std; |
5280 | dest_map = &dpr->rx_jmb_buffers[dest_idx]; | |
5281 | src_desc = &spr->rx_jmb[src_idx].std; | |
5282 | src_map = &spr->rx_jmb_buffers[src_idx]; | |
1da177e4 LT |
5283 | break; |
5284 | ||
5285 | default: | |
5286 | return; | |
855e1111 | 5287 | } |
1da177e4 LT |
5288 | |
5289 | dest_map->skb = src_map->skb; | |
4e5e4f0d FT |
5290 | dma_unmap_addr_set(dest_map, mapping, |
5291 | dma_unmap_addr(src_map, mapping)); | |
1da177e4 LT |
5292 | dest_desc->addr_hi = src_desc->addr_hi; |
5293 | dest_desc->addr_lo = src_desc->addr_lo; | |
e92967bf MC |
5294 | |
5295 | /* Ensure that the update to the skb happens after the physical | |
5296 | * addresses have been transferred to the new BD location. | |
5297 | */ | |
5298 | smp_wmb(); | |
5299 | ||
1da177e4 LT |
5300 | src_map->skb = NULL; |
5301 | } | |
5302 | ||
1da177e4 LT |
5303 | /* The RX ring scheme is composed of multiple rings which post fresh |
5304 | * buffers to the chip, and one special ring the chip uses to report | |
5305 | * status back to the host. | |
5306 | * | |
5307 | * The special ring reports the status of received packets to the | |
5308 | * host. The chip does not write into the original descriptor the | |
5309 | * RX buffer was obtained from. The chip simply takes the original | |
5310 | * descriptor as provided by the host, updates the status and length | |
5311 | * field, then writes this into the next status ring entry. | |
5312 | * | |
5313 | * Each ring the host uses to post buffers to the chip is described | |
5314 | * by a TG3_BDINFO entry in the chips SRAM area. When a packet arrives, | |
5315 | * it is first placed into the on-chip ram. When the packet's length | |
5316 | * is known, it walks down the TG3_BDINFO entries to select the ring. | |
5317 | * Each TG3_BDINFO specifies a MAXLEN field and the first TG3_BDINFO | |
5318 | * which is within the range of the new packet's length is chosen. | |
5319 | * | |
5320 | * The "separate ring for rx status" scheme may sound queer, but it makes | |
5321 | * sense from a cache coherency perspective. If only the host writes | |
5322 | * to the buffer post rings, and only the chip writes to the rx status | |
5323 | * rings, then cache lines never move beyond shared-modified state. | |
5324 | * If both the host and chip were to write into the same ring, cache line | |
5325 | * eviction could occur since both entities want it in an exclusive state. | |
5326 | */ | |
17375d25 | 5327 | static int tg3_rx(struct tg3_napi *tnapi, int budget) |
1da177e4 | 5328 | { |
17375d25 | 5329 | struct tg3 *tp = tnapi->tp; |
f92905de | 5330 | u32 work_mask, rx_std_posted = 0; |
4361935a | 5331 | u32 std_prod_idx, jmb_prod_idx; |
72334482 | 5332 | u32 sw_idx = tnapi->rx_rcb_ptr; |
483ba50b | 5333 | u16 hw_idx; |
1da177e4 | 5334 | int received; |
8fea32b9 | 5335 | struct tg3_rx_prodring_set *tpr = &tnapi->prodring; |
1da177e4 | 5336 | |
8d9d7cfc | 5337 | hw_idx = *(tnapi->rx_rcb_prod_idx); |
1da177e4 LT |
5338 | /* |
5339 | * We need to order the read of hw_idx and the read of | |
5340 | * the opaque cookie. | |
5341 | */ | |
5342 | rmb(); | |
1da177e4 LT |
5343 | work_mask = 0; |
5344 | received = 0; | |
4361935a MC |
5345 | std_prod_idx = tpr->rx_std_prod_idx; |
5346 | jmb_prod_idx = tpr->rx_jmb_prod_idx; | |
1da177e4 | 5347 | while (sw_idx != hw_idx && budget > 0) { |
afc081f8 | 5348 | struct ring_info *ri; |
72334482 | 5349 | struct tg3_rx_buffer_desc *desc = &tnapi->rx_rcb[sw_idx]; |
1da177e4 LT |
5350 | unsigned int len; |
5351 | struct sk_buff *skb; | |
5352 | dma_addr_t dma_addr; | |
5353 | u32 opaque_key, desc_idx, *post_ptr; | |
5354 | ||
5355 | desc_idx = desc->opaque & RXD_OPAQUE_INDEX_MASK; | |
5356 | opaque_key = desc->opaque & RXD_OPAQUE_RING_MASK; | |
5357 | if (opaque_key == RXD_OPAQUE_RING_STD) { | |
8fea32b9 | 5358 | ri = &tp->napi[0].prodring.rx_std_buffers[desc_idx]; |
4e5e4f0d | 5359 | dma_addr = dma_unmap_addr(ri, mapping); |
21f581a5 | 5360 | skb = ri->skb; |
4361935a | 5361 | post_ptr = &std_prod_idx; |
f92905de | 5362 | rx_std_posted++; |
1da177e4 | 5363 | } else if (opaque_key == RXD_OPAQUE_RING_JUMBO) { |
8fea32b9 | 5364 | ri = &tp->napi[0].prodring.rx_jmb_buffers[desc_idx]; |
4e5e4f0d | 5365 | dma_addr = dma_unmap_addr(ri, mapping); |
21f581a5 | 5366 | skb = ri->skb; |
4361935a | 5367 | post_ptr = &jmb_prod_idx; |
21f581a5 | 5368 | } else |
1da177e4 | 5369 | goto next_pkt_nopost; |
1da177e4 LT |
5370 | |
5371 | work_mask |= opaque_key; | |
5372 | ||
5373 | if ((desc->err_vlan & RXD_ERR_MASK) != 0 && | |
5374 | (desc->err_vlan != RXD_ERR_ODD_NIBBLE_RCVD_MII)) { | |
5375 | drop_it: | |
a3896167 | 5376 | tg3_recycle_rx(tnapi, tpr, opaque_key, |
1da177e4 LT |
5377 | desc_idx, *post_ptr); |
5378 | drop_it_no_recycle: | |
5379 | /* Other statistics kept track of by card. */ | |
b0057c51 | 5380 | tp->rx_dropped++; |
1da177e4 LT |
5381 | goto next_pkt; |
5382 | } | |
5383 | ||
ad829268 MC |
5384 | len = ((desc->idx_len & RXD_LEN_MASK) >> RXD_LEN_SHIFT) - |
5385 | ETH_FCS_LEN; | |
1da177e4 | 5386 | |
d2757fc4 | 5387 | if (len > TG3_RX_COPY_THRESH(tp)) { |
1da177e4 LT |
5388 | int skb_size; |
5389 | ||
86b21e59 | 5390 | skb_size = tg3_alloc_rx_skb(tp, tpr, opaque_key, |
afc081f8 | 5391 | *post_ptr); |
1da177e4 LT |
5392 | if (skb_size < 0) |
5393 | goto drop_it; | |
5394 | ||
287be12e | 5395 | pci_unmap_single(tp->pdev, dma_addr, skb_size, |
1da177e4 LT |
5396 | PCI_DMA_FROMDEVICE); |
5397 | ||
61e800cf MC |
5398 | /* Ensure that the update to the skb happens |
5399 | * after the usage of the old DMA mapping. | |
5400 | */ | |
5401 | smp_wmb(); | |
5402 | ||
5403 | ri->skb = NULL; | |
5404 | ||
1da177e4 LT |
5405 | skb_put(skb, len); |
5406 | } else { | |
5407 | struct sk_buff *copy_skb; | |
5408 | ||
a3896167 | 5409 | tg3_recycle_rx(tnapi, tpr, opaque_key, |
1da177e4 LT |
5410 | desc_idx, *post_ptr); |
5411 | ||
bf933c80 | 5412 | copy_skb = netdev_alloc_skb(tp->dev, len + |
9dc7a113 | 5413 | TG3_RAW_IP_ALIGN); |
1da177e4 LT |
5414 | if (copy_skb == NULL) |
5415 | goto drop_it_no_recycle; | |
5416 | ||
bf933c80 | 5417 | skb_reserve(copy_skb, TG3_RAW_IP_ALIGN); |
1da177e4 LT |
5418 | skb_put(copy_skb, len); |
5419 | pci_dma_sync_single_for_cpu(tp->pdev, dma_addr, len, PCI_DMA_FROMDEVICE); | |
d626f62b | 5420 | skb_copy_from_linear_data(skb, copy_skb->data, len); |
1da177e4 LT |
5421 | pci_dma_sync_single_for_device(tp->pdev, dma_addr, len, PCI_DMA_FROMDEVICE); |
5422 | ||
5423 | /* We'll reuse the original ring buffer. */ | |
5424 | skb = copy_skb; | |
5425 | } | |
5426 | ||
dc668910 | 5427 | if ((tp->dev->features & NETIF_F_RXCSUM) && |
1da177e4 LT |
5428 | (desc->type_flags & RXD_FLAG_TCPUDP_CSUM) && |
5429 | (((desc->ip_tcp_csum & RXD_TCPCSUM_MASK) | |
5430 | >> RXD_TCPCSUM_SHIFT) == 0xffff)) | |
5431 | skb->ip_summed = CHECKSUM_UNNECESSARY; | |
5432 | else | |
bc8acf2c | 5433 | skb_checksum_none_assert(skb); |
1da177e4 LT |
5434 | |
5435 | skb->protocol = eth_type_trans(skb, tp->dev); | |
f7b493e0 MC |
5436 | |
5437 | if (len > (tp->dev->mtu + ETH_HLEN) && | |
5438 | skb->protocol != htons(ETH_P_8021Q)) { | |
5439 | dev_kfree_skb(skb); | |
b0057c51 | 5440 | goto drop_it_no_recycle; |
f7b493e0 MC |
5441 | } |
5442 | ||
9dc7a113 | 5443 | if (desc->type_flags & RXD_FLAG_VLAN && |
bf933c80 MC |
5444 | !(tp->rx_mode & RX_MODE_KEEP_VLAN_TAG)) |
5445 | __vlan_hwaccel_put_tag(skb, | |
5446 | desc->err_vlan & RXD_VLAN_MASK); | |
9dc7a113 | 5447 | |
bf933c80 | 5448 | napi_gro_receive(&tnapi->napi, skb); |
1da177e4 | 5449 | |
1da177e4 LT |
5450 | received++; |
5451 | budget--; | |
5452 | ||
5453 | next_pkt: | |
5454 | (*post_ptr)++; | |
f92905de MC |
5455 | |
5456 | if (unlikely(rx_std_posted >= tp->rx_std_max_post)) { | |
2c49a44d MC |
5457 | tpr->rx_std_prod_idx = std_prod_idx & |
5458 | tp->rx_std_ring_mask; | |
86cfe4ff MC |
5459 | tw32_rx_mbox(TG3_RX_STD_PROD_IDX_REG, |
5460 | tpr->rx_std_prod_idx); | |
f92905de MC |
5461 | work_mask &= ~RXD_OPAQUE_RING_STD; |
5462 | rx_std_posted = 0; | |
5463 | } | |
1da177e4 | 5464 | next_pkt_nopost: |
483ba50b | 5465 | sw_idx++; |
7cb32cf2 | 5466 | sw_idx &= tp->rx_ret_ring_mask; |
52f6d697 MC |
5467 | |
5468 | /* Refresh hw_idx to see if there is new work */ | |
5469 | if (sw_idx == hw_idx) { | |
8d9d7cfc | 5470 | hw_idx = *(tnapi->rx_rcb_prod_idx); |
52f6d697 MC |
5471 | rmb(); |
5472 | } | |
1da177e4 LT |
5473 | } |
5474 | ||
5475 | /* ACK the status ring. */ | |
72334482 MC |
5476 | tnapi->rx_rcb_ptr = sw_idx; |
5477 | tw32_rx_mbox(tnapi->consmbox, sw_idx); | |
1da177e4 LT |
5478 | |
5479 | /* Refill RX ring(s). */ | |
63c3a66f | 5480 | if (!tg3_flag(tp, ENABLE_RSS)) { |
b196c7e4 | 5481 | if (work_mask & RXD_OPAQUE_RING_STD) { |
2c49a44d MC |
5482 | tpr->rx_std_prod_idx = std_prod_idx & |
5483 | tp->rx_std_ring_mask; | |
b196c7e4 MC |
5484 | tw32_rx_mbox(TG3_RX_STD_PROD_IDX_REG, |
5485 | tpr->rx_std_prod_idx); | |
5486 | } | |
5487 | if (work_mask & RXD_OPAQUE_RING_JUMBO) { | |
2c49a44d MC |
5488 | tpr->rx_jmb_prod_idx = jmb_prod_idx & |
5489 | tp->rx_jmb_ring_mask; | |
b196c7e4 MC |
5490 | tw32_rx_mbox(TG3_RX_JMB_PROD_IDX_REG, |
5491 | tpr->rx_jmb_prod_idx); | |
5492 | } | |
5493 | mmiowb(); | |
5494 | } else if (work_mask) { | |
5495 | /* rx_std_buffers[] and rx_jmb_buffers[] entries must be | |
5496 | * updated before the producer indices can be updated. | |
5497 | */ | |
5498 | smp_wmb(); | |
5499 | ||
2c49a44d MC |
5500 | tpr->rx_std_prod_idx = std_prod_idx & tp->rx_std_ring_mask; |
5501 | tpr->rx_jmb_prod_idx = jmb_prod_idx & tp->rx_jmb_ring_mask; | |
b196c7e4 | 5502 | |
e4af1af9 MC |
5503 | if (tnapi != &tp->napi[1]) |
5504 | napi_schedule(&tp->napi[1].napi); | |
1da177e4 | 5505 | } |
1da177e4 LT |
5506 | |
5507 | return received; | |
5508 | } | |
5509 | ||
35f2d7d0 | 5510 | static void tg3_poll_link(struct tg3 *tp) |
1da177e4 | 5511 | { |
1da177e4 | 5512 | /* handle link change and other phy events */ |
63c3a66f | 5513 | if (!(tg3_flag(tp, USE_LINKCHG_REG) || tg3_flag(tp, POLL_SERDES))) { |
35f2d7d0 MC |
5514 | struct tg3_hw_status *sblk = tp->napi[0].hw_status; |
5515 | ||
1da177e4 LT |
5516 | if (sblk->status & SD_STATUS_LINK_CHG) { |
5517 | sblk->status = SD_STATUS_UPDATED | | |
35f2d7d0 | 5518 | (sblk->status & ~SD_STATUS_LINK_CHG); |
f47c11ee | 5519 | spin_lock(&tp->lock); |
63c3a66f | 5520 | if (tg3_flag(tp, USE_PHYLIB)) { |
dd477003 MC |
5521 | tw32_f(MAC_STATUS, |
5522 | (MAC_STATUS_SYNC_CHANGED | | |
5523 | MAC_STATUS_CFG_CHANGED | | |
5524 | MAC_STATUS_MI_COMPLETION | | |
5525 | MAC_STATUS_LNKSTATE_CHANGED)); | |
5526 | udelay(40); | |
5527 | } else | |
5528 | tg3_setup_phy(tp, 0); | |
f47c11ee | 5529 | spin_unlock(&tp->lock); |
1da177e4 LT |
5530 | } |
5531 | } | |
35f2d7d0 MC |
5532 | } |
5533 | ||
f89f38b8 MC |
5534 | static int tg3_rx_prodring_xfer(struct tg3 *tp, |
5535 | struct tg3_rx_prodring_set *dpr, | |
5536 | struct tg3_rx_prodring_set *spr) | |
b196c7e4 MC |
5537 | { |
5538 | u32 si, di, cpycnt, src_prod_idx; | |
f89f38b8 | 5539 | int i, err = 0; |
b196c7e4 MC |
5540 | |
5541 | while (1) { | |
5542 | src_prod_idx = spr->rx_std_prod_idx; | |
5543 | ||
5544 | /* Make sure updates to the rx_std_buffers[] entries and the | |
5545 | * standard producer index are seen in the correct order. | |
5546 | */ | |
5547 | smp_rmb(); | |
5548 | ||
5549 | if (spr->rx_std_cons_idx == src_prod_idx) | |
5550 | break; | |
5551 | ||
5552 | if (spr->rx_std_cons_idx < src_prod_idx) | |
5553 | cpycnt = src_prod_idx - spr->rx_std_cons_idx; | |
5554 | else | |
2c49a44d MC |
5555 | cpycnt = tp->rx_std_ring_mask + 1 - |
5556 | spr->rx_std_cons_idx; | |
b196c7e4 | 5557 | |
2c49a44d MC |
5558 | cpycnt = min(cpycnt, |
5559 | tp->rx_std_ring_mask + 1 - dpr->rx_std_prod_idx); | |
b196c7e4 MC |
5560 | |
5561 | si = spr->rx_std_cons_idx; | |
5562 | di = dpr->rx_std_prod_idx; | |
5563 | ||
e92967bf MC |
5564 | for (i = di; i < di + cpycnt; i++) { |
5565 | if (dpr->rx_std_buffers[i].skb) { | |
5566 | cpycnt = i - di; | |
f89f38b8 | 5567 | err = -ENOSPC; |
e92967bf MC |
5568 | break; |
5569 | } | |
5570 | } | |
5571 | ||
5572 | if (!cpycnt) | |
5573 | break; | |
5574 | ||
5575 | /* Ensure that updates to the rx_std_buffers ring and the | |
5576 | * shadowed hardware producer ring from tg3_recycle_skb() are | |
5577 | * ordered correctly WRT the skb check above. | |
5578 | */ | |
5579 | smp_rmb(); | |
5580 | ||
b196c7e4 MC |
5581 | memcpy(&dpr->rx_std_buffers[di], |
5582 | &spr->rx_std_buffers[si], | |
5583 | cpycnt * sizeof(struct ring_info)); | |
5584 | ||
5585 | for (i = 0; i < cpycnt; i++, di++, si++) { | |
5586 | struct tg3_rx_buffer_desc *sbd, *dbd; | |
5587 | sbd = &spr->rx_std[si]; | |
5588 | dbd = &dpr->rx_std[di]; | |
5589 | dbd->addr_hi = sbd->addr_hi; | |
5590 | dbd->addr_lo = sbd->addr_lo; | |
5591 | } | |
5592 | ||
2c49a44d MC |
5593 | spr->rx_std_cons_idx = (spr->rx_std_cons_idx + cpycnt) & |
5594 | tp->rx_std_ring_mask; | |
5595 | dpr->rx_std_prod_idx = (dpr->rx_std_prod_idx + cpycnt) & | |
5596 | tp->rx_std_ring_mask; | |
b196c7e4 MC |
5597 | } |
5598 | ||
5599 | while (1) { | |
5600 | src_prod_idx = spr->rx_jmb_prod_idx; | |
5601 | ||
5602 | /* Make sure updates to the rx_jmb_buffers[] entries and | |
5603 | * the jumbo producer index are seen in the correct order. | |
5604 | */ | |
5605 | smp_rmb(); | |
5606 | ||
5607 | if (spr->rx_jmb_cons_idx == src_prod_idx) | |
5608 | break; | |
5609 | ||
5610 | if (spr->rx_jmb_cons_idx < src_prod_idx) | |
5611 | cpycnt = src_prod_idx - spr->rx_jmb_cons_idx; | |
5612 | else | |
2c49a44d MC |
5613 | cpycnt = tp->rx_jmb_ring_mask + 1 - |
5614 | spr->rx_jmb_cons_idx; | |
b196c7e4 MC |
5615 | |
5616 | cpycnt = min(cpycnt, | |
2c49a44d | 5617 | tp->rx_jmb_ring_mask + 1 - dpr->rx_jmb_prod_idx); |
b196c7e4 MC |
5618 | |
5619 | si = spr->rx_jmb_cons_idx; | |
5620 | di = dpr->rx_jmb_prod_idx; | |
5621 | ||
e92967bf MC |
5622 | for (i = di; i < di + cpycnt; i++) { |
5623 | if (dpr->rx_jmb_buffers[i].skb) { | |
5624 | cpycnt = i - di; | |
f89f38b8 | 5625 | err = -ENOSPC; |
e92967bf MC |
5626 | break; |
5627 | } | |
5628 | } | |
5629 | ||
5630 | if (!cpycnt) | |
5631 | break; | |
5632 | ||
5633 | /* Ensure that updates to the rx_jmb_buffers ring and the | |
5634 | * shadowed hardware producer ring from tg3_recycle_skb() are | |
5635 | * ordered correctly WRT the skb check above. | |
5636 | */ | |
5637 | smp_rmb(); | |
5638 | ||
b196c7e4 MC |
5639 | memcpy(&dpr->rx_jmb_buffers[di], |
5640 | &spr->rx_jmb_buffers[si], | |
5641 | cpycnt * sizeof(struct ring_info)); | |
5642 | ||
5643 | for (i = 0; i < cpycnt; i++, di++, si++) { | |
5644 | struct tg3_rx_buffer_desc *sbd, *dbd; | |
5645 | sbd = &spr->rx_jmb[si].std; | |
5646 | dbd = &dpr->rx_jmb[di].std; | |
5647 | dbd->addr_hi = sbd->addr_hi; | |
5648 | dbd->addr_lo = sbd->addr_lo; | |
5649 | } | |
5650 | ||
2c49a44d MC |
5651 | spr->rx_jmb_cons_idx = (spr->rx_jmb_cons_idx + cpycnt) & |
5652 | tp->rx_jmb_ring_mask; | |
5653 | dpr->rx_jmb_prod_idx = (dpr->rx_jmb_prod_idx + cpycnt) & | |
5654 | tp->rx_jmb_ring_mask; | |
b196c7e4 | 5655 | } |
f89f38b8 MC |
5656 | |
5657 | return err; | |
b196c7e4 MC |
5658 | } |
5659 | ||
35f2d7d0 MC |
5660 | static int tg3_poll_work(struct tg3_napi *tnapi, int work_done, int budget) |
5661 | { | |
5662 | struct tg3 *tp = tnapi->tp; | |
1da177e4 LT |
5663 | |
5664 | /* run TX completion thread */ | |
f3f3f27e | 5665 | if (tnapi->hw_status->idx[0].tx_consumer != tnapi->tx_cons) { |
17375d25 | 5666 | tg3_tx(tnapi); |
63c3a66f | 5667 | if (unlikely(tg3_flag(tp, TX_RECOVERY_PENDING))) |
4fd7ab59 | 5668 | return work_done; |
1da177e4 LT |
5669 | } |
5670 | ||
1da177e4 LT |
5671 | /* run RX thread, within the bounds set by NAPI. |
5672 | * All RX "locking" is done by ensuring outside | |
bea3348e | 5673 | * code synchronizes with tg3->napi.poll() |
1da177e4 | 5674 | */ |
8d9d7cfc | 5675 | if (*(tnapi->rx_rcb_prod_idx) != tnapi->rx_rcb_ptr) |
17375d25 | 5676 | work_done += tg3_rx(tnapi, budget - work_done); |
1da177e4 | 5677 | |
63c3a66f | 5678 | if (tg3_flag(tp, ENABLE_RSS) && tnapi == &tp->napi[1]) { |
8fea32b9 | 5679 | struct tg3_rx_prodring_set *dpr = &tp->napi[0].prodring; |
f89f38b8 | 5680 | int i, err = 0; |
e4af1af9 MC |
5681 | u32 std_prod_idx = dpr->rx_std_prod_idx; |
5682 | u32 jmb_prod_idx = dpr->rx_jmb_prod_idx; | |
b196c7e4 | 5683 | |
e4af1af9 | 5684 | for (i = 1; i < tp->irq_cnt; i++) |
f89f38b8 | 5685 | err |= tg3_rx_prodring_xfer(tp, dpr, |
8fea32b9 | 5686 | &tp->napi[i].prodring); |
b196c7e4 MC |
5687 | |
5688 | wmb(); | |
5689 | ||
e4af1af9 MC |
5690 | if (std_prod_idx != dpr->rx_std_prod_idx) |
5691 | tw32_rx_mbox(TG3_RX_STD_PROD_IDX_REG, | |
5692 | dpr->rx_std_prod_idx); | |
b196c7e4 | 5693 | |
e4af1af9 MC |
5694 | if (jmb_prod_idx != dpr->rx_jmb_prod_idx) |
5695 | tw32_rx_mbox(TG3_RX_JMB_PROD_IDX_REG, | |
5696 | dpr->rx_jmb_prod_idx); | |
b196c7e4 MC |
5697 | |
5698 | mmiowb(); | |
f89f38b8 MC |
5699 | |
5700 | if (err) | |
5701 | tw32_f(HOSTCC_MODE, tp->coal_now); | |
b196c7e4 MC |
5702 | } |
5703 | ||
6f535763 DM |
5704 | return work_done; |
5705 | } | |
5706 | ||
35f2d7d0 MC |
5707 | static int tg3_poll_msix(struct napi_struct *napi, int budget) |
5708 | { | |
5709 | struct tg3_napi *tnapi = container_of(napi, struct tg3_napi, napi); | |
5710 | struct tg3 *tp = tnapi->tp; | |
5711 | int work_done = 0; | |
5712 | struct tg3_hw_status *sblk = tnapi->hw_status; | |
5713 | ||
5714 | while (1) { | |
5715 | work_done = tg3_poll_work(tnapi, work_done, budget); | |
5716 | ||
63c3a66f | 5717 | if (unlikely(tg3_flag(tp, TX_RECOVERY_PENDING))) |
35f2d7d0 MC |
5718 | goto tx_recovery; |
5719 | ||
5720 | if (unlikely(work_done >= budget)) | |
5721 | break; | |
5722 | ||
c6cdf436 | 5723 | /* tp->last_tag is used in tg3_int_reenable() below |
35f2d7d0 MC |
5724 | * to tell the hw how much work has been processed, |
5725 | * so we must read it before checking for more work. | |
5726 | */ | |
5727 | tnapi->last_tag = sblk->status_tag; | |
5728 | tnapi->last_irq_tag = tnapi->last_tag; | |
5729 | rmb(); | |
5730 | ||
5731 | /* check for RX/TX work to do */ | |
6d40db7b MC |
5732 | if (likely(sblk->idx[0].tx_consumer == tnapi->tx_cons && |
5733 | *(tnapi->rx_rcb_prod_idx) == tnapi->rx_rcb_ptr)) { | |
35f2d7d0 MC |
5734 | napi_complete(napi); |
5735 | /* Reenable interrupts. */ | |
5736 | tw32_mailbox(tnapi->int_mbox, tnapi->last_tag << 24); | |
5737 | mmiowb(); | |
5738 | break; | |
5739 | } | |
5740 | } | |
5741 | ||
5742 | return work_done; | |
5743 | ||
5744 | tx_recovery: | |
5745 | /* work_done is guaranteed to be less than budget. */ | |
5746 | napi_complete(napi); | |
5747 | schedule_work(&tp->reset_task); | |
5748 | return work_done; | |
5749 | } | |
5750 | ||
e64de4e6 MC |
5751 | static void tg3_process_error(struct tg3 *tp) |
5752 | { | |
5753 | u32 val; | |
5754 | bool real_error = false; | |
5755 | ||
63c3a66f | 5756 | if (tg3_flag(tp, ERROR_PROCESSED)) |
e64de4e6 MC |
5757 | return; |
5758 | ||
5759 | /* Check Flow Attention register */ | |
5760 | val = tr32(HOSTCC_FLOW_ATTN); | |
5761 | if (val & ~HOSTCC_FLOW_ATTN_MBUF_LWM) { | |
5762 | netdev_err(tp->dev, "FLOW Attention error. Resetting chip.\n"); | |
5763 | real_error = true; | |
5764 | } | |
5765 | ||
5766 | if (tr32(MSGINT_STATUS) & ~MSGINT_STATUS_MSI_REQ) { | |
5767 | netdev_err(tp->dev, "MSI Status error. Resetting chip.\n"); | |
5768 | real_error = true; | |
5769 | } | |
5770 | ||
5771 | if (tr32(RDMAC_STATUS) || tr32(WDMAC_STATUS)) { | |
5772 | netdev_err(tp->dev, "DMA Status error. Resetting chip.\n"); | |
5773 | real_error = true; | |
5774 | } | |
5775 | ||
5776 | if (!real_error) | |
5777 | return; | |
5778 | ||
5779 | tg3_dump_state(tp); | |
5780 | ||
63c3a66f | 5781 | tg3_flag_set(tp, ERROR_PROCESSED); |
e64de4e6 MC |
5782 | schedule_work(&tp->reset_task); |
5783 | } | |
5784 | ||
6f535763 DM |
5785 | static int tg3_poll(struct napi_struct *napi, int budget) |
5786 | { | |
8ef0442f MC |
5787 | struct tg3_napi *tnapi = container_of(napi, struct tg3_napi, napi); |
5788 | struct tg3 *tp = tnapi->tp; | |
6f535763 | 5789 | int work_done = 0; |
898a56f8 | 5790 | struct tg3_hw_status *sblk = tnapi->hw_status; |
6f535763 DM |
5791 | |
5792 | while (1) { | |
e64de4e6 MC |
5793 | if (sblk->status & SD_STATUS_ERROR) |
5794 | tg3_process_error(tp); | |
5795 | ||
35f2d7d0 MC |
5796 | tg3_poll_link(tp); |
5797 | ||
17375d25 | 5798 | work_done = tg3_poll_work(tnapi, work_done, budget); |
6f535763 | 5799 | |
63c3a66f | 5800 | if (unlikely(tg3_flag(tp, TX_RECOVERY_PENDING))) |
6f535763 DM |
5801 | goto tx_recovery; |
5802 | ||
5803 | if (unlikely(work_done >= budget)) | |
5804 | break; | |
5805 | ||
63c3a66f | 5806 | if (tg3_flag(tp, TAGGED_STATUS)) { |
17375d25 | 5807 | /* tp->last_tag is used in tg3_int_reenable() below |
4fd7ab59 MC |
5808 | * to tell the hw how much work has been processed, |
5809 | * so we must read it before checking for more work. | |
5810 | */ | |
898a56f8 MC |
5811 | tnapi->last_tag = sblk->status_tag; |
5812 | tnapi->last_irq_tag = tnapi->last_tag; | |
4fd7ab59 MC |
5813 | rmb(); |
5814 | } else | |
5815 | sblk->status &= ~SD_STATUS_UPDATED; | |
6f535763 | 5816 | |
17375d25 | 5817 | if (likely(!tg3_has_work(tnapi))) { |
288379f0 | 5818 | napi_complete(napi); |
17375d25 | 5819 | tg3_int_reenable(tnapi); |
6f535763 DM |
5820 | break; |
5821 | } | |
1da177e4 LT |
5822 | } |
5823 | ||
bea3348e | 5824 | return work_done; |
6f535763 DM |
5825 | |
5826 | tx_recovery: | |
4fd7ab59 | 5827 | /* work_done is guaranteed to be less than budget. */ |
288379f0 | 5828 | napi_complete(napi); |
6f535763 | 5829 | schedule_work(&tp->reset_task); |
4fd7ab59 | 5830 | return work_done; |
1da177e4 LT |
5831 | } |
5832 | ||
66cfd1bd MC |
5833 | static void tg3_napi_disable(struct tg3 *tp) |
5834 | { | |
5835 | int i; | |
5836 | ||
5837 | for (i = tp->irq_cnt - 1; i >= 0; i--) | |
5838 | napi_disable(&tp->napi[i].napi); | |
5839 | } | |
5840 | ||
5841 | static void tg3_napi_enable(struct tg3 *tp) | |
5842 | { | |
5843 | int i; | |
5844 | ||
5845 | for (i = 0; i < tp->irq_cnt; i++) | |
5846 | napi_enable(&tp->napi[i].napi); | |
5847 | } | |
5848 | ||
5849 | static void tg3_napi_init(struct tg3 *tp) | |
5850 | { | |
5851 | int i; | |
5852 | ||
5853 | netif_napi_add(tp->dev, &tp->napi[0].napi, tg3_poll, 64); | |
5854 | for (i = 1; i < tp->irq_cnt; i++) | |
5855 | netif_napi_add(tp->dev, &tp->napi[i].napi, tg3_poll_msix, 64); | |
5856 | } | |
5857 | ||
5858 | static void tg3_napi_fini(struct tg3 *tp) | |
5859 | { | |
5860 | int i; | |
5861 | ||
5862 | for (i = 0; i < tp->irq_cnt; i++) | |
5863 | netif_napi_del(&tp->napi[i].napi); | |
5864 | } | |
5865 | ||
5866 | static inline void tg3_netif_stop(struct tg3 *tp) | |
5867 | { | |
5868 | tp->dev->trans_start = jiffies; /* prevent tx timeout */ | |
5869 | tg3_napi_disable(tp); | |
5870 | netif_tx_disable(tp->dev); | |
5871 | } | |
5872 | ||
5873 | static inline void tg3_netif_start(struct tg3 *tp) | |
5874 | { | |
5875 | /* NOTE: unconditional netif_tx_wake_all_queues is only | |
5876 | * appropriate so long as all callers are assured to | |
5877 | * have free tx slots (such as after tg3_init_hw) | |
5878 | */ | |
5879 | netif_tx_wake_all_queues(tp->dev); | |
5880 | ||
5881 | tg3_napi_enable(tp); | |
5882 | tp->napi[0].hw_status->status |= SD_STATUS_UPDATED; | |
5883 | tg3_enable_ints(tp); | |
5884 | } | |
5885 | ||
f47c11ee DM |
5886 | static void tg3_irq_quiesce(struct tg3 *tp) |
5887 | { | |
4f125f42 MC |
5888 | int i; |
5889 | ||
f47c11ee DM |
5890 | BUG_ON(tp->irq_sync); |
5891 | ||
5892 | tp->irq_sync = 1; | |
5893 | smp_mb(); | |
5894 | ||
4f125f42 MC |
5895 | for (i = 0; i < tp->irq_cnt; i++) |
5896 | synchronize_irq(tp->napi[i].irq_vec); | |
f47c11ee DM |
5897 | } |
5898 | ||
f47c11ee DM |
5899 | /* Fully shutdown all tg3 driver activity elsewhere in the system. |
5900 | * If irq_sync is non-zero, then the IRQ handler must be synchronized | |
5901 | * with as well. Most of the time, this is not necessary except when | |
5902 | * shutting down the device. | |
5903 | */ | |
5904 | static inline void tg3_full_lock(struct tg3 *tp, int irq_sync) | |
5905 | { | |
46966545 | 5906 | spin_lock_bh(&tp->lock); |
f47c11ee DM |
5907 | if (irq_sync) |
5908 | tg3_irq_quiesce(tp); | |
f47c11ee DM |
5909 | } |
5910 | ||
5911 | static inline void tg3_full_unlock(struct tg3 *tp) | |
5912 | { | |
f47c11ee DM |
5913 | spin_unlock_bh(&tp->lock); |
5914 | } | |
5915 | ||
fcfa0a32 MC |
5916 | /* One-shot MSI handler - Chip automatically disables interrupt |
5917 | * after sending MSI so driver doesn't have to do it. | |
5918 | */ | |
7d12e780 | 5919 | static irqreturn_t tg3_msi_1shot(int irq, void *dev_id) |
fcfa0a32 | 5920 | { |
09943a18 MC |
5921 | struct tg3_napi *tnapi = dev_id; |
5922 | struct tg3 *tp = tnapi->tp; | |
fcfa0a32 | 5923 | |
898a56f8 | 5924 | prefetch(tnapi->hw_status); |
0c1d0e2b MC |
5925 | if (tnapi->rx_rcb) |
5926 | prefetch(&tnapi->rx_rcb[tnapi->rx_rcb_ptr]); | |
fcfa0a32 MC |
5927 | |
5928 | if (likely(!tg3_irq_sync(tp))) | |
09943a18 | 5929 | napi_schedule(&tnapi->napi); |
fcfa0a32 MC |
5930 | |
5931 | return IRQ_HANDLED; | |
5932 | } | |
5933 | ||
88b06bc2 MC |
5934 | /* MSI ISR - No need to check for interrupt sharing and no need to |
5935 | * flush status block and interrupt mailbox. PCI ordering rules | |
5936 | * guarantee that MSI will arrive after the status block. | |
5937 | */ | |
7d12e780 | 5938 | static irqreturn_t tg3_msi(int irq, void *dev_id) |
88b06bc2 | 5939 | { |
09943a18 MC |
5940 | struct tg3_napi *tnapi = dev_id; |
5941 | struct tg3 *tp = tnapi->tp; | |
88b06bc2 | 5942 | |
898a56f8 | 5943 | prefetch(tnapi->hw_status); |
0c1d0e2b MC |
5944 | if (tnapi->rx_rcb) |
5945 | prefetch(&tnapi->rx_rcb[tnapi->rx_rcb_ptr]); | |
88b06bc2 | 5946 | /* |
fac9b83e | 5947 | * Writing any value to intr-mbox-0 clears PCI INTA# and |
88b06bc2 | 5948 | * chip-internal interrupt pending events. |
fac9b83e | 5949 | * Writing non-zero to intr-mbox-0 additional tells the |
88b06bc2 MC |
5950 | * NIC to stop sending us irqs, engaging "in-intr-handler" |
5951 | * event coalescing. | |
5952 | */ | |
5b39de91 | 5953 | tw32_mailbox(tnapi->int_mbox, 0x00000001); |
61487480 | 5954 | if (likely(!tg3_irq_sync(tp))) |
09943a18 | 5955 | napi_schedule(&tnapi->napi); |
61487480 | 5956 | |
88b06bc2 MC |
5957 | return IRQ_RETVAL(1); |
5958 | } | |
5959 | ||
7d12e780 | 5960 | static irqreturn_t tg3_interrupt(int irq, void *dev_id) |
1da177e4 | 5961 | { |
09943a18 MC |
5962 | struct tg3_napi *tnapi = dev_id; |
5963 | struct tg3 *tp = tnapi->tp; | |
898a56f8 | 5964 | struct tg3_hw_status *sblk = tnapi->hw_status; |
1da177e4 LT |
5965 | unsigned int handled = 1; |
5966 | ||
1da177e4 LT |
5967 | /* In INTx mode, it is possible for the interrupt to arrive at |
5968 | * the CPU before the status block posted prior to the interrupt. | |
5969 | * Reading the PCI State register will confirm whether the | |
5970 | * interrupt is ours and will flush the status block. | |
5971 | */ | |
d18edcb2 | 5972 | if (unlikely(!(sblk->status & SD_STATUS_UPDATED))) { |
63c3a66f | 5973 | if (tg3_flag(tp, CHIP_RESETTING) || |
d18edcb2 MC |
5974 | (tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) { |
5975 | handled = 0; | |
f47c11ee | 5976 | goto out; |
fac9b83e | 5977 | } |
d18edcb2 MC |
5978 | } |
5979 | ||
5980 | /* | |
5981 | * Writing any value to intr-mbox-0 clears PCI INTA# and | |
5982 | * chip-internal interrupt pending events. | |
5983 | * Writing non-zero to intr-mbox-0 additional tells the | |
5984 | * NIC to stop sending us irqs, engaging "in-intr-handler" | |
5985 | * event coalescing. | |
c04cb347 MC |
5986 | * |
5987 | * Flush the mailbox to de-assert the IRQ immediately to prevent | |
5988 | * spurious interrupts. The flush impacts performance but | |
5989 | * excessive spurious interrupts can be worse in some cases. | |
d18edcb2 | 5990 | */ |
c04cb347 | 5991 | tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001); |
d18edcb2 MC |
5992 | if (tg3_irq_sync(tp)) |
5993 | goto out; | |
5994 | sblk->status &= ~SD_STATUS_UPDATED; | |
17375d25 | 5995 | if (likely(tg3_has_work(tnapi))) { |
72334482 | 5996 | prefetch(&tnapi->rx_rcb[tnapi->rx_rcb_ptr]); |
09943a18 | 5997 | napi_schedule(&tnapi->napi); |
d18edcb2 MC |
5998 | } else { |
5999 | /* No work, shared interrupt perhaps? re-enable | |
6000 | * interrupts, and flush that PCI write | |
6001 | */ | |
6002 | tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, | |
6003 | 0x00000000); | |
fac9b83e | 6004 | } |
f47c11ee | 6005 | out: |
fac9b83e DM |
6006 | return IRQ_RETVAL(handled); |
6007 | } | |
6008 | ||
7d12e780 | 6009 | static irqreturn_t tg3_interrupt_tagged(int irq, void *dev_id) |
fac9b83e | 6010 | { |
09943a18 MC |
6011 | struct tg3_napi *tnapi = dev_id; |
6012 | struct tg3 *tp = tnapi->tp; | |
898a56f8 | 6013 | struct tg3_hw_status *sblk = tnapi->hw_status; |
fac9b83e DM |
6014 | unsigned int handled = 1; |
6015 | ||
fac9b83e DM |
6016 | /* In INTx mode, it is possible for the interrupt to arrive at |
6017 | * the CPU before the status block posted prior to the interrupt. | |
6018 | * Reading the PCI State register will confirm whether the | |
6019 | * interrupt is ours and will flush the status block. | |
6020 | */ | |
898a56f8 | 6021 | if (unlikely(sblk->status_tag == tnapi->last_irq_tag)) { |
63c3a66f | 6022 | if (tg3_flag(tp, CHIP_RESETTING) || |
d18edcb2 MC |
6023 | (tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) { |
6024 | handled = 0; | |
f47c11ee | 6025 | goto out; |
1da177e4 | 6026 | } |
d18edcb2 MC |
6027 | } |
6028 | ||
6029 | /* | |
6030 | * writing any value to intr-mbox-0 clears PCI INTA# and | |
6031 | * chip-internal interrupt pending events. | |
6032 | * writing non-zero to intr-mbox-0 additional tells the | |
6033 | * NIC to stop sending us irqs, engaging "in-intr-handler" | |
6034 | * event coalescing. | |
c04cb347 MC |
6035 | * |
6036 | * Flush the mailbox to de-assert the IRQ immediately to prevent | |
6037 | * spurious interrupts. The flush impacts performance but | |
6038 | * excessive spurious interrupts can be worse in some cases. | |
d18edcb2 | 6039 | */ |
c04cb347 | 6040 | tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001); |
624f8e50 MC |
6041 | |
6042 | /* | |
6043 | * In a shared interrupt configuration, sometimes other devices' | |
6044 | * interrupts will scream. We record the current status tag here | |
6045 | * so that the above check can report that the screaming interrupts | |
6046 | * are unhandled. Eventually they will be silenced. | |
6047 | */ | |
898a56f8 | 6048 | tnapi->last_irq_tag = sblk->status_tag; |
624f8e50 | 6049 | |
d18edcb2 MC |
6050 | if (tg3_irq_sync(tp)) |
6051 | goto out; | |
624f8e50 | 6052 | |
72334482 | 6053 | prefetch(&tnapi->rx_rcb[tnapi->rx_rcb_ptr]); |
624f8e50 | 6054 | |
09943a18 | 6055 | napi_schedule(&tnapi->napi); |
624f8e50 | 6056 | |
f47c11ee | 6057 | out: |
1da177e4 LT |
6058 | return IRQ_RETVAL(handled); |
6059 | } | |
6060 | ||
7938109f | 6061 | /* ISR for interrupt test */ |
7d12e780 | 6062 | static irqreturn_t tg3_test_isr(int irq, void *dev_id) |
7938109f | 6063 | { |
09943a18 MC |
6064 | struct tg3_napi *tnapi = dev_id; |
6065 | struct tg3 *tp = tnapi->tp; | |
898a56f8 | 6066 | struct tg3_hw_status *sblk = tnapi->hw_status; |
7938109f | 6067 | |
f9804ddb MC |
6068 | if ((sblk->status & SD_STATUS_UPDATED) || |
6069 | !(tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) { | |
b16250e3 | 6070 | tg3_disable_ints(tp); |
7938109f MC |
6071 | return IRQ_RETVAL(1); |
6072 | } | |
6073 | return IRQ_RETVAL(0); | |
6074 | } | |
6075 | ||
8e7a22e3 | 6076 | static int tg3_init_hw(struct tg3 *, int); |
944d980e | 6077 | static int tg3_halt(struct tg3 *, int, int); |
1da177e4 | 6078 | |
b9ec6c1b MC |
6079 | /* Restart hardware after configuration changes, self-test, etc. |
6080 | * Invoked with tp->lock held. | |
6081 | */ | |
6082 | static int tg3_restart_hw(struct tg3 *tp, int reset_phy) | |
78c6146f ED |
6083 | __releases(tp->lock) |
6084 | __acquires(tp->lock) | |
b9ec6c1b MC |
6085 | { |
6086 | int err; | |
6087 | ||
6088 | err = tg3_init_hw(tp, reset_phy); | |
6089 | if (err) { | |
5129c3a3 MC |
6090 | netdev_err(tp->dev, |
6091 | "Failed to re-initialize device, aborting\n"); | |
b9ec6c1b MC |
6092 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
6093 | tg3_full_unlock(tp); | |
6094 | del_timer_sync(&tp->timer); | |
6095 | tp->irq_sync = 0; | |
fed97810 | 6096 | tg3_napi_enable(tp); |
b9ec6c1b MC |
6097 | dev_close(tp->dev); |
6098 | tg3_full_lock(tp, 0); | |
6099 | } | |
6100 | return err; | |
6101 | } | |
6102 | ||
1da177e4 LT |
6103 | #ifdef CONFIG_NET_POLL_CONTROLLER |
6104 | static void tg3_poll_controller(struct net_device *dev) | |
6105 | { | |
4f125f42 | 6106 | int i; |
88b06bc2 MC |
6107 | struct tg3 *tp = netdev_priv(dev); |
6108 | ||
4f125f42 | 6109 | for (i = 0; i < tp->irq_cnt; i++) |
fe234f0e | 6110 | tg3_interrupt(tp->napi[i].irq_vec, &tp->napi[i]); |
1da177e4 LT |
6111 | } |
6112 | #endif | |
6113 | ||
c4028958 | 6114 | static void tg3_reset_task(struct work_struct *work) |
1da177e4 | 6115 | { |
c4028958 | 6116 | struct tg3 *tp = container_of(work, struct tg3, reset_task); |
b02fd9e3 | 6117 | int err; |
1da177e4 LT |
6118 | unsigned int restart_timer; |
6119 | ||
7faa006f | 6120 | tg3_full_lock(tp, 0); |
7faa006f MC |
6121 | |
6122 | if (!netif_running(tp->dev)) { | |
7faa006f MC |
6123 | tg3_full_unlock(tp); |
6124 | return; | |
6125 | } | |
6126 | ||
6127 | tg3_full_unlock(tp); | |
6128 | ||
b02fd9e3 MC |
6129 | tg3_phy_stop(tp); |
6130 | ||
1da177e4 LT |
6131 | tg3_netif_stop(tp); |
6132 | ||
f47c11ee | 6133 | tg3_full_lock(tp, 1); |
1da177e4 | 6134 | |
63c3a66f JP |
6135 | restart_timer = tg3_flag(tp, RESTART_TIMER); |
6136 | tg3_flag_clear(tp, RESTART_TIMER); | |
1da177e4 | 6137 | |
63c3a66f | 6138 | if (tg3_flag(tp, TX_RECOVERY_PENDING)) { |
df3e6548 MC |
6139 | tp->write32_tx_mbox = tg3_write32_tx_mbox; |
6140 | tp->write32_rx_mbox = tg3_write_flush_reg32; | |
63c3a66f JP |
6141 | tg3_flag_set(tp, MBOX_WRITE_REORDER); |
6142 | tg3_flag_clear(tp, TX_RECOVERY_PENDING); | |
df3e6548 MC |
6143 | } |
6144 | ||
944d980e | 6145 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 0); |
b02fd9e3 MC |
6146 | err = tg3_init_hw(tp, 1); |
6147 | if (err) | |
b9ec6c1b | 6148 | goto out; |
1da177e4 LT |
6149 | |
6150 | tg3_netif_start(tp); | |
6151 | ||
1da177e4 LT |
6152 | if (restart_timer) |
6153 | mod_timer(&tp->timer, jiffies + 1); | |
7faa006f | 6154 | |
b9ec6c1b | 6155 | out: |
7faa006f | 6156 | tg3_full_unlock(tp); |
b02fd9e3 MC |
6157 | |
6158 | if (!err) | |
6159 | tg3_phy_start(tp); | |
1da177e4 LT |
6160 | } |
6161 | ||
6162 | static void tg3_tx_timeout(struct net_device *dev) | |
6163 | { | |
6164 | struct tg3 *tp = netdev_priv(dev); | |
6165 | ||
b0408751 | 6166 | if (netif_msg_tx_err(tp)) { |
05dbe005 | 6167 | netdev_err(dev, "transmit timed out, resetting\n"); |
97bd8e49 | 6168 | tg3_dump_state(tp); |
b0408751 | 6169 | } |
1da177e4 LT |
6170 | |
6171 | schedule_work(&tp->reset_task); | |
6172 | } | |
6173 | ||
c58ec932 MC |
6174 | /* Test for DMA buffers crossing any 4GB boundaries: 4G, 8G, etc */ |
6175 | static inline int tg3_4g_overflow_test(dma_addr_t mapping, int len) | |
6176 | { | |
6177 | u32 base = (u32) mapping & 0xffffffff; | |
6178 | ||
807540ba | 6179 | return (base > 0xffffdcc0) && (base + len + 8 < base); |
c58ec932 MC |
6180 | } |
6181 | ||
72f2afb8 MC |
6182 | /* Test for DMA addresses > 40-bit */ |
6183 | static inline int tg3_40bit_overflow_test(struct tg3 *tp, dma_addr_t mapping, | |
6184 | int len) | |
6185 | { | |
6186 | #if defined(CONFIG_HIGHMEM) && (BITS_PER_LONG == 64) | |
63c3a66f | 6187 | if (tg3_flag(tp, 40BIT_DMA_BUG)) |
807540ba | 6188 | return ((u64) mapping + len) > DMA_BIT_MASK(40); |
72f2afb8 MC |
6189 | return 0; |
6190 | #else | |
6191 | return 0; | |
6192 | #endif | |
6193 | } | |
6194 | ||
d1a3b737 | 6195 | static inline void tg3_tx_set_bd(struct tg3_tx_buffer_desc *txbd, |
92cd3a17 MC |
6196 | dma_addr_t mapping, u32 len, u32 flags, |
6197 | u32 mss, u32 vlan) | |
2ffcc981 | 6198 | { |
92cd3a17 MC |
6199 | txbd->addr_hi = ((u64) mapping >> 32); |
6200 | txbd->addr_lo = ((u64) mapping & 0xffffffff); | |
6201 | txbd->len_flags = (len << TXD_LEN_SHIFT) | (flags & 0x0000ffff); | |
6202 | txbd->vlan_tag = (mss << TXD_MSS_SHIFT) | (vlan << TXD_VLAN_TAG_SHIFT); | |
2ffcc981 | 6203 | } |
1da177e4 | 6204 | |
84b67b27 | 6205 | static bool tg3_tx_frag_set(struct tg3_napi *tnapi, u32 *entry, u32 *budget, |
d1a3b737 MC |
6206 | dma_addr_t map, u32 len, u32 flags, |
6207 | u32 mss, u32 vlan) | |
6208 | { | |
6209 | struct tg3 *tp = tnapi->tp; | |
6210 | bool hwbug = false; | |
6211 | ||
6212 | if (tg3_flag(tp, SHORT_DMA_BUG) && len <= 8) | |
6213 | hwbug = 1; | |
6214 | ||
6215 | if (tg3_4g_overflow_test(map, len)) | |
6216 | hwbug = 1; | |
6217 | ||
6218 | if (tg3_40bit_overflow_test(tp, map, len)) | |
6219 | hwbug = 1; | |
6220 | ||
e31aa987 MC |
6221 | if (tg3_flag(tp, 4K_FIFO_LIMIT)) { |
6222 | u32 tmp_flag = flags & ~TXD_FLAG_END; | |
6223 | while (len > TG3_TX_BD_DMA_MAX) { | |
6224 | u32 frag_len = TG3_TX_BD_DMA_MAX; | |
6225 | len -= TG3_TX_BD_DMA_MAX; | |
6226 | ||
6227 | if (len) { | |
6228 | tnapi->tx_buffers[*entry].fragmented = true; | |
6229 | /* Avoid the 8byte DMA problem */ | |
6230 | if (len <= 8) { | |
6231 | len += TG3_TX_BD_DMA_MAX / 2; | |
6232 | frag_len = TG3_TX_BD_DMA_MAX / 2; | |
6233 | } | |
6234 | } else | |
6235 | tmp_flag = flags; | |
6236 | ||
6237 | if (*budget) { | |
6238 | tg3_tx_set_bd(&tnapi->tx_ring[*entry], map, | |
6239 | frag_len, tmp_flag, mss, vlan); | |
6240 | (*budget)--; | |
6241 | *entry = NEXT_TX(*entry); | |
6242 | } else { | |
6243 | hwbug = 1; | |
6244 | break; | |
6245 | } | |
6246 | ||
6247 | map += frag_len; | |
6248 | } | |
6249 | ||
6250 | if (len) { | |
6251 | if (*budget) { | |
6252 | tg3_tx_set_bd(&tnapi->tx_ring[*entry], map, | |
6253 | len, flags, mss, vlan); | |
6254 | (*budget)--; | |
6255 | *entry = NEXT_TX(*entry); | |
6256 | } else { | |
6257 | hwbug = 1; | |
6258 | } | |
6259 | } | |
6260 | } else { | |
84b67b27 MC |
6261 | tg3_tx_set_bd(&tnapi->tx_ring[*entry], map, |
6262 | len, flags, mss, vlan); | |
e31aa987 MC |
6263 | *entry = NEXT_TX(*entry); |
6264 | } | |
d1a3b737 MC |
6265 | |
6266 | return hwbug; | |
6267 | } | |
6268 | ||
0d681b27 | 6269 | static void tg3_tx_skb_unmap(struct tg3_napi *tnapi, u32 entry, int last) |
432aa7ed MC |
6270 | { |
6271 | int i; | |
0d681b27 | 6272 | struct sk_buff *skb; |
df8944cf | 6273 | struct tg3_tx_ring_info *txb = &tnapi->tx_buffers[entry]; |
432aa7ed | 6274 | |
0d681b27 MC |
6275 | skb = txb->skb; |
6276 | txb->skb = NULL; | |
6277 | ||
432aa7ed MC |
6278 | pci_unmap_single(tnapi->tp->pdev, |
6279 | dma_unmap_addr(txb, mapping), | |
6280 | skb_headlen(skb), | |
6281 | PCI_DMA_TODEVICE); | |
e01ee14d MC |
6282 | |
6283 | while (txb->fragmented) { | |
6284 | txb->fragmented = false; | |
6285 | entry = NEXT_TX(entry); | |
6286 | txb = &tnapi->tx_buffers[entry]; | |
6287 | } | |
6288 | ||
9a2e0fb0 | 6289 | for (i = 0; i < last; i++) { |
432aa7ed MC |
6290 | skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; |
6291 | ||
6292 | entry = NEXT_TX(entry); | |
6293 | txb = &tnapi->tx_buffers[entry]; | |
6294 | ||
6295 | pci_unmap_page(tnapi->tp->pdev, | |
6296 | dma_unmap_addr(txb, mapping), | |
6297 | frag->size, PCI_DMA_TODEVICE); | |
e01ee14d MC |
6298 | |
6299 | while (txb->fragmented) { | |
6300 | txb->fragmented = false; | |
6301 | entry = NEXT_TX(entry); | |
6302 | txb = &tnapi->tx_buffers[entry]; | |
6303 | } | |
432aa7ed MC |
6304 | } |
6305 | } | |
6306 | ||
72f2afb8 | 6307 | /* Workaround 4GB and 40-bit hardware DMA bugs. */ |
24f4efd4 | 6308 | static int tigon3_dma_hwbug_workaround(struct tg3_napi *tnapi, |
432aa7ed | 6309 | struct sk_buff *skb, |
84b67b27 | 6310 | u32 *entry, u32 *budget, |
92cd3a17 | 6311 | u32 base_flags, u32 mss, u32 vlan) |
1da177e4 | 6312 | { |
24f4efd4 | 6313 | struct tg3 *tp = tnapi->tp; |
41588ba1 | 6314 | struct sk_buff *new_skb; |
c58ec932 | 6315 | dma_addr_t new_addr = 0; |
432aa7ed | 6316 | int ret = 0; |
1da177e4 | 6317 | |
41588ba1 MC |
6318 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) |
6319 | new_skb = skb_copy(skb, GFP_ATOMIC); | |
6320 | else { | |
6321 | int more_headroom = 4 - ((unsigned long)skb->data & 3); | |
6322 | ||
6323 | new_skb = skb_copy_expand(skb, | |
6324 | skb_headroom(skb) + more_headroom, | |
6325 | skb_tailroom(skb), GFP_ATOMIC); | |
6326 | } | |
6327 | ||
1da177e4 | 6328 | if (!new_skb) { |
c58ec932 MC |
6329 | ret = -1; |
6330 | } else { | |
6331 | /* New SKB is guaranteed to be linear. */ | |
f4188d8a AD |
6332 | new_addr = pci_map_single(tp->pdev, new_skb->data, new_skb->len, |
6333 | PCI_DMA_TODEVICE); | |
6334 | /* Make sure the mapping succeeded */ | |
6335 | if (pci_dma_mapping_error(tp->pdev, new_addr)) { | |
f4188d8a | 6336 | dev_kfree_skb(new_skb); |
c58ec932 | 6337 | ret = -1; |
c58ec932 | 6338 | } else { |
92cd3a17 MC |
6339 | base_flags |= TXD_FLAG_END; |
6340 | ||
84b67b27 MC |
6341 | tnapi->tx_buffers[*entry].skb = new_skb; |
6342 | dma_unmap_addr_set(&tnapi->tx_buffers[*entry], | |
432aa7ed MC |
6343 | mapping, new_addr); |
6344 | ||
84b67b27 | 6345 | if (tg3_tx_frag_set(tnapi, entry, budget, new_addr, |
d1a3b737 MC |
6346 | new_skb->len, base_flags, |
6347 | mss, vlan)) { | |
84b67b27 | 6348 | tg3_tx_skb_unmap(tnapi, *entry, 0); |
d1a3b737 MC |
6349 | dev_kfree_skb(new_skb); |
6350 | ret = -1; | |
6351 | } | |
f4188d8a | 6352 | } |
1da177e4 LT |
6353 | } |
6354 | ||
6355 | dev_kfree_skb(skb); | |
6356 | ||
c58ec932 | 6357 | return ret; |
1da177e4 LT |
6358 | } |
6359 | ||
2ffcc981 | 6360 | static netdev_tx_t tg3_start_xmit(struct sk_buff *, struct net_device *); |
52c0fd83 MC |
6361 | |
6362 | /* Use GSO to workaround a rare TSO bug that may be triggered when the | |
6363 | * TSO header is greater than 80 bytes. | |
6364 | */ | |
6365 | static int tg3_tso_bug(struct tg3 *tp, struct sk_buff *skb) | |
6366 | { | |
6367 | struct sk_buff *segs, *nskb; | |
f3f3f27e | 6368 | u32 frag_cnt_est = skb_shinfo(skb)->gso_segs * 3; |
52c0fd83 MC |
6369 | |
6370 | /* Estimate the number of fragments in the worst case */ | |
f3f3f27e | 6371 | if (unlikely(tg3_tx_avail(&tp->napi[0]) <= frag_cnt_est)) { |
52c0fd83 | 6372 | netif_stop_queue(tp->dev); |
f65aac16 MC |
6373 | |
6374 | /* netif_tx_stop_queue() must be done before checking | |
6375 | * checking tx index in tg3_tx_avail() below, because in | |
6376 | * tg3_tx(), we update tx index before checking for | |
6377 | * netif_tx_queue_stopped(). | |
6378 | */ | |
6379 | smp_mb(); | |
f3f3f27e | 6380 | if (tg3_tx_avail(&tp->napi[0]) <= frag_cnt_est) |
7f62ad5d MC |
6381 | return NETDEV_TX_BUSY; |
6382 | ||
6383 | netif_wake_queue(tp->dev); | |
52c0fd83 MC |
6384 | } |
6385 | ||
6386 | segs = skb_gso_segment(skb, tp->dev->features & ~NETIF_F_TSO); | |
801678c5 | 6387 | if (IS_ERR(segs)) |
52c0fd83 MC |
6388 | goto tg3_tso_bug_end; |
6389 | ||
6390 | do { | |
6391 | nskb = segs; | |
6392 | segs = segs->next; | |
6393 | nskb->next = NULL; | |
2ffcc981 | 6394 | tg3_start_xmit(nskb, tp->dev); |
52c0fd83 MC |
6395 | } while (segs); |
6396 | ||
6397 | tg3_tso_bug_end: | |
6398 | dev_kfree_skb(skb); | |
6399 | ||
6400 | return NETDEV_TX_OK; | |
6401 | } | |
52c0fd83 | 6402 | |
5a6f3074 | 6403 | /* hard_start_xmit for devices that have the 4G bug and/or 40-bit bug and |
63c3a66f | 6404 | * support TG3_FLAG_HW_TSO_1 or firmware TSO only. |
5a6f3074 | 6405 | */ |
2ffcc981 | 6406 | static netdev_tx_t tg3_start_xmit(struct sk_buff *skb, struct net_device *dev) |
1da177e4 LT |
6407 | { |
6408 | struct tg3 *tp = netdev_priv(dev); | |
92cd3a17 | 6409 | u32 len, entry, base_flags, mss, vlan = 0; |
84b67b27 | 6410 | u32 budget; |
432aa7ed | 6411 | int i = -1, would_hit_hwbug; |
90079ce8 | 6412 | dma_addr_t mapping; |
24f4efd4 MC |
6413 | struct tg3_napi *tnapi; |
6414 | struct netdev_queue *txq; | |
432aa7ed | 6415 | unsigned int last; |
f4188d8a | 6416 | |
24f4efd4 MC |
6417 | txq = netdev_get_tx_queue(dev, skb_get_queue_mapping(skb)); |
6418 | tnapi = &tp->napi[skb_get_queue_mapping(skb)]; | |
63c3a66f | 6419 | if (tg3_flag(tp, ENABLE_TSS)) |
24f4efd4 | 6420 | tnapi++; |
1da177e4 | 6421 | |
84b67b27 MC |
6422 | budget = tg3_tx_avail(tnapi); |
6423 | ||
00b70504 | 6424 | /* We are running in BH disabled context with netif_tx_lock |
bea3348e | 6425 | * and TX reclaim runs via tp->napi.poll inside of a software |
f47c11ee DM |
6426 | * interrupt. Furthermore, IRQ processing runs lockless so we have |
6427 | * no IRQ context deadlocks to worry about either. Rejoice! | |
1da177e4 | 6428 | */ |
84b67b27 | 6429 | if (unlikely(budget <= (skb_shinfo(skb)->nr_frags + 1))) { |
24f4efd4 MC |
6430 | if (!netif_tx_queue_stopped(txq)) { |
6431 | netif_tx_stop_queue(txq); | |
1f064a87 SH |
6432 | |
6433 | /* This is a hard error, log it. */ | |
5129c3a3 MC |
6434 | netdev_err(dev, |
6435 | "BUG! Tx Ring full when queue awake!\n"); | |
1f064a87 | 6436 | } |
1da177e4 LT |
6437 | return NETDEV_TX_BUSY; |
6438 | } | |
6439 | ||
f3f3f27e | 6440 | entry = tnapi->tx_prod; |
1da177e4 | 6441 | base_flags = 0; |
84fa7933 | 6442 | if (skb->ip_summed == CHECKSUM_PARTIAL) |
1da177e4 | 6443 | base_flags |= TXD_FLAG_TCPUDP_CSUM; |
24f4efd4 | 6444 | |
be98da6a MC |
6445 | mss = skb_shinfo(skb)->gso_size; |
6446 | if (mss) { | |
eddc9ec5 | 6447 | struct iphdr *iph; |
34195c3d | 6448 | u32 tcp_opt_len, hdr_len; |
1da177e4 LT |
6449 | |
6450 | if (skb_header_cloned(skb) && | |
6451 | pskb_expand_head(skb, 0, 0, GFP_ATOMIC)) { | |
6452 | dev_kfree_skb(skb); | |
6453 | goto out_unlock; | |
6454 | } | |
6455 | ||
34195c3d | 6456 | iph = ip_hdr(skb); |
ab6a5bb6 | 6457 | tcp_opt_len = tcp_optlen(skb); |
1da177e4 | 6458 | |
02e96080 | 6459 | if (skb_is_gso_v6(skb)) { |
34195c3d MC |
6460 | hdr_len = skb_headlen(skb) - ETH_HLEN; |
6461 | } else { | |
6462 | u32 ip_tcp_len; | |
6463 | ||
6464 | ip_tcp_len = ip_hdrlen(skb) + sizeof(struct tcphdr); | |
6465 | hdr_len = ip_tcp_len + tcp_opt_len; | |
6466 | ||
6467 | iph->check = 0; | |
6468 | iph->tot_len = htons(mss + hdr_len); | |
6469 | } | |
6470 | ||
52c0fd83 | 6471 | if (unlikely((ETH_HLEN + hdr_len) > 80) && |
63c3a66f | 6472 | tg3_flag(tp, TSO_BUG)) |
de6f31eb | 6473 | return tg3_tso_bug(tp, skb); |
52c0fd83 | 6474 | |
1da177e4 LT |
6475 | base_flags |= (TXD_FLAG_CPU_PRE_DMA | |
6476 | TXD_FLAG_CPU_POST_DMA); | |
6477 | ||
63c3a66f JP |
6478 | if (tg3_flag(tp, HW_TSO_1) || |
6479 | tg3_flag(tp, HW_TSO_2) || | |
6480 | tg3_flag(tp, HW_TSO_3)) { | |
aa8223c7 | 6481 | tcp_hdr(skb)->check = 0; |
1da177e4 | 6482 | base_flags &= ~TXD_FLAG_TCPUDP_CSUM; |
aa8223c7 ACM |
6483 | } else |
6484 | tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, | |
6485 | iph->daddr, 0, | |
6486 | IPPROTO_TCP, | |
6487 | 0); | |
1da177e4 | 6488 | |
63c3a66f | 6489 | if (tg3_flag(tp, HW_TSO_3)) { |
615774fe MC |
6490 | mss |= (hdr_len & 0xc) << 12; |
6491 | if (hdr_len & 0x10) | |
6492 | base_flags |= 0x00000010; | |
6493 | base_flags |= (hdr_len & 0x3e0) << 5; | |
63c3a66f | 6494 | } else if (tg3_flag(tp, HW_TSO_2)) |
92c6b8d1 | 6495 | mss |= hdr_len << 9; |
63c3a66f | 6496 | else if (tg3_flag(tp, HW_TSO_1) || |
92c6b8d1 | 6497 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) { |
eddc9ec5 | 6498 | if (tcp_opt_len || iph->ihl > 5) { |
1da177e4 LT |
6499 | int tsflags; |
6500 | ||
eddc9ec5 | 6501 | tsflags = (iph->ihl - 5) + (tcp_opt_len >> 2); |
1da177e4 LT |
6502 | mss |= (tsflags << 11); |
6503 | } | |
6504 | } else { | |
eddc9ec5 | 6505 | if (tcp_opt_len || iph->ihl > 5) { |
1da177e4 LT |
6506 | int tsflags; |
6507 | ||
eddc9ec5 | 6508 | tsflags = (iph->ihl - 5) + (tcp_opt_len >> 2); |
1da177e4 LT |
6509 | base_flags |= tsflags << 12; |
6510 | } | |
6511 | } | |
6512 | } | |
bf933c80 | 6513 | |
92cd3a17 MC |
6514 | #ifdef BCM_KERNEL_SUPPORTS_8021Q |
6515 | if (vlan_tx_tag_present(skb)) { | |
6516 | base_flags |= TXD_FLAG_VLAN; | |
6517 | vlan = vlan_tx_tag_get(skb); | |
6518 | } | |
6519 | #endif | |
1da177e4 | 6520 | |
63c3a66f | 6521 | if (tg3_flag(tp, USE_JUMBO_BDFLAG) && |
8fc2f995 | 6522 | !mss && skb->len > VLAN_ETH_FRAME_LEN) |
615774fe MC |
6523 | base_flags |= TXD_FLAG_JMB_PKT; |
6524 | ||
f4188d8a AD |
6525 | len = skb_headlen(skb); |
6526 | ||
6527 | mapping = pci_map_single(tp->pdev, skb->data, len, PCI_DMA_TODEVICE); | |
6528 | if (pci_dma_mapping_error(tp->pdev, mapping)) { | |
90079ce8 DM |
6529 | dev_kfree_skb(skb); |
6530 | goto out_unlock; | |
6531 | } | |
6532 | ||
f3f3f27e | 6533 | tnapi->tx_buffers[entry].skb = skb; |
4e5e4f0d | 6534 | dma_unmap_addr_set(&tnapi->tx_buffers[entry], mapping, mapping); |
1da177e4 LT |
6535 | |
6536 | would_hit_hwbug = 0; | |
6537 | ||
63c3a66f | 6538 | if (tg3_flag(tp, 5701_DMA_BUG)) |
c58ec932 | 6539 | would_hit_hwbug = 1; |
1da177e4 | 6540 | |
84b67b27 | 6541 | if (tg3_tx_frag_set(tnapi, &entry, &budget, mapping, len, base_flags | |
d1a3b737 MC |
6542 | ((skb_shinfo(skb)->nr_frags == 0) ? TXD_FLAG_END : 0), |
6543 | mss, vlan)) | |
6544 | would_hit_hwbug = 1; | |
1da177e4 | 6545 | |
1da177e4 LT |
6546 | /* Now loop through additional data fragments, and queue them. */ |
6547 | if (skb_shinfo(skb)->nr_frags > 0) { | |
92cd3a17 MC |
6548 | u32 tmp_mss = mss; |
6549 | ||
6550 | if (!tg3_flag(tp, HW_TSO_1) && | |
6551 | !tg3_flag(tp, HW_TSO_2) && | |
6552 | !tg3_flag(tp, HW_TSO_3)) | |
6553 | tmp_mss = 0; | |
6554 | ||
1da177e4 LT |
6555 | last = skb_shinfo(skb)->nr_frags - 1; |
6556 | for (i = 0; i <= last; i++) { | |
6557 | skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; | |
6558 | ||
6559 | len = frag->size; | |
dc234d0b IC |
6560 | mapping = skb_frag_dma_map(&tp->pdev->dev, frag, 0, |
6561 | len, PCI_DMA_TODEVICE); | |
1da177e4 | 6562 | |
f3f3f27e | 6563 | tnapi->tx_buffers[entry].skb = NULL; |
4e5e4f0d | 6564 | dma_unmap_addr_set(&tnapi->tx_buffers[entry], mapping, |
f4188d8a AD |
6565 | mapping); |
6566 | if (pci_dma_mapping_error(tp->pdev, mapping)) | |
6567 | goto dma_error; | |
1da177e4 | 6568 | |
84b67b27 MC |
6569 | if (tg3_tx_frag_set(tnapi, &entry, &budget, mapping, |
6570 | len, base_flags | | |
6571 | ((i == last) ? TXD_FLAG_END : 0), | |
d1a3b737 | 6572 | tmp_mss, vlan)) |
72f2afb8 | 6573 | would_hit_hwbug = 1; |
1da177e4 LT |
6574 | } |
6575 | } | |
6576 | ||
6577 | if (would_hit_hwbug) { | |
0d681b27 | 6578 | tg3_tx_skb_unmap(tnapi, tnapi->tx_prod, i); |
1da177e4 LT |
6579 | |
6580 | /* If the workaround fails due to memory/mapping | |
6581 | * failure, silently drop this packet. | |
6582 | */ | |
84b67b27 MC |
6583 | entry = tnapi->tx_prod; |
6584 | budget = tg3_tx_avail(tnapi); | |
6585 | if (tigon3_dma_hwbug_workaround(tnapi, skb, &entry, &budget, | |
6586 | base_flags, mss, vlan)) | |
1da177e4 | 6587 | goto out_unlock; |
1da177e4 LT |
6588 | } |
6589 | ||
d515b450 RC |
6590 | skb_tx_timestamp(skb); |
6591 | ||
1da177e4 | 6592 | /* Packets are ready, update Tx producer idx local and on card. */ |
24f4efd4 | 6593 | tw32_tx_mbox(tnapi->prodmbox, entry); |
1da177e4 | 6594 | |
f3f3f27e MC |
6595 | tnapi->tx_prod = entry; |
6596 | if (unlikely(tg3_tx_avail(tnapi) <= (MAX_SKB_FRAGS + 1))) { | |
24f4efd4 | 6597 | netif_tx_stop_queue(txq); |
f65aac16 MC |
6598 | |
6599 | /* netif_tx_stop_queue() must be done before checking | |
6600 | * checking tx index in tg3_tx_avail() below, because in | |
6601 | * tg3_tx(), we update tx index before checking for | |
6602 | * netif_tx_queue_stopped(). | |
6603 | */ | |
6604 | smp_mb(); | |
f3f3f27e | 6605 | if (tg3_tx_avail(tnapi) > TG3_TX_WAKEUP_THRESH(tnapi)) |
24f4efd4 | 6606 | netif_tx_wake_queue(txq); |
51b91468 | 6607 | } |
1da177e4 LT |
6608 | |
6609 | out_unlock: | |
cdd0db05 | 6610 | mmiowb(); |
1da177e4 LT |
6611 | |
6612 | return NETDEV_TX_OK; | |
f4188d8a AD |
6613 | |
6614 | dma_error: | |
0d681b27 | 6615 | tg3_tx_skb_unmap(tnapi, tnapi->tx_prod, i); |
f4188d8a | 6616 | dev_kfree_skb(skb); |
432aa7ed | 6617 | tnapi->tx_buffers[tnapi->tx_prod].skb = NULL; |
f4188d8a | 6618 | return NETDEV_TX_OK; |
1da177e4 LT |
6619 | } |
6620 | ||
6e01b20b MC |
6621 | static void tg3_mac_loopback(struct tg3 *tp, bool enable) |
6622 | { | |
6623 | if (enable) { | |
6624 | tp->mac_mode &= ~(MAC_MODE_HALF_DUPLEX | | |
6625 | MAC_MODE_PORT_MODE_MASK); | |
6626 | ||
6627 | tp->mac_mode |= MAC_MODE_PORT_INT_LPBACK; | |
6628 | ||
6629 | if (!tg3_flag(tp, 5705_PLUS)) | |
6630 | tp->mac_mode |= MAC_MODE_LINK_POLARITY; | |
6631 | ||
6632 | if (tp->phy_flags & TG3_PHYFLG_10_100_ONLY) | |
6633 | tp->mac_mode |= MAC_MODE_PORT_MODE_MII; | |
6634 | else | |
6635 | tp->mac_mode |= MAC_MODE_PORT_MODE_GMII; | |
6636 | } else { | |
6637 | tp->mac_mode &= ~MAC_MODE_PORT_INT_LPBACK; | |
6638 | ||
6639 | if (tg3_flag(tp, 5705_PLUS) || | |
6640 | (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) || | |
6641 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) | |
6642 | tp->mac_mode &= ~MAC_MODE_LINK_POLARITY; | |
6643 | } | |
6644 | ||
6645 | tw32(MAC_MODE, tp->mac_mode); | |
6646 | udelay(40); | |
6647 | } | |
6648 | ||
941ec90f | 6649 | static int tg3_phy_lpbk_set(struct tg3 *tp, u32 speed, bool extlpbk) |
5e5a7f37 | 6650 | { |
941ec90f | 6651 | u32 val, bmcr, mac_mode, ptest = 0; |
5e5a7f37 MC |
6652 | |
6653 | tg3_phy_toggle_apd(tp, false); | |
6654 | tg3_phy_toggle_automdix(tp, 0); | |
6655 | ||
941ec90f MC |
6656 | if (extlpbk && tg3_phy_set_extloopbk(tp)) |
6657 | return -EIO; | |
6658 | ||
6659 | bmcr = BMCR_FULLDPLX; | |
5e5a7f37 MC |
6660 | switch (speed) { |
6661 | case SPEED_10: | |
6662 | break; | |
6663 | case SPEED_100: | |
6664 | bmcr |= BMCR_SPEED100; | |
6665 | break; | |
6666 | case SPEED_1000: | |
6667 | default: | |
6668 | if (tp->phy_flags & TG3_PHYFLG_IS_FET) { | |
6669 | speed = SPEED_100; | |
6670 | bmcr |= BMCR_SPEED100; | |
6671 | } else { | |
6672 | speed = SPEED_1000; | |
6673 | bmcr |= BMCR_SPEED1000; | |
6674 | } | |
6675 | } | |
6676 | ||
941ec90f MC |
6677 | if (extlpbk) { |
6678 | if (!(tp->phy_flags & TG3_PHYFLG_IS_FET)) { | |
6679 | tg3_readphy(tp, MII_CTRL1000, &val); | |
6680 | val |= CTL1000_AS_MASTER | | |
6681 | CTL1000_ENABLE_MASTER; | |
6682 | tg3_writephy(tp, MII_CTRL1000, val); | |
6683 | } else { | |
6684 | ptest = MII_TG3_FET_PTEST_TRIM_SEL | | |
6685 | MII_TG3_FET_PTEST_TRIM_2; | |
6686 | tg3_writephy(tp, MII_TG3_FET_PTEST, ptest); | |
6687 | } | |
6688 | } else | |
6689 | bmcr |= BMCR_LOOPBACK; | |
6690 | ||
5e5a7f37 MC |
6691 | tg3_writephy(tp, MII_BMCR, bmcr); |
6692 | ||
6693 | /* The write needs to be flushed for the FETs */ | |
6694 | if (tp->phy_flags & TG3_PHYFLG_IS_FET) | |
6695 | tg3_readphy(tp, MII_BMCR, &bmcr); | |
6696 | ||
6697 | udelay(40); | |
6698 | ||
6699 | if ((tp->phy_flags & TG3_PHYFLG_IS_FET) && | |
6700 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) { | |
941ec90f | 6701 | tg3_writephy(tp, MII_TG3_FET_PTEST, ptest | |
5e5a7f37 MC |
6702 | MII_TG3_FET_PTEST_FRC_TX_LINK | |
6703 | MII_TG3_FET_PTEST_FRC_TX_LOCK); | |
6704 | ||
6705 | /* The write needs to be flushed for the AC131 */ | |
6706 | tg3_readphy(tp, MII_TG3_FET_PTEST, &val); | |
6707 | } | |
6708 | ||
6709 | /* Reset to prevent losing 1st rx packet intermittently */ | |
6710 | if ((tp->phy_flags & TG3_PHYFLG_MII_SERDES) && | |
6711 | tg3_flag(tp, 5780_CLASS)) { | |
6712 | tw32_f(MAC_RX_MODE, RX_MODE_RESET); | |
6713 | udelay(10); | |
6714 | tw32_f(MAC_RX_MODE, tp->rx_mode); | |
6715 | } | |
6716 | ||
6717 | mac_mode = tp->mac_mode & | |
6718 | ~(MAC_MODE_PORT_MODE_MASK | MAC_MODE_HALF_DUPLEX); | |
6719 | if (speed == SPEED_1000) | |
6720 | mac_mode |= MAC_MODE_PORT_MODE_GMII; | |
6721 | else | |
6722 | mac_mode |= MAC_MODE_PORT_MODE_MII; | |
6723 | ||
6724 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) { | |
6725 | u32 masked_phy_id = tp->phy_id & TG3_PHY_ID_MASK; | |
6726 | ||
6727 | if (masked_phy_id == TG3_PHY_ID_BCM5401) | |
6728 | mac_mode &= ~MAC_MODE_LINK_POLARITY; | |
6729 | else if (masked_phy_id == TG3_PHY_ID_BCM5411) | |
6730 | mac_mode |= MAC_MODE_LINK_POLARITY; | |
6731 | ||
6732 | tg3_writephy(tp, MII_TG3_EXT_CTRL, | |
6733 | MII_TG3_EXT_CTRL_LNK3_LED_MODE); | |
6734 | } | |
6735 | ||
6736 | tw32(MAC_MODE, mac_mode); | |
6737 | udelay(40); | |
941ec90f MC |
6738 | |
6739 | return 0; | |
5e5a7f37 MC |
6740 | } |
6741 | ||
06c03c02 MB |
6742 | static void tg3_set_loopback(struct net_device *dev, u32 features) |
6743 | { | |
6744 | struct tg3 *tp = netdev_priv(dev); | |
6745 | ||
6746 | if (features & NETIF_F_LOOPBACK) { | |
6747 | if (tp->mac_mode & MAC_MODE_PORT_INT_LPBACK) | |
6748 | return; | |
6749 | ||
06c03c02 | 6750 | spin_lock_bh(&tp->lock); |
6e01b20b | 6751 | tg3_mac_loopback(tp, true); |
06c03c02 MB |
6752 | netif_carrier_on(tp->dev); |
6753 | spin_unlock_bh(&tp->lock); | |
6754 | netdev_info(dev, "Internal MAC loopback mode enabled.\n"); | |
6755 | } else { | |
6756 | if (!(tp->mac_mode & MAC_MODE_PORT_INT_LPBACK)) | |
6757 | return; | |
6758 | ||
06c03c02 | 6759 | spin_lock_bh(&tp->lock); |
6e01b20b | 6760 | tg3_mac_loopback(tp, false); |
06c03c02 MB |
6761 | /* Force link status check */ |
6762 | tg3_setup_phy(tp, 1); | |
6763 | spin_unlock_bh(&tp->lock); | |
6764 | netdev_info(dev, "Internal MAC loopback mode disabled.\n"); | |
6765 | } | |
6766 | } | |
6767 | ||
dc668910 MM |
6768 | static u32 tg3_fix_features(struct net_device *dev, u32 features) |
6769 | { | |
6770 | struct tg3 *tp = netdev_priv(dev); | |
6771 | ||
63c3a66f | 6772 | if (dev->mtu > ETH_DATA_LEN && tg3_flag(tp, 5780_CLASS)) |
dc668910 MM |
6773 | features &= ~NETIF_F_ALL_TSO; |
6774 | ||
6775 | return features; | |
6776 | } | |
6777 | ||
06c03c02 MB |
6778 | static int tg3_set_features(struct net_device *dev, u32 features) |
6779 | { | |
6780 | u32 changed = dev->features ^ features; | |
6781 | ||
6782 | if ((changed & NETIF_F_LOOPBACK) && netif_running(dev)) | |
6783 | tg3_set_loopback(dev, features); | |
6784 | ||
6785 | return 0; | |
6786 | } | |
6787 | ||
1da177e4 LT |
6788 | static inline void tg3_set_mtu(struct net_device *dev, struct tg3 *tp, |
6789 | int new_mtu) | |
6790 | { | |
6791 | dev->mtu = new_mtu; | |
6792 | ||
ef7f5ec0 | 6793 | if (new_mtu > ETH_DATA_LEN) { |
63c3a66f | 6794 | if (tg3_flag(tp, 5780_CLASS)) { |
dc668910 | 6795 | netdev_update_features(dev); |
63c3a66f | 6796 | tg3_flag_clear(tp, TSO_CAPABLE); |
859a5887 | 6797 | } else { |
63c3a66f | 6798 | tg3_flag_set(tp, JUMBO_RING_ENABLE); |
859a5887 | 6799 | } |
ef7f5ec0 | 6800 | } else { |
63c3a66f JP |
6801 | if (tg3_flag(tp, 5780_CLASS)) { |
6802 | tg3_flag_set(tp, TSO_CAPABLE); | |
dc668910 MM |
6803 | netdev_update_features(dev); |
6804 | } | |
63c3a66f | 6805 | tg3_flag_clear(tp, JUMBO_RING_ENABLE); |
ef7f5ec0 | 6806 | } |
1da177e4 LT |
6807 | } |
6808 | ||
6809 | static int tg3_change_mtu(struct net_device *dev, int new_mtu) | |
6810 | { | |
6811 | struct tg3 *tp = netdev_priv(dev); | |
b9ec6c1b | 6812 | int err; |
1da177e4 LT |
6813 | |
6814 | if (new_mtu < TG3_MIN_MTU || new_mtu > TG3_MAX_MTU(tp)) | |
6815 | return -EINVAL; | |
6816 | ||
6817 | if (!netif_running(dev)) { | |
6818 | /* We'll just catch it later when the | |
6819 | * device is up'd. | |
6820 | */ | |
6821 | tg3_set_mtu(dev, tp, new_mtu); | |
6822 | return 0; | |
6823 | } | |
6824 | ||
b02fd9e3 MC |
6825 | tg3_phy_stop(tp); |
6826 | ||
1da177e4 | 6827 | tg3_netif_stop(tp); |
f47c11ee DM |
6828 | |
6829 | tg3_full_lock(tp, 1); | |
1da177e4 | 6830 | |
944d980e | 6831 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
1da177e4 LT |
6832 | |
6833 | tg3_set_mtu(dev, tp, new_mtu); | |
6834 | ||
b9ec6c1b | 6835 | err = tg3_restart_hw(tp, 0); |
1da177e4 | 6836 | |
b9ec6c1b MC |
6837 | if (!err) |
6838 | tg3_netif_start(tp); | |
1da177e4 | 6839 | |
f47c11ee | 6840 | tg3_full_unlock(tp); |
1da177e4 | 6841 | |
b02fd9e3 MC |
6842 | if (!err) |
6843 | tg3_phy_start(tp); | |
6844 | ||
b9ec6c1b | 6845 | return err; |
1da177e4 LT |
6846 | } |
6847 | ||
21f581a5 MC |
6848 | static void tg3_rx_prodring_free(struct tg3 *tp, |
6849 | struct tg3_rx_prodring_set *tpr) | |
1da177e4 | 6850 | { |
1da177e4 LT |
6851 | int i; |
6852 | ||
8fea32b9 | 6853 | if (tpr != &tp->napi[0].prodring) { |
b196c7e4 | 6854 | for (i = tpr->rx_std_cons_idx; i != tpr->rx_std_prod_idx; |
2c49a44d | 6855 | i = (i + 1) & tp->rx_std_ring_mask) |
b196c7e4 MC |
6856 | tg3_rx_skb_free(tp, &tpr->rx_std_buffers[i], |
6857 | tp->rx_pkt_map_sz); | |
6858 | ||
63c3a66f | 6859 | if (tg3_flag(tp, JUMBO_CAPABLE)) { |
b196c7e4 MC |
6860 | for (i = tpr->rx_jmb_cons_idx; |
6861 | i != tpr->rx_jmb_prod_idx; | |
2c49a44d | 6862 | i = (i + 1) & tp->rx_jmb_ring_mask) { |
b196c7e4 MC |
6863 | tg3_rx_skb_free(tp, &tpr->rx_jmb_buffers[i], |
6864 | TG3_RX_JMB_MAP_SZ); | |
6865 | } | |
6866 | } | |
6867 | ||
2b2cdb65 | 6868 | return; |
b196c7e4 | 6869 | } |
1da177e4 | 6870 | |
2c49a44d | 6871 | for (i = 0; i <= tp->rx_std_ring_mask; i++) |
2b2cdb65 MC |
6872 | tg3_rx_skb_free(tp, &tpr->rx_std_buffers[i], |
6873 | tp->rx_pkt_map_sz); | |
1da177e4 | 6874 | |
63c3a66f | 6875 | if (tg3_flag(tp, JUMBO_CAPABLE) && !tg3_flag(tp, 5780_CLASS)) { |
2c49a44d | 6876 | for (i = 0; i <= tp->rx_jmb_ring_mask; i++) |
2b2cdb65 MC |
6877 | tg3_rx_skb_free(tp, &tpr->rx_jmb_buffers[i], |
6878 | TG3_RX_JMB_MAP_SZ); | |
1da177e4 LT |
6879 | } |
6880 | } | |
6881 | ||
c6cdf436 | 6882 | /* Initialize rx rings for packet processing. |
1da177e4 LT |
6883 | * |
6884 | * The chip has been shut down and the driver detached from | |
6885 | * the networking, so no interrupts or new tx packets will | |
6886 | * end up in the driver. tp->{tx,}lock are held and thus | |
6887 | * we may not sleep. | |
6888 | */ | |
21f581a5 MC |
6889 | static int tg3_rx_prodring_alloc(struct tg3 *tp, |
6890 | struct tg3_rx_prodring_set *tpr) | |
1da177e4 | 6891 | { |
287be12e | 6892 | u32 i, rx_pkt_dma_sz; |
1da177e4 | 6893 | |
b196c7e4 MC |
6894 | tpr->rx_std_cons_idx = 0; |
6895 | tpr->rx_std_prod_idx = 0; | |
6896 | tpr->rx_jmb_cons_idx = 0; | |
6897 | tpr->rx_jmb_prod_idx = 0; | |
6898 | ||
8fea32b9 | 6899 | if (tpr != &tp->napi[0].prodring) { |
2c49a44d MC |
6900 | memset(&tpr->rx_std_buffers[0], 0, |
6901 | TG3_RX_STD_BUFF_RING_SIZE(tp)); | |
48035728 | 6902 | if (tpr->rx_jmb_buffers) |
2b2cdb65 | 6903 | memset(&tpr->rx_jmb_buffers[0], 0, |
2c49a44d | 6904 | TG3_RX_JMB_BUFF_RING_SIZE(tp)); |
2b2cdb65 MC |
6905 | goto done; |
6906 | } | |
6907 | ||
1da177e4 | 6908 | /* Zero out all descriptors. */ |
2c49a44d | 6909 | memset(tpr->rx_std, 0, TG3_RX_STD_RING_BYTES(tp)); |
1da177e4 | 6910 | |
287be12e | 6911 | rx_pkt_dma_sz = TG3_RX_STD_DMA_SZ; |
63c3a66f | 6912 | if (tg3_flag(tp, 5780_CLASS) && |
287be12e MC |
6913 | tp->dev->mtu > ETH_DATA_LEN) |
6914 | rx_pkt_dma_sz = TG3_RX_JMB_DMA_SZ; | |
6915 | tp->rx_pkt_map_sz = TG3_RX_DMA_TO_MAP_SZ(rx_pkt_dma_sz); | |
7e72aad4 | 6916 | |
1da177e4 LT |
6917 | /* Initialize invariants of the rings, we only set this |
6918 | * stuff once. This works because the card does not | |
6919 | * write into the rx buffer posting rings. | |
6920 | */ | |
2c49a44d | 6921 | for (i = 0; i <= tp->rx_std_ring_mask; i++) { |
1da177e4 LT |
6922 | struct tg3_rx_buffer_desc *rxd; |
6923 | ||
21f581a5 | 6924 | rxd = &tpr->rx_std[i]; |
287be12e | 6925 | rxd->idx_len = rx_pkt_dma_sz << RXD_LEN_SHIFT; |
1da177e4 LT |
6926 | rxd->type_flags = (RXD_FLAG_END << RXD_FLAGS_SHIFT); |
6927 | rxd->opaque = (RXD_OPAQUE_RING_STD | | |
6928 | (i << RXD_OPAQUE_INDEX_SHIFT)); | |
6929 | } | |
6930 | ||
1da177e4 LT |
6931 | /* Now allocate fresh SKBs for each rx ring. */ |
6932 | for (i = 0; i < tp->rx_pending; i++) { | |
86b21e59 | 6933 | if (tg3_alloc_rx_skb(tp, tpr, RXD_OPAQUE_RING_STD, i) < 0) { |
5129c3a3 MC |
6934 | netdev_warn(tp->dev, |
6935 | "Using a smaller RX standard ring. Only " | |
6936 | "%d out of %d buffers were allocated " | |
6937 | "successfully\n", i, tp->rx_pending); | |
32d8c572 | 6938 | if (i == 0) |
cf7a7298 | 6939 | goto initfail; |
32d8c572 | 6940 | tp->rx_pending = i; |
1da177e4 | 6941 | break; |
32d8c572 | 6942 | } |
1da177e4 LT |
6943 | } |
6944 | ||
63c3a66f | 6945 | if (!tg3_flag(tp, JUMBO_CAPABLE) || tg3_flag(tp, 5780_CLASS)) |
cf7a7298 MC |
6946 | goto done; |
6947 | ||
2c49a44d | 6948 | memset(tpr->rx_jmb, 0, TG3_RX_JMB_RING_BYTES(tp)); |
cf7a7298 | 6949 | |
63c3a66f | 6950 | if (!tg3_flag(tp, JUMBO_RING_ENABLE)) |
0d86df80 | 6951 | goto done; |
cf7a7298 | 6952 | |
2c49a44d | 6953 | for (i = 0; i <= tp->rx_jmb_ring_mask; i++) { |
0d86df80 MC |
6954 | struct tg3_rx_buffer_desc *rxd; |
6955 | ||
6956 | rxd = &tpr->rx_jmb[i].std; | |
6957 | rxd->idx_len = TG3_RX_JMB_DMA_SZ << RXD_LEN_SHIFT; | |
6958 | rxd->type_flags = (RXD_FLAG_END << RXD_FLAGS_SHIFT) | | |
6959 | RXD_FLAG_JUMBO; | |
6960 | rxd->opaque = (RXD_OPAQUE_RING_JUMBO | | |
6961 | (i << RXD_OPAQUE_INDEX_SHIFT)); | |
6962 | } | |
6963 | ||
6964 | for (i = 0; i < tp->rx_jumbo_pending; i++) { | |
6965 | if (tg3_alloc_rx_skb(tp, tpr, RXD_OPAQUE_RING_JUMBO, i) < 0) { | |
5129c3a3 MC |
6966 | netdev_warn(tp->dev, |
6967 | "Using a smaller RX jumbo ring. Only %d " | |
6968 | "out of %d buffers were allocated " | |
6969 | "successfully\n", i, tp->rx_jumbo_pending); | |
0d86df80 MC |
6970 | if (i == 0) |
6971 | goto initfail; | |
6972 | tp->rx_jumbo_pending = i; | |
6973 | break; | |
1da177e4 LT |
6974 | } |
6975 | } | |
cf7a7298 MC |
6976 | |
6977 | done: | |
32d8c572 | 6978 | return 0; |
cf7a7298 MC |
6979 | |
6980 | initfail: | |
21f581a5 | 6981 | tg3_rx_prodring_free(tp, tpr); |
cf7a7298 | 6982 | return -ENOMEM; |
1da177e4 LT |
6983 | } |
6984 | ||
21f581a5 MC |
6985 | static void tg3_rx_prodring_fini(struct tg3 *tp, |
6986 | struct tg3_rx_prodring_set *tpr) | |
1da177e4 | 6987 | { |
21f581a5 MC |
6988 | kfree(tpr->rx_std_buffers); |
6989 | tpr->rx_std_buffers = NULL; | |
6990 | kfree(tpr->rx_jmb_buffers); | |
6991 | tpr->rx_jmb_buffers = NULL; | |
6992 | if (tpr->rx_std) { | |
4bae65c8 MC |
6993 | dma_free_coherent(&tp->pdev->dev, TG3_RX_STD_RING_BYTES(tp), |
6994 | tpr->rx_std, tpr->rx_std_mapping); | |
21f581a5 | 6995 | tpr->rx_std = NULL; |
1da177e4 | 6996 | } |
21f581a5 | 6997 | if (tpr->rx_jmb) { |
4bae65c8 MC |
6998 | dma_free_coherent(&tp->pdev->dev, TG3_RX_JMB_RING_BYTES(tp), |
6999 | tpr->rx_jmb, tpr->rx_jmb_mapping); | |
21f581a5 | 7000 | tpr->rx_jmb = NULL; |
1da177e4 | 7001 | } |
cf7a7298 MC |
7002 | } |
7003 | ||
21f581a5 MC |
7004 | static int tg3_rx_prodring_init(struct tg3 *tp, |
7005 | struct tg3_rx_prodring_set *tpr) | |
cf7a7298 | 7006 | { |
2c49a44d MC |
7007 | tpr->rx_std_buffers = kzalloc(TG3_RX_STD_BUFF_RING_SIZE(tp), |
7008 | GFP_KERNEL); | |
21f581a5 | 7009 | if (!tpr->rx_std_buffers) |
cf7a7298 MC |
7010 | return -ENOMEM; |
7011 | ||
4bae65c8 MC |
7012 | tpr->rx_std = dma_alloc_coherent(&tp->pdev->dev, |
7013 | TG3_RX_STD_RING_BYTES(tp), | |
7014 | &tpr->rx_std_mapping, | |
7015 | GFP_KERNEL); | |
21f581a5 | 7016 | if (!tpr->rx_std) |
cf7a7298 MC |
7017 | goto err_out; |
7018 | ||
63c3a66f | 7019 | if (tg3_flag(tp, JUMBO_CAPABLE) && !tg3_flag(tp, 5780_CLASS)) { |
2c49a44d | 7020 | tpr->rx_jmb_buffers = kzalloc(TG3_RX_JMB_BUFF_RING_SIZE(tp), |
21f581a5 MC |
7021 | GFP_KERNEL); |
7022 | if (!tpr->rx_jmb_buffers) | |
cf7a7298 MC |
7023 | goto err_out; |
7024 | ||
4bae65c8 MC |
7025 | tpr->rx_jmb = dma_alloc_coherent(&tp->pdev->dev, |
7026 | TG3_RX_JMB_RING_BYTES(tp), | |
7027 | &tpr->rx_jmb_mapping, | |
7028 | GFP_KERNEL); | |
21f581a5 | 7029 | if (!tpr->rx_jmb) |
cf7a7298 MC |
7030 | goto err_out; |
7031 | } | |
7032 | ||
7033 | return 0; | |
7034 | ||
7035 | err_out: | |
21f581a5 | 7036 | tg3_rx_prodring_fini(tp, tpr); |
cf7a7298 MC |
7037 | return -ENOMEM; |
7038 | } | |
7039 | ||
7040 | /* Free up pending packets in all rx/tx rings. | |
7041 | * | |
7042 | * The chip has been shut down and the driver detached from | |
7043 | * the networking, so no interrupts or new tx packets will | |
7044 | * end up in the driver. tp->{tx,}lock is not held and we are not | |
7045 | * in an interrupt context and thus may sleep. | |
7046 | */ | |
7047 | static void tg3_free_rings(struct tg3 *tp) | |
7048 | { | |
f77a6a8e | 7049 | int i, j; |
cf7a7298 | 7050 | |
f77a6a8e MC |
7051 | for (j = 0; j < tp->irq_cnt; j++) { |
7052 | struct tg3_napi *tnapi = &tp->napi[j]; | |
cf7a7298 | 7053 | |
8fea32b9 | 7054 | tg3_rx_prodring_free(tp, &tnapi->prodring); |
b28f6428 | 7055 | |
0c1d0e2b MC |
7056 | if (!tnapi->tx_buffers) |
7057 | continue; | |
7058 | ||
0d681b27 MC |
7059 | for (i = 0; i < TG3_TX_RING_SIZE; i++) { |
7060 | struct sk_buff *skb = tnapi->tx_buffers[i].skb; | |
cf7a7298 | 7061 | |
0d681b27 | 7062 | if (!skb) |
f77a6a8e | 7063 | continue; |
cf7a7298 | 7064 | |
0d681b27 | 7065 | tg3_tx_skb_unmap(tnapi, i, skb_shinfo(skb)->nr_frags); |
f77a6a8e MC |
7066 | |
7067 | dev_kfree_skb_any(skb); | |
7068 | } | |
2b2cdb65 | 7069 | } |
cf7a7298 MC |
7070 | } |
7071 | ||
7072 | /* Initialize tx/rx rings for packet processing. | |
7073 | * | |
7074 | * The chip has been shut down and the driver detached from | |
7075 | * the networking, so no interrupts or new tx packets will | |
7076 | * end up in the driver. tp->{tx,}lock are held and thus | |
7077 | * we may not sleep. | |
7078 | */ | |
7079 | static int tg3_init_rings(struct tg3 *tp) | |
7080 | { | |
f77a6a8e | 7081 | int i; |
72334482 | 7082 | |
cf7a7298 MC |
7083 | /* Free up all the SKBs. */ |
7084 | tg3_free_rings(tp); | |
7085 | ||
f77a6a8e MC |
7086 | for (i = 0; i < tp->irq_cnt; i++) { |
7087 | struct tg3_napi *tnapi = &tp->napi[i]; | |
7088 | ||
7089 | tnapi->last_tag = 0; | |
7090 | tnapi->last_irq_tag = 0; | |
7091 | tnapi->hw_status->status = 0; | |
7092 | tnapi->hw_status->status_tag = 0; | |
7093 | memset(tnapi->hw_status, 0, TG3_HW_STATUS_SIZE); | |
cf7a7298 | 7094 | |
f77a6a8e MC |
7095 | tnapi->tx_prod = 0; |
7096 | tnapi->tx_cons = 0; | |
0c1d0e2b MC |
7097 | if (tnapi->tx_ring) |
7098 | memset(tnapi->tx_ring, 0, TG3_TX_RING_BYTES); | |
f77a6a8e MC |
7099 | |
7100 | tnapi->rx_rcb_ptr = 0; | |
0c1d0e2b MC |
7101 | if (tnapi->rx_rcb) |
7102 | memset(tnapi->rx_rcb, 0, TG3_RX_RCB_RING_BYTES(tp)); | |
2b2cdb65 | 7103 | |
8fea32b9 | 7104 | if (tg3_rx_prodring_alloc(tp, &tnapi->prodring)) { |
e4af1af9 | 7105 | tg3_free_rings(tp); |
2b2cdb65 | 7106 | return -ENOMEM; |
e4af1af9 | 7107 | } |
f77a6a8e | 7108 | } |
72334482 | 7109 | |
2b2cdb65 | 7110 | return 0; |
cf7a7298 MC |
7111 | } |
7112 | ||
7113 | /* | |
7114 | * Must not be invoked with interrupt sources disabled and | |
7115 | * the hardware shutdown down. | |
7116 | */ | |
7117 | static void tg3_free_consistent(struct tg3 *tp) | |
7118 | { | |
f77a6a8e | 7119 | int i; |
898a56f8 | 7120 | |
f77a6a8e MC |
7121 | for (i = 0; i < tp->irq_cnt; i++) { |
7122 | struct tg3_napi *tnapi = &tp->napi[i]; | |
7123 | ||
7124 | if (tnapi->tx_ring) { | |
4bae65c8 | 7125 | dma_free_coherent(&tp->pdev->dev, TG3_TX_RING_BYTES, |
f77a6a8e MC |
7126 | tnapi->tx_ring, tnapi->tx_desc_mapping); |
7127 | tnapi->tx_ring = NULL; | |
7128 | } | |
7129 | ||
7130 | kfree(tnapi->tx_buffers); | |
7131 | tnapi->tx_buffers = NULL; | |
7132 | ||
7133 | if (tnapi->rx_rcb) { | |
4bae65c8 MC |
7134 | dma_free_coherent(&tp->pdev->dev, |
7135 | TG3_RX_RCB_RING_BYTES(tp), | |
7136 | tnapi->rx_rcb, | |
7137 | tnapi->rx_rcb_mapping); | |
f77a6a8e MC |
7138 | tnapi->rx_rcb = NULL; |
7139 | } | |
7140 | ||
8fea32b9 MC |
7141 | tg3_rx_prodring_fini(tp, &tnapi->prodring); |
7142 | ||
f77a6a8e | 7143 | if (tnapi->hw_status) { |
4bae65c8 MC |
7144 | dma_free_coherent(&tp->pdev->dev, TG3_HW_STATUS_SIZE, |
7145 | tnapi->hw_status, | |
7146 | tnapi->status_mapping); | |
f77a6a8e MC |
7147 | tnapi->hw_status = NULL; |
7148 | } | |
1da177e4 | 7149 | } |
f77a6a8e | 7150 | |
1da177e4 | 7151 | if (tp->hw_stats) { |
4bae65c8 MC |
7152 | dma_free_coherent(&tp->pdev->dev, sizeof(struct tg3_hw_stats), |
7153 | tp->hw_stats, tp->stats_mapping); | |
1da177e4 LT |
7154 | tp->hw_stats = NULL; |
7155 | } | |
7156 | } | |
7157 | ||
7158 | /* | |
7159 | * Must not be invoked with interrupt sources disabled and | |
7160 | * the hardware shutdown down. Can sleep. | |
7161 | */ | |
7162 | static int tg3_alloc_consistent(struct tg3 *tp) | |
7163 | { | |
f77a6a8e | 7164 | int i; |
898a56f8 | 7165 | |
4bae65c8 MC |
7166 | tp->hw_stats = dma_alloc_coherent(&tp->pdev->dev, |
7167 | sizeof(struct tg3_hw_stats), | |
7168 | &tp->stats_mapping, | |
7169 | GFP_KERNEL); | |
f77a6a8e | 7170 | if (!tp->hw_stats) |
1da177e4 LT |
7171 | goto err_out; |
7172 | ||
f77a6a8e | 7173 | memset(tp->hw_stats, 0, sizeof(struct tg3_hw_stats)); |
1da177e4 | 7174 | |
f77a6a8e MC |
7175 | for (i = 0; i < tp->irq_cnt; i++) { |
7176 | struct tg3_napi *tnapi = &tp->napi[i]; | |
8d9d7cfc | 7177 | struct tg3_hw_status *sblk; |
1da177e4 | 7178 | |
4bae65c8 MC |
7179 | tnapi->hw_status = dma_alloc_coherent(&tp->pdev->dev, |
7180 | TG3_HW_STATUS_SIZE, | |
7181 | &tnapi->status_mapping, | |
7182 | GFP_KERNEL); | |
f77a6a8e MC |
7183 | if (!tnapi->hw_status) |
7184 | goto err_out; | |
898a56f8 | 7185 | |
f77a6a8e | 7186 | memset(tnapi->hw_status, 0, TG3_HW_STATUS_SIZE); |
8d9d7cfc MC |
7187 | sblk = tnapi->hw_status; |
7188 | ||
8fea32b9 MC |
7189 | if (tg3_rx_prodring_init(tp, &tnapi->prodring)) |
7190 | goto err_out; | |
7191 | ||
19cfaecc MC |
7192 | /* If multivector TSS is enabled, vector 0 does not handle |
7193 | * tx interrupts. Don't allocate any resources for it. | |
7194 | */ | |
63c3a66f JP |
7195 | if ((!i && !tg3_flag(tp, ENABLE_TSS)) || |
7196 | (i && tg3_flag(tp, ENABLE_TSS))) { | |
df8944cf MC |
7197 | tnapi->tx_buffers = kzalloc( |
7198 | sizeof(struct tg3_tx_ring_info) * | |
7199 | TG3_TX_RING_SIZE, GFP_KERNEL); | |
19cfaecc MC |
7200 | if (!tnapi->tx_buffers) |
7201 | goto err_out; | |
7202 | ||
4bae65c8 MC |
7203 | tnapi->tx_ring = dma_alloc_coherent(&tp->pdev->dev, |
7204 | TG3_TX_RING_BYTES, | |
7205 | &tnapi->tx_desc_mapping, | |
7206 | GFP_KERNEL); | |
19cfaecc MC |
7207 | if (!tnapi->tx_ring) |
7208 | goto err_out; | |
7209 | } | |
7210 | ||
8d9d7cfc MC |
7211 | /* |
7212 | * When RSS is enabled, the status block format changes | |
7213 | * slightly. The "rx_jumbo_consumer", "reserved", | |
7214 | * and "rx_mini_consumer" members get mapped to the | |
7215 | * other three rx return ring producer indexes. | |
7216 | */ | |
7217 | switch (i) { | |
7218 | default: | |
7219 | tnapi->rx_rcb_prod_idx = &sblk->idx[0].rx_producer; | |
7220 | break; | |
7221 | case 2: | |
7222 | tnapi->rx_rcb_prod_idx = &sblk->rx_jumbo_consumer; | |
7223 | break; | |
7224 | case 3: | |
7225 | tnapi->rx_rcb_prod_idx = &sblk->reserved; | |
7226 | break; | |
7227 | case 4: | |
7228 | tnapi->rx_rcb_prod_idx = &sblk->rx_mini_consumer; | |
7229 | break; | |
7230 | } | |
72334482 | 7231 | |
0c1d0e2b MC |
7232 | /* |
7233 | * If multivector RSS is enabled, vector 0 does not handle | |
7234 | * rx or tx interrupts. Don't allocate any resources for it. | |
7235 | */ | |
63c3a66f | 7236 | if (!i && tg3_flag(tp, ENABLE_RSS)) |
0c1d0e2b MC |
7237 | continue; |
7238 | ||
4bae65c8 MC |
7239 | tnapi->rx_rcb = dma_alloc_coherent(&tp->pdev->dev, |
7240 | TG3_RX_RCB_RING_BYTES(tp), | |
7241 | &tnapi->rx_rcb_mapping, | |
7242 | GFP_KERNEL); | |
f77a6a8e MC |
7243 | if (!tnapi->rx_rcb) |
7244 | goto err_out; | |
72334482 | 7245 | |
f77a6a8e | 7246 | memset(tnapi->rx_rcb, 0, TG3_RX_RCB_RING_BYTES(tp)); |
f77a6a8e | 7247 | } |
1da177e4 LT |
7248 | |
7249 | return 0; | |
7250 | ||
7251 | err_out: | |
7252 | tg3_free_consistent(tp); | |
7253 | return -ENOMEM; | |
7254 | } | |
7255 | ||
7256 | #define MAX_WAIT_CNT 1000 | |
7257 | ||
7258 | /* To stop a block, clear the enable bit and poll till it | |
7259 | * clears. tp->lock is held. | |
7260 | */ | |
b3b7d6be | 7261 | static int tg3_stop_block(struct tg3 *tp, unsigned long ofs, u32 enable_bit, int silent) |
1da177e4 LT |
7262 | { |
7263 | unsigned int i; | |
7264 | u32 val; | |
7265 | ||
63c3a66f | 7266 | if (tg3_flag(tp, 5705_PLUS)) { |
1da177e4 LT |
7267 | switch (ofs) { |
7268 | case RCVLSC_MODE: | |
7269 | case DMAC_MODE: | |
7270 | case MBFREE_MODE: | |
7271 | case BUFMGR_MODE: | |
7272 | case MEMARB_MODE: | |
7273 | /* We can't enable/disable these bits of the | |
7274 | * 5705/5750, just say success. | |
7275 | */ | |
7276 | return 0; | |
7277 | ||
7278 | default: | |
7279 | break; | |
855e1111 | 7280 | } |
1da177e4 LT |
7281 | } |
7282 | ||
7283 | val = tr32(ofs); | |
7284 | val &= ~enable_bit; | |
7285 | tw32_f(ofs, val); | |
7286 | ||
7287 | for (i = 0; i < MAX_WAIT_CNT; i++) { | |
7288 | udelay(100); | |
7289 | val = tr32(ofs); | |
7290 | if ((val & enable_bit) == 0) | |
7291 | break; | |
7292 | } | |
7293 | ||
b3b7d6be | 7294 | if (i == MAX_WAIT_CNT && !silent) { |
2445e461 MC |
7295 | dev_err(&tp->pdev->dev, |
7296 | "tg3_stop_block timed out, ofs=%lx enable_bit=%x\n", | |
7297 | ofs, enable_bit); | |
1da177e4 LT |
7298 | return -ENODEV; |
7299 | } | |
7300 | ||
7301 | return 0; | |
7302 | } | |
7303 | ||
7304 | /* tp->lock is held. */ | |
b3b7d6be | 7305 | static int tg3_abort_hw(struct tg3 *tp, int silent) |
1da177e4 LT |
7306 | { |
7307 | int i, err; | |
7308 | ||
7309 | tg3_disable_ints(tp); | |
7310 | ||
7311 | tp->rx_mode &= ~RX_MODE_ENABLE; | |
7312 | tw32_f(MAC_RX_MODE, tp->rx_mode); | |
7313 | udelay(10); | |
7314 | ||
b3b7d6be DM |
7315 | err = tg3_stop_block(tp, RCVBDI_MODE, RCVBDI_MODE_ENABLE, silent); |
7316 | err |= tg3_stop_block(tp, RCVLPC_MODE, RCVLPC_MODE_ENABLE, silent); | |
7317 | err |= tg3_stop_block(tp, RCVLSC_MODE, RCVLSC_MODE_ENABLE, silent); | |
7318 | err |= tg3_stop_block(tp, RCVDBDI_MODE, RCVDBDI_MODE_ENABLE, silent); | |
7319 | err |= tg3_stop_block(tp, RCVDCC_MODE, RCVDCC_MODE_ENABLE, silent); | |
7320 | err |= tg3_stop_block(tp, RCVCC_MODE, RCVCC_MODE_ENABLE, silent); | |
7321 | ||
7322 | err |= tg3_stop_block(tp, SNDBDS_MODE, SNDBDS_MODE_ENABLE, silent); | |
7323 | err |= tg3_stop_block(tp, SNDBDI_MODE, SNDBDI_MODE_ENABLE, silent); | |
7324 | err |= tg3_stop_block(tp, SNDDATAI_MODE, SNDDATAI_MODE_ENABLE, silent); | |
7325 | err |= tg3_stop_block(tp, RDMAC_MODE, RDMAC_MODE_ENABLE, silent); | |
7326 | err |= tg3_stop_block(tp, SNDDATAC_MODE, SNDDATAC_MODE_ENABLE, silent); | |
7327 | err |= tg3_stop_block(tp, DMAC_MODE, DMAC_MODE_ENABLE, silent); | |
7328 | err |= tg3_stop_block(tp, SNDBDC_MODE, SNDBDC_MODE_ENABLE, silent); | |
1da177e4 LT |
7329 | |
7330 | tp->mac_mode &= ~MAC_MODE_TDE_ENABLE; | |
7331 | tw32_f(MAC_MODE, tp->mac_mode); | |
7332 | udelay(40); | |
7333 | ||
7334 | tp->tx_mode &= ~TX_MODE_ENABLE; | |
7335 | tw32_f(MAC_TX_MODE, tp->tx_mode); | |
7336 | ||
7337 | for (i = 0; i < MAX_WAIT_CNT; i++) { | |
7338 | udelay(100); | |
7339 | if (!(tr32(MAC_TX_MODE) & TX_MODE_ENABLE)) | |
7340 | break; | |
7341 | } | |
7342 | if (i >= MAX_WAIT_CNT) { | |
ab96b241 MC |
7343 | dev_err(&tp->pdev->dev, |
7344 | "%s timed out, TX_MODE_ENABLE will not clear " | |
7345 | "MAC_TX_MODE=%08x\n", __func__, tr32(MAC_TX_MODE)); | |
e6de8ad1 | 7346 | err |= -ENODEV; |
1da177e4 LT |
7347 | } |
7348 | ||
e6de8ad1 | 7349 | err |= tg3_stop_block(tp, HOSTCC_MODE, HOSTCC_MODE_ENABLE, silent); |
b3b7d6be DM |
7350 | err |= tg3_stop_block(tp, WDMAC_MODE, WDMAC_MODE_ENABLE, silent); |
7351 | err |= tg3_stop_block(tp, MBFREE_MODE, MBFREE_MODE_ENABLE, silent); | |
1da177e4 LT |
7352 | |
7353 | tw32(FTQ_RESET, 0xffffffff); | |
7354 | tw32(FTQ_RESET, 0x00000000); | |
7355 | ||
b3b7d6be DM |
7356 | err |= tg3_stop_block(tp, BUFMGR_MODE, BUFMGR_MODE_ENABLE, silent); |
7357 | err |= tg3_stop_block(tp, MEMARB_MODE, MEMARB_MODE_ENABLE, silent); | |
1da177e4 | 7358 | |
f77a6a8e MC |
7359 | for (i = 0; i < tp->irq_cnt; i++) { |
7360 | struct tg3_napi *tnapi = &tp->napi[i]; | |
7361 | if (tnapi->hw_status) | |
7362 | memset(tnapi->hw_status, 0, TG3_HW_STATUS_SIZE); | |
7363 | } | |
1da177e4 LT |
7364 | if (tp->hw_stats) |
7365 | memset(tp->hw_stats, 0, sizeof(struct tg3_hw_stats)); | |
7366 | ||
1da177e4 LT |
7367 | return err; |
7368 | } | |
7369 | ||
ee6a99b5 MC |
7370 | /* Save PCI command register before chip reset */ |
7371 | static void tg3_save_pci_state(struct tg3 *tp) | |
7372 | { | |
8a6eac90 | 7373 | pci_read_config_word(tp->pdev, PCI_COMMAND, &tp->pci_cmd); |
ee6a99b5 MC |
7374 | } |
7375 | ||
7376 | /* Restore PCI state after chip reset */ | |
7377 | static void tg3_restore_pci_state(struct tg3 *tp) | |
7378 | { | |
7379 | u32 val; | |
7380 | ||
7381 | /* Re-enable indirect register accesses. */ | |
7382 | pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL, | |
7383 | tp->misc_host_ctrl); | |
7384 | ||
7385 | /* Set MAX PCI retry to zero. */ | |
7386 | val = (PCISTATE_ROM_ENABLE | PCISTATE_ROM_RETRY_ENABLE); | |
7387 | if (tp->pci_chip_rev_id == CHIPREV_ID_5704_A0 && | |
63c3a66f | 7388 | tg3_flag(tp, PCIX_MODE)) |
ee6a99b5 | 7389 | val |= PCISTATE_RETRY_SAME_DMA; |
0d3031d9 | 7390 | /* Allow reads and writes to the APE register and memory space. */ |
63c3a66f | 7391 | if (tg3_flag(tp, ENABLE_APE)) |
0d3031d9 | 7392 | val |= PCISTATE_ALLOW_APE_CTLSPC_WR | |
f92d9dc1 MC |
7393 | PCISTATE_ALLOW_APE_SHMEM_WR | |
7394 | PCISTATE_ALLOW_APE_PSPACE_WR; | |
ee6a99b5 MC |
7395 | pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE, val); |
7396 | ||
8a6eac90 | 7397 | pci_write_config_word(tp->pdev, PCI_COMMAND, tp->pci_cmd); |
ee6a99b5 | 7398 | |
fcb389df | 7399 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5785) { |
63c3a66f | 7400 | if (tg3_flag(tp, PCI_EXPRESS)) |
cf79003d | 7401 | pcie_set_readrq(tp->pdev, tp->pcie_readrq); |
fcb389df MC |
7402 | else { |
7403 | pci_write_config_byte(tp->pdev, PCI_CACHE_LINE_SIZE, | |
7404 | tp->pci_cacheline_sz); | |
7405 | pci_write_config_byte(tp->pdev, PCI_LATENCY_TIMER, | |
7406 | tp->pci_lat_timer); | |
7407 | } | |
114342f2 | 7408 | } |
5f5c51e3 | 7409 | |
ee6a99b5 | 7410 | /* Make sure PCI-X relaxed ordering bit is clear. */ |
63c3a66f | 7411 | if (tg3_flag(tp, PCIX_MODE)) { |
9974a356 MC |
7412 | u16 pcix_cmd; |
7413 | ||
7414 | pci_read_config_word(tp->pdev, tp->pcix_cap + PCI_X_CMD, | |
7415 | &pcix_cmd); | |
7416 | pcix_cmd &= ~PCI_X_CMD_ERO; | |
7417 | pci_write_config_word(tp->pdev, tp->pcix_cap + PCI_X_CMD, | |
7418 | pcix_cmd); | |
7419 | } | |
ee6a99b5 | 7420 | |
63c3a66f | 7421 | if (tg3_flag(tp, 5780_CLASS)) { |
ee6a99b5 MC |
7422 | |
7423 | /* Chip reset on 5780 will reset MSI enable bit, | |
7424 | * so need to restore it. | |
7425 | */ | |
63c3a66f | 7426 | if (tg3_flag(tp, USING_MSI)) { |
ee6a99b5 MC |
7427 | u16 ctrl; |
7428 | ||
7429 | pci_read_config_word(tp->pdev, | |
7430 | tp->msi_cap + PCI_MSI_FLAGS, | |
7431 | &ctrl); | |
7432 | pci_write_config_word(tp->pdev, | |
7433 | tp->msi_cap + PCI_MSI_FLAGS, | |
7434 | ctrl | PCI_MSI_FLAGS_ENABLE); | |
7435 | val = tr32(MSGINT_MODE); | |
7436 | tw32(MSGINT_MODE, val | MSGINT_MODE_ENABLE); | |
7437 | } | |
7438 | } | |
7439 | } | |
7440 | ||
1da177e4 LT |
7441 | /* tp->lock is held. */ |
7442 | static int tg3_chip_reset(struct tg3 *tp) | |
7443 | { | |
7444 | u32 val; | |
1ee582d8 | 7445 | void (*write_op)(struct tg3 *, u32, u32); |
4f125f42 | 7446 | int i, err; |
1da177e4 | 7447 | |
f49639e6 DM |
7448 | tg3_nvram_lock(tp); |
7449 | ||
77b483f1 MC |
7450 | tg3_ape_lock(tp, TG3_APE_LOCK_GRC); |
7451 | ||
f49639e6 DM |
7452 | /* No matching tg3_nvram_unlock() after this because |
7453 | * chip reset below will undo the nvram lock. | |
7454 | */ | |
7455 | tp->nvram_lock_cnt = 0; | |
1da177e4 | 7456 | |
ee6a99b5 MC |
7457 | /* GRC_MISC_CFG core clock reset will clear the memory |
7458 | * enable bit in PCI register 4 and the MSI enable bit | |
7459 | * on some chips, so we save relevant registers here. | |
7460 | */ | |
7461 | tg3_save_pci_state(tp); | |
7462 | ||
d9ab5ad1 | 7463 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 || |
63c3a66f | 7464 | tg3_flag(tp, 5755_PLUS)) |
d9ab5ad1 MC |
7465 | tw32(GRC_FASTBOOT_PC, 0); |
7466 | ||
1da177e4 LT |
7467 | /* |
7468 | * We must avoid the readl() that normally takes place. | |
7469 | * It locks machines, causes machine checks, and other | |
7470 | * fun things. So, temporarily disable the 5701 | |
7471 | * hardware workaround, while we do the reset. | |
7472 | */ | |
1ee582d8 MC |
7473 | write_op = tp->write32; |
7474 | if (write_op == tg3_write_flush_reg32) | |
7475 | tp->write32 = tg3_write32; | |
1da177e4 | 7476 | |
d18edcb2 MC |
7477 | /* Prevent the irq handler from reading or writing PCI registers |
7478 | * during chip reset when the memory enable bit in the PCI command | |
7479 | * register may be cleared. The chip does not generate interrupt | |
7480 | * at this time, but the irq handler may still be called due to irq | |
7481 | * sharing or irqpoll. | |
7482 | */ | |
63c3a66f | 7483 | tg3_flag_set(tp, CHIP_RESETTING); |
f77a6a8e MC |
7484 | for (i = 0; i < tp->irq_cnt; i++) { |
7485 | struct tg3_napi *tnapi = &tp->napi[i]; | |
7486 | if (tnapi->hw_status) { | |
7487 | tnapi->hw_status->status = 0; | |
7488 | tnapi->hw_status->status_tag = 0; | |
7489 | } | |
7490 | tnapi->last_tag = 0; | |
7491 | tnapi->last_irq_tag = 0; | |
b8fa2f3a | 7492 | } |
d18edcb2 | 7493 | smp_mb(); |
4f125f42 MC |
7494 | |
7495 | for (i = 0; i < tp->irq_cnt; i++) | |
7496 | synchronize_irq(tp->napi[i].irq_vec); | |
d18edcb2 | 7497 | |
255ca311 MC |
7498 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) { |
7499 | val = tr32(TG3_PCIE_LNKCTL) & ~TG3_PCIE_LNKCTL_L1_PLL_PD_EN; | |
7500 | tw32(TG3_PCIE_LNKCTL, val | TG3_PCIE_LNKCTL_L1_PLL_PD_DIS); | |
7501 | } | |
7502 | ||
1da177e4 LT |
7503 | /* do the reset */ |
7504 | val = GRC_MISC_CFG_CORECLK_RESET; | |
7505 | ||
63c3a66f | 7506 | if (tg3_flag(tp, PCI_EXPRESS)) { |
88075d91 MC |
7507 | /* Force PCIe 1.0a mode */ |
7508 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5785 && | |
63c3a66f | 7509 | !tg3_flag(tp, 57765_PLUS) && |
88075d91 MC |
7510 | tr32(TG3_PCIE_PHY_TSTCTL) == |
7511 | (TG3_PCIE_PHY_TSTCTL_PCIE10 | TG3_PCIE_PHY_TSTCTL_PSCRAM)) | |
7512 | tw32(TG3_PCIE_PHY_TSTCTL, TG3_PCIE_PHY_TSTCTL_PSCRAM); | |
7513 | ||
1da177e4 LT |
7514 | if (tp->pci_chip_rev_id != CHIPREV_ID_5750_A0) { |
7515 | tw32(GRC_MISC_CFG, (1 << 29)); | |
7516 | val |= (1 << 29); | |
7517 | } | |
7518 | } | |
7519 | ||
b5d3772c MC |
7520 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
7521 | tw32(VCPU_STATUS, tr32(VCPU_STATUS) | VCPU_STATUS_DRV_RESET); | |
7522 | tw32(GRC_VCPU_EXT_CTRL, | |
7523 | tr32(GRC_VCPU_EXT_CTRL) & ~GRC_VCPU_EXT_CTRL_HALT_CPU); | |
7524 | } | |
7525 | ||
f37500d3 | 7526 | /* Manage gphy power for all CPMU absent PCIe devices. */ |
63c3a66f | 7527 | if (tg3_flag(tp, 5705_PLUS) && !tg3_flag(tp, CPMU_PRESENT)) |
1da177e4 | 7528 | val |= GRC_MISC_CFG_KEEP_GPHY_POWER; |
f37500d3 | 7529 | |
1da177e4 LT |
7530 | tw32(GRC_MISC_CFG, val); |
7531 | ||
1ee582d8 MC |
7532 | /* restore 5701 hardware bug workaround write method */ |
7533 | tp->write32 = write_op; | |
1da177e4 LT |
7534 | |
7535 | /* Unfortunately, we have to delay before the PCI read back. | |
7536 | * Some 575X chips even will not respond to a PCI cfg access | |
7537 | * when the reset command is given to the chip. | |
7538 | * | |
7539 | * How do these hardware designers expect things to work | |
7540 | * properly if the PCI write is posted for a long period | |
7541 | * of time? It is always necessary to have some method by | |
7542 | * which a register read back can occur to push the write | |
7543 | * out which does the reset. | |
7544 | * | |
7545 | * For most tg3 variants the trick below was working. | |
7546 | * Ho hum... | |
7547 | */ | |
7548 | udelay(120); | |
7549 | ||
7550 | /* Flush PCI posted writes. The normal MMIO registers | |
7551 | * are inaccessible at this time so this is the only | |
7552 | * way to make this reliably (actually, this is no longer | |
7553 | * the case, see above). I tried to use indirect | |
7554 | * register read/write but this upset some 5701 variants. | |
7555 | */ | |
7556 | pci_read_config_dword(tp->pdev, PCI_COMMAND, &val); | |
7557 | ||
7558 | udelay(120); | |
7559 | ||
708ebb3a | 7560 | if (tg3_flag(tp, PCI_EXPRESS) && pci_pcie_cap(tp->pdev)) { |
e7126997 MC |
7561 | u16 val16; |
7562 | ||
1da177e4 LT |
7563 | if (tp->pci_chip_rev_id == CHIPREV_ID_5750_A0) { |
7564 | int i; | |
7565 | u32 cfg_val; | |
7566 | ||
7567 | /* Wait for link training to complete. */ | |
7568 | for (i = 0; i < 5000; i++) | |
7569 | udelay(100); | |
7570 | ||
7571 | pci_read_config_dword(tp->pdev, 0xc4, &cfg_val); | |
7572 | pci_write_config_dword(tp->pdev, 0xc4, | |
7573 | cfg_val | (1 << 15)); | |
7574 | } | |
5e7dfd0f | 7575 | |
e7126997 MC |
7576 | /* Clear the "no snoop" and "relaxed ordering" bits. */ |
7577 | pci_read_config_word(tp->pdev, | |
708ebb3a | 7578 | pci_pcie_cap(tp->pdev) + PCI_EXP_DEVCTL, |
e7126997 MC |
7579 | &val16); |
7580 | val16 &= ~(PCI_EXP_DEVCTL_RELAX_EN | | |
7581 | PCI_EXP_DEVCTL_NOSNOOP_EN); | |
7582 | /* | |
7583 | * Older PCIe devices only support the 128 byte | |
7584 | * MPS setting. Enforce the restriction. | |
5e7dfd0f | 7585 | */ |
63c3a66f | 7586 | if (!tg3_flag(tp, CPMU_PRESENT)) |
e7126997 | 7587 | val16 &= ~PCI_EXP_DEVCTL_PAYLOAD; |
5e7dfd0f | 7588 | pci_write_config_word(tp->pdev, |
708ebb3a | 7589 | pci_pcie_cap(tp->pdev) + PCI_EXP_DEVCTL, |
e7126997 | 7590 | val16); |
5e7dfd0f | 7591 | |
cf79003d | 7592 | pcie_set_readrq(tp->pdev, tp->pcie_readrq); |
5e7dfd0f MC |
7593 | |
7594 | /* Clear error status */ | |
7595 | pci_write_config_word(tp->pdev, | |
708ebb3a | 7596 | pci_pcie_cap(tp->pdev) + PCI_EXP_DEVSTA, |
5e7dfd0f MC |
7597 | PCI_EXP_DEVSTA_CED | |
7598 | PCI_EXP_DEVSTA_NFED | | |
7599 | PCI_EXP_DEVSTA_FED | | |
7600 | PCI_EXP_DEVSTA_URD); | |
1da177e4 LT |
7601 | } |
7602 | ||
ee6a99b5 | 7603 | tg3_restore_pci_state(tp); |
1da177e4 | 7604 | |
63c3a66f JP |
7605 | tg3_flag_clear(tp, CHIP_RESETTING); |
7606 | tg3_flag_clear(tp, ERROR_PROCESSED); | |
d18edcb2 | 7607 | |
ee6a99b5 | 7608 | val = 0; |
63c3a66f | 7609 | if (tg3_flag(tp, 5780_CLASS)) |
4cf78e4f | 7610 | val = tr32(MEMARB_MODE); |
ee6a99b5 | 7611 | tw32(MEMARB_MODE, val | MEMARB_MODE_ENABLE); |
1da177e4 LT |
7612 | |
7613 | if (tp->pci_chip_rev_id == CHIPREV_ID_5750_A3) { | |
7614 | tg3_stop_fw(tp); | |
7615 | tw32(0x5000, 0x400); | |
7616 | } | |
7617 | ||
7618 | tw32(GRC_MODE, tp->grc_mode); | |
7619 | ||
7620 | if (tp->pci_chip_rev_id == CHIPREV_ID_5705_A0) { | |
ab0049b4 | 7621 | val = tr32(0xc4); |
1da177e4 LT |
7622 | |
7623 | tw32(0xc4, val | (1 << 15)); | |
7624 | } | |
7625 | ||
7626 | if ((tp->nic_sram_data_cfg & NIC_SRAM_DATA_CFG_MINI_PCI) != 0 && | |
7627 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) { | |
7628 | tp->pci_clock_ctrl |= CLOCK_CTRL_CLKRUN_OENABLE; | |
7629 | if (tp->pci_chip_rev_id == CHIPREV_ID_5705_A0) | |
7630 | tp->pci_clock_ctrl |= CLOCK_CTRL_FORCE_CLKRUN; | |
7631 | tw32(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl); | |
7632 | } | |
7633 | ||
f07e9af3 | 7634 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) { |
9e975cc2 | 7635 | tp->mac_mode = MAC_MODE_PORT_MODE_TBI; |
d2394e6b | 7636 | val = tp->mac_mode; |
f07e9af3 | 7637 | } else if (tp->phy_flags & TG3_PHYFLG_MII_SERDES) { |
9e975cc2 | 7638 | tp->mac_mode = MAC_MODE_PORT_MODE_GMII; |
d2394e6b | 7639 | val = tp->mac_mode; |
1da177e4 | 7640 | } else |
d2394e6b MC |
7641 | val = 0; |
7642 | ||
7643 | tw32_f(MAC_MODE, val); | |
1da177e4 LT |
7644 | udelay(40); |
7645 | ||
77b483f1 MC |
7646 | tg3_ape_unlock(tp, TG3_APE_LOCK_GRC); |
7647 | ||
7a6f4369 MC |
7648 | err = tg3_poll_fw(tp); |
7649 | if (err) | |
7650 | return err; | |
1da177e4 | 7651 | |
0a9140cf MC |
7652 | tg3_mdio_start(tp); |
7653 | ||
63c3a66f | 7654 | if (tg3_flag(tp, PCI_EXPRESS) && |
f6eb9b1f MC |
7655 | tp->pci_chip_rev_id != CHIPREV_ID_5750_A0 && |
7656 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5785 && | |
63c3a66f | 7657 | !tg3_flag(tp, 57765_PLUS)) { |
ab0049b4 | 7658 | val = tr32(0x7c00); |
1da177e4 LT |
7659 | |
7660 | tw32(0x7c00, val | (1 << 25)); | |
7661 | } | |
7662 | ||
d78b59f5 MC |
7663 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) { |
7664 | val = tr32(TG3_CPMU_CLCK_ORIDE); | |
7665 | tw32(TG3_CPMU_CLCK_ORIDE, val & ~CPMU_CLCK_ORIDE_MAC_ORIDE_EN); | |
7666 | } | |
7667 | ||
1da177e4 | 7668 | /* Reprobe ASF enable state. */ |
63c3a66f JP |
7669 | tg3_flag_clear(tp, ENABLE_ASF); |
7670 | tg3_flag_clear(tp, ASF_NEW_HANDSHAKE); | |
1da177e4 LT |
7671 | tg3_read_mem(tp, NIC_SRAM_DATA_SIG, &val); |
7672 | if (val == NIC_SRAM_DATA_SIG_MAGIC) { | |
7673 | u32 nic_cfg; | |
7674 | ||
7675 | tg3_read_mem(tp, NIC_SRAM_DATA_CFG, &nic_cfg); | |
7676 | if (nic_cfg & NIC_SRAM_DATA_CFG_ASF_ENABLE) { | |
63c3a66f | 7677 | tg3_flag_set(tp, ENABLE_ASF); |
4ba526ce | 7678 | tp->last_event_jiffies = jiffies; |
63c3a66f JP |
7679 | if (tg3_flag(tp, 5750_PLUS)) |
7680 | tg3_flag_set(tp, ASF_NEW_HANDSHAKE); | |
1da177e4 LT |
7681 | } |
7682 | } | |
7683 | ||
7684 | return 0; | |
7685 | } | |
7686 | ||
1da177e4 | 7687 | /* tp->lock is held. */ |
944d980e | 7688 | static int tg3_halt(struct tg3 *tp, int kind, int silent) |
1da177e4 LT |
7689 | { |
7690 | int err; | |
7691 | ||
7692 | tg3_stop_fw(tp); | |
7693 | ||
944d980e | 7694 | tg3_write_sig_pre_reset(tp, kind); |
1da177e4 | 7695 | |
b3b7d6be | 7696 | tg3_abort_hw(tp, silent); |
1da177e4 LT |
7697 | err = tg3_chip_reset(tp); |
7698 | ||
daba2a63 MC |
7699 | __tg3_set_mac_addr(tp, 0); |
7700 | ||
944d980e MC |
7701 | tg3_write_sig_legacy(tp, kind); |
7702 | tg3_write_sig_post_reset(tp, kind); | |
1da177e4 LT |
7703 | |
7704 | if (err) | |
7705 | return err; | |
7706 | ||
7707 | return 0; | |
7708 | } | |
7709 | ||
1da177e4 LT |
7710 | #define RX_CPU_SCRATCH_BASE 0x30000 |
7711 | #define RX_CPU_SCRATCH_SIZE 0x04000 | |
7712 | #define TX_CPU_SCRATCH_BASE 0x34000 | |
7713 | #define TX_CPU_SCRATCH_SIZE 0x04000 | |
7714 | ||
7715 | /* tp->lock is held. */ | |
7716 | static int tg3_halt_cpu(struct tg3 *tp, u32 offset) | |
7717 | { | |
7718 | int i; | |
7719 | ||
63c3a66f | 7720 | BUG_ON(offset == TX_CPU_BASE && tg3_flag(tp, 5705_PLUS)); |
1da177e4 | 7721 | |
b5d3772c MC |
7722 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
7723 | u32 val = tr32(GRC_VCPU_EXT_CTRL); | |
7724 | ||
7725 | tw32(GRC_VCPU_EXT_CTRL, val | GRC_VCPU_EXT_CTRL_HALT_CPU); | |
7726 | return 0; | |
7727 | } | |
1da177e4 LT |
7728 | if (offset == RX_CPU_BASE) { |
7729 | for (i = 0; i < 10000; i++) { | |
7730 | tw32(offset + CPU_STATE, 0xffffffff); | |
7731 | tw32(offset + CPU_MODE, CPU_MODE_HALT); | |
7732 | if (tr32(offset + CPU_MODE) & CPU_MODE_HALT) | |
7733 | break; | |
7734 | } | |
7735 | ||
7736 | tw32(offset + CPU_STATE, 0xffffffff); | |
7737 | tw32_f(offset + CPU_MODE, CPU_MODE_HALT); | |
7738 | udelay(10); | |
7739 | } else { | |
7740 | for (i = 0; i < 10000; i++) { | |
7741 | tw32(offset + CPU_STATE, 0xffffffff); | |
7742 | tw32(offset + CPU_MODE, CPU_MODE_HALT); | |
7743 | if (tr32(offset + CPU_MODE) & CPU_MODE_HALT) | |
7744 | break; | |
7745 | } | |
7746 | } | |
7747 | ||
7748 | if (i >= 10000) { | |
05dbe005 JP |
7749 | netdev_err(tp->dev, "%s timed out, %s CPU\n", |
7750 | __func__, offset == RX_CPU_BASE ? "RX" : "TX"); | |
1da177e4 LT |
7751 | return -ENODEV; |
7752 | } | |
ec41c7df MC |
7753 | |
7754 | /* Clear firmware's nvram arbitration. */ | |
63c3a66f | 7755 | if (tg3_flag(tp, NVRAM)) |
ec41c7df | 7756 | tw32(NVRAM_SWARB, SWARB_REQ_CLR0); |
1da177e4 LT |
7757 | return 0; |
7758 | } | |
7759 | ||
7760 | struct fw_info { | |
077f849d JSR |
7761 | unsigned int fw_base; |
7762 | unsigned int fw_len; | |
7763 | const __be32 *fw_data; | |
1da177e4 LT |
7764 | }; |
7765 | ||
7766 | /* tp->lock is held. */ | |
7767 | static int tg3_load_firmware_cpu(struct tg3 *tp, u32 cpu_base, u32 cpu_scratch_base, | |
7768 | int cpu_scratch_size, struct fw_info *info) | |
7769 | { | |
ec41c7df | 7770 | int err, lock_err, i; |
1da177e4 LT |
7771 | void (*write_op)(struct tg3 *, u32, u32); |
7772 | ||
63c3a66f | 7773 | if (cpu_base == TX_CPU_BASE && tg3_flag(tp, 5705_PLUS)) { |
5129c3a3 MC |
7774 | netdev_err(tp->dev, |
7775 | "%s: Trying to load TX cpu firmware which is 5705\n", | |
05dbe005 | 7776 | __func__); |
1da177e4 LT |
7777 | return -EINVAL; |
7778 | } | |
7779 | ||
63c3a66f | 7780 | if (tg3_flag(tp, 5705_PLUS)) |
1da177e4 LT |
7781 | write_op = tg3_write_mem; |
7782 | else | |
7783 | write_op = tg3_write_indirect_reg32; | |
7784 | ||
1b628151 MC |
7785 | /* It is possible that bootcode is still loading at this point. |
7786 | * Get the nvram lock first before halting the cpu. | |
7787 | */ | |
ec41c7df | 7788 | lock_err = tg3_nvram_lock(tp); |
1da177e4 | 7789 | err = tg3_halt_cpu(tp, cpu_base); |
ec41c7df MC |
7790 | if (!lock_err) |
7791 | tg3_nvram_unlock(tp); | |
1da177e4 LT |
7792 | if (err) |
7793 | goto out; | |
7794 | ||
7795 | for (i = 0; i < cpu_scratch_size; i += sizeof(u32)) | |
7796 | write_op(tp, cpu_scratch_base + i, 0); | |
7797 | tw32(cpu_base + CPU_STATE, 0xffffffff); | |
7798 | tw32(cpu_base + CPU_MODE, tr32(cpu_base+CPU_MODE)|CPU_MODE_HALT); | |
077f849d | 7799 | for (i = 0; i < (info->fw_len / sizeof(u32)); i++) |
1da177e4 | 7800 | write_op(tp, (cpu_scratch_base + |
077f849d | 7801 | (info->fw_base & 0xffff) + |
1da177e4 | 7802 | (i * sizeof(u32))), |
077f849d | 7803 | be32_to_cpu(info->fw_data[i])); |
1da177e4 LT |
7804 | |
7805 | err = 0; | |
7806 | ||
7807 | out: | |
1da177e4 LT |
7808 | return err; |
7809 | } | |
7810 | ||
7811 | /* tp->lock is held. */ | |
7812 | static int tg3_load_5701_a0_firmware_fix(struct tg3 *tp) | |
7813 | { | |
7814 | struct fw_info info; | |
077f849d | 7815 | const __be32 *fw_data; |
1da177e4 LT |
7816 | int err, i; |
7817 | ||
077f849d JSR |
7818 | fw_data = (void *)tp->fw->data; |
7819 | ||
7820 | /* Firmware blob starts with version numbers, followed by | |
7821 | start address and length. We are setting complete length. | |
7822 | length = end_address_of_bss - start_address_of_text. | |
7823 | Remainder is the blob to be loaded contiguously | |
7824 | from start address. */ | |
7825 | ||
7826 | info.fw_base = be32_to_cpu(fw_data[1]); | |
7827 | info.fw_len = tp->fw->size - 12; | |
7828 | info.fw_data = &fw_data[3]; | |
1da177e4 LT |
7829 | |
7830 | err = tg3_load_firmware_cpu(tp, RX_CPU_BASE, | |
7831 | RX_CPU_SCRATCH_BASE, RX_CPU_SCRATCH_SIZE, | |
7832 | &info); | |
7833 | if (err) | |
7834 | return err; | |
7835 | ||
7836 | err = tg3_load_firmware_cpu(tp, TX_CPU_BASE, | |
7837 | TX_CPU_SCRATCH_BASE, TX_CPU_SCRATCH_SIZE, | |
7838 | &info); | |
7839 | if (err) | |
7840 | return err; | |
7841 | ||
7842 | /* Now startup only the RX cpu. */ | |
7843 | tw32(RX_CPU_BASE + CPU_STATE, 0xffffffff); | |
077f849d | 7844 | tw32_f(RX_CPU_BASE + CPU_PC, info.fw_base); |
1da177e4 LT |
7845 | |
7846 | for (i = 0; i < 5; i++) { | |
077f849d | 7847 | if (tr32(RX_CPU_BASE + CPU_PC) == info.fw_base) |
1da177e4 LT |
7848 | break; |
7849 | tw32(RX_CPU_BASE + CPU_STATE, 0xffffffff); | |
7850 | tw32(RX_CPU_BASE + CPU_MODE, CPU_MODE_HALT); | |
077f849d | 7851 | tw32_f(RX_CPU_BASE + CPU_PC, info.fw_base); |
1da177e4 LT |
7852 | udelay(1000); |
7853 | } | |
7854 | if (i >= 5) { | |
5129c3a3 MC |
7855 | netdev_err(tp->dev, "%s fails to set RX CPU PC, is %08x " |
7856 | "should be %08x\n", __func__, | |
05dbe005 | 7857 | tr32(RX_CPU_BASE + CPU_PC), info.fw_base); |
1da177e4 LT |
7858 | return -ENODEV; |
7859 | } | |
7860 | tw32(RX_CPU_BASE + CPU_STATE, 0xffffffff); | |
7861 | tw32_f(RX_CPU_BASE + CPU_MODE, 0x00000000); | |
7862 | ||
7863 | return 0; | |
7864 | } | |
7865 | ||
1da177e4 LT |
7866 | /* tp->lock is held. */ |
7867 | static int tg3_load_tso_firmware(struct tg3 *tp) | |
7868 | { | |
7869 | struct fw_info info; | |
077f849d | 7870 | const __be32 *fw_data; |
1da177e4 LT |
7871 | unsigned long cpu_base, cpu_scratch_base, cpu_scratch_size; |
7872 | int err, i; | |
7873 | ||
63c3a66f JP |
7874 | if (tg3_flag(tp, HW_TSO_1) || |
7875 | tg3_flag(tp, HW_TSO_2) || | |
7876 | tg3_flag(tp, HW_TSO_3)) | |
1da177e4 LT |
7877 | return 0; |
7878 | ||
077f849d JSR |
7879 | fw_data = (void *)tp->fw->data; |
7880 | ||
7881 | /* Firmware blob starts with version numbers, followed by | |
7882 | start address and length. We are setting complete length. | |
7883 | length = end_address_of_bss - start_address_of_text. | |
7884 | Remainder is the blob to be loaded contiguously | |
7885 | from start address. */ | |
7886 | ||
7887 | info.fw_base = be32_to_cpu(fw_data[1]); | |
7888 | cpu_scratch_size = tp->fw_len; | |
7889 | info.fw_len = tp->fw->size - 12; | |
7890 | info.fw_data = &fw_data[3]; | |
7891 | ||
1da177e4 | 7892 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) { |
1da177e4 LT |
7893 | cpu_base = RX_CPU_BASE; |
7894 | cpu_scratch_base = NIC_SRAM_MBUF_POOL_BASE5705; | |
1da177e4 | 7895 | } else { |
1da177e4 LT |
7896 | cpu_base = TX_CPU_BASE; |
7897 | cpu_scratch_base = TX_CPU_SCRATCH_BASE; | |
7898 | cpu_scratch_size = TX_CPU_SCRATCH_SIZE; | |
7899 | } | |
7900 | ||
7901 | err = tg3_load_firmware_cpu(tp, cpu_base, | |
7902 | cpu_scratch_base, cpu_scratch_size, | |
7903 | &info); | |
7904 | if (err) | |
7905 | return err; | |
7906 | ||
7907 | /* Now startup the cpu. */ | |
7908 | tw32(cpu_base + CPU_STATE, 0xffffffff); | |
077f849d | 7909 | tw32_f(cpu_base + CPU_PC, info.fw_base); |
1da177e4 LT |
7910 | |
7911 | for (i = 0; i < 5; i++) { | |
077f849d | 7912 | if (tr32(cpu_base + CPU_PC) == info.fw_base) |
1da177e4 LT |
7913 | break; |
7914 | tw32(cpu_base + CPU_STATE, 0xffffffff); | |
7915 | tw32(cpu_base + CPU_MODE, CPU_MODE_HALT); | |
077f849d | 7916 | tw32_f(cpu_base + CPU_PC, info.fw_base); |
1da177e4 LT |
7917 | udelay(1000); |
7918 | } | |
7919 | if (i >= 5) { | |
5129c3a3 MC |
7920 | netdev_err(tp->dev, |
7921 | "%s fails to set CPU PC, is %08x should be %08x\n", | |
05dbe005 | 7922 | __func__, tr32(cpu_base + CPU_PC), info.fw_base); |
1da177e4 LT |
7923 | return -ENODEV; |
7924 | } | |
7925 | tw32(cpu_base + CPU_STATE, 0xffffffff); | |
7926 | tw32_f(cpu_base + CPU_MODE, 0x00000000); | |
7927 | return 0; | |
7928 | } | |
7929 | ||
1da177e4 | 7930 | |
1da177e4 LT |
7931 | static int tg3_set_mac_addr(struct net_device *dev, void *p) |
7932 | { | |
7933 | struct tg3 *tp = netdev_priv(dev); | |
7934 | struct sockaddr *addr = p; | |
986e0aeb | 7935 | int err = 0, skip_mac_1 = 0; |
1da177e4 | 7936 | |
f9804ddb MC |
7937 | if (!is_valid_ether_addr(addr->sa_data)) |
7938 | return -EINVAL; | |
7939 | ||
1da177e4 LT |
7940 | memcpy(dev->dev_addr, addr->sa_data, dev->addr_len); |
7941 | ||
e75f7c90 MC |
7942 | if (!netif_running(dev)) |
7943 | return 0; | |
7944 | ||
63c3a66f | 7945 | if (tg3_flag(tp, ENABLE_ASF)) { |
986e0aeb | 7946 | u32 addr0_high, addr0_low, addr1_high, addr1_low; |
58712ef9 | 7947 | |
986e0aeb MC |
7948 | addr0_high = tr32(MAC_ADDR_0_HIGH); |
7949 | addr0_low = tr32(MAC_ADDR_0_LOW); | |
7950 | addr1_high = tr32(MAC_ADDR_1_HIGH); | |
7951 | addr1_low = tr32(MAC_ADDR_1_LOW); | |
7952 | ||
7953 | /* Skip MAC addr 1 if ASF is using it. */ | |
7954 | if ((addr0_high != addr1_high || addr0_low != addr1_low) && | |
7955 | !(addr1_high == 0 && addr1_low == 0)) | |
7956 | skip_mac_1 = 1; | |
58712ef9 | 7957 | } |
986e0aeb MC |
7958 | spin_lock_bh(&tp->lock); |
7959 | __tg3_set_mac_addr(tp, skip_mac_1); | |
7960 | spin_unlock_bh(&tp->lock); | |
1da177e4 | 7961 | |
b9ec6c1b | 7962 | return err; |
1da177e4 LT |
7963 | } |
7964 | ||
7965 | /* tp->lock is held. */ | |
7966 | static void tg3_set_bdinfo(struct tg3 *tp, u32 bdinfo_addr, | |
7967 | dma_addr_t mapping, u32 maxlen_flags, | |
7968 | u32 nic_addr) | |
7969 | { | |
7970 | tg3_write_mem(tp, | |
7971 | (bdinfo_addr + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH), | |
7972 | ((u64) mapping >> 32)); | |
7973 | tg3_write_mem(tp, | |
7974 | (bdinfo_addr + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW), | |
7975 | ((u64) mapping & 0xffffffff)); | |
7976 | tg3_write_mem(tp, | |
7977 | (bdinfo_addr + TG3_BDINFO_MAXLEN_FLAGS), | |
7978 | maxlen_flags); | |
7979 | ||
63c3a66f | 7980 | if (!tg3_flag(tp, 5705_PLUS)) |
1da177e4 LT |
7981 | tg3_write_mem(tp, |
7982 | (bdinfo_addr + TG3_BDINFO_NIC_ADDR), | |
7983 | nic_addr); | |
7984 | } | |
7985 | ||
7986 | static void __tg3_set_rx_mode(struct net_device *); | |
d244c892 | 7987 | static void __tg3_set_coalesce(struct tg3 *tp, struct ethtool_coalesce *ec) |
15f9850d | 7988 | { |
b6080e12 MC |
7989 | int i; |
7990 | ||
63c3a66f | 7991 | if (!tg3_flag(tp, ENABLE_TSS)) { |
b6080e12 MC |
7992 | tw32(HOSTCC_TXCOL_TICKS, ec->tx_coalesce_usecs); |
7993 | tw32(HOSTCC_TXMAX_FRAMES, ec->tx_max_coalesced_frames); | |
7994 | tw32(HOSTCC_TXCOAL_MAXF_INT, ec->tx_max_coalesced_frames_irq); | |
b6080e12 MC |
7995 | } else { |
7996 | tw32(HOSTCC_TXCOL_TICKS, 0); | |
7997 | tw32(HOSTCC_TXMAX_FRAMES, 0); | |
7998 | tw32(HOSTCC_TXCOAL_MAXF_INT, 0); | |
19cfaecc | 7999 | } |
b6080e12 | 8000 | |
63c3a66f | 8001 | if (!tg3_flag(tp, ENABLE_RSS)) { |
19cfaecc MC |
8002 | tw32(HOSTCC_RXCOL_TICKS, ec->rx_coalesce_usecs); |
8003 | tw32(HOSTCC_RXMAX_FRAMES, ec->rx_max_coalesced_frames); | |
8004 | tw32(HOSTCC_RXCOAL_MAXF_INT, ec->rx_max_coalesced_frames_irq); | |
8005 | } else { | |
b6080e12 MC |
8006 | tw32(HOSTCC_RXCOL_TICKS, 0); |
8007 | tw32(HOSTCC_RXMAX_FRAMES, 0); | |
8008 | tw32(HOSTCC_RXCOAL_MAXF_INT, 0); | |
15f9850d | 8009 | } |
b6080e12 | 8010 | |
63c3a66f | 8011 | if (!tg3_flag(tp, 5705_PLUS)) { |
15f9850d DM |
8012 | u32 val = ec->stats_block_coalesce_usecs; |
8013 | ||
b6080e12 MC |
8014 | tw32(HOSTCC_RXCOAL_TICK_INT, ec->rx_coalesce_usecs_irq); |
8015 | tw32(HOSTCC_TXCOAL_TICK_INT, ec->tx_coalesce_usecs_irq); | |
8016 | ||
15f9850d DM |
8017 | if (!netif_carrier_ok(tp->dev)) |
8018 | val = 0; | |
8019 | ||
8020 | tw32(HOSTCC_STAT_COAL_TICKS, val); | |
8021 | } | |
b6080e12 MC |
8022 | |
8023 | for (i = 0; i < tp->irq_cnt - 1; i++) { | |
8024 | u32 reg; | |
8025 | ||
8026 | reg = HOSTCC_RXCOL_TICKS_VEC1 + i * 0x18; | |
8027 | tw32(reg, ec->rx_coalesce_usecs); | |
b6080e12 MC |
8028 | reg = HOSTCC_RXMAX_FRAMES_VEC1 + i * 0x18; |
8029 | tw32(reg, ec->rx_max_coalesced_frames); | |
b6080e12 MC |
8030 | reg = HOSTCC_RXCOAL_MAXF_INT_VEC1 + i * 0x18; |
8031 | tw32(reg, ec->rx_max_coalesced_frames_irq); | |
19cfaecc | 8032 | |
63c3a66f | 8033 | if (tg3_flag(tp, ENABLE_TSS)) { |
19cfaecc MC |
8034 | reg = HOSTCC_TXCOL_TICKS_VEC1 + i * 0x18; |
8035 | tw32(reg, ec->tx_coalesce_usecs); | |
8036 | reg = HOSTCC_TXMAX_FRAMES_VEC1 + i * 0x18; | |
8037 | tw32(reg, ec->tx_max_coalesced_frames); | |
8038 | reg = HOSTCC_TXCOAL_MAXF_INT_VEC1 + i * 0x18; | |
8039 | tw32(reg, ec->tx_max_coalesced_frames_irq); | |
8040 | } | |
b6080e12 MC |
8041 | } |
8042 | ||
8043 | for (; i < tp->irq_max - 1; i++) { | |
8044 | tw32(HOSTCC_RXCOL_TICKS_VEC1 + i * 0x18, 0); | |
b6080e12 | 8045 | tw32(HOSTCC_RXMAX_FRAMES_VEC1 + i * 0x18, 0); |
b6080e12 | 8046 | tw32(HOSTCC_RXCOAL_MAXF_INT_VEC1 + i * 0x18, 0); |
19cfaecc | 8047 | |
63c3a66f | 8048 | if (tg3_flag(tp, ENABLE_TSS)) { |
19cfaecc MC |
8049 | tw32(HOSTCC_TXCOL_TICKS_VEC1 + i * 0x18, 0); |
8050 | tw32(HOSTCC_TXMAX_FRAMES_VEC1 + i * 0x18, 0); | |
8051 | tw32(HOSTCC_TXCOAL_MAXF_INT_VEC1 + i * 0x18, 0); | |
8052 | } | |
b6080e12 | 8053 | } |
15f9850d | 8054 | } |
1da177e4 | 8055 | |
2d31ecaf MC |
8056 | /* tp->lock is held. */ |
8057 | static void tg3_rings_reset(struct tg3 *tp) | |
8058 | { | |
8059 | int i; | |
f77a6a8e | 8060 | u32 stblk, txrcb, rxrcb, limit; |
2d31ecaf MC |
8061 | struct tg3_napi *tnapi = &tp->napi[0]; |
8062 | ||
8063 | /* Disable all transmit rings but the first. */ | |
63c3a66f | 8064 | if (!tg3_flag(tp, 5705_PLUS)) |
2d31ecaf | 8065 | limit = NIC_SRAM_SEND_RCB + TG3_BDINFO_SIZE * 16; |
63c3a66f | 8066 | else if (tg3_flag(tp, 5717_PLUS)) |
3d37728b | 8067 | limit = NIC_SRAM_SEND_RCB + TG3_BDINFO_SIZE * 4; |
b703df6f MC |
8068 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) |
8069 | limit = NIC_SRAM_SEND_RCB + TG3_BDINFO_SIZE * 2; | |
2d31ecaf MC |
8070 | else |
8071 | limit = NIC_SRAM_SEND_RCB + TG3_BDINFO_SIZE; | |
8072 | ||
8073 | for (txrcb = NIC_SRAM_SEND_RCB + TG3_BDINFO_SIZE; | |
8074 | txrcb < limit; txrcb += TG3_BDINFO_SIZE) | |
8075 | tg3_write_mem(tp, txrcb + TG3_BDINFO_MAXLEN_FLAGS, | |
8076 | BDINFO_FLAGS_DISABLED); | |
8077 | ||
8078 | ||
8079 | /* Disable all receive return rings but the first. */ | |
63c3a66f | 8080 | if (tg3_flag(tp, 5717_PLUS)) |
f6eb9b1f | 8081 | limit = NIC_SRAM_RCV_RET_RCB + TG3_BDINFO_SIZE * 17; |
63c3a66f | 8082 | else if (!tg3_flag(tp, 5705_PLUS)) |
2d31ecaf | 8083 | limit = NIC_SRAM_RCV_RET_RCB + TG3_BDINFO_SIZE * 16; |
b703df6f MC |
8084 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 || |
8085 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) | |
2d31ecaf MC |
8086 | limit = NIC_SRAM_RCV_RET_RCB + TG3_BDINFO_SIZE * 4; |
8087 | else | |
8088 | limit = NIC_SRAM_RCV_RET_RCB + TG3_BDINFO_SIZE; | |
8089 | ||
8090 | for (rxrcb = NIC_SRAM_RCV_RET_RCB + TG3_BDINFO_SIZE; | |
8091 | rxrcb < limit; rxrcb += TG3_BDINFO_SIZE) | |
8092 | tg3_write_mem(tp, rxrcb + TG3_BDINFO_MAXLEN_FLAGS, | |
8093 | BDINFO_FLAGS_DISABLED); | |
8094 | ||
8095 | /* Disable interrupts */ | |
8096 | tw32_mailbox_f(tp->napi[0].int_mbox, 1); | |
0e6cf6a9 MC |
8097 | tp->napi[0].chk_msi_cnt = 0; |
8098 | tp->napi[0].last_rx_cons = 0; | |
8099 | tp->napi[0].last_tx_cons = 0; | |
2d31ecaf MC |
8100 | |
8101 | /* Zero mailbox registers. */ | |
63c3a66f | 8102 | if (tg3_flag(tp, SUPPORT_MSIX)) { |
6fd45cb8 | 8103 | for (i = 1; i < tp->irq_max; i++) { |
f77a6a8e MC |
8104 | tp->napi[i].tx_prod = 0; |
8105 | tp->napi[i].tx_cons = 0; | |
63c3a66f | 8106 | if (tg3_flag(tp, ENABLE_TSS)) |
c2353a32 | 8107 | tw32_mailbox(tp->napi[i].prodmbox, 0); |
f77a6a8e MC |
8108 | tw32_rx_mbox(tp->napi[i].consmbox, 0); |
8109 | tw32_mailbox_f(tp->napi[i].int_mbox, 1); | |
7f230735 | 8110 | tp->napi[i].chk_msi_cnt = 0; |
0e6cf6a9 MC |
8111 | tp->napi[i].last_rx_cons = 0; |
8112 | tp->napi[i].last_tx_cons = 0; | |
f77a6a8e | 8113 | } |
63c3a66f | 8114 | if (!tg3_flag(tp, ENABLE_TSS)) |
c2353a32 | 8115 | tw32_mailbox(tp->napi[0].prodmbox, 0); |
f77a6a8e MC |
8116 | } else { |
8117 | tp->napi[0].tx_prod = 0; | |
8118 | tp->napi[0].tx_cons = 0; | |
8119 | tw32_mailbox(tp->napi[0].prodmbox, 0); | |
8120 | tw32_rx_mbox(tp->napi[0].consmbox, 0); | |
8121 | } | |
2d31ecaf MC |
8122 | |
8123 | /* Make sure the NIC-based send BD rings are disabled. */ | |
63c3a66f | 8124 | if (!tg3_flag(tp, 5705_PLUS)) { |
2d31ecaf MC |
8125 | u32 mbox = MAILBOX_SNDNIC_PROD_IDX_0 + TG3_64BIT_REG_LOW; |
8126 | for (i = 0; i < 16; i++) | |
8127 | tw32_tx_mbox(mbox + i * 8, 0); | |
8128 | } | |
8129 | ||
8130 | txrcb = NIC_SRAM_SEND_RCB; | |
8131 | rxrcb = NIC_SRAM_RCV_RET_RCB; | |
8132 | ||
8133 | /* Clear status block in ram. */ | |
8134 | memset(tnapi->hw_status, 0, TG3_HW_STATUS_SIZE); | |
8135 | ||
8136 | /* Set status block DMA address */ | |
8137 | tw32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH, | |
8138 | ((u64) tnapi->status_mapping >> 32)); | |
8139 | tw32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW, | |
8140 | ((u64) tnapi->status_mapping & 0xffffffff)); | |
8141 | ||
f77a6a8e MC |
8142 | if (tnapi->tx_ring) { |
8143 | tg3_set_bdinfo(tp, txrcb, tnapi->tx_desc_mapping, | |
8144 | (TG3_TX_RING_SIZE << | |
8145 | BDINFO_FLAGS_MAXLEN_SHIFT), | |
8146 | NIC_SRAM_TX_BUFFER_DESC); | |
8147 | txrcb += TG3_BDINFO_SIZE; | |
8148 | } | |
8149 | ||
8150 | if (tnapi->rx_rcb) { | |
8151 | tg3_set_bdinfo(tp, rxrcb, tnapi->rx_rcb_mapping, | |
7cb32cf2 MC |
8152 | (tp->rx_ret_ring_mask + 1) << |
8153 | BDINFO_FLAGS_MAXLEN_SHIFT, 0); | |
f77a6a8e MC |
8154 | rxrcb += TG3_BDINFO_SIZE; |
8155 | } | |
8156 | ||
8157 | stblk = HOSTCC_STATBLCK_RING1; | |
2d31ecaf | 8158 | |
f77a6a8e MC |
8159 | for (i = 1, tnapi++; i < tp->irq_cnt; i++, tnapi++) { |
8160 | u64 mapping = (u64)tnapi->status_mapping; | |
8161 | tw32(stblk + TG3_64BIT_REG_HIGH, mapping >> 32); | |
8162 | tw32(stblk + TG3_64BIT_REG_LOW, mapping & 0xffffffff); | |
8163 | ||
8164 | /* Clear status block in ram. */ | |
8165 | memset(tnapi->hw_status, 0, TG3_HW_STATUS_SIZE); | |
8166 | ||
19cfaecc MC |
8167 | if (tnapi->tx_ring) { |
8168 | tg3_set_bdinfo(tp, txrcb, tnapi->tx_desc_mapping, | |
8169 | (TG3_TX_RING_SIZE << | |
8170 | BDINFO_FLAGS_MAXLEN_SHIFT), | |
8171 | NIC_SRAM_TX_BUFFER_DESC); | |
8172 | txrcb += TG3_BDINFO_SIZE; | |
8173 | } | |
f77a6a8e MC |
8174 | |
8175 | tg3_set_bdinfo(tp, rxrcb, tnapi->rx_rcb_mapping, | |
7cb32cf2 | 8176 | ((tp->rx_ret_ring_mask + 1) << |
f77a6a8e MC |
8177 | BDINFO_FLAGS_MAXLEN_SHIFT), 0); |
8178 | ||
8179 | stblk += 8; | |
f77a6a8e MC |
8180 | rxrcb += TG3_BDINFO_SIZE; |
8181 | } | |
2d31ecaf MC |
8182 | } |
8183 | ||
eb07a940 MC |
8184 | static void tg3_setup_rxbd_thresholds(struct tg3 *tp) |
8185 | { | |
8186 | u32 val, bdcache_maxcnt, host_rep_thresh, nic_rep_thresh; | |
8187 | ||
63c3a66f JP |
8188 | if (!tg3_flag(tp, 5750_PLUS) || |
8189 | tg3_flag(tp, 5780_CLASS) || | |
eb07a940 MC |
8190 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750 || |
8191 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752) | |
8192 | bdcache_maxcnt = TG3_SRAM_RX_STD_BDCACHE_SIZE_5700; | |
8193 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 || | |
8194 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787) | |
8195 | bdcache_maxcnt = TG3_SRAM_RX_STD_BDCACHE_SIZE_5755; | |
8196 | else | |
8197 | bdcache_maxcnt = TG3_SRAM_RX_STD_BDCACHE_SIZE_5906; | |
8198 | ||
8199 | nic_rep_thresh = min(bdcache_maxcnt / 2, tp->rx_std_max_post); | |
8200 | host_rep_thresh = max_t(u32, tp->rx_pending / 8, 1); | |
8201 | ||
8202 | val = min(nic_rep_thresh, host_rep_thresh); | |
8203 | tw32(RCVBDI_STD_THRESH, val); | |
8204 | ||
63c3a66f | 8205 | if (tg3_flag(tp, 57765_PLUS)) |
eb07a940 MC |
8206 | tw32(STD_REPLENISH_LWM, bdcache_maxcnt); |
8207 | ||
63c3a66f | 8208 | if (!tg3_flag(tp, JUMBO_CAPABLE) || tg3_flag(tp, 5780_CLASS)) |
eb07a940 MC |
8209 | return; |
8210 | ||
63c3a66f | 8211 | if (!tg3_flag(tp, 5705_PLUS)) |
eb07a940 MC |
8212 | bdcache_maxcnt = TG3_SRAM_RX_JMB_BDCACHE_SIZE_5700; |
8213 | else | |
8214 | bdcache_maxcnt = TG3_SRAM_RX_JMB_BDCACHE_SIZE_5717; | |
8215 | ||
8216 | host_rep_thresh = max_t(u32, tp->rx_jumbo_pending / 8, 1); | |
8217 | ||
8218 | val = min(bdcache_maxcnt / 2, host_rep_thresh); | |
8219 | tw32(RCVBDI_JUMBO_THRESH, val); | |
8220 | ||
63c3a66f | 8221 | if (tg3_flag(tp, 57765_PLUS)) |
eb07a940 MC |
8222 | tw32(JMB_REPLENISH_LWM, bdcache_maxcnt); |
8223 | } | |
8224 | ||
1da177e4 | 8225 | /* tp->lock is held. */ |
8e7a22e3 | 8226 | static int tg3_reset_hw(struct tg3 *tp, int reset_phy) |
1da177e4 LT |
8227 | { |
8228 | u32 val, rdmac_mode; | |
8229 | int i, err, limit; | |
8fea32b9 | 8230 | struct tg3_rx_prodring_set *tpr = &tp->napi[0].prodring; |
1da177e4 LT |
8231 | |
8232 | tg3_disable_ints(tp); | |
8233 | ||
8234 | tg3_stop_fw(tp); | |
8235 | ||
8236 | tg3_write_sig_pre_reset(tp, RESET_KIND_INIT); | |
8237 | ||
63c3a66f | 8238 | if (tg3_flag(tp, INIT_COMPLETE)) |
e6de8ad1 | 8239 | tg3_abort_hw(tp, 1); |
1da177e4 | 8240 | |
699c0193 MC |
8241 | /* Enable MAC control of LPI */ |
8242 | if (tp->phy_flags & TG3_PHYFLG_EEE_CAP) { | |
8243 | tw32_f(TG3_CPMU_EEE_LNKIDL_CTRL, | |
8244 | TG3_CPMU_EEE_LNKIDL_PCIE_NL0 | | |
8245 | TG3_CPMU_EEE_LNKIDL_UART_IDL); | |
8246 | ||
8247 | tw32_f(TG3_CPMU_EEE_CTRL, | |
8248 | TG3_CPMU_EEE_CTRL_EXIT_20_1_US); | |
8249 | ||
a386b901 MC |
8250 | val = TG3_CPMU_EEEMD_ERLY_L1_XIT_DET | |
8251 | TG3_CPMU_EEEMD_LPI_IN_TX | | |
8252 | TG3_CPMU_EEEMD_LPI_IN_RX | | |
8253 | TG3_CPMU_EEEMD_EEE_ENABLE; | |
8254 | ||
8255 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5717) | |
8256 | val |= TG3_CPMU_EEEMD_SND_IDX_DET_EN; | |
8257 | ||
63c3a66f | 8258 | if (tg3_flag(tp, ENABLE_APE)) |
a386b901 MC |
8259 | val |= TG3_CPMU_EEEMD_APE_TX_DET_EN; |
8260 | ||
8261 | tw32_f(TG3_CPMU_EEE_MODE, val); | |
8262 | ||
8263 | tw32_f(TG3_CPMU_EEE_DBTMR1, | |
8264 | TG3_CPMU_DBTMR1_PCIEXIT_2047US | | |
8265 | TG3_CPMU_DBTMR1_LNKIDLE_2047US); | |
8266 | ||
8267 | tw32_f(TG3_CPMU_EEE_DBTMR2, | |
d7f2ab20 | 8268 | TG3_CPMU_DBTMR2_APE_TX_2047US | |
a386b901 | 8269 | TG3_CPMU_DBTMR2_TXIDXEQ_2047US); |
699c0193 MC |
8270 | } |
8271 | ||
603f1173 | 8272 | if (reset_phy) |
d4d2c558 MC |
8273 | tg3_phy_reset(tp); |
8274 | ||
1da177e4 LT |
8275 | err = tg3_chip_reset(tp); |
8276 | if (err) | |
8277 | return err; | |
8278 | ||
8279 | tg3_write_sig_legacy(tp, RESET_KIND_INIT); | |
8280 | ||
bcb37f6c | 8281 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5784_AX) { |
d30cdd28 MC |
8282 | val = tr32(TG3_CPMU_CTRL); |
8283 | val &= ~(CPMU_CTRL_LINK_AWARE_MODE | CPMU_CTRL_LINK_IDLE_MODE); | |
8284 | tw32(TG3_CPMU_CTRL, val); | |
9acb961e MC |
8285 | |
8286 | val = tr32(TG3_CPMU_LSPD_10MB_CLK); | |
8287 | val &= ~CPMU_LSPD_10MB_MACCLK_MASK; | |
8288 | val |= CPMU_LSPD_10MB_MACCLK_6_25; | |
8289 | tw32(TG3_CPMU_LSPD_10MB_CLK, val); | |
8290 | ||
8291 | val = tr32(TG3_CPMU_LNK_AWARE_PWRMD); | |
8292 | val &= ~CPMU_LNK_AWARE_MACCLK_MASK; | |
8293 | val |= CPMU_LNK_AWARE_MACCLK_6_25; | |
8294 | tw32(TG3_CPMU_LNK_AWARE_PWRMD, val); | |
8295 | ||
8296 | val = tr32(TG3_CPMU_HST_ACC); | |
8297 | val &= ~CPMU_HST_ACC_MACCLK_MASK; | |
8298 | val |= CPMU_HST_ACC_MACCLK_6_25; | |
8299 | tw32(TG3_CPMU_HST_ACC, val); | |
d30cdd28 MC |
8300 | } |
8301 | ||
33466d93 MC |
8302 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) { |
8303 | val = tr32(PCIE_PWR_MGMT_THRESH) & ~PCIE_PWR_MGMT_L1_THRESH_MSK; | |
8304 | val |= PCIE_PWR_MGMT_EXT_ASPM_TMR_EN | | |
8305 | PCIE_PWR_MGMT_L1_THRESH_4MS; | |
8306 | tw32(PCIE_PWR_MGMT_THRESH, val); | |
521e6b90 MC |
8307 | |
8308 | val = tr32(TG3_PCIE_EIDLE_DELAY) & ~TG3_PCIE_EIDLE_DELAY_MASK; | |
8309 | tw32(TG3_PCIE_EIDLE_DELAY, val | TG3_PCIE_EIDLE_DELAY_13_CLKS); | |
8310 | ||
8311 | tw32(TG3_CORR_ERR_STAT, TG3_CORR_ERR_STAT_CLEAR); | |
33466d93 | 8312 | |
f40386c8 MC |
8313 | val = tr32(TG3_PCIE_LNKCTL) & ~TG3_PCIE_LNKCTL_L1_PLL_PD_EN; |
8314 | tw32(TG3_PCIE_LNKCTL, val | TG3_PCIE_LNKCTL_L1_PLL_PD_DIS); | |
255ca311 MC |
8315 | } |
8316 | ||
63c3a66f | 8317 | if (tg3_flag(tp, L1PLLPD_EN)) { |
614b0590 MC |
8318 | u32 grc_mode = tr32(GRC_MODE); |
8319 | ||
8320 | /* Access the lower 1K of PL PCIE block registers. */ | |
8321 | val = grc_mode & ~GRC_MODE_PCIE_PORT_MASK; | |
8322 | tw32(GRC_MODE, val | GRC_MODE_PCIE_PL_SEL); | |
8323 | ||
8324 | val = tr32(TG3_PCIE_TLDLPL_PORT + TG3_PCIE_PL_LO_PHYCTL1); | |
8325 | tw32(TG3_PCIE_TLDLPL_PORT + TG3_PCIE_PL_LO_PHYCTL1, | |
8326 | val | TG3_PCIE_PL_LO_PHYCTL1_L1PLLPD_EN); | |
8327 | ||
8328 | tw32(GRC_MODE, grc_mode); | |
8329 | } | |
8330 | ||
5093eedc MC |
8331 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) { |
8332 | if (tp->pci_chip_rev_id == CHIPREV_ID_57765_A0) { | |
8333 | u32 grc_mode = tr32(GRC_MODE); | |
cea46462 | 8334 | |
5093eedc MC |
8335 | /* Access the lower 1K of PL PCIE block registers. */ |
8336 | val = grc_mode & ~GRC_MODE_PCIE_PORT_MASK; | |
8337 | tw32(GRC_MODE, val | GRC_MODE_PCIE_PL_SEL); | |
cea46462 | 8338 | |
5093eedc MC |
8339 | val = tr32(TG3_PCIE_TLDLPL_PORT + |
8340 | TG3_PCIE_PL_LO_PHYCTL5); | |
8341 | tw32(TG3_PCIE_TLDLPL_PORT + TG3_PCIE_PL_LO_PHYCTL5, | |
8342 | val | TG3_PCIE_PL_LO_PHYCTL5_DIS_L2CLKREQ); | |
cea46462 | 8343 | |
5093eedc MC |
8344 | tw32(GRC_MODE, grc_mode); |
8345 | } | |
a977dbe8 | 8346 | |
1ff30a59 MC |
8347 | if (GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_57765_AX) { |
8348 | u32 grc_mode = tr32(GRC_MODE); | |
8349 | ||
8350 | /* Access the lower 1K of DL PCIE block registers. */ | |
8351 | val = grc_mode & ~GRC_MODE_PCIE_PORT_MASK; | |
8352 | tw32(GRC_MODE, val | GRC_MODE_PCIE_DL_SEL); | |
8353 | ||
8354 | val = tr32(TG3_PCIE_TLDLPL_PORT + | |
8355 | TG3_PCIE_DL_LO_FTSMAX); | |
8356 | val &= ~TG3_PCIE_DL_LO_FTSMAX_MSK; | |
8357 | tw32(TG3_PCIE_TLDLPL_PORT + TG3_PCIE_DL_LO_FTSMAX, | |
8358 | val | TG3_PCIE_DL_LO_FTSMAX_VAL); | |
8359 | ||
8360 | tw32(GRC_MODE, grc_mode); | |
8361 | } | |
8362 | ||
a977dbe8 MC |
8363 | val = tr32(TG3_CPMU_LSPD_10MB_CLK); |
8364 | val &= ~CPMU_LSPD_10MB_MACCLK_MASK; | |
8365 | val |= CPMU_LSPD_10MB_MACCLK_6_25; | |
8366 | tw32(TG3_CPMU_LSPD_10MB_CLK, val); | |
cea46462 MC |
8367 | } |
8368 | ||
1da177e4 LT |
8369 | /* This works around an issue with Athlon chipsets on |
8370 | * B3 tigon3 silicon. This bit has no effect on any | |
8371 | * other revision. But do not set this on PCI Express | |
795d01c5 | 8372 | * chips and don't even touch the clocks if the CPMU is present. |
1da177e4 | 8373 | */ |
63c3a66f JP |
8374 | if (!tg3_flag(tp, CPMU_PRESENT)) { |
8375 | if (!tg3_flag(tp, PCI_EXPRESS)) | |
795d01c5 MC |
8376 | tp->pci_clock_ctrl |= CLOCK_CTRL_DELAY_PCI_GRANT; |
8377 | tw32_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl); | |
8378 | } | |
1da177e4 LT |
8379 | |
8380 | if (tp->pci_chip_rev_id == CHIPREV_ID_5704_A0 && | |
63c3a66f | 8381 | tg3_flag(tp, PCIX_MODE)) { |
1da177e4 LT |
8382 | val = tr32(TG3PCI_PCISTATE); |
8383 | val |= PCISTATE_RETRY_SAME_DMA; | |
8384 | tw32(TG3PCI_PCISTATE, val); | |
8385 | } | |
8386 | ||
63c3a66f | 8387 | if (tg3_flag(tp, ENABLE_APE)) { |
0d3031d9 MC |
8388 | /* Allow reads and writes to the |
8389 | * APE register and memory space. | |
8390 | */ | |
8391 | val = tr32(TG3PCI_PCISTATE); | |
8392 | val |= PCISTATE_ALLOW_APE_CTLSPC_WR | | |
f92d9dc1 MC |
8393 | PCISTATE_ALLOW_APE_SHMEM_WR | |
8394 | PCISTATE_ALLOW_APE_PSPACE_WR; | |
0d3031d9 MC |
8395 | tw32(TG3PCI_PCISTATE, val); |
8396 | } | |
8397 | ||
1da177e4 LT |
8398 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5704_BX) { |
8399 | /* Enable some hw fixes. */ | |
8400 | val = tr32(TG3PCI_MSI_DATA); | |
8401 | val |= (1 << 26) | (1 << 28) | (1 << 29); | |
8402 | tw32(TG3PCI_MSI_DATA, val); | |
8403 | } | |
8404 | ||
8405 | /* Descriptor ring init may make accesses to the | |
8406 | * NIC SRAM area to setup the TX descriptors, so we | |
8407 | * can only do this after the hardware has been | |
8408 | * successfully reset. | |
8409 | */ | |
32d8c572 MC |
8410 | err = tg3_init_rings(tp); |
8411 | if (err) | |
8412 | return err; | |
1da177e4 | 8413 | |
63c3a66f | 8414 | if (tg3_flag(tp, 57765_PLUS)) { |
cbf9ca6c MC |
8415 | val = tr32(TG3PCI_DMA_RW_CTRL) & |
8416 | ~DMA_RWCTRL_DIS_CACHE_ALIGNMENT; | |
1a319025 MC |
8417 | if (tp->pci_chip_rev_id == CHIPREV_ID_57765_A0) |
8418 | val &= ~DMA_RWCTRL_CRDRDR_RDMA_MRRS_MSK; | |
0aebff48 MC |
8419 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_57765 && |
8420 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5717) | |
8421 | val |= DMA_RWCTRL_TAGGED_STAT_WA; | |
cbf9ca6c MC |
8422 | tw32(TG3PCI_DMA_RW_CTRL, val | tp->dma_rwctrl); |
8423 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5784 && | |
8424 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5761) { | |
d30cdd28 MC |
8425 | /* This value is determined during the probe time DMA |
8426 | * engine test, tg3_test_dma. | |
8427 | */ | |
8428 | tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl); | |
8429 | } | |
1da177e4 LT |
8430 | |
8431 | tp->grc_mode &= ~(GRC_MODE_HOST_SENDBDS | | |
8432 | GRC_MODE_4X_NIC_SEND_RINGS | | |
8433 | GRC_MODE_NO_TX_PHDR_CSUM | | |
8434 | GRC_MODE_NO_RX_PHDR_CSUM); | |
8435 | tp->grc_mode |= GRC_MODE_HOST_SENDBDS; | |
d2d746f8 MC |
8436 | |
8437 | /* Pseudo-header checksum is done by hardware logic and not | |
8438 | * the offload processers, so make the chip do the pseudo- | |
8439 | * header checksums on receive. For transmit it is more | |
8440 | * convenient to do the pseudo-header checksum in software | |
8441 | * as Linux does that on transmit for us in all cases. | |
8442 | */ | |
8443 | tp->grc_mode |= GRC_MODE_NO_TX_PHDR_CSUM; | |
1da177e4 LT |
8444 | |
8445 | tw32(GRC_MODE, | |
8446 | tp->grc_mode | | |
8447 | (GRC_MODE_IRQ_ON_MAC_ATTN | GRC_MODE_HOST_STACKUP)); | |
8448 | ||
8449 | /* Setup the timer prescalar register. Clock is always 66Mhz. */ | |
8450 | val = tr32(GRC_MISC_CFG); | |
8451 | val &= ~0xff; | |
8452 | val |= (65 << GRC_MISC_CFG_PRESCALAR_SHIFT); | |
8453 | tw32(GRC_MISC_CFG, val); | |
8454 | ||
8455 | /* Initialize MBUF/DESC pool. */ | |
63c3a66f | 8456 | if (tg3_flag(tp, 5750_PLUS)) { |
1da177e4 LT |
8457 | /* Do nothing. */ |
8458 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5705) { | |
8459 | tw32(BUFMGR_MB_POOL_ADDR, NIC_SRAM_MBUF_POOL_BASE); | |
8460 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) | |
8461 | tw32(BUFMGR_MB_POOL_SIZE, NIC_SRAM_MBUF_POOL_SIZE64); | |
8462 | else | |
8463 | tw32(BUFMGR_MB_POOL_SIZE, NIC_SRAM_MBUF_POOL_SIZE96); | |
8464 | tw32(BUFMGR_DMA_DESC_POOL_ADDR, NIC_SRAM_DMA_DESC_POOL_BASE); | |
8465 | tw32(BUFMGR_DMA_DESC_POOL_SIZE, NIC_SRAM_DMA_DESC_POOL_SIZE); | |
63c3a66f | 8466 | } else if (tg3_flag(tp, TSO_CAPABLE)) { |
1da177e4 LT |
8467 | int fw_len; |
8468 | ||
077f849d | 8469 | fw_len = tp->fw_len; |
1da177e4 LT |
8470 | fw_len = (fw_len + (0x80 - 1)) & ~(0x80 - 1); |
8471 | tw32(BUFMGR_MB_POOL_ADDR, | |
8472 | NIC_SRAM_MBUF_POOL_BASE5705 + fw_len); | |
8473 | tw32(BUFMGR_MB_POOL_SIZE, | |
8474 | NIC_SRAM_MBUF_POOL_SIZE5705 - fw_len - 0xa00); | |
8475 | } | |
1da177e4 | 8476 | |
0f893dc6 | 8477 | if (tp->dev->mtu <= ETH_DATA_LEN) { |
1da177e4 LT |
8478 | tw32(BUFMGR_MB_RDMA_LOW_WATER, |
8479 | tp->bufmgr_config.mbuf_read_dma_low_water); | |
8480 | tw32(BUFMGR_MB_MACRX_LOW_WATER, | |
8481 | tp->bufmgr_config.mbuf_mac_rx_low_water); | |
8482 | tw32(BUFMGR_MB_HIGH_WATER, | |
8483 | tp->bufmgr_config.mbuf_high_water); | |
8484 | } else { | |
8485 | tw32(BUFMGR_MB_RDMA_LOW_WATER, | |
8486 | tp->bufmgr_config.mbuf_read_dma_low_water_jumbo); | |
8487 | tw32(BUFMGR_MB_MACRX_LOW_WATER, | |
8488 | tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo); | |
8489 | tw32(BUFMGR_MB_HIGH_WATER, | |
8490 | tp->bufmgr_config.mbuf_high_water_jumbo); | |
8491 | } | |
8492 | tw32(BUFMGR_DMA_LOW_WATER, | |
8493 | tp->bufmgr_config.dma_low_water); | |
8494 | tw32(BUFMGR_DMA_HIGH_WATER, | |
8495 | tp->bufmgr_config.dma_high_water); | |
8496 | ||
d309a46e MC |
8497 | val = BUFMGR_MODE_ENABLE | BUFMGR_MODE_ATTN_ENABLE; |
8498 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719) | |
8499 | val |= BUFMGR_MODE_NO_TX_UNDERRUN; | |
4d958473 MC |
8500 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
8501 | tp->pci_chip_rev_id == CHIPREV_ID_5719_A0 || | |
8502 | tp->pci_chip_rev_id == CHIPREV_ID_5720_A0) | |
8503 | val |= BUFMGR_MODE_MBLOW_ATTN_ENAB; | |
d309a46e | 8504 | tw32(BUFMGR_MODE, val); |
1da177e4 LT |
8505 | for (i = 0; i < 2000; i++) { |
8506 | if (tr32(BUFMGR_MODE) & BUFMGR_MODE_ENABLE) | |
8507 | break; | |
8508 | udelay(10); | |
8509 | } | |
8510 | if (i >= 2000) { | |
05dbe005 | 8511 | netdev_err(tp->dev, "%s cannot enable BUFMGR\n", __func__); |
1da177e4 LT |
8512 | return -ENODEV; |
8513 | } | |
8514 | ||
eb07a940 MC |
8515 | if (tp->pci_chip_rev_id == CHIPREV_ID_5906_A1) |
8516 | tw32(ISO_PKT_TX, (tr32(ISO_PKT_TX) & ~0x3) | 0x2); | |
b5d3772c | 8517 | |
eb07a940 | 8518 | tg3_setup_rxbd_thresholds(tp); |
1da177e4 LT |
8519 | |
8520 | /* Initialize TG3_BDINFO's at: | |
8521 | * RCVDBDI_STD_BD: standard eth size rx ring | |
8522 | * RCVDBDI_JUMBO_BD: jumbo frame rx ring | |
8523 | * RCVDBDI_MINI_BD: small frame rx ring (??? does not work) | |
8524 | * | |
8525 | * like so: | |
8526 | * TG3_BDINFO_HOST_ADDR: high/low parts of DMA address of ring | |
8527 | * TG3_BDINFO_MAXLEN_FLAGS: (rx max buffer size << 16) | | |
8528 | * ring attribute flags | |
8529 | * TG3_BDINFO_NIC_ADDR: location of descriptors in nic SRAM | |
8530 | * | |
8531 | * Standard receive ring @ NIC_SRAM_RX_BUFFER_DESC, 512 entries. | |
8532 | * Jumbo receive ring @ NIC_SRAM_RX_JUMBO_BUFFER_DESC, 256 entries. | |
8533 | * | |
8534 | * The size of each ring is fixed in the firmware, but the location is | |
8535 | * configurable. | |
8536 | */ | |
8537 | tw32(RCVDBDI_STD_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH, | |
21f581a5 | 8538 | ((u64) tpr->rx_std_mapping >> 32)); |
1da177e4 | 8539 | tw32(RCVDBDI_STD_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW, |
21f581a5 | 8540 | ((u64) tpr->rx_std_mapping & 0xffffffff)); |
63c3a66f | 8541 | if (!tg3_flag(tp, 5717_PLUS)) |
87668d35 MC |
8542 | tw32(RCVDBDI_STD_BD + TG3_BDINFO_NIC_ADDR, |
8543 | NIC_SRAM_RX_BUFFER_DESC); | |
1da177e4 | 8544 | |
fdb72b38 | 8545 | /* Disable the mini ring */ |
63c3a66f | 8546 | if (!tg3_flag(tp, 5705_PLUS)) |
1da177e4 LT |
8547 | tw32(RCVDBDI_MINI_BD + TG3_BDINFO_MAXLEN_FLAGS, |
8548 | BDINFO_FLAGS_DISABLED); | |
8549 | ||
fdb72b38 MC |
8550 | /* Program the jumbo buffer descriptor ring control |
8551 | * blocks on those devices that have them. | |
8552 | */ | |
a0512944 | 8553 | if (tp->pci_chip_rev_id == CHIPREV_ID_5719_A0 || |
63c3a66f | 8554 | (tg3_flag(tp, JUMBO_CAPABLE) && !tg3_flag(tp, 5780_CLASS))) { |
1da177e4 | 8555 | |
63c3a66f | 8556 | if (tg3_flag(tp, JUMBO_RING_ENABLE)) { |
1da177e4 | 8557 | tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH, |
21f581a5 | 8558 | ((u64) tpr->rx_jmb_mapping >> 32)); |
1da177e4 | 8559 | tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW, |
21f581a5 | 8560 | ((u64) tpr->rx_jmb_mapping & 0xffffffff)); |
de9f5230 MC |
8561 | val = TG3_RX_JMB_RING_SIZE(tp) << |
8562 | BDINFO_FLAGS_MAXLEN_SHIFT; | |
1da177e4 | 8563 | tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_MAXLEN_FLAGS, |
de9f5230 | 8564 | val | BDINFO_FLAGS_USE_EXT_RECV); |
63c3a66f | 8565 | if (!tg3_flag(tp, USE_JUMBO_BDFLAG) || |
a50d0796 | 8566 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) |
87668d35 MC |
8567 | tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_NIC_ADDR, |
8568 | NIC_SRAM_RX_JUMBO_BUFFER_DESC); | |
1da177e4 LT |
8569 | } else { |
8570 | tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_MAXLEN_FLAGS, | |
8571 | BDINFO_FLAGS_DISABLED); | |
8572 | } | |
8573 | ||
63c3a66f | 8574 | if (tg3_flag(tp, 57765_PLUS)) { |
7cb32cf2 | 8575 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) |
de9f5230 | 8576 | val = TG3_RX_STD_MAX_SIZE_5700; |
7cb32cf2 | 8577 | else |
de9f5230 | 8578 | val = TG3_RX_STD_MAX_SIZE_5717; |
7cb32cf2 MC |
8579 | val <<= BDINFO_FLAGS_MAXLEN_SHIFT; |
8580 | val |= (TG3_RX_STD_DMA_SZ << 2); | |
8581 | } else | |
04380d40 | 8582 | val = TG3_RX_STD_DMA_SZ << BDINFO_FLAGS_MAXLEN_SHIFT; |
fdb72b38 | 8583 | } else |
de9f5230 | 8584 | val = TG3_RX_STD_MAX_SIZE_5700 << BDINFO_FLAGS_MAXLEN_SHIFT; |
fdb72b38 MC |
8585 | |
8586 | tw32(RCVDBDI_STD_BD + TG3_BDINFO_MAXLEN_FLAGS, val); | |
1da177e4 | 8587 | |
411da640 | 8588 | tpr->rx_std_prod_idx = tp->rx_pending; |
66711e66 | 8589 | tw32_rx_mbox(TG3_RX_STD_PROD_IDX_REG, tpr->rx_std_prod_idx); |
1da177e4 | 8590 | |
63c3a66f JP |
8591 | tpr->rx_jmb_prod_idx = |
8592 | tg3_flag(tp, JUMBO_RING_ENABLE) ? tp->rx_jumbo_pending : 0; | |
66711e66 | 8593 | tw32_rx_mbox(TG3_RX_JMB_PROD_IDX_REG, tpr->rx_jmb_prod_idx); |
1da177e4 | 8594 | |
2d31ecaf MC |
8595 | tg3_rings_reset(tp); |
8596 | ||
1da177e4 | 8597 | /* Initialize MAC address and backoff seed. */ |
986e0aeb | 8598 | __tg3_set_mac_addr(tp, 0); |
1da177e4 LT |
8599 | |
8600 | /* MTU + ethernet header + FCS + optional VLAN tag */ | |
f7b493e0 MC |
8601 | tw32(MAC_RX_MTU_SIZE, |
8602 | tp->dev->mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN); | |
1da177e4 LT |
8603 | |
8604 | /* The slot time is changed by tg3_setup_phy if we | |
8605 | * run at gigabit with half duplex. | |
8606 | */ | |
f2096f94 MC |
8607 | val = (2 << TX_LENGTHS_IPG_CRS_SHIFT) | |
8608 | (6 << TX_LENGTHS_IPG_SHIFT) | | |
8609 | (32 << TX_LENGTHS_SLOT_TIME_SHIFT); | |
8610 | ||
8611 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) | |
8612 | val |= tr32(MAC_TX_LENGTHS) & | |
8613 | (TX_LENGTHS_JMB_FRM_LEN_MSK | | |
8614 | TX_LENGTHS_CNT_DWN_VAL_MSK); | |
8615 | ||
8616 | tw32(MAC_TX_LENGTHS, val); | |
1da177e4 LT |
8617 | |
8618 | /* Receive rules. */ | |
8619 | tw32(MAC_RCV_RULE_CFG, RCV_RULE_CFG_DEFAULT_CLASS); | |
8620 | tw32(RCVLPC_CONFIG, 0x0181); | |
8621 | ||
8622 | /* Calculate RDMAC_MODE setting early, we need it to determine | |
8623 | * the RCVLPC_STATE_ENABLE mask. | |
8624 | */ | |
8625 | rdmac_mode = (RDMAC_MODE_ENABLE | RDMAC_MODE_TGTABORT_ENAB | | |
8626 | RDMAC_MODE_MSTABORT_ENAB | RDMAC_MODE_PARITYERR_ENAB | | |
8627 | RDMAC_MODE_ADDROFLOW_ENAB | RDMAC_MODE_FIFOOFLOW_ENAB | | |
8628 | RDMAC_MODE_FIFOURUN_ENAB | RDMAC_MODE_FIFOOREAD_ENAB | | |
8629 | RDMAC_MODE_LNGREAD_ENAB); | |
85e94ced | 8630 | |
deabaac8 | 8631 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717) |
0339e4e3 MC |
8632 | rdmac_mode |= RDMAC_MODE_MULT_DMA_RD_DIS; |
8633 | ||
57e6983c | 8634 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 || |
321d32a0 MC |
8635 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 || |
8636 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) | |
d30cdd28 MC |
8637 | rdmac_mode |= RDMAC_MODE_BD_SBD_CRPT_ENAB | |
8638 | RDMAC_MODE_MBUF_RBD_CRPT_ENAB | | |
8639 | RDMAC_MODE_MBUF_SBD_CRPT_ENAB; | |
8640 | ||
c5908939 MC |
8641 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 && |
8642 | tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) { | |
63c3a66f | 8643 | if (tg3_flag(tp, TSO_CAPABLE) && |
c13e3713 | 8644 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) { |
1da177e4 LT |
8645 | rdmac_mode |= RDMAC_MODE_FIFO_SIZE_128; |
8646 | } else if (!(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH) && | |
63c3a66f | 8647 | !tg3_flag(tp, IS_5788)) { |
1da177e4 LT |
8648 | rdmac_mode |= RDMAC_MODE_FIFO_LONG_BURST; |
8649 | } | |
8650 | } | |
8651 | ||
63c3a66f | 8652 | if (tg3_flag(tp, PCI_EXPRESS)) |
85e94ced MC |
8653 | rdmac_mode |= RDMAC_MODE_FIFO_LONG_BURST; |
8654 | ||
63c3a66f JP |
8655 | if (tg3_flag(tp, HW_TSO_1) || |
8656 | tg3_flag(tp, HW_TSO_2) || | |
8657 | tg3_flag(tp, HW_TSO_3)) | |
027455ad MC |
8658 | rdmac_mode |= RDMAC_MODE_IPV4_LSO_EN; |
8659 | ||
108a6c16 | 8660 | if (tg3_flag(tp, 57765_PLUS) || |
e849cdc3 | 8661 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 || |
027455ad MC |
8662 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) |
8663 | rdmac_mode |= RDMAC_MODE_IPV6_LSO_EN; | |
1da177e4 | 8664 | |
f2096f94 MC |
8665 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) |
8666 | rdmac_mode |= tr32(RDMAC_MODE) & RDMAC_MODE_H2BNC_VLAN_DET; | |
8667 | ||
41a8a7ee MC |
8668 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761 || |
8669 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 || | |
8670 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 || | |
8671 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780 || | |
63c3a66f | 8672 | tg3_flag(tp, 57765_PLUS)) { |
41a8a7ee | 8673 | val = tr32(TG3_RDMA_RSRVCTRL_REG); |
d78b59f5 MC |
8674 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719 || |
8675 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) { | |
b4495ed8 MC |
8676 | val &= ~(TG3_RDMA_RSRVCTRL_TXMRGN_MASK | |
8677 | TG3_RDMA_RSRVCTRL_FIFO_LWM_MASK | | |
8678 | TG3_RDMA_RSRVCTRL_FIFO_HWM_MASK); | |
8679 | val |= TG3_RDMA_RSRVCTRL_TXMRGN_320B | | |
8680 | TG3_RDMA_RSRVCTRL_FIFO_LWM_1_5K | | |
8681 | TG3_RDMA_RSRVCTRL_FIFO_HWM_1_5K; | |
b75cc0e4 | 8682 | } |
41a8a7ee MC |
8683 | tw32(TG3_RDMA_RSRVCTRL_REG, |
8684 | val | TG3_RDMA_RSRVCTRL_FIFO_OFLW_FIX); | |
8685 | } | |
8686 | ||
d78b59f5 MC |
8687 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719 || |
8688 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) { | |
d309a46e MC |
8689 | val = tr32(TG3_LSO_RD_DMA_CRPTEN_CTRL); |
8690 | tw32(TG3_LSO_RD_DMA_CRPTEN_CTRL, val | | |
8691 | TG3_LSO_RD_DMA_CRPTEN_CTRL_BLEN_BD_4K | | |
8692 | TG3_LSO_RD_DMA_CRPTEN_CTRL_BLEN_LSO_4K); | |
8693 | } | |
8694 | ||
1da177e4 | 8695 | /* Receive/send statistics. */ |
63c3a66f | 8696 | if (tg3_flag(tp, 5750_PLUS)) { |
1661394e MC |
8697 | val = tr32(RCVLPC_STATS_ENABLE); |
8698 | val &= ~RCVLPC_STATSENAB_DACK_FIX; | |
8699 | tw32(RCVLPC_STATS_ENABLE, val); | |
8700 | } else if ((rdmac_mode & RDMAC_MODE_FIFO_SIZE_128) && | |
63c3a66f | 8701 | tg3_flag(tp, TSO_CAPABLE)) { |
1da177e4 LT |
8702 | val = tr32(RCVLPC_STATS_ENABLE); |
8703 | val &= ~RCVLPC_STATSENAB_LNGBRST_RFIX; | |
8704 | tw32(RCVLPC_STATS_ENABLE, val); | |
8705 | } else { | |
8706 | tw32(RCVLPC_STATS_ENABLE, 0xffffff); | |
8707 | } | |
8708 | tw32(RCVLPC_STATSCTRL, RCVLPC_STATSCTRL_ENABLE); | |
8709 | tw32(SNDDATAI_STATSENAB, 0xffffff); | |
8710 | tw32(SNDDATAI_STATSCTRL, | |
8711 | (SNDDATAI_SCTRL_ENABLE | | |
8712 | SNDDATAI_SCTRL_FASTUPD)); | |
8713 | ||
8714 | /* Setup host coalescing engine. */ | |
8715 | tw32(HOSTCC_MODE, 0); | |
8716 | for (i = 0; i < 2000; i++) { | |
8717 | if (!(tr32(HOSTCC_MODE) & HOSTCC_MODE_ENABLE)) | |
8718 | break; | |
8719 | udelay(10); | |
8720 | } | |
8721 | ||
d244c892 | 8722 | __tg3_set_coalesce(tp, &tp->coal); |
1da177e4 | 8723 | |
63c3a66f | 8724 | if (!tg3_flag(tp, 5705_PLUS)) { |
1da177e4 LT |
8725 | /* Status/statistics block address. See tg3_timer, |
8726 | * the tg3_periodic_fetch_stats call there, and | |
8727 | * tg3_get_stats to see how this works for 5705/5750 chips. | |
8728 | */ | |
1da177e4 LT |
8729 | tw32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH, |
8730 | ((u64) tp->stats_mapping >> 32)); | |
8731 | tw32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW, | |
8732 | ((u64) tp->stats_mapping & 0xffffffff)); | |
8733 | tw32(HOSTCC_STATS_BLK_NIC_ADDR, NIC_SRAM_STATS_BLK); | |
2d31ecaf | 8734 | |
1da177e4 | 8735 | tw32(HOSTCC_STATUS_BLK_NIC_ADDR, NIC_SRAM_STATUS_BLK); |
2d31ecaf MC |
8736 | |
8737 | /* Clear statistics and status block memory areas */ | |
8738 | for (i = NIC_SRAM_STATS_BLK; | |
8739 | i < NIC_SRAM_STATUS_BLK + TG3_HW_STATUS_SIZE; | |
8740 | i += sizeof(u32)) { | |
8741 | tg3_write_mem(tp, i, 0); | |
8742 | udelay(40); | |
8743 | } | |
1da177e4 LT |
8744 | } |
8745 | ||
8746 | tw32(HOSTCC_MODE, HOSTCC_MODE_ENABLE | tp->coalesce_mode); | |
8747 | ||
8748 | tw32(RCVCC_MODE, RCVCC_MODE_ENABLE | RCVCC_MODE_ATTN_ENABLE); | |
8749 | tw32(RCVLPC_MODE, RCVLPC_MODE_ENABLE); | |
63c3a66f | 8750 | if (!tg3_flag(tp, 5705_PLUS)) |
1da177e4 LT |
8751 | tw32(RCVLSC_MODE, RCVLSC_MODE_ENABLE | RCVLSC_MODE_ATTN_ENABLE); |
8752 | ||
f07e9af3 MC |
8753 | if (tp->phy_flags & TG3_PHYFLG_MII_SERDES) { |
8754 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; | |
c94e3941 MC |
8755 | /* reset to prevent losing 1st rx packet intermittently */ |
8756 | tw32_f(MAC_RX_MODE, RX_MODE_RESET); | |
8757 | udelay(10); | |
8758 | } | |
8759 | ||
3bda1258 | 8760 | tp->mac_mode |= MAC_MODE_TXSTAT_ENABLE | MAC_MODE_RXSTAT_ENABLE | |
9e975cc2 MC |
8761 | MAC_MODE_TDE_ENABLE | MAC_MODE_RDE_ENABLE | |
8762 | MAC_MODE_FHDE_ENABLE; | |
8763 | if (tg3_flag(tp, ENABLE_APE)) | |
8764 | tp->mac_mode |= MAC_MODE_APE_TX_EN | MAC_MODE_APE_RX_EN; | |
63c3a66f | 8765 | if (!tg3_flag(tp, 5705_PLUS) && |
f07e9af3 | 8766 | !(tp->phy_flags & TG3_PHYFLG_PHY_SERDES) && |
e8f3f6ca MC |
8767 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700) |
8768 | tp->mac_mode |= MAC_MODE_LINK_POLARITY; | |
1da177e4 LT |
8769 | tw32_f(MAC_MODE, tp->mac_mode | MAC_MODE_RXSTAT_CLEAR | MAC_MODE_TXSTAT_CLEAR); |
8770 | udelay(40); | |
8771 | ||
314fba34 | 8772 | /* tp->grc_local_ctrl is partially set up during tg3_get_invariants(). |
63c3a66f | 8773 | * If TG3_FLAG_IS_NIC is zero, we should read the |
314fba34 MC |
8774 | * register to preserve the GPIO settings for LOMs. The GPIOs, |
8775 | * whether used as inputs or outputs, are set by boot code after | |
8776 | * reset. | |
8777 | */ | |
63c3a66f | 8778 | if (!tg3_flag(tp, IS_NIC)) { |
314fba34 MC |
8779 | u32 gpio_mask; |
8780 | ||
9d26e213 MC |
8781 | gpio_mask = GRC_LCLCTRL_GPIO_OE0 | GRC_LCLCTRL_GPIO_OE1 | |
8782 | GRC_LCLCTRL_GPIO_OE2 | GRC_LCLCTRL_GPIO_OUTPUT0 | | |
8783 | GRC_LCLCTRL_GPIO_OUTPUT1 | GRC_LCLCTRL_GPIO_OUTPUT2; | |
3e7d83bc MC |
8784 | |
8785 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752) | |
8786 | gpio_mask |= GRC_LCLCTRL_GPIO_OE3 | | |
8787 | GRC_LCLCTRL_GPIO_OUTPUT3; | |
8788 | ||
af36e6b6 MC |
8789 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755) |
8790 | gpio_mask |= GRC_LCLCTRL_GPIO_UART_SEL; | |
8791 | ||
aaf84465 | 8792 | tp->grc_local_ctrl &= ~gpio_mask; |
314fba34 MC |
8793 | tp->grc_local_ctrl |= tr32(GRC_LOCAL_CTRL) & gpio_mask; |
8794 | ||
8795 | /* GPIO1 must be driven high for eeprom write protect */ | |
63c3a66f | 8796 | if (tg3_flag(tp, EEPROM_WRITE_PROT)) |
9d26e213 MC |
8797 | tp->grc_local_ctrl |= (GRC_LCLCTRL_GPIO_OE1 | |
8798 | GRC_LCLCTRL_GPIO_OUTPUT1); | |
314fba34 | 8799 | } |
1da177e4 LT |
8800 | tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl); |
8801 | udelay(100); | |
8802 | ||
63c3a66f | 8803 | if (tg3_flag(tp, USING_MSIX) && tp->irq_cnt > 1) { |
baf8a94a MC |
8804 | val = tr32(MSGINT_MODE); |
8805 | val |= MSGINT_MODE_MULTIVEC_EN | MSGINT_MODE_ENABLE; | |
5b39de91 MC |
8806 | if (!tg3_flag(tp, 1SHOT_MSI)) |
8807 | val |= MSGINT_MODE_ONE_SHOT_DISABLE; | |
baf8a94a MC |
8808 | tw32(MSGINT_MODE, val); |
8809 | } | |
8810 | ||
63c3a66f | 8811 | if (!tg3_flag(tp, 5705_PLUS)) { |
1da177e4 LT |
8812 | tw32_f(DMAC_MODE, DMAC_MODE_ENABLE); |
8813 | udelay(40); | |
8814 | } | |
8815 | ||
8816 | val = (WDMAC_MODE_ENABLE | WDMAC_MODE_TGTABORT_ENAB | | |
8817 | WDMAC_MODE_MSTABORT_ENAB | WDMAC_MODE_PARITYERR_ENAB | | |
8818 | WDMAC_MODE_ADDROFLOW_ENAB | WDMAC_MODE_FIFOOFLOW_ENAB | | |
8819 | WDMAC_MODE_FIFOURUN_ENAB | WDMAC_MODE_FIFOOREAD_ENAB | | |
8820 | WDMAC_MODE_LNGREAD_ENAB); | |
8821 | ||
c5908939 MC |
8822 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 && |
8823 | tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) { | |
63c3a66f | 8824 | if (tg3_flag(tp, TSO_CAPABLE) && |
1da177e4 LT |
8825 | (tp->pci_chip_rev_id == CHIPREV_ID_5705_A1 || |
8826 | tp->pci_chip_rev_id == CHIPREV_ID_5705_A2)) { | |
8827 | /* nothing */ | |
8828 | } else if (!(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH) && | |
63c3a66f | 8829 | !tg3_flag(tp, IS_5788)) { |
1da177e4 LT |
8830 | val |= WDMAC_MODE_RX_ACCEL; |
8831 | } | |
8832 | } | |
8833 | ||
d9ab5ad1 | 8834 | /* Enable host coalescing bug fix */ |
63c3a66f | 8835 | if (tg3_flag(tp, 5755_PLUS)) |
f51f3562 | 8836 | val |= WDMAC_MODE_STATUS_TAG_FIX; |
d9ab5ad1 | 8837 | |
788a035e MC |
8838 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) |
8839 | val |= WDMAC_MODE_BURST_ALL_DATA; | |
8840 | ||
1da177e4 LT |
8841 | tw32_f(WDMAC_MODE, val); |
8842 | udelay(40); | |
8843 | ||
63c3a66f | 8844 | if (tg3_flag(tp, PCIX_MODE)) { |
9974a356 MC |
8845 | u16 pcix_cmd; |
8846 | ||
8847 | pci_read_config_word(tp->pdev, tp->pcix_cap + PCI_X_CMD, | |
8848 | &pcix_cmd); | |
1da177e4 | 8849 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703) { |
9974a356 MC |
8850 | pcix_cmd &= ~PCI_X_CMD_MAX_READ; |
8851 | pcix_cmd |= PCI_X_CMD_READ_2K; | |
1da177e4 | 8852 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) { |
9974a356 MC |
8853 | pcix_cmd &= ~(PCI_X_CMD_MAX_SPLIT | PCI_X_CMD_MAX_READ); |
8854 | pcix_cmd |= PCI_X_CMD_READ_2K; | |
1da177e4 | 8855 | } |
9974a356 MC |
8856 | pci_write_config_word(tp->pdev, tp->pcix_cap + PCI_X_CMD, |
8857 | pcix_cmd); | |
1da177e4 LT |
8858 | } |
8859 | ||
8860 | tw32_f(RDMAC_MODE, rdmac_mode); | |
8861 | udelay(40); | |
8862 | ||
8863 | tw32(RCVDCC_MODE, RCVDCC_MODE_ENABLE | RCVDCC_MODE_ATTN_ENABLE); | |
63c3a66f | 8864 | if (!tg3_flag(tp, 5705_PLUS)) |
1da177e4 | 8865 | tw32(MBFREE_MODE, MBFREE_MODE_ENABLE); |
9936bcf6 MC |
8866 | |
8867 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) | |
8868 | tw32(SNDDATAC_MODE, | |
8869 | SNDDATAC_MODE_ENABLE | SNDDATAC_MODE_CDELAY); | |
8870 | else | |
8871 | tw32(SNDDATAC_MODE, SNDDATAC_MODE_ENABLE); | |
8872 | ||
1da177e4 LT |
8873 | tw32(SNDBDC_MODE, SNDBDC_MODE_ENABLE | SNDBDC_MODE_ATTN_ENABLE); |
8874 | tw32(RCVBDI_MODE, RCVBDI_MODE_ENABLE | RCVBDI_MODE_RCB_ATTN_ENAB); | |
7cb32cf2 | 8875 | val = RCVDBDI_MODE_ENABLE | RCVDBDI_MODE_INV_RING_SZ; |
63c3a66f | 8876 | if (tg3_flag(tp, LRG_PROD_RING_CAP)) |
7cb32cf2 MC |
8877 | val |= RCVDBDI_MODE_LRG_RING_SZ; |
8878 | tw32(RCVDBDI_MODE, val); | |
1da177e4 | 8879 | tw32(SNDDATAI_MODE, SNDDATAI_MODE_ENABLE); |
63c3a66f JP |
8880 | if (tg3_flag(tp, HW_TSO_1) || |
8881 | tg3_flag(tp, HW_TSO_2) || | |
8882 | tg3_flag(tp, HW_TSO_3)) | |
1da177e4 | 8883 | tw32(SNDDATAI_MODE, SNDDATAI_MODE_ENABLE | 0x8); |
baf8a94a | 8884 | val = SNDBDI_MODE_ENABLE | SNDBDI_MODE_ATTN_ENABLE; |
63c3a66f | 8885 | if (tg3_flag(tp, ENABLE_TSS)) |
baf8a94a MC |
8886 | val |= SNDBDI_MODE_MULTI_TXQ_EN; |
8887 | tw32(SNDBDI_MODE, val); | |
1da177e4 LT |
8888 | tw32(SNDBDS_MODE, SNDBDS_MODE_ENABLE | SNDBDS_MODE_ATTN_ENABLE); |
8889 | ||
8890 | if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0) { | |
8891 | err = tg3_load_5701_a0_firmware_fix(tp); | |
8892 | if (err) | |
8893 | return err; | |
8894 | } | |
8895 | ||
63c3a66f | 8896 | if (tg3_flag(tp, TSO_CAPABLE)) { |
1da177e4 LT |
8897 | err = tg3_load_tso_firmware(tp); |
8898 | if (err) | |
8899 | return err; | |
8900 | } | |
1da177e4 LT |
8901 | |
8902 | tp->tx_mode = TX_MODE_ENABLE; | |
f2096f94 | 8903 | |
63c3a66f | 8904 | if (tg3_flag(tp, 5755_PLUS) || |
b1d05210 MC |
8905 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) |
8906 | tp->tx_mode |= TX_MODE_MBUF_LOCKUP_FIX; | |
f2096f94 MC |
8907 | |
8908 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) { | |
8909 | val = TX_MODE_JMB_FRM_LEN | TX_MODE_CNT_DN_MODE; | |
8910 | tp->tx_mode &= ~val; | |
8911 | tp->tx_mode |= tr32(MAC_TX_MODE) & val; | |
8912 | } | |
8913 | ||
1da177e4 LT |
8914 | tw32_f(MAC_TX_MODE, tp->tx_mode); |
8915 | udelay(100); | |
8916 | ||
63c3a66f | 8917 | if (tg3_flag(tp, ENABLE_RSS)) { |
9d53fa12 | 8918 | int i = 0; |
baf8a94a | 8919 | u32 reg = MAC_RSS_INDIR_TBL_0; |
baf8a94a | 8920 | |
9d53fa12 MC |
8921 | if (tp->irq_cnt == 2) { |
8922 | for (i = 0; i < TG3_RSS_INDIR_TBL_SIZE; i += 8) { | |
8923 | tw32(reg, 0x0); | |
8924 | reg += 4; | |
8925 | } | |
8926 | } else { | |
8927 | u32 val; | |
baf8a94a | 8928 | |
9d53fa12 MC |
8929 | while (i < TG3_RSS_INDIR_TBL_SIZE) { |
8930 | val = i % (tp->irq_cnt - 1); | |
8931 | i++; | |
8932 | for (; i % 8; i++) { | |
8933 | val <<= 4; | |
8934 | val |= (i % (tp->irq_cnt - 1)); | |
8935 | } | |
baf8a94a MC |
8936 | tw32(reg, val); |
8937 | reg += 4; | |
8938 | } | |
8939 | } | |
8940 | ||
8941 | /* Setup the "secret" hash key. */ | |
8942 | tw32(MAC_RSS_HASH_KEY_0, 0x5f865437); | |
8943 | tw32(MAC_RSS_HASH_KEY_1, 0xe4ac62cc); | |
8944 | tw32(MAC_RSS_HASH_KEY_2, 0x50103a45); | |
8945 | tw32(MAC_RSS_HASH_KEY_3, 0x36621985); | |
8946 | tw32(MAC_RSS_HASH_KEY_4, 0xbf14c0e8); | |
8947 | tw32(MAC_RSS_HASH_KEY_5, 0x1bc27a1e); | |
8948 | tw32(MAC_RSS_HASH_KEY_6, 0x84f4b556); | |
8949 | tw32(MAC_RSS_HASH_KEY_7, 0x094ea6fe); | |
8950 | tw32(MAC_RSS_HASH_KEY_8, 0x7dda01e7); | |
8951 | tw32(MAC_RSS_HASH_KEY_9, 0xc04d7481); | |
8952 | } | |
8953 | ||
1da177e4 | 8954 | tp->rx_mode = RX_MODE_ENABLE; |
63c3a66f | 8955 | if (tg3_flag(tp, 5755_PLUS)) |
af36e6b6 MC |
8956 | tp->rx_mode |= RX_MODE_IPV6_CSUM_ENABLE; |
8957 | ||
63c3a66f | 8958 | if (tg3_flag(tp, ENABLE_RSS)) |
baf8a94a MC |
8959 | tp->rx_mode |= RX_MODE_RSS_ENABLE | |
8960 | RX_MODE_RSS_ITBL_HASH_BITS_7 | | |
8961 | RX_MODE_RSS_IPV6_HASH_EN | | |
8962 | RX_MODE_RSS_TCP_IPV6_HASH_EN | | |
8963 | RX_MODE_RSS_IPV4_HASH_EN | | |
8964 | RX_MODE_RSS_TCP_IPV4_HASH_EN; | |
8965 | ||
1da177e4 LT |
8966 | tw32_f(MAC_RX_MODE, tp->rx_mode); |
8967 | udelay(10); | |
8968 | ||
1da177e4 LT |
8969 | tw32(MAC_LED_CTRL, tp->led_ctrl); |
8970 | ||
8971 | tw32(MAC_MI_STAT, MAC_MI_STAT_LNKSTAT_ATTN_ENAB); | |
f07e9af3 | 8972 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) { |
1da177e4 LT |
8973 | tw32_f(MAC_RX_MODE, RX_MODE_RESET); |
8974 | udelay(10); | |
8975 | } | |
8976 | tw32_f(MAC_RX_MODE, tp->rx_mode); | |
8977 | udelay(10); | |
8978 | ||
f07e9af3 | 8979 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) { |
1da177e4 | 8980 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) && |
f07e9af3 | 8981 | !(tp->phy_flags & TG3_PHYFLG_SERDES_PREEMPHASIS)) { |
1da177e4 LT |
8982 | /* Set drive transmission level to 1.2V */ |
8983 | /* only if the signal pre-emphasis bit is not set */ | |
8984 | val = tr32(MAC_SERDES_CFG); | |
8985 | val &= 0xfffff000; | |
8986 | val |= 0x880; | |
8987 | tw32(MAC_SERDES_CFG, val); | |
8988 | } | |
8989 | if (tp->pci_chip_rev_id == CHIPREV_ID_5703_A1) | |
8990 | tw32(MAC_SERDES_CFG, 0x616000); | |
8991 | } | |
8992 | ||
8993 | /* Prevent chip from dropping frames when flow control | |
8994 | * is enabled. | |
8995 | */ | |
666bc831 MC |
8996 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) |
8997 | val = 1; | |
8998 | else | |
8999 | val = 2; | |
9000 | tw32_f(MAC_LOW_WMARK_MAX_RX_FRAME, val); | |
1da177e4 LT |
9001 | |
9002 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 && | |
f07e9af3 | 9003 | (tp->phy_flags & TG3_PHYFLG_PHY_SERDES)) { |
1da177e4 | 9004 | /* Use hardware link auto-negotiation */ |
63c3a66f | 9005 | tg3_flag_set(tp, HW_AUTONEG); |
1da177e4 LT |
9006 | } |
9007 | ||
f07e9af3 | 9008 | if ((tp->phy_flags & TG3_PHYFLG_MII_SERDES) && |
6ff6f81d | 9009 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) { |
d4d2c558 MC |
9010 | u32 tmp; |
9011 | ||
9012 | tmp = tr32(SERDES_RX_CTRL); | |
9013 | tw32(SERDES_RX_CTRL, tmp | SERDES_RX_SIG_DETECT); | |
9014 | tp->grc_local_ctrl &= ~GRC_LCLCTRL_USE_EXT_SIG_DETECT; | |
9015 | tp->grc_local_ctrl |= GRC_LCLCTRL_USE_SIG_DETECT; | |
9016 | tw32(GRC_LOCAL_CTRL, tp->grc_local_ctrl); | |
9017 | } | |
9018 | ||
63c3a66f | 9019 | if (!tg3_flag(tp, USE_PHYLIB)) { |
80096068 MC |
9020 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) { |
9021 | tp->phy_flags &= ~TG3_PHYFLG_IS_LOW_POWER; | |
dd477003 MC |
9022 | tp->link_config.speed = tp->link_config.orig_speed; |
9023 | tp->link_config.duplex = tp->link_config.orig_duplex; | |
9024 | tp->link_config.autoneg = tp->link_config.orig_autoneg; | |
9025 | } | |
1da177e4 | 9026 | |
dd477003 MC |
9027 | err = tg3_setup_phy(tp, 0); |
9028 | if (err) | |
9029 | return err; | |
1da177e4 | 9030 | |
f07e9af3 MC |
9031 | if (!(tp->phy_flags & TG3_PHYFLG_PHY_SERDES) && |
9032 | !(tp->phy_flags & TG3_PHYFLG_IS_FET)) { | |
dd477003 MC |
9033 | u32 tmp; |
9034 | ||
9035 | /* Clear CRC stats. */ | |
9036 | if (!tg3_readphy(tp, MII_TG3_TEST1, &tmp)) { | |
9037 | tg3_writephy(tp, MII_TG3_TEST1, | |
9038 | tmp | MII_TG3_TEST1_CRC_EN); | |
f08aa1a8 | 9039 | tg3_readphy(tp, MII_TG3_RXR_COUNTERS, &tmp); |
dd477003 | 9040 | } |
1da177e4 LT |
9041 | } |
9042 | } | |
9043 | ||
9044 | __tg3_set_rx_mode(tp->dev); | |
9045 | ||
9046 | /* Initialize receive rules. */ | |
9047 | tw32(MAC_RCV_RULE_0, 0xc2000000 & RCV_RULE_DISABLE_MASK); | |
9048 | tw32(MAC_RCV_VALUE_0, 0xffffffff & RCV_RULE_DISABLE_MASK); | |
9049 | tw32(MAC_RCV_RULE_1, 0x86000004 & RCV_RULE_DISABLE_MASK); | |
9050 | tw32(MAC_RCV_VALUE_1, 0xffffffff & RCV_RULE_DISABLE_MASK); | |
9051 | ||
63c3a66f | 9052 | if (tg3_flag(tp, 5705_PLUS) && !tg3_flag(tp, 5780_CLASS)) |
1da177e4 LT |
9053 | limit = 8; |
9054 | else | |
9055 | limit = 16; | |
63c3a66f | 9056 | if (tg3_flag(tp, ENABLE_ASF)) |
1da177e4 LT |
9057 | limit -= 4; |
9058 | switch (limit) { | |
9059 | case 16: | |
9060 | tw32(MAC_RCV_RULE_15, 0); tw32(MAC_RCV_VALUE_15, 0); | |
9061 | case 15: | |
9062 | tw32(MAC_RCV_RULE_14, 0); tw32(MAC_RCV_VALUE_14, 0); | |
9063 | case 14: | |
9064 | tw32(MAC_RCV_RULE_13, 0); tw32(MAC_RCV_VALUE_13, 0); | |
9065 | case 13: | |
9066 | tw32(MAC_RCV_RULE_12, 0); tw32(MAC_RCV_VALUE_12, 0); | |
9067 | case 12: | |
9068 | tw32(MAC_RCV_RULE_11, 0); tw32(MAC_RCV_VALUE_11, 0); | |
9069 | case 11: | |
9070 | tw32(MAC_RCV_RULE_10, 0); tw32(MAC_RCV_VALUE_10, 0); | |
9071 | case 10: | |
9072 | tw32(MAC_RCV_RULE_9, 0); tw32(MAC_RCV_VALUE_9, 0); | |
9073 | case 9: | |
9074 | tw32(MAC_RCV_RULE_8, 0); tw32(MAC_RCV_VALUE_8, 0); | |
9075 | case 8: | |
9076 | tw32(MAC_RCV_RULE_7, 0); tw32(MAC_RCV_VALUE_7, 0); | |
9077 | case 7: | |
9078 | tw32(MAC_RCV_RULE_6, 0); tw32(MAC_RCV_VALUE_6, 0); | |
9079 | case 6: | |
9080 | tw32(MAC_RCV_RULE_5, 0); tw32(MAC_RCV_VALUE_5, 0); | |
9081 | case 5: | |
9082 | tw32(MAC_RCV_RULE_4, 0); tw32(MAC_RCV_VALUE_4, 0); | |
9083 | case 4: | |
9084 | /* tw32(MAC_RCV_RULE_3, 0); tw32(MAC_RCV_VALUE_3, 0); */ | |
9085 | case 3: | |
9086 | /* tw32(MAC_RCV_RULE_2, 0); tw32(MAC_RCV_VALUE_2, 0); */ | |
9087 | case 2: | |
9088 | case 1: | |
9089 | ||
9090 | default: | |
9091 | break; | |
855e1111 | 9092 | } |
1da177e4 | 9093 | |
63c3a66f | 9094 | if (tg3_flag(tp, ENABLE_APE)) |
9ce768ea MC |
9095 | /* Write our heartbeat update interval to APE. */ |
9096 | tg3_ape_write32(tp, TG3_APE_HOST_HEARTBEAT_INT_MS, | |
9097 | APE_HOST_HEARTBEAT_INT_DISABLE); | |
0d3031d9 | 9098 | |
1da177e4 LT |
9099 | tg3_write_sig_post_reset(tp, RESET_KIND_INIT); |
9100 | ||
1da177e4 LT |
9101 | return 0; |
9102 | } | |
9103 | ||
9104 | /* Called at device open time to get the chip ready for | |
9105 | * packet processing. Invoked with tp->lock held. | |
9106 | */ | |
8e7a22e3 | 9107 | static int tg3_init_hw(struct tg3 *tp, int reset_phy) |
1da177e4 | 9108 | { |
1da177e4 LT |
9109 | tg3_switch_clocks(tp); |
9110 | ||
9111 | tw32(TG3PCI_MEM_WIN_BASE_ADDR, 0); | |
9112 | ||
2f751b67 | 9113 | return tg3_reset_hw(tp, reset_phy); |
1da177e4 LT |
9114 | } |
9115 | ||
9116 | #define TG3_STAT_ADD32(PSTAT, REG) \ | |
9117 | do { u32 __val = tr32(REG); \ | |
9118 | (PSTAT)->low += __val; \ | |
9119 | if ((PSTAT)->low < __val) \ | |
9120 | (PSTAT)->high += 1; \ | |
9121 | } while (0) | |
9122 | ||
9123 | static void tg3_periodic_fetch_stats(struct tg3 *tp) | |
9124 | { | |
9125 | struct tg3_hw_stats *sp = tp->hw_stats; | |
9126 | ||
9127 | if (!netif_carrier_ok(tp->dev)) | |
9128 | return; | |
9129 | ||
9130 | TG3_STAT_ADD32(&sp->tx_octets, MAC_TX_STATS_OCTETS); | |
9131 | TG3_STAT_ADD32(&sp->tx_collisions, MAC_TX_STATS_COLLISIONS); | |
9132 | TG3_STAT_ADD32(&sp->tx_xon_sent, MAC_TX_STATS_XON_SENT); | |
9133 | TG3_STAT_ADD32(&sp->tx_xoff_sent, MAC_TX_STATS_XOFF_SENT); | |
9134 | TG3_STAT_ADD32(&sp->tx_mac_errors, MAC_TX_STATS_MAC_ERRORS); | |
9135 | TG3_STAT_ADD32(&sp->tx_single_collisions, MAC_TX_STATS_SINGLE_COLLISIONS); | |
9136 | TG3_STAT_ADD32(&sp->tx_mult_collisions, MAC_TX_STATS_MULT_COLLISIONS); | |
9137 | TG3_STAT_ADD32(&sp->tx_deferred, MAC_TX_STATS_DEFERRED); | |
9138 | TG3_STAT_ADD32(&sp->tx_excessive_collisions, MAC_TX_STATS_EXCESSIVE_COL); | |
9139 | TG3_STAT_ADD32(&sp->tx_late_collisions, MAC_TX_STATS_LATE_COL); | |
9140 | TG3_STAT_ADD32(&sp->tx_ucast_packets, MAC_TX_STATS_UCAST); | |
9141 | TG3_STAT_ADD32(&sp->tx_mcast_packets, MAC_TX_STATS_MCAST); | |
9142 | TG3_STAT_ADD32(&sp->tx_bcast_packets, MAC_TX_STATS_BCAST); | |
9143 | ||
9144 | TG3_STAT_ADD32(&sp->rx_octets, MAC_RX_STATS_OCTETS); | |
9145 | TG3_STAT_ADD32(&sp->rx_fragments, MAC_RX_STATS_FRAGMENTS); | |
9146 | TG3_STAT_ADD32(&sp->rx_ucast_packets, MAC_RX_STATS_UCAST); | |
9147 | TG3_STAT_ADD32(&sp->rx_mcast_packets, MAC_RX_STATS_MCAST); | |
9148 | TG3_STAT_ADD32(&sp->rx_bcast_packets, MAC_RX_STATS_BCAST); | |
9149 | TG3_STAT_ADD32(&sp->rx_fcs_errors, MAC_RX_STATS_FCS_ERRORS); | |
9150 | TG3_STAT_ADD32(&sp->rx_align_errors, MAC_RX_STATS_ALIGN_ERRORS); | |
9151 | TG3_STAT_ADD32(&sp->rx_xon_pause_rcvd, MAC_RX_STATS_XON_PAUSE_RECVD); | |
9152 | TG3_STAT_ADD32(&sp->rx_xoff_pause_rcvd, MAC_RX_STATS_XOFF_PAUSE_RECVD); | |
9153 | TG3_STAT_ADD32(&sp->rx_mac_ctrl_rcvd, MAC_RX_STATS_MAC_CTRL_RECVD); | |
9154 | TG3_STAT_ADD32(&sp->rx_xoff_entered, MAC_RX_STATS_XOFF_ENTERED); | |
9155 | TG3_STAT_ADD32(&sp->rx_frame_too_long_errors, MAC_RX_STATS_FRAME_TOO_LONG); | |
9156 | TG3_STAT_ADD32(&sp->rx_jabbers, MAC_RX_STATS_JABBERS); | |
9157 | TG3_STAT_ADD32(&sp->rx_undersize_packets, MAC_RX_STATS_UNDERSIZE); | |
463d305b MC |
9158 | |
9159 | TG3_STAT_ADD32(&sp->rxbds_empty, RCVLPC_NO_RCV_BD_CNT); | |
310050fa MC |
9160 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5717 && |
9161 | tp->pci_chip_rev_id != CHIPREV_ID_5719_A0 && | |
9162 | tp->pci_chip_rev_id != CHIPREV_ID_5720_A0) { | |
4d958473 MC |
9163 | TG3_STAT_ADD32(&sp->rx_discards, RCVLPC_IN_DISCARDS_CNT); |
9164 | } else { | |
9165 | u32 val = tr32(HOSTCC_FLOW_ATTN); | |
9166 | val = (val & HOSTCC_FLOW_ATTN_MBUF_LWM) ? 1 : 0; | |
9167 | if (val) { | |
9168 | tw32(HOSTCC_FLOW_ATTN, HOSTCC_FLOW_ATTN_MBUF_LWM); | |
9169 | sp->rx_discards.low += val; | |
9170 | if (sp->rx_discards.low < val) | |
9171 | sp->rx_discards.high += 1; | |
9172 | } | |
9173 | sp->mbuf_lwm_thresh_hit = sp->rx_discards; | |
9174 | } | |
463d305b | 9175 | TG3_STAT_ADD32(&sp->rx_errors, RCVLPC_IN_ERRORS_CNT); |
1da177e4 LT |
9176 | } |
9177 | ||
0e6cf6a9 MC |
9178 | static void tg3_chk_missed_msi(struct tg3 *tp) |
9179 | { | |
9180 | u32 i; | |
9181 | ||
9182 | for (i = 0; i < tp->irq_cnt; i++) { | |
9183 | struct tg3_napi *tnapi = &tp->napi[i]; | |
9184 | ||
9185 | if (tg3_has_work(tnapi)) { | |
9186 | if (tnapi->last_rx_cons == tnapi->rx_rcb_ptr && | |
9187 | tnapi->last_tx_cons == tnapi->tx_cons) { | |
9188 | if (tnapi->chk_msi_cnt < 1) { | |
9189 | tnapi->chk_msi_cnt++; | |
9190 | return; | |
9191 | } | |
7f230735 | 9192 | tg3_msi(0, tnapi); |
0e6cf6a9 MC |
9193 | } |
9194 | } | |
9195 | tnapi->chk_msi_cnt = 0; | |
9196 | tnapi->last_rx_cons = tnapi->rx_rcb_ptr; | |
9197 | tnapi->last_tx_cons = tnapi->tx_cons; | |
9198 | } | |
9199 | } | |
9200 | ||
1da177e4 LT |
9201 | static void tg3_timer(unsigned long __opaque) |
9202 | { | |
9203 | struct tg3 *tp = (struct tg3 *) __opaque; | |
1da177e4 | 9204 | |
f475f163 MC |
9205 | if (tp->irq_sync) |
9206 | goto restart_timer; | |
9207 | ||
f47c11ee | 9208 | spin_lock(&tp->lock); |
1da177e4 | 9209 | |
0e6cf6a9 MC |
9210 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
9211 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) | |
9212 | tg3_chk_missed_msi(tp); | |
9213 | ||
63c3a66f | 9214 | if (!tg3_flag(tp, TAGGED_STATUS)) { |
fac9b83e DM |
9215 | /* All of this garbage is because when using non-tagged |
9216 | * IRQ status the mailbox/status_block protocol the chip | |
9217 | * uses with the cpu is race prone. | |
9218 | */ | |
898a56f8 | 9219 | if (tp->napi[0].hw_status->status & SD_STATUS_UPDATED) { |
fac9b83e DM |
9220 | tw32(GRC_LOCAL_CTRL, |
9221 | tp->grc_local_ctrl | GRC_LCLCTRL_SETINT); | |
9222 | } else { | |
9223 | tw32(HOSTCC_MODE, tp->coalesce_mode | | |
fd2ce37f | 9224 | HOSTCC_MODE_ENABLE | HOSTCC_MODE_NOW); |
fac9b83e | 9225 | } |
1da177e4 | 9226 | |
fac9b83e | 9227 | if (!(tr32(WDMAC_MODE) & WDMAC_MODE_ENABLE)) { |
63c3a66f | 9228 | tg3_flag_set(tp, RESTART_TIMER); |
f47c11ee | 9229 | spin_unlock(&tp->lock); |
fac9b83e DM |
9230 | schedule_work(&tp->reset_task); |
9231 | return; | |
9232 | } | |
1da177e4 LT |
9233 | } |
9234 | ||
1da177e4 LT |
9235 | /* This part only runs once per second. */ |
9236 | if (!--tp->timer_counter) { | |
63c3a66f | 9237 | if (tg3_flag(tp, 5705_PLUS)) |
fac9b83e DM |
9238 | tg3_periodic_fetch_stats(tp); |
9239 | ||
b0c5943f MC |
9240 | if (tp->setlpicnt && !--tp->setlpicnt) |
9241 | tg3_phy_eee_enable(tp); | |
52b02d04 | 9242 | |
63c3a66f | 9243 | if (tg3_flag(tp, USE_LINKCHG_REG)) { |
1da177e4 LT |
9244 | u32 mac_stat; |
9245 | int phy_event; | |
9246 | ||
9247 | mac_stat = tr32(MAC_STATUS); | |
9248 | ||
9249 | phy_event = 0; | |
f07e9af3 | 9250 | if (tp->phy_flags & TG3_PHYFLG_USE_MI_INTERRUPT) { |
1da177e4 LT |
9251 | if (mac_stat & MAC_STATUS_MI_INTERRUPT) |
9252 | phy_event = 1; | |
9253 | } else if (mac_stat & MAC_STATUS_LNKSTATE_CHANGED) | |
9254 | phy_event = 1; | |
9255 | ||
9256 | if (phy_event) | |
9257 | tg3_setup_phy(tp, 0); | |
63c3a66f | 9258 | } else if (tg3_flag(tp, POLL_SERDES)) { |
1da177e4 LT |
9259 | u32 mac_stat = tr32(MAC_STATUS); |
9260 | int need_setup = 0; | |
9261 | ||
9262 | if (netif_carrier_ok(tp->dev) && | |
9263 | (mac_stat & MAC_STATUS_LNKSTATE_CHANGED)) { | |
9264 | need_setup = 1; | |
9265 | } | |
be98da6a | 9266 | if (!netif_carrier_ok(tp->dev) && |
1da177e4 LT |
9267 | (mac_stat & (MAC_STATUS_PCS_SYNCED | |
9268 | MAC_STATUS_SIGNAL_DET))) { | |
9269 | need_setup = 1; | |
9270 | } | |
9271 | if (need_setup) { | |
3d3ebe74 MC |
9272 | if (!tp->serdes_counter) { |
9273 | tw32_f(MAC_MODE, | |
9274 | (tp->mac_mode & | |
9275 | ~MAC_MODE_PORT_MODE_MASK)); | |
9276 | udelay(40); | |
9277 | tw32_f(MAC_MODE, tp->mac_mode); | |
9278 | udelay(40); | |
9279 | } | |
1da177e4 LT |
9280 | tg3_setup_phy(tp, 0); |
9281 | } | |
f07e9af3 | 9282 | } else if ((tp->phy_flags & TG3_PHYFLG_MII_SERDES) && |
63c3a66f | 9283 | tg3_flag(tp, 5780_CLASS)) { |
747e8f8b | 9284 | tg3_serdes_parallel_detect(tp); |
57d8b880 | 9285 | } |
1da177e4 LT |
9286 | |
9287 | tp->timer_counter = tp->timer_multiplier; | |
9288 | } | |
9289 | ||
130b8e4d MC |
9290 | /* Heartbeat is only sent once every 2 seconds. |
9291 | * | |
9292 | * The heartbeat is to tell the ASF firmware that the host | |
9293 | * driver is still alive. In the event that the OS crashes, | |
9294 | * ASF needs to reset the hardware to free up the FIFO space | |
9295 | * that may be filled with rx packets destined for the host. | |
9296 | * If the FIFO is full, ASF will no longer function properly. | |
9297 | * | |
9298 | * Unintended resets have been reported on real time kernels | |
9299 | * where the timer doesn't run on time. Netpoll will also have | |
9300 | * same problem. | |
9301 | * | |
9302 | * The new FWCMD_NICDRV_ALIVE3 command tells the ASF firmware | |
9303 | * to check the ring condition when the heartbeat is expiring | |
9304 | * before doing the reset. This will prevent most unintended | |
9305 | * resets. | |
9306 | */ | |
1da177e4 | 9307 | if (!--tp->asf_counter) { |
63c3a66f | 9308 | if (tg3_flag(tp, ENABLE_ASF) && !tg3_flag(tp, ENABLE_APE)) { |
7c5026aa MC |
9309 | tg3_wait_for_event_ack(tp); |
9310 | ||
bbadf503 | 9311 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX, |
130b8e4d | 9312 | FWCMD_NICDRV_ALIVE3); |
bbadf503 | 9313 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_LEN_MBOX, 4); |
c6cdf436 MC |
9314 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX, |
9315 | TG3_FW_UPDATE_TIMEOUT_SEC); | |
4ba526ce MC |
9316 | |
9317 | tg3_generate_fw_event(tp); | |
1da177e4 LT |
9318 | } |
9319 | tp->asf_counter = tp->asf_multiplier; | |
9320 | } | |
9321 | ||
f47c11ee | 9322 | spin_unlock(&tp->lock); |
1da177e4 | 9323 | |
f475f163 | 9324 | restart_timer: |
1da177e4 LT |
9325 | tp->timer.expires = jiffies + tp->timer_offset; |
9326 | add_timer(&tp->timer); | |
9327 | } | |
9328 | ||
4f125f42 | 9329 | static int tg3_request_irq(struct tg3 *tp, int irq_num) |
fcfa0a32 | 9330 | { |
7d12e780 | 9331 | irq_handler_t fn; |
fcfa0a32 | 9332 | unsigned long flags; |
4f125f42 MC |
9333 | char *name; |
9334 | struct tg3_napi *tnapi = &tp->napi[irq_num]; | |
9335 | ||
9336 | if (tp->irq_cnt == 1) | |
9337 | name = tp->dev->name; | |
9338 | else { | |
9339 | name = &tnapi->irq_lbl[0]; | |
9340 | snprintf(name, IFNAMSIZ, "%s-%d", tp->dev->name, irq_num); | |
9341 | name[IFNAMSIZ-1] = 0; | |
9342 | } | |
fcfa0a32 | 9343 | |
63c3a66f | 9344 | if (tg3_flag(tp, USING_MSI) || tg3_flag(tp, USING_MSIX)) { |
fcfa0a32 | 9345 | fn = tg3_msi; |
63c3a66f | 9346 | if (tg3_flag(tp, 1SHOT_MSI)) |
fcfa0a32 | 9347 | fn = tg3_msi_1shot; |
ab392d2d | 9348 | flags = 0; |
fcfa0a32 MC |
9349 | } else { |
9350 | fn = tg3_interrupt; | |
63c3a66f | 9351 | if (tg3_flag(tp, TAGGED_STATUS)) |
fcfa0a32 | 9352 | fn = tg3_interrupt_tagged; |
ab392d2d | 9353 | flags = IRQF_SHARED; |
fcfa0a32 | 9354 | } |
4f125f42 MC |
9355 | |
9356 | return request_irq(tnapi->irq_vec, fn, flags, name, tnapi); | |
fcfa0a32 MC |
9357 | } |
9358 | ||
7938109f MC |
9359 | static int tg3_test_interrupt(struct tg3 *tp) |
9360 | { | |
09943a18 | 9361 | struct tg3_napi *tnapi = &tp->napi[0]; |
7938109f | 9362 | struct net_device *dev = tp->dev; |
b16250e3 | 9363 | int err, i, intr_ok = 0; |
f6eb9b1f | 9364 | u32 val; |
7938109f | 9365 | |
d4bc3927 MC |
9366 | if (!netif_running(dev)) |
9367 | return -ENODEV; | |
9368 | ||
7938109f MC |
9369 | tg3_disable_ints(tp); |
9370 | ||
4f125f42 | 9371 | free_irq(tnapi->irq_vec, tnapi); |
7938109f | 9372 | |
f6eb9b1f MC |
9373 | /* |
9374 | * Turn off MSI one shot mode. Otherwise this test has no | |
9375 | * observable way to know whether the interrupt was delivered. | |
9376 | */ | |
3aa1cdf8 | 9377 | if (tg3_flag(tp, 57765_PLUS)) { |
f6eb9b1f MC |
9378 | val = tr32(MSGINT_MODE) | MSGINT_MODE_ONE_SHOT_DISABLE; |
9379 | tw32(MSGINT_MODE, val); | |
9380 | } | |
9381 | ||
4f125f42 | 9382 | err = request_irq(tnapi->irq_vec, tg3_test_isr, |
09943a18 | 9383 | IRQF_SHARED | IRQF_SAMPLE_RANDOM, dev->name, tnapi); |
7938109f MC |
9384 | if (err) |
9385 | return err; | |
9386 | ||
898a56f8 | 9387 | tnapi->hw_status->status &= ~SD_STATUS_UPDATED; |
7938109f MC |
9388 | tg3_enable_ints(tp); |
9389 | ||
9390 | tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE | | |
fd2ce37f | 9391 | tnapi->coal_now); |
7938109f MC |
9392 | |
9393 | for (i = 0; i < 5; i++) { | |
b16250e3 MC |
9394 | u32 int_mbox, misc_host_ctrl; |
9395 | ||
898a56f8 | 9396 | int_mbox = tr32_mailbox(tnapi->int_mbox); |
b16250e3 MC |
9397 | misc_host_ctrl = tr32(TG3PCI_MISC_HOST_CTRL); |
9398 | ||
9399 | if ((int_mbox != 0) || | |
9400 | (misc_host_ctrl & MISC_HOST_CTRL_MASK_PCI_INT)) { | |
9401 | intr_ok = 1; | |
7938109f | 9402 | break; |
b16250e3 MC |
9403 | } |
9404 | ||
3aa1cdf8 MC |
9405 | if (tg3_flag(tp, 57765_PLUS) && |
9406 | tnapi->hw_status->status_tag != tnapi->last_tag) | |
9407 | tw32_mailbox_f(tnapi->int_mbox, tnapi->last_tag << 24); | |
9408 | ||
7938109f MC |
9409 | msleep(10); |
9410 | } | |
9411 | ||
9412 | tg3_disable_ints(tp); | |
9413 | ||
4f125f42 | 9414 | free_irq(tnapi->irq_vec, tnapi); |
6aa20a22 | 9415 | |
4f125f42 | 9416 | err = tg3_request_irq(tp, 0); |
7938109f MC |
9417 | |
9418 | if (err) | |
9419 | return err; | |
9420 | ||
f6eb9b1f MC |
9421 | if (intr_ok) { |
9422 | /* Reenable MSI one shot mode. */ | |
5b39de91 | 9423 | if (tg3_flag(tp, 57765_PLUS) && tg3_flag(tp, 1SHOT_MSI)) { |
f6eb9b1f MC |
9424 | val = tr32(MSGINT_MODE) & ~MSGINT_MODE_ONE_SHOT_DISABLE; |
9425 | tw32(MSGINT_MODE, val); | |
9426 | } | |
7938109f | 9427 | return 0; |
f6eb9b1f | 9428 | } |
7938109f MC |
9429 | |
9430 | return -EIO; | |
9431 | } | |
9432 | ||
9433 | /* Returns 0 if MSI test succeeds or MSI test fails and INTx mode is | |
9434 | * successfully restored | |
9435 | */ | |
9436 | static int tg3_test_msi(struct tg3 *tp) | |
9437 | { | |
7938109f MC |
9438 | int err; |
9439 | u16 pci_cmd; | |
9440 | ||
63c3a66f | 9441 | if (!tg3_flag(tp, USING_MSI)) |
7938109f MC |
9442 | return 0; |
9443 | ||
9444 | /* Turn off SERR reporting in case MSI terminates with Master | |
9445 | * Abort. | |
9446 | */ | |
9447 | pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd); | |
9448 | pci_write_config_word(tp->pdev, PCI_COMMAND, | |
9449 | pci_cmd & ~PCI_COMMAND_SERR); | |
9450 | ||
9451 | err = tg3_test_interrupt(tp); | |
9452 | ||
9453 | pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd); | |
9454 | ||
9455 | if (!err) | |
9456 | return 0; | |
9457 | ||
9458 | /* other failures */ | |
9459 | if (err != -EIO) | |
9460 | return err; | |
9461 | ||
9462 | /* MSI test failed, go back to INTx mode */ | |
5129c3a3 MC |
9463 | netdev_warn(tp->dev, "No interrupt was generated using MSI. Switching " |
9464 | "to INTx mode. Please report this failure to the PCI " | |
9465 | "maintainer and include system chipset information\n"); | |
7938109f | 9466 | |
4f125f42 | 9467 | free_irq(tp->napi[0].irq_vec, &tp->napi[0]); |
09943a18 | 9468 | |
7938109f MC |
9469 | pci_disable_msi(tp->pdev); |
9470 | ||
63c3a66f | 9471 | tg3_flag_clear(tp, USING_MSI); |
dc8bf1b1 | 9472 | tp->napi[0].irq_vec = tp->pdev->irq; |
7938109f | 9473 | |
4f125f42 | 9474 | err = tg3_request_irq(tp, 0); |
7938109f MC |
9475 | if (err) |
9476 | return err; | |
9477 | ||
9478 | /* Need to reset the chip because the MSI cycle may have terminated | |
9479 | * with Master Abort. | |
9480 | */ | |
f47c11ee | 9481 | tg3_full_lock(tp, 1); |
7938109f | 9482 | |
944d980e | 9483 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
8e7a22e3 | 9484 | err = tg3_init_hw(tp, 1); |
7938109f | 9485 | |
f47c11ee | 9486 | tg3_full_unlock(tp); |
7938109f MC |
9487 | |
9488 | if (err) | |
4f125f42 | 9489 | free_irq(tp->napi[0].irq_vec, &tp->napi[0]); |
7938109f MC |
9490 | |
9491 | return err; | |
9492 | } | |
9493 | ||
9e9fd12d MC |
9494 | static int tg3_request_firmware(struct tg3 *tp) |
9495 | { | |
9496 | const __be32 *fw_data; | |
9497 | ||
9498 | if (request_firmware(&tp->fw, tp->fw_needed, &tp->pdev->dev)) { | |
05dbe005 JP |
9499 | netdev_err(tp->dev, "Failed to load firmware \"%s\"\n", |
9500 | tp->fw_needed); | |
9e9fd12d MC |
9501 | return -ENOENT; |
9502 | } | |
9503 | ||
9504 | fw_data = (void *)tp->fw->data; | |
9505 | ||
9506 | /* Firmware blob starts with version numbers, followed by | |
9507 | * start address and _full_ length including BSS sections | |
9508 | * (which must be longer than the actual data, of course | |
9509 | */ | |
9510 | ||
9511 | tp->fw_len = be32_to_cpu(fw_data[2]); /* includes bss */ | |
9512 | if (tp->fw_len < (tp->fw->size - 12)) { | |
05dbe005 JP |
9513 | netdev_err(tp->dev, "bogus length %d in \"%s\"\n", |
9514 | tp->fw_len, tp->fw_needed); | |
9e9fd12d MC |
9515 | release_firmware(tp->fw); |
9516 | tp->fw = NULL; | |
9517 | return -EINVAL; | |
9518 | } | |
9519 | ||
9520 | /* We no longer need firmware; we have it. */ | |
9521 | tp->fw_needed = NULL; | |
9522 | return 0; | |
9523 | } | |
9524 | ||
679563f4 MC |
9525 | static bool tg3_enable_msix(struct tg3 *tp) |
9526 | { | |
9527 | int i, rc, cpus = num_online_cpus(); | |
9528 | struct msix_entry msix_ent[tp->irq_max]; | |
9529 | ||
9530 | if (cpus == 1) | |
9531 | /* Just fallback to the simpler MSI mode. */ | |
9532 | return false; | |
9533 | ||
9534 | /* | |
9535 | * We want as many rx rings enabled as there are cpus. | |
9536 | * The first MSIX vector only deals with link interrupts, etc, | |
9537 | * so we add one to the number of vectors we are requesting. | |
9538 | */ | |
9539 | tp->irq_cnt = min_t(unsigned, cpus + 1, tp->irq_max); | |
9540 | ||
9541 | for (i = 0; i < tp->irq_max; i++) { | |
9542 | msix_ent[i].entry = i; | |
9543 | msix_ent[i].vector = 0; | |
9544 | } | |
9545 | ||
9546 | rc = pci_enable_msix(tp->pdev, msix_ent, tp->irq_cnt); | |
2430b031 MC |
9547 | if (rc < 0) { |
9548 | return false; | |
9549 | } else if (rc != 0) { | |
679563f4 MC |
9550 | if (pci_enable_msix(tp->pdev, msix_ent, rc)) |
9551 | return false; | |
05dbe005 JP |
9552 | netdev_notice(tp->dev, "Requested %d MSI-X vectors, received %d\n", |
9553 | tp->irq_cnt, rc); | |
679563f4 MC |
9554 | tp->irq_cnt = rc; |
9555 | } | |
9556 | ||
9557 | for (i = 0; i < tp->irq_max; i++) | |
9558 | tp->napi[i].irq_vec = msix_ent[i].vector; | |
9559 | ||
2ddaad39 BH |
9560 | netif_set_real_num_tx_queues(tp->dev, 1); |
9561 | rc = tp->irq_cnt > 1 ? tp->irq_cnt - 1 : 1; | |
9562 | if (netif_set_real_num_rx_queues(tp->dev, rc)) { | |
9563 | pci_disable_msix(tp->pdev); | |
9564 | return false; | |
9565 | } | |
b92b9040 MC |
9566 | |
9567 | if (tp->irq_cnt > 1) { | |
63c3a66f | 9568 | tg3_flag_set(tp, ENABLE_RSS); |
d78b59f5 MC |
9569 | |
9570 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719 || | |
9571 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) { | |
63c3a66f | 9572 | tg3_flag_set(tp, ENABLE_TSS); |
b92b9040 MC |
9573 | netif_set_real_num_tx_queues(tp->dev, tp->irq_cnt - 1); |
9574 | } | |
9575 | } | |
2430b031 | 9576 | |
679563f4 MC |
9577 | return true; |
9578 | } | |
9579 | ||
07b0173c MC |
9580 | static void tg3_ints_init(struct tg3 *tp) |
9581 | { | |
63c3a66f JP |
9582 | if ((tg3_flag(tp, SUPPORT_MSI) || tg3_flag(tp, SUPPORT_MSIX)) && |
9583 | !tg3_flag(tp, TAGGED_STATUS)) { | |
07b0173c MC |
9584 | /* All MSI supporting chips should support tagged |
9585 | * status. Assert that this is the case. | |
9586 | */ | |
5129c3a3 MC |
9587 | netdev_warn(tp->dev, |
9588 | "MSI without TAGGED_STATUS? Not using MSI\n"); | |
679563f4 | 9589 | goto defcfg; |
07b0173c | 9590 | } |
4f125f42 | 9591 | |
63c3a66f JP |
9592 | if (tg3_flag(tp, SUPPORT_MSIX) && tg3_enable_msix(tp)) |
9593 | tg3_flag_set(tp, USING_MSIX); | |
9594 | else if (tg3_flag(tp, SUPPORT_MSI) && pci_enable_msi(tp->pdev) == 0) | |
9595 | tg3_flag_set(tp, USING_MSI); | |
679563f4 | 9596 | |
63c3a66f | 9597 | if (tg3_flag(tp, USING_MSI) || tg3_flag(tp, USING_MSIX)) { |
679563f4 | 9598 | u32 msi_mode = tr32(MSGINT_MODE); |
63c3a66f | 9599 | if (tg3_flag(tp, USING_MSIX) && tp->irq_cnt > 1) |
baf8a94a | 9600 | msi_mode |= MSGINT_MODE_MULTIVEC_EN; |
5b39de91 MC |
9601 | if (!tg3_flag(tp, 1SHOT_MSI)) |
9602 | msi_mode |= MSGINT_MODE_ONE_SHOT_DISABLE; | |
679563f4 MC |
9603 | tw32(MSGINT_MODE, msi_mode | MSGINT_MODE_ENABLE); |
9604 | } | |
9605 | defcfg: | |
63c3a66f | 9606 | if (!tg3_flag(tp, USING_MSIX)) { |
679563f4 MC |
9607 | tp->irq_cnt = 1; |
9608 | tp->napi[0].irq_vec = tp->pdev->irq; | |
2ddaad39 | 9609 | netif_set_real_num_tx_queues(tp->dev, 1); |
85407885 | 9610 | netif_set_real_num_rx_queues(tp->dev, 1); |
679563f4 | 9611 | } |
07b0173c MC |
9612 | } |
9613 | ||
9614 | static void tg3_ints_fini(struct tg3 *tp) | |
9615 | { | |
63c3a66f | 9616 | if (tg3_flag(tp, USING_MSIX)) |
679563f4 | 9617 | pci_disable_msix(tp->pdev); |
63c3a66f | 9618 | else if (tg3_flag(tp, USING_MSI)) |
679563f4 | 9619 | pci_disable_msi(tp->pdev); |
63c3a66f JP |
9620 | tg3_flag_clear(tp, USING_MSI); |
9621 | tg3_flag_clear(tp, USING_MSIX); | |
9622 | tg3_flag_clear(tp, ENABLE_RSS); | |
9623 | tg3_flag_clear(tp, ENABLE_TSS); | |
07b0173c MC |
9624 | } |
9625 | ||
1da177e4 LT |
9626 | static int tg3_open(struct net_device *dev) |
9627 | { | |
9628 | struct tg3 *tp = netdev_priv(dev); | |
4f125f42 | 9629 | int i, err; |
1da177e4 | 9630 | |
9e9fd12d MC |
9631 | if (tp->fw_needed) { |
9632 | err = tg3_request_firmware(tp); | |
9633 | if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0) { | |
9634 | if (err) | |
9635 | return err; | |
9636 | } else if (err) { | |
05dbe005 | 9637 | netdev_warn(tp->dev, "TSO capability disabled\n"); |
63c3a66f JP |
9638 | tg3_flag_clear(tp, TSO_CAPABLE); |
9639 | } else if (!tg3_flag(tp, TSO_CAPABLE)) { | |
05dbe005 | 9640 | netdev_notice(tp->dev, "TSO capability restored\n"); |
63c3a66f | 9641 | tg3_flag_set(tp, TSO_CAPABLE); |
9e9fd12d MC |
9642 | } |
9643 | } | |
9644 | ||
c49a1561 MC |
9645 | netif_carrier_off(tp->dev); |
9646 | ||
c866b7ea | 9647 | err = tg3_power_up(tp); |
2f751b67 | 9648 | if (err) |
bc1c7567 | 9649 | return err; |
2f751b67 MC |
9650 | |
9651 | tg3_full_lock(tp, 0); | |
bc1c7567 | 9652 | |
1da177e4 | 9653 | tg3_disable_ints(tp); |
63c3a66f | 9654 | tg3_flag_clear(tp, INIT_COMPLETE); |
1da177e4 | 9655 | |
f47c11ee | 9656 | tg3_full_unlock(tp); |
1da177e4 | 9657 | |
679563f4 MC |
9658 | /* |
9659 | * Setup interrupts first so we know how | |
9660 | * many NAPI resources to allocate | |
9661 | */ | |
9662 | tg3_ints_init(tp); | |
9663 | ||
1da177e4 LT |
9664 | /* The placement of this call is tied |
9665 | * to the setup and use of Host TX descriptors. | |
9666 | */ | |
9667 | err = tg3_alloc_consistent(tp); | |
9668 | if (err) | |
679563f4 | 9669 | goto err_out1; |
88b06bc2 | 9670 | |
66cfd1bd MC |
9671 | tg3_napi_init(tp); |
9672 | ||
fed97810 | 9673 | tg3_napi_enable(tp); |
1da177e4 | 9674 | |
4f125f42 MC |
9675 | for (i = 0; i < tp->irq_cnt; i++) { |
9676 | struct tg3_napi *tnapi = &tp->napi[i]; | |
9677 | err = tg3_request_irq(tp, i); | |
9678 | if (err) { | |
9679 | for (i--; i >= 0; i--) | |
9680 | free_irq(tnapi->irq_vec, tnapi); | |
9681 | break; | |
9682 | } | |
9683 | } | |
1da177e4 | 9684 | |
07b0173c | 9685 | if (err) |
679563f4 | 9686 | goto err_out2; |
bea3348e | 9687 | |
f47c11ee | 9688 | tg3_full_lock(tp, 0); |
1da177e4 | 9689 | |
8e7a22e3 | 9690 | err = tg3_init_hw(tp, 1); |
1da177e4 | 9691 | if (err) { |
944d980e | 9692 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
1da177e4 LT |
9693 | tg3_free_rings(tp); |
9694 | } else { | |
0e6cf6a9 MC |
9695 | if (tg3_flag(tp, TAGGED_STATUS) && |
9696 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5717 && | |
9697 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_57765) | |
fac9b83e DM |
9698 | tp->timer_offset = HZ; |
9699 | else | |
9700 | tp->timer_offset = HZ / 10; | |
9701 | ||
9702 | BUG_ON(tp->timer_offset > HZ); | |
9703 | tp->timer_counter = tp->timer_multiplier = | |
9704 | (HZ / tp->timer_offset); | |
9705 | tp->asf_counter = tp->asf_multiplier = | |
28fbef78 | 9706 | ((HZ / tp->timer_offset) * 2); |
1da177e4 LT |
9707 | |
9708 | init_timer(&tp->timer); | |
9709 | tp->timer.expires = jiffies + tp->timer_offset; | |
9710 | tp->timer.data = (unsigned long) tp; | |
9711 | tp->timer.function = tg3_timer; | |
1da177e4 LT |
9712 | } |
9713 | ||
f47c11ee | 9714 | tg3_full_unlock(tp); |
1da177e4 | 9715 | |
07b0173c | 9716 | if (err) |
679563f4 | 9717 | goto err_out3; |
1da177e4 | 9718 | |
63c3a66f | 9719 | if (tg3_flag(tp, USING_MSI)) { |
7938109f | 9720 | err = tg3_test_msi(tp); |
fac9b83e | 9721 | |
7938109f | 9722 | if (err) { |
f47c11ee | 9723 | tg3_full_lock(tp, 0); |
944d980e | 9724 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
7938109f | 9725 | tg3_free_rings(tp); |
f47c11ee | 9726 | tg3_full_unlock(tp); |
7938109f | 9727 | |
679563f4 | 9728 | goto err_out2; |
7938109f | 9729 | } |
fcfa0a32 | 9730 | |
63c3a66f | 9731 | if (!tg3_flag(tp, 57765_PLUS) && tg3_flag(tp, USING_MSI)) { |
f6eb9b1f | 9732 | u32 val = tr32(PCIE_TRANSACTION_CFG); |
fcfa0a32 | 9733 | |
f6eb9b1f MC |
9734 | tw32(PCIE_TRANSACTION_CFG, |
9735 | val | PCIE_TRANS_CFG_1SHOT_MSI); | |
fcfa0a32 | 9736 | } |
7938109f MC |
9737 | } |
9738 | ||
b02fd9e3 MC |
9739 | tg3_phy_start(tp); |
9740 | ||
f47c11ee | 9741 | tg3_full_lock(tp, 0); |
1da177e4 | 9742 | |
7938109f | 9743 | add_timer(&tp->timer); |
63c3a66f | 9744 | tg3_flag_set(tp, INIT_COMPLETE); |
1da177e4 LT |
9745 | tg3_enable_ints(tp); |
9746 | ||
f47c11ee | 9747 | tg3_full_unlock(tp); |
1da177e4 | 9748 | |
fe5f5787 | 9749 | netif_tx_start_all_queues(dev); |
1da177e4 | 9750 | |
06c03c02 MB |
9751 | /* |
9752 | * Reset loopback feature if it was turned on while the device was down | |
9753 | * make sure that it's installed properly now. | |
9754 | */ | |
9755 | if (dev->features & NETIF_F_LOOPBACK) | |
9756 | tg3_set_loopback(dev, dev->features); | |
9757 | ||
1da177e4 | 9758 | return 0; |
07b0173c | 9759 | |
679563f4 | 9760 | err_out3: |
4f125f42 MC |
9761 | for (i = tp->irq_cnt - 1; i >= 0; i--) { |
9762 | struct tg3_napi *tnapi = &tp->napi[i]; | |
9763 | free_irq(tnapi->irq_vec, tnapi); | |
9764 | } | |
07b0173c | 9765 | |
679563f4 | 9766 | err_out2: |
fed97810 | 9767 | tg3_napi_disable(tp); |
66cfd1bd | 9768 | tg3_napi_fini(tp); |
07b0173c | 9769 | tg3_free_consistent(tp); |
679563f4 MC |
9770 | |
9771 | err_out1: | |
9772 | tg3_ints_fini(tp); | |
cd0d7228 MC |
9773 | tg3_frob_aux_power(tp, false); |
9774 | pci_set_power_state(tp->pdev, PCI_D3hot); | |
07b0173c | 9775 | return err; |
1da177e4 LT |
9776 | } |
9777 | ||
511d2224 ED |
9778 | static struct rtnl_link_stats64 *tg3_get_stats64(struct net_device *, |
9779 | struct rtnl_link_stats64 *); | |
1da177e4 LT |
9780 | static struct tg3_ethtool_stats *tg3_get_estats(struct tg3 *); |
9781 | ||
9782 | static int tg3_close(struct net_device *dev) | |
9783 | { | |
4f125f42 | 9784 | int i; |
1da177e4 LT |
9785 | struct tg3 *tp = netdev_priv(dev); |
9786 | ||
fed97810 | 9787 | tg3_napi_disable(tp); |
28e53bdd | 9788 | cancel_work_sync(&tp->reset_task); |
7faa006f | 9789 | |
fe5f5787 | 9790 | netif_tx_stop_all_queues(dev); |
1da177e4 LT |
9791 | |
9792 | del_timer_sync(&tp->timer); | |
9793 | ||
24bb4fb6 MC |
9794 | tg3_phy_stop(tp); |
9795 | ||
f47c11ee | 9796 | tg3_full_lock(tp, 1); |
1da177e4 LT |
9797 | |
9798 | tg3_disable_ints(tp); | |
9799 | ||
944d980e | 9800 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
1da177e4 | 9801 | tg3_free_rings(tp); |
63c3a66f | 9802 | tg3_flag_clear(tp, INIT_COMPLETE); |
1da177e4 | 9803 | |
f47c11ee | 9804 | tg3_full_unlock(tp); |
1da177e4 | 9805 | |
4f125f42 MC |
9806 | for (i = tp->irq_cnt - 1; i >= 0; i--) { |
9807 | struct tg3_napi *tnapi = &tp->napi[i]; | |
9808 | free_irq(tnapi->irq_vec, tnapi); | |
9809 | } | |
07b0173c MC |
9810 | |
9811 | tg3_ints_fini(tp); | |
1da177e4 | 9812 | |
511d2224 ED |
9813 | tg3_get_stats64(tp->dev, &tp->net_stats_prev); |
9814 | ||
1da177e4 LT |
9815 | memcpy(&tp->estats_prev, tg3_get_estats(tp), |
9816 | sizeof(tp->estats_prev)); | |
9817 | ||
66cfd1bd MC |
9818 | tg3_napi_fini(tp); |
9819 | ||
1da177e4 LT |
9820 | tg3_free_consistent(tp); |
9821 | ||
c866b7ea | 9822 | tg3_power_down(tp); |
bc1c7567 MC |
9823 | |
9824 | netif_carrier_off(tp->dev); | |
9825 | ||
1da177e4 LT |
9826 | return 0; |
9827 | } | |
9828 | ||
511d2224 | 9829 | static inline u64 get_stat64(tg3_stat64_t *val) |
816f8b86 SB |
9830 | { |
9831 | return ((u64)val->high << 32) | ((u64)val->low); | |
9832 | } | |
9833 | ||
511d2224 | 9834 | static u64 calc_crc_errors(struct tg3 *tp) |
1da177e4 LT |
9835 | { |
9836 | struct tg3_hw_stats *hw_stats = tp->hw_stats; | |
9837 | ||
f07e9af3 | 9838 | if (!(tp->phy_flags & TG3_PHYFLG_PHY_SERDES) && |
1da177e4 LT |
9839 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
9840 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701)) { | |
1da177e4 LT |
9841 | u32 val; |
9842 | ||
f47c11ee | 9843 | spin_lock_bh(&tp->lock); |
569a5df8 MC |
9844 | if (!tg3_readphy(tp, MII_TG3_TEST1, &val)) { |
9845 | tg3_writephy(tp, MII_TG3_TEST1, | |
9846 | val | MII_TG3_TEST1_CRC_EN); | |
f08aa1a8 | 9847 | tg3_readphy(tp, MII_TG3_RXR_COUNTERS, &val); |
1da177e4 LT |
9848 | } else |
9849 | val = 0; | |
f47c11ee | 9850 | spin_unlock_bh(&tp->lock); |
1da177e4 LT |
9851 | |
9852 | tp->phy_crc_errors += val; | |
9853 | ||
9854 | return tp->phy_crc_errors; | |
9855 | } | |
9856 | ||
9857 | return get_stat64(&hw_stats->rx_fcs_errors); | |
9858 | } | |
9859 | ||
9860 | #define ESTAT_ADD(member) \ | |
9861 | estats->member = old_estats->member + \ | |
511d2224 | 9862 | get_stat64(&hw_stats->member) |
1da177e4 LT |
9863 | |
9864 | static struct tg3_ethtool_stats *tg3_get_estats(struct tg3 *tp) | |
9865 | { | |
9866 | struct tg3_ethtool_stats *estats = &tp->estats; | |
9867 | struct tg3_ethtool_stats *old_estats = &tp->estats_prev; | |
9868 | struct tg3_hw_stats *hw_stats = tp->hw_stats; | |
9869 | ||
9870 | if (!hw_stats) | |
9871 | return old_estats; | |
9872 | ||
9873 | ESTAT_ADD(rx_octets); | |
9874 | ESTAT_ADD(rx_fragments); | |
9875 | ESTAT_ADD(rx_ucast_packets); | |
9876 | ESTAT_ADD(rx_mcast_packets); | |
9877 | ESTAT_ADD(rx_bcast_packets); | |
9878 | ESTAT_ADD(rx_fcs_errors); | |
9879 | ESTAT_ADD(rx_align_errors); | |
9880 | ESTAT_ADD(rx_xon_pause_rcvd); | |
9881 | ESTAT_ADD(rx_xoff_pause_rcvd); | |
9882 | ESTAT_ADD(rx_mac_ctrl_rcvd); | |
9883 | ESTAT_ADD(rx_xoff_entered); | |
9884 | ESTAT_ADD(rx_frame_too_long_errors); | |
9885 | ESTAT_ADD(rx_jabbers); | |
9886 | ESTAT_ADD(rx_undersize_packets); | |
9887 | ESTAT_ADD(rx_in_length_errors); | |
9888 | ESTAT_ADD(rx_out_length_errors); | |
9889 | ESTAT_ADD(rx_64_or_less_octet_packets); | |
9890 | ESTAT_ADD(rx_65_to_127_octet_packets); | |
9891 | ESTAT_ADD(rx_128_to_255_octet_packets); | |
9892 | ESTAT_ADD(rx_256_to_511_octet_packets); | |
9893 | ESTAT_ADD(rx_512_to_1023_octet_packets); | |
9894 | ESTAT_ADD(rx_1024_to_1522_octet_packets); | |
9895 | ESTAT_ADD(rx_1523_to_2047_octet_packets); | |
9896 | ESTAT_ADD(rx_2048_to_4095_octet_packets); | |
9897 | ESTAT_ADD(rx_4096_to_8191_octet_packets); | |
9898 | ESTAT_ADD(rx_8192_to_9022_octet_packets); | |
9899 | ||
9900 | ESTAT_ADD(tx_octets); | |
9901 | ESTAT_ADD(tx_collisions); | |
9902 | ESTAT_ADD(tx_xon_sent); | |
9903 | ESTAT_ADD(tx_xoff_sent); | |
9904 | ESTAT_ADD(tx_flow_control); | |
9905 | ESTAT_ADD(tx_mac_errors); | |
9906 | ESTAT_ADD(tx_single_collisions); | |
9907 | ESTAT_ADD(tx_mult_collisions); | |
9908 | ESTAT_ADD(tx_deferred); | |
9909 | ESTAT_ADD(tx_excessive_collisions); | |
9910 | ESTAT_ADD(tx_late_collisions); | |
9911 | ESTAT_ADD(tx_collide_2times); | |
9912 | ESTAT_ADD(tx_collide_3times); | |
9913 | ESTAT_ADD(tx_collide_4times); | |
9914 | ESTAT_ADD(tx_collide_5times); | |
9915 | ESTAT_ADD(tx_collide_6times); | |
9916 | ESTAT_ADD(tx_collide_7times); | |
9917 | ESTAT_ADD(tx_collide_8times); | |
9918 | ESTAT_ADD(tx_collide_9times); | |
9919 | ESTAT_ADD(tx_collide_10times); | |
9920 | ESTAT_ADD(tx_collide_11times); | |
9921 | ESTAT_ADD(tx_collide_12times); | |
9922 | ESTAT_ADD(tx_collide_13times); | |
9923 | ESTAT_ADD(tx_collide_14times); | |
9924 | ESTAT_ADD(tx_collide_15times); | |
9925 | ESTAT_ADD(tx_ucast_packets); | |
9926 | ESTAT_ADD(tx_mcast_packets); | |
9927 | ESTAT_ADD(tx_bcast_packets); | |
9928 | ESTAT_ADD(tx_carrier_sense_errors); | |
9929 | ESTAT_ADD(tx_discards); | |
9930 | ESTAT_ADD(tx_errors); | |
9931 | ||
9932 | ESTAT_ADD(dma_writeq_full); | |
9933 | ESTAT_ADD(dma_write_prioq_full); | |
9934 | ESTAT_ADD(rxbds_empty); | |
9935 | ESTAT_ADD(rx_discards); | |
9936 | ESTAT_ADD(rx_errors); | |
9937 | ESTAT_ADD(rx_threshold_hit); | |
9938 | ||
9939 | ESTAT_ADD(dma_readq_full); | |
9940 | ESTAT_ADD(dma_read_prioq_full); | |
9941 | ESTAT_ADD(tx_comp_queue_full); | |
9942 | ||
9943 | ESTAT_ADD(ring_set_send_prod_index); | |
9944 | ESTAT_ADD(ring_status_update); | |
9945 | ESTAT_ADD(nic_irqs); | |
9946 | ESTAT_ADD(nic_avoided_irqs); | |
9947 | ESTAT_ADD(nic_tx_threshold_hit); | |
9948 | ||
4452d099 MC |
9949 | ESTAT_ADD(mbuf_lwm_thresh_hit); |
9950 | ||
1da177e4 LT |
9951 | return estats; |
9952 | } | |
9953 | ||
511d2224 ED |
9954 | static struct rtnl_link_stats64 *tg3_get_stats64(struct net_device *dev, |
9955 | struct rtnl_link_stats64 *stats) | |
1da177e4 LT |
9956 | { |
9957 | struct tg3 *tp = netdev_priv(dev); | |
511d2224 | 9958 | struct rtnl_link_stats64 *old_stats = &tp->net_stats_prev; |
1da177e4 LT |
9959 | struct tg3_hw_stats *hw_stats = tp->hw_stats; |
9960 | ||
9961 | if (!hw_stats) | |
9962 | return old_stats; | |
9963 | ||
9964 | stats->rx_packets = old_stats->rx_packets + | |
9965 | get_stat64(&hw_stats->rx_ucast_packets) + | |
9966 | get_stat64(&hw_stats->rx_mcast_packets) + | |
9967 | get_stat64(&hw_stats->rx_bcast_packets); | |
6aa20a22 | 9968 | |
1da177e4 LT |
9969 | stats->tx_packets = old_stats->tx_packets + |
9970 | get_stat64(&hw_stats->tx_ucast_packets) + | |
9971 | get_stat64(&hw_stats->tx_mcast_packets) + | |
9972 | get_stat64(&hw_stats->tx_bcast_packets); | |
9973 | ||
9974 | stats->rx_bytes = old_stats->rx_bytes + | |
9975 | get_stat64(&hw_stats->rx_octets); | |
9976 | stats->tx_bytes = old_stats->tx_bytes + | |
9977 | get_stat64(&hw_stats->tx_octets); | |
9978 | ||
9979 | stats->rx_errors = old_stats->rx_errors + | |
4f63b877 | 9980 | get_stat64(&hw_stats->rx_errors); |
1da177e4 LT |
9981 | stats->tx_errors = old_stats->tx_errors + |
9982 | get_stat64(&hw_stats->tx_errors) + | |
9983 | get_stat64(&hw_stats->tx_mac_errors) + | |
9984 | get_stat64(&hw_stats->tx_carrier_sense_errors) + | |
9985 | get_stat64(&hw_stats->tx_discards); | |
9986 | ||
9987 | stats->multicast = old_stats->multicast + | |
9988 | get_stat64(&hw_stats->rx_mcast_packets); | |
9989 | stats->collisions = old_stats->collisions + | |
9990 | get_stat64(&hw_stats->tx_collisions); | |
9991 | ||
9992 | stats->rx_length_errors = old_stats->rx_length_errors + | |
9993 | get_stat64(&hw_stats->rx_frame_too_long_errors) + | |
9994 | get_stat64(&hw_stats->rx_undersize_packets); | |
9995 | ||
9996 | stats->rx_over_errors = old_stats->rx_over_errors + | |
9997 | get_stat64(&hw_stats->rxbds_empty); | |
9998 | stats->rx_frame_errors = old_stats->rx_frame_errors + | |
9999 | get_stat64(&hw_stats->rx_align_errors); | |
10000 | stats->tx_aborted_errors = old_stats->tx_aborted_errors + | |
10001 | get_stat64(&hw_stats->tx_discards); | |
10002 | stats->tx_carrier_errors = old_stats->tx_carrier_errors + | |
10003 | get_stat64(&hw_stats->tx_carrier_sense_errors); | |
10004 | ||
10005 | stats->rx_crc_errors = old_stats->rx_crc_errors + | |
10006 | calc_crc_errors(tp); | |
10007 | ||
4f63b877 JL |
10008 | stats->rx_missed_errors = old_stats->rx_missed_errors + |
10009 | get_stat64(&hw_stats->rx_discards); | |
10010 | ||
b0057c51 ED |
10011 | stats->rx_dropped = tp->rx_dropped; |
10012 | ||
1da177e4 LT |
10013 | return stats; |
10014 | } | |
10015 | ||
10016 | static inline u32 calc_crc(unsigned char *buf, int len) | |
10017 | { | |
10018 | u32 reg; | |
10019 | u32 tmp; | |
10020 | int j, k; | |
10021 | ||
10022 | reg = 0xffffffff; | |
10023 | ||
10024 | for (j = 0; j < len; j++) { | |
10025 | reg ^= buf[j]; | |
10026 | ||
10027 | for (k = 0; k < 8; k++) { | |
10028 | tmp = reg & 0x01; | |
10029 | ||
10030 | reg >>= 1; | |
10031 | ||
859a5887 | 10032 | if (tmp) |
1da177e4 | 10033 | reg ^= 0xedb88320; |
1da177e4 LT |
10034 | } |
10035 | } | |
10036 | ||
10037 | return ~reg; | |
10038 | } | |
10039 | ||
10040 | static void tg3_set_multi(struct tg3 *tp, unsigned int accept_all) | |
10041 | { | |
10042 | /* accept or reject all multicast frames */ | |
10043 | tw32(MAC_HASH_REG_0, accept_all ? 0xffffffff : 0); | |
10044 | tw32(MAC_HASH_REG_1, accept_all ? 0xffffffff : 0); | |
10045 | tw32(MAC_HASH_REG_2, accept_all ? 0xffffffff : 0); | |
10046 | tw32(MAC_HASH_REG_3, accept_all ? 0xffffffff : 0); | |
10047 | } | |
10048 | ||
10049 | static void __tg3_set_rx_mode(struct net_device *dev) | |
10050 | { | |
10051 | struct tg3 *tp = netdev_priv(dev); | |
10052 | u32 rx_mode; | |
10053 | ||
10054 | rx_mode = tp->rx_mode & ~(RX_MODE_PROMISC | | |
10055 | RX_MODE_KEEP_VLAN_TAG); | |
10056 | ||
bf933c80 | 10057 | #if !defined(CONFIG_VLAN_8021Q) && !defined(CONFIG_VLAN_8021Q_MODULE) |
1da177e4 LT |
10058 | /* When ASF is in use, we always keep the RX_MODE_KEEP_VLAN_TAG |
10059 | * flag clear. | |
10060 | */ | |
63c3a66f | 10061 | if (!tg3_flag(tp, ENABLE_ASF)) |
1da177e4 LT |
10062 | rx_mode |= RX_MODE_KEEP_VLAN_TAG; |
10063 | #endif | |
10064 | ||
10065 | if (dev->flags & IFF_PROMISC) { | |
10066 | /* Promiscuous mode. */ | |
10067 | rx_mode |= RX_MODE_PROMISC; | |
10068 | } else if (dev->flags & IFF_ALLMULTI) { | |
10069 | /* Accept all multicast. */ | |
de6f31eb | 10070 | tg3_set_multi(tp, 1); |
4cd24eaf | 10071 | } else if (netdev_mc_empty(dev)) { |
1da177e4 | 10072 | /* Reject all multicast. */ |
de6f31eb | 10073 | tg3_set_multi(tp, 0); |
1da177e4 LT |
10074 | } else { |
10075 | /* Accept one or more multicast(s). */ | |
22bedad3 | 10076 | struct netdev_hw_addr *ha; |
1da177e4 LT |
10077 | u32 mc_filter[4] = { 0, }; |
10078 | u32 regidx; | |
10079 | u32 bit; | |
10080 | u32 crc; | |
10081 | ||
22bedad3 JP |
10082 | netdev_for_each_mc_addr(ha, dev) { |
10083 | crc = calc_crc(ha->addr, ETH_ALEN); | |
1da177e4 LT |
10084 | bit = ~crc & 0x7f; |
10085 | regidx = (bit & 0x60) >> 5; | |
10086 | bit &= 0x1f; | |
10087 | mc_filter[regidx] |= (1 << bit); | |
10088 | } | |
10089 | ||
10090 | tw32(MAC_HASH_REG_0, mc_filter[0]); | |
10091 | tw32(MAC_HASH_REG_1, mc_filter[1]); | |
10092 | tw32(MAC_HASH_REG_2, mc_filter[2]); | |
10093 | tw32(MAC_HASH_REG_3, mc_filter[3]); | |
10094 | } | |
10095 | ||
10096 | if (rx_mode != tp->rx_mode) { | |
10097 | tp->rx_mode = rx_mode; | |
10098 | tw32_f(MAC_RX_MODE, rx_mode); | |
10099 | udelay(10); | |
10100 | } | |
10101 | } | |
10102 | ||
10103 | static void tg3_set_rx_mode(struct net_device *dev) | |
10104 | { | |
10105 | struct tg3 *tp = netdev_priv(dev); | |
10106 | ||
e75f7c90 MC |
10107 | if (!netif_running(dev)) |
10108 | return; | |
10109 | ||
f47c11ee | 10110 | tg3_full_lock(tp, 0); |
1da177e4 | 10111 | __tg3_set_rx_mode(dev); |
f47c11ee | 10112 | tg3_full_unlock(tp); |
1da177e4 LT |
10113 | } |
10114 | ||
1da177e4 LT |
10115 | static int tg3_get_regs_len(struct net_device *dev) |
10116 | { | |
97bd8e49 | 10117 | return TG3_REG_BLK_SIZE; |
1da177e4 LT |
10118 | } |
10119 | ||
10120 | static void tg3_get_regs(struct net_device *dev, | |
10121 | struct ethtool_regs *regs, void *_p) | |
10122 | { | |
1da177e4 | 10123 | struct tg3 *tp = netdev_priv(dev); |
1da177e4 LT |
10124 | |
10125 | regs->version = 0; | |
10126 | ||
97bd8e49 | 10127 | memset(_p, 0, TG3_REG_BLK_SIZE); |
1da177e4 | 10128 | |
80096068 | 10129 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) |
bc1c7567 MC |
10130 | return; |
10131 | ||
f47c11ee | 10132 | tg3_full_lock(tp, 0); |
1da177e4 | 10133 | |
97bd8e49 | 10134 | tg3_dump_legacy_regs(tp, (u32 *)_p); |
1da177e4 | 10135 | |
f47c11ee | 10136 | tg3_full_unlock(tp); |
1da177e4 LT |
10137 | } |
10138 | ||
10139 | static int tg3_get_eeprom_len(struct net_device *dev) | |
10140 | { | |
10141 | struct tg3 *tp = netdev_priv(dev); | |
10142 | ||
10143 | return tp->nvram_size; | |
10144 | } | |
10145 | ||
1da177e4 LT |
10146 | static int tg3_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, u8 *data) |
10147 | { | |
10148 | struct tg3 *tp = netdev_priv(dev); | |
10149 | int ret; | |
10150 | u8 *pd; | |
b9fc7dc5 | 10151 | u32 i, offset, len, b_offset, b_count; |
a9dc529d | 10152 | __be32 val; |
1da177e4 | 10153 | |
63c3a66f | 10154 | if (tg3_flag(tp, NO_NVRAM)) |
df259d8c MC |
10155 | return -EINVAL; |
10156 | ||
80096068 | 10157 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) |
bc1c7567 MC |
10158 | return -EAGAIN; |
10159 | ||
1da177e4 LT |
10160 | offset = eeprom->offset; |
10161 | len = eeprom->len; | |
10162 | eeprom->len = 0; | |
10163 | ||
10164 | eeprom->magic = TG3_EEPROM_MAGIC; | |
10165 | ||
10166 | if (offset & 3) { | |
10167 | /* adjustments to start on required 4 byte boundary */ | |
10168 | b_offset = offset & 3; | |
10169 | b_count = 4 - b_offset; | |
10170 | if (b_count > len) { | |
10171 | /* i.e. offset=1 len=2 */ | |
10172 | b_count = len; | |
10173 | } | |
a9dc529d | 10174 | ret = tg3_nvram_read_be32(tp, offset-b_offset, &val); |
1da177e4 LT |
10175 | if (ret) |
10176 | return ret; | |
be98da6a | 10177 | memcpy(data, ((char *)&val) + b_offset, b_count); |
1da177e4 LT |
10178 | len -= b_count; |
10179 | offset += b_count; | |
c6cdf436 | 10180 | eeprom->len += b_count; |
1da177e4 LT |
10181 | } |
10182 | ||
25985edc | 10183 | /* read bytes up to the last 4 byte boundary */ |
1da177e4 LT |
10184 | pd = &data[eeprom->len]; |
10185 | for (i = 0; i < (len - (len & 3)); i += 4) { | |
a9dc529d | 10186 | ret = tg3_nvram_read_be32(tp, offset + i, &val); |
1da177e4 LT |
10187 | if (ret) { |
10188 | eeprom->len += i; | |
10189 | return ret; | |
10190 | } | |
1da177e4 LT |
10191 | memcpy(pd + i, &val, 4); |
10192 | } | |
10193 | eeprom->len += i; | |
10194 | ||
10195 | if (len & 3) { | |
10196 | /* read last bytes not ending on 4 byte boundary */ | |
10197 | pd = &data[eeprom->len]; | |
10198 | b_count = len & 3; | |
10199 | b_offset = offset + len - b_count; | |
a9dc529d | 10200 | ret = tg3_nvram_read_be32(tp, b_offset, &val); |
1da177e4 LT |
10201 | if (ret) |
10202 | return ret; | |
b9fc7dc5 | 10203 | memcpy(pd, &val, b_count); |
1da177e4 LT |
10204 | eeprom->len += b_count; |
10205 | } | |
10206 | return 0; | |
10207 | } | |
10208 | ||
6aa20a22 | 10209 | static int tg3_nvram_write_block(struct tg3 *tp, u32 offset, u32 len, u8 *buf); |
1da177e4 LT |
10210 | |
10211 | static int tg3_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, u8 *data) | |
10212 | { | |
10213 | struct tg3 *tp = netdev_priv(dev); | |
10214 | int ret; | |
b9fc7dc5 | 10215 | u32 offset, len, b_offset, odd_len; |
1da177e4 | 10216 | u8 *buf; |
a9dc529d | 10217 | __be32 start, end; |
1da177e4 | 10218 | |
80096068 | 10219 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) |
bc1c7567 MC |
10220 | return -EAGAIN; |
10221 | ||
63c3a66f | 10222 | if (tg3_flag(tp, NO_NVRAM) || |
df259d8c | 10223 | eeprom->magic != TG3_EEPROM_MAGIC) |
1da177e4 LT |
10224 | return -EINVAL; |
10225 | ||
10226 | offset = eeprom->offset; | |
10227 | len = eeprom->len; | |
10228 | ||
10229 | if ((b_offset = (offset & 3))) { | |
10230 | /* adjustments to start on required 4 byte boundary */ | |
a9dc529d | 10231 | ret = tg3_nvram_read_be32(tp, offset-b_offset, &start); |
1da177e4 LT |
10232 | if (ret) |
10233 | return ret; | |
1da177e4 LT |
10234 | len += b_offset; |
10235 | offset &= ~3; | |
1c8594b4 MC |
10236 | if (len < 4) |
10237 | len = 4; | |
1da177e4 LT |
10238 | } |
10239 | ||
10240 | odd_len = 0; | |
1c8594b4 | 10241 | if (len & 3) { |
1da177e4 LT |
10242 | /* adjustments to end on required 4 byte boundary */ |
10243 | odd_len = 1; | |
10244 | len = (len + 3) & ~3; | |
a9dc529d | 10245 | ret = tg3_nvram_read_be32(tp, offset+len-4, &end); |
1da177e4 LT |
10246 | if (ret) |
10247 | return ret; | |
1da177e4 LT |
10248 | } |
10249 | ||
10250 | buf = data; | |
10251 | if (b_offset || odd_len) { | |
10252 | buf = kmalloc(len, GFP_KERNEL); | |
ab0049b4 | 10253 | if (!buf) |
1da177e4 LT |
10254 | return -ENOMEM; |
10255 | if (b_offset) | |
10256 | memcpy(buf, &start, 4); | |
10257 | if (odd_len) | |
10258 | memcpy(buf+len-4, &end, 4); | |
10259 | memcpy(buf + b_offset, data, eeprom->len); | |
10260 | } | |
10261 | ||
10262 | ret = tg3_nvram_write_block(tp, offset, len, buf); | |
10263 | ||
10264 | if (buf != data) | |
10265 | kfree(buf); | |
10266 | ||
10267 | return ret; | |
10268 | } | |
10269 | ||
10270 | static int tg3_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) | |
10271 | { | |
b02fd9e3 MC |
10272 | struct tg3 *tp = netdev_priv(dev); |
10273 | ||
63c3a66f | 10274 | if (tg3_flag(tp, USE_PHYLIB)) { |
3f0e3ad7 | 10275 | struct phy_device *phydev; |
f07e9af3 | 10276 | if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) |
b02fd9e3 | 10277 | return -EAGAIN; |
3f0e3ad7 MC |
10278 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
10279 | return phy_ethtool_gset(phydev, cmd); | |
b02fd9e3 | 10280 | } |
6aa20a22 | 10281 | |
1da177e4 LT |
10282 | cmd->supported = (SUPPORTED_Autoneg); |
10283 | ||
f07e9af3 | 10284 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) |
1da177e4 LT |
10285 | cmd->supported |= (SUPPORTED_1000baseT_Half | |
10286 | SUPPORTED_1000baseT_Full); | |
10287 | ||
f07e9af3 | 10288 | if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) { |
1da177e4 LT |
10289 | cmd->supported |= (SUPPORTED_100baseT_Half | |
10290 | SUPPORTED_100baseT_Full | | |
10291 | SUPPORTED_10baseT_Half | | |
10292 | SUPPORTED_10baseT_Full | | |
3bebab59 | 10293 | SUPPORTED_TP); |
ef348144 KK |
10294 | cmd->port = PORT_TP; |
10295 | } else { | |
1da177e4 | 10296 | cmd->supported |= SUPPORTED_FIBRE; |
ef348144 KK |
10297 | cmd->port = PORT_FIBRE; |
10298 | } | |
6aa20a22 | 10299 | |
1da177e4 | 10300 | cmd->advertising = tp->link_config.advertising; |
5bb09778 MC |
10301 | if (tg3_flag(tp, PAUSE_AUTONEG)) { |
10302 | if (tp->link_config.flowctrl & FLOW_CTRL_RX) { | |
10303 | if (tp->link_config.flowctrl & FLOW_CTRL_TX) { | |
10304 | cmd->advertising |= ADVERTISED_Pause; | |
10305 | } else { | |
10306 | cmd->advertising |= ADVERTISED_Pause | | |
10307 | ADVERTISED_Asym_Pause; | |
10308 | } | |
10309 | } else if (tp->link_config.flowctrl & FLOW_CTRL_TX) { | |
10310 | cmd->advertising |= ADVERTISED_Asym_Pause; | |
10311 | } | |
10312 | } | |
1da177e4 | 10313 | if (netif_running(dev)) { |
70739497 | 10314 | ethtool_cmd_speed_set(cmd, tp->link_config.active_speed); |
1da177e4 | 10315 | cmd->duplex = tp->link_config.active_duplex; |
64c22182 | 10316 | } else { |
70739497 | 10317 | ethtool_cmd_speed_set(cmd, SPEED_INVALID); |
64c22182 | 10318 | cmd->duplex = DUPLEX_INVALID; |
1da177e4 | 10319 | } |
882e9793 | 10320 | cmd->phy_address = tp->phy_addr; |
7e5856bd | 10321 | cmd->transceiver = XCVR_INTERNAL; |
1da177e4 LT |
10322 | cmd->autoneg = tp->link_config.autoneg; |
10323 | cmd->maxtxpkt = 0; | |
10324 | cmd->maxrxpkt = 0; | |
10325 | return 0; | |
10326 | } | |
6aa20a22 | 10327 | |
1da177e4 LT |
10328 | static int tg3_set_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
10329 | { | |
10330 | struct tg3 *tp = netdev_priv(dev); | |
25db0338 | 10331 | u32 speed = ethtool_cmd_speed(cmd); |
6aa20a22 | 10332 | |
63c3a66f | 10333 | if (tg3_flag(tp, USE_PHYLIB)) { |
3f0e3ad7 | 10334 | struct phy_device *phydev; |
f07e9af3 | 10335 | if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) |
b02fd9e3 | 10336 | return -EAGAIN; |
3f0e3ad7 MC |
10337 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
10338 | return phy_ethtool_sset(phydev, cmd); | |
b02fd9e3 MC |
10339 | } |
10340 | ||
7e5856bd MC |
10341 | if (cmd->autoneg != AUTONEG_ENABLE && |
10342 | cmd->autoneg != AUTONEG_DISABLE) | |
37ff238d | 10343 | return -EINVAL; |
7e5856bd MC |
10344 | |
10345 | if (cmd->autoneg == AUTONEG_DISABLE && | |
10346 | cmd->duplex != DUPLEX_FULL && | |
10347 | cmd->duplex != DUPLEX_HALF) | |
37ff238d | 10348 | return -EINVAL; |
1da177e4 | 10349 | |
7e5856bd MC |
10350 | if (cmd->autoneg == AUTONEG_ENABLE) { |
10351 | u32 mask = ADVERTISED_Autoneg | | |
10352 | ADVERTISED_Pause | | |
10353 | ADVERTISED_Asym_Pause; | |
10354 | ||
f07e9af3 | 10355 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) |
7e5856bd MC |
10356 | mask |= ADVERTISED_1000baseT_Half | |
10357 | ADVERTISED_1000baseT_Full; | |
10358 | ||
f07e9af3 | 10359 | if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) |
7e5856bd MC |
10360 | mask |= ADVERTISED_100baseT_Half | |
10361 | ADVERTISED_100baseT_Full | | |
10362 | ADVERTISED_10baseT_Half | | |
10363 | ADVERTISED_10baseT_Full | | |
10364 | ADVERTISED_TP; | |
10365 | else | |
10366 | mask |= ADVERTISED_FIBRE; | |
10367 | ||
10368 | if (cmd->advertising & ~mask) | |
10369 | return -EINVAL; | |
10370 | ||
10371 | mask &= (ADVERTISED_1000baseT_Half | | |
10372 | ADVERTISED_1000baseT_Full | | |
10373 | ADVERTISED_100baseT_Half | | |
10374 | ADVERTISED_100baseT_Full | | |
10375 | ADVERTISED_10baseT_Half | | |
10376 | ADVERTISED_10baseT_Full); | |
10377 | ||
10378 | cmd->advertising &= mask; | |
10379 | } else { | |
f07e9af3 | 10380 | if (tp->phy_flags & TG3_PHYFLG_ANY_SERDES) { |
25db0338 | 10381 | if (speed != SPEED_1000) |
7e5856bd MC |
10382 | return -EINVAL; |
10383 | ||
10384 | if (cmd->duplex != DUPLEX_FULL) | |
10385 | return -EINVAL; | |
10386 | } else { | |
25db0338 DD |
10387 | if (speed != SPEED_100 && |
10388 | speed != SPEED_10) | |
7e5856bd MC |
10389 | return -EINVAL; |
10390 | } | |
10391 | } | |
10392 | ||
f47c11ee | 10393 | tg3_full_lock(tp, 0); |
1da177e4 LT |
10394 | |
10395 | tp->link_config.autoneg = cmd->autoneg; | |
10396 | if (cmd->autoneg == AUTONEG_ENABLE) { | |
405d8e5c AG |
10397 | tp->link_config.advertising = (cmd->advertising | |
10398 | ADVERTISED_Autoneg); | |
1da177e4 LT |
10399 | tp->link_config.speed = SPEED_INVALID; |
10400 | tp->link_config.duplex = DUPLEX_INVALID; | |
10401 | } else { | |
10402 | tp->link_config.advertising = 0; | |
25db0338 | 10403 | tp->link_config.speed = speed; |
1da177e4 | 10404 | tp->link_config.duplex = cmd->duplex; |
b02fd9e3 | 10405 | } |
6aa20a22 | 10406 | |
24fcad6b MC |
10407 | tp->link_config.orig_speed = tp->link_config.speed; |
10408 | tp->link_config.orig_duplex = tp->link_config.duplex; | |
10409 | tp->link_config.orig_autoneg = tp->link_config.autoneg; | |
10410 | ||
1da177e4 LT |
10411 | if (netif_running(dev)) |
10412 | tg3_setup_phy(tp, 1); | |
10413 | ||
f47c11ee | 10414 | tg3_full_unlock(tp); |
6aa20a22 | 10415 | |
1da177e4 LT |
10416 | return 0; |
10417 | } | |
6aa20a22 | 10418 | |
1da177e4 LT |
10419 | static void tg3_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info) |
10420 | { | |
10421 | struct tg3 *tp = netdev_priv(dev); | |
6aa20a22 | 10422 | |
1da177e4 LT |
10423 | strcpy(info->driver, DRV_MODULE_NAME); |
10424 | strcpy(info->version, DRV_MODULE_VERSION); | |
c4e6575c | 10425 | strcpy(info->fw_version, tp->fw_ver); |
1da177e4 LT |
10426 | strcpy(info->bus_info, pci_name(tp->pdev)); |
10427 | } | |
6aa20a22 | 10428 | |
1da177e4 LT |
10429 | static void tg3_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
10430 | { | |
10431 | struct tg3 *tp = netdev_priv(dev); | |
6aa20a22 | 10432 | |
63c3a66f | 10433 | if (tg3_flag(tp, WOL_CAP) && device_can_wakeup(&tp->pdev->dev)) |
a85feb8c GZ |
10434 | wol->supported = WAKE_MAGIC; |
10435 | else | |
10436 | wol->supported = 0; | |
1da177e4 | 10437 | wol->wolopts = 0; |
63c3a66f | 10438 | if (tg3_flag(tp, WOL_ENABLE) && device_can_wakeup(&tp->pdev->dev)) |
1da177e4 LT |
10439 | wol->wolopts = WAKE_MAGIC; |
10440 | memset(&wol->sopass, 0, sizeof(wol->sopass)); | |
10441 | } | |
6aa20a22 | 10442 | |
1da177e4 LT |
10443 | static int tg3_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
10444 | { | |
10445 | struct tg3 *tp = netdev_priv(dev); | |
12dac075 | 10446 | struct device *dp = &tp->pdev->dev; |
6aa20a22 | 10447 | |
1da177e4 LT |
10448 | if (wol->wolopts & ~WAKE_MAGIC) |
10449 | return -EINVAL; | |
10450 | if ((wol->wolopts & WAKE_MAGIC) && | |
63c3a66f | 10451 | !(tg3_flag(tp, WOL_CAP) && device_can_wakeup(dp))) |
1da177e4 | 10452 | return -EINVAL; |
6aa20a22 | 10453 | |
f2dc0d18 RW |
10454 | device_set_wakeup_enable(dp, wol->wolopts & WAKE_MAGIC); |
10455 | ||
f47c11ee | 10456 | spin_lock_bh(&tp->lock); |
f2dc0d18 | 10457 | if (device_may_wakeup(dp)) |
63c3a66f | 10458 | tg3_flag_set(tp, WOL_ENABLE); |
f2dc0d18 | 10459 | else |
63c3a66f | 10460 | tg3_flag_clear(tp, WOL_ENABLE); |
f47c11ee | 10461 | spin_unlock_bh(&tp->lock); |
6aa20a22 | 10462 | |
1da177e4 LT |
10463 | return 0; |
10464 | } | |
6aa20a22 | 10465 | |
1da177e4 LT |
10466 | static u32 tg3_get_msglevel(struct net_device *dev) |
10467 | { | |
10468 | struct tg3 *tp = netdev_priv(dev); | |
10469 | return tp->msg_enable; | |
10470 | } | |
6aa20a22 | 10471 | |
1da177e4 LT |
10472 | static void tg3_set_msglevel(struct net_device *dev, u32 value) |
10473 | { | |
10474 | struct tg3 *tp = netdev_priv(dev); | |
10475 | tp->msg_enable = value; | |
10476 | } | |
6aa20a22 | 10477 | |
1da177e4 LT |
10478 | static int tg3_nway_reset(struct net_device *dev) |
10479 | { | |
10480 | struct tg3 *tp = netdev_priv(dev); | |
1da177e4 | 10481 | int r; |
6aa20a22 | 10482 | |
1da177e4 LT |
10483 | if (!netif_running(dev)) |
10484 | return -EAGAIN; | |
10485 | ||
f07e9af3 | 10486 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) |
c94e3941 MC |
10487 | return -EINVAL; |
10488 | ||
63c3a66f | 10489 | if (tg3_flag(tp, USE_PHYLIB)) { |
f07e9af3 | 10490 | if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) |
b02fd9e3 | 10491 | return -EAGAIN; |
3f0e3ad7 | 10492 | r = phy_start_aneg(tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]); |
b02fd9e3 MC |
10493 | } else { |
10494 | u32 bmcr; | |
10495 | ||
10496 | spin_lock_bh(&tp->lock); | |
10497 | r = -EINVAL; | |
10498 | tg3_readphy(tp, MII_BMCR, &bmcr); | |
10499 | if (!tg3_readphy(tp, MII_BMCR, &bmcr) && | |
10500 | ((bmcr & BMCR_ANENABLE) || | |
f07e9af3 | 10501 | (tp->phy_flags & TG3_PHYFLG_PARALLEL_DETECT))) { |
b02fd9e3 MC |
10502 | tg3_writephy(tp, MII_BMCR, bmcr | BMCR_ANRESTART | |
10503 | BMCR_ANENABLE); | |
10504 | r = 0; | |
10505 | } | |
10506 | spin_unlock_bh(&tp->lock); | |
1da177e4 | 10507 | } |
6aa20a22 | 10508 | |
1da177e4 LT |
10509 | return r; |
10510 | } | |
6aa20a22 | 10511 | |
1da177e4 LT |
10512 | static void tg3_get_ringparam(struct net_device *dev, struct ethtool_ringparam *ering) |
10513 | { | |
10514 | struct tg3 *tp = netdev_priv(dev); | |
6aa20a22 | 10515 | |
2c49a44d | 10516 | ering->rx_max_pending = tp->rx_std_ring_mask; |
1da177e4 | 10517 | ering->rx_mini_max_pending = 0; |
63c3a66f | 10518 | if (tg3_flag(tp, JUMBO_RING_ENABLE)) |
2c49a44d | 10519 | ering->rx_jumbo_max_pending = tp->rx_jmb_ring_mask; |
4f81c32b MC |
10520 | else |
10521 | ering->rx_jumbo_max_pending = 0; | |
10522 | ||
10523 | ering->tx_max_pending = TG3_TX_RING_SIZE - 1; | |
1da177e4 LT |
10524 | |
10525 | ering->rx_pending = tp->rx_pending; | |
10526 | ering->rx_mini_pending = 0; | |
63c3a66f | 10527 | if (tg3_flag(tp, JUMBO_RING_ENABLE)) |
4f81c32b MC |
10528 | ering->rx_jumbo_pending = tp->rx_jumbo_pending; |
10529 | else | |
10530 | ering->rx_jumbo_pending = 0; | |
10531 | ||
f3f3f27e | 10532 | ering->tx_pending = tp->napi[0].tx_pending; |
1da177e4 | 10533 | } |
6aa20a22 | 10534 | |
1da177e4 LT |
10535 | static int tg3_set_ringparam(struct net_device *dev, struct ethtool_ringparam *ering) |
10536 | { | |
10537 | struct tg3 *tp = netdev_priv(dev); | |
646c9edd | 10538 | int i, irq_sync = 0, err = 0; |
6aa20a22 | 10539 | |
2c49a44d MC |
10540 | if ((ering->rx_pending > tp->rx_std_ring_mask) || |
10541 | (ering->rx_jumbo_pending > tp->rx_jmb_ring_mask) || | |
bc3a9254 MC |
10542 | (ering->tx_pending > TG3_TX_RING_SIZE - 1) || |
10543 | (ering->tx_pending <= MAX_SKB_FRAGS) || | |
63c3a66f | 10544 | (tg3_flag(tp, TSO_BUG) && |
bc3a9254 | 10545 | (ering->tx_pending <= (MAX_SKB_FRAGS * 3)))) |
1da177e4 | 10546 | return -EINVAL; |
6aa20a22 | 10547 | |
bbe832c0 | 10548 | if (netif_running(dev)) { |
b02fd9e3 | 10549 | tg3_phy_stop(tp); |
1da177e4 | 10550 | tg3_netif_stop(tp); |
bbe832c0 MC |
10551 | irq_sync = 1; |
10552 | } | |
1da177e4 | 10553 | |
bbe832c0 | 10554 | tg3_full_lock(tp, irq_sync); |
6aa20a22 | 10555 | |
1da177e4 LT |
10556 | tp->rx_pending = ering->rx_pending; |
10557 | ||
63c3a66f | 10558 | if (tg3_flag(tp, MAX_RXPEND_64) && |
1da177e4 LT |
10559 | tp->rx_pending > 63) |
10560 | tp->rx_pending = 63; | |
10561 | tp->rx_jumbo_pending = ering->rx_jumbo_pending; | |
646c9edd | 10562 | |
6fd45cb8 | 10563 | for (i = 0; i < tp->irq_max; i++) |
646c9edd | 10564 | tp->napi[i].tx_pending = ering->tx_pending; |
1da177e4 LT |
10565 | |
10566 | if (netif_running(dev)) { | |
944d980e | 10567 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
b9ec6c1b MC |
10568 | err = tg3_restart_hw(tp, 1); |
10569 | if (!err) | |
10570 | tg3_netif_start(tp); | |
1da177e4 LT |
10571 | } |
10572 | ||
f47c11ee | 10573 | tg3_full_unlock(tp); |
6aa20a22 | 10574 | |
b02fd9e3 MC |
10575 | if (irq_sync && !err) |
10576 | tg3_phy_start(tp); | |
10577 | ||
b9ec6c1b | 10578 | return err; |
1da177e4 | 10579 | } |
6aa20a22 | 10580 | |
1da177e4 LT |
10581 | static void tg3_get_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause) |
10582 | { | |
10583 | struct tg3 *tp = netdev_priv(dev); | |
6aa20a22 | 10584 | |
63c3a66f | 10585 | epause->autoneg = !!tg3_flag(tp, PAUSE_AUTONEG); |
8d018621 | 10586 | |
e18ce346 | 10587 | if (tp->link_config.active_flowctrl & FLOW_CTRL_RX) |
8d018621 MC |
10588 | epause->rx_pause = 1; |
10589 | else | |
10590 | epause->rx_pause = 0; | |
10591 | ||
e18ce346 | 10592 | if (tp->link_config.active_flowctrl & FLOW_CTRL_TX) |
8d018621 MC |
10593 | epause->tx_pause = 1; |
10594 | else | |
10595 | epause->tx_pause = 0; | |
1da177e4 | 10596 | } |
6aa20a22 | 10597 | |
1da177e4 LT |
10598 | static int tg3_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause) |
10599 | { | |
10600 | struct tg3 *tp = netdev_priv(dev); | |
b02fd9e3 | 10601 | int err = 0; |
6aa20a22 | 10602 | |
63c3a66f | 10603 | if (tg3_flag(tp, USE_PHYLIB)) { |
2712168f MC |
10604 | u32 newadv; |
10605 | struct phy_device *phydev; | |
1da177e4 | 10606 | |
2712168f | 10607 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
f47c11ee | 10608 | |
2712168f MC |
10609 | if (!(phydev->supported & SUPPORTED_Pause) || |
10610 | (!(phydev->supported & SUPPORTED_Asym_Pause) && | |
2259dca3 | 10611 | (epause->rx_pause != epause->tx_pause))) |
2712168f | 10612 | return -EINVAL; |
1da177e4 | 10613 | |
2712168f MC |
10614 | tp->link_config.flowctrl = 0; |
10615 | if (epause->rx_pause) { | |
10616 | tp->link_config.flowctrl |= FLOW_CTRL_RX; | |
10617 | ||
10618 | if (epause->tx_pause) { | |
10619 | tp->link_config.flowctrl |= FLOW_CTRL_TX; | |
10620 | newadv = ADVERTISED_Pause; | |
b02fd9e3 | 10621 | } else |
2712168f MC |
10622 | newadv = ADVERTISED_Pause | |
10623 | ADVERTISED_Asym_Pause; | |
10624 | } else if (epause->tx_pause) { | |
10625 | tp->link_config.flowctrl |= FLOW_CTRL_TX; | |
10626 | newadv = ADVERTISED_Asym_Pause; | |
10627 | } else | |
10628 | newadv = 0; | |
10629 | ||
10630 | if (epause->autoneg) | |
63c3a66f | 10631 | tg3_flag_set(tp, PAUSE_AUTONEG); |
2712168f | 10632 | else |
63c3a66f | 10633 | tg3_flag_clear(tp, PAUSE_AUTONEG); |
2712168f | 10634 | |
f07e9af3 | 10635 | if (tp->phy_flags & TG3_PHYFLG_IS_CONNECTED) { |
2712168f MC |
10636 | u32 oldadv = phydev->advertising & |
10637 | (ADVERTISED_Pause | ADVERTISED_Asym_Pause); | |
10638 | if (oldadv != newadv) { | |
10639 | phydev->advertising &= | |
10640 | ~(ADVERTISED_Pause | | |
10641 | ADVERTISED_Asym_Pause); | |
10642 | phydev->advertising |= newadv; | |
10643 | if (phydev->autoneg) { | |
10644 | /* | |
10645 | * Always renegotiate the link to | |
10646 | * inform our link partner of our | |
10647 | * flow control settings, even if the | |
10648 | * flow control is forced. Let | |
10649 | * tg3_adjust_link() do the final | |
10650 | * flow control setup. | |
10651 | */ | |
10652 | return phy_start_aneg(phydev); | |
b02fd9e3 | 10653 | } |
b02fd9e3 | 10654 | } |
b02fd9e3 | 10655 | |
2712168f | 10656 | if (!epause->autoneg) |
b02fd9e3 | 10657 | tg3_setup_flow_control(tp, 0, 0); |
2712168f MC |
10658 | } else { |
10659 | tp->link_config.orig_advertising &= | |
10660 | ~(ADVERTISED_Pause | | |
10661 | ADVERTISED_Asym_Pause); | |
10662 | tp->link_config.orig_advertising |= newadv; | |
b02fd9e3 MC |
10663 | } |
10664 | } else { | |
10665 | int irq_sync = 0; | |
10666 | ||
10667 | if (netif_running(dev)) { | |
10668 | tg3_netif_stop(tp); | |
10669 | irq_sync = 1; | |
10670 | } | |
10671 | ||
10672 | tg3_full_lock(tp, irq_sync); | |
10673 | ||
10674 | if (epause->autoneg) | |
63c3a66f | 10675 | tg3_flag_set(tp, PAUSE_AUTONEG); |
b02fd9e3 | 10676 | else |
63c3a66f | 10677 | tg3_flag_clear(tp, PAUSE_AUTONEG); |
b02fd9e3 | 10678 | if (epause->rx_pause) |
e18ce346 | 10679 | tp->link_config.flowctrl |= FLOW_CTRL_RX; |
b02fd9e3 | 10680 | else |
e18ce346 | 10681 | tp->link_config.flowctrl &= ~FLOW_CTRL_RX; |
b02fd9e3 | 10682 | if (epause->tx_pause) |
e18ce346 | 10683 | tp->link_config.flowctrl |= FLOW_CTRL_TX; |
b02fd9e3 | 10684 | else |
e18ce346 | 10685 | tp->link_config.flowctrl &= ~FLOW_CTRL_TX; |
b02fd9e3 MC |
10686 | |
10687 | if (netif_running(dev)) { | |
10688 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); | |
10689 | err = tg3_restart_hw(tp, 1); | |
10690 | if (!err) | |
10691 | tg3_netif_start(tp); | |
10692 | } | |
10693 | ||
10694 | tg3_full_unlock(tp); | |
10695 | } | |
6aa20a22 | 10696 | |
b9ec6c1b | 10697 | return err; |
1da177e4 | 10698 | } |
6aa20a22 | 10699 | |
de6f31eb | 10700 | static int tg3_get_sset_count(struct net_device *dev, int sset) |
1da177e4 | 10701 | { |
b9f2c044 JG |
10702 | switch (sset) { |
10703 | case ETH_SS_TEST: | |
10704 | return TG3_NUM_TEST; | |
10705 | case ETH_SS_STATS: | |
10706 | return TG3_NUM_STATS; | |
10707 | default: | |
10708 | return -EOPNOTSUPP; | |
10709 | } | |
4cafd3f5 MC |
10710 | } |
10711 | ||
de6f31eb | 10712 | static void tg3_get_strings(struct net_device *dev, u32 stringset, u8 *buf) |
1da177e4 LT |
10713 | { |
10714 | switch (stringset) { | |
10715 | case ETH_SS_STATS: | |
10716 | memcpy(buf, ðtool_stats_keys, sizeof(ethtool_stats_keys)); | |
10717 | break; | |
4cafd3f5 MC |
10718 | case ETH_SS_TEST: |
10719 | memcpy(buf, ðtool_test_keys, sizeof(ethtool_test_keys)); | |
10720 | break; | |
1da177e4 LT |
10721 | default: |
10722 | WARN_ON(1); /* we need a WARN() */ | |
10723 | break; | |
10724 | } | |
10725 | } | |
10726 | ||
81b8709c | 10727 | static int tg3_set_phys_id(struct net_device *dev, |
10728 | enum ethtool_phys_id_state state) | |
4009a93d MC |
10729 | { |
10730 | struct tg3 *tp = netdev_priv(dev); | |
4009a93d MC |
10731 | |
10732 | if (!netif_running(tp->dev)) | |
10733 | return -EAGAIN; | |
10734 | ||
81b8709c | 10735 | switch (state) { |
10736 | case ETHTOOL_ID_ACTIVE: | |
fce55922 | 10737 | return 1; /* cycle on/off once per second */ |
4009a93d | 10738 | |
81b8709c | 10739 | case ETHTOOL_ID_ON: |
10740 | tw32(MAC_LED_CTRL, LED_CTRL_LNKLED_OVERRIDE | | |
10741 | LED_CTRL_1000MBPS_ON | | |
10742 | LED_CTRL_100MBPS_ON | | |
10743 | LED_CTRL_10MBPS_ON | | |
10744 | LED_CTRL_TRAFFIC_OVERRIDE | | |
10745 | LED_CTRL_TRAFFIC_BLINK | | |
10746 | LED_CTRL_TRAFFIC_LED); | |
10747 | break; | |
6aa20a22 | 10748 | |
81b8709c | 10749 | case ETHTOOL_ID_OFF: |
10750 | tw32(MAC_LED_CTRL, LED_CTRL_LNKLED_OVERRIDE | | |
10751 | LED_CTRL_TRAFFIC_OVERRIDE); | |
10752 | break; | |
4009a93d | 10753 | |
81b8709c | 10754 | case ETHTOOL_ID_INACTIVE: |
10755 | tw32(MAC_LED_CTRL, tp->led_ctrl); | |
10756 | break; | |
4009a93d | 10757 | } |
81b8709c | 10758 | |
4009a93d MC |
10759 | return 0; |
10760 | } | |
10761 | ||
de6f31eb | 10762 | static void tg3_get_ethtool_stats(struct net_device *dev, |
1da177e4 LT |
10763 | struct ethtool_stats *estats, u64 *tmp_stats) |
10764 | { | |
10765 | struct tg3 *tp = netdev_priv(dev); | |
10766 | memcpy(tmp_stats, tg3_get_estats(tp), sizeof(tp->estats)); | |
10767 | } | |
10768 | ||
535a490e | 10769 | static __be32 *tg3_vpd_readblock(struct tg3 *tp, u32 *vpdlen) |
c3e94500 MC |
10770 | { |
10771 | int i; | |
10772 | __be32 *buf; | |
10773 | u32 offset = 0, len = 0; | |
10774 | u32 magic, val; | |
10775 | ||
63c3a66f | 10776 | if (tg3_flag(tp, NO_NVRAM) || tg3_nvram_read(tp, 0, &magic)) |
c3e94500 MC |
10777 | return NULL; |
10778 | ||
10779 | if (magic == TG3_EEPROM_MAGIC) { | |
10780 | for (offset = TG3_NVM_DIR_START; | |
10781 | offset < TG3_NVM_DIR_END; | |
10782 | offset += TG3_NVM_DIRENT_SIZE) { | |
10783 | if (tg3_nvram_read(tp, offset, &val)) | |
10784 | return NULL; | |
10785 | ||
10786 | if ((val >> TG3_NVM_DIRTYPE_SHIFT) == | |
10787 | TG3_NVM_DIRTYPE_EXTVPD) | |
10788 | break; | |
10789 | } | |
10790 | ||
10791 | if (offset != TG3_NVM_DIR_END) { | |
10792 | len = (val & TG3_NVM_DIRTYPE_LENMSK) * 4; | |
10793 | if (tg3_nvram_read(tp, offset + 4, &offset)) | |
10794 | return NULL; | |
10795 | ||
10796 | offset = tg3_nvram_logical_addr(tp, offset); | |
10797 | } | |
10798 | } | |
10799 | ||
10800 | if (!offset || !len) { | |
10801 | offset = TG3_NVM_VPD_OFF; | |
10802 | len = TG3_NVM_VPD_LEN; | |
10803 | } | |
10804 | ||
10805 | buf = kmalloc(len, GFP_KERNEL); | |
10806 | if (buf == NULL) | |
10807 | return NULL; | |
10808 | ||
10809 | if (magic == TG3_EEPROM_MAGIC) { | |
10810 | for (i = 0; i < len; i += 4) { | |
10811 | /* The data is in little-endian format in NVRAM. | |
10812 | * Use the big-endian read routines to preserve | |
10813 | * the byte order as it exists in NVRAM. | |
10814 | */ | |
10815 | if (tg3_nvram_read_be32(tp, offset + i, &buf[i/4])) | |
10816 | goto error; | |
10817 | } | |
10818 | } else { | |
10819 | u8 *ptr; | |
10820 | ssize_t cnt; | |
10821 | unsigned int pos = 0; | |
10822 | ||
10823 | ptr = (u8 *)&buf[0]; | |
10824 | for (i = 0; pos < len && i < 3; i++, pos += cnt, ptr += cnt) { | |
10825 | cnt = pci_read_vpd(tp->pdev, pos, | |
10826 | len - pos, ptr); | |
10827 | if (cnt == -ETIMEDOUT || cnt == -EINTR) | |
10828 | cnt = 0; | |
10829 | else if (cnt < 0) | |
10830 | goto error; | |
10831 | } | |
10832 | if (pos != len) | |
10833 | goto error; | |
10834 | } | |
10835 | ||
535a490e MC |
10836 | *vpdlen = len; |
10837 | ||
c3e94500 MC |
10838 | return buf; |
10839 | ||
10840 | error: | |
10841 | kfree(buf); | |
10842 | return NULL; | |
10843 | } | |
10844 | ||
566f86ad | 10845 | #define NVRAM_TEST_SIZE 0x100 |
a5767dec MC |
10846 | #define NVRAM_SELFBOOT_FORMAT1_0_SIZE 0x14 |
10847 | #define NVRAM_SELFBOOT_FORMAT1_2_SIZE 0x18 | |
10848 | #define NVRAM_SELFBOOT_FORMAT1_3_SIZE 0x1c | |
727a6d9f MC |
10849 | #define NVRAM_SELFBOOT_FORMAT1_4_SIZE 0x20 |
10850 | #define NVRAM_SELFBOOT_FORMAT1_5_SIZE 0x24 | |
bda18faf | 10851 | #define NVRAM_SELFBOOT_FORMAT1_6_SIZE 0x50 |
b16250e3 MC |
10852 | #define NVRAM_SELFBOOT_HW_SIZE 0x20 |
10853 | #define NVRAM_SELFBOOT_DATA_SIZE 0x1c | |
566f86ad MC |
10854 | |
10855 | static int tg3_test_nvram(struct tg3 *tp) | |
10856 | { | |
535a490e | 10857 | u32 csum, magic, len; |
a9dc529d | 10858 | __be32 *buf; |
ab0049b4 | 10859 | int i, j, k, err = 0, size; |
566f86ad | 10860 | |
63c3a66f | 10861 | if (tg3_flag(tp, NO_NVRAM)) |
df259d8c MC |
10862 | return 0; |
10863 | ||
e4f34110 | 10864 | if (tg3_nvram_read(tp, 0, &magic) != 0) |
1b27777a MC |
10865 | return -EIO; |
10866 | ||
1b27777a MC |
10867 | if (magic == TG3_EEPROM_MAGIC) |
10868 | size = NVRAM_TEST_SIZE; | |
b16250e3 | 10869 | else if ((magic & TG3_EEPROM_MAGIC_FW_MSK) == TG3_EEPROM_MAGIC_FW) { |
a5767dec MC |
10870 | if ((magic & TG3_EEPROM_SB_FORMAT_MASK) == |
10871 | TG3_EEPROM_SB_FORMAT_1) { | |
10872 | switch (magic & TG3_EEPROM_SB_REVISION_MASK) { | |
10873 | case TG3_EEPROM_SB_REVISION_0: | |
10874 | size = NVRAM_SELFBOOT_FORMAT1_0_SIZE; | |
10875 | break; | |
10876 | case TG3_EEPROM_SB_REVISION_2: | |
10877 | size = NVRAM_SELFBOOT_FORMAT1_2_SIZE; | |
10878 | break; | |
10879 | case TG3_EEPROM_SB_REVISION_3: | |
10880 | size = NVRAM_SELFBOOT_FORMAT1_3_SIZE; | |
10881 | break; | |
727a6d9f MC |
10882 | case TG3_EEPROM_SB_REVISION_4: |
10883 | size = NVRAM_SELFBOOT_FORMAT1_4_SIZE; | |
10884 | break; | |
10885 | case TG3_EEPROM_SB_REVISION_5: | |
10886 | size = NVRAM_SELFBOOT_FORMAT1_5_SIZE; | |
10887 | break; | |
10888 | case TG3_EEPROM_SB_REVISION_6: | |
10889 | size = NVRAM_SELFBOOT_FORMAT1_6_SIZE; | |
10890 | break; | |
a5767dec | 10891 | default: |
727a6d9f | 10892 | return -EIO; |
a5767dec MC |
10893 | } |
10894 | } else | |
1b27777a | 10895 | return 0; |
b16250e3 MC |
10896 | } else if ((magic & TG3_EEPROM_MAGIC_HW_MSK) == TG3_EEPROM_MAGIC_HW) |
10897 | size = NVRAM_SELFBOOT_HW_SIZE; | |
10898 | else | |
1b27777a MC |
10899 | return -EIO; |
10900 | ||
10901 | buf = kmalloc(size, GFP_KERNEL); | |
566f86ad MC |
10902 | if (buf == NULL) |
10903 | return -ENOMEM; | |
10904 | ||
1b27777a MC |
10905 | err = -EIO; |
10906 | for (i = 0, j = 0; i < size; i += 4, j++) { | |
a9dc529d MC |
10907 | err = tg3_nvram_read_be32(tp, i, &buf[j]); |
10908 | if (err) | |
566f86ad | 10909 | break; |
566f86ad | 10910 | } |
1b27777a | 10911 | if (i < size) |
566f86ad MC |
10912 | goto out; |
10913 | ||
1b27777a | 10914 | /* Selfboot format */ |
a9dc529d | 10915 | magic = be32_to_cpu(buf[0]); |
b9fc7dc5 | 10916 | if ((magic & TG3_EEPROM_MAGIC_FW_MSK) == |
b16250e3 | 10917 | TG3_EEPROM_MAGIC_FW) { |
1b27777a MC |
10918 | u8 *buf8 = (u8 *) buf, csum8 = 0; |
10919 | ||
b9fc7dc5 | 10920 | if ((magic & TG3_EEPROM_SB_REVISION_MASK) == |
a5767dec MC |
10921 | TG3_EEPROM_SB_REVISION_2) { |
10922 | /* For rev 2, the csum doesn't include the MBA. */ | |
10923 | for (i = 0; i < TG3_EEPROM_SB_F1R2_MBA_OFF; i++) | |
10924 | csum8 += buf8[i]; | |
10925 | for (i = TG3_EEPROM_SB_F1R2_MBA_OFF + 4; i < size; i++) | |
10926 | csum8 += buf8[i]; | |
10927 | } else { | |
10928 | for (i = 0; i < size; i++) | |
10929 | csum8 += buf8[i]; | |
10930 | } | |
1b27777a | 10931 | |
ad96b485 AB |
10932 | if (csum8 == 0) { |
10933 | err = 0; | |
10934 | goto out; | |
10935 | } | |
10936 | ||
10937 | err = -EIO; | |
10938 | goto out; | |
1b27777a | 10939 | } |
566f86ad | 10940 | |
b9fc7dc5 | 10941 | if ((magic & TG3_EEPROM_MAGIC_HW_MSK) == |
b16250e3 MC |
10942 | TG3_EEPROM_MAGIC_HW) { |
10943 | u8 data[NVRAM_SELFBOOT_DATA_SIZE]; | |
a9dc529d | 10944 | u8 parity[NVRAM_SELFBOOT_DATA_SIZE]; |
b16250e3 | 10945 | u8 *buf8 = (u8 *) buf; |
b16250e3 MC |
10946 | |
10947 | /* Separate the parity bits and the data bytes. */ | |
10948 | for (i = 0, j = 0, k = 0; i < NVRAM_SELFBOOT_HW_SIZE; i++) { | |
10949 | if ((i == 0) || (i == 8)) { | |
10950 | int l; | |
10951 | u8 msk; | |
10952 | ||
10953 | for (l = 0, msk = 0x80; l < 7; l++, msk >>= 1) | |
10954 | parity[k++] = buf8[i] & msk; | |
10955 | i++; | |
859a5887 | 10956 | } else if (i == 16) { |
b16250e3 MC |
10957 | int l; |
10958 | u8 msk; | |
10959 | ||
10960 | for (l = 0, msk = 0x20; l < 6; l++, msk >>= 1) | |
10961 | parity[k++] = buf8[i] & msk; | |
10962 | i++; | |
10963 | ||
10964 | for (l = 0, msk = 0x80; l < 8; l++, msk >>= 1) | |
10965 | parity[k++] = buf8[i] & msk; | |
10966 | i++; | |
10967 | } | |
10968 | data[j++] = buf8[i]; | |
10969 | } | |
10970 | ||
10971 | err = -EIO; | |
10972 | for (i = 0; i < NVRAM_SELFBOOT_DATA_SIZE; i++) { | |
10973 | u8 hw8 = hweight8(data[i]); | |
10974 | ||
10975 | if ((hw8 & 0x1) && parity[i]) | |
10976 | goto out; | |
10977 | else if (!(hw8 & 0x1) && !parity[i]) | |
10978 | goto out; | |
10979 | } | |
10980 | err = 0; | |
10981 | goto out; | |
10982 | } | |
10983 | ||
01c3a392 MC |
10984 | err = -EIO; |
10985 | ||
566f86ad MC |
10986 | /* Bootstrap checksum at offset 0x10 */ |
10987 | csum = calc_crc((unsigned char *) buf, 0x10); | |
01c3a392 | 10988 | if (csum != le32_to_cpu(buf[0x10/4])) |
566f86ad MC |
10989 | goto out; |
10990 | ||
10991 | /* Manufacturing block starts at offset 0x74, checksum at 0xfc */ | |
10992 | csum = calc_crc((unsigned char *) &buf[0x74/4], 0x88); | |
01c3a392 | 10993 | if (csum != le32_to_cpu(buf[0xfc/4])) |
a9dc529d | 10994 | goto out; |
566f86ad | 10995 | |
c3e94500 MC |
10996 | kfree(buf); |
10997 | ||
535a490e | 10998 | buf = tg3_vpd_readblock(tp, &len); |
c3e94500 MC |
10999 | if (!buf) |
11000 | return -ENOMEM; | |
d4894f3e | 11001 | |
535a490e | 11002 | i = pci_vpd_find_tag((u8 *)buf, 0, len, PCI_VPD_LRDT_RO_DATA); |
d4894f3e MC |
11003 | if (i > 0) { |
11004 | j = pci_vpd_lrdt_size(&((u8 *)buf)[i]); | |
11005 | if (j < 0) | |
11006 | goto out; | |
11007 | ||
535a490e | 11008 | if (i + PCI_VPD_LRDT_TAG_SIZE + j > len) |
d4894f3e MC |
11009 | goto out; |
11010 | ||
11011 | i += PCI_VPD_LRDT_TAG_SIZE; | |
11012 | j = pci_vpd_find_info_keyword((u8 *)buf, i, j, | |
11013 | PCI_VPD_RO_KEYWORD_CHKSUM); | |
11014 | if (j > 0) { | |
11015 | u8 csum8 = 0; | |
11016 | ||
11017 | j += PCI_VPD_INFO_FLD_HDR_SIZE; | |
11018 | ||
11019 | for (i = 0; i <= j; i++) | |
11020 | csum8 += ((u8 *)buf)[i]; | |
11021 | ||
11022 | if (csum8) | |
11023 | goto out; | |
11024 | } | |
11025 | } | |
11026 | ||
566f86ad MC |
11027 | err = 0; |
11028 | ||
11029 | out: | |
11030 | kfree(buf); | |
11031 | return err; | |
11032 | } | |
11033 | ||
ca43007a MC |
11034 | #define TG3_SERDES_TIMEOUT_SEC 2 |
11035 | #define TG3_COPPER_TIMEOUT_SEC 6 | |
11036 | ||
11037 | static int tg3_test_link(struct tg3 *tp) | |
11038 | { | |
11039 | int i, max; | |
11040 | ||
11041 | if (!netif_running(tp->dev)) | |
11042 | return -ENODEV; | |
11043 | ||
f07e9af3 | 11044 | if (tp->phy_flags & TG3_PHYFLG_ANY_SERDES) |
ca43007a MC |
11045 | max = TG3_SERDES_TIMEOUT_SEC; |
11046 | else | |
11047 | max = TG3_COPPER_TIMEOUT_SEC; | |
11048 | ||
11049 | for (i = 0; i < max; i++) { | |
11050 | if (netif_carrier_ok(tp->dev)) | |
11051 | return 0; | |
11052 | ||
11053 | if (msleep_interruptible(1000)) | |
11054 | break; | |
11055 | } | |
11056 | ||
11057 | return -EIO; | |
11058 | } | |
11059 | ||
a71116d1 | 11060 | /* Only test the commonly used registers */ |
30ca3e37 | 11061 | static int tg3_test_registers(struct tg3 *tp) |
a71116d1 | 11062 | { |
b16250e3 | 11063 | int i, is_5705, is_5750; |
a71116d1 MC |
11064 | u32 offset, read_mask, write_mask, val, save_val, read_val; |
11065 | static struct { | |
11066 | u16 offset; | |
11067 | u16 flags; | |
11068 | #define TG3_FL_5705 0x1 | |
11069 | #define TG3_FL_NOT_5705 0x2 | |
11070 | #define TG3_FL_NOT_5788 0x4 | |
b16250e3 | 11071 | #define TG3_FL_NOT_5750 0x8 |
a71116d1 MC |
11072 | u32 read_mask; |
11073 | u32 write_mask; | |
11074 | } reg_tbl[] = { | |
11075 | /* MAC Control Registers */ | |
11076 | { MAC_MODE, TG3_FL_NOT_5705, | |
11077 | 0x00000000, 0x00ef6f8c }, | |
11078 | { MAC_MODE, TG3_FL_5705, | |
11079 | 0x00000000, 0x01ef6b8c }, | |
11080 | { MAC_STATUS, TG3_FL_NOT_5705, | |
11081 | 0x03800107, 0x00000000 }, | |
11082 | { MAC_STATUS, TG3_FL_5705, | |
11083 | 0x03800100, 0x00000000 }, | |
11084 | { MAC_ADDR_0_HIGH, 0x0000, | |
11085 | 0x00000000, 0x0000ffff }, | |
11086 | { MAC_ADDR_0_LOW, 0x0000, | |
c6cdf436 | 11087 | 0x00000000, 0xffffffff }, |
a71116d1 MC |
11088 | { MAC_RX_MTU_SIZE, 0x0000, |
11089 | 0x00000000, 0x0000ffff }, | |
11090 | { MAC_TX_MODE, 0x0000, | |
11091 | 0x00000000, 0x00000070 }, | |
11092 | { MAC_TX_LENGTHS, 0x0000, | |
11093 | 0x00000000, 0x00003fff }, | |
11094 | { MAC_RX_MODE, TG3_FL_NOT_5705, | |
11095 | 0x00000000, 0x000007fc }, | |
11096 | { MAC_RX_MODE, TG3_FL_5705, | |
11097 | 0x00000000, 0x000007dc }, | |
11098 | { MAC_HASH_REG_0, 0x0000, | |
11099 | 0x00000000, 0xffffffff }, | |
11100 | { MAC_HASH_REG_1, 0x0000, | |
11101 | 0x00000000, 0xffffffff }, | |
11102 | { MAC_HASH_REG_2, 0x0000, | |
11103 | 0x00000000, 0xffffffff }, | |
11104 | { MAC_HASH_REG_3, 0x0000, | |
11105 | 0x00000000, 0xffffffff }, | |
11106 | ||
11107 | /* Receive Data and Receive BD Initiator Control Registers. */ | |
11108 | { RCVDBDI_JUMBO_BD+0, TG3_FL_NOT_5705, | |
11109 | 0x00000000, 0xffffffff }, | |
11110 | { RCVDBDI_JUMBO_BD+4, TG3_FL_NOT_5705, | |
11111 | 0x00000000, 0xffffffff }, | |
11112 | { RCVDBDI_JUMBO_BD+8, TG3_FL_NOT_5705, | |
11113 | 0x00000000, 0x00000003 }, | |
11114 | { RCVDBDI_JUMBO_BD+0xc, TG3_FL_NOT_5705, | |
11115 | 0x00000000, 0xffffffff }, | |
11116 | { RCVDBDI_STD_BD+0, 0x0000, | |
11117 | 0x00000000, 0xffffffff }, | |
11118 | { RCVDBDI_STD_BD+4, 0x0000, | |
11119 | 0x00000000, 0xffffffff }, | |
11120 | { RCVDBDI_STD_BD+8, 0x0000, | |
11121 | 0x00000000, 0xffff0002 }, | |
11122 | { RCVDBDI_STD_BD+0xc, 0x0000, | |
11123 | 0x00000000, 0xffffffff }, | |
6aa20a22 | 11124 | |
a71116d1 MC |
11125 | /* Receive BD Initiator Control Registers. */ |
11126 | { RCVBDI_STD_THRESH, TG3_FL_NOT_5705, | |
11127 | 0x00000000, 0xffffffff }, | |
11128 | { RCVBDI_STD_THRESH, TG3_FL_5705, | |
11129 | 0x00000000, 0x000003ff }, | |
11130 | { RCVBDI_JUMBO_THRESH, TG3_FL_NOT_5705, | |
11131 | 0x00000000, 0xffffffff }, | |
6aa20a22 | 11132 | |
a71116d1 MC |
11133 | /* Host Coalescing Control Registers. */ |
11134 | { HOSTCC_MODE, TG3_FL_NOT_5705, | |
11135 | 0x00000000, 0x00000004 }, | |
11136 | { HOSTCC_MODE, TG3_FL_5705, | |
11137 | 0x00000000, 0x000000f6 }, | |
11138 | { HOSTCC_RXCOL_TICKS, TG3_FL_NOT_5705, | |
11139 | 0x00000000, 0xffffffff }, | |
11140 | { HOSTCC_RXCOL_TICKS, TG3_FL_5705, | |
11141 | 0x00000000, 0x000003ff }, | |
11142 | { HOSTCC_TXCOL_TICKS, TG3_FL_NOT_5705, | |
11143 | 0x00000000, 0xffffffff }, | |
11144 | { HOSTCC_TXCOL_TICKS, TG3_FL_5705, | |
11145 | 0x00000000, 0x000003ff }, | |
11146 | { HOSTCC_RXMAX_FRAMES, TG3_FL_NOT_5705, | |
11147 | 0x00000000, 0xffffffff }, | |
11148 | { HOSTCC_RXMAX_FRAMES, TG3_FL_5705 | TG3_FL_NOT_5788, | |
11149 | 0x00000000, 0x000000ff }, | |
11150 | { HOSTCC_TXMAX_FRAMES, TG3_FL_NOT_5705, | |
11151 | 0x00000000, 0xffffffff }, | |
11152 | { HOSTCC_TXMAX_FRAMES, TG3_FL_5705 | TG3_FL_NOT_5788, | |
11153 | 0x00000000, 0x000000ff }, | |
11154 | { HOSTCC_RXCOAL_TICK_INT, TG3_FL_NOT_5705, | |
11155 | 0x00000000, 0xffffffff }, | |
11156 | { HOSTCC_TXCOAL_TICK_INT, TG3_FL_NOT_5705, | |
11157 | 0x00000000, 0xffffffff }, | |
11158 | { HOSTCC_RXCOAL_MAXF_INT, TG3_FL_NOT_5705, | |
11159 | 0x00000000, 0xffffffff }, | |
11160 | { HOSTCC_RXCOAL_MAXF_INT, TG3_FL_5705 | TG3_FL_NOT_5788, | |
11161 | 0x00000000, 0x000000ff }, | |
11162 | { HOSTCC_TXCOAL_MAXF_INT, TG3_FL_NOT_5705, | |
11163 | 0x00000000, 0xffffffff }, | |
11164 | { HOSTCC_TXCOAL_MAXF_INT, TG3_FL_5705 | TG3_FL_NOT_5788, | |
11165 | 0x00000000, 0x000000ff }, | |
11166 | { HOSTCC_STAT_COAL_TICKS, TG3_FL_NOT_5705, | |
11167 | 0x00000000, 0xffffffff }, | |
11168 | { HOSTCC_STATS_BLK_HOST_ADDR, TG3_FL_NOT_5705, | |
11169 | 0x00000000, 0xffffffff }, | |
11170 | { HOSTCC_STATS_BLK_HOST_ADDR+4, TG3_FL_NOT_5705, | |
11171 | 0x00000000, 0xffffffff }, | |
11172 | { HOSTCC_STATUS_BLK_HOST_ADDR, 0x0000, | |
11173 | 0x00000000, 0xffffffff }, | |
11174 | { HOSTCC_STATUS_BLK_HOST_ADDR+4, 0x0000, | |
11175 | 0x00000000, 0xffffffff }, | |
11176 | { HOSTCC_STATS_BLK_NIC_ADDR, 0x0000, | |
11177 | 0xffffffff, 0x00000000 }, | |
11178 | { HOSTCC_STATUS_BLK_NIC_ADDR, 0x0000, | |
11179 | 0xffffffff, 0x00000000 }, | |
11180 | ||
11181 | /* Buffer Manager Control Registers. */ | |
b16250e3 | 11182 | { BUFMGR_MB_POOL_ADDR, TG3_FL_NOT_5750, |
a71116d1 | 11183 | 0x00000000, 0x007fff80 }, |
b16250e3 | 11184 | { BUFMGR_MB_POOL_SIZE, TG3_FL_NOT_5750, |
a71116d1 MC |
11185 | 0x00000000, 0x007fffff }, |
11186 | { BUFMGR_MB_RDMA_LOW_WATER, 0x0000, | |
11187 | 0x00000000, 0x0000003f }, | |
11188 | { BUFMGR_MB_MACRX_LOW_WATER, 0x0000, | |
11189 | 0x00000000, 0x000001ff }, | |
11190 | { BUFMGR_MB_HIGH_WATER, 0x0000, | |
11191 | 0x00000000, 0x000001ff }, | |
11192 | { BUFMGR_DMA_DESC_POOL_ADDR, TG3_FL_NOT_5705, | |
11193 | 0xffffffff, 0x00000000 }, | |
11194 | { BUFMGR_DMA_DESC_POOL_SIZE, TG3_FL_NOT_5705, | |
11195 | 0xffffffff, 0x00000000 }, | |
6aa20a22 | 11196 | |
a71116d1 MC |
11197 | /* Mailbox Registers */ |
11198 | { GRCMBOX_RCVSTD_PROD_IDX+4, 0x0000, | |
11199 | 0x00000000, 0x000001ff }, | |
11200 | { GRCMBOX_RCVJUMBO_PROD_IDX+4, TG3_FL_NOT_5705, | |
11201 | 0x00000000, 0x000001ff }, | |
11202 | { GRCMBOX_RCVRET_CON_IDX_0+4, 0x0000, | |
11203 | 0x00000000, 0x000007ff }, | |
11204 | { GRCMBOX_SNDHOST_PROD_IDX_0+4, 0x0000, | |
11205 | 0x00000000, 0x000001ff }, | |
11206 | ||
11207 | { 0xffff, 0x0000, 0x00000000, 0x00000000 }, | |
11208 | }; | |
11209 | ||
b16250e3 | 11210 | is_5705 = is_5750 = 0; |
63c3a66f | 11211 | if (tg3_flag(tp, 5705_PLUS)) { |
a71116d1 | 11212 | is_5705 = 1; |
63c3a66f | 11213 | if (tg3_flag(tp, 5750_PLUS)) |
b16250e3 MC |
11214 | is_5750 = 1; |
11215 | } | |
a71116d1 MC |
11216 | |
11217 | for (i = 0; reg_tbl[i].offset != 0xffff; i++) { | |
11218 | if (is_5705 && (reg_tbl[i].flags & TG3_FL_NOT_5705)) | |
11219 | continue; | |
11220 | ||
11221 | if (!is_5705 && (reg_tbl[i].flags & TG3_FL_5705)) | |
11222 | continue; | |
11223 | ||
63c3a66f | 11224 | if (tg3_flag(tp, IS_5788) && |
a71116d1 MC |
11225 | (reg_tbl[i].flags & TG3_FL_NOT_5788)) |
11226 | continue; | |
11227 | ||
b16250e3 MC |
11228 | if (is_5750 && (reg_tbl[i].flags & TG3_FL_NOT_5750)) |
11229 | continue; | |
11230 | ||
a71116d1 MC |
11231 | offset = (u32) reg_tbl[i].offset; |
11232 | read_mask = reg_tbl[i].read_mask; | |
11233 | write_mask = reg_tbl[i].write_mask; | |
11234 | ||
11235 | /* Save the original register content */ | |
11236 | save_val = tr32(offset); | |
11237 | ||
11238 | /* Determine the read-only value. */ | |
11239 | read_val = save_val & read_mask; | |
11240 | ||
11241 | /* Write zero to the register, then make sure the read-only bits | |
11242 | * are not changed and the read/write bits are all zeros. | |
11243 | */ | |
11244 | tw32(offset, 0); | |
11245 | ||
11246 | val = tr32(offset); | |
11247 | ||
11248 | /* Test the read-only and read/write bits. */ | |
11249 | if (((val & read_mask) != read_val) || (val & write_mask)) | |
11250 | goto out; | |
11251 | ||
11252 | /* Write ones to all the bits defined by RdMask and WrMask, then | |
11253 | * make sure the read-only bits are not changed and the | |
11254 | * read/write bits are all ones. | |
11255 | */ | |
11256 | tw32(offset, read_mask | write_mask); | |
11257 | ||
11258 | val = tr32(offset); | |
11259 | ||
11260 | /* Test the read-only bits. */ | |
11261 | if ((val & read_mask) != read_val) | |
11262 | goto out; | |
11263 | ||
11264 | /* Test the read/write bits. */ | |
11265 | if ((val & write_mask) != write_mask) | |
11266 | goto out; | |
11267 | ||
11268 | tw32(offset, save_val); | |
11269 | } | |
11270 | ||
11271 | return 0; | |
11272 | ||
11273 | out: | |
9f88f29f | 11274 | if (netif_msg_hw(tp)) |
2445e461 MC |
11275 | netdev_err(tp->dev, |
11276 | "Register test failed at offset %x\n", offset); | |
a71116d1 MC |
11277 | tw32(offset, save_val); |
11278 | return -EIO; | |
11279 | } | |
11280 | ||
7942e1db MC |
11281 | static int tg3_do_mem_test(struct tg3 *tp, u32 offset, u32 len) |
11282 | { | |
f71e1309 | 11283 | static const u32 test_pattern[] = { 0x00000000, 0xffffffff, 0xaa55a55a }; |
7942e1db MC |
11284 | int i; |
11285 | u32 j; | |
11286 | ||
e9edda69 | 11287 | for (i = 0; i < ARRAY_SIZE(test_pattern); i++) { |
7942e1db MC |
11288 | for (j = 0; j < len; j += 4) { |
11289 | u32 val; | |
11290 | ||
11291 | tg3_write_mem(tp, offset + j, test_pattern[i]); | |
11292 | tg3_read_mem(tp, offset + j, &val); | |
11293 | if (val != test_pattern[i]) | |
11294 | return -EIO; | |
11295 | } | |
11296 | } | |
11297 | return 0; | |
11298 | } | |
11299 | ||
11300 | static int tg3_test_memory(struct tg3 *tp) | |
11301 | { | |
11302 | static struct mem_entry { | |
11303 | u32 offset; | |
11304 | u32 len; | |
11305 | } mem_tbl_570x[] = { | |
38690194 | 11306 | { 0x00000000, 0x00b50}, |
7942e1db MC |
11307 | { 0x00002000, 0x1c000}, |
11308 | { 0xffffffff, 0x00000} | |
11309 | }, mem_tbl_5705[] = { | |
11310 | { 0x00000100, 0x0000c}, | |
11311 | { 0x00000200, 0x00008}, | |
7942e1db MC |
11312 | { 0x00004000, 0x00800}, |
11313 | { 0x00006000, 0x01000}, | |
11314 | { 0x00008000, 0x02000}, | |
11315 | { 0x00010000, 0x0e000}, | |
11316 | { 0xffffffff, 0x00000} | |
79f4d13a MC |
11317 | }, mem_tbl_5755[] = { |
11318 | { 0x00000200, 0x00008}, | |
11319 | { 0x00004000, 0x00800}, | |
11320 | { 0x00006000, 0x00800}, | |
11321 | { 0x00008000, 0x02000}, | |
11322 | { 0x00010000, 0x0c000}, | |
11323 | { 0xffffffff, 0x00000} | |
b16250e3 MC |
11324 | }, mem_tbl_5906[] = { |
11325 | { 0x00000200, 0x00008}, | |
11326 | { 0x00004000, 0x00400}, | |
11327 | { 0x00006000, 0x00400}, | |
11328 | { 0x00008000, 0x01000}, | |
11329 | { 0x00010000, 0x01000}, | |
11330 | { 0xffffffff, 0x00000} | |
8b5a6c42 MC |
11331 | }, mem_tbl_5717[] = { |
11332 | { 0x00000200, 0x00008}, | |
11333 | { 0x00010000, 0x0a000}, | |
11334 | { 0x00020000, 0x13c00}, | |
11335 | { 0xffffffff, 0x00000} | |
11336 | }, mem_tbl_57765[] = { | |
11337 | { 0x00000200, 0x00008}, | |
11338 | { 0x00004000, 0x00800}, | |
11339 | { 0x00006000, 0x09800}, | |
11340 | { 0x00010000, 0x0a000}, | |
11341 | { 0xffffffff, 0x00000} | |
7942e1db MC |
11342 | }; |
11343 | struct mem_entry *mem_tbl; | |
11344 | int err = 0; | |
11345 | int i; | |
11346 | ||
63c3a66f | 11347 | if (tg3_flag(tp, 5717_PLUS)) |
8b5a6c42 MC |
11348 | mem_tbl = mem_tbl_5717; |
11349 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) | |
11350 | mem_tbl = mem_tbl_57765; | |
63c3a66f | 11351 | else if (tg3_flag(tp, 5755_PLUS)) |
321d32a0 MC |
11352 | mem_tbl = mem_tbl_5755; |
11353 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) | |
11354 | mem_tbl = mem_tbl_5906; | |
63c3a66f | 11355 | else if (tg3_flag(tp, 5705_PLUS)) |
321d32a0 MC |
11356 | mem_tbl = mem_tbl_5705; |
11357 | else | |
7942e1db MC |
11358 | mem_tbl = mem_tbl_570x; |
11359 | ||
11360 | for (i = 0; mem_tbl[i].offset != 0xffffffff; i++) { | |
be98da6a MC |
11361 | err = tg3_do_mem_test(tp, mem_tbl[i].offset, mem_tbl[i].len); |
11362 | if (err) | |
7942e1db MC |
11363 | break; |
11364 | } | |
6aa20a22 | 11365 | |
7942e1db MC |
11366 | return err; |
11367 | } | |
11368 | ||
bb158d69 MC |
11369 | #define TG3_TSO_MSS 500 |
11370 | ||
11371 | #define TG3_TSO_IP_HDR_LEN 20 | |
11372 | #define TG3_TSO_TCP_HDR_LEN 20 | |
11373 | #define TG3_TSO_TCP_OPT_LEN 12 | |
11374 | ||
11375 | static const u8 tg3_tso_header[] = { | |
11376 | 0x08, 0x00, | |
11377 | 0x45, 0x00, 0x00, 0x00, | |
11378 | 0x00, 0x00, 0x40, 0x00, | |
11379 | 0x40, 0x06, 0x00, 0x00, | |
11380 | 0x0a, 0x00, 0x00, 0x01, | |
11381 | 0x0a, 0x00, 0x00, 0x02, | |
11382 | 0x0d, 0x00, 0xe0, 0x00, | |
11383 | 0x00, 0x00, 0x01, 0x00, | |
11384 | 0x00, 0x00, 0x02, 0x00, | |
11385 | 0x80, 0x10, 0x10, 0x00, | |
11386 | 0x14, 0x09, 0x00, 0x00, | |
11387 | 0x01, 0x01, 0x08, 0x0a, | |
11388 | 0x11, 0x11, 0x11, 0x11, | |
11389 | 0x11, 0x11, 0x11, 0x11, | |
11390 | }; | |
9f40dead | 11391 | |
28a45957 | 11392 | static int tg3_run_loopback(struct tg3 *tp, u32 pktsz, bool tso_loopback) |
c76949a6 | 11393 | { |
5e5a7f37 | 11394 | u32 rx_start_idx, rx_idx, tx_idx, opaque_key; |
bb158d69 | 11395 | u32 base_flags = 0, mss = 0, desc_idx, coal_now, data_off, val; |
84b67b27 | 11396 | u32 budget; |
c76949a6 MC |
11397 | struct sk_buff *skb, *rx_skb; |
11398 | u8 *tx_data; | |
11399 | dma_addr_t map; | |
11400 | int num_pkts, tx_len, rx_len, i, err; | |
11401 | struct tg3_rx_buffer_desc *desc; | |
898a56f8 | 11402 | struct tg3_napi *tnapi, *rnapi; |
8fea32b9 | 11403 | struct tg3_rx_prodring_set *tpr = &tp->napi[0].prodring; |
c76949a6 | 11404 | |
c8873405 MC |
11405 | tnapi = &tp->napi[0]; |
11406 | rnapi = &tp->napi[0]; | |
0c1d0e2b | 11407 | if (tp->irq_cnt > 1) { |
63c3a66f | 11408 | if (tg3_flag(tp, ENABLE_RSS)) |
1da85aa3 | 11409 | rnapi = &tp->napi[1]; |
63c3a66f | 11410 | if (tg3_flag(tp, ENABLE_TSS)) |
c8873405 | 11411 | tnapi = &tp->napi[1]; |
0c1d0e2b | 11412 | } |
fd2ce37f | 11413 | coal_now = tnapi->coal_now | rnapi->coal_now; |
898a56f8 | 11414 | |
c76949a6 MC |
11415 | err = -EIO; |
11416 | ||
4852a861 | 11417 | tx_len = pktsz; |
a20e9c62 | 11418 | skb = netdev_alloc_skb(tp->dev, tx_len); |
a50bb7b9 JJ |
11419 | if (!skb) |
11420 | return -ENOMEM; | |
11421 | ||
c76949a6 MC |
11422 | tx_data = skb_put(skb, tx_len); |
11423 | memcpy(tx_data, tp->dev->dev_addr, 6); | |
11424 | memset(tx_data + 6, 0x0, 8); | |
11425 | ||
4852a861 | 11426 | tw32(MAC_RX_MTU_SIZE, tx_len + ETH_FCS_LEN); |
c76949a6 | 11427 | |
28a45957 | 11428 | if (tso_loopback) { |
bb158d69 MC |
11429 | struct iphdr *iph = (struct iphdr *)&tx_data[ETH_HLEN]; |
11430 | ||
11431 | u32 hdr_len = TG3_TSO_IP_HDR_LEN + TG3_TSO_TCP_HDR_LEN + | |
11432 | TG3_TSO_TCP_OPT_LEN; | |
11433 | ||
11434 | memcpy(tx_data + ETH_ALEN * 2, tg3_tso_header, | |
11435 | sizeof(tg3_tso_header)); | |
11436 | mss = TG3_TSO_MSS; | |
11437 | ||
11438 | val = tx_len - ETH_ALEN * 2 - sizeof(tg3_tso_header); | |
11439 | num_pkts = DIV_ROUND_UP(val, TG3_TSO_MSS); | |
11440 | ||
11441 | /* Set the total length field in the IP header */ | |
11442 | iph->tot_len = htons((u16)(mss + hdr_len)); | |
11443 | ||
11444 | base_flags = (TXD_FLAG_CPU_PRE_DMA | | |
11445 | TXD_FLAG_CPU_POST_DMA); | |
11446 | ||
63c3a66f JP |
11447 | if (tg3_flag(tp, HW_TSO_1) || |
11448 | tg3_flag(tp, HW_TSO_2) || | |
11449 | tg3_flag(tp, HW_TSO_3)) { | |
bb158d69 MC |
11450 | struct tcphdr *th; |
11451 | val = ETH_HLEN + TG3_TSO_IP_HDR_LEN; | |
11452 | th = (struct tcphdr *)&tx_data[val]; | |
11453 | th->check = 0; | |
11454 | } else | |
11455 | base_flags |= TXD_FLAG_TCPUDP_CSUM; | |
11456 | ||
63c3a66f | 11457 | if (tg3_flag(tp, HW_TSO_3)) { |
bb158d69 MC |
11458 | mss |= (hdr_len & 0xc) << 12; |
11459 | if (hdr_len & 0x10) | |
11460 | base_flags |= 0x00000010; | |
11461 | base_flags |= (hdr_len & 0x3e0) << 5; | |
63c3a66f | 11462 | } else if (tg3_flag(tp, HW_TSO_2)) |
bb158d69 | 11463 | mss |= hdr_len << 9; |
63c3a66f | 11464 | else if (tg3_flag(tp, HW_TSO_1) || |
bb158d69 MC |
11465 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) { |
11466 | mss |= (TG3_TSO_TCP_OPT_LEN << 9); | |
11467 | } else { | |
11468 | base_flags |= (TG3_TSO_TCP_OPT_LEN << 10); | |
11469 | } | |
11470 | ||
11471 | data_off = ETH_ALEN * 2 + sizeof(tg3_tso_header); | |
11472 | } else { | |
11473 | num_pkts = 1; | |
11474 | data_off = ETH_HLEN; | |
11475 | } | |
11476 | ||
11477 | for (i = data_off; i < tx_len; i++) | |
c76949a6 MC |
11478 | tx_data[i] = (u8) (i & 0xff); |
11479 | ||
f4188d8a AD |
11480 | map = pci_map_single(tp->pdev, skb->data, tx_len, PCI_DMA_TODEVICE); |
11481 | if (pci_dma_mapping_error(tp->pdev, map)) { | |
a21771dd MC |
11482 | dev_kfree_skb(skb); |
11483 | return -EIO; | |
11484 | } | |
c76949a6 | 11485 | |
0d681b27 MC |
11486 | val = tnapi->tx_prod; |
11487 | tnapi->tx_buffers[val].skb = skb; | |
11488 | dma_unmap_addr_set(&tnapi->tx_buffers[val], mapping, map); | |
11489 | ||
c76949a6 | 11490 | tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE | |
fd2ce37f | 11491 | rnapi->coal_now); |
c76949a6 MC |
11492 | |
11493 | udelay(10); | |
11494 | ||
898a56f8 | 11495 | rx_start_idx = rnapi->hw_status->idx[0].rx_producer; |
c76949a6 | 11496 | |
84b67b27 MC |
11497 | budget = tg3_tx_avail(tnapi); |
11498 | if (tg3_tx_frag_set(tnapi, &val, &budget, map, tx_len, | |
d1a3b737 MC |
11499 | base_flags | TXD_FLAG_END, mss, 0)) { |
11500 | tnapi->tx_buffers[val].skb = NULL; | |
11501 | dev_kfree_skb(skb); | |
11502 | return -EIO; | |
11503 | } | |
c76949a6 | 11504 | |
f3f3f27e | 11505 | tnapi->tx_prod++; |
c76949a6 | 11506 | |
f3f3f27e MC |
11507 | tw32_tx_mbox(tnapi->prodmbox, tnapi->tx_prod); |
11508 | tr32_mailbox(tnapi->prodmbox); | |
c76949a6 MC |
11509 | |
11510 | udelay(10); | |
11511 | ||
303fc921 MC |
11512 | /* 350 usec to allow enough time on some 10/100 Mbps devices. */ |
11513 | for (i = 0; i < 35; i++) { | |
c76949a6 | 11514 | tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE | |
fd2ce37f | 11515 | coal_now); |
c76949a6 MC |
11516 | |
11517 | udelay(10); | |
11518 | ||
898a56f8 MC |
11519 | tx_idx = tnapi->hw_status->idx[0].tx_consumer; |
11520 | rx_idx = rnapi->hw_status->idx[0].rx_producer; | |
f3f3f27e | 11521 | if ((tx_idx == tnapi->tx_prod) && |
c76949a6 MC |
11522 | (rx_idx == (rx_start_idx + num_pkts))) |
11523 | break; | |
11524 | } | |
11525 | ||
0d681b27 | 11526 | tg3_tx_skb_unmap(tnapi, tnapi->tx_prod - 1, 0); |
c76949a6 MC |
11527 | dev_kfree_skb(skb); |
11528 | ||
f3f3f27e | 11529 | if (tx_idx != tnapi->tx_prod) |
c76949a6 MC |
11530 | goto out; |
11531 | ||
11532 | if (rx_idx != rx_start_idx + num_pkts) | |
11533 | goto out; | |
11534 | ||
bb158d69 MC |
11535 | val = data_off; |
11536 | while (rx_idx != rx_start_idx) { | |
11537 | desc = &rnapi->rx_rcb[rx_start_idx++]; | |
11538 | desc_idx = desc->opaque & RXD_OPAQUE_INDEX_MASK; | |
11539 | opaque_key = desc->opaque & RXD_OPAQUE_RING_MASK; | |
c76949a6 | 11540 | |
bb158d69 MC |
11541 | if ((desc->err_vlan & RXD_ERR_MASK) != 0 && |
11542 | (desc->err_vlan != RXD_ERR_ODD_NIBBLE_RCVD_MII)) | |
11543 | goto out; | |
c76949a6 | 11544 | |
bb158d69 MC |
11545 | rx_len = ((desc->idx_len & RXD_LEN_MASK) >> RXD_LEN_SHIFT) |
11546 | - ETH_FCS_LEN; | |
c76949a6 | 11547 | |
28a45957 | 11548 | if (!tso_loopback) { |
bb158d69 MC |
11549 | if (rx_len != tx_len) |
11550 | goto out; | |
4852a861 | 11551 | |
bb158d69 MC |
11552 | if (pktsz <= TG3_RX_STD_DMA_SZ - ETH_FCS_LEN) { |
11553 | if (opaque_key != RXD_OPAQUE_RING_STD) | |
11554 | goto out; | |
11555 | } else { | |
11556 | if (opaque_key != RXD_OPAQUE_RING_JUMBO) | |
11557 | goto out; | |
11558 | } | |
11559 | } else if ((desc->type_flags & RXD_FLAG_TCPUDP_CSUM) && | |
11560 | (desc->ip_tcp_csum & RXD_TCPCSUM_MASK) | |
54e0a67f | 11561 | >> RXD_TCPCSUM_SHIFT != 0xffff) { |
4852a861 | 11562 | goto out; |
bb158d69 | 11563 | } |
4852a861 | 11564 | |
bb158d69 MC |
11565 | if (opaque_key == RXD_OPAQUE_RING_STD) { |
11566 | rx_skb = tpr->rx_std_buffers[desc_idx].skb; | |
11567 | map = dma_unmap_addr(&tpr->rx_std_buffers[desc_idx], | |
11568 | mapping); | |
11569 | } else if (opaque_key == RXD_OPAQUE_RING_JUMBO) { | |
11570 | rx_skb = tpr->rx_jmb_buffers[desc_idx].skb; | |
11571 | map = dma_unmap_addr(&tpr->rx_jmb_buffers[desc_idx], | |
11572 | mapping); | |
11573 | } else | |
11574 | goto out; | |
c76949a6 | 11575 | |
bb158d69 MC |
11576 | pci_dma_sync_single_for_cpu(tp->pdev, map, rx_len, |
11577 | PCI_DMA_FROMDEVICE); | |
c76949a6 | 11578 | |
bb158d69 MC |
11579 | for (i = data_off; i < rx_len; i++, val++) { |
11580 | if (*(rx_skb->data + i) != (u8) (val & 0xff)) | |
11581 | goto out; | |
11582 | } | |
c76949a6 | 11583 | } |
bb158d69 | 11584 | |
c76949a6 | 11585 | err = 0; |
6aa20a22 | 11586 | |
c76949a6 MC |
11587 | /* tg3_free_rings will unmap and free the rx_skb */ |
11588 | out: | |
11589 | return err; | |
11590 | } | |
11591 | ||
00c266b7 MC |
11592 | #define TG3_STD_LOOPBACK_FAILED 1 |
11593 | #define TG3_JMB_LOOPBACK_FAILED 2 | |
bb158d69 | 11594 | #define TG3_TSO_LOOPBACK_FAILED 4 |
28a45957 MC |
11595 | #define TG3_LOOPBACK_FAILED \ |
11596 | (TG3_STD_LOOPBACK_FAILED | \ | |
11597 | TG3_JMB_LOOPBACK_FAILED | \ | |
11598 | TG3_TSO_LOOPBACK_FAILED) | |
00c266b7 | 11599 | |
941ec90f | 11600 | static int tg3_test_loopback(struct tg3 *tp, u64 *data, bool do_extlpbk) |
9f40dead | 11601 | { |
28a45957 | 11602 | int err = -EIO; |
2215e24c | 11603 | u32 eee_cap; |
9f40dead | 11604 | |
ab789046 MC |
11605 | eee_cap = tp->phy_flags & TG3_PHYFLG_EEE_CAP; |
11606 | tp->phy_flags &= ~TG3_PHYFLG_EEE_CAP; | |
11607 | ||
28a45957 MC |
11608 | if (!netif_running(tp->dev)) { |
11609 | data[0] = TG3_LOOPBACK_FAILED; | |
11610 | data[1] = TG3_LOOPBACK_FAILED; | |
941ec90f MC |
11611 | if (do_extlpbk) |
11612 | data[2] = TG3_LOOPBACK_FAILED; | |
28a45957 MC |
11613 | goto done; |
11614 | } | |
11615 | ||
b9ec6c1b | 11616 | err = tg3_reset_hw(tp, 1); |
ab789046 | 11617 | if (err) { |
28a45957 MC |
11618 | data[0] = TG3_LOOPBACK_FAILED; |
11619 | data[1] = TG3_LOOPBACK_FAILED; | |
941ec90f MC |
11620 | if (do_extlpbk) |
11621 | data[2] = TG3_LOOPBACK_FAILED; | |
ab789046 MC |
11622 | goto done; |
11623 | } | |
9f40dead | 11624 | |
63c3a66f | 11625 | if (tg3_flag(tp, ENABLE_RSS)) { |
4a85f098 MC |
11626 | int i; |
11627 | ||
11628 | /* Reroute all rx packets to the 1st queue */ | |
11629 | for (i = MAC_RSS_INDIR_TBL_0; | |
11630 | i < MAC_RSS_INDIR_TBL_0 + TG3_RSS_INDIR_TBL_SIZE; i += 4) | |
11631 | tw32(i, 0x0); | |
11632 | } | |
11633 | ||
6e01b20b MC |
11634 | /* HW errata - mac loopback fails in some cases on 5780. |
11635 | * Normal traffic and PHY loopback are not affected by | |
11636 | * errata. Also, the MAC loopback test is deprecated for | |
11637 | * all newer ASIC revisions. | |
11638 | */ | |
11639 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5780 && | |
11640 | !tg3_flag(tp, CPMU_PRESENT)) { | |
11641 | tg3_mac_loopback(tp, true); | |
9936bcf6 | 11642 | |
28a45957 MC |
11643 | if (tg3_run_loopback(tp, ETH_FRAME_LEN, false)) |
11644 | data[0] |= TG3_STD_LOOPBACK_FAILED; | |
6e01b20b MC |
11645 | |
11646 | if (tg3_flag(tp, JUMBO_RING_ENABLE) && | |
28a45957 MC |
11647 | tg3_run_loopback(tp, 9000 + ETH_HLEN, false)) |
11648 | data[0] |= TG3_JMB_LOOPBACK_FAILED; | |
6e01b20b MC |
11649 | |
11650 | tg3_mac_loopback(tp, false); | |
11651 | } | |
4852a861 | 11652 | |
f07e9af3 | 11653 | if (!(tp->phy_flags & TG3_PHYFLG_PHY_SERDES) && |
63c3a66f | 11654 | !tg3_flag(tp, USE_PHYLIB)) { |
5e5a7f37 MC |
11655 | int i; |
11656 | ||
941ec90f | 11657 | tg3_phy_lpbk_set(tp, 0, false); |
5e5a7f37 MC |
11658 | |
11659 | /* Wait for link */ | |
11660 | for (i = 0; i < 100; i++) { | |
11661 | if (tr32(MAC_TX_STATUS) & TX_STATUS_LINK_UP) | |
11662 | break; | |
11663 | mdelay(1); | |
11664 | } | |
11665 | ||
28a45957 MC |
11666 | if (tg3_run_loopback(tp, ETH_FRAME_LEN, false)) |
11667 | data[1] |= TG3_STD_LOOPBACK_FAILED; | |
63c3a66f | 11668 | if (tg3_flag(tp, TSO_CAPABLE) && |
28a45957 MC |
11669 | tg3_run_loopback(tp, ETH_FRAME_LEN, true)) |
11670 | data[1] |= TG3_TSO_LOOPBACK_FAILED; | |
63c3a66f | 11671 | if (tg3_flag(tp, JUMBO_RING_ENABLE) && |
28a45957 MC |
11672 | tg3_run_loopback(tp, 9000 + ETH_HLEN, false)) |
11673 | data[1] |= TG3_JMB_LOOPBACK_FAILED; | |
9f40dead | 11674 | |
941ec90f MC |
11675 | if (do_extlpbk) { |
11676 | tg3_phy_lpbk_set(tp, 0, true); | |
11677 | ||
11678 | /* All link indications report up, but the hardware | |
11679 | * isn't really ready for about 20 msec. Double it | |
11680 | * to be sure. | |
11681 | */ | |
11682 | mdelay(40); | |
11683 | ||
11684 | if (tg3_run_loopback(tp, ETH_FRAME_LEN, false)) | |
11685 | data[2] |= TG3_STD_LOOPBACK_FAILED; | |
11686 | if (tg3_flag(tp, TSO_CAPABLE) && | |
11687 | tg3_run_loopback(tp, ETH_FRAME_LEN, true)) | |
11688 | data[2] |= TG3_TSO_LOOPBACK_FAILED; | |
11689 | if (tg3_flag(tp, JUMBO_RING_ENABLE) && | |
11690 | tg3_run_loopback(tp, 9000 + ETH_HLEN, false)) | |
11691 | data[2] |= TG3_JMB_LOOPBACK_FAILED; | |
11692 | } | |
11693 | ||
5e5a7f37 MC |
11694 | /* Re-enable gphy autopowerdown. */ |
11695 | if (tp->phy_flags & TG3_PHYFLG_ENABLE_APD) | |
11696 | tg3_phy_toggle_apd(tp, true); | |
11697 | } | |
6833c043 | 11698 | |
941ec90f | 11699 | err = (data[0] | data[1] | data[2]) ? -EIO : 0; |
28a45957 | 11700 | |
ab789046 MC |
11701 | done: |
11702 | tp->phy_flags |= eee_cap; | |
11703 | ||
9f40dead MC |
11704 | return err; |
11705 | } | |
11706 | ||
4cafd3f5 MC |
11707 | static void tg3_self_test(struct net_device *dev, struct ethtool_test *etest, |
11708 | u64 *data) | |
11709 | { | |
566f86ad | 11710 | struct tg3 *tp = netdev_priv(dev); |
941ec90f | 11711 | bool doextlpbk = etest->flags & ETH_TEST_FL_EXTERNAL_LB; |
566f86ad | 11712 | |
bed9829f MC |
11713 | if ((tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) && |
11714 | tg3_power_up(tp)) { | |
11715 | etest->flags |= ETH_TEST_FL_FAILED; | |
11716 | memset(data, 1, sizeof(u64) * TG3_NUM_TEST); | |
11717 | return; | |
11718 | } | |
bc1c7567 | 11719 | |
566f86ad MC |
11720 | memset(data, 0, sizeof(u64) * TG3_NUM_TEST); |
11721 | ||
11722 | if (tg3_test_nvram(tp) != 0) { | |
11723 | etest->flags |= ETH_TEST_FL_FAILED; | |
11724 | data[0] = 1; | |
11725 | } | |
941ec90f | 11726 | if (!doextlpbk && tg3_test_link(tp)) { |
ca43007a MC |
11727 | etest->flags |= ETH_TEST_FL_FAILED; |
11728 | data[1] = 1; | |
11729 | } | |
a71116d1 | 11730 | if (etest->flags & ETH_TEST_FL_OFFLINE) { |
b02fd9e3 | 11731 | int err, err2 = 0, irq_sync = 0; |
bbe832c0 MC |
11732 | |
11733 | if (netif_running(dev)) { | |
b02fd9e3 | 11734 | tg3_phy_stop(tp); |
a71116d1 | 11735 | tg3_netif_stop(tp); |
bbe832c0 MC |
11736 | irq_sync = 1; |
11737 | } | |
a71116d1 | 11738 | |
bbe832c0 | 11739 | tg3_full_lock(tp, irq_sync); |
a71116d1 MC |
11740 | |
11741 | tg3_halt(tp, RESET_KIND_SUSPEND, 1); | |
ec41c7df | 11742 | err = tg3_nvram_lock(tp); |
a71116d1 | 11743 | tg3_halt_cpu(tp, RX_CPU_BASE); |
63c3a66f | 11744 | if (!tg3_flag(tp, 5705_PLUS)) |
a71116d1 | 11745 | tg3_halt_cpu(tp, TX_CPU_BASE); |
ec41c7df MC |
11746 | if (!err) |
11747 | tg3_nvram_unlock(tp); | |
a71116d1 | 11748 | |
f07e9af3 | 11749 | if (tp->phy_flags & TG3_PHYFLG_MII_SERDES) |
d9ab5ad1 MC |
11750 | tg3_phy_reset(tp); |
11751 | ||
a71116d1 MC |
11752 | if (tg3_test_registers(tp) != 0) { |
11753 | etest->flags |= ETH_TEST_FL_FAILED; | |
11754 | data[2] = 1; | |
11755 | } | |
28a45957 | 11756 | |
7942e1db MC |
11757 | if (tg3_test_memory(tp) != 0) { |
11758 | etest->flags |= ETH_TEST_FL_FAILED; | |
11759 | data[3] = 1; | |
11760 | } | |
28a45957 | 11761 | |
941ec90f MC |
11762 | if (doextlpbk) |
11763 | etest->flags |= ETH_TEST_FL_EXTERNAL_LB_DONE; | |
11764 | ||
11765 | if (tg3_test_loopback(tp, &data[4], doextlpbk)) | |
c76949a6 | 11766 | etest->flags |= ETH_TEST_FL_FAILED; |
a71116d1 | 11767 | |
f47c11ee DM |
11768 | tg3_full_unlock(tp); |
11769 | ||
d4bc3927 MC |
11770 | if (tg3_test_interrupt(tp) != 0) { |
11771 | etest->flags |= ETH_TEST_FL_FAILED; | |
941ec90f | 11772 | data[7] = 1; |
d4bc3927 | 11773 | } |
f47c11ee DM |
11774 | |
11775 | tg3_full_lock(tp, 0); | |
d4bc3927 | 11776 | |
a71116d1 MC |
11777 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
11778 | if (netif_running(dev)) { | |
63c3a66f | 11779 | tg3_flag_set(tp, INIT_COMPLETE); |
b02fd9e3 MC |
11780 | err2 = tg3_restart_hw(tp, 1); |
11781 | if (!err2) | |
b9ec6c1b | 11782 | tg3_netif_start(tp); |
a71116d1 | 11783 | } |
f47c11ee DM |
11784 | |
11785 | tg3_full_unlock(tp); | |
b02fd9e3 MC |
11786 | |
11787 | if (irq_sync && !err2) | |
11788 | tg3_phy_start(tp); | |
a71116d1 | 11789 | } |
80096068 | 11790 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) |
c866b7ea | 11791 | tg3_power_down(tp); |
bc1c7567 | 11792 | |
4cafd3f5 MC |
11793 | } |
11794 | ||
1da177e4 LT |
11795 | static int tg3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) |
11796 | { | |
11797 | struct mii_ioctl_data *data = if_mii(ifr); | |
11798 | struct tg3 *tp = netdev_priv(dev); | |
11799 | int err; | |
11800 | ||
63c3a66f | 11801 | if (tg3_flag(tp, USE_PHYLIB)) { |
3f0e3ad7 | 11802 | struct phy_device *phydev; |
f07e9af3 | 11803 | if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) |
b02fd9e3 | 11804 | return -EAGAIN; |
3f0e3ad7 | 11805 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
28b04113 | 11806 | return phy_mii_ioctl(phydev, ifr, cmd); |
b02fd9e3 MC |
11807 | } |
11808 | ||
33f401ae | 11809 | switch (cmd) { |
1da177e4 | 11810 | case SIOCGMIIPHY: |
882e9793 | 11811 | data->phy_id = tp->phy_addr; |
1da177e4 LT |
11812 | |
11813 | /* fallthru */ | |
11814 | case SIOCGMIIREG: { | |
11815 | u32 mii_regval; | |
11816 | ||
f07e9af3 | 11817 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) |
1da177e4 LT |
11818 | break; /* We have no PHY */ |
11819 | ||
34eea5ac | 11820 | if (!netif_running(dev)) |
bc1c7567 MC |
11821 | return -EAGAIN; |
11822 | ||
f47c11ee | 11823 | spin_lock_bh(&tp->lock); |
1da177e4 | 11824 | err = tg3_readphy(tp, data->reg_num & 0x1f, &mii_regval); |
f47c11ee | 11825 | spin_unlock_bh(&tp->lock); |
1da177e4 LT |
11826 | |
11827 | data->val_out = mii_regval; | |
11828 | ||
11829 | return err; | |
11830 | } | |
11831 | ||
11832 | case SIOCSMIIREG: | |
f07e9af3 | 11833 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) |
1da177e4 LT |
11834 | break; /* We have no PHY */ |
11835 | ||
34eea5ac | 11836 | if (!netif_running(dev)) |
bc1c7567 MC |
11837 | return -EAGAIN; |
11838 | ||
f47c11ee | 11839 | spin_lock_bh(&tp->lock); |
1da177e4 | 11840 | err = tg3_writephy(tp, data->reg_num & 0x1f, data->val_in); |
f47c11ee | 11841 | spin_unlock_bh(&tp->lock); |
1da177e4 LT |
11842 | |
11843 | return err; | |
11844 | ||
11845 | default: | |
11846 | /* do nothing */ | |
11847 | break; | |
11848 | } | |
11849 | return -EOPNOTSUPP; | |
11850 | } | |
11851 | ||
15f9850d DM |
11852 | static int tg3_get_coalesce(struct net_device *dev, struct ethtool_coalesce *ec) |
11853 | { | |
11854 | struct tg3 *tp = netdev_priv(dev); | |
11855 | ||
11856 | memcpy(ec, &tp->coal, sizeof(*ec)); | |
11857 | return 0; | |
11858 | } | |
11859 | ||
d244c892 MC |
11860 | static int tg3_set_coalesce(struct net_device *dev, struct ethtool_coalesce *ec) |
11861 | { | |
11862 | struct tg3 *tp = netdev_priv(dev); | |
11863 | u32 max_rxcoal_tick_int = 0, max_txcoal_tick_int = 0; | |
11864 | u32 max_stat_coal_ticks = 0, min_stat_coal_ticks = 0; | |
11865 | ||
63c3a66f | 11866 | if (!tg3_flag(tp, 5705_PLUS)) { |
d244c892 MC |
11867 | max_rxcoal_tick_int = MAX_RXCOAL_TICK_INT; |
11868 | max_txcoal_tick_int = MAX_TXCOAL_TICK_INT; | |
11869 | max_stat_coal_ticks = MAX_STAT_COAL_TICKS; | |
11870 | min_stat_coal_ticks = MIN_STAT_COAL_TICKS; | |
11871 | } | |
11872 | ||
11873 | if ((ec->rx_coalesce_usecs > MAX_RXCOL_TICKS) || | |
11874 | (ec->tx_coalesce_usecs > MAX_TXCOL_TICKS) || | |
11875 | (ec->rx_max_coalesced_frames > MAX_RXMAX_FRAMES) || | |
11876 | (ec->tx_max_coalesced_frames > MAX_TXMAX_FRAMES) || | |
11877 | (ec->rx_coalesce_usecs_irq > max_rxcoal_tick_int) || | |
11878 | (ec->tx_coalesce_usecs_irq > max_txcoal_tick_int) || | |
11879 | (ec->rx_max_coalesced_frames_irq > MAX_RXCOAL_MAXF_INT) || | |
11880 | (ec->tx_max_coalesced_frames_irq > MAX_TXCOAL_MAXF_INT) || | |
11881 | (ec->stats_block_coalesce_usecs > max_stat_coal_ticks) || | |
11882 | (ec->stats_block_coalesce_usecs < min_stat_coal_ticks)) | |
11883 | return -EINVAL; | |
11884 | ||
11885 | /* No rx interrupts will be generated if both are zero */ | |
11886 | if ((ec->rx_coalesce_usecs == 0) && | |
11887 | (ec->rx_max_coalesced_frames == 0)) | |
11888 | return -EINVAL; | |
11889 | ||
11890 | /* No tx interrupts will be generated if both are zero */ | |
11891 | if ((ec->tx_coalesce_usecs == 0) && | |
11892 | (ec->tx_max_coalesced_frames == 0)) | |
11893 | return -EINVAL; | |
11894 | ||
11895 | /* Only copy relevant parameters, ignore all others. */ | |
11896 | tp->coal.rx_coalesce_usecs = ec->rx_coalesce_usecs; | |
11897 | tp->coal.tx_coalesce_usecs = ec->tx_coalesce_usecs; | |
11898 | tp->coal.rx_max_coalesced_frames = ec->rx_max_coalesced_frames; | |
11899 | tp->coal.tx_max_coalesced_frames = ec->tx_max_coalesced_frames; | |
11900 | tp->coal.rx_coalesce_usecs_irq = ec->rx_coalesce_usecs_irq; | |
11901 | tp->coal.tx_coalesce_usecs_irq = ec->tx_coalesce_usecs_irq; | |
11902 | tp->coal.rx_max_coalesced_frames_irq = ec->rx_max_coalesced_frames_irq; | |
11903 | tp->coal.tx_max_coalesced_frames_irq = ec->tx_max_coalesced_frames_irq; | |
11904 | tp->coal.stats_block_coalesce_usecs = ec->stats_block_coalesce_usecs; | |
11905 | ||
11906 | if (netif_running(dev)) { | |
11907 | tg3_full_lock(tp, 0); | |
11908 | __tg3_set_coalesce(tp, &tp->coal); | |
11909 | tg3_full_unlock(tp); | |
11910 | } | |
11911 | return 0; | |
11912 | } | |
11913 | ||
7282d491 | 11914 | static const struct ethtool_ops tg3_ethtool_ops = { |
1da177e4 LT |
11915 | .get_settings = tg3_get_settings, |
11916 | .set_settings = tg3_set_settings, | |
11917 | .get_drvinfo = tg3_get_drvinfo, | |
11918 | .get_regs_len = tg3_get_regs_len, | |
11919 | .get_regs = tg3_get_regs, | |
11920 | .get_wol = tg3_get_wol, | |
11921 | .set_wol = tg3_set_wol, | |
11922 | .get_msglevel = tg3_get_msglevel, | |
11923 | .set_msglevel = tg3_set_msglevel, | |
11924 | .nway_reset = tg3_nway_reset, | |
11925 | .get_link = ethtool_op_get_link, | |
11926 | .get_eeprom_len = tg3_get_eeprom_len, | |
11927 | .get_eeprom = tg3_get_eeprom, | |
11928 | .set_eeprom = tg3_set_eeprom, | |
11929 | .get_ringparam = tg3_get_ringparam, | |
11930 | .set_ringparam = tg3_set_ringparam, | |
11931 | .get_pauseparam = tg3_get_pauseparam, | |
11932 | .set_pauseparam = tg3_set_pauseparam, | |
4cafd3f5 | 11933 | .self_test = tg3_self_test, |
1da177e4 | 11934 | .get_strings = tg3_get_strings, |
81b8709c | 11935 | .set_phys_id = tg3_set_phys_id, |
1da177e4 | 11936 | .get_ethtool_stats = tg3_get_ethtool_stats, |
15f9850d | 11937 | .get_coalesce = tg3_get_coalesce, |
d244c892 | 11938 | .set_coalesce = tg3_set_coalesce, |
b9f2c044 | 11939 | .get_sset_count = tg3_get_sset_count, |
1da177e4 LT |
11940 | }; |
11941 | ||
11942 | static void __devinit tg3_get_eeprom_size(struct tg3 *tp) | |
11943 | { | |
1b27777a | 11944 | u32 cursize, val, magic; |
1da177e4 LT |
11945 | |
11946 | tp->nvram_size = EEPROM_CHIP_SIZE; | |
11947 | ||
e4f34110 | 11948 | if (tg3_nvram_read(tp, 0, &magic) != 0) |
1da177e4 LT |
11949 | return; |
11950 | ||
b16250e3 MC |
11951 | if ((magic != TG3_EEPROM_MAGIC) && |
11952 | ((magic & TG3_EEPROM_MAGIC_FW_MSK) != TG3_EEPROM_MAGIC_FW) && | |
11953 | ((magic & TG3_EEPROM_MAGIC_HW_MSK) != TG3_EEPROM_MAGIC_HW)) | |
1da177e4 LT |
11954 | return; |
11955 | ||
11956 | /* | |
11957 | * Size the chip by reading offsets at increasing powers of two. | |
11958 | * When we encounter our validation signature, we know the addressing | |
11959 | * has wrapped around, and thus have our chip size. | |
11960 | */ | |
1b27777a | 11961 | cursize = 0x10; |
1da177e4 LT |
11962 | |
11963 | while (cursize < tp->nvram_size) { | |
e4f34110 | 11964 | if (tg3_nvram_read(tp, cursize, &val) != 0) |
1da177e4 LT |
11965 | return; |
11966 | ||
1820180b | 11967 | if (val == magic) |
1da177e4 LT |
11968 | break; |
11969 | ||
11970 | cursize <<= 1; | |
11971 | } | |
11972 | ||
11973 | tp->nvram_size = cursize; | |
11974 | } | |
6aa20a22 | 11975 | |
1da177e4 LT |
11976 | static void __devinit tg3_get_nvram_size(struct tg3 *tp) |
11977 | { | |
11978 | u32 val; | |
11979 | ||
63c3a66f | 11980 | if (tg3_flag(tp, NO_NVRAM) || tg3_nvram_read(tp, 0, &val) != 0) |
1b27777a MC |
11981 | return; |
11982 | ||
11983 | /* Selfboot format */ | |
1820180b | 11984 | if (val != TG3_EEPROM_MAGIC) { |
1b27777a MC |
11985 | tg3_get_eeprom_size(tp); |
11986 | return; | |
11987 | } | |
11988 | ||
6d348f2c | 11989 | if (tg3_nvram_read(tp, 0xf0, &val) == 0) { |
1da177e4 | 11990 | if (val != 0) { |
6d348f2c MC |
11991 | /* This is confusing. We want to operate on the |
11992 | * 16-bit value at offset 0xf2. The tg3_nvram_read() | |
11993 | * call will read from NVRAM and byteswap the data | |
11994 | * according to the byteswapping settings for all | |
11995 | * other register accesses. This ensures the data we | |
11996 | * want will always reside in the lower 16-bits. | |
11997 | * However, the data in NVRAM is in LE format, which | |
11998 | * means the data from the NVRAM read will always be | |
11999 | * opposite the endianness of the CPU. The 16-bit | |
12000 | * byteswap then brings the data to CPU endianness. | |
12001 | */ | |
12002 | tp->nvram_size = swab16((u16)(val & 0x0000ffff)) * 1024; | |
1da177e4 LT |
12003 | return; |
12004 | } | |
12005 | } | |
fd1122a2 | 12006 | tp->nvram_size = TG3_NVRAM_SIZE_512KB; |
1da177e4 LT |
12007 | } |
12008 | ||
12009 | static void __devinit tg3_get_nvram_info(struct tg3 *tp) | |
12010 | { | |
12011 | u32 nvcfg1; | |
12012 | ||
12013 | nvcfg1 = tr32(NVRAM_CFG1); | |
12014 | if (nvcfg1 & NVRAM_CFG1_FLASHIF_ENAB) { | |
63c3a66f | 12015 | tg3_flag_set(tp, FLASH); |
8590a603 | 12016 | } else { |
1da177e4 LT |
12017 | nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; |
12018 | tw32(NVRAM_CFG1, nvcfg1); | |
12019 | } | |
12020 | ||
6ff6f81d | 12021 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750 || |
63c3a66f | 12022 | tg3_flag(tp, 5780_CLASS)) { |
1da177e4 | 12023 | switch (nvcfg1 & NVRAM_CFG1_VENDOR_MASK) { |
8590a603 MC |
12024 | case FLASH_VENDOR_ATMEL_FLASH_BUFFERED: |
12025 | tp->nvram_jedecnum = JEDEC_ATMEL; | |
12026 | tp->nvram_pagesize = ATMEL_AT45DB0X1B_PAGE_SIZE; | |
63c3a66f | 12027 | tg3_flag_set(tp, NVRAM_BUFFERED); |
8590a603 MC |
12028 | break; |
12029 | case FLASH_VENDOR_ATMEL_FLASH_UNBUFFERED: | |
12030 | tp->nvram_jedecnum = JEDEC_ATMEL; | |
12031 | tp->nvram_pagesize = ATMEL_AT25F512_PAGE_SIZE; | |
12032 | break; | |
12033 | case FLASH_VENDOR_ATMEL_EEPROM: | |
12034 | tp->nvram_jedecnum = JEDEC_ATMEL; | |
12035 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; | |
63c3a66f | 12036 | tg3_flag_set(tp, NVRAM_BUFFERED); |
8590a603 MC |
12037 | break; |
12038 | case FLASH_VENDOR_ST: | |
12039 | tp->nvram_jedecnum = JEDEC_ST; | |
12040 | tp->nvram_pagesize = ST_M45PEX0_PAGE_SIZE; | |
63c3a66f | 12041 | tg3_flag_set(tp, NVRAM_BUFFERED); |
8590a603 MC |
12042 | break; |
12043 | case FLASH_VENDOR_SAIFUN: | |
12044 | tp->nvram_jedecnum = JEDEC_SAIFUN; | |
12045 | tp->nvram_pagesize = SAIFUN_SA25F0XX_PAGE_SIZE; | |
12046 | break; | |
12047 | case FLASH_VENDOR_SST_SMALL: | |
12048 | case FLASH_VENDOR_SST_LARGE: | |
12049 | tp->nvram_jedecnum = JEDEC_SST; | |
12050 | tp->nvram_pagesize = SST_25VF0X0_PAGE_SIZE; | |
12051 | break; | |
1da177e4 | 12052 | } |
8590a603 | 12053 | } else { |
1da177e4 LT |
12054 | tp->nvram_jedecnum = JEDEC_ATMEL; |
12055 | tp->nvram_pagesize = ATMEL_AT45DB0X1B_PAGE_SIZE; | |
63c3a66f | 12056 | tg3_flag_set(tp, NVRAM_BUFFERED); |
1da177e4 LT |
12057 | } |
12058 | } | |
12059 | ||
a1b950d5 MC |
12060 | static void __devinit tg3_nvram_get_pagesize(struct tg3 *tp, u32 nvmcfg1) |
12061 | { | |
12062 | switch (nvmcfg1 & NVRAM_CFG1_5752PAGE_SIZE_MASK) { | |
12063 | case FLASH_5752PAGE_SIZE_256: | |
12064 | tp->nvram_pagesize = 256; | |
12065 | break; | |
12066 | case FLASH_5752PAGE_SIZE_512: | |
12067 | tp->nvram_pagesize = 512; | |
12068 | break; | |
12069 | case FLASH_5752PAGE_SIZE_1K: | |
12070 | tp->nvram_pagesize = 1024; | |
12071 | break; | |
12072 | case FLASH_5752PAGE_SIZE_2K: | |
12073 | tp->nvram_pagesize = 2048; | |
12074 | break; | |
12075 | case FLASH_5752PAGE_SIZE_4K: | |
12076 | tp->nvram_pagesize = 4096; | |
12077 | break; | |
12078 | case FLASH_5752PAGE_SIZE_264: | |
12079 | tp->nvram_pagesize = 264; | |
12080 | break; | |
12081 | case FLASH_5752PAGE_SIZE_528: | |
12082 | tp->nvram_pagesize = 528; | |
12083 | break; | |
12084 | } | |
12085 | } | |
12086 | ||
361b4ac2 MC |
12087 | static void __devinit tg3_get_5752_nvram_info(struct tg3 *tp) |
12088 | { | |
12089 | u32 nvcfg1; | |
12090 | ||
12091 | nvcfg1 = tr32(NVRAM_CFG1); | |
12092 | ||
e6af301b MC |
12093 | /* NVRAM protection for TPM */ |
12094 | if (nvcfg1 & (1 << 27)) | |
63c3a66f | 12095 | tg3_flag_set(tp, PROTECTED_NVRAM); |
e6af301b | 12096 | |
361b4ac2 | 12097 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
8590a603 MC |
12098 | case FLASH_5752VENDOR_ATMEL_EEPROM_64KHZ: |
12099 | case FLASH_5752VENDOR_ATMEL_EEPROM_376KHZ: | |
12100 | tp->nvram_jedecnum = JEDEC_ATMEL; | |
63c3a66f | 12101 | tg3_flag_set(tp, NVRAM_BUFFERED); |
8590a603 MC |
12102 | break; |
12103 | case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED: | |
12104 | tp->nvram_jedecnum = JEDEC_ATMEL; | |
63c3a66f JP |
12105 | tg3_flag_set(tp, NVRAM_BUFFERED); |
12106 | tg3_flag_set(tp, FLASH); | |
8590a603 MC |
12107 | break; |
12108 | case FLASH_5752VENDOR_ST_M45PE10: | |
12109 | case FLASH_5752VENDOR_ST_M45PE20: | |
12110 | case FLASH_5752VENDOR_ST_M45PE40: | |
12111 | tp->nvram_jedecnum = JEDEC_ST; | |
63c3a66f JP |
12112 | tg3_flag_set(tp, NVRAM_BUFFERED); |
12113 | tg3_flag_set(tp, FLASH); | |
8590a603 | 12114 | break; |
361b4ac2 MC |
12115 | } |
12116 | ||
63c3a66f | 12117 | if (tg3_flag(tp, FLASH)) { |
a1b950d5 | 12118 | tg3_nvram_get_pagesize(tp, nvcfg1); |
8590a603 | 12119 | } else { |
361b4ac2 MC |
12120 | /* For eeprom, set pagesize to maximum eeprom size */ |
12121 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; | |
12122 | ||
12123 | nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; | |
12124 | tw32(NVRAM_CFG1, nvcfg1); | |
12125 | } | |
12126 | } | |
12127 | ||
d3c7b886 MC |
12128 | static void __devinit tg3_get_5755_nvram_info(struct tg3 *tp) |
12129 | { | |
989a9d23 | 12130 | u32 nvcfg1, protect = 0; |
d3c7b886 MC |
12131 | |
12132 | nvcfg1 = tr32(NVRAM_CFG1); | |
12133 | ||
12134 | /* NVRAM protection for TPM */ | |
989a9d23 | 12135 | if (nvcfg1 & (1 << 27)) { |
63c3a66f | 12136 | tg3_flag_set(tp, PROTECTED_NVRAM); |
989a9d23 MC |
12137 | protect = 1; |
12138 | } | |
d3c7b886 | 12139 | |
989a9d23 MC |
12140 | nvcfg1 &= NVRAM_CFG1_5752VENDOR_MASK; |
12141 | switch (nvcfg1) { | |
8590a603 MC |
12142 | case FLASH_5755VENDOR_ATMEL_FLASH_1: |
12143 | case FLASH_5755VENDOR_ATMEL_FLASH_2: | |
12144 | case FLASH_5755VENDOR_ATMEL_FLASH_3: | |
12145 | case FLASH_5755VENDOR_ATMEL_FLASH_5: | |
12146 | tp->nvram_jedecnum = JEDEC_ATMEL; | |
63c3a66f JP |
12147 | tg3_flag_set(tp, NVRAM_BUFFERED); |
12148 | tg3_flag_set(tp, FLASH); | |
8590a603 MC |
12149 | tp->nvram_pagesize = 264; |
12150 | if (nvcfg1 == FLASH_5755VENDOR_ATMEL_FLASH_1 || | |
12151 | nvcfg1 == FLASH_5755VENDOR_ATMEL_FLASH_5) | |
12152 | tp->nvram_size = (protect ? 0x3e200 : | |
12153 | TG3_NVRAM_SIZE_512KB); | |
12154 | else if (nvcfg1 == FLASH_5755VENDOR_ATMEL_FLASH_2) | |
12155 | tp->nvram_size = (protect ? 0x1f200 : | |
12156 | TG3_NVRAM_SIZE_256KB); | |
12157 | else | |
12158 | tp->nvram_size = (protect ? 0x1f200 : | |
12159 | TG3_NVRAM_SIZE_128KB); | |
12160 | break; | |
12161 | case FLASH_5752VENDOR_ST_M45PE10: | |
12162 | case FLASH_5752VENDOR_ST_M45PE20: | |
12163 | case FLASH_5752VENDOR_ST_M45PE40: | |
12164 | tp->nvram_jedecnum = JEDEC_ST; | |
63c3a66f JP |
12165 | tg3_flag_set(tp, NVRAM_BUFFERED); |
12166 | tg3_flag_set(tp, FLASH); | |
8590a603 MC |
12167 | tp->nvram_pagesize = 256; |
12168 | if (nvcfg1 == FLASH_5752VENDOR_ST_M45PE10) | |
12169 | tp->nvram_size = (protect ? | |
12170 | TG3_NVRAM_SIZE_64KB : | |
12171 | TG3_NVRAM_SIZE_128KB); | |
12172 | else if (nvcfg1 == FLASH_5752VENDOR_ST_M45PE20) | |
12173 | tp->nvram_size = (protect ? | |
12174 | TG3_NVRAM_SIZE_64KB : | |
12175 | TG3_NVRAM_SIZE_256KB); | |
12176 | else | |
12177 | tp->nvram_size = (protect ? | |
12178 | TG3_NVRAM_SIZE_128KB : | |
12179 | TG3_NVRAM_SIZE_512KB); | |
12180 | break; | |
d3c7b886 MC |
12181 | } |
12182 | } | |
12183 | ||
1b27777a MC |
12184 | static void __devinit tg3_get_5787_nvram_info(struct tg3 *tp) |
12185 | { | |
12186 | u32 nvcfg1; | |
12187 | ||
12188 | nvcfg1 = tr32(NVRAM_CFG1); | |
12189 | ||
12190 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { | |
8590a603 MC |
12191 | case FLASH_5787VENDOR_ATMEL_EEPROM_64KHZ: |
12192 | case FLASH_5787VENDOR_ATMEL_EEPROM_376KHZ: | |
12193 | case FLASH_5787VENDOR_MICRO_EEPROM_64KHZ: | |
12194 | case FLASH_5787VENDOR_MICRO_EEPROM_376KHZ: | |
12195 | tp->nvram_jedecnum = JEDEC_ATMEL; | |
63c3a66f | 12196 | tg3_flag_set(tp, NVRAM_BUFFERED); |
8590a603 | 12197 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
1b27777a | 12198 | |
8590a603 MC |
12199 | nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; |
12200 | tw32(NVRAM_CFG1, nvcfg1); | |
12201 | break; | |
12202 | case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED: | |
12203 | case FLASH_5755VENDOR_ATMEL_FLASH_1: | |
12204 | case FLASH_5755VENDOR_ATMEL_FLASH_2: | |
12205 | case FLASH_5755VENDOR_ATMEL_FLASH_3: | |
12206 | tp->nvram_jedecnum = JEDEC_ATMEL; | |
63c3a66f JP |
12207 | tg3_flag_set(tp, NVRAM_BUFFERED); |
12208 | tg3_flag_set(tp, FLASH); | |
8590a603 MC |
12209 | tp->nvram_pagesize = 264; |
12210 | break; | |
12211 | case FLASH_5752VENDOR_ST_M45PE10: | |
12212 | case FLASH_5752VENDOR_ST_M45PE20: | |
12213 | case FLASH_5752VENDOR_ST_M45PE40: | |
12214 | tp->nvram_jedecnum = JEDEC_ST; | |
63c3a66f JP |
12215 | tg3_flag_set(tp, NVRAM_BUFFERED); |
12216 | tg3_flag_set(tp, FLASH); | |
8590a603 MC |
12217 | tp->nvram_pagesize = 256; |
12218 | break; | |
1b27777a MC |
12219 | } |
12220 | } | |
12221 | ||
6b91fa02 MC |
12222 | static void __devinit tg3_get_5761_nvram_info(struct tg3 *tp) |
12223 | { | |
12224 | u32 nvcfg1, protect = 0; | |
12225 | ||
12226 | nvcfg1 = tr32(NVRAM_CFG1); | |
12227 | ||
12228 | /* NVRAM protection for TPM */ | |
12229 | if (nvcfg1 & (1 << 27)) { | |
63c3a66f | 12230 | tg3_flag_set(tp, PROTECTED_NVRAM); |
6b91fa02 MC |
12231 | protect = 1; |
12232 | } | |
12233 | ||
12234 | nvcfg1 &= NVRAM_CFG1_5752VENDOR_MASK; | |
12235 | switch (nvcfg1) { | |
8590a603 MC |
12236 | case FLASH_5761VENDOR_ATMEL_ADB021D: |
12237 | case FLASH_5761VENDOR_ATMEL_ADB041D: | |
12238 | case FLASH_5761VENDOR_ATMEL_ADB081D: | |
12239 | case FLASH_5761VENDOR_ATMEL_ADB161D: | |
12240 | case FLASH_5761VENDOR_ATMEL_MDB021D: | |
12241 | case FLASH_5761VENDOR_ATMEL_MDB041D: | |
12242 | case FLASH_5761VENDOR_ATMEL_MDB081D: | |
12243 | case FLASH_5761VENDOR_ATMEL_MDB161D: | |
12244 | tp->nvram_jedecnum = JEDEC_ATMEL; | |
63c3a66f JP |
12245 | tg3_flag_set(tp, NVRAM_BUFFERED); |
12246 | tg3_flag_set(tp, FLASH); | |
12247 | tg3_flag_set(tp, NO_NVRAM_ADDR_TRANS); | |
8590a603 MC |
12248 | tp->nvram_pagesize = 256; |
12249 | break; | |
12250 | case FLASH_5761VENDOR_ST_A_M45PE20: | |
12251 | case FLASH_5761VENDOR_ST_A_M45PE40: | |
12252 | case FLASH_5761VENDOR_ST_A_M45PE80: | |
12253 | case FLASH_5761VENDOR_ST_A_M45PE16: | |
12254 | case FLASH_5761VENDOR_ST_M_M45PE20: | |
12255 | case FLASH_5761VENDOR_ST_M_M45PE40: | |
12256 | case FLASH_5761VENDOR_ST_M_M45PE80: | |
12257 | case FLASH_5761VENDOR_ST_M_M45PE16: | |
12258 | tp->nvram_jedecnum = JEDEC_ST; | |
63c3a66f JP |
12259 | tg3_flag_set(tp, NVRAM_BUFFERED); |
12260 | tg3_flag_set(tp, FLASH); | |
8590a603 MC |
12261 | tp->nvram_pagesize = 256; |
12262 | break; | |
6b91fa02 MC |
12263 | } |
12264 | ||
12265 | if (protect) { | |
12266 | tp->nvram_size = tr32(NVRAM_ADDR_LOCKOUT); | |
12267 | } else { | |
12268 | switch (nvcfg1) { | |
8590a603 MC |
12269 | case FLASH_5761VENDOR_ATMEL_ADB161D: |
12270 | case FLASH_5761VENDOR_ATMEL_MDB161D: | |
12271 | case FLASH_5761VENDOR_ST_A_M45PE16: | |
12272 | case FLASH_5761VENDOR_ST_M_M45PE16: | |
12273 | tp->nvram_size = TG3_NVRAM_SIZE_2MB; | |
12274 | break; | |
12275 | case FLASH_5761VENDOR_ATMEL_ADB081D: | |
12276 | case FLASH_5761VENDOR_ATMEL_MDB081D: | |
12277 | case FLASH_5761VENDOR_ST_A_M45PE80: | |
12278 | case FLASH_5761VENDOR_ST_M_M45PE80: | |
12279 | tp->nvram_size = TG3_NVRAM_SIZE_1MB; | |
12280 | break; | |
12281 | case FLASH_5761VENDOR_ATMEL_ADB041D: | |
12282 | case FLASH_5761VENDOR_ATMEL_MDB041D: | |
12283 | case FLASH_5761VENDOR_ST_A_M45PE40: | |
12284 | case FLASH_5761VENDOR_ST_M_M45PE40: | |
12285 | tp->nvram_size = TG3_NVRAM_SIZE_512KB; | |
12286 | break; | |
12287 | case FLASH_5761VENDOR_ATMEL_ADB021D: | |
12288 | case FLASH_5761VENDOR_ATMEL_MDB021D: | |
12289 | case FLASH_5761VENDOR_ST_A_M45PE20: | |
12290 | case FLASH_5761VENDOR_ST_M_M45PE20: | |
12291 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; | |
12292 | break; | |
6b91fa02 MC |
12293 | } |
12294 | } | |
12295 | } | |
12296 | ||
b5d3772c MC |
12297 | static void __devinit tg3_get_5906_nvram_info(struct tg3 *tp) |
12298 | { | |
12299 | tp->nvram_jedecnum = JEDEC_ATMEL; | |
63c3a66f | 12300 | tg3_flag_set(tp, NVRAM_BUFFERED); |
b5d3772c MC |
12301 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
12302 | } | |
12303 | ||
321d32a0 MC |
12304 | static void __devinit tg3_get_57780_nvram_info(struct tg3 *tp) |
12305 | { | |
12306 | u32 nvcfg1; | |
12307 | ||
12308 | nvcfg1 = tr32(NVRAM_CFG1); | |
12309 | ||
12310 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { | |
12311 | case FLASH_5787VENDOR_ATMEL_EEPROM_376KHZ: | |
12312 | case FLASH_5787VENDOR_MICRO_EEPROM_376KHZ: | |
12313 | tp->nvram_jedecnum = JEDEC_ATMEL; | |
63c3a66f | 12314 | tg3_flag_set(tp, NVRAM_BUFFERED); |
321d32a0 MC |
12315 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
12316 | ||
12317 | nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; | |
12318 | tw32(NVRAM_CFG1, nvcfg1); | |
12319 | return; | |
12320 | case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED: | |
12321 | case FLASH_57780VENDOR_ATMEL_AT45DB011D: | |
12322 | case FLASH_57780VENDOR_ATMEL_AT45DB011B: | |
12323 | case FLASH_57780VENDOR_ATMEL_AT45DB021D: | |
12324 | case FLASH_57780VENDOR_ATMEL_AT45DB021B: | |
12325 | case FLASH_57780VENDOR_ATMEL_AT45DB041D: | |
12326 | case FLASH_57780VENDOR_ATMEL_AT45DB041B: | |
12327 | tp->nvram_jedecnum = JEDEC_ATMEL; | |
63c3a66f JP |
12328 | tg3_flag_set(tp, NVRAM_BUFFERED); |
12329 | tg3_flag_set(tp, FLASH); | |
321d32a0 MC |
12330 | |
12331 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { | |
12332 | case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED: | |
12333 | case FLASH_57780VENDOR_ATMEL_AT45DB011D: | |
12334 | case FLASH_57780VENDOR_ATMEL_AT45DB011B: | |
12335 | tp->nvram_size = TG3_NVRAM_SIZE_128KB; | |
12336 | break; | |
12337 | case FLASH_57780VENDOR_ATMEL_AT45DB021D: | |
12338 | case FLASH_57780VENDOR_ATMEL_AT45DB021B: | |
12339 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; | |
12340 | break; | |
12341 | case FLASH_57780VENDOR_ATMEL_AT45DB041D: | |
12342 | case FLASH_57780VENDOR_ATMEL_AT45DB041B: | |
12343 | tp->nvram_size = TG3_NVRAM_SIZE_512KB; | |
12344 | break; | |
12345 | } | |
12346 | break; | |
12347 | case FLASH_5752VENDOR_ST_M45PE10: | |
12348 | case FLASH_5752VENDOR_ST_M45PE20: | |
12349 | case FLASH_5752VENDOR_ST_M45PE40: | |
12350 | tp->nvram_jedecnum = JEDEC_ST; | |
63c3a66f JP |
12351 | tg3_flag_set(tp, NVRAM_BUFFERED); |
12352 | tg3_flag_set(tp, FLASH); | |
321d32a0 MC |
12353 | |
12354 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { | |
12355 | case FLASH_5752VENDOR_ST_M45PE10: | |
12356 | tp->nvram_size = TG3_NVRAM_SIZE_128KB; | |
12357 | break; | |
12358 | case FLASH_5752VENDOR_ST_M45PE20: | |
12359 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; | |
12360 | break; | |
12361 | case FLASH_5752VENDOR_ST_M45PE40: | |
12362 | tp->nvram_size = TG3_NVRAM_SIZE_512KB; | |
12363 | break; | |
12364 | } | |
12365 | break; | |
12366 | default: | |
63c3a66f | 12367 | tg3_flag_set(tp, NO_NVRAM); |
321d32a0 MC |
12368 | return; |
12369 | } | |
12370 | ||
a1b950d5 MC |
12371 | tg3_nvram_get_pagesize(tp, nvcfg1); |
12372 | if (tp->nvram_pagesize != 264 && tp->nvram_pagesize != 528) | |
63c3a66f | 12373 | tg3_flag_set(tp, NO_NVRAM_ADDR_TRANS); |
a1b950d5 MC |
12374 | } |
12375 | ||
12376 | ||
12377 | static void __devinit tg3_get_5717_nvram_info(struct tg3 *tp) | |
12378 | { | |
12379 | u32 nvcfg1; | |
12380 | ||
12381 | nvcfg1 = tr32(NVRAM_CFG1); | |
12382 | ||
12383 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { | |
12384 | case FLASH_5717VENDOR_ATMEL_EEPROM: | |
12385 | case FLASH_5717VENDOR_MICRO_EEPROM: | |
12386 | tp->nvram_jedecnum = JEDEC_ATMEL; | |
63c3a66f | 12387 | tg3_flag_set(tp, NVRAM_BUFFERED); |
a1b950d5 MC |
12388 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
12389 | ||
12390 | nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; | |
12391 | tw32(NVRAM_CFG1, nvcfg1); | |
12392 | return; | |
12393 | case FLASH_5717VENDOR_ATMEL_MDB011D: | |
12394 | case FLASH_5717VENDOR_ATMEL_ADB011B: | |
12395 | case FLASH_5717VENDOR_ATMEL_ADB011D: | |
12396 | case FLASH_5717VENDOR_ATMEL_MDB021D: | |
12397 | case FLASH_5717VENDOR_ATMEL_ADB021B: | |
12398 | case FLASH_5717VENDOR_ATMEL_ADB021D: | |
12399 | case FLASH_5717VENDOR_ATMEL_45USPT: | |
12400 | tp->nvram_jedecnum = JEDEC_ATMEL; | |
63c3a66f JP |
12401 | tg3_flag_set(tp, NVRAM_BUFFERED); |
12402 | tg3_flag_set(tp, FLASH); | |
a1b950d5 MC |
12403 | |
12404 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { | |
12405 | case FLASH_5717VENDOR_ATMEL_MDB021D: | |
66ee33bf MC |
12406 | /* Detect size with tg3_nvram_get_size() */ |
12407 | break; | |
a1b950d5 MC |
12408 | case FLASH_5717VENDOR_ATMEL_ADB021B: |
12409 | case FLASH_5717VENDOR_ATMEL_ADB021D: | |
12410 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; | |
12411 | break; | |
12412 | default: | |
12413 | tp->nvram_size = TG3_NVRAM_SIZE_128KB; | |
12414 | break; | |
12415 | } | |
321d32a0 | 12416 | break; |
a1b950d5 MC |
12417 | case FLASH_5717VENDOR_ST_M_M25PE10: |
12418 | case FLASH_5717VENDOR_ST_A_M25PE10: | |
12419 | case FLASH_5717VENDOR_ST_M_M45PE10: | |
12420 | case FLASH_5717VENDOR_ST_A_M45PE10: | |
12421 | case FLASH_5717VENDOR_ST_M_M25PE20: | |
12422 | case FLASH_5717VENDOR_ST_A_M25PE20: | |
12423 | case FLASH_5717VENDOR_ST_M_M45PE20: | |
12424 | case FLASH_5717VENDOR_ST_A_M45PE20: | |
12425 | case FLASH_5717VENDOR_ST_25USPT: | |
12426 | case FLASH_5717VENDOR_ST_45USPT: | |
12427 | tp->nvram_jedecnum = JEDEC_ST; | |
63c3a66f JP |
12428 | tg3_flag_set(tp, NVRAM_BUFFERED); |
12429 | tg3_flag_set(tp, FLASH); | |
a1b950d5 MC |
12430 | |
12431 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { | |
12432 | case FLASH_5717VENDOR_ST_M_M25PE20: | |
a1b950d5 | 12433 | case FLASH_5717VENDOR_ST_M_M45PE20: |
66ee33bf MC |
12434 | /* Detect size with tg3_nvram_get_size() */ |
12435 | break; | |
12436 | case FLASH_5717VENDOR_ST_A_M25PE20: | |
a1b950d5 MC |
12437 | case FLASH_5717VENDOR_ST_A_M45PE20: |
12438 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; | |
12439 | break; | |
12440 | default: | |
12441 | tp->nvram_size = TG3_NVRAM_SIZE_128KB; | |
12442 | break; | |
12443 | } | |
321d32a0 | 12444 | break; |
a1b950d5 | 12445 | default: |
63c3a66f | 12446 | tg3_flag_set(tp, NO_NVRAM); |
a1b950d5 | 12447 | return; |
321d32a0 | 12448 | } |
a1b950d5 MC |
12449 | |
12450 | tg3_nvram_get_pagesize(tp, nvcfg1); | |
12451 | if (tp->nvram_pagesize != 264 && tp->nvram_pagesize != 528) | |
63c3a66f | 12452 | tg3_flag_set(tp, NO_NVRAM_ADDR_TRANS); |
321d32a0 MC |
12453 | } |
12454 | ||
9b91b5f1 MC |
12455 | static void __devinit tg3_get_5720_nvram_info(struct tg3 *tp) |
12456 | { | |
12457 | u32 nvcfg1, nvmpinstrp; | |
12458 | ||
12459 | nvcfg1 = tr32(NVRAM_CFG1); | |
12460 | nvmpinstrp = nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK; | |
12461 | ||
12462 | switch (nvmpinstrp) { | |
12463 | case FLASH_5720_EEPROM_HD: | |
12464 | case FLASH_5720_EEPROM_LD: | |
12465 | tp->nvram_jedecnum = JEDEC_ATMEL; | |
63c3a66f | 12466 | tg3_flag_set(tp, NVRAM_BUFFERED); |
9b91b5f1 MC |
12467 | |
12468 | nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; | |
12469 | tw32(NVRAM_CFG1, nvcfg1); | |
12470 | if (nvmpinstrp == FLASH_5720_EEPROM_HD) | |
12471 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; | |
12472 | else | |
12473 | tp->nvram_pagesize = ATMEL_AT24C02_CHIP_SIZE; | |
12474 | return; | |
12475 | case FLASH_5720VENDOR_M_ATMEL_DB011D: | |
12476 | case FLASH_5720VENDOR_A_ATMEL_DB011B: | |
12477 | case FLASH_5720VENDOR_A_ATMEL_DB011D: | |
12478 | case FLASH_5720VENDOR_M_ATMEL_DB021D: | |
12479 | case FLASH_5720VENDOR_A_ATMEL_DB021B: | |
12480 | case FLASH_5720VENDOR_A_ATMEL_DB021D: | |
12481 | case FLASH_5720VENDOR_M_ATMEL_DB041D: | |
12482 | case FLASH_5720VENDOR_A_ATMEL_DB041B: | |
12483 | case FLASH_5720VENDOR_A_ATMEL_DB041D: | |
12484 | case FLASH_5720VENDOR_M_ATMEL_DB081D: | |
12485 | case FLASH_5720VENDOR_A_ATMEL_DB081D: | |
12486 | case FLASH_5720VENDOR_ATMEL_45USPT: | |
12487 | tp->nvram_jedecnum = JEDEC_ATMEL; | |
63c3a66f JP |
12488 | tg3_flag_set(tp, NVRAM_BUFFERED); |
12489 | tg3_flag_set(tp, FLASH); | |
9b91b5f1 MC |
12490 | |
12491 | switch (nvmpinstrp) { | |
12492 | case FLASH_5720VENDOR_M_ATMEL_DB021D: | |
12493 | case FLASH_5720VENDOR_A_ATMEL_DB021B: | |
12494 | case FLASH_5720VENDOR_A_ATMEL_DB021D: | |
12495 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; | |
12496 | break; | |
12497 | case FLASH_5720VENDOR_M_ATMEL_DB041D: | |
12498 | case FLASH_5720VENDOR_A_ATMEL_DB041B: | |
12499 | case FLASH_5720VENDOR_A_ATMEL_DB041D: | |
12500 | tp->nvram_size = TG3_NVRAM_SIZE_512KB; | |
12501 | break; | |
12502 | case FLASH_5720VENDOR_M_ATMEL_DB081D: | |
12503 | case FLASH_5720VENDOR_A_ATMEL_DB081D: | |
12504 | tp->nvram_size = TG3_NVRAM_SIZE_1MB; | |
12505 | break; | |
12506 | default: | |
12507 | tp->nvram_size = TG3_NVRAM_SIZE_128KB; | |
12508 | break; | |
12509 | } | |
12510 | break; | |
12511 | case FLASH_5720VENDOR_M_ST_M25PE10: | |
12512 | case FLASH_5720VENDOR_M_ST_M45PE10: | |
12513 | case FLASH_5720VENDOR_A_ST_M25PE10: | |
12514 | case FLASH_5720VENDOR_A_ST_M45PE10: | |
12515 | case FLASH_5720VENDOR_M_ST_M25PE20: | |
12516 | case FLASH_5720VENDOR_M_ST_M45PE20: | |
12517 | case FLASH_5720VENDOR_A_ST_M25PE20: | |
12518 | case FLASH_5720VENDOR_A_ST_M45PE20: | |
12519 | case FLASH_5720VENDOR_M_ST_M25PE40: | |
12520 | case FLASH_5720VENDOR_M_ST_M45PE40: | |
12521 | case FLASH_5720VENDOR_A_ST_M25PE40: | |
12522 | case FLASH_5720VENDOR_A_ST_M45PE40: | |
12523 | case FLASH_5720VENDOR_M_ST_M25PE80: | |
12524 | case FLASH_5720VENDOR_M_ST_M45PE80: | |
12525 | case FLASH_5720VENDOR_A_ST_M25PE80: | |
12526 | case FLASH_5720VENDOR_A_ST_M45PE80: | |
12527 | case FLASH_5720VENDOR_ST_25USPT: | |
12528 | case FLASH_5720VENDOR_ST_45USPT: | |
12529 | tp->nvram_jedecnum = JEDEC_ST; | |
63c3a66f JP |
12530 | tg3_flag_set(tp, NVRAM_BUFFERED); |
12531 | tg3_flag_set(tp, FLASH); | |
9b91b5f1 MC |
12532 | |
12533 | switch (nvmpinstrp) { | |
12534 | case FLASH_5720VENDOR_M_ST_M25PE20: | |
12535 | case FLASH_5720VENDOR_M_ST_M45PE20: | |
12536 | case FLASH_5720VENDOR_A_ST_M25PE20: | |
12537 | case FLASH_5720VENDOR_A_ST_M45PE20: | |
12538 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; | |
12539 | break; | |
12540 | case FLASH_5720VENDOR_M_ST_M25PE40: | |
12541 | case FLASH_5720VENDOR_M_ST_M45PE40: | |
12542 | case FLASH_5720VENDOR_A_ST_M25PE40: | |
12543 | case FLASH_5720VENDOR_A_ST_M45PE40: | |
12544 | tp->nvram_size = TG3_NVRAM_SIZE_512KB; | |
12545 | break; | |
12546 | case FLASH_5720VENDOR_M_ST_M25PE80: | |
12547 | case FLASH_5720VENDOR_M_ST_M45PE80: | |
12548 | case FLASH_5720VENDOR_A_ST_M25PE80: | |
12549 | case FLASH_5720VENDOR_A_ST_M45PE80: | |
12550 | tp->nvram_size = TG3_NVRAM_SIZE_1MB; | |
12551 | break; | |
12552 | default: | |
12553 | tp->nvram_size = TG3_NVRAM_SIZE_128KB; | |
12554 | break; | |
12555 | } | |
12556 | break; | |
12557 | default: | |
63c3a66f | 12558 | tg3_flag_set(tp, NO_NVRAM); |
9b91b5f1 MC |
12559 | return; |
12560 | } | |
12561 | ||
12562 | tg3_nvram_get_pagesize(tp, nvcfg1); | |
12563 | if (tp->nvram_pagesize != 264 && tp->nvram_pagesize != 528) | |
63c3a66f | 12564 | tg3_flag_set(tp, NO_NVRAM_ADDR_TRANS); |
9b91b5f1 MC |
12565 | } |
12566 | ||
1da177e4 LT |
12567 | /* Chips other than 5700/5701 use the NVRAM for fetching info. */ |
12568 | static void __devinit tg3_nvram_init(struct tg3 *tp) | |
12569 | { | |
1da177e4 LT |
12570 | tw32_f(GRC_EEPROM_ADDR, |
12571 | (EEPROM_ADDR_FSM_RESET | | |
12572 | (EEPROM_DEFAULT_CLOCK_PERIOD << | |
12573 | EEPROM_ADDR_CLKPERD_SHIFT))); | |
12574 | ||
9d57f01c | 12575 | msleep(1); |
1da177e4 LT |
12576 | |
12577 | /* Enable seeprom accesses. */ | |
12578 | tw32_f(GRC_LOCAL_CTRL, | |
12579 | tr32(GRC_LOCAL_CTRL) | GRC_LCLCTRL_AUTO_SEEPROM); | |
12580 | udelay(100); | |
12581 | ||
12582 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 && | |
12583 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) { | |
63c3a66f | 12584 | tg3_flag_set(tp, NVRAM); |
1da177e4 | 12585 | |
ec41c7df | 12586 | if (tg3_nvram_lock(tp)) { |
5129c3a3 MC |
12587 | netdev_warn(tp->dev, |
12588 | "Cannot get nvram lock, %s failed\n", | |
05dbe005 | 12589 | __func__); |
ec41c7df MC |
12590 | return; |
12591 | } | |
e6af301b | 12592 | tg3_enable_nvram_access(tp); |
1da177e4 | 12593 | |
989a9d23 MC |
12594 | tp->nvram_size = 0; |
12595 | ||
361b4ac2 MC |
12596 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752) |
12597 | tg3_get_5752_nvram_info(tp); | |
d3c7b886 MC |
12598 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755) |
12599 | tg3_get_5755_nvram_info(tp); | |
d30cdd28 | 12600 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 || |
57e6983c MC |
12601 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 || |
12602 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) | |
1b27777a | 12603 | tg3_get_5787_nvram_info(tp); |
6b91fa02 MC |
12604 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) |
12605 | tg3_get_5761_nvram_info(tp); | |
b5d3772c MC |
12606 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) |
12607 | tg3_get_5906_nvram_info(tp); | |
b703df6f MC |
12608 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780 || |
12609 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) | |
321d32a0 | 12610 | tg3_get_57780_nvram_info(tp); |
9b91b5f1 MC |
12611 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
12612 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719) | |
a1b950d5 | 12613 | tg3_get_5717_nvram_info(tp); |
9b91b5f1 MC |
12614 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) |
12615 | tg3_get_5720_nvram_info(tp); | |
361b4ac2 MC |
12616 | else |
12617 | tg3_get_nvram_info(tp); | |
12618 | ||
989a9d23 MC |
12619 | if (tp->nvram_size == 0) |
12620 | tg3_get_nvram_size(tp); | |
1da177e4 | 12621 | |
e6af301b | 12622 | tg3_disable_nvram_access(tp); |
381291b7 | 12623 | tg3_nvram_unlock(tp); |
1da177e4 LT |
12624 | |
12625 | } else { | |
63c3a66f JP |
12626 | tg3_flag_clear(tp, NVRAM); |
12627 | tg3_flag_clear(tp, NVRAM_BUFFERED); | |
1da177e4 LT |
12628 | |
12629 | tg3_get_eeprom_size(tp); | |
12630 | } | |
12631 | } | |
12632 | ||
1da177e4 LT |
12633 | static int tg3_nvram_write_block_using_eeprom(struct tg3 *tp, |
12634 | u32 offset, u32 len, u8 *buf) | |
12635 | { | |
12636 | int i, j, rc = 0; | |
12637 | u32 val; | |
12638 | ||
12639 | for (i = 0; i < len; i += 4) { | |
b9fc7dc5 | 12640 | u32 addr; |
a9dc529d | 12641 | __be32 data; |
1da177e4 LT |
12642 | |
12643 | addr = offset + i; | |
12644 | ||
12645 | memcpy(&data, buf + i, 4); | |
12646 | ||
62cedd11 MC |
12647 | /* |
12648 | * The SEEPROM interface expects the data to always be opposite | |
12649 | * the native endian format. We accomplish this by reversing | |
12650 | * all the operations that would have been performed on the | |
12651 | * data from a call to tg3_nvram_read_be32(). | |
12652 | */ | |
12653 | tw32(GRC_EEPROM_DATA, swab32(be32_to_cpu(data))); | |
1da177e4 LT |
12654 | |
12655 | val = tr32(GRC_EEPROM_ADDR); | |
12656 | tw32(GRC_EEPROM_ADDR, val | EEPROM_ADDR_COMPLETE); | |
12657 | ||
12658 | val &= ~(EEPROM_ADDR_ADDR_MASK | EEPROM_ADDR_DEVID_MASK | | |
12659 | EEPROM_ADDR_READ); | |
12660 | tw32(GRC_EEPROM_ADDR, val | | |
12661 | (0 << EEPROM_ADDR_DEVID_SHIFT) | | |
12662 | (addr & EEPROM_ADDR_ADDR_MASK) | | |
12663 | EEPROM_ADDR_START | | |
12664 | EEPROM_ADDR_WRITE); | |
6aa20a22 | 12665 | |
9d57f01c | 12666 | for (j = 0; j < 1000; j++) { |
1da177e4 LT |
12667 | val = tr32(GRC_EEPROM_ADDR); |
12668 | ||
12669 | if (val & EEPROM_ADDR_COMPLETE) | |
12670 | break; | |
9d57f01c | 12671 | msleep(1); |
1da177e4 LT |
12672 | } |
12673 | if (!(val & EEPROM_ADDR_COMPLETE)) { | |
12674 | rc = -EBUSY; | |
12675 | break; | |
12676 | } | |
12677 | } | |
12678 | ||
12679 | return rc; | |
12680 | } | |
12681 | ||
12682 | /* offset and length are dword aligned */ | |
12683 | static int tg3_nvram_write_block_unbuffered(struct tg3 *tp, u32 offset, u32 len, | |
12684 | u8 *buf) | |
12685 | { | |
12686 | int ret = 0; | |
12687 | u32 pagesize = tp->nvram_pagesize; | |
12688 | u32 pagemask = pagesize - 1; | |
12689 | u32 nvram_cmd; | |
12690 | u8 *tmp; | |
12691 | ||
12692 | tmp = kmalloc(pagesize, GFP_KERNEL); | |
12693 | if (tmp == NULL) | |
12694 | return -ENOMEM; | |
12695 | ||
12696 | while (len) { | |
12697 | int j; | |
e6af301b | 12698 | u32 phy_addr, page_off, size; |
1da177e4 LT |
12699 | |
12700 | phy_addr = offset & ~pagemask; | |
6aa20a22 | 12701 | |
1da177e4 | 12702 | for (j = 0; j < pagesize; j += 4) { |
a9dc529d MC |
12703 | ret = tg3_nvram_read_be32(tp, phy_addr + j, |
12704 | (__be32 *) (tmp + j)); | |
12705 | if (ret) | |
1da177e4 LT |
12706 | break; |
12707 | } | |
12708 | if (ret) | |
12709 | break; | |
12710 | ||
c6cdf436 | 12711 | page_off = offset & pagemask; |
1da177e4 LT |
12712 | size = pagesize; |
12713 | if (len < size) | |
12714 | size = len; | |
12715 | ||
12716 | len -= size; | |
12717 | ||
12718 | memcpy(tmp + page_off, buf, size); | |
12719 | ||
12720 | offset = offset + (pagesize - page_off); | |
12721 | ||
e6af301b | 12722 | tg3_enable_nvram_access(tp); |
1da177e4 LT |
12723 | |
12724 | /* | |
12725 | * Before we can erase the flash page, we need | |
12726 | * to issue a special "write enable" command. | |
12727 | */ | |
12728 | nvram_cmd = NVRAM_CMD_WREN | NVRAM_CMD_GO | NVRAM_CMD_DONE; | |
12729 | ||
12730 | if (tg3_nvram_exec_cmd(tp, nvram_cmd)) | |
12731 | break; | |
12732 | ||
12733 | /* Erase the target page */ | |
12734 | tw32(NVRAM_ADDR, phy_addr); | |
12735 | ||
12736 | nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE | NVRAM_CMD_WR | | |
12737 | NVRAM_CMD_FIRST | NVRAM_CMD_LAST | NVRAM_CMD_ERASE; | |
12738 | ||
c6cdf436 | 12739 | if (tg3_nvram_exec_cmd(tp, nvram_cmd)) |
1da177e4 LT |
12740 | break; |
12741 | ||
12742 | /* Issue another write enable to start the write. */ | |
12743 | nvram_cmd = NVRAM_CMD_WREN | NVRAM_CMD_GO | NVRAM_CMD_DONE; | |
12744 | ||
12745 | if (tg3_nvram_exec_cmd(tp, nvram_cmd)) | |
12746 | break; | |
12747 | ||
12748 | for (j = 0; j < pagesize; j += 4) { | |
b9fc7dc5 | 12749 | __be32 data; |
1da177e4 | 12750 | |
b9fc7dc5 | 12751 | data = *((__be32 *) (tmp + j)); |
a9dc529d | 12752 | |
b9fc7dc5 | 12753 | tw32(NVRAM_WRDATA, be32_to_cpu(data)); |
1da177e4 LT |
12754 | |
12755 | tw32(NVRAM_ADDR, phy_addr + j); | |
12756 | ||
12757 | nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE | | |
12758 | NVRAM_CMD_WR; | |
12759 | ||
12760 | if (j == 0) | |
12761 | nvram_cmd |= NVRAM_CMD_FIRST; | |
12762 | else if (j == (pagesize - 4)) | |
12763 | nvram_cmd |= NVRAM_CMD_LAST; | |
12764 | ||
12765 | if ((ret = tg3_nvram_exec_cmd(tp, nvram_cmd))) | |
12766 | break; | |
12767 | } | |
12768 | if (ret) | |
12769 | break; | |
12770 | } | |
12771 | ||
12772 | nvram_cmd = NVRAM_CMD_WRDI | NVRAM_CMD_GO | NVRAM_CMD_DONE; | |
12773 | tg3_nvram_exec_cmd(tp, nvram_cmd); | |
12774 | ||
12775 | kfree(tmp); | |
12776 | ||
12777 | return ret; | |
12778 | } | |
12779 | ||
12780 | /* offset and length are dword aligned */ | |
12781 | static int tg3_nvram_write_block_buffered(struct tg3 *tp, u32 offset, u32 len, | |
12782 | u8 *buf) | |
12783 | { | |
12784 | int i, ret = 0; | |
12785 | ||
12786 | for (i = 0; i < len; i += 4, offset += 4) { | |
b9fc7dc5 AV |
12787 | u32 page_off, phy_addr, nvram_cmd; |
12788 | __be32 data; | |
1da177e4 LT |
12789 | |
12790 | memcpy(&data, buf + i, 4); | |
b9fc7dc5 | 12791 | tw32(NVRAM_WRDATA, be32_to_cpu(data)); |
1da177e4 | 12792 | |
c6cdf436 | 12793 | page_off = offset % tp->nvram_pagesize; |
1da177e4 | 12794 | |
1820180b | 12795 | phy_addr = tg3_nvram_phys_addr(tp, offset); |
1da177e4 LT |
12796 | |
12797 | tw32(NVRAM_ADDR, phy_addr); | |
12798 | ||
12799 | nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE | NVRAM_CMD_WR; | |
12800 | ||
c6cdf436 | 12801 | if (page_off == 0 || i == 0) |
1da177e4 | 12802 | nvram_cmd |= NVRAM_CMD_FIRST; |
f6d9a256 | 12803 | if (page_off == (tp->nvram_pagesize - 4)) |
1da177e4 LT |
12804 | nvram_cmd |= NVRAM_CMD_LAST; |
12805 | ||
12806 | if (i == (len - 4)) | |
12807 | nvram_cmd |= NVRAM_CMD_LAST; | |
12808 | ||
321d32a0 | 12809 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5752 && |
63c3a66f | 12810 | !tg3_flag(tp, 5755_PLUS) && |
4c987487 MC |
12811 | (tp->nvram_jedecnum == JEDEC_ST) && |
12812 | (nvram_cmd & NVRAM_CMD_FIRST)) { | |
1da177e4 LT |
12813 | |
12814 | if ((ret = tg3_nvram_exec_cmd(tp, | |
12815 | NVRAM_CMD_WREN | NVRAM_CMD_GO | | |
12816 | NVRAM_CMD_DONE))) | |
12817 | ||
12818 | break; | |
12819 | } | |
63c3a66f | 12820 | if (!tg3_flag(tp, FLASH)) { |
1da177e4 LT |
12821 | /* We always do complete word writes to eeprom. */ |
12822 | nvram_cmd |= (NVRAM_CMD_FIRST | NVRAM_CMD_LAST); | |
12823 | } | |
12824 | ||
12825 | if ((ret = tg3_nvram_exec_cmd(tp, nvram_cmd))) | |
12826 | break; | |
12827 | } | |
12828 | return ret; | |
12829 | } | |
12830 | ||
12831 | /* offset and length are dword aligned */ | |
12832 | static int tg3_nvram_write_block(struct tg3 *tp, u32 offset, u32 len, u8 *buf) | |
12833 | { | |
12834 | int ret; | |
12835 | ||
63c3a66f | 12836 | if (tg3_flag(tp, EEPROM_WRITE_PROT)) { |
314fba34 MC |
12837 | tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl & |
12838 | ~GRC_LCLCTRL_GPIO_OUTPUT1); | |
1da177e4 LT |
12839 | udelay(40); |
12840 | } | |
12841 | ||
63c3a66f | 12842 | if (!tg3_flag(tp, NVRAM)) { |
1da177e4 | 12843 | ret = tg3_nvram_write_block_using_eeprom(tp, offset, len, buf); |
859a5887 | 12844 | } else { |
1da177e4 LT |
12845 | u32 grc_mode; |
12846 | ||
ec41c7df MC |
12847 | ret = tg3_nvram_lock(tp); |
12848 | if (ret) | |
12849 | return ret; | |
1da177e4 | 12850 | |
e6af301b | 12851 | tg3_enable_nvram_access(tp); |
63c3a66f | 12852 | if (tg3_flag(tp, 5750_PLUS) && !tg3_flag(tp, PROTECTED_NVRAM)) |
1da177e4 | 12853 | tw32(NVRAM_WRITE1, 0x406); |
1da177e4 LT |
12854 | |
12855 | grc_mode = tr32(GRC_MODE); | |
12856 | tw32(GRC_MODE, grc_mode | GRC_MODE_NVRAM_WR_ENABLE); | |
12857 | ||
63c3a66f | 12858 | if (tg3_flag(tp, NVRAM_BUFFERED) || !tg3_flag(tp, FLASH)) { |
1da177e4 LT |
12859 | ret = tg3_nvram_write_block_buffered(tp, offset, len, |
12860 | buf); | |
859a5887 | 12861 | } else { |
1da177e4 LT |
12862 | ret = tg3_nvram_write_block_unbuffered(tp, offset, len, |
12863 | buf); | |
12864 | } | |
12865 | ||
12866 | grc_mode = tr32(GRC_MODE); | |
12867 | tw32(GRC_MODE, grc_mode & ~GRC_MODE_NVRAM_WR_ENABLE); | |
12868 | ||
e6af301b | 12869 | tg3_disable_nvram_access(tp); |
1da177e4 LT |
12870 | tg3_nvram_unlock(tp); |
12871 | } | |
12872 | ||
63c3a66f | 12873 | if (tg3_flag(tp, EEPROM_WRITE_PROT)) { |
314fba34 | 12874 | tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl); |
1da177e4 LT |
12875 | udelay(40); |
12876 | } | |
12877 | ||
12878 | return ret; | |
12879 | } | |
12880 | ||
12881 | struct subsys_tbl_ent { | |
12882 | u16 subsys_vendor, subsys_devid; | |
12883 | u32 phy_id; | |
12884 | }; | |
12885 | ||
24daf2b0 | 12886 | static struct subsys_tbl_ent subsys_id_to_phy_id[] __devinitdata = { |
1da177e4 | 12887 | /* Broadcom boards. */ |
24daf2b0 | 12888 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
79eb6904 | 12889 | TG3PCI_SUBDEVICE_ID_BROADCOM_95700A6, TG3_PHY_ID_BCM5401 }, |
24daf2b0 | 12890 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
79eb6904 | 12891 | TG3PCI_SUBDEVICE_ID_BROADCOM_95701A5, TG3_PHY_ID_BCM5701 }, |
24daf2b0 | 12892 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
79eb6904 | 12893 | TG3PCI_SUBDEVICE_ID_BROADCOM_95700T6, TG3_PHY_ID_BCM8002 }, |
24daf2b0 MC |
12894 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
12895 | TG3PCI_SUBDEVICE_ID_BROADCOM_95700A9, 0 }, | |
12896 | { TG3PCI_SUBVENDOR_ID_BROADCOM, | |
79eb6904 | 12897 | TG3PCI_SUBDEVICE_ID_BROADCOM_95701T1, TG3_PHY_ID_BCM5701 }, |
24daf2b0 | 12898 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
79eb6904 | 12899 | TG3PCI_SUBDEVICE_ID_BROADCOM_95701T8, TG3_PHY_ID_BCM5701 }, |
24daf2b0 MC |
12900 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
12901 | TG3PCI_SUBDEVICE_ID_BROADCOM_95701A7, 0 }, | |
12902 | { TG3PCI_SUBVENDOR_ID_BROADCOM, | |
79eb6904 | 12903 | TG3PCI_SUBDEVICE_ID_BROADCOM_95701A10, TG3_PHY_ID_BCM5701 }, |
24daf2b0 | 12904 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
79eb6904 | 12905 | TG3PCI_SUBDEVICE_ID_BROADCOM_95701A12, TG3_PHY_ID_BCM5701 }, |
24daf2b0 | 12906 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
79eb6904 | 12907 | TG3PCI_SUBDEVICE_ID_BROADCOM_95703AX1, TG3_PHY_ID_BCM5703 }, |
24daf2b0 | 12908 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
79eb6904 | 12909 | TG3PCI_SUBDEVICE_ID_BROADCOM_95703AX2, TG3_PHY_ID_BCM5703 }, |
1da177e4 LT |
12910 | |
12911 | /* 3com boards. */ | |
24daf2b0 | 12912 | { TG3PCI_SUBVENDOR_ID_3COM, |
79eb6904 | 12913 | TG3PCI_SUBDEVICE_ID_3COM_3C996T, TG3_PHY_ID_BCM5401 }, |
24daf2b0 | 12914 | { TG3PCI_SUBVENDOR_ID_3COM, |
79eb6904 | 12915 | TG3PCI_SUBDEVICE_ID_3COM_3C996BT, TG3_PHY_ID_BCM5701 }, |
24daf2b0 MC |
12916 | { TG3PCI_SUBVENDOR_ID_3COM, |
12917 | TG3PCI_SUBDEVICE_ID_3COM_3C996SX, 0 }, | |
12918 | { TG3PCI_SUBVENDOR_ID_3COM, | |
79eb6904 | 12919 | TG3PCI_SUBDEVICE_ID_3COM_3C1000T, TG3_PHY_ID_BCM5701 }, |
24daf2b0 | 12920 | { TG3PCI_SUBVENDOR_ID_3COM, |
79eb6904 | 12921 | TG3PCI_SUBDEVICE_ID_3COM_3C940BR01, TG3_PHY_ID_BCM5701 }, |
1da177e4 LT |
12922 | |
12923 | /* DELL boards. */ | |
24daf2b0 | 12924 | { TG3PCI_SUBVENDOR_ID_DELL, |
79eb6904 | 12925 | TG3PCI_SUBDEVICE_ID_DELL_VIPER, TG3_PHY_ID_BCM5401 }, |
24daf2b0 | 12926 | { TG3PCI_SUBVENDOR_ID_DELL, |
79eb6904 | 12927 | TG3PCI_SUBDEVICE_ID_DELL_JAGUAR, TG3_PHY_ID_BCM5401 }, |
24daf2b0 | 12928 | { TG3PCI_SUBVENDOR_ID_DELL, |
79eb6904 | 12929 | TG3PCI_SUBDEVICE_ID_DELL_MERLOT, TG3_PHY_ID_BCM5411 }, |
24daf2b0 | 12930 | { TG3PCI_SUBVENDOR_ID_DELL, |
79eb6904 | 12931 | TG3PCI_SUBDEVICE_ID_DELL_SLIM_MERLOT, TG3_PHY_ID_BCM5411 }, |
1da177e4 LT |
12932 | |
12933 | /* Compaq boards. */ | |
24daf2b0 | 12934 | { TG3PCI_SUBVENDOR_ID_COMPAQ, |
79eb6904 | 12935 | TG3PCI_SUBDEVICE_ID_COMPAQ_BANSHEE, TG3_PHY_ID_BCM5701 }, |
24daf2b0 | 12936 | { TG3PCI_SUBVENDOR_ID_COMPAQ, |
79eb6904 | 12937 | TG3PCI_SUBDEVICE_ID_COMPAQ_BANSHEE_2, TG3_PHY_ID_BCM5701 }, |
24daf2b0 MC |
12938 | { TG3PCI_SUBVENDOR_ID_COMPAQ, |
12939 | TG3PCI_SUBDEVICE_ID_COMPAQ_CHANGELING, 0 }, | |
12940 | { TG3PCI_SUBVENDOR_ID_COMPAQ, | |
79eb6904 | 12941 | TG3PCI_SUBDEVICE_ID_COMPAQ_NC7780, TG3_PHY_ID_BCM5701 }, |
24daf2b0 | 12942 | { TG3PCI_SUBVENDOR_ID_COMPAQ, |
79eb6904 | 12943 | TG3PCI_SUBDEVICE_ID_COMPAQ_NC7780_2, TG3_PHY_ID_BCM5701 }, |
1da177e4 LT |
12944 | |
12945 | /* IBM boards. */ | |
24daf2b0 MC |
12946 | { TG3PCI_SUBVENDOR_ID_IBM, |
12947 | TG3PCI_SUBDEVICE_ID_IBM_5703SAX2, 0 } | |
1da177e4 LT |
12948 | }; |
12949 | ||
24daf2b0 | 12950 | static struct subsys_tbl_ent * __devinit tg3_lookup_by_subsys(struct tg3 *tp) |
1da177e4 LT |
12951 | { |
12952 | int i; | |
12953 | ||
12954 | for (i = 0; i < ARRAY_SIZE(subsys_id_to_phy_id); i++) { | |
12955 | if ((subsys_id_to_phy_id[i].subsys_vendor == | |
12956 | tp->pdev->subsystem_vendor) && | |
12957 | (subsys_id_to_phy_id[i].subsys_devid == | |
12958 | tp->pdev->subsystem_device)) | |
12959 | return &subsys_id_to_phy_id[i]; | |
12960 | } | |
12961 | return NULL; | |
12962 | } | |
12963 | ||
7d0c41ef | 12964 | static void __devinit tg3_get_eeprom_hw_cfg(struct tg3 *tp) |
1da177e4 | 12965 | { |
1da177e4 | 12966 | u32 val; |
f49639e6 | 12967 | |
79eb6904 | 12968 | tp->phy_id = TG3_PHY_ID_INVALID; |
7d0c41ef MC |
12969 | tp->led_ctrl = LED_CTRL_MODE_PHY_1; |
12970 | ||
a85feb8c | 12971 | /* Assume an onboard device and WOL capable by default. */ |
63c3a66f JP |
12972 | tg3_flag_set(tp, EEPROM_WRITE_PROT); |
12973 | tg3_flag_set(tp, WOL_CAP); | |
72b845e0 | 12974 | |
b5d3772c | 12975 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
9d26e213 | 12976 | if (!(tr32(PCIE_TRANSACTION_CFG) & PCIE_TRANS_CFG_LOM)) { |
63c3a66f JP |
12977 | tg3_flag_clear(tp, EEPROM_WRITE_PROT); |
12978 | tg3_flag_set(tp, IS_NIC); | |
9d26e213 | 12979 | } |
0527ba35 MC |
12980 | val = tr32(VCPU_CFGSHDW); |
12981 | if (val & VCPU_CFGSHDW_ASPM_DBNC) | |
63c3a66f | 12982 | tg3_flag_set(tp, ASPM_WORKAROUND); |
0527ba35 | 12983 | if ((val & VCPU_CFGSHDW_WOL_ENABLE) && |
6fdbab9d | 12984 | (val & VCPU_CFGSHDW_WOL_MAGPKT)) { |
63c3a66f | 12985 | tg3_flag_set(tp, WOL_ENABLE); |
6fdbab9d RW |
12986 | device_set_wakeup_enable(&tp->pdev->dev, true); |
12987 | } | |
05ac4cb7 | 12988 | goto done; |
b5d3772c MC |
12989 | } |
12990 | ||
1da177e4 LT |
12991 | tg3_read_mem(tp, NIC_SRAM_DATA_SIG, &val); |
12992 | if (val == NIC_SRAM_DATA_SIG_MAGIC) { | |
12993 | u32 nic_cfg, led_cfg; | |
a9daf367 | 12994 | u32 nic_phy_id, ver, cfg2 = 0, cfg4 = 0, eeprom_phy_id; |
7d0c41ef | 12995 | int eeprom_phy_serdes = 0; |
1da177e4 LT |
12996 | |
12997 | tg3_read_mem(tp, NIC_SRAM_DATA_CFG, &nic_cfg); | |
12998 | tp->nic_sram_data_cfg = nic_cfg; | |
12999 | ||
13000 | tg3_read_mem(tp, NIC_SRAM_DATA_VER, &ver); | |
13001 | ver >>= NIC_SRAM_DATA_VER_SHIFT; | |
6ff6f81d MC |
13002 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 && |
13003 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701 && | |
13004 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5703 && | |
1da177e4 LT |
13005 | (ver > 0) && (ver < 0x100)) |
13006 | tg3_read_mem(tp, NIC_SRAM_DATA_CFG_2, &cfg2); | |
13007 | ||
a9daf367 MC |
13008 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) |
13009 | tg3_read_mem(tp, NIC_SRAM_DATA_CFG_4, &cfg4); | |
13010 | ||
1da177e4 LT |
13011 | if ((nic_cfg & NIC_SRAM_DATA_CFG_PHY_TYPE_MASK) == |
13012 | NIC_SRAM_DATA_CFG_PHY_TYPE_FIBER) | |
13013 | eeprom_phy_serdes = 1; | |
13014 | ||
13015 | tg3_read_mem(tp, NIC_SRAM_DATA_PHY_ID, &nic_phy_id); | |
13016 | if (nic_phy_id != 0) { | |
13017 | u32 id1 = nic_phy_id & NIC_SRAM_DATA_PHY_ID1_MASK; | |
13018 | u32 id2 = nic_phy_id & NIC_SRAM_DATA_PHY_ID2_MASK; | |
13019 | ||
13020 | eeprom_phy_id = (id1 >> 16) << 10; | |
13021 | eeprom_phy_id |= (id2 & 0xfc00) << 16; | |
13022 | eeprom_phy_id |= (id2 & 0x03ff) << 0; | |
13023 | } else | |
13024 | eeprom_phy_id = 0; | |
13025 | ||
7d0c41ef | 13026 | tp->phy_id = eeprom_phy_id; |
747e8f8b | 13027 | if (eeprom_phy_serdes) { |
63c3a66f | 13028 | if (!tg3_flag(tp, 5705_PLUS)) |
f07e9af3 | 13029 | tp->phy_flags |= TG3_PHYFLG_PHY_SERDES; |
a50d0796 | 13030 | else |
f07e9af3 | 13031 | tp->phy_flags |= TG3_PHYFLG_MII_SERDES; |
747e8f8b | 13032 | } |
7d0c41ef | 13033 | |
63c3a66f | 13034 | if (tg3_flag(tp, 5750_PLUS)) |
1da177e4 LT |
13035 | led_cfg = cfg2 & (NIC_SRAM_DATA_CFG_LED_MODE_MASK | |
13036 | SHASTA_EXT_LED_MODE_MASK); | |
cbf46853 | 13037 | else |
1da177e4 LT |
13038 | led_cfg = nic_cfg & NIC_SRAM_DATA_CFG_LED_MODE_MASK; |
13039 | ||
13040 | switch (led_cfg) { | |
13041 | default: | |
13042 | case NIC_SRAM_DATA_CFG_LED_MODE_PHY_1: | |
13043 | tp->led_ctrl = LED_CTRL_MODE_PHY_1; | |
13044 | break; | |
13045 | ||
13046 | case NIC_SRAM_DATA_CFG_LED_MODE_PHY_2: | |
13047 | tp->led_ctrl = LED_CTRL_MODE_PHY_2; | |
13048 | break; | |
13049 | ||
13050 | case NIC_SRAM_DATA_CFG_LED_MODE_MAC: | |
13051 | tp->led_ctrl = LED_CTRL_MODE_MAC; | |
9ba27794 MC |
13052 | |
13053 | /* Default to PHY_1_MODE if 0 (MAC_MODE) is | |
13054 | * read on some older 5700/5701 bootcode. | |
13055 | */ | |
13056 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == | |
13057 | ASIC_REV_5700 || | |
13058 | GET_ASIC_REV(tp->pci_chip_rev_id) == | |
13059 | ASIC_REV_5701) | |
13060 | tp->led_ctrl = LED_CTRL_MODE_PHY_1; | |
13061 | ||
1da177e4 LT |
13062 | break; |
13063 | ||
13064 | case SHASTA_EXT_LED_SHARED: | |
13065 | tp->led_ctrl = LED_CTRL_MODE_SHARED; | |
13066 | if (tp->pci_chip_rev_id != CHIPREV_ID_5750_A0 && | |
13067 | tp->pci_chip_rev_id != CHIPREV_ID_5750_A1) | |
13068 | tp->led_ctrl |= (LED_CTRL_MODE_PHY_1 | | |
13069 | LED_CTRL_MODE_PHY_2); | |
13070 | break; | |
13071 | ||
13072 | case SHASTA_EXT_LED_MAC: | |
13073 | tp->led_ctrl = LED_CTRL_MODE_SHASTA_MAC; | |
13074 | break; | |
13075 | ||
13076 | case SHASTA_EXT_LED_COMBO: | |
13077 | tp->led_ctrl = LED_CTRL_MODE_COMBO; | |
13078 | if (tp->pci_chip_rev_id != CHIPREV_ID_5750_A0) | |
13079 | tp->led_ctrl |= (LED_CTRL_MODE_PHY_1 | | |
13080 | LED_CTRL_MODE_PHY_2); | |
13081 | break; | |
13082 | ||
855e1111 | 13083 | } |
1da177e4 LT |
13084 | |
13085 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || | |
13086 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) && | |
13087 | tp->pdev->subsystem_vendor == PCI_VENDOR_ID_DELL) | |
13088 | tp->led_ctrl = LED_CTRL_MODE_PHY_2; | |
13089 | ||
b2a5c19c MC |
13090 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5784_AX) |
13091 | tp->led_ctrl = LED_CTRL_MODE_PHY_1; | |
5f60891b | 13092 | |
9d26e213 | 13093 | if (nic_cfg & NIC_SRAM_DATA_CFG_EEPROM_WP) { |
63c3a66f | 13094 | tg3_flag_set(tp, EEPROM_WRITE_PROT); |
9d26e213 MC |
13095 | if ((tp->pdev->subsystem_vendor == |
13096 | PCI_VENDOR_ID_ARIMA) && | |
13097 | (tp->pdev->subsystem_device == 0x205a || | |
13098 | tp->pdev->subsystem_device == 0x2063)) | |
63c3a66f | 13099 | tg3_flag_clear(tp, EEPROM_WRITE_PROT); |
9d26e213 | 13100 | } else { |
63c3a66f JP |
13101 | tg3_flag_clear(tp, EEPROM_WRITE_PROT); |
13102 | tg3_flag_set(tp, IS_NIC); | |
9d26e213 | 13103 | } |
1da177e4 LT |
13104 | |
13105 | if (nic_cfg & NIC_SRAM_DATA_CFG_ASF_ENABLE) { | |
63c3a66f JP |
13106 | tg3_flag_set(tp, ENABLE_ASF); |
13107 | if (tg3_flag(tp, 5750_PLUS)) | |
13108 | tg3_flag_set(tp, ASF_NEW_HANDSHAKE); | |
1da177e4 | 13109 | } |
b2b98d4a MC |
13110 | |
13111 | if ((nic_cfg & NIC_SRAM_DATA_CFG_APE_ENABLE) && | |
63c3a66f JP |
13112 | tg3_flag(tp, 5750_PLUS)) |
13113 | tg3_flag_set(tp, ENABLE_APE); | |
b2b98d4a | 13114 | |
f07e9af3 | 13115 | if (tp->phy_flags & TG3_PHYFLG_ANY_SERDES && |
a85feb8c | 13116 | !(nic_cfg & NIC_SRAM_DATA_CFG_FIBER_WOL)) |
63c3a66f | 13117 | tg3_flag_clear(tp, WOL_CAP); |
1da177e4 | 13118 | |
63c3a66f | 13119 | if (tg3_flag(tp, WOL_CAP) && |
6fdbab9d | 13120 | (nic_cfg & NIC_SRAM_DATA_CFG_WOL_ENABLE)) { |
63c3a66f | 13121 | tg3_flag_set(tp, WOL_ENABLE); |
6fdbab9d RW |
13122 | device_set_wakeup_enable(&tp->pdev->dev, true); |
13123 | } | |
0527ba35 | 13124 | |
1da177e4 | 13125 | if (cfg2 & (1 << 17)) |
f07e9af3 | 13126 | tp->phy_flags |= TG3_PHYFLG_CAPACITIVE_COUPLING; |
1da177e4 LT |
13127 | |
13128 | /* serdes signal pre-emphasis in register 0x590 set by */ | |
13129 | /* bootcode if bit 18 is set */ | |
13130 | if (cfg2 & (1 << 18)) | |
f07e9af3 | 13131 | tp->phy_flags |= TG3_PHYFLG_SERDES_PREEMPHASIS; |
8ed5d97e | 13132 | |
63c3a66f JP |
13133 | if ((tg3_flag(tp, 57765_PLUS) || |
13134 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 && | |
13135 | GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5784_AX)) && | |
6833c043 | 13136 | (cfg2 & NIC_SRAM_DATA_CFG_2_APD_EN)) |
f07e9af3 | 13137 | tp->phy_flags |= TG3_PHYFLG_ENABLE_APD; |
6833c043 | 13138 | |
63c3a66f | 13139 | if (tg3_flag(tp, PCI_EXPRESS) && |
8c69b1e7 | 13140 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5785 && |
63c3a66f | 13141 | !tg3_flag(tp, 57765_PLUS)) { |
8ed5d97e MC |
13142 | u32 cfg3; |
13143 | ||
13144 | tg3_read_mem(tp, NIC_SRAM_DATA_CFG_3, &cfg3); | |
13145 | if (cfg3 & NIC_SRAM_ASPM_DEBOUNCE) | |
63c3a66f | 13146 | tg3_flag_set(tp, ASPM_WORKAROUND); |
8ed5d97e | 13147 | } |
a9daf367 | 13148 | |
14417063 | 13149 | if (cfg4 & NIC_SRAM_RGMII_INBAND_DISABLE) |
63c3a66f | 13150 | tg3_flag_set(tp, RGMII_INBAND_DISABLE); |
a9daf367 | 13151 | if (cfg4 & NIC_SRAM_RGMII_EXT_IBND_RX_EN) |
63c3a66f | 13152 | tg3_flag_set(tp, RGMII_EXT_IBND_RX_EN); |
a9daf367 | 13153 | if (cfg4 & NIC_SRAM_RGMII_EXT_IBND_TX_EN) |
63c3a66f | 13154 | tg3_flag_set(tp, RGMII_EXT_IBND_TX_EN); |
1da177e4 | 13155 | } |
05ac4cb7 | 13156 | done: |
63c3a66f | 13157 | if (tg3_flag(tp, WOL_CAP)) |
43067ed8 | 13158 | device_set_wakeup_enable(&tp->pdev->dev, |
63c3a66f | 13159 | tg3_flag(tp, WOL_ENABLE)); |
43067ed8 RW |
13160 | else |
13161 | device_set_wakeup_capable(&tp->pdev->dev, false); | |
7d0c41ef MC |
13162 | } |
13163 | ||
b2a5c19c MC |
13164 | static int __devinit tg3_issue_otp_command(struct tg3 *tp, u32 cmd) |
13165 | { | |
13166 | int i; | |
13167 | u32 val; | |
13168 | ||
13169 | tw32(OTP_CTRL, cmd | OTP_CTRL_OTP_CMD_START); | |
13170 | tw32(OTP_CTRL, cmd); | |
13171 | ||
13172 | /* Wait for up to 1 ms for command to execute. */ | |
13173 | for (i = 0; i < 100; i++) { | |
13174 | val = tr32(OTP_STATUS); | |
13175 | if (val & OTP_STATUS_CMD_DONE) | |
13176 | break; | |
13177 | udelay(10); | |
13178 | } | |
13179 | ||
13180 | return (val & OTP_STATUS_CMD_DONE) ? 0 : -EBUSY; | |
13181 | } | |
13182 | ||
13183 | /* Read the gphy configuration from the OTP region of the chip. The gphy | |
13184 | * configuration is a 32-bit value that straddles the alignment boundary. | |
13185 | * We do two 32-bit reads and then shift and merge the results. | |
13186 | */ | |
13187 | static u32 __devinit tg3_read_otp_phycfg(struct tg3 *tp) | |
13188 | { | |
13189 | u32 bhalf_otp, thalf_otp; | |
13190 | ||
13191 | tw32(OTP_MODE, OTP_MODE_OTP_THRU_GRC); | |
13192 | ||
13193 | if (tg3_issue_otp_command(tp, OTP_CTRL_OTP_CMD_INIT)) | |
13194 | return 0; | |
13195 | ||
13196 | tw32(OTP_ADDRESS, OTP_ADDRESS_MAGIC1); | |
13197 | ||
13198 | if (tg3_issue_otp_command(tp, OTP_CTRL_OTP_CMD_READ)) | |
13199 | return 0; | |
13200 | ||
13201 | thalf_otp = tr32(OTP_READ_DATA); | |
13202 | ||
13203 | tw32(OTP_ADDRESS, OTP_ADDRESS_MAGIC2); | |
13204 | ||
13205 | if (tg3_issue_otp_command(tp, OTP_CTRL_OTP_CMD_READ)) | |
13206 | return 0; | |
13207 | ||
13208 | bhalf_otp = tr32(OTP_READ_DATA); | |
13209 | ||
13210 | return ((thalf_otp & 0x0000ffff) << 16) | (bhalf_otp >> 16); | |
13211 | } | |
13212 | ||
e256f8a3 MC |
13213 | static void __devinit tg3_phy_init_link_config(struct tg3 *tp) |
13214 | { | |
13215 | u32 adv = ADVERTISED_Autoneg | | |
13216 | ADVERTISED_Pause; | |
13217 | ||
13218 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) | |
13219 | adv |= ADVERTISED_1000baseT_Half | | |
13220 | ADVERTISED_1000baseT_Full; | |
13221 | ||
13222 | if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) | |
13223 | adv |= ADVERTISED_100baseT_Half | | |
13224 | ADVERTISED_100baseT_Full | | |
13225 | ADVERTISED_10baseT_Half | | |
13226 | ADVERTISED_10baseT_Full | | |
13227 | ADVERTISED_TP; | |
13228 | else | |
13229 | adv |= ADVERTISED_FIBRE; | |
13230 | ||
13231 | tp->link_config.advertising = adv; | |
13232 | tp->link_config.speed = SPEED_INVALID; | |
13233 | tp->link_config.duplex = DUPLEX_INVALID; | |
13234 | tp->link_config.autoneg = AUTONEG_ENABLE; | |
13235 | tp->link_config.active_speed = SPEED_INVALID; | |
13236 | tp->link_config.active_duplex = DUPLEX_INVALID; | |
13237 | tp->link_config.orig_speed = SPEED_INVALID; | |
13238 | tp->link_config.orig_duplex = DUPLEX_INVALID; | |
13239 | tp->link_config.orig_autoneg = AUTONEG_INVALID; | |
13240 | } | |
13241 | ||
7d0c41ef MC |
13242 | static int __devinit tg3_phy_probe(struct tg3 *tp) |
13243 | { | |
13244 | u32 hw_phy_id_1, hw_phy_id_2; | |
13245 | u32 hw_phy_id, hw_phy_id_masked; | |
13246 | int err; | |
1da177e4 | 13247 | |
e256f8a3 | 13248 | /* flow control autonegotiation is default behavior */ |
63c3a66f | 13249 | tg3_flag_set(tp, PAUSE_AUTONEG); |
e256f8a3 MC |
13250 | tp->link_config.flowctrl = FLOW_CTRL_TX | FLOW_CTRL_RX; |
13251 | ||
63c3a66f | 13252 | if (tg3_flag(tp, USE_PHYLIB)) |
b02fd9e3 MC |
13253 | return tg3_phy_init(tp); |
13254 | ||
1da177e4 | 13255 | /* Reading the PHY ID register can conflict with ASF |
877d0310 | 13256 | * firmware access to the PHY hardware. |
1da177e4 LT |
13257 | */ |
13258 | err = 0; | |
63c3a66f | 13259 | if (tg3_flag(tp, ENABLE_ASF) || tg3_flag(tp, ENABLE_APE)) { |
79eb6904 | 13260 | hw_phy_id = hw_phy_id_masked = TG3_PHY_ID_INVALID; |
1da177e4 LT |
13261 | } else { |
13262 | /* Now read the physical PHY_ID from the chip and verify | |
13263 | * that it is sane. If it doesn't look good, we fall back | |
13264 | * to either the hard-coded table based PHY_ID and failing | |
13265 | * that the value found in the eeprom area. | |
13266 | */ | |
13267 | err |= tg3_readphy(tp, MII_PHYSID1, &hw_phy_id_1); | |
13268 | err |= tg3_readphy(tp, MII_PHYSID2, &hw_phy_id_2); | |
13269 | ||
13270 | hw_phy_id = (hw_phy_id_1 & 0xffff) << 10; | |
13271 | hw_phy_id |= (hw_phy_id_2 & 0xfc00) << 16; | |
13272 | hw_phy_id |= (hw_phy_id_2 & 0x03ff) << 0; | |
13273 | ||
79eb6904 | 13274 | hw_phy_id_masked = hw_phy_id & TG3_PHY_ID_MASK; |
1da177e4 LT |
13275 | } |
13276 | ||
79eb6904 | 13277 | if (!err && TG3_KNOWN_PHY_ID(hw_phy_id_masked)) { |
1da177e4 | 13278 | tp->phy_id = hw_phy_id; |
79eb6904 | 13279 | if (hw_phy_id_masked == TG3_PHY_ID_BCM8002) |
f07e9af3 | 13280 | tp->phy_flags |= TG3_PHYFLG_PHY_SERDES; |
da6b2d01 | 13281 | else |
f07e9af3 | 13282 | tp->phy_flags &= ~TG3_PHYFLG_PHY_SERDES; |
1da177e4 | 13283 | } else { |
79eb6904 | 13284 | if (tp->phy_id != TG3_PHY_ID_INVALID) { |
7d0c41ef MC |
13285 | /* Do nothing, phy ID already set up in |
13286 | * tg3_get_eeprom_hw_cfg(). | |
13287 | */ | |
1da177e4 LT |
13288 | } else { |
13289 | struct subsys_tbl_ent *p; | |
13290 | ||
13291 | /* No eeprom signature? Try the hardcoded | |
13292 | * subsys device table. | |
13293 | */ | |
24daf2b0 | 13294 | p = tg3_lookup_by_subsys(tp); |
1da177e4 LT |
13295 | if (!p) |
13296 | return -ENODEV; | |
13297 | ||
13298 | tp->phy_id = p->phy_id; | |
13299 | if (!tp->phy_id || | |
79eb6904 | 13300 | tp->phy_id == TG3_PHY_ID_BCM8002) |
f07e9af3 | 13301 | tp->phy_flags |= TG3_PHYFLG_PHY_SERDES; |
1da177e4 LT |
13302 | } |
13303 | } | |
13304 | ||
a6b68dab | 13305 | if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES) && |
5baa5e9a MC |
13306 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719 || |
13307 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720 || | |
13308 | (tp->pdev->device == TG3PCI_DEVICE_TIGON3_5718 && | |
a6b68dab MC |
13309 | tp->pci_chip_rev_id != CHIPREV_ID_5717_A0) || |
13310 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765 && | |
13311 | tp->pci_chip_rev_id != CHIPREV_ID_57765_A0))) | |
52b02d04 MC |
13312 | tp->phy_flags |= TG3_PHYFLG_EEE_CAP; |
13313 | ||
e256f8a3 MC |
13314 | tg3_phy_init_link_config(tp); |
13315 | ||
f07e9af3 | 13316 | if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES) && |
63c3a66f JP |
13317 | !tg3_flag(tp, ENABLE_APE) && |
13318 | !tg3_flag(tp, ENABLE_ASF)) { | |
42b64a45 | 13319 | u32 bmsr, mask; |
1da177e4 LT |
13320 | |
13321 | tg3_readphy(tp, MII_BMSR, &bmsr); | |
13322 | if (!tg3_readphy(tp, MII_BMSR, &bmsr) && | |
13323 | (bmsr & BMSR_LSTATUS)) | |
13324 | goto skip_phy_reset; | |
6aa20a22 | 13325 | |
1da177e4 LT |
13326 | err = tg3_phy_reset(tp); |
13327 | if (err) | |
13328 | return err; | |
13329 | ||
42b64a45 | 13330 | tg3_phy_set_wirespeed(tp); |
1da177e4 | 13331 | |
3600d918 MC |
13332 | mask = (ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full | |
13333 | ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full | | |
13334 | ADVERTISED_1000baseT_Half | ADVERTISED_1000baseT_Full); | |
13335 | if (!tg3_copper_is_advertising_all(tp, mask)) { | |
42b64a45 MC |
13336 | tg3_phy_autoneg_cfg(tp, tp->link_config.advertising, |
13337 | tp->link_config.flowctrl); | |
1da177e4 LT |
13338 | |
13339 | tg3_writephy(tp, MII_BMCR, | |
13340 | BMCR_ANENABLE | BMCR_ANRESTART); | |
13341 | } | |
1da177e4 LT |
13342 | } |
13343 | ||
13344 | skip_phy_reset: | |
79eb6904 | 13345 | if ((tp->phy_id & TG3_PHY_ID_MASK) == TG3_PHY_ID_BCM5401) { |
1da177e4 LT |
13346 | err = tg3_init_5401phy_dsp(tp); |
13347 | if (err) | |
13348 | return err; | |
1da177e4 | 13349 | |
1da177e4 LT |
13350 | err = tg3_init_5401phy_dsp(tp); |
13351 | } | |
13352 | ||
1da177e4 LT |
13353 | return err; |
13354 | } | |
13355 | ||
184b8904 | 13356 | static void __devinit tg3_read_vpd(struct tg3 *tp) |
1da177e4 | 13357 | { |
a4a8bb15 | 13358 | u8 *vpd_data; |
4181b2c8 | 13359 | unsigned int block_end, rosize, len; |
535a490e | 13360 | u32 vpdlen; |
184b8904 | 13361 | int j, i = 0; |
a4a8bb15 | 13362 | |
535a490e | 13363 | vpd_data = (u8 *)tg3_vpd_readblock(tp, &vpdlen); |
a4a8bb15 MC |
13364 | if (!vpd_data) |
13365 | goto out_no_vpd; | |
1da177e4 | 13366 | |
535a490e | 13367 | i = pci_vpd_find_tag(vpd_data, 0, vpdlen, PCI_VPD_LRDT_RO_DATA); |
4181b2c8 MC |
13368 | if (i < 0) |
13369 | goto out_not_found; | |
1da177e4 | 13370 | |
4181b2c8 MC |
13371 | rosize = pci_vpd_lrdt_size(&vpd_data[i]); |
13372 | block_end = i + PCI_VPD_LRDT_TAG_SIZE + rosize; | |
13373 | i += PCI_VPD_LRDT_TAG_SIZE; | |
1da177e4 | 13374 | |
535a490e | 13375 | if (block_end > vpdlen) |
4181b2c8 | 13376 | goto out_not_found; |
af2c6a4a | 13377 | |
184b8904 MC |
13378 | j = pci_vpd_find_info_keyword(vpd_data, i, rosize, |
13379 | PCI_VPD_RO_KEYWORD_MFR_ID); | |
13380 | if (j > 0) { | |
13381 | len = pci_vpd_info_field_size(&vpd_data[j]); | |
13382 | ||
13383 | j += PCI_VPD_INFO_FLD_HDR_SIZE; | |
13384 | if (j + len > block_end || len != 4 || | |
13385 | memcmp(&vpd_data[j], "1028", 4)) | |
13386 | goto partno; | |
13387 | ||
13388 | j = pci_vpd_find_info_keyword(vpd_data, i, rosize, | |
13389 | PCI_VPD_RO_KEYWORD_VENDOR0); | |
13390 | if (j < 0) | |
13391 | goto partno; | |
13392 | ||
13393 | len = pci_vpd_info_field_size(&vpd_data[j]); | |
13394 | ||
13395 | j += PCI_VPD_INFO_FLD_HDR_SIZE; | |
13396 | if (j + len > block_end) | |
13397 | goto partno; | |
13398 | ||
13399 | memcpy(tp->fw_ver, &vpd_data[j], len); | |
535a490e | 13400 | strncat(tp->fw_ver, " bc ", vpdlen - len - 1); |
184b8904 MC |
13401 | } |
13402 | ||
13403 | partno: | |
4181b2c8 MC |
13404 | i = pci_vpd_find_info_keyword(vpd_data, i, rosize, |
13405 | PCI_VPD_RO_KEYWORD_PARTNO); | |
13406 | if (i < 0) | |
13407 | goto out_not_found; | |
af2c6a4a | 13408 | |
4181b2c8 | 13409 | len = pci_vpd_info_field_size(&vpd_data[i]); |
1da177e4 | 13410 | |
4181b2c8 MC |
13411 | i += PCI_VPD_INFO_FLD_HDR_SIZE; |
13412 | if (len > TG3_BPN_SIZE || | |
535a490e | 13413 | (len + i) > vpdlen) |
4181b2c8 | 13414 | goto out_not_found; |
1da177e4 | 13415 | |
4181b2c8 | 13416 | memcpy(tp->board_part_number, &vpd_data[i], len); |
1da177e4 | 13417 | |
1da177e4 | 13418 | out_not_found: |
a4a8bb15 | 13419 | kfree(vpd_data); |
37a949c5 | 13420 | if (tp->board_part_number[0]) |
a4a8bb15 MC |
13421 | return; |
13422 | ||
13423 | out_no_vpd: | |
37a949c5 MC |
13424 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717) { |
13425 | if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_5717) | |
13426 | strcpy(tp->board_part_number, "BCM5717"); | |
13427 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_5718) | |
13428 | strcpy(tp->board_part_number, "BCM5718"); | |
13429 | else | |
13430 | goto nomatch; | |
13431 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) { | |
13432 | if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57780) | |
13433 | strcpy(tp->board_part_number, "BCM57780"); | |
13434 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57760) | |
13435 | strcpy(tp->board_part_number, "BCM57760"); | |
13436 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57790) | |
13437 | strcpy(tp->board_part_number, "BCM57790"); | |
13438 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57788) | |
13439 | strcpy(tp->board_part_number, "BCM57788"); | |
13440 | else | |
13441 | goto nomatch; | |
13442 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) { | |
13443 | if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57761) | |
13444 | strcpy(tp->board_part_number, "BCM57761"); | |
13445 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57765) | |
13446 | strcpy(tp->board_part_number, "BCM57765"); | |
13447 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57781) | |
13448 | strcpy(tp->board_part_number, "BCM57781"); | |
13449 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57785) | |
13450 | strcpy(tp->board_part_number, "BCM57785"); | |
13451 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57791) | |
13452 | strcpy(tp->board_part_number, "BCM57791"); | |
13453 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57795) | |
13454 | strcpy(tp->board_part_number, "BCM57795"); | |
13455 | else | |
13456 | goto nomatch; | |
13457 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { | |
b5d3772c | 13458 | strcpy(tp->board_part_number, "BCM95906"); |
37a949c5 MC |
13459 | } else { |
13460 | nomatch: | |
b5d3772c | 13461 | strcpy(tp->board_part_number, "none"); |
37a949c5 | 13462 | } |
1da177e4 LT |
13463 | } |
13464 | ||
9c8a620e MC |
13465 | static int __devinit tg3_fw_img_is_valid(struct tg3 *tp, u32 offset) |
13466 | { | |
13467 | u32 val; | |
13468 | ||
e4f34110 | 13469 | if (tg3_nvram_read(tp, offset, &val) || |
9c8a620e | 13470 | (val & 0xfc000000) != 0x0c000000 || |
e4f34110 | 13471 | tg3_nvram_read(tp, offset + 4, &val) || |
9c8a620e MC |
13472 | val != 0) |
13473 | return 0; | |
13474 | ||
13475 | return 1; | |
13476 | } | |
13477 | ||
acd9c119 MC |
13478 | static void __devinit tg3_read_bc_ver(struct tg3 *tp) |
13479 | { | |
ff3a7cb2 | 13480 | u32 val, offset, start, ver_offset; |
75f9936e | 13481 | int i, dst_off; |
ff3a7cb2 | 13482 | bool newver = false; |
acd9c119 MC |
13483 | |
13484 | if (tg3_nvram_read(tp, 0xc, &offset) || | |
13485 | tg3_nvram_read(tp, 0x4, &start)) | |
13486 | return; | |
13487 | ||
13488 | offset = tg3_nvram_logical_addr(tp, offset); | |
13489 | ||
ff3a7cb2 | 13490 | if (tg3_nvram_read(tp, offset, &val)) |
acd9c119 MC |
13491 | return; |
13492 | ||
ff3a7cb2 MC |
13493 | if ((val & 0xfc000000) == 0x0c000000) { |
13494 | if (tg3_nvram_read(tp, offset + 4, &val)) | |
acd9c119 MC |
13495 | return; |
13496 | ||
ff3a7cb2 MC |
13497 | if (val == 0) |
13498 | newver = true; | |
13499 | } | |
13500 | ||
75f9936e MC |
13501 | dst_off = strlen(tp->fw_ver); |
13502 | ||
ff3a7cb2 | 13503 | if (newver) { |
75f9936e MC |
13504 | if (TG3_VER_SIZE - dst_off < 16 || |
13505 | tg3_nvram_read(tp, offset + 8, &ver_offset)) | |
ff3a7cb2 MC |
13506 | return; |
13507 | ||
13508 | offset = offset + ver_offset - start; | |
13509 | for (i = 0; i < 16; i += 4) { | |
13510 | __be32 v; | |
13511 | if (tg3_nvram_read_be32(tp, offset + i, &v)) | |
13512 | return; | |
13513 | ||
75f9936e | 13514 | memcpy(tp->fw_ver + dst_off + i, &v, sizeof(v)); |
ff3a7cb2 MC |
13515 | } |
13516 | } else { | |
13517 | u32 major, minor; | |
13518 | ||
13519 | if (tg3_nvram_read(tp, TG3_NVM_PTREV_BCVER, &ver_offset)) | |
13520 | return; | |
13521 | ||
13522 | major = (ver_offset & TG3_NVM_BCVER_MAJMSK) >> | |
13523 | TG3_NVM_BCVER_MAJSFT; | |
13524 | minor = ver_offset & TG3_NVM_BCVER_MINMSK; | |
75f9936e MC |
13525 | snprintf(&tp->fw_ver[dst_off], TG3_VER_SIZE - dst_off, |
13526 | "v%d.%02d", major, minor); | |
acd9c119 MC |
13527 | } |
13528 | } | |
13529 | ||
a6f6cb1c MC |
13530 | static void __devinit tg3_read_hwsb_ver(struct tg3 *tp) |
13531 | { | |
13532 | u32 val, major, minor; | |
13533 | ||
13534 | /* Use native endian representation */ | |
13535 | if (tg3_nvram_read(tp, TG3_NVM_HWSB_CFG1, &val)) | |
13536 | return; | |
13537 | ||
13538 | major = (val & TG3_NVM_HWSB_CFG1_MAJMSK) >> | |
13539 | TG3_NVM_HWSB_CFG1_MAJSFT; | |
13540 | minor = (val & TG3_NVM_HWSB_CFG1_MINMSK) >> | |
13541 | TG3_NVM_HWSB_CFG1_MINSFT; | |
13542 | ||
13543 | snprintf(&tp->fw_ver[0], 32, "sb v%d.%02d", major, minor); | |
13544 | } | |
13545 | ||
dfe00d7d MC |
13546 | static void __devinit tg3_read_sb_ver(struct tg3 *tp, u32 val) |
13547 | { | |
13548 | u32 offset, major, minor, build; | |
13549 | ||
75f9936e | 13550 | strncat(tp->fw_ver, "sb", TG3_VER_SIZE - strlen(tp->fw_ver) - 1); |
dfe00d7d MC |
13551 | |
13552 | if ((val & TG3_EEPROM_SB_FORMAT_MASK) != TG3_EEPROM_SB_FORMAT_1) | |
13553 | return; | |
13554 | ||
13555 | switch (val & TG3_EEPROM_SB_REVISION_MASK) { | |
13556 | case TG3_EEPROM_SB_REVISION_0: | |
13557 | offset = TG3_EEPROM_SB_F1R0_EDH_OFF; | |
13558 | break; | |
13559 | case TG3_EEPROM_SB_REVISION_2: | |
13560 | offset = TG3_EEPROM_SB_F1R2_EDH_OFF; | |
13561 | break; | |
13562 | case TG3_EEPROM_SB_REVISION_3: | |
13563 | offset = TG3_EEPROM_SB_F1R3_EDH_OFF; | |
13564 | break; | |
a4153d40 MC |
13565 | case TG3_EEPROM_SB_REVISION_4: |
13566 | offset = TG3_EEPROM_SB_F1R4_EDH_OFF; | |
13567 | break; | |
13568 | case TG3_EEPROM_SB_REVISION_5: | |
13569 | offset = TG3_EEPROM_SB_F1R5_EDH_OFF; | |
13570 | break; | |
bba226ac MC |
13571 | case TG3_EEPROM_SB_REVISION_6: |
13572 | offset = TG3_EEPROM_SB_F1R6_EDH_OFF; | |
13573 | break; | |
dfe00d7d MC |
13574 | default: |
13575 | return; | |
13576 | } | |
13577 | ||
e4f34110 | 13578 | if (tg3_nvram_read(tp, offset, &val)) |
dfe00d7d MC |
13579 | return; |
13580 | ||
13581 | build = (val & TG3_EEPROM_SB_EDH_BLD_MASK) >> | |
13582 | TG3_EEPROM_SB_EDH_BLD_SHFT; | |
13583 | major = (val & TG3_EEPROM_SB_EDH_MAJ_MASK) >> | |
13584 | TG3_EEPROM_SB_EDH_MAJ_SHFT; | |
13585 | minor = val & TG3_EEPROM_SB_EDH_MIN_MASK; | |
13586 | ||
13587 | if (minor > 99 || build > 26) | |
13588 | return; | |
13589 | ||
75f9936e MC |
13590 | offset = strlen(tp->fw_ver); |
13591 | snprintf(&tp->fw_ver[offset], TG3_VER_SIZE - offset, | |
13592 | " v%d.%02d", major, minor); | |
dfe00d7d MC |
13593 | |
13594 | if (build > 0) { | |
75f9936e MC |
13595 | offset = strlen(tp->fw_ver); |
13596 | if (offset < TG3_VER_SIZE - 1) | |
13597 | tp->fw_ver[offset] = 'a' + build - 1; | |
dfe00d7d MC |
13598 | } |
13599 | } | |
13600 | ||
acd9c119 | 13601 | static void __devinit tg3_read_mgmtfw_ver(struct tg3 *tp) |
c4e6575c MC |
13602 | { |
13603 | u32 val, offset, start; | |
acd9c119 | 13604 | int i, vlen; |
9c8a620e MC |
13605 | |
13606 | for (offset = TG3_NVM_DIR_START; | |
13607 | offset < TG3_NVM_DIR_END; | |
13608 | offset += TG3_NVM_DIRENT_SIZE) { | |
e4f34110 | 13609 | if (tg3_nvram_read(tp, offset, &val)) |
c4e6575c MC |
13610 | return; |
13611 | ||
9c8a620e MC |
13612 | if ((val >> TG3_NVM_DIRTYPE_SHIFT) == TG3_NVM_DIRTYPE_ASFINI) |
13613 | break; | |
13614 | } | |
13615 | ||
13616 | if (offset == TG3_NVM_DIR_END) | |
13617 | return; | |
13618 | ||
63c3a66f | 13619 | if (!tg3_flag(tp, 5705_PLUS)) |
9c8a620e | 13620 | start = 0x08000000; |
e4f34110 | 13621 | else if (tg3_nvram_read(tp, offset - 4, &start)) |
9c8a620e MC |
13622 | return; |
13623 | ||
e4f34110 | 13624 | if (tg3_nvram_read(tp, offset + 4, &offset) || |
9c8a620e | 13625 | !tg3_fw_img_is_valid(tp, offset) || |
e4f34110 | 13626 | tg3_nvram_read(tp, offset + 8, &val)) |
9c8a620e MC |
13627 | return; |
13628 | ||
13629 | offset += val - start; | |
13630 | ||
acd9c119 | 13631 | vlen = strlen(tp->fw_ver); |
9c8a620e | 13632 | |
acd9c119 MC |
13633 | tp->fw_ver[vlen++] = ','; |
13634 | tp->fw_ver[vlen++] = ' '; | |
9c8a620e MC |
13635 | |
13636 | for (i = 0; i < 4; i++) { | |
a9dc529d MC |
13637 | __be32 v; |
13638 | if (tg3_nvram_read_be32(tp, offset, &v)) | |
c4e6575c MC |
13639 | return; |
13640 | ||
b9fc7dc5 | 13641 | offset += sizeof(v); |
c4e6575c | 13642 | |
acd9c119 MC |
13643 | if (vlen > TG3_VER_SIZE - sizeof(v)) { |
13644 | memcpy(&tp->fw_ver[vlen], &v, TG3_VER_SIZE - vlen); | |
9c8a620e | 13645 | break; |
c4e6575c | 13646 | } |
9c8a620e | 13647 | |
acd9c119 MC |
13648 | memcpy(&tp->fw_ver[vlen], &v, sizeof(v)); |
13649 | vlen += sizeof(v); | |
c4e6575c | 13650 | } |
acd9c119 MC |
13651 | } |
13652 | ||
7fd76445 MC |
13653 | static void __devinit tg3_read_dash_ver(struct tg3 *tp) |
13654 | { | |
13655 | int vlen; | |
13656 | u32 apedata; | |
ecc79648 | 13657 | char *fwtype; |
7fd76445 | 13658 | |
63c3a66f | 13659 | if (!tg3_flag(tp, ENABLE_APE) || !tg3_flag(tp, ENABLE_ASF)) |
7fd76445 MC |
13660 | return; |
13661 | ||
13662 | apedata = tg3_ape_read32(tp, TG3_APE_SEG_SIG); | |
13663 | if (apedata != APE_SEG_SIG_MAGIC) | |
13664 | return; | |
13665 | ||
13666 | apedata = tg3_ape_read32(tp, TG3_APE_FW_STATUS); | |
13667 | if (!(apedata & APE_FW_STATUS_READY)) | |
13668 | return; | |
13669 | ||
13670 | apedata = tg3_ape_read32(tp, TG3_APE_FW_VERSION); | |
13671 | ||
dc6d0744 | 13672 | if (tg3_ape_read32(tp, TG3_APE_FW_FEATURES) & TG3_APE_FW_FEATURE_NCSI) { |
63c3a66f | 13673 | tg3_flag_set(tp, APE_HAS_NCSI); |
ecc79648 | 13674 | fwtype = "NCSI"; |
dc6d0744 | 13675 | } else { |
ecc79648 | 13676 | fwtype = "DASH"; |
dc6d0744 | 13677 | } |
ecc79648 | 13678 | |
7fd76445 MC |
13679 | vlen = strlen(tp->fw_ver); |
13680 | ||
ecc79648 MC |
13681 | snprintf(&tp->fw_ver[vlen], TG3_VER_SIZE - vlen, " %s v%d.%d.%d.%d", |
13682 | fwtype, | |
7fd76445 MC |
13683 | (apedata & APE_FW_VERSION_MAJMSK) >> APE_FW_VERSION_MAJSFT, |
13684 | (apedata & APE_FW_VERSION_MINMSK) >> APE_FW_VERSION_MINSFT, | |
13685 | (apedata & APE_FW_VERSION_REVMSK) >> APE_FW_VERSION_REVSFT, | |
13686 | (apedata & APE_FW_VERSION_BLDMSK)); | |
13687 | } | |
13688 | ||
acd9c119 MC |
13689 | static void __devinit tg3_read_fw_ver(struct tg3 *tp) |
13690 | { | |
13691 | u32 val; | |
75f9936e | 13692 | bool vpd_vers = false; |
acd9c119 | 13693 | |
75f9936e MC |
13694 | if (tp->fw_ver[0] != 0) |
13695 | vpd_vers = true; | |
df259d8c | 13696 | |
63c3a66f | 13697 | if (tg3_flag(tp, NO_NVRAM)) { |
75f9936e | 13698 | strcat(tp->fw_ver, "sb"); |
df259d8c MC |
13699 | return; |
13700 | } | |
13701 | ||
acd9c119 MC |
13702 | if (tg3_nvram_read(tp, 0, &val)) |
13703 | return; | |
13704 | ||
13705 | if (val == TG3_EEPROM_MAGIC) | |
13706 | tg3_read_bc_ver(tp); | |
13707 | else if ((val & TG3_EEPROM_MAGIC_FW_MSK) == TG3_EEPROM_MAGIC_FW) | |
13708 | tg3_read_sb_ver(tp, val); | |
a6f6cb1c MC |
13709 | else if ((val & TG3_EEPROM_MAGIC_HW_MSK) == TG3_EEPROM_MAGIC_HW) |
13710 | tg3_read_hwsb_ver(tp); | |
acd9c119 MC |
13711 | else |
13712 | return; | |
13713 | ||
c9cab24e | 13714 | if (vpd_vers) |
75f9936e | 13715 | goto done; |
acd9c119 | 13716 | |
c9cab24e MC |
13717 | if (tg3_flag(tp, ENABLE_APE)) { |
13718 | if (tg3_flag(tp, ENABLE_ASF)) | |
13719 | tg3_read_dash_ver(tp); | |
13720 | } else if (tg3_flag(tp, ENABLE_ASF)) { | |
13721 | tg3_read_mgmtfw_ver(tp); | |
13722 | } | |
9c8a620e | 13723 | |
75f9936e | 13724 | done: |
9c8a620e | 13725 | tp->fw_ver[TG3_VER_SIZE - 1] = 0; |
c4e6575c MC |
13726 | } |
13727 | ||
7544b097 MC |
13728 | static struct pci_dev * __devinit tg3_find_peer(struct tg3 *); |
13729 | ||
7cb32cf2 MC |
13730 | static inline u32 tg3_rx_ret_ring_size(struct tg3 *tp) |
13731 | { | |
63c3a66f | 13732 | if (tg3_flag(tp, LRG_PROD_RING_CAP)) |
de9f5230 | 13733 | return TG3_RX_RET_MAX_SIZE_5717; |
63c3a66f | 13734 | else if (tg3_flag(tp, JUMBO_CAPABLE) && !tg3_flag(tp, 5780_CLASS)) |
de9f5230 | 13735 | return TG3_RX_RET_MAX_SIZE_5700; |
7cb32cf2 | 13736 | else |
de9f5230 | 13737 | return TG3_RX_RET_MAX_SIZE_5705; |
7cb32cf2 MC |
13738 | } |
13739 | ||
4143470c | 13740 | static DEFINE_PCI_DEVICE_TABLE(tg3_write_reorder_chipsets) = { |
895950c2 JP |
13741 | { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_FE_GATE_700C) }, |
13742 | { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8131_BRIDGE) }, | |
13743 | { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8385_0) }, | |
13744 | { }, | |
13745 | }; | |
13746 | ||
1da177e4 LT |
13747 | static int __devinit tg3_get_invariants(struct tg3 *tp) |
13748 | { | |
1da177e4 | 13749 | u32 misc_ctrl_reg; |
1da177e4 LT |
13750 | u32 pci_state_reg, grc_misc_cfg; |
13751 | u32 val; | |
13752 | u16 pci_cmd; | |
5e7dfd0f | 13753 | int err; |
1da177e4 | 13754 | |
1da177e4 LT |
13755 | /* Force memory write invalidate off. If we leave it on, |
13756 | * then on 5700_BX chips we have to enable a workaround. | |
13757 | * The workaround is to set the TG3PCI_DMA_RW_CTRL boundary | |
13758 | * to match the cacheline size. The Broadcom driver have this | |
13759 | * workaround but turns MWI off all the times so never uses | |
13760 | * it. This seems to suggest that the workaround is insufficient. | |
13761 | */ | |
13762 | pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd); | |
13763 | pci_cmd &= ~PCI_COMMAND_INVALIDATE; | |
13764 | pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd); | |
13765 | ||
16821285 MC |
13766 | /* Important! -- Make sure register accesses are byteswapped |
13767 | * correctly. Also, for those chips that require it, make | |
13768 | * sure that indirect register accesses are enabled before | |
13769 | * the first operation. | |
1da177e4 LT |
13770 | */ |
13771 | pci_read_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL, | |
13772 | &misc_ctrl_reg); | |
16821285 MC |
13773 | tp->misc_host_ctrl |= (misc_ctrl_reg & |
13774 | MISC_HOST_CTRL_CHIPREV); | |
13775 | pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL, | |
13776 | tp->misc_host_ctrl); | |
1da177e4 LT |
13777 | |
13778 | tp->pci_chip_rev_id = (misc_ctrl_reg >> | |
13779 | MISC_HOST_CTRL_CHIPREV_SHIFT); | |
795d01c5 MC |
13780 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_USE_PROD_ID_REG) { |
13781 | u32 prod_id_asic_rev; | |
13782 | ||
5001e2f6 MC |
13783 | if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_5717 || |
13784 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5718 || | |
d78b59f5 MC |
13785 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5719 || |
13786 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5720) | |
f6eb9b1f MC |
13787 | pci_read_config_dword(tp->pdev, |
13788 | TG3PCI_GEN2_PRODID_ASICREV, | |
13789 | &prod_id_asic_rev); | |
b703df6f MC |
13790 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57781 || |
13791 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57785 || | |
13792 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57761 || | |
13793 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57765 || | |
13794 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57791 || | |
13795 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57795) | |
13796 | pci_read_config_dword(tp->pdev, | |
13797 | TG3PCI_GEN15_PRODID_ASICREV, | |
13798 | &prod_id_asic_rev); | |
f6eb9b1f MC |
13799 | else |
13800 | pci_read_config_dword(tp->pdev, TG3PCI_PRODID_ASICREV, | |
13801 | &prod_id_asic_rev); | |
13802 | ||
321d32a0 | 13803 | tp->pci_chip_rev_id = prod_id_asic_rev; |
795d01c5 | 13804 | } |
1da177e4 | 13805 | |
ff645bec MC |
13806 | /* Wrong chip ID in 5752 A0. This code can be removed later |
13807 | * as A0 is not in production. | |
13808 | */ | |
13809 | if (tp->pci_chip_rev_id == CHIPREV_ID_5752_A0_HW) | |
13810 | tp->pci_chip_rev_id = CHIPREV_ID_5752_A0; | |
13811 | ||
6892914f MC |
13812 | /* If we have 5702/03 A1 or A2 on certain ICH chipsets, |
13813 | * we need to disable memory and use config. cycles | |
13814 | * only to access all registers. The 5702/03 chips | |
13815 | * can mistakenly decode the special cycles from the | |
13816 | * ICH chipsets as memory write cycles, causing corruption | |
13817 | * of register and memory space. Only certain ICH bridges | |
13818 | * will drive special cycles with non-zero data during the | |
13819 | * address phase which can fall within the 5703's address | |
13820 | * range. This is not an ICH bug as the PCI spec allows | |
13821 | * non-zero address during special cycles. However, only | |
13822 | * these ICH bridges are known to drive non-zero addresses | |
13823 | * during special cycles. | |
13824 | * | |
13825 | * Since special cycles do not cross PCI bridges, we only | |
13826 | * enable this workaround if the 5703 is on the secondary | |
13827 | * bus of these ICH bridges. | |
13828 | */ | |
13829 | if ((tp->pci_chip_rev_id == CHIPREV_ID_5703_A1) || | |
13830 | (tp->pci_chip_rev_id == CHIPREV_ID_5703_A2)) { | |
13831 | static struct tg3_dev_id { | |
13832 | u32 vendor; | |
13833 | u32 device; | |
13834 | u32 rev; | |
13835 | } ich_chipsets[] = { | |
13836 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AA_8, | |
13837 | PCI_ANY_ID }, | |
13838 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AB_8, | |
13839 | PCI_ANY_ID }, | |
13840 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_11, | |
13841 | 0xa }, | |
13842 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_6, | |
13843 | PCI_ANY_ID }, | |
13844 | { }, | |
13845 | }; | |
13846 | struct tg3_dev_id *pci_id = &ich_chipsets[0]; | |
13847 | struct pci_dev *bridge = NULL; | |
13848 | ||
13849 | while (pci_id->vendor != 0) { | |
13850 | bridge = pci_get_device(pci_id->vendor, pci_id->device, | |
13851 | bridge); | |
13852 | if (!bridge) { | |
13853 | pci_id++; | |
13854 | continue; | |
13855 | } | |
13856 | if (pci_id->rev != PCI_ANY_ID) { | |
44c10138 | 13857 | if (bridge->revision > pci_id->rev) |
6892914f MC |
13858 | continue; |
13859 | } | |
13860 | if (bridge->subordinate && | |
13861 | (bridge->subordinate->number == | |
13862 | tp->pdev->bus->number)) { | |
63c3a66f | 13863 | tg3_flag_set(tp, ICH_WORKAROUND); |
6892914f MC |
13864 | pci_dev_put(bridge); |
13865 | break; | |
13866 | } | |
13867 | } | |
13868 | } | |
13869 | ||
6ff6f81d | 13870 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) { |
41588ba1 MC |
13871 | static struct tg3_dev_id { |
13872 | u32 vendor; | |
13873 | u32 device; | |
13874 | } bridge_chipsets[] = { | |
13875 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PXH_0 }, | |
13876 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PXH_1 }, | |
13877 | { }, | |
13878 | }; | |
13879 | struct tg3_dev_id *pci_id = &bridge_chipsets[0]; | |
13880 | struct pci_dev *bridge = NULL; | |
13881 | ||
13882 | while (pci_id->vendor != 0) { | |
13883 | bridge = pci_get_device(pci_id->vendor, | |
13884 | pci_id->device, | |
13885 | bridge); | |
13886 | if (!bridge) { | |
13887 | pci_id++; | |
13888 | continue; | |
13889 | } | |
13890 | if (bridge->subordinate && | |
13891 | (bridge->subordinate->number <= | |
13892 | tp->pdev->bus->number) && | |
13893 | (bridge->subordinate->subordinate >= | |
13894 | tp->pdev->bus->number)) { | |
63c3a66f | 13895 | tg3_flag_set(tp, 5701_DMA_BUG); |
41588ba1 MC |
13896 | pci_dev_put(bridge); |
13897 | break; | |
13898 | } | |
13899 | } | |
13900 | } | |
13901 | ||
4a29cc2e MC |
13902 | /* The EPB bridge inside 5714, 5715, and 5780 cannot support |
13903 | * DMA addresses > 40-bit. This bridge may have other additional | |
13904 | * 57xx devices behind it in some 4-port NIC designs for example. | |
13905 | * Any tg3 device found behind the bridge will also need the 40-bit | |
13906 | * DMA workaround. | |
13907 | */ | |
a4e2b347 MC |
13908 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780 || |
13909 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) { | |
63c3a66f JP |
13910 | tg3_flag_set(tp, 5780_CLASS); |
13911 | tg3_flag_set(tp, 40BIT_DMA_BUG); | |
4cf78e4f | 13912 | tp->msi_cap = pci_find_capability(tp->pdev, PCI_CAP_ID_MSI); |
859a5887 | 13913 | } else { |
4a29cc2e MC |
13914 | struct pci_dev *bridge = NULL; |
13915 | ||
13916 | do { | |
13917 | bridge = pci_get_device(PCI_VENDOR_ID_SERVERWORKS, | |
13918 | PCI_DEVICE_ID_SERVERWORKS_EPB, | |
13919 | bridge); | |
13920 | if (bridge && bridge->subordinate && | |
13921 | (bridge->subordinate->number <= | |
13922 | tp->pdev->bus->number) && | |
13923 | (bridge->subordinate->subordinate >= | |
13924 | tp->pdev->bus->number)) { | |
63c3a66f | 13925 | tg3_flag_set(tp, 40BIT_DMA_BUG); |
4a29cc2e MC |
13926 | pci_dev_put(bridge); |
13927 | break; | |
13928 | } | |
13929 | } while (bridge); | |
13930 | } | |
4cf78e4f | 13931 | |
f6eb9b1f | 13932 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 || |
3a1e19d3 | 13933 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) |
7544b097 MC |
13934 | tp->pdev_peer = tg3_find_peer(tp); |
13935 | ||
c885e824 | 13936 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
d78b59f5 MC |
13937 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719 || |
13938 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) | |
63c3a66f | 13939 | tg3_flag_set(tp, 5717_PLUS); |
0a58d668 MC |
13940 | |
13941 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765 || | |
63c3a66f JP |
13942 | tg3_flag(tp, 5717_PLUS)) |
13943 | tg3_flag_set(tp, 57765_PLUS); | |
c885e824 | 13944 | |
321d32a0 MC |
13945 | /* Intentionally exclude ASIC_REV_5906 */ |
13946 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 || | |
d9ab5ad1 | 13947 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 || |
d30cdd28 | 13948 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 || |
9936bcf6 | 13949 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761 || |
57e6983c | 13950 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 || |
f6eb9b1f | 13951 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780 || |
63c3a66f JP |
13952 | tg3_flag(tp, 57765_PLUS)) |
13953 | tg3_flag_set(tp, 5755_PLUS); | |
321d32a0 MC |
13954 | |
13955 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750 || | |
13956 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 || | |
b5d3772c | 13957 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906 || |
63c3a66f JP |
13958 | tg3_flag(tp, 5755_PLUS) || |
13959 | tg3_flag(tp, 5780_CLASS)) | |
13960 | tg3_flag_set(tp, 5750_PLUS); | |
6708e5cc | 13961 | |
6ff6f81d | 13962 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 || |
63c3a66f JP |
13963 | tg3_flag(tp, 5750_PLUS)) |
13964 | tg3_flag_set(tp, 5705_PLUS); | |
1b440c56 | 13965 | |
507399f1 | 13966 | /* Determine TSO capabilities */ |
a0512944 | 13967 | if (tp->pci_chip_rev_id == CHIPREV_ID_5719_A0) |
4d163b75 | 13968 | ; /* Do nothing. HW bug. */ |
63c3a66f JP |
13969 | else if (tg3_flag(tp, 57765_PLUS)) |
13970 | tg3_flag_set(tp, HW_TSO_3); | |
13971 | else if (tg3_flag(tp, 5755_PLUS) || | |
e849cdc3 | 13972 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) |
63c3a66f JP |
13973 | tg3_flag_set(tp, HW_TSO_2); |
13974 | else if (tg3_flag(tp, 5750_PLUS)) { | |
13975 | tg3_flag_set(tp, HW_TSO_1); | |
13976 | tg3_flag_set(tp, TSO_BUG); | |
507399f1 MC |
13977 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750 && |
13978 | tp->pci_chip_rev_id >= CHIPREV_ID_5750_C2) | |
63c3a66f | 13979 | tg3_flag_clear(tp, TSO_BUG); |
507399f1 MC |
13980 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 && |
13981 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701 && | |
13982 | tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) { | |
63c3a66f | 13983 | tg3_flag_set(tp, TSO_BUG); |
507399f1 MC |
13984 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) |
13985 | tp->fw_needed = FIRMWARE_TG3TSO5; | |
13986 | else | |
13987 | tp->fw_needed = FIRMWARE_TG3TSO; | |
13988 | } | |
13989 | ||
dabc5c67 | 13990 | /* Selectively allow TSO based on operating conditions */ |
6ff6f81d MC |
13991 | if (tg3_flag(tp, HW_TSO_1) || |
13992 | tg3_flag(tp, HW_TSO_2) || | |
13993 | tg3_flag(tp, HW_TSO_3) || | |
dabc5c67 MC |
13994 | (tp->fw_needed && !tg3_flag(tp, ENABLE_ASF))) |
13995 | tg3_flag_set(tp, TSO_CAPABLE); | |
13996 | else { | |
13997 | tg3_flag_clear(tp, TSO_CAPABLE); | |
13998 | tg3_flag_clear(tp, TSO_BUG); | |
13999 | tp->fw_needed = NULL; | |
14000 | } | |
14001 | ||
14002 | if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0) | |
14003 | tp->fw_needed = FIRMWARE_TG3; | |
14004 | ||
507399f1 MC |
14005 | tp->irq_max = 1; |
14006 | ||
63c3a66f JP |
14007 | if (tg3_flag(tp, 5750_PLUS)) { |
14008 | tg3_flag_set(tp, SUPPORT_MSI); | |
7544b097 MC |
14009 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_AX || |
14010 | GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_BX || | |
14011 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714 && | |
14012 | tp->pci_chip_rev_id <= CHIPREV_ID_5714_A2 && | |
14013 | tp->pdev_peer == tp->pdev)) | |
63c3a66f | 14014 | tg3_flag_clear(tp, SUPPORT_MSI); |
7544b097 | 14015 | |
63c3a66f | 14016 | if (tg3_flag(tp, 5755_PLUS) || |
b5d3772c | 14017 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
63c3a66f | 14018 | tg3_flag_set(tp, 1SHOT_MSI); |
52c0fd83 | 14019 | } |
4f125f42 | 14020 | |
63c3a66f JP |
14021 | if (tg3_flag(tp, 57765_PLUS)) { |
14022 | tg3_flag_set(tp, SUPPORT_MSIX); | |
507399f1 MC |
14023 | tp->irq_max = TG3_IRQ_MAX_VECS; |
14024 | } | |
f6eb9b1f | 14025 | } |
0e1406dd | 14026 | |
2ffcc981 | 14027 | if (tg3_flag(tp, 5755_PLUS)) |
63c3a66f | 14028 | tg3_flag_set(tp, SHORT_DMA_BUG); |
f6eb9b1f | 14029 | |
e31aa987 MC |
14030 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719) |
14031 | tg3_flag_set(tp, 4K_FIFO_LIMIT); | |
14032 | ||
63c3a66f JP |
14033 | if (tg3_flag(tp, 5717_PLUS)) |
14034 | tg3_flag_set(tp, LRG_PROD_RING_CAP); | |
de9f5230 | 14035 | |
63c3a66f | 14036 | if (tg3_flag(tp, 57765_PLUS) && |
a0512944 | 14037 | tp->pci_chip_rev_id != CHIPREV_ID_5719_A0) |
63c3a66f | 14038 | tg3_flag_set(tp, USE_JUMBO_BDFLAG); |
b703df6f | 14039 | |
63c3a66f JP |
14040 | if (!tg3_flag(tp, 5705_PLUS) || |
14041 | tg3_flag(tp, 5780_CLASS) || | |
14042 | tg3_flag(tp, USE_JUMBO_BDFLAG)) | |
14043 | tg3_flag_set(tp, JUMBO_CAPABLE); | |
0f893dc6 | 14044 | |
52f4490c MC |
14045 | pci_read_config_dword(tp->pdev, TG3PCI_PCISTATE, |
14046 | &pci_state_reg); | |
14047 | ||
708ebb3a | 14048 | if (pci_is_pcie(tp->pdev)) { |
5e7dfd0f MC |
14049 | u16 lnkctl; |
14050 | ||
63c3a66f | 14051 | tg3_flag_set(tp, PCI_EXPRESS); |
5f5c51e3 | 14052 | |
cf79003d | 14053 | tp->pcie_readrq = 4096; |
d78b59f5 MC |
14054 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719 || |
14055 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) | |
b4495ed8 | 14056 | tp->pcie_readrq = 2048; |
cf79003d MC |
14057 | |
14058 | pcie_set_readrq(tp->pdev, tp->pcie_readrq); | |
5f5c51e3 | 14059 | |
5e7dfd0f | 14060 | pci_read_config_word(tp->pdev, |
708ebb3a | 14061 | pci_pcie_cap(tp->pdev) + PCI_EXP_LNKCTL, |
5e7dfd0f MC |
14062 | &lnkctl); |
14063 | if (lnkctl & PCI_EXP_LNKCTL_CLKREQ_EN) { | |
7196cd6c MC |
14064 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == |
14065 | ASIC_REV_5906) { | |
63c3a66f | 14066 | tg3_flag_clear(tp, HW_TSO_2); |
dabc5c67 | 14067 | tg3_flag_clear(tp, TSO_CAPABLE); |
7196cd6c | 14068 | } |
5e7dfd0f | 14069 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 || |
321d32a0 | 14070 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761 || |
9cf74ebb MC |
14071 | tp->pci_chip_rev_id == CHIPREV_ID_57780_A0 || |
14072 | tp->pci_chip_rev_id == CHIPREV_ID_57780_A1) | |
63c3a66f | 14073 | tg3_flag_set(tp, CLKREQ_BUG); |
614b0590 | 14074 | } else if (tp->pci_chip_rev_id == CHIPREV_ID_5717_A0) { |
63c3a66f | 14075 | tg3_flag_set(tp, L1PLLPD_EN); |
c7835a77 | 14076 | } |
52f4490c | 14077 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) { |
708ebb3a JM |
14078 | /* BCM5785 devices are effectively PCIe devices, and should |
14079 | * follow PCIe codepaths, but do not have a PCIe capabilities | |
14080 | * section. | |
14081 | */ | |
63c3a66f JP |
14082 | tg3_flag_set(tp, PCI_EXPRESS); |
14083 | } else if (!tg3_flag(tp, 5705_PLUS) || | |
14084 | tg3_flag(tp, 5780_CLASS)) { | |
52f4490c MC |
14085 | tp->pcix_cap = pci_find_capability(tp->pdev, PCI_CAP_ID_PCIX); |
14086 | if (!tp->pcix_cap) { | |
2445e461 MC |
14087 | dev_err(&tp->pdev->dev, |
14088 | "Cannot find PCI-X capability, aborting\n"); | |
52f4490c MC |
14089 | return -EIO; |
14090 | } | |
14091 | ||
14092 | if (!(pci_state_reg & PCISTATE_CONV_PCI_MODE)) | |
63c3a66f | 14093 | tg3_flag_set(tp, PCIX_MODE); |
52f4490c | 14094 | } |
1da177e4 | 14095 | |
399de50b MC |
14096 | /* If we have an AMD 762 or VIA K8T800 chipset, write |
14097 | * reordering to the mailbox registers done by the host | |
14098 | * controller can cause major troubles. We read back from | |
14099 | * every mailbox register write to force the writes to be | |
14100 | * posted to the chip in order. | |
14101 | */ | |
4143470c | 14102 | if (pci_dev_present(tg3_write_reorder_chipsets) && |
63c3a66f JP |
14103 | !tg3_flag(tp, PCI_EXPRESS)) |
14104 | tg3_flag_set(tp, MBOX_WRITE_REORDER); | |
399de50b | 14105 | |
69fc4053 MC |
14106 | pci_read_config_byte(tp->pdev, PCI_CACHE_LINE_SIZE, |
14107 | &tp->pci_cacheline_sz); | |
14108 | pci_read_config_byte(tp->pdev, PCI_LATENCY_TIMER, | |
14109 | &tp->pci_lat_timer); | |
1da177e4 LT |
14110 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 && |
14111 | tp->pci_lat_timer < 64) { | |
14112 | tp->pci_lat_timer = 64; | |
69fc4053 MC |
14113 | pci_write_config_byte(tp->pdev, PCI_LATENCY_TIMER, |
14114 | tp->pci_lat_timer); | |
1da177e4 LT |
14115 | } |
14116 | ||
16821285 MC |
14117 | /* Important! -- It is critical that the PCI-X hw workaround |
14118 | * situation is decided before the first MMIO register access. | |
14119 | */ | |
52f4490c MC |
14120 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5700_BX) { |
14121 | /* 5700 BX chips need to have their TX producer index | |
14122 | * mailboxes written twice to workaround a bug. | |
14123 | */ | |
63c3a66f | 14124 | tg3_flag_set(tp, TXD_MBOX_HWBUG); |
1da177e4 | 14125 | |
52f4490c | 14126 | /* If we are in PCI-X mode, enable register write workaround. |
1da177e4 LT |
14127 | * |
14128 | * The workaround is to use indirect register accesses | |
14129 | * for all chip writes not to mailbox registers. | |
14130 | */ | |
63c3a66f | 14131 | if (tg3_flag(tp, PCIX_MODE)) { |
1da177e4 | 14132 | u32 pm_reg; |
1da177e4 | 14133 | |
63c3a66f | 14134 | tg3_flag_set(tp, PCIX_TARGET_HWBUG); |
1da177e4 LT |
14135 | |
14136 | /* The chip can have it's power management PCI config | |
14137 | * space registers clobbered due to this bug. | |
14138 | * So explicitly force the chip into D0 here. | |
14139 | */ | |
9974a356 MC |
14140 | pci_read_config_dword(tp->pdev, |
14141 | tp->pm_cap + PCI_PM_CTRL, | |
1da177e4 LT |
14142 | &pm_reg); |
14143 | pm_reg &= ~PCI_PM_CTRL_STATE_MASK; | |
14144 | pm_reg |= PCI_PM_CTRL_PME_ENABLE | 0 /* D0 */; | |
9974a356 MC |
14145 | pci_write_config_dword(tp->pdev, |
14146 | tp->pm_cap + PCI_PM_CTRL, | |
1da177e4 LT |
14147 | pm_reg); |
14148 | ||
14149 | /* Also, force SERR#/PERR# in PCI command. */ | |
14150 | pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd); | |
14151 | pci_cmd |= PCI_COMMAND_PARITY | PCI_COMMAND_SERR; | |
14152 | pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd); | |
14153 | } | |
14154 | } | |
14155 | ||
1da177e4 | 14156 | if ((pci_state_reg & PCISTATE_BUS_SPEED_HIGH) != 0) |
63c3a66f | 14157 | tg3_flag_set(tp, PCI_HIGH_SPEED); |
1da177e4 | 14158 | if ((pci_state_reg & PCISTATE_BUS_32BIT) != 0) |
63c3a66f | 14159 | tg3_flag_set(tp, PCI_32BIT); |
1da177e4 LT |
14160 | |
14161 | /* Chip-specific fixup from Broadcom driver */ | |
14162 | if ((tp->pci_chip_rev_id == CHIPREV_ID_5704_A0) && | |
14163 | (!(pci_state_reg & PCISTATE_RETRY_SAME_DMA))) { | |
14164 | pci_state_reg |= PCISTATE_RETRY_SAME_DMA; | |
14165 | pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE, pci_state_reg); | |
14166 | } | |
14167 | ||
1ee582d8 | 14168 | /* Default fast path register access methods */ |
20094930 | 14169 | tp->read32 = tg3_read32; |
1ee582d8 | 14170 | tp->write32 = tg3_write32; |
09ee929c | 14171 | tp->read32_mbox = tg3_read32; |
20094930 | 14172 | tp->write32_mbox = tg3_write32; |
1ee582d8 MC |
14173 | tp->write32_tx_mbox = tg3_write32; |
14174 | tp->write32_rx_mbox = tg3_write32; | |
14175 | ||
14176 | /* Various workaround register access methods */ | |
63c3a66f | 14177 | if (tg3_flag(tp, PCIX_TARGET_HWBUG)) |
1ee582d8 | 14178 | tp->write32 = tg3_write_indirect_reg32; |
98efd8a6 | 14179 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701 || |
63c3a66f | 14180 | (tg3_flag(tp, PCI_EXPRESS) && |
98efd8a6 MC |
14181 | tp->pci_chip_rev_id == CHIPREV_ID_5750_A0)) { |
14182 | /* | |
14183 | * Back to back register writes can cause problems on these | |
14184 | * chips, the workaround is to read back all reg writes | |
14185 | * except those to mailbox regs. | |
14186 | * | |
14187 | * See tg3_write_indirect_reg32(). | |
14188 | */ | |
1ee582d8 | 14189 | tp->write32 = tg3_write_flush_reg32; |
98efd8a6 MC |
14190 | } |
14191 | ||
63c3a66f | 14192 | if (tg3_flag(tp, TXD_MBOX_HWBUG) || tg3_flag(tp, MBOX_WRITE_REORDER)) { |
1ee582d8 | 14193 | tp->write32_tx_mbox = tg3_write32_tx_mbox; |
63c3a66f | 14194 | if (tg3_flag(tp, MBOX_WRITE_REORDER)) |
1ee582d8 MC |
14195 | tp->write32_rx_mbox = tg3_write_flush_reg32; |
14196 | } | |
20094930 | 14197 | |
63c3a66f | 14198 | if (tg3_flag(tp, ICH_WORKAROUND)) { |
6892914f MC |
14199 | tp->read32 = tg3_read_indirect_reg32; |
14200 | tp->write32 = tg3_write_indirect_reg32; | |
14201 | tp->read32_mbox = tg3_read_indirect_mbox; | |
14202 | tp->write32_mbox = tg3_write_indirect_mbox; | |
14203 | tp->write32_tx_mbox = tg3_write_indirect_mbox; | |
14204 | tp->write32_rx_mbox = tg3_write_indirect_mbox; | |
14205 | ||
14206 | iounmap(tp->regs); | |
22abe310 | 14207 | tp->regs = NULL; |
6892914f MC |
14208 | |
14209 | pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd); | |
14210 | pci_cmd &= ~PCI_COMMAND_MEMORY; | |
14211 | pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd); | |
14212 | } | |
b5d3772c MC |
14213 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
14214 | tp->read32_mbox = tg3_read32_mbox_5906; | |
14215 | tp->write32_mbox = tg3_write32_mbox_5906; | |
14216 | tp->write32_tx_mbox = tg3_write32_mbox_5906; | |
14217 | tp->write32_rx_mbox = tg3_write32_mbox_5906; | |
14218 | } | |
6892914f | 14219 | |
bbadf503 | 14220 | if (tp->write32 == tg3_write_indirect_reg32 || |
63c3a66f | 14221 | (tg3_flag(tp, PCIX_MODE) && |
bbadf503 | 14222 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
f49639e6 | 14223 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701))) |
63c3a66f | 14224 | tg3_flag_set(tp, SRAM_USE_CONFIG); |
bbadf503 | 14225 | |
16821285 MC |
14226 | /* The memory arbiter has to be enabled in order for SRAM accesses |
14227 | * to succeed. Normally on powerup the tg3 chip firmware will make | |
14228 | * sure it is enabled, but other entities such as system netboot | |
14229 | * code might disable it. | |
14230 | */ | |
14231 | val = tr32(MEMARB_MODE); | |
14232 | tw32(MEMARB_MODE, val | MEMARB_MODE_ENABLE); | |
14233 | ||
69f11c99 MC |
14234 | if (tg3_flag(tp, PCIX_MODE)) { |
14235 | pci_read_config_dword(tp->pdev, | |
14236 | tp->pcix_cap + PCI_X_STATUS, &val); | |
14237 | tp->pci_fn = val & 0x7; | |
14238 | } else { | |
14239 | tp->pci_fn = PCI_FUNC(tp->pdev->devfn) & 3; | |
14240 | } | |
14241 | ||
7d0c41ef | 14242 | /* Get eeprom hw config before calling tg3_set_power_state(). |
63c3a66f | 14243 | * In particular, the TG3_FLAG_IS_NIC flag must be |
7d0c41ef MC |
14244 | * determined before calling tg3_set_power_state() so that |
14245 | * we know whether or not to switch out of Vaux power. | |
14246 | * When the flag is set, it means that GPIO1 is used for eeprom | |
14247 | * write protect and also implies that it is a LOM where GPIOs | |
14248 | * are not used to switch power. | |
6aa20a22 | 14249 | */ |
7d0c41ef MC |
14250 | tg3_get_eeprom_hw_cfg(tp); |
14251 | ||
63c3a66f | 14252 | if (tg3_flag(tp, ENABLE_APE)) { |
0d3031d9 MC |
14253 | /* Allow reads and writes to the |
14254 | * APE register and memory space. | |
14255 | */ | |
14256 | pci_state_reg |= PCISTATE_ALLOW_APE_CTLSPC_WR | | |
f92d9dc1 MC |
14257 | PCISTATE_ALLOW_APE_SHMEM_WR | |
14258 | PCISTATE_ALLOW_APE_PSPACE_WR; | |
0d3031d9 MC |
14259 | pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE, |
14260 | pci_state_reg); | |
c9cab24e MC |
14261 | |
14262 | tg3_ape_lock_init(tp); | |
0d3031d9 MC |
14263 | } |
14264 | ||
9936bcf6 | 14265 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 || |
57e6983c | 14266 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761 || |
321d32a0 | 14267 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 || |
f6eb9b1f | 14268 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780 || |
63c3a66f JP |
14269 | tg3_flag(tp, 57765_PLUS)) |
14270 | tg3_flag_set(tp, CPMU_PRESENT); | |
d30cdd28 | 14271 | |
16821285 MC |
14272 | /* Set up tp->grc_local_ctrl before calling |
14273 | * tg3_pwrsrc_switch_to_vmain(). GPIO1 driven high | |
14274 | * will bring 5700's external PHY out of reset. | |
314fba34 MC |
14275 | * It is also used as eeprom write protect on LOMs. |
14276 | */ | |
14277 | tp->grc_local_ctrl = GRC_LCLCTRL_INT_ON_ATTN | GRC_LCLCTRL_AUTO_SEEPROM; | |
6ff6f81d | 14278 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
63c3a66f | 14279 | tg3_flag(tp, EEPROM_WRITE_PROT)) |
314fba34 MC |
14280 | tp->grc_local_ctrl |= (GRC_LCLCTRL_GPIO_OE1 | |
14281 | GRC_LCLCTRL_GPIO_OUTPUT1); | |
3e7d83bc MC |
14282 | /* Unused GPIO3 must be driven as output on 5752 because there |
14283 | * are no pull-up resistors on unused GPIO pins. | |
14284 | */ | |
14285 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752) | |
14286 | tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE3; | |
314fba34 | 14287 | |
321d32a0 | 14288 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 || |
cb4ed1fd MC |
14289 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780 || |
14290 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) | |
af36e6b6 MC |
14291 | tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_UART_SEL; |
14292 | ||
8d519ab2 MC |
14293 | if (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5761 || |
14294 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5761S) { | |
5f0c4a3c MC |
14295 | /* Turn off the debug UART. */ |
14296 | tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_UART_SEL; | |
63c3a66f | 14297 | if (tg3_flag(tp, IS_NIC)) |
5f0c4a3c MC |
14298 | /* Keep VMain power. */ |
14299 | tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE0 | | |
14300 | GRC_LCLCTRL_GPIO_OUTPUT0; | |
14301 | } | |
14302 | ||
16821285 MC |
14303 | /* Switch out of Vaux if it is a NIC */ |
14304 | tg3_pwrsrc_switch_to_vmain(tp); | |
1da177e4 | 14305 | |
1da177e4 LT |
14306 | /* Derive initial jumbo mode from MTU assigned in |
14307 | * ether_setup() via the alloc_etherdev() call | |
14308 | */ | |
63c3a66f JP |
14309 | if (tp->dev->mtu > ETH_DATA_LEN && !tg3_flag(tp, 5780_CLASS)) |
14310 | tg3_flag_set(tp, JUMBO_RING_ENABLE); | |
1da177e4 LT |
14311 | |
14312 | /* Determine WakeOnLan speed to use. */ | |
14313 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || | |
14314 | tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 || | |
14315 | tp->pci_chip_rev_id == CHIPREV_ID_5701_B0 || | |
14316 | tp->pci_chip_rev_id == CHIPREV_ID_5701_B2) { | |
63c3a66f | 14317 | tg3_flag_clear(tp, WOL_SPEED_100MB); |
1da177e4 | 14318 | } else { |
63c3a66f | 14319 | tg3_flag_set(tp, WOL_SPEED_100MB); |
1da177e4 LT |
14320 | } |
14321 | ||
7f97a4bd | 14322 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) |
f07e9af3 | 14323 | tp->phy_flags |= TG3_PHYFLG_IS_FET; |
7f97a4bd | 14324 | |
1da177e4 | 14325 | /* A few boards don't want Ethernet@WireSpeed phy feature */ |
6ff6f81d MC |
14326 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
14327 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 && | |
1da177e4 | 14328 | (tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) && |
747e8f8b | 14329 | (tp->pci_chip_rev_id != CHIPREV_ID_5705_A1)) || |
f07e9af3 MC |
14330 | (tp->phy_flags & TG3_PHYFLG_IS_FET) || |
14331 | (tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) | |
14332 | tp->phy_flags |= TG3_PHYFLG_NO_ETH_WIRE_SPEED; | |
1da177e4 LT |
14333 | |
14334 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5703_AX || | |
14335 | GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5704_AX) | |
f07e9af3 | 14336 | tp->phy_flags |= TG3_PHYFLG_ADC_BUG; |
1da177e4 | 14337 | if (tp->pci_chip_rev_id == CHIPREV_ID_5704_A0) |
f07e9af3 | 14338 | tp->phy_flags |= TG3_PHYFLG_5704_A0_BUG; |
1da177e4 | 14339 | |
63c3a66f | 14340 | if (tg3_flag(tp, 5705_PLUS) && |
f07e9af3 | 14341 | !(tp->phy_flags & TG3_PHYFLG_IS_FET) && |
321d32a0 | 14342 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5785 && |
f6eb9b1f | 14343 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_57780 && |
63c3a66f | 14344 | !tg3_flag(tp, 57765_PLUS)) { |
c424cb24 | 14345 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 || |
d30cdd28 | 14346 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 || |
9936bcf6 MC |
14347 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 || |
14348 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) { | |
d4011ada MC |
14349 | if (tp->pdev->device != PCI_DEVICE_ID_TIGON3_5756 && |
14350 | tp->pdev->device != PCI_DEVICE_ID_TIGON3_5722) | |
f07e9af3 | 14351 | tp->phy_flags |= TG3_PHYFLG_JITTER_BUG; |
c1d2a196 | 14352 | if (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5755M) |
f07e9af3 | 14353 | tp->phy_flags |= TG3_PHYFLG_ADJUST_TRIM; |
321d32a0 | 14354 | } else |
f07e9af3 | 14355 | tp->phy_flags |= TG3_PHYFLG_BER_BUG; |
c424cb24 | 14356 | } |
1da177e4 | 14357 | |
b2a5c19c MC |
14358 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 && |
14359 | GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5784_AX) { | |
14360 | tp->phy_otp = tg3_read_otp_phycfg(tp); | |
14361 | if (tp->phy_otp == 0) | |
14362 | tp->phy_otp = TG3_OTP_DEFAULT; | |
14363 | } | |
14364 | ||
63c3a66f | 14365 | if (tg3_flag(tp, CPMU_PRESENT)) |
8ef21428 MC |
14366 | tp->mi_mode = MAC_MI_MODE_500KHZ_CONST; |
14367 | else | |
14368 | tp->mi_mode = MAC_MI_MODE_BASE; | |
14369 | ||
1da177e4 | 14370 | tp->coalesce_mode = 0; |
1da177e4 LT |
14371 | if (GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5700_AX && |
14372 | GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5700_BX) | |
14373 | tp->coalesce_mode |= HOSTCC_MODE_32BYTE; | |
14374 | ||
4d958473 MC |
14375 | /* Set these bits to enable statistics workaround. */ |
14376 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || | |
14377 | tp->pci_chip_rev_id == CHIPREV_ID_5719_A0 || | |
14378 | tp->pci_chip_rev_id == CHIPREV_ID_5720_A0) { | |
14379 | tp->coalesce_mode |= HOSTCC_MODE_ATTN; | |
14380 | tp->grc_mode |= GRC_MODE_IRQ_ON_FLOW_ATTN; | |
14381 | } | |
14382 | ||
321d32a0 MC |
14383 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 || |
14384 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) | |
63c3a66f | 14385 | tg3_flag_set(tp, USE_PHYLIB); |
57e6983c | 14386 | |
158d7abd MC |
14387 | err = tg3_mdio_init(tp); |
14388 | if (err) | |
14389 | return err; | |
1da177e4 LT |
14390 | |
14391 | /* Initialize data/descriptor byte/word swapping. */ | |
14392 | val = tr32(GRC_MODE); | |
f2096f94 MC |
14393 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) |
14394 | val &= (GRC_MODE_BYTE_SWAP_B2HRX_DATA | | |
14395 | GRC_MODE_WORD_SWAP_B2HRX_DATA | | |
14396 | GRC_MODE_B2HRX_ENABLE | | |
14397 | GRC_MODE_HTX2B_ENABLE | | |
14398 | GRC_MODE_HOST_STACKUP); | |
14399 | else | |
14400 | val &= GRC_MODE_HOST_STACKUP; | |
14401 | ||
1da177e4 LT |
14402 | tw32(GRC_MODE, val | tp->grc_mode); |
14403 | ||
14404 | tg3_switch_clocks(tp); | |
14405 | ||
14406 | /* Clear this out for sanity. */ | |
14407 | tw32(TG3PCI_MEM_WIN_BASE_ADDR, 0); | |
14408 | ||
14409 | pci_read_config_dword(tp->pdev, TG3PCI_PCISTATE, | |
14410 | &pci_state_reg); | |
14411 | if ((pci_state_reg & PCISTATE_CONV_PCI_MODE) == 0 && | |
63c3a66f | 14412 | !tg3_flag(tp, PCIX_TARGET_HWBUG)) { |
1da177e4 LT |
14413 | u32 chiprevid = GET_CHIP_REV_ID(tp->misc_host_ctrl); |
14414 | ||
14415 | if (chiprevid == CHIPREV_ID_5701_A0 || | |
14416 | chiprevid == CHIPREV_ID_5701_B0 || | |
14417 | chiprevid == CHIPREV_ID_5701_B2 || | |
14418 | chiprevid == CHIPREV_ID_5701_B5) { | |
14419 | void __iomem *sram_base; | |
14420 | ||
14421 | /* Write some dummy words into the SRAM status block | |
14422 | * area, see if it reads back correctly. If the return | |
14423 | * value is bad, force enable the PCIX workaround. | |
14424 | */ | |
14425 | sram_base = tp->regs + NIC_SRAM_WIN_BASE + NIC_SRAM_STATS_BLK; | |
14426 | ||
14427 | writel(0x00000000, sram_base); | |
14428 | writel(0x00000000, sram_base + 4); | |
14429 | writel(0xffffffff, sram_base + 4); | |
14430 | if (readl(sram_base) != 0x00000000) | |
63c3a66f | 14431 | tg3_flag_set(tp, PCIX_TARGET_HWBUG); |
1da177e4 LT |
14432 | } |
14433 | } | |
14434 | ||
14435 | udelay(50); | |
14436 | tg3_nvram_init(tp); | |
14437 | ||
14438 | grc_misc_cfg = tr32(GRC_MISC_CFG); | |
14439 | grc_misc_cfg &= GRC_MISC_CFG_BOARD_ID_MASK; | |
14440 | ||
1da177e4 LT |
14441 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 && |
14442 | (grc_misc_cfg == GRC_MISC_CFG_BOARD_ID_5788 || | |
14443 | grc_misc_cfg == GRC_MISC_CFG_BOARD_ID_5788M)) | |
63c3a66f | 14444 | tg3_flag_set(tp, IS_5788); |
1da177e4 | 14445 | |
63c3a66f | 14446 | if (!tg3_flag(tp, IS_5788) && |
6ff6f81d | 14447 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700) |
63c3a66f JP |
14448 | tg3_flag_set(tp, TAGGED_STATUS); |
14449 | if (tg3_flag(tp, TAGGED_STATUS)) { | |
fac9b83e DM |
14450 | tp->coalesce_mode |= (HOSTCC_MODE_CLRTICK_RXBD | |
14451 | HOSTCC_MODE_CLRTICK_TXBD); | |
14452 | ||
14453 | tp->misc_host_ctrl |= MISC_HOST_CTRL_TAGGED_STATUS; | |
14454 | pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL, | |
14455 | tp->misc_host_ctrl); | |
14456 | } | |
14457 | ||
3bda1258 | 14458 | /* Preserve the APE MAC_MODE bits */ |
63c3a66f | 14459 | if (tg3_flag(tp, ENABLE_APE)) |
d2394e6b | 14460 | tp->mac_mode = MAC_MODE_APE_TX_EN | MAC_MODE_APE_RX_EN; |
3bda1258 | 14461 | else |
6e01b20b | 14462 | tp->mac_mode = 0; |
3bda1258 | 14463 | |
1da177e4 LT |
14464 | /* these are limited to 10/100 only */ |
14465 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 && | |
14466 | (grc_misc_cfg == 0x8000 || grc_misc_cfg == 0x4000)) || | |
14467 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 && | |
14468 | tp->pdev->vendor == PCI_VENDOR_ID_BROADCOM && | |
14469 | (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5901 || | |
14470 | tp->pdev->device == PCI_DEVICE_ID_TIGON3_5901_2 || | |
14471 | tp->pdev->device == PCI_DEVICE_ID_TIGON3_5705F)) || | |
14472 | (tp->pdev->vendor == PCI_VENDOR_ID_BROADCOM && | |
14473 | (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5751F || | |
676917d4 MC |
14474 | tp->pdev->device == PCI_DEVICE_ID_TIGON3_5753F || |
14475 | tp->pdev->device == PCI_DEVICE_ID_TIGON3_5787F)) || | |
321d32a0 | 14476 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57790 || |
d1101142 MC |
14477 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57791 || |
14478 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57795 || | |
f07e9af3 MC |
14479 | (tp->phy_flags & TG3_PHYFLG_IS_FET)) |
14480 | tp->phy_flags |= TG3_PHYFLG_10_100_ONLY; | |
1da177e4 LT |
14481 | |
14482 | err = tg3_phy_probe(tp); | |
14483 | if (err) { | |
2445e461 | 14484 | dev_err(&tp->pdev->dev, "phy probe failed, err %d\n", err); |
1da177e4 | 14485 | /* ... but do not return immediately ... */ |
b02fd9e3 | 14486 | tg3_mdio_fini(tp); |
1da177e4 LT |
14487 | } |
14488 | ||
184b8904 | 14489 | tg3_read_vpd(tp); |
c4e6575c | 14490 | tg3_read_fw_ver(tp); |
1da177e4 | 14491 | |
f07e9af3 MC |
14492 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) { |
14493 | tp->phy_flags &= ~TG3_PHYFLG_USE_MI_INTERRUPT; | |
1da177e4 LT |
14494 | } else { |
14495 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) | |
f07e9af3 | 14496 | tp->phy_flags |= TG3_PHYFLG_USE_MI_INTERRUPT; |
1da177e4 | 14497 | else |
f07e9af3 | 14498 | tp->phy_flags &= ~TG3_PHYFLG_USE_MI_INTERRUPT; |
1da177e4 LT |
14499 | } |
14500 | ||
14501 | /* 5700 {AX,BX} chips have a broken status block link | |
14502 | * change bit implementation, so we must use the | |
14503 | * status register in those cases. | |
14504 | */ | |
14505 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) | |
63c3a66f | 14506 | tg3_flag_set(tp, USE_LINKCHG_REG); |
1da177e4 | 14507 | else |
63c3a66f | 14508 | tg3_flag_clear(tp, USE_LINKCHG_REG); |
1da177e4 LT |
14509 | |
14510 | /* The led_ctrl is set during tg3_phy_probe, here we might | |
14511 | * have to force the link status polling mechanism based | |
14512 | * upon subsystem IDs. | |
14513 | */ | |
14514 | if (tp->pdev->subsystem_vendor == PCI_VENDOR_ID_DELL && | |
007a880d | 14515 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701 && |
f07e9af3 MC |
14516 | !(tp->phy_flags & TG3_PHYFLG_PHY_SERDES)) { |
14517 | tp->phy_flags |= TG3_PHYFLG_USE_MI_INTERRUPT; | |
63c3a66f | 14518 | tg3_flag_set(tp, USE_LINKCHG_REG); |
1da177e4 LT |
14519 | } |
14520 | ||
14521 | /* For all SERDES we poll the MAC status register. */ | |
f07e9af3 | 14522 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) |
63c3a66f | 14523 | tg3_flag_set(tp, POLL_SERDES); |
1da177e4 | 14524 | else |
63c3a66f | 14525 | tg3_flag_clear(tp, POLL_SERDES); |
1da177e4 | 14526 | |
bf933c80 | 14527 | tp->rx_offset = NET_IP_ALIGN; |
d2757fc4 | 14528 | tp->rx_copy_thresh = TG3_RX_COPY_THRESHOLD; |
1da177e4 | 14529 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701 && |
63c3a66f | 14530 | tg3_flag(tp, PCIX_MODE)) { |
bf933c80 | 14531 | tp->rx_offset = 0; |
d2757fc4 | 14532 | #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS |
9dc7a113 | 14533 | tp->rx_copy_thresh = ~(u16)0; |
d2757fc4 MC |
14534 | #endif |
14535 | } | |
1da177e4 | 14536 | |
2c49a44d MC |
14537 | tp->rx_std_ring_mask = TG3_RX_STD_RING_SIZE(tp) - 1; |
14538 | tp->rx_jmb_ring_mask = TG3_RX_JMB_RING_SIZE(tp) - 1; | |
7cb32cf2 MC |
14539 | tp->rx_ret_ring_mask = tg3_rx_ret_ring_size(tp) - 1; |
14540 | ||
2c49a44d | 14541 | tp->rx_std_max_post = tp->rx_std_ring_mask + 1; |
f92905de MC |
14542 | |
14543 | /* Increment the rx prod index on the rx std ring by at most | |
14544 | * 8 for these chips to workaround hw errata. | |
14545 | */ | |
14546 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750 || | |
14547 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 || | |
14548 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755) | |
14549 | tp->rx_std_max_post = 8; | |
14550 | ||
63c3a66f | 14551 | if (tg3_flag(tp, ASPM_WORKAROUND)) |
8ed5d97e MC |
14552 | tp->pwrmgmt_thresh = tr32(PCIE_PWR_MGMT_THRESH) & |
14553 | PCIE_PWR_MGMT_L1_THRESH_MSK; | |
14554 | ||
1da177e4 LT |
14555 | return err; |
14556 | } | |
14557 | ||
49b6e95f | 14558 | #ifdef CONFIG_SPARC |
1da177e4 LT |
14559 | static int __devinit tg3_get_macaddr_sparc(struct tg3 *tp) |
14560 | { | |
14561 | struct net_device *dev = tp->dev; | |
14562 | struct pci_dev *pdev = tp->pdev; | |
49b6e95f | 14563 | struct device_node *dp = pci_device_to_OF_node(pdev); |
374d4cac | 14564 | const unsigned char *addr; |
49b6e95f DM |
14565 | int len; |
14566 | ||
14567 | addr = of_get_property(dp, "local-mac-address", &len); | |
14568 | if (addr && len == 6) { | |
14569 | memcpy(dev->dev_addr, addr, 6); | |
14570 | memcpy(dev->perm_addr, dev->dev_addr, 6); | |
14571 | return 0; | |
1da177e4 LT |
14572 | } |
14573 | return -ENODEV; | |
14574 | } | |
14575 | ||
14576 | static int __devinit tg3_get_default_macaddr_sparc(struct tg3 *tp) | |
14577 | { | |
14578 | struct net_device *dev = tp->dev; | |
14579 | ||
14580 | memcpy(dev->dev_addr, idprom->id_ethaddr, 6); | |
2ff43697 | 14581 | memcpy(dev->perm_addr, idprom->id_ethaddr, 6); |
1da177e4 LT |
14582 | return 0; |
14583 | } | |
14584 | #endif | |
14585 | ||
14586 | static int __devinit tg3_get_device_address(struct tg3 *tp) | |
14587 | { | |
14588 | struct net_device *dev = tp->dev; | |
14589 | u32 hi, lo, mac_offset; | |
008652b3 | 14590 | int addr_ok = 0; |
1da177e4 | 14591 | |
49b6e95f | 14592 | #ifdef CONFIG_SPARC |
1da177e4 LT |
14593 | if (!tg3_get_macaddr_sparc(tp)) |
14594 | return 0; | |
14595 | #endif | |
14596 | ||
14597 | mac_offset = 0x7c; | |
6ff6f81d | 14598 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 || |
63c3a66f | 14599 | tg3_flag(tp, 5780_CLASS)) { |
1da177e4 LT |
14600 | if (tr32(TG3PCI_DUAL_MAC_CTRL) & DUAL_MAC_CTRL_ID) |
14601 | mac_offset = 0xcc; | |
14602 | if (tg3_nvram_lock(tp)) | |
14603 | tw32_f(NVRAM_CMD, NVRAM_CMD_RESET); | |
14604 | else | |
14605 | tg3_nvram_unlock(tp); | |
63c3a66f | 14606 | } else if (tg3_flag(tp, 5717_PLUS)) { |
69f11c99 | 14607 | if (tp->pci_fn & 1) |
a1b950d5 | 14608 | mac_offset = 0xcc; |
69f11c99 | 14609 | if (tp->pci_fn > 1) |
a50d0796 | 14610 | mac_offset += 0x18c; |
a1b950d5 | 14611 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) |
b5d3772c | 14612 | mac_offset = 0x10; |
1da177e4 LT |
14613 | |
14614 | /* First try to get it from MAC address mailbox. */ | |
14615 | tg3_read_mem(tp, NIC_SRAM_MAC_ADDR_HIGH_MBOX, &hi); | |
14616 | if ((hi >> 16) == 0x484b) { | |
14617 | dev->dev_addr[0] = (hi >> 8) & 0xff; | |
14618 | dev->dev_addr[1] = (hi >> 0) & 0xff; | |
14619 | ||
14620 | tg3_read_mem(tp, NIC_SRAM_MAC_ADDR_LOW_MBOX, &lo); | |
14621 | dev->dev_addr[2] = (lo >> 24) & 0xff; | |
14622 | dev->dev_addr[3] = (lo >> 16) & 0xff; | |
14623 | dev->dev_addr[4] = (lo >> 8) & 0xff; | |
14624 | dev->dev_addr[5] = (lo >> 0) & 0xff; | |
1da177e4 | 14625 | |
008652b3 MC |
14626 | /* Some old bootcode may report a 0 MAC address in SRAM */ |
14627 | addr_ok = is_valid_ether_addr(&dev->dev_addr[0]); | |
14628 | } | |
14629 | if (!addr_ok) { | |
14630 | /* Next, try NVRAM. */ | |
63c3a66f | 14631 | if (!tg3_flag(tp, NO_NVRAM) && |
df259d8c | 14632 | !tg3_nvram_read_be32(tp, mac_offset + 0, &hi) && |
6d348f2c | 14633 | !tg3_nvram_read_be32(tp, mac_offset + 4, &lo)) { |
62cedd11 MC |
14634 | memcpy(&dev->dev_addr[0], ((char *)&hi) + 2, 2); |
14635 | memcpy(&dev->dev_addr[2], (char *)&lo, sizeof(lo)); | |
008652b3 MC |
14636 | } |
14637 | /* Finally just fetch it out of the MAC control regs. */ | |
14638 | else { | |
14639 | hi = tr32(MAC_ADDR_0_HIGH); | |
14640 | lo = tr32(MAC_ADDR_0_LOW); | |
14641 | ||
14642 | dev->dev_addr[5] = lo & 0xff; | |
14643 | dev->dev_addr[4] = (lo >> 8) & 0xff; | |
14644 | dev->dev_addr[3] = (lo >> 16) & 0xff; | |
14645 | dev->dev_addr[2] = (lo >> 24) & 0xff; | |
14646 | dev->dev_addr[1] = hi & 0xff; | |
14647 | dev->dev_addr[0] = (hi >> 8) & 0xff; | |
14648 | } | |
1da177e4 LT |
14649 | } |
14650 | ||
14651 | if (!is_valid_ether_addr(&dev->dev_addr[0])) { | |
7582a335 | 14652 | #ifdef CONFIG_SPARC |
1da177e4 LT |
14653 | if (!tg3_get_default_macaddr_sparc(tp)) |
14654 | return 0; | |
14655 | #endif | |
14656 | return -EINVAL; | |
14657 | } | |
2ff43697 | 14658 | memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len); |
1da177e4 LT |
14659 | return 0; |
14660 | } | |
14661 | ||
59e6b434 DM |
14662 | #define BOUNDARY_SINGLE_CACHELINE 1 |
14663 | #define BOUNDARY_MULTI_CACHELINE 2 | |
14664 | ||
14665 | static u32 __devinit tg3_calc_dma_bndry(struct tg3 *tp, u32 val) | |
14666 | { | |
14667 | int cacheline_size; | |
14668 | u8 byte; | |
14669 | int goal; | |
14670 | ||
14671 | pci_read_config_byte(tp->pdev, PCI_CACHE_LINE_SIZE, &byte); | |
14672 | if (byte == 0) | |
14673 | cacheline_size = 1024; | |
14674 | else | |
14675 | cacheline_size = (int) byte * 4; | |
14676 | ||
14677 | /* On 5703 and later chips, the boundary bits have no | |
14678 | * effect. | |
14679 | */ | |
14680 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 && | |
14681 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701 && | |
63c3a66f | 14682 | !tg3_flag(tp, PCI_EXPRESS)) |
59e6b434 DM |
14683 | goto out; |
14684 | ||
14685 | #if defined(CONFIG_PPC64) || defined(CONFIG_IA64) || defined(CONFIG_PARISC) | |
14686 | goal = BOUNDARY_MULTI_CACHELINE; | |
14687 | #else | |
14688 | #if defined(CONFIG_SPARC64) || defined(CONFIG_ALPHA) | |
14689 | goal = BOUNDARY_SINGLE_CACHELINE; | |
14690 | #else | |
14691 | goal = 0; | |
14692 | #endif | |
14693 | #endif | |
14694 | ||
63c3a66f | 14695 | if (tg3_flag(tp, 57765_PLUS)) { |
cbf9ca6c MC |
14696 | val = goal ? 0 : DMA_RWCTRL_DIS_CACHE_ALIGNMENT; |
14697 | goto out; | |
14698 | } | |
14699 | ||
59e6b434 DM |
14700 | if (!goal) |
14701 | goto out; | |
14702 | ||
14703 | /* PCI controllers on most RISC systems tend to disconnect | |
14704 | * when a device tries to burst across a cache-line boundary. | |
14705 | * Therefore, letting tg3 do so just wastes PCI bandwidth. | |
14706 | * | |
14707 | * Unfortunately, for PCI-E there are only limited | |
14708 | * write-side controls for this, and thus for reads | |
14709 | * we will still get the disconnects. We'll also waste | |
14710 | * these PCI cycles for both read and write for chips | |
14711 | * other than 5700 and 5701 which do not implement the | |
14712 | * boundary bits. | |
14713 | */ | |
63c3a66f | 14714 | if (tg3_flag(tp, PCIX_MODE) && !tg3_flag(tp, PCI_EXPRESS)) { |
59e6b434 DM |
14715 | switch (cacheline_size) { |
14716 | case 16: | |
14717 | case 32: | |
14718 | case 64: | |
14719 | case 128: | |
14720 | if (goal == BOUNDARY_SINGLE_CACHELINE) { | |
14721 | val |= (DMA_RWCTRL_READ_BNDRY_128_PCIX | | |
14722 | DMA_RWCTRL_WRITE_BNDRY_128_PCIX); | |
14723 | } else { | |
14724 | val |= (DMA_RWCTRL_READ_BNDRY_384_PCIX | | |
14725 | DMA_RWCTRL_WRITE_BNDRY_384_PCIX); | |
14726 | } | |
14727 | break; | |
14728 | ||
14729 | case 256: | |
14730 | val |= (DMA_RWCTRL_READ_BNDRY_256_PCIX | | |
14731 | DMA_RWCTRL_WRITE_BNDRY_256_PCIX); | |
14732 | break; | |
14733 | ||
14734 | default: | |
14735 | val |= (DMA_RWCTRL_READ_BNDRY_384_PCIX | | |
14736 | DMA_RWCTRL_WRITE_BNDRY_384_PCIX); | |
14737 | break; | |
855e1111 | 14738 | } |
63c3a66f | 14739 | } else if (tg3_flag(tp, PCI_EXPRESS)) { |
59e6b434 DM |
14740 | switch (cacheline_size) { |
14741 | case 16: | |
14742 | case 32: | |
14743 | case 64: | |
14744 | if (goal == BOUNDARY_SINGLE_CACHELINE) { | |
14745 | val &= ~DMA_RWCTRL_WRITE_BNDRY_DISAB_PCIE; | |
14746 | val |= DMA_RWCTRL_WRITE_BNDRY_64_PCIE; | |
14747 | break; | |
14748 | } | |
14749 | /* fallthrough */ | |
14750 | case 128: | |
14751 | default: | |
14752 | val &= ~DMA_RWCTRL_WRITE_BNDRY_DISAB_PCIE; | |
14753 | val |= DMA_RWCTRL_WRITE_BNDRY_128_PCIE; | |
14754 | break; | |
855e1111 | 14755 | } |
59e6b434 DM |
14756 | } else { |
14757 | switch (cacheline_size) { | |
14758 | case 16: | |
14759 | if (goal == BOUNDARY_SINGLE_CACHELINE) { | |
14760 | val |= (DMA_RWCTRL_READ_BNDRY_16 | | |
14761 | DMA_RWCTRL_WRITE_BNDRY_16); | |
14762 | break; | |
14763 | } | |
14764 | /* fallthrough */ | |
14765 | case 32: | |
14766 | if (goal == BOUNDARY_SINGLE_CACHELINE) { | |
14767 | val |= (DMA_RWCTRL_READ_BNDRY_32 | | |
14768 | DMA_RWCTRL_WRITE_BNDRY_32); | |
14769 | break; | |
14770 | } | |
14771 | /* fallthrough */ | |
14772 | case 64: | |
14773 | if (goal == BOUNDARY_SINGLE_CACHELINE) { | |
14774 | val |= (DMA_RWCTRL_READ_BNDRY_64 | | |
14775 | DMA_RWCTRL_WRITE_BNDRY_64); | |
14776 | break; | |
14777 | } | |
14778 | /* fallthrough */ | |
14779 | case 128: | |
14780 | if (goal == BOUNDARY_SINGLE_CACHELINE) { | |
14781 | val |= (DMA_RWCTRL_READ_BNDRY_128 | | |
14782 | DMA_RWCTRL_WRITE_BNDRY_128); | |
14783 | break; | |
14784 | } | |
14785 | /* fallthrough */ | |
14786 | case 256: | |
14787 | val |= (DMA_RWCTRL_READ_BNDRY_256 | | |
14788 | DMA_RWCTRL_WRITE_BNDRY_256); | |
14789 | break; | |
14790 | case 512: | |
14791 | val |= (DMA_RWCTRL_READ_BNDRY_512 | | |
14792 | DMA_RWCTRL_WRITE_BNDRY_512); | |
14793 | break; | |
14794 | case 1024: | |
14795 | default: | |
14796 | val |= (DMA_RWCTRL_READ_BNDRY_1024 | | |
14797 | DMA_RWCTRL_WRITE_BNDRY_1024); | |
14798 | break; | |
855e1111 | 14799 | } |
59e6b434 DM |
14800 | } |
14801 | ||
14802 | out: | |
14803 | return val; | |
14804 | } | |
14805 | ||
1da177e4 LT |
14806 | static int __devinit tg3_do_test_dma(struct tg3 *tp, u32 *buf, dma_addr_t buf_dma, int size, int to_device) |
14807 | { | |
14808 | struct tg3_internal_buffer_desc test_desc; | |
14809 | u32 sram_dma_descs; | |
14810 | int i, ret; | |
14811 | ||
14812 | sram_dma_descs = NIC_SRAM_DMA_DESC_POOL_BASE; | |
14813 | ||
14814 | tw32(FTQ_RCVBD_COMP_FIFO_ENQDEQ, 0); | |
14815 | tw32(FTQ_RCVDATA_COMP_FIFO_ENQDEQ, 0); | |
14816 | tw32(RDMAC_STATUS, 0); | |
14817 | tw32(WDMAC_STATUS, 0); | |
14818 | ||
14819 | tw32(BUFMGR_MODE, 0); | |
14820 | tw32(FTQ_RESET, 0); | |
14821 | ||
14822 | test_desc.addr_hi = ((u64) buf_dma) >> 32; | |
14823 | test_desc.addr_lo = buf_dma & 0xffffffff; | |
14824 | test_desc.nic_mbuf = 0x00002100; | |
14825 | test_desc.len = size; | |
14826 | ||
14827 | /* | |
14828 | * HP ZX1 was seeing test failures for 5701 cards running at 33Mhz | |
14829 | * the *second* time the tg3 driver was getting loaded after an | |
14830 | * initial scan. | |
14831 | * | |
14832 | * Broadcom tells me: | |
14833 | * ...the DMA engine is connected to the GRC block and a DMA | |
14834 | * reset may affect the GRC block in some unpredictable way... | |
14835 | * The behavior of resets to individual blocks has not been tested. | |
14836 | * | |
14837 | * Broadcom noted the GRC reset will also reset all sub-components. | |
14838 | */ | |
14839 | if (to_device) { | |
14840 | test_desc.cqid_sqid = (13 << 8) | 2; | |
14841 | ||
14842 | tw32_f(RDMAC_MODE, RDMAC_MODE_ENABLE); | |
14843 | udelay(40); | |
14844 | } else { | |
14845 | test_desc.cqid_sqid = (16 << 8) | 7; | |
14846 | ||
14847 | tw32_f(WDMAC_MODE, WDMAC_MODE_ENABLE); | |
14848 | udelay(40); | |
14849 | } | |
14850 | test_desc.flags = 0x00000005; | |
14851 | ||
14852 | for (i = 0; i < (sizeof(test_desc) / sizeof(u32)); i++) { | |
14853 | u32 val; | |
14854 | ||
14855 | val = *(((u32 *)&test_desc) + i); | |
14856 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, | |
14857 | sram_dma_descs + (i * sizeof(u32))); | |
14858 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val); | |
14859 | } | |
14860 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0); | |
14861 | ||
859a5887 | 14862 | if (to_device) |
1da177e4 | 14863 | tw32(FTQ_DMA_HIGH_READ_FIFO_ENQDEQ, sram_dma_descs); |
859a5887 | 14864 | else |
1da177e4 | 14865 | tw32(FTQ_DMA_HIGH_WRITE_FIFO_ENQDEQ, sram_dma_descs); |
1da177e4 LT |
14866 | |
14867 | ret = -ENODEV; | |
14868 | for (i = 0; i < 40; i++) { | |
14869 | u32 val; | |
14870 | ||
14871 | if (to_device) | |
14872 | val = tr32(FTQ_RCVBD_COMP_FIFO_ENQDEQ); | |
14873 | else | |
14874 | val = tr32(FTQ_RCVDATA_COMP_FIFO_ENQDEQ); | |
14875 | if ((val & 0xffff) == sram_dma_descs) { | |
14876 | ret = 0; | |
14877 | break; | |
14878 | } | |
14879 | ||
14880 | udelay(100); | |
14881 | } | |
14882 | ||
14883 | return ret; | |
14884 | } | |
14885 | ||
ded7340d | 14886 | #define TEST_BUFFER_SIZE 0x2000 |
1da177e4 | 14887 | |
4143470c | 14888 | static DEFINE_PCI_DEVICE_TABLE(tg3_dma_wait_state_chipsets) = { |
895950c2 JP |
14889 | { PCI_DEVICE(PCI_VENDOR_ID_APPLE, PCI_DEVICE_ID_APPLE_UNI_N_PCI15) }, |
14890 | { }, | |
14891 | }; | |
14892 | ||
1da177e4 LT |
14893 | static int __devinit tg3_test_dma(struct tg3 *tp) |
14894 | { | |
14895 | dma_addr_t buf_dma; | |
59e6b434 | 14896 | u32 *buf, saved_dma_rwctrl; |
cbf9ca6c | 14897 | int ret = 0; |
1da177e4 | 14898 | |
4bae65c8 MC |
14899 | buf = dma_alloc_coherent(&tp->pdev->dev, TEST_BUFFER_SIZE, |
14900 | &buf_dma, GFP_KERNEL); | |
1da177e4 LT |
14901 | if (!buf) { |
14902 | ret = -ENOMEM; | |
14903 | goto out_nofree; | |
14904 | } | |
14905 | ||
14906 | tp->dma_rwctrl = ((0x7 << DMA_RWCTRL_PCI_WRITE_CMD_SHIFT) | | |
14907 | (0x6 << DMA_RWCTRL_PCI_READ_CMD_SHIFT)); | |
14908 | ||
59e6b434 | 14909 | tp->dma_rwctrl = tg3_calc_dma_bndry(tp, tp->dma_rwctrl); |
1da177e4 | 14910 | |
63c3a66f | 14911 | if (tg3_flag(tp, 57765_PLUS)) |
cbf9ca6c MC |
14912 | goto out; |
14913 | ||
63c3a66f | 14914 | if (tg3_flag(tp, PCI_EXPRESS)) { |
1da177e4 LT |
14915 | /* DMA read watermark not used on PCIE */ |
14916 | tp->dma_rwctrl |= 0x00180000; | |
63c3a66f | 14917 | } else if (!tg3_flag(tp, PCIX_MODE)) { |
85e94ced MC |
14918 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 || |
14919 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750) | |
1da177e4 LT |
14920 | tp->dma_rwctrl |= 0x003f0000; |
14921 | else | |
14922 | tp->dma_rwctrl |= 0x003f000f; | |
14923 | } else { | |
14924 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 || | |
14925 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) { | |
14926 | u32 ccval = (tr32(TG3PCI_CLOCK_CTRL) & 0x1f); | |
49afdeb6 | 14927 | u32 read_water = 0x7; |
1da177e4 | 14928 | |
4a29cc2e MC |
14929 | /* If the 5704 is behind the EPB bridge, we can |
14930 | * do the less restrictive ONE_DMA workaround for | |
14931 | * better performance. | |
14932 | */ | |
63c3a66f | 14933 | if (tg3_flag(tp, 40BIT_DMA_BUG) && |
4a29cc2e MC |
14934 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) |
14935 | tp->dma_rwctrl |= 0x8000; | |
14936 | else if (ccval == 0x6 || ccval == 0x7) | |
1da177e4 LT |
14937 | tp->dma_rwctrl |= DMA_RWCTRL_ONE_DMA; |
14938 | ||
49afdeb6 MC |
14939 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703) |
14940 | read_water = 4; | |
59e6b434 | 14941 | /* Set bit 23 to enable PCIX hw bug fix */ |
49afdeb6 MC |
14942 | tp->dma_rwctrl |= |
14943 | (read_water << DMA_RWCTRL_READ_WATER_SHIFT) | | |
14944 | (0x3 << DMA_RWCTRL_WRITE_WATER_SHIFT) | | |
14945 | (1 << 23); | |
4cf78e4f MC |
14946 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780) { |
14947 | /* 5780 always in PCIX mode */ | |
14948 | tp->dma_rwctrl |= 0x00144000; | |
a4e2b347 MC |
14949 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) { |
14950 | /* 5714 always in PCIX mode */ | |
14951 | tp->dma_rwctrl |= 0x00148000; | |
1da177e4 LT |
14952 | } else { |
14953 | tp->dma_rwctrl |= 0x001b000f; | |
14954 | } | |
14955 | } | |
14956 | ||
14957 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 || | |
14958 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) | |
14959 | tp->dma_rwctrl &= 0xfffffff0; | |
14960 | ||
14961 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || | |
14962 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) { | |
14963 | /* Remove this if it causes problems for some boards. */ | |
14964 | tp->dma_rwctrl |= DMA_RWCTRL_USE_MEM_READ_MULT; | |
14965 | ||
14966 | /* On 5700/5701 chips, we need to set this bit. | |
14967 | * Otherwise the chip will issue cacheline transactions | |
14968 | * to streamable DMA memory with not all the byte | |
14969 | * enables turned on. This is an error on several | |
14970 | * RISC PCI controllers, in particular sparc64. | |
14971 | * | |
14972 | * On 5703/5704 chips, this bit has been reassigned | |
14973 | * a different meaning. In particular, it is used | |
14974 | * on those chips to enable a PCI-X workaround. | |
14975 | */ | |
14976 | tp->dma_rwctrl |= DMA_RWCTRL_ASSERT_ALL_BE; | |
14977 | } | |
14978 | ||
14979 | tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl); | |
14980 | ||
14981 | #if 0 | |
14982 | /* Unneeded, already done by tg3_get_invariants. */ | |
14983 | tg3_switch_clocks(tp); | |
14984 | #endif | |
14985 | ||
1da177e4 LT |
14986 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 && |
14987 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) | |
14988 | goto out; | |
14989 | ||
59e6b434 DM |
14990 | /* It is best to perform DMA test with maximum write burst size |
14991 | * to expose the 5700/5701 write DMA bug. | |
14992 | */ | |
14993 | saved_dma_rwctrl = tp->dma_rwctrl; | |
14994 | tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK; | |
14995 | tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl); | |
14996 | ||
1da177e4 LT |
14997 | while (1) { |
14998 | u32 *p = buf, i; | |
14999 | ||
15000 | for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++) | |
15001 | p[i] = i; | |
15002 | ||
15003 | /* Send the buffer to the chip. */ | |
15004 | ret = tg3_do_test_dma(tp, buf, buf_dma, TEST_BUFFER_SIZE, 1); | |
15005 | if (ret) { | |
2445e461 MC |
15006 | dev_err(&tp->pdev->dev, |
15007 | "%s: Buffer write failed. err = %d\n", | |
15008 | __func__, ret); | |
1da177e4 LT |
15009 | break; |
15010 | } | |
15011 | ||
15012 | #if 0 | |
15013 | /* validate data reached card RAM correctly. */ | |
15014 | for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++) { | |
15015 | u32 val; | |
15016 | tg3_read_mem(tp, 0x2100 + (i*4), &val); | |
15017 | if (le32_to_cpu(val) != p[i]) { | |
2445e461 MC |
15018 | dev_err(&tp->pdev->dev, |
15019 | "%s: Buffer corrupted on device! " | |
15020 | "(%d != %d)\n", __func__, val, i); | |
1da177e4 LT |
15021 | /* ret = -ENODEV here? */ |
15022 | } | |
15023 | p[i] = 0; | |
15024 | } | |
15025 | #endif | |
15026 | /* Now read it back. */ | |
15027 | ret = tg3_do_test_dma(tp, buf, buf_dma, TEST_BUFFER_SIZE, 0); | |
15028 | if (ret) { | |
5129c3a3 MC |
15029 | dev_err(&tp->pdev->dev, "%s: Buffer read failed. " |
15030 | "err = %d\n", __func__, ret); | |
1da177e4 LT |
15031 | break; |
15032 | } | |
15033 | ||
15034 | /* Verify it. */ | |
15035 | for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++) { | |
15036 | if (p[i] == i) | |
15037 | continue; | |
15038 | ||
59e6b434 DM |
15039 | if ((tp->dma_rwctrl & DMA_RWCTRL_WRITE_BNDRY_MASK) != |
15040 | DMA_RWCTRL_WRITE_BNDRY_16) { | |
15041 | tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK; | |
1da177e4 LT |
15042 | tp->dma_rwctrl |= DMA_RWCTRL_WRITE_BNDRY_16; |
15043 | tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl); | |
15044 | break; | |
15045 | } else { | |
2445e461 MC |
15046 | dev_err(&tp->pdev->dev, |
15047 | "%s: Buffer corrupted on read back! " | |
15048 | "(%d != %d)\n", __func__, p[i], i); | |
1da177e4 LT |
15049 | ret = -ENODEV; |
15050 | goto out; | |
15051 | } | |
15052 | } | |
15053 | ||
15054 | if (i == (TEST_BUFFER_SIZE / sizeof(u32))) { | |
15055 | /* Success. */ | |
15056 | ret = 0; | |
15057 | break; | |
15058 | } | |
15059 | } | |
59e6b434 DM |
15060 | if ((tp->dma_rwctrl & DMA_RWCTRL_WRITE_BNDRY_MASK) != |
15061 | DMA_RWCTRL_WRITE_BNDRY_16) { | |
15062 | /* DMA test passed without adjusting DMA boundary, | |
6d1cfbab MC |
15063 | * now look for chipsets that are known to expose the |
15064 | * DMA bug without failing the test. | |
59e6b434 | 15065 | */ |
4143470c | 15066 | if (pci_dev_present(tg3_dma_wait_state_chipsets)) { |
6d1cfbab MC |
15067 | tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK; |
15068 | tp->dma_rwctrl |= DMA_RWCTRL_WRITE_BNDRY_16; | |
859a5887 | 15069 | } else { |
6d1cfbab MC |
15070 | /* Safe to use the calculated DMA boundary. */ |
15071 | tp->dma_rwctrl = saved_dma_rwctrl; | |
859a5887 | 15072 | } |
6d1cfbab | 15073 | |
59e6b434 DM |
15074 | tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl); |
15075 | } | |
1da177e4 LT |
15076 | |
15077 | out: | |
4bae65c8 | 15078 | dma_free_coherent(&tp->pdev->dev, TEST_BUFFER_SIZE, buf, buf_dma); |
1da177e4 LT |
15079 | out_nofree: |
15080 | return ret; | |
15081 | } | |
15082 | ||
1da177e4 LT |
15083 | static void __devinit tg3_init_bufmgr_config(struct tg3 *tp) |
15084 | { | |
63c3a66f | 15085 | if (tg3_flag(tp, 57765_PLUS)) { |
666bc831 MC |
15086 | tp->bufmgr_config.mbuf_read_dma_low_water = |
15087 | DEFAULT_MB_RDMA_LOW_WATER_5705; | |
15088 | tp->bufmgr_config.mbuf_mac_rx_low_water = | |
15089 | DEFAULT_MB_MACRX_LOW_WATER_57765; | |
15090 | tp->bufmgr_config.mbuf_high_water = | |
15091 | DEFAULT_MB_HIGH_WATER_57765; | |
15092 | ||
15093 | tp->bufmgr_config.mbuf_read_dma_low_water_jumbo = | |
15094 | DEFAULT_MB_RDMA_LOW_WATER_5705; | |
15095 | tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo = | |
15096 | DEFAULT_MB_MACRX_LOW_WATER_JUMBO_57765; | |
15097 | tp->bufmgr_config.mbuf_high_water_jumbo = | |
15098 | DEFAULT_MB_HIGH_WATER_JUMBO_57765; | |
63c3a66f | 15099 | } else if (tg3_flag(tp, 5705_PLUS)) { |
fdfec172 MC |
15100 | tp->bufmgr_config.mbuf_read_dma_low_water = |
15101 | DEFAULT_MB_RDMA_LOW_WATER_5705; | |
15102 | tp->bufmgr_config.mbuf_mac_rx_low_water = | |
15103 | DEFAULT_MB_MACRX_LOW_WATER_5705; | |
15104 | tp->bufmgr_config.mbuf_high_water = | |
15105 | DEFAULT_MB_HIGH_WATER_5705; | |
b5d3772c MC |
15106 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
15107 | tp->bufmgr_config.mbuf_mac_rx_low_water = | |
15108 | DEFAULT_MB_MACRX_LOW_WATER_5906; | |
15109 | tp->bufmgr_config.mbuf_high_water = | |
15110 | DEFAULT_MB_HIGH_WATER_5906; | |
15111 | } | |
fdfec172 MC |
15112 | |
15113 | tp->bufmgr_config.mbuf_read_dma_low_water_jumbo = | |
15114 | DEFAULT_MB_RDMA_LOW_WATER_JUMBO_5780; | |
15115 | tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo = | |
15116 | DEFAULT_MB_MACRX_LOW_WATER_JUMBO_5780; | |
15117 | tp->bufmgr_config.mbuf_high_water_jumbo = | |
15118 | DEFAULT_MB_HIGH_WATER_JUMBO_5780; | |
15119 | } else { | |
15120 | tp->bufmgr_config.mbuf_read_dma_low_water = | |
15121 | DEFAULT_MB_RDMA_LOW_WATER; | |
15122 | tp->bufmgr_config.mbuf_mac_rx_low_water = | |
15123 | DEFAULT_MB_MACRX_LOW_WATER; | |
15124 | tp->bufmgr_config.mbuf_high_water = | |
15125 | DEFAULT_MB_HIGH_WATER; | |
15126 | ||
15127 | tp->bufmgr_config.mbuf_read_dma_low_water_jumbo = | |
15128 | DEFAULT_MB_RDMA_LOW_WATER_JUMBO; | |
15129 | tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo = | |
15130 | DEFAULT_MB_MACRX_LOW_WATER_JUMBO; | |
15131 | tp->bufmgr_config.mbuf_high_water_jumbo = | |
15132 | DEFAULT_MB_HIGH_WATER_JUMBO; | |
15133 | } | |
1da177e4 LT |
15134 | |
15135 | tp->bufmgr_config.dma_low_water = DEFAULT_DMA_LOW_WATER; | |
15136 | tp->bufmgr_config.dma_high_water = DEFAULT_DMA_HIGH_WATER; | |
15137 | } | |
15138 | ||
15139 | static char * __devinit tg3_phy_string(struct tg3 *tp) | |
15140 | { | |
79eb6904 MC |
15141 | switch (tp->phy_id & TG3_PHY_ID_MASK) { |
15142 | case TG3_PHY_ID_BCM5400: return "5400"; | |
15143 | case TG3_PHY_ID_BCM5401: return "5401"; | |
15144 | case TG3_PHY_ID_BCM5411: return "5411"; | |
15145 | case TG3_PHY_ID_BCM5701: return "5701"; | |
15146 | case TG3_PHY_ID_BCM5703: return "5703"; | |
15147 | case TG3_PHY_ID_BCM5704: return "5704"; | |
15148 | case TG3_PHY_ID_BCM5705: return "5705"; | |
15149 | case TG3_PHY_ID_BCM5750: return "5750"; | |
15150 | case TG3_PHY_ID_BCM5752: return "5752"; | |
15151 | case TG3_PHY_ID_BCM5714: return "5714"; | |
15152 | case TG3_PHY_ID_BCM5780: return "5780"; | |
15153 | case TG3_PHY_ID_BCM5755: return "5755"; | |
15154 | case TG3_PHY_ID_BCM5787: return "5787"; | |
15155 | case TG3_PHY_ID_BCM5784: return "5784"; | |
15156 | case TG3_PHY_ID_BCM5756: return "5722/5756"; | |
15157 | case TG3_PHY_ID_BCM5906: return "5906"; | |
15158 | case TG3_PHY_ID_BCM5761: return "5761"; | |
15159 | case TG3_PHY_ID_BCM5718C: return "5718C"; | |
15160 | case TG3_PHY_ID_BCM5718S: return "5718S"; | |
15161 | case TG3_PHY_ID_BCM57765: return "57765"; | |
302b500b | 15162 | case TG3_PHY_ID_BCM5719C: return "5719C"; |
6418f2c1 | 15163 | case TG3_PHY_ID_BCM5720C: return "5720C"; |
79eb6904 | 15164 | case TG3_PHY_ID_BCM8002: return "8002/serdes"; |
1da177e4 LT |
15165 | case 0: return "serdes"; |
15166 | default: return "unknown"; | |
855e1111 | 15167 | } |
1da177e4 LT |
15168 | } |
15169 | ||
f9804ddb MC |
15170 | static char * __devinit tg3_bus_string(struct tg3 *tp, char *str) |
15171 | { | |
63c3a66f | 15172 | if (tg3_flag(tp, PCI_EXPRESS)) { |
f9804ddb MC |
15173 | strcpy(str, "PCI Express"); |
15174 | return str; | |
63c3a66f | 15175 | } else if (tg3_flag(tp, PCIX_MODE)) { |
f9804ddb MC |
15176 | u32 clock_ctrl = tr32(TG3PCI_CLOCK_CTRL) & 0x1f; |
15177 | ||
15178 | strcpy(str, "PCIX:"); | |
15179 | ||
15180 | if ((clock_ctrl == 7) || | |
15181 | ((tr32(GRC_MISC_CFG) & GRC_MISC_CFG_BOARD_ID_MASK) == | |
15182 | GRC_MISC_CFG_BOARD_ID_5704CIOBE)) | |
15183 | strcat(str, "133MHz"); | |
15184 | else if (clock_ctrl == 0) | |
15185 | strcat(str, "33MHz"); | |
15186 | else if (clock_ctrl == 2) | |
15187 | strcat(str, "50MHz"); | |
15188 | else if (clock_ctrl == 4) | |
15189 | strcat(str, "66MHz"); | |
15190 | else if (clock_ctrl == 6) | |
15191 | strcat(str, "100MHz"); | |
f9804ddb MC |
15192 | } else { |
15193 | strcpy(str, "PCI:"); | |
63c3a66f | 15194 | if (tg3_flag(tp, PCI_HIGH_SPEED)) |
f9804ddb MC |
15195 | strcat(str, "66MHz"); |
15196 | else | |
15197 | strcat(str, "33MHz"); | |
15198 | } | |
63c3a66f | 15199 | if (tg3_flag(tp, PCI_32BIT)) |
f9804ddb MC |
15200 | strcat(str, ":32-bit"); |
15201 | else | |
15202 | strcat(str, ":64-bit"); | |
15203 | return str; | |
15204 | } | |
15205 | ||
8c2dc7e1 | 15206 | static struct pci_dev * __devinit tg3_find_peer(struct tg3 *tp) |
1da177e4 LT |
15207 | { |
15208 | struct pci_dev *peer; | |
15209 | unsigned int func, devnr = tp->pdev->devfn & ~7; | |
15210 | ||
15211 | for (func = 0; func < 8; func++) { | |
15212 | peer = pci_get_slot(tp->pdev->bus, devnr | func); | |
15213 | if (peer && peer != tp->pdev) | |
15214 | break; | |
15215 | pci_dev_put(peer); | |
15216 | } | |
16fe9d74 MC |
15217 | /* 5704 can be configured in single-port mode, set peer to |
15218 | * tp->pdev in that case. | |
15219 | */ | |
15220 | if (!peer) { | |
15221 | peer = tp->pdev; | |
15222 | return peer; | |
15223 | } | |
1da177e4 LT |
15224 | |
15225 | /* | |
15226 | * We don't need to keep the refcount elevated; there's no way | |
15227 | * to remove one half of this device without removing the other | |
15228 | */ | |
15229 | pci_dev_put(peer); | |
15230 | ||
15231 | return peer; | |
15232 | } | |
15233 | ||
15f9850d DM |
15234 | static void __devinit tg3_init_coal(struct tg3 *tp) |
15235 | { | |
15236 | struct ethtool_coalesce *ec = &tp->coal; | |
15237 | ||
15238 | memset(ec, 0, sizeof(*ec)); | |
15239 | ec->cmd = ETHTOOL_GCOALESCE; | |
15240 | ec->rx_coalesce_usecs = LOW_RXCOL_TICKS; | |
15241 | ec->tx_coalesce_usecs = LOW_TXCOL_TICKS; | |
15242 | ec->rx_max_coalesced_frames = LOW_RXMAX_FRAMES; | |
15243 | ec->tx_max_coalesced_frames = LOW_TXMAX_FRAMES; | |
15244 | ec->rx_coalesce_usecs_irq = DEFAULT_RXCOAL_TICK_INT; | |
15245 | ec->tx_coalesce_usecs_irq = DEFAULT_TXCOAL_TICK_INT; | |
15246 | ec->rx_max_coalesced_frames_irq = DEFAULT_RXCOAL_MAXF_INT; | |
15247 | ec->tx_max_coalesced_frames_irq = DEFAULT_TXCOAL_MAXF_INT; | |
15248 | ec->stats_block_coalesce_usecs = DEFAULT_STAT_COAL_TICKS; | |
15249 | ||
15250 | if (tp->coalesce_mode & (HOSTCC_MODE_CLRTICK_RXBD | | |
15251 | HOSTCC_MODE_CLRTICK_TXBD)) { | |
15252 | ec->rx_coalesce_usecs = LOW_RXCOL_TICKS_CLRTCKS; | |
15253 | ec->rx_coalesce_usecs_irq = DEFAULT_RXCOAL_TICK_INT_CLRTCKS; | |
15254 | ec->tx_coalesce_usecs = LOW_TXCOL_TICKS_CLRTCKS; | |
15255 | ec->tx_coalesce_usecs_irq = DEFAULT_TXCOAL_TICK_INT_CLRTCKS; | |
15256 | } | |
d244c892 | 15257 | |
63c3a66f | 15258 | if (tg3_flag(tp, 5705_PLUS)) { |
d244c892 MC |
15259 | ec->rx_coalesce_usecs_irq = 0; |
15260 | ec->tx_coalesce_usecs_irq = 0; | |
15261 | ec->stats_block_coalesce_usecs = 0; | |
15262 | } | |
15f9850d DM |
15263 | } |
15264 | ||
7c7d64b8 SH |
15265 | static const struct net_device_ops tg3_netdev_ops = { |
15266 | .ndo_open = tg3_open, | |
15267 | .ndo_stop = tg3_close, | |
00829823 | 15268 | .ndo_start_xmit = tg3_start_xmit, |
511d2224 | 15269 | .ndo_get_stats64 = tg3_get_stats64, |
00829823 | 15270 | .ndo_validate_addr = eth_validate_addr, |
afc4b13d | 15271 | .ndo_set_rx_mode = tg3_set_rx_mode, |
00829823 SH |
15272 | .ndo_set_mac_address = tg3_set_mac_addr, |
15273 | .ndo_do_ioctl = tg3_ioctl, | |
15274 | .ndo_tx_timeout = tg3_tx_timeout, | |
15275 | .ndo_change_mtu = tg3_change_mtu, | |
dc668910 | 15276 | .ndo_fix_features = tg3_fix_features, |
06c03c02 | 15277 | .ndo_set_features = tg3_set_features, |
00829823 SH |
15278 | #ifdef CONFIG_NET_POLL_CONTROLLER |
15279 | .ndo_poll_controller = tg3_poll_controller, | |
15280 | #endif | |
15281 | }; | |
15282 | ||
1da177e4 LT |
15283 | static int __devinit tg3_init_one(struct pci_dev *pdev, |
15284 | const struct pci_device_id *ent) | |
15285 | { | |
1da177e4 LT |
15286 | struct net_device *dev; |
15287 | struct tg3 *tp; | |
646c9edd MC |
15288 | int i, err, pm_cap; |
15289 | u32 sndmbx, rcvmbx, intmbx; | |
f9804ddb | 15290 | char str[40]; |
72f2afb8 | 15291 | u64 dma_mask, persist_dma_mask; |
0da0606f | 15292 | u32 features = 0; |
1da177e4 | 15293 | |
05dbe005 | 15294 | printk_once(KERN_INFO "%s\n", version); |
1da177e4 LT |
15295 | |
15296 | err = pci_enable_device(pdev); | |
15297 | if (err) { | |
2445e461 | 15298 | dev_err(&pdev->dev, "Cannot enable PCI device, aborting\n"); |
1da177e4 LT |
15299 | return err; |
15300 | } | |
15301 | ||
1da177e4 LT |
15302 | err = pci_request_regions(pdev, DRV_MODULE_NAME); |
15303 | if (err) { | |
2445e461 | 15304 | dev_err(&pdev->dev, "Cannot obtain PCI resources, aborting\n"); |
1da177e4 LT |
15305 | goto err_out_disable_pdev; |
15306 | } | |
15307 | ||
15308 | pci_set_master(pdev); | |
15309 | ||
15310 | /* Find power-management capability. */ | |
15311 | pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM); | |
15312 | if (pm_cap == 0) { | |
2445e461 MC |
15313 | dev_err(&pdev->dev, |
15314 | "Cannot find Power Management capability, aborting\n"); | |
1da177e4 LT |
15315 | err = -EIO; |
15316 | goto err_out_free_res; | |
15317 | } | |
15318 | ||
16821285 MC |
15319 | err = pci_set_power_state(pdev, PCI_D0); |
15320 | if (err) { | |
15321 | dev_err(&pdev->dev, "Transition to D0 failed, aborting\n"); | |
15322 | goto err_out_free_res; | |
15323 | } | |
15324 | ||
fe5f5787 | 15325 | dev = alloc_etherdev_mq(sizeof(*tp), TG3_IRQ_MAX_VECS); |
1da177e4 | 15326 | if (!dev) { |
2445e461 | 15327 | dev_err(&pdev->dev, "Etherdev alloc failed, aborting\n"); |
1da177e4 | 15328 | err = -ENOMEM; |
16821285 | 15329 | goto err_out_power_down; |
1da177e4 LT |
15330 | } |
15331 | ||
1da177e4 LT |
15332 | SET_NETDEV_DEV(dev, &pdev->dev); |
15333 | ||
1da177e4 LT |
15334 | tp = netdev_priv(dev); |
15335 | tp->pdev = pdev; | |
15336 | tp->dev = dev; | |
15337 | tp->pm_cap = pm_cap; | |
1da177e4 LT |
15338 | tp->rx_mode = TG3_DEF_RX_MODE; |
15339 | tp->tx_mode = TG3_DEF_TX_MODE; | |
8ef21428 | 15340 | |
1da177e4 LT |
15341 | if (tg3_debug > 0) |
15342 | tp->msg_enable = tg3_debug; | |
15343 | else | |
15344 | tp->msg_enable = TG3_DEF_MSG_ENABLE; | |
15345 | ||
15346 | /* The word/byte swap controls here control register access byte | |
15347 | * swapping. DMA data byte swapping is controlled in the GRC_MODE | |
15348 | * setting below. | |
15349 | */ | |
15350 | tp->misc_host_ctrl = | |
15351 | MISC_HOST_CTRL_MASK_PCI_INT | | |
15352 | MISC_HOST_CTRL_WORD_SWAP | | |
15353 | MISC_HOST_CTRL_INDIR_ACCESS | | |
15354 | MISC_HOST_CTRL_PCISTATE_RW; | |
15355 | ||
15356 | /* The NONFRM (non-frame) byte/word swap controls take effect | |
15357 | * on descriptor entries, anything which isn't packet data. | |
15358 | * | |
15359 | * The StrongARM chips on the board (one for tx, one for rx) | |
15360 | * are running in big-endian mode. | |
15361 | */ | |
15362 | tp->grc_mode = (GRC_MODE_WSWAP_DATA | GRC_MODE_BSWAP_DATA | | |
15363 | GRC_MODE_WSWAP_NONFRM_DATA); | |
15364 | #ifdef __BIG_ENDIAN | |
15365 | tp->grc_mode |= GRC_MODE_BSWAP_NONFRM_DATA; | |
15366 | #endif | |
15367 | spin_lock_init(&tp->lock); | |
1da177e4 | 15368 | spin_lock_init(&tp->indirect_lock); |
c4028958 | 15369 | INIT_WORK(&tp->reset_task, tg3_reset_task); |
1da177e4 | 15370 | |
d5fe488a | 15371 | tp->regs = pci_ioremap_bar(pdev, BAR_0); |
ab0049b4 | 15372 | if (!tp->regs) { |
ab96b241 | 15373 | dev_err(&pdev->dev, "Cannot map device registers, aborting\n"); |
1da177e4 LT |
15374 | err = -ENOMEM; |
15375 | goto err_out_free_dev; | |
15376 | } | |
15377 | ||
c9cab24e MC |
15378 | if (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5761 || |
15379 | tp->pdev->device == PCI_DEVICE_ID_TIGON3_5761E || | |
15380 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5761S || | |
15381 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5761SE || | |
15382 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5717 || | |
15383 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5718 || | |
15384 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5719 || | |
15385 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5720) { | |
15386 | tg3_flag_set(tp, ENABLE_APE); | |
15387 | tp->aperegs = pci_ioremap_bar(pdev, BAR_2); | |
15388 | if (!tp->aperegs) { | |
15389 | dev_err(&pdev->dev, | |
15390 | "Cannot map APE registers, aborting\n"); | |
15391 | err = -ENOMEM; | |
15392 | goto err_out_iounmap; | |
15393 | } | |
15394 | } | |
15395 | ||
1da177e4 LT |
15396 | tp->rx_pending = TG3_DEF_RX_RING_PENDING; |
15397 | tp->rx_jumbo_pending = TG3_DEF_RX_JUMBO_RING_PENDING; | |
1da177e4 | 15398 | |
1da177e4 | 15399 | dev->ethtool_ops = &tg3_ethtool_ops; |
1da177e4 | 15400 | dev->watchdog_timeo = TG3_TX_TIMEOUT; |
2ffcc981 | 15401 | dev->netdev_ops = &tg3_netdev_ops; |
1da177e4 | 15402 | dev->irq = pdev->irq; |
1da177e4 LT |
15403 | |
15404 | err = tg3_get_invariants(tp); | |
15405 | if (err) { | |
ab96b241 MC |
15406 | dev_err(&pdev->dev, |
15407 | "Problem fetching invariants of chip, aborting\n"); | |
c9cab24e | 15408 | goto err_out_apeunmap; |
1da177e4 LT |
15409 | } |
15410 | ||
4a29cc2e MC |
15411 | /* The EPB bridge inside 5714, 5715, and 5780 and any |
15412 | * device behind the EPB cannot support DMA addresses > 40-bit. | |
72f2afb8 MC |
15413 | * On 64-bit systems with IOMMU, use 40-bit dma_mask. |
15414 | * On 64-bit systems without IOMMU, use 64-bit dma_mask and | |
15415 | * do DMA address check in tg3_start_xmit(). | |
15416 | */ | |
63c3a66f | 15417 | if (tg3_flag(tp, IS_5788)) |
284901a9 | 15418 | persist_dma_mask = dma_mask = DMA_BIT_MASK(32); |
63c3a66f | 15419 | else if (tg3_flag(tp, 40BIT_DMA_BUG)) { |
50cf156a | 15420 | persist_dma_mask = dma_mask = DMA_BIT_MASK(40); |
72f2afb8 | 15421 | #ifdef CONFIG_HIGHMEM |
6a35528a | 15422 | dma_mask = DMA_BIT_MASK(64); |
72f2afb8 | 15423 | #endif |
4a29cc2e | 15424 | } else |
6a35528a | 15425 | persist_dma_mask = dma_mask = DMA_BIT_MASK(64); |
72f2afb8 MC |
15426 | |
15427 | /* Configure DMA attributes. */ | |
284901a9 | 15428 | if (dma_mask > DMA_BIT_MASK(32)) { |
72f2afb8 MC |
15429 | err = pci_set_dma_mask(pdev, dma_mask); |
15430 | if (!err) { | |
0da0606f | 15431 | features |= NETIF_F_HIGHDMA; |
72f2afb8 MC |
15432 | err = pci_set_consistent_dma_mask(pdev, |
15433 | persist_dma_mask); | |
15434 | if (err < 0) { | |
ab96b241 MC |
15435 | dev_err(&pdev->dev, "Unable to obtain 64 bit " |
15436 | "DMA for consistent allocations\n"); | |
c9cab24e | 15437 | goto err_out_apeunmap; |
72f2afb8 MC |
15438 | } |
15439 | } | |
15440 | } | |
284901a9 YH |
15441 | if (err || dma_mask == DMA_BIT_MASK(32)) { |
15442 | err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); | |
72f2afb8 | 15443 | if (err) { |
ab96b241 MC |
15444 | dev_err(&pdev->dev, |
15445 | "No usable DMA configuration, aborting\n"); | |
c9cab24e | 15446 | goto err_out_apeunmap; |
72f2afb8 MC |
15447 | } |
15448 | } | |
15449 | ||
fdfec172 | 15450 | tg3_init_bufmgr_config(tp); |
1da177e4 | 15451 | |
0da0606f MC |
15452 | features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX; |
15453 | ||
15454 | /* 5700 B0 chips do not support checksumming correctly due | |
15455 | * to hardware bugs. | |
15456 | */ | |
15457 | if (tp->pci_chip_rev_id != CHIPREV_ID_5700_B0) { | |
15458 | features |= NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_RXCSUM; | |
15459 | ||
15460 | if (tg3_flag(tp, 5755_PLUS)) | |
15461 | features |= NETIF_F_IPV6_CSUM; | |
15462 | } | |
15463 | ||
4e3a7aaa MC |
15464 | /* TSO is on by default on chips that support hardware TSO. |
15465 | * Firmware TSO on older chips gives lower performance, so it | |
15466 | * is off by default, but can be enabled using ethtool. | |
15467 | */ | |
63c3a66f JP |
15468 | if ((tg3_flag(tp, HW_TSO_1) || |
15469 | tg3_flag(tp, HW_TSO_2) || | |
15470 | tg3_flag(tp, HW_TSO_3)) && | |
0da0606f MC |
15471 | (features & NETIF_F_IP_CSUM)) |
15472 | features |= NETIF_F_TSO; | |
63c3a66f | 15473 | if (tg3_flag(tp, HW_TSO_2) || tg3_flag(tp, HW_TSO_3)) { |
0da0606f MC |
15474 | if (features & NETIF_F_IPV6_CSUM) |
15475 | features |= NETIF_F_TSO6; | |
63c3a66f | 15476 | if (tg3_flag(tp, HW_TSO_3) || |
e849cdc3 | 15477 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761 || |
57e6983c MC |
15478 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 && |
15479 | GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5784_AX) || | |
63c3a66f | 15480 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 || |
dc668910 | 15481 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) |
0da0606f | 15482 | features |= NETIF_F_TSO_ECN; |
b0026624 | 15483 | } |
1da177e4 | 15484 | |
d542fe27 MC |
15485 | dev->features |= features; |
15486 | dev->vlan_features |= features; | |
15487 | ||
06c03c02 MB |
15488 | /* |
15489 | * Add loopback capability only for a subset of devices that support | |
15490 | * MAC-LOOPBACK. Eventually this need to be enhanced to allow INT-PHY | |
15491 | * loopback for the remaining devices. | |
15492 | */ | |
15493 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5780 && | |
15494 | !tg3_flag(tp, CPMU_PRESENT)) | |
15495 | /* Add the loopback capability */ | |
0da0606f MC |
15496 | features |= NETIF_F_LOOPBACK; |
15497 | ||
0da0606f | 15498 | dev->hw_features |= features; |
06c03c02 | 15499 | |
1da177e4 | 15500 | if (tp->pci_chip_rev_id == CHIPREV_ID_5705_A1 && |
63c3a66f | 15501 | !tg3_flag(tp, TSO_CAPABLE) && |
1da177e4 | 15502 | !(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH)) { |
63c3a66f | 15503 | tg3_flag_set(tp, MAX_RXPEND_64); |
1da177e4 LT |
15504 | tp->rx_pending = 63; |
15505 | } | |
15506 | ||
1da177e4 LT |
15507 | err = tg3_get_device_address(tp); |
15508 | if (err) { | |
ab96b241 MC |
15509 | dev_err(&pdev->dev, |
15510 | "Could not obtain valid ethernet address, aborting\n"); | |
c9cab24e | 15511 | goto err_out_apeunmap; |
c88864df MC |
15512 | } |
15513 | ||
1da177e4 LT |
15514 | /* |
15515 | * Reset chip in case UNDI or EFI driver did not shutdown | |
15516 | * DMA self test will enable WDMAC and we'll see (spurious) | |
15517 | * pending DMA on the PCI bus at that point. | |
15518 | */ | |
15519 | if ((tr32(HOSTCC_MODE) & HOSTCC_MODE_ENABLE) || | |
15520 | (tr32(WDMAC_MODE) & WDMAC_MODE_ENABLE)) { | |
1da177e4 | 15521 | tw32(MEMARB_MODE, MEMARB_MODE_ENABLE); |
944d980e | 15522 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
1da177e4 LT |
15523 | } |
15524 | ||
15525 | err = tg3_test_dma(tp); | |
15526 | if (err) { | |
ab96b241 | 15527 | dev_err(&pdev->dev, "DMA engine test failed, aborting\n"); |
c88864df | 15528 | goto err_out_apeunmap; |
1da177e4 LT |
15529 | } |
15530 | ||
78f90dcf MC |
15531 | intmbx = MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW; |
15532 | rcvmbx = MAILBOX_RCVRET_CON_IDX_0 + TG3_64BIT_REG_LOW; | |
15533 | sndmbx = MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW; | |
6fd45cb8 | 15534 | for (i = 0; i < tp->irq_max; i++) { |
78f90dcf MC |
15535 | struct tg3_napi *tnapi = &tp->napi[i]; |
15536 | ||
15537 | tnapi->tp = tp; | |
15538 | tnapi->tx_pending = TG3_DEF_TX_RING_PENDING; | |
15539 | ||
15540 | tnapi->int_mbox = intmbx; | |
15541 | if (i < 4) | |
15542 | intmbx += 0x8; | |
15543 | else | |
15544 | intmbx += 0x4; | |
15545 | ||
15546 | tnapi->consmbox = rcvmbx; | |
15547 | tnapi->prodmbox = sndmbx; | |
15548 | ||
66cfd1bd | 15549 | if (i) |
78f90dcf | 15550 | tnapi->coal_now = HOSTCC_MODE_COAL_VEC1_NOW << (i - 1); |
66cfd1bd | 15551 | else |
78f90dcf | 15552 | tnapi->coal_now = HOSTCC_MODE_NOW; |
78f90dcf | 15553 | |
63c3a66f | 15554 | if (!tg3_flag(tp, SUPPORT_MSIX)) |
78f90dcf MC |
15555 | break; |
15556 | ||
15557 | /* | |
15558 | * If we support MSIX, we'll be using RSS. If we're using | |
15559 | * RSS, the first vector only handles link interrupts and the | |
15560 | * remaining vectors handle rx and tx interrupts. Reuse the | |
15561 | * mailbox values for the next iteration. The values we setup | |
15562 | * above are still useful for the single vectored mode. | |
15563 | */ | |
15564 | if (!i) | |
15565 | continue; | |
15566 | ||
15567 | rcvmbx += 0x8; | |
15568 | ||
15569 | if (sndmbx & 0x4) | |
15570 | sndmbx -= 0x4; | |
15571 | else | |
15572 | sndmbx += 0xc; | |
15573 | } | |
15574 | ||
15f9850d DM |
15575 | tg3_init_coal(tp); |
15576 | ||
c49a1561 MC |
15577 | pci_set_drvdata(pdev, dev); |
15578 | ||
cd0d7228 MC |
15579 | if (tg3_flag(tp, 5717_PLUS)) { |
15580 | /* Resume a low-power mode */ | |
15581 | tg3_frob_aux_power(tp, false); | |
15582 | } | |
15583 | ||
1da177e4 LT |
15584 | err = register_netdev(dev); |
15585 | if (err) { | |
ab96b241 | 15586 | dev_err(&pdev->dev, "Cannot register net device, aborting\n"); |
0d3031d9 | 15587 | goto err_out_apeunmap; |
1da177e4 LT |
15588 | } |
15589 | ||
05dbe005 JP |
15590 | netdev_info(dev, "Tigon3 [partno(%s) rev %04x] (%s) MAC address %pM\n", |
15591 | tp->board_part_number, | |
15592 | tp->pci_chip_rev_id, | |
15593 | tg3_bus_string(tp, str), | |
15594 | dev->dev_addr); | |
1da177e4 | 15595 | |
f07e9af3 | 15596 | if (tp->phy_flags & TG3_PHYFLG_IS_CONNECTED) { |
3f0e3ad7 MC |
15597 | struct phy_device *phydev; |
15598 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; | |
5129c3a3 MC |
15599 | netdev_info(dev, |
15600 | "attached PHY driver [%s] (mii_bus:phy_addr=%s)\n", | |
05dbe005 | 15601 | phydev->drv->name, dev_name(&phydev->dev)); |
f07e9af3 MC |
15602 | } else { |
15603 | char *ethtype; | |
15604 | ||
15605 | if (tp->phy_flags & TG3_PHYFLG_10_100_ONLY) | |
15606 | ethtype = "10/100Base-TX"; | |
15607 | else if (tp->phy_flags & TG3_PHYFLG_ANY_SERDES) | |
15608 | ethtype = "1000Base-SX"; | |
15609 | else | |
15610 | ethtype = "10/100/1000Base-T"; | |
15611 | ||
5129c3a3 | 15612 | netdev_info(dev, "attached PHY is %s (%s Ethernet) " |
47007831 MC |
15613 | "(WireSpeed[%d], EEE[%d])\n", |
15614 | tg3_phy_string(tp), ethtype, | |
15615 | (tp->phy_flags & TG3_PHYFLG_NO_ETH_WIRE_SPEED) == 0, | |
15616 | (tp->phy_flags & TG3_PHYFLG_EEE_CAP) != 0); | |
f07e9af3 | 15617 | } |
05dbe005 JP |
15618 | |
15619 | netdev_info(dev, "RXcsums[%d] LinkChgREG[%d] MIirq[%d] ASF[%d] TSOcap[%d]\n", | |
dc668910 | 15620 | (dev->features & NETIF_F_RXCSUM) != 0, |
63c3a66f | 15621 | tg3_flag(tp, USE_LINKCHG_REG) != 0, |
f07e9af3 | 15622 | (tp->phy_flags & TG3_PHYFLG_USE_MI_INTERRUPT) != 0, |
63c3a66f JP |
15623 | tg3_flag(tp, ENABLE_ASF) != 0, |
15624 | tg3_flag(tp, TSO_CAPABLE) != 0); | |
05dbe005 JP |
15625 | netdev_info(dev, "dma_rwctrl[%08x] dma_mask[%d-bit]\n", |
15626 | tp->dma_rwctrl, | |
15627 | pdev->dma_mask == DMA_BIT_MASK(32) ? 32 : | |
15628 | ((u64)pdev->dma_mask) == DMA_BIT_MASK(40) ? 40 : 64); | |
1da177e4 | 15629 | |
b45aa2f6 MC |
15630 | pci_save_state(pdev); |
15631 | ||
1da177e4 LT |
15632 | return 0; |
15633 | ||
0d3031d9 MC |
15634 | err_out_apeunmap: |
15635 | if (tp->aperegs) { | |
15636 | iounmap(tp->aperegs); | |
15637 | tp->aperegs = NULL; | |
15638 | } | |
15639 | ||
1da177e4 | 15640 | err_out_iounmap: |
6892914f MC |
15641 | if (tp->regs) { |
15642 | iounmap(tp->regs); | |
22abe310 | 15643 | tp->regs = NULL; |
6892914f | 15644 | } |
1da177e4 LT |
15645 | |
15646 | err_out_free_dev: | |
15647 | free_netdev(dev); | |
15648 | ||
16821285 MC |
15649 | err_out_power_down: |
15650 | pci_set_power_state(pdev, PCI_D3hot); | |
15651 | ||
1da177e4 LT |
15652 | err_out_free_res: |
15653 | pci_release_regions(pdev); | |
15654 | ||
15655 | err_out_disable_pdev: | |
15656 | pci_disable_device(pdev); | |
15657 | pci_set_drvdata(pdev, NULL); | |
15658 | return err; | |
15659 | } | |
15660 | ||
15661 | static void __devexit tg3_remove_one(struct pci_dev *pdev) | |
15662 | { | |
15663 | struct net_device *dev = pci_get_drvdata(pdev); | |
15664 | ||
15665 | if (dev) { | |
15666 | struct tg3 *tp = netdev_priv(dev); | |
15667 | ||
077f849d JSR |
15668 | if (tp->fw) |
15669 | release_firmware(tp->fw); | |
15670 | ||
23f333a2 | 15671 | cancel_work_sync(&tp->reset_task); |
158d7abd | 15672 | |
63c3a66f | 15673 | if (!tg3_flag(tp, USE_PHYLIB)) { |
b02fd9e3 | 15674 | tg3_phy_fini(tp); |
158d7abd | 15675 | tg3_mdio_fini(tp); |
b02fd9e3 | 15676 | } |
158d7abd | 15677 | |
1da177e4 | 15678 | unregister_netdev(dev); |
0d3031d9 MC |
15679 | if (tp->aperegs) { |
15680 | iounmap(tp->aperegs); | |
15681 | tp->aperegs = NULL; | |
15682 | } | |
6892914f MC |
15683 | if (tp->regs) { |
15684 | iounmap(tp->regs); | |
22abe310 | 15685 | tp->regs = NULL; |
6892914f | 15686 | } |
1da177e4 LT |
15687 | free_netdev(dev); |
15688 | pci_release_regions(pdev); | |
15689 | pci_disable_device(pdev); | |
15690 | pci_set_drvdata(pdev, NULL); | |
15691 | } | |
15692 | } | |
15693 | ||
aa6027ca | 15694 | #ifdef CONFIG_PM_SLEEP |
c866b7ea | 15695 | static int tg3_suspend(struct device *device) |
1da177e4 | 15696 | { |
c866b7ea | 15697 | struct pci_dev *pdev = to_pci_dev(device); |
1da177e4 LT |
15698 | struct net_device *dev = pci_get_drvdata(pdev); |
15699 | struct tg3 *tp = netdev_priv(dev); | |
15700 | int err; | |
15701 | ||
15702 | if (!netif_running(dev)) | |
15703 | return 0; | |
15704 | ||
23f333a2 | 15705 | flush_work_sync(&tp->reset_task); |
b02fd9e3 | 15706 | tg3_phy_stop(tp); |
1da177e4 LT |
15707 | tg3_netif_stop(tp); |
15708 | ||
15709 | del_timer_sync(&tp->timer); | |
15710 | ||
f47c11ee | 15711 | tg3_full_lock(tp, 1); |
1da177e4 | 15712 | tg3_disable_ints(tp); |
f47c11ee | 15713 | tg3_full_unlock(tp); |
1da177e4 LT |
15714 | |
15715 | netif_device_detach(dev); | |
15716 | ||
f47c11ee | 15717 | tg3_full_lock(tp, 0); |
944d980e | 15718 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
63c3a66f | 15719 | tg3_flag_clear(tp, INIT_COMPLETE); |
f47c11ee | 15720 | tg3_full_unlock(tp); |
1da177e4 | 15721 | |
c866b7ea | 15722 | err = tg3_power_down_prepare(tp); |
1da177e4 | 15723 | if (err) { |
b02fd9e3 MC |
15724 | int err2; |
15725 | ||
f47c11ee | 15726 | tg3_full_lock(tp, 0); |
1da177e4 | 15727 | |
63c3a66f | 15728 | tg3_flag_set(tp, INIT_COMPLETE); |
b02fd9e3 MC |
15729 | err2 = tg3_restart_hw(tp, 1); |
15730 | if (err2) | |
b9ec6c1b | 15731 | goto out; |
1da177e4 LT |
15732 | |
15733 | tp->timer.expires = jiffies + tp->timer_offset; | |
15734 | add_timer(&tp->timer); | |
15735 | ||
15736 | netif_device_attach(dev); | |
15737 | tg3_netif_start(tp); | |
15738 | ||
b9ec6c1b | 15739 | out: |
f47c11ee | 15740 | tg3_full_unlock(tp); |
b02fd9e3 MC |
15741 | |
15742 | if (!err2) | |
15743 | tg3_phy_start(tp); | |
1da177e4 LT |
15744 | } |
15745 | ||
15746 | return err; | |
15747 | } | |
15748 | ||
c866b7ea | 15749 | static int tg3_resume(struct device *device) |
1da177e4 | 15750 | { |
c866b7ea | 15751 | struct pci_dev *pdev = to_pci_dev(device); |
1da177e4 LT |
15752 | struct net_device *dev = pci_get_drvdata(pdev); |
15753 | struct tg3 *tp = netdev_priv(dev); | |
15754 | int err; | |
15755 | ||
15756 | if (!netif_running(dev)) | |
15757 | return 0; | |
15758 | ||
1da177e4 LT |
15759 | netif_device_attach(dev); |
15760 | ||
f47c11ee | 15761 | tg3_full_lock(tp, 0); |
1da177e4 | 15762 | |
63c3a66f | 15763 | tg3_flag_set(tp, INIT_COMPLETE); |
b9ec6c1b MC |
15764 | err = tg3_restart_hw(tp, 1); |
15765 | if (err) | |
15766 | goto out; | |
1da177e4 LT |
15767 | |
15768 | tp->timer.expires = jiffies + tp->timer_offset; | |
15769 | add_timer(&tp->timer); | |
15770 | ||
1da177e4 LT |
15771 | tg3_netif_start(tp); |
15772 | ||
b9ec6c1b | 15773 | out: |
f47c11ee | 15774 | tg3_full_unlock(tp); |
1da177e4 | 15775 | |
b02fd9e3 MC |
15776 | if (!err) |
15777 | tg3_phy_start(tp); | |
15778 | ||
b9ec6c1b | 15779 | return err; |
1da177e4 LT |
15780 | } |
15781 | ||
c866b7ea | 15782 | static SIMPLE_DEV_PM_OPS(tg3_pm_ops, tg3_suspend, tg3_resume); |
aa6027ca ED |
15783 | #define TG3_PM_OPS (&tg3_pm_ops) |
15784 | ||
15785 | #else | |
15786 | ||
15787 | #define TG3_PM_OPS NULL | |
15788 | ||
15789 | #endif /* CONFIG_PM_SLEEP */ | |
c866b7ea | 15790 | |
b45aa2f6 MC |
15791 | /** |
15792 | * tg3_io_error_detected - called when PCI error is detected | |
15793 | * @pdev: Pointer to PCI device | |
15794 | * @state: The current pci connection state | |
15795 | * | |
15796 | * This function is called after a PCI bus error affecting | |
15797 | * this device has been detected. | |
15798 | */ | |
15799 | static pci_ers_result_t tg3_io_error_detected(struct pci_dev *pdev, | |
15800 | pci_channel_state_t state) | |
15801 | { | |
15802 | struct net_device *netdev = pci_get_drvdata(pdev); | |
15803 | struct tg3 *tp = netdev_priv(netdev); | |
15804 | pci_ers_result_t err = PCI_ERS_RESULT_NEED_RESET; | |
15805 | ||
15806 | netdev_info(netdev, "PCI I/O error detected\n"); | |
15807 | ||
15808 | rtnl_lock(); | |
15809 | ||
15810 | if (!netif_running(netdev)) | |
15811 | goto done; | |
15812 | ||
15813 | tg3_phy_stop(tp); | |
15814 | ||
15815 | tg3_netif_stop(tp); | |
15816 | ||
15817 | del_timer_sync(&tp->timer); | |
63c3a66f | 15818 | tg3_flag_clear(tp, RESTART_TIMER); |
b45aa2f6 MC |
15819 | |
15820 | /* Want to make sure that the reset task doesn't run */ | |
15821 | cancel_work_sync(&tp->reset_task); | |
63c3a66f JP |
15822 | tg3_flag_clear(tp, TX_RECOVERY_PENDING); |
15823 | tg3_flag_clear(tp, RESTART_TIMER); | |
b45aa2f6 MC |
15824 | |
15825 | netif_device_detach(netdev); | |
15826 | ||
15827 | /* Clean up software state, even if MMIO is blocked */ | |
15828 | tg3_full_lock(tp, 0); | |
15829 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 0); | |
15830 | tg3_full_unlock(tp); | |
15831 | ||
15832 | done: | |
15833 | if (state == pci_channel_io_perm_failure) | |
15834 | err = PCI_ERS_RESULT_DISCONNECT; | |
15835 | else | |
15836 | pci_disable_device(pdev); | |
15837 | ||
15838 | rtnl_unlock(); | |
15839 | ||
15840 | return err; | |
15841 | } | |
15842 | ||
15843 | /** | |
15844 | * tg3_io_slot_reset - called after the pci bus has been reset. | |
15845 | * @pdev: Pointer to PCI device | |
15846 | * | |
15847 | * Restart the card from scratch, as if from a cold-boot. | |
15848 | * At this point, the card has exprienced a hard reset, | |
15849 | * followed by fixups by BIOS, and has its config space | |
15850 | * set up identically to what it was at cold boot. | |
15851 | */ | |
15852 | static pci_ers_result_t tg3_io_slot_reset(struct pci_dev *pdev) | |
15853 | { | |
15854 | struct net_device *netdev = pci_get_drvdata(pdev); | |
15855 | struct tg3 *tp = netdev_priv(netdev); | |
15856 | pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT; | |
15857 | int err; | |
15858 | ||
15859 | rtnl_lock(); | |
15860 | ||
15861 | if (pci_enable_device(pdev)) { | |
15862 | netdev_err(netdev, "Cannot re-enable PCI device after reset.\n"); | |
15863 | goto done; | |
15864 | } | |
15865 | ||
15866 | pci_set_master(pdev); | |
15867 | pci_restore_state(pdev); | |
15868 | pci_save_state(pdev); | |
15869 | ||
15870 | if (!netif_running(netdev)) { | |
15871 | rc = PCI_ERS_RESULT_RECOVERED; | |
15872 | goto done; | |
15873 | } | |
15874 | ||
15875 | err = tg3_power_up(tp); | |
bed9829f | 15876 | if (err) |
b45aa2f6 | 15877 | goto done; |
b45aa2f6 MC |
15878 | |
15879 | rc = PCI_ERS_RESULT_RECOVERED; | |
15880 | ||
15881 | done: | |
15882 | rtnl_unlock(); | |
15883 | ||
15884 | return rc; | |
15885 | } | |
15886 | ||
15887 | /** | |
15888 | * tg3_io_resume - called when traffic can start flowing again. | |
15889 | * @pdev: Pointer to PCI device | |
15890 | * | |
15891 | * This callback is called when the error recovery driver tells | |
15892 | * us that its OK to resume normal operation. | |
15893 | */ | |
15894 | static void tg3_io_resume(struct pci_dev *pdev) | |
15895 | { | |
15896 | struct net_device *netdev = pci_get_drvdata(pdev); | |
15897 | struct tg3 *tp = netdev_priv(netdev); | |
15898 | int err; | |
15899 | ||
15900 | rtnl_lock(); | |
15901 | ||
15902 | if (!netif_running(netdev)) | |
15903 | goto done; | |
15904 | ||
15905 | tg3_full_lock(tp, 0); | |
63c3a66f | 15906 | tg3_flag_set(tp, INIT_COMPLETE); |
b45aa2f6 MC |
15907 | err = tg3_restart_hw(tp, 1); |
15908 | tg3_full_unlock(tp); | |
15909 | if (err) { | |
15910 | netdev_err(netdev, "Cannot restart hardware after reset.\n"); | |
15911 | goto done; | |
15912 | } | |
15913 | ||
15914 | netif_device_attach(netdev); | |
15915 | ||
15916 | tp->timer.expires = jiffies + tp->timer_offset; | |
15917 | add_timer(&tp->timer); | |
15918 | ||
15919 | tg3_netif_start(tp); | |
15920 | ||
15921 | tg3_phy_start(tp); | |
15922 | ||
15923 | done: | |
15924 | rtnl_unlock(); | |
15925 | } | |
15926 | ||
15927 | static struct pci_error_handlers tg3_err_handler = { | |
15928 | .error_detected = tg3_io_error_detected, | |
15929 | .slot_reset = tg3_io_slot_reset, | |
15930 | .resume = tg3_io_resume | |
15931 | }; | |
15932 | ||
1da177e4 LT |
15933 | static struct pci_driver tg3_driver = { |
15934 | .name = DRV_MODULE_NAME, | |
15935 | .id_table = tg3_pci_tbl, | |
15936 | .probe = tg3_init_one, | |
15937 | .remove = __devexit_p(tg3_remove_one), | |
b45aa2f6 | 15938 | .err_handler = &tg3_err_handler, |
aa6027ca | 15939 | .driver.pm = TG3_PM_OPS, |
1da177e4 LT |
15940 | }; |
15941 | ||
15942 | static int __init tg3_init(void) | |
15943 | { | |
29917620 | 15944 | return pci_register_driver(&tg3_driver); |
1da177e4 LT |
15945 | } |
15946 | ||
15947 | static void __exit tg3_cleanup(void) | |
15948 | { | |
15949 | pci_unregister_driver(&tg3_driver); | |
15950 | } | |
15951 | ||
15952 | module_init(tg3_init); | |
15953 | module_exit(tg3_cleanup); |